📄 gatepstn.bak.txt
字号:
* INPUT : USHORT channel - Channel to make the dialing on
* PCHAR dialString - Extention to dial to
* OUTPUT :
* RETURNS : TRUE - success, FALSE - fail
* CAUTIONS : None
****************************************************************/
BOOL pstnDial(USHORT channel, PCHAR dialString)
{
int rc;
/* Dialing */
rc = dx_dial(Session[channel].PstnInfo.phoneDevice,dialString,NULL, EV_SYNC);
if(rc < 0) {
gateFATAL(channel,(Session[channel].LogFile,"\tError dialing in pstnDial(..) on channel %d\n", channel));
return(DM3FAIL);
}
return (DM3SUCCESS);
} /* Function pstnDial */
/*****FUNCTION***************************************************
* NAME : pstnCloseFrontEnd
* DESCRIPTION : Closes front end hardware
* INPUT : USHORT channel - Channel to close
* OUTPUT : None
* RETURNS : TRUE - success, FALSE - fail
* CAUTIONS : None
****************************************************************/
BOOL pstnCloseFrontEnd(USHORT channel)
{
USHORT index;
if ( channel == ALL_CHANNELS ) {
for (index = 1; index <= gateChannels; index++) {
if (closePstnChannel(index) == DM3FAIL)
return(DM3FAIL);
}
}
else { /* Closes a specific channel */
if (closePstnChannel(channel) == DM3FAIL) {
return(DM3FAIL);
}
}
return (DM3SUCCESS);
} /* Function pstnCloseFrontEnd */
/*****FUNCTION***************************************************
* NAME : pstnGetXMitSlot
* DESCRIPTION : Get transmit timeslot for given channel
* INPUT : USHORT channel - Channel to get its transmit TS
* UINT *timeslot - Time slot
* OUTPUT : UINT *timeslot - Time slot the channel transmit on
* RETURNS : TRUE - success
* CAUTIONS : None
****************************************************************/
BOOL pstnGetXMitSlot(USHORT channel, UINT *pTimeslot)
{
*pTimeslot = Session[channel].PstnInfo.pstnTxTSlot;
return(DM3SUCCESS);
} /* Function pstnGetXMitSlot */
/*****FUNCTION***************************************************
* NAME : pstnListen
* DESCRIPTION : Listen to a given timeslot
* INPUT : USHORT channel
* UINT timeslot - Time slot to listen to
* OUTPUT : None
* RETURNS : TRUE - success, FALSE - fail
* CAUTIONS : None
****************************************************************/
BOOL pstnListen(USHORT channel, UINT timeslot)
{
int rc;
SC_TSINFO tsInfo;
ULONG tsArray[1];
/* Set the timeslot */
tsArray[0] = timeslot;
/* Set SC structure to point to timeslot */
tsInfo.sc_tsarrayp = tsArray;
tsInfo.sc_numts = 1;
// switch on front end
switch(frontEnd) {
case GATE_LEGACY_ANALOG:
// Listen
if ( (rc = ag_listen(Session[channel].PstnInfo.phoneDevice,
&tsInfo)) == -1) {
gateFATAL(channel,(Session[channel].LogFile,"\tError in ag_listen on channel %d\n",channel));
}
gateTRACE(channel, (Session[channel].LogFile,"\t ag_listen on channel %d\n",channel));
break;
case GATE_LEGACY_T1:
case GATE_LEGACY_E1:
if ( (rc = dt_listen(Session[channel].PstnInfo.phoneDevice,
&tsInfo)) == -1) { // error
gateFATAL(channel,(Session[channel].LogFile,"\tError in dt_listen on channel %d\n",channel));
}
gateTRACE(channel, (Session[channel].LogFile,"\t dt_listen on channel %d\n",channel));
break;
default:
break;
} /* end switch(frontEnd) */
return(DM3SUCCESS);
} /* Function pstnListen */
/*****FUNCTION***************************************************
* NAME : pstnUnListen
* DESCRIPTION : UnListen on a given channel, and relisten to default
* INPUT : USHORT channel
* OUTPUT : None
* RETURNS : TRUE - success, FALSE -fail
* CAUTIONS : None
****************************************************************/
BOOL pstnUnListen(USHORT channel)
{
int rc;
SC_TSINFO tsInfo;
LONG tsArray;
/* Set the timeslot */
tsInfo.sc_numts = 1;
tsInfo.sc_tsarrayp = &tsArray;
// switch on front end
switch(frontEnd) {
case GATE_LEGACY_ANALOG:
// UnListen
if ((rc = ag_unlisten(Session[channel].PstnInfo.phoneDevice)) == -1 ) {
gateFATAL(channel,(Session[channel].LogFile,"\tError UnListening on pstn channel %d\n",channel));
return(DM3FAIL);
}
// Get voice xmit line
if ( (rc =dx_getxmitslot(Session[channel].PstnInfo.phoneDevice,
&tsInfo)) == -1) {
gateFATAL(channel,(Session[channel].LogFile,"\tError in dx_getxmitslot on channel %d %s\n",channel,ATDV_ERRMSGP(Session[channel].PstnInfo.phoneDevice)));
return(DM3FAIL);
}
// Listen to this again
if ( (rc =ag_listen(Session[channel].PstnInfo.phoneDevice,&tsInfo)) == -1) {
gateFATAL(channel,(Session[channel].LogFile,"\tError in ag_listen on channel %d\n",channel));
return(DM3FAIL);
}
break;
case GATE_LEGACY_T1:
case GATE_LEGACY_E1:
// UnListen
if ( (rc = dt_unlisten(Session[channel].PstnInfo.phoneDevice) ) == -1) {
gateFATAL(channel,(Session[channel].LogFile,"\tError in dt_unlisten on channel %d\n",channel));
return(DM3FAIL);
}
break;
default:
break;
} /* end switch(frontEnd) */
return(DM3SUCCESS);
}
/*****FUNCTION***************************************************
* NAME : pstnOffHook
* DESCRIPTION : Sets the channel off hook
*
* INPUT : channel, the event device
* OUTPUT : none
* RETURNS : none
* CAUTIONS : none
****************************************************************/
BOOL pstnOffHook(USHORT channel)
{
if (frontEnd == GATE_LEGACY_ANALOG) {
#if 1
return(pstnSetLine(channel,PSTN_OFFHOOK));
#else
if (pstnSetLine(channel,PSTN_OFFHOOK)) {
/* Get remote phone number, by getting digits */
pstnGetDigits(channel);
}
#endif
}
if (frontEnd == GATE_LEGACY_T1) {
return(pstnSetLine(channel,DTB_AON|DTB_BON));
}
if (frontEnd == GATE_LEGACY_E1) {
return(pstnSetLine(channel,DTB_AOFF));
}
}
/*****FUNCTION***************************************************
* NAME : pstnOnHook
* DESCRIPTION : Sets the channel on hook
* INPUT : channel, the event device
* OUTPUT : none
* RETURNS : none
* CAUTIONS : none
****************************************************************/
BOOL pstnOnHook(USHORT channel)
{
/* Set the phone back onhook */
if (frontEnd == GATE_LEGACY_ANALOG) {
return(pstnSetLine(channel,PSTN_ONHOOK));
}
if (frontEnd == GATE_LEGACY_T1) {
return(pstnSetLine(channel,DTB_AOFF|DTB_BOFF));
}
if (frontEnd == GATE_LEGACY_E1) {
return(pstnSetLine(channel,DTB_AON));
}
}
/*****FUNCTION***************************************************
* NAME : pstnGetEvent
* DESCRIPTION : Gets SRL event and channel
* INPUT : None
* OUTPUT : None
* RETURNS : TRUE - success, FALSE - fail
* CAUTIONS : None
****************************************************************/
BOOL pstnGetEvent()
{
LONG Event;
USHORT chDevice;
USHORT Channel;
BOOL rc;
DX_CST *cstp;
LONG eType;
USHORT *dti_data; // Data returned by network signal event
// added for digital front end
if(sr_waitevt(0) == -1) {
// Signal for exit
printf("NOEVENT on SRL DEVICE\n");
fflush(NULL);
return(DM3FAIL);
}
else {
eType = sr_getevttype(0);
switch(eType) {
case TDX_CST:
// Call status transition events:
cstp = (DX_CST *)sr_getevtdatap();
Event = (LONG) cstp->cst_event;
chDevice = (USHORT) sr_getevtdev(0);
Channel = deviceToChannel[chDevice];
break;
case TDX_CALLP:
// call progress (dialing) events
chDevice = (USHORT) sr_getevtdev(0);
Channel = deviceToChannel[chDevice];
Event = ATDX_CPTERM(Channel);
break;
case DTEV_SIG:
dti_data = (USHORT *) sr_getevtdatap();
chDevice = (USHORT ) sr_getevtdev(0);
Channel = deviceToChannel[chDevice];
if ( (*dti_data & DTMM_AON) == DTMM_AON ) {
if (frontEnd==GATE_LEGACY_T1) {
Event = (LONG)DIGITAL_OFFHOOK;
}
else {
Event = (LONG)DIGITAL_ONHOOK;
}
}
else {
if ( (*dti_data & DTMM_AOFF) == DTMM_AOFF ) {
if (frontEnd==GATE_LEGACY_T1) {
Event = (LONG)DIGITAL_ONHOOK;
}
else {
Event = (LONG)DIGITAL_OFFHOOK;
}
}
else {
// Unexpected DIGITAL signaling transition received
gateERROR(Channel,(Session[Channel].LogFile,"%s: Unexpected signaling transition, data = 0x%X\n",
ATDV_NAMEP(Channel), dti_data));
}
}
break;
default:
break;
} /* end switch(eType) */
} // end else.
if((Event == DE_RINGS) || (Event == DIGITAL_OFFHOOK)) {
chanInfo[Channel].off_hook++;
}
if((Event == DIGITAL_ONHOOK) || (Event == DE_TONEON) || (Event == DE_LCOFF)) {
chanInfo[Channel].on_hook++;
}
/* We have an event
Run the state machine function for this channel */
rc = (*(Session[Channel].stateFxn))(&(Session[Channel].NetTscComp),Event,NULL);
/* Check return code */
if(rc != DM3SUCCESS) {
gateFATAL(Channel,(Session[Channel].LogFile,"State Machine Error on Channel %d Event %s\n", Channel, gateEventStr(Event)));
}
return(rc);
} /* Function pstnGetEvent */
///////////////////////////////////////////////////////
/// ///
/// DECLARATION OF LOCAL FUNCTIONS ///
/// ///
///////////////////////////////////////////////////////
/*****FUNCTION***************************************************
* NAME : closePstnChannel
* DESCRIPTION : Closes one pstn channel
* INPUT : USHORT channel - Channel to close
* OUTPUT :
* RETURNS : TRUE - success, FALSE - fail
* CAUTIONS : None
****************************************************************/
BOOL closePstnChannel(USHORT channel)
{
/* Check if opened */
if(Session[channel].PstnInfo.phoneDevice == 0) {
return(DM3SUCCESS);
}
gateTRACE(channel, (Session[channel].LogFile,"\t[%s] - CLOSING\n",ATDV_NAMEP((Session[channel]).PstnInfo.phoneDevice)));
switch (frontEnd) {
case GATE_LEGACY_ANALOG :
pstnSetLine((USHORT)channel,PSTN_ONHOOK);
if(dx_close((Session[channel]).PstnInfo.phoneDevice) == -1)
gateFATAL(channel,(Session[channel].LogFile,"\nERROR E%04d: dx_close() failed for device \"%s\": errno = 0x%X\n",
__LINE__,ATDV_NAMEP(Session[channel].PstnInfo.phoneDevice),errno));
break;
case GATE_LEGACY_T1:
pstnSetLine((USHORT)channel,DTB_AOFF|DTB_BOFF);
if(dt_close((Session[channel]).PstnInfo.phoneDevice) == -1)
gateFATAL(channel,(Session[channel].LogFile,"\nERROR E%04d: dt_close() failed for device \"%s\": errno = 0x%X\n",
__LINE__,ATDV_NAMEP(Session[channel].PstnInfo.phoneDevice),errno));
break;
case GATE_LEGACY_E1:
pstnSetLine((USHORT)channel,DTB_AON);
if(dt_close((Session[channel]).PstnInfo.phoneDevice) == -1)
gateFATAL(channel,(Session[channel].LogFile,"\nERROR E%04d: dt_close() failed for device \"%s\": errno = 0x%X\n",
__LINE__,ATDV_NAMEP(Session[channel].PstnInfo.phoneDevice),errno));
break;
}
return(DM3SUCCESS);
} /* Function closePstnChannel */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -