2 * This file is part of the libserialport project.
4 * Copyright (C) 2013 Martin Ling <martin-libserialport@earth.li>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * At the time of writing, glibc does not support the Linux kernel interfaces
22 * for setting non-standard baud rates and flow control. We therefore have to
23 * prepare the correct ioctls ourselves, for which we need the declarations in
26 * We can't include linux/termios.h in serialport.c however, because its
27 * contents conflict with the termios.h provided by glibc. So this file exists
28 * to isolate the bits of code which use the kernel termios declarations.
30 * The details vary by architecture. Some architectures have c_ispeed/c_ospeed
31 * in struct termios, accessed with TCSETS/TCGETS. Others have these fields in
32 * struct termios2, accessed with TCSETS2/TCGETS2. Some architectures have the
33 * TCSETX/TCGETX ioctls used with struct termiox, others do not.
36 #include <linux/termios.h>
37 #include "linux_termios.h"
39 int get_termios_get_ioctl(void)
48 int get_termios_set_ioctl(void)
57 int get_termios_size(void)
60 return sizeof(struct termios2
);
62 return sizeof(struct termios
);
66 #if defined(HAVE_TERMIOS_SPEED) || defined(HAVE_TERMIOS2_SPEED)
67 int get_termios_speed(void *data
)
70 struct termios2
*term
= (struct termios2
*) data
;
72 struct termios
*term
= (struct termios
*) data
;
74 if (term
->c_ispeed
!= term
->c_ospeed
)
77 return term
->c_ispeed
;
80 void set_termios_speed(void *data
, int speed
)
83 struct termios2
*term
= (struct termios2
*) data
;
85 struct termios
*term
= (struct termios
*) data
;
87 term
->c_cflag
&= ~CBAUD
;
88 term
->c_cflag
|= BOTHER
;
89 term
->c_ispeed
= term
->c_ospeed
= speed
;
94 int get_termiox_size(void)
96 return sizeof(struct termiox
);
99 int get_termiox_flow(void *data
, int *rts
, int *cts
, int *dtr
, int *dsr
)
101 struct termiox
*termx
= (struct termiox
*) data
;
104 *rts
= (termx
->x_cflag
& RTSXOFF
);
105 *cts
= (termx
->x_cflag
& CTSXON
);
106 *dtr
= (termx
->x_cflag
& DTRXOFF
);
107 *dsr
= (termx
->x_cflag
& DSRXON
);
112 void set_termiox_flow(void *data
, int rts
, int cts
, int dtr
, int dsr
)
114 struct termiox
*termx
= (struct termiox
*) data
;
116 termx
->x_cflag
&= ~(RTSXOFF
| CTSXON
| DTRXOFF
| DSRXON
);
119 termx
->x_cflag
|= RTSXOFF
;
121 termx
->x_cflag
|= CTSXON
;
123 termx
->x_cflag
|= DTRXOFF
;
125 termx
->x_cflag
|= DSRXON
;