OSDN Git Service

Merge tag 'android-8.1.0_r69' into oreo-x86
[android-x86/system-connectivity-wificond.git] / ap_interface_impl.cpp
index 44a30b3..dde3655 100644 (file)
@@ -26,6 +26,7 @@
 using android::net::wifi::IApInterface;
 using android::wifi_system::HostapdManager;
 using android::wifi_system::InterfaceTool;
+using std::endl;
 using std::string;
 using std::unique_ptr;
 using std::vector;
@@ -47,7 +48,8 @@ ApInterfaceImpl::ApInterfaceImpl(const string& interface_name,
       netlink_utils_(netlink_utils),
       if_tool_(if_tool),
       hostapd_manager_(hostapd_manager),
-      binder_(new ApInterfaceBinder(this)) {
+      binder_(new ApInterfaceBinder(this)),
+      number_of_associated_stations_(0) {
   // This log keeps compiler happy.
   LOG(DEBUG) << "Created ap interface " << interface_name_
              << " with index " << interface_index_;
@@ -69,6 +71,15 @@ sp<IApInterface> ApInterfaceImpl::GetBinder() const {
   return binder_;
 }
 
+void ApInterfaceImpl::Dump(std::stringstream* ss) const {
+  *ss << "------- Dump of AP interface with index: "
+      << interface_index_ << " and name: " << interface_name_
+      << "-------" << endl;
+  *ss << "Number of associated stations: "
+      <<  number_of_associated_stations_ << endl;
+  *ss << "------- Dump End -------" << endl;
+}
+
 bool ApInterfaceImpl::StartHostapd() {
   return hostapd_manager_->StartHostapd();
 }
@@ -120,12 +131,23 @@ void ApInterfaceImpl::OnStationEvent(StationEvent event,
     LOG(INFO) << "New station "
               << LoggingUtils::GetMacString(mac_address)
               << " associated with hotspot";
+    number_of_associated_stations_++;
   } else if (event == DEL_STATION) {
     LOG(INFO) << "Station "
               << LoggingUtils::GetMacString(mac_address)
               << " disassociated from hotspot";
+    if (number_of_associated_stations_ <= 0) {
+      LOG(ERROR) << "Received DEL_STATION event when station counter is: "
+                 << number_of_associated_stations_;
+    } else {
+      number_of_associated_stations_--;
+    }
   }
 }
 
+int ApInterfaceImpl::GetNumberOfAssociatedStations() const {
+  return number_of_associated_stations_;
+}
+
 }  // namespace wificond
 }  // namespace android