1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __UM_SLIP_COMMON_H
3 #define __UM_SLIP_COMMON_H
6 /* two bytes each for a (pathological) max packet of escaped chars + *
7 * terminating END char + initial END char */
8 #define ENC_BUF_SIZE (2 * BUF_SIZE + 2)
10 /* SLIP protocol characters. */
11 #define SLIP_END 0300 /* indicates end of frame */
12 #define SLIP_ESC 0333 /* indicates byte stuffing */
13 #define SLIP_ESC_END 0334 /* ESC ESC_END means END 'data' */
14 #define SLIP_ESC_ESC 0335 /* ESC ESC_ESC means ESC 'data' */
16 static inline int slip_unesc(unsigned char c, unsigned char *buf, int *pos,
47 static inline int slip_esc(unsigned char *s, unsigned char *d, int len)
49 unsigned char *ptr = d;
53 * Send an initial END character to flush out any
54 * data that may have accumulated in the receiver
61 * For each byte in the packet, send the appropriate
62 * character sequence, according to the SLIP protocol.
69 *ptr++ = SLIP_ESC_END;
73 *ptr++ = SLIP_ESC_ESC;
85 unsigned char ibuf[ENC_BUF_SIZE];
86 unsigned char obuf[ENC_BUF_SIZE];
87 int more; /* more data: do not read fd until ibuf has been drained */
92 static inline void slip_proto_init(struct slip_proto * slip)
94 memset(slip->ibuf, 0, sizeof(slip->ibuf));
95 memset(slip->obuf, 0, sizeof(slip->obuf));
101 extern int slip_proto_read(int fd, void *buf, int len,
102 struct slip_proto *slip);
103 extern int slip_proto_write(int fd, void *buf, int len,
104 struct slip_proto *slip);