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