Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: components/proximity_auth/ble/bluetooth_low_energy_weave_packet_generator.h

Issue 2031953003: Weave Packet Generator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: increased the number of packets to test wrap arounds even better! Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_GENERATO R_H_
6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_GENERATO R_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <memory>
12 #include <string>
13 #include <vector>
14
15 namespace proximity_auth {
16 // Generates the messages sent using the uWeave protocol.
17 class BluetoothLowEnergyWeavePacketGenerator {
18 public:
19 class Factory {
20 public:
21 static std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator>
22 NewInstance();
23
24 // Exposed for testing.
25 static void SetInstanceForTesting(Factory* factory);
26
27 protected:
28 // Exposed for testing.
29 virtual std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator>
30 BuildInstance();
31
32 private:
33 static Factory* factory_instance_;
34 };
35
36 // Determine whether a packet is a control packet or a data packet.
37 enum PacketType { DATA = 0x00, CONTROL = 0x01 };
38
39 // Identify the action intended by the control packet.
40 enum ControlCommand {
41 CONNECTION_REQUEST = 0x00,
42 CONNECTION_RESPONSE = 0x01,
43 CONNECTION_CLOSE = 0x02
44 };
45
46 // Sent with the ConnectionClose control packet.
47 // Identify why the client/server wished to close the connection.
48 enum ReasonForClose {
49 CLOSE_WITHOUT_ERROR = 0x00,
50 UNKNOWN_ERROR = 0x01,
51 NO_COMMON_VERSION_SUPPORTED = 0x02,
52 RECEIVED_PACKET_OUT_OF_SEQUENCE = 0x03,
53 APPLICATION_ERROR = 0x80
54 };
55
56 typedef std::vector<uint8_t> Packet;
57
58 Packet CreateConnectionRequest();
59 Packet CreateConnectionResponse();
60 Packet CreateConnectionClose(ReasonForClose reason_for_close);
61
62 // Packet size must be greater than 2.
Tim Song 2016/06/22 18:41:31 Why have this limitation as long as its greater th
jingxuy 2016/06/22 19:07:02 I originally set it to 2 because there need to be
63 void SetDataPacketSize(uint32_t size);
64
65 // Will crash if message is empty.
Tim Song 2016/06/22 18:41:32 Crashing isn't the right thing to do. You should r
jingxuy 2016/06/22 19:07:02 It originally returned an empty vector returned on
66 std::vector<Packet> EncodeDataMessage(std::string message);
67
68 protected:
69 BluetoothLowEnergyWeavePacketGenerator();
70
71 private:
72 Packet CreateControlPacket(uint16_t size);
73
74 void SetShortField(uint32_t byte_offset, uint16_t val, Packet* packet);
75 void SetPacketTypeBit(PacketType val, Packet* packet);
76 void SetControlCommand(ControlCommand val, Packet* packet);
77 void SetPacketCounter(Packet* packet);
78 void SetDataFirstBit(Packet* packet);
79 void SetDataLastBit(Packet* packet);
80
81 // The default data packet length is 20 unless SetDataPacketLength() is called
82 // and specified otherwise.
83 uint32_t packet_size_;
84
85 // Counter for the number of packets sent, starting at 0.
86 uint32_t packet_number_;
87 };
88
89 } // namespace proximity_auth
90
91 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_GENER ATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698