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, ConnectionState state) = 0;
57 
58   /** Callback for the new available device */
59   virtual void OnDeviceAvailable(const RawAddress& addr, int group_id, int group_size, int rank,
60                                  const bluetooth::Uuid& uuid) = 0;
61 
62   /* Callback for available set member*/
63   virtual void OnSetMemberAvailable(const RawAddress& address, int group_id) = 0;
64 
65   /* Callback for lock changed in the group */
66   virtual void OnGroupLockChanged(int group_id, bool locked, CsisGroupLockStatus status) = 0;
67 };
68 
69 class CsisClientInterface {
70 public:
71   virtual ~CsisClientInterface() = default;
72 
73   /** Register the Csis Client profile callbacks */
74   virtual void Init(CsisClientCallbacks* callbacks) = 0;
75 
76   /** Connect to Csis Client */
77   virtual void Connect(const RawAddress& addr) = 0;
78 
79   /** Disconnect from Csis Client */
80   virtual void Disconnect(const RawAddress& addr) = 0;
81 
82   /** Lock/Unlock Csis group */
83   virtual void LockGroup(int group_id, bool lock) = 0;
84 
85   /* Called when unbonded. */
86   virtual void RemoveDevice(const RawAddress& address) = 0;
87 
88   /** Closes the interface */
89   virtual void Cleanup(void) = 0;
90 };
91 
92 } /* namespace csis */
93 } /* namespace bluetooth */
94