Myles Watson | 90ee15b | 2017-02-09 16:47:33 -0800 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2017 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 <android/hardware/bluetooth/1.0/IBluetoothHci.h> |
| 20 | |
| 21 | #include <hidl/MQDescriptor.h> |
| 22 | |
| 23 | #include "async_fd_watcher.h" |
Myles Watson | 761dc49 | 2017-03-03 13:50:49 -0800 | [diff] [blame] | 24 | #include "h4_protocol.h" |
Myles Watson | 90ee15b | 2017-02-09 16:47:33 -0800 | [diff] [blame] | 25 | |
| 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | namespace bluetooth { |
| 29 | namespace V1_0 { |
| 30 | namespace hikey { |
| 31 | |
| 32 | using ::android::hardware::Return; |
| 33 | using ::android::hardware::hidl_vec; |
| 34 | |
Myles Watson | 7cc9c40 | 2017-03-03 14:58:47 -0800 | [diff] [blame] | 35 | struct BluetoothDeathRecipient : hidl_death_recipient { |
| 36 | BluetoothDeathRecipient(const sp<IBluetoothHci> hci) : mHci(hci) {} |
| 37 | |
| 38 | virtual void serviceDied( |
| 39 | uint64_t /*cookie*/, |
| 40 | const wp<::android::hidl::base::V1_0::IBase>& /*who*/) { |
| 41 | mHci->close(); |
| 42 | } |
| 43 | sp<IBluetoothHci> mHci; |
| 44 | }; |
| 45 | |
Myles Watson | 90ee15b | 2017-02-09 16:47:33 -0800 | [diff] [blame] | 46 | class BluetoothHci : public IBluetoothHci { |
| 47 | public: |
Myles Watson | 7cc9c40 | 2017-03-03 14:58:47 -0800 | [diff] [blame] | 48 | BluetoothHci(); |
Myles Watson | 90ee15b | 2017-02-09 16:47:33 -0800 | [diff] [blame] | 49 | Return<void> initialize( |
| 50 | const ::android::sp<IBluetoothHciCallbacks>& cb) override; |
| 51 | Return<void> sendHciCommand(const hidl_vec<uint8_t>& packet) override; |
| 52 | Return<void> sendAclData(const hidl_vec<uint8_t>& packet) override; |
| 53 | Return<void> sendScoData(const hidl_vec<uint8_t>& packet) override; |
| 54 | Return<void> close() override; |
| 55 | |
| 56 | static void OnPacketReady(); |
| 57 | |
Myles Watson | 90ee15b | 2017-02-09 16:47:33 -0800 | [diff] [blame] | 58 | private: |
| 59 | ::android::sp<IBluetoothHciCallbacks> event_cb_; |
| 60 | int hci_tty_fd_; |
| 61 | |
Myles Watson | 90ee15b | 2017-02-09 16:47:33 -0800 | [diff] [blame] | 62 | async::AsyncFdWatcher fd_watcher_; |
| 63 | |
Myles Watson | 761dc49 | 2017-03-03 13:50:49 -0800 | [diff] [blame] | 64 | hci::H4Protocol* hci_; |
Myles Watson | 7cc9c40 | 2017-03-03 14:58:47 -0800 | [diff] [blame] | 65 | |
| 66 | ::android::sp<BluetoothDeathRecipient> deathRecipient; |
Myles Watson | 90ee15b | 2017-02-09 16:47:33 -0800 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | } // namespace hikey |
| 70 | } // namespace V1_0 |
| 71 | } // namespace bluetooth |
| 72 | } // namespace hardware |
| 73 | } // namespace android |