summaryrefslogtreecommitdiff
path: root/channels
diff options
context:
space:
mode:
authorKevin P. Fleming <kpfleming@digium.com>2006-01-04 23:33:59 +0000
committerKevin P. Fleming <kpfleming@digium.com>2006-01-04 23:33:59 +0000
commitce81ea81221ba91c5931ead9b437b0fec4c5ad7c (patch)
tree0a84c2b5be2406fc5bdc8808c6517345c781c942 /channels
parentc3ce1852bce480784b2aec840689597e40b691c8 (diff)
remove deprecated chan_modem drivers
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7802 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels')
-rw-r--r--channels/Makefile11
-rw-r--r--channels/chan_modem.c1120
-rw-r--r--channels/chan_modem_aopen.c502
-rw-r--r--channels/chan_modem_bestdata.c615
-rw-r--r--channels/chan_modem_i4l.c745
5 files changed, 0 insertions, 2993 deletions
diff --git a/channels/Makefile b/channels/Makefile
index 314a9ee61..56935d941 100644
--- a/channels/Makefile
+++ b/channels/Makefile
@@ -16,11 +16,6 @@
CHANNEL_LIBS=chan_sip.so chan_agent.so chan_mgcp.so chan_iax2.so chan_local.so chan_skinny.so chan_features.so
-ifneq (${OSARCH},CYGWIN)
-# if you really, really want to use these drivers, uncomment the line below
-#CHANNEL_LIBS+=chan_modem.so chan_modem_aopen.so chan_modem_bestdata.so
-endif
-
ifeq ($(findstring BSD,${OSARCH}),BSD)
CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include -L$(CROSS_COMPILE_TARGET)/usr/local/lib
endif
@@ -61,9 +56,6 @@ endif
ifneq (${OSARCH},Darwin)
ifneq (${OSARCH},SunOS)
ifneq (${OSARCH},CYGWIN)
-# the ISDN4Linux channel driver is probably broken on all modern kernels,
-# but if you wish to try to use it, uncomment the line below
-# CHANNEL_LIBS+=chan_modem_i4l.so
CHANNEL_LIBS+=chan_oss.so
endif
endif
@@ -242,9 +234,6 @@ chan_misdn.so: chan_misdn.o chan_misdn_config.o misdn/chan_misdn_lib.a
chan_misdn.o: chan_misdn.c
$(CC) $(CFLAGS) -DCHAN_MISDN_VERSION=\"0.2.1\" -c $< -o $@
-#chan_modem.so : chan_modem.o
-# $(CC) -rdynamic -shared -Xlinker -x -o $@ $<
-
install: all
for x in $(CHANNEL_LIBS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
if ! [ -f chan_iax.so ]; then rm -f $(DESTDIR)$(MODULES_DIR)/chan_iax.so ; fi
diff --git a/channels/chan_modem.c b/channels/chan_modem.c
deleted file mode 100644
index 86f6afa30..000000000
--- a/channels/chan_modem.c
+++ /dev/null
@@ -1,1120 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief A/Open ITU-56/2 Voice Modem Driver (Rockwell, IS-101, and others)
- *
- * \author Mark Spencer <markster@digium.com>
- *
- * \ingroup channel_drivers
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-#include <sys/time.h>
-#include <errno.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/termios.h>
-#include <sys/signal.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/logger.h"
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/vmodem.h"
-#include "asterisk/utils.h"
-
-/* Up to 10 seconds for an echo to arrive */
-#define ECHO_TIMEOUT 10
-
-static const char desc[] = "Generic Voice Modem Driver";
-static const char tdesc[] = "Generic Voice Modem Channel Driver";
-static const char type[] = "Modem";
-static const char config[] = "modem.conf";
-static char dialtype = 'T';
-static int gmode = MODEM_MODE_IMMEDIATE;
-
-/* Default modem type */
-static char mtype[80] = "autodetect";
-/* Default context for incoming calls */
-static char context[AST_MAX_EXTENSION]= "default";
-
-/* Default language */
-static char language[MAX_LANGUAGE] = "";
-
-/* Initialization String */
-static char initstr[AST_MAX_INIT_STR] = "ATE0Q0";
-
-/* Default MSN */
-static char msn[AST_MAX_EXTENSION]="";
-
-/* Default Listen */
-static char incomingmsn[AST_MAX_EXTENSION]="";
-
-/* Default DTMF-detection mode (i4l/asterisk) */
-static int dtmfmode = MODEM_DTMF_AST;
-/* Default DTMF-generation mode (i4l (outband) / asterisk (inband) */
-static int dtmfmodegen = MODEM_DTMF_AST;
-
-struct ast_dsp *dsp = NULL;
-
-/* Default valid outgoing MSN */
-static char outgoingmsn[AST_MAX_EXTENSION]="";
-
-/* Default group */
-static ast_group_t cur_group = 0;
-
-static int usecnt =0;
-
-static int baudrate = 115200;
-
-static int stripmsd = 0;
-
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-/* Protect the interface list (of ast_modem_pvt's) */
-AST_MUTEX_DEFINE_STATIC(iflock);
-
-/* Protect the monitoring thread, so only one process can kill or start it, and not
- when it's doing something critical. */
-AST_MUTEX_DEFINE_STATIC(monlock);
-
-/* This is the thread for the monitor which checks for input on the channels
- which are not currently in use. */
-static pthread_t monitor_thread = AST_PTHREADT_NULL;
-
-static int restart_monitor(void);
-
-int dep_warning = 0;
-
-static struct ast_channel *modem_request(const char *type, int format, void *data, int *cause);
-static int modem_digit(struct ast_channel *ast, char digit);
-static int modem_call(struct ast_channel *ast, char *idest, int timeout);
-static int modem_hangup(struct ast_channel *ast);
-static int modem_answer(struct ast_channel *ast);
-static struct ast_frame *modem_read(struct ast_channel *);
-static int modem_write(struct ast_channel *ast, struct ast_frame *frame);
-static int modem_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
-
-static const struct ast_channel_tech modem_tech = {
- .type = type,
- .description = tdesc,
- .capabilities = AST_FORMAT_SLINEAR,
- .requester = modem_request,
- .send_digit = modem_digit,
- .call = modem_call,
- .hangup = modem_hangup,
- .answer = modem_answer,
- .read = modem_read,
- .write = modem_write,
- .fixup = modem_fixup,
-};
-
-/* The private structures of the Phone Jack channels are linked for
- selecting outgoing channels */
-
-static struct ast_modem_pvt *iflist = NULL;
-
-static int modem_digit(struct ast_channel *ast, char digit)
-{
- struct ast_modem_pvt *p;
- p = ast->tech_pvt;
- if (p->mc->dialdigit)
- return p->mc->dialdigit(p, digit);
- ast_log(LOG_DEBUG, "Channel %s lacks digit dialing\n", ast->name);
- return -1;
-}
-
-static struct ast_modem_driver *drivers = NULL;
-
-static struct ast_modem_driver *find_capability(char *ident)
-{
- struct ast_modem_driver *mc;
- int x;
- mc = drivers;
- while(mc) {
- for (x=0;mc->idents[x];x++) {
- if (!strcmp(ident, mc->idents[x]))
- break;
- }
- if (mc->idents[x])
- break;
- mc = mc->next;
- }
- if (mc) {
- if (mc->incusecnt)
- mc->incusecnt();
- }
- return mc;
-}
-
-static struct ast_modem_driver *find_driver(char *drv)
-{
- struct ast_modem_driver *mc;
- mc = drivers;
- while(mc) {
- if (!strcasecmp(mc->name, drv))
- break;
- mc = mc->next;
- }
- if (mc) {
- if (mc->incusecnt)
- mc->incusecnt();
- }
- return mc;
-}
-
-int ast_register_modem_driver(struct ast_modem_driver *mc)
-{
- mc->next = drivers;
- drivers = mc;
- return 0;
-}
-
-int ast_unregister_modem_driver(struct ast_modem_driver *mc)
-{
- struct ast_modem_driver *last = NULL, *cur;
- cur = drivers;
- while(cur) {
- if (cur == mc) {
- if (last)
- last->next = mc->next;
- else
- drivers = mc->next;
- return 0;
- }
- cur = cur->next;
- }
- return -1;
-}
-
-static int modem_call(struct ast_channel *ast, char *idest, int timeout)
-{
- struct ast_modem_pvt *p;
- int ms = timeout;
- char rdest[80], *where, dstr[100] = "";
- char *stringp=NULL;
- strncpy(rdest, idest, sizeof(rdest)-1);
- stringp=rdest;
- strsep(&stringp, ":");
- where = strsep(&stringp, ":");
- if (!where) {
- ast_log(LOG_WARNING, "Destination %s requres a real destination (device:destination)\n", idest);
- return -1;
- }
- p = ast->tech_pvt;
- strncpy(dstr, where + p->stripmsd, sizeof(dstr) - 1);
- /* if not a transfer or just sending tones, must be in correct state */
- if (strcasecmp(rdest, "transfer") && strcasecmp(rdest,"sendtones")) {
- if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
- ast_log(LOG_WARNING, "modem_call called on %s, neither down nor reserved\n", ast->name);
- return -1;
- }
- }
- if (!strcasecmp(rdest,"transfer")) /* if a transfer, put in transfer stuff */
- {
- snprintf(dstr, sizeof(dstr), "!,%s", where + p->stripmsd);
- }
- if (!strcasecmp(where, "handset")) {
- if (p->mc->setdev)
- if (p->mc->setdev(p, MODEM_DEV_HANDSET))
- return -1;
- /* Should be immediately up */
- ast_setstate(ast, AST_STATE_UP);
- } else {
- if (p->mc->setdev)
- if (p->mc->setdev(p, MODEM_DEV_TELCO_SPK))
- return -1;
- if (p->mc->dial)
- p->mc->dial(p, dstr);
- ast_setstate(ast, AST_STATE_DIALING);
- while((ast->_state != AST_STATE_UP) && (ms > 0)) {
- ms = ast_waitfor(ast, ms);
- /* Just read packets and watch what happens */
- if (ms > 0) {
- if (!modem_read(ast))
- return -1;
- }
- }
- if (ms < 0)
- return -1;
- }
- return 0;
-}
-
-int ast_modem_send(struct ast_modem_pvt *p, char *cmd, int len)
-{
- int i;
- usleep(5000);
- if (!len) {
- for(i = 0; cmd[i];)
- {
- if (fwrite(cmd + i,1,1,p->f) != 1)
- {
- if (errno == EWOULDBLOCK) continue;
- return -1;
- }
- i++;
- }
- tcdrain(fileno(p->f));
- fprintf(p->f,"\r\n");
- return 0;
- } else {
- if (fwrite(cmd, 1, len, p->f) < len)
- return -1;
- return 0;
- }
-}
-
-int ast_modem_read_response(struct ast_modem_pvt *p, int timeout)
-{
- int res = -1,c,i;
- timeout *= 1000;
- p->response[0] = 0;
- c = i = 0;
- do {
- res = ast_waitfor_n_fd(&p->fd, 1, &timeout, NULL);
- if (res < 0) {
- strncpy(p->response, "(No Response)", sizeof(p->response)-1);
- return -1;
- }
- /* get no more then buffer length */
- while(i < sizeof(p->response) - 1)
- {
- c = fgetc(p->f); /* get a char */
- if (c < 1) /* if error */
- {
- /* if nothing in buffer, go back into timeout stuff */
- if (errno == EWOULDBLOCK) break;
- /* return as error */
- strncpy(p->response, "(No Response)", sizeof(p->response)-1);
- return -1;
- }
- /* save char */
- p->response[i++] = c;
- p->response[i] = 0;
- /* if end of input */
- if (c == '\n') break;
- }
- if (c >= 0) /* if input terminated normally */
- {
- /* ignore just CR/LF */
- if (!strcmp(p->response,"\r\n"))
- {
- /* reset input buffer stuff */
- i = 0;
- p->response[0] = 0;
- }
- else /* otherwise return with info in buffer */
- {
- return 0;
- }
- }
- } while(timeout > 0);
- strncpy(p->response, "(No Response)", sizeof(p->response)-1);
- return -1;
-}
-
-int ast_modem_expect(struct ast_modem_pvt *p, char *result, int timeout)
-{
- int res = -1;
- timeout *= 1000;
- strncpy(p->response, "(No Response)", sizeof(p->response)-1);
- do {
- res = ast_waitfor_n_fd(&p->fd, 1, &timeout, NULL);
- if (res < 0) {
- return -1;
- }
- /* Read a response */
- fgets(p->response, sizeof(p->response), p->f);
-#if 0
- fprintf(stderr, "Modem said: %s", p->response);
-#endif
- if (!strncasecmp(p->response, result, strlen(result)))
- return 0;
- } while(timeout > 0);
- return -1;
-}
-
-void ast_modem_trim(char *s)
-{
- int x;
- x = strlen(s) - 1;
- while(x >= 0) {
- if ((s[x] != '\r') && (s[x] != '\n') && (s[x] != ' '))
- break;
- s[x] = '\0';
- x--;
- }
-}
-
-static int modem_setup(struct ast_modem_pvt *p, int baudrate)
-{
-
- /* Make sure there's a modem there and that it's in a reasonable
- mode. Set the baud rate, etc. */
- char identity[256];
- char *ident = NULL;
- char etx[2] = { 0x10, '!' };
- if (option_debug)
- ast_log(LOG_DEBUG, "Setting up modem %s\n", p->dev);
- if (ast_modem_send(p, etx, 2)) {
- ast_log(LOG_WARNING, "Failed to send ETX?\n");
- return -1;
- }
- if (ast_modem_send(p, "\r\n", 2)) {
- ast_log(LOG_WARNING, "Failed to send enter?\n");
- return -1;
- }
- usleep(10000);
- /* Read any outstanding stuff */
- while(!ast_modem_read_response(p, 0));
- if (ast_modem_send(p, "ATZ", 0)) {
- ast_log(LOG_WARNING, "Modem not responding on %s\n", p->dev);
- return -1;
- }
- if (ast_modem_expect(p, "OK", ECHO_TIMEOUT)) {
- ast_log(LOG_WARNING, "Modem reset failed: %s\n", p->response);
- return -1;
- }
- if (ast_modem_send(p, p->initstr, 0)) {
- ast_log(LOG_WARNING, "Modem not responding on %s\n", p->dev);
- return -1;
- }
- if (ast_modem_expect(p, "OK", ECHO_TIMEOUT)) {
- ast_log(LOG_WARNING, "Modem initialization failed: %s\n", p->response);
- return -1;
- }
- if (ast_modem_send(p, "ATI3", 0)) {
- ast_log(LOG_WARNING, "Modem not responding on %s\n", p->dev);
- return -1;
- }
- if (ast_modem_read_response(p, ECHO_TIMEOUT)) {
- ast_log(LOG_WARNING, "Modem did not provide identification\n");
- return -1;
- }
- strncpy(identity, p->response, sizeof(identity)-1);
- ast_modem_trim(identity);
- if (ast_modem_expect(p, "OK", ECHO_TIMEOUT)) {
- ast_log(LOG_WARNING, "Modem did not provide identification\n");
- return -1;
- }
- if (!strcasecmp(mtype, "autodetect")) {
- p->mc = find_capability(identity);
- if (!p->mc) {
- ast_log(LOG_WARNING, "Unable to autodetect modem. You'll need to specify a driver in modem.conf. Please report modem identification (%s) and which driver works to markster@linux-support.net.\n", identity);
- return -1;
- }
- } else {
- p->mc = find_driver(mtype);
- if (!p->mc) {
- ast_log(LOG_WARNING, "No driver for modem type '%s'\n", mtype);
- return -1;
- }
- }
- if (p->mc->init) {
- if (p->mc->init(p)) {
- ast_log(LOG_WARNING, "Modem Initialization Failed on '%s', driver %s.\n", p->dev, p->mc->name);
- p->mc->decusecnt();
- return -1;
- }
- }
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Configured modem %s with driver %s (%s)\n", p->dev, p->mc->name, p->mc->identify ? (ident = p->mc->identify(p)) : "No identification");
- }
- if (ident)
- free(ident);
- return 0;
-}
-
-static int modem_hangup(struct ast_channel *ast)
-{
- struct ast_modem_pvt *p;
- if (option_debug)
- ast_log(LOG_DEBUG, "modem_hangup(%s)\n", ast->name);
- p = ast->tech_pvt;
- /* Hang up */
- if (p->mc->hangup)
- p->mc->hangup(p);
- /* Re-initialize */
- if (p->mc->init)
- p->mc->init(p);
- ast_setstate(ast, AST_STATE_DOWN);
- memset(p->cid_num, 0, sizeof(p->cid_num));
- memset(p->cid_name, 0, sizeof(p->cid_name));
- memset(p->dnid, 0, sizeof(p->dnid));
- ((struct ast_modem_pvt *)(ast->tech_pvt))->owner = NULL;
- ast_mutex_lock(&usecnt_lock);
- usecnt--;
- if (usecnt < 0)
- ast_log(LOG_WARNING, "Usecnt < 0???\n");
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name);
- ast->tech_pvt = NULL;
- ast_setstate(ast, AST_STATE_DOWN);
- restart_monitor();
- return 0;
-}
-
-static int modem_answer(struct ast_channel *ast)
-{
- struct ast_modem_pvt *p;
- int res=0;
- if (option_debug)
- ast_log(LOG_DEBUG, "modem_answer(%s)\n", ast->name);
- p = ast->tech_pvt;
- if (p->mc->answer) {
- res = p->mc->answer(p);
- }
- if (!res) {
- ast->rings = 0;
- ast_setstate(ast, AST_STATE_UP);
- }
- return res;
-}
-
-#if 0
-static char modem_2digit(char c)
-{
- if (c == 12)
- return '#';
- else if (c == 11)
- return '*';
- else if ((c < 10) && (c >= 0))
- return '0' + c - 1;
- else
- return '?';
-}
-#endif
-static struct ast_frame *modem_read(struct ast_channel *ast)
-{
- struct ast_modem_pvt *p = ast->tech_pvt;
- struct ast_frame *fr=NULL;
- if (p->mc->read)
- fr = p->mc->read(p);
- return fr;
-}
-
-static int modem_write(struct ast_channel *ast, struct ast_frame *frame)
-{
- int res=0;
- long flags;
- struct ast_modem_pvt *p = ast->tech_pvt;
-
- /* Modems tend to get upset when they receive data whilst in
- * command mode. This makes esp. dial commands short lived.
- * Pauline Middelink - 2002-09-24 */
- if (ast->_state != AST_STATE_UP)
- return 0;
-
- /* Temporarily make non-blocking */
- flags = fcntl(ast->fds[0], F_GETFL);
- fcntl(ast->fds[0], F_SETFL, flags | O_NONBLOCK);
-
- if (p->mc->write)
- res = p->mc->write(p, frame);
-
- /* Block again */
- fcntl(ast->fds[0], F_SETFL, flags);
- return res;
-}
-
-static int modem_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
-{
- struct ast_modem_pvt *p = newchan->tech_pvt;
-ast_log(LOG_WARNING, "fixup called\n");
- if (p->owner!=oldchan) {
- ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n",oldchan,p->owner);
- return -1;
- }
- p->owner = newchan;
- return 0;
-}
-
-struct ast_channel *ast_modem_new(struct ast_modem_pvt *i, int state)
-{
- struct ast_channel *tmp;
- tmp = ast_channel_alloc(1);
- if (tmp) {
- tmp->tech = &modem_tech;
- snprintf(tmp->name, sizeof(tmp->name), "Modem[%s]/%s", i->mc->name, i->dev + 5);
- tmp->type = type;
- tmp->fds[0] = i->fd;
- tmp->nativeformats = i->mc->formats;
- ast_setstate(tmp, state);
- if (state == AST_STATE_RING)
- tmp->rings = 1;
- tmp->tech_pvt = i;
- strncpy(tmp->context, i->context, sizeof(tmp->context)-1);
-
- if (!ast_strlen_zero(i->cid_num))
- tmp->cid.cid_num = strdup(i->cid_num);
- if (!ast_strlen_zero(i->cid_name))
- tmp->cid.cid_name = strdup(i->cid_name);
-
- if (!ast_strlen_zero(i->language))
- strncpy(tmp->language,i->language, sizeof(tmp->language)-1);
- if (!ast_strlen_zero(i->dnid))
- strncpy(tmp->exten, i->dnid, sizeof(tmp->exten) - 1);
- i->owner = tmp;
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
- if (state != AST_STATE_DOWN) {
- if (ast_pbx_start(tmp)) {
- ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
- ast_hangup(tmp);
- tmp = NULL;
- }
- }
- } else
- ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
- return tmp;
-}
-
-static void modem_mini_packet(struct ast_modem_pvt *i)
-{
- struct ast_frame *fr;
- fr = i->mc->read(i);
- if (!fr) return;
- if (fr->frametype == AST_FRAME_CONTROL) {
- if (fr->subclass == AST_CONTROL_RING) {
- ast_modem_new(i, AST_STATE_RING);
- }
- }
-}
-
-static void *do_monitor(void *data)
-{
- fd_set rfds, efds;
- int n, res;
- struct ast_modem_pvt *i;
- /* This thread monitors all the frame relay interfaces which are not yet in use
- (and thus do not have a separate thread) indefinitely */
- /* From here on out, we die whenever asked */
-#if 0
- if (pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL)) {
- ast_log(LOG_WARNING, "Unable to set cancel type to asynchronous\n");
- return NULL;
- }
-#endif
- for(;;) {
- /* Don't let anybody kill us right away. Nobody should lock the interface list
- and wait for the monitor list, but the other way around is okay. */
- if (ast_mutex_lock(&monlock)) {
- ast_log(LOG_ERROR, "Unable to grab monitor lock\n");
- return NULL;
- }
- /* Lock the interface list */
- if (ast_mutex_lock(&iflock)) {
- ast_log(LOG_ERROR, "Unable to grab interface lock\n");
- ast_mutex_unlock(&monlock);
- return NULL;
- }
- /* Build the stuff we're going to select on, that is the socket of every
- ast_modem_pvt that does not have an associated owner channel */
- n = -1;
- FD_ZERO(&rfds);
- FD_ZERO(&efds);
- i = iflist;
- while(i) {
- if (FD_ISSET(i->fd, &rfds))
- ast_log(LOG_WARNING, "Descriptor %d appears twice (%s)?\n", i->fd, i->dev);
- if (!i->owner) {
- /* This needs to be watched, as it lacks an owner */
- FD_SET(i->fd, &rfds);
- FD_SET(i->fd, &efds);
- if (i->fd > n)
- n = i->fd;
- }
-
- i = i->next;
- }
- /* Okay, now that we know what to do, release the interface lock */
- ast_mutex_unlock(&iflock);
-
- /* And from now on, we're okay to be killed, so release the monitor lock as well */
- ast_mutex_unlock(&monlock);
-#if 0
- ast_log(LOG_DEBUG, "In monitor, n=%d, pid=%d\n", n, getpid());
-#endif
- /* Wait indefinitely for something to happen */
- pthread_testcancel();
- res = ast_select(n + 1, &rfds, NULL, &efds, NULL);
- pthread_testcancel();
- /* Okay, select has finished. Let's see what happened. */
- if (res < 1) {
- if ((errno != EINTR) && (errno != EAGAIN))
- ast_log(LOG_WARNING, "select return %d: %s\n", res, strerror(errno));
- continue;
- }
- /* Alright, lock the interface list again, and let's look and see what has
- happened */
- if (ast_mutex_lock(&iflock)) {
- ast_log(LOG_WARNING, "Unable to lock the interface list\n");
- continue;
- }
- i = iflist;
- while(i) {
- if (FD_ISSET(i->fd, &rfds) || FD_ISSET(i->fd, &efds)) {
- if (i->owner) {
- ast_log(LOG_WARNING, "Whoa.... I'm owned but found (%d, %s)...\n", i->fd, i->dev);
- i = i->next;
- continue;
- }
- modem_mini_packet(i);
- }
- i=i->next;
- }
- ast_mutex_unlock(&iflock);
- }
- /* Never reached */
- return NULL;
-
-}
-
-static int restart_monitor()
-{
- /* If we're supposed to be stopped -- stay stopped */
- if (monitor_thread == AST_PTHREADT_STOP)
- return 0;
- if (ast_mutex_lock(&monlock)) {
- ast_log(LOG_WARNING, "Unable to lock monitor\n");
- return -1;
- }
- if (monitor_thread == pthread_self()) {
- ast_mutex_unlock(&monlock);
- ast_log(LOG_WARNING, "Cannot kill myself\n");
- return -1;
- }
- if (monitor_thread != AST_PTHREADT_NULL) {
- pthread_cancel(monitor_thread);
- /* Nudge it a little, as it's probably stuck in select */
- pthread_kill(monitor_thread, SIGURG);
- pthread_join(monitor_thread, NULL);
- }
- /* Start a new monitor */
- if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
- ast_mutex_unlock(&monlock);
- ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
- return -1;
- }
- ast_mutex_unlock(&monlock);
- return 0;
-}
-
-static void stty(struct ast_modem_pvt *p)
-{
- struct termios mode;
- memset(&mode, 0, sizeof(mode));
- if (tcgetattr(p->fd, &mode)) {
- ast_log(LOG_WARNING, "Unable to get serial parameters on %s: %s\n", p->dev, strerror(errno));
- return;
- }
-#ifndef SOLARIS
- cfmakeraw(&mode);
-#else
- mode.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
- |INLCR|IGNCR|ICRNL|IXON);
- mode.c_oflag &= ~OPOST;
- mode.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
- mode.c_cflag &= ~(CSIZE|PARENB);
- mode.c_cflag |= CS8;
-#endif
-
- cfsetispeed(&mode, B115200);
- cfsetospeed(&mode, B115200);
- if (tcsetattr(p->fd, TCSANOW, &mode))
- ast_log(LOG_WARNING, "Unable to set serial parameters on %s: %s\n", p->dev, strerror(errno));
-
-}
-
-static struct ast_modem_pvt *mkif(char *iface)
-{
- /* Make a ast_modem_pvt structure for this interface */
- struct ast_modem_pvt *tmp;
-#if 0
- int flags;
-#endif
-
- tmp = malloc(sizeof(struct ast_modem_pvt));
- if (tmp) {
- memset(tmp, 0, sizeof(struct ast_modem_pvt));
- tmp->fd = open(iface, O_RDWR | O_NONBLOCK);
- if (tmp->fd < 0) {
- ast_log(LOG_WARNING, "Unable to open '%s'\n", iface);
- free(tmp);
- return NULL;
- }
- strncpy(tmp->language, language, sizeof(tmp->language)-1);
- strncpy(tmp->msn, msn, sizeof(tmp->msn)-1);
- strncpy(tmp->incomingmsn, incomingmsn, sizeof(tmp->incomingmsn)-1);
- tmp->dtmfmode = dtmfmode;
- tmp->dtmfmodegen = dtmfmodegen;
- snprintf(tmp->outgoingmsn, sizeof(tmp->outgoingmsn), ",%s,", outgoingmsn);
- strncpy(tmp->dev, iface, sizeof(tmp->dev)-1);
- /* Maybe in the future we want to allow variable
- serial settings */
- stty(tmp);
- tmp->f = fdopen(tmp->fd, "w+");
- /* Disable buffering */
- setvbuf(tmp->f, NULL, _IONBF,0);
- if (tmp->f < 0) {
- ast_log(LOG_WARNING, "Unable to fdopen '%s'\n", iface);
- free(tmp);
- return NULL;
- }
- tmp->owner = NULL;
- tmp->ministate = 0;
- tmp->stripmsd = stripmsd;
- tmp->dialtype = dialtype;
- tmp->mode = gmode;
- tmp->group = cur_group;
- memset(tmp->cid_num, 0, sizeof(tmp->cid_num));
- memset(tmp->cid_name, 0, sizeof(tmp->cid_name));
- strncpy(tmp->context, context, sizeof(tmp->context)-1);
- strncpy(tmp->initstr, initstr, sizeof(tmp->initstr)-1);
- tmp->next = NULL;
- tmp->obuflen = 0;
-
- if (modem_setup(tmp, baudrate) < 0) {
- ast_log(LOG_WARNING, "Unable to configure modem '%s'\n", iface);
- free(tmp);
- return NULL;
- }
- }
- return tmp;
-}
-
-static struct ast_channel *modem_request(const char *type, int format, void *data, int *cause)
-{
- int oldformat;
- struct ast_modem_pvt *p;
- struct ast_channel *tmp = NULL;
- char dev[80];
- ast_group_t group = 0;
- int groupint;
- char *stringp=NULL;
- strncpy(dev, (char *)data, sizeof(dev)-1);
- stringp=dev;
- strsep(&stringp, ":");
- oldformat = format;
-
- if (!dep_warning) {
- ast_log(LOG_WARNING, "This channel driver is deprecated. Please see the UPGRADE.txt file.\n");
- dep_warning = 1;
- }
-
- if (dev[0]=='g' && isdigit(dev[1])) {
- /* Retrieve the group number */
- if (sscanf(dev+1, "%u", &groupint) < 1) {
- ast_log(LOG_WARNING, "Unable to determine group from [%s]\n", (char *)data);
- return NULL;
- }
- group = 1 << groupint;
- }
-
- /* Search for an unowned channel */
- if (ast_mutex_lock(&iflock)) {
- ast_log(LOG_ERROR, "Unable to lock interface list???\n");
- return NULL;
- }
- p = iflist;
- while(p) {
- if (group) {
- /* if it belongs to the proper group, and the format matches
- * and it is not in use, we found a candidate! */
- if (p->group & group &&
- p->mc->formats & format &&
- !p->owner) {
- /* XXX Not quite sure that not having an owner is
- * sufficient evidence of beeing a free device XXX */
- tmp = ast_modem_new(p, AST_STATE_DOWN);
- restart_monitor();
- break;
- }
- } else {
- if (!strcmp(dev, p->dev + 5)) {
- if (p->mc->formats & format) {
- if (!p->owner) {
- tmp = ast_modem_new(p, AST_STATE_DOWN);
- restart_monitor();
- break;
- } else
- ast_log(LOG_WARNING, "Device '%s' is busy\n", p->dev);
- } else
- ast_log(LOG_WARNING, "Asked for a format %s line on %s\n", ast_getformatname(format), p->dev);
- break;
- }
- }
- p = p->next;
- }
- if (!p)
- ast_log(LOG_WARNING, "Requested device '%s' does not exist\n", dev);
-
- ast_mutex_unlock(&iflock);
- return tmp;
-}
-
-static ast_group_t get_group(char *s)
-{
- char *piece;
- int start, finish,x;
- ast_group_t group = 0;
- char *copy = ast_strdupa(s);
- char *stringp=NULL;
- if (!copy) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return 0;
- }
- stringp=copy;
- piece = strsep(&stringp, ",");
- while(piece) {
- if (sscanf(piece, "%d-%d", &start, &finish) == 2) {
- /* Range */
- } else if (sscanf(piece, "%d", &start)) {
- /* Just one */
- finish = start;
- } else {
- ast_log(LOG_ERROR, "Syntax error parsing '%s' at '%s'. Using '0'\n", s,piece);
- return 0;
- }
- piece = strsep(&stringp, ",");
-
- for (x=start;x<=finish;x++) {
- if ((x > 63) || (x < 0)) {
- ast_log(LOG_WARNING, "Ignoring invalid group %d\n", x);
- break;
- }
- group |= (1 << x);
- }
- }
- return group;
-}
-
-static int __unload_module(void)
-{
- struct ast_modem_pvt *p, *pl;
- /* First, take us out of the channel loop */
- ast_channel_unregister(&modem_tech);
- if (!ast_mutex_lock(&iflock)) {
- /* Hangup all interfaces if they have an owner */
- p = iflist;
- while(p) {
- if (p->owner)
- ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
- p = p->next;
- }
- iflist = NULL;
- ast_mutex_unlock(&iflock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
- if (!ast_mutex_lock(&monlock)) {
- if (monitor_thread != AST_PTHREADT_NULL && monitor_thread != AST_PTHREADT_STOP) {
- pthread_cancel(monitor_thread);
- pthread_join(monitor_thread, NULL);
- }
- monitor_thread = AST_PTHREADT_STOP;
- ast_mutex_unlock(&monlock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
-
- if (!ast_mutex_lock(&iflock)) {
- /* Destroy all the interfaces and free their memory */
- p = iflist;
- while(p) {
- /* Close the socket, assuming it's real */
- if (p->fd > -1)
- close(p->fd);
- pl = p;
- p = p->next;
- /* Free associated memory */
- free(pl);
- }
- iflist = NULL;
- ast_mutex_unlock(&iflock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
-
- return 0;
-}
-
-int unload_module()
-{
- return __unload_module();
-}
-
-int load_module()
-{
- struct ast_config *cfg;
- struct ast_variable *v;
- struct ast_modem_pvt *tmp;
- char driver[80];
- cfg = ast_config_load(config);
-
- /* We *must* have a config file otherwise stop immediately */
- if (!cfg) {
- ast_log(LOG_ERROR, "Unable to load config %s\n", config);
- return -1;
- }
- if (ast_mutex_lock(&iflock)) {
- /* It's a little silly to lock it, but we mind as well just to be sure */
- ast_log(LOG_ERROR, "Unable to lock interface list???\n");
- return -1;
- }
- v = ast_variable_browse(cfg, "interfaces");
- while(v) {
- /* Create the interface list */
- if (!strcasecmp(v->name, "device")) {
- tmp = mkif(v->value);
- if (tmp) {
- tmp->next = iflist;
- iflist = tmp;
-
- } else {
- ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value);
- ast_config_destroy(cfg);
- ast_mutex_unlock(&iflock);
- __unload_module();
- return -1;
- }
- } else if (!strcasecmp(v->name, "driver")) {
- snprintf(driver, sizeof(driver), "chan_modem_%s.so", v->value);
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Loading modem driver %s", driver);
-
- if (ast_load_resource(driver)) {
- ast_log(LOG_ERROR, "Failed to load driver %s\n", driver);
- ast_config_destroy(cfg);
- ast_mutex_unlock(&iflock);
- __unload_module();
- return -1;
- }
- } else if (!strcasecmp(v->name, "mode")) {
- if (!strncasecmp(v->value, "ri", 2))
- gmode = MODEM_MODE_WAIT_RING;
- else if (!strncasecmp(v->value, "im", 2))
- gmode = MODEM_MODE_IMMEDIATE;
- else if (!strncasecmp(v->value, "an", 2))
- gmode = MODEM_MODE_WAIT_ANSWER;
- else
- ast_log(LOG_WARNING, "Unknown mode: %s\n", v->value);
- } else if (!strcasecmp(v->name, "stripmsd")) {
- stripmsd = atoi(v->value);
- } else if (!strcasecmp(v->name, "type")) {
- strncpy(mtype, v->value, sizeof(mtype)-1);
- } else if (!strcasecmp(v->name, "initstr")) {
- strncpy(initstr, v->value, sizeof(initstr)-1);
- } else if (!strcasecmp(v->name, "dialtype")) {
- dialtype = toupper(v->value[0]);
- } else if (!strcasecmp(v->name, "context")) {
- strncpy(context, v->value, sizeof(context)-1);
- } else if (!strcasecmp(v->name, "msn")) {
- strncpy(msn, v->value, sizeof(msn)-1);
- } else if (!strcasecmp(v->name, "incomingmsn")) {
- strncpy(incomingmsn, v->value, sizeof(incomingmsn)-1);
- } else if (!strcasecmp(v->name, "dtmfmode")) {
- char tmp[80];
- char *alt;
- strncpy(tmp, v->value, sizeof(tmp) - 1);
- alt = strchr(tmp, '/');
- if (!strcasecmp(tmp, "none"))
- dtmfmode=MODEM_DTMF_NONE;
- else if (!strcasecmp(tmp, "asterisk"))
- dtmfmode = MODEM_DTMF_AST;
- else if (!strcasecmp(tmp, "i4l"))
- dtmfmode = MODEM_DTMF_I4L;
- else {
- ast_log(LOG_WARNING, "Unknown dtmf detection mode '%s', using 'asterisk'\n", v->value);
- dtmfmode = MODEM_DTMF_AST;
- }
- if (alt) {
- if (!strcasecmp(alt, "none"))
- dtmfmodegen=MODEM_DTMF_NONE;
- else if (!strcasecmp(alt, "asterisk"))
- dtmfmodegen = MODEM_DTMF_AST;
- else if (!strcasecmp(alt, "i4l"))
- dtmfmodegen = MODEM_DTMF_I4L;
- else if (!strcasecmp(alt, "both"))
- dtmfmodegen = MODEM_DTMF_I4L | MODEM_DTMF_AST;
- else {
- ast_log(LOG_WARNING, "Unknown dtmf generation mode '%s', using 'asterisk'\n", v->value);
- dtmfmodegen = MODEM_DTMF_AST;
- }
- } else
- dtmfmodegen = dtmfmode;
- } else if (!strcasecmp(v->name, "outgoingmsn")) {
- strncpy(outgoingmsn, v->value, sizeof(outgoingmsn)-1);
- } else if (!strcasecmp(v->name, "language")) {
- strncpy(language, v->value, sizeof(language)-1);
- } else if (!strcasecmp(v->name, "group")) {
- cur_group = get_group(v->value);
- }
- v = v->next;
- }
- ast_mutex_unlock(&iflock);
- if (ast_channel_register(&modem_tech)) {
- ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
- ast_config_destroy(cfg);
- __unload_module();
- return -1;
- }
- ast_config_destroy(cfg);
- /* And start the monitor for the first time */
- restart_monitor();
- return 0;
-}
-
-int usecount(void)
-{
- return usecnt;
-}
-
-char *description()
-{
- return (char *) desc;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
-
diff --git a/channels/chan_modem_aopen.c b/channels/chan_modem_aopen.c
deleted file mode 100644
index f49fe6568..000000000
--- a/channels/chan_modem_aopen.c
+++ /dev/null
@@ -1,502 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*
- * \brief A/Open ITU-56/2 Voice Modem Driver (Rockwell, IS-101, and others)
- *
- * \author Mark Spencer <markster@digium.com>
- *
- * \ingroup channel_drivers
- */
-
-#include <stdio.h>
-
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/vmodem.h"
-#include "asterisk/module.h"
-#include "asterisk/frame.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-
-#define STATE_COMMAND 0
-#define STATE_VOICE 1
-
-#define VRA "40" /* Number of 100ms of non-ring after a ring cadence after which we consider the lien to be answered */
-#define VRN "100" /* Number of 100ms of non-ring with no cadence after which we assume an answer */
-
-static char *breakcmd = "\0x10\0x03";
-
-static char *desc = "A/Open (Rockwell Chipset) ITU-2 VoiceModem Driver";
-
-static int usecnt;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-static char *aopen_idents[] = {
- /* Identify A/Open Modem */
- "V2.210-V90_2M_DLP",
- NULL
-};
-
-static int aopen_setdev(struct ast_modem_pvt *p, int dev)
-{
- char cmd[80];
- if (ast_modem_send(p, "AT#VLS?", 0)) {
- ast_log(LOG_WARNING, "Unable to select current mode %d\n", dev);
- return -1;
- }
- if (ast_modem_read_response(p, 5)) {
- ast_log(LOG_WARNING, "Unable to select device %d\n", dev);
- return -1;
- }
- ast_modem_trim(p->response);
- strncpy(cmd, p->response, sizeof(cmd)-1);
- if (ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Modem did not respond properly\n");
- return -1;
- }
- if (dev == atoi(cmd)) {
- /* We're already in the right mode, don't bother changing for fear of
- hanging up */
- return 0;
- }
- snprintf(cmd, sizeof(cmd), "AT#VLS=%d", dev);
- if (ast_modem_send(p, cmd, 0)) {
- ast_log(LOG_WARNING, "Unable to select device %d\n", dev);
- return -1;
- }
- if (ast_modem_read_response(p, 5)) {
- ast_log(LOG_WARNING, "Unable to select device %d\n", dev);
- return -1;
- }
- ast_modem_trim(p->response);
- if (strcasecmp(p->response, "VCON") && strcasecmp(p->response, "OK")) {
- ast_log(LOG_WARNING, "Unexpected reply: %s\n", p->response);
- return -1;
- }
- return 0;
-}
-
-static int aopen_startrec(struct ast_modem_pvt *p)
-{
- if (ast_modem_send(p, "AT#VRX", 0) ||
- ast_modem_expect(p, "CONNECT", 5)) {
- ast_log(LOG_WARNING, "Unable to start recording\n");
- return -1;
- }
- p->ministate = STATE_VOICE;
- return 0;
-}
-
-static int aopen_break(struct ast_modem_pvt *p)
-{
- if (ast_modem_send(p, "\r\n", 2)) {
- ast_log(LOG_WARNING, "Failed to send enter?\n");
- return -1;
- }
- if (ast_modem_send(p, breakcmd, 2)) {
- ast_log(LOG_WARNING, "Failed to break\n");
- return -1;
- }
- if (ast_modem_send(p, "\r\n", 2)) {
- ast_log(LOG_WARNING, "Failed to send enter?\n");
- return -1;
- }
- /* Read any outstanding junk */
- while(!ast_modem_read_response(p, 1));
- if (ast_modem_send(p, "AT", 0)) {
- /* Modem might be stuck in some weird mode, try to get it out */
- ast_modem_send(p, "+++", 3);
- if (ast_modem_expect(p, "OK", 10)) {
- ast_log(LOG_WARNING, "Modem is not responding\n");
- return -1;
- }
- if (ast_modem_send(p, "AT", 0)) {
- ast_log(LOG_WARNING, "Modem is not responding\n");
- return -1;
- }
- }
- if (ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Modem did not respond properly\n");
- return -1;
- }
- return 0;
-}
-
-static int aopen_init(struct ast_modem_pvt *p)
-{
- if (option_debug)
- ast_log(LOG_DEBUG, "aopen_init()\n");
- if (aopen_break(p))
- return -1;
- /* Force into command mode */
- p->ministate = STATE_COMMAND;
- if (ast_modem_send(p, "AT#BDR=0", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to auto-baud\n");
- return -1;
- }
- if (ast_modem_send(p, "AT#CLS=8", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to voice mode\n");
- return -1;
- }
- if (ast_modem_send(p, "AT#VBS=8", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to 8-bit mode\n");
- return -1;
- }
- if (ast_modem_send(p, "AT#VSR=8000", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to 8000 Hz sampling\n");
- return -1;
- }
- if (ast_modem_send(p, "AT#VLS=0", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to telco interface\n");
- return -1;
- }
- if (ast_modem_send(p, "AT#VRA=" VRA, 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to 'ringback goes away' timer\n");
- return -1;
- }
- if (ast_modem_send(p, "AT#VRN=" VRN, 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to 'ringback never came timer'\n");
- return -1;
- }
- if (ast_modem_send(p, "AT#VTD=3F,3F,3F", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to tone detection\n");
- return -1;
- }
-
- return 0;
-}
-
-static struct ast_frame *aopen_handle_escape(struct ast_modem_pvt *p, char esc)
-{
- /* Handle escaped characters -- but sometimes we call it directly as
- a quick way to cause known responses */
- p->fr.frametype = AST_FRAME_NULL;
- p->fr.subclass = 0;
- p->fr.data = NULL;
- p->fr.datalen = 0;
- p->fr.samples = 0;
- p->fr.offset = 0;
- p->fr.mallocd = 0;
- p->fr.delivery.tv_sec = 0;
- p->fr.delivery.tv_usec = 0;
- if (esc)
- ast_log(LOG_DEBUG, "Escaped character '%c'\n", esc);
-
- switch(esc) {
- case 'R': /* Pseudo ring */
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_RING;
- return &p->fr;
- case 'X': /* Pseudo connect */
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_RING;
- if (p->owner)
- ast_setstate(p->owner, AST_STATE_UP);
- if (aopen_startrec(p))
- return NULL;
- return &p->fr;
- case 'b': /* Busy signal */
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_BUSY;
- return &p->fr;
- case 'o': /* Overrun */
- ast_log(LOG_WARNING, "Overflow on modem, flushing buffers\n");
- if (ast_modem_send(p, "\0x10E", 2))
- ast_log(LOG_WARNING, "Unable to flush buffers\n");
- return &p->fr;
- case 'u': /* Underrun */
- ast_log(LOG_WARNING, "Data underrun\n");
- /* Fall Through */
- case CHAR_ETX: /* End Transmission */
- case 'd': /* Dialtone */
- case 'c': /* Calling Tone */
- case 'e': /* European version */
- case 'a': /* Answer Tone */
- case 'f': /* Bell Answer Tone */
- case 'T': /* Timing mark */
- case 't': /* Handset off hook */
- case 'h': /* Handset hungup */
- case 0: /* Pseudo signal */
- /* Ignore */
- return &p->fr;
- default:
- ast_log(LOG_DEBUG, "Unknown Escaped character '%c' (%d)\n", esc, esc);
- }
- return &p->fr;
-}
-
-static struct ast_frame *aopen_read(struct ast_modem_pvt *p)
-{
- char result[256];
- short *b;
- struct ast_frame *f=NULL;
- int res;
- int x;
- if (p->ministate == STATE_COMMAND) {
- /* Read the first two bytes, first, in case it's a control message */
- fread(result, 1, 2, p->f);
- if (result[0] == CHAR_DLE) {
- return aopen_handle_escape(p, result[1]);
-
- } else {
- if ((result[0] == '\n') || (result[0] == '\r'))
- return aopen_handle_escape(p, 0);
- /* Read the rest of the line */
- fgets(result + 2, sizeof(result) - 2, p->f);
- ast_modem_trim(result);
- if (!strcasecmp(result, "VCON")) {
- /* If we're in immediate mode, reply now */
- if (p->mode == MODEM_MODE_IMMEDIATE)
- return aopen_handle_escape(p, 'X');
- } else
- if (!strcasecmp(result, "BUSY")) {
- /* Same as a busy signal */
- return aopen_handle_escape(p, 'b');
- } else
- if (!strcasecmp(result, "RING")) {
- return aopen_handle_escape(p, 'R');
- } else
- if (!strcasecmp(result, "NO DIALTONE")) {
- /* There's no dialtone, so the line isn't working */
- ast_log(LOG_WARNING, "Device '%s' lacking dialtone\n", p->dev);
- return NULL;
- }
- ast_log(LOG_DEBUG, "Modem said '%s'\n", result);
- return aopen_handle_escape(p, 0);
- }
- } else {
- /* We have to be more efficient in voice mode */
- b = (short *)(p->obuf + p->obuflen);
- while (p->obuflen/2 < 240) {
- /* Read ahead the full amount */
- res = fread(result, 1, 240 - p->obuflen/2, p->f);
- if (res < 1) {
- /* If there's nothing there, just continue on */
- if (errno == EAGAIN)
- return aopen_handle_escape(p, 0);
- ast_log(LOG_WARNING, "Read failed: %s\n", strerror(errno));
- }
- for (x=0;x<res;x++) {
- /* Process all the bytes that we've read */
- if (result[x] == CHAR_DLE) {
- /* We assume there is no more than one signal frame among our
- data. */
- if (f)
- ast_log(LOG_WARNING, "Warning: Dropped a signal frame\n");
- f = aopen_handle_escape(p, result[x+1]);
- /* If aopen_handle_escape says NULL, say it now, doesn't matter
- what else is there, the connection is dead. */
- if (!f)
- return NULL;
- } else {
- /* Generate a 16-bit signed linear value from our
- unsigned 8-bit value */
- *(b++) = (((short)result[x]) - 127) * 0xff;
- p->obuflen += 2;
- }
- }
- if (f)
- break;
- }
- /* If we have a control frame, return it now */
- if (f)
- return f;
- /* If we get here, we have a complete voice frame */
- p->fr.frametype = AST_FRAME_VOICE;
- p->fr.subclass = AST_FORMAT_SLINEAR;
- p->fr.samples = 240;
- p->fr.data = p->obuf;
- p->fr.datalen = p->obuflen;
- p->fr.mallocd = 0;
- p->fr.delivery.tv_sec = 0;
- p->fr.delivery.tv_usec = 0;
- p->fr.offset = AST_FRIENDLY_OFFSET;
- p->fr.src = __FUNCTION__;
- if (option_debug)
- ast_log(LOG_DEBUG, "aopen_read(voice frame)\n");
- p->obuflen = 0;
- return &p->fr;
- }
- return NULL;
-}
-
-static int aopen_write(struct ast_modem_pvt *p, struct ast_frame *f)
-{
- if (option_debug)
- ast_log(LOG_DEBUG, "aopen_write()\n");
- return 0;
-}
-
-static char *aopen_identify(struct ast_modem_pvt *p)
-{
- char identity[256];
- char mfr[80];
- char mdl[80];
- char rev[80];
- ast_modem_send(p, "AT#MDL?", 0);
- ast_modem_read_response(p, 5);
- strncpy(mdl, p->response, sizeof(mdl)-1);
- ast_modem_trim(mdl);
- ast_modem_expect(p, "OK", 5);
- ast_modem_send(p, "AT#MFR?", 0);
- ast_modem_read_response(p, 5);
- strncpy(mfr, p->response, sizeof(mfr)-1);
- ast_modem_trim(mfr);
- ast_modem_expect(p, "OK", 5);
- ast_modem_send(p, "AT#REV?", 0);
- ast_modem_read_response(p, 5);
- strncpy(rev, p->response, sizeof(rev)-1);
- ast_modem_trim(rev);
- ast_modem_expect(p, "OK", 5);
- snprintf(identity, sizeof(identity), "%s Model %s Revision %s", mfr, mdl, rev);
- return strdup(identity);
-}
-
-static void aopen_incusecnt(void)
-{
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
-}
-
-static void aopen_decusecnt(void)
-{
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
-}
-
-static int aopen_answer(struct ast_modem_pvt *p)
-{
- if (ast_modem_send(p, "ATA", 0) ||
- ast_modem_expect(p, "VCON", 10)) {
- ast_log(LOG_WARNING, "Unable to answer: %s", p->response);
- return -1;
- }
- return 0;
-}
-
-static int aopen_dialdigit(struct ast_modem_pvt *p, char digit)
-{
- char cmd[80];
- snprintf(cmd, sizeof(cmd), "AT#VTS=%c", digit);
- if (ast_modem_send(p, cmd, 0) ||
- ast_modem_expect(p, "VCON", 10)) {
- ast_log(LOG_WARNING, "Unable to answer: %s", p->response);
- return -1;
- }
- return 0;
-}
-
-static int aopen_dial(struct ast_modem_pvt *p, char *stuff)
-{
- char cmd[80];
- snprintf(cmd, sizeof(cmd), "ATD%c %s", p->dialtype,stuff);
- if (ast_modem_send(p, cmd, 0)) {
- ast_log(LOG_WARNING, "Unable to dial\n");
- return -1;
- }
- return 0;
-}
-
-static int aopen_hangup(struct ast_modem_pvt *p)
-{
- if (aopen_break(p))
- return -1;
- /* Hangup by switching to data, then back to voice */
- if (ast_modem_send(p, "ATH", 0) ||
- ast_modem_expect(p, "OK", 8)) {
- ast_log(LOG_WARNING, "Unable to set to data mode\n");
- return -1;
- }
- if (ast_modem_send(p, "AT#CLS=8", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to voice mode\n");
- return -1;
- }
- return 0;
-}
-
-static struct ast_modem_driver aopen_driver =
-{
- "AOpen",
- aopen_idents,
- AST_FORMAT_SLINEAR,
- 0, /* Not full duplex */
- aopen_incusecnt, /* incusecnt */
- aopen_decusecnt, /* decusecnt */
- aopen_identify, /* identify */
- aopen_init, /* init */
- aopen_setdev, /* setdev */
- aopen_read,
- aopen_write,
- aopen_dial, /* dial */
- aopen_answer, /* answer */
- aopen_hangup, /* hangup */
- aopen_startrec, /* start record */
- NULL, /* stop record */
- NULL, /* start playback */
- NULL, /* stop playback */
- NULL, /* set silence supression */
- aopen_dialdigit, /* dialdigit */
-};
-
-
-
-int usecount(void)
-{
- return usecnt;
-}
-
-int load_module(void)
-{
- return ast_register_modem_driver(&aopen_driver);
-}
-
-int unload_module(void)
-{
- return ast_unregister_modem_driver(&aopen_driver);
-}
-
-char *description()
-{
- return desc;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/channels/chan_modem_bestdata.c b/channels/chan_modem_bestdata.c
deleted file mode 100644
index a643635f1..000000000
--- a/channels/chan_modem_bestdata.c
+++ /dev/null
@@ -1,615 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999, Mark Spencer and 2001 Jim Dixon
- *
- * Mark Spencer <markster@linux-support.net>
- * Jim Dixon <jim@lambdatel.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*
- * \brief BestData 56SX-92 Voice Modem Driver (Conexant)
- *
- * \author Mark Spencer <markster@digium.com>
- * \author Jim Dixon <jim@lambdatel.com>
- *
- * \ingroup channel_drivers
- */
-
-#include <stdio.h>
-
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/vmodem.h"
-#include "asterisk/module.h"
-#include "asterisk/frame.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-
-#define STATE_COMMAND 0
-#define STATE_VOICE 1
-#define STATE_VOICEPLAY 2
-
-#define VRA "40" /* Number of 100ms of non-ring after a ring cadence after which we consider the lien to be answered */
-#define VRN "25" /* Number of 100ms of non-ring with no cadence after which we assume an answer */
-
-#define RINGT 7000
-
-static char *breakcmd = "\020!";
-
-static char *desc = "BestData (Conexant V.90 Chipset) VoiceModem Driver";
-
-static int usecnt;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-static char *bestdata_idents[] = {
- /* Identify BestData Modem */
- "ACF3_V1.010-V90_P21_FSH",
- NULL
-};
-
-static int bestdata_break(struct ast_modem_pvt *p);
-
-static int bestdata_startrec(struct ast_modem_pvt *p)
-{
- if (p->ministate != STATE_COMMAND) bestdata_break(p);
- if (ast_modem_send(p, "AT+VRX", 0) ||
- ast_modem_expect(p, "CONNECT", 5)) {
- ast_log(LOG_WARNING, "Unable to start recording\n");
- return -1;
- }
- p->ministate = STATE_VOICE;
- return 0;
-}
-
-static int bestdata_startplay(struct ast_modem_pvt *p)
-{
- if (p->ministate != STATE_COMMAND) bestdata_break(p);
- if (ast_modem_send(p, "AT+VTX", 0) ||
- ast_modem_expect(p, "CONNECT", 5)) {
- ast_log(LOG_WARNING, "Unable to start recording\n");
- return -1;
- }
- p->ministate = STATE_VOICEPLAY;
- return 0;
-}
-
-static int bestdata_break(struct ast_modem_pvt *p)
-{
- if (ast_modem_send(p, breakcmd, 2)) {
- ast_log(LOG_WARNING, "Failed to break\n");
- return -1;
- }
- p->ministate = STATE_COMMAND;
- usleep(10000);
- /* Read any outstanding junk */
- while(!ast_modem_read_response(p, 1));
- if (ast_modem_send(p, "AT", 0)) {
- /* Modem might be stuck in some weird mode, try to get it out */
- ast_modem_send(p, "+++", 3);
- if (ast_modem_expect(p, "OK", 10)) {
- ast_log(LOG_WARNING, "Modem is not responding\n");
- return -1;
- }
- if (ast_modem_send(p, "AT", 0)) {
- ast_log(LOG_WARNING, "Modem is not responding\n");
- return -1;
- }
- }
- if (ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Modem did not respond properly\n");
- return -1;
- }
- return 0;
-}
-
-static int bestdata_init(struct ast_modem_pvt *p)
-{
- if (option_debug)
- ast_log(LOG_DEBUG, "bestdata_init()\n");
- if (bestdata_break(p))
- return -1;
- /* Force into command mode */
- p->ministate = STATE_COMMAND;
- if (ast_modem_send(p, "AT+FCLASS=8", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to voice mode\n");
- return -1;
- }
- if (ast_modem_send(p, "AT+VSM=1,8000,0,0", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to 8000 Hz sampling\n");
- return -1;
- }
- if (ast_modem_send(p, "AT+VLS=0", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to telco interface\n");
- return -1;
- }
- if (ast_modem_send(p, "AT+VRA=" VRA, 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to 'ringback goes away' timer\n");
- return -1;
- }
- if (ast_modem_send(p, "AT+VRN=" VRN, 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to 'ringback never came timer'\n");
- return -1;
- }
- if (ast_modem_send(p, "AT+VTD=63", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to tone detection\n");
- return -1;
- }
- if (ast_modem_send(p, "AT+VCID=1", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to enable Caller*ID\n");
- return -1;
- }
- return 0;
-}
-
-static struct ast_frame *bestdata_handle_escape(struct ast_modem_pvt *p, char esc)
-{
- char name[30]="",nmbr[30]="";
- time_t now;
-
- /* Handle escaped characters -- but sometimes we call it directly as
- a quick way to cause known responses */
- p->fr.frametype = AST_FRAME_NULL;
- p->fr.subclass = 0;
- p->fr.data = NULL;
- p->fr.datalen = 0;
- p->fr.samples = 0;
- p->fr.offset = 0;
- p->fr.mallocd = 0;
- p->fr.delivery.tv_sec = 0;
- p->fr.delivery.tv_usec = 0;
- if (esc)
- ast_log(LOG_DEBUG, "Escaped character '%c'\n", esc);
-
- switch(esc) {
- case 'R': /* Pseudo ring */
- time(&now);
- if (now > (p->lastring + (RINGT / 1000)))
- { /* if stale, treat as new */
- p->gotclid = 0;
- }
- if (p->gotclid)
- {
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_RING;
- }
- p->ringt = RINGT;
- time(&p->lastring);
- return &p->fr;
- case 'X': /* Caller-ID Spill */
- if (p->gotclid) return &p->fr;
- name[0] = nmbr[0] = 0;
- for(;;)
- {
- char res[1000]="";
-
- if (ast_modem_read_response(p, 5)) break;
- strncpy(res, p->response, sizeof(res)-1);
- ast_modem_trim(res);
- if (!strncmp(res,"\020.",2)) break;
- if (!strncmp(res,"NAME",4)) strncpy(name,res + 7, sizeof(name) - 1);
- if (!strncmp(res,"NMBR",4)) strncpy(nmbr,res + 7, sizeof(nmbr) - 1);
- }
- p->gotclid = 1;
- if ((!strcmp(name,"O")) || (!strcmp(name,"P"))) name[0] = 0;
- if ((!strcmp(nmbr,"O")) || (!strcmp(nmbr,"P"))) nmbr[0] = 0;
- if (name[0])
- strncpy(p->cid_name, name, sizeof(p->cid_name) - 1);
- if (nmbr[0])
- strncpy(p->cid_num, nmbr, sizeof(p->cid_num) - 1);
- if (p->owner) {
- p->owner->cid.cid_num = strdup(p->cid_num);
- p->owner->cid.cid_name = strdup(p->cid_name);
- }
- return &p->fr;
- case '@': /* response from "OK" in command mode */
- if (p->owner)
- ast_setstate(p->owner, AST_STATE_UP);
- if (bestdata_startrec(p)) return NULL;
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_RING;
- return &p->fr;
- case 'b': /* Busy signal */
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_BUSY;
- return &p->fr;
- case 'o': /* Overrun */
- ast_log(LOG_WARNING, "Overflow on modem, flushing buffers\n");
- if (ast_modem_send(p, "\0x10E", 2))
- ast_log(LOG_WARNING, "Unable to flush buffers\n");
- return &p->fr;
- case '0': /* All the DTMF characters */
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- case '*':
- case '#':
- case 'A':
- case 'B':
- case 'C':
- case 'D':
- p->dtmfrx = esc; /* save this for when its done */
- return &p->fr;
- case '/': /* Start of DTMF tone shielding */
- p->dtmfrx = ' ';
- return &p->fr;
- case '~': /* DTMF transition to off */
- if (p->dtmfrx > ' ')
- {
- p->fr.frametype = AST_FRAME_DTMF;
- p->fr.subclass = p->dtmfrx;
- }
- p->dtmfrx = 0;
- return &p->fr;
- case 'u': /* Underrun */
- ast_log(LOG_WARNING, "Data underrun\n");
- /* Fall Through */
- case CHAR_ETX: /* End Transmission */
- case 'd': /* Dialtone */
- case 'c': /* Calling Tone */
- case 'e': /* European version */
- case 'a': /* Answer Tone */
- case 'f': /* Bell Answer Tone */
- case 'T': /* Timing mark */
- case 't': /* Handset off hook */
- case 'h': /* Handset hungup */
- case 0: /* Pseudo signal */
- /* Ignore */
- return &p->fr;
- default:
- ast_log(LOG_DEBUG, "Unknown Escaped character '%c' (%d)\n", esc, esc);
- }
- return &p->fr;
-}
-
-static struct ast_frame *bestdata_read(struct ast_modem_pvt *p)
-{
- char result[256];
- short *b;
- struct ast_frame *f=NULL;
- int res;
- int x;
-
- if (p->ministate == STATE_COMMAND) {
- /* Read the first two bytes, first, in case it's a control message */
- fread(result, 1, 2, p->f);
- if (result[0] == CHAR_DLE) {
- return bestdata_handle_escape(p, result[1]);
- } else {
- if (p->ringt) /* if ring timeout specified */
- {
- x = fileno(p->f);
- res = ast_waitfor_n_fd(&x, 1, &p->ringt, NULL);
- if (res < 0) {
- return NULL;
- }
- }
- if ((result[0] == '\n') || (result[0] == '\r'))
- return bestdata_handle_escape(p, 0);
- /* Read the rest of the line */
- fgets(result + 2, sizeof(result) - 2, p->f);
- ast_modem_trim(result);
- if (!strcasecmp(result, "OK")) {
- /* If we're in immediate mode, reply now */
- if (p->mode == MODEM_MODE_IMMEDIATE)
- return bestdata_handle_escape(p, '@');
- } else
- if (!strcasecmp(result, "BUSY")) {
- /* Same as a busy signal */
- return bestdata_handle_escape(p, 'b');
- } else
- if (!strcasecmp(result, "RING")) {
- return bestdata_handle_escape(p, 'R');
- } else
- if (!strcasecmp(result, "NO DIALTONE")) {
- /* There's no dialtone, so the line isn't working */
- ast_log(LOG_WARNING, "Device '%s' lacking dialtone\n", p->dev);
- return NULL;
- }
- ast_log(LOG_DEBUG, "Modem said '%s'\n", result);
- return bestdata_handle_escape(p, 0);
- }
- } else {
- /* if playing, start recording instead */
- if (p->ministate == STATE_VOICEPLAY)
- {
- if (bestdata_startrec(p)) return NULL;
- }
- /* We have to be more efficient in voice mode */
- b = (short *)(p->obuf + p->obuflen);
- while (p->obuflen/2 < 240) {
- /* Read ahead the full amount */
- res = fread(result, 1, 240 - p->obuflen/2, p->f);
- if (res < 1) {
- /* If there's nothing there, just continue on */
- if (errno == EAGAIN)
- return bestdata_handle_escape(p, 0);
- ast_log(LOG_WARNING, "Read failed: %s\n", strerror(errno));
- }
- for (x=0;x<res;x++) {
- /* Process all the bytes that we've read */
- if (result[x] == CHAR_DLE) {
- /* We assume there is no more than one signal frame among our
- data. */
- if (f) ast_log(LOG_WARNING, "Warning: Dropped a signal frame\n");
- /* if not a DLE in the data */
- if (result[++x] != CHAR_DLE)
- {
- /* If bestdata_handle_escape says NULL, say it now, doesn't matter
- what else is there, the connection is dead. */
- f = bestdata_handle_escape(p, result[x]);
- if (p->dtmfrx) continue;
- return(f);
- }
- }
- /* Generate a 16-bit signed linear value from our
- unsigned 8-bit value */
- *(b++) = (((short)result[x]) - 127) * 0xff;
- p->obuflen += 2;
- }
- if (f) break;
- }
- /* If we have a control frame, return it now */
- if (f) return f;
- /* If we get here, we have a complete voice frame */
- p->fr.frametype = AST_FRAME_VOICE;
- p->fr.subclass = AST_FORMAT_SLINEAR;
- p->fr.samples = 240;
- p->fr.data = p->obuf;
- p->fr.datalen = p->obuflen;
- p->fr.mallocd = 0;
- p->fr.delivery.tv_sec = 0;
- p->fr.delivery.tv_usec = 0;
- p->fr.offset = AST_FRIENDLY_OFFSET;
- p->fr.src = __FUNCTION__;
- if (option_debug)
- ast_log(LOG_DEBUG, "bestdata_read(voice frame)\n");
- p->obuflen = 0;
- return &p->fr;
- }
- return NULL;
-}
-
-static int bestdata_write(struct ast_modem_pvt *p, struct ast_frame *f)
-{
-unsigned char c,buf[32768]; /* I hope we dont have frames larger then 16K */
-int i,j;
-short *sp;
-unsigned long u;
-#define DLE 16
-
- if (p->owner && (p->owner->_state == AST_STATE_UP) &&
- (p->ministate != STATE_VOICEPLAY) && bestdata_startplay(p)) return -1;
- sp = (short *) f->data;
- /* stick DLE's in ahead of anything else */
- for(i = 0,j = 0; i < f->datalen / 2; i++)
- {
- *sp *= 3;
- u = *sp++ + 32768;
- c = u >> 8;
- if (c == DLE) buf[j++] = DLE;
- buf[j++] = c;
- }
- do i = fwrite(buf,1,j,p->f);
- while ((i == -1) && (errno == EWOULDBLOCK));
- if (i != j)
- {
- ast_log(LOG_WARNING,"modem short write!!\n");
- return -1;
- }
- fflush(p->f);
- if (option_debug)
- ast_log(LOG_DEBUG, "bestdata_write()\n");
- return 0;
-}
-
-static char *bestdata_identify(struct ast_modem_pvt *p)
-{
- char identity[256];
- char mfr[80];
- char mdl[80];
- char rev[80];
- ast_modem_send(p, "AT+FMM", 0);
- ast_modem_read_response(p, 5);
- strncpy(mdl, p->response, sizeof(mdl)-1);
- ast_modem_trim(mdl);
- ast_modem_expect(p, "OK", 5);
- ast_modem_send(p, "AT+FMI", 0);
- ast_modem_read_response(p, 5);
- strncpy(mfr, p->response, sizeof(mfr)-1);
- ast_modem_trim(mfr);
- ast_modem_expect(p, "OK", 5);
- ast_modem_send(p, "AT+FMR", 0);
- ast_modem_read_response(p, 5);
- strncpy(rev, p->response, sizeof(rev)-1);
- ast_modem_trim(rev);
- ast_modem_expect(p, "OK", 5);
- snprintf(identity, sizeof(identity), "%s Model %s Revision %s", mfr, mdl, rev);
- return strdup(identity);
-}
-
-static void bestdata_incusecnt(void)
-{
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
-}
-
-static void bestdata_decusecnt(void)
-{
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
-}
-
-static int bestdata_answer(struct ast_modem_pvt *p)
-{
- p->ringt = 0;
- p->lastring = 0;
- if (ast_modem_send(p, "AT+VLS=1", 0) ||
- ast_modem_expect(p, "OK", 10)) {
- ast_log(LOG_WARNING, "Unable to answer: %s", p->response);
- return -1;
- }
- return 0;
-}
-
-static int bestdata_dialdigit(struct ast_modem_pvt *p, char digit)
-{
- char cmd[80];
-
- if (p->ministate != STATE_COMMAND) bestdata_break(p);
- snprintf(cmd, sizeof(cmd), "AT+VTS=%c", digit);
- if (ast_modem_send(p, cmd, 0) ||
- ast_modem_expect(p, "OK", 10)) {
- ast_log(LOG_WARNING, "Unable to answer: %s", p->response);
- return -1;
- }
- return 0;
-}
-
-static int bestdata_dial(struct ast_modem_pvt *p, char *stuff)
-{
- char cmd[800] = "",a[20]="";
- int i,j;
-
- if (p->ministate != STATE_COMMAND)
- {
- bestdata_break(p);
- strncpy(cmd, "AT+VTS=", sizeof(cmd) - 1);
- j = strlen(cmd);
- for(i = 0; stuff[i]; i++)
- {
- switch(stuff[i])
- {
- case '!' :
- a[0] = stuff[i];
- a[1] = 0;
- break;
- case ',':
- strncpy(a, "[,,100]", sizeof(a) - 1);
- break;
- default:
- snprintf(a, sizeof(a), "{%c,7}", stuff[i]);
- }
- if (stuff[i + 1]) strncat(a, ",", sizeof(a) - strlen(a) - 1);
- strncpy(cmd + j, a, sizeof(cmd) - j - 1);
- j += strlen(a);
- }
- }
- else
- {
- snprintf(cmd, sizeof(cmd), "ATD%c %s", p->dialtype,stuff);
- }
- if (ast_modem_send(p, cmd, 0)) {
- ast_log(LOG_WARNING, "Unable to dial\n");
- return -1;
- }
- return 0;
-}
-
-static int bestdata_hangup(struct ast_modem_pvt *p)
-{
- if (bestdata_break(p))
- return -1;
- /* Hangup by switching to data, then back to voice */
- if (ast_modem_send(p, "ATH", 0) ||
- ast_modem_expect(p, "OK", 8)) {
- ast_log(LOG_WARNING, "Unable to set to data mode\n");
- return -1;
- }
- if (ast_modem_send(p, "AT+FCLASS=8", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to voice mode\n");
- return -1;
- }
- p->gotclid = 0;
- p->ringt = 0;
- p->lastring = 0;
- p->dtmfrx = 0;
- return 0;
-}
-
-static struct ast_modem_driver bestdata_driver =
-{
- "BestData",
- bestdata_idents,
- AST_FORMAT_SLINEAR,
- 0, /* Not full duplex */
- bestdata_incusecnt, /* incusecnt */
- bestdata_decusecnt, /* decusecnt */
- bestdata_identify, /* identify */
- bestdata_init, /* init */
- NULL, /* setdev */
- bestdata_read,
- bestdata_write,
- bestdata_dial, /* dial */
- bestdata_answer, /* answer */
- bestdata_hangup, /* hangup */
- bestdata_startrec, /* start record */
- NULL, /* stop record */
- bestdata_startplay, /* start playback */
- NULL, /* stop playback */
- NULL, /* set silence supression */
- bestdata_dialdigit, /* dialdigit */
-};
-
-
-
-int usecount(void)
-{
- return usecnt;
-}
-
-int load_module(void)
-{
- return ast_register_modem_driver(&bestdata_driver);
-}
-
-int unload_module(void)
-{
- return ast_unregister_modem_driver(&bestdata_driver);
-}
-
-char *description()
-{
- return desc;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}
diff --git a/channels/chan_modem_i4l.c b/channels/chan_modem_i4l.c
deleted file mode 100644
index 36a2bd802..000000000
--- a/channels/chan_modem_i4l.c
+++ /dev/null
@@ -1,745 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*! \file
- *
- * \brief ISDN4Linux TTY Driver
- *
- * \author Mark Spencer <markster@digium.com>
- *
- * \ingroup channel_drivers
- */
-
-#include <stdio.h>
-
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/lock.h"
-#include "asterisk/vmodem.h"
-#include "asterisk/module.h"
-#include "asterisk/frame.h"
-#include "asterisk/logger.h"
-#include "asterisk/options.h"
-#include "asterisk/dsp.h"
-#include "asterisk/callerid.h"
-#include "asterisk/ulaw.h"
-#include "asterisk/pbx.h"
-#include "asterisk/utils.h"
-
-#define STATE_COMMAND 0
-#define STATE_VOICE 1
-
-static char *breakcmd = "\0x10\0x14\0x10\0x3";
-
-static char *desc = "ISDN4Linux Emulated Modem Driver";
-
-static int usecnt;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-static char *i4l_idents[] = {
- /* Identify ISDN4Linux Driver */
- "Linux ISDN",
- NULL
-};
-
-static int i4l_setdev(struct ast_modem_pvt *p, int dev)
-{
- char cmd[80];
- if ((dev != MODEM_DEV_TELCO) && (dev != MODEM_DEV_TELCO_SPK)) {
- ast_log(LOG_WARNING, "ISDN4Linux only supports telco device, not %d.\n", dev);
- return -1;
- } else /* Convert DEV to our understanding of it */
- dev = 2;
- if (ast_modem_send(p, "AT+VLS?", 0)) {
- ast_log(LOG_WARNING, "Unable to select current mode %d\n", dev);
- return -1;
- }
- if (ast_modem_read_response(p, 5)) {
- ast_log(LOG_WARNING, "Unable to select device %d\n", dev);
- return -1;
- }
- ast_modem_trim(p->response);
- strncpy(cmd, p->response, sizeof(cmd)-1);
- if (ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Modem did not respond properly\n");
- return -1;
- }
- if (dev == atoi(cmd)) {
- /* We're already in the right mode, don't bother changing for fear of
- hanging up */
- return 0;
- }
- snprintf(cmd, sizeof(cmd), "AT+VLS=%d", dev);
- if (ast_modem_send(p, cmd, 0)) {
- ast_log(LOG_WARNING, "Unable to select device %d\n", dev);
- return -1;
- }
- if (ast_modem_read_response(p, 5)) {
- ast_log(LOG_WARNING, "Unable to select device %d\n", dev);
- return -1;
- }
- ast_modem_trim(p->response);
- if (strcasecmp(p->response, "VCON") && strcasecmp(p->response, "OK")) {
- ast_log(LOG_WARNING, "Unexpected reply: %s\n", p->response);
- return -1;
- }
- return 0;
-}
-
-static int i4l_startrec(struct ast_modem_pvt *p)
-{
- if (ast_modem_send(p, "AT+VRX+VTX", 0) ||
- ast_modem_expect(p, "CONNECT", 5)) {
- ast_log(LOG_WARNING, "Unable to start recording\n");
- return -1;
- }
- p->ministate = STATE_VOICE;
-
- /* let ast dsp detect dtmf */
- if (p->dtmfmode & MODEM_DTMF_AST) {
- if (p->dsp) {
- ast_log(LOG_DEBUG, "Already have a dsp on %s?\n", p->dev);
- } else {
- p->dsp = ast_dsp_new();
- if (p->dsp) {
- ast_log(LOG_DEBUG, "Detecting DTMF inband with sw DSP on %s\n",p->dev);
- ast_dsp_set_features(p->dsp, DSP_FEATURE_DTMF_DETECT|DSP_FEATURE_FAX_DETECT);
- ast_dsp_digitmode(p->dsp, DSP_DIGITMODE_DTMF | 0);
- }
- }
- }
-
- return 0;
-}
-
-static int i4l_break(struct ast_modem_pvt *p)
-{
- if (ast_modem_send(p, breakcmd, 2)) {
- ast_log(LOG_WARNING, "Failed to break\n");
- return -1;
- }
- if (ast_modem_send(p, "\r\n", 2)) {
- ast_log(LOG_WARNING, "Failed to send enter?\n");
- return -1;
- }
-#if 0
- /* Read any outstanding junk */
- while(!ast_modem_read_response(p, 1));
-#endif
- if (ast_modem_send(p, "AT", 0)) {
- /* Modem might be stuck in some weird mode, try to get it out */
- ast_modem_send(p, "+++", 3);
- if (ast_modem_expect(p, "OK", 10)) {
- ast_log(LOG_WARNING, "Modem is not responding\n");
- return -1;
- }
- if (ast_modem_send(p, "AT", 0)) {
- ast_log(LOG_WARNING, "Modem is not responding\n");
- return -1;
- }
- }
- if (ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Modem did not respond properly\n");
- return -1;
- }
- return 0;
-}
-
-static int i4l_init(struct ast_modem_pvt *p)
-{
- char cmd[256];
- if (option_debug)
- ast_log(LOG_DEBUG, "i4l_init()\n");
- if (i4l_break(p))
- return -1;
- /* Force into command mode */
- p->ministate = STATE_COMMAND;
- if (ast_modem_send(p, "AT+FCLASS=8", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to voice mode\n");
- return -1;
- }
- if (!ast_strlen_zero(p->msn)) {
- snprintf(cmd, sizeof(cmd), "AT&E%s", p->msn);
- if (ast_modem_send(p, cmd, 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set MSN to %s\n", p->msn);
- return -1;
- }
- }
- if (!ast_strlen_zero(p->incomingmsn)) {
- char *q;
- snprintf(cmd, sizeof(cmd), "AT&L%s", p->incomingmsn);
- /* translate , into ; since that is the seperator I4L uses, but can't be directly */
- /* put in the config file because it will interpret the rest of the line as comment. */
- q = cmd+4;
- while (*q) {
- if (*q == ',') *q = ';';
- ++q;
- }
- if (ast_modem_send(p, cmd, 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set Listen to %s\n", p->msn);
- return -1;
- }
- }
- if (ast_modem_send(p, "AT&D2", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to DTR disconnect mode\n");
- return -1;
- }
- if (ast_modem_send(p, "ATS18=1", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to audio only mode\n");
- return -1;
- }
- if (ast_modem_send(p, "ATS13.6=1", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to RUNG indication\n");
- return -1;
- }
- if (ast_modem_send(p, "ATS14=4", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to transparent mode\n");
- return -1;
- }
- if (ast_modem_send(p, "ATS23=9", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to transparent/ringing mode\n");
- return -1;
- }
-
- if (ast_modem_send(p, "AT+VSM=6", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to muLAW mode\n");
- return -1;
- }
- if (ast_modem_send(p, "AT+VLS=2", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to phone line interface\n");
- return -1;
- }
- p->escape = 0;
- return 0;
-}
-
-static struct ast_frame *i4l_handle_escape(struct ast_modem_pvt *p, char esc)
-{
- /* Handle escaped characters -- but sometimes we call it directly as
- a quick way to cause known responses */
- p->fr.frametype = AST_FRAME_NULL;
- p->fr.subclass = 0;
- p->fr.data = NULL;
- p->fr.datalen = 0;
- p->fr.samples = 0;
- p->fr.offset = 0;
- p->fr.mallocd = 0;
- p->fr.delivery.tv_sec = 0;
- p->fr.delivery.tv_usec = 0;
- if (esc && option_debug)
- ast_log(LOG_DEBUG, "Escaped character '%c'\n", esc);
-
- switch(esc) {
- case 'R': /* Pseudo ring */
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_RING;
- return &p->fr;
- case 'I': /* Pseudo ringing */
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_RINGING;
- return &p->fr;
- case 'X': /* Pseudo connect */
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_ANSWER;
- if (p->owner)
- ast_setstate(p->owner, AST_STATE_UP);
- if (i4l_startrec(p))
- return NULL;
- return &p->fr;
- case 'b': /* Busy signal */
- p->fr.frametype = AST_FRAME_CONTROL;
- p->fr.subclass = AST_CONTROL_BUSY;
- return &p->fr;
- case 'o': /* Overrun */
- ast_log(LOG_WARNING, "Overflow on modem, flushing buffers\n");
- if (ast_modem_send(p, "\0x10E", 2))
- ast_log(LOG_WARNING, "Unable to flush buffers\n");
- return &p->fr;
- case CHAR_ETX: /* End Transmission */
- return NULL;
- case 'u': /* Underrun */
- ast_log(LOG_WARNING, "Data underrun\n");
- /* Fall Through */
- case 'd': /* Dialtone */
- case 'c': /* Calling Tone */
- case 'e': /* European version */
- case 'a': /* Answer Tone */
- case 'f': /* Bell Answer Tone */
- case 'T': /* Timing mark */
- case 't': /* Handset off hook */
- case 'h': /* Handset hungup */
- /* Ignore */
- if (option_debug)
- ast_log(LOG_DEBUG, "Ignoring Escaped character '%c' (%d)\n", esc, esc);
- return &p->fr;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- case '*':
- case '#':
- ast_log(LOG_DEBUG, "Detected outband DTMF digit: '%c' (%d)\n", esc, esc);
- p->fr.frametype=AST_FRAME_DTMF;
- p->fr.subclass=esc;
- return &p->fr;
- case 0: /* Pseudo signal */
- return &p->fr;
- default:
- ast_log(LOG_DEBUG, "Unknown Escaped character '%c' (%d)\n", esc, esc);
- }
- return &p->fr;
-}
-
-static struct ast_frame *i4l_read(struct ast_modem_pvt *p)
-{
- unsigned char result[256];
- short *b;
- struct ast_frame *f=NULL;
- int res;
- int x;
- if (p->ministate == STATE_COMMAND) {
- /* Read the first two bytes, first, in case it's a control message */
- res = read(p->fd, result, 2);
- if (res < 2) {
- /* short read, means there was a hangup? */
- /* (or is this also possible without hangup?) */
- /* Anyway, reading from unitialized buffers is a bad idea anytime. */
- if (errno == EAGAIN)
- return i4l_handle_escape(p, 0);
- return NULL;
- }
- if (result[0] == CHAR_DLE) {
- return i4l_handle_escape(p, result[1]);
-
- } else {
- if ((result[0] == '\n') || (result[0] == '\r'))
- return i4l_handle_escape(p, 0);
- /* Read the rest of the line */
- fgets(result + 2, sizeof(result) - 2, p->f);
- ast_modem_trim(result);
- if (!strcasecmp(result, "VCON")) {
- /* If we're in immediate mode, reply now */
-/* if (p->mode == MODEM_MODE_IMMEDIATE) */
- return i4l_handle_escape(p, 'X');
- } else
- if (!strcasecmp(result, "BUSY")) {
- /* Same as a busy signal */
- return i4l_handle_escape(p, 'b');
- } else
- if (!strncasecmp(result, "CALLER NUMBER: ", 15 )) {
- strncpy(p->cid_num, result + 15, sizeof(p->cid_num)-1);
- return i4l_handle_escape(p, 0);
- } else
- if (!strcasecmp(result, "RINGING")) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "%s is ringing...\n", p->dev);
- return i4l_handle_escape(p, 'I');
- } else
- if (!strncasecmp(result, "RUNG", 4)) {
- /* PM2002: the line was hung up before we picked it up, bye bye */
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "%s was hung up on before we answered\n", p->dev);
- return NULL;
- } else
- if (!strncasecmp(result, "RING", 4)) {
- if (result[4]=='/')
- strncpy(p->dnid, result + 5, sizeof(p->dnid)-1);
- return i4l_handle_escape(p, 'R');
- } else
- if (!strcasecmp(result, "NO CARRIER")) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "%s hung up on\n", p->dev);
- return NULL;
- } else
- if (!strcasecmp(result, "NO DIALTONE")) {
- /* There's no dialtone, so the line isn't working */
- ast_log(LOG_WARNING, "Device '%s' lacking dialtone\n", p->dev);
- return NULL;
- }
- if (option_debug)
- ast_log(LOG_DEBUG, "Modem said '%s'\n", result);
- return i4l_handle_escape(p, 0);
- }
- } else {
- /* We have to be more efficient in voice mode */
- b = (short *)(p->obuf + p->obuflen);
- while (p->obuflen/2 < 240) {
- /* Read ahead the full amount */
- res = read(p->fd, result, 240 - p->obuflen/2);
- if (res < 1) {
- /* If there's nothing there, just continue on */
- if (errno == EAGAIN)
- return i4l_handle_escape(p, 0);
- ast_log(LOG_WARNING, "Read failed: %s\n", strerror(errno));
- return NULL;
- }
-
- for (x=0;x<res;x++) {
- /* Process all the bytes that we've read */
- switch(result[x]) {
- case CHAR_DLE:
-#if 0
- ast_log(LOG_DEBUG, "Ooh, an escape at %d...\n", x);
-#endif
- if (!p->escape) {
- /* Note that next value is
- an escape, and continue. */
- p->escape++;
- break;
- } else {
- /* Send as is -- fallthrough */
- p->escape = 0;
- }
- default:
- if (p->escape) {
- ast_log(LOG_DEBUG, "Value of escape is %c (%d)...\n", result[x] < 32 ? '^' : result[x], result[x]);
- p->escape = 0;
- if (f)
- ast_log(LOG_WARNING, "Warning: Dropped a signal frame\n");
- f = i4l_handle_escape(p, result[x]);
- /* If i4l_handle_escape says NULL, say it now, doesn't matter
- what else is there, the connection is dead. */
- if (!f)
- return NULL;
- } else {
- *(b++) = AST_MULAW((int)result[x]);
- p->obuflen += 2;
- }
- }
- }
- if (f)
- break;
- }
- if (f) {
- if( ! (!(p->dtmfmode & MODEM_DTMF_I4L) && f->frametype == AST_FRAME_DTMF))
- return f;
- }
-
- /* If we get here, we have a complete voice frame */
- p->fr.frametype = AST_FRAME_VOICE;
- p->fr.subclass = AST_FORMAT_SLINEAR;
- p->fr.samples = 240;
- p->fr.data = p->obuf;
- p->fr.datalen = p->obuflen;
- p->fr.mallocd = 0;
- p->fr.delivery.tv_sec = 0;
- p->fr.delivery.tv_usec = 0;
- p->fr.offset = AST_FRIENDLY_OFFSET;
- p->fr.src = __FUNCTION__;
- p->obuflen = 0;
-
- /* process with dsp */
- if (p->dsp) {
- f = ast_dsp_process(p->owner, p->dsp, &p->fr);
- if (f && (f->frametype == AST_FRAME_DTMF)) {
- ast_log(LOG_DEBUG, "Detected inband DTMF digit: %c on %s\n", f->subclass, p->dev);
- if (f->subclass == 'f') {
- /* Fax tone -- Handle and return NULL */
- struct ast_channel *ast = p->owner;
- if (!p->faxhandled) {
- p->faxhandled++;
- if (strcmp(ast->exten, "fax")) {
- const char *target_context = ast_strlen_zero(ast->macrocontext) ? ast->context : ast->macrocontext;
-
- if (ast_exists_extension(ast, target_context, "fax", 1, ast->cid.cid_num)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Redirecting %s to fax extension\n", ast->name);
- /* Save the DID/DNIS when we transfer the fax call to a "fax" extension */
- pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast->exten);
- if (ast_async_goto(ast, target_context, "fax", 1))
- ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", ast->name, target_context);
- } else
- ast_log(LOG_NOTICE, "Fax detected, but no fax extension\n");
- } else
- ast_log(LOG_DEBUG, "Already in a fax extension, not redirecting\n");
- } else
- ast_log(LOG_DEBUG, "Fax already handled\n");
- p->fr.frametype = AST_FRAME_NULL;
- p->fr.subclass = 0;
- f = &p->fr;
- }
- return f;
- }
- }
-
- return &p->fr;
- }
- return NULL;
-}
-
-static int i4l_write(struct ast_modem_pvt *p, struct ast_frame *f)
-{
-#define MAX_WRITE_SIZE 2048
- unsigned char result[MAX_WRITE_SIZE << 1];
- unsigned char b;
- int bpos=0, x;
- int res;
- if (f->datalen > MAX_WRITE_SIZE) {
- ast_log(LOG_WARNING, "Discarding too big frame of size %d\n", f->datalen);
- return -1;
- }
- if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Don't know how to handle %d type frames\n", f->frametype);
- return -1;
- }
- if (f->subclass != AST_FORMAT_SLINEAR) {
- ast_log(LOG_WARNING, "Don't know how to handle anything but signed linear frames\n");
- return -1;
- }
- for (x=0;x<f->datalen/2;x++) {
- b = AST_LIN2MU(((short *)f->data)[x]);
- result[bpos++] = b;
- if (b == CHAR_DLE)
- result[bpos++]=b;
- }
-#if 0
- res = fwrite(result, bpos, 1, p->f);
- res *= bpos;
-#else
- res = write(p->fd, result, bpos);
-#endif
- if (res < 1) {
- if (errno != EAGAIN) {
- ast_log(LOG_WARNING, "Failed to write buffer\n");
- return -1;
- }
- }
-#if 0
- printf("Result of write is %d\n", res);
-#endif
- return 0;
-}
-
-static char *i4l_identify(struct ast_modem_pvt *p)
-{
- return strdup("Linux ISDN");
-}
-
-static void i4l_incusecnt(void)
-{
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
-}
-
-static void i4l_decusecnt(void)
-{
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- ast_update_use_count();
-}
-
-static int i4l_answer(struct ast_modem_pvt *p)
-{
- if (ast_modem_send(p, "ATA\r", 4) ||
- ast_modem_expect(p, "VCON", 10)) {
- ast_log(LOG_WARNING, "Unable to answer: %s", p->response);
- return -1;
- }
-#if 1
- if (ast_modem_send(p, "AT+VDD=0,8", 0) ||
- ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Unable to set to phone line interface\n");
- return -1;
- }
-#endif
- if (ast_modem_send(p, "AT+VTX+VRX", 0) ||
- ast_modem_expect(p, "CONNECT", 10)) {
- ast_log(LOG_WARNING, "Unable to answer: %s", p->response);
- return -1;
- }
- p->ministate = STATE_VOICE;
-
- /* let ast dsp detect dtmf */
- if (p->dtmfmode & MODEM_DTMF_AST) {
- if (p->dsp) {
- ast_log(LOG_DEBUG, "Already have a dsp on %s?\n", p->dev);
- } else {
- p->dsp = ast_dsp_new();
- if (p->dsp) {
- ast_log(LOG_DEBUG, "Detecting DTMF inband with sw DSP on %s\n",p->dev);
- ast_dsp_set_features(p->dsp, DSP_FEATURE_DTMF_DETECT|DSP_FEATURE_FAX_DETECT);
- ast_dsp_digitmode(p->dsp, DSP_DIGITMODE_DTMF | 0);
- }
- }
- }
-
- return 0;
-}
-
-static int i4l_dialdigit(struct ast_modem_pvt *p, char digit)
-{
- char c[2];
- if (p->ministate == STATE_VOICE) {
- if (p->dtmfmodegen & MODEM_DTMF_I4L) {
- c[0] = CHAR_DLE;
- c[1] = digit;
- write(p->fd, c, 2);
- ast_log(LOG_DEBUG, "Send ISDN out-of-band DTMF %c\n",digit);
- }
- if(p->dtmfmodegen & MODEM_DTMF_AST) {
- ast_log(LOG_DEBUG, "Generating inband DTMF\n");
- return -1;
- }
- } else
- ast_log(LOG_DEBUG, "Asked to send digit but call not up on %s\n", p->dev);
- return 0;
-}
-
-static int i4l_dial(struct ast_modem_pvt *p, char *stuff)
-{
- char cmd[80];
- char tmpmsn[255];
- struct ast_channel *c = p->owner;
-
- /* Find callerid number first, to set the correct A number */
- if (c && c->cid.cid_num && !(c->cid.cid_pres & 0x20)) {
- snprintf(tmpmsn, sizeof(tmpmsn), ",%s,", c->cid.cid_num);
- if(!ast_strlen_zero(p->outgoingmsn) && strstr(p->outgoingmsn,tmpmsn) != NULL) {
- /* Tell ISDN4Linux to use this as A number */
- snprintf(cmd, sizeof(cmd), "AT&E%s\n", c->cid.cid_num);
- if (ast_modem_send(p, cmd, strlen(cmd))) {
- ast_log(LOG_WARNING, "Unable to set A number to %s\n", c->cid.cid_num);
- }
-
- } else {
- ast_log(LOG_WARNING, "Outgoing MSN %s not allowed (see outgoingmsn=%s in modem.conf)\n",c->cid.cid_num,p->outgoingmsn);
- }
- }
-
- snprintf(cmd, sizeof(cmd), "ATD%c %s\n", p->dialtype,stuff);
- if (ast_modem_send(p, cmd, strlen(cmd))) {
- ast_log(LOG_WARNING, "Unable to dial\n");
- return -1;
- }
- return 0;
-}
-
-static int i4l_hangup(struct ast_modem_pvt *p)
-{
- char dummy[50];
- int dtr = TIOCM_DTR;
-
- /* free the memory used by the DSP */
- if (p->dsp) {
- ast_dsp_free(p->dsp);
- p->dsp = NULL;
- }
-
- /* down DTR to hangup modem */
- ioctl(p->fd, TIOCMBIC, &dtr);
- /* Read anything outstanding */
- while(read(p->fd, dummy, sizeof(dummy)) > 0);
-
- /* rise DTR to re-enable line */
- ioctl(p->fd, TIOCMBIS, &dtr);
-
- /* Read anything outstanding */
- while(read(p->fd, dummy, sizeof(dummy)) > 0);
-
- /* basically we're done, just to be sure */
- write(p->fd, "\n\n", 2);
- read(p->fd, dummy, sizeof(dummy));
- if (ast_modem_send(p, "ATH", 0)) {
- ast_log(LOG_WARNING, "Unable to hang up\n");
- return -1;
- }
- if (ast_modem_expect(p, "OK", 5)) {
- ast_log(LOG_WARNING, "Final 'OK' not received\n");
- return -1;
- }
-
- return 0;
-}
-
-static struct ast_modem_driver i4l_driver =
-{
- "i4l",
- i4l_idents,
- AST_FORMAT_SLINEAR,
- 0, /* Not full duplex */
- i4l_incusecnt, /* incusecnt */
- i4l_decusecnt, /* decusecnt */
- i4l_identify, /* identify */
- i4l_init, /* init */
- i4l_setdev, /* setdev */
- i4l_read,
- i4l_write,
- i4l_dial, /* dial */
- i4l_answer, /* answer */
- i4l_hangup, /* hangup */
- i4l_startrec, /* start record */
- NULL, /* stop record */
- NULL, /* start playback */
- NULL, /* stop playback */
- NULL, /* set silence supression */
- i4l_dialdigit, /* dialdigit */
-};
-
-
-
-int usecount(void)
-{
- return usecnt;
-}
-
-int load_module(void)
-{
- return ast_register_modem_driver(&i4l_driver);
-}
-
-int unload_module(void)
-{
- return ast_unregister_modem_driver(&i4l_driver);
-}
-
-char *description()
-{
- return desc;
-}
-
-char *key()
-{
- return ASTERISK_GPL_KEY;
-}