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_ = DeviceBoutique::Register("beacon_swarm", &BeaconSwarm::Create);
33 
BeaconSwarm(const std::vector<std::string> & args)34 BeaconSwarm::BeaconSwarm(const std::vector<std::string>& args) : Beacon(args) {
35   advertising_interval_ = 1280ms;
36   advertising_type_ = LegacyAdvertisingType::ADV_NONCONN_IND;
37   advertising_data_ = {
38           0x15 /* Length */,
39           0x09 /* TYPE_NAME_COMPLETE */,
40           'g',
41           'D',
42           'e',
43           'v',
44           'i',
45           'c',
46           'e',
47           '-',
48           'b',
49           'e',
50           'a',
51           'c',
52           'o',
53           'n',
54           '_',
55           's',
56           'w',
57           'a',
58           'r',
59           'm',
60           0x02 /* Length */,
61           0x01 /* TYPE_FLAG */,
62           0x4 /* BREDR_NOT_SUPPORTED */ | 0x2 /* GENERAL_DISCOVERABLE */,
63   };
64 
65   scan_response_data_ = {0x06 /* Length */, 0x08 /* TYPE_NAME_SHORT */, 'c', 'b', 'e', 'a', 'c'};
66 }
67 
Tick()68 void BeaconSwarm::Tick() {
69   // Rotate the advertising address.
70   uint8_t* low_order_byte = address_.data();
71   *low_order_byte += 1;
72   Beacon::Tick();
73 }
74 
75 }  // namespace rootcanal
76