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

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

Issue 2053013002: Weave Packet Receiver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proximity_auth_weave_migration
Patch Set: fixed a slight typo in the .h file 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_RECEIVER _H_
6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_RECEIVER _H_
7
8 #include <stdint.h>
9
10 #include <memory>
11 #include <string>
12 #include <vector>
13
14 #include "components/proximity_auth/ble/bluetooth_low_energy_weave_packet_genera tor.h"
15
16 namespace proximity_auth {
17 // Receive the messages sent with uWeave protocol.
18 // TODO(jingxuy): move the enums from BluetoothLowEnergyWeavePacketGenerator to
19 // a shared location
20 class BluetoothLowEnergyWeavePacketReceiver {
21 public:
22 class Factory {
23 public:
24 static std::unique_ptr<BluetoothLowEnergyWeavePacketReceiver> NewInstance();
25
26 // Exposed for testing.
27 static void SetInstanceForTesting(Factory* factory);
28
29 protected:
30 // Exposed for testing.
31 BluetoothLowEnergyWeavePacketReceiver* BuildInstance();
32
33 private:
34 static Factory* factory_instance_;
35 };
36
37 enum State {
38 EXCHANGING_CONTROLS = 0x00,
39 RECEIVING_DATA = 0x01,
40 DATA_READY = 0x02,
41 CONNECTION_CLOSED = 0x03,
42 ERROR = 0x04
43 };
44
45 ~BluetoothLowEnergyWeavePacketReceiver();
46
47 typedef std::vector<uint8_t> Packet;
48
49 void ResetReceiver();
Tim Song 2016/06/10 21:25:21 It's usually simpler and less prone to error to cr
jingxuy 2016/06/11 00:10:47 Done.
50
51 // Get the receiver’s state.
52 State GetState();
53
54 // Return the packet size that the receiver parsed out of request/response.
55 uint32_t GetPacketSize();
56
57 // Return something valid only when receiver in CONNECTION_CLOSED
58 BluetoothLowEnergyWeavePacketGenerator::ReasonForClose GetReasonForClose();
59
60 // Returns non empty string only when the receiver is in DATA_READY
61 std::string GetDataMessage();
62
63 // Add a packet that's just been received over Connection to the receiver
64 State ReceivePacket(const Packet& packet);
65
66 protected:
67 BluetoothLowEnergyWeavePacketReceiver();
68
69 private:
70 void ReceiveWithPartialData(const Packet& packet);
71 void ReceiveWithEmptyData(const Packet& packet);
72
73 void ReceiveConnectionRequest(const Packet& packet);
74 void ReceiveConnectionResponse(const Packet& packet);
75 void ReceiveConnectionClose(const Packet& packet);
76 void AppendData(const Packet& packet);
77
78 uint16_t GetShortField(const Packet& packet, uint32_t index);
79 BluetoothLowEnergyWeavePacketGenerator::PacketType GetPacketType(
80 const Packet& packet);
81 BluetoothLowEnergyWeavePacketGenerator::ControlCommand GetControlCommand(
82 const Packet& packet);
83 void VerifyPacketCounter(const Packet& packet);
84 bool IsFirstDataPacket(const Packet& packet);
85 bool IsLastDataPacket(const Packet& packet);
86
87 // Max packet size of the connection.
88 // Default is 0 which means the server will determine the size by observing
89 // ATT_MTU of the client.
90 uint32_t packet_size_;
91
92 // Counter for the number of packets sent, starting at 0
93 uint32_t packet_number_;
94
95 // Current state of the receiver.
96 // Certain functions will only return valid value if the receiver is in the
97 // appropriate state
98 State state_;
99
100 // The reason why the connection was closed if any
101 BluetoothLowEnergyWeavePacketGenerator::ReasonForClose reason_for_close_;
102
103 // The data message if there is one
104 std::vector<uint8_t> data_message_;
105 };
106
107 } // namespace proximity_auth
108
109 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_RECEI VER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698