Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / protocols / Protocols.h
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *
5  *    Licensed under the Apache License, Version 2.0 (the "License");
6  *    you may not use this file except in compliance with the License.
7  *    You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *    Unless required by applicable law or agreed to in writing, software
12  *    distributed under the License is distributed on an "AS IS" BASIS,
13  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *    See the License for the specific language governing permissions and
15  *    limitations under the License.
16  */
17
18 /**
19  *    @file
20  *      This file defines constant enumerations for all public (or
21  *      common) protocols.
22  *
23  */
24
25 #pragma once
26
27 #include <core/CHIPVendorIdentifiers.hpp>
28
29 namespace chip {
30 namespace Protocols {
31
32 //
33 // CHIP Protocol Ids (32-bits max)
34 //
35 class Id
36 {
37 public:
38     constexpr Id(VendorId aVendorId, uint16_t aProtocolId) : mVendorId(aVendorId), mProtocolId(aProtocolId) {}
39
40     constexpr bool operator==(const Id & aOther) const
41     {
42         return mVendorId == aOther.mVendorId && mProtocolId == aOther.mProtocolId;
43     }
44
45     // Convert the Protocols::Id to a TLV profile id.
46     // NOTE: We may want to change the TLV reader/writer to take Protocols::Id
47     // directly later on and get rid of this method.
48     constexpr uint32_t ToTLVProfileId() const { return ToUint32(); }
49
50     // Convert the protocol id to a 32-bit unsigned integer "fully qualified"
51     // form as defined in the spec.  This should only be used in the places
52     // where the spec defines a 32-bit unsigned in as a wire representation of
53     // protocol id.
54     constexpr uint32_t ToFullyQualifiedSpecForm() const { return ToUint32(); }
55
56     constexpr VendorId GetVendorId() const { return mVendorId; }
57     constexpr uint16_t GetProtocolId() const { return mProtocolId; }
58
59 private:
60     constexpr uint32_t ToUint32() const { return (static_cast<uint32_t>(mVendorId) << 16) | mProtocolId; }
61
62     chip::VendorId mVendorId;
63     uint16_t mProtocolId;
64 };
65
66 // Common Protocols
67 //
68 // NOTE: Do not attempt to allocate these values yourself.
69 #define CHIP_STANDARD_PROTOCOL(name, id)                                                                                           \
70     namespace name {                                                                                                               \
71     static constexpr Protocols::Id Id(VendorId::Common, id);                                                                       \
72     } // namespace name.
73
74 CHIP_STANDARD_PROTOCOL(SecureChannel, 0x0000)       // Secure Channel Protocol
75 CHIP_STANDARD_PROTOCOL(Echo, 0x0002)                // Echo Protocol
76 CHIP_STANDARD_PROTOCOL(BDX, 0x0003)                 // Bulk Data Exchange Protocol
77 CHIP_STANDARD_PROTOCOL(NetworkProvisioning, 0x0004) // Network Provisioning Protocol
78 CHIP_STANDARD_PROTOCOL(InteractionModel, 0x0005)    // Interaction Model Protocol
79 CHIP_STANDARD_PROTOCOL(FabricProvisioning, 0x0006)  // Fabric Provisioning Protocol
80 CHIP_STANDARD_PROTOCOL(ServiceProvisioning, 0x0007) // Service Provisioning Protocol
81 CHIP_STANDARD_PROTOCOL(OpCredentials, 0x0008)       // Operational Credentials
82
83 #undef CHIP_STANDARD_PROTOCOL
84
85 // Protocols reserved for internal protocol use
86 static constexpr Id NotSpecified(VendorId::NotSpecified, 0xFFFF); // The profile ID is either not specified or a wildcard
87
88 // Pre-delare our MessageTypeTraits so message type headers know what they are
89 // specializing.
90 template <typename T>
91 struct MessageTypeTraits;
92
93 } // namespace Protocols
94 } // namespace chip