update analog

git-svn-id: http://svn.openzap.org/svn/openzap/trunk@273 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
Anthony Minessale 2007-06-18 21:32:56 +00:00
parent 93b8880e1e
commit 441b487329
7 changed files with 131 additions and 27 deletions

View File

@ -386,6 +386,7 @@ struct zap_span {
zio_event_cb_t event_callback;
zap_mutex_t *mutex;
zap_trunk_type_t trunk_type;
zap_analog_start_type_t start_type;
zap_signal_type_t signal_type;
struct zap_isdn_data *isdn_data;
struct zap_analog_data *analog_data;

View File

@ -119,6 +119,15 @@ typedef enum {
#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "FXO", "FXS", "NONE"
ZAP_STR2ENUM_P(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t)
typedef enum {
ZAP_ANALOG_START_KEWL,
ZAP_ANALOG_START_LOOP,
ZAP_ANALOG_START_GROUND,
ZAP_ANALOG_START_INVALID
} zap_analog_start_type_t;
#define START_TYPE_STRINGS "KEWL", "LOOP", "GROUND", "INVALID"
ZAP_STR2ENUM_P(zap_str2zap_analog_start_type, zap_analog_start_type2str, zap_analog_start_type_t)
typedef enum {
ZAP_OOB_DTMF,
ZAP_OOB_ONHOOK,

View File

@ -110,26 +110,26 @@ struct zt_maintinfo {
int span_no; /* span number */
int command; /* Maintenance mode to set (from zt_maintenance_mode_t) */
};
struct zt_lineconfig {
/* Used in ZT_SPANCONFIG */
int span; /* Which span number (0 to use name) */
char name[20]; /* Name of span to use */
int lbo; /* line build-outs */
int lineconfig; /* line config parameters (framing, coding) */
int sync; /* what level of sync source we are */
}
struct zt_chanconfig {
/* Used in ZT_CHANCONFIG */
int chan; /* Channel we're applying this to (0 to use name) */
char name[40]; /* Name of channel to use */
int sigtype; /* Signal type */
int deflaw; /* Default law (ZT_LAW_DEFAULT, ZT_LAW_MULAW, or ZT_LAW_ALAW */
int master; /* Master channel if sigtype is ZT_SLAVE */
int idlebits; /* Idle bits (if this is a CAS channel) or channel to monitor (if this is DACS channel) */
char netdev_name[16]; /* name for the hdlc network device */
}
struct zt_lineconfig {
/* Used in ZT_SPANCONFIG */
int span; /* Which span number (0 to use name) */
char name[20]; /* Name of span to use */
int lbo; /* line build-outs */
int lineconfig; /* line config parameters (framing, coding) */
int sync; /* what level of sync source we are */
};
struct zt_chanconfig {
/* Used in ZT_CHANCONFIG */
int chan; /* Channel we're applying this to (0 to use name) */
char name[40]; /* Name of channel to use */
int sigtype; /* Signal type */
int deflaw; /* Default law (ZT_LAW_DEFAULT, ZT_LAW_MULAW, or ZT_LAW_ALAW */
int master; /* Master channel if sigtype is ZT_SLAVE */
int idlebits; /* Idle bits (if this is a CAS channel) or channel to monitor (if this is DACS channel) */
char netdev_name[16]; /* name for the hdlc network device */
};
/* Enumerations */
@ -238,7 +238,8 @@ ZT_SIG_EM = (1 << 6) /* E&M */
#define ZT_GETGAINS _IOWR (ZT_CODE, 16, struct zt_gains) /* Get Channel audio gains */
#define ZT_SETGAINS _IOWR (ZT_CODE, 17, struct zt_gains) /* Set Channel audio gains */
#define ZT_SPANCONFIG _IOW (ZT_CODE, 18, struct zt_lineconfig) /*Set Line (T1) Configurations and start system */
#define ZT_CHANCONFIG _IOW (ZT_CODE, 19, struct zt_chanconfig) /* Set Channel Configuration */
#define ZT_AUDIOMODE _IOW (ZT_CODE, 32, int) /* Set a clear channel into audio mode */
#define ZT_ECHOCANCEL _IOW (ZT_CODE, 33, int) /* Control Echo Canceller */
#define ZT_HDLCRAWMODE _IOW (ZT_CODE, 36, int) /* Set a clear channel into HDLC w/out FCS checking/calculation mode */

View File

@ -44,6 +44,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj);
static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxo_outgoing_call)
{
if (!zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) {
//zap_channel_command(zchan, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul");
zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL);
zap_channel_command(zchan, ZAP_COMMAND_ENABLE_PROGRESS_DETECT, NULL);
zchan->needed_tones[ZAP_TONEMAP_DIAL] = 1;
@ -424,7 +425,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
case ZAP_CHANNEL_STATE_GENRING:
{
send_caller_id(chan);
//zap_channel_command(chan, ZAP_COMMAND_TRACE_OUTPUT, "/tmp/outbound.ul");
zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_ON, NULL);
}
break;

View File

@ -95,6 +95,9 @@ ZAP_STR2ENUM(zap_str2zap_oob_event, zap_oob_event2str, zap_oob_event_t, OOB_NAME
ZAP_ENUM_NAMES(TRUNK_TYPE_NAMES, TRUNK_STRINGS)
ZAP_STR2ENUM(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t, TRUNK_TYPE_NAMES, ZAP_TRUNK_NONE)
ZAP_ENUM_NAMES(START_TYPE_NAMES, START_TYPE_STRINGS)
ZAP_STR2ENUM(zap_str2zap_analog_start_type, zap_analog_start_type2str, zap_analog_start_type_t, START_TYPE_NAMES, ZAP_ANALOG_START_INVALID)
ZAP_ENUM_NAMES(SIGNAL_NAMES, SIGNAL_STRINGS)
ZAP_STR2ENUM(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t, SIGNAL_NAMES, ZAP_SIGEVENT_INVALID)
@ -1719,10 +1722,23 @@ static zap_status_t load_config(void)
} else {
zap_copy_string(number, val, sizeof(number));
}
} else if (!strcasecmp(var, "fxo-channel")) {
} else if (!strncasecmp(var, "fxo-channel", 11)) {
if (span->trunk_type == ZAP_TRUNK_NONE) {
span->trunk_type = ZAP_TRUNK_FXO;
zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type));
char *stype = var + 11;
zap_analog_start_type_t tmp, start_type = ZAP_ANALOG_START_KEWL;
span->trunk_type = ZAP_TRUNK_FXO;
if (stype) {
while(*stype == '-') stype++;
if ((tmp = zap_str2zap_analog_start_type(stype)) != ZAP_ANALOG_START_INVALID) {
start_type = tmp;
}
}
span->start_type = start_type;
zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s' (%s)\n", zap_trunk_type2str(span->trunk_type),
zap_analog_start_type2str(start_type));
}
if (span->trunk_type == ZAP_TRUNK_FXO) {
configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXO, name, number);
@ -1731,8 +1747,21 @@ static zap_status_t load_config(void)
}
} else if (!strcasecmp(var, "fxs-channel")) {
if (span->trunk_type == ZAP_TRUNK_NONE) {
span->trunk_type = ZAP_TRUNK_FXS;
zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type));
char *stype = var + 11;
zap_analog_start_type_t tmp, start_type = ZAP_ANALOG_START_KEWL;
span->trunk_type = ZAP_TRUNK_FXS;
if (stype) {
while(*stype == '-') stype++;
if ((tmp = zap_str2zap_analog_start_type(stype)) != ZAP_ANALOG_START_INVALID) {
start_type = tmp;
}
}
span->start_type = start_type;
zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s' (%s)\n", zap_trunk_type2str(span->trunk_type),
zap_analog_start_type2str(start_type));
}
if (span->trunk_type == ZAP_TRUNK_FXS) {
configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXS, name, number);

