little progess

This commit is contained in:
Martin Bachem 2006-05-18 19:01:22 +00:00
parent 3225869f02
commit 25c870554f
12 changed files with 542 additions and 301 deletions

View File

@ -106,6 +106,9 @@
/* Define if your <locale.h> file defines LC_MESSAGES. */
#undef HAVE_LC_MESSAGES
/* Define to 1 if you have the `capi20' library (-lcapi20). */
#undef HAVE_LIBCAPI20
/* Define to 1 if you have the `m' library (-lm). */
#undef HAVE_LIBM

6
ant-phone/configure vendored
View File

@ -1634,7 +1634,7 @@ fi
# Define the identity of the package.
PACKAGE=ant-phone
VERSION="0.1.12c"
VERSION="0.1.12-capiconn"
# Some tools Automake needs.
@ -3497,10 +3497,6 @@ _ACEOF
LIBS="-lcapi20 $LIBS"
else
{ { echo "$as_me:$LINENO: error: You need the capi20 headers to build this package" >&5
echo "$as_me: error: You need the capi20 headers to build this package" >&2;}
{ (exit 1); exit 1; }; }
fi

View File

@ -1,6 +1,6 @@
# Process this file with autoconf to produce a configure script.
AC_INIT(ant-phone)
AM_INIT_AUTOMAKE(ant-phone, "0.1.12c", ant-phone-devel@nongnu.org)
AM_INIT_AUTOMAKE(ant-phone, "0.1.12-capiconn", ant-phone-devel@nongnu.org)
AC_PREREQ(2.53)
AC_CONFIG_SRCDIR([config.h.in])
AM_CONFIG_HEADER([config.h])
@ -20,7 +20,7 @@ AC_PROG_YACC
# Checks for libraries.
AC_CHECK_LIB([m], [floor])
AC_CHECK_LIB([sndfile], [sf_open],, AC_MSG_ERROR(You need the libsndfile headers to build this package))
AC_CHECK_LIB([capi20], [capi20_register],, AC_MSG_ERROR(You need the capi20 headers to build this package))
AC_CHECK_LIB([capi20], [capi20_register])
# Checks for header files.
AC_HEADER_STDC

View File

@ -27,9 +27,9 @@ ant_phone_SOURCES = \
server.c \
client.c \
recording.c \
isdntree.c \
isdn_capi.c \
capiconn.c
isdntree.c
ant_phone_SOURCES += isdn_capi.c capiconn.c
noinst_HEADERS = \
callerid.h \
@ -51,9 +51,9 @@ noinst_HEADERS = \
globals.h \
gettext.h \
isdnlexer.h \
isdntree.h \
isdn_capi.h \
capiconn.h
isdntree.h
noinst_HEADERS += isdn_capi.h capiconn.h
EXTRA_DIST = \
pickup.xpm \

View File

