blob: 2c8819ce16d6992a47a6a9839b76472f1d10aa6a [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
Eric Holmbergb8435c82012-06-05 14:51:29 -060032/* Maximum number of packets in retry queue */
33#define SMUX_RX_RETRY_MAX_PKTS 32
34
Eric Holmberg8ed30f22012-05-10 19:16:51 -060035struct tty_struct;
36
37/* Packet header. */
38struct smux_hdr_t {
39 uint16_t magic;
40 uint8_t flags;
41 uint8_t cmd;
42 uint8_t pad_len;
43 uint8_t lcid;
44 uint16_t payload_len;
45};
46
47/* Internal packet structure. */
48struct smux_pkt_t {
49 struct smux_hdr_t hdr;
50 int allocated;
51 unsigned char *payload;
52 int free_payload;
53 struct list_head list;
54 void *priv;
55};
56
57/* SMUX Packet Commands */
58enum {
59 SMUX_CMD_DATA = 0x0,
60 SMUX_CMD_OPEN_LCH = 0x1,
61 SMUX_CMD_CLOSE_LCH = 0x2,
62 SMUX_CMD_STATUS = 0x3,
63 SMUX_CMD_PWR_CTL = 0x4,
64
65 SMUX_CMD_BYTE, /* for internal usage */
66 SMUX_NUM_COMMANDS
67};
68
69/* Open command flags */
70enum {
71 SMUX_CMD_OPEN_ACK = 1 << 0,
72 SMUX_CMD_OPEN_POWER_COLLAPSE = 1 << 1,
73 SMUX_CMD_OPEN_REMOTE_LOOPBACK = 1 << 2,
74};
75
76/* Close command flags */
77enum {
78 SMUX_CMD_CLOSE_ACK = 1 << 0,
79};
80
81/* Power command flags */
82enum {
83 SMUX_CMD_PWR_CTL_ACK = 1 << 0,
Eric Holmberg8ed30f22012-05-10 19:16:51 -060084};
85
86/* Local logical channel states */
87enum {
88 SMUX_LCH_LOCAL_CLOSED,
89 SMUX_LCH_LOCAL_OPENING,
90 SMUX_LCH_LOCAL_OPENED,
91 SMUX_LCH_LOCAL_CLOSING,
92};
93
94/* Remote logical channel states */
95enum {
96 SMUX_LCH_REMOTE_CLOSED,
97 SMUX_LCH_REMOTE_OPENED,
98};
99
100
101int smux_assert_lch_id(uint32_t lcid);
102void smux_init_pkt(struct smux_pkt_t *pkt);
103struct smux_pkt_t *smux_alloc_pkt(void);
104int smux_alloc_pkt_payload(struct smux_pkt_t *pkt);
105void smux_free_pkt(struct smux_pkt_t *pkt);
106int smux_serialize(struct smux_pkt_t *pkt, char *out,
107 unsigned int *out_len);
108
109void smux_rx_state_machine(const unsigned char *data, int len, int flag);
110void smuxld_receive_buf(struct tty_struct *tty, const unsigned char *cp,
111 char *fp, int count);
112
113/* testing parameters */
114extern int smux_byte_loopback;
115extern int smux_simulate_wakeup_delay;
116
117#endif /* SMUX_PRIVATE_H */