Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / ble / CHIPBleServiceData.h
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    Copyright (c) 2019 Google LLC.
5  *
6  *    Licensed under the Apache License, Version 2.0 (the "License");
7  *    you may not use this file except in compliance with the License.
8  *    You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *    Unless required by applicable law or agreed to in writing, software
13  *    distributed under the License is distributed on an "AS IS" BASIS,
14  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *    See the License for the specific language governing permissions and
16  *    limitations under the License.
17  */
18
19 /**
20  *    @file
21  *          Definitions for chip BLE service advertisement data.
22  */
23
24 #pragma once
25
26 #include <core/CHIPEncoding.h>
27
28 namespace chip {
29 namespace Ble {
30
31 /**
32  * chip data block types that may appear with chip BLE service advertisement data.
33  */
34 enum chipBLEServiceDataType
35 {
36     kchipBLEServiceDataType_DeviceIdentificationInfo = 0x01,
37     kchipBLEServiceDataType_TokenIdentificationInfo  = 0x02,
38 };
39
40 /**
41  * chip BLE Device Identification Information Block
42  *
43  * Defines the over-the-air encoded format of the device identification information block that appears
44  * within chip BLE service advertisement data.
45  */
46 struct ChipBLEDeviceIdentificationInfo
47 {
48     constexpr static uint16_t kDiscriminatorMask = 0xfff;
49
50     uint8_t OpCode;
51     uint8_t DeviceDiscriminator[2];
52     uint8_t DeviceVendorId[2];
53     uint8_t DeviceProductId[2];
54
55     void Init() { memset(this, 0, sizeof(*this)); }
56
57     uint16_t GetVendorId() const { return chip::Encoding::LittleEndian::Get16(DeviceVendorId); }
58
59     void SetVendorId(uint16_t vendorId) { chip::Encoding::LittleEndian::Put16(DeviceVendorId, vendorId); }
60
61     uint16_t GetProductId() const { return chip::Encoding::LittleEndian::Get16(DeviceProductId); }
62
63     void SetProductId(uint16_t productId) { chip::Encoding::LittleEndian::Put16(DeviceProductId, productId); }
64
65     uint16_t GetDeviceDiscriminator() const
66     {
67         return chip::Encoding::LittleEndian::Get16(DeviceDiscriminator) & kDiscriminatorMask;
68     }
69
70     void SetDeviceDiscriminator(uint16_t deviceDiscriminator)
71     {
72         // Discriminator is 12-bit long, so don't overwrite bits 12th through 15th
73         deviceDiscriminator &= kDiscriminatorMask;
74         deviceDiscriminator |= static_cast<uint16_t>(DeviceDiscriminator[1] << 8u & ~kDiscriminatorMask);
75         chip::Encoding::LittleEndian::Put16(DeviceDiscriminator, deviceDiscriminator);
76     }
77 } __attribute__((packed));
78
79 } /* namespace Ble */
80 } /* namespace chip */