Module Bluetooth USB de débogage RK3588 Android12

1. Architecture Bluetooth

  Android4.2 之后采用 bluedroid 作为协议;整体由 bluetooth.apk,bluedroid ,libbt-vendor 三个 部 分 组 成 。
  • bluetooth.apk : en tant que processus de service Bluetooth, obtenez l'interface de contrôle bt_interface_t fournie par bluetooth*.default.so via la couche libblueooth_jni et enregistrez l'état et le rappel des données sur bluetooth*.default.so ; complétez le contrôle et la réception des données du Module Bluetooth ;
  • libbluetooth : Principalement l'implémentation spécifique de la pile de protocole Bluetooth de bluedroid.Il appelle l'interface libbt-hci vers le bas pour charger **libbt-vendor; ** vers le haut fournit le rappel de libblueooth_jni;
  • **libbt-vendor * Complète l'initialisation matérielle et le contrôle du module Bluetooth (initialisation de l'interface de communication physique, téléchargement du firmware, contrôle de l'alimentation).La plateforme RK détermine le type de module wifi+Bt et sélectionne et charge différents protocoles du fabricant de l'adaptateur. piles au niveau de la couche libbuetooth_jni ; et Dans libbt-hci, chargez libbt-vendor .so de modules de différents fabricants en fonction du type de module pour compléter le module d'adaptation dynamique.

Diagramme du cadre Bluetooth Android.png
La plateforme RK détermine le type du module et sélectionne et charge les piles de protocoles de différents fabricants d'adaptateurs dans la couche libbuetooth_jni ; et charge libbt-vendor*.so de modules de différents fabricants dans libbt-hci en fonction du type de module pour compléter la dynamique. module d'adaptation.

2. Débogage du module USB Bluetooth

L'option ici est un adaptateur USB Bluetooth du RTL8723DU. Ce qui suit examinera le processus d'adaptation étape par étape en commençant par le noyau ;

Partie noyau 2.1

Tout d'abord, copiez les fichiers du pilote Bluetooth rtk_btusb.h et rtk_btusb.c fournis par Realtek dans le répertoire drivers/bluetooth/ du noyau :

kernel-5.10/drivers/bluetooth/rtk_btusb.c
kernel-5.10/drivers/bluetooth/rtk_btusb.h

Modifiez les fichiers "Kconfig" et "Makefile" dans le répertoire drivers/bluetooth/ du noyau.

config BT_RTKBTUSB
    tristate "RTK HCI USB driver"
    depends on USB
    help
       RTK Bluetooth HCI USB driver
obj-$(CONFIG_BT_RTKBTUSB)	+= rtk_btusb.o

Ajoutez les définitions de macro supportées par Realtek BT ​​​​Chip au fichier defconfig correspondant à la plateforme. Voici le fichier dten_ribeye_me_pro.config.

diff --git a/kernel-5.10/arch/arm64/configs/dten_ribeye_me_pro.config b/kernel-5.10/arch/arm64/configs/dten_ribeye_me_pro.config
index 54246f39..6894e782 100755
--- a/kernel-5.10/arch/arm64/configs/dten_ribeye_me_pro.config
+++ b/kernel-5.10/arch/arm64/configs/dten_ribeye_me_pro.config
@@ -34,3 +34,5 @@ CONFIG_RTC_DRV_AT8563=y
 #DTEN Codec AD82088
 CONFIG_SND_SOC_AD82088=y
 CONFIG_BACKLIGHT_PWM=n
+# Add for usb bluetooth adapter
+CONFIG_BT_RTKBTUSB=y

2.2 Ajouter des nœuds de périphérique et des autorisations

Répertoire device/rockchip/common : ajoutez des autorisations de nœud et des commutateurs de macro
dans le fichier device/rockchip/common/init.connectivity.rc (le code général de la plate-forme rk a été ajouté) :

cfliu@sw-eng:RKOverlay$ gd device/rockchip/common/init.connectivity.rc
diff --git a/device/rockchip/common/init.connectivity.rc b/device/rockchip/common/init.connectivity.rc
index 82603ec0..db2e7176 100755
--- a/device/rockchip/common/init.connectivity.rc
+++ b/device/rockchip/common/init.connectivity.rc
@@ -8,6 +8,8 @@ on zygote-start
     chown bluetooth net_bt /proc/bluetooth/sleep/lpm
     chown bluetooth net_bt /proc/bluetooth/sleep/btwrite    
 
+    # USB device
+    insmod /system/lib/modules/rtk_btusb.ko
     chmod 0660 /dev/rtk_btusb
     chown bluetooth net_bt /dev/rtk_btusb
     chmod 0660 /dev/rtkbt_dev

Dans le fichier device/rockchip/common/wifi_bt_common.mk (le code général de la plate-forme rk a été ajouté), cela désactive d'abord la puce BCM pour éviter l'impact du BCM.

diff --git a/device/rockchip/common/wifi_bt_common.mk b/device/rockchip/common/wifi_bt_common.mk
index 23149e85..af3c7017 100644
--- a/device/rockchip/common/wifi_bt_common.mk
+++ b/device/rockchip/common/wifi_bt_common.mk
@@ -53,7 +53,7 @@ WIFI_DRIVER_FW_PATH_STA     := "/vendor/etc/firmware/fw_bcm4329.bin"
 WIFI_DRIVER_FW_PATH_P2P     := "/vendor/etc/firmware/fw_bcm4329_p2p.bin"
 WIFI_DRIVER_FW_PATH_AP      := "/vendor/etc/firmware/fw_bcm4329_apsta.bin"
 BOARD_HAVE_BLUETOOTH := true
