• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /*
20  * Define states and events for the RFC multiplexer state machine
21  */
22 typedef enum : uint16_t {
23   RFC_MX_STATE_IDLE = 0,
24   RFC_MX_STATE_WAIT_CONN_CNF = 1,
25   RFC_MX_STATE_CONFIGURE = 2,
26   RFC_MX_STATE_SABME_WAIT_UA = 3,
27   RFC_MX_STATE_WAIT_SABME = 4,
28   RFC_MX_STATE_CONNECTED = 5,
29   RFC_MX_STATE_DISC_WAIT_UA = 6,
30 } tRFC_MX_STATE;
31 
32 /*
33  * Define port states
34  */
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 
44 #define CASE_RETURN_TEXT(code) \
45   case code:                   \
46     return #code
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 #undef CASE_RETURN_TEXT
76