View File

@ -801,12 +801,14 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event)
break;
case WP_TDMAPI_EVENT_RING_DETECT:
{
printf("you fucking suck: ring\n");
event_id = tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_ring_state & WP_TDMAPI_EVENT_RING_PRESENT ? ZAP_OOB_RING_START : ZAP_OOB_RING_STOP;
}
break;
case WP_TDMAPI_EVENT_RING_TRIP_DETECT:
{
printf("you fucking suck: trip\n");
event_id = tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_ring_state & WP_TDMAPI_EVENT_RING_PRESENT ? ZAP_OOB_ONHOOK : ZAP_OOB_OFFHOOK;
}

View File

@ -48,8 +48,16 @@ static struct {
static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, zap_chan_type_t type, char *name, char *number)
{
unsigned configured = 0, x;
const char ctlpath[] = "/dev/zap/ctl";
char path[128] = "";
zt_params_t ztp;
zap_socket_t ctlfd = ZT_INVALID_SOCKET;
if ((ctlfd = open(ctlpath, O_RDWR)) < 0) {
zap_log(ZAP_LOG_ERROR, "Cannot open control device\n");
return 0;
}
memset(&ztp, 0, sizeof(ztp));
@ -62,6 +70,56 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za
sockfd = open(path, O_RDWR);
if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) {
if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) {
struct zt_chanconfig cc;
memset(&cc, 0, sizeof(cc));
cc.chan = cc.master = x;
switch(type) {
case ZAP_CHAN_TYPE_FXS:
{
switch(span->start_type) {
case ZAP_ANALOG_START_KEWL:
cc.sigtype = ZT_SIG_FXOKS;
break;
case ZAP_ANALOG_START_LOOP:
cc.sigtype = ZT_SIG_FXOLS;
break;
case ZAP_ANALOG_START_GROUND:
cc.sigtype = ZT_SIG_FXOGS;
break;
default:
break;
}
}
break;
case ZAP_CHAN_TYPE_FXO:
{
switch(span->start_type) {
case ZAP_ANALOG_START_KEWL:
cc.sigtype = ZT_SIG_FXSKS;
break;
case ZAP_ANALOG_START_LOOP:
cc.sigtype = ZT_SIG_FXSLS;
break;
case ZAP_ANALOG_START_GROUND:
cc.sigtype = ZT_SIG_FXSGS;
break;
default:
break;
}
}
break;
default:
break;
}
if (ioctl(ctlfd, ZT_CHANCONFIG, &cc)) {
zap_log(ZAP_LOG_INFO, "failure configuring device %s chan %d fd %d (%s)\n",
path, x, ctlfd, strerror(errno));
close(sockfd);
break;
}
}
len = zt_globals.eclevel;
if (ioctl(chan->sockfd, ZT_ECHOCANCEL, &len)) {
zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n",
@ -92,6 +150,8 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za
}
zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd);
chan->rate = 8000;
chan->physical_span_id = ztp.span_no;
chan->physical_chan_id = ztp.chan_no;
@ -125,6 +185,8 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za
}
}
close(ctlfd);
return configured;
}