• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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 "car_kit.h"
18 
19 #include "model/setup/device_boutique.h"
20 #include "os/log.h"
21 
22 using std::vector;
23 
24 namespace test_vendor_lib {
25 
26 bool CarKit::registered_ = DeviceBoutique::Register("car_kit", &CarKit::Create);
27 const std::string kCarKitPropertiesFile =
28     "/etc/bluetooth/car_kit_controller_properties.json";
29 
CarKit()30 CarKit::CarKit() : Device(kCarKitPropertiesFile) {
31   advertising_interval_ms_ = std::chrono::milliseconds(0);
32 
33   page_scan_delay_ms_ = std::chrono::milliseconds(600);
34 
35   // Stub in packet handling for now
36   link_layer_controller_.RegisterAclChannel(
37       [](std::shared_ptr<bluetooth::hci::AclBuilder>) {});
38   link_layer_controller_.RegisterEventChannel(
39       [](std::shared_ptr<bluetooth::hci::EventBuilder>) {});
40   link_layer_controller_.RegisterScoChannel(
41       [](std::shared_ptr<bluetooth::hci::ScoBuilder>) {});
42   link_layer_controller_.RegisterRemoteChannel(
43       [this](std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet,
44              Phy::Type phy_type) {
45         CarKit::SendLinkLayerPacket(packet, phy_type);
46       });
47 
48   properties_.SetPageScanRepetitionMode(0);
49   properties_.SetClassOfDevice(0x600420);
50   properties_.SetExtendedFeatures(0x8779ff9bfe8defff, 0);
51   properties_.SetExtendedInquiryData({
52       16,  // length
53       9,   // Type: Device Name
54       'g',  'D', 'e', 'v', 'i', 'c', 'e', '-', 'c', 'a', 'r', '_', 'k', 'i', 't',
55       7,     // length
56       3,     // Type: 16-bit UUIDs
57       0x0e,  // AVRC
58       0x11,
59       0x0B,  // Audio Sink
60       0x11,
61       0x00,  // PnP Information
62       0x12,
63   });
64   properties_.SetName({
65       'g',
66       'D',
67       'e',
68       'v',
69       'i',
70       'c',
71       'e',
72       '-',
73       'C',
74       'a',
75       'r',
76       '_',
77       'K',
78       'i',
79       't',
80   });
81 }
82 
Initialize(const vector<std::string> & args)83 void CarKit::Initialize(const vector<std::string>& args) {
84   if (args.size() < 2) return;
85 
86   Address addr{};
87   if (Address::FromString(args[1], addr)) properties_.SetAddress(addr);
88   LOG_INFO("%s SetAddress %s", ToString().c_str(), addr.ToString().c_str());
89 
90   if (args.size() < 3) return;
91 
92   properties_.SetClockOffset(std::stoi(args[2]));
93 }
94 
TimerTick()95 void CarKit::TimerTick() {
96   link_layer_controller_.TimerTick();
97 }
98 
IncomingPacket(model::packets::LinkLayerPacketView packet)99 void CarKit::IncomingPacket(model::packets::LinkLayerPacketView packet) {
100   LOG_WARN("Incoming Packet");
101   link_layer_controller_.IncomingPacket(packet);
102 }
103 
104 }  // namespace test_vendor_lib
105