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

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 typo build problem 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 enum ReceiverType { CLIENT, SERVER };
24
25 class Factory {
26 public:
27 static std::unique_ptr<BluetoothLowEnergyWeavePacketReceiver> NewInstance(
28 ReceiverType receiver_type);
29
30 // Exposed for testing.
31 static void SetInstanceForTesting(Factory* factory);
32
33 protected:
34 // Exposed for testing.
35 BluetoothLowEnergyWeavePacketReceiver* BuildInstance(
36 ReceiverType receiver_type);
37
38 private:
39 static Factory* factory_instance_;
40 };
41
42 enum State {
43 CONNECTING = 0x00,
Kyle Horimoto 2016/06/20 23:25:40 Please add descriptions to each state which make i
jingxuy 2016/06/21 01:19:15 It was a TODO that I didn't get to. Done.
44 WAITING = 0x01,
45 RECEIVING_DATA = 0x02,
46 DATA_READY = 0x03,
47 CONNECTION_CLOSED = 0x04,
48 ERROR = 0x05
49 };
50
51 ~BluetoothLowEnergyWeavePacketReceiver();
52
53 typedef std::vector<uint8_t> Packet;
54
55 // Get the receiver’s state.
56 State GetState();
57
58 // Return the packet size that the receiver parsed out of request/response.
Kyle Horimoto 2016/06/20 23:25:40 Please list the conditions under which this can be
jingxuy 2016/06/21 01:19:15 This is always valid, see comment in cc file
Kyle Horimoto 2016/06/21 18:13:37 Readers of this class should only need to look at
jingxuy 2016/06/22 01:42:23 I meant refer to my reply comment to you in the cc
59 uint16_t GetMaxPacketSize();
60
61 // Will crash unless receiver is in State::CONNECTION_CLOSED.
62 BluetoothLowEnergyWeavePacketGenerator::ReasonForClose GetReasonForClose();
Kyle Horimoto 2016/06/20 23:25:40 Please add documentation to the GetReason{For|To}C
jingxuy 2016/06/21 01:19:15 Done.
63
64 // Will crash unless receiver is in State::ERROR.
65 // The reason that the receiver decided to enter ERROR state.
66 BluetoothLowEnergyWeavePacketGenerator::ReasonForClose GetReasonToClose();
67
68 // Will crash unless receiver is in State::DATA_READY.
69 // NOTE: if this function is not called in DATA_READY state and the receiver
70 // transitions out of that state, the data will be gone!
71 std::string GetDataMessage();
Kyle Horimoto 2016/06/20 23:25:40 Likewise, please document this function.
jingxuy 2016/06/22 01:42:23 Done.
72
73 // Add a packet that's just been received over Connection to the receiver.
74 State ReceivePacket(const Packet& packet);
75
76 protected:
77 explicit BluetoothLowEnergyWeavePacketReceiver(ReceiverType receiver_type);
78
79 private:
80 void ReceiveFirstPacket(const Packet& packet);
81 void ReceiveNonFirstPacket(const Packet& packet, bool expect_first_packet);
82
83 void ReceiveConnectionRequest(const Packet& packet);
84 void ReceiveConnectionResponse(const Packet& packet);
85 void ReceiveConnectionClose(const Packet& packet);
86 void AppendData(const Packet& packet, uint32_t byte_offset);
87
88 uint16_t GetShortField(const Packet& packet, uint32_t byte_offset);
89 uint8_t GetPacketType(const Packet& packet);
90 uint8_t GetControlCommand(const Packet& packet);
91 void VerifyPacketCounter(const Packet& packet);
92 bool IsFirstDataPacket(const Packet& packet);
93 bool IsLastDataPacket(const Packet& packet);
94 bool IsLowerTwoBitsCleared(const Packet& packet);
Kyle Horimoto 2016/06/20 23:25:40 nit: s/Is/Are/
jingxuy 2016/06/21 01:19:14 Done.
95
96 void Error(
Kyle Horimoto 2016/06/20 23:25:40 nit: s/Error/TransitionToErrorState/
jingxuy 2016/06/21 01:19:14 I changed it to ThrowError
Kyle Horimoto 2016/06/21 02:10:26 This function doesn't throw an error, though. Plea
Kyle Horimoto 2016/06/21 18:13:37 Ping.
jingxuy 2016/06/22 01:42:23 Done.
97 std::string error_message,
98 BluetoothLowEnergyWeavePacketGenerator::ReasonForClose reason_to_close);
99
100 void SetMaxPacketSize(uint16_t packet_size);
101 uint16_t GetConceptualMaxPacketSize();
102
103 // Identify whether the receiver is for a client or a server.
104 ReceiverType receiver_type_;
105
106 // Max packet size of the connection.
107 // Default is 0 which means the server will determine the size by observing
108 // ATT_MTU of the client.
109 uint16_t max_packet_size_;
110
111 // Counter for the number of packets sent, starting at 0.
112 uint32_t packet_number_;
Kyle Horimoto 2016/06/20 23:25:40 nit: How about next_packet_number_ instead? Otherw
jingxuy 2016/06/21 01:19:15 Done.
113
114 // Current state of the receiver.
115 // Certain functions will only return valid value if the receiver is in the
116 // appropriate state.
117 State state_;
118
119 // The reason why the connection was closed by the sender if any.
120 BluetoothLowEnergyWeavePacketGenerator::ReasonForClose reason_for_close_;
121
122 // The reason why the receiver is in an erronous state if any.
123 BluetoothLowEnergyWeavePacketGenerator::ReasonForClose reason_to_close_;
124
125 // The data message if there is one.
126 Packet data_message_;
127 };
128
129 } // namespace proximity_auth
130
131 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_RECEI VER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698