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 "beacon"
18 
19 #include "beacon.h"
20 #include "stack/include/hcidefs.h"
21 
22 using std::vector;
23 
24 namespace test_vendor_lib {
25 Beacon::Beacon() {
26   advertising_interval_ms_ = std::chrono::milliseconds(1280);
27   advertising_type_ = BTM_BLE_NON_CONNECT_EVT;
28   adv_data_ = {0x0F,  // Length
29                BTM_BLE_AD_TYPE_NAME_CMPL,
30                'g',
31                'D',
32                'e',
33                'v',
34                'i',
35                'c',
36                'e',
37                '-',
38                'b',
39                'e',
40                'a',
41                'c',
42                'o',
43                'n',
44                0x02,  // Length
45                BTM_BLE_AD_TYPE_FLAG,
46                BTM_BLE_BREDR_NOT_SPT | BTM_BLE_GEN_DISC_FLAG};
47 
48   scan_data_ = {0x05,  // Length
49                 BTM_BLE_AD_TYPE_NAME_SHORT,
50                 'b',
51                 'e',
52                 'a',
53                 'c'};
54 }
55 
56 void Beacon::Initialize(const vector<std::string>& args) {
57   if (args.size() < 2) return;
58 
59   BtAddress addr;
60   if (addr.FromString(args[1])) SetBtAddress(addr);
61 
62   if (args.size() < 3) return;
63 
64   SetAdvertisementInterval(std::chrono::milliseconds(std::stoi(args[2])));
65 }
66 
67 }  // namespace test_vendor_lib
68