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