• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2016 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #pragma once
18 
19 #include <fcntl.h>
20 
21 #include <cstdint>
22 #include <string>
23 #include <vector>
24 
25 namespace android {
26 namespace hardware {
27 namespace bluetooth {
28 namespace V1_0 {
29 namespace implementation {
30 
31 // The property key stores the storage location of Bluetooth Device Address
32 static constexpr char PROPERTY_BT_BDADDR_PATH[] = "ro.bt.bdaddr_path";
33 
34 // Check for a legacy address stored as a property.
35 static constexpr char PERSIST_BDADDR_PROPERTY[] =
36     "persist.service.bdroid.bdaddr";
37 
38 // If there is no valid bdaddr available from PROPERTY_BT_BDADDR_PATH and there
39 // is no available persistent bdaddr available from PERSIST_BDADDR_PROPERTY,
40 // use a factory set address.
41 static constexpr char FACTORY_BDADDR_PROPERTY[] = "ro.boot.btmacaddr";
42 
43 // Encapsulate handling for Bluetooth Addresses:
44 class BluetoothAddress {
45  public:
46   // Conversion constants
47   static constexpr size_t kStringLength = sizeof("XX:XX:XX:XX:XX:XX") - 1;
48   static constexpr size_t kBytes = (kStringLength + 1) / 3;
49 
50   static void bytes_to_string(const uint8_t* addr, char* addr_str);
51 
52   static bool string_to_bytes(const char* addr_str, uint8_t* addr);
53 
54   static bool get_local_address(uint8_t* addr);
55 };
56 
57 }  // namespace implementation
58 }  // namespace V1_0
59 }  // namespace bluetooth
60 }  // namespace hardware
61 }  // namespace android
62