Okay, here is the first try for an user-land

ttyI daemon. Compilable but not useable.
This commit is contained in:
armin 2000-08-30 18:27:01 +00:00
parent ca25662b9a
commit 7095164c7d
10 changed files with 2164 additions and 0 deletions

35
ttyId/Makefile Normal file
View File

@ -0,0 +1,35 @@
# $Id: Makefile,v 1.1 2000/08/30 18:27:01 armin Exp $
VERSION = 0.1
libdir = $(exec_prefix)/lib
CC = gcc
CCFLAGS = -O -Wall -I.
LINK = $(CC)
CFLAGS = $(CCFLAGS) \
-DVERSION=\"$(VERSION)\"
LDFLAGS = -L$(libdir)
MAKE = make
MKDIR = mkdir -p -m 755
STRIP = strip
RM = rm
INSTALL = install -c -o root -g root -m 700
INSTALL2 = install -c -o root -g root -m 600
all: ttyId
MAINOBJS = main.o pty.o utils.o profile.o emulator.o \
communicate.o
ttyId: $(MAINOBJS)
$(CC) $(MAINOBJS) -o ./ttyId
clean: ignore
@find . -name '*.o' -exec $(RM) {} ';'
ignore:

153
ttyId/communicate.c Normal file
View File

@ -0,0 +1,153 @@
/* $Id: communicate.c,v 1.1 2000/08/30 18:27:01 armin Exp $
*
* ttyId - CAPI TTY AT-command emulator
*
* based on the AT-command emulator of the isdn4linux
* kernel subsystem.
*
* Copyright 2000 by Armin Schindler (mac@melware.de)
*
* 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, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: communicate.c,v $
* Revision 1.1 2000/08/30 18:27:01 armin
* Okay, here is the first try for an user-land
* ttyI daemon. Compilable but not useable.
*
*
*/
#include "ttyId.h"
int
tty_write(unsigned char *buf, int len)
{
int c;
int total = 0;
/* TODO */
while (1) {
/*
c = MIN(count, info->xmit_size - info->xmit_count);
if (info->isdn_driver >= 0)
c = MIN(c, dev->drv[info->isdn_driver]->maxbufsize);
if (c <= 0)
break;
*/
#if 0
if ((info->online > 1)
|| (info->vonline & 3)
) {
if (!info->vonline)
isdn_tty_check_esc(buf, m->mdmreg[REG_ESC], c,
&(m->pluscount),
&(m->lastplus),
from_user);
if (from_user)
copy_from_user(&(info->xmit_buf[info->xmit_count]), buf, c);
else
memcpy(&(info->xmit_buf[info->xmit_count]), buf, c);
if (info->vonline) {
int cc = isdn_tty_handleDLEdown(info, m, c);
if (info->vonline & 2) {
if (!cc) {
/* If DLE decoding results in zero-transmit, but
* c originally was non-zero, do a wakeup.
*/
if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
tty->ldisc.write_wakeup)
(tty->ldisc.write_wakeup) (tty);
wake_up_interruptible(&tty->write_wait);
info->msr |= UART_MSR_CTS;
info->lsr |= UART_LSR_TEMT;
}
info->xmit_count += cc;
}
if ((info->vonline & 3) == 1) {
/* Do NOT handle Ctrl-Q or Ctrl-S
* when in full-duplex audio mode.
*/
if (isdn_tty_end_vrx(buf, c, from_user)) {
info->vonline &= ~1;
#ifdef ISDN_DEBUG_MODEM_VOICE
printk(KERN_DEBUG
"got !^Q/^S, send DLE-ETX,VCON on ttyI%d\n",
info->line);
#endif
isdn_tty_at_cout("\020\003\r\nVCON\r\n", info);
}
}
} else
#if 0 /* def ISDN_TTY_FCLASS1 */
if (TTY_IS_FCLASS1(info)) {
int cc = isdn_tty_handleDLEdown(info, m, c);
if (info->vonline & 4) { /* ETX seen */
isdn_ctrl c;
c.command = ISDN_CMD_FAXCMD;
c.driver = info->isdn_driver;
c.arg = info->isdn_channel;
c.parm.aux.cmd = ISDN_FAX_CLASS1_CTRL;
c.parm.aux.subcmd = ETX;
isdn_command(&c);
}
info->vonline = 0;
printk(KERN_DEBUG "fax dle cc/c %d/%d\n", cc,c);
info->xmit_count += cc;
} else
#endif
info->xmit_count += c;
} else {
#endif
info.msr |= UART_MSR_CTS;
info.lsr |= UART_LSR_TEMT;
if (info.dialing) {
info.dialing = 0;
logit(LOG_DEBUG, "Mhup in tty write");
/*
isdn_tty_modem_result(RESULT_NO_CARRIER, info);
isdn_tty_modem_hup(info, 1);
*/
} else {
tty_edit_at(buf, len);
return(len);
}
#if 0
}
buf += c;
count -= c;
total += c;
#endif
}
#if 0
atomic_dec(&info->xmit_lock);
if ((info->xmit_count) || (skb_queue_len(&info->xmit_queue))) {
if (m->mdmreg[REG_DXMT] & BIT_DXMT) {
isdn_tty_senddown(info);
isdn_tty_tint(info);
}
isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1);
}
if (from_user)
up(&info->write_sem);
#endif
return total;
}