@ -39,8 +39,7 @@ host_triplet = @host@
bin_PROGRAMS = ant-phone$(EXEEXT)
DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in calleridlexer.c calleridparser.c \
calleridparser.h isdnlexer.c isdnparser.c isdnparser.h \
isdn_capi.c isdn_capi.h capiconn.c capiconn.h
calleridparser.h isdnlexer.c isdnparser.c isdnparser.h
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
@ -198,56 +197,15 @@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
ant_phone_SOURCES = \
ant-phone.c \
callerid.c \
g711.c \
gtk.c \
isdn.c \
llcheck.c \
mediation.c \
session.c \
sound.c \
util.c \
settings.c \
calleridlexer.l \
calleridparser.y \
isdnlexer.l \
isdnparser.y \
gtksettings.c \
controlpad.c \
fxgenerator.c \
server.c \
client.c \
recording.c \
isdntree.c \
isdn_capi.c \
capiconn.c
noinst_HEADERS = \
callerid.h \
g711.h \
gtk.h \
isdn.h \
llcheck.h \
mediation.h \
session.h \
sound.h \
util.h \
settings.h \
gtksettings.h \
controlpad.h \
fxgenerator.h \
server.h \
client.h \
recording.h \
globals.h \
gettext.h \
isdnlexer.h \
isdntree.h \
isdn_capi.h \
capiconn.h
ant_phone_SOURCES = ant-phone.c callerid.c g711.c gtk.c isdn.c \
llcheck.c mediation.c session.c sound.c util.c settings.c \
calleridlexer.l calleridparser.y isdnlexer.l isdnparser.y \
gtksettings.c controlpad.c fxgenerator.c server.c client.c \
recording.c isdntree.c isdn_capi.c capiconn.c
noinst_HEADERS = callerid.h g711.h gtk.h isdn.h llcheck.h mediation.h \
session.h sound.h util.h settings.h gtksettings.h controlpad.h \
fxgenerator.h server.h client.h recording.h globals.h \
gettext.h isdnlexer.h isdntree.h isdn_capi.h capiconn.h
EXTRA_DIST = \
pickup.xpm \
hangup.xpm \
@ -353,6 +311,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/callerid.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/calleridlexer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/calleridparser.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/capiconn.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/client.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/controlpad.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fxgenerator.Po@am__quote@
@ -360,6 +319,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gtk.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gtksettings.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isdn.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isdn_capi.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isdnlexer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isdnparser.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isdntree.Po@am__quote@
@ -371,8 +331,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/settings.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sound.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/util.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isdn_capi.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/capiconn.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \

View File

@ -115,7 +115,9 @@ int main(int argc, char *argv[]) {
char *audio_device_name_out = "";
char *msn = "";
char *msns = "";
#ifdef HAVE_LIBCAPI20
unsigned int interface=0; // 0=HiSax (ttyIx), 1..2 = capi20 controller num
#endif
int gtk_result;
@ -187,13 +189,16 @@ Options:\n\
default: 0\n\
-l, --msns=MSNS MSNs to listen on, semicolon-separated list or '*'\n\
default: *\n\
-c, --call=NUMBER Call specified number\n\
\n\
-c, --call=NUMBER Call specified number\n"), argv[0]);
#ifdef HAVE_LIBCAPI20
printf ("\n\
-f, --interface=X 0=HiSax, [1..9]=capi20 controller num\n\
default: 0\n\
\n\
default: 0\n");
#endif
printf ("\n\
Note: If arguments of --soundin and --soundout are equal, a full duplex\n\
sound device is needed.\n"), argv[0]);
sound device is needed.\n");
exit(0);
case 'v': /* version */
printf("ANT " VERSION "\n");
@ -231,6 +236,7 @@ Note: If arguments of --soundin and --soundout are equal, a full duplex\n\
}
exit(0);
break;
#ifdef HAVE_LIBCAPI20
case 'f':
if (optarg) {
interface = strtol(optarg, NULL, 0);
@ -238,6 +244,7 @@ Note: If arguments of --soundin and --soundout are equal, a full duplex\n\
interface = 0;
}
break;
#endif
case '?':
exit(1);
}
@ -247,7 +254,12 @@ Note: If arguments of --soundin and --soundout are equal, a full duplex\n\
output_codeset_set("UTF-8"); /* GTK needs UTF-8 strings */
if (session_init(&session, audio_device_name_in, audio_device_name_out,
msn, msns, interface))
msn, msns
#ifdef HAVE_LIBCAPI20
, interface))
#else
))
#endif
{
fprintf(stderr, "Error at session init.\n");
exit(1);

View File

@ -59,6 +59,13 @@
* Plugin for pppd to support PPP over CAPI2.0.
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /* HAVE_CONFIG_H */
#ifdef HAVE_LIBCAPI20
#include <string.h>
#include "capiconn.h"
@ -2102,3 +2109,5 @@ capiconn_listenstate(capiconn_context *ctx, unsigned contr)
return CAPICONN_WRONG_STATE;
return CAPICONN_OK;
}
#endif HAVE_LIBCAPI20

View File

