3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2014-2017 Nest Labs, Inc.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <ble/BleConfig.h>
20 #if CONFIG_NETWORK_LAYER_BLE
31 const ChipBleUUID CHIP_BLE_SVC_ID = { { // 0000FEAF-0000-1000-8000-00805F9B34FB
32 0x00, 0x00, 0xFE, 0xAF, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34,
35 inline static uint8_t HexDigitToInt(const char c)
37 return static_cast<uint8_t>(c >= '0' && c <= '9' ? c - '0' : tolower(c) - 'a' + 10);
40 bool UUIDsMatch(const ChipBleUUID * idOne, const ChipBleUUID * idTwo)
42 if ((idOne == nullptr) || (idTwo == nullptr))
46 return (memcmp(idOne->bytes, idTwo->bytes, 16) == 0);
49 // Convert a string like "0000FEAF-0000-1000-8000-00805F9B34FB" to binary UUID
50 bool StringToUUID(const char * str, ChipBleUUID & uuid)
52 constexpr size_t NUM_UUID_NIBBLES = sizeof(uuid.bytes) * 2;
57 if (*str == '-') // skip separators
60 if (!isxdigit(*str)) // invalid character!
63 if (nibbleId >= NUM_UUID_NIBBLES) // too long string!
66 uint8_t & byte = uuid.bytes[nibbleId / 2];
67 if (nibbleId % 2 == 0)
68 byte = static_cast<uint8_t>(HexDigitToInt(*str) << 4);
70 byte = static_cast<uint8_t>(byte | HexDigitToInt(*str));
75 // All bytes were initialized?
76 return nibbleId == NUM_UUID_NIBBLES;
80 } /* namespace chip */
82 #endif /* CONFIG_NETWORK_LAYER_BLE */