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