1030
ttyId/emulator.c Normal file

File diff suppressed because it is too large Load Diff

214
ttyId/main.c Normal file
View File

@ -0,0 +1,214 @@
/* $Id: main.c,v 1.1 2000/08/30 18:27:01 armin Exp $
*
* ttyId - CAPI TTY AT-command emulator
*
* based on the AT-command emulator of the isdn4linux
* kernel subsystem.
*
* Copyright 2000 by Armin Schindler (mac@melware.de)
*
* 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, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: main.c,v $
* Revision 1.1 2000/08/30 18:27:01 armin
* Okay, here is the first try for an user-land
* ttyI daemon. Compilable but not useable.
*
*
*/
#include "ttyId.h"
#include "pty.h"
#include <getopt.h>
int debug = 0;
int dev_linked = 0;
int pty_fd = -1;
char slave_name[80];
char device_name[80];
modem_info info;
void EXIT_ttyId(int rc);
static struct option Arguments[] =
{
{ "device" , 1, NULL, 'd' },
{ "verbose" , 0, NULL, 'v' },
{ "help", 0, NULL, 'h' },
{ NULL, 0, NULL, 0 }
};
void
HUP_Signal(int sig)
{
logit(LOG_DEBUG, "got HUP signal");
}
void
TERM_Signal(int sig)
{
logit(LOG_DEBUG, "got TERM signal");
EXIT_ttyId(sig);
}
void
ALARM_Signal(int sig)
{
}
static void SetSignals(void)
{
signal(SIGTERM , TERM_Signal);
signal(SIGHUP , HUP_Signal);
signal(SIGALRM , ALARM_Signal);
signal(SIGTTIN , SIG_IGN);
signal(SIGTTOU , SIG_IGN);
signal(SIGINT , SIG_IGN);
signal(SIGQUIT , SIG_IGN);
signal(SIGILL , SIG_IGN);
signal(SIGTRAP , SIG_IGN);
signal(SIGABRT , SIG_IGN);
signal(SIGUNUSED , SIG_IGN);
signal(SIGUSR1 , SIG_IGN);
signal(SIGUSR2 , SIG_IGN);
signal(SIGPIPE , SIG_IGN);
signal(SIGSTKFLT , SIG_IGN);
signal(SIGCHLD , SIG_IGN);
signal(SIGTSTP , SIG_IGN);
signal(SIGIO , SIG_IGN);
signal(SIGXCPU , SIG_IGN);
signal(SIGXFSZ , SIG_IGN);
signal(SIGVTALRM , SIG_IGN);
signal(SIGPROF , SIG_IGN);
signal(SIGWINCH , SIG_IGN);
}
void
EXIT_ttyId(int rc)
{
if (pty_fd)
close(pty_fd);
if ((dev_linked) && (strlen(device_name)))
unlink(device_name);
logit(LOG_NOTICE, "ending ttyId (code=%d)", rc);
exit(rc);
}
void
Usage(void)
{
fprintf(stderr, "\n");
fprintf(stderr, "Usage: ttyId OPTION OPTION OPTION [...]\n");
fprintf(stderr, "\n");
fprintf(stderr, "-d, --device NAME Device name to use (eg. /dev/ttyI5).\n");
fprintf(stderr, "-v, --verbose Set debug mode on.\n");
fprintf(stderr, "-h, --help Displays this help message.\n");
fprintf(stderr, "\n");
exit(100);
}
int
main(int argc, char *argv[])
{
int Opts, i;
int ret = 0;
struct timeval Timeout;
fd_set FD;
unsigned char buf[4096];
*device_name = 0;
while ((Opts = getopt_long(argc, argv, "d:hv", Arguments, (int *)0)) != EOF)
{
switch (Opts)
{
case 'v':
debug = 1;
break;
case 'd':
CopyString(device_name, optarg, sizeof(device_name) - 1);
break;
case 'h':
default:
Usage();
break;
}
}
openlog("ttyId", LOG_PID | LOG_NDELAY, LOG_DAEMON);
logit(LOG_NOTICE, "starting ttyId version %s ...", VERSION);
logit(LOG_DEBUG, "set device=\"%s\" debug=%d", device_name, debug);
if (!get_pty(&pty_fd, slave_name)) {
logit(LOG_ERR, "Unable to get pty master-slave");
EXIT_ttyId(101);
}
logit(LOG_DEBUG, "got pty_fd=%d with slave: %s", pty_fd, slave_name);
if (strlen(device_name)) {
if (create_devicelink(slave_name, device_name))
EXIT_ttyId(103);
dev_linked = 1;
logit(LOG_DEBUG, "link created for %s", device_name);
}
SetSignals();
modem_init();
while(1) {
FD_ZERO(&FD);
FD_SET(pty_fd, &FD);
Timeout.tv_sec = 10;
Timeout.tv_usec = 0;
ret = select(FD_SETSIZE, &FD, NULL, NULL, &Timeout);
if (ret < 0) {
logit(LOG_ERR, "main select error %d", errno);
continue;
}
if (!ret) {
continue;
}
i = read(pty_fd, buf, sizeof(buf));
if (i < 0) {
/* TODO help me */
usleep(100);
}
if (i > 0) {
tty_write(buf, i);
logit(LOG_DEBUG, "got %d byte(s) from slave", i);
}
}
EXIT_ttyId(0);
return(0);
}

