1 /*
2 * Copyright 2016 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 "keyboard"
18
19 #include "keyboard.h"
20
21 #include "model/setup/device_boutique.h"
22
23 using std::vector;
24
25 namespace test_vendor_lib {
26 bool Keyboard::registered_ = DeviceBoutique::Register(LOG_TAG, &Keyboard::Create);
27
Keyboard()28 Keyboard::Keyboard() {
29 properties_.SetLeAdvertisementType(BTM_BLE_CONNECT_EVT);
30 properties_.SetLeAdvertisement({0x11, // Length
31 BTM_BLE_AD_TYPE_NAME_CMPL,
32 'g',
33 'D',
34 'e',
35 'v',
36 'i',
37 'c',
38 'e',
39 '-',
40 'k',
41 'e',
42 'y',
43 'b',
44 'o',
45 'a',
46 'r',
47 'd',
48 0x03, // Length
49 0x19,
50 0xC1,
51 0x03,
52 0x03, // Length
53 0x03,
54 0x12,
55 0x18,
56 0x02, // Length
57 BTM_BLE_AD_TYPE_FLAG,
58 BTM_BLE_BREDR_NOT_SPT | BTM_BLE_GEN_DISC_FLAG});
59
60 properties_.SetLeScanResponse({0x04, // Length
61 BTM_BLE_AD_TYPE_NAME_SHORT, 'k', 'e', 'y'});
62 }
63
GetTypeString() const64 std::string Keyboard::GetTypeString() const {
65 return "keyboard";
66 }
67
Initialize(const vector<std::string> & args)68 void Keyboard::Initialize(const vector<std::string>& args) {
69 if (args.size() < 2) return;
70
71 Address addr;
72 if (Address::FromString(args[1], addr)) properties_.SetLeAddress(addr);
73
74 if (args.size() < 3) return;
75
76 SetAdvertisementInterval(std::chrono::milliseconds(std::stoi(args[2])));
77 }
78
TimerTick()79 void Keyboard::TimerTick() {
80 if (!connected_) {
81 Beacon::TimerTick();
82 }
83 }
84
IncomingPacket(packets::LinkLayerPacketView packet)85 void Keyboard::IncomingPacket(packets::LinkLayerPacketView packet) {
86 if (!connected_) {
87 Beacon::IncomingPacket(packet);
88 }
89 }
90
91 } // namespace test_vendor_lib
92