• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021, 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 #include "hal_nxpuwb.h"
17 #include "phNxpUciHal_Adaptation.h"
18 #include "uwb.h"
19 
20 namespace {
21 constexpr static int32_t kAndroidUciVersion = 1;
22 }
23 
24 namespace android {
25 namespace hardware {
26 namespace uwb {
27 namespace impl {
28 using namespace ::aidl::android::hardware::uwb;
29 
UwbChip(const std::string & name)30 UwbChip::UwbChip(const std::string& name) : name_(name){};
31 std::shared_ptr<IUwbClientCallback> UwbChip:: mClientCallback = nullptr;
~UwbChip()32 UwbChip::~UwbChip() {}
33 
getName(std::string * name)34 ::ndk::ScopedAStatus UwbChip::getName(std::string* name) {
35     *name = name_;
36     return ndk::ScopedAStatus::ok();
37 }
38 
open(const std::shared_ptr<IUwbClientCallback> & clientCallback)39 ::ndk::ScopedAStatus UwbChip::open(const std::shared_ptr<IUwbClientCallback>& clientCallback) {
40     mClientCallback = clientCallback;
41       LOG(INFO) << "AIDL-open Enter";
42 
43       if (mClientCallback == nullptr) {
44         LOG(ERROR) << "AIDL-HAL open clientCallback is null......";
45         return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
46       }
47       int status = phNxpUciHal_open(eventCallback, dataCallback);
48       LOG(INFO) << "AIDL-open Exit" << status;
49       return ndk::ScopedAStatus::ok();
50 }
51 
close()52 ::ndk::ScopedAStatus UwbChip::close() {
53      LOG(INFO) << "AIDL-Close Enter";
54      if (mClientCallback == nullptr) {
55         LOG(ERROR) << "AIDL-HAL close mCallback is null......";
56         return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
57       }
58      phNxpUciHal_close();
59      if (mClientCallback != nullptr) {
60        mClientCallback = nullptr;
61      }
62      return ndk::ScopedAStatus::ok();
63 }
64 
coreInit()65 ::ndk::ScopedAStatus UwbChip::coreInit() {
66       LOG(INFO) << "AIDL-coreInit Enter";
67      phNxpUciHal_coreInitialization();
68     return ndk::ScopedAStatus::ok();
69 }
70 
getSupportedAndroidUciVersion(int32_t * version)71 ::ndk::ScopedAStatus UwbChip::getSupportedAndroidUciVersion(int32_t* version) {
72     *version = kAndroidUciVersion;
73     return ndk::ScopedAStatus::ok();
74 }
75 
sendUciMessage(const std::vector<uint8_t> & data,int32_t * _aidl_return)76 ::ndk::ScopedAStatus UwbChip::sendUciMessage(const std::vector<uint8_t>&  data,
77                                              int32_t* _aidl_return /* bytes_written */) {
78     // TODO(b/195992658): Need emulator support for UCI stack.
79      std::vector<uint8_t> copy = data;
80      LOG(INFO) << "AIDL-Write Enter";
81      int32_t ret = phNxpUciHal_write(data.size(), &copy[0]);
82      *_aidl_return = ret;
83      return ndk::ScopedAStatus::ok();
84 }
85 
sessionInit(int32_t sessionId)86 ::ndk::ScopedAStatus UwbChip::sessionInit(int32_t sessionId) {
87       LOG(INFO) << "AIDL-SessionInitialization Enter";
88       phNxpUciHal_sessionInitialization(sessionId);
89       return ndk::ScopedAStatus::ok();
90 }
91 }  // namespace impl
92 }  // namespace uwb
93 }  // namespace hardware
94 }  // namespace android
95