OSDN Git Service

Add RTTController and corresponding aidl interface to wificond
authorNingyuan Wang <nywang@google.com>
Mon, 10 Oct 2016 18:16:59 +0000 (11:16 -0700)
committerNingyuan Wang <nywang@google.com>
Wed, 19 Oct 2016 18:08:13 +0000 (11:08 -0700)
This add RttController interface as a lazy initialization object.
User can get an instance of RttController while register a RttClient
through wificond.

Currently HAL RttController has an optional parameter for choosing
on which network interface will RTT run. However, in order to
hide interface concept from RTT framework as well as keep simplicity,
we don't expose this interface choice via aidl to framework for now.

Bug: 31756849
Test: compile

Change-Id: I2a13374254fd8c6bd7911e5cfbe3297cde25e9e7

Android.mk
aidl/android/net/wifi/IRttClient.aidl [new file with mode: 0644]
aidl/android/net/wifi/IRttController.aidl [new file with mode: 0644]
aidl/android/net/wifi/IWificond.aidl
rtt/rtt_controller_binder.cpp [new file with mode: 0644]
rtt/rtt_controller_binder.h [new file with mode: 0644]
rtt/rtt_controller_impl.cpp [new file with mode: 0644]
rtt/rtt_controller_impl.h [new file with mode: 0644]
server.cpp
server.h

index bb3f864..53297a8 100644 (file)
@@ -54,6 +54,8 @@ LOCAL_SRC_FILES := \
     client_interface_binder.cpp \
     client_interface_impl.cpp \
     looper_backed_event_loop.cpp \
+    rtt/rtt_controller_binder.cpp \
+    rtt/rtt_controller_impl.cpp \
     scanning/scan_result.cpp \
     scanning/scan_utils.cpp \
     server.cpp
@@ -97,6 +99,8 @@ LOCAL_SRC_FILES := \
     aidl/android/net/wifi/IANQPDoneCallback.aidl \
     aidl/android/net/wifi/IClientInterface.aidl \
     aidl/android/net/wifi/IInterfaceEventCallback.aidl \
+    aidl/android/net/wifi/IRttClient.aidl \
+    aidl/android/net/wifi/IRttController.aidl \
     aidl/android/net/wifi/IWificond.aidl
 LOCAL_SHARED_LIBRARIES := \
     libbinder
diff --git a/aidl/android/net/wifi/IRttClient.aidl b/aidl/android/net/wifi/IRttClient.aidl
new file mode 100644 (file)
index 0000000..b58fdca
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi;
+
+interface IRttClient {
+  // TODO(nywang) add functions
+}
diff --git a/aidl/android/net/wifi/IRttController.aidl b/aidl/android/net/wifi/IRttController.aidl
new file mode 100644 (file)
index 0000000..30f8d0d
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi;
+
+interface IRttController {
+  // TODO(nywang) add functions
+}
index 628af06..48e2924 100644 (file)
@@ -19,6 +19,8 @@ package android.net.wifi;
 import android.net.wifi.IApInterface;
 import android.net.wifi.IClientInterface;
 import android.net.wifi.IInterfaceEventCallback;
+import android.net.wifi.IRttClient;
+import android.net.wifi.IRttController;
 
 // Service interface that exposes primitives for controlling the WiFi
 // subsystems of a device.
@@ -56,4 +58,13 @@ interface IWificond {
     // @param callback object to remove from the set of registered callbacks.
     oneway void UnregisterCallback(IInterfaceEventCallback callback);
 
+    // Obtain a reference to a IRttController that can be used to
+    // request ranging information.
+    // Results will be returned via the registered IRttClient.
+    IRttController registerRttClient(IRttClient rttClient);
+
+    // Remove an IRttClient from the set of registered IRttClient callbacks.
+    // @param rttClient object to remove from the set of registered
+    // IRttClient callbacks.
+    void unregisterRttClient(IRttClient rttClient);
 }
