A method for Android to identify Bluetooth and load corresponding manufacturer library
By initializing the Bluetooth module in the Android system and traversing the USB, MMC, PCI, and UART interfaces, the system automatically identifies and loads the corresponding manufacturer's library, solving the problem of incompatibility between Bluetooth devices with different interfaces and manufacturers in existing technologies, and achieving efficient device identification and library loading.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- KYLIN CORP
- Filing Date
- 2026-06-23
- Publication Date
- 2026-07-21
AI Technical Summary
Existing technologies cannot automatically identify and load Bluetooth devices from different interfaces and manufacturers, resulting in high maintenance costs, poor flexibility, inability to dynamically adapt at runtime, and difficulty in identifying UART devices.
After the Android system boots up, the Bluetooth module is initialized and powered on using the rfkill mechanism. The system then iterates through the USB, MMC, PCI, and UART interfaces, identifies and obtains the vendor ID, and loads the corresponding vendor library based on the vendor ID.
It enables automated identification and loading of Bluetooth devices with various interface types, reducing maintenance costs, improving flexibility and identification success rate, supporting Bluetooth devices with multiple physical interfaces, and simplifying PCB design.
Smart Images

Figure CN122431752A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to computer systems, specifically to a method for Android to identify Bluetooth and load the corresponding manufacturer's library. Background Technology
[0002] With the development of embedded systems, unified platform compatibility with multiple hardware components is becoming increasingly important. AOSP (Android Open Source Project) Bluetooth is an indispensable function in daily use and development, enabling short-range communication. However, when AOSP needs to be compatible with multiple Bluetooth modules on the same hardware platform, it requires configuring macros to load vendor libraries separately for each module. This necessitates generating multiple images or configurations for Bluetooth modules from different vendors on the same platform to load their respective Bluetooth vendor libraries, or using hardware-based methods to differentiate PCB boards to load the corresponding Bluetooth vendor libraries.
[0003] In practical applications, Bluetooth devices can communicate with the host through various physical interfaces, including USB, SDIO / MMC, PCI, and UART. Bluetooth devices with different interfaces have different identification methods and characteristics: USB devices: Identified by device ID and vendor ID. SDIO / MMC devices: Identified by the device's chip ID. PCI devices: identified by device ID UART devices: require obtaining the vendor ID via HCI command interaction. Specifically, in the Android operating system, the Hal layer loads the Bluetooth vendor library through fixed macros, requiring macros to be configured before compilation to specify the corresponding Bluetooth vendor library. Existing technology has the following shortcomings: 1. Lack of automatic identification mechanism: The system cannot automatically identify the type and manufacturer of the currently connected Bluetooth device, which needs to be pre-configured.
[0004] 2. Limited interface type: Existing solutions typically only support Bluetooth devices with a single interface type and cannot handle multiple interfaces such as USB, SDIO, PCI, and UART simultaneously.
[0005] 3. Difficulty in identifying UART devices: For Bluetooth devices with UART interfaces, existing technologies lack effective automatic identification methods, requiring manual configuration or hardware differentiation.
[0006] 4. High maintenance costs: Each time the Bluetooth module is replaced, the configuration needs to be modified and recompiled, which increases development and maintenance costs.
[0007] 5. Poor flexibility: It cannot dynamically adapt to Bluetooth devices from different manufacturers at runtime.
[0008] There is currently no comprehensive and compatible solution specifically addressing the above issues.
[0009] Therefore, how to achieve compatibility with Bluetooth devices from different interfaces and manufacturers within the same AOSP, and automatically load the corresponding Bluetooth manufacturer libraries, has become an urgent problem to be solved. Summary of the Invention
[0010] To address the shortcomings of existing technologies, this invention provides, for the first time, a method for Android to identify Bluetooth and load the corresponding vendor library, comprising the following steps: S1. After the Android system starts up, the Bluetooth module is initialized, and the Bluetooth vendor library is loaded through VendorInterface::Open; S2. Power on the Bluetooth module using the rfkill mechanism; S3. Using the Bluetooth module, sequentially traverse the USB bus, MMC bus, and PCI bus, and identify whether the Bluetooth device exists based on the device identification information corresponding to each bus; S4. If the Bluetooth device is detected in the USB bus, MMC bus, or PCI bus, obtain the corresponding vendor ID; Otherwise, switch and traverse the UART interface to identify the Bluetooth device, and obtain the corresponding vendor ID through HCI commands; S5. Based on the returned vendor ID, set the Android property system and load the corresponding vendor library.
[0011] Furthermore, the step of powering on the Bluetooth module via the rfkill mechanism specifically includes: Traverse each rfkillX subdirectory under the / sys / class / rfkill / directory and read each rfkillX / type node; Determine the path with the type value "bluetooth" and obtain the corresponding rfkill ID number; Write 1 to the / sys / class / rfkill / rfkillX / state node to power on the Bluetooth module.
[0012] Furthermore, the traversal of the USB bus and the identification of the Bluetooth device specifically include: Iterate through the devices connected to the bus in the / sys / bus / usb / devices / directory; Read the idProduct and idVendor node information of the USB device to obtain the PID and VID respectively; The system determines whether the PID and VID correspond to the Bluetooth device based on a preset device information table. If they do, the system identifies the Bluetooth device and the corresponding manufacturer ID based on the PID and VID.
[0013] Furthermore, the traversal of the MMC bus and the identification of the Bluetooth device specifically include: Iterate through the devices connected to the MMC bus in the / sys / bus / mmc / devices / directory; Read the device and vendor node information of the MMC device to obtain the PID and VID respectively; The system determines whether the PID and VID correspond to the Bluetooth device based on a preset device information table. If they do, the system identifies the Bluetooth device and the corresponding manufacturer ID based on the PID and VID.
[0014] Furthermore, the traversal of the PCI bus and the identification of the Bluetooth device specifically include: Iterate through the PCI bus-connected devices in the / sys / bus / pci / devices / directory; Read the device and vendor node information of the PCI device to obtain the PID and VID respectively; The system determines whether the PID and VID correspond to the Bluetooth device based on a preset device information table. If they do, the system identifies the Bluetooth device and the corresponding manufacturer ID based on the PID and VID.
[0015] Furthermore, the specific steps for traversing the UART interface to identify the Bluetooth device and obtaining the vendor ID via HCI commands include: Enable the default tty node assigned to the UART interface by the hardware platform; Configure multiple sets of serial port parameters, and use one set of the serial port parameters to send a Bluetooth reset command to the tty node to reset it to the initial state. Then read the feedback data buff. If feedback data that conforms to the preset format is received, continue to send a Bluetooth information acquisition command. Extract the vendor ID based on the received response data, and then determine whether the Bluetooth device is supported based on the extracted vendor ID.
[0016] Furthermore, the preset format is: the data length is greater than 7, and the data buff[4] = 0x03, buff[5] = 0x0c and buff[6] = 0x00.
[0017] Furthermore, the specific steps also include: If the command sent to the Bluetooth device under the current serial port parameters does not receive a valid response, switch to the next set of serial port parameters and resend the Bluetooth reset command and the Bluetooth information acquisition command until the manufacturer ID is successfully obtained or all serial port parameters have been tried. If the Bluetooth device is not found using all the serial port parameters, the identification is deemed to have failed.
[0018] Furthermore, the method for determining whether the corresponding Bluetooth device is supported based on the manufacturer ID is as follows: If the response data length is greater than or equal to 13, and the manufacturer ID = buff
[11] << 8 | buff
[12] or the response data length is less than 13 and buff[0] = 0xC0, buff[1] = 0x00, then the Bluetooth device is considered to be supported. If none of the above conditions are met, it is considered that the Bluetooth device is not supported, and the process switches to the next set of serial port parameters to continue obtaining the vendor ID through the HCI command.
[0019] Furthermore, after confirming that the vendor ID is supported, the vendor ID is matched with the device information table. If the match is successful, the vendor library name is returned and the corresponding vendor library is loaded.
[0020] Compared with existing technologies, this method for Android to identify Bluetooth and load the corresponding manufacturer's library has the following advantages: 1. Identify Bluetooth manufacturers by automatically traversing USB, MMC, PCI, and UART; 2. Ensure automatic identification of which manufacturer's Bluetooth is being used by the current PCB; 3. Supports identification of Bluetooth devices with multiple physical interfaces; 4. Supports automatic baud rate switching for Bluetooth devices with UART interfaces to ensure accurate identification of connected Bluetooth devices; 5. Automatically load the corresponding Bluetooth vendor library based on the recognition results.
[0021] Other advantages, objectives and features of the invention will be set forth in part in the description which follows, and in part will be apparent to those skilled in the art from the following examination or study, or may be learned from the practice of the invention. Attached Figure Description
[0022] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are merely some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without any creative effort.
[0023] Figure 1 This is a schematic diagram of the overall concept of the present invention; Figure 2 This is a detailed flowchart of the present invention; Figure 3 This is a flowchart illustrating the USB, MMC, and PCI device identification process of the present invention. Figure 4 This is a flowchart of the UART device identification process of the present invention. Detailed Implementation
[0024] To further illustrate the technical means and effects of the present invention in achieving its intended purpose, the following detailed description of the specific implementation methods, structures, features, and effects of the present invention, in conjunction with the accompanying drawings and preferred embodiments, is provided below.
[0025] In this invention, the terminology used and its interpretation are as follows: HAL (Hardware Abstraction Layer) is a hardware abstraction layer that contains standard interfaces that hardware vendors must implement.
[0026] USB (Universal Serial Bus) is a universal serial bus that contains a standard interface and protocol for communication between a host and a device.
[0027] SDIO (Secure Digital Input and Output) is a secure digital input / output interface that includes a device interconnect standard that extends the SD card standard.
[0028] MMC (MultiMediaCard) is a multimedia card that includes a memory card interface standard.
[0029] UART (Universal Asynchronous Receiver / Transmitter) is a universal asynchronous receiver / transmitter that includes a hardware interface standard for serial communication.
[0030] PCI (Peripheral Component Interconnect) is a peripheral component interconnect standard that includes a local bus standard.
[0031] HCI (Host Controller Interface) is a standard for communication commands and events between the host and the Bluetooth controller.
[0032] The H4 protocol is a type of Bluetooth UART transmission protocol that includes a 3-wire Bluetooth transmission standard based on UART.
[0033] The H5 protocol is a type of Bluetooth UART transmission protocol, which includes a UART-based transmission standard with error checking and retransmission mechanisms.
[0034] rfkill (Radio Frequency Kill) is a radio frequency shielding (or radio frequency blocking) mechanism that includes a standard interface in the kernel subsystem for registering and querying the soft and hard switch status of wireless devices such as Wi-Fi and Bluetooth.
[0035] Example 1: like Figure 1 and Figure 2 As shown, the overall approach is as follows: S001 Android system startup initialization; The S002 Bluetooth module is initialized and loaded, and the vendor library is loaded via VendorInterface::Open; S003 Iterates through / sys / class / rfkill / rfkillX / type, determines the path where type is bluetooth, determines the rfkill id number (i.e., the value of X), and writes 1 to the / sys / class / rfkill / rfkillX / state node to power on the Bluetooth module; S004 will first iterate through the USB, MMC, and PCI Bluetooth modules, such as Figure 3 As shown; (1) Traverse all USB devices under / sys / bus / usb / devices; (2) Obtain its idProduct and idVendor, which correspond to pid and vid respectively, and can uniquely determine whether the module supports Bluetooth; (a) If Bluetooth is found, its corresponding manufacturer library name can be determined and jump value S006 can be used; (b) If no Bluetooth device is found, continue to try the next USB device path. If no Bluetooth device is found after searching all USB devices, try to find the next MMC Bluetooth device. (3) Traverse all MMC devices under / sys / bus / mmc / devices; (4) Obtain its device and vendor node information, which correspond to pid and vid respectively, and can uniquely determine whether the Bluetooth device is supported and its specific model; (a) If a Bluetooth device is found, its corresponding vendor ID can be determined and the jump value S006 can be used; (b) If no Bluetooth is found, continue to try the next MMC device path. If no Bluetooth is found after searching all MMC devices, the next step will be to try to find a Bluetooth device for PCI. (5) Traverse all PCI devices under / sys / bus / pci / devices / ; (6) Obtain its device and vendor node information, which correspond to pid and vid respectively, and can uniquely determine whether the Bluetooth device is supported and its specific model; (c) If a Bluetooth device is found, its corresponding vendor library ID can be determined and the jump value S006 can be used; (d) If no Bluetooth device is found, continue to try the next MMC device path. If no device is found after searching all MMC devices, proceed to S005. S005 iterates through the UART, such as Figure 4 As shown: (1) Open the tty node (determined by the hardware platform) that the hardware platform uses by default for Uart Bluetooth. The default is / dev / ttyS1. Configure the H4 / H5 serial port parameters according to the implementation requirements. These parameters are variable. The current default first set of parameters is baud rate 115200, data bits 8 bits, and stop bits 1. If the H5 serial port parameters are set, the vendorsync command must be sent first, i.e., 0xc0,0x00,0x2f,0x00,0xd0,0x01,0x7e,0xc0.
[0036] (2) Send the Bluetooth reset command HCl reset, i.e. 0x01, 0x03, 0x0c, 0x00, to reset the Bluetooth module to its initial state. After sending, use the poll function to set a timeout of 200ms and read the feedback data buff. When the length of the read data is greater than 7, and the data buff[4] = 0x03, buff[5] = 0x0c and buff[6] = 0x00 (i.e. Figure 2 In the process of trying the predefined serial port parameters of H4 / H5 and finding the Bluetooth device after protocol communication, it indicates that the signal was successfully sent; otherwise, return to (1) to switch to the next set of serial port parameters. (3) Send Bluetooth information to obtain the command HCI vendor info, i.e. 0x01, 0x01, 0x10, 0x00. After checking the sending status in the same way as (2), extract the vendor ID. When the data length is greater than or equal to 13, the Bluetooth vendor ID can be extracted from it, i.e. vid=buff
[11] <<8|buff
[12] . When the data length is less than 13 and buff[0]=0xc0, buff[1]=0x00, it is considered to be a Realtek Bluetooth device and vid is assigned the value 0x5d00vid=0x5D00. Otherwise, it is an unsupported Bluetooth device and returns to (1) to switch the next set of serial port parameters. If any Bluetooth reset command or Bluetooth information acquisition command fails to be sent, the current serial port parameters are determined to be incorrect, and the next set of serial port parameters is used. If no remaining serial port parameters are available at this point, the identification is considered a failure. (4) Finally, based on the vendor ID, the matching UART device information table is as follows: Broadcom: 0x0F00 → libbt-vendor_bcmMulti.so Qualcomm: 0x1D00 → libbt-vendor_qcaMulti.so Realtek: 0x5D00 → libbt-vendor_rtlMulti.so MediaTek: 0x4600 → libbt-vendor_mtkMulti.so Amlogic: 0xFFFF → libbt-vendor_amlMulti.so Unispre: 0xEC01 → libbt-vendor_uweMulti.so Barrot: 0xE708 → libbt-vendor_brtMulti.so Beken: 0xF005 → libbt-vendor_bekMulti.so S006 Loads the corresponding vendor library based on the vendor ID and module name returned in step S004 or S005, sets relevant attributes through the Android property system, and finally calls the op callback in the vendor library according to the standard process to realize the interaction between the Bluetooth device and the host.
[0037] The advantage of this embodiment is that: Software aspects: (1) A method for automatically identifying Bluetooth devices with multiple interface types in Android system is proposed for the first time. This function can be added to the original Hal layer to automatically load the corresponding manufacturer's library.
[0038] (2) It does not require generating an image or modifying the configuration for each Bluetooth device separately, and achieves compatibility with most mainstream Bluetooth devices, including products from Broadcom, Qualcomm, Realtek, MediaTek, Amlogic and other manufacturers.
[0039] (3) It effectively reduces the situation where Bluetooth cannot be used due to misconfiguration, realizes automatic identification of Bluetooth devices and manufacturers, and loads the corresponding manufacturer library.
[0040] (4) It supports four mainstream interfaces: USB, MMC, PCI and UART, covering the vast majority of Bluetooth devices on the market.
[0041] (5) For UART devices, automatic switching between H4 and H5 protocols is supported to improve the recognition success rate.
[0042] (6) Manage equipment information through the equipment information table. Adding new equipment only requires adding table entries, without modifying the core logic.
[0043] Hardware aspects: (7) For UART Bluetooth, there is no need to modify the configuration or use additional hardware to identify Bluetooth devices, which reduces hardware costs.
[0044] (8) No special identification circuit needs to be designed to distinguish different Bluetooth devices, which simplifies PCB design.
[0045] (9) The same PCB can be adapted to a variety of Bluetooth devices, which improves the versatility and flexibility of the hardware platform.
[0046] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention in any way. Although the present invention has been disclosed above with reference to preferred embodiments, it is not intended to limit the present invention. Any person skilled in the art can make some modifications or alterations to the above-disclosed technical content to create equivalent embodiments without departing from the scope of the present invention. Any simple modifications, equivalent changes and alterations made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention shall still fall within the scope of the present invention.
Claims
1. A method for Android to identify Bluetooth and load the corresponding manufacturer's library, characterized in that, Includes the following steps: S1. After the Android system starts up, the Bluetooth module is initialized, and the Bluetooth vendor library is loaded through VendorInterface::Open; S2. Power on the Bluetooth module using the rfkill mechanism; S3. Using the Bluetooth module, sequentially traverse the USB bus, MMC bus, and PCI bus, and identify whether the Bluetooth device exists based on the device identification information corresponding to each bus; S4. If the Bluetooth device is detected in the USB bus, MMC bus, or PCI bus, obtain the corresponding vendor ID; Otherwise, switch and traverse the UART interface to identify the Bluetooth device, and obtain the corresponding vendor ID through HCI commands; S5. Based on the returned vendor ID, set the Android property system and load the corresponding vendor library.
2. The method for Android to identify Bluetooth and load the corresponding manufacturer's library according to claim 1, characterized in that, The step of powering on the Bluetooth module via the rfkill mechanism specifically includes: Traverse each rfkillX subdirectory under the / sys / class / rfkill / directory and read each rfkillX / type node; Determine the path with the type value "bluetooth" and obtain the corresponding rfkill ID number; Write 1 to the / sys / class / rfkill / rfkillX / state node to power on the Bluetooth module.
3. The method for Android to identify Bluetooth and load the corresponding manufacturer's library according to claim 1, characterized in that, The traversal of the USB bus and the identification of the Bluetooth device specifically include: Iterate through the devices connected to the bus in the / sys / bus / usb / devices / directory; Read the idProduct and idVendor node information of the USB device to obtain the PID and VID respectively; The system determines whether the PID and VID correspond to the Bluetooth device based on a preset device information table. If they do, the system identifies the Bluetooth device and the corresponding manufacturer ID based on the PID and VID.
4. The method for Android to identify Bluetooth and load the corresponding manufacturer's library according to claim 1, characterized in that, The traversal of the MMC bus and the identification of the Bluetooth device specifically include: Iterate through the devices connected to the MMC bus in the / sys / bus / mmc / devices / directory; Read the device and vendor node information of the MMC device to obtain the PID and VID respectively; The system determines whether the PID and VID correspond to the Bluetooth device based on a preset device information table. If they do, the system identifies the Bluetooth device and the corresponding manufacturer ID based on the PID and VID.
5. The method for Android to identify Bluetooth and load the corresponding manufacturer's library according to claim 1, characterized in that, The traversal of the PCI bus and the identification of the Bluetooth device specifically include: Iterate through the PCI bus-connected devices in the / sys / bus / pci / devices / directory; Read the device and vendor node information of the PCI device to obtain the PID and VID respectively; The system determines whether the PID and VID correspond to the Bluetooth device based on a preset device information table. If they do, the system identifies the Bluetooth device and the corresponding manufacturer ID based on the PID and VID.
6. The method for Android to identify Bluetooth and load the corresponding manufacturer's library according to claim 1, characterized in that, The specific steps for identifying the Bluetooth device by traversing the UART interface and obtaining the vendor ID via HCI commands include: Enable the default tty node assigned to the UART interface by the hardware platform; Configure multiple sets of serial port parameters, and use one set of the serial port parameters to send a Bluetooth reset command to the tty node to reset it to the initial state. Then read the feedback data buff. If feedback data that conforms to the preset format is received, continue to send a Bluetooth information acquisition command. Extract the vendor ID based on the received response data, and then determine whether the Bluetooth device is supported based on the extracted vendor ID.
7. The method for Android to identify Bluetooth and load the corresponding manufacturer's library according to claim 6, characterized in that, The preset format is: the data length is greater than 7, and the data buff[4] = 0x03, buff[5] = 0x0c and buff[6] = 0x00.
8. A method for Android to identify Bluetooth and load the corresponding manufacturer's library according to claim 6, characterized in that, The specific steps also include: If the command sent to the Bluetooth device under the current serial port parameters does not receive a valid response, switch to the next set of serial port parameters and resend the Bluetooth reset command and the Bluetooth information acquisition command until the manufacturer ID is successfully obtained or all serial port parameters have been tried. If the Bluetooth device is not found using all the serial port parameters, the identification is deemed to have failed.
9. A method for Android to identify Bluetooth and load the corresponding manufacturer's library according to claim 6, characterized in that, The method for determining whether the corresponding Bluetooth device is supported based on the manufacturer ID is as follows: If the response data length is greater than or equal to 13, and the manufacturer ID = buff[11] << 8 | buff[12] or the response data length is less than 13 and buff[0] = 0xC0, buff[1] = 0x00, then the Bluetooth device is considered to be supported. If none of the above conditions are met, it is considered that the Bluetooth device is not supported, and the process switches to the next set of serial port parameters to continue obtaining the vendor ID through the HCI command.
10. A method for Android to identify Bluetooth and load the corresponding manufacturer's library according to claim 1, characterized in that, After confirming that the vendor ID is supported, the vendor ID is matched with the device information table. If the match is successful, the vendor library name is returned and the corresponding vendor library is loaded.