-BOARD_HAVE_BLUETOOTH_BCM := true
+BOARD_HAVE_BLUETOOTH_BCM := false
 BOARD_HAVE_BLUETOOTH_RTK := true
 BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR ?= device/rockchip/$(TARGET_BOARD_PLATFORM)/bluetooth
 endif

2.3 Configuration de libbt-vendor.so

Dans le répertoire hardware/realtek : couche HAL, ajoutez le code de la pile de protocole Bluetooth et le code source correspondant de libbt-vendor.so. libbt-vendor termine l'initialisation matérielle et le contrôle du module Bluetooth (initialisation de l'interface de communication physique, firmware téléchargement, contrôle de l'alimentation)

@sw-eng:RK3588S$ cd hardware/realtek/rtkbt/vendor/firmware
@sw-eng:firmware$ 
@sw-eng:firmware$ ls
BT_Firmware.mk        rtl8723a_fw              rtl8723c_fw          rtl8723f_config     rtl8761at_config        rtl8761cs_fw      rtl8822bs_config
fw_info.txt           rtl8723as_config         rtl8723cs_cg_config  rtl8723f_fw         rtl8761at_fw            rtl8821a_config   rtl8822bs_fw
readme.txt            rtl8723as_fw             rtl8723cs_cg_fw      rtl8723fs_config    rtl8761au8192ee_fw      rtl8821a_fw       rtl8822c_config
rtl8703as_config      rtl8723b_config          rtl8723cs_vf_config  rtl8723fs_fw        rtl8761au8812ae_fw      rtl8821as_config  rtl8822c_fw
rtl8703as_fw          rtl8723b_config_2Ant_S0  rtl8723cs_vf_fw      rtl8725a_config     rtl8761au_fw            rtl8821as_fw      rtl8822cs_config
rtl8703bs_config      rtl8723b_fw              rtl8723cs_xx_config  rtl8725a_fw         rtl8761aw8192eu_config  rtl8821c_config   rtl8822cs_fw
rtl8703bs_fw          rtl8723bs_config         rtl8723cs_xx_fw      rtl8725as_config    rtl8761aw8192eu_fw      rtl8821c_fw       rtl8852as_config
rtl8703cs_config      rtl8723bs_fw             rtl8723d_config      rtl8725as_fw        rtl8761b_config         rtl8821cs_config  rtl8852as_fw
rtl8703cs_fw          rtl8723bs_VQ0_config     rtl8723d_fw          rtl8761a_config     rtl8761b_fw             rtl8821cs_fw      rtl8852au_config
rtl8723a_config       rtl8723bs_VQ0_fw         rtl8723ds_config     rtl8761at8192ee_fw  rtl8761bt_config        rtl8822b_config   rtl8852au_fw
rtl8723a_config_addr  rtl8723bu_config         rtl8723ds_fw         rtl8761at8812ae_fw  rtl8761bt_fw            rtl8822b_fw
cfliu@sw-eng:firmware$ 

Finalement, le fichier mk hardware/realtek/rtkbt/rtkbt.mk sera copié dans le répertoire suivant de la machine, et fw sera chargé lorsque Bluetooth sera activé :

ifeq ($(strip $(TARGET_BOARD_PLATFORM_PRODUCT)), tablet)
BT_FIRMWARE_FILES := $(shell ls $(CUR_PATH)/vendor/firmware)
PRODUCT_COPY_FILES += \
	$(foreach file, $(BT_FIRMWARE_FILES), $(CUR_PATH)/vendor/firmware/$(file):$(TARGET_COPY_OUT_VENDOR)/etc/firmware/$(file))

La copie finale sur l'appareil est :/vendor/etc/firmware