diff --git a/rtt/rtt_controller_binder.cpp b/rtt/rtt_controller_binder.cpp
new file mode 100644 (file)
index 0000000..ba37018
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "wificond/rtt/rtt_controller_binder.h"
+
+#include "wificond/rtt/rtt_controller_impl.h"
+
+namespace android {
+namespace wificond {
+
+RttControllerBinder::RttControllerBinder(RttControllerImpl* impl) : impl_{impl} {
+}
+
+RttControllerBinder::~RttControllerBinder() {
+}
+
+}  // namespace wificond
+}  // namespace android
diff --git a/rtt/rtt_controller_binder.h b/rtt/rtt_controller_binder.h
new file mode 100644 (file)
index 0000000..ed8ce81
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef WIFICOND_RTT_CONTROLLER_BINDER_H_
+#define WIFICOND_RTT_CONTROLLER_BINDER_H_
+
+#include <android-base/macros.h>
+#include <binder/Status.h>
+
+#include "android/net/wifi/BnRttController.h"
+
+namespace android {
+namespace wificond {
+
+class RttControllerImpl;
+
+class RttControllerBinder : public android::net::wifi::BnRttController {
+ public:
+  explicit RttControllerBinder(RttControllerImpl* impl);
+  ~RttControllerBinder() override;
+
+  // Called by |impl_| its destruction.
+  // This informs the binder proxy that no future manipulations of |impl_|
+  // by remote processes are possible.
+  void NotifyImplDead() { impl_ = nullptr; }
+
+ private:
+  RttControllerImpl* impl_;
+
+  DISALLOW_COPY_AND_ASSIGN(RttControllerBinder);
+};
+
+}  // namespace wificond
+}  // namespace android
+
+#endif  // WIFICOND_RTT_CONTROLLER_BINDER_H_
diff --git a/rtt/rtt_controller_impl.cpp b/rtt/rtt_controller_impl.cpp
new file mode 100644 (file)
index 0000000..197faca
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "wificond/rtt/rtt_controller_impl.h"
+
+#include <android-base/logging.h>
+
+#include "wificond/rtt/rtt_controller_binder.h"
+
+using android::net::wifi::IRttClient;
+using android::net::wifi::IRttController;
+using android::sp;
+
+namespace android {
+namespace wificond {
+
+RttControllerImpl::RttControllerImpl()
+    : binder_(new RttControllerBinder(this)) {
+  // TODO(nywang): create a HAL RttController object.
+}
+
+RttControllerImpl::~RttControllerImpl() {
+  binder_->NotifyImplDead();
+}
+
+sp<IRttController> RttControllerImpl::GetBinder() const {
+  return binder_;
+}
+
+bool RttControllerImpl::RegisterRttClient(android::sp<IRttClient> client) {
+  for (auto& it : clients_) {
+    if (IRttClient::asBinder(client) == IRttClient::asBinder(it)) {
+      LOG(WARNING) << "Ignore duplicate RttClient registration";
+      return false;
+    }
+  }
+  clients_.push_back(client);
+  return true;
+
+}
+
+bool RttControllerImpl::UnregisterRttClient(android::sp<IRttClient> client) {
+  for (auto it = clients_.begin(); it != clients_.end(); it++) {
+    if (IRttClient::asBinder(client) == IRttClient::asBinder(*it)) {
+      clients_.erase(it);
+      return true;
+    }
+  }
+  LOG(WARNING) << "Failed to find registered RttClient to unregister";
+  return false;
+}
+
+size_t RttControllerImpl::GetClientCount() const {
+  return clients_.size();
+}
+
+}  // namespace wificond
+}  // namespace android
diff --git a/rtt/rtt_controller_impl.h b/rtt/rtt_controller_impl.h
new file mode 100644 (file)
index 0000000..da650ef
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef WIFICOND_RTT_CONTROLLER_IMPL_H_
+#define WIFICOND_RTT_CONTROLLER_IMPL_H_
+
+#include <vector>
+
+#include <android-base/macros.h>
+
+#include "android/net/wifi/IRttController.h"
+#include "android/net/wifi/IRttClient.h"
+
+namespace android {
+namespace wificond {
+
+class RttControllerBinder;
+
+class RttControllerImpl {
+ public:
+  RttControllerImpl();
+  ~RttControllerImpl();
+
+  bool RegisterRttClient(android::sp<android::net::wifi::IRttClient> client);
+  bool UnregisterRttClient(android::sp<android::net::wifi::IRttClient> client);
+  size_t GetClientCount() const;
+
+  // Get a pointer to the binder representing this RttControllerImpl.
+  android::sp<android::net::wifi::IRttController> GetBinder() const;
+
+ private:
+  const android::sp<RttControllerBinder> binder_;
+  std::vector<android::sp<android::net::wifi::IRttClient>> clients_;
+
+  DISALLOW_COPY_AND_ASSIGN(RttControllerImpl);
+};
+
+}  // namespace wificond
+}  // namespace android
+
+#endif  // WIFICOND_RTT_CONTROLLER_IMPL_H_
index 61cfb21..d655d71 100644 (file)
@@ -30,6 +30,8 @@ using std::unique_ptr;
 using android::net::wifi::IApInterface;
 using android::net::wifi::IClientInterface;
 using android::net::wifi::IInterfaceEventCallback;
