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 SOCKET_SDP_SERVER_H
17 #define SOCKET_SDP_SERVER_H
18 
19 #include <stdint.h>
20 #include <string>
21 #include "base_def.h"
22 #include "bt_uuid.h"
23 #include "sdp.h"
24 
25 namespace OHOS {
26 namespace bluetooth {
27 /**
28  * @brief This class provides a set of methods used to interact with the SDP protocol.
29  * @see SDP Service Records for Serial Port Profile. Table 6.1.
30  */
31 class SocketSdpServer {
32 public:
33     /**
34      * @brief Constructor.
35      */
36     SocketSdpServer() = default;
37 
38     /**
39      * @brief Destructor.
40      */
41     virtual ~SocketSdpServer() = default;
42 
43     /**
44      * @brief Registers a record of the SPP into the SDP.
45      *
46      * @param name service name.
47      * @param uuid server uuid.
48      * @param scn server channel number.
49      * @return int
50      */
51     int RegisterSdpService(const std::string &name, const Uuid &uuid, uint8_t scn);
52 
53     /**
54      * @brief Unregisters a record of the SPP from the SDP.
55      *
56      * @return int
57      */
58     int UnregisterSdpService();
59 
60 private:
61     BT_DISALLOW_COPY_AND_ASSIGN(SocketSdpServer);
62 
63     /**
64      * @brief Add service class id info.
65      * @details Add service class id info to the previously created SDP service record.
66      * @return int
67      */
68     int AddServiceClassId(const Uuid &uuid);
69 
70     /**
71      * @brief Add protocol info.
72      * @details Add protocol info to the previously created SDP service record.
73      * @param scn Server channel number
74      * @return int
75      */
76     int AddProtocol(uint8_t scn);
77 
78     /**
79      * @brief Add profile info.
80      * @details Add profile info to the previously created SDP service record.
81      * @return int
82      */
83     int AddProfile();
84 
85     /**
86      * @brief Add service name info.
87      * @details Add service name info to the previously created SDP service record.
88      * @return int
89      */
90     int AddServiceName(const std::string &name);
91 
92     /**
93      * @brief Add browse group list info.
94      * @details Add browse group list info to the previously created SDP service record.
95      * @return int
96      */
97     int AddBrowseGroupList();
98 
99     // SDP service record handle
100     uint32_t sdpHandle_ {0};
101     inline static constexpr uint16_t SPP_CLASSID_NUM = 1;
102     inline static constexpr uint16_t SPP_PRRTOCOL_NUM = 2;
103     inline static constexpr uint16_t SPP_PROFILE_NUM = 1;
104     inline static constexpr uint16_t SPP_BROWSE_LIST_NUM = 1;
105 };
106 }  // namespace bluetooth
107 }  // namespace OHOS
108 #endif  // SOCKET_SDP_SERVER_H