| Eric Holmberg | 8ed30f2 | 2012-05-10 19:16:51 -0600 | [diff] [blame] | 1 | /* 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 Holmberg | ffddd4c | 2012-06-08 12:37:51 -0600 | [diff] [blame^] | 19 | #define SMUX_BROADCAST_LCID 0xFF |
| Eric Holmberg | 8ed30f2 | 2012-05-10 19:16:51 -0600 | [diff] [blame] | 20 | |
| 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 Holmberg | b8435c8 | 2012-06-05 14:51:29 -0600 | [diff] [blame] | 33 | /* Maximum number of packets in retry queue */ |
| 34 | #define SMUX_RX_RETRY_MAX_PKTS 32 |
| 35 | |
| Eric Holmberg | 8ed30f2 | 2012-05-10 19:16:51 -0600 | [diff] [blame] | 36 | struct tty_struct; |
| 37 | |
| 38 | /* Packet header. */ |
| 39 | struct 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. */ |
| 49 | struct 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 */ |
| 59 | enum { |
| 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 */ |
| 71 | enum { |
| 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 */ |
| 78 | enum { |
| 79 | SMUX_CMD_CLOSE_ACK = 1 << 0, |
| 80 | }; |
| 81 | |
| 82 | /* Power command flags */ |
| 83 | enum { |
| 84 | SMUX_CMD_PWR_CTL_ACK = 1 << 0, |
| Eric Holmberg | 8ed30f2 | 2012-05-10 19:16:51 -0600 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | /* Local logical channel states */ |
| 88 | enum { |
| 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 */ |
| 96 | enum { |
| 97 | SMUX_LCH_REMOTE_CLOSED, |
| 98 | SMUX_LCH_REMOTE_OPENED, |
| 99 | }; |
| 100 | |
| 101 | |
| 102 | int smux_assert_lch_id(uint32_t lcid); |
| 103 | void smux_init_pkt(struct smux_pkt_t *pkt); |
| 104 | struct smux_pkt_t *smux_alloc_pkt(void); |
| 105 | int smux_alloc_pkt_payload(struct smux_pkt_t *pkt); |
| 106 | void smux_free_pkt(struct smux_pkt_t *pkt); |
| 107 | int smux_serialize(struct smux_pkt_t *pkt, char *out, |
| 108 | unsigned int *out_len); |
| 109 | |
| 110 | void smux_rx_state_machine(const unsigned char *data, int len, int flag); |
| 111 | void smuxld_receive_buf(struct tty_struct *tty, const unsigned char *cp, |
| 112 | char *fp, int count); |
| 113 | |
| 114 | /* testing parameters */ |
| 115 | extern int smux_byte_loopback; |
| 116 | extern int smux_simulate_wakeup_delay; |
| 117 | |
| 118 | #endif /* SMUX_PRIVATE_H */ |