outbound isdn w00t
git-svn-id: http://svn.openzap.org/svn/openzap/trunk@264 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
parent
ba4244b28b
commit
bed2275bc8
|
@ -554,7 +554,14 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session,
|
||||||
assert(tech_pvt != NULL);
|
assert(tech_pvt != NULL);
|
||||||
|
|
||||||
switch (msg->message_id) {
|
switch (msg->message_id) {
|
||||||
|
case SWITCH_MESSAGE_INDICATE_RINGING:
|
||||||
|
if (!switch_channel_test_flag(channel, CF_OUTBOUND)) {
|
||||||
|
zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS);
|
||||||
|
}
|
||||||
case SWITCH_MESSAGE_INDICATE_PROGRESS:
|
case SWITCH_MESSAGE_INDICATE_PROGRESS:
|
||||||
|
if (!switch_channel_test_flag(channel, CF_OUTBOUND)) {
|
||||||
|
zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_EARLY_MEDIA);
|
||||||
|
}
|
||||||
case SWITCH_MESSAGE_INDICATE_ANSWER:
|
case SWITCH_MESSAGE_INDICATE_ANSWER:
|
||||||
if (!switch_channel_test_flag(channel, CF_OUTBOUND)) {
|
if (!switch_channel_test_flag(channel, CF_OUTBOUND)) {
|
||||||
zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP);
|
zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP);
|
||||||
|
@ -697,14 +704,17 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
|
||||||
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
|
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dest = outbound_profile->destination_number;
|
||||||
|
|
||||||
if ((p = strchr(outbound_profile->destination_number, '/'))) {
|
if ((p = strchr(outbound_profile->destination_number, '/'))) {
|
||||||
dest = p + 1;
|
dest = p + 1;
|
||||||
span_id = atoi(outbound_profile->destination_number);
|
span_id = atoi(outbound_profile->destination_number);
|
||||||
chan_id = atoi(dest);
|
chan_id = atoi(dest);
|
||||||
|
if ((p = strchr(dest, '/'))) {
|
||||||
|
dest = p + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dest = outbound_profile->destination_number;
|
|
||||||
|
|
||||||
if (!dest) {
|
if (!dest) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n");
|
||||||
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
|
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
|
||||||
|
@ -972,6 +982,23 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal)
|
||||||
switch_core_session_rwunlock(session);
|
switch_core_session_rwunlock(session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case ZAP_SIGEVENT_PROGRESS_MEDIA:
|
||||||
|
{
|
||||||
|
if ((session = zap_channel_get_session(sigmsg->channel, 0))) {
|
||||||
|
channel = switch_core_session_get_channel(session);
|
||||||
|
switch_channel_mark_pre_answered(channel);
|
||||||
|
switch_core_session_rwunlock(session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ZAP_SIGEVENT_PROGRESS:
|
||||||
|
{
|
||||||
|
if ((session = zap_channel_get_session(sigmsg->channel, 0))) {
|
||||||
|
channel = switch_core_session_get_channel(session);
|
||||||
|
switch_channel_mark_ring_ready(channel);
|
||||||
|
switch_core_session_rwunlock(session);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -482,6 +482,7 @@ void zap_global_set_logger(zap_logger_t logger);
|
||||||
void zap_global_set_default_logger(int level);
|
void zap_global_set_default_logger(int level);
|
||||||
uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen);
|
uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen);
|
||||||
void print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss);
|
void print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss);
|
||||||
|
void print_hex_bytes(uint8_t *data, zap_size_t dlen, uint8_t *buf, zap_size_t blen);
|
||||||
ZIO_CODEC_FUNCTION(zio_slin2ulaw);
|
ZIO_CODEC_FUNCTION(zio_slin2ulaw);
|
||||||
ZIO_CODEC_FUNCTION(zio_ulaw2slin);
|
ZIO_CODEC_FUNCTION(zio_ulaw2slin);
|
||||||
ZIO_CODEC_FUNCTION(zio_slin2alaw);
|
ZIO_CODEC_FUNCTION(zio_slin2alaw);
|
||||||
|
|
|
@ -263,11 +263,13 @@ typedef enum {
|
||||||
ZAP_CHANNEL_STATE_CALLWAITING,
|
ZAP_CHANNEL_STATE_CALLWAITING,
|
||||||
ZAP_CHANNEL_STATE_TERMINATING,
|
ZAP_CHANNEL_STATE_TERMINATING,
|
||||||
ZAP_CHANNEL_STATE_RESTART,
|
ZAP_CHANNEL_STATE_RESTART,
|
||||||
|
ZAP_CHANNEL_STATE_EARLY_MEDIA,
|
||||||
|
ZAP_CHANNEL_STATE_PROGRESS,
|
||||||
ZAP_CHANNEL_STATE_INVALID
|
ZAP_CHANNEL_STATE_INVALID
|
||||||
} zap_channel_state_t;
|
} zap_channel_state_t;
|
||||||
#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", \
|
#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", \
|
||||||
"RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \
|
"RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \
|
||||||
"TERMINATING", "RESTART", "INVALID"
|
"TERMINATING", "RESTART", "EARLY_MEDIA", "PROGRESS", "INVALID"
|
||||||
ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t)
|
ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t)
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -288,7 +290,8 @@ typedef enum {
|
||||||
ZAP_CHANNEL_OFFHOOK = (1 << 14),
|
ZAP_CHANNEL_OFFHOOK = (1 << 14),
|
||||||
ZAP_CHANNEL_RINGING = (1 << 15),
|
ZAP_CHANNEL_RINGING = (1 << 15),
|
||||||
ZAP_CHANNEL_PROGRESS_DETECT = (1 << 16),
|
ZAP_CHANNEL_PROGRESS_DETECT = (1 << 16),
|
||||||
ZAP_CHANNEL_CALLERID_DETECT = (1 << 17)
|
ZAP_CHANNEL_CALLERID_DETECT = (1 << 17),
|
||||||
|
ZAP_CHANNEL_OUTBOUND = (1 << 18)
|
||||||
} zap_channel_flag_t;
|
} zap_channel_flag_t;
|
||||||
|
|
||||||
typedef struct zap_channel zap_channel_t;
|
typedef struct zap_channel zap_channel_t;
|
||||||
|
|
|
@ -217,7 +217,7 @@ L3INT Q931GetUniqueCRV(Q931_TrunkInfo_t *pTrunk)
|
||||||
L3INT Q931InitMesGeneric(Q931mes_Generic *pMes)
|
L3INT Q931InitMesGeneric(Q931mes_Generic *pMes)
|
||||||
{
|
{
|
||||||
memset(pMes, 0, sizeof(*pMes));
|
memset(pMes, 0, sizeof(*pMes));
|
||||||
pMes->ProtDisc = 0x80;
|
pMes->ProtDisc = 0x08;
|
||||||
pMes->Size = Q931GetMesSize(pMes);
|
pMes->Size = Q931GetMesSize(pMes);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -225,7 +225,7 @@ L3INT Q931InitMesGeneric(Q931mes_Generic *pMes)
|
||||||
|
|
||||||
L3INT Q931InitMesResume(Q931mes_Generic * pMes)
|
L3INT Q931InitMesResume(Q931mes_Generic * pMes)
|
||||||
{
|
{
|
||||||
pMes->ProtDisc = 0x80;
|
pMes->ProtDisc = 0x08;
|
||||||
pMes->CRV = 0; /* CRV to be allocated, might be receive*/
|
pMes->CRV = 0; /* CRV to be allocated, might be receive*/
|
||||||
pMes->MesType = Q931mes_RESUME;
|
pMes->MesType = Q931mes_RESUME;
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ L3INT Q931InitMesResume(Q931mes_Generic * pMes)
|
||||||
|
|
||||||
L3INT Q931InitMesRestartAck(Q931mes_Generic * pMes)
|
L3INT Q931InitMesRestartAck(Q931mes_Generic * pMes)
|
||||||
{
|
{
|
||||||
pMes->ProtDisc = 0x80;
|
pMes->ProtDisc = 0x08;
|
||||||
pMes->CRV = 0; /* CRV to be allocated, might be receive*/
|
pMes->CRV = 0; /* CRV to be allocated, might be receive*/
|
||||||
pMes->MesType = Q931mes_RESTART_ACKNOWLEDGE;
|
pMes->MesType = Q931mes_RESTART_ACKNOWLEDGE;
|
||||||
|
|
||||||
|
|
|
@ -322,17 +322,12 @@ L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf,
|
||||||
li=(*Octet)++; /* remember length position */
|
li=(*Octet)++; /* remember length position */
|
||||||
|
|
||||||
/* Octet 3 - Coding standard / Information transfer capability */
|
/* Octet 3 - Coding standard / Information transfer capability */
|
||||||
OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<5) | (pIE->ITR & 0x1f);
|
OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<5) | (pIE->ITC & 0x1f);
|
||||||
|
|
||||||
/* Octet 4 - Transfer mode / Information transfer rate */
|
/* Octet 4 - Transfer mode / Information transfer rate */
|
||||||
|
OBuf[(*Octet)++] = 0x80 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f);
|
||||||
if(pIE->ITR == 0x18)
|
if(pIE->ITR == 0x18)
|
||||||
{
|
{
|
||||||
OBuf[(*Octet)++] = 0x80 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
OBuf[(*Octet)++] = 0x00 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f);
|
|
||||||
|
|
||||||
/* Octet 4.1 - Rate Multiplier */
|
/* Octet 4.1 - Rate Multiplier */
|
||||||
OBuf[(*Octet)++] = 0x80 | pIE->RateMul;
|
OBuf[(*Octet)++] = 0x80 | pIE->RateMul;
|
||||||
}
|
}
|
||||||
|
@ -382,7 +377,7 @@ L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
OBuf[(*Octet)++] = 0x80 | (pIE->Layer1Ident<<5) | (pIE->UIL1Prot & 0x15);
|
OBuf[(*Octet)++] = 0x80 | (pIE->Layer1Ident<<5) | (pIE->UIL1Prot & 0x1F);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -748,11 +743,11 @@ L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
|
L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
|
||||||
{
|
{
|
||||||
Q931ie_CalledSub * pIE = (Q931ie_CalledSub*)IBuf;
|
Q931ie_CalledNum * pIE = (Q931ie_CalledNum*)IBuf;
|
||||||
L3INT rc=0;
|
L3INT rc=0;
|
||||||
L3INT Beg=*Octet;
|
L3INT Beg=*Octet;
|
||||||
L3INT li;
|
L3INT li;
|
||||||
L3INT sN = pIE->Size - sizeof(Q931ie_CalledSub) + 1;
|
L3INT sN = pIE->Size - sizeof(Q931ie_CalledNum);
|
||||||
L3INT x;
|
L3INT x;
|
||||||
|
|
||||||
/* Octet 1 */
|
/* Octet 1 */
|
||||||
|
@ -760,7 +755,7 @@ L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf,
|
||||||
li=(*Octet)++;
|
li=(*Octet)++;
|
||||||
|
|
||||||
/* Octet 3 */
|
/* Octet 3 */
|
||||||
OBuf[(*Octet)++] = 0x80 | (pIE->TypNum << 4) | (pIE->OddEvenInd << 3);
|
OBuf[(*Octet)++] = 0x80 | (pIE->TypNum << 4) | (pIE->NumPlanID);
|
||||||
|
|
||||||
/* Octet 4 */
|
/* Octet 4 */
|
||||||
for(x=0;x<sN;x++)
|
for(x=0;x<sN;x++)
|
||||||
|
@ -768,8 +763,6 @@ L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf,
|
||||||
OBuf[(*Octet)++] = pIE->Digit[x];
|
OBuf[(*Octet)++] = pIE->Digit[x];
|
||||||
}
|
}
|
||||||
|
|
||||||
OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */
|
|
||||||
|
|
||||||
OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2;
|
OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -290,6 +290,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
|
|
||||||
debug = PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE;
|
debug = PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE;
|
||||||
|
printf("WTF %d\n", debug);
|
||||||
|
|
||||||
if (sangoma_init_pri(&spri,
|
if (sangoma_init_pri(&spri,
|
||||||
1, // span
|
1, // span
|
||||||
|
|
|
@ -658,6 +658,7 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan)
|
||||||
zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF);
|
zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF);
|
||||||
zap_channel_done(zchan);
|
zap_channel_done(zchan);
|
||||||
zap_clear_flag_locked(zchan, ZAP_CHANNEL_HOLD);
|
zap_clear_flag_locked(zchan, ZAP_CHANNEL_HOLD);
|
||||||
|
|
||||||
memset(zchan->tokens, 0, sizeof(zchan->tokens));
|
memset(zchan->tokens, 0, sizeof(zchan->tokens));
|
||||||
zchan->token_count = 0;
|
zchan->token_count = 0;
|
||||||
|
|
||||||
|
@ -747,9 +748,15 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t
|
||||||
|
|
||||||
zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan)
|
zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan)
|
||||||
{
|
{
|
||||||
|
zap_status_t status;
|
||||||
|
|
||||||
assert(zchan != NULL);
|
assert(zchan != NULL);
|
||||||
|
|
||||||
if (zchan->span->outgoing_call) {
|
if (zchan->span->outgoing_call) {
|
||||||
return zchan->span->outgoing_call(zchan);
|
if ((status = zchan->span->outgoing_call(zchan)) == ZAP_SUCCESS) {
|
||||||
|
zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
} else {
|
} else {
|
||||||
zap_log(ZAP_LOG_ERROR, "outgoing_call method not implemented!\n");
|
zap_log(ZAP_LOG_ERROR, "outgoing_call method not implemented!\n");
|
||||||
}
|
}
|
||||||
|
@ -765,6 +772,7 @@ zap_status_t zap_channel_done(zap_channel_t *zchan)
|
||||||
|
|
||||||
memset(&zchan->caller_data, 0, sizeof(zchan->caller_data));
|
memset(&zchan->caller_data, 0, sizeof(zchan->caller_data));
|
||||||
zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE);
|
zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE);
|
||||||
|
zap_clear_flag_locked(zchan, ZAP_CHANNEL_OUTBOUND);
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
if (zchan->fds[i] > -1) {
|
if (zchan->fds[i] > -1) {
|
||||||
close(zchan->fds[i]);
|
close(zchan->fds[i]);
|
||||||
|
@ -1967,6 +1975,28 @@ int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp)
|
||||||
return bit;
|
return bit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_hex_bytes(uint8_t *data, zap_size_t dlen, uint8_t *buf, zap_size_t blen)
|
||||||
|
{
|
||||||
|
char *bp = buf;
|
||||||
|
uint8_t *byte = data;
|
||||||
|
uint32_t i, j = 0;
|
||||||
|
|
||||||
|
if (blen < (dlen * 3) + 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
*bp++ = '[';
|
||||||
|
j++;
|
||||||
|
|
||||||
|
for(i = 0; i < dlen; i++) {
|
||||||
|
snprintf(bp, blen-j, "%02x ", *byte++);
|
||||||
|
bp += 3;
|
||||||
|
j += 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
*--bp = ']';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, uint8_t ss)
|
void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, uint8_t ss)
|
||||||
{
|
{
|
||||||
|
|
|
@ -108,6 +108,21 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen)
|
||||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING);
|
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case Q931mes_ALERTING:
|
||||||
|
{
|
||||||
|
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_EARLY_MEDIA);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Q931mes_PROGRESS:
|
||||||
|
{
|
||||||
|
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Q931mes_CONNECT:
|
||||||
|
{
|
||||||
|
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case Q931mes_SETUP:
|
case Q931mes_SETUP:
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -155,7 +170,12 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen)
|
||||||
|
|
||||||
static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen)
|
static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen)
|
||||||
{
|
{
|
||||||
int ret = Q931Rx23(pvt, msg, mlen);
|
int ret;
|
||||||
|
char bb[4096] = "";
|
||||||
|
print_hex_bytes(msg, mlen, bb, sizeof(bb));
|
||||||
|
zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen, LINE, bb);
|
||||||
|
|
||||||
|
ret = Q931Rx23(pvt, msg, mlen);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
zap_log(ZAP_LOG_DEBUG, "931 parse error [%d] [%s]\n", ret, q931_error_to_name(ret));
|
zap_log(ZAP_LOG_DEBUG, "931 parse error [%d] [%s]\n", ret, q931_error_to_name(ret));
|
||||||
return ((ret >= 0) ? 1 : 0);
|
return ((ret >= 0) ? 1 : 0);
|
||||||
|
@ -166,9 +186,10 @@ static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen)
|
||||||
zap_span_t *span = (zap_span_t *) pvt;
|
zap_span_t *span = (zap_span_t *) pvt;
|
||||||
zap_size_t len = (zap_size_t) mlen;
|
zap_size_t len = (zap_size_t) mlen;
|
||||||
#ifdef IODEBUG
|
#ifdef IODEBUG
|
||||||
char bb[4096] = "";
|
//char bb[4096] = "";
|
||||||
print_bits(msg, (int)len, bb, sizeof(bb), ZAP_ENDIAN_LITTLE, 0);
|
//print_hex_bytes(msg, len, bb, sizeof(bb));
|
||||||
zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)len, LINE, bb);
|
//print_bits(msg, (int)len, bb, sizeof(bb), ZAP_ENDIAN_LITTLE, 0);
|
||||||
|
//zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)len, LINE, bb);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -192,11 +213,31 @@ static __inline__ void state_advance(zap_channel_t *zchan)
|
||||||
sig.channel = zchan;
|
sig.channel = zchan;
|
||||||
|
|
||||||
switch (zchan->state) {
|
switch (zchan->state) {
|
||||||
|
case ZAP_CHANNEL_STATE_DOWN:
|
||||||
|
{
|
||||||
|
zap_channel_done(zchan);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ZAP_CHANNEL_STATE_PROGRESS:
|
||||||
|
{
|
||||||
|
if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
|
||||||
|
sig.event_id = ZAP_SIGEVENT_PROGRESS;
|
||||||
|
if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) {
|
||||||
|
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
gen->MesType = Q931mes_PROGRESS;
|
||||||
|
Q931Rx43(&data->q931, (void *)gen, gen->Size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case ZAP_CHANNEL_STATE_RING:
|
case ZAP_CHANNEL_STATE_RING:
|
||||||
{
|
{
|
||||||
sig.event_id = ZAP_SIGEVENT_START;
|
if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
|
||||||
if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) {
|
sig.event_id = ZAP_SIGEVENT_START;
|
||||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
|
if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) {
|
||||||
|
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -207,11 +248,31 @@ static __inline__ void state_advance(zap_channel_t *zchan)
|
||||||
zap_channel_close(&zchan);
|
zap_channel_close(&zchan);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case ZAP_CHANNEL_STATE_EARLY_MEDIA:
|
||||||
|
{
|
||||||
|
if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
|
||||||
|
sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA;
|
||||||
|
if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) {
|
||||||
|
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
gen->MesType = Q931mes_ALERTING;
|
||||||
|
Q931Rx43(&data->q931, (void *)gen, gen->Size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case ZAP_CHANNEL_STATE_UP:
|
case ZAP_CHANNEL_STATE_UP:
|
||||||
{
|
{
|
||||||
gen->MesType = Q931mes_CONNECT;
|
if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) {
|
||||||
gen->BearerCap = 0;
|
sig.event_id = ZAP_SIGEVENT_UP;
|
||||||
Q931Rx43(&data->q931, (void *)gen, zchan->caller_data.raw_data_len);
|
if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) {
|
||||||
|
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
gen->MesType = Q931mes_CONNECT;
|
||||||
|
gen->BearerCap = 0;
|
||||||
|
Q931Rx43(&data->q931, (void *)gen, zchan->caller_data.raw_data_len);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ZAP_CHANNEL_STATE_DIALING:
|
case ZAP_CHANNEL_STATE_DIALING:
|
||||||
|
@ -220,25 +281,75 @@ static __inline__ void state_advance(zap_channel_t *zchan)
|
||||||
Q931ie_ChanID ChanID;
|
Q931ie_ChanID ChanID;
|
||||||
Q931ie_CallingNum CallingNum;
|
Q931ie_CallingNum CallingNum;
|
||||||
Q931ie_CalledNum CalledNum;
|
Q931ie_CalledNum CalledNum;
|
||||||
|
Q931ie_CalledNum *ptrCalledNum;
|
||||||
|
|
||||||
Q931InitIEBearerCap(&BearerCap);
|
Q931InitIEBearerCap(&BearerCap);
|
||||||
Q931InitIEChanID(&ChanID);
|
Q931InitIEChanID(&ChanID);
|
||||||
Q931InitIECallingNum(&CallingNum);
|
Q931InitIECallingNum(&CallingNum);
|
||||||
Q931InitIECalledNum(&CalledNum);
|
Q931InitIECalledNum(&CalledNum);
|
||||||
|
|
||||||
//is cast right here?
|
|
||||||
ChanID.ChanSlot = (unsigned char)zchan->chan_id;
|
|
||||||
|
|
||||||
//CallingNum.Digits
|
|
||||||
|
|
||||||
|
|
||||||
Q931InitMesGeneric(gen);
|
Q931InitMesGeneric(gen);
|
||||||
gen->MesType = Q931mes_SETUP;
|
gen->MesType = Q931mes_SETUP;
|
||||||
|
|
||||||
|
BearerCap.CodStand = 0; /* ITU-T = 0, ISO/IEC = 1, National = 2, Network = 3 */
|
||||||
|
BearerCap.ITC = 0; /* Speech */
|
||||||
|
BearerCap.TransMode = 0; /* Circuit = 0, Packet = 1 */
|
||||||
|
BearerCap.ITR = 16; /* 64k */
|
||||||
|
BearerCap.Layer1Ident = 1;
|
||||||
|
BearerCap.UIL1Prot = 2; /* U-law (a-law = 3)*/
|
||||||
|
#if 0
|
||||||
|
BearerCap.SyncAsync = ;
|
||||||
|
BearerCap.Negot = ;
|
||||||
|
BearerCap.UserRate = ;
|
||||||
|
BearerCap.InterRate = ;
|
||||||
|
BearerCap.NIConTx = ;
|
||||||
|
BearerCap.FlowCtlTx = ;
|
||||||
|
BearerCap.HDR = ;
|
||||||
|
BearerCap.MultiFrame = ;
|
||||||
|
BearerCap.Mode = ;
|
||||||
|
BearerCap.LLInegot = ;
|
||||||
|
BearerCap.Assignor = ;
|
||||||
|
BearerCap.InBandNeg = ;
|
||||||
|
BearerCap.NumStopBits = ;
|
||||||
|
BearerCap.NumDataBits = ;
|
||||||
|
BearerCap.Parity = ;
|
||||||
|
BearerCap.DuplexMode = ;
|
||||||
|
BearerCap.ModemType = ;
|
||||||
|
BearerCap.Layer2Ident = ;
|
||||||
|
BearerCap.UIL2Prot = ;
|
||||||
|
BearerCap.Layer3Ident = ;
|
||||||
|
BearerCap.UIL3Prot = ;
|
||||||
|
BearerCap.AL3Info1 = ;
|
||||||
|
BearerCap.AL3Info2 = ;
|
||||||
|
#endif
|
||||||
|
|
||||||
gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap);
|
gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap);
|
||||||
|
|
||||||
|
//is cast right here?
|
||||||
|
ChanID.IntType = 1; /* PRI = 1, BRI = 0 */
|
||||||
|
ChanID.InfoChanSel = 1;
|
||||||
|
ChanID.ChanMapType = 3; /* B-Chan */
|
||||||
|
ChanID.ChanSlot = (unsigned char)zchan->chan_id;
|
||||||
gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID);
|
gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID);
|
||||||
gen->CallingNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CallingNum);
|
#if 0
|
||||||
|
CallingNum.Size += strlen(zchan->caller_data.cid_num);
|
||||||
|
gen->CallingNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CallingNum);
|
||||||
|
zap_set_string((char *)CallingNum.Digit, zchan->caller_data.cid_num);
|
||||||
|
gen->Size += strlen(zchan->caller_data.cid_num);
|
||||||
|
|
||||||
|
//zap_set_string(zchan->caller_data.dnis, (char *)callednum->Digit);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
CalledNum.TypNum = 2;
|
||||||
|
CalledNum.NumPlanID = 1;
|
||||||
|
printf("WTF: [%s]\n", zchan->caller_data.ani);
|
||||||
|
CalledNum.Size += strlen(zchan->caller_data.ani);
|
||||||
gen->CalledNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CalledNum);
|
gen->CalledNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CalledNum);
|
||||||
|
ptrCalledNum = Q931GetIEPtr(gen->CalledNum, gen->buf);
|
||||||
|
zap_copy_string((char *)ptrCalledNum->Digit, zchan->caller_data.ani, strlen(zchan->caller_data.ani)+1);
|
||||||
|
|
||||||
|
//gen->Size += strlen(zchan->caller_data.ani);
|
||||||
|
Q931Rx43(&data->q931, (L3UCHAR *) gen, gen->Size);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ZAP_CHANNEL_STATE_HANGUP:
|
case ZAP_CHANNEL_STATE_HANGUP:
|
||||||
|
@ -328,9 +439,11 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj)
|
||||||
len = sizeof(buf);
|
len = sizeof(buf);
|
||||||
if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) {
|
if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) {
|
||||||
#ifdef IODEBUG
|
#ifdef IODEBUG
|
||||||
char bb[4096] = "";
|
//char bb[4096] = "";
|
||||||
print_bits(buf, (int)len, bb, sizeof(bb), ZAP_ENDIAN_LITTLE, 0);
|
//print_hex_bytes(buf, len, bb, sizeof(bb));
|
||||||
zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)len, LINE, bb);
|
|
||||||
|
//print_bits(buf, (int)len, bb, sizeof(bb), ZAP_ENDIAN_LITTLE, 0);
|
||||||
|
//zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)len, LINE, bb);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Q921QueueHDLCFrame(&data->q921, buf, (int)len);
|
Q921QueueHDLCFrame(&data->q921, buf, (int)len);
|
||||||
|
@ -374,6 +487,16 @@ zap_status_t zap_isdn_start(zap_span_t *span)
|
||||||
return zap_thread_create_detached(zap_isdn_run, span);
|
return zap_thread_create_detached(zap_isdn_run, span);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int q931_rx_32(void *pvt,L3UCHAR *msg, L3INT mlen)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
char bb[4096] = "";
|
||||||
|
ret = Q921Rx32(pvt, msg, mlen);
|
||||||
|
print_hex_bytes(msg, mlen, bb, sizeof(bb));
|
||||||
|
zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)mlen, LINE, bb);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zio_signal_cb_t sig_cb)
|
zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zio_signal_cb_t sig_cb)
|
||||||
{
|
{
|
||||||
uint32_t i, x = 0;
|
uint32_t i, x = 0;
|
||||||
|
@ -428,12 +551,13 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D
|
||||||
mode,
|
mode,
|
||||||
span->trunk_type,
|
span->trunk_type,
|
||||||
zap_isdn_931_34,
|
zap_isdn_931_34,
|
||||||
(Q931TxCB_t)Q921Rx32,
|
(Q931TxCB_t)q931_rx_32,
|
||||||
zap_isdn_931_err,
|
zap_isdn_931_err,
|
||||||
&span->isdn_data->q921,
|
&span->isdn_data->q921,
|
||||||
span);
|
span);
|
||||||
|
|
||||||
span->isdn_data->q931.autoRestartAck = 1;
|
span->isdn_data->q931.autoRestartAck = 1;
|
||||||
|
span->isdn_data->q931.autoConnectAck = 1;
|
||||||
span->signal_type = ZAP_SIGTYPE_ISDN;
|
span->signal_type = ZAP_SIGTYPE_ISDN;
|
||||||
span->outgoing_call = isdn_outgoing_call;
|
span->outgoing_call = isdn_outgoing_call;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue