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_CLIENT_H 17 #define SOCKET_SDP_CLIENT_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 SocketSdpClient { 32 public: 33 /** 34 * @brief Constructor. 35 */ 36 SocketSdpClient() = default; 37 38 /** 39 * @brief Destructor. 40 */ 41 virtual ~SocketSdpClient(); 42 43 /** 44 * @brief Finds a record of the SPP from the SDP. 45 * 46 * @param addr The address of the bluetooth device. 47 * @param uuid The uuid is used to search server channel number. 48 * @param context The context is used to send the event in the callback. 49 * @return BT_SUCCESS : The function is executed successfully. 50 */ 51 static int StartDiscovery(const std::string &addr, const Uuid &uuid, void *context); 52 53 /** 54 * @brief Callback of SDP discovery. 55 * 56 * @param addr The address of the bluetooth device. 57 * @param serviceAry The serviceAry is Array of services discovered. 58 * @param serviceNum The serviceNum is number of services discovered. 59 * @param context The context is used to send the event in the callback. 60 */ 61 static void SdpSearchCallback(const BtAddr *addr, const SdpService *serviceAry, 62 uint16_t serviceNum, void *context); 63 64 private: 65 BT_DISALLOW_COPY_AND_ASSIGN(SocketSdpClient); 66 67 /** 68 * @brief Search the attributes of serviceAry. 69 * 70 * @param addr The address of the bluetooth device. 71 * @param serviceAry The serviceAry is Array of services discovered. 72 * @param serviceNum The serviceNum is number of services discovered. 73 * @return uint8_t server channel number. 74 */ 75 static uint8_t SearchAttributes(const BtAddr *addr, const SdpService *serviceAry, uint16_t serviceNum); 76 77 /** 78 * @brief Search the server channel number. 79 * 80 * @param protocolNum Protocol descriptor number. 81 * @param protocol Protocol descriptor. 82 * @param scn server channel number. 83 * @return true Function executed successfully. 84 * @return false Function executed failed. 85 */ 86 static bool SearchScn(uint16_t protocolNum, const SdpProtocolDescriptor *protocol, uint8_t &scn); 87 88 static constexpr uint16_t SPP_CLASSID_NUM = 1; 89 static constexpr uint16_t SPP_ATTR_NUM = 3; 90 }; 91 } // namespace bluetooth 92 } // namespace OHOS 93 #endif // SOCKET_SDP_CLIENT_H