pro:/vendor/etc/firmware # ls
4343A0.hcd                       bcm4329.hcd                  fw_awnb108_ap.bin           fw_bcm43438a0.bin                fw_cyw43438.bin       nvram_ap6212a.txt    rtl8703bs_config         rtl8723ds_config        rtl8821a_fw
AP6275P_NVRAM_V1.1_20200702.txt  bcm43341b0.hcd               fw_bcm40181a2.bin           fw_bcm43438a0_apsta.bin          fw_cyw43455.bin       nvram_ap6214.txt     rtl8703bs_fw             rtl8723ds_fw            rtl8821as_config
BCM20710A1.hcd                   bcm4339a0.hcd                fw_bcm40181a2_apsta.bin     fw_bcm43438a0_p2p.bin            fw_info.txt           nvram_ap6214a.txt    rtl8703cs_config         rtl8723f_config         rtl8821as_fw
BCM4330B1.hcd                    bcm43438a0.hcd               fw_bcm40183b2.bin           fw_bcm43438a1.bin                mali_csffw.bin        nvram_ap6216.txt     rtl8703cs_fw             rtl8723f_fw             rtl8821c_config
BCM4343A0.hcd                    bcm43438a1.hcd               fw_bcm40183b2_ag.bin        fw_bcm43438a1_apsta.bin          nh660.hcd             nvram_ap6233f.txt    rtl8723a_config          rtl8723fs_config        rtl8821c_fw
BCM4343A1.hcd                    bcm4354a1.hcd                fw_bcm40183b2_ag_apsta.bin  fw_bcm43438a1_p2p.bin            nvram.txt             nvram_ap6236.txt     rtl8723a_config_addr     rtl8723fs_fw            rtl8821cs_config
BCM4343B0.hcd                    clm_bcm43752a2_ag.blob       fw_bcm40183b2_ag_p2p.bin    fw_bcm43455c0_ag.bin             nvram_4330.txt        nvram_ap6255.txt     rtl8723a_fw              rtl8725a_config         rtl8821cs_fw
BCM4345C0.hcd                    clm_bcm43752a2_pcie_ag.blob  fw_bcm40183b2_apsta.bin     fw_bcm43455c0_ag_apsta.bin       nvram_4330_oob.txt    nvram_ap6256.txt     rtl8723as_config         rtl8725a_fw             rtl8822b_config
BCM4345C5.hcd                    clm_bcm4375b4_pcie_ag.blob   fw_bcm40183b2_p2p.bin       fw_bcm43455c0_ag_p2p.bin         nvram_AP6181.txt      nvram_ap6275hh3.txt  rtl8723as_fw             rtl8725as_config        rtl8822b_fw
BCM4354A2.hcd                    config.txt                   fw_bcm43241b4_ag.bin        fw_bcm43456c5_ag.bin             nvram_AP6210.txt      nvram_ap6275s.txt    rtl8723b_config          rtl8725as_fw            rtl8822bs_config
BCM4356A2.hcd                    esp32                        fw_bcm43241b4_ag_apsta.bin  fw_bcm43456c5_ag_apsta.bin       nvram_AP6210_24M.txt  nvram_ap62x2.txt     rtl8723b_config_2Ant_S0  rtl8761a_config         rtl8822bs_fw
BCM4359C0.hcd                    fw_RK901.bin                 fw_bcm43241b4_ag_p2p.bin    fw_bcm4354a1_ag.bin              nvram_AP6234.txt      nvram_ap6354.txt     rtl8723b_fw              rtl8761at8192ee_fw      rtl8822c_config
BCM4362A2.hcd                    fw_RK901a0.bin               fw_bcm4330.bin              fw_bcm4354a1_ag_apsta.bin        nvram_AP6275P.txt     nvram_ap6356.txt     rtl8723bs_VQ0_config     rtl8761at8812ae_fw      rtl8822c_fw
BCM4375B1.hcd                    fw_RK901a0_apsta.bin         fw_bcm4330_apsta.bin        fw_bcm4354a1_ag_p2p.bin          nvram_AP6330.txt      nvram_ap6356s.txt    rtl8723bs_VQ0_fw         rtl8761at_config        rtl8822cs_config
BT_Firmware.mk                   fw_RK901a2.bin               fw_bcm43341b0_ag.bin        fw_bcm4356a2_ag.bin              nvram_AP6335.txt      nvram_ap6398s.txt    rtl8723bs_config         rtl8761at_fw            rtl8822cs_fw
RT2870AP.dat                     fw_RK901a2_apsta.bin         fw_bcm43341b0_ag_apsta.bin  fw_bcm4356a2_ag_apsta.bin        nvram_AP6441.txt      nvram_ap6398sa.txt   rtl8723bs_fw             rtl8761au8192ee_fw      rtl8852as_config
RT2870APCard.dat                 fw_RK901a2_p2p.bin           fw_bcm43341b0_ag_p2p.bin    fw_bcm4356a2_ag_p2p.bin          nvram_AP6476.txt      nvram_ap6452.txt     rtl8723bu_config         rtl8761au8812ae_fw      rtl8852as_fw
RT2870STA.dat                    fw_RK903.bin                 fw_bcm4334b1_ag.bin         fw_bcm4359c0_ag.bin              nvram_AP6493.txt      nvram_awnb108.txt    rtl8723c_fw              rtl8761au_fw            rtl8852au_config
RT2870STACard.dat                fw_RK903_ag.bin              fw_bcm4334b1_ag_apsta.bin   fw_bcm4359c0_ag_apsta.bin        nvram_B23.txt         nvram_azw256.txt     rtl8723cs_cg_config      rtl8761aw8192eu_config  rtl8852au_fw
awnb108.hcd                      fw_RK903_ag_apsta.bin        fw_bcm4334b1_ag_p2p.bin     fw_bcm4359c0_ag_p2p.bin          nvram_GB86302I.txt    nvram_azw372.txt     rtl8723cs_cg_fw          rtl8761aw8192eu_fw      ssv6051-sw.bin
bcm20710a1.hcd                   fw_RK903_ag_p2p.bin          fw_bcm4339a0_ag.bin         fw_bcm43752a2_ag.bin             nvram_RK901.txt       otp.bin.z77          rtl8723cs_vf_config      rtl8761b_config         ssv6051-wifi.cfg
bcm20710a1_24M.hcd               fw_RK903_p2p.bin             fw_bcm4339a0_ag_apsta.bin   fw_bcm43752a2_ag_apsta.bin       nvram_RK903.cal       readme.txt           rtl8723cs_vf_fw          rtl8761b_fw             wifi_efuse_8189e.map
bcm20710a1_26M.hcd               fw_RK903b2.bin               fw_bcm4339a0_ag_p2p.bin     fw_bcm43752a2_pcie_ag.bin        nvram_RK903.txt       rk903.hcd            rtl8723cs_xx_config      rtl8761bt_config        wifi_efuse_8723bs-vq0.map
bcm2076b1.hcd                    fw_RK903b2_apsta.bin         fw_bcm43436b0.bin           fw_bcm43752a2_pcie_ag_apsta.bin  nvram_RK903_26M.cal   rk903_26M.hcd        rtl8723cs_xx_fw          rtl8761bt_fw            wifi_efuse_8723cs.map
bcm40183b2.hcd                   fw_RK903b2_p2p.bin           fw_bcm43436b0_apsta.bin     fw_bcm4375b4_pcie_ag.bin         nvram_WL211.txt       rtl8703as_config     rtl8723d_config          rtl8761cs_fw            wifi_efuse_8723ds.map
bcm43241b4.hcd                   fw_awnb108.bin               fw_bcm43436b0_p2p.bin       fw_bcm4375b4_pcie_ag_apsta.bin   nvram_ap6212.txt      rtl8703as_fw         rtl8723d_fw              rtl8821a_config         wifi_efuse_8821cs.map