134
ttyId/profile.c Normal file
View File

@ -0,0 +1,134 @@
/* $Id: profile.c,v 1.1 2000/08/30 18:27:01 armin Exp $
*
* ttyId - CAPI TTY AT-command emulator
*
* based on the AT-command emulator of the isdn4linux
* kernel subsystem.
*
* Copyright 2000 by Armin Schindler (mac@melware.de)
*
* 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, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: profile.c,v $
* Revision 1.1 2000/08/30 18:27:01 armin
* Okay, here is the first try for an user-land
* ttyI daemon. Compilable but not useable.
*
*
*/
#include "ttyId.h"
void
modem_reset_faxpar(void)
{
T30_s *f = &info.fax;
f->code = 0;
f->phase = ISDN_FAX_PHASE_IDLE;
f->direction = 0;
f->resolution = 1; /* fine */
f->rate = 5; /* 14400 bit/s */
f->width = 0;
f->length = 0;
f->compression = 0;
f->ecm = 0;
f->binary = 0;
f->scantime = 0;
memset(&f->id[0], 32, FAXIDLEN - 1);
f->id[FAXIDLEN - 1] = 0;
f->badlin = 0;
f->badmul = 0;
f->bor = 0;
f->nbc = 0;
f->cq = 0;
f->cr = 0;
f->ctcrty = 0;
f->minsp = 0;
f->phcto = 30;
f->rel = 0;
memset(&f->pollid[0], 32, FAXIDLEN - 1);
f->pollid[FAXIDLEN - 1] = 0;
}
void
modem_reset_vpar(atemu * m)
{
m->vpar[0] = 2; /* Voice-device (2 = phone line) */
m->vpar[1] = 0; /* Silence detection level (0 = none ) */
m->vpar[2] = 70; /* Silence interval (7 sec. ) */
m->vpar[3] = 2; /* Compression type (1 = ADPCM-2 ) */
m->vpar[4] = 0; /* DTMF detection level (0 = softcode ) */
m->vpar[5] = 8; /* DTMF interval (8 * 5 ms. ) */
}
void
modem_reset_regs(int force)
{
atemu *m = &info.emu;
if ((m->mdmreg[REG_DTRR] & BIT_DTRR) || force) {
memcpy(m->mdmreg, m->profile, ISDN_MODEM_NUMREG);
memcpy(m->msn, m->pmsn, ISDN_MSNLEN);
memcpy(m->lmsn, m->plmsn, ISDN_LMSNLEN);
}
modem_reset_vpar(m);
modem_reset_faxpar();
m->mdmcmdl = 0;
}
void
reset_profile(void)
{
atemu *m = &info.emu;
m->profile[0] = 0;
m->profile[1] = 0;
m->profile[2] = 43;
m->profile[3] = 13;
m->profile[4] = 10;
m->profile[5] = 8;
m->profile[6] = 3;
m->profile[7] = 60;
m->profile[8] = 2;
m->profile[9] = 6;
m->profile[10] = 7;
m->profile[11] = 70;
m->profile[12] = 0x45;
m->profile[13] = 4;
m->profile[14] = ISDN_PROTO_L2_X75I;
m->profile[15] = ISDN_PROTO_L3_TRANS;
m->profile[16] = 128;
m->profile[17] = ISDN_MODEM_WINSIZE;
m->profile[18] = 4;
m->profile[19] = 0;
m->profile[20] = 0;
m->profile[23] = 0;
m->pmsn[0] = '\0';
m->plmsn[0] = '\0';
}
void
modem_init(void)
{
sprintf(info.last_cause, "0000");
sprintf(info.last_num, "none");
info.last_dir = 0;
info.last_lhup = 1;
info.last_l2 = -1;
info.last_si = 0;
reset_profile();
modem_reset_regs(1);
}

