diff options
author | Myles Watson | 2017-05-08 12:25:11 -0500 |
---|---|---|
committer | Myles Watson | 2017-08-25 08:18:41 -0500 |
commit | 8d0d6f99dfbd121140549adc43f360686467e875 (patch) | |
tree | a697395a7e41550d242b01bd2905c37f061bea02 | |
parent | dcc6f25d059b23da52522cc6af6bf06c9cbc047b (diff) | |
download | platform-hardware-interfaces-8d0d6f99dfbd121140549adc43f360686467e875.tar.gz platform-hardware-interfaces-8d0d6f99dfbd121140549adc43f360686467e875.tar.xz platform-hardware-interfaces-8d0d6f99dfbd121140549adc43f360686467e875.zip |
Bluetooth: Remove random MAC addresses
Bug:65014945
Test: boot a wiped device with no property set, check the Bluetooth address
Change-Id: I905f9dbf2f0782e19de64a8f798d1e26ffd9f1bf
-rw-r--r-- | bluetooth/1.0/default/bluetooth_address.cc | 45 |
1 files changed, 7 insertions, 38 deletions
diff --git a/bluetooth/1.0/default/bluetooth_address.cc b/bluetooth/1.0/default/bluetooth_address.cc index 65dc6a61..34df752b 100644 --- a/bluetooth/1.0/default/bluetooth_address.cc +++ b/bluetooth/1.0/default/bluetooth_address.cc | |||
@@ -44,15 +44,12 @@ bool BluetoothAddress::string_to_bytes(const char* addr_str, uint8_t* addr) { | |||
44 | 44 | ||
45 | bool BluetoothAddress::get_local_address(uint8_t* local_addr) { | 45 | bool BluetoothAddress::get_local_address(uint8_t* local_addr) { |
46 | char property[PROPERTY_VALUE_MAX] = {0}; | 46 | char property[PROPERTY_VALUE_MAX] = {0}; |
47 | bool valid_bda = false; | ||
48 | 47 | ||
49 | // Get local bdaddr storage path from a system property. | 48 | // Get local bdaddr storage path from a system property. |
50 | if (property_get(PROPERTY_BT_BDADDR_PATH, property, NULL)) { | 49 | if (property_get(PROPERTY_BT_BDADDR_PATH, property, NULL)) { |
51 | int addr_fd; | ||
52 | |||
53 | ALOGD("%s: Trying %s", __func__, property); | 50 | ALOGD("%s: Trying %s", __func__, property); |
54 | 51 | ||
55 | addr_fd = open(property, O_RDONLY); | 52 | int addr_fd = open(property, O_RDONLY); |
56 | if (addr_fd != -1) { | 53 | if (addr_fd != -1) { |
57 | char address[kStringLength + 1] = {0}; | 54 | char address[kStringLength + 1] = {0}; |
58 | int bytes_read = read(addr_fd, address, kStringLength); | 55 | int bytes_read = read(addr_fd, address, kStringLength); |
@@ -69,8 +66,8 @@ bool BluetoothAddress::get_local_address(uint8_t* local_addr) { | |||
69 | const uint8_t zero_bdaddr[kBytes] = {0, 0, 0, 0, 0, 0}; | 66 | const uint8_t zero_bdaddr[kBytes] = {0, 0, 0, 0, 0, 0}; |
70 | if ((string_to_bytes(address, local_addr)) && | 67 | if ((string_to_bytes(address, local_addr)) && |
71 | (memcmp(local_addr, zero_bdaddr, kBytes) != 0)) { | 68 | (memcmp(local_addr, zero_bdaddr, kBytes) != 0)) { |
72 | valid_bda = true; | ||
73 | ALOGD("%s: Got Factory BDA %s", __func__, address); | 69 | ALOGD("%s: Got Factory BDA %s", __func__, address); |
70 | return true; | ||
74 | } else { | 71 | } else { |
75 | ALOGE("%s: Got Invalid BDA '%s' from %s", __func__, address, property); | 72 | ALOGE("%s: Got Invalid BDA '%s' from %s", __func__, address, property); |
76 | } | 73 | } |
@@ -78,46 +75,18 @@ bool BluetoothAddress::get_local_address(uint8_t* local_addr) { | |||
78 | } | 75 | } |
79 | 76 | ||
80 | // No BDADDR found in the file. Look for BDA in a factory property. | 77 | // No BDADDR found in the file. Look for BDA in a factory property. |
81 | if (!valid_bda && property_get(FACTORY_BDADDR_PROPERTY, property, NULL) && | 78 | if (property_get(FACTORY_BDADDR_PROPERTY, property, NULL) && |
82 | string_to_bytes(property, local_addr)) { | 79 | string_to_bytes(property, local_addr)) { |
83 | valid_bda = true; | 80 | return true; |
84 | } | 81 | } |
85 | 82 | ||
86 | // No factory BDADDR found. Look for a previously stored BDA. | 83 | // No factory BDADDR found. Look for a previously stored BDA. |
87 | if (!valid_bda && property_get(PERSIST_BDADDR_PROPERTY, property, NULL) && | 84 | if (property_get(PERSIST_BDADDR_PROPERTY, property, NULL) && |
88 | string_to_bytes(property, local_addr)) { | 85 | string_to_bytes(property, local_addr)) { |
89 | valid_bda = true; | 86 | return true; |
90 | } | ||
91 | |||
92 | /* Generate new BDA if necessary */ | ||
93 | if (!valid_bda) { | ||
94 | char bdstr[kStringLength + 1]; | ||
95 | |||
96 | /* No autogen BDA. Generate one now. */ | ||
97 | local_addr[0] = 0x22; | ||
98 | local_addr[1] = 0x22; | ||
99 | local_addr[2] = (uint8_t)rand(); | ||
100 | local_addr[3] = (uint8_t)rand(); | ||
101 | local_addr[4] = (uint8_t)rand(); | ||
102 | local_addr[5] = (uint8_t)rand(); | ||
103 | |||
104 | /* Convert to ascii, and store as a persistent property */ | ||
105 | bytes_to_string(local_addr, bdstr); | ||
106 | |||
107 | ALOGE("%s: No preset BDA! Generating BDA: %s for prop %s", __func__, | ||
108 | (char*)bdstr, PERSIST_BDADDR_PROPERTY); | ||
109 | ALOGE("%s: This is a bug in the platform! Please fix!", __func__); | ||
110 | |||
111 | if (property_set(PERSIST_BDADDR_PROPERTY, (char*)bdstr) < 0) { | ||
112 | ALOGE("%s: Failed to set random BDA in prop %s", __func__, | ||
113 | PERSIST_BDADDR_PROPERTY); | ||
114 | valid_bda = false; | ||
115 | } else { | ||
116 | valid_bda = true; | ||
117 | } | ||
118 | } | 87 | } |
119 | 88 | ||
120 | return valid_bda; | 89 | return false; |
121 | } | 90 | } |
122 | 91 | ||
123 | } // namespace implementation | 92 | } // namespace implementation |