@ -37,7 +37,9 @@
#include <gdk/gdkkeysyms.h>
/* capi support */
#ifdef HAVE_LIBCAPI20
#include "isdn_capi.h"
#endif
/* own header files */
#include "globals.h"
@ -168,9 +170,13 @@ gint timeout_callback(gpointer data) {
free(timediff);
}
#ifdef HAVE_LIBCAPI20
/* use periodic timer to handle CAPI messages */
if (session->capi_contr)
if (session->capi_contr) {
printf ("capi messages\n");
ant_capi_messages(session);
}
#endif
return TRUE; /* call it again */
}

View File

@ -1,64 +1,81 @@
/* $Id$
*
* This file is part of ANT (Ant is Not a Telephone)
*
* Authors:
* - Martin Bachem, m.bachem@gmx.de
* - heavy capitalized on: isdn4k-utils/[pppdcapiplugin,capiiinfo]
*
/* $Id$
*
* This file is part of ANT (Ant is Not a Telephone)
*
* Authors:
* - Martin Bachem, m.bachem@gmx.de
*
* heavy capitalized on:
* + isdn4k-utils/[pppdcapiplugin,capiiinfo]
* + capiconn samples capiintest/capiouttest
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*/
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <malloc.h>
#include <capi20.h>
#include <linux/capi.h>
#include <unistd.h>
#include <stddef.h>
#include "session.h"
#include "globals.h"
#include "isdn_capi.h"
#include "capiconn.h"
static char msgbuf[4096];
static void
ant_capi_incoming(capi_connection *cp,
unsigned contr,
unsigned cipvalue,
char *callednumber,
char *callingnumber)
{
printf ("ant_capi_incoming\n");
}
static void
ant_capi_connected(capi_connection *cp, _cstruct NCPI)
{
printf ("JEHOVA: ant_capi_connected\n");
}
static void
ant_capi_disconnected(capi_connection *cp,
int localdisconnect,
unsigned reason,
unsigned reason_b3)
{
printf ("ant_capi_disconnected\n");
}
static char *ant_capi_conninfo(capi_connection *p)
* (at your option) any later version.
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /* HAVE_CONFIG_H */
#ifdef HAVE_LIBCAPI20
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <malloc.h>
#include <capi20.h>
#include <linux/capi.h>
#include <unistd.h>
#include <stddef.h>
#include "globals.h"
#include "callerid.h"
#include "session.h"
#include "isdn_capi.h"
#include "capiconn.h"
static char msgbuf[4096];
/* callback for capiconn, TODO: don't use global session */
static void
ant_capi_incoming(capi_connection * cp, unsigned contr,
unsigned cipvalue, char *callednumber,
char *callingnumber)
{
switch (session.state) {
case STATE_READY:
/* caller id update */
session.ring_time = time(NULL);
/* save callee's number */
free(session.to);
session.to = strdup(callednumber);
cid_add_line(&session, CALL_IN, NULL, session.to);
/* save caller's number */
free(session.from);
session.from = strdup(callingnumber);
cid_set_from(&session, session.from);
if (session_set_state(&session, STATE_RINGING))
session_set_state(&session,
STATE_RINGING_QUIET);
session.cipvalue = cipvalue;
session.cp = cp;
break;
default:
if (debug)
printf
("ERROR: incoming call at state %i\n",
session.state);
}
}
static char *
ant_capi_conninfo(capi_connection * p)
{
static char buf[1024];
capi_conninfo *cp = capiconn_getinfo(p);
@ -66,196 +83,382 @@ static char *ant_capi_conninfo(capi_connection *p)
char *callednumber = "";
if (cp->callingnumber && cp->callingnumber[0] > 2)
callingnumber = cp->callingnumber+3;
callingnumber = cp->callingnumber + 3;
if (cp->callednumber && cp->callednumber[0] > 1)
callednumber = cp->callednumber+2;
callednumber = cp->callednumber + 2;
if (debug) {
snprintf(buf, sizeof(buf),
"\"%s\" -> \"%s\" %s (pcli=0x%x/ncci=0x%x)",
callingnumber, callednumber,
cp->isincoming ? "incoming" : "outgoing",
cp->plci, cp->ncci
);
"\"%s\" -> \"%s\" %s (pcli=0x%x/ncci=0x%x)",
callingnumber, callednumber,
cp->isincoming ? "incoming" : "outgoing",
cp->plci, cp->ncci);
} else {
snprintf(buf, sizeof(buf),
"\"%s\" -> \"%s\" %s",
callingnumber, callednumber,
cp->isincoming ? "incoming" : "outgoing");
"\"%s\" -> \"%s\" %s",
callingnumber, callednumber,
cp->isincoming ? "incoming" : "outgoing");
}
buf[sizeof(buf)-1] = 0;
buf[sizeof(buf) - 1] = 0;
return buf;
}
static void
ant_capi_chargeinfo(capi_connection *cp, unsigned long charge, int inunits)
{
if (debug) {
if (inunits) {
printf ("%s: charge in units: %ul", ant_capi_conninfo(cp), charge);
} else {
printf ("%s: charge in currency: %ul", ant_capi_conninfo(cp), charge);
}
}
}
static int
ant_capi_put_message(unsigned appid, unsigned char *msg)
{
unsigned err;
err = capi20_put_message (appid, msg);
if (err && debug) {
fprintf(stderr, "putmessage(appid=%d) - %s 0x%x",
appid, capi_info2str(err), err);
}
return 0;
}
static void
}
#define OUTSIZE 128
static int senddata(capi_connection *cp)
{
char *data;
data = (char *)malloc(OUTSIZE);
if (!data) {
printf ("ERROR: malloc failed\n");
return -1;
}
if (capiconn_send(cp, data, OUTSIZE) == CAPICONN_OK) {
return 0;
}
free(data);
return -1;
}
/* callback for capiconn, TODO: don't use global session */
static void
ant_capi_connected(capi_connection * cp, _cstruct NCPI)
{
capi_conninfo *p = capiconn_getinfo(cp);
printf ("connected(%s) NCPIlen=%d\n", ant_capi_conninfo(cp), NCPI[0]);
session.vcon_time = time(NULL); /* for caller id monitor */
cid_set_date(&session, session.vcon_time);
session_set_state(&session, STATE_CONVERSATION);
if (p->b1proto == 1 && p->b2proto == 1 && p->b3proto == 0) {
printf ("enabling DTMF\n");
(void)capiconn_dtmf_setstate(cp, 1);
}
// senddata(cp);
}
/* callback for capiconn, TODO: don't use global session */
static void
ant_capi_disconnected(capi_connection * cp, int localdisconnect,
unsigned reason, unsigned reason_b3)
{
switch (session.state) {
case STATE_RINGING:
case STATE_RINGING_QUIET:
/* caller giving up */
session_set_state(&session, STATE_READY);
cid_set_duration(&session, _("(RUNG)"));
cid_mark_row(&session, session.cid_num - 1, TRUE);
break;
default:
if (debug)
printf
("ERROR: got disconnect at state %i\n",
session.state);
}
}
/* callback for GTK widget */
int
ant_capi_pickup(session_t * session)
{
switch (session->state) {
case STATE_RINGING:
case STATE_RINGING_QUIET:
switch (session->cipvalue) {
case 1: /* Speech */
case 4: /* 3.1 KHz audio */
case 5: /* 7 KHz audio */
case 16: /* Telephony */
case 26: /* 7kHz telephony */
(void)capiconn_accept(session->cp, 1, 1, 0, 0, 0, 0, 0);
break;
case 2: /* unrestricted digital information */
case 3: /* restricted digital infomation */
/* HDLC: 0,1,0 X75: 0,0,0 X75+V42Bis: 0,8,0 */
/* x25overx75: 0,0,2 */
(void)capiconn_accept(session->cp, 0, 1, 0, 0, 0, 0, 0);
/*(void)capiconn_accept(cp, 0, 0, 2, 0, 0, 0, 0);*/
break;
case 17: /* Group 2/3 facsimile */
(void)capiconn_accept(session->cp, 4, 4, 4, 0, 0, 0, 0);
break;
default:
(void)capiconn_ignore(session->cp);
break;
}
break;
default:
if (debug)
printf
("ERROR: got disconnect at state %i\n",
session->state);
}
}
/* callback for GTK widget */
int
ant_capi_hangup(session_t * session)
{
switch (session->state) {
/* abort dialing */
case STATE_DIALING:
break;
/* reject call */
case STATE_RINGING:
case STATE_RINGING_QUIET:
session_set_state(session, STATE_READY);
cid_set_duration(session, _("(REJECTED)"));
(void) capiconn_reject(session->cp);
break;
/* hang up (while b-channel is open) */
case STATE_CONVERSATION:
(void)capiconn_disconnect(session->cp, 0);
session_deinit_conversation(session, 1); /* 1 == we hang up ourselves ;) */
session_set_state(session, STATE_READY);
cid_set_duration(session, NULL);
break;
default:
if (debug)
printf
("ERROR: got disconnect at state %i\n",
session->state);
}
}
static void
ant_capi_chargeinfo(capi_connection * cp, unsigned long charge,
int inunits)
{
if (debug) {
if (inunits) {
printf("%s: charge in units: %ul",
ant_capi_conninfo(cp), charge);
} else {
printf("%s: charge in currency: %ul",
ant_capi_conninfo(cp), charge);
}
}
}
static int
ant_capi_put_message(unsigned appid, unsigned char *msg)
{
unsigned err;
err = capi20_put_message(appid, msg);
if (err && debug) {
fprintf(stderr, "putmessage(appid=%d) - %s 0x%x", appid,
capi_info2str(err), err);
}
return 0;
}
static void
ant_capi_msg(const char *prefix, const char *format, va_list args)
{
char *s = msgbuf;
char *e = msgbuf + sizeof(msgbuf);
(void)snprintf(s, e-s, "%s", prefix);
(void) snprintf(s, e - s, "%s", prefix);
s += strlen(s);
(void)vsnprintf(s, e-s, format, args);
(void) vsnprintf(s, e - s, format, args);
s += strlen(s);
printf("%s\n", msgbuf);
}
static void
static void
ant_capi_err(const char *format, ...)
{
va_list args;
if (debug) {
if (debug) {
va_start(args, format);
ant_capi_msg("CAPI Error: ", format, args);
va_end(args);
va_end(args);
}
}
static void
}
static void
ant_capi_dbg(const char *format, ...)
{
va_list args;
if (debug > 1) {
va_start(args, format);
ant_capi_msg("CAPI Debug: ", format, args);
va_end(args);
ant_capi_msg("CAPI Debug: ", format, args);
va_end(args);
}
}
static void
static void
ant_capi_info(const char *format, ...)
{
va_list args;
if (debug > 2) {
va_start(args, format);
ant_capi_msg("CAPI Info: ", format, args);
va_end(args);
va_end(args);
}
}
capiconn_callbacks ant_capi_callbacks = {
malloc: malloc,
free: free,
disconnected: ant_capi_disconnected,
incoming: ant_capi_incoming,
connected: ant_capi_connected,
chargeinfo: ant_capi_chargeinfo,
capi_put_message: ant_capi_put_message,
received: 0,
datasent: 0,
dtmf_received: 0,
debugmsg: (void (*)(const char *, ...))ant_capi_dbg,
infomsg: (void (*)(const char *, ...))ant_capi_info,
errmsg: (void (*)(const char *, ...))ant_capi_err
};
int ant_capi_init(session_t *session)
{
int serrno, err;
if (CAPI20_ISINSTALLED() != CapiNoError) {
fprintf(stderr, "CAPI not installed - %s (%d)\n", strerror(errno), errno);
return -2;
}
if ((err = capi20_register (2, 8, 2048, &session->applid)) != 0) {
serrno = errno;
fprintf(stderr, "CAPI_REGISTER failed - %s (0x%04x) [%s (%d)]\n",
capi_info2str(err), err, strerror(serrno), errno);
return(-3);
}
if (capi20ext_set_flags(session->applid, 1) < 0) {
serrno = errno;
(void)capi20_release(session->applid);
fprintf(stderr, "CAPI: failed to set highjacking mode - %s (%d)\n",
strerror(serrno), serrno);
return(-4);
}
if ((session->ctx = capiconn_getcontext(session->applid, &ant_capi_callbacks)) == 0) {
(void)capi20_release(session->applid);
fprintf(stderr, "CAPI: get_context failed\n");
return(-5);
}
if (capiconn_addcontr(session->ctx, session->capi_contr, &session->cinfo) != CAPICONN_OK) {
(void)capiconn_freecontext(session->ctx);
(void)capi20_release(session->applid);
fprintf(stderr, "CAPI: add controller %d failed", session->capi_contr);
return(-1);
static char *conninfo(capi_connection *p)
{
static char buf[1024];
capi_conninfo *cp = capiconn_getinfo(p);
snprintf(buf, sizeof(buf),
"appl=%d plci=0x%x ncci=0x%x %s",
cp->appid,
cp->plci,
cp->ncci,
cp->isincoming ? "incoming" : "outgoing"
);
return buf;
}
static void
ant_capi_rx(capi_connection * cp, unsigned char *data, unsigned datalen)
{
printf ("received(%s): len=%u\n", conninfo(cp), datalen);
}
static void
ant_capi_tx(capi_connection * cp, unsigned char *buf)
{
printf ("sent(%s): %p\n", conninfo(cp), buf);
free(buf);
senddata(cp);
// printf ("sent(%s)\n", conninfo(cp));
}
static void
ant_capi_dtmf_rx(capi_connection * cp,
unsigned char *data, unsigned datalen)
{
ant_capi_info("dtmf_reveived(%s): %ld \"%-*.*s\"",
conninfo(cp), datalen, (int) datalen, (int) datalen, data);
}
capiconn_callbacks ant_capi_callbacks = {
malloc: malloc,
free: free,
disconnected: ant_capi_disconnected,
incoming: ant_capi_incoming,
connected: ant_capi_connected,
chargeinfo: ant_capi_chargeinfo,
/*
received: ant_capi_rx,
datasent: ant_capi_tx,
dtmf_received: ant_capi_dtmf_rx,
*/
received: 0,
datasent: 0,
dtmf_received: 0,
capi_put_message: ant_capi_put_message,
debugmsg: (void (*)(const char *,...)) ant_capi_dbg,
infomsg: (void (*)(const char *,...)) ant_capi_info,
errmsg: (void (*)(const char *,...)) ant_capi_err
};
int
ant_capi_init(session_t * session)
{
int serrno, err;
if (CAPI20_ISINSTALLED() != CapiNoError) {
fprintf(stderr, "CAPI not installed - %s (%d)\n",
strerror(errno), errno);
return -2;
}
return(0);
}
void ant_capi_listen(session_t *session)
{
/*
call
if ((err = capi20_register(2, 8, 2048, &session->applid)) != 0) {
serrno = errno;
fprintf(stderr,
"CAPI_REGISTER failed - %s (0x%04x) [%s (%d)]\n",
capi_info2str(err), err, strerror(serrno), errno);
return (-3);
}
if (capi20ext_set_flags(session->applid, 1) < 0) {
serrno = errno;
(void) capi20_release(session->applid);
fprintf(stderr,
"CAPI: failed to set highjacking mode - %s (%d)\n",
strerror(serrno), serrno);
return (-4);
}
if ((session->ctx =
capiconn_getcontext(session->applid,
&ant_capi_callbacks)) == 0) {
(void) capi20_release(session->applid);
fprintf(stderr, "CAPI: get_context failed\n");
return (-5);
}
session->cinfo.ddi = 0;
session->cinfo.ndigits = 0;
if (capiconn_addcontr
(session->ctx, session->capi_contr,
&session->cinfo) != CAPICONN_OK) {
(void) capiconn_freecontext(session->ctx);
(void) capi20_release(session->applid);
fprintf(stderr, "CAPI: add controller %d failed",
session->capi_contr);
return (-1);
}
return (0);
}
void
ant_capi_listen(session_t * session)
{
/*
call
conn = capiconn_connect(ctx,
session->opt_contr, // contr
session->opt_contr, // contr
1, // cipvalue
number_to_call,
number_to_call,
session->msn,
1, 1, 0,
0, 0, 0, 0, 0);
*/
(void)capiconn_listen(session->ctx, session->capi_contr, 0x1FFF03FF, 0);
}
void ant_capi_free(session_t *session)
{
(void)capiconn_freecontext(session->ctx);
(void)capi20_release(session->applid);
}
/* attention: get called periodically by timer defined TIMER_DELAY in gtk.c,
* so be quick ;)
*/
void ant_capi_messages(session_t *session)
0, 0, 0, 0, 0);
*/
(void) capiconn_listen(session->ctx, session->capi_contr,
0x1FFF03FF, 0);
} void
ant_capi_free(session_t * session)
{
(void) capiconn_freecontext(session->ctx);
(void) capi20_release(session->applid);
}
/* attention: get called periodically by timer defined TIMER_DELAY in gtk.c,
* so be quick ;)
*/
void
ant_capi_messages(session_t * session)
{
unsigned char *msg = 0;
struct timeval tv;
tv.tv_sec = 0;
tv.tv_sec = 0;
tv.tv_usec = 100;
if (capi20_waitformessage(session->applid, &tv) == 0) {
if (capi20_get_message(session->applid, &msg) == 0)
capiconn_inject(session->applid, msg);
}
}
}
#endif /* HAVE_LIBCAPI20 */

