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