1 /*
2  * Copyright 2021 HIMSA II K/S - www.himsa.com.
3  * Represented by EHIMA - www.ehima.com
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 <hardware/bluetooth.h>
21 
22 #include <array>
23 #include <optional>
24 #include <vector>
25 
26 typedef std::array<uint8_t, 16> Octet16;
27 
28 namespace bluetooth {
29 namespace csis {
30 
31 /** Connection State */
32 enum class ConnectionState : uint8_t {
33   DISCONNECTED = 0,
34   CONNECTING,
35   CONNECTED,
36   DISCONNECTING,
37 };
38 
39 enum class CsisGroupLockStatus {
40   SUCCESS = 0,
41   FAILED_INVALID_GROUP,
42   FAILED_GROUP_EMPTY,
43   FAILED_GROUP_NOT_CONNECTED,
44   FAILED_LOCKED_BY_OTHER,
45   FAILED_OTHER_REASON,
46   LOCKED_GROUP_MEMBER_LOST,
47 };
48 
49 static constexpr uint8_t CSIS_RANK_INVALID = 0x00;
50 
51 class CsisClientCallbacks {
52  public:
53   virtual ~CsisClientCallbacks() = default;
54 
55   /** Callback for profile connection state change */
56   virtual void OnConnectionState(const RawAddress& addr,
57                                  ConnectionState state) = 0;
58 
59   /** Callback for the new available device */
60   virtual void OnDeviceAvailable(const RawAddress& addr, int group_id,
61                                  int group_size, int rank,
62                                  const bluetooth::Uuid& uuid) = 0;
63 
64   /* Callback for available set member*/
65   virtual void OnSetMemberAvailable(const RawAddress& address,
66                                     int group_id) = 0;
67 
68   /* Callback for lock changed in the group */
69   virtual void OnGroupLockChanged(int group_id, bool locked,
70                                   CsisGroupLockStatus status) = 0;
71 };
72 
73 class CsisClientInterface {
74  public:
75   virtual ~CsisClientInterface() = default;
76 
77   /** Register the Csis Client profile callbacks */
78   virtual void Init(CsisClientCallbacks* callbacks) = 0;
79 
80   /** Connect to Csis Client */
81   virtual void Connect(const RawAddress& addr) = 0;
82 
83   /** Disconnect from Csis Client */
84   virtual void Disconnect(const RawAddress& addr) = 0;
85 
86   /** Lock/Unlock Csis group */
87   virtual void LockGroup(int group_id, bool lock) = 0;
88 
89   /* Called when unbonded. */
90   virtual void RemoveDevice(const RawAddress& address) = 0;
91 
92   /** Closes the interface */
93   virtual void Cleanup(void) = 0;
94 };
95 
96 } /* namespace csis */
97 } /* namespace bluetooth */
98