1 /******************************************************************************
2  *
3  *  Copyright 2002-2012 Broadcom Corporation
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 
19 /******************************************************************************
20  *
21  *  This file contains HID connection internal definitions
22  *
23  ******************************************************************************/
24 
25 #ifndef HID_CONN_H
26 #define HID_CONN_H
27 
28 #include <base/strings/stringprintf.h>
29 #include <bluetooth/log.h>
30 
31 #include "macros.h"
32 #include "osi/include/alarm.h"
33 
34 typedef enum : uint8_t {
35   HID_CONN_STATE_UNUSED = 0,
36   HID_CONN_STATE_CONNECTING_CTRL = 1,
37   HID_CONN_STATE_CONNECTING_INTR = 2,
38   HID_CONN_STATE_CONFIG = 3,
39   HID_CONN_STATE_CONNECTED = 4,
40   HID_CONN_STATE_DISCONNECTING = 5,
41   HID_CONN_STATE_SECURITY = 6,
42 } tHID_CONN_STATE;
43 
44 /* Define the HID Connection Block
45 */
46 typedef struct hid_conn {
47   tHID_CONN_STATE conn_state;
48 
state_texthid_conn49   static inline std::string state_text(const tHID_CONN_STATE& state) {
50     switch (state) {
51       CASE_RETURN_TEXT(HID_CONN_STATE_UNUSED);
52       CASE_RETURN_TEXT(HID_CONN_STATE_CONNECTING_CTRL);
53       CASE_RETURN_TEXT(HID_CONN_STATE_CONNECTING_INTR);
54       CASE_RETURN_TEXT(HID_CONN_STATE_CONFIG);
55       CASE_RETURN_TEXT(HID_CONN_STATE_CONNECTED);
56       CASE_RETURN_TEXT(HID_CONN_STATE_DISCONNECTING);
57       CASE_RETURN_TEXT(HID_CONN_STATE_SECURITY);
58       default:
59         return base::StringPrintf("UNKNOWN[%hhu]", state);
60     }
61   }
62 
63 #define HID_CONN_FLAGS_IS_ORIG (0x01)
64 #define HID_CONN_FLAGS_CONGESTED (0x20)
65 #define HID_CONN_FLAGS_INACTIVE (0x40)
66 
67   uint8_t conn_flags;
68 
69   uint16_t ctrl_cid;
70   uint16_t intr_cid;
71   uint16_t rem_mtu_size;
72   uint16_t disc_reason; /* Reason for disconnecting (for HID_HDEV_EVT_CLOSE) */
73   alarm_t* process_repage_timer;
74 } tHID_CONN;
75 
76 #define HID_SEC_CHN 1
77 #define HID_NOSEC_CHN 2
78 
79 #define HIDD_SEC_CHN 3
80 
81 namespace fmt {
82 template <>
83 struct formatter<tHID_CONN_STATE> : enum_formatter<tHID_CONN_STATE> {};
84 }  // namespace fmt
85 
86 #endif
87