Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 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; |
Nate Jiang | 38e8db5 | 2022-12-02 17:30:27 -0800 | [diff] [blame^] | 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 initiateBootstrappingRequest(char16_t in_cmdId, |
| 86 | const NanBootstrappingRequest& in_msg) override; |
| 87 | ndk::ScopedAStatus respondToBootstrappingIndicationRequest( |
| 88 | char16_t in_cmdId, const NanBootstrappingResponse& in_msg) override; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 89 | |
| 90 | protected: |
| 91 | // Accessible to child class in the gTest suite. |
| 92 | void setWeakPtr(std::weak_ptr<WifiNanIface> ptr); |
| 93 | void registerCallbackHandlers(); |
| 94 | |
| 95 | private: |
| 96 | // Corresponding worker functions for the AIDL methods. |
| 97 | std::pair<std::string, ndk::ScopedAStatus> getNameInternal(); |
| 98 | ndk::ScopedAStatus registerEventCallbackInternal( |
| 99 | const std::shared_ptr<IWifiNanIfaceEventCallback>& callback); |
| 100 | ndk::ScopedAStatus getCapabilitiesRequestInternal(char16_t cmd_id); |
| 101 | ndk::ScopedAStatus enableRequestInternal(char16_t cmd_id, const NanEnableRequest& msg1, |
| 102 | const NanConfigRequestSupplemental& msg2); |
| 103 | ndk::ScopedAStatus configRequestInternal(char16_t cmd_id, const NanConfigRequest& msg1, |
| 104 | const NanConfigRequestSupplemental& msg2); |
| 105 | ndk::ScopedAStatus disableRequestInternal(char16_t cmd_id); |
| 106 | ndk::ScopedAStatus startPublishRequestInternal(char16_t cmd_id, const NanPublishRequest& msg); |
| 107 | ndk::ScopedAStatus stopPublishRequestInternal(char16_t cmd_id, int8_t sessionId); |
| 108 | ndk::ScopedAStatus startSubscribeRequestInternal(char16_t cmd_id, |
| 109 | const NanSubscribeRequest& msg); |
| 110 | ndk::ScopedAStatus stopSubscribeRequestInternal(char16_t cmd_id, int8_t sessionId); |
| 111 | ndk::ScopedAStatus transmitFollowupRequestInternal(char16_t cmd_id, |
| 112 | const NanTransmitFollowupRequest& msg); |
| 113 | ndk::ScopedAStatus createDataInterfaceRequestInternal(char16_t cmd_id, |
| 114 | const std::string& iface_name); |
| 115 | ndk::ScopedAStatus deleteDataInterfaceRequestInternal(char16_t cmd_id, |
| 116 | const std::string& iface_name); |
| 117 | ndk::ScopedAStatus initiateDataPathRequestInternal(char16_t cmd_id, |
| 118 | const NanInitiateDataPathRequest& msg); |
| 119 | ndk::ScopedAStatus respondToDataPathIndicationRequestInternal( |
| 120 | char16_t cmd_id, const NanRespondToDataPathIndicationRequest& msg); |
| 121 | ndk::ScopedAStatus terminateDataPathRequestInternal(char16_t cmd_id, int32_t ndpInstanceId); |
Nate Jiang | 38e8db5 | 2022-12-02 17:30:27 -0800 | [diff] [blame^] | 122 | ndk::ScopedAStatus initiatePairingRequestInternal(char16_t cmd_id, |
| 123 | const NanPairingRequest& msg); |
| 124 | ndk::ScopedAStatus respondToPairingIndicationRequestInternal( |
| 125 | char16_t cmd_id, const NanRespondToPairingIndicationRequest& msg); |
| 126 | ndk::ScopedAStatus initiateBootstrappingRequestInternal(char16_t cmd_id, |
| 127 | const NanBootstrappingRequest& msg); |
| 128 | ndk::ScopedAStatus respondToBootstrappingIndicationRequestInternal( |
| 129 | char16_t cmd_id, const NanBootstrappingResponse& msg); |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 130 | |
| 131 | // Overridden in the gTest suite. |
| 132 | virtual std::set<std::shared_ptr<IWifiNanIfaceEventCallback>> getEventCallbacks(); |
| 133 | |
| 134 | std::string ifname_; |
| 135 | bool is_dedicated_iface_; |
| 136 | std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_; |
| 137 | std::weak_ptr<iface_util::WifiIfaceUtil> iface_util_; |
| 138 | bool is_valid_; |
| 139 | std::weak_ptr<WifiNanIface> weak_ptr_this_; |
| 140 | aidl_callback_util::AidlCallbackHandler<IWifiNanIfaceEventCallback> event_cb_handler_; |
| 141 | |
| 142 | DISALLOW_COPY_AND_ASSIGN(WifiNanIface); |
| 143 | }; |
| 144 | |
| 145 | } // namespace wifi |
| 146 | } // namespace hardware |
| 147 | } // namespace android |
| 148 | } // namespace aidl |
| 149 | |
| 150 | #endif // WIFI_NAN_IFACE_H_ |