103
ttyId/pty.c Normal file
View File

@ -0,0 +1,103 @@
/* $Id: pty.c,v 1.1 2000/08/30 18:27:01 armin Exp $
*
* ttyId - CAPI TTY AT-command emulator
*
* based on the AT-command emulator of the isdn4linux
* kernel subsystem.
*
* Copyright 2000 by Armin Schindler (mac@melware.de)
*
* 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, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: pty.c,v $
* Revision 1.1 2000/08/30 18:27:01 armin
* Okay, here is the first try for an user-land
* ttyI daemon. Compilable but not useable.
*
*
*/
#include "ttyId.h"
#include "pty.h"
/*
* get_pty - get a pty master/slave pair and chown the slave side
* to the uid given. Assumes slave_name points to >= 16 bytes of space.
*/
int
get_pty(int *master_fdp, char *slave_name)
{
int i, mfd, sfd = -1;
char pty_name[16];
#ifdef TIOCGPTN
/*
* Try the unix98 way first.
*/
mfd = open("/dev/ptmx", O_RDWR | O_NONBLOCK);
if (mfd >= 0) {
int ptn;
if (ioctl(mfd, TIOCGPTN, &ptn) >= 0) {
sprintf(pty_name, "/dev/pts/%d", ptn);
chmod(pty_name, S_IRUSR | S_IWUSR);
#ifdef TIOCSPTLCK
ptn = 0;
if (ioctl(mfd, TIOCSPTLCK, &ptn) < 0)
logit(LOG_ERR,"Couldn't unlock pty slave %s", pty_name);
#endif
sfd = 1;
}
}
#endif /* TIOCGPTN */
if (sfd < 0) {
/* the old way - scan through the pty name space */
for (i = 0; i < 64; ++i) {
sprintf(pty_name, "/dev/pty%c%x",
'p' + i / 16, i % 16);
mfd = open(pty_name, O_RDWR | O_NONBLOCK, 0);
if (mfd >= 0) {
pty_name[5] = 't';
sfd = 1;
break;
}
close(mfd);
}
}
if (sfd < 0)
return 0;
strcpy(slave_name, pty_name);
*master_fdp = mfd;
return 1;
}
int
create_devicelink(char *old, char *new)
{
if (symlink(old, new)) {
logit(LOG_ERR,"Unable to create link to %s", new);
return 1;
}
return 0;
}
int
writepty(unsigned char *buf, int len)
{
return(write(pty_fd, buf, len));
}

