• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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 #include "hci_device.h"
18 
19 #include "log.h"
20 
21 namespace rootcanal {
22 
HciDevice(std::shared_ptr<HciTransport> transport,ControllerProperties const & properties)23 HciDevice::HciDevice(std::shared_ptr<HciTransport> transport,
24                      ControllerProperties const& properties)
25     : DualModeController(ControllerProperties(properties)),
26       transport_(transport) {
27   link_layer_controller_.SetLocalName(std::vector<uint8_t>({
28       'g',
29       'D',
30       'e',
31       'v',
32       'i',
33       'c',
34       'e',
35       '-',
36       'H',
37       'C',
38       'I',
39   }));
40   link_layer_controller_.SetExtendedInquiryResponse(std::vector<uint8_t>({
41       12,  // Length
42       9,   // Type: Device Name
43       'g',
44       'D',
45       'e',
46       'v',
47       'i',
48       'c',
49       'e',
50       '-',
51       'h',
52       'c',
53       'i',
54   }));
55 
56   RegisterEventChannel([this](std::shared_ptr<std::vector<uint8_t>> packet) {
57     transport_->SendEvent(*packet);
58   });
59   RegisterAclChannel([this](std::shared_ptr<std::vector<uint8_t>> packet) {
60     transport_->SendAcl(*packet);
61   });
62   RegisterScoChannel([this](std::shared_ptr<std::vector<uint8_t>> packet) {
63     transport_->SendSco(*packet);
64   });
65   RegisterIsoChannel([this](std::shared_ptr<std::vector<uint8_t>> packet) {
66     transport_->SendIso(*packet);
67   });
68 
69   transport_->RegisterCallbacks(
70       [this](const std::shared_ptr<std::vector<uint8_t>> command) {
71         HandleCommand(command);
72       },
73       [this](const std::shared_ptr<std::vector<uint8_t>> acl) {
74         HandleAcl(acl);
75       },
76       [this](const std::shared_ptr<std::vector<uint8_t>> sco) {
77         HandleSco(sco);
78       },
79       [this](const std::shared_ptr<std::vector<uint8_t>> iso) {
80         HandleIso(iso);
81       },
82       [this]() {
83         LOG_INFO("HCI transport closed");
84         Close();
85       });
86 }
87 
Tick()88 void HciDevice::Tick() {
89   transport_->Tick();
90   DualModeController::Tick();
91 }
92 
Close()93 void HciDevice::Close() {
94   transport_->Close();
95   DualModeController::Close();
96 }
97 
98 }  // namespace rootcanal
99