Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 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 | |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 17 | #include <android-base/logging.h> |
| 18 | |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 19 | #include "hidl_return_util.h" |
| 20 | #include "wifi_nan_iface.h" |
Roshan Pius | 734fea0 | 2016-10-11 08:30:28 -0700 | [diff] [blame] | 21 | #include "wifi_status_util.h" |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 22 | |
| 23 | namespace android { |
| 24 | namespace hardware { |
| 25 | namespace wifi { |
| 26 | namespace V1_0 { |
| 27 | namespace implementation { |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 28 | using hidl_return_util::validateAndCall; |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 29 | |
Roshan Pius | 6cedc97 | 2016-10-28 10:11:17 -0700 | [diff] [blame^] | 30 | WifiNanIface::WifiNanIface( |
| 31 | const std::string& ifname, |
| 32 | const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal) |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 33 | : ifname_(ifname), legacy_hal_(legacy_hal), is_valid_(true) {} |
| 34 | |
| 35 | void WifiNanIface::invalidate() { |
| 36 | legacy_hal_.reset(); |
Roshan Pius | 0c92d44 | 2016-10-27 17:38:53 -0700 | [diff] [blame] | 37 | event_callbacks_.clear(); |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 38 | is_valid_ = false; |
| 39 | } |
| 40 | |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 41 | bool WifiNanIface::isValid() { |
| 42 | return is_valid_; |
| 43 | } |
| 44 | |
Roshan Pius | 734fea0 | 2016-10-11 08:30:28 -0700 | [diff] [blame] | 45 | Return<void> WifiNanIface::getName(getName_cb hidl_status_cb) { |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 46 | return validateAndCall(this, |
| 47 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 48 | &WifiNanIface::getNameInternal, |
| 49 | hidl_status_cb); |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Roshan Pius | 0c92d44 | 2016-10-27 17:38:53 -0700 | [diff] [blame] | 52 | Return<void> WifiNanIface::registerEventCallback( |
| 53 | const sp<IWifiNanIfaceEventCallback>& callback, |
| 54 | registerEventCallback_cb hidl_status_cb) { |
| 55 | return validateAndCall(this, |
| 56 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 57 | &WifiNanIface::registerEventCallbackInternal, |
| 58 | hidl_status_cb, |
| 59 | callback); |
| 60 | } |
| 61 | |
| 62 | Return<void> WifiNanIface::enableRequest(uint32_t cmd_id, |
| 63 | const NanEnableRequest& msg, |
| 64 | enableRequest_cb hidl_status_cb) { |
| 65 | return validateAndCall(this, |
| 66 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 67 | &WifiNanIface::enableRequestInternal, |
| 68 | hidl_status_cb, |
| 69 | cmd_id, |
| 70 | msg); |
| 71 | } |
| 72 | |
| 73 | Return<void> WifiNanIface::disableRequest(uint32_t cmd_id, |
| 74 | disableRequest_cb hidl_status_cb) { |
| 75 | return validateAndCall(this, |
| 76 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 77 | &WifiNanIface::disableRequestInternal, |
| 78 | hidl_status_cb, |
| 79 | cmd_id); |
| 80 | } |
| 81 | |
| 82 | Return<void> WifiNanIface::publishRequest(uint32_t cmd_id, |
| 83 | const NanPublishRequest& msg, |
| 84 | publishRequest_cb hidl_status_cb) { |
| 85 | return validateAndCall(this, |
| 86 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 87 | &WifiNanIface::publishRequestInternal, |
| 88 | hidl_status_cb, |
| 89 | cmd_id, |
| 90 | msg); |
| 91 | } |
| 92 | |
| 93 | Return<void> WifiNanIface::publishCancelRequest( |
| 94 | uint32_t cmd_id, |
| 95 | const NanPublishCancelRequest& msg, |
| 96 | publishCancelRequest_cb hidl_status_cb) { |
| 97 | return validateAndCall(this, |
| 98 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 99 | &WifiNanIface::publishCancelRequestInternal, |
| 100 | hidl_status_cb, |
| 101 | cmd_id, |
| 102 | msg); |
| 103 | } |
| 104 | |
| 105 | Return<void> WifiNanIface::subscribeRequest( |
| 106 | uint32_t cmd_id, |
| 107 | const NanSubscribeRequest& msg, |
| 108 | subscribeRequest_cb hidl_status_cb) { |
| 109 | return validateAndCall(this, |
| 110 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 111 | &WifiNanIface::subscribeRequestInternal, |
| 112 | hidl_status_cb, |
| 113 | cmd_id, |
| 114 | msg); |
| 115 | } |
| 116 | |
| 117 | Return<void> WifiNanIface::subscribeCancelRequest( |
| 118 | uint32_t cmd_id, |
| 119 | const NanSubscribeCancelRequest& msg, |
| 120 | subscribeCancelRequest_cb hidl_status_cb) { |
| 121 | return validateAndCall(this, |
| 122 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 123 | &WifiNanIface::subscribeCancelRequestInternal, |
| 124 | hidl_status_cb, |
| 125 | cmd_id, |
| 126 | msg); |
| 127 | } |
| 128 | |
| 129 | Return<void> WifiNanIface::transmitFollowupRequest( |
| 130 | uint32_t cmd_id, |
| 131 | const NanTransmitFollowupRequest& msg, |
| 132 | transmitFollowupRequest_cb hidl_status_cb) { |
| 133 | return validateAndCall(this, |
| 134 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 135 | &WifiNanIface::transmitFollowupRequestInternal, |
| 136 | hidl_status_cb, |
| 137 | cmd_id, |
| 138 | msg); |
| 139 | } |
| 140 | |
| 141 | Return<void> WifiNanIface::configRequest(uint32_t cmd_id, |
| 142 | const NanConfigRequest& msg, |
| 143 | configRequest_cb hidl_status_cb) { |
| 144 | return validateAndCall(this, |
| 145 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 146 | &WifiNanIface::configRequestInternal, |
| 147 | hidl_status_cb, |
| 148 | cmd_id, |
| 149 | msg); |
| 150 | } |
| 151 | |
| 152 | Return<void> WifiNanIface::beaconSdfPayloadRequest( |
| 153 | uint32_t cmd_id, |
| 154 | const NanBeaconSdfPayloadRequest& msg, |
| 155 | beaconSdfPayloadRequest_cb hidl_status_cb) { |
| 156 | return validateAndCall(this, |
| 157 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 158 | &WifiNanIface::beaconSdfPayloadRequestInternal, |
| 159 | hidl_status_cb, |
| 160 | cmd_id, |
| 161 | msg); |
| 162 | } |
| 163 | |
| 164 | Return<void> WifiNanIface::getVersion(getVersion_cb hidl_status_cb) { |
| 165 | return validateAndCall(this, |
| 166 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 167 | &WifiNanIface::getVersionInternal, |
| 168 | hidl_status_cb); |
| 169 | } |
| 170 | |
| 171 | Return<void> WifiNanIface::getCapabilities(uint32_t cmd_id, |
| 172 | getCapabilities_cb hidl_status_cb) { |
| 173 | return validateAndCall(this, |
| 174 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 175 | &WifiNanIface::getCapabilitiesInternal, |
| 176 | hidl_status_cb, |
| 177 | cmd_id); |
| 178 | } |
| 179 | |
| 180 | Return<void> WifiNanIface::dataInterfaceCreate( |
| 181 | uint32_t cmd_id, |
| 182 | const hidl_string& iface_name, |
| 183 | dataInterfaceCreate_cb hidl_status_cb) { |
| 184 | return validateAndCall(this, |
| 185 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 186 | &WifiNanIface::dataInterfaceCreateInternal, |
| 187 | hidl_status_cb, |
| 188 | cmd_id, |
| 189 | iface_name); |
| 190 | } |
| 191 | |
| 192 | Return<void> WifiNanIface::dataInterfaceDelete( |
| 193 | uint32_t cmd_id, |
| 194 | const hidl_string& iface_name, |
| 195 | dataInterfaceDelete_cb hidl_status_cb) { |
| 196 | return validateAndCall(this, |
| 197 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 198 | &WifiNanIface::dataInterfaceDeleteInternal, |
| 199 | hidl_status_cb, |
| 200 | cmd_id, |
| 201 | iface_name); |
| 202 | } |
| 203 | |
| 204 | Return<void> WifiNanIface::dataRequestInitiator( |
| 205 | uint32_t cmd_id, |
| 206 | const NanDataPathInitiatorRequest& msg, |
| 207 | dataRequestInitiator_cb hidl_status_cb) { |
| 208 | return validateAndCall(this, |
| 209 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 210 | &WifiNanIface::dataRequestInitiatorInternal, |
| 211 | hidl_status_cb, |
| 212 | cmd_id, |
| 213 | msg); |
| 214 | } |
| 215 | |
| 216 | Return<void> WifiNanIface::dataIndicationResponse( |
| 217 | uint32_t cmd_id, |
| 218 | const NanDataPathIndicationResponse& msg, |
| 219 | dataIndicationResponse_cb hidl_status_cb) { |
| 220 | return validateAndCall(this, |
| 221 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 222 | &WifiNanIface::dataIndicationResponseInternal, |
| 223 | hidl_status_cb, |
| 224 | cmd_id, |
| 225 | msg); |
| 226 | } |
| 227 | |
| 228 | Return<void> WifiNanIface::dataEnd(uint32_t cmd_id, |
| 229 | const NanDataPathEndRequest& msg, |
| 230 | dataEnd_cb hidl_status_cb) { |
| 231 | return validateAndCall(this, |
| 232 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 233 | &WifiNanIface::dataEndInternal, |
| 234 | hidl_status_cb, |
| 235 | cmd_id, |
| 236 | msg); |
| 237 | } |
| 238 | |
Roshan Pius | 734fea0 | 2016-10-11 08:30:28 -0700 | [diff] [blame] | 239 | Return<void> WifiNanIface::getType(getType_cb hidl_status_cb) { |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 240 | return validateAndCall(this, |
| 241 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 242 | &WifiNanIface::getTypeInternal, |
| 243 | hidl_status_cb); |
| 244 | } |
| 245 | |
| 246 | std::pair<WifiStatus, std::string> WifiNanIface::getNameInternal() { |
| 247 | return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_}; |
| 248 | } |
| 249 | |
| 250 | std::pair<WifiStatus, IfaceType> WifiNanIface::getTypeInternal() { |
| 251 | return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::NAN}; |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Roshan Pius | 0c92d44 | 2016-10-27 17:38:53 -0700 | [diff] [blame] | 254 | WifiStatus WifiNanIface::registerEventCallbackInternal( |
| 255 | const sp<IWifiNanIfaceEventCallback>& callback) { |
| 256 | // TODO(b/31632518): remove the callback when the client is destroyed |
| 257 | event_callbacks_.emplace_back(callback); |
| 258 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 259 | } |
| 260 | |
| 261 | WifiStatus WifiNanIface::enableRequestInternal( |
| 262 | uint32_t /* cmd_id */, const NanEnableRequest& /* msg */) { |
| 263 | // TODO implement |
| 264 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 265 | } |
| 266 | |
| 267 | WifiStatus WifiNanIface::disableRequestInternal(uint32_t /* cmd_id */) { |
| 268 | // TODO implement |
| 269 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 270 | } |
| 271 | |
| 272 | WifiStatus WifiNanIface::publishRequestInternal( |
| 273 | uint32_t /* cmd_id */, const NanPublishRequest& /* msg */) { |
| 274 | // TODO implement |
| 275 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 276 | } |
| 277 | |
| 278 | WifiStatus WifiNanIface::publishCancelRequestInternal( |
| 279 | uint32_t /* cmd_id */, const NanPublishCancelRequest& /* msg */) { |
| 280 | // TODO implement |
| 281 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 282 | } |
| 283 | WifiStatus WifiNanIface::subscribeRequestInternal( |
| 284 | uint32_t /* cmd_id */, const NanSubscribeRequest& /* msg */) { |
| 285 | // TODO implement |
| 286 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 287 | } |
| 288 | WifiStatus WifiNanIface::subscribeCancelRequestInternal( |
| 289 | uint32_t /* cmd_id */, const NanSubscribeCancelRequest& /* msg */) { |
| 290 | // TODO implement |
| 291 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 292 | } |
| 293 | WifiStatus WifiNanIface::transmitFollowupRequestInternal( |
| 294 | uint32_t /* cmd_id */, const NanTransmitFollowupRequest& /* msg */) { |
| 295 | // TODO implement |
| 296 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 297 | } |
| 298 | WifiStatus WifiNanIface::configRequestInternal( |
| 299 | uint32_t /* cmd_id */, const NanConfigRequest& /* msg */) { |
| 300 | // TODO implement |
| 301 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 302 | } |
| 303 | WifiStatus WifiNanIface::beaconSdfPayloadRequestInternal( |
| 304 | uint32_t /* cmd_id */, const NanBeaconSdfPayloadRequest& /* msg */) { |
| 305 | // TODO implement |
| 306 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 307 | } |
| 308 | std::pair<WifiStatus, NanVersion> WifiNanIface::getVersionInternal() { |
| 309 | // TODO implement |
| 310 | return {createWifiStatus(WifiStatusCode::SUCCESS), 0}; |
| 311 | } |
| 312 | WifiStatus WifiNanIface::getCapabilitiesInternal(uint32_t /* cmd_id */) { |
| 313 | // TODO implement |
| 314 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 315 | } |
| 316 | WifiStatus WifiNanIface::dataInterfaceCreateInternal( |
| 317 | uint32_t /* cmd_id */, const std::string& /* iface_name */) { |
| 318 | // TODO implement |
| 319 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 320 | } |
| 321 | WifiStatus WifiNanIface::dataInterfaceDeleteInternal( |
| 322 | uint32_t /* cmd_id */, const std::string& /* iface_name */) { |
| 323 | // TODO implement |
| 324 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 325 | } |
| 326 | WifiStatus WifiNanIface::dataRequestInitiatorInternal( |
| 327 | uint32_t /* cmd_id */, const NanDataPathInitiatorRequest& /* msg */) { |
| 328 | // TODO implement |
| 329 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 330 | } |
| 331 | WifiStatus WifiNanIface::dataIndicationResponseInternal( |
| 332 | uint32_t /* cmd_id */, const NanDataPathIndicationResponse& /* msg */) { |
| 333 | // TODO implement |
| 334 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 335 | } |
| 336 | WifiStatus WifiNanIface::dataEndInternal( |
| 337 | uint32_t /* cmd_id */, const NanDataPathEndRequest& /* msg */) { |
| 338 | // TODO implement |
| 339 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 340 | } |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 341 | } // namespace implementation |
| 342 | } // namespace V1_0 |
| 343 | } // namespace wifi |
| 344 | } // namespace hardware |
| 345 | } // namespace android |