2.4 Sélectionnez une bibliothèque de fournisseur spécifique en fonction du type

Une brève analyse du code source de libbt-vendor.so correspondant à certaines couches HAL :
Tout d'abord, la pile de protocoles Bluetooth bluedroid libbt-hci [pile de protocoles Bluetooth native] appelle les interfaces/ via la fonction hci_initialize de system/bt/hci/src /hci_layer_android.cc La fonction initialize dans bluetooth/1.0/default/vendor_interface.cc appelle ensuite la fonction open pour ouvrir la bibliothèque so correspondante.

//interfaces/bluetooth/1.0/default/vendor_interface.cc
static const char* VENDOR_LIBRARY_NAME = "libbt-vendor.so";
static const char* VENDOR_REALTEK_LIBRARY_NAME = "libbt-vendor-realtek.so";

static char wifi_type[64] = {
    
    0};
extern "C" int check_wifi_chip_type_string(char *type);
bool VendorInterface::Open(InitializeCompleteCallback initialize_complete_cb,
                           PacketReadCallback event_cb,
                           PacketReadCallback acl_cb,
                           PacketReadCallback sco_cb,
                           PacketReadCallback iso_cb) {
    
    
  initialize_complete_cb_ = initialize_complete_cb;
  char vendor_lib_name[32];

  // Initialize vendor interface
  if (wifi_type[0] == 0)
      //获取当前wifi芯片的type加载不同的so库,目前这个接口有权限问题,待进一步分析
	  check_wifi_chip_type_string(wifi_type);
  if ((0 == strncmp(wifi_type, "RTL", 3)) ||
      (0 == strncmp(wifi_type, "SSV", 3))) {
    
     // for ssv6051 wifi + rtl8761 bt
      //此时加载的是libbt-vendor-realtek.so
    strcpy(vendor_lib_name, VENDOR_REALTEK_LIBRARY_NAME);
  } else {
    
    
      //此时加载的是libbt-vendor.so
    strcpy(vendor_lib_name, VENDOR_LIBRARY_NAME);
  }

  ALOGD("%s: %s", __func__, vendor_lib_name);
  lib_handle_ = dlopen(vendor_lib_name, RTLD_NOW);
  if (!lib_handle_) {
    
    
    ALOGE("%s unable to open %s (%s)", __func__, vendor_lib_name,
          dlerror());
    return false;
  }

  lib_interface_ = reinterpret_cast<bt_vendor_interface_t*>(
      dlsym(lib_handle_, VENDOR_LIBRARY_SYMBOL_NAME));
  if (!lib_interface_) {
    
    
    ALOGE("%s unable to find symbol %s in %s (%s)", __func__,
          VENDOR_LIBRARY_SYMBOL_NAME, vendor_lib_name, dlerror());
    return false;
  }

  // Get the local BD address
  uint8_t local_bda[BluetoothAddress::kBytes];
  //获取本地的蓝牙地址
  if (!BluetoothAddress::get_local_address(local_bda)) {
    
    
    LOG_ALWAYS_FATAL("%s: No Bluetooth Address!", __func__);
  }
  //接口的初始化
  int status = lib_interface_->init(&lib_callbacks, (unsigned char*)local_bda);
  if (status) {
    
    
    ALOGE("%s unable to initialize vendor library: %d", __func__, status);
    return false;
  }

  ALOGD("%s vendor library loaded", __func__);

  // Power on the controller
  int power_state = BT_VND_PWR_ON;
  lib_interface_->op(BT_VND_OP_POWER_CTRL, &power_state);

  // Get the UART socket(s)
  int fd_list[CH_MAX] = {
    
    0};
  int fd_count = lib_interface_->op(BT_VND_OP_USERIAL_OPEN, &fd_list);

  if (fd_count < 1 || fd_count > CH_MAX - 1) {
    
    
    ALOGE("%s: fd_count %d is invalid!", __func__, fd_count);
    return false;
  }

  for (int i = 0; i < fd_count; i++) {
    
    
    if (fd_list[i] == INVALID_FD) {
    
    
      ALOGE("%s: fd %d is invalid!", __func__, fd_list[i]);
      return false;
    }
  }

  event_cb_ = event_cb;
  PacketReadCallback intercept_events = [this](const hidl_vec<uint8_t>& event) {
    
    
    HandleIncomingEvent(event);
  };

  if (fd_count == 1) {
    
    
    hci::H4Protocol* h4_hci =
        new hci::H4Protocol(fd_list[0], intercept_events, acl_cb, sco_cb, iso_cb);
    fd_watcher_.WatchFdForNonBlockingReads(
        fd_list[0], [h4_hci](int fd) {
    
     h4_hci->OnDataReady(fd); });
    hci_ = h4_hci;
  } else {
    
    
    hci::MctProtocol* mct_hci =
        new hci::MctProtocol(fd_list, intercept_events, acl_cb);
    fd_watcher_.WatchFdForNonBlockingReads(
        fd_list[CH_EVT], [mct_hci](int fd) {
    
     mct_hci->OnEventDataReady(fd); });
    fd_watcher_.WatchFdForNonBlockingReads(
        fd_list[CH_ACL_IN], [mct_hci](int fd) {
    
     mct_hci->OnAclDataReady(fd); });
    hci_ = mct_hci;
  }

  // Initially, the power management is off.
  lpm_wake_deasserted = true;

  // Start configuring the firmware
  //配置和加载Firmware
  firmware_startup_timer_ = new FirmwareStartupTimer();
  lib_interface_->op(BT_VND_OP_FW_CFG, nullptr);

  return true;
}

