Bluetooth connection methods, devices, electronic devices and computer-readable storage media
By assessing the application's data encryption capabilities, the process of generating temporary keys can be skipped or directly addressed, resolving the issue of slow Bluetooth connection speeds and enabling faster connections and secure data transmission.
Patent Information
- Application Number
- CN202311550065.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-20
- Publication Date
- 2026-11-17
- Estimated Expiration
- 2043-11-20
AI Technical Summary
In the current Bluetooth connection process, the generation of temporary keys takes a long time, which affects the connection speed.
If the first application has data encryption capabilities, it will not generate a temporary key and will directly establish a Bluetooth serial communication connection with the second Bluetooth device. If it does not have encryption capabilities, it will proceed with the key generation process.
It improves the speed of Bluetooth serial communication connections and ensures the security and flexibility of data transmission.
Smart Images

Figure CN117377134B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communication technology, specifically to a Bluetooth connection method, apparatus, electronic device, and computer-readable storage medium. Background Technology
[0002] Bluetooth is a short-range wireless technology that provides low-cost, short-range wireless connectivity and enables various types of data transmission. Most electronic devices are equipped with Bluetooth communication capabilities to meet data transmission needs in various scenarios. Improving Bluetooth connection speed has always been one of the key research issues in the field of Bluetooth communication. Summary of the Invention
[0003] This application discloses a Bluetooth connection method, apparatus, electronic device, and computer-readable storage medium, which can improve Bluetooth connection speed.
[0004] This application discloses a Bluetooth connection method applied to a first Bluetooth device, the method comprising: If a target Bluetooth command initiated by the first application is detected, it is determined whether the first application has data encryption capabilities. If the first application has the data encryption function, it will not generate a temporary key and will establish a Bluetooth serial communication connection with the second Bluetooth device. The temporary key is used to encrypt the data transmitted through the Bluetooth serial communication connection.
[0005] This application discloses a Bluetooth connection device applied to a first Bluetooth device, the device comprising: The judgment module is used to determine whether the first application has data encryption function if a target Bluetooth command initiated by the first application is detected. The connection module is configured to, if the first application has the data encryption function, not generate a temporary key and establish a Bluetooth serial communication connection with the second Bluetooth device, wherein the temporary key is used to encrypt the data transmitted through the Bluetooth serial communication connection.
[0006] This application discloses an electronic device, including a memory, a processor, and a transceiver unit. The memory stores a computer program, and when the computer program is executed by the processor, the electronic device performs the method described above.
[0007] This application discloses a computer-readable storage medium storing a computer program thereon, which, when executed by a processor in an electronic device, causes the electronic device to implement the method described above.
[0008] This application discloses a Bluetooth connection method, apparatus, electronic device, and computer-readable storage medium. If a first Bluetooth device detects a target Bluetooth command initiated by a first application, it determines whether the first application has data encryption functionality. If the first application has data encryption functionality, no temporary key is generated, and a Bluetooth serial communication connection is established with a second Bluetooth device. In this application embodiment, when the first application initiating the target Bluetooth command has data encryption functionality, the transmitted data is encrypted, ensuring data transmission security. Therefore, the process of generating a temporary key can be skipped, and the first Bluetooth device can directly establish a Bluetooth serial communication connection with the second Bluetooth device, saving the time spent generating a temporary key. This ensures data transmission security and improves the speed at which the first Bluetooth device and the second Bluetooth device establish a Bluetooth serial communication connection. Attached Figure Description
[0009] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0010] Figure 1 A schematic diagram illustrating the establishment of a Bluetooth connection between two Bluetooth devices in a related technology. Figure 2 This is an application scenario diagram of the Bluetooth connection method in one embodiment; Figure 3 Here is a flowchart of a Bluetooth connection method in one embodiment; Figure 4 A flowchart of a Bluetooth connection method in another embodiment; Figure 5 This is a timing diagram of a Bluetooth connection method in one embodiment; Figure 6 Here is a flowchart of a Bluetooth connection method in another embodiment; Figure 7 This is a block diagram of a Bluetooth connectivity device in one embodiment; Figure 8 This is a structural block diagram of an electronic device in one embodiment. Detailed Implementation
[0011] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0012] It should be noted that the terms "comprising" and "having," and any variations thereof, in the embodiments and accompanying drawings of this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the steps or units listed, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices.
[0013] It is understood that the terms "first," "second," etc., used in this application may be used herein to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish one element from another. For example, without departing from the scope of this application, a second Bluetooth device may be referred to as a first Bluetooth device, and similarly, a first Bluetooth device may be referred to as a second Bluetooth device. Both the second Bluetooth device and the first Bluetooth device are Bluetooth devices, but they are not the same Bluetooth device. The term "multiple" as used in this application refers to two or more. The term "and / or" as used in this application refers to one of the solutions, or any combination of multiple solutions.
[0014] In related technologies, in scenarios where two Bluetooth devices need to transmit data, one Bluetooth device can use BLE (Bluetooth Low Energy) broadcasting to scan and discover the other device. The two devices can then establish a BLE connection and then establish a classic Bluetooth SPP Socket (Serial Port Profile Socket) connection.
[0015] For example, it can be as follows Figure 1As shown, after establishing a BLE connection, the two Bluetooth devices exchange data via GATT (Generic Attribute Profile). Since GATT data exchange does not require encryption, the two Bluetooth devices do not perform a key pairing process. Subsequently, the two Bluetooth devices establish a classic Bluetooth connection. To ensure data transmission security, the classic Bluetooth SPP Socket connection needs to be encrypted. In Insecure SPP mode, a temporary key, such as a temporary Link Key, is generated before establishing the SPP Socket connection. The two Bluetooth devices can then use this SPP Socket connection for data transmission. Because the two Bluetooth devices generate a temporary key before each SPP Socket connection establishment, this process takes 1-2 seconds, affecting the Bluetooth connection speed.
[0016] Figure 2 This is a diagram illustrating an application scenario of a Bluetooth connection method in one embodiment. For example... Figure 2 As shown, a Bluetooth connection can be established between the first Bluetooth device 210 and the second Bluetooth device 220. The first Bluetooth device 210 and the second Bluetooth device 220 may include, but are not limited to, mobile phones, vehicle terminals, wearable devices, tablets, PCs (personal computers), smart home devices and other electronic devices that support Bluetooth communication functions. The first Bluetooth device 210 and the second Bluetooth device 220 may be the same type of electronic device or different types of electronic devices.
[0017] The Bluetooth connection established between the first Bluetooth device 210 and the second Bluetooth device 220 may include, but is not limited to, classic Bluetooth connection and BLE connection. Here, classic Bluetooth connection refers to a Bluetooth communication connection established based on the classic Bluetooth protocol, and BLE connection refers to a Bluetooth communication connection established based on the BLE protocol. Classic Bluetooth protocol generally refers to Bluetooth protocols below version 4.0, while BLE protocol generally refers to Bluetooth protocols above version 4.0.
[0018] Furthermore, the first Bluetooth device 210 and the second Bluetooth device 220 can be electronic devices that support dual-mode Bluetooth, which means electronic devices that simultaneously support both the classic Bluetooth protocol and the BLE protocol. The first Bluetooth device 210 and the second Bluetooth device 220 can simultaneously establish both a BLE connection and a classic Bluetooth connection.
[0019] In this embodiment, if the first Bluetooth device 210 detects a target Bluetooth command initiated by the first application, it can determine whether the first application has data encryption functionality. If the first application has data encryption functionality, the first Bluetooth device 210 and the second Bluetooth device 220 do not need to generate a temporary key; they can directly establish a Bluetooth serial communication connection. The temporary key is used to encrypt the data transmitted through the Bluetooth serial communication connection. This saves the time spent generating a temporary key and improves the speed at which the first Bluetooth device 210 and the second Bluetooth device 220 establish a Bluetooth serial communication connection.
[0020] like Figure 3 As shown, in one embodiment, a Bluetooth connection method is provided, which can be applied to the first Bluetooth device described above. The method may include the following steps: Step 310: If a target Bluetooth command initiated by the first application is detected, determine whether the first application has data encryption function. If yes, proceed to step 320; otherwise, proceed to step 330.
[0021] The first Bluetooth device may have one or more applications installed. During the operation of the first application, if the first application has a communication requirement, it can initiate a target Bluetooth command. This target Bluetooth command can be used to instruct the establishment of a Bluetooth connection with the second Bluetooth device. Further, this target Bluetooth command can be used to instruct the establishment of a Bluetooth serial communication connection with the second Bluetooth device. This communication requirement may include the need to establish a Bluetooth connection with the second Bluetooth device and transmit data with it, or the need to transmit data with the second Bluetooth device with which a Bluetooth connection has already been established. Further, this communication requirement may be the need to establish a Bluetooth communication channel with a third application in the second Bluetooth device and transmit data with that third application. Optionally, the third application may be the same application as the first application, or an application belonging to the same application family as the first application. For example, the first application may be a video application A on a mobile client, and the second application may be a video application A on a TV client.
[0022] In some embodiments, when the first application has communication requirements, it can invoke a Bluetooth connection interface to generate target Bluetooth commands. Optionally, the Bluetooth connection interface may include a serial communication connection interface. By invoking the serial communication connection interface, target Bluetooth commands can be generated to instruct the establishment of a Bluetooth serial communication connection. This Bluetooth serial communication connection refers to creating a serial communication channel between two Bluetooth devices, allowing the two Bluetooth devices to transmit data streams via serial communication. The serial communication connection interface may include an SPP socket connection interface, such as interfaces related to the BluetoothSocket class.
[0023] If the first Bluetooth device detects a target Bluetooth command initiated by the first application, it can determine whether the first application has data encryption capabilities. This data encryption capability refers to the ability to encrypt transmitted data. If the first application has data encryption capabilities, it will encrypt the data to be transmitted before sending it to the Bluetooth module of the first Bluetooth device, which will then transmit it to other Bluetooth devices.
[0024] In some embodiments, the first Bluetooth device may pre-store a list of encrypted applications. This list may include application information for one or more applications with data encryption capabilities. This application information may include, but is not limited to, one or more of the following: application name, package name, application ID, version number, and vendor information. If the first Bluetooth device detects a target Bluetooth command initiated by the first application, it can obtain the application information of the first application and compare it with the application information of each application stored in the encrypted application list to determine whether the encrypted application list contains the application information of the first application. If the encrypted application list contains the application information of the first application, it can be determined that the first application has data encryption capabilities; if the encrypted application list does not contain the application information of the first application, it can be determined that the first application does not have data encryption capabilities.
[0025] Optionally, the application information of applications with data encryption capabilities included in the encrypted application list can be obtained by the manufacturer of the first Bluetooth device and maintained in the first Bluetooth device. For example, the manufacturer of the first Bluetooth device can analyze whether various applications on the market have data encryption capabilities, obtain the application information of applications with data encryption capabilities, generate an encrypted application list, and store it in the first Bluetooth device. The manufacturer can update and maintain the encrypted application list by uploading each updated encrypted application list to a server, which then distributes it to the first Bluetooth device to update the encrypted application list stored in the first Bluetooth device. Furthermore, the applications included in the encrypted application list maintained by the manufacturer can be applications frequently used by users of the Bluetooth device. For example, the manufacturer can obtain applications with download numbers exceeding a preset value and analyze whether they have data encryption capabilities. The analysis can be conducted by detecting whether the data stream transmitted by the application is encrypted data, or by confirming with the application's development team whether the application has data encryption capabilities, but is not limited to these methods.
[0026] Optionally, the first Bluetooth device can also update the encrypted application list itself. When a new application is installed on the first Bluetooth device, it can analyze the application's code and determine whether the new application has data encryption capabilities. Alternatively, the first Bluetooth device can intercept the data transmitted by the new application for the first time and analyze whether the transmitted data is encrypted to determine whether the new application has data encryption capabilities. If it is determined that the new application has data encryption capabilities, its application information can be added to the encrypted application list.
[0027] The first Bluetooth device determines whether the first application has data encryption capabilities by storing a list of encrypted applications. This method is simple and quick.
[0028] In other embodiments, the target Bluetooth command initiated by the first application may carry an encrypted field. This encrypted field can be used to indicate whether the first application has data encryption capabilities. The encrypted field can be a string composed of one or more of numbers, letters, and symbols. For example, an encrypted field of "Yes" indicates that the first application has data encryption capabilities, while an encrypted field of "No" indicates that the first application does not have data encryption capabilities. The first application can generate a target Bluetooth command carrying the corresponding encrypted field based on whether it has data encryption capabilities. The first Bluetooth device detects the target Bluetooth command and determines whether the first application has data encryption capabilities based on the encrypted field carried by the target Bluetooth command, which can more accurately determine whether the first application has data encryption capabilities.
[0029] Step 320: Do not generate a temporary key, and establish a Bluetooth serial communication connection with the second Bluetooth device.
[0030] When the first application has data encryption capabilities, the first and second Bluetooth devices can skip the key generation process and directly establish a Bluetooth serial communication connection without generating a temporary key. The key generation process refers to the process of generating a temporary key for the Bluetooth serial communication connection, which is used to encrypt the data transmitted over that connection. The temporary key may include a temporary link key, etc. This temporary key is only used to encrypt the Bluetooth serial communication connection established at that time. Once the connection is established, the temporary key becomes invalid, and a new temporary key is generated when the connection is re-established.
[0031] If the first application has data encryption capabilities, it means that the first application will encrypt the data transmitted to other Bluetooth devices. Therefore, there is no need for secondary encryption of the Bluetooth serial communication connection. In this embodiment, if the first application has data encryption capabilities, the first Bluetooth device and the second Bluetooth device can skip the key generation process, not generate a temporary key, and not encrypt the Bluetooth serial communication connection for data transmission. The first Bluetooth device directly establishes a Bluetooth serial communication connection with the second Bluetooth device. This Bluetooth serial communication connection can be used to transmit application data of the first application, including sending data of the first application to the second Bluetooth device and / or receiving data sent to the first application by the second Bluetooth device.
[0032] In one specific implementation, the first Bluetooth device can establish a classic Bluetooth link with the second Bluetooth device, such as an ACL link or an SCO link. After establishing the classic Bluetooth link, no temporary key is generated, and a Bluetooth serial communication connection is directly established with the second Bluetooth device. For example, after establishing an ACL link with the second Bluetooth device, the first Bluetooth device directly establishes an SPP Socket connection.
[0033] The second Bluetooth device can be any other Bluetooth device around the first Bluetooth device. The first Bluetooth device can scan for the second Bluetooth device and establish a Bluetooth connection with it.
[0034] Furthermore, the second Bluetooth device can be a Bluetooth device with a third application installed and running. The first application in the first Bluetooth device can initiate a target Bluetooth command. Based on the target Bluetooth command, the first Bluetooth device establishes a Bluetooth serial communication connection with the second Bluetooth device, enabling data transmission between the first application in the first Bluetooth device and the third application in the second Bluetooth device. The third application can be the same application as the first application, or an application belonging to the same application family as the first application. Therefore, if the first application has data encryption capabilities, the third application also has data encryption capabilities. Even without encrypting the Bluetooth serial communication connection, the security of the transmitted data can be guaranteed by both the first and third applications.
[0035] Step 330: Perform the key generation process to generate a temporary key and establish a Bluetooth serial communication connection with the second Bluetooth device.
[0036] If the first application lacks data encryption capabilities, to ensure data transmission security, the first and second Bluetooth devices can engage in a key generation process. They negotiate and generate a temporary key, and after generating the temporary key, establish a Bluetooth serial communication connection. This Bluetooth serial communication connection can be used to transmit application data from the first application, including sending data from the first application to the second Bluetooth device and / or receiving data sent from the second Bluetooth device to the first application. Data transmitted between the first and second Bluetooth devices via this Bluetooth serial communication connection can be encrypted using the temporary key to ensure data transmission security.
[0037] In one specific implementation, the first Bluetooth device can establish a classic Bluetooth link with the second Bluetooth device, such as an ACL link or an SCO link. After establishing the classic Bluetooth link, a key generation process is performed, and the two devices negotiate to generate a temporary key. After generating the temporary key, a Bluetooth serial communication connection is established.
[0038] By determining whether the first application initiating the target Bluetooth command has data encryption capabilities and flexibly adjusting the key generation process, the connection speed of Bluetooth serial communication can be improved.
[0039] In this embodiment, when the first application that initiates the target Bluetooth command has a data encryption function, the transmitted data will be encrypted due to the data encryption function of the first application, thus ensuring the security of data transmission. Therefore, the key generation process of generating a temporary key can be skipped, and the first Bluetooth device can directly establish a Bluetooth serial communication connection with the second Bluetooth device, saving the time spent on the key generation process. This not only ensures the security of data transmission, but also improves the speed at which the first Bluetooth device and the second Bluetooth device establish a Bluetooth serial communication connection.
[0040] like Figure 4 As shown, in another embodiment, a Bluetooth connection method is provided, which can be applied to the first Bluetooth device described above. The method may include the following steps: Step 402: If a target Bluetooth command initiated by the first application is detected, scan and obtain the device information of the second Bluetooth device.
[0041] If the first Bluetooth device detects the target Bluetooth command initiated by the first application, it can scan for nearby Bluetooth devices based on the target Bluetooth command and obtain the device information of the scanned second Bluetooth device.
[0042] In one implementation, the first Bluetooth device can activate scanning mode and scan for surrounding Bluetooth devices. The first Bluetooth device can send a scan request to a nearby second Bluetooth device. Upon receiving the scan request, the second Bluetooth device can return a scan response to the first Bluetooth device. The first Bluetooth device can obtain the device information of the second Bluetooth device based on the received scan response. This device information may include, but is not limited to, one or more of the following: the second Bluetooth device's Bluetooth address (such as a classic Bluetooth address, BLE address, etc.), the Bluetooth device's device name, and its MAC address.
[0043] In another implementation, the first Bluetooth device can send a BLE broadcast signal, which can be used to scan for Bluetooth devices in the vicinity of the first Bluetooth device. When the second Bluetooth device receives the BLE broadcast signal, it can send a response message to the first Bluetooth device. The first Bluetooth device can receive the response message sent by the second Bluetooth device in response to the BLE broadcast signal and obtain the device information of the second Bluetooth device based on the response message. Furthermore, the first Bluetooth device can establish a BLE connection with the second Bluetooth device based on the device information of the second Bluetooth device, and then establish a classic Bluetooth connection after establishing the BLE connection.
[0044] Optionally, when the first Bluetooth device sends a scan request or BLE broadcast signal, the scan request or BLE broadcast signal may carry application information of the first application. The scan request or BLE broadcast signal can be used to scan for Bluetooth devices with a third application installed around the first Bluetooth device. When the second Bluetooth device receives the scan request or BLE broadcast signal sent by the first Bluetooth device, it can parse the received scan request or BLE broadcast signal to obtain the application information of the first application. Based on the application information of the first application, it can determine whether it is running the same application or an application belonging to the same application family as the first application, i.e., whether it is running the third application. If the second Bluetooth device is running the third application, it can respond to the received scan request or BLE broadcast signal, thereby establishing a Bluetooth serial communication connection with the first Bluetooth device to realize data transmission between the first application and the third application. By carrying the application information of the first application in the scan request or BLE broadcast signal, it is possible to scan and discover second Bluetooth devices with the same application or the same application series installed around the first Bluetooth device. This allows the data transmission channel between the two applications to be established, and makes the determination of whether to perform the key generation process more accurate. It also avoids the situation where the first application has data encryption function but the data sent by the second Bluetooth device is not encrypted, thus reducing the risk of data leakage.
[0045] Step 404: Determine whether the first application has data encryption function. If yes, proceed to step 406; otherwise, proceed to step 410.
[0046] The description of step 404 can be found in the description of step 310 in the above embodiments, and will not be repeated here.
[0047] It should be noted that step 404 can be performed before the first Bluetooth device scans and obtains the device information of the second Bluetooth device, or after the first Bluetooth device scans and obtains the device information of the second Bluetooth device, or both can be performed simultaneously. This application embodiment does not limit the timing relationship between the two steps.
[0048] Step 406: Establish a classic Bluetooth link with the second Bluetooth device based on the device information of the second Bluetooth device, without generating a temporary key, and establish a Bluetooth serial communication connection with the second Bluetooth device.
[0049] When the first application has data encryption capabilities, the first Bluetooth device can establish a classic Bluetooth link with the second Bluetooth device based on the device information of the second Bluetooth device. After establishing the classic Bluetooth link, the key generation process is skipped, no temporary key is generated, and a Bluetooth serial communication connection is directly established with the second Bluetooth device.
[0050] For example, Figure 5 This is a timing diagram of a Bluetooth connection method in one embodiment. Figure 5 As shown, Bluetooth device B can send a BLE broadcast. After receiving the BLE broadcast from Bluetooth device B, Bluetooth device A can respond to the broadcast and establish a BLE connection with Bluetooth device B. Bluetooth device A can then exchange BLE GATT data with Bluetooth device B. After the BLE GATT data exchange, Bluetooth device A and Bluetooth device B can establish a classic Bluetooth connection. Furthermore, Bluetooth device A and Bluetooth device B can establish classic Bluetooth links such as ACLs, and then establish an SPP Socket connection. After establishing the SPP Socket connection, the two devices can transmit application data through this SPP Socket connection. Compared to... Figure 1 The Bluetooth connection process shown in the related technologies reduces the process of generating temporary keys and improves the speed of establishing SPP Socket connections in dual-connection scenarios.
[0051] Step 408: Obtain the third data to be transmitted by the first application, and send the third data to the second Bluetooth device through the Bluetooth serial communication connection; the third data is data encrypted by the first application; and / or, receive the fourth data sent by the second Bluetooth device through the Bluetooth serial communication connection, the fourth data is encrypted and sent by the third application running in the second Bluetooth device.
[0052] When the first application has data encryption capabilities, and the first Bluetooth device and the second Bluetooth device transmit data via an established Bluetooth serial communication connection, the first application can encrypt the data to be transmitted to obtain third data, which is then transmitted to the Bluetooth module. The Bluetooth module of the first Bluetooth device obtains the third data to be transmitted from the first application and sends the third data to the second Bluetooth device via the Bluetooth serial communication connection. In some embodiments, after receiving the third data sent by the first Bluetooth device, the Bluetooth module of the second Bluetooth device can transmit the third data to the upper-layer third application, which decrypts the third data to obtain the data sent by the first application.
[0053] Similarly, the second Bluetooth device can also send fourth data to the first Bluetooth device via Bluetooth serial communication. The third application running on the second Bluetooth device can encrypt the data to be transmitted, obtain the fourth data, and then transmit the fourth data to the Bluetooth module. The Bluetooth module of the second Bluetooth device obtains the fourth data to be transmitted from the third application and sends it to the first Bluetooth device via Bluetooth serial communication. After receiving the fourth data sent by the second Bluetooth device, the Bluetooth module of the first Bluetooth device can pass the fourth data to the upper-layer first application. The first application decrypts the third data to obtain the data sent by the third application.
[0054] In this embodiment of the application, when the first application has data encryption function, the Bluetooth module of the first Bluetooth device does not need to encrypt and decrypt the transmitted data. After the Bluetooth module obtains the data transmitted by the upper-layer application, it directly transmits the data through the Bluetooth serial port communication connection, which improves data transmission efficiency while ensuring data security.
[0055] Step 410: Establish a classic Bluetooth link with the second Bluetooth device based on the device information of the second Bluetooth device, perform a key generation process to generate a temporary key, and establish a Bluetooth serial communication connection with the second Bluetooth device.
[0056] If the first application does not have data encryption capabilities, the first Bluetooth device can establish a classic Bluetooth link with the second Bluetooth device based on the device information of the second Bluetooth device. After establishing the classic Bluetooth link, a key generation process is performed to generate a temporary key, and then a Bluetooth serial communication connection is established with the second Bluetooth device.
[0057] Step 412: Obtain the first data to be transmitted by the first application, encrypt the first data to be transmitted according to the temporary key, and send the encrypted first data to the second Bluetooth device through the Bluetooth serial communication connection; and / or, receive the second data sent by the second Bluetooth device through the Bluetooth serial communication connection, decrypt the second data according to the temporary key, and obtain the decrypted second data.
[0058] When the first application lacks data encryption capabilities, and data is transmitted between the first Bluetooth device and the second Bluetooth device via an established Bluetooth serial communication connection, the first application can send the first data to be transmitted to the Bluetooth module. The Bluetooth module can encrypt the first data to be transmitted by the first application using a temporary key, and then send the encrypted first data to the second Bluetooth device via the Bluetooth serial communication connection. In some embodiments, after receiving the encrypted first data sent by the first Bluetooth device, the Bluetooth module of the second Bluetooth device can decrypt the encrypted first data using a temporary key to obtain the first data transmitted by the first application, and then pass the first data to the upper-layer application.
[0059] Similarly, the second Bluetooth device can also send data to the first Bluetooth device via Bluetooth serial communication. The Bluetooth module of the second Bluetooth device can encrypt the data to be transmitted using a temporary key to obtain the second data, and then send the second data to the first Bluetooth device via Bluetooth serial communication. After receiving the second data sent by the second Bluetooth device via Bluetooth serial communication, the Bluetooth module of the first Bluetooth device can decrypt the second data using the temporary key to obtain the decrypted second data, and then pass the decrypted second data to the upper-layer first application.
[0060] It should be noted that the Bluetooth device described above encrypts data using a temporary key, which can be either direct or indirect encryption. Direct encryption refers to directly using the temporary key as the encryption key to encrypt the data; indirect encryption refers to generating an encryption key based on the temporary key and using the generated encryption key to encrypt the data. This application does not limit the specific method used for encrypting and decrypting data transmitted via Bluetooth serial communication.
[0061] In this embodiment, it can be determined whether the first application initiating the target Bluetooth command has data encryption functionality, and flexibly proceed with the key generation process. If the first application initiating the target Bluetooth command has data encryption functionality, the first Bluetooth device directly establishes a Bluetooth serial communication connection with the second Bluetooth device, omitting the key generation process before establishing the Bluetooth serial communication connection, thus improving the speed of establishing the Bluetooth serial communication connection. If the first application initiating the target Bluetooth command does not have data encryption functionality, then the key generation process is performed, which can ensure the security of data transmission and improve the flexibility of Bluetooth applications.
[0062] like Figure 6 As shown, in another embodiment, a Bluetooth connection method is provided, which can be applied to the first Bluetooth device described above. The method may include the following steps: Step 602: If a target Bluetooth command initiated by the first application is detected, scan and obtain the device information of the second Bluetooth device.
[0063] The description of step 602 can be found in the description of step 402 in the above embodiments, and will not be repeated here.
[0064] Step 604: Identify the Bluetooth connection type corresponding to the target Bluetooth command.
[0065] The first Bluetooth device can identify the Bluetooth connection type corresponding to the target Bluetooth command initiated by the first application. The Bluetooth connection type refers to the type of Bluetooth connection to be established. The Bluetooth connection type may include any one of the following, but is not limited to: pairing connection type, Bluetooth socket type, BLE connection type, etc.
[0066] The pairing connection type refers to establishing a Bluetooth connection and pairing operation with a second Bluetooth device. This pairing operation involves the two Bluetooth devices negotiating and generating a link key. This link key is used to encrypt data transmitted over the Bluetooth connection. Unlike temporary keys, this link key is a persistent key that can be stored in both Bluetooth devices. Even if the two Bluetooth devices disconnect and then re-establish the Bluetooth connection, the data transmitted over the Bluetooth connection can still be encrypted. Pairing operations typically occur in scenarios such as the first time two Bluetooth devices establish a Bluetooth connection, or when two Bluetooth devices establish a connection before but have not previously paired, or when two Bluetooth devices have previously paired but deleted the generated link key.
[0067] The Bluetooth socket type refers to establishing a Bluetooth serial communication connection with a second Bluetooth device. Further, the Bluetooth socket type can refer to establishing an SPP socket connection with a second Bluetooth device.
[0068] BLE connection type refers to establishing a BLE connection with a second Bluetooth device.
[0069] In one specific implementation, upon detecting a target Bluetooth command initiated by a first application, the first Bluetooth device can obtain the Bluetooth connection interface invoked by the first application and identify the Bluetooth connection type corresponding to the target Bluetooth command based on the Bluetooth connection interface invoked by the first application. For example, if the first application invokes an SPP socket connection interface, the Bluetooth connection type corresponding to the target Bluetooth command can be determined to be a Bluetooth socket type. If the first application invokes a device connection interface, such as an interface related to the BluetoothDevice class, the Bluetooth connection type corresponding to the target Bluetooth command can be determined to be a pairing connection type.
[0070] Optionally, since pairing is performed during Bluetooth connection establishment when the target Bluetooth command is a pairing connection type, or if pairing has been performed previously, the two Bluetooth devices store a link key. Subsequent Bluetooth serial communication connections can directly utilize this stored link key for data encryption, thus eliminating the need for a temporary key generation process. However, for BLE connection types, only a BLE connection is established between the two Bluetooth devices, not a Bluetooth serial communication connection. Therefore, in this embodiment, when the Bluetooth connection type corresponding to the target Bluetooth command initiated by the first application is not a Bluetooth socket type, it is not necessary to determine whether the first application has data encryption capabilities. A Bluetooth connection can be directly established with the second Bluetooth device based on the target Bluetooth command, improving Bluetooth connection efficiency.
[0071] If the Bluetooth connection type corresponding to the target Bluetooth command initiated by the first application is a Bluetooth socket type, the first Bluetooth device can determine whether the first application has data encryption function, and thus determine whether to proceed with the key generation process to generate a temporary key.
[0072] In some embodiments, when the first Bluetooth device detects a target Bluetooth command initiated by the first application, before establishing a Bluetooth serial communication connection with the second Bluetooth device, it can first determine whether a link key corresponding to the second Bluetooth device is stored. This link key refers to the link key generated during the pairing operation, which can be performed during the current Bluetooth connection establishment process between the first Bluetooth device and the second Bluetooth device, or during a previous Bluetooth connection establishment process. If a link key corresponding to the second Bluetooth device is stored, since the data transmitted through the subsequently established Bluetooth serial communication connection can be encrypted using this link key, a key generation process is not required, and it is not necessary to determine whether the first application has data encryption capabilities. Regardless of whether the first application has data encryption capabilities, the first Bluetooth device can directly establish a Bluetooth serial communication connection with the second Bluetooth device and encrypt the data transmitted through the Bluetooth serial communication connection according to the stored link key to ensure data security.
[0073] In this application embodiment, in scenarios where a key generation process is performed in related technologies, it is determined whether the first application scenario that initiates the target Bluetooth command has data encryption function, thereby determining whether to perform the key generation process, improving the flexibility of Bluetooth connection, and improving the connection speed of Bluetooth serial communication connection.
[0074] Step 606: If the Bluetooth connection type is Bluetooth socket type, determine whether the first application has data encryption function. If yes, proceed to step 608; otherwise, proceed to step 612.
[0075] Step 608: Establish a classic Bluetooth link with the second Bluetooth device based on the device information of the second Bluetooth device, without generating a temporary key, and establish a Bluetooth serial communication connection with the second Bluetooth device.
[0076] Step 610: Obtain the third data to be transmitted by the first application, and send the third data to the second Bluetooth device through the Bluetooth serial communication connection; the third data is data encrypted by the first application; and / or, receive the fourth data sent by the second Bluetooth device through the Bluetooth serial communication connection, the fourth data is encrypted and sent by the third application running in the second Bluetooth device.
[0077] Step 612: Establish a classic Bluetooth link with the second Bluetooth device based on the device information of the second Bluetooth device, perform a key generation process to generate a temporary key, and establish a Bluetooth serial communication connection with the second Bluetooth device.
[0078] Step 614: Obtain the first data to be transmitted by the first application, encrypt the first data to be transmitted according to the temporary key, and send the encrypted first data to the second Bluetooth device through the Bluetooth serial communication connection; and / or, receive the second data sent by the second Bluetooth device through the Bluetooth serial communication connection, decrypt the second data according to the temporary key, and obtain the decrypted second data.
[0079] The descriptions of steps 606 to 614 can be found in the relevant descriptions in the above embodiments, and will not be repeated here.
[0080] In some embodiments, if the first Bluetooth device detects that the first application has stopped communicating, it disconnects the Bluetooth serial communication connection. Optionally, the first Bluetooth device detecting that the first application has stopped communicating could be due to the first Bluetooth device detecting that the first application has stopped running (e.g., the first application has been closed), or it could be due to a user performing a disconnection operation within the first application. If the first Bluetooth device detects a disconnection operation for the first application, it can determine that the first application has stopped communicating.
[0081] When the first Bluetooth device detects that the first application has stopped communicating, it can disconnect the Bluetooth serial communication connection. After disconnecting the Bluetooth serial communication connection, if it detects a target Bluetooth command initiated by the second application, the first Bluetooth device can determine whether the second application has data encryption capabilities. If the second application has data encryption capabilities, it will not generate a temporary key and will establish a Bluetooth serial communication connection with the second Bluetooth device. This established Bluetooth serial communication connection can be used to transmit application data of the second application, including sending data from the second application to the second Bluetooth device and / or receiving data sent from the second application by the second Bluetooth device.
[0082] In the event of an application switch on the first Bluetooth device, such as switching from the first application to the second application, the Bluetooth serial communication connection corresponding to the first application is disconnected. When the second application has a communication requirement, the second application can generate a target Bluetooth command by adjusting the Bluetooth connection interface. The first Bluetooth device can determine whether the second application that initiates the target Bluetooth command has data encryption capabilities, and thus decide whether to perform a key generation process before establishing a Bluetooth serial communication connection corresponding to the second application with the second Bluetooth device.
[0083] It should be noted that the process by which the first Bluetooth device determines whether the second application has data encryption capabilities, and the process by which the second application transmits data via Bluetooth serial communication, is similar to the process described in the above embodiments, whereby the first Bluetooth device determines whether the first application has data encryption capabilities, and the process by which the first application transmits data via Bluetooth serial communication. Therefore, it will not be repeated here. Optionally, since the first Bluetooth device previously established a Bluetooth connection with the second Bluetooth device, when disconnecting the Bluetooth serial communication connection corresponding to the first application, the classic Bluetooth link between the first and second Bluetooth devices can be preserved. This eliminates the need to re-establish the classic Bluetooth link before establishing a new Bluetooth serial communication connection with the second Bluetooth device (i.e., the Bluetooth serial communication connection corresponding to the second application).
[0084] In this embodiment, for target Bluetooth commands initiated by different applications, the first Bluetooth device can determine whether the application initiating the target Bluetooth command has data encryption function, thereby determining whether to proceed with the key generation process. This balances the security of data transmission with the speed of establishing a Bluetooth serial communication connection, thus improving the flexibility of the Bluetooth connection.
[0085] like Figure 7 As shown, in one embodiment, a Bluetooth connection device 700 is provided, which can be applied to the first Bluetooth device described above. The Bluetooth connection device 700 may include a judgment module 710 and a connection module 720.
[0086] The judgment module 710 is used to determine whether the first application has data encryption function if a target Bluetooth command initiated by the first application is detected.
[0087] The connection module 720 is used to establish a Bluetooth serial communication connection with the second Bluetooth device without generating a temporary key if the first application has data encryption function. The temporary key is used to encrypt the data transmitted through the Bluetooth serial communication connection.
[0088] In one embodiment, the Bluetooth connectivity device 700 further includes a data transmission module.
[0089] The connection module 720 is also used to perform a key generation process to generate a temporary key and establish a Bluetooth serial communication connection with the second Bluetooth device if the first application does not have data encryption functionality.
[0090] The data transmission module is used to acquire first data to be transmitted by the first application, encrypt the first data to be transmitted according to a temporary key, and send the encrypted first data to the second Bluetooth device through a Bluetooth serial communication connection; and / or, receive second data sent by the second Bluetooth device through a Bluetooth serial communication connection, decrypt the second data according to a temporary key, and obtain the decrypted second data.
[0091] In one embodiment, the Bluetooth connectivity device 700 further includes a scanning module.
[0092] The scanning module is used to scan and obtain device information of the second Bluetooth device.
[0093] The connection module 720 is also used to establish a classic Bluetooth link with the second Bluetooth device based on the device information of the second Bluetooth device, without generating a temporary key, and to establish a Bluetooth serial communication connection with the second Bluetooth device.
[0094] In one embodiment, the scanning module is further configured to send a BLE broadcast signal for scanning Bluetooth devices around the first Bluetooth device; receive response information from the second Bluetooth device in response to the BLE broadcast signal; and obtain device information of the second Bluetooth device based on the response information.
[0095] The connection module 720 is also used to establish a BLE connection with the second Bluetooth device based on the device information of the second Bluetooth device.
[0096] In one embodiment, the data transmission module is further configured to acquire third data to be transmitted by the first application and send the third data to the second Bluetooth device via a Bluetooth serial communication connection; the third data is data encrypted by the first application; and / or, receive fourth data sent by the second Bluetooth device via a Bluetooth serial communication connection, the fourth data being encrypted and sent by the third application running in the second Bluetooth device.
[0097] In one embodiment, the connection module 720 is further configured to disconnect the Bluetooth serial communication connection if it detects that the first application has stopped communicating.
[0098] The judgment module 710 is also used to determine whether the second application has data encryption function if a target Bluetooth command initiated by the second application is detected.
[0099] The connection module 720 is also configured to not generate a temporary key and establish a Bluetooth serial communication connection with the second Bluetooth device if the second application has the data encryption function.
[0100] In this embodiment, when the first application that initiates the target Bluetooth command has a data encryption function, the transmitted data will be encrypted due to the data encryption function of the first application, thus ensuring the security of data transmission. Therefore, the key generation process of generating a temporary key can be skipped, and the first Bluetooth device can directly establish a Bluetooth serial communication connection with the second Bluetooth device, saving the time spent on the key generation process. This not only ensures the security of data transmission, but also improves the speed at which the first Bluetooth device and the second Bluetooth device establish a Bluetooth serial communication connection.
[0101] Figure 8 This is a structural block diagram of an electronic device in one embodiment. For example... Figure 8 As shown, the electronic device 800 may include one or more of the following components: a processor 810 and a memory 820 coupled to the processor 810, wherein the memory 820 may store one or more computer programs, and the one or more computer programs may be configured to cause the electronic device 800 to perform the methods described in the above embodiments when executed by one or more processors 810.
[0102] The processor 810 may include one or more processing cores. The processor 810 connects to various parts within the electronic device 800 using various interfaces and lines, and performs various functions and processes data of the electronic device 800 by running or executing instructions, programs, code sets, or instruction sets stored in the memory 820, and by calling data stored in the memory 820. Optionally, the processor 810 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 810 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the displayed content; and the modem handles wireless communication. It is understood that the modem may also not be integrated into the processor 810 and may be implemented separately using a communication chip.
[0103] The memory 820 may include random access memory (RAM) or read-only memory (ROM). The memory 820 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 820 may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as touch functionality, sound playback functionality, image playback functionality, etc.), and instructions for implementing the various method embodiments described above. The data storage area may also store data created by the electronic device 800 during use.
[0104] The electronic device 800 may also include a transceiver unit, such as a Bluetooth module. The Bluetooth module can provide Bluetooth communication functionality, establish a Bluetooth connection with a second Bluetooth device, and perform Bluetooth data transmission. The Bluetooth module may support one or more Bluetooth protocols, such as Classic Bluetooth, BLE, BLE Audio, etc., but is not limited to these and may change as Bluetooth protocols evolve.
[0105] This application discloses a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor in an electronic device, the electronic device performs the methods described in the above embodiments.
[0106] This application discloses a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program, when executed by a processor in an electronic device, causes the electronic device to implement the methods described in the above embodiments.
[0107] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, ROM, etc.
[0108] Any references to memory, storage, databases, or other media used herein may include non-volatile and / or volatile memory. Suitable non-volatile memory may include ROM, Programmable ROM (PROM), Erasable PROM (EPROM), Electrically Erasable PROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM), which is used as an external cache memory. By way of illustration and not limitation, RAM may take many forms, such as Static RAM (SRAM), Dynamic Random Access Memory (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced Synchronous DRAM (ESDRAM), Synchlink DRAM (SLDRAM), Rambus DRAM (RDRAM), and Direct Rambus DRAM (DRDRAM).
[0109] It should be understood that the phrase "one embodiment" or "an embodiment" throughout the specification means that a specific feature, structure, or characteristic related to the embodiment is included in at least one embodiment of this application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. Those skilled in the art should also recognize that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily essential to this application. It should be noted that "multiple" in this application includes "two or more".
[0110] In the various embodiments of this application, it should be understood that the sequence number of each process does not necessarily imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0111] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; they can be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0112] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0113] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0114] The foregoing has provided a detailed description of a Bluetooth connection method, apparatus, electronic device, and computer-readable storage medium disclosed in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are merely for the purpose of helping to understand the method and its core ideas. Furthermore, those skilled in the art will recognize that, based on the ideas of this application, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of this application. It is understood that some technical features and means in this application can also be referenced to the relevant provisions of the Bluetooth standard, or combined with the relevant provisions of the Bluetooth standard.
Claims
1. A Bluetooth connection method, characterized by, Applied to a first Bluetooth device, the method includes: If a target Bluetooth command initiated by the first application is detected, it is determined whether the first application has data encryption capabilities. If the first application has the data encryption function, it will not generate a temporary key and will establish a Bluetooth serial communication connection with the second Bluetooth device. The temporary key is used to encrypt the data transmitted through the Bluetooth serial communication connection.
2. The method according to claim 1, characterized in that, After determining whether the first application has data encryption functionality, the method further includes: If the first application does not have the data encryption function, a key generation process is performed to generate a temporary key and establish a Bluetooth serial communication connection with the second Bluetooth device. The system acquires first data to be transmitted from the first application, encrypts the first data to be transmitted according to the temporary key, and sends the encrypted first data to the second Bluetooth device through the Bluetooth serial communication connection; and / or receives second data sent by the second Bluetooth device through the Bluetooth serial communication connection, decrypts the second data according to the temporary key, and obtains the decrypted second data.
3. The method according to claim 1 or 2, characterized in that, Before generating a temporary key and establishing a Bluetooth serial communication connection with the second Bluetooth device, the method further includes: Scan and obtain device information for the second Bluetooth device; The step of not generating a temporary key and establishing a Bluetooth serial communication connection with the second Bluetooth device includes: Establish a classic Bluetooth link with the second Bluetooth device based on the device information of the second Bluetooth device, without generating a temporary key, and establish a Bluetooth serial communication connection with the second Bluetooth device.
4. The method according to claim 3, characterized in that, The step of scanning and obtaining device information of the second Bluetooth device includes: Send a Bluetooth Low Energy (BLE) broadcast signal, the BLE broadcast signal being used to scan for Bluetooth devices in the vicinity of the first Bluetooth device; Receive response information from the second Bluetooth device in response to the BLE broadcast signal, and obtain device information of the second Bluetooth device based on the response information; Before establishing a classic Bluetooth link with the second Bluetooth device based on the device information of the second Bluetooth device, the method further includes: Establish a BLE connection with the second Bluetooth device based on the device information of the second Bluetooth device.
5. The method according to claim 1 or 2, characterized in that, If a target Bluetooth command initiated by the first application is detected, determining whether the first application has data encryption functionality includes: If a target Bluetooth command initiated by the first application is detected, the Bluetooth connection type corresponding to the target Bluetooth command is identified. If the Bluetooth connection type is Bluetooth socket type, then determine whether the first application has data encryption function.
6. The method according to claim 1, characterized in that, The method further includes: The first application acquires the third data to be transmitted and sends the third data to the second Bluetooth device via the Bluetooth serial communication connection; the third data is data encrypted by the first application; and / or, The system receives fourth data sent by the second Bluetooth device via the Bluetooth serial communication connection. The fourth data is encrypted and sent by a third application running on the second Bluetooth device.
7. The method according to claim 1 or 2, characterized in that, The method further includes: If the first application is detected to have stopped communicating, the Bluetooth serial communication connection is disconnected. If a target Bluetooth command initiated by a second application is detected, it is determined whether the second application has data encryption capabilities. If the second application has the data encryption function, it will not generate a temporary key and will establish a Bluetooth serial communication connection with the second Bluetooth device.
8. A Bluetooth connection device, characterized in that, Applied to a first Bluetooth device, the device includes: The judgment module is used to determine whether the first application has data encryption function if a target Bluetooth command initiated by the first application is detected. The connection module is configured to, if the first application has the data encryption function, not generate a temporary key and establish a Bluetooth serial communication connection with the second Bluetooth device, wherein the temporary key is used to encrypt the data transmitted through the Bluetooth serial communication connection.
9. An electronic device, characterized in that, The device includes a memory, a processor, and a transceiver unit. The memory stores a computer program, which, when executed by the processor, causes the electronic device to perform the method as described in any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor in an electronic device, the electronic device causes the electronic device to perform the method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Intelligent mobile device and BLE device pairing method
CN104768125A
Application program logging method and system based on vehicle bluetooth communication in mobile terminal
CN105471480A
