/*
* AT Command Utilities (and terminal stuff for now)
*
* Copyright (C) 2010 by Multi-Tech Systems
*
* Author: James Maki <jmaki@multitech.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#define _GNU_SOURCE
#define __ATCMD_C 1
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <errno.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <string.h>
#include "global.h"
#include "log.h"
#include "utils.h"
#include "atcmd.h"
#include "sms_utils.h"
static const struct baud_map __baud_map[] = {
{B300, 300},
{B600, 600},
{B1200, 1200},
{B1800, 1800},
{B2400, 2400},
{B4800, 4800},
{B9600, 9600},
{B19200, 19200},
{B38400, 38400},
{B57600, 57600},
{B115200, 115200},
{B230400, 230400},
{B460800, 460800},
{B921600, 921600},
};
speed_t value_to_baud(speed_t value)
{
int n = ARRAY_SIZE(__baud_map);
int i;
for (i = 0; i < n; ++i) {
if (__baud_map[i].value == value) {
return __baud_map[i].baud;
}
}
log_warning("baud rate not valid: %lu", (unsigned long) value);
return (speed_t) -1;
}
int rts_get(int fd)
{
int err;
int status;
err = ioctl(fd, TIOCMGET, &status);
if (err < 0) {
return -1;
}
return status & TIOCM_RTS ? 1 : 0;
}
int dtr_get(int fd)
{
int err;
int status;
err = ioctl(fd, TIOCMGET, &status);
if (err < 0) {
return -1;
}
return status & TIOCM_DTR ? 1 : 0;
}
int cts_get(int fd)
{
int err;
int status;
err = ioctl(fd, TIOCMGET, &status);
if (err < 0) {
return -1;
}
return status & TIOCM_CTS ? 1 : 0;
}
int dsr_get(int fd)
{
int err;
int status;
err = ioctl(fd, TIOCMGET, &status);
if (err < 0) {
return -1;
}
return status & TIOCM_DSR ? 1 : 0;
}
int cd_get(int fd)
{
int err;
int status;
err = ioctl(fd, TIOCMGET, &status);
if (err < 0) {
return -1;
}
return status & TIOCM_CD ? 1 : 0;
}
int ri_get(int fd)
{
int err;
int status;
err = ioctl(fd, TIOCMGET, &status);
if (err < 0) {
return -1;
}
return status & TIOCM_RI ? 1 : 0;
}
int line_signal_set(int fd, int signal, int value)
{
int err;
int status;
err = ioctl(fd, TIOCMGET, &status);
if (err < 0
|