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 #include "model/devices/beacon_swarm.h"
18 
19 #include <chrono>
20 #include <cstdint>
21 #include <string>
22 #include <vector>
23 
24 #include "model/devices/beacon.h"
25 #include "model/setup/device_boutique.h"
26 #include "packets/link_layer_packets.h"
27 
28 namespace rootcanal {
29 using namespace model::packets;
30 using namespace std::chrono_literals;
31 
32 bool BeaconSwarm::registered_ =
33     DeviceBoutique::Register("beacon_swarm", &BeaconSwarm::Create);
34 
BeaconSwarm(const std::vector<std::string> & args)35 BeaconSwarm::BeaconSwarm(const std::vector<std::string>& args) : Beacon(args) {
36   advertising_interval_ = 1280ms;
37   advertising_type_ = LegacyAdvertisingType::ADV_NONCONN_IND;
38   advertising_data_ = {
39       0x15 /* Length */,
40       0x09 /* TYPE_NAME_COMPLETE */,
41       'g',
42       'D',
43       'e',
44       'v',
45       'i',
46       'c',
47       'e',
48       '-',
49       'b',
50       'e',
51       'a',
52       'c',
53       'o',
54       'n',
55       '_',
56       's',
57       'w',
58       'a',
59       'r',
60       'm',
61       0x02 /* Length */,
62       0x01 /* TYPE_FLAG */,
63       0x4 /* BREDR_NOT_SUPPORTED */ | 0x2 /* GENERAL_DISCOVERABLE */,
64   };
65 
66   scan_response_data_ = {
67       0x06 /* Length */, 0x08 /* TYPE_NAME_SHORT */, 'c', 'b', 'e', 'a', 'c'};
68 }
69 
Tick()70 void BeaconSwarm::Tick() {
71   // Rotate the advertising address.
72   uint8_t* low_order_byte = address_.data();
73   *low_order_byte += 1;
74   Beacon::Tick();
75 }
76 
77 }  // namespace rootcanal
78