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
;
36 transaction_id followupTid
;
37 transaction_id publishTid
;
38 transaction_id publishCancelTid
;
39 transaction_id subscribeTid
;
40 transaction_id subscribeCancelTid
;
41 transaction_id enableTid
;
42 transaction_id disableTid
;
43 transaction_id configTid
;
44 transaction_id capabilitiesTid
;
46 NanCapabilities capabilities
;
47 NanDataCommand datacmd
;
49 void registerNanEvents(void) {
50 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_PUBLISH_TERMINATED
);
51 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_MATCH
);
52 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_MATCH_EXPIRED
);
53 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED
);
54 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_FOLLOWUP
);
55 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_DISCOVERY_ENGINE
);
56 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS
);
57 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_NDP_REQ
);
58 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_NDP_CFM
);
59 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_NDP_END
);
62 void unregisterNanEvents(void) {
63 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_PUBLISH_TERMINATED
);
64 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_MATCH
);
65 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_MATCH_EXPIRED
);
66 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED
);
67 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_FOLLOWUP
);
68 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_DISCOVERY_ENGINE
);
69 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS
);
70 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_NDP_REQ
);
71 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_NDP_CFM
);
72 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_NDP_END
);
75 int processResponse(WifiEvent
&reply
, NanResponseMsg
*response
) {
76 NanCapabilities
*capabilities
= &response
->body
.nan_capabilities
;
77 nlattr
*vendor_data
= reply
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
80 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
81 switch(nl_itr
.get_type()) {
82 case NAN_REPLY_ATTR_STATUS_TYPE
:
83 response
->status
= NanStatusType(nl_itr
.get_u32());
85 case NAN_REPLY_ATTR_VALUE
:
86 val
= nl_itr
.get_u32();
88 strncpy(response
->nan_error
, "Lower_layer_error",NAN_ERROR_STR_LEN
);
91 case NAN_REPLY_ATTR_RESPONSE_TYPE
:
92 response
->response_type
= NanResponseType(nl_itr
.get_u32());
94 case NAN_REPLY_ATTR_PUBLISH_SUBSCRIBE_TYPE
:
95 response
->body
.publish_response
.publish_id
= nl_itr
.get_u16();
97 case NAN_REPLY_ATTR_NDP_INSTANCE_ID
:
98 response
->body
.data_request_response
.ndp_instance_id
= nl_itr
.get_u32();
100 case NAN_REPLY_ATTR_CAP_MAX_CONCURRENT_CLUSTER
:
101 capabilities
->max_concurrent_nan_clusters
= nl_itr
.get_u32();
103 case NAN_REPLY_ATTR_CAP_MAX_PUBLISHES
:
104 capabilities
->max_publishes
= nl_itr
.get_u32();
106 case NAN_REPLY_ATTR_CAP_MAX_SUBSCRIBES
:
107 capabilities
->max_subscribes
= nl_itr
.get_u32();
109 case NAN_REPLY_ATTR_CAP_MAX_SERVICE_NAME_LEN
:
110 capabilities
->max_service_name_len
= nl_itr
.get_u32();
112 case NAN_REPLY_ATTR_CAP_MAX_MATCH_FILTER_LEN
:
113 capabilities
->max_match_filter_len
= nl_itr
.get_u32();
115 case NAN_REPLY_ATTR_CAP_MAX_TOTAL_MATCH_FILTER_LEN
:
116 capabilities
->max_total_match_filter_len
= nl_itr
.get_u32();
118 case NAN_REPLY_ATTR_CAP_MAX_SERVICE_SPECIFIC_INFO_LEN
:
119 capabilities
->max_service_specific_info_len
= nl_itr
.get_u32();
121 case NAN_REPLY_ATTR_CAP_MAX_VSA_DATA_LEN
:
122 capabilities
->max_vsa_data_len
= nl_itr
.get_u32();
124 case NAN_REPLY_ATTR_CAP_MAX_MESH_DATA_LEN
:
125 capabilities
->max_mesh_data_len
= nl_itr
.get_u32();
127 case NAN_REPLY_ATTR_CAP_MAX_NDI_INTERFACES
:
128 capabilities
->max_ndi_interfaces
= nl_itr
.get_u32();
130 case NAN_REPLY_ATTR_CAP_MAX_NDP_SESSIONS
:
131 capabilities
->max_ndp_sessions
= nl_itr
.get_u32();
133 case NAN_REPLY_ATTR_CAP_MAX_APP_INFO_LEN
:
134 capabilities
->max_app_info_len
= nl_itr
.get_u32();
137 case NAN_REPLY_ATTR_CAP_MAX_QUEUED_TRANSMIT_FOLLOWUP_MGS
:
138 capabilities
->max_queued_transmit_followup_msgs
= nl_itr
.get_u32();
140 case NAN_REPLY_ATTR_CAP_MAX_NDP_SUPPORTED_BANDS
:
141 capabilities
->ndp_supported_bands
= nl_itr
.get_u32();
143 case NAN_REPLY_ATTR_CAP_MAX_CIPHER_SUITES_SUPPORTED
:
144 capabilities
->cipher_suites_supported
= nl_itr
.get_u32();
146 case NAN_REPLY_ATTR_CAP_MAX_SCID_LEN
:
147 capabilities
->max_scid_len
= nl_itr
.get_u32();
149 case NAN_REPLY_ATTR_CAP_NDP_SECURITY_SUPPORTED
:
150 capabilities
->is_ndp_security_supported
= (bool)nl_itr
.get_u32();
152 case NAN_REPLY_ATTR_CAP_MAX_SDEA_SERVICE_SPECIFIC_INFO_LEN
:
153 capabilities
->max_sdea_service_specific_info_len
= nl_itr
.get_u32();
155 case NAN_REPLY_ATTR_CAP_MAX_SUBSCRIBE_ADDRESS
:
156 capabilities
->max_subscribe_address
= nl_itr
.get_u32();
158 case NAN_REPLY_ATTR_CAP_NDPE_ATTR_SUPPORTED
:
159 capabilities
->ndpe_attr_supported
= nl_itr
.get_u32();
162 ALOGE("received unknown type(%d) in response", nl_itr
.get_type());
166 this->capabilities
= *capabilities
;
170 int processMatchEvent(WifiEvent
&event
) {
172 memset(&ind
,0,sizeof(NanMatchInd
));
173 int famchan_idx
= 0, disc_idx
= 0;
174 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
176 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
177 switch(nl_itr
.get_type()) {
178 case NAN_EVT_ATTR_MATCH_PUBLISH_SUBSCRIBE_ID
:
179 ind
.publish_subscribe_id
= nl_itr
.get_u16();
181 case NAN_EVT_ATTR_MATCH_REQUESTOR_INSTANCE_ID
:
182 ind
.requestor_instance_id
= nl_itr
.get_u32();
184 case NAN_EVT_ATTR_MATCH_ADDR
:
185 memcpy(ind
.addr
, nl_itr
.get_data(), NAN_MAC_ADDR_LEN
);
187 case NAN_EVT_ATTR_MATCH_SERVICE_SPECIFIC_INFO_LEN
:
188 ind
.service_specific_info_len
= nl_itr
.get_u16();
190 case NAN_EVT_ATTR_MATCH_SERVICE_SPECIFIC_INFO
:
191 memcpy(ind
.service_specific_info
, nl_itr
.get_data(), ind
.service_specific_info_len
);
193 case NAN_EVT_ATTR_MATCH_SDF_MATCH_FILTER_LEN
:
194 ind
.sdf_match_filter_len
= nl_itr
.get_u16();
196 case NAN_EVT_ATTR_MATCH_SDF_MATCH_FILTER
:
197 memcpy(ind
.sdf_match_filter
, nl_itr
.get_data(), ind
.sdf_match_filter_len
);
199 case NAN_EVT_ATTR_MATCH_MATCH_OCCURED_FLAG
:
200 ind
.match_occured_flag
= nl_itr
.get_u8();
202 case NAN_EVT_ATTR_MATCH_OUT_OF_RESOURCE_FLAG
:
203 ind
.out_of_resource_flag
= nl_itr
.get_u8();
205 case NAN_EVT_ATTR_MATCH_RSSI_VALUE
:
206 ind
.rssi_value
= nl_itr
.get_u8();
208 case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_IBSS_SUPPORTED
:
209 ind
.conn_capability
.is_ibss_supported
= nl_itr
.get_u8();
211 case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_WFD_SUPPORTED
:
212 ind
.conn_capability
.is_wfd_supported
= nl_itr
.get_u8();
214 case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_WFDS_SUPPORTED
:
215 ind
.conn_capability
.is_wfds_supported
= nl_itr
.get_u8();
217 case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_TDLS_SUPPORTED
:
218 ind
.conn_capability
.is_tdls_supported
= nl_itr
.get_u8();
220 case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_MESH_SUPPORTED
:
221 ind
.conn_capability
.is_mesh_supported
= nl_itr
.get_u8();
223 case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_WLAN_INFRA_FIELD
:
224 ind
.conn_capability
.wlan_infra_field
= nl_itr
.get_u8();
226 case NAN_EVT_ATTR_MATCH_NUM_RX_DISCOVERY_ATTR
:
227 ind
.num_rx_discovery_attr
= nl_itr
.get_u8();
229 case NAN_EVT_ATTR_MATCH_RX_DISCOVERY_ATTR
:
230 NanReceivePostDiscovery
*disc_attr
;
231 disc_attr
= &ind
.discovery_attr
[disc_idx
];
233 for(nl_iterator
nl_nested_itr((struct nlattr
*)nl_itr
.get_data()); nl_nested_itr
.has_next(); nl_nested_itr
.next()) {
234 switch(nl_nested_itr
.get_type()) {
235 case NAN_EVT_ATTR_MATCH_DISC_ATTR_TYPE
:
236 disc_attr
->type
= (NanConnectionType
)nl_nested_itr
.get_u8();
238 case NAN_EVT_ATTR_MATCH_DISC_ATTR_ROLE
:
239 disc_attr
->role
= (NanDeviceRole
)nl_nested_itr
.get_u8();
241 case NAN_EVT_ATTR_MATCH_DISC_ATTR_DURATION
:
242 disc_attr
->duration
= (NanAvailDuration
)nl_nested_itr
.get_u8();
244 case NAN_EVT_ATTR_MATCH_DISC_ATTR_AVAIL_INTERVAL_BITMAP
:
245 disc_attr
->avail_interval_bitmap
= nl_nested_itr
.get_u32();
247 case NAN_EVT_ATTR_MATCH_DISC_ATTR_MAPID
:
248 disc_attr
->mapid
= nl_nested_itr
.get_u8();
250 case NAN_EVT_ATTR_MATCH_DISC_ATTR_ADDR
:
251 memcpy(disc_attr
->addr
, nl_nested_itr
.get_data(), NAN_MAC_ADDR_LEN
);
253 case NAN_EVT_ATTR_MATCH_DISC_ATTR_MESH_ID_LEN
:
254 disc_attr
->mesh_id_len
= nl_nested_itr
.get_u8();
256 case NAN_EVT_ATTR_MATCH_DISC_ATTR_MESH_ID
:
257 memcpy(disc_attr
->mesh_id
, nl_nested_itr
.get_data(), disc_attr
->mesh_id_len
);
259 case NAN_EVT_ATTR_MATCH_DISC_ATTR_INFRASTRUCTURE_SSID_LEN
:
260 disc_attr
->infrastructure_ssid_len
= nl_nested_itr
.get_u16();
262 case NAN_EVT_ATTR_MATCH_DISC_ATTR_INFRASTRUCTURE_SSID_VAL
:
263 memcpy(disc_attr
->infrastructure_ssid_val
, nl_nested_itr
.get_data(), disc_attr
->infrastructure_ssid_len
);
268 case NAN_EVT_ATTR_MATCH_NUM_CHANS
:
269 ind
.num_chans
= nl_itr
.get_u8();
271 case NAN_EVT_ATTR_MATCH_FAMCHAN
:
272 NanFurtherAvailabilityChannel
*famchan
;
273 famchan
= &ind
.famchan
[famchan_idx
];
275 for(nl_iterator
nl_nested_itr((struct nlattr
*)nl_itr
.get_data()); nl_nested_itr
.has_next(); nl_nested_itr
.next()) {
276 switch(nl_nested_itr
.get_type()) {
277 case NAN_EVT_ATTR_MATCH_FAM_ENTRY_CONTROL
:
278 famchan
->entry_control
= (NanAvailDuration
)nl_nested_itr
.get_u8();
280 case NAN_EVT_ATTR_MATCH_FAM_CLASS_VAL
:
281 famchan
->class_val
= nl_nested_itr
.get_u8();
283 case NAN_EVT_ATTR_MATCH_FAM_CHANNEL
:
284 famchan
->channel
= nl_nested_itr
.get_u8();
286 case NAN_EVT_ATTR_MATCH_FAM_MAPID
:
287 famchan
->mapid
= nl_nested_itr
.get_u8();
289 case NAN_EVT_ATTR_MATCH_FAM_AVAIL_INTERVAL_BITMAP
:
290 famchan
->avail_interval_bitmap
= nl_nested_itr
.get_u32();
295 case NAN_EVT_ATTR_MATCH_CLUSTER_ATTRIBUTE_LEN
:
296 ind
.cluster_attribute_len
= nl_itr
.get_u8();
298 case NAN_EVT_ATTR_MATCH_CLUSTER_ATTRIBUTE
:
299 memcpy(ind
.cluster_attribute
, nl_itr
.get_data(), ind
.cluster_attribute_len
);
301 case NAN_EVT_ATTR_SDEA_LEN
:
302 ind
.sdea_service_specific_info_len
= nl_itr
.get_u16();
304 case NAN_EVT_ATTR_SDEA
:
305 memcpy(ind
.sdea_service_specific_info
, nl_itr
.get_data(), ind
.sdea_service_specific_info_len
);
307 case NAN_EVT_ATTR_SCID_LEN
:
308 ind
.scid_len
= nl_itr
.get_u32();
310 case NAN_EVT_ATTR_SCID
:
311 memcpy(ind
.scid
, nl_itr
.get_data(), ind
.scid_len
);
313 case NAN_EVT_ATTR_SDEA_PARAM_CONFIG_NAN_DATA_PATH
:
314 ind
.peer_sdea_params
.config_nan_data_path
= nl_itr
.get_u8();
316 case NAN_EVT_ATTR_SDEA_PARAM_NDP_TYPE
:
317 ind
.peer_sdea_params
.ndp_type
= (NdpType
)nl_itr
.get_u8();
319 case NAN_EVT_ATTR_SDEA_PARAM_SECURITY_CONFIG
:
320 ind
.peer_sdea_params
.security_cfg
= (NanDataPathSecurityCfgStatus
)nl_itr
.get_u8();
322 case NAN_EVT_ATTR_SDEA_PARAM_RANGE_STATE
:
323 ind
.peer_sdea_params
.ranging_state
= (NanRangingState
)nl_itr
.get_u8();
325 case NAN_EVT_ATTR_SDEA_PARAM_RANGE_REPORT
:
326 ind
.peer_sdea_params
.range_report
= (NanRangeReport
)nl_itr
.get_u8();
328 case NAN_EVT_ATTR_SDEA_PARAM_QOS_CFG
:
329 ind
.peer_sdea_params
.qos_cfg
= (NanQosCfgStatus
)nl_itr
.get_u8();
331 case NAN_EVT_ATTR_RANGE_MEASUREMENT_MM
:
332 ind
.range_info
.range_measurement_mm
= nl_itr
.get_u32();
334 case NAN_EVT_ATTR_RANGEING_EVENT_TYPE
:
335 ind
.range_info
.ranging_event_type
= nl_itr
.get_u32();
340 if (this->callbackEventHandler
.EventMatch
)
341 this->callbackEventHandler
.EventMatch(&ind
);
345 int processMatchExpiredEvent(WifiEvent
&event
) {
346 NanMatchExpiredInd ind
;
347 memset(&ind
,0,sizeof(NanMatchExpiredInd
));
349 for(nl_iterator
nl_itr((struct nlattr
*)event
.get_vendor_data()); nl_itr
.has_next(); nl_itr
.next()) {
350 switch(nl_itr
.get_type()) {
351 case NAN_EVT_ATTR_MATCH_PUBLISH_SUBSCRIBE_ID
:
352 ind
.publish_subscribe_id
= nl_itr
.get_u16();
354 case NAN_EVT_ATTR_MATCH_REQUESTOR_INSTANCE_ID
:
355 ind
.requestor_instance_id
= nl_itr
.get_u32();
358 ALOGE("processMatchExpiredEvent: unknown attribute(%d)", nl_itr
.get_type());
363 if (callbackEventHandler
.EventMatchExpired
)
364 callbackEventHandler
.EventMatchExpired(&ind
);
369 int processPublishTerminatedEvent(WifiEvent
&event
) {
370 NanPublishTerminatedInd ind
;
371 memset(&ind
,0,sizeof(ind
));
373 for(nl_iterator
nl_itr((struct nlattr
*)event
.get_vendor_data()); nl_itr
.has_next(); nl_itr
.next()) {
374 switch(nl_itr
.get_type()) {
375 case NAN_EVT_ATTR_PUBLISH_ID
:
376 ind
.publish_id
= nl_itr
.get_u16();
378 case NAN_EVT_ATTR_PUBLISH_REASON
:
379 ind
.reason
= (NanStatusType
)nl_itr
.get_u32();
382 ALOGE("processPublishTerminatedEvent: unknown attribute(%d)", nl_itr
.get_type());
387 if (callbackEventHandler
.EventPublishTerminated
)
388 callbackEventHandler
.EventPublishTerminated(&ind
);
394 int processSubscribeTerminatedEvent(WifiEvent
&event
) {
395 NanSubscribeTerminatedInd ind
;
396 memset(&ind
,0,sizeof(ind
));
398 for(nl_iterator
nl_itr((struct nlattr
*)event
.get_vendor_data()); nl_itr
.has_next(); nl_itr
.next()) {
399 switch(nl_itr
.get_type()) {
400 case NAN_EVT_ATTR_SUBSCRIBE_ID
:
401 ind
.subscribe_id
= nl_itr
.get_u16();
403 case NAN_EVT_ATTR_SUBSCRIBE_REASON
:
404 ind
.reason
= (NanStatusType
)nl_itr
.get_u32();
407 ALOGE("processSubscribeTerminatedEvent: unknown attribute(%d)", nl_itr
.get_type());
412 if (callbackEventHandler
.EventSubscribeTerminated
)
413 callbackEventHandler
.EventSubscribeTerminated(&ind
);
418 int processFollowupEvent(WifiEvent
&event
) {
420 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
421 memset(&ind
,0,sizeof(ind
));
423 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
424 switch(nl_itr
.get_type()) {
425 case NAN_EVT_ATTR_FOLLOWUP_PUBLISH_SUBSCRIBE_ID
:
426 ind
.publish_subscribe_id
= nl_itr
.get_u16();
428 case NAN_EVT_ATTR_FOLLOWUP_REQUESTOR_INSTANCE_ID
:
429 ind
.requestor_instance_id
= nl_itr
.get_u32();
431 case NAN_EVT_ATTR_FOLLOWUP_ADDR
:
432 memcpy(ind
.addr
, nl_itr
.get_data(), NAN_MAC_ADDR_LEN
);
434 case NAN_EVT_ATTR_FOLLOWUP_DW_OR_FAW
:
435 ind
.dw_or_faw
= nl_itr
.get_u8();
437 case NAN_EVT_ATTR_FOLLOWUP_SERVICE_SPECIFIC_INFO_LEN
:
438 ind
.service_specific_info_len
= nl_itr
.get_u16();
440 case NAN_EVT_ATTR_FOLLOWUP_SERVICE_SPECIFIC_INFO
:
441 memcpy(ind
.service_specific_info
, nl_itr
.get_data(), ind
.service_specific_info_len
);
443 case NAN_EVT_ATTR_SDEA_LEN
:
444 ind
.sdea_service_specific_info_len
= nl_itr
.get_u16();
446 case NAN_EVT_ATTR_SDEA
:
447 memcpy(ind
.sdea_service_specific_info
, nl_itr
.get_data(), ind
.sdea_service_specific_info_len
);
450 ALOGE("processNanDisabledEvent: unknown attribute(%d)", nl_itr
.get_type());
455 if (callbackEventHandler
.EventFollowup
)
456 callbackEventHandler
.EventFollowup(&ind
);
461 int processNanDisabledEvent(WifiEvent
&event
) {
463 memset(&ind
,0,sizeof(ind
));
464 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
465 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
466 switch(nl_itr
.get_type()) {
467 case NAN_EVT_ATTR_DISABLED_REASON
:
468 ind
.reason
= (NanStatusType
)nl_itr
.get_u32();
471 ALOGE("processNanDisabledEvent: unknown attribute(%d)", nl_itr
.get_type());
476 if (callbackEventHandler
.EventDisabled
)
477 callbackEventHandler
.EventDisabled(&ind
);
482 int processNanDiscoveryEvent(WifiEvent
&event
) {
483 NanDiscEngEventInd ind
;
484 memset(&ind
,0,sizeof(ind
));
486 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
487 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
488 switch(nl_itr
.get_type()) {
489 case NAN_EVT_ATTR_DISCOVERY_ENGINE_EVT_TYPE
:
490 ind
.event_type
= (NanDiscEngEventType
)nl_itr
.get_u16();
492 case NAN_EVT_ATTR_DISCOVERY_ENGINE_MAC_ADDR
:
493 addr
= (u8
*)nl_itr
.get_data();
495 case NAN_EVT_ATTR_STATUS
:
498 ALOGE("processNanDiscoveryEvent: unknown attribute(%d)", nl_itr
.get_type());
503 if (ind
.event_type
== NAN_EVENT_ID_DISC_MAC_ADDR
)
504 memcpy(ind
.data
.mac_addr
.addr
, addr
, NAN_MAC_ADDR_LEN
);
506 memcpy(ind
.data
.cluster
.addr
, addr
, NAN_MAC_ADDR_LEN
);
508 ALOGE("processNanDiscoveryEvent: No Mac/cluster Address");
511 if (callbackEventHandler
.EventDiscEngEvent
)
512 callbackEventHandler
.EventDiscEngEvent(&ind
);
517 int processNanFollowupStatus(WifiEvent
&event
) {
518 NanTransmitFollowupInd ind
;
519 memset(&ind
,0,sizeof(ind
));
520 ind
.id
= followupTid
;
522 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
523 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
524 if (nl_itr
.get_type() == NAN_EVT_ATTR_STATUS
) {
525 ind
.reason
= (NanStatusType
)nl_itr
.get_u16();
527 ALOGE("processNanFollowupStatus: unknown attribute(%d)", nl_itr
.get_type());
532 if (callbackEventHandler
.EventTransmitFollowup
)
533 callbackEventHandler
.EventTransmitFollowup(&ind
);
538 int putSdeaParams(NanSdeaCtrlParams
*sdea_params
, WifiRequest
*request
)
542 if (!sdea_params
->config_nan_data_path
)
545 result
= request
->put_u8(NAN_REQ_ATTR_SDEA_PARAM_NDP_TYPE
, sdea_params
->ndp_type
);
546 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put SDEA PARAM ndp_type");
548 result
= request
->put_u8(NAN_REQ_ATTR_SDEA_PARAM_SECURITY_CFG
, sdea_params
->security_cfg
);
549 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put SDEA PARAM security_cfg");
551 result
= request
->put_u8(NAN_REQ_ATTR_SDEA_PARAM_RANGING_STATE
, sdea_params
->ranging_state
);
552 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put SDEA PARAM ranging_state");
554 result
= request
->put_u8(NAN_REQ_ATTR_SDEA_PARAM_RANGE_REPORT
, sdea_params
->range_report
);
555 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put SDEA PARAM range_report");
557 result
= request
->put_u8(NAN_REQ_ATTR_SDEA_PARAM_QOS_CFG
, sdea_params
->qos_cfg
);
558 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put SDEA PARAM qos_cfg");
563 int putRangingCfg(NanRangingCfg
*ranging_cfg
, WifiRequest
*request
)
567 result
= request
->put_u32(NAN_REQ_ATTR_RANGING_CFG_INTERVAL
, ranging_cfg
->ranging_interval_msec
);
568 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put Ranging CFG ranging_interval_msec");
570 result
= request
->put_u32(NAN_REQ_ATTR_RANGING_CFG_INDICATION
, ranging_cfg
->config_ranging_indications
);
571 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put Ranging CFG config_ranging_indications");
573 result
= request
->put_u32(NAN_REQ_ATTR_RANGING_CFG_INGRESS_MM
, ranging_cfg
->distance_ingress_mm
);
574 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put Ranging CFG distance_ingress_mm");
576 result
= request
->put_u32(NAN_REQ_ATTR_RANGING_CFG_EGRESS_MM
, ranging_cfg
->distance_egress_mm
);
577 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put Ranging CFG distance_egress_mm");
582 int putRangeResponseCfg(NanRangeResponseCfg
*range_resp_cfg
, WifiRequest
*request
)
586 result
= request
->put_u16(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_PUBLISH_ID
, range_resp_cfg
->publish_id
);
587 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "Failed to put range response cfg::publish_id");
589 result
= request
->put_u32(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_REQUESTOR_ID
, range_resp_cfg
->requestor_instance_id
);
590 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "Failed to put range response cfg::requestor_instance_id");
592 result
= request
->put_addr(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_PEER_ADDR
, range_resp_cfg
->peer_addr
);
593 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "Failed to put range response cfg::peer_addr");
595 result
= request
->put_u16(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_RANGING_RESPONSE
, range_resp_cfg
->ranging_response
);
596 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "Failed to put range response cfg::ranging_response");
602 NanCommand(wifi_interface_handle iface
, int id
)
603 : WifiCommand(iface
, id
), datacmd()
614 publishCancelTid
= 0;
616 subscribeCancelTid
= 0;
623 memset(&capabilities
, 0, sizeof(capabilities
));
626 int enable(transaction_id id
, NanEnableRequest
*msg
) {
627 ALOGD("NAN enable id:%d", id
);
628 WifiRequest
request(familyId(), ifaceId());
630 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_ENABLE
);
631 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to create WifiRequest");
633 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
635 ALOGE("enable: request.attr_start fail");
636 return WIFI_ERROR_OUT_OF_MEMORY
;
638 /* Valid master pref values are 2-254 */
640 if (msg
->master_pref
< 2)
642 else if (msg
->master_pref
> 254)
645 master_pref
= msg
->master_pref
;
646 result
= request
.put_u8(NAN_REQ_ATTR_MASTER_PREF
, master_pref
);
647 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put master_pref");
649 result
= request
.put_u16(NAN_REQ_ATTR_CLUSTER_LOW
, msg
->cluster_low
);
650 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put cluster_low");
652 result
= request
.put_u16(NAN_REQ_ATTR_CLUSTER_HIGH
, msg
->cluster_high
);
653 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put cluster_high");
655 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_support_5g
, msg
->support_5g_val
,
656 NAN_REQ_ATTR_SUPPORT_5G_VAL
, request
, result
, "enable:Failed to put support_5g_val");
658 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_sid_beacon
, msg
->sid_beacon_val
,
659 NAN_REQ_ATTR_SID_BEACON_VAL
, request
, result
, "enable:Failed to put sid_beacon_val");
661 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_2dot4g_rssi_close
, msg
->rssi_close_2dot4g_val
,
662 NAN_REQ_ATTR_RSSI_CLOSE_2G4_VAL
, request
, result
, "enable:Failed to put rssi_close_2dot4g_val");
664 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_2dot4g_rssi_middle
, msg
->rssi_middle_2dot4g_val
,
665 NAN_REQ_ATTR_RSSI_MIDDLE_2G4_VAL
, request
, result
, "enable:Failed to put rssi_middle_2dot4g_val");
667 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_2dot4g_rssi_proximity
, msg
->rssi_proximity_2dot4g_val
,
668 NAN_REQ_ATTR_RSSI_PROXIMITY_2G4_VAL
, request
, result
, "enable:Failed to put rssi_proximity_2dot4g_val");
670 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_hop_count_limit
, msg
->hop_count_limit_val
,
671 NAN_REQ_ATTR_HOP_COUNT_LIMIT_VAL
, request
, result
, "enable:Failed to put hop_count_limit_val");
673 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_2dot4g_support
, msg
->support_2dot4g_val
,
674 NAN_REQ_ATTR_SUPPORT_2G4_VAL
, request
, result
, "enable:Failed to put support_2dot4g_val");
676 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_2dot4g_beacons
, msg
->beacon_2dot4g_val
,
677 NAN_REQ_ATTR_BEACONS_2G4_VAL
, request
, result
, "enable:Failed to put beacon_2dot4g_val");
679 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_2dot4g_sdf
, msg
->sdf_2dot4g_val
,
680 NAN_REQ_ATTR_SDF_2G4_VAL
, request
, result
, "enable:Failed to put sdf_2dot4g_val");
682 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_5g_beacons
, msg
->beacon_5g_val
,
683 NAN_REQ_ATTR_BEACON_5G_VAL
, request
, result
, "enable:Failed to put beacon_5g_val");
685 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_5g_sdf
, msg
->sdf_5g_val
,
686 NAN_REQ_ATTR_SDF_5G_VAL
, request
, result
, "enable:Failed to put sdf_5g_val");
688 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_5g_rssi_close
, msg
->rssi_close_5g_val
,
689 NAN_REQ_ATTR_RSSI_CLOSE_5G_VAL
, request
, result
, "enable:Failed to put rssi_close_5g_val");
691 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_5g_rssi_middle
, msg
->rssi_middle_5g_val
,
692 NAN_REQ_ATTR_RSSI_MIDDLE_5G_VAL
, request
, result
, "enable:Failed to put rssi_middle_5g_val");
694 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_5g_rssi_close_proximity
, msg
->rssi_close_proximity_5g_val
,
695 NAN_REQ_ATTR_RSSI_CLOSE_PROXIMITY_5G_VAL
, request
, result
, "enable:Failed to put rssi_close_proximity_5g_val");
697 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_rssi_window_size
, msg
->rssi_window_size_val
,
698 NAN_REQ_ATTR_RSSI_WINDOW_SIZE_VAL
, request
, result
, "enable:Failed to put rssi_window_size_val");
700 CHECK_CONFIG_PUT_32_RETURN_FAIL(msg
->config_oui
, msg
->oui_val
,
701 NAN_REQ_ATTR_OUI_VAL
, request
, result
, "enable:Failed to put oui_val");
703 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->config_intf_addr
, msg
->intf_addr_val
, NAN_MAC_ADDR_LEN
,
704 NAN_REQ_ATTR_MAC_ADDR_VAL
, request
, result
, "enable:Failed to put intf_addr_val");
706 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->config_cluster_attribute_val
,
707 NAN_REQ_ATTR_CLUSTER_VAL
, request
, result
, "enable:Failed to put config_cluster_attribute_val");
709 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->config_scan_params
, msg
->scan_params_val
.dwell_time
, sizeof(msg
->scan_params_val
.dwell_time
),
710 NAN_REQ_ATTR_SOCIAL_CH_SCAN_DWELL_TIME
, request
, result
, "enable:Failed to put scan_params_val.dwell_time");
712 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->config_scan_params
, msg
->scan_params_val
.scan_period
, sizeof(msg
->scan_params_val
.scan_period
),
713 NAN_REQ_ATTR_SOCIAL_CH_SCAN_PERIOD
, request
, result
, "enable:Failed to put scan_params_val.scan_period");
715 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_random_factor_force
, msg
->random_factor_force_val
,
716 NAN_REQ_ATTR_RANDOM_FACTOR_FORCE_VAL
, request
, result
, "enable:Failed to put random_factor_force_val");
718 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_hop_count_force
, msg
->hop_count_force_val
,
719 NAN_REQ_ATTR_HOP_COUNT_FORCE_VAL
, request
, result
, "enable:Failed to put hop_count_force_val");
721 CHECK_CONFIG_PUT_32_RETURN_FAIL(msg
->config_24g_channel
, msg
->channel_24g_val
,
722 NAN_REQ_ATTR_CHANNEL_2G4_MHZ_VAL
, request
, result
, "enable:Failed to put channel_24g_val");
724 CHECK_CONFIG_PUT_32_RETURN_FAIL(msg
->config_5g_channel
, msg
->channel_5g_val
,
725 NAN_REQ_ATTR_CHANNEL_5G_MHZ_VAL
, request
, result
, "enable:Failed to put channel_5g_val");
727 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_subscribe_sid_beacon
, msg
->subscribe_sid_beacon_val
,
728 NAN_REQ_ATTR_SUBSCRIBE_SID_BEACON_VAL
, request
, result
, "enable:Failed to put subscribe_sid_beacon_val");
730 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_dw
.config_2dot4g_dw_band
, msg
->config_dw
.dw_2dot4g_interval_val
,
731 NAN_REQ_ATTR_DW_2G4_INTERVAL
, request
, result
, "enable:Failed to put dw_2dot4g_interval_val");
733 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_dw
.config_5g_dw_band
, msg
->config_dw
.dw_5g_interval_val
,
734 NAN_REQ_ATTR_DW_5G_INTERVAL
, request
, result
, "enable:Failed to put dw_5g_interval_val");
736 CHECK_CONFIG_PUT_32_RETURN_FAIL(msg
->config_disc_mac_addr_randomization
, msg
->disc_mac_addr_rand_interval_sec
,
737 NAN_REQ_ATTR_DISC_MAC_ADDR_RANDOM_INTERVAL
, request
, result
, "enable:Failed to put disc_mac_addr_rand_interval_sec");
739 CHECK_CONFIG_PUT_32_RETURN_FAIL(msg
->config_ndpe_attr
, msg
->use_ndpe_attr
,
740 NAN_REQ_ATTR_USE_NDPE_ATTR
, request
, result
, "enable:Failed to put use_ndpe_attr");
742 request
.attr_end(data
);
746 result
= requestResponse(request
);
747 if (result
!= WIFI_SUCCESS
) {
749 ALOGE("failed to NAN; result = %d", result
);
750 unregisterNanEvents();
752 ALOGD("Start NAN...success");
757 int disable(transaction_id id
)
759 ALOGD("NAN disable id:%d", id
);
760 WifiRequest
request(familyId(), ifaceId());
762 unregisterNanEvents();
764 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_DISABLE
);
765 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "disable:Failed to create WifiRequest");
767 result
= requestResponse(request
);
768 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "disable:Failed to requestResponse");
772 int config(transaction_id id
, NanConfigRequest
*msg
) {
773 ALOGD("NAN config id:%d", id
);
774 WifiRequest
request(familyId(), ifaceId());
776 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_CONFIG
);
777 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "config:Failed to create WifiRequest");
779 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
781 ALOGE("config: request.attr_start fail");
782 return WIFI_ERROR_OUT_OF_MEMORY
;
785 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_sid_beacon
, msg
->sid_beacon
,
786 NAN_REQ_ATTR_SID_BEACON_VAL
, request
, result
, "config:Failed to put sid_beacon");
788 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_rssi_proximity
, msg
->rssi_proximity
,
789 NAN_REQ_ATTR_RSSI_PROXIMITY_2G4_VAL
, request
, result
, "config:Failed to put rssi_proximity");
791 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_master_pref
, msg
->master_pref
,
792 NAN_REQ_ATTR_MASTER_PREF
, request
, result
, "config:Failed to put master_pref");
794 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_5g_rssi_close_proximity
, msg
->rssi_close_proximity_5g_val
,
795 NAN_REQ_ATTR_RSSI_CLOSE_PROXIMITY_5G_VAL
, request
, result
, "config:Failed to put rssi_close_proximity_5g_val");
797 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_rssi_window_size
, msg
->rssi_window_size_val
,
798 NAN_REQ_ATTR_RSSI_WINDOW_SIZE_VAL
, request
, result
, "config:Failed to put rssi_window_size_val");
800 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->config_cluster_attribute_val
,
801 NAN_REQ_ATTR_CLUSTER_VAL
, request
, result
, "config:Failed to put config_cluster_attribute_val");
803 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->config_scan_params
, msg
->scan_params_val
.dwell_time
, sizeof(msg
->scan_params_val
.dwell_time
),
804 NAN_REQ_ATTR_SOCIAL_CH_SCAN_DWELL_TIME
, request
, result
, "config:Failed to put scan_params_val.dwell_time");
806 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->config_scan_params
, msg
->scan_params_val
.scan_period
, sizeof(msg
->scan_params_val
.scan_period
),
807 NAN_REQ_ATTR_SOCIAL_CH_SCAN_PERIOD
, request
, result
, "config:Failed to put scan_params_val.scan_period");
809 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_random_factor_force
, msg
->random_factor_force_val
,
810 NAN_REQ_ATTR_RANDOM_FACTOR_FORCE_VAL
, request
, result
, "config:Failed to put random_factor_force_val");
812 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_hop_count_force
, msg
->hop_count_force_val
,
813 NAN_REQ_ATTR_HOP_COUNT_FORCE_VAL
, request
, result
, "config:Failed to put hop_count_force_val");
815 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.payload_transmit_flag
,
816 NAN_REQ_ATTR_CONN_CAPABILITY_PAYLOAD_TX
, request
, result
, "config:Failed to put payload_transmit_flag");
818 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.is_wfd_supported
,
819 NAN_REQ_ATTR_CONN_CAPABILITY_WFD
, request
, result
, "config:Failed to put is_wfd_supported");
821 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.is_wfds_supported
,
822 NAN_REQ_ATTR_CONN_CAPABILITY_WFDS
, request
, result
, "config:Failed to put is_wfds_supported");
824 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.is_tdls_supported
,
825 NAN_REQ_ATTR_CONN_CAPABILITY_TDLS
, request
, result
, "config:Failed to put is_tdls_supported");
827 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.is_ibss_supported
,
828 NAN_REQ_ATTR_CONN_CAPABILITY_IBSS
, request
, result
, "config:Failed to put is_ibss_supported");
830 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.is_mesh_supported
,
831 NAN_REQ_ATTR_CONN_CAPABILITY_MESH
, request
, result
, "config:Failed to put is_mesh_supported");
833 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.wlan_infra_field
,
834 NAN_REQ_ATTR_CONN_CAPABILITY_WLAN_INFRA
, request
, result
, "config:Failed to put wlan_infra_field");
836 if (msg
->num_config_discovery_attr
) {
837 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->num_config_discovery_attr
,
838 NAN_REQ_ATTR_DISCOVERY_ATTR_NUM_ENTRIES
, request
, result
, "config:Failed to put msg->num_config_discovery_attr");
839 for (int i
= 0; i
< msg
->num_config_discovery_attr
; i
++) {
840 nlattr
*nl_disc_attribute
= request
.attr_start(NAN_REQ_ATTR_DISCOVERY_ATTR_VAL
);
841 NanTransmitPostDiscovery
*discovery_attr
= &msg
->discovery_attr_val
[i
];
842 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr
->type
,
843 NAN_REQ_ATTR_CONN_TYPE
, request
, result
, "config:Failed to put discovery_attr->type");
844 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr
->role
,
845 NAN_REQ_ATTR_NAN_ROLE
, request
, result
, "config:Failed to put discovery_attr->role");
846 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr
->transmit_freq
,
847 NAN_REQ_ATTR_TRANSMIT_FREQ
, request
, result
, "config:Failed to put discovery_attr->transmit_freq");
848 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr
->duration
,
849 NAN_REQ_ATTR_AVAILABILITY_DURATION
, request
, result
, "config:Failed to put discovery_attr->duration");
850 CHECK_CONFIG_PUT_32_RETURN_FAIL(1, discovery_attr
->avail_interval_bitmap
,
851 NAN_REQ_ATTR_AVAILABILITY_INTERVAL
, request
, result
, "config:Failed to put discovery_attr->avail_interval_bitmap");
852 CHECK_CONFIG_PUT_RETURN_FAIL(1, discovery_attr
->addr
, NAN_MAC_ADDR_LEN
,
853 NAN_REQ_ATTR_MAC_ADDR_VAL
, request
, result
, "config:Failed to put discovery_attr->addr");
854 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, discovery_attr
->mesh_id_len
,
855 NAN_REQ_ATTR_MESH_ID_LEN
, request
, result
, "config:Failed to put discovery_attr->mesh_id");
856 CHECK_CONFIG_PUT_RETURN_FAIL(discovery_attr
->mesh_id_len
, discovery_attr
->mesh_id
, discovery_attr
->mesh_id_len
,
857 NAN_REQ_ATTR_MESH_ID
, request
, result
, "config:Failed to put discovery_attr->mesh_id");
858 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, discovery_attr
->infrastructure_ssid_len
,
859 NAN_REQ_ATTR_INFRASTRUCTURE_SSID_LEN
, request
, result
, "config:Failed to put discovery_attr->infrastructure_ssid_val");
860 CHECK_CONFIG_PUT_RETURN_FAIL(discovery_attr
->infrastructure_ssid_len
, discovery_attr
->infrastructure_ssid_val
, discovery_attr
->infrastructure_ssid_len
,
861 NAN_REQ_ATTR_INFRASTRUCTURE_SSID
, request
, result
, "config:Failed to put discovery_attr->infrastructure_ssid_val");
862 request
.attr_end(nl_disc_attribute
);
866 if (msg
->config_fam
) {
867 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->fam_val
.numchans
,
868 NAN_REQ_ATTR_FURTHER_AVAIL_NUM_ENTRIES
, request
, result
, "config:Failed to put msg->fam_val.numchans");
869 for (int i
= 0; i
< msg
->fam_val
.numchans
; i
++) {
870 nlattr
*nl_fam_attribute
= request
.attr_start(NAN_REQ_ATTR_FURTHER_AVAIL_VAL
);
871 NanFurtherAvailabilityChannel
*further_avail_chan
= &msg
->fam_val
.famchan
[i
];
872 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan
->entry_control
,
873 NAN_REQ_ATTR_FURTHER_AVAIL_ENTRY_CTRL
, request
, result
, "config:Failed to put further_avail_chan->entry_control");
874 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan
->class_val
,
875 NAN_REQ_ATTR_FURTHER_AVAIL_CHAN_CLASS
, request
, result
, "config:Failed to put further_avail_chan->class_val");
876 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan
->channel
,
877 NAN_REQ_ATTR_FURTHER_AVAIL_CHAN
, request
, result
, "config:Failed to put further_avail_chan->channel");
878 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan
->mapid
,
879 NAN_REQ_ATTR_FURTHER_AVAIL_CHAN_MAPID
, request
, result
, "config:Failed to put further_avail_chan->mapid");
880 CHECK_CONFIG_PUT_32_RETURN_FAIL(1, further_avail_chan
->avail_interval_bitmap
,
881 NAN_REQ_ATTR_FURTHER_AVAIL_INTERVAL_BITMAP
, request
, result
, "config:Failed to put further_avail_chan->avail_interval_bitmap");
882 request
.attr_end(nl_fam_attribute
);
886 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_subscribe_sid_beacon
, msg
->subscribe_sid_beacon_val
,
887 NAN_REQ_ATTR_SUBSCRIBE_SID_BEACON_VAL
, request
, result
, "config:Failed to put subscribe_sid_beacon_val");
889 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_dw
.config_2dot4g_dw_band
, msg
->config_dw
.dw_2dot4g_interval_val
,
890 NAN_REQ_ATTR_DW_2G4_INTERVAL
, request
, result
, "config:Failed to put dw_2dot4g_interval_val");
892 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_dw
.config_5g_dw_band
, msg
->config_dw
.dw_5g_interval_val
,
893 NAN_REQ_ATTR_DW_5G_INTERVAL
, request
, result
, "config:Failed to put dw_5g_interval_val");
895 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_disc_mac_addr_randomization
, msg
->disc_mac_addr_rand_interval_sec
,
896 NAN_REQ_ATTR_DISC_MAC_ADDR_RANDOM_INTERVAL
, request
, result
, "config:Failed to put disc_mac_addr_rand_interval_sec");
898 CHECK_CONFIG_PUT_32_RETURN_FAIL(msg
->config_ndpe_attr
, msg
->use_ndpe_attr
,
899 NAN_REQ_ATTR_USE_NDPE_ATTR
, request
, result
, "enable:Failed to put use_ndpe_attr");
901 request
.attr_end(data
);
903 result
= requestResponse(request
);
904 if (result
!= WIFI_SUCCESS
) {
906 ALOGE("failed to set_config; result = %d", result
);
908 ALOGD("NAN config...success");
913 static int setCallbackHandler(NanCallbackHandler handlers
) {
914 callbackEventHandler
= handlers
;
918 static int getVersion(NanVersion
*version
) {
919 *version
= SLSI_WIFI_HAL_NAN_VERSION
;
923 int publish(transaction_id id
, NanPublishRequest
*msg
) {
924 ALOGD("NAN publish transId:%d publishId:%d publishType:%d", id
, msg
->publish_id
, msg
->publish_type
);
925 WifiRequest
request(familyId(), ifaceId());
927 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_PUBLISH
);
928 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "publish:Failed to create WifiRequest");
930 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
932 ALOGE("publish: request.attr_start fail");
933 return WIFI_ERROR_OUT_OF_MEMORY
;
936 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->publish_id
, msg
->publish_id
,
937 NAN_REQ_ATTR_PUBLISH_ID
, request
, result
, "publish:Failed to put msg->publish_id");
939 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->ttl
, msg
->ttl
,
940 NAN_REQ_ATTR_PUBLISH_TTL
, request
, result
, "publish:Failed to put msg->ttl");
942 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->period
,
943 NAN_REQ_ATTR_PUBLISH_PERIOD
, request
, result
, "publish:Failed to put msg->period");
945 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->publish_type
,
946 NAN_REQ_ATTR_PUBLISH_TYPE
, request
, result
, "publish:Failed to put msg->publish_type");
948 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->tx_type
,
949 NAN_REQ_ATTR_PUBLISH_TX_TYPE
, request
, result
, "publish:Failed to put msg->tx_type");
951 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->publish_count
,
952 NAN_REQ_ATTR_PUBLISH_COUNT
, request
, result
, "publish:Failed to put msg->publish_count");
954 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->service_name_len
, msg
->service_name_len
,
955 NAN_REQ_ATTR_PUBLISH_SERVICE_NAME_LEN
, request
, result
, "publish:Failed to put msg->service_name_len");
957 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->service_name_len
, msg
->service_name
, msg
->service_name_len
,
958 NAN_REQ_ATTR_PUBLISH_SERVICE_NAME
, request
, result
, "publish:Failed to put msg->service_name");
960 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->publish_match_indicator
,
961 NAN_REQ_ATTR_PUBLISH_MATCH_ALGO
, request
, result
, "publish:Failed to put msg->publish_match_indicator");
963 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->service_specific_info_len
, msg
->service_specific_info_len
,
964 NAN_REQ_ATTR_PUBLISH_SERVICE_INFO_LEN
, request
, result
, "publish:Failed to put msg->service_specific_info_len");
966 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->service_specific_info_len
, msg
->service_specific_info
, msg
->service_specific_info_len
,
967 NAN_REQ_ATTR_PUBLISH_SERVICE_INFO
, request
, result
, "publish:Failed to put msg->service_specific_info");
969 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->rx_match_filter_len
, msg
->rx_match_filter_len
,
970 NAN_REQ_ATTR_PUBLISH_RX_MATCH_FILTER_LEN
, request
, result
, "publish:Failed to put msg->rx_match_filter_len");
972 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->rx_match_filter_len
, msg
->rx_match_filter
, msg
->rx_match_filter_len
,
973 NAN_REQ_ATTR_PUBLISH_RX_MATCH_FILTER
, request
, result
, "publish:Failed to put msg->rx_match_filter");
975 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->tx_match_filter_len
, msg
->tx_match_filter_len
,
976 NAN_REQ_ATTR_PUBLISH_TX_MATCH_FILTER_LEN
, request
, result
, "publish:Failed to put msg->tx_match_filter_len");
978 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->tx_match_filter_len
, msg
->tx_match_filter
, msg
->tx_match_filter_len
,
979 NAN_REQ_ATTR_PUBLISH_TX_MATCH_FILTER
, request
, result
, "publish:Failed to put msg->tx_match_filter");
981 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->rssi_threshold_flag
,
982 NAN_REQ_ATTR_PUBLISH_RSSI_THRESHOLD_FLAG
, request
, result
, "publish:Failed to put msg->rssi_threshold_flag");
984 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->connmap
,
985 NAN_REQ_ATTR_PUBLISH_CONN_MAP
, request
, result
, "publish:Failed to put msg->connmap");
987 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->recv_indication_cfg
,
988 NAN_REQ_ATTR_PUBLISH_RECV_IND_CFG
, request
, result
, "publish:Failed to put msg->recv_indication_cfg");
990 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->sdea_service_specific_info_len
,
991 NAN_REQ_ATTR_PUBLISH_SDEA_LEN
, request
, result
, "publish:Failed to put msg->sdea_service_specific_info_len");
993 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->sdea_service_specific_info_len
, msg
->sdea_service_specific_info
, msg
->sdea_service_specific_info_len
,
994 NAN_REQ_ATTR_PUBLISH_SDEA
, request
, result
, "publish:Failed to put msg->sdea_service_specific_info");
996 result
= request
.put_u8(NAN_REQ_ATTR_RANGING_AUTO_RESPONSE
, msg
->ranging_auto_response
);
997 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put ranging_auto_response");
999 result
= putSdeaParams(&msg
->sdea_params
, &request
);
1002 result
= putRangingCfg(&msg
->ranging_cfg
, &request
);
1005 result
= NanDataCommand::putSecurityInfo(msg
->cipher_type
, &msg
->key_info
, msg
->scid_len
, msg
->scid
, &request
);
1008 result
= putRangeResponseCfg(&msg
->range_response_cfg
, &request
);
1012 request
.attr_end(data
);
1014 result
= requestResponse(request
);
1015 if (result
!= WIFI_SUCCESS
) {
1017 ALOGE("failed to publish; result = %d", result
);
1019 ALOGD("NAN publish...success");
1024 int publishCancel(transaction_id id
, NanPublishCancelRequest
*msg
) {
1025 ALOGD("NAN publishCancel transId:%d, publish_id:%d", id
, msg
->publish_id
);
1026 WifiRequest
request(familyId(), ifaceId());
1028 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_PUBLISHCANCEL
);
1029 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "publishCancel:Failed to create WifiRequest");
1031 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
1033 ALOGE("publishCancel: request.attr_start fail");
1034 return WIFI_ERROR_OUT_OF_MEMORY
;
1037 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->publish_id
,
1038 NAN_REQ_ATTR_PUBLISH_ID
, request
, result
, "publishCancel:Failed to put msg->publish_id");
1040 request
.attr_end(data
);
1041 publishCancelTid
= id
;
1042 result
= requestResponse(request
);
1043 if (result
!= WIFI_SUCCESS
) {
1044 publishCancelTid
= 0;
1045 ALOGE("failed to publishCancel; result = %d", result
);
1047 ALOGD("NAN publishCancel...success");
1053 int subscribe(transaction_id id
, NanSubscribeRequest
*msg
) {
1054 ALOGD("NAN subscribe trans_id:%d subscribe_id:%d subscribetype:%d", id
, msg
->subscribe_id
, msg
->subscribe_type
);
1055 WifiRequest
request(familyId(), ifaceId());
1057 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_SUBSCRIBE
);
1058 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "subscribe:Failed to create WifiRequest");
1060 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
1062 ALOGE("subscribe: request.attr_start fail");
1063 return WIFI_ERROR_OUT_OF_MEMORY
;
1066 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->subscribe_id
, msg
->subscribe_id
,
1067 NAN_REQ_ATTR_SUBSCRIBE_ID
, request
, result
, "subscribe:Failed to put msg->publish_id");
1069 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->ttl
,
1070 NAN_REQ_ATTR_SUBSCRIBE_TTL
, request
, result
, "subscribe:Failed to put msg->ttl");
1072 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->period
,
1073 NAN_REQ_ATTR_SUBSCRIBE_PERIOD
, request
, result
, "subscribe:Failed to put msg->period");
1075 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->subscribe_type
,
1076 NAN_REQ_ATTR_SUBSCRIBE_TYPE
, request
, result
, "subscribe:Failed to put msg->subscribe_type");
1078 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->serviceResponseFilter
,
1079 NAN_REQ_ATTR_SUBSCRIBE_RESP_FILTER_TYPE
, request
, result
, "subscribe:Failed to put msg->serviceResponseFilter");
1081 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->serviceResponseInclude
,
1082 NAN_REQ_ATTR_SUBSCRIBE_RESP_INCLUDE
, request
, result
, "subscribe:Failed to put msg->serviceResponseInclude");
1084 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->useServiceResponseFilter
,
1085 NAN_REQ_ATTR_SUBSCRIBE_USE_RESP_FILTER
, request
, result
, "subscribe:Failed to put msg->useServiceResponseFilter");
1087 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->ssiRequiredForMatchIndication
,
1088 NAN_REQ_ATTR_SUBSCRIBE_SSI_REQUIRED
, request
, result
, "subscribe:Failed to put msg->ssiRequiredForMatchIndication");
1090 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->subscribe_match_indicator
,
1091 NAN_REQ_ATTR_SUBSCRIBE_MATCH_INDICATOR
, request
, result
, "subscribe:Failed to put msg->subscribe_match_indicator");
1093 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->subscribe_count
,
1094 NAN_REQ_ATTR_SUBSCRIBE_COUNT
, request
, result
, "subscribe:Failed to put msg->subscribe_count");
1096 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->service_name_len
, msg
->service_name_len
,
1097 NAN_REQ_ATTR_SUBSCRIBE_SERVICE_NAME_LEN
, request
, result
, "subscribe:Failed to put msg->service_name_len");
1099 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->service_name_len
, msg
->service_name
, msg
->service_name_len
,
1100 NAN_REQ_ATTR_SUBSCRIBE_SERVICE_NAME
, request
, result
, "subscribe:Failed to put msg->service_name");
1102 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->service_specific_info_len
, msg
->service_specific_info_len
,
1103 NAN_REQ_ATTR_SUBSCRIBE_SERVICE_INFO_LEN
, request
, result
, "subscribe:Failed to put msg->service_specific_info_len");
1105 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->service_specific_info_len
, msg
->service_specific_info
, msg
->service_specific_info_len
,
1106 NAN_REQ_ATTR_SUBSCRIBE_SERVICE_INFO
, request
, result
, "subscribe:Failed to put msg->service_specific_info");
1108 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->rx_match_filter_len
, msg
->rx_match_filter_len
,
1109 NAN_REQ_ATTR_SUBSCRIBE_RX_MATCH_FILTER_LEN
, request
, result
, "subscribe:Failed to put msg->rx_match_filter_len");
1111 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->rx_match_filter_len
, msg
->rx_match_filter
, msg
->rx_match_filter_len
,
1112 NAN_REQ_ATTR_SUBSCRIBE_RX_MATCH_FILTER
, request
, result
, "subscribe:Failed to put msg->rx_match_filter");
1114 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->tx_match_filter_len
, msg
->tx_match_filter_len
,
1115 NAN_REQ_ATTR_SUBSCRIBE_TX_MATCH_FILTER_LEN
, request
, result
, "subscribe:Failed to put msg->tx_match_filter_len");
1117 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->tx_match_filter_len
, msg
->tx_match_filter
, msg
->tx_match_filter_len
,
1118 NAN_REQ_ATTR_SUBSCRIBE_TX_MATCH_FILTER
, request
, result
, "subscribe:Failed to put msg->tx_match_filter");
1120 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->rssi_threshold_flag
,
1121 NAN_REQ_ATTR_SUBSCRIBE_RSSI_THRESHOLD_FLAG
, request
, result
, "subscribe:Failed to put msg->rssi_threshold_flag");
1123 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->connmap
,
1124 NAN_REQ_ATTR_SUBSCRIBE_CONN_MAP
, request
, result
, "subscribe:Failed to put msg->connmap");
1126 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->num_intf_addr_present
, msg
->num_intf_addr_present
,
1127 NAN_REQ_ATTR_SUBSCRIBE_NUM_INTF_ADDR_PRESENT
, request
, result
, "subscribe:Failed to put msg->num_intf_addr_present");
1129 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->num_intf_addr_present
, msg
->intf_addr
, NAN_MAC_ADDR_LEN
* msg
->num_intf_addr_present
,
1130 NAN_REQ_ATTR_SUBSCRIBE_INTF_ADDR
, request
, result
, "subscribe:Failed to put msg->intf_addr");
1132 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->recv_indication_cfg
,
1133 NAN_REQ_ATTR_SUBSCRIBE_RECV_IND_CFG
, request
, result
, "subscribe:Failed to put msg->recv_indication_cfg");
1135 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->sdea_service_specific_info_len
,
1136 NAN_REQ_ATTR_PUBLISH_SDEA_LEN
, request
, result
, "subscribe:Failed to put msg->sdea_service_specific_info_len");
1138 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->sdea_service_specific_info_len
, msg
->sdea_service_specific_info
, msg
->sdea_service_specific_info_len
,
1139 NAN_REQ_ATTR_PUBLISH_SDEA
, request
, result
, "subscribe:Failed to put msg->sdea_service_specific_info");
1141 result
= request
.put_u8(NAN_REQ_ATTR_RANGING_AUTO_RESPONSE
, msg
->ranging_auto_response
);
1142 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put ranging_auto_response");
1144 result
= putSdeaParams(&msg
->sdea_params
, &request
);
1147 result
= putRangingCfg(&msg
->ranging_cfg
, &request
);
1150 result
= NanDataCommand::putSecurityInfo(msg
->cipher_type
, &msg
->key_info
, msg
->scid_len
, msg
->scid
, &request
);
1153 result
= putRangeResponseCfg(&msg
->range_response_cfg
, &request
);
1157 request
.attr_end(data
);
1159 result
= requestResponse(request
);
1160 if (result
!= WIFI_SUCCESS
) {
1162 ALOGE("failed to subscribe; result = %d", result
);
1164 ALOGD("NAN subscribe...success");
1170 int subscribeCancel(transaction_id id
, NanSubscribeCancelRequest
*msg
) {
1171 ALOGD("NAN subscribeCancel transId:%d subscribeId:%d", id
, msg
->subscribe_id
);
1172 WifiRequest
request(familyId(), ifaceId());
1174 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_SUBSCRIBECANCEL
);
1175 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "subscribeCancel:Failed to create WifiRequest");
1177 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
1179 ALOGE("subscribeCancel: request.attr_start fail");
1180 return WIFI_ERROR_OUT_OF_MEMORY
;
1183 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->subscribe_id
,
1184 NAN_REQ_ATTR_SUBSCRIBE_ID
, request
, result
, "subscribeCancel:Failed to put msg->subscribe_id");
1186 request
.attr_end(data
);
1187 subscribeCancelTid
= id
;
1188 result
= requestResponse(request
);
1189 if (result
!= WIFI_SUCCESS
) {
1190 subscribeCancelTid
= 0;
1191 ALOGE("failed to subscribeCancel; result = %d", result
);
1193 ALOGD("NAN subscribeCancel...success");
1198 int followup(transaction_id id
, NanTransmitFollowupRequest
*msg
) {
1199 ALOGD("NAN followup transid:%d pub/subId:%d reqInstId:%d", id
, msg
->publish_subscribe_id
, msg
->requestor_instance_id
);
1200 WifiRequest
request(familyId(), ifaceId());
1202 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_TXFOLLOWUP
);
1203 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "followup:Failed to create WifiRequest");
1205 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
1207 ALOGE("followup: request.attr_start fail");
1208 return WIFI_ERROR_OUT_OF_MEMORY
;
1211 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->publish_subscribe_id
,
1212 NAN_REQ_ATTR_FOLLOWUP_ID
, request
, result
, "followup:Failed to put msg->publish_subscribe_id");
1214 CHECK_CONFIG_PUT_32_RETURN_FAIL(1, msg
->requestor_instance_id
,
1215 NAN_REQ_ATTR_FOLLOWUP_REQUESTOR_ID
, request
, result
, "followup:Failed to put msg->requestor_instance_id");
1217 CHECK_CONFIG_PUT_RETURN_FAIL(1, msg
->addr
, NAN_MAC_ADDR_LEN
,
1218 NAN_REQ_ATTR_FOLLOWUP_ADDR
, request
, result
, "followup:Failed to put msg->addr");
1220 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->priority
,
1221 NAN_REQ_ATTR_FOLLOWUP_PRIORITY
, request
, result
, "followup:Failed to put msg->priority");
1223 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->dw_or_faw
,
1224 NAN_REQ_ATTR_FOLLOWUP_TX_WINDOW
, request
, result
, "followup:Failed to put msg->dw_or_faw");
1226 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->service_specific_info_len
, msg
->service_specific_info_len
,
1227 NAN_REQ_ATTR_FOLLOWUP_SERVICE_NAME_LEN
, request
, result
, "followup:Failed to put msg->service_specific_info_len");
1229 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->service_specific_info_len
, msg
->service_specific_info
, msg
->service_specific_info_len
,
1230 NAN_REQ_ATTR_FOLLOWUP_SERVICE_NAME
, request
, result
, "followup:Failed to put msg->service_specific_info");
1232 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->recv_indication_cfg
,
1233 NAN_REQ_ATTR_FOLLOWUP_RECV_IND_CFG
, request
, result
, "followup:Failed to put msg->recv_indication_cfg");
1235 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->sdea_service_specific_info_len
,
1236 NAN_REQ_ATTR_PUBLISH_SDEA_LEN
, request
, result
, "publish:Failed to put msg->sdea_service_specific_info_len");
1238 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->sdea_service_specific_info_len
, msg
->sdea_service_specific_info
, msg
->sdea_service_specific_info_len
,
1239 NAN_REQ_ATTR_PUBLISH_SDEA
, request
, result
, "publish:Failed to put msg->sdea_service_specific_info");
1241 request
.attr_end(data
);
1243 result
= requestResponse(request
);
1244 if (result
!= WIFI_SUCCESS
) {
1246 ALOGE("failed to followup; result = %d", result
);
1248 ALOGD("NAN followup...success");
1254 int getCapabilities(transaction_id id
) {
1255 ALOGD("NAN getCapabilities transId:%d", id
);
1256 WifiRequest
request(familyId(), ifaceId());
1258 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_CAPABILITIES
);
1259 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "getCapabilities:Failed to create WifiRequest");
1261 capabilitiesTid
= id
;
1262 result
= requestResponse(request
);
1263 if (result
!= WIFI_SUCCESS
) {
1264 capabilitiesTid
= 0;
1265 ALOGE("failed to getCapabilities; result = %d", result
);
1267 ALOGD("NAN getCapabilities...success");
1272 int handleEvent(WifiEvent
&event
) {
1275 if (event
.get_cmd() != NL80211_CMD_VENDOR
) {
1276 ALOGD("NAN %s Ignoring event with cmd = %d", __func__
, event
.get_cmd());
1280 int id
= event
.get_vendor_id();
1281 int subcmd
= event
.get_vendor_subcmd();
1283 ALOGI("NAN %s Id = %0x, subcmd = %d", __func__
, id
, subcmd
);
1286 case SLSI_NAN_EVENT_MATCH
:
1287 ret
= processMatchEvent(event
);
1289 case SLSI_NAN_EVENT_MATCH_EXPIRED
:
1290 ret
= processMatchExpiredEvent(event
);
1292 case SLSI_NAN_EVENT_PUBLISH_TERMINATED
:
1293 ret
= processPublishTerminatedEvent(event
);
1295 case SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED
:
1296 ret
= processSubscribeTerminatedEvent(event
);
1298 case SLSI_NAN_EVENT_FOLLOWUP
:
1299 ret
= processFollowupEvent(event
);
1301 case SLSI_NAN_EVENT_DISABLED
:
1302 ret
= processNanDisabledEvent(event
);
1304 case SLSI_NAN_EVENT_DISCOVERY_ENGINE
:
1305 ret
= processNanDiscoveryEvent(event
);
1307 case SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS
:
1308 ret
= processNanFollowupStatus(event
);
1311 return datacmd
.handleEvent(event
, callbackEventHandler
);
1317 int handleResponse(WifiEvent
&reply
) {
1318 if (reply
.get_cmd() != NL80211_CMD_VENDOR
) {
1319 ALOGD("NAN %s Ignoring reply with cmd = %d", __func__
, reply
.get_cmd());
1323 NanResponseMsg response
;
1324 memset(&response
, 0, sizeof(response
));
1326 if (processResponse(reply
, &response
) == NL_SKIP
)
1329 transaction_id id
= 0;
1330 switch ((int)response
.response_type
) {
1331 case NAN_RESPONSE_PUBLISH
:
1335 case NAN_RESPONSE_ENABLED
:
1339 case NAN_RESPONSE_DISABLED
:
1343 case NAN_RESPONSE_PUBLISH_CANCEL
:
1344 id
= publishCancelTid
;
1345 publishCancelTid
= 0;
1347 case NAN_RESPONSE_SUBSCRIBE_CANCEL
:
1348 id
= subscribeCancelTid
;
1349 subscribeCancelTid
= 0;
1351 case NAN_RESPONSE_CONFIG
:
1355 case NAN_GET_CAPABILITIES
:
1356 id
= capabilitiesTid
;
1357 capabilitiesTid
= 0;
1359 case NAN_RESPONSE_SUBSCRIBE
:
1363 case NAN_RESPONSE_TRANSMIT_FOLLOWUP
:
1365 /* followupTid is required on receiving followup_up transmit status.
1366 * Do not reset followupTid here*/
1369 id
= datacmd
.getResponseTransactionId(&response
);
1371 ALOGD("NAN %s transId:%d status:%d, response:%d", __func__
, id
, response
.status
, response
.response_type
);
1372 if (callbackEventHandler
.NotifyResponse
)
1373 callbackEventHandler
.NotifyResponse(id
, &response
);
1377 int dataPathReq(u16 id
, void *data
, int subcmd
) {
1379 WifiRequest
request(familyId(), ifaceId());
1381 ALOGI("NAN DATA-PATH req subcmd:%d transaction_id:%d", subcmd
, id
);
1383 result
= datacmd
.getDataPathNLMsg(id
, data
, subcmd
, request
);
1384 if (result
!= WIFI_SUCCESS
) {
1387 result
= requestResponse(request
);
1388 if (result
!= WIFI_SUCCESS
) {
1389 ALOGE("failed DATA-PATH req; result = %d", result
);
1390 unregisterNanEvents();
1392 datacmd
.requestSuccess(id
, data
, subcmd
);
1393 ALOGD("NAN DATA-PATH req(subcmd:%d)...success", subcmd
);
1399 NanCallbackHandler
NanCommand::callbackEventHandler
;
1401 NanCommand
*nan_get_object(transaction_id id
,
1402 wifi_interface_handle iface
) {
1403 wifi_handle handle
= getWifiHandle(iface
);
1404 NanCommand
*nanRequest
= (NanCommand
*)wifi_get_nan_cmd(handle
);
1406 nanRequest
= new NanCommand(iface
, id
);
1408 ALOGE("Could not alloc NanCommand");
1415 wifi_error
nan_enable_request(transaction_id id
,
1416 wifi_interface_handle iface
,
1417 NanEnableRequest
*msg
) {
1418 wifi_handle handle
= getWifiHandle(iface
);
1421 NanCommand
*nanRequest
= new NanCommand(iface
, id
);
1423 ALOGE("nan_enable_request:: Unable to create NanCommand");
1424 return WIFI_ERROR_OUT_OF_MEMORY
;
1427 wifi_set_nan_cmd(handle
, nanRequest
);
1428 ret
= (wifi_error
)nanRequest
->enable(id
, msg
);
1429 if (ret
!= WIFI_SUCCESS
) {
1430 wifi_reset_nan_cmd(handle
);
1436 /* Disable NAN functionality. */
1437 wifi_error
nan_disable_request(transaction_id id
, wifi_interface_handle iface
) {
1438 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1442 return WIFI_ERROR_OUT_OF_MEMORY
;
1444 ret
= (wifi_error
)nanRequest
->disable(id
);
1445 wifi_reset_nan_cmd(getWifiHandle(iface
));
1450 /* Publish request to advertize a service. */
1451 wifi_error
nan_publish_request(transaction_id id
,
1452 wifi_interface_handle iface
,
1453 NanPublishRequest
*msg
) {
1454 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1456 return WIFI_ERROR_OUT_OF_MEMORY
;
1458 return (wifi_error
)nanRequest
->publish(id
, msg
);
1461 /* Cancel previous publish requests. */
1462 wifi_error
nan_publish_cancel_request(transaction_id id
,
1463 wifi_interface_handle iface
,
1464 NanPublishCancelRequest
*msg
) {
1465 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1467 return WIFI_ERROR_OUT_OF_MEMORY
;
1469 return (wifi_error
)nanRequest
->publishCancel(id
, msg
);
1472 /* Subscribe request to search for a service. */
1473 wifi_error
nan_subscribe_request(transaction_id id
,
1474 wifi_interface_handle iface
,
1475 NanSubscribeRequest
*msg
) {
1476 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1478 return WIFI_ERROR_OUT_OF_MEMORY
;
1480 return (wifi_error
)nanRequest
->subscribe(id
, msg
);
1483 /* Cancel previous subscribe requests. */
1484 wifi_error
nan_subscribe_cancel_request(transaction_id id
,
1485 wifi_interface_handle iface
,
1486 NanSubscribeCancelRequest
*msg
) {
1487 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1489 return WIFI_ERROR_OUT_OF_MEMORY
;
1491 return (wifi_error
)nanRequest
->subscribeCancel(id
, msg
);
1494 /* NAN transmit follow up request. */
1495 wifi_error
nan_transmit_followup_request(transaction_id id
,
1496 wifi_interface_handle iface
,
1497 NanTransmitFollowupRequest
*msg
) {
1498 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1500 return WIFI_ERROR_OUT_OF_MEMORY
;
1502 return (wifi_error
)nanRequest
->followup(id
, msg
);
1505 /* NAN configuration request. */
1506 wifi_error
nan_config_request(transaction_id id
,
1507 wifi_interface_handle iface
,
1508 NanConfigRequest
*msg
) {
1509 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1511 return WIFI_ERROR_OUT_OF_MEMORY
;
1513 return (wifi_error
)nanRequest
->config(id
, msg
);
1516 /* Register NAN callbacks. */
1517 wifi_error
nan_register_handler(wifi_interface_handle iface
,
1518 NanCallbackHandler handlers
) {
1519 return (wifi_error
)NanCommand::setCallbackHandler(handlers
);
1522 /* Get NAN HAL version. */
1523 wifi_error
nan_get_version(wifi_handle handle
,
1524 NanVersion
*version
) {
1525 return (wifi_error
)NanCommand::getVersion(version
);
1528 /* Get NAN capabilities. */
1529 wifi_error
nan_get_capabilities(transaction_id id
,
1530 wifi_interface_handle iface
) {
1531 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1533 return WIFI_ERROR_OUT_OF_MEMORY
;
1535 return (wifi_error
)nanRequest
->getCapabilities(id
);
1538 wifi_error
nan_data_interface_create(transaction_id id
,
1539 wifi_interface_handle iface
,
1541 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1543 return WIFI_ERROR_OUT_OF_MEMORY
;
1545 return (wifi_error
)nanRequest
->dataPathReq(id
, iface_name
,
1546 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_INTERFACE_CREATE
);
1549 wifi_error
nan_data_interface_delete(transaction_id id
,
1550 wifi_interface_handle iface
,
1552 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1554 return WIFI_ERROR_OUT_OF_MEMORY
;
1556 return (wifi_error
)nanRequest
->dataPathReq(id
, iface_name
,
1557 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_INTERFACE_DELETE
);
1561 wifi_error
nan_data_request_initiator(transaction_id id
,
1562 wifi_interface_handle iface
,
1563 NanDataPathInitiatorRequest
* msg
) {
1564 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1566 return WIFI_ERROR_OUT_OF_MEMORY
;
1568 return (wifi_error
)nanRequest
->dataPathReq(id
, msg
,
1569 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_REQUEST_INITIATOR
);
1573 wifi_error
nan_data_indication_response(transaction_id id
,
1574 wifi_interface_handle iface
,
1575 NanDataPathIndicationResponse
* msg
) {
1576 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1578 return WIFI_ERROR_OUT_OF_MEMORY
;
1580 return (wifi_error
)nanRequest
->dataPathReq(id
, msg
,
1581 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_INDICATION_RESPONSE
);
1585 wifi_error
nan_data_end(transaction_id id
,
1586 wifi_interface_handle iface
,
1587 NanDataPathEndRequest
* msg
) {
1588 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1590 return WIFI_ERROR_OUT_OF_MEMORY
;
1592 return (wifi_error
)nanRequest
->dataPathReq(id
, msg
,
1593 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_END
);