Method for automatically switching mac address of ble device and ble device
By dividing the MAC address of a BLE device into a fixed and a variable part, and automatically switching the variable part to solve the problem of iOS devices being unable to obtain the MAC address, a stable and secure connection for BLE devices is achieved, simplifying user operation.
Patent Information
- Application Number
- CN202211464076.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-22
- Publication Date
- 2026-02-06
- Estimated Expiration
- 2042-11-22
AI Technical Summary
iOS devices are unable to obtain the MAC address of BLE devices, which leads to security vulnerabilities and performance degradation during BLE connections. Furthermore, the process is cumbersome for users, requiring them to frequently clear pairing information to restore the connection.
The MAC address of BLE devices is divided into a fixed part and a variable part. The variable part of the MAC address is automatically switched by decrypting the handshake information to ensure that the MAC address is different for each connection, avoiding repeated connection and disconnection and simplifying user operation.
It achieves stable and secure BLE device connections, avoids repeated connection issues for iOS devices, simplifies user operation processes, and improves connection efficiency.
Smart Images

Figure CN115715001B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application relates to the field of wireless communication, and in particular to a method for automatically switching the Mac address of a BLE device and the BLE device. BACKGROUND
[0002] When BLE is connected, an Android phone can completely obtain broadcast information, and the Mac address of the BLE device can be obtained, but an iOS device cannot obtain the Mac address of the BLE device, and the Mac needs to be displayed in the broadcast to occupy the broadcast field.
[0003] When single-connection BLE is connected, a fixed Mac address is generally used, and in an application, in order to use the safety of connection, a mobile phone A and a vehicle BLE are connected in pairing, so as to be bound with the mobile phone A, and these processes are all identity confirmation based on the Mac address of the BLE. Based on the characteristics of the BLE HID, after the mobile phone A is bound with the vehicle BLE, the mobile phone A automatically connects the BLE, and when the BLE clears local pairing information, since the pairing has been invalidated, the mobile phone A repeatedly initiatively connects and disconnects the BLE according to the Mac address, which causes a security vulnerability of the BLE, and the connection performance is also reduced, especially for an iOS mobile phone. This will inevitably cause interference when other new mobile phone B is connected and paired, at this time, the owner needs to actively clear the BLE pairing information of the mobile phone A, which also brings unnecessary troubles to the owner. Another serious problem is that if the mobile phone B has been paired with the BLE device, the previous mobile phone A cannot normally connect the BLE, and must be paired again after the pairing information of the mobile phone A is cleared, so as to restore the connection, which brings great trouble to the user operating the mobile phone A. SUMMARY
[0004] The present application is proposed to solve the above problems and technical requirements, and provides a method for automatically switching the Mac address of a BLE device and the BLE device, so as to solve the problem that when the BLE end has deleted pairing information, the mobile phone repeatedly connects and disconnects the BLE device, and cannot restore the connection.
[0005] The technical scheme of the application is as follows:
[0006] In a first aspect, the application provides a method for automatically switching the Mac address of a BLE device, comprising the following steps:
[0007] The BLE device is connected with an external device, and receives encrypted handshake information;
[0008] The encrypted handshake information is decrypted to obtain an assigned serial number;
[0009] If the assigned serial number is the same as the change part of the current Mac address of the BLE device, the pairing process is entered; otherwise, the change part of the Mac address of the BLE device is modified according to the assigned serial number, and the BLE device is disconnected and reset with the external device, and the steps of connecting the BLE device with the external device are re-executed.
[0010] A further technical solution is to decrypt the encrypted handshake information, including:
[0011] Each character of the encrypted handshake information is subjected to reverse cyclic shift according to the coefficient represented by the corresponding character in the shift cycle array during array encryption, to obtain a group of intermediate decryption arrays.
[0012] Each character of the intermediate decryption array is subjected to XOR calculation with each character of the random array, to obtain a plaintext array provided by the external device, and the plaintext array contains an assigned serial number given by the external device.
[0013] The handshake state of the BLE device and the external device is determined according to the plaintext array.
[0014] A further technical solution is to decrypt the encrypted handshake information, and also obtain a pairing enable instruction, and the pairing process includes:
[0015] If the pairing enable instruction requires pairing, the BLE device and the external device perform pairing operation, and enter the local information query process.
[0016] If the pairing enable instruction does not require pairing, the BLE device and the external device are directly connected and kept in a connected state.
[0017] A further technical solution is that the random array is composed of 16 Byte randomly read from a feature with a BLE UUID of 0xFFF1; and the shift cycle array is composed of the remainders obtained by dividing each character of the random array by 8.
[0018] A further technical solution is to determine the handshake state of the BLE device and the external device according to the plaintext array, including:
[0019] The plaintext array also contains a fixed value given by the external device as a check group, if the value of the read check group is consistent with the given fixed value, it indicates that the BLE device and the external device have successfully completed handshake, and the BLE device sends a handshake success flag to the outside; if the read values are inconsistent or the read time is exceeded, it indicates that the BLE device and the external device have failed to complete handshake, and the BLE device sends a handshake failure flag to the outside.
[0020] The BLE device uses a feature with a BLE UUID of 0xFFF2 when sending the flag.
[0021] Further, the plaintext array is divided into an information array and a check group, the information array is composed of 12 bits, wherein: the first and second bits are used for storing account information of the external device, the third bit is used for storing a system type of the external device, the fourth bit is used for storing an application type of the external device, the fifth bit is used for storing a pairing enable instruction given by the external device, the sixth bit is used for storing an allocation serial number given by the external device, and the seventh to twelfth bits are used for storing a Mac address of the external device; the check group is composed of 4 bits, and the thirteenth to sixteenth bits are used for storing fixed values given by the external device.
[0022] Further, the local information query process includes the following steps:
[0023] If the BLE device queries that the Mac address of the external device is stored in the local device, the BLE device and the external device directly enter a keep-connected state.
[0024] If the BLE device queries that the Mac address of the external device is not stored in the local device, the Mac address of the external device is saved in the local device, and the BLE device and the external device enter a keep-connected state.
[0025] Further, the method further includes the following steps:
[0026] If the BLE device and the external device are automatically connected, it indicates that the pairing process has been performed, and the Mac address of the BLE device has not been changed, so that the BLE device receives the encrypted handshake information and keeps the connection state.
[0027] If the BLE device and the external device cannot be automatically connected, it indicates that the Mac address of the BLE device has been changed, so that the step of connecting the BLE device and the external device is performed.
[0028] In the second aspect, the application further provides a BLE device, which includes a memory and a processor, the memory stores a computer program, and the processor implements the steps of the method provided in the first aspect when the computer program is executed during the connection and interaction between the BLE device and the external device.
[0029] Further, the Mac address of the BLE device includes a fixed part and a changeable part, the fixed part occupies the last four bytes of the Mac address and serves as a BLE device name, and the changeable part occupies the first two bytes of the Mac address, wherein the first byte represents a BLE device type, and the second byte is an allocation serial number provided by the external device.
[0030] The application has the following beneficial technical effects:
[0031] The Mac address of the BLE device is divided into a fixed part and a change part in the application, the BLE device name is determined through the fixed part, so that the external device can find the corresponding BLE device by searching for the fixed name when searching for the BLE device; and in each connection process, the corresponding allocation serial number obtained by decrypting the handshake information changes the Mac address of the BLE device, that is, the serial number is saved as the change part address of the Mac, so that the BLE device becomes a new device, which has no relationship with the previously paired external device and has no influence on the currently paired external device, until it is connected with another external device. If it is necessary to connect the previously paired external device again, the Mac of the change part can be restored to the serial number allocated by the corresponding external device. Through the method for automatically switching the Mac address provided in the application, the user does not need to delete the pairing information of the BLE device saved in the external device, because the Mac address of the BLE device has been changed, the connection cannot be found according to the original paired Mac, and it is not necessary to clear the pairing information of the BLE end, which simplifies the pairing and connection operation of the two ends, and makes the connection more stable and safe. BRIEF DESCRIPTION OF DRAWINGS
[0032] Figure 1 is a flow chart of the method for automatically switching the Mac address of the BLE device provided in the application.
[0033] Figure 2 is the clear text array expression form provided in the application, wherein (a) is the overall expression form, (b) is the information array expression form, and (c) is the check group expression form.
[0034] Figure 3 is a schematic diagram of the binding connection of multiple external devices and the BLE device provided in the application. DETAILED DESCRIPTION
[0035] The specific embodiments of the application will be further described in combination with the drawings.
[0036] Example 1
[0037] The application provides a method for automatically switching the Mac address of the BLE device, as shown in Figure 1 , including the following steps:
[0038] Step 2: Determine whether the BLE device and the external device can be automatically connected, if the BLE device and the external device can be automatically connected, it indicates that the pairing process has been performed between the two, and the Mac address of the BLE device has not been changed, then the BLE device receives the encrypted handshake information sent by the external device, and the two maintain the connection state.
[0039] If the BLE device cannot connect to the external device automatically, it means that the MAC address of the BLE device has changed, so proceed to step 4.
[0040] Optionally, external devices can be Bluetooth-enabled devices such as mobile phones, computers, and tablets.
[0041] Step 4: The BLE device connects to the external device and receives encrypted handshake information, denoted as CipherText
[16] .
[0042] Step 6: Decrypt the encrypted handshake information to obtain the allocation sequence number, specifically including:
[0043] Step 61: Each character of the encrypted handshake information CipherText
[16] is shifted in the reverse circular shift according to the circular shift coefficient represented by the corresponding character in the shift circular array Bitnums
[16] , to obtain a set of intermediate decryption arrays Xordata
[16] . For example, if the encrypted handshake information CipherText
[16] is formed by a circular left shift on the external device, then the intermediate decryption array Xordata
[16] is formed by a circular right shift during decryption on the BLE device. The circular shift operations of the two sets of arrays are shown in Table 1.
[0044] Table 1. Circular shift operations for two arrays
[0045]
[0046]
[0047] Here, ">>" represents the circular right shift symbol.
[0048] Step 62: Perform a bitwise XOR operation between each character of the intermediate decryption array Xordata
[16] and each character of the random array Randkey
[16] to obtain the plaintext array PlainText
[16] provided by the external device. The XOR operation between the two arrays is shown in Table 2.
[0049] Table 2. XOR calculation of two arrays
[0050] X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 = = = = = = = = = = = = = = = = P0 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13 P14 P15
[0051] Here, "^" represents the XOR symbol.
[0052] Specifically, the plaintext array PlainText
[16] is expressed as follows: Figure 2 As shown in (a), it is divided into an information array HsCmd
[12] and a check array Hsdata[4]. The information array HsCmd
[12] consists of 12 bits, and its expression is as follows: Figure 2(b) shown, wherein: the first and second bits (P0-P1) are used to store the account information of the external device, such as 0x0001 representing the owner's main account, having the highest authority, i.e. can limit and delete the authority of other sub-accounts, 0xFFFF representing that no account has been bound, and the rest of the addresses representing sub-accounts; the third bit (P2) is used to store the system type of the external device, such as 0x00-Android, 0x02-Harmony, 0x03-iOS, 0x04-other system; the fourth bit (P3) is used to store the application type of the external device, such as 0x00-Android application, 0x01-iOS application, 0x02-WeChat applet, 0x03-Alipay applet, 0x04-other type; the fifth bit (P4) is used to store the pairing enable instruction given by the external device, such as 0x00-no pairing required (the device can be directly connected), 0x01-pairing required (the device is connected after pairing); the sixth bit (P5) is used to store the allocation serial number given by the external device, which is used to specify the second byte of the BLE device Mac address, optionally, the serial number can be accumulated and transformed according to the number of Bluetooth connected external devices, or can be randomly assigned different values; the seventh to twelfth bits (P6-P11) are used to store the Mac address of the external device. The check group Hsdata[4] consists of 4 bits, and its expression form is as shown in Figure 2 (c) shown, the thirteenth to sixteenth bits (P12-P15) are used to store the fixed value given by the external device, such as selected 0x59, 0x44, 0x4B, 0x4A form a check group, used to determine the handshake state of the two devices.
[0053] Step 63: determine the handshake state of the BLE device and the external device according to the plaintext array PlainText
[16] , which specifically includes:
[0054] If the value of the read check group Hsdata[4] is consistent with the given fixed value, it indicates that the BLE device and the external device have successfully completed the handshake, and the BLE device sends a handshake success flag to the outside, such as sending the handshake success flag {0x45, 0x39, 0xF1} to the mobile phone APP; if the read is inconsistent or the read is timed out, it indicates that the BLE device and the external device have failed to complete the handshake, and the BLE device sends a handshake failure flag to the outside, such as sending the handshake failure flag {0x45, 0x39, 0xF0} to the mobile phone APP. Wherein, the BLE device sends the flag using the BLE UUID 0xFFF2 feature.
[0055] Wherein, the random array Randkey
[16] is composed of 16 bytes randomly read in the feature with BLE UUID 0xFFF1. The shift cycle array Bitnums
[16] is composed of the remainder of each character of the random array Randkey
[16] divided by 8 arranged by bit, expressed as Bitnums[n] = Randkey[n] % 8.
[0056] Step 8: judge whether the obtained allocation serial number matches the current Mac address of the BLE device, if the allocation serial number is the same as the change part of the current Mac address of the BLE device, go to step 10; otherwise, go to step 14.
[0057] Step 10: perform the pairing process, specifically including:
[0058] If the pairing enable instruction is to require pairing, the BLE device and the external device perform pairing operation, and go to step 12.
[0059] If the pairing enable instruction is not to require pairing, the BLE device and the external device are directly connected and kept in the connection state.
[0060] Step 12: query the local information process, specifically including:
[0061] If the BLE device queries that the external device Mac address is stored in the local, the BLE device and the external device directly enter the connection state.
[0062] If the BLE device queries that the external device Mac address is not stored in the local, save the external device Mac address in the local, and the BLE device and the external device enter the connection state.
[0063] The process can avoid the external device Mac address repeatedly saved in the local, occupying the memory of the BLE device.
[0064] Step 14: modify the change part of the Mac address of the BLE device according to the allocation serial number, and disconnect and reset with the external device, and re-execute step 4.
[0065] On the basis of the single-end operation of the BLE device, the embodiment also provides a multi-end interactive operation step of the external device and the BLE device, as shown in Figure 1 The process also includes the following steps:
[0066] Step 0: log in to the APP in the external device, register account information, and register a plurality of BLE devices under the account management name, and the APP obtains the local Mac address and other information.
[0067] Step 1: search and add the BLE device in the APP according to the BLE master name, and go to step 2.
[0068] In step 2, if the BLE device can automatically connect with the external device, it indicates that the two have performed the pairing process and the Mac address of the BLE device has not changed, and the external device will encrypt the plaintext array to form encrypted handshake information and send it to the BLE device; the BLE device receives the encrypted handshake information sent by the external device, and the two maintain the connection state. If the BLE device cannot automatically connect with the external device, it indicates that the Mac address of the BLE device has changed, and step 3 is performed.
[0069] The encryption of the plaintext array by the external device to form the encrypted handshake information is the reverse operation of steps 61 and 62, which will not be described here.
[0070] Step 3: The external device searches for the BLE device according to the BLE device name and enters step 4 to gradually perform the above process.
[0071] In step 14, the Mac address change part of the BLE device is modified according to the allocation serial number, and the external device is disconnected and reset to re-perform step 3.
[0072] In this embodiment, the external device searches for the Mac according to the BLE device name, and the Mac address of the BLE device is modified through the two-end handshake protocol, that is, a new Mac is generated. Based on the difference in the Mac, the original external device cannot identify the BLE device with the new address, so the problem of automatic connection and disconnection of the external device will not occur again, and the BLE device also does not need to delete the pairing information. As long as the original Mac is changed back, the previously connected external device can automatically restore the connection.
[0073] Embodiment two:
[0074] The application also provides a BLE device, the Mac address of which includes a fixed part and a change part. The fixed part occupies the last four bytes of the Mac address, and the fixed part is used as the BLE device name to serve as a device identifier. The change part occupies the first two bytes of the Mac address, wherein the first byte represents the type of the BLE device, and the second byte is an allocation serial number provided by the external device. In this embodiment, it is specified that the BLE device name is composed of a manufacturer logo, a main name and a sub-name, for example, a BLE device, whose Bluetooth name is named as YD-12345678-YYXX. The main name is used as a unique identifier of the BLE device and is set as the fixed part of the BLE Mac. The sub-name is composed of YYXX, wherein YY is a fixed byte and XX is a change byte, which is determined according to the allocation serial number given by the external device, that is, a BLE device will have at most 240 addresses from 0x00 to 0xEF, each address corresponds to an external device, the addresses from 0xF0 to 0xFE are reserved, and 0xFF represents that the BLE device is not activated, that is, it has not been paired.
[0075] The BLE device includes a memory and a processor, the memory stores a computer program, the BLE device can be carried on an electric vehicle, when connected and interacted with a matched external device, the processor executes the computer program to realize the steps of the method provided in Embodiment I, which will not be repeated here.
[0076] The matched external device can realize the APP management BLE device information function, and bind the external device and the BLE device one by one. For example, Figure 3 As shown in the figure, when the mobile phone 0 logs in the APP account A, the mobile phone 0 connects the BLE device to become the first mobile phone device of the account A, and is assigned with the serial number 0x00, at this time the Mac address of the BLE device is changed to C1:00:12:34:56:78, and then the pairing process is performed. When the mobile phone 1 logs in the account A, the mobile phone 1 connects the BLE device to become the second mobile phone device of the account A, and is assigned with the serial number 0x01, at this time the Mac address of the BLE device is changed to C1:01:12:34:56:78, and then the pairing process is performed, and other mobile phones are sequentially performed according to the above process.
[0077] The above is only the preferred embodiment of the present application, and the present application is not limited to the above embodiments. It can be understood that other improvements and changes directly derived or thought by those skilled in the art without departing from the spirit and concept of the present application should be considered to be included in the protection scope of the present application.
Claims
1. A method for automatically switching a BLE device Mac address, characterized in that, The method comprises: The BLE device connects with the external device and receives encrypted handshake information; The encrypted handshake information is decrypted to obtain an allocation serial number; If the allocation serial number is the same as a change part of a current Mac address of the BLE device, a pairing process is entered; otherwise, the Mac address of the BLE device is modified according to the allocation serial number, and the BLE device is disconnected and reset to re-execute the step of connecting with the external device; The encrypted handshake information is decrypted, comprising: Each character of the encrypted handshake information is subjected to inverse cyclic shift according to a coefficient represented by a corresponding character in a shift cycle array to obtain a group of intermediate decryption arrays; Each character of the intermediate decryption array is subjected to exclusive or calculation with each character of a random array to obtain a plaintext array provided by the external device, the plaintext array containing an allocation serial number given by the external device; The handshake state of the BLE device and the external device is determined according to the plaintext array.
2. The method for automatically switching BLE device Mac address according to claim 1, characterized in that, If the pairing enable instruction is pairing required, the BLE device and the external device perform pairing operation and enter a local information query process; If the pairing enable instruction is not pairing required, the BLE device and the external device are directly connected and kept in a connected state. The random array is composed of 16 Byte randomly read from a feature with a BLE UUID of 0xFFF1; the shift cycle array is composed of remainders obtained by dividing each character of the random array by 8.
3. The method for automatically switching BLE device Mac address of claim 1, wherein, The handshake state of the BLE device and the external device is determined according to the plaintext array, comprising:
4. The method for automatically switching BLE device Mac address of claim 1, wherein, The plaintext array further contains a fixed value given by the external device as a check group; if the value of the read check group is consistent with the given fixed value, it indicates that the BLE device and the external device have successfully performed handshake, and the BLE device sends a handshake success flag to the outside; if the values are inconsistent or the reading is timed out, it indicates that the BLE device and the external device have failed to perform handshake, and the BLE device sends a handshake failure flag to the outside; When the BLE device sends the flag, a feature with a BLE UUID of 0xFFF2 is used. The plaintext array is divided into an information array and a check group; the information array is composed of 12 bits, wherein the first and second bits are used to store account information of the external device, the third bit is used to store a system type of the external device, the fourth bit is used to store an application type of the external device, the fifth bit is used to store a pairing enable instruction given by the external device, the sixth bit is used to store an allocation serial number given by the external device, and the seventh to twelfth bits are used to store a Mac address of the external device; the check group is composed of 4 bits, and the thirteenth to sixteenth bits are used to store a fixed value given by the external device.
5. The method for automatically switching BLE device Mac address of claim 1, wherein, If the BLE device queries that the external device Mac address is stored in the local device, the BLE device and the external device directly enter a connected state; 6. The method for automatically switching BLE device Mac address of claim 2, wherein, If the BLE device queries the local storage and does not find the Mac address of the external device, the Mac address of the external device is saved in the local storage, and the BLE device and the external device enter a connection maintaining state.
7. The method for automatically switching BLE device Mac address of claim 1, wherein, The method further comprises: If the BLE device and the external device are automatically connected, it indicates that the pairing process has been performed, and the Mac address of the BLE device has not changed, the BLE device receives the encrypted handshake information and maintains the connection state; If the BLE device and the external device cannot be automatically connected, it indicates that the Mac address of the BLE device has changed, and the step of connecting the BLE device and the external device is performed. 8.A BLE device comprising a memory and a processor, the memory storing a computer program, characterized in that, When the BLE device and the external device are connected and interact, the processor executes the computer program to implement the steps of the method of any one of claims 1 to 7.
9. The BLE device of claim 8, wherein, The Mac address of the BLE device comprises a fixed part and a changeable part, the fixed part occupies the last four bytes of the Mac address and serves as the BLE device name, playing an identification role; the changeable part occupies the first two bytes of the Mac address, wherein the first byte represents the type of the BLE device, and the second byte is an allocation serial number provided by the external device.
Citation Information
Patent Citations
Bluetooth connection method and device
CN110381487A
Bluetooth network distribution method, device and system and storage medium
CN114698064A