• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 #pragma once
18 
19 #include <aidl/android/hardware/threadnetwork/BnThreadChip.h>
20 #include <aidl/android/hardware/threadnetwork/IThreadChipCallback.h>
21 
22 #include "lib/spinel/spinel_interface.hpp"
23 #include "mainloop.hpp"
24 #include "radio_url.hpp"
25 
26 #include <android/binder_auto_utils.h>
27 #include <android/binder_ibinder.h>
28 #include <utils/Mutex.h>
29 
30 namespace aidl {
31 namespace android {
32 namespace hardware {
33 namespace threadnetwork {
34 
35 class ThreadChip : public BnThreadChip, ot::Posix::Mainloop::Source {
36   public:
37     ThreadChip(const char* url);
~ThreadChip()38     ~ThreadChip() {}
39 
40     ndk::ScopedAStatus open(const std::shared_ptr<IThreadChipCallback>& in_callback) override;
41     ndk::ScopedAStatus close() override;
42     ndk::ScopedAStatus sendSpinelFrame(const std::vector<uint8_t>& in_frame) override;
43     ndk::ScopedAStatus hardwareReset() override;
44     void Update(otSysMainloopContext& context) override;
45     void Process(const otSysMainloopContext& context) override;
46     void setVendorCallback(const std::shared_ptr<IThreadChipCallback>& vendorCallback);
47 
48   private:
49     static void onBinderDiedJump(void* context);
50     void onBinderDied(void);
51     static void onBinderUnlinkedJump(void* context);
52     void onBinderUnlinked(void);
53     static void handleReceivedFrameJump(void* context);
54     void handleReceivedFrame(void);
55     ndk::ScopedAStatus errorStatus(int32_t error, const char* message);
56     ndk::ScopedAStatus initChip(const std::shared_ptr<IThreadChipCallback>& in_callback);
57     ndk::ScopedAStatus deinitChip();
58 
59     ot::Posix::RadioUrl mUrl;
60     std::shared_ptr<ot::Spinel::SpinelInterface> mSpinelInterface;
61     ot::Spinel::SpinelInterface::RxFrameBuffer mRxFrameBuffer;
62     std::shared_ptr<IThreadChipCallback> mCallback;
63     std::shared_ptr<IThreadChipCallback> mVendorCallback;
64     ::ndk::ScopedAIBinder_DeathRecipient mDeathRecipient;
65 };
66 
67 }  // namespace threadnetwork
68 }  // namespace hardware
69 }  // namespace android
70 }  // namespace aidl
71