From a202d83c097fda9f2203246b516dd8df00b92288 Mon Sep 17 00:00:00 2001
From: dengguanghong <2228266166@qq.com>
Date: Mon, 11 Nov 2024 15:52:31 +0800
Subject: [PATCH 1/4] Signed-off-by:dengguanghong <2228266166@qq.com>
---
.../service/src/avrcp_ct/avrcp_ct_profile.cpp | 21 +++-------
.../service/src/avrcp_ct/avrcp_ct_sdp.cpp | 21 +++++++---
.../service/src/avrcp_ct/avrcp_ct_sdp.h | 4 +-
.../service/src/avrcp_ct/avrcp_ct_service.cpp | 39 ++++++++++++++++---
.../service/src/avrcp_ct/avrcp_ct_service.h | 22 ++++++++---
5 files changed, 73 insertions(+), 34 deletions(-)
diff --git a/services/bluetooth/service/src/avrcp_ct/avrcp_ct_profile.cpp b/services/bluetooth/service/src/avrcp_ct/avrcp_ct_profile.cpp
index 70793617..e57bb901 100644
--- a/services/bluetooth/service/src/avrcp_ct/avrcp_ct_profile.cpp
+++ b/services/bluetooth/service/src/avrcp_ct/avrcp_ct_profile.cpp
@@ -91,23 +91,12 @@ int AvrcCtProfile::Enable(bool isTgEnabled)
int result = BT_SUCCESS;
SetEnableFlag(true);
-
- if (!isTgEnabled) {
- /// If the following statement in the debt_config.xml. That means that TG allows to enable. CT do not
- /// allow the passive connection. Because if CT and TG are registered passive connections, it will case that the
- /// inability to distinguish between the end device
- /// "true"
- AVCT_Register(controlMtu_, browseMtu_, AVCT_CT);
-
- AvctConnectParam param = {eventCallback_, msgCallback_, AVRC_CT_AV_REMOTE_CONTROL, AVCT_ACPT, nullptr};
- BtAddr btAddr = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0x00};
- if (AVCT_ConnectReq(&connectId_, ¶m, &btAddr) != AVCT_SUCCESS) {
- result = RET_BAD_STATUS;
- }
- } else {
- /// CT is only allowed the active connection.
+ AVCT_Register(controlMtu_, browseMtu_, AVCT_CT);
+ AvctConnectParam param = {eventCallback_, msgCallback_, AVRC_CT_AV_REMOTE_CONTROL, AVCT_ACPT, nullptr};
+ BtAddr btAddr = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0x00};
+ if (AVCT_ConnectReq(&connectId_, ¶m, &btAddr) != AVCT_SUCCESS) {
+ result = RET_BAD_STATUS;
}
-
return result;
}
diff --git a/services/bluetooth/service/src/avrcp_ct/avrcp_ct_sdp.cpp b/services/bluetooth/service/src/avrcp_ct/avrcp_ct_sdp.cpp
index 76136876..0872e3b6 100644
--- a/services/bluetooth/service/src/avrcp_ct/avrcp_ct_sdp.cpp
+++ b/services/bluetooth/service/src/avrcp_ct/avrcp_ct_sdp.cpp
@@ -114,19 +114,30 @@ int AvrcCtSdpManager::UnregisterService(void) const
}
int AvrcCtSdpManager::FindTgService(const RawAddress &rawAddr,
- void (*callback)(const BtAddr *btAddr, const uint32_t *handleArray, uint16_t handleNum, void *context))
+ void (*callback)(const BtAddr *btAddr, const SdpService *serviceArray, uint16_t serviceNum, void *context))
{
HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
BtAddr btAddr;
rawAddr.ConvertToUint8(btAddr.addr);
- BtUuid classIdList[AVRC_SERVICE_CLASS_ID_LIST_NUMBER - 1];
+ BtUuid classIdList[AVRC_SERVICE_CLASS_ID_LIST_NUMBER];
classIdList[0].type = BT_UUID_16;
- classIdList[0].uuid16 = AVRC_CT_AV_REMOTE_CONTROL_TARGET;
- SdpUuid sdpUuid = {.uuidNum = AVRC_SERVICE_CLASS_ID_LIST_NUMBER - 1, .uuid = classIdList};
+ classIdList[0].uuid16 = AVRC_CT_AV_REMOTE_CONTROL;
+ SdpUuid sdpUuid = {
+ .uuidNum = AVRC_SERVICE_CLASS_ID_LIST_NUMBER,
+ .uuid = classIdList
+ };
+
+ SdpAttributeIdList attributeIdList;
+ attributeIdList.type = SDP_TYPE_LIST;
+
+ attributeIdList.attributeIdList.attributeIdNumber = AVRC_SDP_ATTRIBUTE_NUM;
+ attributeIdList.attributeIdList.attributeId[0] = SDP_ATTRIBUTE_SERVICE_CLASS_ID_LIST;
+ attributeIdList.attributeIdList.attributeId[1] = SDP_ATTRIBUTE_BLUETOOTH_PROFILE_DESCRIPTOR_LIST;
+ attributeIdList.attributeIdList.attributeId[2] = AVRC_CT_ATTRIBUTE_ID_SUPPORTED_FEATURES;
- int result = SDP_ServiceSearch(&btAddr, &sdpUuid, nullptr, callback);
+ int result = SDP_ServiceSearchAttribute(&btAddr, &sdpUuid, attributeIdList, nullptr, callback);
(result == BT_SUCCESS) ? (result = BT_SUCCESS) : (result = RET_BAD_STATUS);
return result;
diff --git a/services/bluetooth/service/src/avrcp_ct/avrcp_ct_sdp.h b/services/bluetooth/service/src/avrcp_ct/avrcp_ct_sdp.h
index fc6b1f71..9ba85c10 100644
--- a/services/bluetooth/service/src/avrcp_ct/avrcp_ct_sdp.h
+++ b/services/bluetooth/service/src/avrcp_ct/avrcp_ct_sdp.h
@@ -17,6 +17,8 @@
#define AVRCP_CT_SDP_H
#include "avrcp_ct_internal.h"
+#include "sdp.h"
+#define AVRC_SDP_ATTRIBUTE_NUM 3
namespace OHOS {
namespace bluetooth {
@@ -71,7 +73,7 @@ public:
* @retval RET_BAD_STATUS Execute failure.
*/
static int FindTgService(const RawAddress &rawAddr,
- void (*callback)(const BtAddr *btAddr, const uint32_t *handleArray, uint16_t handleNum, void *context));
+ void (*callback)(const BtAddr *btAddr, const SdpService *serviceArray, uint16_t serviceNum, void *context));
private:
uint32_t sdpHandle_; // The handle got from the SDP.
diff --git a/services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.cpp b/services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.cpp
index 2b586c0a..261c144a 100644
--- a/services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.cpp
+++ b/services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.cpp
@@ -211,7 +211,7 @@ int AvrcpCtService::EnableProfile(void)
config->GetValue(SECTION_AVRCP_CT_SERVICE, PROPERTY_BROWSE_MTU, browseMtu);
config->GetValue(SECTION_CLASSIC_ADAPTER, PROPERTY_AVRCP_TG_SERVICE, isTgEnabled);
- profile_ = std::make_unique(features_,
+ profile_ = std::make_unique(features_ & AVRC_CT_SDP_ALL_SUPPORTED_FEATURES,
AVRC_CT_DEFAULT_BLUETOOTH_SIG_COMPANY_ID,
controlMtu,
browseMtu,
@@ -487,6 +487,29 @@ void AvrcpCtService::RejectActiveConnect(const RawAddress &rawAddr) const
HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
}
+// Parse AVRCP SDP Information
+// supports browsing || supports advanced control
+void AvrcpCtService::ParseSDPInformation(
+ const BtAddr *btAddr, const SdpService *serviceArray, uint16_t serviceNum)
+{
+ HILOGI("serviceNum(%{public}d)\n", serviceNum);
+
+ uint16_t peerFeatures = 0;
+ uint16_t peerAvrcpVersion = 0;
+
+ for (int i = 0; i < serviceNum; i++) {
+ HILOGI("uuid16: %{public}4x\n", serviceArray[i].classId->uuid16);
+ if (serviceArray[i].classId->uuid16 == AVRC_CT_AV_REMOTE_CONTROL_TARGET) {
+ peerAvrcpVersion = serviceArray[i].profileDescriptor->versionNumber;
+ HILOGI("peerAvrcpVersion: %{public}x\n", peerAvrcpVersion);
+ if(peerAvrcpVersion >= AVCT_REV_1_4) {
+ peerFeatures = *(uint16_t*)serviceArray[i].attribute[0].attributeValue;
+ HILOGI("peerFeatures: %{public}x\n", peerFeatures);
+ }
+ }
+ }
+}
+
int AvrcpCtService::FindTgService(const RawAddress &rawAddr) const
{
HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
@@ -495,17 +518,19 @@ int AvrcpCtService::FindTgService(const RawAddress &rawAddr) const
}
void AvrcpCtService::FindTgServiceCallback(
- const BtAddr *btAddr, const uint32_t *handleArray, uint16_t handleCount, void *context)
+ const BtAddr *btAddr, const SdpService *serviceArray, uint16_t serviceNum, void *context)
{
- HILOGI("handleCount: %{public}d", handleCount);
+ HILOGI("serviceNum: %{public}d", serviceNum);
auto servManager = IProfileManager::GetInstance();
auto service = static_cast(servManager->GetProfileService(PROFILE_NAME_AVRCP_CT));
RawAddress rawAddr(RawAddress::ConvertToString(btAddr->addr));
if (service != nullptr) {
- if (handleCount > 0) {
+ if (serviceNum > 0) {
+ ParseSDPInformation(btAddr, serviceArray, serviceNum);
service->GetDispatcher()->PostTask(std::bind(&AvrcpCtService::AcceptActiveConnect, service, rawAddr));
- } else {
+ }
+ else {
service->GetDispatcher()->PostTask(std::bind(&AvrcpCtService::RejectActiveConnect, service, rawAddr));
}
}
@@ -2211,7 +2236,9 @@ void AvrcpCtService::ChannelMessageCallback(
{
HILOGI("connectId: %{public}d, label: %{public}d, crType: %{public}d, chType: %{public}d",
connectId, label, crType, chType);
-
+ if (!crType) {
+ return;
+ }
auto servManager = IProfileManager::GetInstance();
auto service = static_cast(servManager->GetProfileService(PROFILE_NAME_AVRCP_CT));
auto myPkt = PacketRefMalloc(pkt);
diff --git a/services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.h b/services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.h
index 3cf23b51..f9898f0c 100644
--- a/services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.h
+++ b/services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.h
@@ -610,7 +610,7 @@ private:
/// The flag is used to indicate that the state of the AVRCP CT service.
std::atomic_uint8_t state_ {AVRC_CT_SERVICE_STATE_DISABLED};
/// The features supported by the AVRCP CT service.
- uint16_t features_ {AVRC_CT_FEATURE_INVALID_FEATURE};
+ uint32_t features_ {AVRC_CT_FEATURE_INVALID_FEATURE};
/// The observer registered by the AVRCP CT framework.
/// @see AvrcCtProfile::Observer
@@ -770,13 +770,23 @@ private:
/**
* @brief The callback function that receives the search result return from the SDP.
*
- * @param[in] btAddr The address of the peer Bluetooth device.
- * @param[in] handleArray The list of handle to a qualifying service.
- * @param[in] handleCount The number of handle to a qualifying service.
- * @param[in] context The context is used to send the event in the callback.
+ * @param[in] btAddr The address of the peer Bluetooth device.
+ * @param[in] serviceArray The list of serviceArray to a qualifying service.
+ * @param[in] serviceNum The number of serviceArray to a qualifying service.
+ * @param[in] context The context is used to send the event in the callback.
*/
static void FindTgServiceCallback(
- const BtAddr *btAddr, const uint32_t *handleArray, uint16_t handleCount, void *context);
+ const BtAddr *btAddr, const SdpService *serviceArray, uint16_t serviceNum, void *context);
+
+ // parse SDP_SERVICE_SEARCH_ATTR_RSP
+ /**
+ * @brief The parse function, which parse SDP search result.
+ *
+ * @param[in] btAddr The address of the peer Bluetooth device.
+ * @param[in] serviceArray The list of handle to a qualifying service.
+ * @param[in] serviceNum The number of handle to a qualifying service.
+ */
+ static void ParseSDPInformation(const BtAddr *btAddr, const SdpService *serviceArray, uint16_t serviceNum);
/******************************************************************
* BUTTON OPERATION *
--
Gitee
From b444923f0ea0db563810fb95930a33e85b09b568 Mon Sep 17 00:00:00 2001
From: dengguanghong <2228266166@qq.com>
Date: Fri, 22 Nov 2024 02:22:17 +0000
Subject: [PATCH 2/4] update
services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.cpp.
Signed-off-by: dengguanghong <2228266166@qq.com>
---
services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.cpp | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.cpp b/services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.cpp
index 261c144a..f9669e5d 100644
--- a/services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.cpp
+++ b/services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.cpp
@@ -502,7 +502,7 @@ void AvrcpCtService::ParseSDPInformation(
if (serviceArray[i].classId->uuid16 == AVRC_CT_AV_REMOTE_CONTROL_TARGET) {
peerAvrcpVersion = serviceArray[i].profileDescriptor->versionNumber;
HILOGI("peerAvrcpVersion: %{public}x\n", peerAvrcpVersion);
- if(peerAvrcpVersion >= AVCT_REV_1_4) {
+ if (peerAvrcpVersion >= AVCT_REV_1_4) {
peerFeatures = *(uint16_t*)serviceArray[i].attribute[0].attributeValue;
HILOGI("peerFeatures: %{public}x\n", peerFeatures);
}
@@ -529,8 +529,7 @@ void AvrcpCtService::FindTgServiceCallback(
if (serviceNum > 0) {
ParseSDPInformation(btAddr, serviceArray, serviceNum);
service->GetDispatcher()->PostTask(std::bind(&AvrcpCtService::AcceptActiveConnect, service, rawAddr));
- }
- else {
+ } else {
service->GetDispatcher()->PostTask(std::bind(&AvrcpCtService::RejectActiveConnect, service, rawAddr));
}
}
--
Gitee
From 65b346f88052ab71fda92af9c94c5d44e67ed79e Mon Sep 17 00:00:00 2001
From: dengguanghong <2228266166@qq.com>
Date: Mon, 9 Dec 2024 08:17:58 +0000
Subject: [PATCH 3/4] update
services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.cpp.
Signed-off-by: dengguanghong <2228266166@qq.com>
---
services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.cpp b/services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.cpp
index f9669e5d..ae861964 100644
--- a/services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.cpp
+++ b/services/bluetooth/service/src/avrcp_ct/avrcp_ct_service.cpp
@@ -518,7 +518,7 @@ int AvrcpCtService::FindTgService(const RawAddress &rawAddr) const
}
void AvrcpCtService::FindTgServiceCallback(
- const BtAddr *btAddr, const SdpService *serviceArray, uint16_t serviceNum, void *context)
+ const BtAddr *btAddr, const SdpService *serviceArray, uint16_t serviceNum, void *context)
{
HILOGI("serviceNum: %{public}d", serviceNum);
--
Gitee
From 91d27ccab004da8abf3e920b07480a241e405d0f Mon Sep 17 00:00:00 2001
From: dengguanghong <2228266166@qq.com>
Date: Mon, 9 Dec 2024 08:29:49 +0000
Subject: [PATCH 4/4] update
services/bluetooth/service/src/avrcp_ct/avrcp_ct_sdp.cpp.
Signed-off-by: dengguanghong <2228266166@qq.com>
---
services/bluetooth/service/src/avrcp_ct/avrcp_ct_sdp.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/services/bluetooth/service/src/avrcp_ct/avrcp_ct_sdp.cpp b/services/bluetooth/service/src/avrcp_ct/avrcp_ct_sdp.cpp
index 0872e3b6..2de031a3 100644
--- a/services/bluetooth/service/src/avrcp_ct/avrcp_ct_sdp.cpp
+++ b/services/bluetooth/service/src/avrcp_ct/avrcp_ct_sdp.cpp
@@ -18,6 +18,8 @@
namespace OHOS {
namespace bluetooth {
+const int ATTR_NUMBER2 = 2;
+const int ATTR_NUMBER1 = 1;
/// Number of items when add service class id list.
const uint16_t AVRC_SERVICE_CLASS_ID_LIST_NUMBER = 0x0002;
/// Number of items when add protocol descriptor.
@@ -134,8 +136,8 @@ int AvrcCtSdpManager::FindTgService(const RawAddress &rawAddr,
attributeIdList.attributeIdList.attributeIdNumber = AVRC_SDP_ATTRIBUTE_NUM;
attributeIdList.attributeIdList.attributeId[0] = SDP_ATTRIBUTE_SERVICE_CLASS_ID_LIST;
- attributeIdList.attributeIdList.attributeId[1] = SDP_ATTRIBUTE_BLUETOOTH_PROFILE_DESCRIPTOR_LIST;
- attributeIdList.attributeIdList.attributeId[2] = AVRC_CT_ATTRIBUTE_ID_SUPPORTED_FEATURES;
+ attributeIdList.attributeIdList.attributeId[ATTR_NUMBER1] = SDP_ATTRIBUTE_BLUETOOTH_PROFILE_DESCRIPTOR_LIST;
+ attributeIdList.attributeIdList.attributeId[ATTR_NUMBER2] = AVRC_CT_ATTRIBUTE_ID_SUPPORTED_FEATURES;
int result = SDP_ServiceSearchAttribute(&btAddr, &sdpUuid, attributeIdList, nullptr, callback);
(result == BT_SUCCESS) ? (result = BT_SUCCESS) : (result = RET_BAD_STATUS);
--
Gitee