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

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: added state transtion out of connecting 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 // TODO(jingxuy): a complete state transition comment
21 class BluetoothLowEnergyWeavePacketReceiver {
22 public:
23 class Factory {
24 public:
25 static std::unique_ptr<BluetoothLowEnergyWeavePacketReceiver> NewInstance();
26
27 // Exposed for testing.
28 static void SetInstanceForTesting(Factory* factory);
29
30 protected:
31 // Exposed for testing.
32 BluetoothLowEnergyWeavePacketReceiver* BuildInstance();
33
34 private:
35 static Factory* factory_instance_;
36 };
37
38 enum State {
39 CONNECTING = 0x00,
40 RECEIVING_DATA = 0x01,
41 DATA_READY = 0x02,
42 CONNECTION_CLOSED = 0x03,
43 ERROR = 0x04
44 };
sacomoto 2016/06/13 17:16:40 When this class detect an error, e.g. wrong packet
jingxuy 2016/06/16 08:42:28 Done.
45
46 ~BluetoothLowEnergyWeavePacketReceiver();
47
48 typedef std::vector<uint8_t> Packet;
49
50 // Get the receiver’s state.
51 State GetState();
52
53 // Return the packet size that the receiver parsed out of request/response.
54 uint32_t GetPacketSize();
55
56 // Will crash unless receiver is in State::CONNECTION_CLOSED.
57 BluetoothLowEnergyWeavePacketGenerator::ReasonForClose GetReasonForClose();
58
59 // Will crash unless receiver is in State::DATA_READY.
60 // NOTE: if this function is not called in DATA_READY state and the receiver
61 // transitions out of that state, the data will be gone!
62 std::string GetDataMessage();
63
64 // Add a packet that's just been received over Connection to the receiver.
65 State ReceivePacket(const Packet& packet);
66
67 protected:
68 BluetoothLowEnergyWeavePacketReceiver();
69
70 private:
71 void ReceiveControlPacket(const Packet& packet);
72 void ReceiveDataPacket(const Packet& packet);
73
74 void ReceiveConnectionRequest(const Packet& packet);
75 void ReceiveConnectionResponse(const Packet& packet);
76 void ReceiveConnectionClose(const Packet& packet);
77 void AppendData(const Packet& packet);
78
79 uint16_t GetShortField(const Packet& packet, uint32_t index);
80 uint8_t GetPacketType(const Packet& packet);
81 uint8_t GetControlCommand(const Packet& packet);
82 void VerifyPacketCounter(const Packet& packet);
83 bool IsFirstDataPacket(const Packet& packet);
84 bool IsLastDataPacket(const Packet& packet);
85
86 // Max packet size of the connection.
87 // Default is 0 which means the server will determine the size by observing
88 // ATT_MTU of the client.
89 uint32_t packet_size_;
90
91 // Counter for the number of packets sent, starting at 0.
92 uint32_t packet_number_;
93
94 // Current state of the receiver.
95 // Certain functions will only return valid value if the receiver is in the
96 // appropriate state.
97 State state_;
98
99 // The reason why the connection was closed if any.
100 BluetoothLowEnergyWeavePacketGenerator::ReasonForClose reason_for_close_;
101
102 // The data message if there is one.
103 Packet data_message_;
104 };
105
106 } // namespace proximity_auth
107
108 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_RECEI VER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698