Commit | Line | Data |
---|---|---|
d3a587e8 JPS |
1 | |
2 | #include <stdint.h> | |
3 | #include <stddef.h> | |
4 | #include <fcntl.h> | |
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> | |
18 | ||
19 | #include "sync.h" | |
20 | ||
21 | #include <utils/Log.h> | |
22 | ||
23 | #include "wifi_hal.h" | |
24 | #include "common.h" | |
25 | #include "cpp_bindings.h" | |
c2afddcb JPS |
26 | #include "nan_data.h" |
27 | #include "nan_common.h" | |
d3a587e8 JPS |
28 | |
29 | #define SLSI_WIFI_HAL_NAN_VERSION 1 | |
30 | ||
d3a587e8 JPS |
31 | class NanCommand : public WifiCommand { |
32 | static NanCallbackHandler callbackEventHandler; | |
33 | int subscribeID[2]; | |
34 | int publishID[2]; | |
35 | int followupID[2]; | |
650a9e6a JPS |
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; | |
d3a587e8 JPS |
45 | int version; |
46 | NanCapabilities capabilities; | |
c2afddcb | 47 | NanDataCommand datacmd; |
d3a587e8 JPS |
48 | |
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); | |
650a9e6a | 56 | registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS); |
c2afddcb JPS |
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); | |
d3a587e8 JPS |
60 | } |
61 | ||
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); | |
650a9e6a | 69 | unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS); |
c2afddcb JPS |
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); | |
d3a587e8 JPS |
73 | } |
74 | ||
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); | |
d3a587e8 JPS |
78 | unsigned int val; |
79 | ||
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()); | |
84 | break; | |
85 | case NAN_REPLY_ATTR_VALUE: | |
86 | val = nl_itr.get_u32(); | |
87 | if (val) { | |
88 | strncpy(response->nan_error, "Lower_layer_error",NAN_ERROR_STR_LEN); | |
89 | } | |
90 | break; | |
91 | case NAN_REPLY_ATTR_RESPONSE_TYPE: | |
92 | response->response_type = NanResponseType(nl_itr.get_u32()); | |
93 | break; | |
94 | case NAN_REPLY_ATTR_PUBLISH_SUBSCRIBE_TYPE: | |
95 | response->body.publish_response.publish_id = nl_itr.get_u16(); | |
96 | break; | |
c2afddcb JPS |
97 | case NAN_REPLY_ATTR_NDP_INSTANCE_ID: |
98 | response->body.data_request_response.ndp_instance_id = nl_itr.get_u32(); | |
99 | break; | |
d3a587e8 JPS |
100 | case NAN_REPLY_ATTR_CAP_MAX_CONCURRENT_CLUSTER: |
101 | capabilities->max_concurrent_nan_clusters = nl_itr.get_u32(); | |
102 | break; | |
103 | case NAN_REPLY_ATTR_CAP_MAX_PUBLISHES: | |
104 | capabilities->max_publishes = nl_itr.get_u32(); | |
105 | break; | |
106 | case NAN_REPLY_ATTR_CAP_MAX_SUBSCRIBES: | |
107 | capabilities->max_subscribes = nl_itr.get_u32(); | |
108 | break; | |
109 | case NAN_REPLY_ATTR_CAP_MAX_SERVICE_NAME_LEN: | |
110 | capabilities->max_service_name_len = nl_itr.get_u32(); | |
111 | break; | |
112 | case NAN_REPLY_ATTR_CAP_MAX_MATCH_FILTER_LEN: | |
113 | capabilities->max_match_filter_len = nl_itr.get_u32(); | |
114 | break; | |
115 | case NAN_REPLY_ATTR_CAP_MAX_TOTAL_MATCH_FILTER_LEN: | |
116 | capabilities->max_total_match_filter_len = nl_itr.get_u32(); | |
117 | break; | |
118 | case NAN_REPLY_ATTR_CAP_MAX_SERVICE_SPECIFIC_INFO_LEN: | |
119 | capabilities->max_service_specific_info_len = nl_itr.get_u32(); | |
120 | break; | |
121 | case NAN_REPLY_ATTR_CAP_MAX_VSA_DATA_LEN: | |
122 | capabilities->max_vsa_data_len = nl_itr.get_u32(); | |
123 | break; | |
124 | case NAN_REPLY_ATTR_CAP_MAX_MESH_DATA_LEN: | |
125 | capabilities->max_mesh_data_len = nl_itr.get_u32(); | |
126 | break; | |
127 | case NAN_REPLY_ATTR_CAP_MAX_NDI_INTERFACES: | |
128 | capabilities->max_ndi_interfaces = nl_itr.get_u32(); | |
129 | break; | |
130 | case NAN_REPLY_ATTR_CAP_MAX_NDP_SESSIONS: | |
131 | capabilities->max_ndp_sessions = nl_itr.get_u32(); | |
132 | break; | |
133 | case NAN_REPLY_ATTR_CAP_MAX_APP_INFO_LEN: | |
134 | capabilities->max_app_info_len = nl_itr.get_u32(); | |
135 | break; | |
c2afddcb JPS |
136 | |
137 | case NAN_REPLY_ATTR_CAP_MAX_QUEUED_TRANSMIT_FOLLOWUP_MGS: | |
138 | capabilities->max_queued_transmit_followup_msgs = nl_itr.get_u32(); | |
139 | break; | |
140 | case NAN_REPLY_ATTR_CAP_MAX_NDP_SUPPORTED_BANDS: | |
141 | capabilities->ndp_supported_bands = nl_itr.get_u32(); | |
142 | break; | |
143 | case NAN_REPLY_ATTR_CAP_MAX_CIPHER_SUITES_SUPPORTED: | |
144 | capabilities->cipher_suites_supported = nl_itr.get_u32(); | |
145 | break; | |
146 | case NAN_REPLY_ATTR_CAP_MAX_SCID_LEN: | |
147 | capabilities->max_scid_len = nl_itr.get_u32(); | |
148 | break; | |
149 | case NAN_REPLY_ATTR_CAP_NDP_SECURITY_SUPPORTED: | |
150 | capabilities->is_ndp_security_supported = (bool)nl_itr.get_u32(); | |
151 | break; | |
152 | case NAN_REPLY_ATTR_CAP_MAX_SDEA_SERVICE_SPECIFIC_INFO_LEN: | |
153 | capabilities->max_sdea_service_specific_info_len = nl_itr.get_u32(); | |
154 | break; | |
155 | case NAN_REPLY_ATTR_CAP_MAX_SUBSCRIBE_ADDRESS: | |
156 | capabilities->max_subscribe_address = nl_itr.get_u32(); | |
157 | break; | |
158 | case NAN_REPLY_ATTR_CAP_NDPE_ATTR_SUPPORTED: | |
159 | capabilities->ndpe_attr_supported = nl_itr.get_u32(); | |
160 | break; | |
d3a587e8 JPS |
161 | default : |
162 | ALOGE("received unknown type(%d) in response", nl_itr.get_type()); | |
163 | return NL_SKIP; | |
164 | } | |
165 | } | |
166 | this->capabilities = *capabilities; | |
167 | return NL_OK; | |
168 | } | |
169 | ||
170 | int processMatchEvent(WifiEvent &event) { | |
171 | NanMatchInd ind; | |
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); | |
175 | ||
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(); | |
180 | break; | |
181 | case NAN_EVT_ATTR_MATCH_REQUESTOR_INSTANCE_ID: | |
182 | ind.requestor_instance_id = nl_itr.get_u32(); | |
183 | break; | |
184 | case NAN_EVT_ATTR_MATCH_ADDR: | |
185 | memcpy(ind.addr, nl_itr.get_data(), NAN_MAC_ADDR_LEN); | |
186 | break; | |
187 | case NAN_EVT_ATTR_MATCH_SERVICE_SPECIFIC_INFO_LEN: | |
188 | ind.service_specific_info_len = nl_itr.get_u16(); | |
189 | break; | |
190 | case NAN_EVT_ATTR_MATCH_SERVICE_SPECIFIC_INFO: | |
191 | memcpy(ind.service_specific_info, nl_itr.get_data(), ind.service_specific_info_len); | |
192 | break; | |
193 | case NAN_EVT_ATTR_MATCH_SDF_MATCH_FILTER_LEN: | |
194 | ind.sdf_match_filter_len = nl_itr.get_u16(); | |
195 | break; | |
196 | case NAN_EVT_ATTR_MATCH_SDF_MATCH_FILTER: | |
197 | memcpy(ind.sdf_match_filter, nl_itr.get_data(), ind.sdf_match_filter_len); | |
198 | break; | |
199 | case NAN_EVT_ATTR_MATCH_MATCH_OCCURED_FLAG: | |
200 | ind.match_occured_flag = nl_itr.get_u8(); | |
201 | break; | |
202 | case NAN_EVT_ATTR_MATCH_OUT_OF_RESOURCE_FLAG: | |
203 | ind.out_of_resource_flag = nl_itr.get_u8(); | |
204 | break; | |
205 | case NAN_EVT_ATTR_MATCH_RSSI_VALUE: | |
206 | ind.rssi_value = nl_itr.get_u8(); | |
207 | break; | |
208 | case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_IBSS_SUPPORTED: | |
209 | ind.conn_capability.is_ibss_supported = nl_itr.get_u8(); | |
210 | break; | |
211 | case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_WFD_SUPPORTED: | |
212 | ind.conn_capability.is_wfd_supported = nl_itr.get_u8(); | |
213 | break; | |
214 | case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_WFDS_SUPPORTED: | |
215 | ind.conn_capability.is_wfds_supported = nl_itr.get_u8(); | |
216 | break; | |
217 | case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_TDLS_SUPPORTED: | |
218 | ind.conn_capability.is_tdls_supported = nl_itr.get_u8(); | |
219 | break; | |
220 | case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_MESH_SUPPORTED: | |
221 | ind.conn_capability.is_mesh_supported= nl_itr.get_u8(); | |
222 | break; | |
223 | case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_WLAN_INFRA_FIELD: | |
224 | ind.conn_capability.wlan_infra_field = nl_itr.get_u8(); | |
225 | break; | |
226 | case NAN_EVT_ATTR_MATCH_NUM_RX_DISCOVERY_ATTR: | |
227 | ind.num_rx_discovery_attr = nl_itr.get_u8(); | |
228 | break; | |
229 | case NAN_EVT_ATTR_MATCH_RX_DISCOVERY_ATTR: | |
230 | NanReceivePostDiscovery *disc_attr; | |
231 | disc_attr = &ind.discovery_attr[disc_idx]; | |
232 | 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(); | |
237 | break; | |
238 | case NAN_EVT_ATTR_MATCH_DISC_ATTR_ROLE: | |
239 | disc_attr->role = (NanDeviceRole)nl_nested_itr.get_u8(); | |
240 | break; | |
241 | case NAN_EVT_ATTR_MATCH_DISC_ATTR_DURATION: | |
242 | disc_attr->duration = (NanAvailDuration)nl_nested_itr.get_u8(); | |
243 | break; | |
244 | case NAN_EVT_ATTR_MATCH_DISC_ATTR_AVAIL_INTERVAL_BITMAP: | |
245 | disc_attr->avail_interval_bitmap = nl_nested_itr.get_u32(); | |
246 | break; | |
247 | case NAN_EVT_ATTR_MATCH_DISC_ATTR_MAPID: | |
248 | disc_attr->mapid = nl_nested_itr.get_u8(); | |
249 | break; | |
250 | case NAN_EVT_ATTR_MATCH_DISC_ATTR_ADDR: | |
251 | memcpy(disc_attr->addr, nl_nested_itr.get_data(), NAN_MAC_ADDR_LEN); | |
252 | break; | |
253 | case NAN_EVT_ATTR_MATCH_DISC_ATTR_MESH_ID_LEN: | |
254 | disc_attr->mesh_id_len = nl_nested_itr.get_u8(); | |
255 | break; | |
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); | |
258 | break; | |
259 | case NAN_EVT_ATTR_MATCH_DISC_ATTR_INFRASTRUCTURE_SSID_LEN: | |
260 | disc_attr->infrastructure_ssid_len = nl_nested_itr.get_u16(); | |
261 | break; | |
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); | |
264 | break; | |
265 | } | |
266 | } | |
267 | break; | |
268 | case NAN_EVT_ATTR_MATCH_NUM_CHANS: | |
269 | ind.num_chans = nl_itr.get_u8(); | |
270 | break; | |
271 | case NAN_EVT_ATTR_MATCH_FAMCHAN: | |
272 | NanFurtherAvailabilityChannel *famchan; | |
273 | famchan = &ind.famchan[famchan_idx]; | |
274 | 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(); | |
279 | break; | |
280 | case NAN_EVT_ATTR_MATCH_FAM_CLASS_VAL: | |
281 | famchan->class_val = nl_nested_itr.get_u8(); | |
282 | break; | |
283 | case NAN_EVT_ATTR_MATCH_FAM_CHANNEL: | |
284 | famchan->channel = nl_nested_itr.get_u8(); | |
285 | break; | |
286 | case NAN_EVT_ATTR_MATCH_FAM_MAPID: | |
287 | famchan->mapid = nl_nested_itr.get_u8(); | |
288 | break; | |
289 | case NAN_EVT_ATTR_MATCH_FAM_AVAIL_INTERVAL_BITMAP: | |
290 | famchan->avail_interval_bitmap = nl_nested_itr.get_u32(); | |
291 | break; | |
292 | } | |
293 | } | |
45011ff7 | 294 | break; |
d3a587e8 JPS |
295 | case NAN_EVT_ATTR_MATCH_CLUSTER_ATTRIBUTE_LEN: |
296 | ind.cluster_attribute_len = nl_itr.get_u8(); | |
297 | break; | |
298 | case NAN_EVT_ATTR_MATCH_CLUSTER_ATTRIBUTE: | |
299 | memcpy(ind.cluster_attribute, nl_itr.get_data(), ind.cluster_attribute_len); | |
300 | break; | |
f8c9e3bb JPS |
301 | case NAN_EVT_ATTR_SDEA_LEN: |
302 | ind.sdea_service_specific_info_len = nl_itr.get_u16(); | |
303 | break; | |
304 | case NAN_EVT_ATTR_SDEA: | |
305 | memcpy(ind.sdea_service_specific_info, nl_itr.get_data(), ind.sdea_service_specific_info_len); | |
306 | break; | |
e8aa68c3 JPS |
307 | case NAN_EVT_ATTR_SCID_LEN: |
308 | ind.scid_len = nl_itr.get_u32(); | |
309 | break; | |
310 | case NAN_EVT_ATTR_SCID: | |
311 | memcpy(ind.scid, nl_itr.get_data(), ind.scid_len); | |
312 | break; | |
313 | case NAN_EVT_ATTR_SDEA_PARAM_CONFIG_NAN_DATA_PATH: | |
314 | ind.peer_sdea_params.config_nan_data_path = nl_itr.get_u8(); | |
315 | break; | |
316 | case NAN_EVT_ATTR_SDEA_PARAM_NDP_TYPE: | |
317 | ind.peer_sdea_params.ndp_type = (NdpType)nl_itr.get_u8(); | |
318 | break; | |
319 | case NAN_EVT_ATTR_SDEA_PARAM_SECURITY_CONFIG: | |
320 | ind.peer_sdea_params.security_cfg = (NanDataPathSecurityCfgStatus)nl_itr.get_u8(); | |
321 | break; | |
322 | case NAN_EVT_ATTR_SDEA_PARAM_RANGE_STATE: | |
323 | ind.peer_sdea_params.ranging_state = (NanRangingState)nl_itr.get_u8(); | |
324 | break; | |
325 | case NAN_EVT_ATTR_SDEA_PARAM_RANGE_REPORT: | |
326 | ind.peer_sdea_params.range_report = (NanRangeReport)nl_itr.get_u8(); | |
327 | break; | |
328 | case NAN_EVT_ATTR_SDEA_PARAM_QOS_CFG: | |
329 | ind.peer_sdea_params.qos_cfg = (NanQosCfgStatus)nl_itr.get_u8(); | |
330 | break; | |
331 | case NAN_EVT_ATTR_RANGE_MEASUREMENT_MM: | |
332 | ind.range_info.range_measurement_mm = nl_itr.get_u32(); | |
333 | break; | |
334 | case NAN_EVT_ATTR_RANGEING_EVENT_TYPE: | |
335 | ind.range_info.ranging_event_type = nl_itr.get_u32(); | |
336 | break; | |
d3a587e8 JPS |
337 | } |
338 | } | |
45011ff7 | 339 | |
d3a587e8 JPS |
340 | if (this->callbackEventHandler.EventMatch) |
341 | this->callbackEventHandler.EventMatch(&ind); | |
342 | return NL_OK; | |
343 | } | |
344 | ||
345 | int processMatchExpiredEvent(WifiEvent &event) { | |
346 | NanMatchExpiredInd ind; | |
347 | memset(&ind,0,sizeof(NanMatchExpiredInd)); | |
348 | ||
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(); | |
353 | break; | |
354 | case NAN_EVT_ATTR_MATCH_REQUESTOR_INSTANCE_ID: | |
355 | ind.requestor_instance_id = nl_itr.get_u32(); | |
356 | break; | |
357 | default : | |
358 | ALOGE("processMatchExpiredEvent: unknown attribute(%d)", nl_itr.get_type()); | |
359 | return NL_SKIP; | |
360 | } | |
361 | } | |
362 | ||
363 | if (callbackEventHandler.EventMatchExpired) | |
364 | callbackEventHandler.EventMatchExpired(&ind); | |
365 | ||
366 | return NL_OK; | |
367 | } | |
368 | ||
369 | int processPublishTerminatedEvent(WifiEvent &event) { | |
370 | NanPublishTerminatedInd ind; | |
371 | memset(&ind,0,sizeof(ind)); | |
372 | ||
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(); | |
377 | break; | |
378 | case NAN_EVT_ATTR_PUBLISH_REASON: | |
379 | ind.reason = (NanStatusType)nl_itr.get_u32(); | |
380 | break; | |
381 | default : | |
382 | ALOGE("processPublishTerminatedEvent: unknown attribute(%d)", nl_itr.get_type()); | |
383 | return NL_SKIP; | |
384 | } | |
385 | } | |
386 | ||
387 | if (callbackEventHandler.EventPublishTerminated) | |
388 | callbackEventHandler.EventPublishTerminated(&ind); | |
389 | ||
390 | return NL_OK; | |
391 | ||
392 | } | |
393 | ||
394 | int processSubscribeTerminatedEvent(WifiEvent &event) { | |
395 | NanSubscribeTerminatedInd ind; | |
396 | memset(&ind,0,sizeof(ind)); | |
397 | ||
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(); | |
402 | break; | |
403 | case NAN_EVT_ATTR_SUBSCRIBE_REASON: | |
404 | ind.reason = (NanStatusType)nl_itr.get_u32(); | |
405 | break; | |
406 | default : | |
407 | ALOGE("processSubscribeTerminatedEvent: unknown attribute(%d)", nl_itr.get_type()); | |
408 | return NL_SKIP; | |
409 | } | |
410 | } | |
411 | ||
412 | if (callbackEventHandler.EventSubscribeTerminated) | |
413 | callbackEventHandler.EventSubscribeTerminated(&ind); | |
414 | ||
415 | return NL_OK; | |
416 | } | |
417 | ||
418 | int processFollowupEvent(WifiEvent &event) { | |
419 | NanFollowupInd ind; | |
f8c9e3bb | 420 | nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA); |
d3a587e8 JPS |
421 | memset(&ind,0,sizeof(ind)); |
422 | ||
f8c9e3bb | 423 | for(nl_iterator nl_itr(vendor_data); nl_itr.has_next(); nl_itr.next()) { |
d3a587e8 JPS |
424 | switch(nl_itr.get_type()) { |
425 | case NAN_EVT_ATTR_FOLLOWUP_PUBLISH_SUBSCRIBE_ID: | |
426 | ind.publish_subscribe_id = nl_itr.get_u16(); | |
427 | break; | |
428 | case NAN_EVT_ATTR_FOLLOWUP_REQUESTOR_INSTANCE_ID: | |
429 | ind.requestor_instance_id = nl_itr.get_u32(); | |
430 | break; | |
431 | case NAN_EVT_ATTR_FOLLOWUP_ADDR: | |
432 | memcpy(ind.addr, nl_itr.get_data(), NAN_MAC_ADDR_LEN); | |
433 | break; | |
434 | case NAN_EVT_ATTR_FOLLOWUP_DW_OR_FAW: | |
435 | ind.dw_or_faw = nl_itr.get_u8(); | |
436 | break; | |
437 | case NAN_EVT_ATTR_FOLLOWUP_SERVICE_SPECIFIC_INFO_LEN: | |
438 | ind.service_specific_info_len = nl_itr.get_u16(); | |
439 | break; | |
440 | case NAN_EVT_ATTR_FOLLOWUP_SERVICE_SPECIFIC_INFO: | |
441 | memcpy(ind.service_specific_info, nl_itr.get_data(), ind.service_specific_info_len); | |
442 | break; | |
f8c9e3bb JPS |
443 | case NAN_EVT_ATTR_SDEA_LEN: |
444 | ind.sdea_service_specific_info_len = nl_itr.get_u16(); | |
445 | break; | |
446 | case NAN_EVT_ATTR_SDEA: | |
447 | memcpy(ind.sdea_service_specific_info, nl_itr.get_data(), ind.sdea_service_specific_info_len); | |
448 | break; | |
d3a587e8 JPS |
449 | default : |
450 | ALOGE("processNanDisabledEvent: unknown attribute(%d)", nl_itr.get_type()); | |
451 | return NL_SKIP; | |
452 | } | |
453 | } | |
454 | ||
455 | if (callbackEventHandler.EventFollowup) | |
456 | callbackEventHandler.EventFollowup(&ind); | |
457 | ||
458 | return NL_OK; | |
459 | } | |
460 | ||
461 | int processNanDisabledEvent(WifiEvent &event) { | |
462 | NanDisabledInd ind; | |
463 | memset(&ind,0,sizeof(ind)); | |
f8c9e3bb JPS |
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()) { | |
d3a587e8 JPS |
466 | switch(nl_itr.get_type()) { |
467 | case NAN_EVT_ATTR_DISABLED_REASON: | |
468 | ind.reason = (NanStatusType)nl_itr.get_u32(); | |
469 | break; | |
470 | default : | |
471 | ALOGE("processNanDisabledEvent: unknown attribute(%d)", nl_itr.get_type()); | |
472 | return NL_SKIP; | |
473 | } | |
474 | } | |
475 | ||
476 | if (callbackEventHandler.EventDisabled) | |
477 | callbackEventHandler.EventDisabled(&ind); | |
478 | ||
479 | return NL_OK; | |
480 | } | |
481 | ||
482 | int processNanDiscoveryEvent(WifiEvent &event) { | |
483 | NanDiscEngEventInd ind; | |
484 | memset(&ind,0,sizeof(ind)); | |
cdcc8b21 | 485 | u8 *addr = NULL; |
f8c9e3bb JPS |
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()) { | |
d3a587e8 JPS |
488 | switch(nl_itr.get_type()) { |
489 | case NAN_EVT_ATTR_DISCOVERY_ENGINE_EVT_TYPE: | |
490 | ind.event_type = (NanDiscEngEventType)nl_itr.get_u16(); | |
491 | break; | |
492 | case NAN_EVT_ATTR_DISCOVERY_ENGINE_MAC_ADDR: | |
493 | addr = (u8 *)nl_itr.get_data(); | |
494 | break; | |
bb0eba7e KV |
495 | case NAN_EVT_ATTR_STATUS: |
496 | break; | |
d3a587e8 JPS |
497 | default : |
498 | ALOGE("processNanDiscoveryEvent: unknown attribute(%d)", nl_itr.get_type()); | |
499 | return NL_SKIP; | |
500 | } | |
501 | } | |
cdcc8b21 JPS |
502 | if (addr) { |
503 | if (ind.event_type == NAN_EVENT_ID_DISC_MAC_ADDR) | |
504 | memcpy(ind.data.mac_addr.addr, addr, NAN_MAC_ADDR_LEN); | |
505 | else | |
506 | memcpy(ind.data.cluster.addr, addr, NAN_MAC_ADDR_LEN); | |
507 | } else { | |
508 | ALOGE("processNanDiscoveryEvent: No Mac/cluster Address"); | |
509 | } | |
d3a587e8 JPS |
510 | |
511 | if (callbackEventHandler.EventDiscEngEvent) | |
512 | callbackEventHandler.EventDiscEngEvent(&ind); | |
513 | ||
514 | return NL_OK; | |
515 | } | |
516 | ||
650a9e6a JPS |
517 | int processNanFollowupStatus(WifiEvent &event) { |
518 | NanTransmitFollowupInd ind; | |
519 | memset(&ind,0,sizeof(ind)); | |
520 | ind.id = followupTid; | |
521 | followupTid = 0; | |
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(); | |
526 | } else { | |
527 | ALOGE("processNanFollowupStatus: unknown attribute(%d)", nl_itr.get_type()); | |
528 | return NL_SKIP; | |
529 | } | |
530 | } | |
531 | ||
532 | if (callbackEventHandler.EventTransmitFollowup) | |
533 | callbackEventHandler.EventTransmitFollowup(&ind); | |
534 | ||
535 | return NL_OK; | |
536 | } | |
537 | ||
e8aa68c3 JPS |
538 | int putSdeaParams(NanSdeaCtrlParams *sdea_params, WifiRequest *request) |
539 | { | |
540 | int result; | |
541 | ||
542 | if (!sdea_params->config_nan_data_path) | |
543 | return 0; | |
544 | ||
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"); | |
547 | ||
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"); | |
550 | ||
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"); | |
553 | ||
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"); | |
556 | ||
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"); | |
559 | ||
560 | return result; | |
561 | } | |
562 | ||
563 | int putRangingCfg(NanRangingCfg *ranging_cfg, WifiRequest *request) | |
564 | { | |
565 | int result; | |
566 | ||
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"); | |
569 | ||
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"); | |
572 | ||
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"); | |
575 | ||
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"); | |
578 | ||
579 | return result; | |
580 | } | |
581 | ||
582 | int putRangeResponseCfg(NanRangeResponseCfg *range_resp_cfg, WifiRequest *request) | |
583 | { | |
584 | int result; | |
585 | ||
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"); | |
588 | ||
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"); | |
591 | ||
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"); | |
594 | ||
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"); | |
597 | ||
598 | return result; | |
599 | } | |
600 | ||
d3a587e8 JPS |
601 | public: |
602 | NanCommand(wifi_interface_handle iface, int id) | |
c2afddcb | 603 | : WifiCommand(iface, id), datacmd() |
d3a587e8 JPS |
604 | { |
605 | subscribeID[0] = 0; | |
606 | subscribeID[1] = 0; | |
607 | publishID[0] = 0; | |
608 | publishID[1] = 0; | |
609 | followupID[0] = 0; | |
650a9e6a JPS |
610 | followupID[1] = 0; |
611 | ||
612 | followupTid = 0; | |
613 | publishTid = 0; | |
614 | publishCancelTid = 0; | |
615 | subscribeTid = 0; | |
616 | subscribeCancelTid = 0; | |
617 | enableTid = 0; | |
618 | disableTid = 0; | |
619 | configTid = 0; | |
620 | capabilitiesTid = 0; | |
621 | ||
d3a587e8 JPS |
622 | version = 0; |
623 | memset(&capabilities, 0, sizeof(capabilities)); | |
624 | } | |
625 | ||
650a9e6a JPS |
626 | int enable(transaction_id id, NanEnableRequest *msg) { |
627 | ALOGD("NAN enable id:%d", id); | |
d3a587e8 JPS |
628 | WifiRequest request(familyId(), ifaceId()); |
629 | ||
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"); | |
632 | ||
633 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
634 | if (!data) { | |
635 | ALOGE("enable: request.attr_start fail"); | |
636 | return WIFI_ERROR_OUT_OF_MEMORY; | |
637 | } | |
49e66671 JPS |
638 | /* Valid master pref values are 2-254 */ |
639 | int master_pref; | |
640 | if (msg->master_pref < 2) | |
641 | master_pref = 2; | |
642 | else if (msg->master_pref > 254) | |
643 | master_pref = 254; | |
644 | else | |
645 | master_pref = msg->master_pref; | |
646 | result = request.put_u8(NAN_REQ_ATTR_MASTER_PREF, master_pref); | |
d3a587e8 JPS |
647 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put master_pref"); |
648 | ||
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"); | |
651 | ||
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"); | |
654 | ||
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"); | |
657 | ||
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"); | |
660 | ||
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"); | |
663 | ||
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"); | |
666 | ||
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"); | |
669 | ||
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"); | |
672 | ||
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"); | |
675 | ||
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"); | |
678 | ||
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"); | |
681 | ||
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"); | |
684 | ||
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"); | |
687 | ||
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"); | |
690 | ||
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"); | |
693 | ||
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"); | |
696 | ||
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"); | |
699 | ||
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"); | |
702 | ||
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"); | |
705 | ||
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"); | |
708 | ||
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"); | |
711 | ||
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"); | |
714 | ||
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"); | |
717 | ||
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"); | |
720 | ||
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"); | |
723 | ||
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"); | |
726 | ||
f8c9e3bb JPS |
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"); | |
729 | ||
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"); | |
732 | ||
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"); | |
735 | ||
c2afddcb | 736 | CHECK_CONFIG_PUT_32_RETURN_FAIL(msg->config_disc_mac_addr_randomization, msg->disc_mac_addr_rand_interval_sec, |
f8c9e3bb JPS |
737 | NAN_REQ_ATTR_DISC_MAC_ADDR_RANDOM_INTERVAL, request, result, "enable:Failed to put disc_mac_addr_rand_interval_sec"); |
738 | ||
c2afddcb JPS |
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"); | |
741 | ||
d3a587e8 JPS |
742 | request.attr_end(data); |
743 | ||
744 | registerNanEvents(); | |
650a9e6a | 745 | enableTid = id; |
d3a587e8 JPS |
746 | result = requestResponse(request); |
747 | if (result != WIFI_SUCCESS) { | |
650a9e6a | 748 | enableTid = 0; |
d3a587e8 JPS |
749 | ALOGE("failed to NAN; result = %d", result); |
750 | unregisterNanEvents(); | |
751 | } else { | |
752 | ALOGD("Start NAN...success"); | |
753 | } | |
754 | return result; | |
755 | } | |
756 | ||
650a9e6a | 757 | int disable(transaction_id id) |
d3a587e8 | 758 | { |
650a9e6a | 759 | ALOGD("NAN disable id:%d", id); |
d3a587e8 JPS |
760 | WifiRequest request(familyId(), ifaceId()); |
761 | ||
762 | unregisterNanEvents(); | |
763 | ||
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"); | |
650a9e6a | 766 | disableTid = id; |
d3a587e8 JPS |
767 | result = requestResponse(request); |
768 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "disable:Failed to requestResponse"); | |
769 | return result; | |
770 | } | |
771 | ||
650a9e6a JPS |
772 | int config(transaction_id id, NanConfigRequest *msg) { |
773 | ALOGD("NAN config id:%d", id); | |
d3a587e8 JPS |
774 | WifiRequest request(familyId(), ifaceId()); |
775 | ||
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"); | |
778 | ||
779 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
780 | if (!data) { | |
781 | ALOGE("config: request.attr_start fail"); | |
782 | return WIFI_ERROR_OUT_OF_MEMORY; | |
783 | } | |
784 | ||
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"); | |
787 | ||
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"); | |
790 | ||
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"); | |
793 | ||
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"); | |
796 | ||
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"); | |
799 | ||
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"); | |
802 | ||
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"); | |
805 | ||
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"); | |
808 | ||
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"); | |
811 | ||
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"); | |
814 | ||
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"); | |
817 | ||
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"); | |
820 | ||
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"); | |
823 | ||
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"); | |
826 | ||
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"); | |
829 | ||
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"); | |
832 | ||
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"); | |
835 | ||
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); | |
863 | } | |
864 | } | |
865 | ||
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); | |
883 | } | |
884 | } | |
885 | ||
f8c9e3bb JPS |
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"); | |
888 | ||
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"); | |
891 | ||
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"); | |
894 | ||
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"); | |
897 | ||
c2afddcb JPS |
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"); | |
900 | ||
d3a587e8 | 901 | request.attr_end(data); |
650a9e6a | 902 | configTid = id; |
d3a587e8 JPS |
903 | result = requestResponse(request); |
904 | if (result != WIFI_SUCCESS) { | |
650a9e6a | 905 | configTid = 0; |
d3a587e8 JPS |
906 | ALOGE("failed to set_config; result = %d", result); |
907 | } else { | |
49e66671 | 908 | ALOGD("NAN config...success"); |
d3a587e8 JPS |
909 | } |
910 | return result; | |
911 | } | |
912 | ||
913 | static int setCallbackHandler(NanCallbackHandler handlers) { | |
914 | callbackEventHandler = handlers; | |
915 | return WIFI_SUCCESS; | |
916 | } | |
917 | ||
918 | static int getVersion(NanVersion *version) { | |
919 | *version = SLSI_WIFI_HAL_NAN_VERSION; | |
920 | return WIFI_SUCCESS; | |
921 | } | |
922 | ||
650a9e6a JPS |
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); | |
d3a587e8 JPS |
925 | WifiRequest request(familyId(), ifaceId()); |
926 | ||
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"); | |
929 | ||
930 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
931 | if (!data) { | |
932 | ALOGE("publish: request.attr_start fail"); | |
933 | return WIFI_ERROR_OUT_OF_MEMORY; | |
934 | } | |
935 | ||
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"); | |
938 | ||
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"); | |
941 | ||
942 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg->period, | |
943 | NAN_REQ_ATTR_PUBLISH_PERIOD, request, result, "publish:Failed to put msg->period"); | |
944 | ||
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"); | |
947 | ||
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"); | |
950 | ||
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"); | |
953 | ||
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"); | |
956 | ||
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"); | |
959 | ||
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"); | |
962 | ||
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"); | |
965 | ||
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"); | |
968 | ||
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"); | |
971 | ||
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"); | |
974 | ||
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"); | |
977 | ||
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"); | |
980 | ||
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"); | |
983 | ||
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"); | |
986 | ||
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"); | |
989 | ||
f8c9e3bb JPS |
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"); | |
992 | ||
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"); | |
995 | ||
e8aa68c3 JPS |
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"); | |
998 | ||
999 | result = putSdeaParams(&msg->sdea_params, &request); | |
1000 | if (result != 0) | |
1001 | return result; | |
1002 | result = putRangingCfg(&msg->ranging_cfg, &request); | |
1003 | if (result != 0) | |
1004 | return result; | |
c2afddcb | 1005 | result = NanDataCommand::putSecurityInfo(msg->cipher_type, &msg->key_info, msg->scid_len, msg->scid, &request); |
e8aa68c3 JPS |
1006 | if (result != 0) |
1007 | return result; | |
1008 | result = putRangeResponseCfg(&msg->range_response_cfg, &request); | |
1009 | if (result != 0) | |
1010 | return result; | |
1011 | ||
d3a587e8 | 1012 | request.attr_end(data); |
650a9e6a | 1013 | publishTid = id; |
d3a587e8 JPS |
1014 | result = requestResponse(request); |
1015 | if (result != WIFI_SUCCESS) { | |
650a9e6a | 1016 | publishTid = 0; |
d3a587e8 JPS |
1017 | ALOGE("failed to publish; result = %d", result); |
1018 | } else { | |
49e66671 | 1019 | ALOGD("NAN publish...success"); |
d3a587e8 JPS |
1020 | } |
1021 | return result; | |
1022 | } | |
1023 | ||
650a9e6a JPS |
1024 | int publishCancel(transaction_id id, NanPublishCancelRequest *msg) { |
1025 | ALOGD("NAN publishCancel transId:%d, publish_id:%d", id, msg->publish_id); | |
d3a587e8 JPS |
1026 | WifiRequest request(familyId(), ifaceId()); |
1027 | ||
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"); | |
1030 | ||
1031 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
1032 | if (!data) { | |
1033 | ALOGE("publishCancel: request.attr_start fail"); | |
1034 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1035 | } | |
1036 | ||
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"); | |
1039 | ||
1040 | request.attr_end(data); | |
650a9e6a | 1041 | publishCancelTid = id; |
d3a587e8 JPS |
1042 | result = requestResponse(request); |
1043 | if (result != WIFI_SUCCESS) { | |
650a9e6a | 1044 | publishCancelTid = 0; |
d3a587e8 JPS |
1045 | ALOGE("failed to publishCancel; result = %d", result); |
1046 | } else { | |
49e66671 | 1047 | ALOGD("NAN publishCancel...success"); |
d3a587e8 JPS |
1048 | } |
1049 | return result; | |
1050 | ||
1051 | } | |
1052 | ||
650a9e6a JPS |
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); | |
d3a587e8 JPS |
1055 | WifiRequest request(familyId(), ifaceId()); |
1056 | ||
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"); | |
1059 | ||
1060 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
1061 | if (!data) { | |
1062 | ALOGE("subscribe: request.attr_start fail"); | |
1063 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1064 | } | |
1065 | ||
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"); | |
1068 | ||
1069 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg->ttl, | |
1070 | NAN_REQ_ATTR_SUBSCRIBE_TTL, request, result, "subscribe:Failed to put msg->ttl"); | |
1071 | ||
1072 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg->period, | |
1073 | NAN_REQ_ATTR_SUBSCRIBE_PERIOD, request, result, "subscribe:Failed to put msg->period"); | |
1074 | ||
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"); | |
1077 | ||
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"); | |
1080 | ||
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"); | |
1083 | ||
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"); | |
1086 | ||
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"); | |
1089 | ||
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"); | |
1092 | ||
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"); | |
1095 | ||
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"); | |
1098 | ||
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"); | |
1101 | ||
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"); | |
1104 | ||
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"); | |
1107 | ||
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"); | |
1110 | ||
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"); | |
1113 | ||
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"); | |
1116 | ||
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"); | |
1119 | ||
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"); | |
1122 | ||
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"); | |
1125 | ||
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"); | |
1128 | ||
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"); | |
1131 | ||
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"); | |
1134 | ||
f8c9e3bb JPS |
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"); | |
1137 | ||
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"); | |
1140 | ||
e8aa68c3 JPS |
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"); | |
1143 | ||
1144 | result = putSdeaParams(&msg->sdea_params, &request); | |
1145 | if (result != 0) | |
1146 | return result; | |
1147 | result = putRangingCfg(&msg->ranging_cfg, &request); | |
1148 | if (result != 0) | |
1149 | return result; | |
c2afddcb | 1150 | result = NanDataCommand::putSecurityInfo(msg->cipher_type, &msg->key_info, msg->scid_len, msg->scid, &request); |
e8aa68c3 JPS |
1151 | if (result != 0) |
1152 | return result; | |
1153 | result = putRangeResponseCfg(&msg->range_response_cfg, &request); | |
1154 | if (result != 0) | |
1155 | return result; | |
f8c9e3bb | 1156 | |
d3a587e8 | 1157 | request.attr_end(data); |
650a9e6a | 1158 | subscribeTid = id; |
d3a587e8 JPS |
1159 | result = requestResponse(request); |
1160 | if (result != WIFI_SUCCESS) { | |
650a9e6a | 1161 | subscribeTid = 0; |
d3a587e8 JPS |
1162 | ALOGE("failed to subscribe; result = %d", result); |
1163 | } else { | |
49e66671 | 1164 | ALOGD("NAN subscribe...success"); |
d3a587e8 JPS |
1165 | } |
1166 | return result; | |
1167 | ||
1168 | } | |
1169 | ||
650a9e6a JPS |
1170 | int subscribeCancel(transaction_id id, NanSubscribeCancelRequest *msg) { |
1171 | ALOGD("NAN subscribeCancel transId:%d subscribeId:%d", id, msg->subscribe_id); | |
d3a587e8 JPS |
1172 | WifiRequest request(familyId(), ifaceId()); |
1173 | ||
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"); | |
1176 | ||
1177 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
1178 | if (!data) { | |
1179 | ALOGE("subscribeCancel: request.attr_start fail"); | |
1180 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1181 | } | |
1182 | ||
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"); | |
1185 | ||
1186 | request.attr_end(data); | |
650a9e6a | 1187 | subscribeCancelTid = id; |
d3a587e8 JPS |
1188 | result = requestResponse(request); |
1189 | if (result != WIFI_SUCCESS) { | |
650a9e6a | 1190 | subscribeCancelTid = 0; |
d3a587e8 JPS |
1191 | ALOGE("failed to subscribeCancel; result = %d", result); |
1192 | } else { | |
49e66671 | 1193 | ALOGD("NAN subscribeCancel...success"); |
d3a587e8 JPS |
1194 | } |
1195 | return result; | |
1196 | } | |
1197 | ||
650a9e6a JPS |
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); | |
d3a587e8 JPS |
1200 | WifiRequest request(familyId(), ifaceId()); |
1201 | ||
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"); | |
1204 | ||
1205 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
1206 | if (!data) { | |
1207 | ALOGE("followup: request.attr_start fail"); | |
1208 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1209 | } | |
1210 | ||
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"); | |
1213 | ||
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"); | |
1216 | ||
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"); | |
1219 | ||
1220 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->priority, | |
1221 | NAN_REQ_ATTR_FOLLOWUP_PRIORITY, request, result, "followup:Failed to put msg->priority"); | |
1222 | ||
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"); | |
1225 | ||
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"); | |
1228 | ||
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"); | |
1231 | ||
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"); | |
1234 | ||
f8c9e3bb JPS |
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"); | |
1237 | ||
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"); | |
1240 | ||
d3a587e8 | 1241 | request.attr_end(data); |
650a9e6a | 1242 | followupTid = id; |
d3a587e8 JPS |
1243 | result = requestResponse(request); |
1244 | if (result != WIFI_SUCCESS) { | |
650a9e6a | 1245 | followupTid = 0; |
d3a587e8 JPS |
1246 | ALOGE("failed to followup; result = %d", result); |
1247 | } else { | |
49e66671 | 1248 | ALOGD("NAN followup...success"); |
d3a587e8 JPS |
1249 | } |
1250 | return result; | |
1251 | ||
1252 | } | |
1253 | ||
650a9e6a JPS |
1254 | int getCapabilities(transaction_id id) { |
1255 | ALOGD("NAN getCapabilities transId:%d", id); | |
d3a587e8 JPS |
1256 | WifiRequest request(familyId(), ifaceId()); |
1257 | ||
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"); | |
1260 | ||
650a9e6a | 1261 | capabilitiesTid = id; |
d3a587e8 JPS |
1262 | result = requestResponse(request); |
1263 | if (result != WIFI_SUCCESS) { | |
650a9e6a | 1264 | capabilitiesTid = 0; |
d3a587e8 JPS |
1265 | ALOGE("failed to getCapabilities; result = %d", result); |
1266 | } else { | |
49e66671 | 1267 | ALOGD("NAN getCapabilities...success"); |
d3a587e8 JPS |
1268 | } |
1269 | return result; | |
1270 | } | |
1271 | ||
1272 | int handleEvent(WifiEvent &event) { | |
1273 | int ret; | |
d3a587e8 JPS |
1274 | |
1275 | if (event.get_cmd() != NL80211_CMD_VENDOR) { | |
650a9e6a | 1276 | ALOGD("NAN %s Ignoring event with cmd = %d", __func__, event.get_cmd()); |
d3a587e8 JPS |
1277 | return NL_SKIP; |
1278 | } | |
1279 | ||
1280 | int id = event.get_vendor_id(); | |
1281 | int subcmd = event.get_vendor_subcmd(); | |
1282 | ||
650a9e6a | 1283 | ALOGI("NAN %s Id = %0x, subcmd = %d", __func__, id, subcmd); |
d3a587e8 JPS |
1284 | |
1285 | switch(subcmd) { | |
1286 | case SLSI_NAN_EVENT_MATCH: | |
1287 | ret = processMatchEvent(event); | |
1288 | break; | |
1289 | case SLSI_NAN_EVENT_MATCH_EXPIRED: | |
1290 | ret = processMatchExpiredEvent(event); | |
1291 | break; | |
1292 | case SLSI_NAN_EVENT_PUBLISH_TERMINATED: | |
1293 | ret = processPublishTerminatedEvent(event); | |
1294 | break; | |
1295 | case SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED: | |
1296 | ret = processSubscribeTerminatedEvent(event); | |
1297 | break; | |
1298 | case SLSI_NAN_EVENT_FOLLOWUP: | |
1299 | ret = processFollowupEvent(event); | |
1300 | break; | |
1301 | case SLSI_NAN_EVENT_DISABLED: | |
1302 | ret = processNanDisabledEvent(event); | |
1303 | break; | |
1304 | case SLSI_NAN_EVENT_DISCOVERY_ENGINE: | |
1305 | ret = processNanDiscoveryEvent(event); | |
1306 | break; | |
650a9e6a JPS |
1307 | case SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS: |
1308 | ret = processNanFollowupStatus(event); | |
1309 | break; | |
c2afddcb JPS |
1310 | default: |
1311 | return datacmd.handleEvent(event, callbackEventHandler); | |
d3a587e8 JPS |
1312 | } |
1313 | ||
1314 | return NL_OK; | |
1315 | } | |
1316 | ||
1317 | int handleResponse(WifiEvent &reply) { | |
d3a587e8 | 1318 | if (reply.get_cmd() != NL80211_CMD_VENDOR) { |
650a9e6a | 1319 | ALOGD("NAN %s Ignoring reply with cmd = %d", __func__, reply.get_cmd()); |
d3a587e8 JPS |
1320 | return NL_SKIP; |
1321 | } | |
1322 | ||
d3a587e8 JPS |
1323 | NanResponseMsg response; |
1324 | memset(&response, 0, sizeof(response)); | |
1325 | ||
1326 | if (processResponse(reply, &response) == NL_SKIP) | |
1327 | return NL_SKIP; | |
1328 | ||
650a9e6a JPS |
1329 | transaction_id id = 0; |
1330 | switch ((int)response.response_type) { | |
1331 | case NAN_RESPONSE_PUBLISH: | |
1332 | id = publishTid; | |
1333 | publishTid = 0; | |
1334 | break; | |
1335 | case NAN_RESPONSE_ENABLED: | |
1336 | id = enableTid; | |
1337 | enableTid = 0; | |
1338 | break; | |
1339 | case NAN_RESPONSE_DISABLED: | |
1340 | id = disableTid; | |
1341 | disableTid = 0; | |
1342 | break; | |
1343 | case NAN_RESPONSE_PUBLISH_CANCEL: | |
1344 | id = publishCancelTid; | |
1345 | publishCancelTid = 0; | |
1346 | break; | |
1347 | case NAN_RESPONSE_SUBSCRIBE_CANCEL: | |
1348 | id = subscribeCancelTid; | |
1349 | subscribeCancelTid = 0; | |
1350 | break; | |
1351 | case NAN_RESPONSE_CONFIG: | |
1352 | id = configTid; | |
1353 | configTid = 0; | |
1354 | break; | |
1355 | case NAN_GET_CAPABILITIES: | |
1356 | id = capabilitiesTid; | |
1357 | capabilitiesTid = 0; | |
1358 | break; | |
1359 | case NAN_RESPONSE_SUBSCRIBE: | |
1360 | id = subscribeTid; | |
1361 | subscribeTid = 0; | |
1362 | break; | |
1363 | case NAN_RESPONSE_TRANSMIT_FOLLOWUP: | |
1364 | id = followupTid; | |
1365 | /* followupTid is required on receiving followup_up transmit status. | |
1366 | * Do not reset followupTid here*/ | |
1367 | break; | |
c2afddcb JPS |
1368 | default: |
1369 | id = datacmd.getResponseTransactionId(&response); | |
650a9e6a JPS |
1370 | } |
1371 | ALOGD("NAN %s transId:%d status:%d, response:%d", __func__, id, response.status, response.response_type); | |
d3a587e8 | 1372 | if (callbackEventHandler.NotifyResponse) |
650a9e6a | 1373 | callbackEventHandler.NotifyResponse(id, &response); |
d3a587e8 JPS |
1374 | return NL_OK; |
1375 | } | |
c2afddcb JPS |
1376 | |
1377 | int dataPathReq(u16 id, void *data, int subcmd) { | |
1378 | int result; | |
1379 | WifiRequest request(familyId(), ifaceId()); | |
1380 | ||
082f0000 | 1381 | ALOGI("NAN DATA-PATH req subcmd:%d transaction_id:%d", subcmd, id); |
c2afddcb | 1382 | |
082f0000 | 1383 | result = datacmd.getDataPathNLMsg(id, data, subcmd, request); |
c2afddcb JPS |
1384 | if (result != WIFI_SUCCESS) { |
1385 | return result; | |
1386 | } | |
1387 | result = requestResponse(request); | |
1388 | if (result != WIFI_SUCCESS) { | |
082f0000 | 1389 | ALOGE("failed DATA-PATH req; result = %d", result); |
c2afddcb JPS |
1390 | unregisterNanEvents(); |
1391 | } else { | |
1392 | datacmd.requestSuccess(id, data, subcmd); | |
1393 | ALOGD("NAN DATA-PATH req(subcmd:%d)...success", subcmd); | |
1394 | } | |
1395 | return result; | |
1396 | } | |
d3a587e8 JPS |
1397 | }; |
1398 | ||
1399 | NanCallbackHandler NanCommand::callbackEventHandler; | |
1400 | ||
1401 | NanCommand *nan_get_object(transaction_id id, | |
1402 | wifi_interface_handle iface) { | |
1403 | wifi_handle handle = getWifiHandle(iface); | |
650a9e6a | 1404 | NanCommand *nanRequest = (NanCommand *)wifi_get_nan_cmd(handle); |
d3a587e8 JPS |
1405 | if (!nanRequest) { |
1406 | nanRequest = new NanCommand(iface, id); | |
1407 | if (!nanRequest){ | |
1408 | ALOGE("Could not alloc NanCommand"); | |
1409 | return NULL; | |
1410 | } | |
1411 | } | |
1412 | return nanRequest; | |
1413 | } | |
1414 | ||
1415 | wifi_error nan_enable_request(transaction_id id, | |
1416 | wifi_interface_handle iface, | |
1417 | NanEnableRequest *msg) { | |
1418 | wifi_handle handle = getWifiHandle(iface); | |
1419 | wifi_error ret; | |
1420 | ||
1421 | NanCommand *nanRequest = new NanCommand(iface, id); | |
1422 | if (!nanRequest) { | |
1423 | ALOGE("nan_enable_request:: Unable to create NanCommand"); | |
1424 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1425 | } | |
1426 | ||
650a9e6a JPS |
1427 | wifi_set_nan_cmd(handle, nanRequest); |
1428 | ret = (wifi_error)nanRequest->enable(id, msg); | |
d3a587e8 | 1429 | if (ret != WIFI_SUCCESS) { |
650a9e6a | 1430 | wifi_reset_nan_cmd(handle); |
d3a587e8 JPS |
1431 | delete nanRequest; |
1432 | } | |
1433 | return ret; | |
1434 | } | |
1435 | ||
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); | |
1439 | wifi_error ret; | |
1440 | ||
1441 | if (!nanRequest) { | |
1442 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1443 | } | |
650a9e6a JPS |
1444 | ret = (wifi_error)nanRequest->disable(id); |
1445 | wifi_reset_nan_cmd(getWifiHandle(iface)); | |
d3a587e8 JPS |
1446 | delete nanRequest; |
1447 | return ret; | |
1448 | } | |
1449 | ||
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); | |
1455 | if (!nanRequest) { | |
1456 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1457 | } | |
650a9e6a | 1458 | return (wifi_error)nanRequest->publish(id, msg); |
d3a587e8 JPS |
1459 | } |
1460 | ||
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); | |
1466 | if (!nanRequest) { | |
1467 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1468 | } | |
650a9e6a | 1469 | return (wifi_error)nanRequest->publishCancel(id, msg); |
d3a587e8 JPS |
1470 | } |
1471 | ||
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); | |
1477 | if (!nanRequest) { | |
1478 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1479 | } | |
650a9e6a | 1480 | return (wifi_error)nanRequest->subscribe(id, msg); |
d3a587e8 JPS |
1481 | } |
1482 | ||
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); | |
1488 | if (!nanRequest) { | |
1489 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1490 | } | |
650a9e6a | 1491 | return (wifi_error)nanRequest->subscribeCancel(id, msg); |
d3a587e8 JPS |
1492 | } |
1493 | ||
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); | |
1499 | if (!nanRequest) { | |
1500 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1501 | } | |
650a9e6a | 1502 | return (wifi_error)nanRequest->followup(id, msg); |
d3a587e8 JPS |
1503 | } |
1504 | ||
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); | |
1510 | if (!nanRequest) { | |
1511 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1512 | } | |
650a9e6a | 1513 | return (wifi_error)nanRequest->config(id, msg); |
d3a587e8 JPS |
1514 | } |
1515 | ||
1516 | /* Register NAN callbacks. */ | |
1517 | wifi_error nan_register_handler(wifi_interface_handle iface, | |
1518 | NanCallbackHandler handlers) { | |
1519 | return (wifi_error)NanCommand::setCallbackHandler(handlers); | |
1520 | } | |
1521 | ||
1522 | /* Get NAN HAL version. */ | |
1523 | wifi_error nan_get_version(wifi_handle handle, | |
1524 | NanVersion *version) { | |
1525 | return (wifi_error)NanCommand::getVersion(version); | |
1526 | } | |
1527 | ||
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); | |
1532 | if (!nanRequest) { | |
1533 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1534 | } | |
650a9e6a | 1535 | return (wifi_error)nanRequest->getCapabilities(id); |
d3a587e8 JPS |
1536 | } |
1537 | ||
c2afddcb JPS |
1538 | wifi_error nan_data_interface_create(transaction_id id, |
1539 | wifi_interface_handle iface, | |
1540 | char* iface_name) { | |
1541 | NanCommand *nanRequest = nan_get_object(id, iface); | |
1542 | if (!nanRequest) { | |
1543 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1544 | } | |
082f0000 | 1545 | return (wifi_error)nanRequest->dataPathReq(id, iface_name, |
c2afddcb JPS |
1546 | SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_INTERFACE_CREATE); |
1547 | } | |
1548 | ||
1549 | wifi_error nan_data_interface_delete(transaction_id id, | |
1550 | wifi_interface_handle iface, | |
1551 | char* iface_name) { | |
1552 | NanCommand *nanRequest = nan_get_object(id, iface); | |
1553 | if (!nanRequest) { | |
1554 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1555 | } | |
082f0000 | 1556 | return (wifi_error)nanRequest->dataPathReq(id, iface_name, |
c2afddcb JPS |
1557 | SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_INTERFACE_DELETE); |
1558 | ||
1559 | } | |
1560 | ||
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); | |
1565 | if (!nanRequest) { | |
1566 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1567 | } | |
082f0000 | 1568 | return (wifi_error)nanRequest->dataPathReq(id, msg, |
c2afddcb JPS |
1569 | SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_REQUEST_INITIATOR); |
1570 | ||
1571 | } | |
1572 | ||
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); | |
1577 | if (!nanRequest) { | |
1578 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1579 | } | |
082f0000 | 1580 | return (wifi_error)nanRequest->dataPathReq(id, msg, |
c2afddcb JPS |
1581 | SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_INDICATION_RESPONSE); |
1582 | ||
1583 | } | |
1584 | ||
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); | |
1589 | if (!nanRequest) { | |
1590 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1591 | } | |
082f0000 | 1592 | return (wifi_error)nanRequest->dataPathReq(id, msg, |
c2afddcb JPS |
1593 | SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_END); |
1594 | ||
1595 | } | |
1596 |