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

Unified 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: changed magic numbers to enums 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 side-by-side diff with in-line comments
Download patch
Index: components/proximity_auth/ble/bluetooth_low_energy_weave_packet_generator.h
diff --git a/components/proximity_auth/ble/bluetooth_low_energy_weave_packet_generator.h b/components/proximity_auth/ble/bluetooth_low_energy_weave_packet_generator.h
new file mode 100644
index 0000000000000000000000000000000000000000..6be5e6b2bc0601a401f696443e5940b6edb53167
--- /dev/null
+++ b/components/proximity_auth/ble/bluetooth_low_energy_weave_packet_generator.h
@@ -0,0 +1,95 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_GENERATOR_H_
+#define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_GENERATOR_H_
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+
+namespace proximity_auth {
+// Generates the messages sent using the uWeave protocol.
+// Internally tracks the packet number.
+class BluetoothLowEnergyWeavePacketGenerator {
+ public:
+ class Factory {
+ public:
+ static std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator>
+ NewInstance();
+
+ // Exposed for testing.
+ static void SetInstanceForTesting(Factory* factory);
+
+ protected:
+ // Exposed for testing.
+ BluetoothLowEnergyWeavePacketGenerator* BuildInstance();
+
+ private:
+ static Factory* factory_instance_;
+ };
+
+ enum PacketType { DATA = 0x00, CONTROL = 0x01 };
+
+ enum ControlPacketCommand { REQUEST = 0x00, RESPONSE = 0x01, CLOSE = 0x02 };
Kyle Horimoto 2016/06/08 00:06:30 Prefix these with CONNECTION_.
+
+ enum ReasonForClose {
+ CLOSE_WITHOUT_ERROR = 0x00,
+ UNKNOWN_ERROR = 0x01,
+ NO_COMMON_VERSION_SUPPORTED = 0x02,
+ RECEIVED_PACKET_OUT_OF_SEQUENCE = 0x03,
+ APPLICATION_ERROR = 0x80
+ };
+
+ typedef std::vector<uint8_t> Packet;
+
+ std::unique_ptr<Packet> CreateConnectionRequest();
+ std::unique_ptr<Packet> CreateConnectionResponse();
+ std::unique_ptr<Packet> CreateConnectionClose(
+ ReasonForClose reason_for_close);
+
+ void SetDataPacketSize(uint32_t size);
+
+ std::unique_ptr<std::vector<Packet>> EncodeDataMessage(std::string message);
+
+ protected:
+ BluetoothLowEnergyWeavePacketGenerator();
+
+ private:
+ static const uint16_t kMinSupportedWeaveVersion = 1;
+ static const uint16_t kMaxSupportedWeaveVersion = 1;
+ static const uint16_t kServerWeaveVersion = 1;
+ static const uint16_t kControlPacketSize = 20;
+ static const uint32_t kDefaultDataPacketSize = 20;
+
+ // Max packet size is 0, which means defer the decision to the server.
+ static const uint16_t kMaxSupportedPacketSize = 0;
+ static const uint8_t kMaxPacketCounter = 8;
+
+ Packet* CreateControlPacket();
+
+ // For error checking.
+ bool IsBit(uint8_t val);
+
+ void SetIntField(Packet* packet, uint32_t index, uint16_t val);
+ void SetPacketTypeBit(Packet* packet, bool val);
+ void SetControlCmd(Packet* packet, uint8_t val);
+ void SetPacketCounter(Packet* packet);
+ void SetDataFirstBit(Packet* packet);
+ void SetDataLastBit(Packet* packet);
+
+ // The default data packet length is 20 unless setDataPacketLength() is called
+ // and specified otherwise.
+ uint32_t packet_size_;
+
+ // Counter for the number of packets sent, starting at 0.
+ uint32_t packet_number_;
+};
+
+} // namespace proximity_auth
+
+#endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_GENERATOR_H_

Powered by Google App Engine
This is Rietveld 408576698