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 <cstdint>
20
21 #include "macros.h"
22
23 // Multiplexer states
24 typedef enum : uint16_t {
25 RFC_MX_STATE_IDLE = 0,
26 RFC_MX_STATE_WAIT_CONN_CNF = 1,
27 RFC_MX_STATE_CONFIGURE = 2,
28 RFC_MX_STATE_SABME_WAIT_UA = 3,
29 RFC_MX_STATE_WAIT_SABME = 4,
30 RFC_MX_STATE_CONNECTED = 5,
31 RFC_MX_STATE_DISC_WAIT_UA = 6,
32 } tRFC_MX_STATE;
33
34 // Port states
35 typedef enum : uint8_t {
36 RFC_STATE_CLOSED = 0,
37 RFC_STATE_SABME_WAIT_UA = 1,
38 RFC_STATE_ORIG_WAIT_SEC_CHECK = 2,
39 RFC_STATE_TERM_WAIT_SEC_CHECK = 3,
40 RFC_STATE_OPENED = 4,
41 RFC_STATE_DISC_WAIT_UA = 5,
42 } tRFC_PORT_STATE;
43
rfcomm_mx_state_text(const tRFC_MX_STATE & state)44 inline std::string rfcomm_mx_state_text(const tRFC_MX_STATE& state) {
45 switch (state) {
46 CASE_RETURN_TEXT(RFC_MX_STATE_IDLE);
47 CASE_RETURN_TEXT(RFC_MX_STATE_WAIT_CONN_CNF);
48 CASE_RETURN_TEXT(RFC_MX_STATE_CONFIGURE);
49 CASE_RETURN_TEXT(RFC_MX_STATE_SABME_WAIT_UA);
50 CASE_RETURN_TEXT(RFC_MX_STATE_WAIT_SABME);
51 CASE_RETURN_TEXT(RFC_MX_STATE_CONNECTED);
52 CASE_RETURN_TEXT(RFC_MX_STATE_DISC_WAIT_UA);
53 default:
54 return std::string("UNKNOWN[") + std::to_string(state) + std::string("]");
55 }
56 }
57
rfcomm_port_state_text(const tRFC_PORT_STATE & state)58 inline std::string rfcomm_port_state_text(const tRFC_PORT_STATE& state) {
59 switch (state) {
60 CASE_RETURN_TEXT(RFC_STATE_CLOSED);
61 CASE_RETURN_TEXT(RFC_STATE_SABME_WAIT_UA);
62 CASE_RETURN_TEXT(RFC_STATE_ORIG_WAIT_SEC_CHECK);
63 CASE_RETURN_TEXT(RFC_STATE_TERM_WAIT_SEC_CHECK);
64 CASE_RETURN_TEXT(RFC_STATE_OPENED);
65 CASE_RETURN_TEXT(RFC_STATE_DISC_WAIT_UA);
66 default:
67 return std::string("UNKNOWN[") + std::to_string(state) + std::string("]");
68 }
69 }
70
71 namespace std {
72 template <>
73 struct formatter<tRFC_MX_STATE> : enum_formatter<tRFC_MX_STATE> {};
74 template <>
75 struct formatter<tRFC_PORT_STATE> : enum_formatter<tRFC_PORT_STATE> {};
76
77 } // namespace std
78