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