39
ttyId/pty.h Normal file
View File

@ -0,0 +1,39 @@
/* $Id: pty.h,v 1.1 2000/08/30 18:27:01 armin Exp $
*
* ttyId - CAPI TTY AT-command emulator
*
* based on the AT-command emulator of the isdn4linux
* kernel subsystem.
*
* Copyright 2000 by Armin Schindler (mac@melware.de)
*
* 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, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: pty.h,v $
* Revision 1.1 2000/08/30 18:27:01 armin
* Okay, here is the first try for an user-land
* ttyI daemon. Compilable but not useable.
*
*
*/
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/file.h>
extern int get_pty(int *master_fdp, char *slave_name);
extern int create_devicelink(char *old, char *new);

253
ttyId/ttyId.h Normal file
View File

@ -0,0 +1,253 @@
/* $Id: ttyId.h,v 1.1 2000/08/30 18:27:01 armin Exp $
*
* ttyId - CAPI TTY AT-command emulator
*
* based on the AT-command emulator of the isdn4linux
* kernel subsystem.
*
* Copyright 2000 by Armin Schindler (mac@melware.de)
*
* 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, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: ttyId.h,v $
* Revision 1.1 2000/08/30 18:27:01 armin
* Okay, here is the first try for an user-land
* ttyI daemon. Compilable but not useable.
*
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <string.h>
#include <time.h>
#include <signal.h>
#include <fcntl.h>
#include <ctype.h>
#include <termios.h>
#include <unistd.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/serial_reg.h>
#define ETX 0x03
#define DLE 0x10
#define XON 0x11
#define DC2 0x12
#define XOFF 0x13
#define DC4 0x14
/*
* Definition of some special Registers of AT-Emulator
*/
#define REG_RINGATA 0
#define REG_RINGCNT 1 /* ring counter register */
#define REG_ESC 2
#define REG_CR 3
#define REG_LF 4
#define REG_BS 5
#define REG_WAITC 7
#define REG_RESP 12 /* show response messages register */
#define BIT_RESP 1 /* show response messages bit */
#define REG_RESPNUM 12 /* show numeric responses register */
#define BIT_RESPNUM 2 /* show numeric responses bit */
#define REG_ECHO 12
#define BIT_ECHO 4
#define REG_DCD 12
#define BIT_DCD 8
#define REG_CTS 12
#define BIT_CTS 16
#define REG_DTRR 12
#define BIT_DTRR 32
#define REG_DSR 12
#define BIT_DSR 64
#define REG_CPPP 12
#define BIT_CPPP 128
#define REG_DXMT 13
#define BIT_DXMT 1
#define REG_T70 13
#define BIT_T70 2
#define BIT_T70_EXT 32
#define REG_DTRHUP 13
#define BIT_DTRHUP 4
#define REG_RESPXT 13
#define BIT_RESPXT 8
#define REG_CIDONCE 13
#define BIT_CIDONCE 16
#define REG_RUNG 13 /* show RUNG message register */
#define BIT_RUNG 64 /* show RUNG message bit */
#define REG_DISPLAY 13
#define BIT_DISPLAY 128
#define REG_L2PROT 14
#define REG_L3PROT 15
#define REG_PSIZE 16
#define REG_WSIZE 17
#define REG_SI1 18
#define REG_SI2 19
#define REG_SI1I 20
#define REG_PLAN 21
#define REG_SCREEN 22
#define REG_CPN 23
#define BIT_CPN 1
#define BIT_CPNFCON 2
/* defines for result codes */
#define RESULT_OK 0
#define RESULT_CONNECT 1
#define RESULT_RING 2
#define RESULT_NO_CARRIER 3
#define RESULT_ERROR 4
#define RESULT_CONNECT64000 5
#define RESULT_NO_DIALTONE 6
#define RESULT_BUSY 7
#define RESULT_NO_ANSWER 8
#define RESULT_RINGING 9
#define RESULT_NO_MSN_EAZ 10
#define RESULT_VCON 11
#define RESULT_RUNG 12
/*
* Values for Layer-2-protocol-selection
*/
#define ISDN_PROTO_L2_X75I 0 /* X75/LAPB with I-Frames */
#define ISDN_PROTO_L2_X75UI 1 /* X75/LAPB with UI-Frames */
#define ISDN_PROTO_L2_X75BUI 2 /* X75/LAPB with UI-Frames */
#define ISDN_PROTO_L2_HDLC 3 /* HDLC */
#define ISDN_PROTO_L2_TRANS 4 /* Transparent (Voice) */
#define ISDN_PROTO_L2_X25DTE 5 /* X25/LAPB DTE mode */
#define ISDN_PROTO_L2_X25DCE 6 /* X25/LAPB DCE mode */
#define ISDN_PROTO_L2_V11096 7 /* V.110 bitrate adaption 9600 Baud */
#define ISDN_PROTO_L2_V11019 8 /* V.110 bitrate adaption 19200 Baud */
#define ISDN_PROTO_L2_V11038 9 /* V.110 bitrate adaption 38400 Baud */
#define ISDN_PROTO_L2_MODEM 10 /* Analog Modem on Board */
#define ISDN_PROTO_L2_FAX 11 /* Fax Group 2/3 */
#define ISDN_PROTO_L2_MAX 31 /* Max. 32 Protocols */
/*
* Values for Layer-3-protocol-selection
*/
#define ISDN_PROTO_L3_TRANS 0 /* Transparent */
#define ISDN_PROTO_L3_TRANSDSP 1 /* Transparent with DSP */
#define ISDN_PROTO_L3_FCLASS2 2 /* Fax Group 2/3 CLASS 2 */
#define ISDN_PROTO_L3_FCLASS1 3 /* Fax Group 2/3 CLASS 1 */
#define ISDN_PROTO_L3_MAX 31 /* Max. 32 Protocols */
#define ISDN_MODEM_WINSIZE 8
#define ISDN_MODEM_NUMREG 99 /* Number of Modem-Registers */
#define ISDN_LMSNLEN 255 /* Length of Listen-MSN string */
#define ISDN_CMSGLEN 80 /* Length of CONNECT-Message to add for Modem */
#define ISDN_MSNLEN 32 /* Length of MSN string */
#include "ttyId_fax.h"
/* data of AT-command-interpreter */
typedef struct atemu {
u_char profile[ISDN_MODEM_NUMREG]; /* Modem-Regs. Profile 0 */
u_char mdmreg[ISDN_MODEM_NUMREG]; /* Modem-Registers */
char pmsn[ISDN_MSNLEN]; /* EAZ/MSNs Profile 0 */
char msn[ISDN_MSNLEN]; /* EAZ/MSN */
char plmsn[ISDN_LMSNLEN]; /* Listening MSNs Profile 0 */
char lmsn[ISDN_LMSNLEN]; /* Listening MSNs */
char cpn[ISDN_MSNLEN]; /* CalledPartyNumber on incoming call */
char connmsg[ISDN_CMSGLEN]; /* CONNECT-Msg from HL-Driver */
u_char vpar[10]; /* Voice-parameters */
int lastDLE; /* Flag for voice-coding: DLE seen */
int mdmcmdl; /* Length of Modem-Commandbuffer */
int pluscount; /* Counter for +++ sequence */
int lastplus; /* Timestamp of last + */
int carrierwait; /* Seconds of carrier waiting */
char mdmcmd[255]; /* Modem-Commandbuffer */
unsigned int charge; /* Charge units of current connection */
} atemu;
typedef struct modem_info {
int x_char; /* xon/xoff character */
int mcr; /* Modem control register */
int msr; /* Modem status register */
int lsr; /* Line status register */
int online; /* 1 = B-Channel is up, drop data */
/* 2 = B-Channel is up, deliver d.*/
int dialing; /* Dial in progress or ATA */
int ncarrier; /* Flag: schedule NO CARRIER */
unsigned char OAD[ISDN_MSNLEN];
unsigned char OSA[ISDN_MSNLEN];
unsigned char CPN[ISDN_MSNLEN];
unsigned char CSA[ISDN_MSNLEN];
unsigned char last_cause[8]; /* Last cause message */
unsigned char last_num[ISDN_MSNLEN];
/* Last phone-number */
unsigned char last_l2; /* Last layer-2 protocol */
unsigned char last_si; /* Last service */
unsigned char last_lhup; /* Last hangup local? */
unsigned char last_dir; /* Last direction (in or out) */
int xmit_count; /* # of chars in xmit_buf */
unsigned char *xmit_buf; /* transmit buffer */
int vonline; /* Voice-channel status */
/* Bit 0 = recording */
/* Bit 1 = playback */
/* Bit 2 = playback, DLE-ETX seen */
void *adpcms; /* state for adpcm decompression */
void *adpcmr; /* state for adpcm compression */
void *dtmf_state; /* state for dtmf decoder */
void *silence_state; /* state for silence detection */
struct T30_s fax; /* T30 Fax Group 3 data/interface */
atemu emu; /* AT-emulator data */
struct termios normal_termios; /* For saving termios structs */
} modem_info;
/* Utility-Macros */
#define MIN(a,b) ((a<b)?a:b)
#define MAX(a,b) ((a>b)?a:b)
/* main */
extern int pty_fd;
extern int debug;
extern modem_info info;
/* utils */
extern void logit(int level, char *fmt, ...);
extern void CopyString(char *Destination, char *Source, int Len);
extern int getnum(char **p);
extern void getdial(char *p, char *q,int cnt);
extern void get_msnstr(char *n, char **p);
/* profile */
extern void modem_init(void);
extern void reset_profile(void);
/* emulator */
extern int tty_edit_at(const char *p, int count);
extern void tty_cmd_ATA(void);
extern void modem_reset_regs(int force);
/* communicate */
extern int tty_write(unsigned char *buf, int len);
/* pty */
extern int writepty(unsigned char *buf, int len);