2.5 Sélection de la pile de protocoles

Dans le répertoire system/bt, le code de la pile de protocoles Bluetooth et le code de chargement de la bibliothèque libbt-vendor.so sont généralement recommandés pour utiliser la pile de protocoles Bluetooth native [dans le répertoire system/bt]. S'il existe une pile de protocoles du fabricant cela fait la pile de protocoles native S'il est nécessaire d'utiliser la propre pile de protocoles du fabricant en raison de modifications majeures, chargez les piles de protocoles des différents fabricants [généralement dans le répertoire matériel] au niveau de la couche jni.

//packages/apps/Bluetooth/jni/com_android_bluetooth_btservice_AdapterService.cpp
static void classInitNative(JNIEnv* env, jclass clazz) {
    
    
    ......
    char type[64];
    check_wifi_chip_type_string(type);
    if (!strncmp(type, "RTL", 3)) {
    
     //加载rtl厂商对应的蓝牙协议栈的库:bluetooth_rtk.default.so
        ALOGD("%s, load %s.default.so", __func__, BT_STACK_RTK_MODULE_ID); 
        err = hw_get_module(BT_STACK_RTK_MODULE_ID, (hw_module_t const**)&module);
    } else {
    
     //加载原生的蓝牙协议栈的库:bluetooth.default.so
        ALOGD("%s, load %s.default.so", __func__, id);
        err = hw_get_module(id, (hw_module_t const**)&module);
    }
}

//处理一些回调
const bt_vendor_callbacks_t lib_callbacks = {
    
    
    sizeof(lib_callbacks), firmware_config_cb, sco_config_cb,
    low_power_mode_cb,     sco_audiostate_cb,  buffer_alloc_cb,
    buffer_free_cb,        transmit_cb,        epilog_cb,
    a2dp_offload_cb};

}  // namespace
//BT_STACK_RTK_MODULE_ID在./hardware/libhardware/include/hardware/bluetooth.h定义

3. Journaux associés

3.1 Journaux liés au noyau

//USB识别设备类型pid,vid以及序列号等
02-24 14:08:54.866 I/KERNEL: usb 4-1.1( 7855): New USB device found, idVendor=0bda, idProduct=d723, bcdDevice= 2.00
02-24 14:08:54.866 I/KERNEL: usb 4-1.1( 7855): New USB device strings: Mfr=1, Product=2, SerialNumber=3
02-24 14:08:54.866 I/KERNEL: usb 4-1.1( 7855): Product: 802.11n WLAN Adapter
02-24 14:08:54.866 I/KERNEL: usb 4-1.1( 7855): Manufacturer: Realtek
02-24 14:08:54.866 I/KERNEL: usb 4-1.1( 7855): SerialNumber: 00e04c000001
//Realtk驱动加载已经装载firmware信息
02-24 14:08:54.869 I/KERNEL: rtk_btusb( 7855): btusb_probe: usb_interface 00000000a7ea3647, bInterfaceNumber 0, idVendor 0x0bda, idProduct 0x0000
02-24 14:08:54.869 I/KERNEL: rtk_btusb( 7855): get_fw_table_entry: Product id = 0xd723, fw table entry size 71
02-24 14:08:54.870 I/KERNEL: rtk_btusb( 7855): firmware_info_init: Auto suspend is disabled
02-24 14:08:54.870 I/KERNEL: rtk_btusb( 7855): btusb_probe: Check bt reset flag 0
02-24 14:08:54.870 I/KERNEL: rtk_btusb( 7855): load_firmware_info: Default lmp version = 0x8723, fw file name[rtl8723d_fw]
02-24 14:08:54.870 I/KERNEL: rtk_btusb( 7855): load_firmware_info: epatch_buf = vmalloc(fw->size, GFP_KERNEL)
02-24 14:08:55.152 I/KERNEL: rtk_btusb( 7855): get_eversion: status 0, eversion 2
02-24 14:08:55.152 I/KERNEL: rtk_btusb( 7855): load_firmware_info: Default lmp_version 0x8723, project_id[9] 0x8723 -> match