View File

@ -19,3 +19,5 @@ int ant_capi_init(session_t *session);
void ant_capi_listen(session_t *session);
void ant_capi_free(session_t *session);
void ant_capi_messages(session_t *session);
int ant_capi_pickup(session_t *session);
int ant_capi_hangup(session_t *session);

View File

@ -47,7 +47,6 @@
#include "session.h"
#include "sound.h"
#include "isdn.h"
#include "isdn_capi.h"
#include "mediation.h"
#include "gtk.h"
#include "util.h"
@ -56,6 +55,9 @@
#include "settings.h"
#include "fxgenerator.h"
#include "server.h"
#ifdef HAVE_LIBCAPI20
#include "isdn_capi.h"
#endif
/*
* This is our session. Currently just one globally.
@ -192,12 +194,15 @@ int session_isdn_init(session_t *session) {
if (debug)
fprintf(stderr, "Initializing ISDN device...\n");
#ifdef HAVE_LIBCAPI20
if (session->capi_contr) {
if (ant_capi_init(session)) {
printf ("CAPI 2.0 initialization failed!\n");
return -1;
}
} else {
} else
#endif
{
if ((session->isdn_fd =
open_isdn_device(&session->isdn_device_name,
&session->isdn_lockfile_name)) < 0) {
@ -222,9 +227,12 @@ int session_isdn_init(session_t *session) {
return -1;
}
#ifdef HAVE_LIBCAPI20
if (session->capi_contr) {
ant_capi_listen(session);
} else {
} else
#endif
{
if (isdn_setMSN(session->isdn_fd, session->msn) ||
isdn_setMSNs(session->isdn_fd, session->msns)) {
fprintf(stderr, "Error setting MSN properties.\n");
@ -324,10 +332,13 @@ int session_isdn_deinit(session_t *session) {
fprintf(stderr, "Closing ISDN device...\n");
/* de-init / restore isdn device */
#ifdef HAVE_LIBCAPI20
if (session->capi_contr) {
ant_capi_free(session);
}
else {
else
#endif
{
if (deinit_isdn_device(session->isdn_fd, &session->isdn_backup)) {
fprintf(stderr, "Error restoring ttyI state.\n");
}
@ -360,8 +371,14 @@ int session_isdn_deinit(session_t *session) {
int session_init(session_t *session,
char *audio_device_name_in,
char *audio_device_name_out,
char *msn, char *msns,
unsigned int interface) {
char *msn, char *msns
#ifdef HAVE_LIBCAPI20
, unsigned int interface)
#else
)
#endif
{
int i;
/*
@ -436,7 +453,9 @@ int session_init(session_t *session,
session->ring_time = 0;
session->unanswered = 0;
#ifdef HAVE_LIBCAPI20
session->capi_contr = interface;
#endif
/* setup audio and isdn */
if (!session->option_release_devices)
@ -521,12 +540,16 @@ void session_io_handlers_start(session_t *session) {
(gpointer) session,
NULL);
}
session->gtk_isdn_input_tag = gtk_input_add_full(session->isdn_fd,
GDK_INPUT_READ,
gtk_handle_isdn_input,
NULL,
(gpointer) session,
NULL);
if (!session->capi_contr) {
session->gtk_isdn_input_tag = gtk_input_add_full(session->isdn_fd,
GDK_INPUT_READ,
gtk_handle_isdn_input,
NULL,
(gpointer) session,
NULL);
}
/* server functionality */
session->gtk_local_input_tag = gtk_input_add_full(session->local_sock,
@ -687,19 +710,24 @@ void session_deinit_conversation(session_t *session, int self_hangup) {
session_io_handlers_stop(session);
session_reset_audio(session);
session_io_handlers_start(session);
if (isdn_blockmode(session->isdn_fd, 0))
fprintf(stderr, "Warning: "
"Switching back to normal isdn tty mode not successful.\n");
/* go back to command mode */
if (isdn_stop_audio(session->isdn_fd, self_hangup)) {
fprintf(stderr, "Error switching back to command mode.\n");
}
/* isdn hangup */
if (isdn_hangup(session->isdn_fd)) {
fprintf(stderr, "Error hanging up.\n");
#ifdef HAVE_LIBCAPI20
if (!(session->capi_contr))
#endif
{
if (isdn_blockmode(session->isdn_fd, 0))
fprintf(stderr, "Warning: "
"Switching back to normal isdn tty mode not successful.\n");
/* go back to command mode */
if (isdn_stop_audio(session->isdn_fd, self_hangup)) {
fprintf(stderr, "Error switching back to command mode.\n");
}
/* isdn hangup */
if (isdn_hangup(session->isdn_fd)) {
fprintf(stderr, "Error hanging up.\n");
}
}
session->isdn_inbuf_len = 0;
@ -1309,6 +1337,13 @@ void gtk_handle_pick_up_button(GtkWidget *widget _U_, gpointer data) {
char *clear_number; /* number after un_vanity() */
int result;
#ifdef HAVE_LIBCAPI20
if (session->capi_contr) {
ant_capi_pickup(session);
return;
}
#endif
switch (session->state) {
case STATE_READY: /* we are in command mode and want to dial */
number = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(session->dial_number_box)
@ -1392,6 +1427,13 @@ void gtk_handle_pick_up_button(GtkWidget *widget _U_, gpointer data) {
void gtk_handle_hang_up_button(GtkWidget *widget _U_, gpointer data) {
session_t *session = (session_t *) data;
#ifdef HAVE_LIBCAPI20
if (session->capi_contr) {
ant_capi_hangup(session);
return;
}
#endif
switch (session->state) {
case STATE_READY: /* we are already in command mode */
break;

View File

@ -36,9 +36,11 @@
#include <gtk/gtk.h>
/* Capi 2.0 */
#ifdef HAVE_LIBCAPI20
#include <linux/capi.h>
#include <capi20.h>
#include "capiconn.h"
#endif
/* own header files */
#include "recording.h"
@ -216,11 +218,15 @@ typedef struct {
char* msn; /* originating msn, allocated memory! */
char* msns; /* comma-separated list of msns to listen on, allocated memory!*/
#ifdef HAVE_LIBCAPI20
/* capi 2.0 control variables */
unsigned char capi_contr; /* 0=HiSax /dev/ttyIx, [1..?]=capi20 controller num */
capiconn_context *ctx;
capi_contrinfo cinfo;
capi_connection *cp;
unsigned cipvalue;
unsigned applid;
#endif
int unanswered; /* unanswered calls for this session */
@ -263,8 +269,12 @@ int session_audio_deinit(session_t *session);
int session_init(session_t *session,
char *audio_device_name_in,
char *audio_device_name_out,
char *msn, char *msns,
unsigned int interface);
char *msn, char *msns
#ifdef HAVE_LIBCAPI20
, unsigned int interface);
#else
);
#endif
void session_audio_free(session_t *session);
int session_deinit(session_t *session);