86
ttyId/ttyId_fax.h Normal file
View File

@ -0,0 +1,86 @@
/* $Id: ttyId_fax.h,v 1.1 2000/08/30 18:27:01 armin Exp $
*
* ttyId - CAPI TTY AT-command emulator
*
* based on the AT-command emulator of the isdn4linux
* kernel subsystem.
*
* Copyright 2000 by Armin Schindler (mac@melware.de)
*
* 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, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: ttyId_fax.h,v $
* Revision 1.1 2000/08/30 18:27:01 armin
* Okay, here is the first try for an user-land
* ttyI daemon. Compilable but not useable.
*
*
*/
#define __u8 u_char
#define FAXIDLEN 21
#define ISDN_FAX_PHASE_IDLE 0
#define ISDN_FAX_PHASE_A 1
#define ISDN_FAX_PHASE_B 2
#define ISDN_FAX_PHASE_C 3
#define ISDN_FAX_PHASE_D 4
#define ISDN_FAX_PHASE_E 5
typedef struct T30_s {
/* session parameters */
__u8 resolution __attribute__ ((packed));
__u8 rate __attribute__ ((packed));
__u8 width __attribute__ ((packed));
__u8 length __attribute__ ((packed));
__u8 compression __attribute__ ((packed));
__u8 ecm __attribute__ ((packed));
__u8 binary __attribute__ ((packed));
__u8 scantime __attribute__ ((packed));
__u8 id[FAXIDLEN] __attribute__ ((packed));
/* additional parameters */
__u8 phase __attribute__ ((packed));
__u8 direction __attribute__ ((packed));
__u8 code __attribute__ ((packed));
__u8 badlin __attribute__ ((packed));
__u8 badmul __attribute__ ((packed));
__u8 bor __attribute__ ((packed));
__u8 fet __attribute__ ((packed));
__u8 pollid[FAXIDLEN] __attribute__ ((packed));
__u8 cq __attribute__ ((packed));
__u8 cr __attribute__ ((packed));
__u8 ctcrty __attribute__ ((packed));
__u8 minsp __attribute__ ((packed));
__u8 phcto __attribute__ ((packed));
__u8 rel __attribute__ ((packed));
__u8 nbc __attribute__ ((packed));
/* remote station parameters */
__u8 r_resolution __attribute__ ((packed));
__u8 r_rate __attribute__ ((packed));
__u8 r_width __attribute__ ((packed));
__u8 r_length __attribute__ ((packed));
__u8 r_compression __attribute__ ((packed));
__u8 r_ecm __attribute__ ((packed));
__u8 r_binary __attribute__ ((packed));
__u8 r_scantime __attribute__ ((packed));
__u8 r_id[FAXIDLEN] __attribute__ ((packed));
__u8 r_code __attribute__ ((packed));
} T30_s;