+using android::net::wifi::IRttClient;
+using android::net::wifi::IRttController;
 using android::wifi_hal::DriverTool;
 using android::wifi_system::HalTool;
 using android::wifi_system::HostapdManager;
@@ -82,6 +84,24 @@ Status Server::UnregisterCallback(const sp<IInterfaceEventCallback>& callback) {
   return Status::ok();
 }
 
+Status Server::registerRttClient(const sp<IRttClient>& rtt_client,
+                                 sp<IRttController>* out_rtt_controller) {
+  if (rtt_controller_ == nullptr) {
+    rtt_controller_.reset(new RttControllerImpl());
+  }
+  rtt_controller_->RegisterRttClient(rtt_client);
+
+  *out_rtt_controller = rtt_controller_->GetBinder();
+  return Status::ok();
+}
+
+Status Server::unregisterRttClient(const sp<IRttClient>& rttClient) {
+  rtt_controller_->UnregisterRttClient(rttClient);
+  if (rtt_controller_->GetClientCount() == 0) {
+    rtt_controller_.reset();
+  }
+  return Status::ok();
+}
 
 Status Server::createApInterface(sp<IApInterface>* created_interface) {
   string interface_name;
index 7860683..119ee2e 100644 (file)
--- a/server.h
+++ b/server.h
@@ -33,6 +33,7 @@
 
 #include "wificond/ap_interface_impl.h"
 #include "wificond/client_interface_impl.h"
+#include "wificond/rtt/rtt_controller_impl.h"
 
 namespace android {
 namespace wificond {
@@ -59,6 +60,15 @@ class Server : public android::net::wifi::BnWificond {
       const android::sp<android::net::wifi::IInterfaceEventCallback>&
           callback) override;
 
+  android::binder::Status registerRttClient(
+      const ::android::sp<::android::net::wifi::IRttClient>& rtt_client,
+      ::android::sp<::android::net::wifi::IRttController>*
+          out_rtt_controller) override;
+
+  android::binder::Status unregisterRttClient(
+      const ::android::sp<::android::net::wifi::IRttClient>&
+          rttClient) override;
+
   android::binder::Status createApInterface(
       android::sp<android::net::wifi::IApInterface>*
           created_interface) override;
@@ -115,6 +125,8 @@ class Server : public android::net::wifi::BnWificond {
   std::vector<android::sp<android::net::wifi::IInterfaceEventCallback>>
       interface_event_callbacks_;
 
+  std::unique_ptr<RttControllerImpl> rtt_controller_;
+
   DISALLOW_COPY_AND_ASSIGN(Server);
 };