1 /*
2 * Copyright 2021 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 <bluetooth/log.h>
20
21 #include <cstdint>
22
23 #include "macros.h"
24
25 /*
26 * Events that can be received by multiplexer as well as port state machines
27 */
28 enum tRFC_EVENT : uint16_t {
29 /*
30 * Events that can be received by multiplexer as well as port state machines
31 */
32 RFC_EVENT_SABME = 0,
33 RFC_EVENT_UA = 1,
34 RFC_EVENT_DM = 2,
35 RFC_EVENT_DISC = 3,
36 RFC_EVENT_UIH = 4,
37 RFC_EVENT_TIMEOUT = 5,
38 RFC_EVENT_BAD_FRAME = 50,
39 };
40
41 /*
42 * Multiplexer events
43 */
44 enum tRFC_MX_EVENT : uint16_t {
45 /*
46 * Multiplexer events
47 */
48 RFC_MX_EVENT_SABME = RFC_EVENT_SABME,
49 RFC_MX_EVENT_UA = RFC_EVENT_UA,
50 RFC_MX_EVENT_DM = RFC_EVENT_DM,
51 RFC_MX_EVENT_DISC = RFC_EVENT_DISC,
52 RFC_MX_EVENT_UIH = RFC_EVENT_UIH,
53 RFC_MX_EVENT_TIMEOUT = RFC_EVENT_TIMEOUT,
54 RFC_MX_EVENT_START_REQ = 6,
55 RFC_MX_EVENT_START_RSP = 7,
56 RFC_MX_EVENT_CLOSE_REQ = 8,
57 RFC_MX_EVENT_CONN_CNF = 9,
58 RFC_MX_EVENT_CONN_IND = 10,
59 RFC_MX_EVENT_CONF_CNF = 11,
60 RFC_MX_EVENT_CONF_IND = 12,
61 RFC_MX_EVENT_QOS_VIOLATION_IND = 13,
62 RFC_MX_EVENT_DISC_IND = 14,
63 };
64
65 /*
66 * Port events
67 */
68 enum tRFC_PORT_EVENT : uint16_t {
69 /*
70 * Port events
71 */
72 RFC_PORT_EVENT_SABME = RFC_EVENT_SABME,
73 RFC_PORT_EVENT_UA = RFC_EVENT_UA,
74 RFC_PORT_EVENT_DM = RFC_EVENT_DM,
75 RFC_PORT_EVENT_DISC = RFC_EVENT_DISC,
76 RFC_PORT_EVENT_UIH = RFC_EVENT_UIH,
77 RFC_PORT_EVENT_TIMEOUT = RFC_EVENT_TIMEOUT,
78 RFC_PORT_EVENT_OPEN = 9,
79 RFC_PORT_EVENT_ESTABLISH_RSP = 11,
80 RFC_PORT_EVENT_CLOSE = 12,
81 RFC_PORT_EVENT_CLEAR = 13,
82 RFC_PORT_EVENT_DATA = 14,
83 RFC_PORT_EVENT_SEC_COMPLETE = 15,
84 };
85
86 // Common events for both port and mux
rfcomm_event_text(const tRFC_EVENT & event)87 inline std::string rfcomm_event_text(const tRFC_EVENT& event) {
88 switch (event) {
89 CASE_RETURN_TEXT(RFC_EVENT_SABME);
90 CASE_RETURN_TEXT(RFC_EVENT_UA);
91 CASE_RETURN_TEXT(RFC_EVENT_DM);
92 CASE_RETURN_TEXT(RFC_EVENT_DISC);
93 CASE_RETURN_TEXT(RFC_EVENT_UIH);
94 CASE_RETURN_TEXT(RFC_EVENT_TIMEOUT);
95 CASE_RETURN_TEXT(RFC_EVENT_BAD_FRAME);
96 default:
97 return std::string("UNKNOWN[") + std::to_string(event) + std::string("]");
98 }
99 }
100
rfcomm_mx_event_text(const tRFC_MX_EVENT & event)101 inline std::string rfcomm_mx_event_text(const tRFC_MX_EVENT& event) {
102 switch (event) {
103 CASE_RETURN_TEXT(RFC_MX_EVENT_SABME);
104 CASE_RETURN_TEXT(RFC_MX_EVENT_UA);
105 CASE_RETURN_TEXT(RFC_MX_EVENT_DM);
106 CASE_RETURN_TEXT(RFC_MX_EVENT_DISC);
107 CASE_RETURN_TEXT(RFC_MX_EVENT_UIH);
108 CASE_RETURN_TEXT(RFC_MX_EVENT_TIMEOUT);
109 CASE_RETURN_TEXT(RFC_MX_EVENT_START_REQ);
110 CASE_RETURN_TEXT(RFC_MX_EVENT_START_RSP);
111 CASE_RETURN_TEXT(RFC_MX_EVENT_CLOSE_REQ);
112 CASE_RETURN_TEXT(RFC_MX_EVENT_CONN_CNF);
113 CASE_RETURN_TEXT(RFC_MX_EVENT_CONN_IND);
114 CASE_RETURN_TEXT(RFC_MX_EVENT_CONF_CNF);
115 CASE_RETURN_TEXT(RFC_MX_EVENT_CONF_IND);
116 CASE_RETURN_TEXT(RFC_MX_EVENT_QOS_VIOLATION_IND);
117 CASE_RETURN_TEXT(RFC_MX_EVENT_DISC_IND);
118 default:
119 return std::string("UNKNOWN[") + std::to_string(event) + std::string("]");
120 }
121 }
122
rfcomm_port_event_text(const tRFC_PORT_EVENT & event)123 inline std::string rfcomm_port_event_text(const tRFC_PORT_EVENT& event) {
124 switch (event) {
125 CASE_RETURN_TEXT(RFC_PORT_EVENT_SABME);
126 CASE_RETURN_TEXT(RFC_PORT_EVENT_UA);
127 CASE_RETURN_TEXT(RFC_PORT_EVENT_DM);
128 CASE_RETURN_TEXT(RFC_PORT_EVENT_DISC);
129 CASE_RETURN_TEXT(RFC_PORT_EVENT_UIH);
130 CASE_RETURN_TEXT(RFC_PORT_EVENT_TIMEOUT);
131 CASE_RETURN_TEXT(RFC_PORT_EVENT_OPEN);
132 CASE_RETURN_TEXT(RFC_PORT_EVENT_ESTABLISH_RSP);
133 CASE_RETURN_TEXT(RFC_PORT_EVENT_CLOSE);
134 CASE_RETURN_TEXT(RFC_PORT_EVENT_CLEAR);
135 CASE_RETURN_TEXT(RFC_PORT_EVENT_DATA);
136 CASE_RETURN_TEXT(RFC_PORT_EVENT_SEC_COMPLETE);
137 default:
138 return std::string("UNKNOWN[") + std::to_string(event) + std::string("]");
139 }
140 }
141
142 namespace fmt {
143 template <>
144 struct formatter<tRFC_EVENT> : enum_formatter<tRFC_EVENT> {};
145 template <>
146 struct formatter<tRFC_MX_EVENT> : enum_formatter<tRFC_MX_EVENT> {};
147 template <>
148 struct formatter<tRFC_PORT_EVENT> : enum_formatter<tRFC_PORT_EVENT> {};
149 } // namespace fmt
150