diff options
author | John Crispin <blogic@openwrt.org> | 2015-01-20 06:33:49 +0000 |
---|---|---|
committer | John Crispin <blogic@openwrt.org> | 2015-01-20 06:33:49 +0000 |
commit | 410d22ac0358660dc54ffc100b023e29bc90133f (patch) | |
tree | e358b221616faa3d7c48203d19188f2b0208483c | |
parent | ea4c8284ee45cab04ae1ffd6193e88f57459bdb9 (diff) | |
download | upstream-410d22ac0358660dc54ffc100b023e29bc90133f.tar.gz upstream-410d22ac0358660dc54ffc100b023e29bc90133f.tar.bz2 upstream-410d22ac0358660dc54ffc100b023e29bc90133f.zip |
comgt: Allow using non-TTY devices
Some Huawei mobile broadband sticks utilizing the NCM protocol expose
the control channel as a cdc-wdm device node instead of a virtual TTY.
This device node does not support the terminal ioctls. This patch
adds a check whether the provided device is a TTY or not and does not
attempt to use the terminal ioctls if they are not supported.
v2: reduce diffstat by simplifying code a little
Signed-off-by: Matti Laakso <malaakso@elisanet.fi>
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@44054 3c298f89-4303-0410-b956-a3cf2f4a3e73
-rw-r--r-- | package/network/utils/comgt/patches/004-check_tty.patch | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/package/network/utils/comgt/patches/004-check_tty.patch b/package/network/utils/comgt/patches/004-check_tty.patch new file mode 100644 index 0000000000..b81b0514c8 --- /dev/null +++ b/package/network/utils/comgt/patches/004-check_tty.patch @@ -0,0 +1,68 @@ +--- a/comgt.c ++++ b/comgt.c +@@ -91,6 +91,7 @@ unsigned long hstart,hset; + char NullString[]={ "" }; + BOOL lastcharnl=1; /* Indicate that last char printed from getonebyte + was a nl, so no new one is needed */ ++BOOL tty=1; + + + //"open com \"/dev/modem\"\nset com 38400n81\nset senddelay 0.05\nsend \"ATi^m\"\nget 2 \" ^m\" $s\nprint \"Response : \",$s,\"\\n\"\nget 2 \" ^m\" $s\nprint \"Response :\",$s,\"\\n\"\nget 2 \" ^m\" $s\nprint \"Response : \",$s,\"\\n\"\n\n"; +@@ -920,7 +921,7 @@ BOOL getonoroff(void) { + void setcom(void) { + stbuf.c_cflag &= ~(CBAUD | CSIZE | CSTOPB | CLOCAL | PARENB); + stbuf.c_cflag |= (speed | bits | CREAD | clocal | parity | stopbits ); +- if (ioctl(comfd, TCSETA, &stbuf) < 0) { ++ if (tty && ioctl(comfd, TCSETA, &stbuf) < 0) { + serror("Can't ioctl set device",1); + } + } +@@ -1224,7 +1225,7 @@ void doclose(void) { + if(strcmp(token,"hardcom")==0) { + if(comfd== -1) serror("Com device not open",1); + vmsg("Closing device"); +- if (ioctl(comfd, TCSETA, &svbuf) < 0) { ++ if (tty && ioctl(comfd, TCSETA, &svbuf) < 0) { + sprintf(msg,"Can't ioctl set device %s.\n",device); + serror(msg,1); + } +@@ -1266,12 +1267,17 @@ void opengt(void) { + ext(1); + } + } +- if (ioctl (comfd, TCGETA, &svbuf) < 0) { ++ if (isatty (comfd)) ++ tty=1; ++ else ++ tty=0; ++ if (tty && ioctl (comfd, TCGETA, &svbuf) < 0) { + sprintf(msg,"Can't control %s, please try again.\n",device); + serror(msg,1); + } + setenv("COMGTDEVICE",device,1); +- ioctl(comfd, TCGETA, &stbuf); ++ if (tty) ++ ioctl(comfd, TCGETA, &stbuf); + speed=stbuf.c_cflag & CBAUD; + if (high_speed == 0) strcpy(cspeed,"115200"); + else strcpy(cspeed,"57600"); +@@ -1302,12 +1308,16 @@ void opendevice(void) { + } + } + else comfd=0; +- +- if (ioctl (comfd, TCGETA, &svbuf) < 0) { ++ if (isatty (comfd)) ++ tty=1; ++ else ++ tty=0; ++ if (tty && ioctl (comfd, TCGETA, &svbuf) < 0) { + sprintf(msg,"Can't ioctl get device %s.\n",device); + serror(msg,1); + } +- ioctl(comfd, TCGETA, &stbuf); ++ if (tty) ++ ioctl(comfd, TCGETA, &stbuf); + speed=stbuf.c_cflag & CBAUD; + switch(speed) { + case B0: strcpy(cspeed,"0");break; |