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