Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/proximity_auth/ble/bluetooth_low_energy_weave_packet_genera tor.h" | 5 #include "components/proximity_auth/ble/bluetooth_low_energy_weave_packet_genera tor.h" |
| 6 | 6 |
| 7 #ifdef OS_WIN | 7 #ifdef OS_WIN |
| 8 #include <winsock2.h> | 8 #include <winsock2.h> |
| 9 #else | 9 #else |
| 10 #include <netinet/in.h> | 10 #include <netinet/in.h> |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include <string.h> | 13 #include <string.h> |
| 14 | 14 |
| 15 #include <algorithm> | 15 #include <algorithm> |
| 16 | 16 |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 | 18 |
| 19 namespace proximity_auth { | |
|
Kyle Horimoto
2016/06/27 20:51:12
Why is this moved? Same in the other unit test.
jingxuy
2016/06/27 22:21:33
I saw that this is how the connection class does i
Kyle Horimoto
2016/06/27 22:25:40
Ah, good idea. Thanks for the explanation.
jingxuy
2016/06/27 22:49:08
np
| |
| 20 | |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 typedef proximity_auth::BluetoothLowEnergyWeavePacketGenerator::Packet Packet; | 23 typedef BluetoothLowEnergyWeavePacket::ControlCommand ControlCommand; |
| 24 typedef BluetoothLowEnergyWeavePacket::Packet Packet; | |
| 25 typedef BluetoothLowEnergyWeavePacket::PacketType PacketType; | |
| 26 typedef BluetoothLowEnergyWeavePacket::ReasonForClose ReasonForClose; | |
| 22 | 27 |
| 23 const uint16_t kMinSupportedWeaveVersion = 1; | 28 const uint16_t kMinSupportedWeaveVersion = 1; |
| 24 const uint16_t kMaxSupportedWeaveVersion = 1; | 29 const uint16_t kMaxSupportedWeaveVersion = 1; |
| 25 const uint16_t kServerWeaveVersion = 1; | 30 const uint16_t kServerWeaveVersion = 1; |
| 26 const uint16_t kMinConnectionRequestSize = 7; | 31 const uint16_t kMinConnectionRequestSize = 7; |
| 27 const uint16_t kMinConnectionResponseSize = 5; | 32 const uint16_t kMinConnectionResponseSize = 5; |
| 28 const uint16_t kMinConnectionCloseSize = 3; | 33 const uint16_t kMinConnectionCloseSize = 3; |
| 29 const uint32_t kDefaultMaxPacketSize = 20; | 34 const uint32_t kDefaultMaxPacketSize = 20; |
| 30 // Max packet size is 0, which means defer the decision to the server. | 35 // Max packet size is 0, which means defer the decision to the server. |
| 31 const uint16_t kMaxSupportedPacketSize = 0; | 36 const uint16_t kMaxSupportedPacketSize = 0; |
| 32 const uint8_t kMaxPacketCounter = 8; | 37 const uint8_t kMaxPacketCounter = 8; |
| 33 | 38 |
| 34 } // namespace | 39 } // namespace |
| 35 | 40 |
| 36 namespace proximity_auth { | |
| 37 | |
| 38 // static. | 41 // static. |
| 39 BluetoothLowEnergyWeavePacketGenerator::Factory* | 42 BluetoothLowEnergyWeavePacketGenerator::Factory* |
| 40 BluetoothLowEnergyWeavePacketGenerator::Factory::factory_instance_ = | 43 BluetoothLowEnergyWeavePacketGenerator::Factory::factory_instance_ = |
| 41 nullptr; | 44 nullptr; |
| 42 | 45 |
| 43 // static. | 46 // static. |
| 44 std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator> | 47 std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator> |
| 45 BluetoothLowEnergyWeavePacketGenerator::Factory::NewInstance() { | 48 BluetoothLowEnergyWeavePacketGenerator::Factory::NewInstance() { |
| 46 if (factory_instance_ == nullptr) { | 49 if (factory_instance_ == nullptr) { |
| 47 factory_instance_ = new Factory(); | 50 factory_instance_ = new Factory(); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 | 209 |
| 207 void BluetoothLowEnergyWeavePacketGenerator::SetDataLastBit(Packet* packet) { | 210 void BluetoothLowEnergyWeavePacketGenerator::SetDataLastBit(Packet* packet) { |
| 208 DCHECK(packet); | 211 DCHECK(packet); |
| 209 DCHECK(!packet->empty()); | 212 DCHECK(!packet->empty()); |
| 210 | 213 |
| 211 // Last bit is the bit 2 of the packet's first byte and set it to 1. | 214 // Last bit is the bit 2 of the packet's first byte and set it to 1. |
| 212 packet->at(0) = packet->at(0) | (1 << 2); | 215 packet->at(0) = packet->at(0) | (1 << 2); |
| 213 } | 216 } |
| 214 | 217 |
| 215 } // namespace proximity_auth | 218 } // namespace proximity_auth |
| OLD | NEW |