117
ttyId/utils.c Normal file
View File

@ -0,0 +1,117 @@
/* $Id: utils.c,v 1.1 2000/08/30 18:27:01 armin Exp $
*
* ttyId - CAPI TTY AT-command emulator
*
* based on the AT-command emulator of the isdn4linux
* kernel subsystem.
*
* Copyright 2000 by Armin Schindler (mac@melware.de)
*
* 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, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: utils.c,v $
* Revision 1.1 2000/08/30 18:27:01 armin
* Okay, here is the first try for an user-land
* ttyI daemon. Compilable but not useable.
*
*
*/
#include <stdarg.h>
#include "ttyId.h"
void
logit(int level, char *fmt, ...)
{
va_list pvar;
char buf[1024];
if ((level == LOG_DEBUG) && (!debug))
return;
#if defined(__STDC__)
va_start(pvar, fmt);
#else
char *fmt;
va_start(pvar);
fmt = va_arg(pvar, char *);
#endif
vsprintf(buf, fmt, pvar);
syslog(level, "%s", buf);
va_end(pvar);
}
void CopyString(char *Destination, char *Source, int Len)
{
strncpy(Destination, Source, Len);
Destination[Len] = 0;
}
/*
* Get integer from char-pointer, set pointer to end of number
*/
int
getnum(char **p)
{
int v = -1;
while (*p[0] >= '0' && *p[0] <= '9')
v = ((v < 0) ? 0 : (v * 10)) + (int) ((*p[0]++) - '0');
return v;
}
/*
* Get phone-number from modem-commandbuffer
*/
void
getdial(char *p, char *q,int cnt)
{
int first = 1;
int limit = ISDN_MSNLEN - 1; /* MUST match the size of interface var to avoid
buffer overflow */
while (strchr(" 0123456789,#.*WPTS-", *p) && *p && --cnt>0) {
if ((*p >= '0' && *p <= '9') || ((*p == 'S') && first) ||
(*p == '*') || (*p == '#')) {
*q++ = *p;
limit--;
}
if(!limit)
break;
p++;
first = 0;
}
*q = 0;
}
/*
* Get MSN-string from char-pointer, set pointer to end of number
*/
void
get_msnstr(char *n, char **p)
{
int limit = ISDN_MSNLEN - 1;
while (((*p[0] >= '0' && *p[0] <= '9') ||
/* Why a comma ??? */
(*p[0] == ',')) &&
(limit--))
*n++ = *p[0]++;
*n = '\0';
}