Commit | Line | Data |
---|---|---|
7753f181 DD |
1 | |
2 | #include <stdint.h> | |
6ff2d683 | 3 | #include <stddef.h> |
7753f181 DD |
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 | ||
14 | #include <linux/pkt_sched.h> | |
15 | #include <netlink/object-api.h> | |
16 | #include <netlink/netlink.h> | |
17 | #include <netlink/socket.h> | |
18 | #include <netlink/handlers.h> | |
19 | ||
20 | #include "sync.h" | |
21 | ||
22 | #define LOG_TAG "WifiHAL" | |
23 | ||
24 | #include <utils/Log.h> | |
25 | ||
26 | #include "wifi_hal.h" | |
27 | #include "common.h" | |
28 | #include "cpp_bindings.h" | |
29 | ||
30 | typedef enum { | |
31 | ||
32 | GSCAN_ATTRIBUTE_NUM_BUCKETS = 10, | |
33 | GSCAN_ATTRIBUTE_BASE_PERIOD, | |
34 | GSCAN_ATTRIBUTE_BUCKETS_BAND, | |
35 | GSCAN_ATTRIBUTE_BUCKET_ID, | |
36 | GSCAN_ATTRIBUTE_BUCKET_PERIOD, | |
37 | GSCAN_ATTRIBUTE_BUCKET_NUM_CHANNELS, | |
38 | GSCAN_ATTRIBUTE_BUCKET_CHANNELS, | |
39 | GSCAN_ATTRIBUTE_NUM_AP_PER_SCAN, | |
40 | GSCAN_ATTRIBUTE_REPORT_THRESHOLD, | |
41 | GSCAN_ATTRIBUTE_NUM_SCANS_TO_CACHE, | |
42 | GSCAN_ATTRIBUTE_REPORT_THRESHOLD_NUM_SCANS, | |
43 | GSCAN_ATTRIBUTE_BAND = GSCAN_ATTRIBUTE_BUCKETS_BAND, | |
44 | ||
45 | GSCAN_ATTRIBUTE_ENABLE_FEATURE = 20, | |
46 | GSCAN_ATTRIBUTE_SCAN_RESULTS_COMPLETE, /* indicates no more results */ | |
47 | GSCAN_ATTRIBUTE_REPORT_EVENTS, | |
48 | ||
49 | /* remaining reserved for additional attributes */ | |
50 | GSCAN_ATTRIBUTE_NUM_OF_RESULTS = 30, | |
51 | GSCAN_ATTRIBUTE_SCAN_RESULTS, /* flat array of wifi_scan_result */ | |
52 | GSCAN_ATTRIBUTE_NUM_CHANNELS, | |
53 | GSCAN_ATTRIBUTE_CHANNEL_LIST, | |
54 | GSCAN_ATTRIBUTE_SCAN_ID, | |
55 | GSCAN_ATTRIBUTE_SCAN_FLAGS, | |
acc9b163 | 56 | GSCAN_ATTRIBUTE_SCAN_BUCKET_BIT, |
7753f181 DD |
57 | |
58 | /* remaining reserved for additional attributes */ | |
59 | ||
60 | GSCAN_ATTRIBUTE_SSID = 40, | |
61 | GSCAN_ATTRIBUTE_BSSID, | |
62 | GSCAN_ATTRIBUTE_CHANNEL, | |
63 | GSCAN_ATTRIBUTE_RSSI, | |
64 | GSCAN_ATTRIBUTE_TIMESTAMP, | |
65 | GSCAN_ATTRIBUTE_RTT, | |
66 | GSCAN_ATTRIBUTE_RTTSD, | |
67 | ||
68 | /* remaining reserved for additional attributes */ | |
69 | ||
70 | GSCAN_ATTRIBUTE_HOTLIST_BSSIDS = 50, | |
71 | GSCAN_ATTRIBUTE_RSSI_LOW, | |
72 | GSCAN_ATTRIBUTE_RSSI_HIGH, | |
73 | GSCAN_ATTRIBUTE_HOTLIST_ELEM, | |
74 | GSCAN_ATTRIBUTE_HOTLIST_FLUSH, | |
75 | GSCAN_ATTRIBUTE_CHANNEL_NUMBER, | |
76 | ||
77 | /* remaining reserved for additional attributes */ | |
78 | GSCAN_ATTRIBUTE_RSSI_SAMPLE_SIZE = 60, | |
79 | GSCAN_ATTRIBUTE_LOST_AP_SAMPLE_SIZE, | |
80 | GSCAN_ATTRIBUTE_MIN_BREACHING, | |
81 | GSCAN_ATTRIBUTE_SIGNIFICANT_CHANGE_BSSIDS, | |
82 | ||
0e19df50 JPS |
83 | GSCAN_ATTRIBUTE_BUCKET_STEP_COUNT = 70, |
84 | GSCAN_ATTRIBUTE_BUCKET_EXPONENT, | |
85 | GSCAN_ATTRIBUTE_BUCKET_MAX_PERIOD, | |
86 | ||
10d7569e PG |
87 | GSCAN_ATTRIBUTE_NUM_BSSID, |
88 | GSCAN_ATTRIBUTE_BLACKLIST_BSSID, | |
89 | ||
7753f181 DD |
90 | GSCAN_ATTRIBUTE_MAX |
91 | ||
92 | } GSCAN_ATTRIBUTE; | |
93 | ||
6ff2d683 | 94 | typedef enum { |
1fc70afb MG |
95 | EPNO_ATTRIBUTE_MINIMUM_5G_RSSI, |
96 | EPNO_ATTRIBUTE_MINIMUM_2G_RSSI, | |
97 | EPNO_ATTRIBUTE_INITIAL_SCORE_MAX, | |
98 | EPNO_ATTRIBUTE_CUR_CONN_BONUS, | |
99 | EPNO_ATTRIBUTE_SAME_NETWORK_BONUS, | |
100 | EPNO_ATTRIBUTE_SECURE_BONUS, | |
101 | EPNO_ATTRIBUTE_5G_BONUS, | |
6ff2d683 | 102 | EPNO_ATTRIBUTE_SSID_NUM, |
1fc70afb | 103 | EPNO_ATTRIBUTE_SSID_LIST, |
6ff2d683 JPS |
104 | EPNO_ATTRIBUTE_SSID, |
105 | EPNO_ATTRIBUTE_SSID_LEN, | |
6ff2d683 JPS |
106 | EPNO_ATTRIBUTE_FLAGS, |
107 | EPNO_ATTRIBUTE_AUTH, | |
108 | EPNO_ATTRIBUTE_MAX | |
109 | } EPNO_ATTRIBUTE; | |
110 | ||
111 | typedef enum { | |
112 | EPNO_ATTRIBUTE_HS_PARAM_LIST, | |
113 | EPNO_ATTRIBUTE_HS_NUM, | |
114 | EPNO_ATTRIBUTE_HS_ID, | |
115 | EPNO_ATTRIBUTE_HS_REALM, | |
116 | EPNO_ATTRIBUTE_HS_CONSORTIUM_IDS, | |
117 | EPNO_ATTRIBUTE_HS_PLMN, | |
118 | EPNO_ATTRIBUTE_HS_MAX | |
119 | } EPNO_HS_ATTRIBUTE; | |
120 | ||
7753f181 DD |
121 | |
122 | class GetCapabilitiesCommand : public WifiCommand | |
123 | { | |
124 | wifi_gscan_capabilities *mCapabilities; | |
125 | public: | |
126 | GetCapabilitiesCommand(wifi_interface_handle iface, wifi_gscan_capabilities *capabitlites) | |
127 | : WifiCommand(iface, 0), mCapabilities(capabitlites) | |
128 | { | |
129 | memset(mCapabilities, 0, sizeof(*mCapabilities)); | |
130 | } | |
131 | ||
132 | virtual int create() { | |
133 | ALOGD("Creating message to get scan capablities; iface = %d", mIfaceInfo->id); | |
134 | ||
135 | int ret = mMsg.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_GET_CAPABILITIES); | |
136 | if (ret < 0) { | |
9a2ccc1c | 137 | ALOGE("NL message creation failed"); |
7753f181 DD |
138 | return ret; |
139 | } | |
140 | ||
141 | return ret; | |
142 | } | |
143 | ||
144 | protected: | |
145 | virtual int handleResponse(WifiEvent& reply) { | |
146 | ||
7753f181 DD |
147 | if (reply.get_cmd() != NL80211_CMD_VENDOR) { |
148 | ALOGD("Ignoring reply with cmd = %d", reply.get_cmd()); | |
149 | return NL_SKIP; | |
150 | } | |
151 | ||
152 | int id = reply.get_vendor_id(); | |
153 | int subcmd = reply.get_vendor_subcmd(); | |
154 | ||
155 | void *data = reply.get_vendor_data(); | |
156 | int len = reply.get_vendor_data_len(); | |
157 | ||
9a2ccc1c | 158 | ALOGD("GetCapabilities::handleResponse - Id = %0x, subcmd = %d, len = %d, expected len = %d", id, subcmd, len, |
7753f181 DD |
159 | sizeof(*mCapabilities)); |
160 | ||
161 | memcpy(mCapabilities, data, min(len, (int) sizeof(*mCapabilities))); | |
162 | ||
163 | return NL_OK; | |
164 | } | |
165 | }; | |
166 | ||
167 | ||
168 | wifi_error wifi_get_gscan_capabilities(wifi_interface_handle handle, | |
169 | wifi_gscan_capabilities *capabilities) | |
170 | { | |
171 | GetCapabilitiesCommand command(handle, capabilities); | |
172 | return (wifi_error) command.requestResponse(); | |
173 | } | |
174 | ||
175 | class GetChannelListCommand : public WifiCommand | |
176 | { | |
177 | wifi_channel *channels; | |
178 | int max_channels; | |
179 | int *num_channels; | |
180 | int band; | |
181 | public: | |
182 | GetChannelListCommand(wifi_interface_handle iface, wifi_channel *channel_buf, int *ch_num, | |
183 | int num_max_ch, int band) | |
184 | : WifiCommand(iface, 0), channels(channel_buf), max_channels(num_max_ch), num_channels(ch_num), | |
185 | band(band) | |
186 | { | |
187 | memset(channels, 0, sizeof(wifi_channel) * max_channels); | |
188 | } | |
189 | virtual int create() { | |
190 | ALOGD("Creating message to get channel list; iface = %d", mIfaceInfo->id); | |
191 | ||
192 | int ret = mMsg.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_GET_VALID_CHANNELS); | |
193 | if (ret < 0) { | |
194 | return ret; | |
195 | } | |
196 | ||
197 | nlattr *data = mMsg.attr_start(NL80211_ATTR_VENDOR_DATA); | |
198 | ret = mMsg.put_u32(GSCAN_ATTRIBUTE_BAND, band); | |
199 | if (ret < 0) { | |
200 | return ret; | |
201 | } | |
202 | ||
203 | mMsg.attr_end(data); | |
204 | ||
205 | return ret; | |
206 | } | |
207 | ||
208 | protected: | |
209 | virtual int handleResponse(WifiEvent& reply) { | |
210 | ||
7753f181 DD |
211 | if (reply.get_cmd() != NL80211_CMD_VENDOR) { |
212 | ALOGD("Ignoring reply with cmd = %d", reply.get_cmd()); | |
213 | return NL_SKIP; | |
214 | } | |
215 | ||
216 | int id = reply.get_vendor_id(); | |
217 | int subcmd = reply.get_vendor_subcmd(); | |
218 | int num_channels_to_copy = 0; | |
219 | ||
220 | nlattr *vendor_data = reply.get_attribute(NL80211_ATTR_VENDOR_DATA); | |
221 | int len = reply.get_vendor_data_len(); | |
222 | ||
9a2ccc1c | 223 | ALOGD("GetChannelList::handleResponse - Id = %0x, subcmd = %d, len = %d", id, subcmd, len); |
7753f181 DD |
224 | if (vendor_data == NULL || len == 0) { |
225 | ALOGE("no vendor data in GetChannelList response; ignoring it"); | |
226 | return NL_SKIP; | |
227 | } | |
228 | ||
229 | for (nl_iterator it(vendor_data); it.has_next(); it.next()) { | |
230 | if (it.get_type() == GSCAN_ATTRIBUTE_NUM_CHANNELS) { | |
231 | num_channels_to_copy = it.get_u32(); | |
232 | ALOGD("Got channel list with %d channels", num_channels_to_copy); | |
233 | if(num_channels_to_copy > max_channels) | |
234 | num_channels_to_copy = max_channels; | |
235 | *num_channels = num_channels_to_copy; | |
236 | } else if (it.get_type() == GSCAN_ATTRIBUTE_CHANNEL_LIST && num_channels_to_copy) { | |
237 | memcpy(channels, it.get_data(), sizeof(int) * num_channels_to_copy); | |
238 | } else { | |
239 | ALOGW("Ignoring invalid attribute type = %d, size = %d", | |
240 | it.get_type(), it.get_len()); | |
241 | } | |
242 | } | |
243 | ||
244 | return NL_OK; | |
245 | } | |
246 | }; | |
247 | ||
248 | wifi_error wifi_get_valid_channels(wifi_interface_handle handle, | |
249 | int band, int max_channels, wifi_channel *channels, int *num_channels) | |
250 | { | |
251 | GetChannelListCommand command(handle, channels, num_channels, | |
252 | max_channels, band); | |
253 | return (wifi_error) command.requestResponse(); | |
254 | } | |
255 | ///////////////////////////////////////////////////////////////////////////// | |
256 | ||
257 | /* helper functions */ | |
258 | ||
259 | static int parseScanResults(wifi_scan_result *results, int num, nlattr *attr) | |
260 | { | |
261 | memset(results, 0, sizeof(wifi_scan_result) * num); | |
262 | ||
263 | int i = 0; | |
264 | for (nl_iterator it(attr); it.has_next() && i < num; it.next(), i++) { | |
265 | ||
266 | int index = it.get_type(); | |
267 | ALOGD("retrieved scan result %d", index); | |
268 | nlattr *sc_data = (nlattr *) it.get_data(); | |
269 | wifi_scan_result *result = results + i; | |
270 | ||
271 | for (nl_iterator it2(sc_data); it2.has_next(); it2.next()) { | |
272 | int type = it2.get_type(); | |
273 | if (type == GSCAN_ATTRIBUTE_SSID) { | |
274 | strncpy(result->ssid, (char *) it2.get_data(), it2.get_len()); | |
275 | result->ssid[it2.get_len()] = 0; | |
276 | } else if (type == GSCAN_ATTRIBUTE_BSSID) { | |
277 | memcpy(result->bssid, (byte *) it2.get_data(), sizeof(mac_addr)); | |
278 | } else if (type == GSCAN_ATTRIBUTE_TIMESTAMP) { | |
279 | result->ts = it2.get_u64(); | |
280 | } else if (type == GSCAN_ATTRIBUTE_CHANNEL) { | |
281 | result->ts = it2.get_u16(); | |
282 | } else if (type == GSCAN_ATTRIBUTE_RSSI) { | |
283 | result->rssi = it2.get_u8(); | |
284 | } else if (type == GSCAN_ATTRIBUTE_RTT) { | |
285 | result->rtt = it2.get_u64(); | |
286 | } else if (type == GSCAN_ATTRIBUTE_RTTSD) { | |
287 | result->rtt_sd = it2.get_u64(); | |
288 | } | |
289 | } | |
290 | ||
291 | } | |
292 | ||
293 | if (i >= num) { | |
294 | ALOGE("Got too many results; skipping some"); | |
295 | } | |
296 | ||
297 | return i; | |
298 | } | |
299 | ||
300 | int createFeatureRequest(WifiRequest& request, int subcmd) { | |
301 | ||
302 | int result = request.create(GOOGLE_OUI, subcmd); | |
303 | if (result < 0) { | |
304 | return result; | |
305 | } | |
306 | ||
307 | return WIFI_SUCCESS; | |
308 | } | |
309 | ||
310 | class ScanCommand : public WifiCommand | |
311 | { | |
312 | wifi_scan_cmd_params *mParams; | |
313 | wifi_scan_result_handler mHandler; | |
314 | static unsigned mGlobalFullScanBuckets; | |
315 | bool mLocalFullScanBuckets; | |
316 | public: | |
317 | ScanCommand(wifi_interface_handle iface, int id, wifi_scan_cmd_params *params, | |
318 | wifi_scan_result_handler handler) | |
319 | : WifiCommand(iface, id), mParams(params), mHandler(handler), | |
320 | mLocalFullScanBuckets(0) | |
321 | { } | |
322 | ||
323 | int createSetupRequest(WifiRequest& request) { | |
324 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_ADD_GSCAN); | |
325 | if (result < 0) { | |
326 | return result; | |
327 | } | |
328 | ||
329 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
330 | result = request.put_u32(GSCAN_ATTRIBUTE_BASE_PERIOD, mParams->base_period); | |
331 | if (result < 0) { | |
332 | return result; | |
333 | } | |
334 | ||
acc9b163 | 335 | result = request.put_u32(GSCAN_ATTRIBUTE_NUM_AP_PER_SCAN, mParams->max_ap_per_scan); |
7753f181 DD |
336 | if (result < 0) { |
337 | return result; | |
338 | } | |
339 | ||
340 | result = request.put_u32(GSCAN_ATTRIBUTE_REPORT_THRESHOLD, mParams->report_threshold_percent); | |
341 | if (result < 0) { | |
342 | return result; | |
343 | } | |
344 | ||
345 | result = request.put_u32(GSCAN_ATTRIBUTE_REPORT_THRESHOLD_NUM_SCANS, mParams->report_threshold_num_scans); | |
346 | if (result < 0) { | |
347 | return result; | |
348 | } | |
349 | ||
350 | result = request.put_u32(GSCAN_ATTRIBUTE_NUM_BUCKETS, mParams->num_buckets); | |
351 | if (result < 0) { | |
352 | return result; | |
353 | } | |
354 | ||
355 | for (int i = 0; i < mParams->num_buckets; i++) { | |
356 | nlattr * bucket = request.attr_start(i); // next bucket | |
357 | result = request.put_u32(GSCAN_ATTRIBUTE_BUCKET_ID, mParams->buckets[i].bucket); | |
358 | if (result < 0) { | |
359 | return result; | |
360 | } | |
361 | result = request.put_u32(GSCAN_ATTRIBUTE_BUCKET_PERIOD, mParams->buckets[i].period); | |
362 | if (result < 0) { | |
363 | return result; | |
364 | } | |
365 | result = request.put_u32(GSCAN_ATTRIBUTE_BUCKETS_BAND, | |
366 | mParams->buckets[i].band); | |
367 | if (result < 0) { | |
368 | return result; | |
369 | } | |
370 | ||
371 | result = request.put_u32(GSCAN_ATTRIBUTE_REPORT_EVENTS, | |
372 | mParams->buckets[i].report_events); | |
373 | if (result < 0) { | |
374 | return result; | |
375 | } | |
376 | ||
377 | result = request.put_u32(GSCAN_ATTRIBUTE_BUCKET_NUM_CHANNELS, | |
378 | mParams->buckets[i].num_channels); | |
379 | if (result < 0) { | |
380 | return result; | |
381 | } | |
382 | ||
0e19df50 | 383 | result = request.put_u32(GSCAN_ATTRIBUTE_BUCKET_EXPONENT, |
acc9b163 | 384 | mParams->buckets[i].base); |
0e19df50 JPS |
385 | if (result < 0) { |
386 | return result; | |
387 | } | |
388 | ||
389 | result = request.put_u32(GSCAN_ATTRIBUTE_BUCKET_MAX_PERIOD, | |
390 | mParams->buckets[i].max_period); | |
391 | if (result < 0) { | |
392 | return result; | |
393 | } | |
394 | ||
395 | result = request.put_u32(GSCAN_ATTRIBUTE_BUCKET_STEP_COUNT, | |
396 | mParams->buckets[i].step_count); | |
397 | if (result < 0) { | |
398 | return result; | |
399 | } | |
400 | ||
7753f181 DD |
401 | if (mParams->buckets[i].num_channels) { |
402 | nlattr *channels = request.attr_start(GSCAN_ATTRIBUTE_BUCKET_CHANNELS); | |
403 | for (int j = 0; j < mParams->buckets[i].num_channels; j++) { | |
404 | result = request.put_u32(j, mParams->buckets[i].channels[j].channel); | |
405 | if (result < 0) { | |
406 | return result; | |
407 | } | |
408 | } | |
409 | request.attr_end(channels); | |
410 | } | |
411 | ||
412 | request.attr_end(bucket); | |
413 | } | |
414 | ||
415 | request.attr_end(data); | |
416 | return WIFI_SUCCESS; | |
417 | } | |
418 | ||
419 | int createStartRequest(WifiRequest& request) { | |
420 | return createFeatureRequest(request, SLSI_NL80211_VENDOR_SUBCMD_ADD_GSCAN); | |
421 | } | |
422 | ||
423 | int createStopRequest(WifiRequest& request) { | |
424 | return createFeatureRequest(request, SLSI_NL80211_VENDOR_SUBCMD_DEL_GSCAN); | |
425 | } | |
426 | ||
427 | int start() { | |
428 | ALOGD(" sending scan req to driver"); | |
429 | WifiRequest request(familyId(), ifaceId()); | |
430 | int result = createSetupRequest(request); | |
431 | if (result != WIFI_SUCCESS) { | |
432 | ALOGE("failed to create setup request; result = %d", result); | |
433 | return result; | |
434 | } | |
435 | ALOGD("Starting scan"); | |
436 | ||
437 | registerVendorHandler(GOOGLE_OUI, GSCAN_EVENT_SCAN_RESULTS_AVAILABLE); | |
438 | registerVendorHandler(GOOGLE_OUI, GSCAN_EVENT_COMPLETE_SCAN); | |
439 | ||
440 | int nBuckets = 0; | |
441 | for (int i = 0; i < mParams->num_buckets; i++) { | |
442 | if (mParams->buckets[i].report_events == 2) { | |
443 | nBuckets++; | |
444 | } | |
445 | } | |
446 | ||
447 | if (nBuckets != 0) { | |
448 | ALOGI("Full scan requested with nBuckets = %d", nBuckets); | |
449 | registerVendorHandler(GOOGLE_OUI, GSCAN_EVENT_FULL_SCAN_RESULTS); | |
450 | } | |
451 | result = requestResponse(request); | |
452 | if (result != WIFI_SUCCESS) { | |
453 | ALOGE("failed to start scan; result = %d", result); | |
454 | unregisterVendorHandler(GOOGLE_OUI, GSCAN_EVENT_COMPLETE_SCAN); | |
455 | unregisterVendorHandler(GOOGLE_OUI, GSCAN_EVENT_SCAN_RESULTS_AVAILABLE); | |
456 | return result; | |
457 | } | |
458 | ||
0fe9bfaf | 459 | |
7753f181 DD |
460 | return result; |
461 | } | |
462 | ||
463 | virtual int cancel() { | |
464 | ALOGD("Stopping scan"); | |
465 | ||
466 | WifiRequest request(familyId(), ifaceId()); | |
467 | int result = createStopRequest(request); | |
468 | if (result != WIFI_SUCCESS) { | |
469 | ALOGE("failed to create stop request; result = %d", result); | |
470 | } else { | |
471 | result = requestResponse(request); | |
472 | if (result != WIFI_SUCCESS) { | |
473 | ALOGE("failed to stop scan; result = %d", result); | |
474 | } | |
475 | } | |
476 | ||
477 | unregisterVendorHandler(GOOGLE_OUI, GSCAN_EVENT_COMPLETE_SCAN); | |
478 | unregisterVendorHandler(GOOGLE_OUI, GSCAN_EVENT_SCAN_RESULTS_AVAILABLE); | |
479 | unregisterVendorHandler(GOOGLE_OUI, GSCAN_EVENT_FULL_SCAN_RESULTS); | |
480 | ||
481 | return WIFI_SUCCESS; | |
482 | } | |
483 | ||
484 | virtual int handleResponse(WifiEvent& reply) { | |
485 | /* Nothing to do on response! */ | |
486 | return NL_SKIP; | |
487 | } | |
488 | ||
489 | virtual int handleEvent(WifiEvent& event) { | |
490 | ALOGD("Got a scan results event"); | |
491 | ||
492 | event.log(); | |
493 | ||
494 | nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA); | |
495 | unsigned int len = event.get_vendor_data_len(); | |
496 | int event_id = event.get_vendor_subcmd(); | |
497 | ALOGD("handleEvent, event_id = %d", event_id); | |
498 | ||
499 | if(event_id == GSCAN_EVENT_COMPLETE_SCAN) { | |
500 | if (vendor_data == NULL || len != 4) { | |
9a2ccc1c | 501 | ALOGE("Scan complete type not mentioned!"); |
7753f181 DD |
502 | return NL_SKIP; |
503 | } | |
504 | wifi_scan_event evt_type; | |
505 | ||
506 | evt_type = (wifi_scan_event) event.get_u32(NL80211_ATTR_VENDOR_DATA); | |
507 | ALOGD("Scan complete: Received event type %d", evt_type); | |
508 | if(*mHandler.on_scan_event) | |
509 | (*mHandler.on_scan_event)(evt_type, evt_type); | |
510 | } else if(event_id == GSCAN_EVENT_FULL_SCAN_RESULTS) { | |
0fe9bfaf | 511 | uint32_t bucket_scanned = 0; |
acc9b163 JPS |
512 | wifi_scan_result *scan_result = NULL; |
513 | for (nl_iterator it(vendor_data); it.has_next(); it.next()) { | |
514 | if (it.get_type() == GSCAN_ATTRIBUTE_SCAN_BUCKET_BIT) { | |
515 | bucket_scanned = it.get_u32(); | |
516 | } else if (it.get_type() == GSCAN_ATTRIBUTE_SCAN_RESULTS) { | |
517 | if (it.get_len() >= (int)sizeof(*scan_result)) | |
518 | scan_result = (wifi_scan_result *)it.get_data(); | |
519 | } | |
520 | } | |
521 | if (scan_result) { | |
522 | if(*mHandler.on_full_scan_result) | |
523 | (*mHandler.on_full_scan_result)(id(), scan_result, bucket_scanned); | |
524 | ||
525 | ALOGD("%-32s\t", scan_result->ssid); | |
526 | ALOGD("%02x:%02x:%02x:%02x:%02x:%02x ", scan_result->bssid[0], scan_result->bssid[1], | |
527 | scan_result->bssid[2], scan_result->bssid[3], scan_result->bssid[4], scan_result->bssid[5]); | |
528 | ALOGD("%d\t", scan_result->rssi); | |
529 | ALOGD("%d\t", scan_result->channel); | |
530 | ALOGD("%lld\t", scan_result->ts); | |
531 | ALOGD("%lld\t", scan_result->rtt); | |
532 | ALOGD("%lld\n", scan_result->rtt_sd); | |
7753f181 | 533 | } |
7753f181 DD |
534 | } |
535 | return NL_SKIP; | |
536 | } | |
537 | }; | |
538 | ||
539 | unsigned ScanCommand::mGlobalFullScanBuckets = 0; | |
540 | ||
541 | wifi_error wifi_start_gscan( | |
542 | wifi_request_id id, | |
543 | wifi_interface_handle iface, | |
544 | wifi_scan_cmd_params params, | |
545 | wifi_scan_result_handler handler) | |
546 | { | |
547 | wifi_handle handle = getWifiHandle(iface); | |
548 | ||
549 | ALOGD("Starting GScan, halHandle = %p", handle); | |
550 | ||
551 | ScanCommand *cmd = new ScanCommand(iface, id, ¶ms, handler); | |
552 | wifi_register_cmd(handle, id, cmd); | |
553 | return (wifi_error)cmd->start(); | |
554 | } | |
555 | ||
556 | wifi_error wifi_stop_gscan(wifi_request_id id, wifi_interface_handle iface) | |
557 | { | |
558 | ALOGD("Stopping GScan"); | |
559 | wifi_handle handle = getWifiHandle(iface); | |
560 | ||
561 | if(id == -1) { | |
562 | wifi_scan_result_handler handler; | |
563 | wifi_scan_cmd_params dummy_params; | |
564 | wifi_handle handle = getWifiHandle(iface); | |
565 | memset(&handler, 0, sizeof(handler)); | |
566 | ||
567 | ScanCommand *cmd = new ScanCommand(iface, id, &dummy_params, handler); | |
568 | cmd->cancel(); | |
569 | cmd->releaseRef(); | |
570 | return WIFI_SUCCESS; | |
571 | } | |
572 | ||
573 | ||
574 | WifiCommand *cmd = wifi_unregister_cmd(handle, id); | |
575 | if (cmd) { | |
576 | cmd->cancel(); | |
577 | cmd->releaseRef(); | |
578 | return WIFI_SUCCESS; | |
579 | } | |
580 | ||
581 | return WIFI_ERROR_INVALID_ARGS; | |
582 | } | |
583 | ||
584 | class GetScanResultsCommand : public WifiCommand { | |
585 | wifi_cached_scan_results *mScans; | |
586 | int mMax; | |
587 | int *mNum; | |
588 | int mRetrieved; | |
589 | byte mFlush; | |
590 | int mCompleted; | |
591 | static const int MAX_RESULTS = 320; | |
592 | wifi_scan_result mScanResults[MAX_RESULTS]; | |
593 | int mNextScanResult; | |
594 | public: | |
595 | GetScanResultsCommand(wifi_interface_handle iface, byte flush, | |
596 | wifi_cached_scan_results *results, int max, int *num) | |
597 | : WifiCommand(iface, -1), mScans(results), mMax(max), mNum(num), | |
598 | mRetrieved(0), mFlush(flush), mCompleted(0) | |
0fe9bfaf PG |
599 | { |
600 | memset(mScanResults,0,sizeof(mScanResults)); | |
601 | mNextScanResult = 0; | |
602 | } | |
7753f181 DD |
603 | |
604 | int createRequest(WifiRequest& request, int num, byte flush) { | |
605 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_GET_SCAN_RESULTS); | |
606 | if (result < 0) { | |
607 | return result; | |
608 | } | |
609 | ||
610 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
611 | result = request.put_u32(GSCAN_ATTRIBUTE_NUM_OF_RESULTS, num); | |
612 | if (result < 0) { | |
613 | return result; | |
614 | } | |
615 | ||
616 | request.attr_end(data); | |
617 | return WIFI_SUCCESS; | |
618 | } | |
619 | ||
620 | int execute() { | |
621 | WifiRequest request(familyId(), ifaceId()); | |
622 | ALOGD("retrieving %d scan results", mMax); | |
623 | ||
624 | for (int i = 0; i < 10 && mRetrieved < mMax; i++) { | |
625 | int result = createRequest(request, (mMax - mRetrieved), mFlush); | |
626 | if (result < 0) { | |
627 | ALOGE("failed to create request"); | |
628 | return result; | |
629 | } | |
630 | ||
631 | int prev_retrieved = mRetrieved; | |
632 | ||
633 | result = requestResponse(request); | |
634 | ||
635 | if (result != WIFI_SUCCESS) { | |
636 | ALOGE("failed to retrieve scan results; result = %d", result); | |
637 | return result; | |
638 | } | |
639 | ||
640 | if (mRetrieved == prev_retrieved || mCompleted) { | |
641 | /* no more items left to retrieve */ | |
642 | break; | |
643 | } | |
644 | ||
645 | request.destroy(); | |
646 | } | |
647 | ||
648 | ALOGE("GetScanResults read %d results", mRetrieved); | |
649 | *mNum = mRetrieved; | |
650 | return WIFI_SUCCESS; | |
651 | } | |
652 | ||
653 | virtual int handleResponse(WifiEvent& reply) { | |
7753f181 DD |
654 | |
655 | if (reply.get_cmd() != NL80211_CMD_VENDOR) { | |
656 | ALOGD("Ignoring reply with cmd = %d", reply.get_cmd()); | |
657 | return NL_SKIP; | |
658 | } | |
659 | ||
660 | int id = reply.get_vendor_id(); | |
661 | int subcmd = reply.get_vendor_subcmd(); | |
662 | ||
9a2ccc1c | 663 | ALOGD("GetScanResultsCommand::handleResponse - Id = %0x, subcmd = %d", id, subcmd); |
7753f181 DD |
664 | |
665 | nlattr *vendor_data = reply.get_attribute(NL80211_ATTR_VENDOR_DATA); | |
666 | int len = reply.get_vendor_data_len(); | |
667 | ||
668 | if (vendor_data == NULL || len == 0) { | |
669 | ALOGE("no vendor data in GetScanResults response; ignoring it"); | |
670 | return NL_SKIP; | |
671 | } | |
672 | ||
673 | for (nl_iterator it(vendor_data); it.has_next(); it.next()) { | |
674 | if (it.get_type() == GSCAN_ATTRIBUTE_SCAN_RESULTS_COMPLETE) { | |
675 | mCompleted = it.get_u8(); | |
676 | ALOGD("retrieved mCompleted flag : %d", mCompleted); | |
677 | } else if (it.get_type() == GSCAN_ATTRIBUTE_SCAN_RESULTS || it.get_type() == 0) { | |
678 | int scan_id = 0, flags = 0, num = 0; | |
679 | for (nl_iterator it2(it.get()); it2.has_next(); it2.next()) { | |
680 | if (it2.get_type() == GSCAN_ATTRIBUTE_SCAN_ID) { | |
681 | scan_id = it2.get_u32(); | |
682 | ALOGD("retrieved scan_id : 0x%0x", scan_id); | |
683 | } else if (it2.get_type() == GSCAN_ATTRIBUTE_SCAN_FLAGS) { | |
684 | flags = it2.get_u8(); | |
685 | ALOGD("retrieved scan_flags : 0x%0x", flags); | |
686 | } else if (it2.get_type() == GSCAN_ATTRIBUTE_NUM_OF_RESULTS) { | |
687 | num = it2.get_u32(); | |
688 | ALOGD("retrieved num_results: %d", num); | |
689 | } else if (it2.get_type() == GSCAN_ATTRIBUTE_SCAN_RESULTS) { | |
690 | if (mRetrieved >= mMax) { | |
691 | ALOGW("Stored %d scans, ignoring excess results", mRetrieved); | |
692 | break; | |
693 | } | |
694 | num = it2.get_len() / sizeof(wifi_scan_result); | |
695 | num = min(MAX_RESULTS - mNextScanResult, num); | |
696 | num = min((int)MAX_AP_CACHE_PER_SCAN, num); | |
697 | memcpy(mScanResults + mNextScanResult, it2.get_data(), | |
698 | sizeof(wifi_scan_result) * num); | |
699 | ALOGD("Retrieved %d scan results", num); | |
700 | wifi_scan_result *results = (wifi_scan_result *)it2.get_data(); | |
701 | for (int i = 0; i < num; i++) { | |
702 | wifi_scan_result *result = results + i; | |
703 | ALOGD("%02d %-32s %02x:%02x:%02x:%02x:%02x:%02x %04d", i, | |
704 | result->ssid, result->bssid[0], result->bssid[1], result->bssid[2], | |
705 | result->bssid[3], result->bssid[4], result->bssid[5], | |
706 | result->rssi); | |
707 | } | |
708 | mScans[mRetrieved].scan_id = scan_id; | |
709 | mScans[mRetrieved].flags = flags; | |
710 | mScans[mRetrieved].num_results = num; | |
711 | ALOGD("Setting result of scan_id : 0x%0x", mScans[mRetrieved].scan_id); | |
712 | memcpy(mScans[mRetrieved].results, | |
713 | &(mScanResults[mNextScanResult]), num * sizeof(wifi_scan_result)); | |
714 | mNextScanResult += num; | |
715 | mRetrieved++; | |
716 | } else { | |
717 | ALOGW("Ignoring invalid attribute type = %d, size = %d", | |
718 | it.get_type(), it.get_len()); | |
719 | } | |
720 | } | |
721 | } else { | |
722 | ALOGW("Ignoring invalid attribute type = %d, size = %d", | |
723 | it.get_type(), it.get_len()); | |
724 | } | |
725 | } | |
726 | ||
727 | return NL_OK; | |
728 | } | |
729 | }; | |
730 | ||
731 | wifi_error wifi_get_cached_gscan_results(wifi_interface_handle iface, byte flush, | |
732 | int max, wifi_cached_scan_results *results, int *num) { | |
733 | ALOGD("Getting cached scan results, iface handle = %p, num = %d", iface, *num); | |
734 | ||
735 | GetScanResultsCommand *cmd = new GetScanResultsCommand(iface, flush, results, max, num); | |
736 | return (wifi_error)cmd->execute(); | |
737 | } | |
738 | ||
739 | ///////////////////////////////////////////////////////////////////////////// | |
740 | ||
741 | class BssidHotlistCommand : public WifiCommand | |
742 | { | |
743 | private: | |
744 | wifi_bssid_hotlist_params mParams; | |
745 | wifi_hotlist_ap_found_handler mHandler; | |
746 | static const int MAX_RESULTS = 64; | |
747 | wifi_scan_result mResults[MAX_RESULTS]; | |
748 | public: | |
749 | BssidHotlistCommand(wifi_interface_handle handle, int id, | |
750 | wifi_bssid_hotlist_params params, wifi_hotlist_ap_found_handler handler) | |
751 | : WifiCommand(handle, id), mParams(params), mHandler(handler) | |
0fe9bfaf PG |
752 | { |
753 | memset(mResults, 0, sizeof(mResults)); | |
754 | } | |
7753f181 DD |
755 | |
756 | int createSetupRequest(WifiRequest& request) { | |
757 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_SET_BSSID_HOTLIST); | |
758 | if (result < 0) { | |
759 | return result; | |
760 | } | |
761 | ||
762 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
763 | ||
764 | result = request.put_u32(GSCAN_ATTRIBUTE_LOST_AP_SAMPLE_SIZE, mParams.lost_ap_sample_size); | |
765 | if (result < 0) { | |
766 | return result; | |
767 | } | |
768 | ||
769 | struct nlattr * attr = request.attr_start(GSCAN_ATTRIBUTE_HOTLIST_BSSIDS); | |
770 | for (int i = 0; i < mParams.num_bssid; i++) { | |
771 | nlattr *attr2 = request.attr_start(GSCAN_ATTRIBUTE_HOTLIST_ELEM); | |
772 | if (attr2 == NULL) { | |
773 | return WIFI_ERROR_OUT_OF_MEMORY; | |
774 | } | |
775 | result = request.put_addr(GSCAN_ATTRIBUTE_BSSID, mParams.ap[i].bssid); | |
776 | if (result < 0) { | |
777 | return result; | |
778 | } | |
779 | result = request.put_u8(GSCAN_ATTRIBUTE_RSSI_HIGH, mParams.ap[i].high); | |
780 | if (result < 0) { | |
781 | return result; | |
782 | } | |
783 | result = request.put_u8(GSCAN_ATTRIBUTE_RSSI_LOW, mParams.ap[i].low); | |
784 | if (result < 0) { | |
785 | return result; | |
786 | } | |
787 | request.attr_end(attr2); | |
788 | } | |
789 | ||
790 | request.attr_end(attr); | |
791 | request.attr_end(data); | |
792 | return result; | |
793 | } | |
794 | ||
795 | int createTeardownRequest(WifiRequest& request) { | |
796 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_RESET_BSSID_HOTLIST); | |
797 | if (result < 0) { | |
798 | return result; | |
799 | } | |
800 | ||
801 | return result; | |
802 | } | |
803 | ||
804 | int start() { | |
805 | ALOGD("Executing hotlist setup request, num = %d", mParams.num_bssid); | |
806 | WifiRequest request(familyId(), ifaceId()); | |
807 | int result = createSetupRequest(request); | |
808 | if (result < 0) { | |
809 | return result; | |
810 | } | |
811 | ||
812 | result = requestResponse(request); | |
813 | if (result < 0) { | |
814 | ALOGD("Failed to execute hotlist setup request, result = %d", result); | |
815 | unregisterVendorHandler(GOOGLE_OUI, GSCAN_EVENT_HOTLIST_RESULTS_FOUND); | |
816 | unregisterVendorHandler(GOOGLE_OUI, GSCAN_EVENT_HOTLIST_RESULTS_LOST); | |
817 | return result; | |
818 | } | |
819 | ||
820 | ALOGD("Successfully set %d APs in the hotlist", mParams.num_bssid); | |
821 | ||
822 | registerVendorHandler(GOOGLE_OUI, GSCAN_EVENT_HOTLIST_RESULTS_FOUND); | |
823 | registerVendorHandler(GOOGLE_OUI, GSCAN_EVENT_HOTLIST_RESULTS_LOST); | |
824 | ||
825 | return result; | |
826 | } | |
827 | ||
828 | virtual int cancel() { | |
829 | /* unregister event handler */ | |
830 | unregisterVendorHandler(GOOGLE_OUI, GSCAN_EVENT_HOTLIST_RESULTS_FOUND); | |
831 | unregisterVendorHandler(GOOGLE_OUI, GSCAN_EVENT_HOTLIST_RESULTS_LOST); | |
832 | /* create set hotlist message with empty hotlist */ | |
833 | WifiRequest request(familyId(), ifaceId()); | |
834 | int result = createTeardownRequest(request); | |
835 | if (result < 0) { | |
836 | return result; | |
837 | } | |
838 | ||
839 | result = requestResponse(request); | |
840 | if (result < 0) { | |
841 | return result; | |
842 | } | |
843 | ||
844 | ALOGD("Successfully reset APs in current hotlist"); | |
845 | return result; | |
846 | } | |
847 | ||
848 | virtual int handleResponse(WifiEvent& reply) { | |
849 | /* Nothing to do on response! */ | |
850 | return NL_SKIP; | |
851 | } | |
852 | ||
853 | virtual int handleEvent(WifiEvent& event) { | |
854 | ALOGD("Hotlist AP event"); | |
855 | int event_id = event.get_vendor_subcmd(); | |
856 | event.log(); | |
857 | ||
858 | nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA); | |
859 | int len = event.get_vendor_data_len(); | |
860 | ||
861 | if (vendor_data == NULL || len == 0) { | |
9a2ccc1c | 862 | ALOGE("No scan results found"); |
7753f181 DD |
863 | return NL_SKIP; |
864 | } | |
865 | ||
7753f181 DD |
866 | |
867 | int num = len / sizeof(wifi_scan_result); | |
868 | num = min(MAX_RESULTS, num); | |
869 | memcpy(mResults, event.get_vendor_data(), num * sizeof(wifi_scan_result)); | |
870 | ||
871 | if (event_id == GSCAN_EVENT_HOTLIST_RESULTS_FOUND) { | |
872 | ALOGD("FOUND %d hotlist APs", num); | |
873 | if (*mHandler.on_hotlist_ap_found) | |
874 | (*mHandler.on_hotlist_ap_found)(id(), num, mResults); | |
875 | } else if (event_id == GSCAN_EVENT_HOTLIST_RESULTS_LOST) { | |
876 | ALOGD("LOST %d hotlist APs", num); | |
877 | if (*mHandler.on_hotlist_ap_lost) | |
878 | (*mHandler.on_hotlist_ap_lost)(id(), num, mResults); | |
879 | } | |
880 | return NL_SKIP; | |
881 | } | |
882 | }; | |
883 | ||
884 | wifi_error wifi_set_bssid_hotlist(wifi_request_id id, wifi_interface_handle iface, | |
885 | wifi_bssid_hotlist_params params, wifi_hotlist_ap_found_handler handler) | |
886 | { | |
887 | wifi_handle handle = getWifiHandle(iface); | |
888 | ||
889 | BssidHotlistCommand *cmd = new BssidHotlistCommand(iface, id, params, handler); | |
890 | wifi_register_cmd(handle, id, cmd); | |
891 | return (wifi_error)cmd->start(); | |
892 | } | |
893 | ||
894 | wifi_error wifi_reset_bssid_hotlist(wifi_request_id id, wifi_interface_handle iface) | |
895 | { | |
896 | wifi_handle handle = getWifiHandle(iface); | |
897 | ||
898 | WifiCommand *cmd = wifi_unregister_cmd(handle, id); | |
899 | if (cmd) { | |
900 | cmd->cancel(); | |
901 | cmd->releaseRef(); | |
902 | return WIFI_SUCCESS; | |
903 | } | |
904 | ||
905 | return WIFI_ERROR_INVALID_ARGS; | |
906 | } | |
907 | ||
908 | ||
909 | ///////////////////////////////////////////////////////////////////////////// | |
910 | ||
911 | class SignificantWifiChangeCommand : public WifiCommand | |
912 | { | |
913 | typedef struct { | |
914 | mac_addr bssid; // BSSID | |
915 | wifi_channel channel; // channel frequency in MHz | |
916 | int num_rssi; // number of rssi samples | |
917 | wifi_rssi rssi[8]; // RSSI history in db | |
918 | } wifi_significant_change_result_internal; | |
919 | ||
920 | private: | |
921 | wifi_significant_change_params mParams; | |
922 | wifi_significant_change_handler mHandler; | |
923 | static const int MAX_RESULTS = 64; | |
924 | wifi_significant_change_result_internal mResultsBuffer[MAX_RESULTS]; | |
925 | wifi_significant_change_result *mResults[MAX_RESULTS]; | |
926 | public: | |
927 | SignificantWifiChangeCommand(wifi_interface_handle handle, int id, | |
928 | wifi_significant_change_params params, wifi_significant_change_handler handler) | |
929 | : WifiCommand(handle, id), mParams(params), mHandler(handler) | |
0fe9bfaf PG |
930 | { |
931 | memset(mResultsBuffer,0,sizeof(mResultsBuffer)); | |
932 | memset(mResults,0,sizeof(mResults)); | |
933 | } | |
7753f181 DD |
934 | |
935 | int createSetupRequest(WifiRequest& request) { | |
936 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_SET_SIGNIFICANT_CHANGE); | |
937 | if (result < 0) { | |
938 | return result; | |
939 | } | |
940 | ||
941 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
942 | ||
943 | result = request.put_u16(GSCAN_ATTRIBUTE_RSSI_SAMPLE_SIZE, mParams.rssi_sample_size); | |
944 | if (result < 0) { | |
945 | return result; | |
946 | } | |
947 | result = request.put_u16(GSCAN_ATTRIBUTE_LOST_AP_SAMPLE_SIZE, mParams.lost_ap_sample_size); | |
948 | if (result < 0) { | |
949 | return result; | |
950 | } | |
951 | result = request.put_u16(GSCAN_ATTRIBUTE_MIN_BREACHING, mParams.min_breaching); | |
952 | if (result < 0) { | |
953 | return result; | |
954 | } | |
955 | ||
956 | struct nlattr * attr = request.attr_start(GSCAN_ATTRIBUTE_SIGNIFICANT_CHANGE_BSSIDS); | |
957 | ||
958 | for (int i = 0; i < mParams.num_bssid; i++) { | |
959 | ||
960 | nlattr *attr2 = request.attr_start(i); | |
961 | if (attr2 == NULL) { | |
962 | return WIFI_ERROR_OUT_OF_MEMORY; | |
963 | } | |
964 | result = request.put_addr(GSCAN_ATTRIBUTE_BSSID, mParams.ap[i].bssid); | |
965 | if (result < 0) { | |
966 | return result; | |
967 | } | |
968 | result = request.put_u8(GSCAN_ATTRIBUTE_RSSI_HIGH, mParams.ap[i].high); | |
969 | if (result < 0) { | |
970 | return result; | |
971 | } | |
972 | result = request.put_u8(GSCAN_ATTRIBUTE_RSSI_LOW, mParams.ap[i].low); | |
973 | if (result < 0) { | |
974 | return result; | |
975 | } | |
976 | request.attr_end(attr2); | |
977 | } | |
978 | ||
979 | request.attr_end(attr); | |
980 | request.attr_end(data); | |
981 | ||
982 | return result; | |
983 | } | |
984 | ||
985 | int createTeardownRequest(WifiRequest& request) { | |
986 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_RESET_SIGNIFICANT_CHANGE); | |
987 | if (result < 0) { | |
988 | return result; | |
989 | } | |
990 | ||
991 | return result; | |
992 | } | |
993 | ||
994 | int start() { | |
995 | ALOGD("Set significant wifi change"); | |
996 | WifiRequest request(familyId(), ifaceId()); | |
997 | ||
998 | int result = createSetupRequest(request); | |
999 | if (result < 0) { | |
1000 | return result; | |
1001 | } | |
1002 | ||
1003 | result = requestResponse(request); | |
1004 | if (result < 0) { | |
1005 | ALOGD("failed to set significant wifi change %d", result); | |
1006 | return result; | |
1007 | } | |
1008 | registerVendorHandler(GOOGLE_OUI, GSCAN_EVENT_SIGNIFICANT_CHANGE_RESULTS); | |
1009 | ||
1010 | return result; | |
1011 | } | |
1012 | ||
1013 | virtual int cancel() { | |
1014 | /* unregister event handler */ | |
1015 | unregisterVendorHandler(GOOGLE_OUI, GSCAN_EVENT_SIGNIFICANT_CHANGE_RESULTS); | |
1016 | ||
1017 | /* create set significant change monitor message with empty hotlist */ | |
1018 | WifiRequest request(familyId(), ifaceId()); | |
1019 | ||
1020 | int result = createTeardownRequest(request); | |
1021 | if (result < 0) { | |
1022 | return result; | |
1023 | } | |
1024 | ||
1025 | result = requestResponse(request); | |
1026 | if (result < 0) { | |
1027 | return result; | |
1028 | } | |
1029 | ||
1030 | ALOGD("successfully reset significant wifi change"); | |
1031 | return result; | |
1032 | } | |
1033 | ||
1034 | virtual int handleResponse(WifiEvent& reply) { | |
1035 | /* Nothing to do on response! */ | |
1036 | return NL_SKIP; | |
1037 | } | |
1038 | ||
1039 | virtual int handleEvent(WifiEvent& event) { | |
1040 | ALOGD("Got a significant wifi change event"); | |
1041 | ||
1042 | nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA); | |
1043 | int len = event.get_vendor_data_len(); | |
1044 | ||
1045 | if (vendor_data == NULL || len == 0) { | |
9a2ccc1c | 1046 | ALOGE("No scan results found"); |
7753f181 DD |
1047 | return NL_SKIP; |
1048 | } | |
1049 | ||
1050 | typedef struct { | |
1051 | uint16_t channel; | |
1052 | mac_addr bssid; | |
1053 | int16_t rssi_history[8]; | |
1054 | } ChangeInfo; | |
1055 | ||
1056 | int num = min(len / sizeof(ChangeInfo), MAX_RESULTS); | |
1057 | ChangeInfo *ci = (ChangeInfo *)event.get_vendor_data(); | |
1058 | ||
1059 | for (int i = 0; i < num; i++) { | |
1060 | memcpy(mResultsBuffer[i].bssid, ci[i].bssid, sizeof(mac_addr)); | |
1061 | mResultsBuffer[i].channel = ci[i].channel; | |
acc9b163 JPS |
1062 | /* Driver sends N samples and the rest 8-N are filled 0x7FFF |
1063 | * N = no of rssi samples to average sent in significant change request. */ | |
7753f181 DD |
1064 | int num_rssi = 0; |
1065 | for (int j = 0; j < 8; j++) { | |
1066 | if (ci[i].rssi_history[j] == 0x7FFF) { | |
1067 | num_rssi = j; | |
1068 | break; | |
1069 | } | |
1070 | mResultsBuffer[i].rssi[j] = (int) ci[i].rssi_history[j]; | |
1071 | } | |
1072 | mResultsBuffer[i].num_rssi = num_rssi; | |
1073 | mResults[i] = reinterpret_cast<wifi_significant_change_result *>(&(mResultsBuffer[i])); | |
1074 | } | |
1075 | ||
1076 | ALOGD("Retrieved %d scan results", num); | |
1077 | ||
1078 | if (num != 0) { | |
1079 | (*mHandler.on_significant_change)(id(), num, mResults); | |
1080 | } else { | |
1081 | ALOGW("No significant change reported"); | |
1082 | } | |
1083 | ||
1084 | return NL_SKIP; | |
1085 | } | |
1086 | }; | |
1087 | ||
1088 | wifi_error wifi_set_significant_change_handler(wifi_request_id id, wifi_interface_handle iface, | |
1089 | wifi_significant_change_params params, wifi_significant_change_handler handler) | |
1090 | { | |
1091 | wifi_handle handle = getWifiHandle(iface); | |
1092 | ||
1093 | SignificantWifiChangeCommand *cmd = new SignificantWifiChangeCommand( | |
1094 | iface, id, params, handler); | |
1095 | wifi_register_cmd(handle, id, cmd); | |
1096 | return (wifi_error)cmd->start(); | |
1097 | } | |
1098 | ||
1099 | wifi_error wifi_reset_significant_change_handler(wifi_request_id id, wifi_interface_handle iface) | |
1100 | { | |
1101 | wifi_handle handle = getWifiHandle(iface); | |
1102 | ||
1103 | WifiCommand *cmd = wifi_unregister_cmd(handle, id); | |
1104 | if (cmd) { | |
1105 | cmd->cancel(); | |
1106 | cmd->releaseRef(); | |
1107 | return WIFI_SUCCESS; | |
1108 | } | |
1109 | ||
1110 | return WIFI_ERROR_INVALID_ARGS; | |
1111 | } | |
c15187c1 | 1112 | |
6ff2d683 JPS |
1113 | class ePNOCommand : public WifiCommand |
1114 | { | |
1115 | private: | |
c15187c1 | 1116 | wifi_epno_params *epno_params; |
6ff2d683 JPS |
1117 | wifi_epno_handler mHandler; |
1118 | wifi_scan_result mResults; | |
1119 | public: | |
1120 | ePNOCommand(wifi_interface_handle handle, int id, | |
c15187c1 | 1121 | wifi_epno_params *params, wifi_epno_handler handler) |
6ff2d683 JPS |
1122 | : WifiCommand(handle, id), mHandler(handler) |
1123 | { | |
c15187c1 | 1124 | epno_params = params; |
0fe9bfaf | 1125 | memset(&mResults,0,sizeof(wifi_scan_result)); |
6ff2d683 JPS |
1126 | } |
1127 | ||
1128 | int createSetupRequest(WifiRequest& request) { | |
1129 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_SET_EPNO_LIST); | |
1130 | if (result < 0) { | |
1131 | return result; | |
1132 | } | |
1133 | ||
1134 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
c15187c1 JPS |
1135 | if (epno_params == NULL) { |
1136 | result = request.put_u8(EPNO_ATTRIBUTE_SSID_NUM, 0); | |
1137 | if (result < 0) { | |
1138 | return result; | |
1139 | } | |
1140 | request.attr_end(data); | |
1141 | return result; | |
1142 | } | |
1fc70afb MG |
1143 | result = request.put_u16(EPNO_ATTRIBUTE_MINIMUM_5G_RSSI, epno_params->min5GHz_rssi); |
1144 | if (result < 0) { | |
1145 | return result; | |
1146 | } | |
1147 | result = request.put_u16(EPNO_ATTRIBUTE_MINIMUM_2G_RSSI, epno_params->min24GHz_rssi); | |
1148 | if (result < 0) { | |
1149 | return result; | |
1150 | } | |
1151 | result = request.put_u16(EPNO_ATTRIBUTE_INITIAL_SCORE_MAX, epno_params->initial_score_max); | |
1152 | if (result < 0) { | |
1153 | return result; | |
1154 | } | |
1155 | result = request.put_u8(EPNO_ATTRIBUTE_CUR_CONN_BONUS, epno_params->current_connection_bonus); | |
1156 | if (result < 0) { | |
1157 | return result; | |
1158 | } | |
1159 | result = request.put_u8(EPNO_ATTRIBUTE_SAME_NETWORK_BONUS, epno_params->same_network_bonus); | |
1160 | if (result < 0) { | |
1161 | return result; | |
1162 | } | |
1163 | result = request.put_u8(EPNO_ATTRIBUTE_SECURE_BONUS, epno_params->secure_bonus); | |
1164 | if (result < 0) { | |
1165 | return result; | |
1166 | } | |
1167 | result = request.put_u8(EPNO_ATTRIBUTE_5G_BONUS, epno_params->band5GHz_bonus); | |
1168 | if (result < 0) { | |
1169 | return result; | |
1170 | } | |
c15187c1 | 1171 | result = request.put_u8(EPNO_ATTRIBUTE_SSID_NUM, epno_params->num_networks); |
6ff2d683 JPS |
1172 | if (result < 0) { |
1173 | return result; | |
1174 | } | |
1175 | ||
1fc70afb MG |
1176 | ALOGI("ePNO [min5GHz_rssi:%d min24GHz_rssi:%d initial_score_max:%d current_connection_bonus:%d same_network_bonus:%d secure_bonus:%d band5GHz_bonus:%d num_networks:%d]", |
1177 | epno_params->min5GHz_rssi, | |
1178 | epno_params->min24GHz_rssi, | |
1179 | epno_params->initial_score_max, | |
1180 | epno_params->current_connection_bonus, | |
1181 | epno_params->same_network_bonus, | |
1182 | epno_params->secure_bonus, | |
1183 | epno_params->band5GHz_bonus, | |
1184 | epno_params->num_networks); | |
1185 | ||
6ff2d683 | 1186 | struct nlattr * attr = request.attr_start(EPNO_ATTRIBUTE_SSID_LIST); |
c15187c1 | 1187 | for (int i = 0; i < epno_params->num_networks; i++) { |
6ff2d683 JPS |
1188 | nlattr *attr2 = request.attr_start(i); |
1189 | if (attr2 == NULL) { | |
1190 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1191 | } | |
1fc70afb | 1192 | result = request.put_u16(EPNO_ATTRIBUTE_FLAGS, epno_params->networks[i].flags); |
6ff2d683 JPS |
1193 | if (result < 0) { |
1194 | return result; | |
1195 | } | |
1fc70afb | 1196 | result = request.put_u8(EPNO_ATTRIBUTE_AUTH, epno_params->networks[i].auth_bit_field); |
6ff2d683 JPS |
1197 | if (result < 0) { |
1198 | return result; | |
1199 | } | |
1fc70afb | 1200 | result = request.put_u8(EPNO_ATTRIBUTE_SSID_LEN, strlen(epno_params->networks[i].ssid)); |
6ff2d683 JPS |
1201 | if (result < 0) { |
1202 | return result; | |
1203 | } | |
1fc70afb MG |
1204 | result = request.put(EPNO_ATTRIBUTE_SSID, epno_params->networks[i].ssid, strlen(epno_params->networks[i].ssid)); |
1205 | ALOGI("ePNO [SSID:%s flags:%d auth:%d]", epno_params->networks[i].ssid, | |
1206 | epno_params->networks[i].flags, | |
1207 | epno_params->networks[i].auth_bit_field); | |
6ff2d683 JPS |
1208 | if (result < 0) { |
1209 | return result; | |
1210 | } | |
1211 | request.attr_end(attr2); | |
1212 | } | |
1213 | ||
1214 | request.attr_end(attr); | |
1215 | request.attr_end(data); | |
1216 | return result; | |
1217 | } | |
1218 | ||
1219 | int start() { | |
c15187c1 | 1220 | ALOGI("ePNO num_network=%d", epno_params ? epno_params->num_networks : 0); |
6ff2d683 JPS |
1221 | WifiRequest request(familyId(), ifaceId()); |
1222 | int result = createSetupRequest(request); | |
1223 | if (result < 0) { | |
1224 | return result; | |
1225 | } | |
1226 | ||
1227 | result = requestResponse(request); | |
1228 | if (result < 0) { | |
1229 | ALOGI("Failed: ePNO setup request, result = %d", result); | |
1230 | unregisterVendorHandler(GOOGLE_OUI, WIFI_EPNO_EVENT); | |
1231 | return result; | |
1232 | } | |
1233 | ||
c15187c1 JPS |
1234 | if (epno_params) { |
1235 | ALOGI("Successfully set %d SSIDs for ePNO", epno_params->num_networks); | |
1236 | registerVendorHandler(GOOGLE_OUI, WIFI_EPNO_EVENT); | |
1237 | } else { | |
1238 | ALOGI("Successfully reset ePNO"); | |
1239 | } | |
6ff2d683 JPS |
1240 | return result; |
1241 | } | |
1242 | ||
1243 | virtual int cancel() { | |
1244 | /* unregister event handler */ | |
1245 | unregisterVendorHandler(GOOGLE_OUI, WIFI_EPNO_EVENT); | |
1246 | return 0; | |
1247 | } | |
1248 | ||
1249 | virtual int handleResponse(WifiEvent& reply) { | |
1250 | /* Nothing to do on response! */ | |
1251 | return NL_SKIP; | |
1252 | } | |
1253 | ||
1254 | virtual int handleEvent(WifiEvent& event) { | |
1255 | ALOGI("ePNO event"); | |
1256 | int event_id = event.get_vendor_subcmd(); | |
1257 | // event.log(); | |
1258 | ||
1259 | nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA); | |
1260 | int len = event.get_vendor_data_len(); | |
1261 | ||
1262 | if (vendor_data == NULL || len == 0) { | |
1263 | ALOGI("No scan results found"); | |
1264 | return NL_SKIP; | |
1265 | } | |
1266 | ||
0fe9bfaf | 1267 | |
6ff2d683 JPS |
1268 | mResults = *(wifi_scan_result *) event.get_vendor_data(); |
1269 | if (*mHandler.on_network_found) | |
1270 | (*mHandler.on_network_found)(id(), 1, &mResults); | |
1271 | return NL_SKIP; | |
1272 | } | |
1273 | }; | |
1274 | ||
1275 | wifi_error wifi_set_epno_list(wifi_request_id id, | |
1276 | wifi_interface_handle iface, | |
c15187c1 | 1277 | const wifi_epno_params *epno_params, |
6ff2d683 JPS |
1278 | wifi_epno_handler handler) |
1279 | { | |
c15187c1 | 1280 | wifi_handle handle = getWifiHandle(iface); |
c15187c1 JPS |
1281 | ePNOCommand *cmd = new ePNOCommand(iface, id, (wifi_epno_params *)epno_params, handler); |
1282 | wifi_register_cmd(handle, id, cmd); | |
1283 | wifi_error result = (wifi_error)cmd->start(); | |
1284 | if (result != WIFI_SUCCESS) { | |
1285 | wifi_unregister_cmd(handle, id); | |
1286 | } | |
1287 | return result; | |
1288 | } | |
1289 | ||
1290 | wifi_error wifi_reset_epno_list(wifi_request_id id, wifi_interface_handle iface) | |
1291 | { | |
1292 | wifi_handle handle = getWifiHandle(iface); | |
1293 | wifi_epno_handler handler; | |
1294 | ||
1295 | handler.on_network_found = NULL; | |
1296 | ePNOCommand *cmd = new ePNOCommand(iface, id, NULL, handler); | |
1297 | wifi_register_cmd(handle, id, cmd); | |
1298 | wifi_error result = (wifi_error)cmd->start(); | |
1299 | if (result != WIFI_SUCCESS) { | |
1300 | wifi_unregister_cmd(handle, id); | |
1301 | } | |
1302 | return result; | |
6ff2d683 JPS |
1303 | } |
1304 | ||
1305 | class HsListCommand : public WifiCommand | |
1306 | { | |
1307 | int num_hs; | |
1308 | wifi_passpoint_network *mNetworks; | |
1309 | wifi_passpoint_event_handler mHandler; | |
1310 | public: | |
1311 | HsListCommand(wifi_request_id id, wifi_interface_handle iface, | |
1312 | int num, wifi_passpoint_network *hs_list, wifi_passpoint_event_handler handler) | |
1313 | : WifiCommand(iface, id), num_hs(num), mNetworks(hs_list), | |
1314 | mHandler(handler) | |
1315 | { | |
1316 | } | |
1317 | ||
1318 | HsListCommand(wifi_request_id id, wifi_interface_handle iface, | |
1319 | int num) | |
1320 | : WifiCommand(iface, id), num_hs(num), mNetworks(NULL) | |
1321 | { | |
0fe9bfaf | 1322 | mHandler.on_passpoint_network_found = NULL; |
6ff2d683 JPS |
1323 | } |
1324 | ||
1325 | int createRequest(WifiRequest& request, int val) { | |
1326 | int result; | |
1327 | ||
1328 | if (val) { | |
1329 | result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_SET_HS_LIST); | |
1330 | result = request.put_u32(EPNO_ATTRIBUTE_HS_NUM, num_hs); | |
1331 | if (result < 0) { | |
1332 | return result; | |
1333 | } | |
1334 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
1335 | ||
1336 | struct nlattr * attr = request.attr_start(EPNO_ATTRIBUTE_HS_PARAM_LIST); | |
1337 | for (int i = 0; i < num_hs; i++) { | |
1338 | nlattr *attr2 = request.attr_start(i); | |
1339 | if (attr2 == NULL) { | |
1340 | return WIFI_ERROR_OUT_OF_MEMORY; | |
1341 | } | |
1342 | result = request.put_u32(EPNO_ATTRIBUTE_HS_ID, mNetworks[i].id); | |
1343 | if (result < 0) { | |
1344 | return result; | |
1345 | } | |
1346 | result = request.put(EPNO_ATTRIBUTE_HS_REALM, mNetworks[i].realm, 256); | |
1347 | if (result < 0) { | |
1348 | return result; | |
1349 | } | |
1350 | result = request.put(EPNO_ATTRIBUTE_HS_CONSORTIUM_IDS, mNetworks[i].roamingConsortiumIds, 128); | |
1351 | if (result < 0) { | |
1352 | return result; | |
1353 | } | |
1354 | result = request.put(EPNO_ATTRIBUTE_HS_PLMN, mNetworks[i].plmn, 3); | |
1355 | if (result < 0) { | |
1356 | return result; | |
1357 | } | |
1358 | request.attr_end(attr2); | |
1359 | } | |
1360 | request.attr_end(attr); | |
1361 | request.attr_end(data); | |
1362 | }else { | |
1363 | result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_RESET_HS_LIST); | |
1364 | if (result < 0) { | |
1365 | return result; | |
1366 | } | |
1367 | } | |
1368 | ||
1369 | return WIFI_SUCCESS; | |
1370 | } | |
1371 | ||
1372 | int start() { | |
1373 | ||
1374 | WifiRequest request(familyId(), ifaceId()); | |
1375 | int result = createRequest(request, num_hs); | |
1376 | if (result != WIFI_SUCCESS) { | |
1377 | ALOGE("failed to create request; result = %d", result); | |
1378 | return result; | |
1379 | } | |
1380 | ||
1381 | registerVendorHandler(GOOGLE_OUI, WIFI_HOTSPOT_MATCH); | |
1382 | ||
1383 | result = requestResponse(request); | |
1384 | if (result != WIFI_SUCCESS) { | |
1385 | ALOGE("failed to set ANQPO networks; result = %d", result); | |
1386 | unregisterVendorHandler(GOOGLE_OUI, WIFI_HOTSPOT_MATCH); | |
1387 | return result; | |
1388 | } | |
1389 | ||
1390 | return result; | |
1391 | } | |
1392 | ||
1393 | virtual int cancel() { | |
1394 | ||
1395 | WifiRequest request(familyId(), ifaceId()); | |
1396 | int result = createRequest(request, 0); | |
1397 | if (result != WIFI_SUCCESS) { | |
1398 | ALOGE("failed to create request; result = %d", result); | |
1399 | } else { | |
1400 | result = requestResponse(request); | |
1401 | if (result != WIFI_SUCCESS) { | |
1402 | ALOGE("failed to reset ANQPO networks;result = %d", result); | |
1403 | } | |
1404 | } | |
1405 | ||
1406 | unregisterVendorHandler(GOOGLE_OUI, WIFI_HOTSPOT_MATCH); | |
1407 | return WIFI_SUCCESS; | |
1408 | } | |
1409 | ||
1410 | virtual int handleResponse(WifiEvent& reply) { | |
1411 | ALOGD("Request complete!"); | |
1412 | /* Nothing to do on response! */ | |
1413 | return NL_SKIP; | |
1414 | } | |
1415 | ||
1416 | virtual int handleEvent(WifiEvent& event) { | |
1417 | ||
1418 | ALOGI("hotspot matched event"); | |
1419 | nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA); | |
1420 | unsigned int len = event.get_vendor_data_len(); | |
1421 | if (vendor_data == NULL || len < sizeof(wifi_scan_result)) { | |
1422 | ALOGE("ERROR: No scan results found"); | |
1423 | return NL_SKIP; | |
1424 | } | |
1425 | ||
1426 | wifi_scan_result *result = (wifi_scan_result *)event.get_vendor_data(); | |
1427 | byte *anqp = (byte *)result + offsetof(wifi_scan_result, ie_data) + result->ie_length; | |
1428 | int networkId = *(int *)anqp; | |
1429 | anqp += sizeof(int); | |
1430 | int anqp_len = *(u16 *)anqp; | |
1431 | anqp += sizeof(u16); | |
1432 | ||
1433 | ALOGI("%-32s\t", result->ssid); | |
1434 | ||
1435 | ALOGI("%02x:%02x:%02x:%02x:%02x:%02x ", result->bssid[0], result->bssid[1], | |
1436 | result->bssid[2], result->bssid[3], result->bssid[4], result->bssid[5]); | |
1437 | ||
1438 | ALOGI("%d\t", result->rssi); | |
1439 | ALOGI("%d\t", result->channel); | |
1440 | ALOGI("%lld\t", result->ts); | |
1441 | ALOGI("%lld\t", result->rtt); | |
1442 | ALOGI("%lld\n", result->rtt_sd); | |
1443 | ||
1444 | if(*mHandler.on_passpoint_network_found) | |
1445 | (*mHandler.on_passpoint_network_found)(id(), networkId, result, anqp_len, anqp); | |
1446 | ||
1447 | return NL_SKIP; | |
1448 | } | |
1449 | }; | |
1450 | ||
1451 | wifi_error wifi_set_passpoint_list(wifi_request_id id, wifi_interface_handle iface, int num, | |
1452 | wifi_passpoint_network *networks, wifi_passpoint_event_handler handler) | |
1453 | { | |
1454 | wifi_handle handle = getWifiHandle(iface); | |
1455 | HsListCommand *cmd = new HsListCommand(id, iface, num, networks, handler); | |
1456 | ||
1457 | wifi_register_cmd(handle, id, cmd); | |
1458 | wifi_error result = (wifi_error)cmd->start(); | |
1459 | if (result != WIFI_SUCCESS) { | |
1460 | wifi_unregister_cmd(handle, id); | |
1461 | } | |
1462 | return result; | |
1463 | } | |
1464 | ||
1465 | wifi_error wifi_reset_passpoint_list(wifi_request_id id, wifi_interface_handle iface) | |
1466 | { | |
1467 | wifi_handle handle = getWifiHandle(iface); | |
1468 | wifi_error result; | |
1469 | HsListCommand *cmd = (HsListCommand *)(wifi_get_cmd(handle, id)); | |
1470 | ||
1471 | if (cmd == NULL) { | |
1472 | cmd = new HsListCommand(id, iface, 0); | |
1473 | wifi_register_cmd(handle, id, cmd); | |
1474 | } | |
1475 | result = (wifi_error)cmd->cancel(); | |
1476 | wifi_unregister_cmd(handle, id); | |
1477 | return result; | |
1478 | } | |
c15187c1 | 1479 | |
10d7569e PG |
1480 | class BssidBlacklistCommand : public WifiCommand |
1481 | { | |
1482 | private: | |
1483 | wifi_bssid_params *mParams; | |
1484 | public: | |
1485 | BssidBlacklistCommand(wifi_interface_handle handle, int id, | |
1486 | wifi_bssid_params *params) | |
1487 | : WifiCommand(handle, id), mParams(params) | |
1488 | { } | |
1489 | int createRequest(WifiRequest& request) { | |
1490 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_SET_BSSID_BLACKLIST); | |
1491 | if (result < 0) { | |
1492 | return result; | |
1493 | } | |
1494 | ||
1495 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
1496 | result = request.put_u32(GSCAN_ATTRIBUTE_NUM_BSSID, mParams->num_bssid); | |
1497 | if (result < 0) { | |
1498 | return result; | |
1499 | } | |
1500 | ||
1501 | for (int i = 0; i < mParams->num_bssid; i++) { | |
1502 | result = request.put_addr(GSCAN_ATTRIBUTE_BLACKLIST_BSSID, mParams->bssids[i]); | |
1503 | if (result < 0) { | |
1504 | return result; | |
1505 | } | |
1506 | } | |
1507 | request.attr_end(data); | |
1508 | return result; | |
1509 | } | |
1510 | ||
1511 | int start() { | |
1512 | ALOGD("Executing bssid blacklist request, num = %d", mParams->num_bssid); | |
1513 | WifiRequest request(familyId(), ifaceId()); | |
1514 | int result = createRequest(request); | |
1515 | if (result < 0) { | |
1516 | return result; | |
1517 | } | |
1518 | ||
1519 | result = requestResponse(request); | |
1520 | if (result < 0) { | |
1521 | ALOGE("Failed to execute bssid blacklist request, result = %d", result); | |
1522 | return result; | |
1523 | } | |
1524 | ||
1525 | ALOGI("Successfully added %d blacklist bssids", mParams->num_bssid); | |
1526 | return result; | |
1527 | } | |
1528 | ||
1529 | ||
1530 | virtual int handleResponse(WifiEvent& reply) { | |
1531 | /* Nothing to do on response! */ | |
1532 | return NL_SKIP; | |
1533 | } | |
1534 | }; | |
1535 | ||
1536 | wifi_error wifi_set_bssid_blacklist(wifi_request_id id, wifi_interface_handle iface, | |
1537 | wifi_bssid_params params) | |
1538 | { | |
1539 | wifi_handle handle = getWifiHandle(iface); | |
1540 | ||
1541 | BssidBlacklistCommand *cmd = new BssidBlacklistCommand(iface, id, ¶ms); | |
1542 | wifi_error result = (wifi_error)cmd->start(); | |
1543 | //release the reference of command as well | |
1544 | cmd->releaseRef(); | |
1545 | return result; | |
1fc70afb | 1546 | } |