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_HF_SDP_SERVER_H
17 #define HFP_HF_SDP_SERVER_H
18 
19 #include <cstdint>
20 
21 #include "base/base_def.h"
22 #include "hfp_hf_defines.h"
23 #include "sdp.h"
24 
25 namespace OHOS {
26 namespace bluetooth {
27 /**
28  * @brief Class for managing SDP server register/unregister as HFP HF role.
29  */
30 class HfpHfSdpServer {
31 public:
32     /**
33      * @brief Get the Instance object.
34      *
35      * @return Returns HfpHfSdpServer instance.
36      */
37     static HfpHfSdpServer &GetInstance();
38 
39     /**
40      * @brief Create and register SDP service required by HFP HF role, including Service class id,
41      *        protocol, profile, service name, network, HF support features and browse group list.
42      *
43      * @param scn Server channel number.
44      * @return Returns error code of register sdp service result.
45      */
46     int RegisterSdpService(uint8_t scn);
47 
48     /**
49      * @brief Destroy and unregister the previously registered SDP service.
50      *
51      * @return Returns error code of deregister sdp service result.
52      */
53     int DeregisterSdpService();
54 
55 private:
56     /**
57      * @brief Construct a new HfpHfSdpServer object.
58      */
59     HfpHfSdpServer() = default;
60 
61     /**
62      * @brief Destroy the HfpHfSdpServer object.
63      */
64     ~HfpHfSdpServer() = default;
65 
66     /**
67      * @brief Add service class id info.
68      *
69      * @return Returns error code of the result.
70      */
71     int AddServiceClassId() const;
72 
73     /**
74      * @brief Add protocol info.
75      *
76      * @param scn Server channel number.
77      * @return Returns error code of the result.
78      */
79     int AddProtocol(uint8_t scn) const;
80 
81     /**
82      * @brief Add profile info.
83      *
84      * @return Returns error code of the result.
85      */
86     int AddProfile() const;
87 
88     /**
89      * @brief Add service name info.
90      *
91      * @return Returns error code of the result.
92      */
93     int AddServiceName() const;
94 
95     /**
96      * @brief Add local features.
97      *
98      * @return Returns error code of the result.
99      */
100     int AddFeatures() const;
101 
102     /**
103      * @brief Add browse group list info.
104      *
105      * @return Returns error code of the result.
106      */
107     int AddBrowseGroupList() const;
108 
109     /**
110      * @brief Add attribute info.
111      *
112      * @return Returns error code of the result.
113      */
114     int AddAttribute(SdpAttribute attribute) const;
115 
116     inline static constexpr uint16_t HFP_HF_SERVER_CLASSID_NUM = 2;
117     inline static constexpr uint16_t HFP_HF_HSP_SERVER_CLASSID_NUM = 3;
118     inline static constexpr uint16_t HFP_HF_SERVER_PROTOCOL_NUM = 2;
119     inline static constexpr uint16_t HFP_HF_SERVER_PROFILE_NUM = 1;
120     inline static constexpr uint16_t HFP_HF_HSP_SERVER_PROFILE_NUM = 2;
121     inline static constexpr uint16_t HFP_HF_SERVER_BROWSE_LIST_NUM = 1;
122     inline static constexpr uint16_t HFP_HF_SERVER_FEATURES_LENGTH = 2;
123 
124     // SDP service record handle
125     uint32_t sdpHandle_ {0};
126 
127     int hspState_ = 1;
128 
129     BT_DISALLOW_COPY_AND_ASSIGN(HfpHfSdpServer);
130 };
131 }  // namespace bluetooth
132 }  // namespace OHOS
133 #endif // HFP_HF_SDP_SERVER_H