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 static const u8
*getEventName(int event
) {
77 case SLSI_NAN_EVENT_RESPONSE
:
78 return (const u8
*)"SLSI_NAN_EVENT_RESPONSE";
79 case SLSI_NAN_EVENT_PUBLISH_TERMINATED
:
80 return (const u8
*)"SLSI_NAN_EVENT_PUBLISH_TERMINATED";
81 case SLSI_NAN_EVENT_MATCH
:
82 return (const u8
*)"SLSI_NAN_EVENT_MATCH";
83 case SLSI_NAN_EVENT_MATCH_EXPIRED
:
84 return (const u8
*)"SLSI_NAN_EVENT_MATCH_EXPIRED";
85 case SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED
:
86 return (const u8
*)"SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED";
87 case SLSI_NAN_EVENT_FOLLOWUP
:
88 return (const u8
*)"SLSI_NAN_EVENT_FOLLOWUP";
89 case SLSI_NAN_EVENT_DISCOVERY_ENGINE
:
90 return (const u8
*)"SLSI_NAN_EVENT_DISCOVERY_ENGINE";
91 case SLSI_NAN_EVENT_DISABLED
:
92 return (const u8
*)"SLSI_NAN_EVENT_DISABLED";
93 case SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS
:
94 return (const u8
*)"SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS";
95 case SLSI_NAN_EVENT_NDP_REQ
:
96 return (const u8
*)"SLSI_NAN_EVENT_NDP_REQ";
97 case SLSI_NAN_EVENT_NDP_CFM
:
98 return (const u8
*)"SLSI_NAN_EVENT_NDP_CFM";
99 case SLSI_NAN_EVENT_NDP_END
:
100 return (const u8
*)"SLSI_NAN_EVENT_NDP_END";
102 return (const u8
*)"UNKNOWN event";
104 return (const u8
*)"UNKNOWN event";
107 int processResponse(WifiEvent
&reply
, NanResponseMsg
*response
) {
108 NanCapabilities
*capabilities
= &response
->body
.nan_capabilities
;
109 nlattr
*vendor_data
= reply
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
112 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
113 switch(nl_itr
.get_type()) {
114 case NAN_REPLY_ATTR_STATUS_TYPE
:
115 response
->status
= NanStatusType(nl_itr
.get_u32());
117 case NAN_REPLY_ATTR_VALUE
:
118 val
= nl_itr
.get_u32();
120 strncpy(response
->nan_error
, "Lower_layer_error",NAN_ERROR_STR_LEN
);
123 case NAN_REPLY_ATTR_RESPONSE_TYPE
:
124 response
->response_type
= NanResponseType(nl_itr
.get_u32());
126 case NAN_REPLY_ATTR_PUBLISH_SUBSCRIBE_TYPE
:
127 response
->body
.publish_response
.publish_id
= nl_itr
.get_u16();
129 case NAN_REPLY_ATTR_NDP_INSTANCE_ID
:
130 response
->body
.data_request_response
.ndp_instance_id
= nl_itr
.get_u32();
132 case NAN_REPLY_ATTR_CAP_MAX_CONCURRENT_CLUSTER
:
133 capabilities
->max_concurrent_nan_clusters
= nl_itr
.get_u32();
135 case NAN_REPLY_ATTR_CAP_MAX_PUBLISHES
:
136 capabilities
->max_publishes
= nl_itr
.get_u32();
138 case NAN_REPLY_ATTR_CAP_MAX_SUBSCRIBES
:
139 capabilities
->max_subscribes
= nl_itr
.get_u32();
141 case NAN_REPLY_ATTR_CAP_MAX_SERVICE_NAME_LEN
:
142 capabilities
->max_service_name_len
= nl_itr
.get_u32();
144 case NAN_REPLY_ATTR_CAP_MAX_MATCH_FILTER_LEN
:
145 capabilities
->max_match_filter_len
= nl_itr
.get_u32();
147 case NAN_REPLY_ATTR_CAP_MAX_TOTAL_MATCH_FILTER_LEN
:
148 capabilities
->max_total_match_filter_len
= nl_itr
.get_u32();
150 case NAN_REPLY_ATTR_CAP_MAX_SERVICE_SPECIFIC_INFO_LEN
:
151 capabilities
->max_service_specific_info_len
= nl_itr
.get_u32();
153 case NAN_REPLY_ATTR_CAP_MAX_VSA_DATA_LEN
:
154 capabilities
->max_vsa_data_len
= nl_itr
.get_u32();
156 case NAN_REPLY_ATTR_CAP_MAX_MESH_DATA_LEN
:
157 capabilities
->max_mesh_data_len
= nl_itr
.get_u32();
159 case NAN_REPLY_ATTR_CAP_MAX_NDI_INTERFACES
:
160 capabilities
->max_ndi_interfaces
= nl_itr
.get_u32();
162 case NAN_REPLY_ATTR_CAP_MAX_NDP_SESSIONS
:
163 capabilities
->max_ndp_sessions
= nl_itr
.get_u32();
165 case NAN_REPLY_ATTR_CAP_MAX_APP_INFO_LEN
:
166 capabilities
->max_app_info_len
= nl_itr
.get_u32();
169 case NAN_REPLY_ATTR_CAP_MAX_QUEUED_TRANSMIT_FOLLOWUP_MGS
:
170 capabilities
->max_queued_transmit_followup_msgs
= nl_itr
.get_u32();
172 case NAN_REPLY_ATTR_CAP_MAX_NDP_SUPPORTED_BANDS
:
173 capabilities
->ndp_supported_bands
= nl_itr
.get_u32();
175 case NAN_REPLY_ATTR_CAP_MAX_CIPHER_SUITES_SUPPORTED
:
176 capabilities
->cipher_suites_supported
= nl_itr
.get_u32();
178 case NAN_REPLY_ATTR_CAP_MAX_SCID_LEN
:
179 capabilities
->max_scid_len
= nl_itr
.get_u32();
181 case NAN_REPLY_ATTR_CAP_NDP_SECURITY_SUPPORTED
:
182 capabilities
->is_ndp_security_supported
= (bool)nl_itr
.get_u32();
184 case NAN_REPLY_ATTR_CAP_MAX_SDEA_SERVICE_SPECIFIC_INFO_LEN
:
185 capabilities
->max_sdea_service_specific_info_len
= nl_itr
.get_u32();
187 case NAN_REPLY_ATTR_CAP_MAX_SUBSCRIBE_ADDRESS
:
188 capabilities
->max_subscribe_address
= nl_itr
.get_u32();
190 case NAN_REPLY_ATTR_CAP_NDPE_ATTR_SUPPORTED
:
191 capabilities
->ndpe_attr_supported
= nl_itr
.get_u32();
194 ALOGE("received unknown type(%d) in response", nl_itr
.get_type());
198 this->capabilities
= *capabilities
;
202 int processMatchEvent(WifiEvent
&event
) {
204 memset(&ind
,0,sizeof(NanMatchInd
));
205 int famchan_idx
= 0, disc_idx
= 0;
206 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
208 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
209 switch(nl_itr
.get_type()) {
210 case NAN_EVT_ATTR_MATCH_PUBLISH_SUBSCRIBE_ID
:
211 ind
.publish_subscribe_id
= nl_itr
.get_u16();
213 case NAN_EVT_ATTR_MATCH_REQUESTOR_INSTANCE_ID
:
214 ind
.requestor_instance_id
= nl_itr
.get_u32();
216 case NAN_EVT_ATTR_MATCH_ADDR
:
217 memcpy(ind
.addr
, nl_itr
.get_data(), NAN_MAC_ADDR_LEN
);
219 case NAN_EVT_ATTR_MATCH_SERVICE_SPECIFIC_INFO_LEN
:
220 ind
.service_specific_info_len
= nl_itr
.get_u16();
222 case NAN_EVT_ATTR_MATCH_SERVICE_SPECIFIC_INFO
:
223 memcpy(ind
.service_specific_info
, nl_itr
.get_data(), ind
.service_specific_info_len
);
225 case NAN_EVT_ATTR_MATCH_SDF_MATCH_FILTER_LEN
:
226 ind
.sdf_match_filter_len
= nl_itr
.get_u16();
228 case NAN_EVT_ATTR_MATCH_SDF_MATCH_FILTER
:
229 memcpy(ind
.sdf_match_filter
, nl_itr
.get_data(), ind
.sdf_match_filter_len
);
231 case NAN_EVT_ATTR_MATCH_MATCH_OCCURED_FLAG
:
232 ind
.match_occured_flag
= nl_itr
.get_u8();
234 case NAN_EVT_ATTR_MATCH_OUT_OF_RESOURCE_FLAG
:
235 ind
.out_of_resource_flag
= nl_itr
.get_u8();
237 case NAN_EVT_ATTR_MATCH_RSSI_VALUE
:
238 ind
.rssi_value
= nl_itr
.get_u8();
240 case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_IBSS_SUPPORTED
:
241 ind
.conn_capability
.is_ibss_supported
= nl_itr
.get_u8();
243 case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_WFD_SUPPORTED
:
244 ind
.conn_capability
.is_wfd_supported
= nl_itr
.get_u8();
246 case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_WFDS_SUPPORTED
:
247 ind
.conn_capability
.is_wfds_supported
= nl_itr
.get_u8();
249 case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_TDLS_SUPPORTED
:
250 ind
.conn_capability
.is_tdls_supported
= nl_itr
.get_u8();
252 case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_MESH_SUPPORTED
:
253 ind
.conn_capability
.is_mesh_supported
= nl_itr
.get_u8();
255 case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_WLAN_INFRA_FIELD
:
256 ind
.conn_capability
.wlan_infra_field
= nl_itr
.get_u8();
258 case NAN_EVT_ATTR_MATCH_NUM_RX_DISCOVERY_ATTR
:
259 ind
.num_rx_discovery_attr
= nl_itr
.get_u8();
261 case NAN_EVT_ATTR_MATCH_RX_DISCOVERY_ATTR
:
262 NanReceivePostDiscovery
*disc_attr
;
263 disc_attr
= &ind
.discovery_attr
[disc_idx
];
265 for(nl_iterator
nl_nested_itr((struct nlattr
*)nl_itr
.get_data()); nl_nested_itr
.has_next(); nl_nested_itr
.next()) {
266 switch(nl_nested_itr
.get_type()) {
267 case NAN_EVT_ATTR_MATCH_DISC_ATTR_TYPE
:
268 disc_attr
->type
= (NanConnectionType
)nl_nested_itr
.get_u8();
270 case NAN_EVT_ATTR_MATCH_DISC_ATTR_ROLE
:
271 disc_attr
->role
= (NanDeviceRole
)nl_nested_itr
.get_u8();
273 case NAN_EVT_ATTR_MATCH_DISC_ATTR_DURATION
:
274 disc_attr
->duration
= (NanAvailDuration
)nl_nested_itr
.get_u8();
276 case NAN_EVT_ATTR_MATCH_DISC_ATTR_AVAIL_INTERVAL_BITMAP
:
277 disc_attr
->avail_interval_bitmap
= nl_nested_itr
.get_u32();
279 case NAN_EVT_ATTR_MATCH_DISC_ATTR_MAPID
:
280 disc_attr
->mapid
= nl_nested_itr
.get_u8();
282 case NAN_EVT_ATTR_MATCH_DISC_ATTR_ADDR
:
283 memcpy(disc_attr
->addr
, nl_nested_itr
.get_data(), NAN_MAC_ADDR_LEN
);
285 case NAN_EVT_ATTR_MATCH_DISC_ATTR_MESH_ID_LEN
:
286 disc_attr
->mesh_id_len
= nl_nested_itr
.get_u8();
288 case NAN_EVT_ATTR_MATCH_DISC_ATTR_MESH_ID
:
289 memcpy(disc_attr
->mesh_id
, nl_nested_itr
.get_data(), disc_attr
->mesh_id_len
);
291 case NAN_EVT_ATTR_MATCH_DISC_ATTR_INFRASTRUCTURE_SSID_LEN
:
292 disc_attr
->infrastructure_ssid_len
= nl_nested_itr
.get_u16();
294 case NAN_EVT_ATTR_MATCH_DISC_ATTR_INFRASTRUCTURE_SSID_VAL
:
295 memcpy(disc_attr
->infrastructure_ssid_val
, nl_nested_itr
.get_data(), disc_attr
->infrastructure_ssid_len
);
300 case NAN_EVT_ATTR_MATCH_NUM_CHANS
:
301 ind
.num_chans
= nl_itr
.get_u8();
303 case NAN_EVT_ATTR_MATCH_FAMCHAN
:
304 NanFurtherAvailabilityChannel
*famchan
;
305 famchan
= &ind
.famchan
[famchan_idx
];
307 for(nl_iterator
nl_nested_itr((struct nlattr
*)nl_itr
.get_data()); nl_nested_itr
.has_next(); nl_nested_itr
.next()) {
308 switch(nl_nested_itr
.get_type()) {
309 case NAN_EVT_ATTR_MATCH_FAM_ENTRY_CONTROL
:
310 famchan
->entry_control
= (NanAvailDuration
)nl_nested_itr
.get_u8();
312 case NAN_EVT_ATTR_MATCH_FAM_CLASS_VAL
:
313 famchan
->class_val
= nl_nested_itr
.get_u8();
315 case NAN_EVT_ATTR_MATCH_FAM_CHANNEL
:
316 famchan
->channel
= nl_nested_itr
.get_u8();
318 case NAN_EVT_ATTR_MATCH_FAM_MAPID
:
319 famchan
->mapid
= nl_nested_itr
.get_u8();
321 case NAN_EVT_ATTR_MATCH_FAM_AVAIL_INTERVAL_BITMAP
:
322 famchan
->avail_interval_bitmap
= nl_nested_itr
.get_u32();
327 case NAN_EVT_ATTR_MATCH_CLUSTER_ATTRIBUTE_LEN
:
328 ind
.cluster_attribute_len
= nl_itr
.get_u8();
330 case NAN_EVT_ATTR_MATCH_CLUSTER_ATTRIBUTE
:
331 memcpy(ind
.cluster_attribute
, nl_itr
.get_data(), ind
.cluster_attribute_len
);
333 case NAN_EVT_ATTR_SDEA_LEN
:
334 ind
.sdea_service_specific_info_len
= nl_itr
.get_u16();
336 case NAN_EVT_ATTR_SDEA
:
337 memcpy(ind
.sdea_service_specific_info
, nl_itr
.get_data(), ind
.sdea_service_specific_info_len
);
339 case NAN_EVT_ATTR_SCID_LEN
:
340 ind
.scid_len
= nl_itr
.get_u32();
342 case NAN_EVT_ATTR_SCID
:
343 memcpy(ind
.scid
, nl_itr
.get_data(), ind
.scid_len
);
345 case NAN_EVT_ATTR_SDEA_PARAM_CONFIG_NAN_DATA_PATH
:
346 ind
.peer_sdea_params
.config_nan_data_path
= nl_itr
.get_u8();
348 case NAN_EVT_ATTR_SDEA_PARAM_NDP_TYPE
:
349 ind
.peer_sdea_params
.ndp_type
= (NdpType
)nl_itr
.get_u8();
351 case NAN_EVT_ATTR_SDEA_PARAM_SECURITY_CONFIG
:
352 ind
.peer_sdea_params
.security_cfg
= (NanDataPathSecurityCfgStatus
)nl_itr
.get_u8();
354 case NAN_EVT_ATTR_SDEA_PARAM_RANGE_STATE
:
355 ind
.peer_sdea_params
.ranging_state
= (NanRangingState
)nl_itr
.get_u8();
357 case NAN_EVT_ATTR_SDEA_PARAM_RANGE_REPORT
:
358 ind
.peer_sdea_params
.range_report
= (NanRangeReport
)nl_itr
.get_u8();
360 case NAN_EVT_ATTR_SDEA_PARAM_QOS_CFG
:
361 ind
.peer_sdea_params
.qos_cfg
= (NanQosCfgStatus
)nl_itr
.get_u8();
363 case NAN_EVT_ATTR_RANGE_MEASUREMENT_MM
:
364 ind
.range_info
.range_measurement_mm
= nl_itr
.get_u32();
366 case NAN_EVT_ATTR_RANGEING_EVENT_TYPE
:
367 ind
.range_info
.ranging_event_type
= nl_itr
.get_u32();
372 if (this->callbackEventHandler
.EventMatch
)
373 this->callbackEventHandler
.EventMatch(&ind
);
377 int processMatchExpiredEvent(WifiEvent
&event
) {
378 NanMatchExpiredInd ind
;
379 memset(&ind
,0,sizeof(NanMatchExpiredInd
));
381 for(nl_iterator
nl_itr((struct nlattr
*)event
.get_vendor_data()); nl_itr
.has_next(); nl_itr
.next()) {
382 switch(nl_itr
.get_type()) {
383 case NAN_EVT_ATTR_MATCH_PUBLISH_SUBSCRIBE_ID
:
384 ind
.publish_subscribe_id
= nl_itr
.get_u16();
386 case NAN_EVT_ATTR_MATCH_REQUESTOR_INSTANCE_ID
:
387 ind
.requestor_instance_id
= nl_itr
.get_u32();
390 ALOGE("processMatchExpiredEvent: unknown attribute(%d)", nl_itr
.get_type());
395 if (callbackEventHandler
.EventMatchExpired
)
396 callbackEventHandler
.EventMatchExpired(&ind
);
401 int processPublishTerminatedEvent(WifiEvent
&event
) {
402 NanPublishTerminatedInd ind
;
403 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
404 memset(&ind
,0,sizeof(ind
));
406 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
407 switch(nl_itr
.get_type()) {
408 case NAN_EVT_ATTR_PUBLISH_ID
:
409 ind
.publish_id
= nl_itr
.get_u16();
411 case NAN_EVT_ATTR_PUBLISH_REASON
:
412 ind
.reason
= (NanStatusType
)nl_itr
.get_u32();
414 case NAN_EVT_ATTR_STATUS
:
417 ALOGE("processPublishTerminatedEvent: unknown attribute(%d)", nl_itr
.get_type());
422 if (callbackEventHandler
.EventPublishTerminated
)
423 callbackEventHandler
.EventPublishTerminated(&ind
);
429 int processSubscribeTerminatedEvent(WifiEvent
&event
) {
430 NanSubscribeTerminatedInd ind
;
431 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
432 memset(&ind
,0,sizeof(ind
));
434 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
435 switch(nl_itr
.get_type()) {
436 case NAN_EVT_ATTR_SUBSCRIBE_ID
:
437 ind
.subscribe_id
= nl_itr
.get_u16();
439 case NAN_EVT_ATTR_SUBSCRIBE_REASON
:
440 ind
.reason
= (NanStatusType
)nl_itr
.get_u32();
442 case NAN_EVT_ATTR_STATUS
:
445 ALOGE("processSubscribeTerminatedEvent: unknown attribute(%d)", nl_itr
.get_type());
450 if (callbackEventHandler
.EventSubscribeTerminated
)
451 callbackEventHandler
.EventSubscribeTerminated(&ind
);
456 int processFollowupEvent(WifiEvent
&event
) {
458 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
459 memset(&ind
,0,sizeof(ind
));
461 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
462 switch(nl_itr
.get_type()) {
463 case NAN_EVT_ATTR_FOLLOWUP_PUBLISH_SUBSCRIBE_ID
:
464 ind
.publish_subscribe_id
= nl_itr
.get_u16();
466 case NAN_EVT_ATTR_FOLLOWUP_REQUESTOR_INSTANCE_ID
:
467 ind
.requestor_instance_id
= nl_itr
.get_u32();
469 case NAN_EVT_ATTR_FOLLOWUP_ADDR
:
470 memcpy(ind
.addr
, nl_itr
.get_data(), NAN_MAC_ADDR_LEN
);
472 case NAN_EVT_ATTR_FOLLOWUP_DW_OR_FAW
:
473 ind
.dw_or_faw
= nl_itr
.get_u8();
475 case NAN_EVT_ATTR_FOLLOWUP_SERVICE_SPECIFIC_INFO_LEN
:
476 ind
.service_specific_info_len
= nl_itr
.get_u16();
478 case NAN_EVT_ATTR_FOLLOWUP_SERVICE_SPECIFIC_INFO
:
479 memcpy(ind
.service_specific_info
, nl_itr
.get_data(), ind
.service_specific_info_len
);
481 case NAN_EVT_ATTR_SDEA_LEN
:
482 ind
.sdea_service_specific_info_len
= nl_itr
.get_u16();
484 case NAN_EVT_ATTR_SDEA
:
485 memcpy(ind
.sdea_service_specific_info
, nl_itr
.get_data(), ind
.sdea_service_specific_info_len
);
488 ALOGE("processNanDisabledEvent: unknown attribute(%d)", nl_itr
.get_type());
493 if (callbackEventHandler
.EventFollowup
)
494 callbackEventHandler
.EventFollowup(&ind
);
499 int processNanDisabledEvent(WifiEvent
&event
) {
501 memset(&ind
,0,sizeof(ind
));
502 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
503 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
504 switch(nl_itr
.get_type()) {
505 case NAN_EVT_ATTR_DISABLED_REASON
:
506 ind
.reason
= (NanStatusType
)nl_itr
.get_u32();
509 ALOGE("processNanDisabledEvent: unknown attribute(%d)", nl_itr
.get_type());
514 if (callbackEventHandler
.EventDisabled
)
515 callbackEventHandler
.EventDisabled(&ind
);
520 int processNanDiscoveryEvent(WifiEvent
&event
) {
521 NanDiscEngEventInd ind
;
522 memset(&ind
,0,sizeof(ind
));
524 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
525 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
526 switch(nl_itr
.get_type()) {
527 case NAN_EVT_ATTR_DISCOVERY_ENGINE_EVT_TYPE
:
528 ind
.event_type
= (NanDiscEngEventType
)nl_itr
.get_u16();
530 case NAN_EVT_ATTR_DISCOVERY_ENGINE_MAC_ADDR
:
531 addr
= (u8
*)nl_itr
.get_data();
533 case NAN_EVT_ATTR_STATUS
:
536 ALOGE("processNanDiscoveryEvent: unknown attribute(%d)", nl_itr
.get_type());
541 if (ind
.event_type
== NAN_EVENT_ID_DISC_MAC_ADDR
)
542 memcpy(ind
.data
.mac_addr
.addr
, addr
, NAN_MAC_ADDR_LEN
);
544 memcpy(ind
.data
.cluster
.addr
, addr
, NAN_MAC_ADDR_LEN
);
546 ALOGE("processNanDiscoveryEvent: No Mac/cluster Address");
549 if (callbackEventHandler
.EventDiscEngEvent
)
550 callbackEventHandler
.EventDiscEngEvent(&ind
);
555 int processNanFollowupStatus(WifiEvent
&event
) {
556 NanTransmitFollowupInd ind
;
557 memset(&ind
,0,sizeof(ind
));
558 ind
.id
= followupTid
;
560 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
561 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
562 if (nl_itr
.get_type() == NAN_EVT_ATTR_STATUS
) {
563 ind
.reason
= (NanStatusType
)nl_itr
.get_u16();
565 ALOGE("processNanFollowupStatus: unknown attribute(%d)", nl_itr
.get_type());
570 if (callbackEventHandler
.EventTransmitFollowup
)
571 callbackEventHandler
.EventTransmitFollowup(&ind
);
576 int putSdeaParams(NanSdeaCtrlParams
*sdea_params
, WifiRequest
*request
)
580 if (!sdea_params
->config_nan_data_path
)
583 result
= request
->put_u8(NAN_REQ_ATTR_SDEA_PARAM_NDP_TYPE
, sdea_params
->ndp_type
);
584 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put SDEA PARAM ndp_type");
586 result
= request
->put_u8(NAN_REQ_ATTR_SDEA_PARAM_SECURITY_CFG
, sdea_params
->security_cfg
);
587 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put SDEA PARAM security_cfg");
589 result
= request
->put_u8(NAN_REQ_ATTR_SDEA_PARAM_RANGING_STATE
, sdea_params
->ranging_state
);
590 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put SDEA PARAM ranging_state");
592 result
= request
->put_u8(NAN_REQ_ATTR_SDEA_PARAM_RANGE_REPORT
, sdea_params
->range_report
);
593 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put SDEA PARAM range_report");
595 result
= request
->put_u8(NAN_REQ_ATTR_SDEA_PARAM_QOS_CFG
, sdea_params
->qos_cfg
);
596 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put SDEA PARAM qos_cfg");
601 int putRangingCfg(NanRangingCfg
*ranging_cfg
, WifiRequest
*request
)
605 result
= request
->put_u32(NAN_REQ_ATTR_RANGING_CFG_INTERVAL
, ranging_cfg
->ranging_interval_msec
);
606 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put Ranging CFG ranging_interval_msec");
608 result
= request
->put_u32(NAN_REQ_ATTR_RANGING_CFG_INDICATION
, ranging_cfg
->config_ranging_indications
);
609 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put Ranging CFG config_ranging_indications");
611 result
= request
->put_u32(NAN_REQ_ATTR_RANGING_CFG_INGRESS_MM
, ranging_cfg
->distance_ingress_mm
);
612 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put Ranging CFG distance_ingress_mm");
614 result
= request
->put_u32(NAN_REQ_ATTR_RANGING_CFG_EGRESS_MM
, ranging_cfg
->distance_egress_mm
);
615 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put Ranging CFG distance_egress_mm");
620 int putRangeResponseCfg(NanRangeResponseCfg
*range_resp_cfg
, WifiRequest
*request
)
624 result
= request
->put_u16(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_PUBLISH_ID
, range_resp_cfg
->publish_id
);
625 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "Failed to put range response cfg::publish_id");
627 result
= request
->put_u32(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_REQUESTOR_ID
, range_resp_cfg
->requestor_instance_id
);
628 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "Failed to put range response cfg::requestor_instance_id");
630 result
= request
->put_addr(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_PEER_ADDR
, range_resp_cfg
->peer_addr
);
631 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "Failed to put range response cfg::peer_addr");
633 result
= request
->put_u16(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_RANGING_RESPONSE
, range_resp_cfg
->ranging_response
);
634 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "Failed to put range response cfg::ranging_response");
640 NanCommand(wifi_interface_handle iface
, int id
)
641 : WifiCommand(iface
, id
), datacmd()
652 publishCancelTid
= 0;
654 subscribeCancelTid
= 0;
661 memset(&capabilities
, 0, sizeof(capabilities
));
664 int enable(transaction_id id
, NanEnableRequest
*msg
) {
665 ALOGD("NAN enable id:%d", id
);
666 WifiRequest
request(familyId(), ifaceId());
668 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_ENABLE
);
669 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to create WifiRequest");
671 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
673 ALOGE("enable: request.attr_start fail");
674 return WIFI_ERROR_OUT_OF_MEMORY
;
676 /* Valid master pref values are 2-254 */
678 if (msg
->master_pref
< 2)
680 else if (msg
->master_pref
> 254)
683 master_pref
= msg
->master_pref
;
684 result
= request
.put_u8(NAN_REQ_ATTR_MASTER_PREF
, master_pref
);
685 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put master_pref");
687 result
= request
.put_u16(NAN_REQ_ATTR_CLUSTER_LOW
, msg
->cluster_low
);
688 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put cluster_low");
690 result
= request
.put_u16(NAN_REQ_ATTR_CLUSTER_HIGH
, msg
->cluster_high
);
691 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put cluster_high");
693 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_support_5g
, msg
->support_5g_val
,
694 NAN_REQ_ATTR_SUPPORT_5G_VAL
, request
, result
, "enable:Failed to put support_5g_val");
696 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_sid_beacon
, msg
->sid_beacon_val
,
697 NAN_REQ_ATTR_SID_BEACON_VAL
, request
, result
, "enable:Failed to put sid_beacon_val");
699 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_2dot4g_rssi_close
, msg
->rssi_close_2dot4g_val
,
700 NAN_REQ_ATTR_RSSI_CLOSE_2G4_VAL
, request
, result
, "enable:Failed to put rssi_close_2dot4g_val");
702 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_2dot4g_rssi_middle
, msg
->rssi_middle_2dot4g_val
,
703 NAN_REQ_ATTR_RSSI_MIDDLE_2G4_VAL
, request
, result
, "enable:Failed to put rssi_middle_2dot4g_val");
705 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_2dot4g_rssi_proximity
, msg
->rssi_proximity_2dot4g_val
,
706 NAN_REQ_ATTR_RSSI_PROXIMITY_2G4_VAL
, request
, result
, "enable:Failed to put rssi_proximity_2dot4g_val");
708 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_hop_count_limit
, msg
->hop_count_limit_val
,
709 NAN_REQ_ATTR_HOP_COUNT_LIMIT_VAL
, request
, result
, "enable:Failed to put hop_count_limit_val");
711 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_2dot4g_support
, msg
->support_2dot4g_val
,
712 NAN_REQ_ATTR_SUPPORT_2G4_VAL
, request
, result
, "enable:Failed to put support_2dot4g_val");
714 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_2dot4g_beacons
, msg
->beacon_2dot4g_val
,
715 NAN_REQ_ATTR_BEACONS_2G4_VAL
, request
, result
, "enable:Failed to put beacon_2dot4g_val");
717 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_2dot4g_sdf
, msg
->sdf_2dot4g_val
,
718 NAN_REQ_ATTR_SDF_2G4_VAL
, request
, result
, "enable:Failed to put sdf_2dot4g_val");
720 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_5g_beacons
, msg
->beacon_5g_val
,
721 NAN_REQ_ATTR_BEACON_5G_VAL
, request
, result
, "enable:Failed to put beacon_5g_val");
723 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_5g_sdf
, msg
->sdf_5g_val
,
724 NAN_REQ_ATTR_SDF_5G_VAL
, request
, result
, "enable:Failed to put sdf_5g_val");
726 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_5g_rssi_close
, msg
->rssi_close_5g_val
,
727 NAN_REQ_ATTR_RSSI_CLOSE_5G_VAL
, request
, result
, "enable:Failed to put rssi_close_5g_val");
729 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_5g_rssi_middle
, msg
->rssi_middle_5g_val
,
730 NAN_REQ_ATTR_RSSI_MIDDLE_5G_VAL
, request
, result
, "enable:Failed to put rssi_middle_5g_val");
732 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_5g_rssi_close_proximity
, msg
->rssi_close_proximity_5g_val
,
733 NAN_REQ_ATTR_RSSI_CLOSE_PROXIMITY_5G_VAL
, request
, result
, "enable:Failed to put rssi_close_proximity_5g_val");
735 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_rssi_window_size
, msg
->rssi_window_size_val
,
736 NAN_REQ_ATTR_RSSI_WINDOW_SIZE_VAL
, request
, result
, "enable:Failed to put rssi_window_size_val");
738 CHECK_CONFIG_PUT_32_RETURN_FAIL(msg
->config_oui
, msg
->oui_val
,
739 NAN_REQ_ATTR_OUI_VAL
, request
, result
, "enable:Failed to put oui_val");
741 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->config_intf_addr
, msg
->intf_addr_val
, NAN_MAC_ADDR_LEN
,
742 NAN_REQ_ATTR_MAC_ADDR_VAL
, request
, result
, "enable:Failed to put intf_addr_val");
744 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->config_cluster_attribute_val
,
745 NAN_REQ_ATTR_CLUSTER_VAL
, request
, result
, "enable:Failed to put config_cluster_attribute_val");
747 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->config_scan_params
, msg
->scan_params_val
.dwell_time
, sizeof(msg
->scan_params_val
.dwell_time
),
748 NAN_REQ_ATTR_SOCIAL_CH_SCAN_DWELL_TIME
, request
, result
, "enable:Failed to put scan_params_val.dwell_time");
750 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->config_scan_params
, msg
->scan_params_val
.scan_period
, sizeof(msg
->scan_params_val
.scan_period
),
751 NAN_REQ_ATTR_SOCIAL_CH_SCAN_PERIOD
, request
, result
, "enable:Failed to put scan_params_val.scan_period");
753 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_random_factor_force
, msg
->random_factor_force_val
,
754 NAN_REQ_ATTR_RANDOM_FACTOR_FORCE_VAL
, request
, result
, "enable:Failed to put random_factor_force_val");
756 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_hop_count_force
, msg
->hop_count_force_val
,
757 NAN_REQ_ATTR_HOP_COUNT_FORCE_VAL
, request
, result
, "enable:Failed to put hop_count_force_val");
759 CHECK_CONFIG_PUT_32_RETURN_FAIL(msg
->config_24g_channel
, msg
->channel_24g_val
,
760 NAN_REQ_ATTR_CHANNEL_2G4_MHZ_VAL
, request
, result
, "enable:Failed to put channel_24g_val");
762 CHECK_CONFIG_PUT_32_RETURN_FAIL(msg
->config_5g_channel
, msg
->channel_5g_val
,
763 NAN_REQ_ATTR_CHANNEL_5G_MHZ_VAL
, request
, result
, "enable:Failed to put channel_5g_val");
765 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_subscribe_sid_beacon
, msg
->subscribe_sid_beacon_val
,
766 NAN_REQ_ATTR_SUBSCRIBE_SID_BEACON_VAL
, request
, result
, "enable:Failed to put subscribe_sid_beacon_val");
768 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_dw
.config_2dot4g_dw_band
, msg
->config_dw
.dw_2dot4g_interval_val
,
769 NAN_REQ_ATTR_DW_2G4_INTERVAL
, request
, result
, "enable:Failed to put dw_2dot4g_interval_val");
771 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_dw
.config_5g_dw_band
, msg
->config_dw
.dw_5g_interval_val
,
772 NAN_REQ_ATTR_DW_5G_INTERVAL
, request
, result
, "enable:Failed to put dw_5g_interval_val");
774 CHECK_CONFIG_PUT_32_RETURN_FAIL(msg
->config_disc_mac_addr_randomization
, msg
->disc_mac_addr_rand_interval_sec
,
775 NAN_REQ_ATTR_DISC_MAC_ADDR_RANDOM_INTERVAL
, request
, result
, "enable:Failed to put disc_mac_addr_rand_interval_sec");
777 CHECK_CONFIG_PUT_32_RETURN_FAIL(msg
->config_ndpe_attr
, msg
->use_ndpe_attr
,
778 NAN_REQ_ATTR_USE_NDPE_ATTR
, request
, result
, "enable:Failed to put use_ndpe_attr");
780 request
.attr_end(data
);
784 result
= requestResponse(request
);
785 if (result
!= WIFI_SUCCESS
) {
787 ALOGE("failed to NAN; result = %d", result
);
788 unregisterNanEvents();
790 ALOGD("Start NAN...success");
795 int disable(transaction_id id
)
797 ALOGD("NAN disable id:%d", id
);
798 WifiRequest
request(familyId(), ifaceId());
800 unregisterNanEvents();
802 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_DISABLE
);
803 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "disable:Failed to create WifiRequest");
805 result
= requestResponse(request
);
806 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "disable:Failed to requestResponse");
810 int config(transaction_id id
, NanConfigRequest
*msg
) {
811 ALOGD("NAN config id:%d", id
);
812 WifiRequest
request(familyId(), ifaceId());
814 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_CONFIG
);
815 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "config:Failed to create WifiRequest");
817 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
819 ALOGE("config: request.attr_start fail");
820 return WIFI_ERROR_OUT_OF_MEMORY
;
823 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_sid_beacon
, msg
->sid_beacon
,
824 NAN_REQ_ATTR_SID_BEACON_VAL
, request
, result
, "config:Failed to put sid_beacon");
826 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_rssi_proximity
, msg
->rssi_proximity
,
827 NAN_REQ_ATTR_RSSI_PROXIMITY_2G4_VAL
, request
, result
, "config:Failed to put rssi_proximity");
829 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_master_pref
, msg
->master_pref
,
830 NAN_REQ_ATTR_MASTER_PREF
, request
, result
, "config:Failed to put master_pref");
832 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_5g_rssi_close_proximity
, msg
->rssi_close_proximity_5g_val
,
833 NAN_REQ_ATTR_RSSI_CLOSE_PROXIMITY_5G_VAL
, request
, result
, "config:Failed to put rssi_close_proximity_5g_val");
835 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_rssi_window_size
, msg
->rssi_window_size_val
,
836 NAN_REQ_ATTR_RSSI_WINDOW_SIZE_VAL
, request
, result
, "config:Failed to put rssi_window_size_val");
838 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->config_cluster_attribute_val
,
839 NAN_REQ_ATTR_CLUSTER_VAL
, request
, result
, "config:Failed to put config_cluster_attribute_val");
841 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->config_scan_params
, msg
->scan_params_val
.dwell_time
, sizeof(msg
->scan_params_val
.dwell_time
),
842 NAN_REQ_ATTR_SOCIAL_CH_SCAN_DWELL_TIME
, request
, result
, "config:Failed to put scan_params_val.dwell_time");
844 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->config_scan_params
, msg
->scan_params_val
.scan_period
, sizeof(msg
->scan_params_val
.scan_period
),
845 NAN_REQ_ATTR_SOCIAL_CH_SCAN_PERIOD
, request
, result
, "config:Failed to put scan_params_val.scan_period");
847 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_random_factor_force
, msg
->random_factor_force_val
,
848 NAN_REQ_ATTR_RANDOM_FACTOR_FORCE_VAL
, request
, result
, "config:Failed to put random_factor_force_val");
850 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_hop_count_force
, msg
->hop_count_force_val
,
851 NAN_REQ_ATTR_HOP_COUNT_FORCE_VAL
, request
, result
, "config:Failed to put hop_count_force_val");
853 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.payload_transmit_flag
,
854 NAN_REQ_ATTR_CONN_CAPABILITY_PAYLOAD_TX
, request
, result
, "config:Failed to put payload_transmit_flag");
856 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.is_wfd_supported
,
857 NAN_REQ_ATTR_CONN_CAPABILITY_WFD
, request
, result
, "config:Failed to put is_wfd_supported");
859 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.is_wfds_supported
,
860 NAN_REQ_ATTR_CONN_CAPABILITY_WFDS
, request
, result
, "config:Failed to put is_wfds_supported");
862 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.is_tdls_supported
,
863 NAN_REQ_ATTR_CONN_CAPABILITY_TDLS
, request
, result
, "config:Failed to put is_tdls_supported");
865 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.is_ibss_supported
,
866 NAN_REQ_ATTR_CONN_CAPABILITY_IBSS
, request
, result
, "config:Failed to put is_ibss_supported");
868 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.is_mesh_supported
,
869 NAN_REQ_ATTR_CONN_CAPABILITY_MESH
, request
, result
, "config:Failed to put is_mesh_supported");
871 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.wlan_infra_field
,
872 NAN_REQ_ATTR_CONN_CAPABILITY_WLAN_INFRA
, request
, result
, "config:Failed to put wlan_infra_field");
874 if (msg
->num_config_discovery_attr
) {
875 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->num_config_discovery_attr
,
876 NAN_REQ_ATTR_DISCOVERY_ATTR_NUM_ENTRIES
, request
, result
, "config:Failed to put msg->num_config_discovery_attr");
877 for (int i
= 0; i
< msg
->num_config_discovery_attr
; i
++) {
878 nlattr
*nl_disc_attribute
= request
.attr_start(NAN_REQ_ATTR_DISCOVERY_ATTR_VAL
);
879 NanTransmitPostDiscovery
*discovery_attr
= &msg
->discovery_attr_val
[i
];
880 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr
->type
,
881 NAN_REQ_ATTR_CONN_TYPE
, request
, result
, "config:Failed to put discovery_attr->type");
882 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr
->role
,
883 NAN_REQ_ATTR_NAN_ROLE
, request
, result
, "config:Failed to put discovery_attr->role");
884 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr
->transmit_freq
,
885 NAN_REQ_ATTR_TRANSMIT_FREQ
, request
, result
, "config:Failed to put discovery_attr->transmit_freq");
886 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr
->duration
,
887 NAN_REQ_ATTR_AVAILABILITY_DURATION
, request
, result
, "config:Failed to put discovery_attr->duration");
888 CHECK_CONFIG_PUT_32_RETURN_FAIL(1, discovery_attr
->avail_interval_bitmap
,
889 NAN_REQ_ATTR_AVAILABILITY_INTERVAL
, request
, result
, "config:Failed to put discovery_attr->avail_interval_bitmap");
890 CHECK_CONFIG_PUT_RETURN_FAIL(1, discovery_attr
->addr
, NAN_MAC_ADDR_LEN
,
891 NAN_REQ_ATTR_MAC_ADDR_VAL
, request
, result
, "config:Failed to put discovery_attr->addr");
892 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, discovery_attr
->mesh_id_len
,
893 NAN_REQ_ATTR_MESH_ID_LEN
, request
, result
, "config:Failed to put discovery_attr->mesh_id");
894 CHECK_CONFIG_PUT_RETURN_FAIL(discovery_attr
->mesh_id_len
, discovery_attr
->mesh_id
, discovery_attr
->mesh_id_len
,
895 NAN_REQ_ATTR_MESH_ID
, request
, result
, "config:Failed to put discovery_attr->mesh_id");
896 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, discovery_attr
->infrastructure_ssid_len
,
897 NAN_REQ_ATTR_INFRASTRUCTURE_SSID_LEN
, request
, result
, "config:Failed to put discovery_attr->infrastructure_ssid_val");
898 CHECK_CONFIG_PUT_RETURN_FAIL(discovery_attr
->infrastructure_ssid_len
, discovery_attr
->infrastructure_ssid_val
, discovery_attr
->infrastructure_ssid_len
,
899 NAN_REQ_ATTR_INFRASTRUCTURE_SSID
, request
, result
, "config:Failed to put discovery_attr->infrastructure_ssid_val");
900 request
.attr_end(nl_disc_attribute
);
904 if (msg
->config_fam
) {
905 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->fam_val
.numchans
,
906 NAN_REQ_ATTR_FURTHER_AVAIL_NUM_ENTRIES
, request
, result
, "config:Failed to put msg->fam_val.numchans");
907 for (int i
= 0; i
< msg
->fam_val
.numchans
; i
++) {
908 nlattr
*nl_fam_attribute
= request
.attr_start(NAN_REQ_ATTR_FURTHER_AVAIL_VAL
);
909 NanFurtherAvailabilityChannel
*further_avail_chan
= &msg
->fam_val
.famchan
[i
];
910 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan
->entry_control
,
911 NAN_REQ_ATTR_FURTHER_AVAIL_ENTRY_CTRL
, request
, result
, "config:Failed to put further_avail_chan->entry_control");
912 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan
->class_val
,
913 NAN_REQ_ATTR_FURTHER_AVAIL_CHAN_CLASS
, request
, result
, "config:Failed to put further_avail_chan->class_val");
914 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan
->channel
,
915 NAN_REQ_ATTR_FURTHER_AVAIL_CHAN
, request
, result
, "config:Failed to put further_avail_chan->channel");
916 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan
->mapid
,
917 NAN_REQ_ATTR_FURTHER_AVAIL_CHAN_MAPID
, request
, result
, "config:Failed to put further_avail_chan->mapid");
918 CHECK_CONFIG_PUT_32_RETURN_FAIL(1, further_avail_chan
->avail_interval_bitmap
,
919 NAN_REQ_ATTR_FURTHER_AVAIL_INTERVAL_BITMAP
, request
, result
, "config:Failed to put further_avail_chan->avail_interval_bitmap");
920 request
.attr_end(nl_fam_attribute
);
924 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_subscribe_sid_beacon
, msg
->subscribe_sid_beacon_val
,
925 NAN_REQ_ATTR_SUBSCRIBE_SID_BEACON_VAL
, request
, result
, "config:Failed to put subscribe_sid_beacon_val");
927 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_dw
.config_2dot4g_dw_band
, msg
->config_dw
.dw_2dot4g_interval_val
,
928 NAN_REQ_ATTR_DW_2G4_INTERVAL
, request
, result
, "config:Failed to put dw_2dot4g_interval_val");
930 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_dw
.config_5g_dw_band
, msg
->config_dw
.dw_5g_interval_val
,
931 NAN_REQ_ATTR_DW_5G_INTERVAL
, request
, result
, "config:Failed to put dw_5g_interval_val");
933 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_disc_mac_addr_randomization
, msg
->disc_mac_addr_rand_interval_sec
,
934 NAN_REQ_ATTR_DISC_MAC_ADDR_RANDOM_INTERVAL
, request
, result
, "config:Failed to put disc_mac_addr_rand_interval_sec");
936 CHECK_CONFIG_PUT_32_RETURN_FAIL(msg
->config_ndpe_attr
, msg
->use_ndpe_attr
,
937 NAN_REQ_ATTR_USE_NDPE_ATTR
, request
, result
, "enable:Failed to put use_ndpe_attr");
939 request
.attr_end(data
);
941 result
= requestResponse(request
);
942 if (result
!= WIFI_SUCCESS
) {
944 ALOGE("failed to set_config; result = %d", result
);
946 ALOGD("NAN config...success");
951 static int setCallbackHandler(NanCallbackHandler handlers
) {
952 callbackEventHandler
= handlers
;
956 static int getVersion(NanVersion
*version
) {
957 *version
= SLSI_WIFI_HAL_NAN_VERSION
;
961 int publish(transaction_id id
, NanPublishRequest
*msg
) {
962 ALOGD("NAN publish transId:%d publishId:%d publishType:%d", id
, msg
->publish_id
, msg
->publish_type
);
963 WifiRequest
request(familyId(), ifaceId());
965 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_PUBLISH
);
966 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "publish:Failed to create WifiRequest");
968 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
970 ALOGE("publish: request.attr_start fail");
971 return WIFI_ERROR_OUT_OF_MEMORY
;
974 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->publish_id
, msg
->publish_id
,
975 NAN_REQ_ATTR_PUBLISH_ID
, request
, result
, "publish:Failed to put msg->publish_id");
977 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->ttl
, msg
->ttl
,
978 NAN_REQ_ATTR_PUBLISH_TTL
, request
, result
, "publish:Failed to put msg->ttl");
980 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->period
,
981 NAN_REQ_ATTR_PUBLISH_PERIOD
, request
, result
, "publish:Failed to put msg->period");
983 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->publish_type
,
984 NAN_REQ_ATTR_PUBLISH_TYPE
, request
, result
, "publish:Failed to put msg->publish_type");
986 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->tx_type
,
987 NAN_REQ_ATTR_PUBLISH_TX_TYPE
, request
, result
, "publish:Failed to put msg->tx_type");
989 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->publish_count
,
990 NAN_REQ_ATTR_PUBLISH_COUNT
, request
, result
, "publish:Failed to put msg->publish_count");
992 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->service_name_len
, msg
->service_name_len
,
993 NAN_REQ_ATTR_PUBLISH_SERVICE_NAME_LEN
, request
, result
, "publish:Failed to put msg->service_name_len");
995 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->service_name_len
, msg
->service_name
, msg
->service_name_len
,
996 NAN_REQ_ATTR_PUBLISH_SERVICE_NAME
, request
, result
, "publish:Failed to put msg->service_name");
998 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->publish_match_indicator
,
999 NAN_REQ_ATTR_PUBLISH_MATCH_ALGO
, request
, result
, "publish:Failed to put msg->publish_match_indicator");
1001 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->service_specific_info_len
, msg
->service_specific_info_len
,
1002 NAN_REQ_ATTR_PUBLISH_SERVICE_INFO_LEN
, request
, result
, "publish:Failed to put msg->service_specific_info_len");
1004 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->service_specific_info_len
, msg
->service_specific_info
, msg
->service_specific_info_len
,
1005 NAN_REQ_ATTR_PUBLISH_SERVICE_INFO
, request
, result
, "publish:Failed to put msg->service_specific_info");
1007 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->rx_match_filter_len
, msg
->rx_match_filter_len
,
1008 NAN_REQ_ATTR_PUBLISH_RX_MATCH_FILTER_LEN
, request
, result
, "publish:Failed to put msg->rx_match_filter_len");
1010 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->rx_match_filter_len
, msg
->rx_match_filter
, msg
->rx_match_filter_len
,
1011 NAN_REQ_ATTR_PUBLISH_RX_MATCH_FILTER
, request
, result
, "publish:Failed to put msg->rx_match_filter");
1013 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->tx_match_filter_len
, msg
->tx_match_filter_len
,
1014 NAN_REQ_ATTR_PUBLISH_TX_MATCH_FILTER_LEN
, request
, result
, "publish:Failed to put msg->tx_match_filter_len");
1016 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->tx_match_filter_len
, msg
->tx_match_filter
, msg
->tx_match_filter_len
,
1017 NAN_REQ_ATTR_PUBLISH_TX_MATCH_FILTER
, request
, result
, "publish:Failed to put msg->tx_match_filter");
1019 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->rssi_threshold_flag
,
1020 NAN_REQ_ATTR_PUBLISH_RSSI_THRESHOLD_FLAG
, request
, result
, "publish:Failed to put msg->rssi_threshold_flag");
1022 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->connmap
,
1023 NAN_REQ_ATTR_PUBLISH_CONN_MAP
, request
, result
, "publish:Failed to put msg->connmap");
1025 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->recv_indication_cfg
,
1026 NAN_REQ_ATTR_PUBLISH_RECV_IND_CFG
, request
, result
, "publish:Failed to put msg->recv_indication_cfg");
1028 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->sdea_service_specific_info_len
,
1029 NAN_REQ_ATTR_PUBLISH_SDEA_LEN
, request
, result
, "publish:Failed to put msg->sdea_service_specific_info_len");
1031 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->sdea_service_specific_info_len
, msg
->sdea_service_specific_info
, msg
->sdea_service_specific_info_len
,
1032 NAN_REQ_ATTR_PUBLISH_SDEA
, request
, result
, "publish:Failed to put msg->sdea_service_specific_info");
1034 result
= request
.put_u8(NAN_REQ_ATTR_RANGING_AUTO_RESPONSE
, msg
->ranging_auto_response
);
1035 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put ranging_auto_response");
1037 result
= putSdeaParams(&msg
->sdea_params
, &request
);
1040 result
= putRangingCfg(&msg
->ranging_cfg
, &request
);
1043 result
= NanDataCommand::putSecurityInfo(msg
->cipher_type
, &msg
->key_info
, msg
->scid_len
, msg
->scid
, &request
);
1046 result
= putRangeResponseCfg(&msg
->range_response_cfg
, &request
);
1050 request
.attr_end(data
);
1052 result
= requestResponse(request
);
1053 if (result
!= WIFI_SUCCESS
) {
1055 ALOGE("failed to publish; result = %d", result
);
1057 ALOGD("NAN publish...success");
1062 int publishCancel(transaction_id id
, NanPublishCancelRequest
*msg
) {
1063 ALOGD("NAN publishCancel transId:%d, publish_id:%d", id
, msg
->publish_id
);
1064 WifiRequest
request(familyId(), ifaceId());
1066 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_PUBLISHCANCEL
);
1067 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "publishCancel:Failed to create WifiRequest");
1069 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
1071 ALOGE("publishCancel: request.attr_start fail");
1072 return WIFI_ERROR_OUT_OF_MEMORY
;
1075 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->publish_id
,
1076 NAN_REQ_ATTR_PUBLISH_ID
, request
, result
, "publishCancel:Failed to put msg->publish_id");
1078 request
.attr_end(data
);
1079 publishCancelTid
= id
;
1080 result
= requestResponse(request
);
1081 if (result
!= WIFI_SUCCESS
) {
1082 publishCancelTid
= 0;
1083 ALOGE("failed to publishCancel; result = %d", result
);
1085 ALOGD("NAN publishCancel...success");
1091 int subscribe(transaction_id id
, NanSubscribeRequest
*msg
) {
1092 ALOGD("NAN subscribe trans_id:%d subscribe_id:%d subscribetype:%d", id
, msg
->subscribe_id
, msg
->subscribe_type
);
1093 WifiRequest
request(familyId(), ifaceId());
1095 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_SUBSCRIBE
);
1096 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "subscribe:Failed to create WifiRequest");
1098 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
1100 ALOGE("subscribe: request.attr_start fail");
1101 return WIFI_ERROR_OUT_OF_MEMORY
;
1104 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->subscribe_id
, msg
->subscribe_id
,
1105 NAN_REQ_ATTR_SUBSCRIBE_ID
, request
, result
, "subscribe:Failed to put msg->publish_id");
1107 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->ttl
,
1108 NAN_REQ_ATTR_SUBSCRIBE_TTL
, request
, result
, "subscribe:Failed to put msg->ttl");
1110 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->period
,
1111 NAN_REQ_ATTR_SUBSCRIBE_PERIOD
, request
, result
, "subscribe:Failed to put msg->period");
1113 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->subscribe_type
,
1114 NAN_REQ_ATTR_SUBSCRIBE_TYPE
, request
, result
, "subscribe:Failed to put msg->subscribe_type");
1116 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->serviceResponseFilter
,
1117 NAN_REQ_ATTR_SUBSCRIBE_RESP_FILTER_TYPE
, request
, result
, "subscribe:Failed to put msg->serviceResponseFilter");
1119 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->serviceResponseInclude
,
1120 NAN_REQ_ATTR_SUBSCRIBE_RESP_INCLUDE
, request
, result
, "subscribe:Failed to put msg->serviceResponseInclude");
1122 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->useServiceResponseFilter
,
1123 NAN_REQ_ATTR_SUBSCRIBE_USE_RESP_FILTER
, request
, result
, "subscribe:Failed to put msg->useServiceResponseFilter");
1125 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->ssiRequiredForMatchIndication
,
1126 NAN_REQ_ATTR_SUBSCRIBE_SSI_REQUIRED
, request
, result
, "subscribe:Failed to put msg->ssiRequiredForMatchIndication");
1128 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->subscribe_match_indicator
,
1129 NAN_REQ_ATTR_SUBSCRIBE_MATCH_INDICATOR
, request
, result
, "subscribe:Failed to put msg->subscribe_match_indicator");
1131 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->subscribe_count
,
1132 NAN_REQ_ATTR_SUBSCRIBE_COUNT
, request
, result
, "subscribe:Failed to put msg->subscribe_count");
1134 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->service_name_len
, msg
->service_name_len
,
1135 NAN_REQ_ATTR_SUBSCRIBE_SERVICE_NAME_LEN
, request
, result
, "subscribe:Failed to put msg->service_name_len");
1137 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->service_name_len
, msg
->service_name
, msg
->service_name_len
,
1138 NAN_REQ_ATTR_SUBSCRIBE_SERVICE_NAME
, request
, result
, "subscribe:Failed to put msg->service_name");
1140 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->service_specific_info_len
, msg
->service_specific_info_len
,
1141 NAN_REQ_ATTR_SUBSCRIBE_SERVICE_INFO_LEN
, request
, result
, "subscribe:Failed to put msg->service_specific_info_len");
1143 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->service_specific_info_len
, msg
->service_specific_info
, msg
->service_specific_info_len
,
1144 NAN_REQ_ATTR_SUBSCRIBE_SERVICE_INFO
, request
, result
, "subscribe:Failed to put msg->service_specific_info");
1146 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->rx_match_filter_len
, msg
->rx_match_filter_len
,
1147 NAN_REQ_ATTR_SUBSCRIBE_RX_MATCH_FILTER_LEN
, request
, result
, "subscribe:Failed to put msg->rx_match_filter_len");
1149 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->rx_match_filter_len
, msg
->rx_match_filter
, msg
->rx_match_filter_len
,
1150 NAN_REQ_ATTR_SUBSCRIBE_RX_MATCH_FILTER
, request
, result
, "subscribe:Failed to put msg->rx_match_filter");
1152 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->tx_match_filter_len
, msg
->tx_match_filter_len
,
1153 NAN_REQ_ATTR_SUBSCRIBE_TX_MATCH_FILTER_LEN
, request
, result
, "subscribe:Failed to put msg->tx_match_filter_len");
1155 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->tx_match_filter_len
, msg
->tx_match_filter
, msg
->tx_match_filter_len
,
1156 NAN_REQ_ATTR_SUBSCRIBE_TX_MATCH_FILTER
, request
, result
, "subscribe:Failed to put msg->tx_match_filter");
1158 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->rssi_threshold_flag
,
1159 NAN_REQ_ATTR_SUBSCRIBE_RSSI_THRESHOLD_FLAG
, request
, result
, "subscribe:Failed to put msg->rssi_threshold_flag");
1161 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->connmap
,
1162 NAN_REQ_ATTR_SUBSCRIBE_CONN_MAP
, request
, result
, "subscribe:Failed to put msg->connmap");
1164 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->num_intf_addr_present
, msg
->num_intf_addr_present
,
1165 NAN_REQ_ATTR_SUBSCRIBE_NUM_INTF_ADDR_PRESENT
, request
, result
, "subscribe:Failed to put msg->num_intf_addr_present");
1167 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->num_intf_addr_present
, msg
->intf_addr
, NAN_MAC_ADDR_LEN
* msg
->num_intf_addr_present
,
1168 NAN_REQ_ATTR_SUBSCRIBE_INTF_ADDR
, request
, result
, "subscribe:Failed to put msg->intf_addr");
1170 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->recv_indication_cfg
,
1171 NAN_REQ_ATTR_SUBSCRIBE_RECV_IND_CFG
, request
, result
, "subscribe:Failed to put msg->recv_indication_cfg");
1173 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->sdea_service_specific_info_len
,
1174 NAN_REQ_ATTR_PUBLISH_SDEA_LEN
, request
, result
, "subscribe:Failed to put msg->sdea_service_specific_info_len");
1176 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->sdea_service_specific_info_len
, msg
->sdea_service_specific_info
, msg
->sdea_service_specific_info_len
,
1177 NAN_REQ_ATTR_PUBLISH_SDEA
, request
, result
, "subscribe:Failed to put msg->sdea_service_specific_info");
1179 result
= request
.put_u8(NAN_REQ_ATTR_RANGING_AUTO_RESPONSE
, msg
->ranging_auto_response
);
1180 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put ranging_auto_response");
1182 result
= putSdeaParams(&msg
->sdea_params
, &request
);
1185 result
= putRangingCfg(&msg
->ranging_cfg
, &request
);
1188 result
= NanDataCommand::putSecurityInfo(msg
->cipher_type
, &msg
->key_info
, msg
->scid_len
, msg
->scid
, &request
);
1191 result
= putRangeResponseCfg(&msg
->range_response_cfg
, &request
);
1195 request
.attr_end(data
);
1197 result
= requestResponse(request
);
1198 if (result
!= WIFI_SUCCESS
) {
1200 ALOGE("failed to subscribe; result = %d", result
);
1202 ALOGD("NAN subscribe...success");
1208 int subscribeCancel(transaction_id id
, NanSubscribeCancelRequest
*msg
) {
1209 ALOGD("NAN subscribeCancel transId:%d subscribeId:%d", id
, msg
->subscribe_id
);
1210 WifiRequest
request(familyId(), ifaceId());
1212 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_SUBSCRIBECANCEL
);
1213 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "subscribeCancel:Failed to create WifiRequest");
1215 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
1217 ALOGE("subscribeCancel: request.attr_start fail");
1218 return WIFI_ERROR_OUT_OF_MEMORY
;
1221 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->subscribe_id
,
1222 NAN_REQ_ATTR_SUBSCRIBE_ID
, request
, result
, "subscribeCancel:Failed to put msg->subscribe_id");
1224 request
.attr_end(data
);
1225 subscribeCancelTid
= id
;
1226 result
= requestResponse(request
);
1227 if (result
!= WIFI_SUCCESS
) {
1228 subscribeCancelTid
= 0;
1229 ALOGE("failed to subscribeCancel; result = %d", result
);
1231 ALOGD("NAN subscribeCancel...success");
1236 int followup(transaction_id id
, NanTransmitFollowupRequest
*msg
) {
1237 ALOGD("NAN followup transid:%d pub/subId:%d reqInstId:%d", id
, msg
->publish_subscribe_id
, msg
->requestor_instance_id
);
1238 WifiRequest
request(familyId(), ifaceId());
1240 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_TXFOLLOWUP
);
1241 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "followup:Failed to create WifiRequest");
1243 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
1245 ALOGE("followup: request.attr_start fail");
1246 return WIFI_ERROR_OUT_OF_MEMORY
;
1249 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->publish_subscribe_id
,
1250 NAN_REQ_ATTR_FOLLOWUP_ID
, request
, result
, "followup:Failed to put msg->publish_subscribe_id");
1252 CHECK_CONFIG_PUT_32_RETURN_FAIL(1, msg
->requestor_instance_id
,
1253 NAN_REQ_ATTR_FOLLOWUP_REQUESTOR_ID
, request
, result
, "followup:Failed to put msg->requestor_instance_id");
1255 CHECK_CONFIG_PUT_RETURN_FAIL(1, msg
->addr
, NAN_MAC_ADDR_LEN
,
1256 NAN_REQ_ATTR_FOLLOWUP_ADDR
, request
, result
, "followup:Failed to put msg->addr");
1258 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->priority
,
1259 NAN_REQ_ATTR_FOLLOWUP_PRIORITY
, request
, result
, "followup:Failed to put msg->priority");
1261 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->dw_or_faw
,
1262 NAN_REQ_ATTR_FOLLOWUP_TX_WINDOW
, request
, result
, "followup:Failed to put msg->dw_or_faw");
1264 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->service_specific_info_len
, msg
->service_specific_info_len
,
1265 NAN_REQ_ATTR_FOLLOWUP_SERVICE_NAME_LEN
, request
, result
, "followup:Failed to put msg->service_specific_info_len");
1267 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->service_specific_info_len
, msg
->service_specific_info
, msg
->service_specific_info_len
,
1268 NAN_REQ_ATTR_FOLLOWUP_SERVICE_NAME
, request
, result
, "followup:Failed to put msg->service_specific_info");
1270 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->recv_indication_cfg
,
1271 NAN_REQ_ATTR_FOLLOWUP_RECV_IND_CFG
, request
, result
, "followup:Failed to put msg->recv_indication_cfg");
1273 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->sdea_service_specific_info_len
,
1274 NAN_REQ_ATTR_PUBLISH_SDEA_LEN
, request
, result
, "publish:Failed to put msg->sdea_service_specific_info_len");
1276 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->sdea_service_specific_info_len
, msg
->sdea_service_specific_info
, msg
->sdea_service_specific_info_len
,
1277 NAN_REQ_ATTR_PUBLISH_SDEA
, request
, result
, "publish:Failed to put msg->sdea_service_specific_info");
1279 request
.attr_end(data
);
1281 result
= requestResponse(request
);
1282 if (result
!= WIFI_SUCCESS
) {
1284 ALOGE("failed to followup; result = %d", result
);
1286 ALOGD("NAN followup...success");
1292 int getCapabilities(transaction_id id
) {
1293 ALOGD("NAN getCapabilities transId:%d", id
);
1294 WifiRequest
request(familyId(), ifaceId());
1296 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_CAPABILITIES
);
1297 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "getCapabilities:Failed to create WifiRequest");
1299 capabilitiesTid
= id
;
1300 result
= requestResponse(request
);
1301 if (result
!= WIFI_SUCCESS
) {
1302 capabilitiesTid
= 0;
1303 ALOGE("failed to getCapabilities; result = %d", result
);
1305 ALOGD("NAN getCapabilities...success");
1310 int handleEvent(WifiEvent
&event
) {
1313 if (event
.get_cmd() != NL80211_CMD_VENDOR
) {
1314 ALOGD("NAN %s Ignoring event with cmd = %d", __func__
, event
.get_cmd());
1318 int id
= event
.get_vendor_id();
1319 int subcmd
= event
.get_vendor_subcmd();
1321 ALOGI("NAN %s Id = 0x%x, subcmd = %s(0x%x)", __func__
, id
, getEventName(subcmd
), subcmd
);
1324 case SLSI_NAN_EVENT_MATCH
:
1325 ret
= processMatchEvent(event
);
1327 case SLSI_NAN_EVENT_MATCH_EXPIRED
:
1328 ret
= processMatchExpiredEvent(event
);
1330 case SLSI_NAN_EVENT_PUBLISH_TERMINATED
:
1331 ret
= processPublishTerminatedEvent(event
);
1333 case SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED
:
1334 ret
= processSubscribeTerminatedEvent(event
);
1336 case SLSI_NAN_EVENT_FOLLOWUP
:
1337 ret
= processFollowupEvent(event
);
1339 case SLSI_NAN_EVENT_DISABLED
:
1340 ret
= processNanDisabledEvent(event
);
1342 case SLSI_NAN_EVENT_DISCOVERY_ENGINE
:
1343 ret
= processNanDiscoveryEvent(event
);
1345 case SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS
:
1346 ret
= processNanFollowupStatus(event
);
1349 return datacmd
.handleEvent(event
, callbackEventHandler
);
1355 int handleResponse(WifiEvent
&reply
) {
1356 if (reply
.get_cmd() != NL80211_CMD_VENDOR
) {
1357 ALOGD("NAN %s Ignoring reply with cmd = %d", __func__
, reply
.get_cmd());
1361 NanResponseMsg response
;
1362 memset(&response
, 0, sizeof(response
));
1364 if (processResponse(reply
, &response
) == NL_SKIP
)
1367 transaction_id id
= 0;
1368 switch ((int)response
.response_type
) {
1369 case NAN_RESPONSE_PUBLISH
:
1373 case NAN_RESPONSE_ENABLED
:
1377 case NAN_RESPONSE_DISABLED
:
1381 case NAN_RESPONSE_PUBLISH_CANCEL
:
1382 id
= publishCancelTid
;
1383 publishCancelTid
= 0;
1385 case NAN_RESPONSE_SUBSCRIBE_CANCEL
:
1386 id
= subscribeCancelTid
;
1387 subscribeCancelTid
= 0;
1389 case NAN_RESPONSE_CONFIG
:
1393 case NAN_GET_CAPABILITIES
:
1394 id
= capabilitiesTid
;
1395 capabilitiesTid
= 0;
1397 case NAN_RESPONSE_SUBSCRIBE
:
1401 case NAN_RESPONSE_TRANSMIT_FOLLOWUP
:
1403 /* followupTid is required on receiving followup_up transmit status.
1404 * Do not reset followupTid here*/
1407 id
= datacmd
.getResponseTransactionId(&response
);
1409 ALOGD("NAN %s transId:%d status:%d, response:%d", __func__
, id
, response
.status
, response
.response_type
);
1410 if (callbackEventHandler
.NotifyResponse
)
1411 callbackEventHandler
.NotifyResponse(id
, &response
);
1415 int dataPathReq(u16 id
, void *data
, int subcmd
) {
1417 WifiRequest
request(familyId(), ifaceId());
1419 ALOGI("NAN DATA-PATH req subcmd:%s(0x%x) transaction_id:%d", datacmd
.getCmdName(subcmd
), subcmd
, id
);
1421 result
= datacmd
.getDataPathNLMsg(id
, data
, subcmd
, request
);
1422 if (result
!= WIFI_SUCCESS
) {
1425 result
= requestResponse(request
);
1426 if (result
!= WIFI_SUCCESS
) {
1427 ALOGE("NAN DATA-PATH req subcmd:%s(0x%x)...failed(%d)", datacmd
.getCmdName(subcmd
), subcmd
, result
);
1428 unregisterNanEvents();
1430 datacmd
.requestSuccess(id
, data
, subcmd
);
1431 ALOGD("NAN DATA-PATH req subcmd:%s(0x%x)...success", datacmd
.getCmdName(subcmd
), subcmd
);
1437 NanCallbackHandler
NanCommand::callbackEventHandler
;
1439 NanCommand
*nan_get_object(transaction_id id
,
1440 wifi_interface_handle iface
) {
1441 wifi_handle handle
= getWifiHandle(iface
);
1442 NanCommand
*nanRequest
= (NanCommand
*)wifi_get_nan_cmd(handle
);
1444 nanRequest
= new NanCommand(iface
, id
);
1446 ALOGE("Could not alloc NanCommand");
1453 wifi_error
nan_enable_request(transaction_id id
,
1454 wifi_interface_handle iface
,
1455 NanEnableRequest
*msg
) {
1456 wifi_handle handle
= getWifiHandle(iface
);
1459 NanCommand
*nanRequest
= new NanCommand(iface
, id
);
1461 ALOGE("nan_enable_request:: Unable to create NanCommand");
1462 return WIFI_ERROR_OUT_OF_MEMORY
;
1465 wifi_set_nan_cmd(handle
, nanRequest
);
1466 ret
= (wifi_error
)nanRequest
->enable(id
, msg
);
1467 if (ret
!= WIFI_SUCCESS
) {
1468 wifi_reset_nan_cmd(handle
);
1474 /* Disable NAN functionality. */
1475 wifi_error
nan_disable_request(transaction_id id
, wifi_interface_handle iface
) {
1476 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1480 return WIFI_ERROR_OUT_OF_MEMORY
;
1482 ret
= (wifi_error
)nanRequest
->disable(id
);
1483 wifi_reset_nan_cmd(getWifiHandle(iface
));
1488 /* Publish request to advertize a service. */
1489 wifi_error
nan_publish_request(transaction_id id
,
1490 wifi_interface_handle iface
,
1491 NanPublishRequest
*msg
) {
1492 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1494 return WIFI_ERROR_OUT_OF_MEMORY
;
1496 return (wifi_error
)nanRequest
->publish(id
, msg
);
1499 /* Cancel previous publish requests. */
1500 wifi_error
nan_publish_cancel_request(transaction_id id
,
1501 wifi_interface_handle iface
,
1502 NanPublishCancelRequest
*msg
) {
1503 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1505 return WIFI_ERROR_OUT_OF_MEMORY
;
1507 return (wifi_error
)nanRequest
->publishCancel(id
, msg
);
1510 /* Subscribe request to search for a service. */
1511 wifi_error
nan_subscribe_request(transaction_id id
,
1512 wifi_interface_handle iface
,
1513 NanSubscribeRequest
*msg
) {
1514 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1516 return WIFI_ERROR_OUT_OF_MEMORY
;
1518 return (wifi_error
)nanRequest
->subscribe(id
, msg
);
1521 /* Cancel previous subscribe requests. */
1522 wifi_error
nan_subscribe_cancel_request(transaction_id id
,
1523 wifi_interface_handle iface
,
1524 NanSubscribeCancelRequest
*msg
) {
1525 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1527 return WIFI_ERROR_OUT_OF_MEMORY
;
1529 return (wifi_error
)nanRequest
->subscribeCancel(id
, msg
);
1532 /* NAN transmit follow up request. */
1533 wifi_error
nan_transmit_followup_request(transaction_id id
,
1534 wifi_interface_handle iface
,
1535 NanTransmitFollowupRequest
*msg
) {
1536 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1538 return WIFI_ERROR_OUT_OF_MEMORY
;
1540 return (wifi_error
)nanRequest
->followup(id
, msg
);
1543 /* NAN configuration request. */
1544 wifi_error
nan_config_request(transaction_id id
,
1545 wifi_interface_handle iface
,
1546 NanConfigRequest
*msg
) {
1547 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1549 return WIFI_ERROR_OUT_OF_MEMORY
;
1551 return (wifi_error
)nanRequest
->config(id
, msg
);
1554 /* Register NAN callbacks. */
1555 wifi_error
nan_register_handler(wifi_interface_handle iface
,
1556 NanCallbackHandler handlers
) {
1557 return (wifi_error
)NanCommand::setCallbackHandler(handlers
);
1560 /* Get NAN HAL version. */
1561 wifi_error
nan_get_version(wifi_handle handle
,
1562 NanVersion
*version
) {
1563 return (wifi_error
)NanCommand::getVersion(version
);
1566 /* Get NAN capabilities. */
1567 wifi_error
nan_get_capabilities(transaction_id id
,
1568 wifi_interface_handle iface
) {
1569 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1571 return WIFI_ERROR_OUT_OF_MEMORY
;
1573 return (wifi_error
)nanRequest
->getCapabilities(id
);
1576 wifi_error
nan_data_interface_create(transaction_id id
,
1577 wifi_interface_handle iface
,
1579 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1581 return WIFI_ERROR_OUT_OF_MEMORY
;
1583 return (wifi_error
)nanRequest
->dataPathReq(id
, iface_name
,
1584 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_INTERFACE_CREATE
);
1587 wifi_error
nan_data_interface_delete(transaction_id id
,
1588 wifi_interface_handle iface
,
1590 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1592 return WIFI_ERROR_OUT_OF_MEMORY
;
1594 return (wifi_error
)nanRequest
->dataPathReq(id
, iface_name
,
1595 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_INTERFACE_DELETE
);
1599 wifi_error
nan_data_request_initiator(transaction_id id
,
1600 wifi_interface_handle iface
,
1601 NanDataPathInitiatorRequest
* msg
) {
1602 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1604 return WIFI_ERROR_OUT_OF_MEMORY
;
1606 return (wifi_error
)nanRequest
->dataPathReq(id
, msg
,
1607 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_REQUEST_INITIATOR
);
1611 wifi_error
nan_data_indication_response(transaction_id id
,
1612 wifi_interface_handle iface
,
1613 NanDataPathIndicationResponse
* msg
) {
1614 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1616 return WIFI_ERROR_OUT_OF_MEMORY
;
1618 return (wifi_error
)nanRequest
->dataPathReq(id
, msg
,
1619 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_INDICATION_RESPONSE
);
1623 wifi_error
nan_data_end(transaction_id id
,
1624 wifi_interface_handle iface
,
1625 NanDataPathEndRequest
* msg
) {
1626 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1628 return WIFI_ERROR_OUT_OF_MEMORY
;
1630 return (wifi_error
)nanRequest
->dataPathReq(id
, msg
,
1631 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_END
);