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;
#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,
int span_no; /* span number */
int command; /* Maintenance mode to set (from zt_maintenance_mode_t) */
};
-\r
-struct zt_lineconfig {\r
-/* Used in ZT_SPANCONFIG */\r
- int span; /* Which span number (0 to use name) */\r
- char name[20]; /* Name of span to use */\r
- int lbo; /* line build-outs */\r
- int lineconfig; /* line config parameters (framing, coding) */\r
- int sync; /* what level of sync source we are */\r
-}\r
-\r
-struct zt_chanconfig {\r
-/* Used in ZT_CHANCONFIG */\r
- int chan; /* Channel we're applying this to (0 to use name) */\r
- char name[40]; /* Name of channel to use */\r
- int sigtype; /* Signal type */\r
- int deflaw; /* Default law (ZT_LAW_DEFAULT, ZT_LAW_MULAW, or ZT_LAW_ALAW */\r
- int master; /* Master channel if sigtype is ZT_SLAVE */\r
- int idlebits; /* Idle bits (if this is a CAS channel) or channel to monitor (if this is DACS channel) */\r
- char netdev_name[16]; /* name for the hdlc network device */\r
-}
+
+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 */
#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 */
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;
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;
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)
} 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);
}
} 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);
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;
}
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));
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",
}
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;
}
}
+ close(ctlfd);
+
return configured;
}