Merge "wifi: Update band_info in client_interface for PNO scan" into tm-qpr-dev
diff --git a/net/netlink_manager.cpp b/net/netlink_manager.cpp
index 64db5d8..95d8a46 100644
--- a/net/netlink_manager.cpp
+++ b/net/netlink_manager.cpp
@@ -48,7 +48,7 @@
 // netlink.h suggests NLMSG_GOODSIZE to be at most 8192 bytes.
 constexpr int kReceiveBufferSize = 8 * 1024;
 constexpr uint32_t kBroadcastSequenceNumber = 0;
-constexpr int kMaximumNetlinkMessageWaitMilliSeconds = 1000;
+constexpr int kMaximumNetlinkMessageWaitMilliSeconds = 4000;
 uint8_t ReceiveBuffer[kReceiveBufferSize];
 
 void AppendPacket(vector<unique_ptr<const NL80211Packet>>* vec,
@@ -99,7 +99,8 @@
 void NetlinkManager::ReceivePacketAndRunHandler(int fd) {
   ssize_t len = read(fd, ReceiveBuffer, kReceiveBufferSize);
   if (len == -1) {
-    LOG(ERROR) << "Failed to read packet from buffer on fd: " << fd;
+    LOG(ERROR) << "Failed to read packet from buffer on fd: " << fd
+               << ", error is " << strerror(errno);
     perror(" netlink error ");
     return;
   }
@@ -136,7 +137,8 @@
     auto itr = message_handlers_.find(sequence_number);
     // There is no handler for this sequence number.
     if (itr == message_handlers_.end()) {
-      LOG(WARNING) << "No handler for message: " << sequence_number;
+      LOG(WARNING) << "No handler for message: " << sequence_number
+                   << ", packet len = " << len;
       return;
     }
     // A multipart message is terminated by NLMSG_DONE.
@@ -308,11 +310,13 @@
                            time_remaining);
 
     if (poll_return == 0) {
-      LOG(ERROR) << "Failed to poll netlink fd:" << sync_netlink_fd_.get() << "time out ";
+      LOG(ERROR) << "Failed to poll netlink fd:" << sync_netlink_fd_.get()
+                 << "time out, sequence is " << sequence ;
       message_handlers_.erase(sequence);
       return false;
     } else if (poll_return == -1) {
-      PLOG(ERROR) << "Failed to poll netlink fd";
+      LOG(ERROR) << "Failed to poll netlink fd:" << sync_netlink_fd_.get()
+                 << ", sequence is " << sequence;
       message_handlers_.erase(sequence);
       return false;
     }
@@ -321,7 +325,7 @@
     time_remaining -= static_cast<int>(ns2ms(interval));
   }
   if (time_remaining <= 0) {
-    LOG(ERROR) << "Timeout waiting for netlink reply messages";
+    LOG(ERROR) << "Timeout waiting for netlink reply messages, sequence is " << sequence;
     message_handlers_.erase(sequence);
     return false;
   }
diff --git a/net/netlink_utils.cpp b/net/netlink_utils.cpp
index 6c34d9e..ff29a13 100644
--- a/net/netlink_utils.cpp
+++ b/net/netlink_utils.cpp
@@ -73,6 +73,7 @@
 
 constexpr uint8_t kEhtCapPhyNumByte = 8;
 constexpr uint8_t kEht320MhzBitMask = 0x2;
+constexpr int kNl80211CmdRetryCount = 1;
 
 bool IsExtFeatureFlagSet(
     const std::vector<uint8_t>& ext_feature_flags_bytes,
@@ -145,11 +146,20 @@
     get_wiphy.AddAttribute(NL80211Attr<uint32_t>(NL80211_ATTR_IFINDEX, ifindex));
   }
   vector<unique_ptr<const NL80211Packet>> response;
-  if (!netlink_manager_->SendMessageAndGetResponses(get_wiphy, &response))  {
-    LOG(ERROR) << "NL80211_CMD_GET_WIPHY dump failed, ifindex: "
-               << ifindex << " and name: " << iface_name.c_str();
-    return false;
+  for (int i = kNl80211CmdRetryCount; i >= 0; i--) {
+      if (netlink_manager_->SendMessageAndGetResponses(get_wiphy, &response))  {
+          break;
+      } else {
+        if (i == 0) {
+            LOG(ERROR) << "NL80211_CMD_GET_WIPHY dump failed, ifindex: "
+                       << ifindex << " and name: " << iface_name.c_str();
+            return false;
+        } else {
+            LOG(INFO) << "Failed to get wiphy index, retry again";
+        }
+      }
   }
+
   if (response.empty()) {
     LOG(INFO) << "No wiphy is found";
     return false;
@@ -320,9 +330,17 @@
     get_wiphy.AddFlag(NLM_F_DUMP);
   }
   vector<unique_ptr<const NL80211Packet>> response;
-  if (!netlink_manager_->SendMessageAndGetResponses(get_wiphy, &response))  {
-    LOG(ERROR) << "NL80211_CMD_GET_WIPHY dump failed";
-    return false;
+  for (int i = kNl80211CmdRetryCount; i >= 0; i--) {
+      if (netlink_manager_->SendMessageAndGetResponses(get_wiphy, &response))  {
+          break;
+      } else {
+        if (i == 0) {
+            LOG(ERROR) << "NL80211_CMD_GET_WIPHY dump failed";
+            return false;
+        } else {
+            LOG(INFO) << "Failed to get wiphy info, retry again";
+        }
+      }
   }
 
   vector<NL80211Packet> packet_per_wiphy;