1 /*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "android/net/wifi/nl80211/IWifiScannerImpl.h"
18 #include "wificond/scanning/scan_utils.h"
19
20 #include <array>
21 #include <vector>
22
23 #include <linux/netlink.h>
24 #include <linux/if_ether.h>
25
26 #include <android-base/logging.h>
27
28 #include "wificond/net/kernel-header-latest/nl80211.h"
29 #include "wificond/net/netlink_manager.h"
30 #include "wificond/net/nl80211_packet.h"
31 #include "wificond/scanning/scan_result.h"
32
33 using android::net::wifi::nl80211::IWifiScannerImpl;
34 using android::net::wifi::nl80211::NativeScanResult;
35 using android::net::wifi::nl80211::RadioChainInfo;
36 using std::array;
37 using std::unique_ptr;
38 using std::vector;
39
40 namespace android {
41 namespace wificond {
42 namespace {
43
44 constexpr uint8_t kElemIdSsid = 0;
45 constexpr unsigned int kMsecPerSec = 1000;
46
47 } // namespace
48
ScanUtils(NetlinkManager * netlink_manager)49 ScanUtils::ScanUtils(NetlinkManager* netlink_manager)
50 : netlink_manager_(netlink_manager) {
51 if (!netlink_manager_->IsStarted()) {
52 netlink_manager_->Start();
53 }
54 }
55
~ScanUtils()56 ScanUtils::~ScanUtils() {}
57
SubscribeScanResultNotification(uint32_t interface_index,OnScanResultsReadyHandler handler)58 void ScanUtils::SubscribeScanResultNotification(
59 uint32_t interface_index,
60 OnScanResultsReadyHandler handler) {
61 netlink_manager_->SubscribeScanResultNotification(interface_index, handler);
62 }
63
UnsubscribeScanResultNotification(uint32_t interface_index)64 void ScanUtils::UnsubscribeScanResultNotification(uint32_t interface_index) {
65 netlink_manager_->UnsubscribeScanResultNotification(interface_index);
66 }
67
SubscribeSchedScanResultNotification(uint32_t interface_index,OnSchedScanResultsReadyHandler handler)68 void ScanUtils::SubscribeSchedScanResultNotification(
69 uint32_t interface_index,
70 OnSchedScanResultsReadyHandler handler) {
71 netlink_manager_->SubscribeSchedScanResultNotification(interface_index,
72 handler);
73 }
74
UnsubscribeSchedScanResultNotification(uint32_t interface_index)75 void ScanUtils::UnsubscribeSchedScanResultNotification(
76 uint32_t interface_index) {
77 netlink_manager_->UnsubscribeSchedScanResultNotification(interface_index);
78 }
79
GetScanResult(uint32_t interface_index,vector<NativeScanResult> * out_scan_results)80 bool ScanUtils::GetScanResult(uint32_t interface_index,
81 vector<NativeScanResult>* out_scan_results) {
82 NL80211Packet get_scan(
83 netlink_manager_->GetFamilyId(),
84 NL80211_CMD_GET_SCAN,
85 netlink_manager_->GetSequenceNumber(),
86 getpid());
87 get_scan.AddFlag(NLM_F_DUMP);
88 NL80211Attr<uint32_t> ifindex(NL80211_ATTR_IFINDEX, interface_index);
89 get_scan.AddAttribute(ifindex);
90
91 vector<unique_ptr<const NL80211Packet>> response;
92 if (!netlink_manager_->SendMessageAndGetResponses(get_scan, &response)) {
93 LOG(ERROR) << "NL80211_CMD_GET_SCAN dump failed";
94 return false;
95 }
96 if (response.empty()) {
97 LOG(INFO) << "Unexpected empty scan result!";
98 return true;
99 }
100
101 for (auto& packet : response) {
102 if (packet->GetMessageType() == NLMSG_ERROR) {
103 LOG(ERROR) << "Receive ERROR message: "
104 << strerror(packet->GetErrorCode());
105 continue;
106 }
107 if (packet->GetMessageType() != netlink_manager_->GetFamilyId()) {
108 LOG(ERROR) << "Wrong message type: "
109 << packet->GetMessageType();
110 continue;
111 }
112 uint32_t if_index;
113 if (!packet->GetAttributeValue(NL80211_ATTR_IFINDEX, &if_index)) {
114 LOG(ERROR) << "No interface index in scan result.";
115 continue;
116 }
117 if (if_index != interface_index) {
118 LOG(WARNING) << "Uninteresting scan result for interface: " << if_index;
119 continue;
120 }
121
122 NativeScanResult scan_result;
123 if (!ParseScanResult(std::move(packet), &scan_result)) {
124 LOG(DEBUG) << "Ignore invalid scan result";
125 continue;
126 }
127 out_scan_results->push_back(std::move(scan_result));
128 }
129 return true;
130 }
131
ParseScanResult(unique_ptr<const NL80211Packet> packet,NativeScanResult * scan_result)132 bool ScanUtils::ParseScanResult(unique_ptr<const NL80211Packet> packet,
133 NativeScanResult* scan_result) {
134 if (packet->GetCommand() != NL80211_CMD_NEW_SCAN_RESULTS) {
135 LOG(ERROR) << "Wrong command for new scan result message";
136 return false;
137 }
138 NL80211NestedAttr bss(0);
139 if (packet->GetAttribute(NL80211_ATTR_BSS, &bss)) {
140 array<uint8_t, ETH_ALEN> bssid;
141 if (!bss.GetAttributeValue(NL80211_BSS_BSSID, &bssid)) {
142 LOG(ERROR) << "Failed to get BSSID from scan result packet";
143 return false;
144 }
145 uint32_t freq;
146 if (!bss.GetAttributeValue(NL80211_BSS_FREQUENCY, &freq)) {
147 LOG(ERROR) << "Failed to get Frequency from scan result packet";
148 return false;
149 }
150 vector<uint8_t> ie;
151 if (!bss.GetAttributeValue(NL80211_BSS_INFORMATION_ELEMENTS, &ie)) {
152 LOG(ERROR) << "Failed to get Information Element from scan result packet";
153 return false;
154 }
155 vector<uint8_t> ssid;
156 if (!GetSSIDFromInfoElement(ie, &ssid)) {
157 // Skip BSS without SSID IE.
158 // These scan results are considered as malformed.
159 return false;
160 }
161 uint64_t last_seen_since_boot_microseconds;
162 if (!GetBssTimestamp(bss, &last_seen_since_boot_microseconds)) {
163 // Logging is done inside |GetBssTimestamp|.
164 return false;
165 }
166 int32_t signal;
167 if (!bss.GetAttributeValue(NL80211_BSS_SIGNAL_MBM, &signal)) {
168 LOG(ERROR) << "Failed to get Signal Strength from scan result packet";
169 return false;
170 }
171 uint16_t capability;
172 if (!bss.GetAttributeValue(NL80211_BSS_CAPABILITY, &capability)) {
173 LOG(ERROR) << "Failed to get capability field from scan result packet";
174 return false;
175 }
176 bool associated = false;
177 uint32_t bss_status;
178 if (bss.GetAttributeValue(NL80211_BSS_STATUS, &bss_status) &&
179 (bss_status == NL80211_BSS_STATUS_AUTHENTICATED ||
180 bss_status == NL80211_BSS_STATUS_ASSOCIATED)) {
181 associated = true;
182 }
183 std::vector<RadioChainInfo> radio_chain_infos;
184 ParseRadioChainInfos(bss, &radio_chain_infos);
185
186 *scan_result =
187 NativeScanResult(ssid, bssid, ie, freq, signal,
188 last_seen_since_boot_microseconds,
189 capability, associated, radio_chain_infos);
190 }
191 return true;
192 }
193
GetBssTimestampForTesting(const NL80211NestedAttr & bss,uint64_t * last_seen_since_boot_microseconds)194 bool ScanUtils::GetBssTimestampForTesting(
195 const NL80211NestedAttr& bss,
196 uint64_t* last_seen_since_boot_microseconds){
197 return GetBssTimestamp(bss, last_seen_since_boot_microseconds);
198 }
199
GetBssTimestamp(const NL80211NestedAttr & bss,uint64_t * last_seen_since_boot_microseconds)200 bool ScanUtils::GetBssTimestamp(const NL80211NestedAttr& bss,
201 uint64_t* last_seen_since_boot_microseconds){
202 uint64_t last_seen_since_boot_nanoseconds;
203 if (bss.GetAttributeValue(NL80211_BSS_LAST_SEEN_BOOTTIME,
204 &last_seen_since_boot_nanoseconds)) {
205 *last_seen_since_boot_microseconds = last_seen_since_boot_nanoseconds / 1000;
206 } else {
207 // Fall back to use TSF if we can't find NL80211_BSS_LAST_SEEN_BOOTTIME
208 // attribute.
209 if (!bss.GetAttributeValue(NL80211_BSS_TSF, last_seen_since_boot_microseconds)) {
210 LOG(ERROR) << "Failed to get TSF from scan result packet";
211 return false;
212 }
213 uint64_t beacon_tsf_microseconds;
214 if (bss.GetAttributeValue(NL80211_BSS_BEACON_TSF, &beacon_tsf_microseconds)) {
215 *last_seen_since_boot_microseconds = std::max(*last_seen_since_boot_microseconds,
216 beacon_tsf_microseconds);
217 }
218 }
219 return true;
220 }
221
ParseRadioChainInfos(const NL80211NestedAttr & bss,std::vector<RadioChainInfo> * radio_chain_infos)222 bool ScanUtils::ParseRadioChainInfos(
223 const NL80211NestedAttr& bss,
224 std::vector<RadioChainInfo> *radio_chain_infos) {
225 *radio_chain_infos = {};
226 // Contains a nested array of signal strength attributes: (ChainId, Rssi in dBm)
227 NL80211NestedAttr radio_chain_infos_attr(0);
228 if (!bss.GetAttribute(NL80211_BSS_CHAIN_SIGNAL, &radio_chain_infos_attr)) {
229 return false;
230 }
231 std::vector<NL80211Attr<int8_t>> radio_chain_infos_attrs;
232 if (!radio_chain_infos_attr.GetListOfAttributes(
233 &radio_chain_infos_attrs)) {
234 LOG(ERROR) << "Failed to get radio chain info attrs within "
235 << "NL80211_BSS_CHAIN_SIGNAL";
236 return false;
237 }
238 for (const auto& attr : radio_chain_infos_attrs) {
239 RadioChainInfo radio_chain_info;
240 radio_chain_info.chain_id = attr.GetAttributeId();
241 radio_chain_info.level = attr.GetValue();
242 radio_chain_infos->push_back(radio_chain_info);
243 }
244 return true;
245 }
246
GetSSIDFromInfoElement(const vector<uint8_t> & ie,vector<uint8_t> * ssid)247 bool ScanUtils::GetSSIDFromInfoElement(const vector<uint8_t>& ie,
248 vector<uint8_t>* ssid) {
249 // Information elements are stored in 'TLV' format.
250 // Field: | Type | Length | Value |
251 // Length: | 1 | 1 | variable |
252 // Content:| Element ID | Length of the Value field | Element payload |
253 const uint8_t* end = ie.data() + ie.size();
254 const uint8_t* ptr = ie.data();
255 // +1 means we must have space for the length field.
256 while (ptr + 1 < end) {
257 uint8_t type = *ptr;
258 uint8_t length = *(ptr + 1);
259 // Length field is invalid.
260 if (ptr + 1 + length >= end) {
261 return false;
262 }
263 // SSID element is found.
264 if (type == kElemIdSsid) {
265 // SSID is an empty string.
266 if (length == 0) {
267 *ssid = vector<uint8_t>();
268 } else {
269 *ssid = vector<uint8_t>(ptr + 2, ptr + length + 2);
270 }
271 return true;
272 }
273 ptr += 2 + length;
274 }
275 return false;
276 }
277
Scan(uint32_t interface_index,bool request_random_mac,int scan_type,bool enable_6ghz_rnr,const vector<vector<uint8_t>> & ssids,const vector<uint32_t> & freqs,int * error_code)278 bool ScanUtils::Scan(uint32_t interface_index,
279 bool request_random_mac,
280 int scan_type,
281 bool enable_6ghz_rnr,
282 const vector<vector<uint8_t>>& ssids,
283 const vector<uint32_t>& freqs,
284 int* error_code) {
285 NL80211Packet trigger_scan(
286 netlink_manager_->GetFamilyId(),
287 NL80211_CMD_TRIGGER_SCAN,
288 netlink_manager_->GetSequenceNumber(),
289 getpid());
290 // If we do not use NLM_F_ACK, we only receive a unicast repsonse
291 // when there is an error. If everything is good, scan results notification
292 // will only be sent through multicast.
293 // If NLM_F_ACK is set, there will always be an unicast repsonse, either an
294 // ERROR or an ACK message. The handler will always be called and removed by
295 // NetlinkManager.
296 trigger_scan.AddFlag(NLM_F_ACK);
297 NL80211Attr<uint32_t> if_index_attr(NL80211_ATTR_IFINDEX, interface_index);
298
299 NL80211NestedAttr ssids_attr(NL80211_ATTR_SCAN_SSIDS);
300 for (size_t i = 0; i < ssids.size(); i++) {
301 ssids_attr.AddAttribute(NL80211Attr<vector<uint8_t>>(i, ssids[i]));
302 }
303 NL80211NestedAttr freqs_attr(NL80211_ATTR_SCAN_FREQUENCIES);
304 for (size_t i = 0; i < freqs.size(); i++) {
305 freqs_attr.AddAttribute(NL80211Attr<uint32_t>(i, freqs[i]));
306 }
307
308 trigger_scan.AddAttribute(if_index_attr);
309 trigger_scan.AddAttribute(ssids_attr);
310 // An absence of NL80211_ATTR_SCAN_FREQUENCIES attribue informs kernel to
311 // scan all supported frequencies.
312 if (!freqs.empty()) {
313 trigger_scan.AddAttribute(freqs_attr);
314 }
315
316 uint32_t scan_flags = 0;
317 if (request_random_mac) {
318 scan_flags |= NL80211_SCAN_FLAG_RANDOM_ADDR;
319 }
320 switch (scan_type) {
321 case IWifiScannerImpl::SCAN_TYPE_LOW_SPAN:
322 scan_flags |= NL80211_SCAN_FLAG_LOW_SPAN;
323 break;
324 case IWifiScannerImpl::SCAN_TYPE_LOW_POWER:
325 scan_flags |= NL80211_SCAN_FLAG_LOW_POWER;
326 break;
327 case IWifiScannerImpl::SCAN_TYPE_HIGH_ACCURACY:
328 scan_flags |= NL80211_SCAN_FLAG_HIGH_ACCURACY;
329 break;
330 case IWifiScannerImpl::SCAN_TYPE_DEFAULT:
331 break;
332 default:
333 CHECK(0) << "Invalid scan type received: " << scan_type;
334 }
335 if (enable_6ghz_rnr) {
336 scan_flags |= NL80211_SCAN_FLAG_COLOCATED_6GHZ;
337 }
338 if (scan_flags) {
339 trigger_scan.AddAttribute(
340 NL80211Attr<uint32_t>(NL80211_ATTR_SCAN_FLAGS,
341 scan_flags));
342 LOG(DEBUG) << "Triggering scan with scan_flag=" << scan_flags;
343 }
344 // We are receiving an ERROR/ACK message instead of the actual
345 // scan results here, so it is OK to expect a timely response because
346 // kernel is supposed to send the ERROR/ACK back before the scan starts.
347 vector<unique_ptr<const NL80211Packet>> response;
348 if (!netlink_manager_->SendMessageAndGetAckOrError(trigger_scan,
349 error_code)) {
350 // Logging is done inside |SendMessageAndGetAckOrError|.
351 return false;
352 }
353 if (*error_code != 0) {
354 LOG(ERROR) << "NL80211_CMD_TRIGGER_SCAN failed: " << strerror(*error_code);
355 return false;
356 }
357 return true;
358 }
359
StopScheduledScan(uint32_t interface_index)360 bool ScanUtils::StopScheduledScan(uint32_t interface_index) {
361 NL80211Packet stop_sched_scan(
362 netlink_manager_->GetFamilyId(),
363 NL80211_CMD_STOP_SCHED_SCAN,
364 netlink_manager_->GetSequenceNumber(),
365 getpid());
366 // Force an ACK response upon success.
367 stop_sched_scan.AddFlag(NLM_F_ACK);
368 stop_sched_scan.AddAttribute(
369 NL80211Attr<uint32_t>(NL80211_ATTR_IFINDEX, interface_index));
370 vector<unique_ptr<const NL80211Packet>> response;
371 int error_code;
372 if (!netlink_manager_->SendMessageAndGetAckOrError(stop_sched_scan,
373 &error_code)) {
374 LOG(ERROR) << "NL80211_CMD_STOP_SCHED_SCAN failed";
375 return false;
376 }
377 if (error_code == ENOENT) {
378 LOG(WARNING) << "Scheduled scan is not running!";
379 return false;
380 } else if (error_code != 0) {
381 LOG(ERROR) << "Receive ERROR message in response to"
382 << " 'stop scheduled scan' request: "
383 << strerror(error_code);
384 return false;
385 }
386 return true;
387 }
388
AbortScan(uint32_t interface_index)389 bool ScanUtils::AbortScan(uint32_t interface_index) {
390 NL80211Packet abort_scan(
391 netlink_manager_->GetFamilyId(),
392 NL80211_CMD_ABORT_SCAN,
393 netlink_manager_->GetSequenceNumber(),
394 getpid());
395
396 // Force an ACK response upon success.
397 abort_scan.AddFlag(NLM_F_ACK);
398 abort_scan.AddAttribute(
399 NL80211Attr<uint32_t>(NL80211_ATTR_IFINDEX, interface_index));
400
401 if (!netlink_manager_->SendMessageAndGetAck(abort_scan)) {
402 LOG(ERROR) << "NL80211_CMD_ABORT_SCAN failed";
403 return false;
404 }
405 return true;
406 }
407
StartScheduledScan(uint32_t interface_index,const SchedScanIntervalSetting & interval_setting,int32_t rssi_threshold_2g,int32_t rssi_threshold_5g,int32_t rssi_threshold_6g,const SchedScanReqFlags & req_flags,const std::vector<std::vector<uint8_t>> & scan_ssids,const std::vector<std::vector<uint8_t>> & match_ssids,const std::vector<uint32_t> & freqs,int * error_code)408 bool ScanUtils::StartScheduledScan(
409 uint32_t interface_index,
410 const SchedScanIntervalSetting& interval_setting,
411 int32_t rssi_threshold_2g,
412 int32_t rssi_threshold_5g,
413 int32_t rssi_threshold_6g,
414 const SchedScanReqFlags& req_flags,
415 const std::vector<std::vector<uint8_t>>& scan_ssids,
416 const std::vector<std::vector<uint8_t>>& match_ssids,
417 const std::vector<uint32_t>& freqs,
418 int* error_code) {
419 NL80211Packet start_sched_scan(
420 netlink_manager_->GetFamilyId(),
421 NL80211_CMD_START_SCHED_SCAN,
422 netlink_manager_->GetSequenceNumber(),
423 getpid());
424 // Force an ACK response upon success.
425 start_sched_scan.AddFlag(NLM_F_ACK);
426
427 NL80211NestedAttr scan_ssids_attr(NL80211_ATTR_SCAN_SSIDS);
428 for (size_t i = 0; i < scan_ssids.size(); i++) {
429 scan_ssids_attr.AddAttribute(NL80211Attr<vector<uint8_t>>(i, scan_ssids[i]));
430 }
431 NL80211NestedAttr freqs_attr(NL80211_ATTR_SCAN_FREQUENCIES);
432 for (size_t i = 0; i < freqs.size(); i++) {
433 freqs_attr.AddAttribute(NL80211Attr<uint32_t>(i, freqs[i]));
434 }
435
436 // Structure of attributes of scheduled scan filters:
437 // | Nested Attribute: id: NL80211_ATTR_SCHED_SCAN_MATCH |
438 // | Nested Attributed: id: 0 | Nested Attributed: id: 1 | Nested Attr: id: 2 | ... |
439 // | MATCH_SSID | MATCH_RSSI(optional) | MATCH_SSID | MACTCH_RSSI(optional) | MATCH_RSSI(optinal, global) | ... |
440 NL80211NestedAttr scan_match_attr(NL80211_ATTR_SCHED_SCAN_MATCH);
441 for (size_t i = 0; i < match_ssids.size(); i++) {
442 NL80211NestedAttr match_group(i);
443 match_group.AddAttribute(
444 NL80211Attr<vector<uint8_t>>(NL80211_SCHED_SCAN_MATCH_ATTR_SSID, match_ssids[i]));
445 match_group.AddAttribute(
446 NL80211Attr<int32_t>(NL80211_SCHED_SCAN_MATCH_ATTR_RSSI, rssi_threshold_5g));
447 scan_match_attr.AddAttribute(match_group);
448 }
449 start_sched_scan.AddAttribute(scan_match_attr);
450
451 // We set 5g threshold for default and ajust threshold for 2g band.
452 // check sched_scan supported before set NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST attribute.
453 if (req_flags.request_sched_scan_relative_rssi) {
454 struct nl80211_bss_select_rssi_adjust rssi_adjust;
455 rssi_adjust.band = NL80211_BAND_2GHZ;
456 rssi_adjust.delta = static_cast<int8_t>(rssi_threshold_2g - rssi_threshold_5g);
457 NL80211Attr<vector<uint8_t>> rssi_adjust_attr(
458 NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
459 vector<uint8_t>(
460 reinterpret_cast<uint8_t*>(&rssi_adjust),
461 reinterpret_cast<uint8_t*>(&rssi_adjust) + sizeof(rssi_adjust)));
462 start_sched_scan.AddAttribute(rssi_adjust_attr);
463 }
464
465 //TODO: No adjustment is possible now for 6GHz due to lack of definition in
466 //nl80211.h for NL80211_BAND_6GHZ attribute
467
468 // Append all attributes to the NL80211_CMD_START_SCHED_SCAN packet.
469 start_sched_scan.AddAttribute(
470 NL80211Attr<uint32_t>(NL80211_ATTR_IFINDEX, interface_index));
471 start_sched_scan.AddAttribute(scan_ssids_attr);
472 // An absence of NL80211_ATTR_SCAN_FREQUENCIES attribue informs kernel to
473 // scan all supported frequencies.
474 if (!freqs.empty()) {
475 start_sched_scan.AddAttribute(freqs_attr);
476 }
477
478 if (!interval_setting.plans.empty()) {
479 NL80211NestedAttr scan_plans(NL80211_ATTR_SCHED_SCAN_PLANS);
480 for (unsigned int i = 0; i < interval_setting.plans.size(); i++) {
481 NL80211NestedAttr scan_plan(i + 1);
482 scan_plan.AddAttribute(
483 NL80211Attr<uint32_t>(NL80211_SCHED_SCAN_PLAN_INTERVAL,
484 interval_setting.plans[i].interval_ms / kMsecPerSec));
485 scan_plan.AddAttribute(
486 NL80211Attr<uint32_t>(NL80211_SCHED_SCAN_PLAN_ITERATIONS,
487 interval_setting.plans[i].n_iterations));
488 scan_plans.AddAttribute(scan_plan);
489 }
490 NL80211NestedAttr last_scan_plan(interval_setting.plans.size() + 1);
491 last_scan_plan.AddAttribute(
492 NL80211Attr<uint32_t>(NL80211_SCHED_SCAN_PLAN_INTERVAL,
493 interval_setting.final_interval_ms / kMsecPerSec));
494 scan_plans.AddAttribute(last_scan_plan);
495 start_sched_scan.AddAttribute(scan_plans);
496 } else {
497 start_sched_scan.AddAttribute(
498 NL80211Attr<uint32_t>(NL80211_ATTR_SCHED_SCAN_INTERVAL,
499 interval_setting.final_interval_ms));
500 }
501 uint32_t scan_flags = 0;
502 if (req_flags.request_random_mac) {
503 scan_flags |= NL80211_SCAN_FLAG_RANDOM_ADDR;
504 }
505 if (req_flags.request_low_power) {
506 scan_flags |= NL80211_SCAN_FLAG_LOW_POWER;
507 }
508 if (scan_flags) {
509 start_sched_scan.AddAttribute(
510 NL80211Attr<uint32_t>(NL80211_ATTR_SCAN_FLAGS,
511 scan_flags));
512 }
513
514 vector<unique_ptr<const NL80211Packet>> response;
515 if (!netlink_manager_->SendMessageAndGetAckOrError(start_sched_scan,
516 error_code)) {
517 // Logging is done inside |SendMessageAndGetAckOrError|.
518 return false;
519 }
520 if (*error_code != 0) {
521 LOG(ERROR) << "NL80211_CMD_START_SCHED_SCAN failed: " << strerror(*error_code);
522 return false;
523 }
524
525 return true;
526 }
527
528 } // namespace wificond
529 } // namespace android
530