3.2 Journaux liés à l'application et au framework

02-24 14:09:01.039 D/BluetoothManagerService(  797): enable(com.android.dten.settings):  mBluetooth =null mBinding = false mState = OFF
02-24 14:09:01.039 D/BluetoothManagerService(  797): enable returning
02-24 14:09:01.039 D/BluetoothManagerService(  797): binding Bluetooth service
02-24 14:09:01.040 D/BluetoothA2dp( 1770): Binding service...
02-24 14:09:01.041 D/BluetoothHidHost( 1770): Binding service...
//加载协议栈libbluetooth.so库
02-24 14:09:01.091 I/BluetoothServiceJni( 9618): hal_util_load_bt_library: loaded Bluetooth library successfully
02-24 14:09:01.117 D/BluetoothManagerService(  797): MESSAGE_BLUETOOTH_STATE_CHANGE: OFF > BLE_TURNING_ON
02-24 14:09:01.117 D/BluetoothManagerService(  797): Sending BLE State Change: OFF > BLE_TURNING_ON

3.3 Journal de la pile de protocoles libbluetooth/libbt_hci

//协议栈初始化以及消息线程的处理
02-24 14:09:01.104 I/bt_btif ( 9618): system/bt/btif/src/bluetooth.cc:162 init: init: start restricted = 0 ; common criteria mode = 0, config compare result = 0
02-24 14:09:01.105 I/droid.bluetoot( 9618): [0224/140901.105332:INFO:message_loop_thread.cc(224)] Run: message loop starting for thread bt_stack_manager_thread
02-24 14:09:01.105 I/bt_stack_manager( 9618): system/bt/btif/src/stack_manager.cc:210 event_init_stack: is initializing the stack
02-24 14:09:01.106 I/bt_btif_core( 9618): system/bt/btif/src/btif_core.cc:235 btif_init_bluetooth: btif_init_bluetooth entered
02-24 14:09:01.106 I/bt_stack_manager( 9618): system/bt/btif/src/stack_manager.cc:233 event_init_stack: finished
//hci协议层初始化,并且调用hardware下HDIL接口
02-24 14:09:01.135 I/bt_hci  ( 9618): system/bt/hci/src/hci_layer.cc:200 hci_module_start_up: hci_module_start_up
02-24 14:09:01.135 I/bt_hci  ( 9618): system/bt/hci/src/hci_layer_android.cc:159 hci_initialize: hci_initialize
02-24 14:09:01.136 I/bt_hci  ( 9618): system/bt/hci/src/hci_layer_android.cc:178 hci_initialize: hci_initialize: IBluetoothHci::getService() returned 0xb400006ff7a7d390 (remote)
02-24 14:09:01.136 I/[email protected]( 9496): BluetoothHci::initialize()

3.4 Journaux liés à l'interface HDIL

02-24 14:09:01.136 I/[email protected]( 9496): BluetoothHci::initialize()
//根据type来决定加载不同的so库
02-24 14:09:01.137 E/[email protected]( 9496): check_wifi_chip_type_string : APXXX: Permission denied
//打开libbt-vendor.so来配置端口,上下电,firmware的加载等
02-24 14:09:01.137 D/[email protected]( 9496): Open: libbt-vendor.so
02-24 14:09:01.138 E/[email protected]( 9496): vendor storage read error
02-24 14:09:01.138 D/[email protected]( 9496): get_local_address: Trying /data/misc/bluetooth/bdaddr
// libbt_verdor库中处理,获取版本信息,日志开关等等
02-24 14:09:01.138 I/libbt_vendor( 9496): RTKBT_RELEASE_NAME: 20201130_BT_ANDROID_11.0
02-24 14:09:01.138 I/libbt_vendor( 9496): init
02-24 14:09:01.138 I/rtk_parse( 9496): RTKBT_RELEASE_NAME: 20200318_BT_ANDROID_10.0
02-24 14:09:01.138 E/libbt_vendor( 9496): rtk_btsnoop_dump = 0, rtk_btsnoop_save_log = 0
02-24 14:09:01.138 D/[email protected]( 9496): Open vendor library loaded
//设置电源管理情况,先下电在上电
02-24 14:09:01.338 D/libbt_vendor( 9496): set power off and delay 200ms
02-24 14:09:02.339 D/libbt_vendor( 9496): set power on and delay 1000ms
02-24 14:09:02.339 D/libbt_vendor( 9496): USB op for 3
02-24 14:09:02.339 I/bt_userial_vendor( 9496): device fd = 8 open
02-24 14:09:02.339 D/bt_service( 9496): OsAllocateTimer bt_service sigev.sigev_notify_thread_id = syscall(__NR_gettid)!
02-24 14:09:02.339 D/bt_service( 9496): RTK_btservice_init init done!
//驱动打开USB设备
02-24 14:09:03.814 I/KERNEL: DTEN(  182): HW_INFO:time:2023-2-24 6:9:3.
02-24 14:09:04.111 I/KERNEL: rtk_btusb( 9498): btchr_open: BT usb char device is opening
02-24 14:09:04.112 I/KERNEL: rtk_btusb( 9498): btchr_ioctl with Cmd:-2147203660


