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]; | |
36 | int version; | |
37 | NanCapabilities capabilities; | |
c2afddcb | 38 | NanDataCommand datacmd; |
d3a587e8 JPS |
39 | |
40 | void registerNanEvents(void) { | |
41 | registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_PUBLISH_TERMINATED); | |
42 | registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_MATCH); | |
43 | registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_MATCH_EXPIRED); | |
44 | registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED); | |
45 | registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_FOLLOWUP); | |
46 | registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_DISCOVERY_ENGINE); | |
650a9e6a | 47 | registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS); |
c2afddcb JPS |
48 | registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_NDP_REQ); |
49 | registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_NDP_CFM); | |
50 | registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_NDP_END); | |
d3a587e8 JPS |
51 | } |
52 | ||
53 | void unregisterNanEvents(void) { | |
54 | unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_PUBLISH_TERMINATED); | |
55 | unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_MATCH); | |
56 | unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_MATCH_EXPIRED); | |
57 | unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED); | |
58 | unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_FOLLOWUP); | |
59 | unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_DISCOVERY_ENGINE); | |
650a9e6a | 60 | unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS); |
c2afddcb JPS |
61 | unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_NDP_REQ); |
62 | unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_NDP_CFM); | |
63 | unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_NDP_END); | |
d3a587e8 JPS |
64 | } |
65 | ||
4d2d047a JPS |
66 | static const u8 *getEventName(int event) { |
67 | switch(event) { | |
68 | case SLSI_NAN_EVENT_RESPONSE: | |
69 | return (const u8 *)"SLSI_NAN_EVENT_RESPONSE"; | |
70 | case SLSI_NAN_EVENT_PUBLISH_TERMINATED: | |
71 | return (const u8 *)"SLSI_NAN_EVENT_PUBLISH_TERMINATED"; | |
72 | case SLSI_NAN_EVENT_MATCH: | |
73 | return (const u8 *)"SLSI_NAN_EVENT_MATCH"; | |
74 | case SLSI_NAN_EVENT_MATCH_EXPIRED: | |
75 | return (const u8 *)"SLSI_NAN_EVENT_MATCH_EXPIRED"; | |
76 | case SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED: | |
77 | return (const u8 *)"SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED"; | |
78 | case SLSI_NAN_EVENT_FOLLOWUP: | |
79 | return (const u8 *)"SLSI_NAN_EVENT_FOLLOWUP"; | |
80 | case SLSI_NAN_EVENT_DISCOVERY_ENGINE: | |
81 | return (const u8 *)"SLSI_NAN_EVENT_DISCOVERY_ENGINE"; | |
82 | case SLSI_NAN_EVENT_DISABLED: | |
83 | return (const u8 *)"SLSI_NAN_EVENT_DISABLED"; | |
84 | case SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS: | |
85 | return (const u8 *)"SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS"; | |
86 | case SLSI_NAN_EVENT_NDP_REQ: | |
87 | return (const u8 *)"SLSI_NAN_EVENT_NDP_REQ"; | |
88 | case SLSI_NAN_EVENT_NDP_CFM: | |
89 | return (const u8 *)"SLSI_NAN_EVENT_NDP_CFM"; | |
90 | case SLSI_NAN_EVENT_NDP_END: | |
91 | return (const u8 *)"SLSI_NAN_EVENT_NDP_END"; | |
92 | default: | |
93 | return (const u8 *)"UNKNOWN event"; | |
94 | } | |
95 | return (const u8 *)"UNKNOWN event"; | |
96 | } | |
97 | ||
d3a587e8 JPS |
98 | int processResponse(WifiEvent &reply, NanResponseMsg *response) { |
99 | NanCapabilities *capabilities = &response->body.nan_capabilities; | |
100 | nlattr *vendor_data = reply.get_attribute(NL80211_ATTR_VENDOR_DATA); | |
d3a587e8 | 101 | unsigned int val; |
1eccec64 | 102 | transaction_id id = 0; |
d3a587e8 JPS |
103 | |
104 | for(nl_iterator nl_itr(vendor_data); nl_itr.has_next(); nl_itr.next()) { | |
105 | switch(nl_itr.get_type()) { | |
106 | case NAN_REPLY_ATTR_STATUS_TYPE: | |
107 | response->status = NanStatusType(nl_itr.get_u32()); | |
108 | break; | |
109 | case NAN_REPLY_ATTR_VALUE: | |
110 | val = nl_itr.get_u32(); | |
111 | if (val) { | |
112 | strncpy(response->nan_error, "Lower_layer_error",NAN_ERROR_STR_LEN); | |
113 | } | |
114 | break; | |
115 | case NAN_REPLY_ATTR_RESPONSE_TYPE: | |
116 | response->response_type = NanResponseType(nl_itr.get_u32()); | |
117 | break; | |
118 | case NAN_REPLY_ATTR_PUBLISH_SUBSCRIBE_TYPE: | |
119 | response->body.publish_response.publish_id = nl_itr.get_u16(); | |
120 | break; | |
c2afddcb JPS |
121 | case NAN_REPLY_ATTR_NDP_INSTANCE_ID: |
122 | response->body.data_request_response.ndp_instance_id = nl_itr.get_u32(); | |
123 | break; | |
d3a587e8 JPS |
124 | case NAN_REPLY_ATTR_CAP_MAX_CONCURRENT_CLUSTER: |
125 | capabilities->max_concurrent_nan_clusters = nl_itr.get_u32(); | |
126 | break; | |
127 | case NAN_REPLY_ATTR_CAP_MAX_PUBLISHES: | |
128 | capabilities->max_publishes = nl_itr.get_u32(); | |
129 | break; | |
130 | case NAN_REPLY_ATTR_CAP_MAX_SUBSCRIBES: | |
131 | capabilities->max_subscribes = nl_itr.get_u32(); | |
132 | break; | |
133 | case NAN_REPLY_ATTR_CAP_MAX_SERVICE_NAME_LEN: | |
134 | capabilities->max_service_name_len = nl_itr.get_u32(); | |
135 | break; | |
136 | case NAN_REPLY_ATTR_CAP_MAX_MATCH_FILTER_LEN: | |
137 | capabilities->max_match_filter_len = nl_itr.get_u32(); | |
138 | break; | |
139 | case NAN_REPLY_ATTR_CAP_MAX_TOTAL_MATCH_FILTER_LEN: | |
140 | capabilities->max_total_match_filter_len = nl_itr.get_u32(); | |
141 | break; | |
142 | case NAN_REPLY_ATTR_CAP_MAX_SERVICE_SPECIFIC_INFO_LEN: | |
143 | capabilities->max_service_specific_info_len = nl_itr.get_u32(); | |
144 | break; | |
145 | case NAN_REPLY_ATTR_CAP_MAX_VSA_DATA_LEN: | |
146 | capabilities->max_vsa_data_len = nl_itr.get_u32(); | |
147 | break; | |
148 | case NAN_REPLY_ATTR_CAP_MAX_MESH_DATA_LEN: | |
149 | capabilities->max_mesh_data_len = nl_itr.get_u32(); | |
150 | break; | |
151 | case NAN_REPLY_ATTR_CAP_MAX_NDI_INTERFACES: | |
152 | capabilities->max_ndi_interfaces = nl_itr.get_u32(); | |
153 | break; | |
154 | case NAN_REPLY_ATTR_CAP_MAX_NDP_SESSIONS: | |
155 | capabilities->max_ndp_sessions = nl_itr.get_u32(); | |
156 | break; | |
157 | case NAN_REPLY_ATTR_CAP_MAX_APP_INFO_LEN: | |
158 | capabilities->max_app_info_len = nl_itr.get_u32(); | |
159 | break; | |
c2afddcb JPS |
160 | |
161 | case NAN_REPLY_ATTR_CAP_MAX_QUEUED_TRANSMIT_FOLLOWUP_MGS: | |
162 | capabilities->max_queued_transmit_followup_msgs = nl_itr.get_u32(); | |
163 | break; | |
164 | case NAN_REPLY_ATTR_CAP_MAX_NDP_SUPPORTED_BANDS: | |
165 | capabilities->ndp_supported_bands = nl_itr.get_u32(); | |
166 | break; | |
167 | case NAN_REPLY_ATTR_CAP_MAX_CIPHER_SUITES_SUPPORTED: | |
168 | capabilities->cipher_suites_supported = nl_itr.get_u32(); | |
169 | break; | |
170 | case NAN_REPLY_ATTR_CAP_MAX_SCID_LEN: | |
171 | capabilities->max_scid_len = nl_itr.get_u32(); | |
172 | break; | |
173 | case NAN_REPLY_ATTR_CAP_NDP_SECURITY_SUPPORTED: | |
174 | capabilities->is_ndp_security_supported = (bool)nl_itr.get_u32(); | |
175 | break; | |
176 | case NAN_REPLY_ATTR_CAP_MAX_SDEA_SERVICE_SPECIFIC_INFO_LEN: | |
177 | capabilities->max_sdea_service_specific_info_len = nl_itr.get_u32(); | |
178 | break; | |
179 | case NAN_REPLY_ATTR_CAP_MAX_SUBSCRIBE_ADDRESS: | |
180 | capabilities->max_subscribe_address = nl_itr.get_u32(); | |
181 | break; | |
182 | case NAN_REPLY_ATTR_CAP_NDPE_ATTR_SUPPORTED: | |
183 | capabilities->ndpe_attr_supported = nl_itr.get_u32(); | |
184 | break; | |
1eccec64 JPS |
185 | case NAN_REPLY_ATTR_HAL_TRANSACTION_ID: |
186 | id = nl_itr.get_u16(); | |
187 | break; | |
d3a587e8 JPS |
188 | default : |
189 | ALOGE("received unknown type(%d) in response", nl_itr.get_type()); | |
1eccec64 | 190 | return -1; |
d3a587e8 JPS |
191 | } |
192 | } | |
193 | this->capabilities = *capabilities; | |
1eccec64 | 194 | return id; |
d3a587e8 JPS |
195 | } |
196 | ||
197 | int processMatchEvent(WifiEvent &event) { | |
198 | NanMatchInd ind; | |
199 | memset(&ind,0,sizeof(NanMatchInd)); | |
200 | int famchan_idx = 0, disc_idx = 0; | |
201 | nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA); | |
202 | ||
203 | for(nl_iterator nl_itr(vendor_data); nl_itr.has_next(); nl_itr.next()) { | |
204 | switch(nl_itr.get_type()) { | |
205 | case NAN_EVT_ATTR_MATCH_PUBLISH_SUBSCRIBE_ID: | |
206 | ind.publish_subscribe_id = nl_itr.get_u16(); | |
207 | break; | |
208 | case NAN_EVT_ATTR_MATCH_REQUESTOR_INSTANCE_ID: | |
209 | ind.requestor_instance_id = nl_itr.get_u32(); | |
210 | break; | |
211 | case NAN_EVT_ATTR_MATCH_ADDR: | |
212 | memcpy(ind.addr, nl_itr.get_data(), NAN_MAC_ADDR_LEN); | |
213 | break; | |
214 | case NAN_EVT_ATTR_MATCH_SERVICE_SPECIFIC_INFO_LEN: | |
215 | ind.service_specific_info_len = nl_itr.get_u16(); | |
216 | break; | |
217 | case NAN_EVT_ATTR_MATCH_SERVICE_SPECIFIC_INFO: | |
218 | memcpy(ind.service_specific_info, nl_itr.get_data(), ind.service_specific_info_len); | |
219 | break; | |
220 | case NAN_EVT_ATTR_MATCH_SDF_MATCH_FILTER_LEN: | |
221 | ind.sdf_match_filter_len = nl_itr.get_u16(); | |
222 | break; | |
223 | case NAN_EVT_ATTR_MATCH_SDF_MATCH_FILTER: | |
224 | memcpy(ind.sdf_match_filter, nl_itr.get_data(), ind.sdf_match_filter_len); | |
225 | break; | |
226 | case NAN_EVT_ATTR_MATCH_MATCH_OCCURED_FLAG: | |
227 | ind.match_occured_flag = nl_itr.get_u8(); | |
228 | break; | |
229 | case NAN_EVT_ATTR_MATCH_OUT_OF_RESOURCE_FLAG: | |
230 | ind.out_of_resource_flag = nl_itr.get_u8(); | |
231 | break; | |
232 | case NAN_EVT_ATTR_MATCH_RSSI_VALUE: | |
233 | ind.rssi_value = nl_itr.get_u8(); | |
234 | break; | |
235 | case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_IBSS_SUPPORTED: | |
236 | ind.conn_capability.is_ibss_supported = nl_itr.get_u8(); | |
237 | break; | |
238 | case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_WFD_SUPPORTED: | |
239 | ind.conn_capability.is_wfd_supported = nl_itr.get_u8(); | |
240 | break; | |
241 | case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_WFDS_SUPPORTED: | |
242 | ind.conn_capability.is_wfds_supported = nl_itr.get_u8(); | |
243 | break; | |
244 | case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_TDLS_SUPPORTED: | |
245 | ind.conn_capability.is_tdls_supported = nl_itr.get_u8(); | |
246 | break; | |
247 | case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_MESH_SUPPORTED: | |
248 | ind.conn_capability.is_mesh_supported= nl_itr.get_u8(); | |
249 | break; | |
250 | case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_WLAN_INFRA_FIELD: | |
251 | ind.conn_capability.wlan_infra_field = nl_itr.get_u8(); | |
252 | break; | |
253 | case NAN_EVT_ATTR_MATCH_NUM_RX_DISCOVERY_ATTR: | |
254 | ind.num_rx_discovery_attr = nl_itr.get_u8(); | |
255 | break; | |
256 | case NAN_EVT_ATTR_MATCH_RX_DISCOVERY_ATTR: | |
257 | NanReceivePostDiscovery *disc_attr; | |
258 | disc_attr = &ind.discovery_attr[disc_idx]; | |
259 | disc_idx++; | |
260 | for(nl_iterator nl_nested_itr((struct nlattr *)nl_itr.get_data()); nl_nested_itr.has_next(); nl_nested_itr.next()) { | |
261 | switch(nl_nested_itr.get_type()) { | |
262 | case NAN_EVT_ATTR_MATCH_DISC_ATTR_TYPE: | |
263 | disc_attr->type = (NanConnectionType)nl_nested_itr.get_u8(); | |
264 | break; | |
265 | case NAN_EVT_ATTR_MATCH_DISC_ATTR_ROLE: | |
266 | disc_attr->role = (NanDeviceRole)nl_nested_itr.get_u8(); | |
267 | break; | |
268 | case NAN_EVT_ATTR_MATCH_DISC_ATTR_DURATION: | |
269 | disc_attr->duration = (NanAvailDuration)nl_nested_itr.get_u8(); | |
270 | break; | |
271 | case NAN_EVT_ATTR_MATCH_DISC_ATTR_AVAIL_INTERVAL_BITMAP: | |
272 | disc_attr->avail_interval_bitmap = nl_nested_itr.get_u32(); | |
273 | break; | |
274 | case NAN_EVT_ATTR_MATCH_DISC_ATTR_MAPID: | |
275 | disc_attr->mapid = nl_nested_itr.get_u8(); | |
276 | break; | |
277 | case NAN_EVT_ATTR_MATCH_DISC_ATTR_ADDR: | |
278 | memcpy(disc_attr->addr, nl_nested_itr.get_data(), NAN_MAC_ADDR_LEN); | |
279 | break; | |
280 | case NAN_EVT_ATTR_MATCH_DISC_ATTR_MESH_ID_LEN: | |
281 | disc_attr->mesh_id_len = nl_nested_itr.get_u8(); | |
282 | break; | |
283 | case NAN_EVT_ATTR_MATCH_DISC_ATTR_MESH_ID: | |
284 | memcpy(disc_attr->mesh_id, nl_nested_itr.get_data(), disc_attr->mesh_id_len); | |
285 | break; | |
286 | case NAN_EVT_ATTR_MATCH_DISC_ATTR_INFRASTRUCTURE_SSID_LEN: | |
287 | disc_attr->infrastructure_ssid_len = nl_nested_itr.get_u16(); | |
288 | break; | |
289 | case NAN_EVT_ATTR_MATCH_DISC_ATTR_INFRASTRUCTURE_SSID_VAL: | |
290 | memcpy(disc_attr->infrastructure_ssid_val, nl_nested_itr.get_data(), disc_attr->infrastructure_ssid_len); | |
291 | break; | |
292 | } | |
293 | } | |
294 | break; | |
295 | case NAN_EVT_ATTR_MATCH_NUM_CHANS: | |
296 | ind.num_chans = nl_itr.get_u8(); | |
297 | break; | |
298 | case NAN_EVT_ATTR_MATCH_FAMCHAN: | |
299 | NanFurtherAvailabilityChannel *famchan; | |
300 | famchan = &ind.famchan[famchan_idx]; | |
301 | famchan_idx++; | |
302 | for(nl_iterator nl_nested_itr((struct nlattr *)nl_itr.get_data()); nl_nested_itr.has_next(); nl_nested_itr.next()) { | |
303 | switch(nl_nested_itr.get_type()) { | |
304 | case NAN_EVT_ATTR_MATCH_FAM_ENTRY_CONTROL: | |
305 | famchan->entry_control = (NanAvailDuration)nl_nested_itr.get_u8(); | |
306 | break; | |
307 | case NAN_EVT_ATTR_MATCH_FAM_CLASS_VAL: | |
308 | famchan->class_val = nl_nested_itr.get_u8(); | |
309 | break; | |
310 | case NAN_EVT_ATTR_MATCH_FAM_CHANNEL: | |
311 | famchan->channel = nl_nested_itr.get_u8(); | |
312 | break; | |
313 | case NAN_EVT_ATTR_MATCH_FAM_MAPID: | |
314 | famchan->mapid = nl_nested_itr.get_u8(); | |
315 | break; | |
316 | case NAN_EVT_ATTR_MATCH_FAM_AVAIL_INTERVAL_BITMAP: | |
317 | famchan->avail_interval_bitmap = nl_nested_itr.get_u32(); | |
318 | break; | |
319 | } | |
320 | } | |
45011ff7 | 321 | break; |
d3a587e8 JPS |
322 | case NAN_EVT_ATTR_MATCH_CLUSTER_ATTRIBUTE_LEN: |
323 | ind.cluster_attribute_len = nl_itr.get_u8(); | |
324 | break; | |
325 | case NAN_EVT_ATTR_MATCH_CLUSTER_ATTRIBUTE: | |
326 | memcpy(ind.cluster_attribute, nl_itr.get_data(), ind.cluster_attribute_len); | |
327 | break; | |
f8c9e3bb JPS |
328 | case NAN_EVT_ATTR_SDEA_LEN: |
329 | ind.sdea_service_specific_info_len = nl_itr.get_u16(); | |
330 | break; | |
331 | case NAN_EVT_ATTR_SDEA: | |
332 | memcpy(ind.sdea_service_specific_info, nl_itr.get_data(), ind.sdea_service_specific_info_len); | |
333 | break; | |
e8aa68c3 JPS |
334 | case NAN_EVT_ATTR_SCID_LEN: |
335 | ind.scid_len = nl_itr.get_u32(); | |
336 | break; | |
337 | case NAN_EVT_ATTR_SCID: | |
338 | memcpy(ind.scid, nl_itr.get_data(), ind.scid_len); | |
339 | break; | |
340 | case NAN_EVT_ATTR_SDEA_PARAM_CONFIG_NAN_DATA_PATH: | |
341 | ind.peer_sdea_params.config_nan_data_path = nl_itr.get_u8(); | |
342 | break; | |
343 | case NAN_EVT_ATTR_SDEA_PARAM_NDP_TYPE: | |
344 | ind.peer_sdea_params.ndp_type = (NdpType)nl_itr.get_u8(); | |
345 | break; | |
346 | case NAN_EVT_ATTR_SDEA_PARAM_SECURITY_CONFIG: | |
347 | ind.peer_sdea_params.security_cfg = (NanDataPathSecurityCfgStatus)nl_itr.get_u8(); | |
348 | break; | |
349 | case NAN_EVT_ATTR_SDEA_PARAM_RANGE_STATE: | |
350 | ind.peer_sdea_params.ranging_state = (NanRangingState)nl_itr.get_u8(); | |
351 | break; | |
352 | case NAN_EVT_ATTR_SDEA_PARAM_RANGE_REPORT: | |
353 | ind.peer_sdea_params.range_report = (NanRangeReport)nl_itr.get_u8(); | |
354 | break; | |
355 | case NAN_EVT_ATTR_SDEA_PARAM_QOS_CFG: | |
356 | ind.peer_sdea_params.qos_cfg = (NanQosCfgStatus)nl_itr.get_u8(); | |
357 | break; | |
358 | case NAN_EVT_ATTR_RANGE_MEASUREMENT_MM: | |
359 | ind.range_info.range_measurement_mm = nl_itr.get_u32(); | |
360 | break; | |
361 | case NAN_EVT_ATTR_RANGEING_EVENT_TYPE: | |
362 | ind.range_info.ranging_event_type = nl_itr.get_u32(); | |
363 | break; | |
d3a587e8 JPS |
364 | } |
365 | } | |
45011ff7 | 366 | |
d3a587e8 JPS |
367 | if (this->callbackEventHandler.EventMatch) |
368 | this->callbackEventHandler.EventMatch(&ind); | |
369 | return NL_OK; | |
370 | } | |
371 | ||
372 | int processMatchExpiredEvent(WifiEvent &event) { | |
373 | NanMatchExpiredInd ind; | |
374 | memset(&ind,0,sizeof(NanMatchExpiredInd)); | |
375 | ||
376 | for(nl_iterator nl_itr((struct nlattr *)event.get_vendor_data()); nl_itr.has_next(); nl_itr.next()) { | |
377 | switch(nl_itr.get_type()) { | |
378 | case NAN_EVT_ATTR_MATCH_PUBLISH_SUBSCRIBE_ID: | |
379 | ind.publish_subscribe_id = nl_itr.get_u16(); | |
380 | break; | |
381 | case NAN_EVT_ATTR_MATCH_REQUESTOR_INSTANCE_ID: | |
382 | ind.requestor_instance_id = nl_itr.get_u32(); | |
383 | break; | |
384 | default : | |
385 | ALOGE("processMatchExpiredEvent: unknown attribute(%d)", nl_itr.get_type()); | |
386 | return NL_SKIP; | |
387 | } | |
388 | } | |
389 | ||
390 | if (callbackEventHandler.EventMatchExpired) | |
391 | callbackEventHandler.EventMatchExpired(&ind); | |
392 | ||
393 | return NL_OK; | |
394 | } | |
395 | ||
396 | int processPublishTerminatedEvent(WifiEvent &event) { | |
397 | NanPublishTerminatedInd ind; | |
88140d66 | 398 | nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA); |
d3a587e8 JPS |
399 | memset(&ind,0,sizeof(ind)); |
400 | ||
88140d66 | 401 | for(nl_iterator nl_itr(vendor_data); nl_itr.has_next(); nl_itr.next()) { |
d3a587e8 JPS |
402 | switch(nl_itr.get_type()) { |
403 | case NAN_EVT_ATTR_PUBLISH_ID: | |
404 | ind.publish_id = nl_itr.get_u16(); | |
405 | break; | |
406 | case NAN_EVT_ATTR_PUBLISH_REASON: | |
407 | ind.reason = (NanStatusType)nl_itr.get_u32(); | |
408 | break; | |
88140d66 KV |
409 | case NAN_EVT_ATTR_STATUS: |
410 | break; | |
d3a587e8 JPS |
411 | default : |
412 | ALOGE("processPublishTerminatedEvent: unknown attribute(%d)", nl_itr.get_type()); | |
413 | return NL_SKIP; | |
414 | } | |
415 | } | |
416 | ||
417 | if (callbackEventHandler.EventPublishTerminated) | |
418 | callbackEventHandler.EventPublishTerminated(&ind); | |
419 | ||
420 | return NL_OK; | |
421 | ||
422 | } | |
423 | ||
424 | int processSubscribeTerminatedEvent(WifiEvent &event) { | |
425 | NanSubscribeTerminatedInd ind; | |
88140d66 | 426 | nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA); |
d3a587e8 JPS |
427 | memset(&ind,0,sizeof(ind)); |
428 | ||
88140d66 | 429 | for(nl_iterator nl_itr(vendor_data); nl_itr.has_next(); nl_itr.next()) { |
d3a587e8 JPS |
430 | switch(nl_itr.get_type()) { |
431 | case NAN_EVT_ATTR_SUBSCRIBE_ID: | |
432 | ind.subscribe_id = nl_itr.get_u16(); | |
433 | break; | |
434 | case NAN_EVT_ATTR_SUBSCRIBE_REASON: | |
435 | ind.reason = (NanStatusType)nl_itr.get_u32(); | |
436 | break; | |
88140d66 KV |
437 | case NAN_EVT_ATTR_STATUS: |
438 | break; | |
d3a587e8 JPS |
439 | default : |
440 | ALOGE("processSubscribeTerminatedEvent: unknown attribute(%d)", nl_itr.get_type()); | |
441 | return NL_SKIP; | |
442 | } | |
443 | } | |
444 | ||
445 | if (callbackEventHandler.EventSubscribeTerminated) | |
446 | callbackEventHandler.EventSubscribeTerminated(&ind); | |
447 | ||
448 | return NL_OK; | |
449 | } | |
450 | ||
451 | int processFollowupEvent(WifiEvent &event) { | |
452 | NanFollowupInd ind; | |
f8c9e3bb | 453 | nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA); |
d3a587e8 JPS |
454 | memset(&ind,0,sizeof(ind)); |
455 | ||
f8c9e3bb | 456 | for(nl_iterator nl_itr(vendor_data); nl_itr.has_next(); nl_itr.next()) { |
d3a587e8 JPS |
457 | switch(nl_itr.get_type()) { |
458 | case NAN_EVT_ATTR_FOLLOWUP_PUBLISH_SUBSCRIBE_ID: | |
459 | ind.publish_subscribe_id = nl_itr.get_u16(); | |
460 | break; | |
461 | case NAN_EVT_ATTR_FOLLOWUP_REQUESTOR_INSTANCE_ID: | |
462 | ind.requestor_instance_id = nl_itr.get_u32(); | |
463 | break; | |
464 | case NAN_EVT_ATTR_FOLLOWUP_ADDR: | |
465 | memcpy(ind.addr, nl_itr.get_data(), NAN_MAC_ADDR_LEN); | |
466 | break; | |
467 | case NAN_EVT_ATTR_FOLLOWUP_DW_OR_FAW: | |
468 | ind.dw_or_faw = nl_itr.get_u8(); | |
469 | break; | |
470 | case NAN_EVT_ATTR_FOLLOWUP_SERVICE_SPECIFIC_INFO_LEN: | |
471 | ind.service_specific_info_len = nl_itr.get_u16(); | |
472 | break; | |
473 | case NAN_EVT_ATTR_FOLLOWUP_SERVICE_SPECIFIC_INFO: | |
474 | memcpy(ind.service_specific_info, nl_itr.get_data(), ind.service_specific_info_len); | |
475 | break; | |
f8c9e3bb JPS |
476 | case NAN_EVT_ATTR_SDEA_LEN: |
477 | ind.sdea_service_specific_info_len = nl_itr.get_u16(); | |
478 | break; | |
479 | case NAN_EVT_ATTR_SDEA: | |
480 | memcpy(ind.sdea_service_specific_info, nl_itr.get_data(), ind.sdea_service_specific_info_len); | |
481 | break; | |
d3a587e8 JPS |
482 | default : |
483 | ALOGE("processNanDisabledEvent: unknown attribute(%d)", nl_itr.get_type()); | |
484 | return NL_SKIP; | |
485 | } | |
486 | } | |
487 | ||
488 | if (callbackEventHandler.EventFollowup) | |
489 | callbackEventHandler.EventFollowup(&ind); | |
490 | ||
491 | return NL_OK; | |
492 | } | |
493 | ||
494 | int processNanDisabledEvent(WifiEvent &event) { | |
495 | NanDisabledInd ind; | |
496 | memset(&ind,0,sizeof(ind)); | |
f8c9e3bb JPS |
497 | nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA); |
498 | for(nl_iterator nl_itr(vendor_data); nl_itr.has_next(); nl_itr.next()) { | |
d3a587e8 JPS |
499 | switch(nl_itr.get_type()) { |
500 | case NAN_EVT_ATTR_DISABLED_REASON: | |
501 | ind.reason = (NanStatusType)nl_itr.get_u32(); | |
502 | break; | |
503 | default : | |
504 | ALOGE("processNanDisabledEvent: unknown attribute(%d)", nl_itr.get_type()); | |
505 | return NL_SKIP; | |
506 | } | |
507 | } | |
508 | ||
509 | if (callbackEventHandler.EventDisabled) | |
510 | callbackEventHandler.EventDisabled(&ind); | |
511 | ||
512 | return NL_OK; | |
513 | } | |
514 | ||
515 | int processNanDiscoveryEvent(WifiEvent &event) { | |
516 | NanDiscEngEventInd ind; | |
517 | memset(&ind,0,sizeof(ind)); | |
cdcc8b21 | 518 | u8 *addr = NULL; |
f8c9e3bb JPS |
519 | nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA); |
520 | for(nl_iterator nl_itr(vendor_data); nl_itr.has_next(); nl_itr.next()) { | |
d3a587e8 JPS |
521 | switch(nl_itr.get_type()) { |
522 | case NAN_EVT_ATTR_DISCOVERY_ENGINE_EVT_TYPE: | |
523 | ind.event_type = (NanDiscEngEventType)nl_itr.get_u16(); | |
524 | break; | |
525 | case NAN_EVT_ATTR_DISCOVERY_ENGINE_MAC_ADDR: | |
526 | addr = (u8 *)nl_itr.get_data(); | |
527 | break; | |
13bc1fa6 KV |
528 | case NAN_EVT_ATTR_STATUS: |
529 | break; | |
d3a587e8 JPS |
530 | default : |
531 | ALOGE("processNanDiscoveryEvent: unknown attribute(%d)", nl_itr.get_type()); | |
532 | return NL_SKIP; | |
533 | } | |
534 | } | |
cdcc8b21 JPS |
535 | if (addr) { |
536 | if (ind.event_type == NAN_EVENT_ID_DISC_MAC_ADDR) | |
537 | memcpy(ind.data.mac_addr.addr, addr, NAN_MAC_ADDR_LEN); | |
538 | else | |
539 | memcpy(ind.data.cluster.addr, addr, NAN_MAC_ADDR_LEN); | |
540 | } else { | |
541 | ALOGE("processNanDiscoveryEvent: No Mac/cluster Address"); | |
542 | } | |
d3a587e8 JPS |
543 | |
544 | if (callbackEventHandler.EventDiscEngEvent) | |
545 | callbackEventHandler.EventDiscEngEvent(&ind); | |
546 | ||
547 | return NL_OK; | |
548 | } | |
549 | ||
650a9e6a JPS |
550 | int processNanFollowupStatus(WifiEvent &event) { |
551 | NanTransmitFollowupInd ind; | |
552 | memset(&ind,0,sizeof(ind)); | |
650a9e6a JPS |
553 | nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA); |
554 | for(nl_iterator nl_itr(vendor_data); nl_itr.has_next(); nl_itr.next()) { | |
555 | if (nl_itr.get_type() == NAN_EVT_ATTR_STATUS) { | |
556 | ind.reason = (NanStatusType)nl_itr.get_u16(); | |
1eccec64 JPS |
557 | } else if(nl_itr.get_type() == NAN_EVT_ATTR_HAL_TRANSACTION_ID) { |
558 | ind.id = nl_itr.get_u16(); | |
559 | }else { | |
650a9e6a JPS |
560 | ALOGE("processNanFollowupStatus: unknown attribute(%d)", nl_itr.get_type()); |
561 | return NL_SKIP; | |
562 | } | |
563 | } | |
564 | ||
565 | if (callbackEventHandler.EventTransmitFollowup) | |
566 | callbackEventHandler.EventTransmitFollowup(&ind); | |
567 | ||
568 | return NL_OK; | |
569 | } | |
570 | ||
e8aa68c3 JPS |
571 | int putSdeaParams(NanSdeaCtrlParams *sdea_params, WifiRequest *request) |
572 | { | |
573 | int result; | |
574 | ||
575 | if (!sdea_params->config_nan_data_path) | |
576 | return 0; | |
577 | ||
578 | result = request->put_u8(NAN_REQ_ATTR_SDEA_PARAM_NDP_TYPE, sdea_params->ndp_type); | |
579 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put SDEA PARAM ndp_type"); | |
580 | ||
581 | result = request->put_u8(NAN_REQ_ATTR_SDEA_PARAM_SECURITY_CFG, sdea_params->security_cfg); | |
582 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put SDEA PARAM security_cfg"); | |
583 | ||
584 | result = request->put_u8(NAN_REQ_ATTR_SDEA_PARAM_RANGING_STATE, sdea_params->ranging_state); | |
585 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put SDEA PARAM ranging_state"); | |
586 | ||
587 | result = request->put_u8(NAN_REQ_ATTR_SDEA_PARAM_RANGE_REPORT, sdea_params->range_report); | |
588 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put SDEA PARAM range_report"); | |
589 | ||
590 | result = request->put_u8(NAN_REQ_ATTR_SDEA_PARAM_QOS_CFG, sdea_params->qos_cfg); | |
591 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put SDEA PARAM qos_cfg"); | |
592 | ||
593 | return result; | |
594 | } | |
595 | ||
596 | int putRangingCfg(NanRangingCfg *ranging_cfg, WifiRequest *request) | |
597 | { | |
598 | int result; | |
599 | ||
600 | result = request->put_u32(NAN_REQ_ATTR_RANGING_CFG_INTERVAL, ranging_cfg->ranging_interval_msec); | |
601 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put Ranging CFG ranging_interval_msec"); | |
602 | ||
603 | result = request->put_u32(NAN_REQ_ATTR_RANGING_CFG_INDICATION, ranging_cfg->config_ranging_indications); | |
604 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put Ranging CFG config_ranging_indications"); | |
605 | ||
606 | result = request->put_u32(NAN_REQ_ATTR_RANGING_CFG_INGRESS_MM, ranging_cfg->distance_ingress_mm); | |
607 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put Ranging CFG distance_ingress_mm"); | |
608 | ||
609 | result = request->put_u32(NAN_REQ_ATTR_RANGING_CFG_EGRESS_MM, ranging_cfg->distance_egress_mm); | |
610 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put Ranging CFG distance_egress_mm"); | |
611 | ||
612 | return result; | |
613 | } | |
614 | ||
615 | int putRangeResponseCfg(NanRangeResponseCfg *range_resp_cfg, WifiRequest *request) | |
616 | { | |
617 | int result; | |
618 | ||
619 | result = request->put_u16(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_PUBLISH_ID, range_resp_cfg->publish_id); | |
620 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "Failed to put range response cfg::publish_id"); | |
621 | ||
622 | result = request->put_u32(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_REQUESTOR_ID, range_resp_cfg->requestor_instance_id); | |
623 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "Failed to put range response cfg::requestor_instance_id"); | |
624 | ||
625 | result = request->put_addr(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_PEER_ADDR, range_resp_cfg->peer_addr); | |
626 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "Failed to put range response cfg::peer_addr"); | |
627 | ||
628 | result = request->put_u16(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_RANGING_RESPONSE, range_resp_cfg->ranging_response); | |
629 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "Failed to put range response cfg::ranging_response"); | |
630 | ||
631 | return result; | |
632 | } | |
633 | ||
d3a587e8 JPS |
634 | public: |
635 | NanCommand(wifi_interface_handle iface, int id) | |
c2afddcb | 636 | : WifiCommand(iface, id), datacmd() |
d3a587e8 JPS |
637 | { |
638 | subscribeID[0] = 0; | |
639 | subscribeID[1] = 0; | |
640 | publishID[0] = 0; | |
641 | publishID[1] = 0; | |
642 | followupID[0] = 0; | |
650a9e6a JPS |
643 | followupID[1] = 0; |
644 | ||
d3a587e8 JPS |
645 | version = 0; |
646 | memset(&capabilities, 0, sizeof(capabilities)); | |
647 | } | |
648 | ||
650a9e6a JPS |
649 | int enable(transaction_id id, NanEnableRequest *msg) { |
650 | ALOGD("NAN enable id:%d", id); | |
d3a587e8 JPS |
651 | WifiRequest request(familyId(), ifaceId()); |
652 | ||
653 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_NAN_ENABLE); | |
654 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to create WifiRequest"); | |
655 | ||
656 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
657 | if (!data) { | |
658 | ALOGE("enable: request.attr_start fail"); | |
659 | return WIFI_ERROR_OUT_OF_MEMORY; | |
660 | } | |
49e66671 JPS |
661 | /* Valid master pref values are 2-254 */ |
662 | int master_pref; | |
663 | if (msg->master_pref < 2) | |
664 | master_pref = 2; | |
665 | else if (msg->master_pref > 254) | |
666 | master_pref = 254; | |
667 | else | |
668 | master_pref = msg->master_pref; | |
669 | result = request.put_u8(NAN_REQ_ATTR_MASTER_PREF, master_pref); | |
d3a587e8 JPS |
670 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put master_pref"); |
671 | ||
672 | result = request.put_u16(NAN_REQ_ATTR_CLUSTER_LOW, msg->cluster_low); | |
673 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put cluster_low"); | |
674 | ||
675 | result = request.put_u16(NAN_REQ_ATTR_CLUSTER_HIGH, msg->cluster_high); | |
676 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put cluster_high"); | |
677 | ||
678 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_support_5g, msg->support_5g_val, | |
679 | NAN_REQ_ATTR_SUPPORT_5G_VAL, request, result, "enable:Failed to put support_5g_val"); | |
680 | ||
681 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_sid_beacon, msg->sid_beacon_val, | |
682 | NAN_REQ_ATTR_SID_BEACON_VAL, request, result, "enable:Failed to put sid_beacon_val"); | |
683 | ||
684 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_2dot4g_rssi_close, msg->rssi_close_2dot4g_val, | |
685 | NAN_REQ_ATTR_RSSI_CLOSE_2G4_VAL, request, result, "enable:Failed to put rssi_close_2dot4g_val"); | |
686 | ||
687 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_2dot4g_rssi_middle, msg->rssi_middle_2dot4g_val, | |
688 | NAN_REQ_ATTR_RSSI_MIDDLE_2G4_VAL, request, result, "enable:Failed to put rssi_middle_2dot4g_val"); | |
689 | ||
690 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_2dot4g_rssi_proximity, msg->rssi_proximity_2dot4g_val, | |
691 | NAN_REQ_ATTR_RSSI_PROXIMITY_2G4_VAL, request, result, "enable:Failed to put rssi_proximity_2dot4g_val"); | |
692 | ||
693 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_hop_count_limit, msg->hop_count_limit_val, | |
694 | NAN_REQ_ATTR_HOP_COUNT_LIMIT_VAL, request, result, "enable:Failed to put hop_count_limit_val"); | |
695 | ||
696 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_2dot4g_support, msg->support_2dot4g_val, | |
697 | NAN_REQ_ATTR_SUPPORT_2G4_VAL, request, result, "enable:Failed to put support_2dot4g_val"); | |
698 | ||
699 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_2dot4g_beacons, msg->beacon_2dot4g_val, | |
700 | NAN_REQ_ATTR_BEACONS_2G4_VAL, request, result, "enable:Failed to put beacon_2dot4g_val"); | |
701 | ||
702 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_2dot4g_sdf, msg->sdf_2dot4g_val, | |
703 | NAN_REQ_ATTR_SDF_2G4_VAL, request, result, "enable:Failed to put sdf_2dot4g_val"); | |
704 | ||
705 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_5g_beacons, msg->beacon_5g_val, | |
706 | NAN_REQ_ATTR_BEACON_5G_VAL, request, result, "enable:Failed to put beacon_5g_val"); | |
707 | ||
708 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_5g_sdf, msg->sdf_5g_val, | |
709 | NAN_REQ_ATTR_SDF_5G_VAL, request, result, "enable:Failed to put sdf_5g_val"); | |
710 | ||
711 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_5g_rssi_close, msg->rssi_close_5g_val, | |
712 | NAN_REQ_ATTR_RSSI_CLOSE_5G_VAL, request, result, "enable:Failed to put rssi_close_5g_val"); | |
713 | ||
714 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_5g_rssi_middle, msg->rssi_middle_5g_val, | |
715 | NAN_REQ_ATTR_RSSI_MIDDLE_5G_VAL, request, result, "enable:Failed to put rssi_middle_5g_val"); | |
716 | ||
717 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_5g_rssi_close_proximity, msg->rssi_close_proximity_5g_val, | |
718 | NAN_REQ_ATTR_RSSI_CLOSE_PROXIMITY_5G_VAL, request, result, "enable:Failed to put rssi_close_proximity_5g_val"); | |
719 | ||
720 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_rssi_window_size, msg->rssi_window_size_val, | |
721 | NAN_REQ_ATTR_RSSI_WINDOW_SIZE_VAL, request, result, "enable:Failed to put rssi_window_size_val"); | |
722 | ||
723 | CHECK_CONFIG_PUT_32_RETURN_FAIL(msg->config_oui, msg->oui_val, | |
724 | NAN_REQ_ATTR_OUI_VAL, request, result, "enable:Failed to put oui_val"); | |
725 | ||
726 | CHECK_CONFIG_PUT_RETURN_FAIL(msg->config_intf_addr, msg->intf_addr_val, NAN_MAC_ADDR_LEN, | |
727 | NAN_REQ_ATTR_MAC_ADDR_VAL, request, result, "enable:Failed to put intf_addr_val"); | |
728 | ||
729 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->config_cluster_attribute_val, | |
730 | NAN_REQ_ATTR_CLUSTER_VAL, request, result, "enable:Failed to put config_cluster_attribute_val"); | |
731 | ||
732 | CHECK_CONFIG_PUT_RETURN_FAIL(msg->config_scan_params, msg->scan_params_val.dwell_time, sizeof(msg->scan_params_val.dwell_time), | |
733 | NAN_REQ_ATTR_SOCIAL_CH_SCAN_DWELL_TIME, request, result, "enable:Failed to put scan_params_val.dwell_time"); | |
734 | ||
735 | CHECK_CONFIG_PUT_RETURN_FAIL(msg->config_scan_params, msg->scan_params_val.scan_period, sizeof(msg->scan_params_val.scan_period), | |
736 | NAN_REQ_ATTR_SOCIAL_CH_SCAN_PERIOD, request, result, "enable:Failed to put scan_params_val.scan_period"); | |
737 | ||
738 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_random_factor_force, msg->random_factor_force_val, | |
739 | NAN_REQ_ATTR_RANDOM_FACTOR_FORCE_VAL, request, result, "enable:Failed to put random_factor_force_val"); | |
740 | ||
741 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_hop_count_force, msg->hop_count_force_val, | |
742 | NAN_REQ_ATTR_HOP_COUNT_FORCE_VAL, request, result, "enable:Failed to put hop_count_force_val"); | |
743 | ||
744 | CHECK_CONFIG_PUT_32_RETURN_FAIL(msg->config_24g_channel, msg->channel_24g_val, | |
745 | NAN_REQ_ATTR_CHANNEL_2G4_MHZ_VAL, request, result, "enable:Failed to put channel_24g_val"); | |
746 | ||
747 | CHECK_CONFIG_PUT_32_RETURN_FAIL(msg->config_5g_channel, msg->channel_5g_val, | |
748 | NAN_REQ_ATTR_CHANNEL_5G_MHZ_VAL, request, result, "enable:Failed to put channel_5g_val"); | |
749 | ||
f8c9e3bb JPS |
750 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_subscribe_sid_beacon, msg->subscribe_sid_beacon_val, |
751 | NAN_REQ_ATTR_SUBSCRIBE_SID_BEACON_VAL, request, result, "enable:Failed to put subscribe_sid_beacon_val"); | |
752 | ||
753 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_dw.config_2dot4g_dw_band, msg->config_dw.dw_2dot4g_interval_val, | |
754 | NAN_REQ_ATTR_DW_2G4_INTERVAL, request, result, "enable:Failed to put dw_2dot4g_interval_val"); | |
755 | ||
756 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_dw.config_5g_dw_band, msg->config_dw.dw_5g_interval_val, | |
757 | NAN_REQ_ATTR_DW_5G_INTERVAL, request, result, "enable:Failed to put dw_5g_interval_val"); | |
758 | ||
c2afddcb | 759 | CHECK_CONFIG_PUT_32_RETURN_FAIL(msg->config_disc_mac_addr_randomization, msg->disc_mac_addr_rand_interval_sec, |
f8c9e3bb JPS |
760 | NAN_REQ_ATTR_DISC_MAC_ADDR_RANDOM_INTERVAL, request, result, "enable:Failed to put disc_mac_addr_rand_interval_sec"); |
761 | ||
c2afddcb JPS |
762 | CHECK_CONFIG_PUT_32_RETURN_FAIL(msg->config_ndpe_attr, msg->use_ndpe_attr, |
763 | NAN_REQ_ATTR_USE_NDPE_ATTR, request, result, "enable:Failed to put use_ndpe_attr"); | |
764 | ||
1eccec64 JPS |
765 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id, NAN_REQ_ATTR_HAL_TRANSACTION_ID, request, result, "enable:Failed to put transaction id"); |
766 | ||
d3a587e8 JPS |
767 | request.attr_end(data); |
768 | ||
769 | registerNanEvents(); | |
d3a587e8 JPS |
770 | result = requestResponse(request); |
771 | if (result != WIFI_SUCCESS) { | |
772 | ALOGE("failed to NAN; result = %d", result); | |
773 | unregisterNanEvents(); | |
774 | } else { | |
775 | ALOGD("Start NAN...success"); | |
776 | } | |
777 | return result; | |
778 | } | |
779 | ||
650a9e6a | 780 | int disable(transaction_id id) |
d3a587e8 | 781 | { |
650a9e6a | 782 | ALOGD("NAN disable id:%d", id); |
d3a587e8 JPS |
783 | WifiRequest request(familyId(), ifaceId()); |
784 | ||
785 | unregisterNanEvents(); | |
786 | ||
787 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_NAN_DISABLE); | |
788 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "disable:Failed to create WifiRequest"); | |
1eccec64 JPS |
789 | |
790 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
791 | if (!data) { | |
792 | ALOGE("enable: request.attr_start fail"); | |
793 | return WIFI_ERROR_OUT_OF_MEMORY; | |
794 | } | |
795 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id, NAN_REQ_ATTR_HAL_TRANSACTION_ID, request, result, "disable:Failed to put transaction id"); | |
796 | request.attr_end(data); | |
d3a587e8 JPS |
797 | result = requestResponse(request); |
798 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "disable:Failed to requestResponse"); | |
799 | return result; | |
800 | } | |
801 | ||
650a9e6a JPS |
802 | int config(transaction_id id, NanConfigRequest *msg) { |
803 | ALOGD("NAN config id:%d", id); | |
d3a587e8 JPS |
804 | WifiRequest request(familyId(), ifaceId()); |
805 | ||
806 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_NAN_CONFIG); | |
807 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "config:Failed to create WifiRequest"); | |
808 | ||
809 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
810 | if (!data) { | |
811 | ALOGE("config: request.attr_start fail"); | |
812 | return WIFI_ERROR_OUT_OF_MEMORY; | |
813 | } | |
814 | ||
815 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_sid_beacon, msg->sid_beacon, | |
816 | NAN_REQ_ATTR_SID_BEACON_VAL, request, result, "config:Failed to put sid_beacon"); | |
817 | ||
818 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_rssi_proximity, msg->rssi_proximity, | |
819 | NAN_REQ_ATTR_RSSI_PROXIMITY_2G4_VAL, request, result, "config:Failed to put rssi_proximity"); | |
820 | ||
821 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_master_pref, msg->master_pref, | |
822 | NAN_REQ_ATTR_MASTER_PREF, request, result, "config:Failed to put master_pref"); | |
823 | ||
824 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_5g_rssi_close_proximity, msg->rssi_close_proximity_5g_val, | |
825 | NAN_REQ_ATTR_RSSI_CLOSE_PROXIMITY_5G_VAL, request, result, "config:Failed to put rssi_close_proximity_5g_val"); | |
826 | ||
827 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_rssi_window_size, msg->rssi_window_size_val, | |
828 | NAN_REQ_ATTR_RSSI_WINDOW_SIZE_VAL, request, result, "config:Failed to put rssi_window_size_val"); | |
829 | ||
830 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->config_cluster_attribute_val, | |
831 | NAN_REQ_ATTR_CLUSTER_VAL, request, result, "config:Failed to put config_cluster_attribute_val"); | |
832 | ||
833 | CHECK_CONFIG_PUT_RETURN_FAIL(msg->config_scan_params, msg->scan_params_val.dwell_time, sizeof(msg->scan_params_val.dwell_time), | |
834 | NAN_REQ_ATTR_SOCIAL_CH_SCAN_DWELL_TIME, request, result, "config:Failed to put scan_params_val.dwell_time"); | |
835 | ||
836 | CHECK_CONFIG_PUT_RETURN_FAIL(msg->config_scan_params, msg->scan_params_val.scan_period, sizeof(msg->scan_params_val.scan_period), | |
837 | NAN_REQ_ATTR_SOCIAL_CH_SCAN_PERIOD, request, result, "config:Failed to put scan_params_val.scan_period"); | |
838 | ||
839 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_random_factor_force, msg->random_factor_force_val, | |
840 | NAN_REQ_ATTR_RANDOM_FACTOR_FORCE_VAL, request, result, "config:Failed to put random_factor_force_val"); | |
841 | ||
842 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_hop_count_force, msg->hop_count_force_val, | |
843 | NAN_REQ_ATTR_HOP_COUNT_FORCE_VAL, request, result, "config:Failed to put hop_count_force_val"); | |
844 | ||
845 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_conn_capability, msg->conn_capability_val.payload_transmit_flag, | |
846 | NAN_REQ_ATTR_CONN_CAPABILITY_PAYLOAD_TX, request, result, "config:Failed to put payload_transmit_flag"); | |
847 | ||
848 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_conn_capability, msg->conn_capability_val.is_wfd_supported, | |
849 | NAN_REQ_ATTR_CONN_CAPABILITY_WFD, request, result, "config:Failed to put is_wfd_supported"); | |
850 | ||
851 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_conn_capability, msg->conn_capability_val.is_wfds_supported, | |
852 | NAN_REQ_ATTR_CONN_CAPABILITY_WFDS, request, result, "config:Failed to put is_wfds_supported"); | |
853 | ||
854 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_conn_capability, msg->conn_capability_val.is_tdls_supported, | |
855 | NAN_REQ_ATTR_CONN_CAPABILITY_TDLS, request, result, "config:Failed to put is_tdls_supported"); | |
856 | ||
857 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_conn_capability, msg->conn_capability_val.is_ibss_supported, | |
858 | NAN_REQ_ATTR_CONN_CAPABILITY_IBSS, request, result, "config:Failed to put is_ibss_supported"); | |
859 | ||
860 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_conn_capability, msg->conn_capability_val.is_mesh_supported, | |
861 | NAN_REQ_ATTR_CONN_CAPABILITY_MESH, request, result, "config:Failed to put is_mesh_supported"); | |
862 | ||
863 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_conn_capability, msg->conn_capability_val.wlan_infra_field, | |
864 | NAN_REQ_ATTR_CONN_CAPABILITY_WLAN_INFRA, request, result, "config:Failed to put wlan_infra_field"); | |
865 | ||
866 | if (msg->num_config_discovery_attr) { | |
867 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->num_config_discovery_attr, | |
868 | NAN_REQ_ATTR_DISCOVERY_ATTR_NUM_ENTRIES, request, result, "config:Failed to put msg->num_config_discovery_attr"); | |
869 | for (int i = 0; i < msg->num_config_discovery_attr; i++) { | |
870 | nlattr *nl_disc_attribute = request.attr_start(NAN_REQ_ATTR_DISCOVERY_ATTR_VAL); | |
871 | NanTransmitPostDiscovery *discovery_attr = &msg->discovery_attr_val[i]; | |
872 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr->type, | |
873 | NAN_REQ_ATTR_CONN_TYPE, request, result, "config:Failed to put discovery_attr->type"); | |
874 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr->role, | |
875 | NAN_REQ_ATTR_NAN_ROLE, request, result, "config:Failed to put discovery_attr->role"); | |
876 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr->transmit_freq, | |
877 | NAN_REQ_ATTR_TRANSMIT_FREQ, request, result, "config:Failed to put discovery_attr->transmit_freq"); | |
878 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr->duration, | |
879 | NAN_REQ_ATTR_AVAILABILITY_DURATION, request, result, "config:Failed to put discovery_attr->duration"); | |
880 | CHECK_CONFIG_PUT_32_RETURN_FAIL(1, discovery_attr->avail_interval_bitmap, | |
881 | NAN_REQ_ATTR_AVAILABILITY_INTERVAL, request, result, "config:Failed to put discovery_attr->avail_interval_bitmap"); | |
882 | CHECK_CONFIG_PUT_RETURN_FAIL(1, discovery_attr->addr, NAN_MAC_ADDR_LEN, | |
883 | NAN_REQ_ATTR_MAC_ADDR_VAL, request, result, "config:Failed to put discovery_attr->addr"); | |
884 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, discovery_attr->mesh_id_len, | |
885 | NAN_REQ_ATTR_MESH_ID_LEN, request, result, "config:Failed to put discovery_attr->mesh_id"); | |
886 | CHECK_CONFIG_PUT_RETURN_FAIL(discovery_attr->mesh_id_len, discovery_attr->mesh_id, discovery_attr->mesh_id_len, | |
887 | NAN_REQ_ATTR_MESH_ID, request, result, "config:Failed to put discovery_attr->mesh_id"); | |
888 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, discovery_attr->infrastructure_ssid_len, | |
889 | NAN_REQ_ATTR_INFRASTRUCTURE_SSID_LEN, request, result, "config:Failed to put discovery_attr->infrastructure_ssid_val"); | |
890 | CHECK_CONFIG_PUT_RETURN_FAIL(discovery_attr->infrastructure_ssid_len, discovery_attr->infrastructure_ssid_val, discovery_attr->infrastructure_ssid_len, | |
891 | NAN_REQ_ATTR_INFRASTRUCTURE_SSID, request, result, "config:Failed to put discovery_attr->infrastructure_ssid_val"); | |
892 | request.attr_end(nl_disc_attribute); | |
893 | } | |
894 | } | |
895 | ||
896 | if (msg->config_fam) { | |
897 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->fam_val.numchans, | |
898 | NAN_REQ_ATTR_FURTHER_AVAIL_NUM_ENTRIES, request, result, "config:Failed to put msg->fam_val.numchans"); | |
899 | for (int i = 0; i < msg->fam_val.numchans; i++) { | |
900 | nlattr *nl_fam_attribute = request.attr_start(NAN_REQ_ATTR_FURTHER_AVAIL_VAL); | |
901 | NanFurtherAvailabilityChannel *further_avail_chan = &msg->fam_val.famchan[i]; | |
902 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan->entry_control, | |
903 | NAN_REQ_ATTR_FURTHER_AVAIL_ENTRY_CTRL, request, result, "config:Failed to put further_avail_chan->entry_control"); | |
904 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan->class_val, | |
905 | NAN_REQ_ATTR_FURTHER_AVAIL_CHAN_CLASS, request, result, "config:Failed to put further_avail_chan->class_val"); | |
906 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan->channel, | |
907 | NAN_REQ_ATTR_FURTHER_AVAIL_CHAN, request, result, "config:Failed to put further_avail_chan->channel"); | |
908 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan->mapid, | |
909 | NAN_REQ_ATTR_FURTHER_AVAIL_CHAN_MAPID, request, result, "config:Failed to put further_avail_chan->mapid"); | |
910 | CHECK_CONFIG_PUT_32_RETURN_FAIL(1, further_avail_chan->avail_interval_bitmap, | |
911 | NAN_REQ_ATTR_FURTHER_AVAIL_INTERVAL_BITMAP, request, result, "config:Failed to put further_avail_chan->avail_interval_bitmap"); | |
912 | request.attr_end(nl_fam_attribute); | |
913 | } | |
914 | } | |
915 | ||
f8c9e3bb JPS |
916 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_subscribe_sid_beacon, msg->subscribe_sid_beacon_val, |
917 | NAN_REQ_ATTR_SUBSCRIBE_SID_BEACON_VAL, request, result, "config:Failed to put subscribe_sid_beacon_val"); | |
918 | ||
919 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_dw.config_2dot4g_dw_band, msg->config_dw.dw_2dot4g_interval_val, | |
920 | NAN_REQ_ATTR_DW_2G4_INTERVAL, request, result, "config:Failed to put dw_2dot4g_interval_val"); | |
921 | ||
922 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_dw.config_5g_dw_band, msg->config_dw.dw_5g_interval_val, | |
923 | NAN_REQ_ATTR_DW_5G_INTERVAL, request, result, "config:Failed to put dw_5g_interval_val"); | |
924 | ||
925 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_disc_mac_addr_randomization, msg->disc_mac_addr_rand_interval_sec, | |
926 | NAN_REQ_ATTR_DISC_MAC_ADDR_RANDOM_INTERVAL, request, result, "config:Failed to put disc_mac_addr_rand_interval_sec"); | |
927 | ||
c2afddcb | 928 | CHECK_CONFIG_PUT_32_RETURN_FAIL(msg->config_ndpe_attr, msg->use_ndpe_attr, |
1eccec64 JPS |
929 | NAN_REQ_ATTR_USE_NDPE_ATTR, request, result, "config:Failed to put use_ndpe_attr"); |
930 | ||
931 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id, NAN_REQ_ATTR_HAL_TRANSACTION_ID, request, result, "config:Failed to put transaction id"); | |
c2afddcb | 932 | |
d3a587e8 JPS |
933 | request.attr_end(data); |
934 | result = requestResponse(request); | |
935 | if (result != WIFI_SUCCESS) { | |
936 | ALOGE("failed to set_config; result = %d", result); | |
937 | } else { | |
49e66671 | 938 | ALOGD("NAN config...success"); |
d3a587e8 JPS |
939 | } |
940 | return result; | |
941 | } | |
942 | ||
943 | static int setCallbackHandler(NanCallbackHandler handlers) { | |
944 | callbackEventHandler = handlers; | |
945 | return WIFI_SUCCESS; | |
946 | } | |
947 | ||
948 | static int getVersion(NanVersion *version) { | |
949 | *version = SLSI_WIFI_HAL_NAN_VERSION; | |
950 | return WIFI_SUCCESS; | |
951 | } | |
952 | ||
650a9e6a JPS |
953 | int publish(transaction_id id, NanPublishRequest *msg) { |
954 | ALOGD("NAN publish transId:%d publishId:%d publishType:%d", id, msg->publish_id, msg->publish_type); | |
d3a587e8 JPS |
955 | WifiRequest request(familyId(), ifaceId()); |
956 | ||
957 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_NAN_PUBLISH); | |
958 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "publish:Failed to create WifiRequest"); | |
959 | ||
960 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
961 | if (!data) { | |
962 | ALOGE("publish: request.attr_start fail"); | |
963 | return WIFI_ERROR_OUT_OF_MEMORY; | |
964 | } | |
965 | ||
966 | CHECK_CONFIG_PUT_16_RETURN_FAIL(msg->publish_id, msg->publish_id, | |
967 | NAN_REQ_ATTR_PUBLISH_ID, request, result, "publish:Failed to put msg->publish_id"); | |
968 | ||
969 | CHECK_CONFIG_PUT_16_RETURN_FAIL(msg->ttl, msg->ttl, | |
970 | NAN_REQ_ATTR_PUBLISH_TTL, request, result, "publish:Failed to put msg->ttl"); | |
971 | ||
972 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg->period, | |
973 | NAN_REQ_ATTR_PUBLISH_PERIOD, request, result, "publish:Failed to put msg->period"); | |
974 | ||
975 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->publish_type, | |
976 | NAN_REQ_ATTR_PUBLISH_TYPE, request, result, "publish:Failed to put msg->publish_type"); | |
977 | ||
978 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->tx_type, | |
979 | NAN_REQ_ATTR_PUBLISH_TX_TYPE, request, result, "publish:Failed to put msg->tx_type"); | |
980 | ||
981 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->publish_count, | |
982 | NAN_REQ_ATTR_PUBLISH_COUNT, request, result, "publish:Failed to put msg->publish_count"); | |
983 | ||
984 | CHECK_CONFIG_PUT_16_RETURN_FAIL(msg->service_name_len, msg->service_name_len, | |
985 | NAN_REQ_ATTR_PUBLISH_SERVICE_NAME_LEN, request, result, "publish:Failed to put msg->service_name_len"); | |
986 | ||
987 | CHECK_CONFIG_PUT_RETURN_FAIL(msg->service_name_len, msg->service_name, msg->service_name_len, | |
988 | NAN_REQ_ATTR_PUBLISH_SERVICE_NAME, request, result, "publish:Failed to put msg->service_name"); | |
989 | ||
990 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->publish_match_indicator, | |
991 | NAN_REQ_ATTR_PUBLISH_MATCH_ALGO, request, result, "publish:Failed to put msg->publish_match_indicator"); | |
992 | ||
993 | CHECK_CONFIG_PUT_16_RETURN_FAIL(msg->service_specific_info_len, msg->service_specific_info_len, | |
994 | NAN_REQ_ATTR_PUBLISH_SERVICE_INFO_LEN, request, result, "publish:Failed to put msg->service_specific_info_len"); | |
995 | ||
996 | CHECK_CONFIG_PUT_RETURN_FAIL(msg->service_specific_info_len, msg->service_specific_info, msg->service_specific_info_len, | |
997 | NAN_REQ_ATTR_PUBLISH_SERVICE_INFO, request, result, "publish:Failed to put msg->service_specific_info"); | |
998 | ||
999 | CHECK_CONFIG_PUT_16_RETURN_FAIL(msg->rx_match_filter_len, msg->rx_match_filter_len, | |
1000 | NAN_REQ_ATTR_PUBLISH_RX_MATCH_FILTER_LEN, request, result, "publish:Failed to put msg->rx_match_filter_len"); | |
1001 | ||
1002 | CHECK_CONFIG_PUT_RETURN_FAIL(msg->rx_match_filter_len, msg->rx_match_filter, msg->rx_match_filter_len, | |
1003 | NAN_REQ_ATTR_PUBLISH_RX_MATCH_FILTER, request, result, "publish:Failed to put msg->rx_match_filter"); | |
1004 | ||
1005 | CHECK_CONFIG_PUT_16_RETURN_FAIL(msg->tx_match_filter_len, msg->tx_match_filter_len, | |
1006 | NAN_REQ_ATTR_PUBLISH_TX_MATCH_FILTER_LEN, request, result, "publish:Failed to put msg->tx_match_filter_len"); | |
1007 | ||
1008 | CHECK_CONFIG_PUT_RETURN_FAIL(msg->tx_match_filter_len, msg->tx_match_filter, msg->tx_match_filter_len, | |
1009 | NAN_REQ_ATTR_PUBLISH_TX_MATCH_FILTER, request, result, "publish:Failed to put msg->tx_match_filter"); | |
1010 | ||
1011 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->rssi_threshold_flag, | |
1012 | NAN_REQ_ATTR_PUBLISH_RSSI_THRESHOLD_FLAG, request, result, "publish:Failed to put msg->rssi_threshold_flag"); | |
1013 | ||
1014 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->connmap, | |
1015 | NAN_REQ_ATTR_PUBLISH_CONN_MAP, request, result, "publish:Failed to put msg->connmap"); | |
1016 | ||
1017 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->recv_indication_cfg, | |
1018 | NAN_REQ_ATTR_PUBLISH_RECV_IND_CFG, request, result, "publish:Failed to put msg->recv_indication_cfg"); | |
1019 | ||
f8c9e3bb JPS |
1020 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg->sdea_service_specific_info_len, |
1021 | NAN_REQ_ATTR_PUBLISH_SDEA_LEN, request, result, "publish:Failed to put msg->sdea_service_specific_info_len"); | |
1022 | ||
1023 | CHECK_CONFIG_PUT_RETURN_FAIL(msg->sdea_service_specific_info_len, msg->sdea_service_specific_info, msg->sdea_service_specific_info_len, | |
1024 | NAN_REQ_ATTR_PUBLISH_SDEA, request, result, "publish:Failed to put msg->sdea_service_specific_info"); | |
1025 | ||
e8aa68c3 | 1026 | result = request.put_u8(NAN_REQ_ATTR_RANGING_AUTO_RESPONSE, msg->ranging_auto_response); |
1eccec64 | 1027 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "publish:Failed to put ranging_auto_response"); |
e8aa68c3 JPS |
1028 | |
1029 | result = putSdeaParams(&msg->sdea_params, &request); | |
1030 | if (result != 0) | |
1031 | return result; | |
1032 | result = putRangingCfg(&msg->ranging_cfg, &request); | |
1033 | if (result != 0) | |
1034 | return result; | |
c2afddcb | 1035 | result = NanDataCommand::putSecurityInfo(msg->cipher_type, &msg->key_info, msg->scid_len, msg->scid, &request); |
e8aa68c3 JPS |
1036 | if (result != 0) |
1037 | return result; | |
1038 | result = putRangeResponseCfg(&msg->range_response_cfg, &request); | |
1039 | if (result != 0) | |
1040 | return result; | |
1041 | ||
1eccec64 JPS |
1042 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id, NAN_REQ_ATTR_HAL_TRANSACTION_ID, request, result, "publish:Failed to put transaction id"); |
1043 | ||
d3a587e8 JPS |
1044 | request.attr_end(data); |
1045 | result = requestResponse(request); | |
1046 | if (result != WIFI_SUCCESS) { | |
1047 | ALOGE("failed to publish; result = %d", result); | |
1048 | } else { | |
49e66671 | 1049 | ALOGD("NAN publish...success"); |
d3a587e8 JPS |
1050 | } |
1051 | return result; | |
1052 | } | |
1053 | ||
650a9e6a JPS |
1054 | int publishCancel(transaction_id id, NanPublishCancelRequest *msg) { |
1055 | ALOGD("NAN publishCancel transId:%d, publish_id:%d", id, msg->publish_id); | |
d3a587e8 JPS |
1056 | WifiRequest request(familyId(), ifaceId()); |
1057 | ||
1058 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_NAN_PUBLISHCANCEL); | |
1059 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "publishCancel:Failed to create WifiRequest"); | |
1060 | ||
1061 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
1062 | if (!data) { | |
1063 | ALOGE("publishCancel: request.attr_start fail"); | |
1064 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1065 | } | |
1066 | ||
1067 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg->publish_id, | |
1068 | NAN_REQ_ATTR_PUBLISH_ID, request, result, "publishCancel:Failed to put msg->publish_id"); | |
1069 | ||
1eccec64 JPS |
1070 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id, NAN_REQ_ATTR_HAL_TRANSACTION_ID, request, result, "publishCancel:Failed to put transaction id"); |
1071 | ||
d3a587e8 JPS |
1072 | request.attr_end(data); |
1073 | result = requestResponse(request); | |
1074 | if (result != WIFI_SUCCESS) { | |
1075 | ALOGE("failed to publishCancel; result = %d", result); | |
1076 | } else { | |
49e66671 | 1077 | ALOGD("NAN publishCancel...success"); |
d3a587e8 JPS |
1078 | } |
1079 | return result; | |
1080 | ||
1081 | } | |
1082 | ||
650a9e6a JPS |
1083 | int subscribe(transaction_id id, NanSubscribeRequest *msg) { |
1084 | ALOGD("NAN subscribe trans_id:%d subscribe_id:%d subscribetype:%d", id, msg->subscribe_id, msg->subscribe_type); | |
d3a587e8 JPS |
1085 | WifiRequest request(familyId(), ifaceId()); |
1086 | ||
1087 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_NAN_SUBSCRIBE); | |
1088 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "subscribe:Failed to create WifiRequest"); | |
1089 | ||
1090 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
1091 | if (!data) { | |
1092 | ALOGE("subscribe: request.attr_start fail"); | |
1093 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1094 | } | |
1095 | ||
1096 | CHECK_CONFIG_PUT_16_RETURN_FAIL(msg->subscribe_id, msg->subscribe_id, | |
1097 | NAN_REQ_ATTR_SUBSCRIBE_ID, request, result, "subscribe:Failed to put msg->publish_id"); | |
1098 | ||
1099 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg->ttl, | |
1100 | NAN_REQ_ATTR_SUBSCRIBE_TTL, request, result, "subscribe:Failed to put msg->ttl"); | |
1101 | ||
1102 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg->period, | |
1103 | NAN_REQ_ATTR_SUBSCRIBE_PERIOD, request, result, "subscribe:Failed to put msg->period"); | |
1104 | ||
1105 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->subscribe_type, | |
1106 | NAN_REQ_ATTR_SUBSCRIBE_TYPE, request, result, "subscribe:Failed to put msg->subscribe_type"); | |
1107 | ||
1108 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->serviceResponseFilter, | |
1109 | NAN_REQ_ATTR_SUBSCRIBE_RESP_FILTER_TYPE, request, result, "subscribe:Failed to put msg->serviceResponseFilter"); | |
1110 | ||
1111 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->serviceResponseInclude, | |
1112 | NAN_REQ_ATTR_SUBSCRIBE_RESP_INCLUDE, request, result, "subscribe:Failed to put msg->serviceResponseInclude"); | |
1113 | ||
1114 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->useServiceResponseFilter, | |
1115 | NAN_REQ_ATTR_SUBSCRIBE_USE_RESP_FILTER, request, result, "subscribe:Failed to put msg->useServiceResponseFilter"); | |
1116 | ||
1117 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->ssiRequiredForMatchIndication, | |
1118 | NAN_REQ_ATTR_SUBSCRIBE_SSI_REQUIRED, request, result, "subscribe:Failed to put msg->ssiRequiredForMatchIndication"); | |
1119 | ||
1120 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->subscribe_match_indicator, | |
1121 | NAN_REQ_ATTR_SUBSCRIBE_MATCH_INDICATOR, request, result, "subscribe:Failed to put msg->subscribe_match_indicator"); | |
1122 | ||
1123 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->subscribe_count, | |
1124 | NAN_REQ_ATTR_SUBSCRIBE_COUNT, request, result, "subscribe:Failed to put msg->subscribe_count"); | |
1125 | ||
1126 | CHECK_CONFIG_PUT_16_RETURN_FAIL(msg->service_name_len, msg->service_name_len, | |
1127 | NAN_REQ_ATTR_SUBSCRIBE_SERVICE_NAME_LEN, request, result, "subscribe:Failed to put msg->service_name_len"); | |
1128 | ||
1129 | CHECK_CONFIG_PUT_RETURN_FAIL(msg->service_name_len, msg->service_name, msg->service_name_len, | |
1130 | NAN_REQ_ATTR_SUBSCRIBE_SERVICE_NAME, request, result, "subscribe:Failed to put msg->service_name"); | |
1131 | ||
1132 | CHECK_CONFIG_PUT_16_RETURN_FAIL(msg->service_specific_info_len, msg->service_specific_info_len, | |
1133 | NAN_REQ_ATTR_SUBSCRIBE_SERVICE_INFO_LEN, request, result, "subscribe:Failed to put msg->service_specific_info_len"); | |
1134 | ||
1135 | CHECK_CONFIG_PUT_RETURN_FAIL(msg->service_specific_info_len, msg->service_specific_info, msg->service_specific_info_len, | |
1136 | NAN_REQ_ATTR_SUBSCRIBE_SERVICE_INFO, request, result, "subscribe:Failed to put msg->service_specific_info"); | |
1137 | ||
1138 | CHECK_CONFIG_PUT_16_RETURN_FAIL(msg->rx_match_filter_len, msg->rx_match_filter_len, | |
1139 | NAN_REQ_ATTR_SUBSCRIBE_RX_MATCH_FILTER_LEN, request, result, "subscribe:Failed to put msg->rx_match_filter_len"); | |
1140 | ||
1141 | CHECK_CONFIG_PUT_RETURN_FAIL(msg->rx_match_filter_len, msg->rx_match_filter, msg->rx_match_filter_len, | |
1142 | NAN_REQ_ATTR_SUBSCRIBE_RX_MATCH_FILTER, request, result, "subscribe:Failed to put msg->rx_match_filter"); | |
1143 | ||
1144 | CHECK_CONFIG_PUT_16_RETURN_FAIL(msg->tx_match_filter_len, msg->tx_match_filter_len, | |
1145 | NAN_REQ_ATTR_SUBSCRIBE_TX_MATCH_FILTER_LEN, request, result, "subscribe:Failed to put msg->tx_match_filter_len"); | |
1146 | ||
1147 | CHECK_CONFIG_PUT_RETURN_FAIL(msg->tx_match_filter_len, msg->tx_match_filter, msg->tx_match_filter_len, | |
1148 | NAN_REQ_ATTR_SUBSCRIBE_TX_MATCH_FILTER, request, result, "subscribe:Failed to put msg->tx_match_filter"); | |
1149 | ||
1150 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->rssi_threshold_flag, | |
1151 | NAN_REQ_ATTR_SUBSCRIBE_RSSI_THRESHOLD_FLAG, request, result, "subscribe:Failed to put msg->rssi_threshold_flag"); | |
1152 | ||
1153 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->connmap, | |
1154 | NAN_REQ_ATTR_SUBSCRIBE_CONN_MAP, request, result, "subscribe:Failed to put msg->connmap"); | |
1155 | ||
1156 | CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->num_intf_addr_present, msg->num_intf_addr_present, | |
1157 | NAN_REQ_ATTR_SUBSCRIBE_NUM_INTF_ADDR_PRESENT, request, result, "subscribe:Failed to put msg->num_intf_addr_present"); | |
1158 | ||
1159 | CHECK_CONFIG_PUT_RETURN_FAIL(msg->num_intf_addr_present, msg->intf_addr, NAN_MAC_ADDR_LEN * msg->num_intf_addr_present, | |
1160 | NAN_REQ_ATTR_SUBSCRIBE_INTF_ADDR, request, result, "subscribe:Failed to put msg->intf_addr"); | |
1161 | ||
1162 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->recv_indication_cfg, | |
1163 | NAN_REQ_ATTR_SUBSCRIBE_RECV_IND_CFG, request, result, "subscribe:Failed to put msg->recv_indication_cfg"); | |
1164 | ||
f8c9e3bb JPS |
1165 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg->sdea_service_specific_info_len, |
1166 | NAN_REQ_ATTR_PUBLISH_SDEA_LEN, request, result, "subscribe:Failed to put msg->sdea_service_specific_info_len"); | |
1167 | ||
1168 | CHECK_CONFIG_PUT_RETURN_FAIL(msg->sdea_service_specific_info_len, msg->sdea_service_specific_info, msg->sdea_service_specific_info_len, | |
1169 | NAN_REQ_ATTR_PUBLISH_SDEA, request, result, "subscribe:Failed to put msg->sdea_service_specific_info"); | |
1170 | ||
e8aa68c3 | 1171 | result = request.put_u8(NAN_REQ_ATTR_RANGING_AUTO_RESPONSE, msg->ranging_auto_response); |
1eccec64 | 1172 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "subscribe:Failed to put ranging_auto_response"); |
e8aa68c3 JPS |
1173 | |
1174 | result = putSdeaParams(&msg->sdea_params, &request); | |
1175 | if (result != 0) | |
1176 | return result; | |
1177 | result = putRangingCfg(&msg->ranging_cfg, &request); | |
1178 | if (result != 0) | |
1179 | return result; | |
c2afddcb | 1180 | result = NanDataCommand::putSecurityInfo(msg->cipher_type, &msg->key_info, msg->scid_len, msg->scid, &request); |
e8aa68c3 JPS |
1181 | if (result != 0) |
1182 | return result; | |
1183 | result = putRangeResponseCfg(&msg->range_response_cfg, &request); | |
1184 | if (result != 0) | |
1185 | return result; | |
f8c9e3bb | 1186 | |
1eccec64 JPS |
1187 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id, NAN_REQ_ATTR_HAL_TRANSACTION_ID, request, result, "subscribe:Failed to put transaction id"); |
1188 | ||
d3a587e8 JPS |
1189 | request.attr_end(data); |
1190 | result = requestResponse(request); | |
1191 | if (result != WIFI_SUCCESS) { | |
1192 | ALOGE("failed to subscribe; result = %d", result); | |
1193 | } else { | |
49e66671 | 1194 | ALOGD("NAN subscribe...success"); |
d3a587e8 JPS |
1195 | } |
1196 | return result; | |
1197 | ||
1198 | } | |
1199 | ||
650a9e6a JPS |
1200 | int subscribeCancel(transaction_id id, NanSubscribeCancelRequest *msg) { |
1201 | ALOGD("NAN subscribeCancel transId:%d subscribeId:%d", id, msg->subscribe_id); | |
d3a587e8 JPS |
1202 | WifiRequest request(familyId(), ifaceId()); |
1203 | ||
1204 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_NAN_SUBSCRIBECANCEL); | |
1205 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "subscribeCancel:Failed to create WifiRequest"); | |
1206 | ||
1207 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
1208 | if (!data) { | |
1209 | ALOGE("subscribeCancel: request.attr_start fail"); | |
1210 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1211 | } | |
1212 | ||
1213 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg->subscribe_id, | |
1214 | NAN_REQ_ATTR_SUBSCRIBE_ID, request, result, "subscribeCancel:Failed to put msg->subscribe_id"); | |
1215 | ||
1eccec64 JPS |
1216 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id, NAN_REQ_ATTR_HAL_TRANSACTION_ID, request, result, "subscribeCancel:Failed to put transaction id"); |
1217 | ||
d3a587e8 JPS |
1218 | request.attr_end(data); |
1219 | result = requestResponse(request); | |
1220 | if (result != WIFI_SUCCESS) { | |
1221 | ALOGE("failed to subscribeCancel; result = %d", result); | |
1222 | } else { | |
49e66671 | 1223 | ALOGD("NAN subscribeCancel...success"); |
d3a587e8 JPS |
1224 | } |
1225 | return result; | |
1226 | } | |
1227 | ||
650a9e6a JPS |
1228 | int followup(transaction_id id, NanTransmitFollowupRequest *msg) { |
1229 | ALOGD("NAN followup transid:%d pub/subId:%d reqInstId:%d", id, msg->publish_subscribe_id, msg->requestor_instance_id); | |
d3a587e8 JPS |
1230 | WifiRequest request(familyId(), ifaceId()); |
1231 | ||
1232 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_NAN_TXFOLLOWUP); | |
1233 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "followup:Failed to create WifiRequest"); | |
1234 | ||
1235 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
1236 | if (!data) { | |
1237 | ALOGE("followup: request.attr_start fail"); | |
1238 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1239 | } | |
1240 | ||
1241 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg->publish_subscribe_id, | |
1242 | NAN_REQ_ATTR_FOLLOWUP_ID, request, result, "followup:Failed to put msg->publish_subscribe_id"); | |
1243 | ||
1244 | CHECK_CONFIG_PUT_32_RETURN_FAIL(1, msg->requestor_instance_id, | |
1245 | NAN_REQ_ATTR_FOLLOWUP_REQUESTOR_ID, request, result, "followup:Failed to put msg->requestor_instance_id"); | |
1246 | ||
1247 | CHECK_CONFIG_PUT_RETURN_FAIL(1, msg->addr, NAN_MAC_ADDR_LEN, | |
1248 | NAN_REQ_ATTR_FOLLOWUP_ADDR, request, result, "followup:Failed to put msg->addr"); | |
1249 | ||
1250 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->priority, | |
1251 | NAN_REQ_ATTR_FOLLOWUP_PRIORITY, request, result, "followup:Failed to put msg->priority"); | |
1252 | ||
1253 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->dw_or_faw, | |
1254 | NAN_REQ_ATTR_FOLLOWUP_TX_WINDOW, request, result, "followup:Failed to put msg->dw_or_faw"); | |
1255 | ||
1256 | CHECK_CONFIG_PUT_16_RETURN_FAIL(msg->service_specific_info_len, msg->service_specific_info_len, | |
1257 | NAN_REQ_ATTR_FOLLOWUP_SERVICE_NAME_LEN, request, result, "followup:Failed to put msg->service_specific_info_len"); | |
1258 | ||
1259 | CHECK_CONFIG_PUT_RETURN_FAIL(msg->service_specific_info_len, msg->service_specific_info, msg->service_specific_info_len, | |
1260 | NAN_REQ_ATTR_FOLLOWUP_SERVICE_NAME, request, result, "followup:Failed to put msg->service_specific_info"); | |
1261 | ||
1262 | CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->recv_indication_cfg, | |
1263 | NAN_REQ_ATTR_FOLLOWUP_RECV_IND_CFG, request, result, "followup:Failed to put msg->recv_indication_cfg"); | |
1264 | ||
f8c9e3bb JPS |
1265 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg->sdea_service_specific_info_len, |
1266 | NAN_REQ_ATTR_PUBLISH_SDEA_LEN, request, result, "publish:Failed to put msg->sdea_service_specific_info_len"); | |
1267 | ||
1268 | CHECK_CONFIG_PUT_RETURN_FAIL(msg->sdea_service_specific_info_len, msg->sdea_service_specific_info, msg->sdea_service_specific_info_len, | |
1269 | NAN_REQ_ATTR_PUBLISH_SDEA, request, result, "publish:Failed to put msg->sdea_service_specific_info"); | |
1270 | ||
1eccec64 JPS |
1271 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id, NAN_REQ_ATTR_HAL_TRANSACTION_ID, request, result, "followup:Failed to put transaction id"); |
1272 | ||
d3a587e8 JPS |
1273 | request.attr_end(data); |
1274 | result = requestResponse(request); | |
1275 | if (result != WIFI_SUCCESS) { | |
1276 | ALOGE("failed to followup; result = %d", result); | |
1277 | } else { | |
49e66671 | 1278 | ALOGD("NAN followup...success"); |
d3a587e8 JPS |
1279 | } |
1280 | return result; | |
1281 | ||
1282 | } | |
1283 | ||
650a9e6a JPS |
1284 | int getCapabilities(transaction_id id) { |
1285 | ALOGD("NAN getCapabilities transId:%d", id); | |
d3a587e8 JPS |
1286 | WifiRequest request(familyId(), ifaceId()); |
1287 | ||
1288 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_NAN_CAPABILITIES); | |
1289 | CHECK_WIFI_STATUS_RETURN_FAIL(result, "getCapabilities:Failed to create WifiRequest"); | |
1290 | ||
1eccec64 JPS |
1291 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); |
1292 | if (!data) { | |
1293 | ALOGE("enable: request.attr_start fail"); | |
1294 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1295 | } | |
1296 | CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id, NAN_REQ_ATTR_HAL_TRANSACTION_ID, request, result, "getCapabilities:Failed to put transaction id"); | |
1297 | request.attr_end(data); | |
d3a587e8 JPS |
1298 | result = requestResponse(request); |
1299 | if (result != WIFI_SUCCESS) { | |
1300 | ALOGE("failed to getCapabilities; result = %d", result); | |
1301 | } else { | |
49e66671 | 1302 | ALOGD("NAN getCapabilities...success"); |
d3a587e8 JPS |
1303 | } |
1304 | return result; | |
1305 | } | |
1306 | ||
1307 | int handleEvent(WifiEvent &event) { | |
1308 | int ret; | |
d3a587e8 JPS |
1309 | |
1310 | if (event.get_cmd() != NL80211_CMD_VENDOR) { | |
650a9e6a | 1311 | ALOGD("NAN %s Ignoring event with cmd = %d", __func__, event.get_cmd()); |
d3a587e8 JPS |
1312 | return NL_SKIP; |
1313 | } | |
1314 | ||
1315 | int id = event.get_vendor_id(); | |
1316 | int subcmd = event.get_vendor_subcmd(); | |
1317 | ||
4d2d047a | 1318 | ALOGI("NAN %s Id = 0x%x, subcmd = %s(0x%x)", __func__, id, getEventName(subcmd), subcmd); |
d3a587e8 JPS |
1319 | |
1320 | switch(subcmd) { | |
1321 | case SLSI_NAN_EVENT_MATCH: | |
1322 | ret = processMatchEvent(event); | |
1323 | break; | |
1324 | case SLSI_NAN_EVENT_MATCH_EXPIRED: | |
1325 | ret = processMatchExpiredEvent(event); | |
1326 | break; | |
1327 | case SLSI_NAN_EVENT_PUBLISH_TERMINATED: | |
1328 | ret = processPublishTerminatedEvent(event); | |
1329 | break; | |
1330 | case SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED: | |
1331 | ret = processSubscribeTerminatedEvent(event); | |
1332 | break; | |
1333 | case SLSI_NAN_EVENT_FOLLOWUP: | |
1334 | ret = processFollowupEvent(event); | |
1335 | break; | |
1336 | case SLSI_NAN_EVENT_DISABLED: | |
1337 | ret = processNanDisabledEvent(event); | |
1338 | break; | |
1339 | case SLSI_NAN_EVENT_DISCOVERY_ENGINE: | |
1340 | ret = processNanDiscoveryEvent(event); | |
1341 | break; | |
650a9e6a JPS |
1342 | case SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS: |
1343 | ret = processNanFollowupStatus(event); | |
1344 | break; | |
c2afddcb JPS |
1345 | default: |
1346 | return datacmd.handleEvent(event, callbackEventHandler); | |
d3a587e8 JPS |
1347 | } |
1348 | ||
1349 | return NL_OK; | |
1350 | } | |
1351 | ||
1352 | int handleResponse(WifiEvent &reply) { | |
d3a587e8 | 1353 | if (reply.get_cmd() != NL80211_CMD_VENDOR) { |
650a9e6a | 1354 | ALOGD("NAN %s Ignoring reply with cmd = %d", __func__, reply.get_cmd()); |
d3a587e8 JPS |
1355 | return NL_SKIP; |
1356 | } | |
1357 | ||
d3a587e8 JPS |
1358 | NanResponseMsg response; |
1359 | memset(&response, 0, sizeof(response)); | |
1360 | ||
1eccec64 JPS |
1361 | transaction_id id = processResponse(reply, &response); |
1362 | if ( id < 0) | |
d3a587e8 JPS |
1363 | return NL_SKIP; |
1364 | ||
650a9e6a | 1365 | ALOGD("NAN %s transId:%d status:%d, response:%d", __func__, id, response.status, response.response_type); |
d3a587e8 | 1366 | if (callbackEventHandler.NotifyResponse) |
650a9e6a | 1367 | callbackEventHandler.NotifyResponse(id, &response); |
d3a587e8 JPS |
1368 | return NL_OK; |
1369 | } | |
c2afddcb JPS |
1370 | |
1371 | int dataPathReq(u16 id, void *data, int subcmd) { | |
1372 | int result; | |
1373 | WifiRequest request(familyId(), ifaceId()); | |
1374 | ||
4d2d047a | 1375 | ALOGI("NAN DATA-PATH req subcmd:%s(0x%x) transaction_id:%d", datacmd.getCmdName(subcmd), subcmd, id); |
c2afddcb | 1376 | |
082f0000 | 1377 | result = datacmd.getDataPathNLMsg(id, data, subcmd, request); |
c2afddcb JPS |
1378 | if (result != WIFI_SUCCESS) { |
1379 | return result; | |
1380 | } | |
1381 | result = requestResponse(request); | |
1382 | if (result != WIFI_SUCCESS) { | |
4d2d047a | 1383 | ALOGE("NAN DATA-PATH req subcmd:%s(0x%x)...failed(%d)", datacmd.getCmdName(subcmd), subcmd, result); |
c2afddcb JPS |
1384 | unregisterNanEvents(); |
1385 | } else { | |
1386 | datacmd.requestSuccess(id, data, subcmd); | |
4d2d047a | 1387 | ALOGD("NAN DATA-PATH req subcmd:%s(0x%x)...success", datacmd.getCmdName(subcmd), subcmd); |
c2afddcb JPS |
1388 | } |
1389 | return result; | |
1390 | } | |
d3a587e8 JPS |
1391 | }; |
1392 | ||
1393 | NanCallbackHandler NanCommand::callbackEventHandler; | |
1394 | ||
1395 | NanCommand *nan_get_object(transaction_id id, | |
1396 | wifi_interface_handle iface) { | |
1397 | wifi_handle handle = getWifiHandle(iface); | |
650a9e6a | 1398 | NanCommand *nanRequest = (NanCommand *)wifi_get_nan_cmd(handle); |
d3a587e8 JPS |
1399 | if (!nanRequest) { |
1400 | nanRequest = new NanCommand(iface, id); | |
1401 | if (!nanRequest){ | |
1402 | ALOGE("Could not alloc NanCommand"); | |
1403 | return NULL; | |
1404 | } | |
1405 | } | |
1406 | return nanRequest; | |
1407 | } | |
1408 | ||
1409 | wifi_error nan_enable_request(transaction_id id, | |
1410 | wifi_interface_handle iface, | |
1411 | NanEnableRequest *msg) { | |
1412 | wifi_handle handle = getWifiHandle(iface); | |
1413 | wifi_error ret; | |
1414 | ||
1415 | NanCommand *nanRequest = new NanCommand(iface, id); | |
1416 | if (!nanRequest) { | |
1417 | ALOGE("nan_enable_request:: Unable to create NanCommand"); | |
1418 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1419 | } | |
1420 | ||
650a9e6a JPS |
1421 | wifi_set_nan_cmd(handle, nanRequest); |
1422 | ret = (wifi_error)nanRequest->enable(id, msg); | |
d3a587e8 | 1423 | if (ret != WIFI_SUCCESS) { |
650a9e6a | 1424 | wifi_reset_nan_cmd(handle); |
d3a587e8 JPS |
1425 | delete nanRequest; |
1426 | } | |
1427 | return ret; | |
1428 | } | |
1429 | ||
1430 | /* Disable NAN functionality. */ | |
1431 | wifi_error nan_disable_request(transaction_id id, wifi_interface_handle iface) { | |
1432 | NanCommand *nanRequest = nan_get_object(id, iface); | |
1433 | wifi_error ret; | |
1434 | ||
1435 | if (!nanRequest) { | |
1436 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1437 | } | |
650a9e6a JPS |
1438 | ret = (wifi_error)nanRequest->disable(id); |
1439 | wifi_reset_nan_cmd(getWifiHandle(iface)); | |
d3a587e8 JPS |
1440 | delete nanRequest; |
1441 | return ret; | |
1442 | } | |
1443 | ||
1444 | /* Publish request to advertize a service. */ | |
1445 | wifi_error nan_publish_request(transaction_id id, | |
1446 | wifi_interface_handle iface, | |
1447 | NanPublishRequest *msg) { | |
1448 | NanCommand *nanRequest = nan_get_object(id, iface); | |
1449 | if (!nanRequest) { | |
1450 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1451 | } | |
650a9e6a | 1452 | return (wifi_error)nanRequest->publish(id, msg); |
d3a587e8 JPS |
1453 | } |
1454 | ||
1455 | /* Cancel previous publish requests. */ | |
1456 | wifi_error nan_publish_cancel_request(transaction_id id, | |
1457 | wifi_interface_handle iface, | |
1458 | NanPublishCancelRequest *msg) { | |
1459 | NanCommand *nanRequest = nan_get_object(id, iface); | |
1460 | if (!nanRequest) { | |
1461 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1462 | } | |
650a9e6a | 1463 | return (wifi_error)nanRequest->publishCancel(id, msg); |
d3a587e8 JPS |
1464 | } |
1465 | ||
1466 | /* Subscribe request to search for a service. */ | |
1467 | wifi_error nan_subscribe_request(transaction_id id, | |
1468 | wifi_interface_handle iface, | |
1469 | NanSubscribeRequest *msg) { | |
1470 | NanCommand *nanRequest = nan_get_object(id, iface); | |
1471 | if (!nanRequest) { | |
1472 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1473 | } | |
650a9e6a | 1474 | return (wifi_error)nanRequest->subscribe(id, msg); |
d3a587e8 JPS |
1475 | } |
1476 | ||
1477 | /* Cancel previous subscribe requests. */ | |
1478 | wifi_error nan_subscribe_cancel_request(transaction_id id, | |
1479 | wifi_interface_handle iface, | |
1480 | NanSubscribeCancelRequest *msg) { | |
1481 | NanCommand *nanRequest = nan_get_object(id, iface); | |
1482 | if (!nanRequest) { | |
1483 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1484 | } | |
650a9e6a | 1485 | return (wifi_error)nanRequest->subscribeCancel(id, msg); |
d3a587e8 JPS |
1486 | } |
1487 | ||
1488 | /* NAN transmit follow up request. */ | |
1489 | wifi_error nan_transmit_followup_request(transaction_id id, | |
1490 | wifi_interface_handle iface, | |
1491 | NanTransmitFollowupRequest *msg) { | |
1492 | NanCommand *nanRequest = nan_get_object(id, iface); | |
1493 | if (!nanRequest) { | |
1494 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1495 | } | |
650a9e6a | 1496 | return (wifi_error)nanRequest->followup(id, msg); |
d3a587e8 JPS |
1497 | } |
1498 | ||
1499 | /* NAN configuration request. */ | |
1500 | wifi_error nan_config_request(transaction_id id, | |
1501 | wifi_interface_handle iface, | |
1502 | NanConfigRequest *msg) { | |
1503 | NanCommand *nanRequest = nan_get_object(id, iface); | |
1504 | if (!nanRequest) { | |
1505 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1506 | } | |
650a9e6a | 1507 | return (wifi_error)nanRequest->config(id, msg); |
d3a587e8 JPS |
1508 | } |
1509 | ||
1510 | /* Register NAN callbacks. */ | |
1511 | wifi_error nan_register_handler(wifi_interface_handle iface, | |
1512 | NanCallbackHandler handlers) { | |
1513 | return (wifi_error)NanCommand::setCallbackHandler(handlers); | |
1514 | } | |
1515 | ||
1516 | /* Get NAN HAL version. */ | |
1517 | wifi_error nan_get_version(wifi_handle handle, | |
1518 | NanVersion *version) { | |
1519 | return (wifi_error)NanCommand::getVersion(version); | |
1520 | } | |
1521 | ||
1522 | /* Get NAN capabilities. */ | |
1523 | wifi_error nan_get_capabilities(transaction_id id, | |
1524 | wifi_interface_handle iface) { | |
1525 | NanCommand *nanRequest = nan_get_object(id, iface); | |
1526 | if (!nanRequest) { | |
1527 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1528 | } | |
650a9e6a | 1529 | return (wifi_error)nanRequest->getCapabilities(id); |
d3a587e8 JPS |
1530 | } |
1531 | ||
c2afddcb JPS |
1532 | wifi_error nan_data_interface_create(transaction_id id, |
1533 | wifi_interface_handle iface, | |
1534 | char* iface_name) { | |
1535 | NanCommand *nanRequest = nan_get_object(id, iface); | |
1536 | if (!nanRequest) { | |
1537 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1538 | } | |
082f0000 | 1539 | return (wifi_error)nanRequest->dataPathReq(id, iface_name, |
c2afddcb JPS |
1540 | SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_INTERFACE_CREATE); |
1541 | } | |
1542 | ||
1543 | wifi_error nan_data_interface_delete(transaction_id id, | |
1544 | wifi_interface_handle iface, | |
1545 | char* iface_name) { | |
1546 | NanCommand *nanRequest = nan_get_object(id, iface); | |
1547 | if (!nanRequest) { | |
1548 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1549 | } | |
082f0000 | 1550 | return (wifi_error)nanRequest->dataPathReq(id, iface_name, |
c2afddcb JPS |
1551 | SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_INTERFACE_DELETE); |
1552 | ||
1553 | } | |
1554 | ||
1555 | wifi_error nan_data_request_initiator(transaction_id id, | |
1556 | wifi_interface_handle iface, | |
1557 | NanDataPathInitiatorRequest* msg) { | |
1558 | NanCommand *nanRequest = nan_get_object(id, iface); | |
1559 | if (!nanRequest) { | |
1560 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1561 | } | |
082f0000 | 1562 | return (wifi_error)nanRequest->dataPathReq(id, msg, |
c2afddcb JPS |
1563 | SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_REQUEST_INITIATOR); |
1564 | ||
1565 | } | |
1566 | ||
1567 | wifi_error nan_data_indication_response(transaction_id id, | |
1568 | wifi_interface_handle iface, | |
1569 | NanDataPathIndicationResponse* msg) { | |
1570 | NanCommand *nanRequest = nan_get_object(id, iface); | |
1571 | if (!nanRequest) { | |
1572 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1573 | } | |
082f0000 | 1574 | return (wifi_error)nanRequest->dataPathReq(id, msg, |
c2afddcb JPS |
1575 | SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_INDICATION_RESPONSE); |
1576 | ||
1577 | } | |
1578 | ||
1579 | wifi_error nan_data_end(transaction_id id, | |
1580 | wifi_interface_handle iface, | |
1581 | NanDataPathEndRequest* msg) { | |
1582 | NanCommand *nanRequest = nan_get_object(id, iface); | |
1583 | if (!nanRequest) { | |
1584 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1585 | } | |
082f0000 | 1586 | return (wifi_error)nanRequest->dataPathReq(id, msg, |
c2afddcb JPS |
1587 | SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_END); |
1588 | ||
1589 | } | |
1590 |