1 /* 2 * Copyright (C) 2016 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 <android-base/macros.h> 21 #include <android/hardware/wifi/1.0/IWifiNanIfaceEventCallback.h> 22 #include <android/hardware/wifi/1.2/IWifiNanIface.h> 23 24 #include "hidl_callback_util.h" 25 #include "wifi_iface_util.h" 26 #include "wifi_legacy_hal.h" 27 28 namespace android { 29 namespace hardware { 30 namespace wifi { 31 namespace V1_3 { 32 namespace implementation { 33 using namespace android::hardware::wifi::V1_0; 34 35 /** 36 * HIDL interface object used to control a NAN Iface instance. 37 */ 38 class WifiNanIface : public V1_2::IWifiNanIface { 39 public: 40 WifiNanIface(const std::string& ifname, 41 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal, 42 const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util); 43 // Refer to |WifiChip::invalidate()|. 44 void invalidate(); 45 bool isValid(); 46 std::string getName(); 47 48 // HIDL methods exposed. 49 Return<void> getName(getName_cb hidl_status_cb) override; 50 Return<void> getType(getType_cb hidl_status_cb) override; 51 Return<void> registerEventCallback( 52 const sp<V1_0::IWifiNanIfaceEventCallback>& callback, 53 registerEventCallback_cb hidl_status_cb) override; 54 Return<void> getCapabilitiesRequest( 55 uint16_t cmd_id, getCapabilitiesRequest_cb hidl_status_cb) override; 56 Return<void> enableRequest(uint16_t cmd_id, const NanEnableRequest& msg, 57 enableRequest_cb hidl_status_cb) override; 58 Return<void> configRequest(uint16_t cmd_id, const NanConfigRequest& msg, 59 configRequest_cb hidl_status_cb) override; 60 Return<void> disableRequest(uint16_t cmd_id, 61 disableRequest_cb hidl_status_cb) override; 62 Return<void> startPublishRequest( 63 uint16_t cmd_id, const NanPublishRequest& msg, 64 startPublishRequest_cb hidl_status_cb) override; 65 Return<void> stopPublishRequest( 66 uint16_t cmd_id, uint8_t sessionId, 67 stopPublishRequest_cb hidl_status_cb) override; 68 Return<void> startSubscribeRequest( 69 uint16_t cmd_id, const NanSubscribeRequest& msg, 70 startSubscribeRequest_cb hidl_status_cb) override; 71 Return<void> stopSubscribeRequest( 72 uint16_t cmd_id, uint8_t sessionId, 73 stopSubscribeRequest_cb hidl_status_cb) override; 74 Return<void> transmitFollowupRequest( 75 uint16_t cmd_id, const NanTransmitFollowupRequest& msg, 76 transmitFollowupRequest_cb hidl_status_cb) override; 77 Return<void> createDataInterfaceRequest( 78 uint16_t cmd_id, const hidl_string& iface_name, 79 createDataInterfaceRequest_cb hidl_status_cb) override; 80 Return<void> deleteDataInterfaceRequest( 81 uint16_t cmd_id, const hidl_string& iface_name, 82 deleteDataInterfaceRequest_cb hidl_status_cb) override; 83 Return<void> initiateDataPathRequest( 84 uint16_t cmd_id, const NanInitiateDataPathRequest& msg, 85 initiateDataPathRequest_cb hidl_status_cb) override; 86 Return<void> respondToDataPathIndicationRequest( 87 uint16_t cmd_id, const NanRespondToDataPathIndicationRequest& msg, 88 respondToDataPathIndicationRequest_cb hidl_status_cb) override; 89 Return<void> terminateDataPathRequest( 90 uint16_t cmd_id, uint32_t ndpInstanceId, 91 terminateDataPathRequest_cb hidl_status_cb) override; 92 93 Return<void> registerEventCallback_1_2( 94 const sp<V1_2::IWifiNanIfaceEventCallback>& callback, 95 registerEventCallback_1_2_cb hidl_status_cb) override; 96 Return<void> enableRequest_1_2( 97 uint16_t cmd_id, const NanEnableRequest& msg1, 98 const V1_2::NanConfigRequestSupplemental& msg2, 99 enableRequest_1_2_cb hidl_status_cb) override; 100 Return<void> configRequest_1_2( 101 uint16_t cmd_id, const NanConfigRequest& msg1, 102 const V1_2::NanConfigRequestSupplemental& msg2, 103 configRequest_1_2_cb hidl_status_cb) override; 104 105 private: 106 // Corresponding worker functions for the HIDL methods. 107 std::pair<WifiStatus, std::string> getNameInternal(); 108 std::pair<WifiStatus, IfaceType> getTypeInternal(); 109 WifiStatus registerEventCallbackInternal( 110 const sp<V1_0::IWifiNanIfaceEventCallback>& callback); 111 WifiStatus getCapabilitiesRequestInternal(uint16_t cmd_id); 112 WifiStatus enableRequestInternal(uint16_t cmd_id, 113 const NanEnableRequest& msg); 114 WifiStatus configRequestInternal(uint16_t cmd_id, 115 const NanConfigRequest& msg); 116 WifiStatus disableRequestInternal(uint16_t cmd_id); 117 WifiStatus startPublishRequestInternal(uint16_t cmd_id, 118 const NanPublishRequest& msg); 119 WifiStatus stopPublishRequestInternal(uint16_t cmd_id, uint8_t sessionId); 120 WifiStatus startSubscribeRequestInternal(uint16_t cmd_id, 121 const NanSubscribeRequest& msg); 122 WifiStatus stopSubscribeRequestInternal(uint16_t cmd_id, uint8_t sessionId); 123 WifiStatus transmitFollowupRequestInternal( 124 uint16_t cmd_id, const NanTransmitFollowupRequest& msg); 125 WifiStatus createDataInterfaceRequestInternal( 126 uint16_t cmd_id, const std::string& iface_name); 127 WifiStatus deleteDataInterfaceRequestInternal( 128 uint16_t cmd_id, const std::string& iface_name); 129 WifiStatus initiateDataPathRequestInternal( 130 uint16_t cmd_id, const NanInitiateDataPathRequest& msg); 131 WifiStatus respondToDataPathIndicationRequestInternal( 132 uint16_t cmd_id, const NanRespondToDataPathIndicationRequest& msg); 133 WifiStatus terminateDataPathRequestInternal(uint16_t cmd_id, 134 uint32_t ndpInstanceId); 135 136 WifiStatus registerEventCallback_1_2Internal( 137 const sp<V1_2::IWifiNanIfaceEventCallback>& callback); 138 WifiStatus enableRequest_1_2Internal( 139 uint16_t cmd_id, const NanEnableRequest& msg1, 140 const V1_2::NanConfigRequestSupplemental& msg2); 141 WifiStatus configRequest_1_2Internal( 142 uint16_t cmd_id, const NanConfigRequest& msg, 143 const V1_2::NanConfigRequestSupplemental& msg2); 144 145 // all 1_0 and descendant callbacks 146 std::set<sp<V1_0::IWifiNanIfaceEventCallback>> getEventCallbacks(); 147 // all 1_2 and descendant callbacks 148 std::set<sp<V1_2::IWifiNanIfaceEventCallback>> getEventCallbacks_1_2(); 149 150 std::string ifname_; 151 std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_; 152 std::weak_ptr<iface_util::WifiIfaceUtil> iface_util_; 153 bool is_valid_; 154 hidl_callback_util::HidlCallbackHandler<V1_0::IWifiNanIfaceEventCallback> 155 event_cb_handler_; 156 hidl_callback_util::HidlCallbackHandler<V1_2::IWifiNanIfaceEventCallback> 157 event_cb_handler_1_2_; 158 159 DISALLOW_COPY_AND_ASSIGN(WifiNanIface); 160 }; 161 162 } // namespace implementation 163 } // namespace V1_3 164 } // namespace wifi 165 } // namespace hardware 166 } // namespace android 167 168 #endif // WIFI_NAN_IFACE_H_ 169