//libbt_verdor对设备的firmware的配置,以及信息的获取
02-24 14:09:02.601 D/bt_hwcfg_usb( 9496): RTKBT_RELEASE_NAME: 20201130_BT_ANDROID_11.0
02-24 14:09:02.601 D/bt_hwcfg_usb( 9496): 
02-24 14:09:02.601 D/bt_hwcfg_usb( 9496): Realtek libbt-vendor_usb Version 5.1.1 
02-24 14:09:02.601 D/bt_hwcfg_usb( 9496): hw_usb_config_start, transtype = 0x20, pid = 0xd723, vid = 0x0bda 
02-24 14:09:04.373 I/KERNEL: rtk_btusb( 9498): btusb_open: Start, PM usage count 0
02-24 14:09:04.373 I/KERNEL: rtk_btusb( 9498): btusb_open: End, PM usage count 0
02-24 14:09:02.610 D/bt_hwcfg_usb( 9496): hw_cfg_cb.state = 9
02-24 14:09:02.911 D/bt_hwcfg_usb( 9496): hw_cfg_cb.state = 2
02-24 14:09:02.911 I/bt_hwcfg_usb( 9496): BT config file: /vendor/etc/firmware/rtl8723d_config
02-24 14:09:02.911 D/bt_hwcfg_usb( 9496): bt_addr = 0
02-24 14:09:02.911 I/bt_hwcfg_usb( 9496): config offset(0xe4),length(0x1)
//装载固件成功
02-24 14:09:02.911 I/bt_hwcfg( 9496): BT fw file: /vendor//etc/firmware/rtl8723d_fw
02-24 14:09:02.911 I/bt_hwcfg( 9496): Load FW OK

//解析firmware以及rtl8723d_config的信息
02-24 14:09:02.911 D/bt_hwcfg_usb( 9496): lmp_subversion = 0x8723 hw_cfg_cb.hci_version = 0x8 hw_cfg_cb.hci_revision = 0xd, hw_cfg_cb.lmp_sub_current = 0x4b4a
02-24 14:09:02.911 D/bt_hwcfg_usb( 9496): hw_usb_config_cback: Cold BT controller startup
02-24 14:09:02.912 D/bt_hwcfg_usb( 9496): hw_cfg_cb.state = 3
02-24 14:09:02.912 D/bt_hwcfg_usb( 9496): hw_usb_config_cback chip_id of the IC:3
02-24 14:09:02.912 E/bt_hwcfg_usb( 9496): update altsettings
02-24 14:09:02.912 I/bt_hwcfg_usb( 9496): ORG Config len=0000000a:
02-24 14:09:02.912 I/bt_hwcfg_usb( 9496): 00000000: 55 ab 23 87 04 00 e4 00 01 08 00 00 00 00 00 00
02-24 14:09:02.912 I/bt_hwcfg_usb( 9496): Couldn't open extra config /vendor/etc/bluetooth/rtk_btconfig.txt, err:No such file or directory
02-24 14:09:02.912 I/bt_hwcfg_usb( 9496): rtk_update_altsettings: 1 AltSettings
02-24 14:09:02.912 I/bt_hwcfg_usb( 9496): MAC: 22:22:2b:2c:02:00
02-24 14:09:02.912 I/bt_hwcfg_usb( 9496): rtk_update_altsettings: add 0044[06]
02-24 14:09:02.912 I/bt_hwcfg_usb( 9496): NEW Config len=00000013:
02-24 14:09:02.912 I/bt_hwcfg_usb( 9496): 00000000: 55 ab 23 87 0d 00 e4 00 01 08 44 00 06 00 02 2c
02-24 14:09:02.912 I/bt_hwcfg_usb( 9496): 00000010: 2b 22 22 00 00 00 00 00 00 00 00 00 00 00 00 00
02-24 14:09:02.912 I/bt_hwcfg( 9496): bt_hw_parse_project_id: opcode 0, len 1, data 9
02-24 14:09:02.912 I/bt_hwcfg( 9496): rtk_get_patch_entry: fw_ver 0x829a4b4a, patch_num 3
02-24 14:09:02.912 I/bt_hwcfg( 9496): rtk_get_patch_entry: chip_id 3, patch_len 0x7ea0, patch_offset 0x4940
02-24 14:09:02.912 I/bt_hwcfg_usb( 9496): total_len = 0x7eb3
02-24 14:09:02.912 I/bt_hwcfg_usb( 9496): BTCOEX:20200103-3535 svn_version:24232 lmp_subversion:0x8723 hci_version:0x8 hci_revision:0xd chip_type:31 Cut:3 libbt-vendor_uart version:5.1.1, patch->fw_version = 829a4b4a
02-24 14:09:02.912 I/bt_hwcfg_usb( 9496): Fw: exists, config file: exists
02-24 14:09:02.912 D/bt_hwcfg_usb( 9496): Check total_len(0x00007eb3) max_patch_size(0x0000a000)
//总共129条
02-24 14:09:02.912 D/bt_hwcfg_usb( 9496): patch fragment count 129, tail len 179
02-24 14:09:02.913 D/bt_hwcfg_usb( 9496): bt vendor lib: HW_CFG_DL_FW_PATCH status:0, opcode:0xfc20
02-24 14:09:02.913 D/bt_hwcfg_usb( 9496): bt vendor lib: HW_CFG_DL_FW_PATCH status:0, iIndexRx:0
....
02-24 14:09:03.170 D/bt_hwcfg_usb( 9496): bt vendor lib: HW_CFG_DL_FW_PATCH status:0, opcode:0xfc20
02-24 14:09:03.170 D/bt_hwcfg_usb( 9496): bt vendor lib: HW_CFG_DL_FW_PATCH status:0, iIndexRx:129
02-24 14:09:03.170 D/bt_hwcfg_usb( 9496): vendor lib fwcfg completed

