OSDN Git Service

Notify scan aborted events
authorNingyuan Wang <nywang@google.com>
Tue, 20 Sep 2016 18:00:11 +0000 (11:00 -0700)
committerNingyuan Wang <nywang@google.com>
Tue, 20 Sep 2016 18:11:55 +0000 (11:11 -0700)
Bug: 31495091
Test: compile, manual tests

Change-Id: I94c50f44449bd1f0c7c445775434a34d5ca7390a

client_interface_impl.cpp
client_interface_impl.h
net/netlink_manager.cpp
net/netlink_manager.h

index 11927aa..1de2dac 100644 (file)
@@ -55,7 +55,9 @@ ClientInterfaceImpl::ClientInterfaceImpl(
       binder_(new ClientInterfaceBinder(this)) {
   scan_utils_->SubscribeScanResultNotification(
       interface_index_,
-      std::bind(&ClientInterfaceImpl::OnScanResultsReady, this, _1, _2, _3));
+      std::bind(&ClientInterfaceImpl::OnScanResultsReady,
+                this,
+                _1, _2, _3, _4));
 }
 
 ClientInterfaceImpl::~ClientInterfaceImpl() {
@@ -90,8 +92,13 @@ bool ClientInterfaceImpl::GetPacketCounters(vector<int32_t>* out_packet_counters
 
 void ClientInterfaceImpl::OnScanResultsReady(
                          uint32_t interface_index,
+                         bool aborted,
                          std::vector<std::vector<uint8_t>>& ssids,
                          std::vector<uint32_t>& frequencies) {
+  if (aborted) {
+    LOG(ERROR) << "Scan aborted";
+    return;
+  }
   vector<ScanResult> scan_results;
   // TODO(nywang): Find a way to differentiate scan results for
   // internel/external scan request. This is useful when location is
index af1c316..38dc369 100644 (file)
@@ -58,6 +58,7 @@ class ClientInterfaceImpl {
 
  private:
   void OnScanResultsReady(uint32_t interface_index,
+                          bool aborted,
                           std::vector<std::vector<uint8_t>>& ssids,
                           std::vector<uint32_t>& frequencies);
 
index 3469dc3..e17f25c 100644 (file)
@@ -449,7 +449,10 @@ void NetlinkManager::BroadcastHandler(unique_ptr<const NL80211Packet> packet) {
   // There is another scan result notification: NL80211_CMD_SCHED_SCAN_RESULTS.
   // which is used by PNO scan. Wificond is not going to handle that at this
   // time.
-  if (command == NL80211_CMD_NEW_SCAN_RESULTS) {
+  if (command == NL80211_CMD_NEW_SCAN_RESULTS ||
+      // Scan was aborted, for unspecified reasons.partial scan results may be
+      // available.
+      command == NL80211_CMD_SCAN_ABORTED) {
     OnScanResultsReady(std::move(packet));
   }
 }
@@ -460,6 +463,10 @@ void NetlinkManager::OnScanResultsReady(unique_ptr<const NL80211Packet> packet)
     LOG(ERROR) << "Failed to get interface index from scan result notification";
     return;
   }
+  bool aborted = false;
+  if (packet->GetCommand() == NL80211_CMD_SCAN_ABORTED) {
+    aborted = true;
+  }
 
   auto handler = on_scan_result_ready_handler_.find(if_index);
   if (handler == on_scan_result_ready_handler_.end()) {
@@ -471,7 +478,9 @@ void NetlinkManager::OnScanResultsReady(unique_ptr<const NL80211Packet> packet)
   vector<vector<uint8_t>> ssids;
   NL80211NestedAttr ssids_attr(0);
   if (!packet->GetAttribute(NL80211_ATTR_SCAN_SSIDS, &ssids_attr)) {
-    LOG(WARNING) << "Failed to get scan ssids from scan result notification";
+    if (!aborted) {
+      LOG(WARNING) << "Failed to get scan ssids from scan result notification";
+    }
   } else {
     if (!ssids_attr.GetListOfAttributeValues(&ssids)) {
       return;
@@ -480,14 +489,16 @@ void NetlinkManager::OnScanResultsReady(unique_ptr<const NL80211Packet> packet)
   vector<uint32_t> freqs;
   NL80211NestedAttr freqs_attr(0);
   if (!packet->GetAttribute(NL80211_ATTR_SCAN_FREQUENCIES, &freqs_attr)) {
-    LOG(WARNING) << "Failed to get scan freqs from scan result notification";
+    if (!aborted) {
+      LOG(WARNING) << "Failed to get scan freqs from scan result notification";
+    }
   } else {
     if (!freqs_attr.GetListOfAttributeValues(&freqs)) {
       return;
     }
   }
   // Run scan result notification handler.
-  handler->second(if_index, ssids, freqs);
+  handler->second(if_index, aborted, ssids, freqs);
 }
 
 void NetlinkManager::SubscribeScanResultNotification(
index 36f2772..c61fb6d 100644 (file)
@@ -48,12 +48,14 @@ struct MessageType {
 // This describes a type of function handling scan results ready notification.
 // |interface_index| is the index of interface which the scan results
 // are from.
+// |aborted| is a boolean indicating if this scan request was aborted or not.
 // |ssids| is a vector of scan ssids associated with the corresponding
 // scan request.
 // |frequencies| is a vector of scan frequencies associated with the
 // corresponding scan request.
 typedef std::function<void(
     uint32_t interface_index,
+    bool aborted,
     std::vector<std::vector<uint8_t>>& ssids,
     std::vector<uint32_t>& frequencies)> OnScanResultsReadyHandler;