• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2019 The Android Open Source Project
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 #pragma once
19 
20 #include "hci/device.h"
21 
22 namespace bluetooth::hci {
23 
24 /**
25  * TODO(optedoblivion): Build out AddressType getter/setter
26  */
27 // enum AddressType {};
28 
29 /**
30  * A device representing a LE device.
31  *
32  * <p>This can be a LE only or a piece of a DUAL MODE device.
33  *
34  * <p>LE specific public address logic goes here.
35  */
36 class LeDevice : public Device {
37  public:
SetPublicAddress(Address public_address)38   void SetPublicAddress(Address public_address) {
39     public_address_ = public_address;
40   }
41 
GetPublicAddress()42   Address GetPublicAddress() {
43     return public_address_;
44   }
45 
SetIrk(uint8_t irk)46   void SetIrk(uint8_t irk) {
47     irk_ = irk;
48     // TODO(optedoblivion): Set derived Address
49   }
50 
GetIrk()51   uint8_t GetIrk() {
52     return irk_;
53   }
54 
55  protected:
56   friend class DeviceDatabase;
57   // TODO(optedoblivion): How to set public address.  Do I set it when no IRK is known?
58   // Right now my thought is to do this:
59   // 1. Construct LeDevice with address of all 0s
60   // 2. IF NO IRK AND NO PRIVATE ADDRESS: (i.e. nothing in disk cache)
61   //  a. Hopefully pairing will happen
62   //  b. Pending successful pairing get the IRK and Private Address
63   //  c. Set Both to device.
64   //  (d). If available set IRK to the controller (later iteration)
65   // [#3 should indicate we have a bug]
66   // 3. IF YES IRK AND NO PRIVATE ADDRESS: (Partial Disk Cache Information)
67   //  a. Set IRK
68   //  b. Generate Private Address
69   //  c. Set Private Address to device
70   //  (d). If available set IRK to the controller (later iteration)
71   // 4. IF YES IRK AND YES PRIVATE ADDRESS: (i.e. Disk cache hit)
72   //  a. Construct with private address
73   //  b. Set IRK
74   //  (c). If available set IRK to the controller (later iteration)
75   // 5. IF NO IRK AND YES PRIVATE ADDRESS (we have a bug)
76   //  a1. -Construct with private address-
77   //  b. -Indicate we need to repair or query for IRK?-
78   //
79   //  or
80   //
81   //  a2. Don't use class
LeDevice(Address address)82   explicit LeDevice(Address address) : Device(address, DeviceType::LE), public_address_(), irk_(0) {}
83 
84  private:
85   Address public_address_;
86   uint8_t irk_;
87 };
88 
89 }  // namespace bluetooth::hci
90