1 /* 2 * Copyright (C) 2022 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 #ifndef WIFI_NAN_IFACE_H_ 18 #define WIFI_NAN_IFACE_H_ 19 20 #include <aidl/android/hardware/wifi/BnWifiNanIface.h> 21 #include <aidl/android/hardware/wifi/IWifiNanIfaceEventCallback.h> 22 #include <android-base/macros.h> 23 24 #include "aidl_callback_util.h" 25 #include "wifi_iface_util.h" 26 #include "wifi_legacy_hal.h" 27 28 namespace aidl { 29 namespace android { 30 namespace hardware { 31 namespace wifi { 32 33 /** 34 * AIDL interface object used to control a NAN Iface instance. 35 */ 36 class WifiNanIface : public BnWifiNanIface { 37 public: 38 WifiNanIface(const std::string& ifname, bool is_dedicated_iface, 39 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal, 40 const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util); 41 42 // Factory method - use instead of default constructor. 43 static std::shared_ptr<WifiNanIface> create( 44 const std::string& ifname, bool is_dedicated_iface, 45 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal, 46 const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util); 47 48 // Refer to |WifiChip::invalidate()|. 49 void invalidate(); 50 bool isValid(); 51 std::string getName(); 52 53 // AIDL methods exposed. 54 ndk::ScopedAStatus getName(std::string* _aidl_return) override; 55 ndk::ScopedAStatus registerEventCallback( 56 const std::shared_ptr<IWifiNanIfaceEventCallback>& in_callback) override; 57 ndk::ScopedAStatus getCapabilitiesRequest(char16_t in_cmdId) override; 58 ndk::ScopedAStatus enableRequest(char16_t in_cmdId, const NanEnableRequest& in_msg1, 59 const NanConfigRequestSupplemental& in_msg2) override; 60 ndk::ScopedAStatus configRequest(char16_t in_cmdId, const NanConfigRequest& in_msg1, 61 const NanConfigRequestSupplemental& in_msg2) override; 62 ndk::ScopedAStatus disableRequest(char16_t in_cmdId) override; 63 ndk::ScopedAStatus startPublishRequest(char16_t in_cmdId, 64 const NanPublishRequest& in_msg) override; 65 ndk::ScopedAStatus stopPublishRequest(char16_t in_cmdId, int8_t in_sessionId) override; 66 ndk::ScopedAStatus startSubscribeRequest(char16_t in_cmdId, 67 const NanSubscribeRequest& in_msg) override; 68 ndk::ScopedAStatus stopSubscribeRequest(char16_t in_cmdId, int8_t in_sessionId) override; 69 ndk::ScopedAStatus transmitFollowupRequest(char16_t in_cmdId, 70 const NanTransmitFollowupRequest& in_msg) override; 71 ndk::ScopedAStatus createDataInterfaceRequest(char16_t in_cmdId, 72 const std::string& in_ifaceName) override; 73 ndk::ScopedAStatus deleteDataInterfaceRequest(char16_t in_cmdId, 74 const std::string& in_ifaceName) override; 75 ndk::ScopedAStatus initiateDataPathRequest(char16_t in_cmdId, 76 const NanInitiateDataPathRequest& in_msg) override; 77 ndk::ScopedAStatus respondToDataPathIndicationRequest( 78 char16_t in_cmdId, const NanRespondToDataPathIndicationRequest& in_msg) override; 79 ndk::ScopedAStatus terminateDataPathRequest(char16_t in_cmdId, 80 int32_t in_ndpInstanceId) override; 81 ndk::ScopedAStatus initiatePairingRequest(char16_t in_cmdId, 82 const NanPairingRequest& in_msg) override; 83 ndk::ScopedAStatus respondToPairingIndicationRequest( 84 char16_t in_cmdId, const NanRespondToPairingIndicationRequest& in_msg) override; 85 ndk::ScopedAStatus terminatePairingRequest(char16_t in_cmdId, int32_t in_pairingId) override; 86 ndk::ScopedAStatus initiateBootstrappingRequest(char16_t in_cmdId, 87 const NanBootstrappingRequest& in_msg) override; 88 ndk::ScopedAStatus respondToBootstrappingIndicationRequest( 89 char16_t in_cmdId, const NanBootstrappingResponse& in_msg) override; 90 ndk::ScopedAStatus suspendRequest(char16_t in_cmdId, int8_t sessionId) override; 91 ndk::ScopedAStatus resumeRequest(char16_t in_cmdId, int8_t sessionId) override; 92 93 protected: 94 // Accessible to child class in the gTest suite. 95 void setWeakPtr(std::weak_ptr<WifiNanIface> ptr); 96 void registerCallbackHandlers(); 97 98 private: 99 // Corresponding worker functions for the AIDL methods. 100 std::pair<std::string, ndk::ScopedAStatus> getNameInternal(); 101 ndk::ScopedAStatus registerEventCallbackInternal( 102 const std::shared_ptr<IWifiNanIfaceEventCallback>& callback); 103 ndk::ScopedAStatus getCapabilitiesRequestInternal(char16_t cmd_id); 104 ndk::ScopedAStatus enableRequestInternal(char16_t cmd_id, const NanEnableRequest& msg1, 105 const NanConfigRequestSupplemental& msg2); 106 ndk::ScopedAStatus configRequestInternal(char16_t cmd_id, const NanConfigRequest& msg1, 107 const NanConfigRequestSupplemental& msg2); 108 ndk::ScopedAStatus disableRequestInternal(char16_t cmd_id); 109 ndk::ScopedAStatus startPublishRequestInternal(char16_t cmd_id, const NanPublishRequest& msg); 110 ndk::ScopedAStatus stopPublishRequestInternal(char16_t cmd_id, int8_t sessionId); 111 ndk::ScopedAStatus startSubscribeRequestInternal(char16_t cmd_id, 112 const NanSubscribeRequest& msg); 113 ndk::ScopedAStatus stopSubscribeRequestInternal(char16_t cmd_id, int8_t sessionId); 114 ndk::ScopedAStatus transmitFollowupRequestInternal(char16_t cmd_id, 115 const NanTransmitFollowupRequest& msg); 116 ndk::ScopedAStatus createDataInterfaceRequestInternal(char16_t cmd_id, 117 const std::string& iface_name); 118 ndk::ScopedAStatus deleteDataInterfaceRequestInternal(char16_t cmd_id, 119 const std::string& iface_name); 120 ndk::ScopedAStatus initiateDataPathRequestInternal(char16_t cmd_id, 121 const NanInitiateDataPathRequest& msg); 122 ndk::ScopedAStatus respondToDataPathIndicationRequestInternal( 123 char16_t cmd_id, const NanRespondToDataPathIndicationRequest& msg); 124 ndk::ScopedAStatus terminateDataPathRequestInternal(char16_t cmd_id, int32_t ndpInstanceId); 125 ndk::ScopedAStatus initiatePairingRequestInternal(char16_t cmd_id, 126 const NanPairingRequest& msg); 127 ndk::ScopedAStatus respondToPairingIndicationRequestInternal( 128 char16_t cmd_id, const NanRespondToPairingIndicationRequest& msg); 129 ndk::ScopedAStatus terminatePairingRequestInternal(char16_t cmd_id, int32_t pairingId); 130 ndk::ScopedAStatus initiateBootstrappingRequestInternal(char16_t cmd_id, 131 const NanBootstrappingRequest& msg); 132 ndk::ScopedAStatus respondToBootstrappingIndicationRequestInternal( 133 char16_t cmd_id, const NanBootstrappingResponse& msg); 134 ndk::ScopedAStatus suspendRequestInternal(char16_t in_cmdId, int8_t sessionId); 135 ndk::ScopedAStatus resumeRequestInternal(char16_t in_cmdId, int8_t sessionId); 136 137 // Overridden in the gTest suite. 138 virtual std::set<std::shared_ptr<IWifiNanIfaceEventCallback>> getEventCallbacks(); 139 140 std::string ifname_; 141 bool is_dedicated_iface_; 142 std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_; 143 std::weak_ptr<iface_util::WifiIfaceUtil> iface_util_; 144 bool is_valid_; 145 std::weak_ptr<WifiNanIface> weak_ptr_this_; 146 aidl_callback_util::AidlCallbackHandler<IWifiNanIfaceEventCallback> event_cb_handler_; 147 148 DISALLOW_COPY_AND_ASSIGN(WifiNanIface); 149 }; 150 151 } // namespace wifi 152 } // namespace hardware 153 } // namespace android 154 } // namespace aidl 155 156 #endif // WIFI_NAN_IFACE_H_ 157