1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
Description: update dzcomm allegro library for USB serial device support.
Author: Kees Cook <kees@outflux.net>
Origin: http://sourceforge.net/tracker/?func=detail&aid=1930348&group_id=48395&atid=457650
Index: scantool-1.21/dzcomm/AUTHORS
===================================================================
--- scantool-1.21.orig/dzcomm/AUTHORS 2011-05-22 17:41:07.034735699 -0700
+++ scantool-1.21/dzcomm/AUTHORS 2011-05-22 17:41:36.805151087 -0700
@@ -31,3 +31,6 @@
Made it IRQ sharing and now trying to move it to multi-platform
status.
+ Kees Cook (kees@outflux.net).
+ Fix for USB serial devices.
+
Index: scantool-1.21/dzcomm/configure.in
===================================================================
--- scantool-1.21.orig/dzcomm/configure.in 2011-05-22 17:41:07.084736399 -0700
+++ scantool-1.21/dzcomm/configure.in 2011-05-22 17:41:36.805151087 -0700
@@ -263,21 +263,27 @@
AC_DEFINE(MAP_FAILED, [(void *)-1])
fi
-dnl Some miscellaneous defines.
DZCOMM_MAYBE_LINUX_FILES=DZCOMM_EMPTY_LIST
-dzcomm_system=`uname -s | tr A-Z a-z`
-case "$dzcomm_system" in
+if test "$dzcomm_support_linux" = yes; then
+ AC_MSG_CHECKING([whether we are using Linux])
-*linux*)
- if test "$dzcomm_support_linux" = yes; then
+ dzcomm_system=`uname -s | tr A-Z a-z`
+ case "$dzcomm_system" in
+
+ *linux*)
+ AC_MSG_RESULT([yes])
AC_DEFINE(DZCOMM_LINUX)
+ AC_SUBST(DZCOMM_LINUX)
DZCOMM_MAYBE_LINUX_FILES=DZCOMM_SRC_LINUX_FILES
+ ;;
- fi
- ;;
+ *)
+ AC_MSG_RESULT([no])
+ ;;
-esac
+ esac
+fi
AC_SUBST(DZCOMM_MAYBE_LINUX_FILES)
Index: scantool-1.21/dzcomm/dzcomm.txt
===================================================================
--- scantool-1.21.orig/dzcomm/dzcomm.txt 2011-05-22 17:41:07.104736677 -0700
+++ scantool-1.21/dzcomm/dzcomm.txt 2011-05-22 17:41:36.805151087 -0700
@@ -395,6 +395,32 @@
A break signal is issued on the serial line. The break signal will be at
least of the duration specified. It may be longer.
+int comm_port_give_line_status(comm_port *port, dzcomm_line line);
+ Returns the value (1 or 0) of the register requested or -1 on failure. Note
+ that the value returned is the inverse of the physical state of the line
+ connected to the UART because the control lines on a UART are all low
+ when the register is high and vice versa.
+
+ The control line is defined using the following enum:
+
+ typedef enum {DZCOMM_DTR, DZCOMM_RTS, DZCOMM_CTS, DZCOMM_DSR} dzcomm_line;
+
+
+int comm_port_set_line_status(comm_port *port, dzcomm_line line, int value);
+ Sets the value of the register requested and return 1 on success or -1 on
+ failure. Note that the physical state of the line connected to the UART
+ will be the inverse of the value set here because the control lines on
+ a UART are all low when the register is high and vice versa.
+
+ The control line is defined using the following enum:
+
+ typedef enum {DZCOMM_DTR, DZCOMM_RTS, DZCOMM_CTS, DZCOMM_DSR} dzcomm_line;
+
+
+ Be careful when using this function - if you are using CTS_RTS flow
+ control or if the UART at the other end is snesitive to it, you may
+ cause confusion ...
+
int modem_hangup(comm_port *port);
Sends "+++ATH0" to the line which tells it to hang up if it's a modem. Returns
one if the entire string (including the concluding '\r') is placed on the output
Index: scantool-1.21/dzcomm/include/dzcomm.h
===================================================================
--- scantool-1.21.orig/dzcomm/include/dzcomm.h 2011-05-22 17:41:06.994735142 -0700
+++ scantool-1.21/dzcomm/include/dzcomm.h 2011-05-22 17:41:36.805151087 -0700
@@ -192,6 +192,8 @@
unsigned short int SCR; /* SCR Register */
unsigned short int ISR_8259; /* interrupt service register */
unsigned short int IMR_8259; /* interrupt mask register */
+
+ unsigned short int sio_missing; /* Should TIOCSSERIAL be skipped? */
} comm_port;
typedef DZ_METHOD(int, dz_ll_handler, (comm_port *, int));
Index: scantool-1.21/dzcomm/include/dzcomm/dzconfig.h
===================================================================
--- scantool-1.21.orig/dzcomm/include/dzcomm/dzconfig.h 2011-05-22 17:41:07.014735420 -0700
+++ scantool-1.21/dzcomm/include/dzcomm/dzconfig.h 2011-05-22 17:41:36.815151226 -0700
@@ -50,7 +50,9 @@
#define CONSTRUCTOR_FUNCTION(func) func __attribute__ ((constructor))
- #define INLINE inline
+ #ifndef INLINE
+ # define INLINE inline
+ #endif
#ifndef ZERO_SIZE
#define ZERO_SIZE 0
Index: scantool-1.21/dzcomm/src/comm.c
===================================================================
--- scantool-1.21.orig/dzcomm/src/comm.c 2011-05-22 17:41:07.064736120 -0700
+++ scantool-1.21/dzcomm/src/comm.c 2011-05-22 17:41:36.815151226 -0700
@@ -448,7 +448,10 @@
/* And call the Machine/OS appropriate installer */
if (comm_port_funcs->install_handler) {
- if (comm_port_funcs->install_handler(port) == 0) return 0;
+ if (comm_port_funcs->install_handler(port) == 0) {
+ dz_make_comm_err("OS handler failed.");
+ return 0;
+ }
}
switch(port->nData) {
@@ -650,8 +653,8 @@
(port->installed == PORT_NOT_INSTALLED) || (comm_port_funcs->out == NULL)) return 0;
/* Make sure it is being sent in a machine/OS correct way */
- c = comm_port_funcs->out(port, s);
- for (i=1; ((s[i]!=0) && (c==i)); i++) c += comm_port_funcs->out(port, &s[i]);
+ c = comm_port_funcs->out(port, (unsigned char *)s);
+ for (i=1; ((s[i]!=0) && (c==i)); i++) c += comm_port_funcs->out(port, (unsigned char *)&s[i]);
return c;
}
@@ -668,9 +671,9 @@
(port->installed == PORT_NOT_INSTALLED) || (comm_port_funcs->out == NULL)) return 0;
/* Make sure it is being sent in a machine/OS correct way */
- c = comm_port_funcs->out(port, s);
- for (i=1; ((s[i]!=0) && (c==i)); i++) c += comm_port_funcs->out(port, &s[i]);
- if (c==i) c += comm_port_funcs->out(port, &r);
+ c = comm_port_funcs->out(port, (unsigned char *)s);
+ for (i=1; ((s[i]!=0) && (c==i)); i++) c += comm_port_funcs->out(port, (unsigned char *)&s[i]);
+ if (c==i) c += comm_port_funcs->out(port, (unsigned char *)&r);
return c;
}
Index: scantool-1.21/dzcomm/src/linux/lcomm.c
===================================================================
--- scantool-1.21.orig/dzcomm/src/linux/lcomm.c 2011-05-22 17:41:07.054735980 -0700
+++ scantool-1.21/dzcomm/src/linux/lcomm.c 2011-05-22 18:37:49.531191384 -0700
@@ -75,7 +75,6 @@
struct termios tio;
speed_t i_speed;
speed_t o_speed;
- int sio_avail = 1;
int tio_avail = 1;
/*
@@ -85,12 +84,21 @@
* into our structure and return. The user then call the _set_ routines
* which are implemented on the port_install call.
*/
- sprintf(port->szName, "/dev/ttyS%x", (int) com);
+ sprintf(port->szName, "/dev/ttyUSB%x", (int) com);
+ /* USB serial ports don't have this information */
+ port->sio_missing = 1;
port->fd = open(port->szName, O_RDWR | O_NOCTTY | O_NONBLOCK );
- if (port->fd == -1) return NULL;
+ if (port->fd == -1) {
+ sprintf(port->szName, "/dev/ttyS%x", (int) com);
+ port->fd = open(port->szName, O_RDWR | O_NOCTTY | O_NONBLOCK );
+ if (port->fd == -1) {
+ return NULL;
+ }
+ }
+ fprintf(stderr, "opened %s\n", port->szName);
if (tcgetattr(port->fd, &tio) == -1) tio_avail = 0;
- if (ioctl(port->fd, TIOCGSERIAL, &sio) < 0) sio_avail = 0;
+ if (ioctl(port->fd, TIOCGSERIAL, &sio) < 0) port->sio_missing = 1;
if (tio_avail == 1) {
if (tio.c_cflag & CSTOPB) port->nStop = STOP_2;
@@ -161,7 +169,7 @@
port->nBaud = _9600;
}
- if (sio_avail) {
+ if (!port->sio_missing) {
port->nPort = sio.port;
port->nIRQ = sio.irq;
}
@@ -256,8 +264,16 @@
cfsetospeed(&tio, speed);
cfsetispeed(&tio, speed);
- if (ioctl(port->fd, TIOCSSERIAL, &sio) < 0) return 0;
- if (ioctl(port->fd, TIOCSERCONFIG) < 0) return 0;
+ if (!port->sio_missing) {
+ if (ioctl(port->fd, TIOCSSERIAL, &sio) < 0) {
+ perror("ioctl(TIOCSSERIAL)");
+ return 0;
+ }
+ if (ioctl(port->fd, TIOCSERCONFIG) < 0) {
+ perror("ioctl(TIOCSERCONFIG)");
+ return 0;
+ }
+ }
tcsetattr(port->fd, TCSANOW, &tio);
return 1;
@@ -312,7 +328,7 @@
/*-------------- LINUX COMM SET LINE STATUS ------------------------------*/
int linux_comm_set_line_status(comm_port *port, dzcomm_line line, int value)
{
- int flag;
+ int flag=0;
if ((line == DZCOMM_CTS) || (line == DZCOMM_DSR)) return -1;
|