return(0);
}
+ /* default tx_dejitter */
+ bchannel->b_tx_dejitter = 1;
+
/* open socket */
channel->b_sock = socket(PF_ISDN, SOCK_DGRAM, ISDN_P_B_L2DSP);
if (bchannel->b_sock < 0)
/* set dsp features */
if (bchannel->b_txdata)
- ph_control(handle, (bchannel->b_txdata)?CMX_TXDATA_ON:CMX_TXDATA_OFF, 0, "DSP-TXDATA", bchannel->b_txdata);
+ ph_control(handle, (bchannel->b_txdata)?DSP_TXDATA_ON:DSP_TXDATA_OFF, 0, "DSP-TXDATA", bchannel->b_txdata);
if (bchannel->b_delay)
- ph_control(handle, CMX_DELAY, bchannel->b_delay, "DSP-DELAY", bchannel->b_delay);
+ ph_control(handle, DSP_DELAY, bchannel->b_delay, "DSP-DELAY", bchannel->b_delay);
if (bchannel->b_tx_dejitter)
- ph_control(handle, (bchannel->b_tx_dejitter)?CMX_TX_DEJITTER:CMX_TX_DEJ_OFF, 0, "DSP-DELAY", bchannel->b_tx_dejitter);
+ ph_control(handle, (bchannel->b_tx_dejitter)?DSP_TX_DEJITTER:DSP_TX_DEJ_OFF, 0, "DSP-TX_DEJITTER", bchannel->b_tx_dejitter);
if (bchannel->b_tx_gain)
- ph_control(handle, VOL_CHANGE_TX, bchannel->b_tx_gain, "DSP-TX_GAIN", bchannel->b_tx_gain);
+ ph_control(handle, DSP_VOL_CHANGE_TX, bchannel->b_tx_gain, "DSP-TX_GAIN", bchannel->b_tx_gain);
if (bchannel->b_rx_gain)
- ph_control(handle, VOL_CHANGE_RX, bchannel->b_rx_gain, "DSP-RX_GAIN", bchannel->b_rx_gain);
+ ph_control(handle, DSP_VOL_CHANGE_RX, bchannel->b_rx_gain, "DSP-RX_GAIN", bchannel->b_rx_gain);
if (bchannel->b_pipeline[0])
ph_control_block(handle, PIPELINE_CFG, bchannel->b_pipeline, strlen(bchannel->b_pipeline)+1, "DSP-PIPELINE", 0);
if (bchannel->b_conf)
- ph_control(handle, CMX_CONF_JOIN, bchannel->b_conf, "DSP-CONF", bchannel->b_conf);
+ ph_control(handle, DSP_CONF_JOIN, bchannel->b_conf, "DSP-CONF", bchannel->b_conf);
if (bchannel->b_echo)
- ph_control(handle, CMX_ECHO_ON, 0, "DSP-ECHO", 1);
+ ph_control(handle, DSP_ECHO_ON, 0, "DSP-ECHO", 1);
if (bchannel->b_tone)
- ph_control(handle, TONE_PATT_ON, bchannel->b_tone, "DSP-TONE", bchannel->b_tone);
+ ph_control(handle, DSP_TONE_PATT_ON, bchannel->b_tone, "DSP-TONE", bchannel->b_tone);
if (bchannel->b_rxoff)
- ph_control(handle, CMX_RECEIVE_OFF, 0, "DSP-RXOFF", 1);
+ ph_control(handle, DSP_RECEIVE_OFF, 0, "DSP-RXOFF", 1);
// if (bchannel->b_txmix)
-// ph_control(handle, CMX_MIX_ON, 0, "DSP-MIX", 1);
+// ph_control(handle, DSP_MIX_ON, 0, "DSP-MIX", 1);
if (bchannel->b_dtmf)
ph_control(handle, DTMF_TONE_START, 0, "DSP-DTMF", 1);
if (bchannel->b_crypt_len)
- ph_control_block(handle, BF_ENABLE_KEY, bchannel->b_crypt_key, bchannel->b_crypt_len, "DSP-CRYPT", bchannel->b_crypt_len);
+ ph_control_block(handle, DSP_BF_ENABLE_KEY, bchannel->b_crypt_key, bchannel->b_crypt_len, "DSP-CRYPT", bchannel->b_crypt_len);
if (bchannel->b_conf)
- ph_control(handle, CMX_CONF_JOIN, bchannel->b_conf, "DSP-CONF", bchannel->b_conf);
+ ph_control(handle, DSP_CONF_JOIN, bchannel->b_conf, "DSP-CONF", bchannel->b_conf);
bchannel->b_state = BSTATE_ACTIVE;
}
return;
}
- if (bchannel->rx_data)
- bchannel->rx_data(bchannel, data, len);
+ if (!bchannel->call)
+ {
+ PDEBUG("PmISDN(%s) ignoring data, because no call associated with bchannel\n", p_name);
+ return;
+ }
+ len = write(bchannel->call->pipe[1], data, len);
+ if (len < 0)
+ {
+ PDEBUG("PmISDN(%s) broken pipe on bchannel pipe\n", p_name);
+ return;
+ }
}
handle = bchannel->b_addr;
#endif
- if (id)
+ if (id) {
bchannel->b_conf = (id<<16) + bchannel_pid;
- else
+ bchannel->b_rxoff = 1;
+ } else {
bchannel->b_conf = 0;
+ bchannel->b_rxoff = 0;
+ }
if (bchannel->b_state == BSTATE_ACTIVE)
- ph_control(handle, CMX_CONF_JOIN, bchannel->b_conf, "DSP-CONF", bchannel->b_conf);
+ {
+ ph_control(handle, DSP_RX_OFF, bchannel->b_rxoff, "DSP-RX_OFF", bchannel->b_conf);
+ ph_control(handle, DSP_CONF_JOIN, bchannel->b_conf, "DSP-CONF", bchannel->b_conf);
+ }
}
*/
+u_char flip_bits[256];
+
+#warning TODO: bchannel oeffnen und aktivieren (wer macht das?:)
#warning reconnect after socket closed, release all calls.
#warning debug of call handling
#warning ausloesen beim socket-verlust
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
*callp = (struct chan_call *)malloc(sizeof(struct chan_call));
if (*callp)
memset(*callp, 0, sizeof(struct chan_call));
+ if (pipe((*callp)->pipe) < 0) {
+ free_call(*callp);
+ return;
+ }
return(*callp);
}
+
void free_call(struct chan_call *call)
{
struct chan_call **temp = &call_first;
if (*temp == call)
{
*temp = (*temp)->next;
+ if (call->pipe[0])
+ close(call->pipe[0]);
+ if (call->pipe[1])
+ close(call->pipe[1]);
if (call->bchannel)
{
if (call->bchannel->call)
call->bchannel->call = NULL;
+ else
+ warnung
}
if (call->bridge_call)
{
if (call->bridge_call->bridge_call)
call->bridge_call->bridge_call = NULL;
+ else
+ warnung
}
free(call);
return;
/* check bridge */
if (!call) return;
if (!call->bridge_call) return;
- send_message(MESSAGE_RELEASE, call->bridge_call->ref, param);
+ send_message(message_type, call->bridge_call->ref, param);
+}
+
+/*
+ * check if extension matches and start asterisk
+ * if it can match, proceed
+ * if not, release
+ */
+static void lcr_setup_pbx(struct chan_call *call, struct ast_channel *ast, int complete)
+{
+ int cause;
+
+ if (complete)
+ {
+ /* if not match */
+ if (!ast_canmatch_extension(ast, ast->context, call->dad, 1, call->oad))
+ {
+ cause = 1;
+ goto release;
+ if (!ast_exists_extension(ast, ast->context, call->dad, 1, call->oad))
+ {
+ cause = 28;
+ goto release;
+ }
+ /* send setup acknowledge to lcr */
+ memset(&newparam, 0, sizeof(union parameter));
+ send_message(MESSAGE_PROCEEDING, call->ref, &newparam);
+
+ /* change state */
+ call->state = CHAN_LCR_STATE_IN_PROCEEDING;
+
+ goto start;
+ }
+
+ if (ast_canmatch_extension(ast, ast->context, dad, 1, oad))
+ {
+ /* send setup acknowledge to lcr */
+ memset(&newparam, 0, sizeof(union parameter));
+ send_message(MESSAGE_OVERLAP, call->ref, &newparam);
+
+ /* change state */
+ call->state = CHAN_LCR_STATE_IN_DIALING;
+
+ /* if match, start pbx */
+ if (ast_exists_extension(ast, ast->context, dad, 1, oad))
+ goto start;
+
+ /* if can match */
+ return;
+ }
+
+ /* if not match */
+ cause = 1;
+ release:
+ /* release lcr */
+ memset(&newparam, 0, sizeof(union parameter));
+ newparam.disconnectinfo.cause = cause;
+ newparam.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
+ send_message(MESSAGE_RELEASE, call->ref, &newparam);
+ call->ref = 0;
+ /* release asterisk */
+ ast->hangupcause = call->cause;
+ ast_queue_hangup(ast);
+ /* change to release state */
+ call->state = CHAN_LCR_STATE_RELEASE;
+ return;
+
+ start:
+ /* send setup to asterisk */
+ ret = ast_pbx_start(ast);
+ if (ret < 0)
+ {
+ cause = (ret==-2)?34:27;
+ goto release;
+ }
+ call->pbx_started = 1;
+ return;
}
/*
union parameter newparam;
/* create asterisk channel instrance */
-#warning anstatt vom lcr "setup.exten" zu bekommen, sollten wir den context übertragen, der dann in der channel.conf zu dem richtigen ruleset führt.
ast = ast_channel_alloc(1, AST_STATE_RESERVED, NULL, NULL, "", NULL, "", 0, "%s/%d", lcr_type, ++glob_channel);
- if (!call->ast)
+ if (!ast)
{
/* release */
memset(&newparam, 0, sizeof(union parameter));
call->ast = ast;
ast->tech_pvt = call;
ast->tech = &lcr_tech;
+ ast->fds[0] = call->pipe[0];
/* fill setup information */
- if (param->setup.exten[0])
- strncpy(ast->exten, param->setup.exten, AST_MAX_EXTENSION);
+ if (param->setup.dialinginfo.id)
+ strncpy(ast->exten, param->setup.dialinginfo.id, AST_MAX_EXTENSION-1);
+ if (param->setup.context[0])
+ strncpy(ast->context, param->setup.exten, AST_MAX_CONTEXT-1);
if (param->setup.callerinfo.id[0])
ast->cid.cid_num = strdup(param->setup.callerinfo.id);
if (param->setup.callerinfo.name[0])
#warning todo
#if 0
if (param->setup.redirinfo.id[0])
- ast->cid.cid_name = strdup(numberrize_callerinfo(param->setup.callerinfo.name, param->setup.callerinfo.ntype, configfile->prefix_nat, configfile->prefix_inter));
+ ast->cid.cid_name = strdup(numberrize_callerinfo(param->setup.callerinfo.id, param->setup.callerinfo.ntype, configfile->prefix_nat, configfile->prefix_inter));
#endif
switch (param->setup.callerinfo.present)
{
ast->cid.cid_ton = 0;
}
ast->transfercapability = param->setup.capainfo.bearer_capa;
+ strcpy(call->dad, param->setup.dialinginfo.id);
+ strcpy(call->oad, numberrize_callerinfo(param->setup.callerinfo.id, param->setup.callerinfo.ntype, configfile->prefix_nat, configfile->prefix_inter));
/* configure channel */
#warning todo
/* change state */
call->state = CHAN_LCR_STATE_IN_SETUP;
- /* send setup to asterisk */
- ast_pbx_start(ast);
-
- /* send setup acknowledge to lcr */
- memset(&newparam, 0, sizeof(union parameter));
- send_message(MESSAGE_OVERLAP, call->ref, &newparam);
-
- /* change state */
- call->state = CHAN_LCR_STATE_IN_DIALING;
+ lcr_start_pbx(call, ast, param->setup.dialinginfo.complete);
}
/*
/* save cause */
call->cause = param->disconnectinfo.cause;
call->location = param->disconnectinfo.location;
+per option
+
+wenn setup raus geht, pointer
/* if bridge, forward disconnect and return */
if (call->bridge_call)
{
char *p;
if (!call->ast) return;
+
+ /* pbx not started */
+ if (!call->pbx_started)
+ {
+ strncat(ast->exten, param->information.id, AST_MAX_EXTENSION-1);
+ lcr_start_pbx(call, ast, param->information.complete);
+ return;
+ }
/* copy digits */
p = param->information.id;
static void *chan_thread(void *arg)
{
int work;
+ int ret;
ast_mutex_lock(&chan_lock);
work = 0;
/* handle socket */
- int ret = handle_socket();
+ ret = handle_socket();
if (ret < 0)
break;
if (ret)
*/
static int lcr_call(struct ast_channel *ast, char *dest, int timeout)
{
- struct chan_call *call=ast->tech_pvt;
-
- if (!call) return -1;
+ struct chan_call *call;
ast_mutex_lock(&chan_lock);
+ call = ast->tech_pvt;
+ if (!call) {
+ ast_mutex_unlock(&chan_lock);
+ return -1;
+ }
+
#warning hier muss noch
#if 0
static int lcr_digit(struct ast_channel *ast, char digit)
{
- struct chan_call *call = ast->tech_pvt;
+ struct chan_call *call;
union parameter newparam;
char buf[]="x";
- if (!call) return -1;
-
/* only pass IA5 number space */
if (digit > 126 || digit < 32)
return 0;
ast_mutex_lock(&chan_lock);
+ call = ast->tech_pvt;
+ if (!call) {
+ ast_mutex_unlock(&chan_lock);
+ return -1;
+ }
/* send information or queue them */
if (call->ref && call->state == CHAN_LCR_STATE_OUT_DIALING)
static int lcr_answer(struct ast_channel *ast)
{
union parameter newparam;
- struct chan_call *call = ast->tech_pvt;
-
- if (!call) return -1;
+ struct chan_call *call;
ast_mutex_lock(&chan_lock);
-
+ call = ast->tech_pvt;
+ if (!call) {
+ ast_mutex_unlock(&chan_lock);
+ return -1;
+ }
+
/* copy connectinfo, if bridged */
if (call->bridge_call)
memcpy(&call->connectinfo, &call->bridge_call->connectinfo, sizeof(struct connect_info));
static int lcr_hangup(struct ast_channel *ast)
{
union parameter newparam;
- struct chan_call *call = ast->tech_pvt;
-
- if (!call)
- return 0;
+ struct chan_call *call;
ast_mutex_lock(&chan_lock);
+ call = ast->tech_pvt;
+ if (!call) {
+ ast_mutex_unlock(&chan_lock);
+ return -1;
+ }
+
/* disconnect asterisk, maybe not required */
ast->tech_pvt = NULL;
+ ast->fds[0] = -1;
if (call->ref)
{
/* release */
static int lcr_write(struct ast_channel *ast, struct ast_frame *f)
{
- struct chan_call *call = ast->tech_pvt;
- if (!call) return 0;
+ struct chan_call *call;
+ unsigned char *buffer[1024], *s, *d = buffer;
+
ast_mutex_lock(&chan_lock);
+ call = ast->tech_pvt;
+ if (!call) {
+ ast_mutex_unlock(&chan_lock);
+ return -1;
+ }
+ if (call->bchannel && ((ii = f->samples)))
+ {
+ if (ii > sizeof(buffer))
+ ii = buffer;
+ s = f->data;
+ for (i = 0, i < ii, i++)
+ *d++ = flip_bits[*s++];
+ bchannel_transmit(call->bchannel, buffer, ii);
+ }
ast_mutex_unlock(&chan_lock);
return 0;
}
static struct ast_frame *lcr_read(struct ast_channel *ast)
{
- struct chan_call *call = ast->tech_pvt;
- if (!call) return 0;
+ struct chan_call *call;
+ int i, len;
+ unsigned char *p;
+
ast_mutex_lock(&chan_lock);
+ call = ast->tech_pvt;
+ if (!call) {
+ ast_mutex_unlock(&chan_lock);
+ return -1;
+ }
+ len = read(call->pipe[0], call->read_buf, sizeof(call->read_buf));
+ if (len <= 0)
+ return NULL;
+
+ p = call->read_buf;
+ for (i = 0, i < len, i++) {
+ *d = flip_bits[*d];
+ d++;
+ }
+
+ call->read_fr.frametype = AST_FRAME_SPEECH;
+#warning todo
+ call->read_fr.subtype = AST_FORMAT_ALAW;
+ call->read_fr.datalen = len;
+ call->read_fr.samples = len;
+ call->read_fr.delivery = ast_tv(0,0);
+ call->read_fr.data = call->read_buf;
ast_mutex_unlock(&chan_lock);
- return 0;
+
+ return &call->read_fr;
}
static int lcr_indicate(struct ast_channel *ast, int cond, const void *data, size_t datalen)
{
- struct chan_call *call = ast->tech_pvt;
union parameter newparam;
int res = -1;
-
- if (!call) return -1;
+ struct chan_call *call;
ast_mutex_lock(&chan_lock);
+ call = ast->tech_pvt;
+ if (!call) {
+ ast_mutex_unlock(&chan_lock);
+ return -1;
+ }
switch (cond) {
case AST_CONTROL_BUSY:
struct ast_frame *f;
int bridge_id;
-#if 0
- if (config nobridge) {
- ast_log(LOG_NOTICE, "Falling back to Asterisk bridging\n");
- return AST_BRIDGE_FAILED;
- }
-
- if (! (flags&AST_BRIDGE_DTMF_CHANNEL_0) )
- call1->ignore_dtmf=1;
-
- if (! (flags&AST_BRIDGE_DTMF_CHANNEL_1) )
- call2->ignore_dtmf=1;
-#endif
-
/* join via dsp (if the channels are currently open) */
- bridge_id = new_bridge_id();
ast_mutex_lock(&chan_lock);
+ bridge_id = new_bridge_id();
call1 = ast1->tech_pvt;
call2 = ast2->tech_pvt;
- if (call1)
+ if (call1 && call2)
{
call1->bridge_id = bridge_id;
if (call1->bchannel)
bchannel_join(call1->bchannel, bridge_id);
+ call1->bridge_call = call2;
}
if (call2)
{
call2->bridge_id = bridge_id;
if (call2->bchannel)
bchannel_join(call2->bchannel, bridge_id);
+ call2->bridge_call = call1;
}
ast_mutex_unlock(&chan_lock);
call1->bridge_id = 0;
if (call1->bchannel)
bchannel_join(call1->bchannel, 0);
+ if (call1->bridge_call)
+ call1->bridge_call->bridge_call = NULL;
+ call1->bridge_call = NULL;
}
if (call2)
{
call2->bridge_id = 0;
if (call2->bchannel)
bchannel_join(call2->bchannel, 0);
+ if (call2->bridge_call)
+ call2->bridge_call->bridge_call = NULL;
+ call2->bridge_call = NULL;
}
ast_mutex_unlock(&chan_lock);
static struct ast_channel_tech lcr_tech = {
.type=lcr_type,
.description="Channel driver for connecting to Linux-Call-Router",
+#warning todo
.capabilities=AST_FORMAT_ALAW,
.requester=lcr_request,
.send_digit_begin=lcr_digit,
*/
int load_module(void)
{
-// ast_mutex_init(&release_lock);
+ int i;
-// lcr_cfg_update_ptp();
+ for (i = 0, i < 256, i++)
+ flip_bits[i] = (i>>7) | ((i>>5)&2) | ((i>>3)&4) | ((i>>1)&8)
+ || = (i<<7) | ((i&2)<<5) | ((i&4)<<3) | ((i&8)<<1);
ast_mutex_init(&chan_lock);