1 /* 2 * Copyright (C) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HFP_AG_SDP_SERVER_H 17 #define HFP_AG_SDP_SERVER_H 18 19 #include <cstdint> 20 #include "base/base_def.h" 21 #include "sdp.h" 22 23 namespace OHOS { 24 namespace bluetooth { 25 /** 26 * @brief Class for managing SDP server register/unregister as HFP AG role. 27 */ 28 class HfpAgSdpServer { 29 public: 30 /** 31 * @brief Get the Instance object. 32 * 33 * @return Returns HfpAgSdpServer instance. 34 */ 35 static HfpAgSdpServer &GetInstance(); 36 37 /** 38 * @brief Create and register SDP service required by HFP Ag role, including Service class id, 39 * protocol, profile, service name, network, AG support features and browse group list. 40 * 41 * @param scn Server channel number. 42 * @return Returns error code of register sdp service result. 43 */ 44 int RegisterSdpService(uint8_t scn); 45 46 /** 47 * @brief Destroy and unregister the previously registered SDP service. 48 * 49 * @return Returns error code of deregister sdp service result. 50 */ 51 int DeregisterSdpService(); 52 53 private: 54 /** 55 * @brief Construct a new HfpAgSdpServer object. 56 */ 57 HfpAgSdpServer() = default; 58 59 /** 60 * @brief Destroy the HfpAgSdpServer object. 61 */ 62 ~HfpAgSdpServer() = default; 63 64 /** 65 * @brief Add service class id info. 66 * 67 * @return Returns error code of the result. 68 */ 69 int AddServiceClassId() const; 70 71 /** 72 * @brief Add protocol info. 73 * 74 * @param scn Server channel number. 75 * @return Returns error code of the result. 76 */ 77 int AddProtocol(uint8_t scn) const; 78 79 /** 80 * @brief Add profile info. 81 * 82 * @return Returns error code of the result. 83 */ 84 int AddProfile() const; 85 86 /** 87 * @brief Add service name info. 88 * 89 * @return Returns error code of the result. 90 */ 91 int AddServiceName() const; 92 93 /** 94 * @brief Add network info. 95 * 96 * @return Returns error code of the result. 97 */ 98 int AddNetwork() const; 99 100 /** 101 * @brief Add local features. 102 * 103 * @return Returns error code of the result. 104 */ 105 int AddFeatures() const; 106 107 /** 108 * @brief Add browse group list info. 109 * 110 * @return Returns error code of the result. 111 */ 112 int AddBrowseGroupList() const; 113 114 /** 115 * @brief Add attribute info. 116 * 117 * @return Returns error code of the result. 118 */ 119 int AddAttribute(const SdpAttribute &attribute) const; 120 121 inline static constexpr uint16_t HFP_AG_SERVER_CLASSID_NUM = 2; 122 inline static constexpr uint16_t HFP_AG_HSP_SERVER_CLASSID_NUM = 3; 123 inline static constexpr uint16_t HFP_AG_SERVER_PROTOCOL_NUM = 2; 124 inline static constexpr uint16_t HFP_AG_SERVER_PROFILE_NUM = 1; 125 inline static constexpr uint16_t HFP_AG_HSP_SERVER_PROFILE_NUM = 2; 126 inline static constexpr uint16_t HFP_AG_SERVER_BROWSE_LIST_NUM = 1; 127 inline static constexpr uint16_t HFP_AG_SERVER_NETWORK_LENGTH = 1; 128 inline static constexpr uint16_t HFP_AG_SERVER_FEATURES_LENGTH = 2; 129 inline static constexpr uint16_t HSP_AG_SERVER_CLASSID_NUM = 2; 130 131 // SDP service record handle 132 uint32_t sdpHandle_ {0}; 133 134 int hspState_ = 1; 135 136 BT_DISALLOW_COPY_AND_ASSIGN(HfpAgSdpServer); 137 }; 138 } // namespace bluetooth 139 } // namespace OHOS 140 #endif // HFP_AG_SDP_SERVER_H