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