| Chris Manton | e0746b1 | 2023-05-14 18:31:47 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright 1999-2012 Broadcom Corporation |
| 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 | #pragma once |
| 20 | |
| Henri Chataing | 7bf239a | 2024-02-07 00:21:34 +0000 | [diff] [blame] | 21 | #include <bluetooth/log.h> |
| Chris Manton | e0746b1 | 2023-05-14 18:31:47 -0700 | [diff] [blame] | 22 | |
| 23 | #include <cstdint> |
| 24 | |
| Hui Peng | 4b5f1bc | 2023-12-03 06:24:36 +0000 | [diff] [blame] | 25 | #include "macros.h" |
| 26 | |
| Chris Manton | e0746b1 | 2023-05-14 18:31:47 -0700 | [diff] [blame] | 27 | /***************************************************************************** |
| 28 | * Constants |
| 29 | ****************************************************************************/ |
| 30 | |
| 31 | /* Success code and error codes */ |
| Chris Manton | d28b52e | 2024-07-12 18:04:44 -0700 | [diff] [blame] | 32 | enum class tSDP_STATUS : uint16_t { |
| Chris Manton | e0746b1 | 2023-05-14 18:31:47 -0700 | [diff] [blame] | 33 | SDP_SUCCESS = 0x0000, |
| 34 | SDP_INVALID_VERSION = 0x0001, |
| 35 | SDP_INVALID_SERV_REC_HDL = 0x0002, |
| 36 | SDP_INVALID_REQ_SYNTAX = 0x0003, |
| 37 | SDP_INVALID_PDU_SIZE = 0x0004, |
| 38 | SDP_INVALID_CONT_STATE = 0x0005, |
| 39 | SDP_NO_RESOURCES = 0x0006, |
| 40 | SDP_DI_REG_FAILED = 0x0007, |
| 41 | SDP_DI_DISC_FAILED = 0x0008, |
| 42 | SDP_NO_DI_RECORD_FOUND = 0x0009, |
| 43 | SDP_ERR_ATTR_NOT_PRESENT = 0x000A, |
| 44 | SDP_ILLEGAL_PARAMETER = 0x000B, |
| 45 | |
| Chris Manton | d28b52e | 2024-07-12 18:04:44 -0700 | [diff] [blame] | 46 | HID_SDP_NO_SERV_UUID = (tSDP_STATUS::SDP_ILLEGAL_PARAMETER + 1), |
| Chris Manton | e0746b1 | 2023-05-14 18:31:47 -0700 | [diff] [blame] | 47 | HID_SDP_MANDATORY_MISSING, |
| 48 | |
| 49 | SDP_NO_RECS_MATCH = 0xFFF0, |
| 50 | SDP_CONN_FAILED = 0xFFF1, |
| 51 | SDP_CFG_FAILED = 0xFFF2, |
| 52 | SDP_GENERIC_ERROR = 0xFFF3, |
| 53 | SDP_DB_FULL = 0xFFF4, |
| 54 | SDP_CANCEL = 0xFFF8, |
| Chris Manton | d28b52e | 2024-07-12 18:04:44 -0700 | [diff] [blame] | 55 | }; |
| Chris Manton | e0746b1 | 2023-05-14 18:31:47 -0700 | [diff] [blame] | 56 | using tSDP_RESULT = tSDP_STATUS; |
| 57 | using tSDP_REASON = tSDP_STATUS; |
| 58 | |
| Chris Manton | e0746b1 | 2023-05-14 18:31:47 -0700 | [diff] [blame] | 59 | inline std::string sdp_status_text(const tSDP_STATUS& status) { |
| 60 | switch (status) { |
| Chris Manton | d28b52e | 2024-07-12 18:04:44 -0700 | [diff] [blame] | 61 | CASE_RETURN_TEXT(tSDP_STATUS::SDP_SUCCESS); |
| 62 | CASE_RETURN_TEXT(tSDP_STATUS::SDP_INVALID_VERSION); |
| 63 | CASE_RETURN_TEXT(tSDP_STATUS::SDP_INVALID_SERV_REC_HDL); |
| 64 | CASE_RETURN_TEXT(tSDP_STATUS::SDP_INVALID_REQ_SYNTAX); |
| 65 | CASE_RETURN_TEXT(tSDP_STATUS::SDP_INVALID_PDU_SIZE); |
| 66 | CASE_RETURN_TEXT(tSDP_STATUS::SDP_INVALID_CONT_STATE); |
| 67 | CASE_RETURN_TEXT(tSDP_STATUS::SDP_NO_RESOURCES); |
| 68 | CASE_RETURN_TEXT(tSDP_STATUS::SDP_DI_REG_FAILED); |
| 69 | CASE_RETURN_TEXT(tSDP_STATUS::SDP_DI_DISC_FAILED); |
| 70 | CASE_RETURN_TEXT(tSDP_STATUS::SDP_NO_DI_RECORD_FOUND); |
| 71 | CASE_RETURN_TEXT(tSDP_STATUS::SDP_ERR_ATTR_NOT_PRESENT); |
| 72 | CASE_RETURN_TEXT(tSDP_STATUS::SDP_ILLEGAL_PARAMETER); |
| Chris Manton | e0746b1 | 2023-05-14 18:31:47 -0700 | [diff] [blame] | 73 | |
| Chris Manton | d28b52e | 2024-07-12 18:04:44 -0700 | [diff] [blame] | 74 | CASE_RETURN_TEXT(tSDP_STATUS::HID_SDP_NO_SERV_UUID); |
| 75 | CASE_RETURN_TEXT(tSDP_STATUS::HID_SDP_MANDATORY_MISSING); |
| Chris Manton | e0746b1 | 2023-05-14 18:31:47 -0700 | [diff] [blame] | 76 | |
| Chris Manton | d28b52e | 2024-07-12 18:04:44 -0700 | [diff] [blame] | 77 | CASE_RETURN_TEXT(tSDP_STATUS::SDP_NO_RECS_MATCH); |
| 78 | CASE_RETURN_TEXT(tSDP_STATUS::SDP_CONN_FAILED); |
| 79 | CASE_RETURN_TEXT(tSDP_STATUS::SDP_CFG_FAILED); |
| 80 | CASE_RETURN_TEXT(tSDP_STATUS::SDP_GENERIC_ERROR); |
| 81 | CASE_RETURN_TEXT(tSDP_STATUS::SDP_DB_FULL); |
| 82 | CASE_RETURN_TEXT(tSDP_STATUS::SDP_CANCEL); |
| Chris Manton | e0746b1 | 2023-05-14 18:31:47 -0700 | [diff] [blame] | 83 | default: |
| Henri Chataing | 833941b | 2024-12-11 17:37:39 -0800 | [diff] [blame] | 84 | return std::format("UNKNOWN[{}]", static_cast<uint16_t>(status)); |
| Chris Manton | e0746b1 | 2023-05-14 18:31:47 -0700 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | const auto sdp_result_text = sdp_status_text; |
| Henri Chataing | 7bf239a | 2024-02-07 00:21:34 +0000 | [diff] [blame] | 88 | |
| Henri Chataing | b052e58 | 2024-11-13 01:18:45 +0000 | [diff] [blame] | 89 | namespace std { |
| Henri Chataing | 7bf239a | 2024-02-07 00:21:34 +0000 | [diff] [blame] | 90 | template <> |
| 91 | struct formatter<tSDP_STATUS> : enum_formatter<tSDP_STATUS> {}; |
| Henri Chataing | b052e58 | 2024-11-13 01:18:45 +0000 | [diff] [blame] | 92 | } // namespace std |