//HDIL的相关回调
02-24 14:09:03.170 D/[email protected]( 9496): OnFirmwareConfigured result: 0
02-24 14:09:03.170 I/[email protected]( 9496): Firmware configured in 0.831s
02-24 14:09:03.170 I/[email protected]( 9496): OnFirmwareConfigured: lpm_timeout_ms 0
02-24 14:09:03.170 D/[email protected]( 9496): OnFirmwareConfigured Calling StartLowPowerWatchdog()
//Kernel io接口OK
02-24 14:09:04.943 I/KERNEL: rtk_btusb( 9722): btchr_ioctl with Cmd:1074021811
02-24 14:09:04.943 I/KERNEL: rtk_btusb( 9722): btchr_ioctl lmp_sub = 0x4b4a, patch_entry->lmp_sub = 0x4b4a

02-24 14:09:03.202 E/bt_userial_vendor( 9496): set event mask, it should bt stack init, set coex bt on
//rtk心跳相关配置和初始化
02-24 14:09:03.202 D/rtk_heartbeat( 9496): Heartbeat_init start
02-24 14:09:03.202 E/rtk_heartbeat( 9496): load_rtkbt_heartbeat_conf unable to open file '/vendor/etc/bluetooth/rtkbt_heartbeat.conf': No such file or directory
02-24 14:09:03.202 D/rtk_heartbeat( 9496): Heartbeat_init res = 0
02-24 14:09:03.202 D/rtk_heartbeat( 9496): Heartbeat_init end

4. Problèmes restants

4.1 Anomalie dans l'acquisition du type de puce

Actuellement, l'interface check_wifi_chip_type_string indique qu'il y a un problème d'autorisation, donc lors du débogage du RTL8723DU, la macro BCM est désactivée. Si l'interface check_wifi_chip_type_string est correcte plus tard, la macro BCM peut être activée par défaut pour le traitement de compatibilité. Ensuite, vous devez ajouter des journaux pour analyser spécifiquement le problème de retour anormal depuis l'interface check_wifi_chip_type_string.

4.2 Problème de fonctionnement du mode SCO de l'adaptateur USB Bluetooth

Le casque peut fonctionner normalement lorsqu'il est couplé et connecté via le mode A2DP, car il n'est pas nécessaire d'enregistrer la carte son et il utilise le protocole Bluetooth lui-même ; tandis que SCO utilise le flux pcm et doit passer par le processus de carte son via ALSA. Le test actuel montre que la carte son utilise la carte native 2 et que le périphérique 0 est configuré pour le coin de la puce BCM. Par conséquent, la carte son de l'adaptateur USB Bluetooth doit être enregistrée par elle-même et les données USB doivent être converti en PCM pour le traitement.

4.3 Utilisation obligatoire de l'A2DP lors des réunions

Afin d'utiliser un casque Bluetooth lors d'une réunion, vous devez d'abord forcer l'utilisation du mode A2DP pendant la réunion, et le Mic utilisera le micro local de la machine. Lors de l'utilisation du mode SCO pour les réunions, les interfaces suivantes sont principalement appelées :

//audioManager.java
//开启sco模式
void startBluetoothSco()
void startBluetoothScoVirtualCall()

//停止sco模式
void stopBluetoothSco()

//是否使用本机speaker
void setSpeakerphoneOn(boolean on)
//通知hal层进行模式和设备选择
void setMode(@AudioMode int mode)

//设置communication的设备,替代传统的方式startBluetoothSco/stopBluetoothSco/setSpeakerphoneOn
boolean setCommunicationDevice(@NonNull AudioDeviceInfo device)

Pour forcer l’activation d’A2DP, protégez simplement les interfaces ci-dessus. Voici une brève introduction à l'utilisation de la nouvelle interface setCommunicationDevice

//The example below shows how to enable and disable speakerphone mode.	
 // Get an AudioManager instance
 AudioManager audioManager = Context.getSystemService(AudioManager.class);
 AudioDeviceInfo speakerDevice = null;
 List<AudioDeviceInfo> devices = audioManager.getAvailableCommunicationDevices();
 for (AudioDeviceInfo device : devices) {
    
    
     if (device.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
    
    
         speakerDevice = device;
         break;
     }
 }
 if (speakerDevice != null) {
    
    
     // Turn speakerphone ON.
     boolean result = audioManager.setCommunicationDevice(speakerDevice);
     if (!result) {
    
    
         // Handle error.
     }
     // Turn speakerphone OFF.
     audioManager.clearCommunicationDevice();
 }

Je suppose que tu aimes

Origine blog.csdn.net/franc521/article/details/130103992
conseillé
Classement