17 #include "../../gsmstate.h" 19 #ifdef GSM_ENABLE_SERIALDEVICE 35 #include "../../gsmcomon.h" 44 # define B57600 0010001 47 # define B115200 0010002 50 # define B230400 0010003 60 # define SERIAL_DEFAULT_SPEED 115200 62 # define SERIAL_DEFAULT_SPEED 19200 64 # define SERIAL_DEFAULT_SPEED 9600 67 static baud_record baud_table[] = {
108 { _B230400, 230400 },
115 { _B460800, 460800 },
128 { B1000000, 1000000 },
131 { B1152000, 1152000 },
134 { B1500000, 1500000 },
137 { B2000000, 2000000 },
140 { B2500000, 2500000 },
143 { B3000000, 3000000 },
146 { B3500000, 3500000 },
149 { B4000000, 4000000 },
164 flock(d->
hPhone, LOCK_UN);
185 if (orig_errno == ENOENT) {
188 if (orig_errno == EACCES) {
197 ioctl(d->
hPhone, TIOCEXCL, (
char *) 0);
201 ioctl(d->
hPhone, I_SETSIG, (
char *) 0);
205 if (flock(d->
hPhone, LOCK_EX | LOCK_NB) != 0) {
206 if (errno == EWOULDBLOCK) {
207 GSM_OSErrorInfo(s,
"failed to lock device, probably opened by other process");
218 if (tcflush(d->
hPhone, TCIOFLUSH) == -1) {
233 t.c_cflag = B0 | CS8 | CREAD | CLOCAL | HUPCL;
240 if (tcsetattr(d->
hPhone, TCSANOW, &t) == -1) {
256 if (tcgetattr(d->
hPhone, &t)) {
262 t.c_cflag |= (PARENB | PARODD);
268 if (tcsetattr(d->
hPhone, TCSANOW, &t) == -1){
287 if (tcgetattr(d->
hPhone, &t)) {
294 t.c_cflag &= ~CRTSCTS;
297 if (tcsetattr(d->
hPhone, TCSANOW, &t) == -1) {
305 ioctl(d->
hPhone, TIOCMBIS, &flags);
307 ioctl(d->
hPhone, TIOCMBIC, &flags);
312 ioctl(d->
hPhone, TIOCMBIS, &flags);
314 ioctl(d->
hPhone, TIOCMBIC, &flags);
318 ioctl(d->
hPhone, TIOCMGET, &flags);
321 smprintf(s,
" DTR is %s", flags & TIOCM_DTR ?
"up" :
"down");
322 smprintf(s,
", RTS is %s", flags & TIOCM_RTS ?
"up" :
"down");
323 smprintf(s,
", CAR is %s", flags & TIOCM_CAR ?
"up" :
"down");
324 smprintf(s,
", CTS is %s\n", flags & TIOCM_CTS ?
"up" :
"down");
326 if (((flags & TIOCM_DTR) == TIOCM_DTR) != dtr) {
327 smprintf(s,
"Setting DTR failed, disabling setting of DTR/RTS signals.\n");
331 if (((flags & TIOCM_RTS) == TIOCM_RTS) != rts) {
332 smprintf(s,
"Setting RTS failed, disabling setting of DTR/RTS signals.\n");
343 baud_record *curr = baud_table;
349 if (tcgetattr(d->
hPhone, &t)) {
354 while (curr->value != speed) {
357 if (curr->value == 0) {
358 if (speed == SERIAL_DEFAULT_SPEED) {
362 speed = SERIAL_DEFAULT_SPEED;
366 smprintf(s,
"Setting speed to %d\n", curr->value);
368 cfsetispeed(&t, curr->code);
369 cfsetospeed(&t, curr->code);
371 if (tcsetattr(d->
hPhone, TCSADRAIN, &t) == -1) {
383 struct timeval timeout2;
390 FD_SET(d->
hPhone, &readfds);
393 timeout2.tv_usec = 50000;
395 if (select(d->
hPhone+1, &readfds, NULL, NULL, &timeout2)) {
396 actual = read(d->
hPhone, buf, nbytes);
402 static int serial_write(
GSM_StateMachine *s,
const void *buf,
size_t nbytes)
407 const unsigned char *buffer = (
const unsigned char *)buf;
412 ret = write(d->
hPhone, buffer, nbytes - actual);
414 if (errno == EAGAIN) {
418 if (actual != nbytes) {
420 smprintf(s,
"Wanted to write %ld bytes, but %ld were written\n",
421 (
long)nbytes, (
long)actual);
428 }
while (actual < nbytes);
GSM_Config * CurrentConfig
union GSM_Device::@0 Data
GSM_ConnectionType ConnectionType
void GSM_OSErrorInfo(GSM_StateMachine *s, const char *description)
struct termios old_settings
int smprintf(GSM_StateMachine *s, const char *format,...)