]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/um/drivers/slip_proto.h
Linux-2.6.12-rc2
[mirror_ubuntu-artful-kernel.git] / arch / um / drivers / slip_proto.h
1 /*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6 #ifndef __UM_SLIP_PROTO_H__
7 #define __UM_SLIP_PROTO_H__
8
9 /* SLIP protocol characters. */
10 #define SLIP_END 0300 /* indicates end of frame */
11 #define SLIP_ESC 0333 /* indicates byte stuffing */
12 #define SLIP_ESC_END 0334 /* ESC ESC_END means END 'data' */
13 #define SLIP_ESC_ESC 0335 /* ESC ESC_ESC means ESC 'data' */
14
15 static inline int slip_unesc(unsigned char c,char *buf,int *pos, int *esc)
16 {
17 int ret;
18
19 switch(c){
20 case SLIP_END:
21 *esc = 0;
22 ret=*pos;
23 *pos=0;
24 return(ret);
25 case SLIP_ESC:
26 *esc = 1;
27 return(0);
28 case SLIP_ESC_ESC:
29 if(*esc){
30 *esc = 0;
31 c = SLIP_ESC;
32 }
33 break;
34 case SLIP_ESC_END:
35 if(*esc){
36 *esc = 0;
37 c = SLIP_END;
38 }
39 break;
40 }
41 buf[(*pos)++] = c;
42 return(0);
43 }
44
45 static inline int slip_esc(unsigned char *s, unsigned char *d, int len)
46 {
47 unsigned char *ptr = d;
48 unsigned char c;
49
50 /*
51 * Send an initial END character to flush out any
52 * data that may have accumulated in the receiver
53 * due to line noise.
54 */
55
56 *ptr++ = SLIP_END;
57
58 /*
59 * For each byte in the packet, send the appropriate
60 * character sequence, according to the SLIP protocol.
61 */
62
63 while (len-- > 0) {
64 switch(c = *s++) {
65 case SLIP_END:
66 *ptr++ = SLIP_ESC;
67 *ptr++ = SLIP_ESC_END;
68 break;
69 case SLIP_ESC:
70 *ptr++ = SLIP_ESC;
71 *ptr++ = SLIP_ESC_ESC;
72 break;
73 default:
74 *ptr++ = c;
75 break;
76 }
77 }
78 *ptr++ = SLIP_END;
79 return (ptr - d);
80 }
81
82 #endif
83
84 /*
85 * Overrides for Emacs so that we follow Linus's tabbing style.
86 * Emacs will notice this stuff at the end of the file and automatically
87 * adjust the settings for this buffer only. This must remain at the end
88 * of the file.
89 * ---------------------------------------------------------------------------
90 * Local variables:
91 * c-file-style: "linux"
92 * End:
93 */