Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 BluetoothLowEnergyWeavePacketGenerator* BuildInstance(); | |
| 30 | |
| 31 private: | |
| 32 static Factory* factory_instance_; | |
| 33 }; | |
| 34 | |
| 35 // Determine whether a packet is a control packet or a data packet. | |
| 36 enum PacketType { DATA = 0x00, CONTROL = 0x01 }; | |
| 37 | |
| 38 // Identify the action intended by the control packet. | |
| 39 enum ControlCommand { | |
| 40 CONNECTION_REQUEST = 0x00, | |
| 41 CONNECTION_RESPONSE = 0x01, | |
| 42 CONNECTION_CLOSE = 0x02 | |
| 43 }; | |
|
sacomoto
2016/06/13 16:05:19
Why PacketType and ControlCommand are public?
jingxuy
2016/06/17 00:56:45
It's part of a todo in the receiver. the commonali
sacomoto
2016/06/17 15:38:04
Ok, that makes sense.
jingxuy
2016/06/17 18:59:00
Done.
| |
| 44 | |
| 45 // Sent with the ConnectionClose control packet. | |
| 46 // Identify why the client/server wished to close the connection. | |
| 47 enum ReasonForClose { | |
| 48 CLOSE_WITHOUT_ERROR = 0x00, | |
| 49 UNKNOWN_ERROR = 0x01, | |
| 50 NO_COMMON_VERSION_SUPPORTED = 0x02, | |
| 51 RECEIVED_PACKET_OUT_OF_SEQUENCE = 0x03, | |
| 52 APPLICATION_ERROR = 0x80 | |
| 53 }; | |
| 54 | |
| 55 typedef std::vector<uint8_t> Packet; | |
| 56 | |
| 57 std::unique_ptr<Packet> CreateConnectionRequest(); | |
| 58 std::unique_ptr<Packet> CreateConnectionResponse(); | |
|
sacomoto
2016/06/13 16:05:19
This method should receive the chosen protocol ver
jingxuy
2016/06/17 00:56:45
Initially the protocol version is a parameter, but
sacomoto
2016/06/17 15:38:04
Ok, that makes sense.
jingxuy
2016/06/17 18:59:00
Done.
| |
| 59 std::unique_ptr<Packet> CreateConnectionClose( | |
| 60 ReasonForClose reason_for_close); | |
| 61 | |
| 62 void SetDataPacketSize(uint32_t size); | |
| 63 | |
| 64 std::unique_ptr<std::vector<Packet>> EncodeDataMessage(std::string message); | |
| 65 | |
| 66 protected: | |
| 67 BluetoothLowEnergyWeavePacketGenerator(); | |
| 68 | |
| 69 private: | |
| 70 Packet* CreateControlPacket(); | |
| 71 | |
| 72 void SetShortField(Packet* packet, uint32_t byte_offset, uint16_t val); | |
| 73 void SetPacketTypeBit(Packet* packet, PacketType val); | |
| 74 void SetControlCommand(Packet* packet, ControlCommand val); | |
| 75 void SetPacketCounter(Packet* packet); | |
| 76 void SetDataFirstBit(Packet* packet); | |
| 77 void SetDataLastBit(Packet* packet); | |
| 78 | |
| 79 // The default data packet length is 20 unless SetDataPacketLength() is called | |
| 80 // and specified otherwise. | |
| 81 uint32_t packet_size_; | |
| 82 | |
| 83 // Counter for the number of packets sent, starting at 0. | |
| 84 uint32_t packet_number_; | |
| 85 }; | |
| 86 | |
| 87 } // namespace proximity_auth | |
| 88 | |
| 89 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_GENER ATOR_H_ | |
| OLD | NEW |