blob: 5ce8fb8ae0cb70dd6bf1f3f5070f2883e163ae2b [file] [log] [blame]
Eric Holmberg8ed30f22012-05-10 19:16:51 -06001/* drivers/tty/smux_private.h
2 *
3 * Copyright (c) 2012, Code Aurora Forum. All rights reserved.
4 *
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 */
15#ifndef SMUX_PRIVATE_H
16#define SMUX_PRIVATE_H
17
18#define SMUX_MAX_PKT_SIZE 8192
19
20/* SMUX Protocol Characters */
21#define SMUX_MAGIC 0x33FC
22#define SMUX_MAGIC_WORD1 0xFC
23#define SMUX_MAGIC_WORD2 0x33
24#define SMUX_WAKEUP_REQ 0xFD
25#define SMUX_WAKEUP_ACK 0xFE
26
27/* Unit testing characters */
28#define SMUX_UT_ECHO_REQ 0xF0
29#define SMUX_UT_ECHO_ACK_OK 0xF1
30#define SMUX_UT_ECHO_ACK_FAIL 0xF2
31
32struct tty_struct;
33
34/* Packet header. */
35struct smux_hdr_t {
36 uint16_t magic;
37 uint8_t flags;
38 uint8_t cmd;
39 uint8_t pad_len;
40 uint8_t lcid;
41 uint16_t payload_len;
42};
43
44/* Internal packet structure. */
45struct smux_pkt_t {
46 struct smux_hdr_t hdr;
47 int allocated;
48 unsigned char *payload;
49 int free_payload;
50 struct list_head list;
51 void *priv;
52};
53
54/* SMUX Packet Commands */
55enum {
56 SMUX_CMD_DATA = 0x0,
57 SMUX_CMD_OPEN_LCH = 0x1,
58 SMUX_CMD_CLOSE_LCH = 0x2,
59 SMUX_CMD_STATUS = 0x3,
60 SMUX_CMD_PWR_CTL = 0x4,
61
62 SMUX_CMD_BYTE, /* for internal usage */
63 SMUX_NUM_COMMANDS
64};
65
66/* Open command flags */
67enum {
68 SMUX_CMD_OPEN_ACK = 1 << 0,
69 SMUX_CMD_OPEN_POWER_COLLAPSE = 1 << 1,
70 SMUX_CMD_OPEN_REMOTE_LOOPBACK = 1 << 2,
71};
72
73/* Close command flags */
74enum {
75 SMUX_CMD_CLOSE_ACK = 1 << 0,
76};
77
78/* Power command flags */
79enum {
80 SMUX_CMD_PWR_CTL_ACK = 1 << 0,
81 SMUX_CMD_PWR_CTL_SLEEP_REQ = 1 << 1,
82};
83
84/* Local logical channel states */
85enum {
86 SMUX_LCH_LOCAL_CLOSED,
87 SMUX_LCH_LOCAL_OPENING,
88 SMUX_LCH_LOCAL_OPENED,
89 SMUX_LCH_LOCAL_CLOSING,
90};
91
92/* Remote logical channel states */
93enum {
94 SMUX_LCH_REMOTE_CLOSED,
95 SMUX_LCH_REMOTE_OPENED,
96};
97
98
99int smux_assert_lch_id(uint32_t lcid);
100void smux_init_pkt(struct smux_pkt_t *pkt);
101struct smux_pkt_t *smux_alloc_pkt(void);
102int smux_alloc_pkt_payload(struct smux_pkt_t *pkt);
103void smux_free_pkt(struct smux_pkt_t *pkt);
104int smux_serialize(struct smux_pkt_t *pkt, char *out,
105 unsigned int *out_len);
106
107void smux_rx_state_machine(const unsigned char *data, int len, int flag);
108void smuxld_receive_buf(struct tty_struct *tty, const unsigned char *cp,
109 char *fp, int count);
110
111/* testing parameters */
112extern int smux_byte_loopback;
113extern int smux_simulate_wakeup_delay;
114
115#endif /* SMUX_PRIVATE_H */