checkin q931/q932/q921 code.
git-svn-id: http://svn.openzap.org/svn/openzap/trunk@65 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
parent
5ab3190cc8
commit
70f5fc6153
|
@ -0,0 +1,46 @@
|
|||
/*****************************************************************************
|
||||
|
||||
FileName: EuroISDNStateNT.c
|
||||
|
||||
Contents: EuroISDN State Engine for NT (Network Mode).
|
||||
|
||||
The controlling state engine for Q.931 is the state engine
|
||||
on the NT side. The state engine on the TE side is a slave
|
||||
of this. The TE side maintain it's own states as described in
|
||||
ITU-T Q931, but will in raise conditions be overridden by
|
||||
the NT side.
|
||||
|
||||
License/Copyright:
|
||||
|
||||
Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
|
||||
email:janvb@caselaboratories.com
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the Case Labs, Ltd nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "Q931.h"
|
||||
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/*****************************************************************************
|
||||
|
||||
FileName: EuroISDNStateTE.c
|
||||
|
||||
Contents: EuroISDN State Engine for TE (User Mode).
|
||||
|
||||
The controlling state engine for Q.931 is the state engine
|
||||
on the NT side. The state engine on the TE side is a slave
|
||||
of this. The TE side maintain it's own states as described in
|
||||
ITU-T Q931, but will in raise conditions be overridden by
|
||||
the NT side.
|
||||
|
||||
License/Copyright:
|
||||
|
||||
Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
|
||||
email:janvb@caselaboratories.com
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the Case Labs, Ltd nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "Q931.h"
|
||||
|
||||
/*
|
||||
EuroISDN is a sub-set of Q.931. Q.931 is very generic as it embrase a lot,
|
||||
while EuroISDN is more exact and make decitions on some of the
|
||||
'implementation options' in the original standard. EuroISDN will
|
||||
however run smoothly under the generic space, so these functions are more
|
||||
for show
|
||||
*/
|
||||
|
||||
void EuroISDNCreateTE(L3UCHAR i)
|
||||
{
|
||||
Q931CreateTE(i);
|
||||
}
|
|
@ -0,0 +1,477 @@
|
|||
/*****************************************************************************
|
||||
|
||||
FileName: q921.c
|
||||
|
||||
Description: Contains the implementation of a Q.921 protocol on top of the
|
||||
Comet Driver.
|
||||
|
||||
Most of the work required to execute a Q.921 protocol is
|
||||
taken care of by the Comet ship and it's driver. This layer
|
||||
will simply configure and make use of these features to
|
||||
complete a Q.921 implementation.
|
||||
|
||||
Created: 27.dec.2000/JVB
|
||||
|
||||
License/Copyright:
|
||||
|
||||
Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
|
||||
email:janvb@caselaboratories.com
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the Case Labs, Ltd nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*****************************************************************************/
|
||||
#include "q921.h"
|
||||
#include <stdlib.h>
|
||||
#include "mfifo.h"
|
||||
|
||||
/*****************************************************************************
|
||||
Global Tables & Variables.
|
||||
*****************************************************************************/
|
||||
Q921Data Q921DevSpace[Q921MAXTRUNK];
|
||||
int Q921HeaderSpace={0};
|
||||
|
||||
int (*Q921Tx21Proc)(int dev, unsigned char *, int)={NULL};
|
||||
int (*Q921Tx23Proc)(int dev, unsigned char *, int)={NULL};
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q921Init
|
||||
|
||||
Decription: Initialize the Q.921 stack so it is ready for use. This
|
||||
function MUST be called as part of initializing the
|
||||
application.
|
||||
|
||||
*****************************************************************************/
|
||||
void Q921Init()
|
||||
{
|
||||
int x;
|
||||
for(x=0; x<Q921MAXTRUNK;x++)
|
||||
{
|
||||
MFIFOCreate(Q921DevSpace[x].HDLCInQueue, Q921MAXHDLCSPACE, 10);
|
||||
Q921DevSpace[x].vr=0;
|
||||
Q921DevSpace[x].vs=0;
|
||||
Q921DevSpace[x].state=0;;
|
||||
}
|
||||
}
|
||||
|
||||
void Q921SetHeaderSpace(int hspace)
|
||||
{
|
||||
Q921HeaderSpace=hspace;
|
||||
}
|
||||
|
||||
void Q921SetTx21CB(int (*callback)(int dev, unsigned char *, int))
|
||||
{
|
||||
Q921Tx21Proc = callback;
|
||||
}
|
||||
|
||||
void Q921SetTx23CB(int (*callback)(int dev, unsigned char *, int))
|
||||
{
|
||||
Q921Tx23Proc = callback;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q921QueueHDLCFrame
|
||||
|
||||
Description: Called to receive and queue an incoming HDLC frame. Will
|
||||
queue this in Q921HDLCInQueue. The called must either call
|
||||
Q921Rx12 directly afterwards or signal Q921Rx12 to be called
|
||||
later. Q921Rx12 will read from the same queue and process
|
||||
the frame.
|
||||
|
||||
This function assumes that the message contains header
|
||||
space. This is removed for internal Q921 processing, but
|
||||
must be keept for I frames.
|
||||
|
||||
Parameters: trunk trunk #
|
||||
b ptr to frame;
|
||||
size size of frame in bytes
|
||||
|
||||
*****************************************************************************/
|
||||
int Q921QueueHDLCFrame(int trunk, char *b, int size)
|
||||
{
|
||||
return MFIFOWriteMes(Q921DevSpace[trunk].HDLCInQueue, b, size);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q921SendI
|
||||
|
||||
Description: Compose and Send I Frame to layer. Will receive an I frame
|
||||
with space for L2 header and fill out that header before
|
||||
it call Q921Tx21Proc.
|
||||
|
||||
Parameters: trunk trunk #
|
||||
Sapi Sapi
|
||||
cr C/R field.
|
||||
Tei Tei.
|
||||
pf P fiels octet 5
|
||||
mes ptr to I frame message.
|
||||
size size of message in bytes.
|
||||
|
||||
Return Value: 0 if failed, 1 if Send.
|
||||
|
||||
*****************************************************************************/
|
||||
int Q921SendI(int trunk, unsigned char Sapi, char cr, unsigned char Tei, char pf, char *mes, int size)
|
||||
{
|
||||
mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02);
|
||||
mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01;
|
||||
mes[Q921HeaderSpace+2] = Q921DevSpace[trunk].vs<<1;
|
||||
mes[Q921HeaderSpace+3] = (Q921DevSpace[trunk].vr<<1) | (pf & 0x01);
|
||||
Q921DevSpace[trunk].vs++;
|
||||
|
||||
return Q921Tx21Proc(trunk, mes, size);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q921SendRR
|
||||
|
||||
Description: Compose and send Receive Ready.
|
||||
|
||||
Parameters: trunk trunk #
|
||||
Sapi Sapi
|
||||
cr C/R field.
|
||||
Tei Tei.
|
||||
pf P/F fiels octet 5
|
||||
|
||||
Return Value: 0 if failed, 1 if Send.
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
int Q921SendRR(int trunk, int Sapi, int cr, int Tei, int pf)
|
||||
{
|
||||
char mes[400];
|
||||
|
||||
mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02);
|
||||
mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01;
|
||||
mes[Q921HeaderSpace+2] = 0x01;
|
||||
mes[Q921HeaderSpace+3] = (Q921DevSpace[trunk].vr<<1) | (pf & 0x01);
|
||||
|
||||
return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q921SendRNR
|
||||
|
||||
Description: Compose and send Receive Nor Ready
|
||||
|
||||
Parameters: trunk trunk #
|
||||
Sapi Sapi
|
||||
cr C/R field.
|
||||
Tei Tei.
|
||||
pf P/F fiels octet 5
|
||||
|
||||
Return Value: 0 if failed, 1 if Send.
|
||||
|
||||
*****************************************************************************/
|
||||
int Q921SendRNR(int trunk, int Sapi, int cr, int Tei, int pf)
|
||||
{
|
||||
char mes[400];
|
||||
|
||||
mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02);
|
||||
mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01;
|
||||
mes[Q921HeaderSpace+2] = 0x05;
|
||||
mes[Q921HeaderSpace+3] = (Q921DevSpace[trunk].vr<<1) | (pf & 0x01);
|
||||
|
||||
return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q921SendREJ
|
||||
|
||||
Description: Compose and Send Reject.
|
||||
|
||||
Parameters: trunk trunk #
|
||||
Sapi Sapi
|
||||
cr C/R field.
|
||||
Tei Tei.
|
||||
pf P/F fiels octet 5
|
||||
|
||||
Return Value: 0 if failed, 1 if Send.
|
||||
|
||||
*****************************************************************************/
|
||||
int Q921SendREJ(int trunk, int Sapi, int cr, int Tei, int pf)
|
||||
{
|
||||
char mes[400];
|
||||
|
||||
mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02);
|
||||
mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01;
|
||||
mes[Q921HeaderSpace+2] = 0x09;
|
||||
mes[Q921HeaderSpace+3] = (Q921DevSpace[trunk].vr<<1) | (pf & 0x01);
|
||||
|
||||
return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q921SendSABME
|
||||
|
||||
Description: Compose and send SABME
|
||||
|
||||
Parameters: trunk trunk #
|
||||
Sapi Sapi
|
||||
cr C/R field.
|
||||
Tei Tei.
|
||||
pf P fiels octet 4
|
||||
|
||||
Return Value: 0 if failed, 1 if Send.
|
||||
|
||||
*****************************************************************************/
|
||||
int Q921SendSABME(int trunk, int Sapi, int cr, int Tei, int pf)
|
||||
{
|
||||
char mes[400];
|
||||
|
||||
mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02);
|
||||
mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01;
|
||||
mes[Q921HeaderSpace+2] = 0x6f | ((pf<<4)&0x10);
|
||||
|
||||
return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q921SendDM
|
||||
|
||||
Description: Comose and Send DM (Disconnected Mode)
|
||||
|
||||
Parameters: trunk trunk #
|
||||
Sapi Sapi
|
||||
cr C/R field.
|
||||
Tei Tei.
|
||||
pf F fiels octet 4
|
||||
|
||||
Return Value: 0 if failed, 1 if Send.
|
||||
|
||||
*****************************************************************************/
|
||||
int Q921SendDM(int trunk, int Sapi, int cr, int Tei, int pf)
|
||||
{
|
||||
char mes[400];
|
||||
|
||||
mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02);
|
||||
mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01;
|
||||
mes[Q921HeaderSpace+2] = 0x0f | ((pf<<4)&0x10);
|
||||
|
||||
return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q921
|
||||
|
||||
Description:
|
||||
|
||||
Parameters: trunk trunk #
|
||||
Sapi Sapi
|
||||
cr C/R field.
|
||||
Tei Tei.
|
||||
pf P fiels octet 4
|
||||
|
||||
Return Value: 0 if failed, 1 if Send.
|
||||
|
||||
*****************************************************************************/
|
||||
//int Q921SendUI(...)
|
||||
//{
|
||||
//}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q921SendDISC
|
||||
|
||||
Description: Compose and Send Disconnect
|
||||
|
||||
Parameters: trunk trunk #
|
||||
Sapi Sapi
|
||||
cr C/R field.
|
||||
Tei Tei.
|
||||
pf P fiels octet 4
|
||||
|
||||
Return Value: 0 if failed, 1 if Send.
|
||||
|
||||
*****************************************************************************/
|
||||
int Q921SendDISC(int trunk, int Sapi, int cr, int Tei, int pf)
|
||||
{
|
||||
char mes[400];
|
||||
|
||||
mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02);
|
||||
mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01;
|
||||
mes[Q921HeaderSpace+2] = 0x43 | ((pf<<4)&0x10);
|
||||
|
||||
return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q921SendUA
|
||||
|
||||
Description: Compose and Send UA
|
||||
|
||||
Parameters: trunk trunk #
|
||||
Sapi Sapi
|
||||
cr C/R field.
|
||||
Tei Tei.
|
||||
pf F fiels octet 4
|
||||
|
||||
Return Value: 0 if failed, 1 if Send.
|
||||
|
||||
*****************************************************************************/
|
||||
int Q921SendUA(int trunk, int Sapi, int cr, int Tei, int pf)
|
||||
{
|
||||
char mes[400];
|
||||
|
||||
mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02);
|
||||
mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01;
|
||||
mes[Q921HeaderSpace+2] = 0x63 | ((pf<<4)&0x10);
|
||||
|
||||
return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q921
|
||||
|
||||
Description:
|
||||
|
||||
Parameters: trunk trunk #
|
||||
Sapi Sapi
|
||||
cr C/R field.
|
||||
Tei Tei.
|
||||
pf P fiels octet 5
|
||||
|
||||
Return Value: 0 if failed, 1 if Send.
|
||||
|
||||
*****************************************************************************/
|
||||
//int Q921SendFRMR(...)
|
||||
//{
|
||||
//}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q921
|
||||
|
||||
Description:
|
||||
|
||||
Parameters: trunk trunk #
|
||||
Sapi Sapi
|
||||
cr C/R field.
|
||||
Tei Tei.
|
||||
pf P fiels octet 5
|
||||
|
||||
Return Value: 0 if failed, 1 if Send.
|
||||
|
||||
*****************************************************************************/
|
||||
//int Q921SendXID(...)
|
||||
//{
|
||||
//}
|
||||
|
||||
int Q921ProcSABME(int trunk, char *mes, int size)
|
||||
{
|
||||
Q921DevSpace[trunk].vr=0;
|
||||
Q921DevSpace[trunk].vs=0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q921Rx12
|
||||
|
||||
Description: Called to process a message frame from layer 1. Will
|
||||
identify the message and call the proper 'processor' for
|
||||
layer 2 messages and forward I frames to the layer 3 entity.
|
||||
|
||||
Q921Rx12 will check the input fifo for a message, and if a
|
||||
message exist process one message before it exits. The caller
|
||||
must either call Q921Rx12 polling or keep track on #
|
||||
messages in the queue.
|
||||
|
||||
Parameters: trunk trunk #.
|
||||
|
||||
Return Value: # messages processed (always 1 or 0).
|
||||
|
||||
*****************************************************************************/
|
||||
int Q921Rx12(long trunk)
|
||||
{
|
||||
char *mes;
|
||||
int rs,size; /* receive size & Q921 frame size*/
|
||||
char *smes = MFIFOGetMesPtr(Q921DevSpace[trunk].HDLCInQueue, &size);
|
||||
if(smes != NULL)
|
||||
{
|
||||
rs = size - Q921HeaderSpace;
|
||||
mes = &smes[Q921HeaderSpace];
|
||||
/* check for I frame */
|
||||
if((mes[2] & 0x01) == 0)
|
||||
{
|
||||
if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */
|
||||
{
|
||||
Q921DevSpace[trunk].vr++;
|
||||
Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* todo: whatever*/
|
||||
}
|
||||
}
|
||||
|
||||
/* check for RR */
|
||||
else if(mes[2] ==0x01)
|
||||
{
|
||||
/* todo: check if RR is responce to I */
|
||||
Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01);
|
||||
}
|
||||
|
||||
/* check for RNR */
|
||||
/* check for REJ */
|
||||
/* check for SABME */
|
||||
else if((mes[2] & 0xef) == 0x6f)
|
||||
{
|
||||
Q921ProcSABME(trunk, mes, rs);
|
||||
Q921SendUA(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, (mes[2]&0x10)>>4);
|
||||
}
|
||||
|
||||
/* check for DM */
|
||||
/* check for UI */
|
||||
/* check for DISC */
|
||||
/* check for UA */
|
||||
/* check for FRMR */
|
||||
/* check for XID */
|
||||
|
||||
else
|
||||
{
|
||||
/* what the ? Issue an error */
|
||||
// Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs);
|
||||
/* todo: REJ or FRMR */
|
||||
}
|
||||
|
||||
MFIFOKillNext(Q921DevSpace[trunk].HDLCInQueue);
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,664 @@
|
|||
/*****************************************************************************
|
||||
|
||||
FileName: Q931.c
|
||||
|
||||
Contents: Implementation of Q.931 stack main interface functions.
|
||||
See q931.h for description.
|
||||
|
||||
License/Copyright:
|
||||
|
||||
Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
|
||||
email:janvb@caselaboratories.com
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the Case Labs, Ltd nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "Q931.h"
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Dialect function pointers tables.
|
||||
|
||||
The following function pointer arrays define pack/unpack functions and
|
||||
processing furnctions for the different Q.931 based dialects.
|
||||
|
||||
The arrays are initialized with pointers to dummy functions and later
|
||||
overrided with pointers to actual functions as new dialects are added.
|
||||
|
||||
The initial Q.931 will as an example define 2 dielects as it treats User
|
||||
and Network mode as separate ISDN dialects.
|
||||
|
||||
The API messages Q931AddProc, Q931AddMes, Q931AddIE are used to initialize
|
||||
these table entries during system inititialization of a stack.
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT);
|
||||
|
||||
L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size);
|
||||
L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
|
||||
|
||||
L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff);
|
||||
L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet);
|
||||
|
||||
void (*Q931CreateDialectCB[Q931MAXDLCT]) (L3UCHAR iDialect)=
|
||||
{
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
Q931State Q931st[Q931MAXSTATE];
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Core system tables and variables.
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
L3INT Q931L4HeaderSpace={0}; /* header space to be ignoder/inserted */
|
||||
/* at head of each message. */
|
||||
|
||||
L3INT Q931L2HeaderSpace = {4}; /* Q921 header space, sapi, tei etc */
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Main interface callback functions.
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
L3INT (*Q931Tx34Proc)(Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT);
|
||||
/* callback for messages to be send to */
|
||||
/* layer 4. */
|
||||
|
||||
L3INT (*Q931Tx32Proc)(Q931_TrunkInfo *pTrunk,L3UCHAR *,L3INT);
|
||||
/* callback ptr for messages to be send */
|
||||
/* to layer 2. */
|
||||
|
||||
void (*Q931ErrorProc)(Q931_TrunkInfo *pTrunk, L3INT,L3INT,L3INT);
|
||||
/* callback for error messages. */
|
||||
|
||||
L3ULONG (*Q931GetTimeProc) ()=NULL; /* callback for func reading time in ms */
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931SetL4HeaderSpace
|
||||
|
||||
Description: Set the # of bytes to be inserted/ignored at the head of
|
||||
each message. Q931 will issue a message with space for header
|
||||
and the user will use this to fill in whatever header info
|
||||
is required to support the architecture used.
|
||||
|
||||
*****************************************************************************/
|
||||
void Q931SetL4HeaderSpace(L3INT space)
|
||||
{
|
||||
Q931L4HeaderSpace = space;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931SetL2HeaderSpace
|
||||
|
||||
Description: Set the # of bytes to be inserted/ignored at the head of
|
||||
each message. Q931 will issue a message with space for header
|
||||
and the user will use this to fill in whatever header info
|
||||
is required to support the architecture used.
|
||||
|
||||
*****************************************************************************/
|
||||
void Q931SetL2HeaderSpace(L3INT space)
|
||||
{
|
||||
Q931L2HeaderSpace = space;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931
|
||||
|
||||
Description: Dummy function for message processing.
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q931ProcDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b,L3INT c)
|
||||
{
|
||||
return Q931E_INTERNAL;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931
|
||||
|
||||
Description: Dummy function for message processing
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q931UmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size)
|
||||
{
|
||||
return Q931E_UNKNOWN_MESSAGE;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931
|
||||
|
||||
Description: Dummy function for message processing
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q931UieDummy(Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
|
||||
{
|
||||
return Q931E_UNKNOWN_IE;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931
|
||||
|
||||
Description: Dummy function for message processing
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q931PmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
|
||||
{
|
||||
return Q931E_UNKNOWN_MESSAGE;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931PieDummy
|
||||
|
||||
Description: Dummy function for message processing
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q931PieDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
|
||||
{
|
||||
return Q931E_UNKNOWN_IE;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931TxDummy
|
||||
|
||||
Description: Dummy function for message processing
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q931TxDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT n)
|
||||
{
|
||||
return Q931E_MISSING_CB;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931ErrorDummy
|
||||
|
||||
Description: Dummy function for error processing
|
||||
|
||||
*****************************************************************************/
|
||||
void Q931ErrorDummy(Q931_TrunkInfo *pTrunk,L3INT a, L3INT b, L3INT c)
|
||||
{
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931Initialize
|
||||
|
||||
Description: This function Initialize the stack.
|
||||
|
||||
Will set up the trunk array, channel
|
||||
arrays and initialize Q931 function arrays before it finally
|
||||
set up EuroISDN processing with User as diealect 0 and
|
||||
Network as dialect 1.
|
||||
|
||||
Note: Initialization of other stacks should be inserted after
|
||||
the initialization of EuroISDN.
|
||||
|
||||
*****************************************************************************/
|
||||
void Q931Initialize()
|
||||
{
|
||||
L3INT x,y;
|
||||
|
||||
/* Secure the callbacks to default procs */
|
||||
Q931Tx34Proc = Q931TxDummy;
|
||||
Q931Tx32Proc = Q931TxDummy;
|
||||
Q931ErrorProc = Q931ErrorDummy;
|
||||
|
||||
/* The user will only add the message handlers and IE handlers he need, */
|
||||
/* so we need to initialize every single entry to a default function */
|
||||
/* that will throw an appropriate error if they are ever called. */
|
||||
for(x=0;x< Q931MAXDLCT;x++)
|
||||
{
|
||||
for(y=0;y<Q931MAXMES;y++)
|
||||
{
|
||||
Q931Proc[x][y] = Q931ProcDummy;
|
||||
Q931Umes[x][y] = Q931UmesDummy;
|
||||
Q931Pmes[x][y] = Q931PmesDummy;
|
||||
}
|
||||
for(y=0;y<Q931MAXIE;y++)
|
||||
{
|
||||
Q931Pie[x][y] = Q931PieDummy;
|
||||
Q931Uie[x][y] = Q931UieDummy;
|
||||
}
|
||||
}
|
||||
|
||||
if(Q931CreateDialectCB[0] == NULL)
|
||||
Q931AddDialect(0, Q931CreateTE);
|
||||
|
||||
if(Q931CreateDialectCB[1] == NULL)
|
||||
Q931AddDialect(1, Q931CreateNT);
|
||||
|
||||
/* The last step we do is to call the callbacks to create the dialects */
|
||||
for(x=0; x< Q931MAXDLCT; x++)
|
||||
{
|
||||
if(Q931CreateDialectCB[x] != NULL)
|
||||
{
|
||||
Q931CreateDialectCB[x]((L3UCHAR)x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931TimeTick
|
||||
|
||||
Description: Called periodically from an external source to allow the
|
||||
stack to process and maintain it's own timers.
|
||||
|
||||
Parameters: ms[IN] Milliseconds since last call.
|
||||
|
||||
Return Value: none
|
||||
|
||||
*****************************************************************************/
|
||||
void Q931TimeTick(L3ULONG ms)
|
||||
{
|
||||
ms=ms; // avoid warning for now.
|
||||
|
||||
// TODO: Loop through all active calls, check timers and call timour procs
|
||||
// if timers are expired.
|
||||
// Implement an function array so each dialect can deal with their own
|
||||
// timeouts.
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931Rx23
|
||||
|
||||
Description: Receive message from layer 2 (LAPD). Receiving a message
|
||||
is always done in 2 steps. First the message must be
|
||||
interpreted and translated to a static struct. Secondly
|
||||
the message is processed and responded to.
|
||||
|
||||
The Q.931 message contains a static header that is
|
||||
interpreated in his function. The rest is interpreted
|
||||
in a sub function according to mestype.
|
||||
|
||||
Parameters: pTrunk [IN] Ptr to trunk info.
|
||||
buf [IN] Ptr to buffer containing message.
|
||||
Size [IN] Size of message.
|
||||
|
||||
Return Value: Error Code. 0 = No Error, < 0 :error, > 0 : Warning
|
||||
see q931errors.h for details.
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT Size)
|
||||
{
|
||||
L3UCHAR *Mes = &buf[Q931L2HeaderSpace];
|
||||
L3INT RetCode = Q931E_NO_ERROR;
|
||||
|
||||
Q931mes_Alerting * m = (Q931mes_Alerting*)Mes;
|
||||
L3INT ISize;
|
||||
L3INT IOff = 0;
|
||||
|
||||
/* Protocol Discriminator */
|
||||
m->ProtDisc = Mes[IOff++];
|
||||
|
||||
/* CRV */
|
||||
m->CRV = Q931Uie_CRV(pTrunk, Mes,m->buf, &IOff, &ISize);
|
||||
|
||||
/* Message Type */
|
||||
m->MesType = Mes[IOff++];
|
||||
|
||||
/* Call table proc to unpack codec message */
|
||||
RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, pTrunk->L3Buf,Q931L4HeaderSpace,Size- Q931L4HeaderSpace);
|
||||
if(RetCode >= Q931E_NO_ERROR)
|
||||
{
|
||||
RetCode=Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2);
|
||||
}
|
||||
|
||||
return RetCode;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931Tx34
|
||||
|
||||
Description: Called from the stac to send a message to layer 4.
|
||||
|
||||
Parameters: Mes[IN] Ptr to message buffer.
|
||||
Size[IN] Message size in bytes.
|
||||
|
||||
Return Value: Error Code. 0 = No Error, < 0 :error, > 0 : Warning
|
||||
see q931errors.h for details.
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size)
|
||||
{
|
||||
return Q931Tx34Proc(pTrunk, Mes, Size);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931Rx43
|
||||
|
||||
Description: Receive message from Layer 4 (application).
|
||||
|
||||
Parameters: pTrunk[IN] Trunk #.
|
||||
buf[IN] Message Pointer.
|
||||
Size[IN] Message size in bytes.
|
||||
|
||||
Return Value: Error Code. 0 = No Error, < 0 :error, > 0 : Warning
|
||||
see q931errors.h for details.
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q931Rx43(Q931_TrunkInfo *pTrunk,L3UCHAR * buf, L3INT Size)
|
||||
{
|
||||
Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace];
|
||||
L3INT RetCode = Q931E_NO_ERROR;
|
||||
|
||||
RetCode=Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk,buf,4);
|
||||
|
||||
return RetCode;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931Tx32
|
||||
|
||||
Description: Called from the stack to send a message to L2. The input is
|
||||
always a non-packed message so it will first make a proper
|
||||
call to create a packed message before it transmits that
|
||||
message to layer 2.
|
||||
|
||||
Parameters: pTrunk[IN] Trunk #
|
||||
buf[IN] Ptr to message buffer.
|
||||
Size[IN] Message size in bytes.
|
||||
|
||||
Return Value: Error Code. 0 = No Error, < 0 :error, > 0 : Warning
|
||||
see q931errors.h for details.
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size)
|
||||
{
|
||||
L3INT OSize;
|
||||
Q931mes_Alerting *ptr = (Q931mes_Alerting*)Mes;
|
||||
L3INT RetCode = Q931E_NO_ERROR;
|
||||
L3INT iDialect = pTrunk->Dialect;
|
||||
|
||||
/* Call pack function through table. */
|
||||
RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk,Mes,Size,&pTrunk->L2Buf[Q931L2HeaderSpace], &OSize);
|
||||
if(RetCode >= Q931E_NO_ERROR)
|
||||
{
|
||||
RetCode = Q931Tx32Proc(pTrunk, pTrunk->L2Buf, Size);
|
||||
}
|
||||
|
||||
return RetCode;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931SetError
|
||||
|
||||
Description: Called from the stack to indicate an error.
|
||||
|
||||
Parameters: ErrID ID of ie or message causing error.
|
||||
ErrPar1 Error parameter 1
|
||||
ErrPar2 Error parameter 2.
|
||||
|
||||
|
||||
*****************************************************************************/
|
||||
void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2)
|
||||
{
|
||||
Q931ErrorProc(pTrunk,ErrID, ErrPar1, ErrPar2);
|
||||
}
|
||||
|
||||
void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size))
|
||||
{
|
||||
Q931Tx34Proc = Q931Tx34Par;
|
||||
}
|
||||
|
||||
void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size))
|
||||
{
|
||||
Q931Tx32Proc = Q931Tx32Par;
|
||||
}
|
||||
|
||||
void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT))
|
||||
{
|
||||
Q931ErrorProc = Q931ErrorPar;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931CreateCRV
|
||||
|
||||
Description: Create a CRV entry and return it's index. The function will
|
||||
locate a free entry in the call tables allocate it and
|
||||
allocate a unique CRV value attached to it.
|
||||
|
||||
Parameters: pTrunk [IN] Trunk number
|
||||
callindex [OUT] return call table index.
|
||||
|
||||
Return Value: Error Code. 0 = No Error, < 0 :error, > 0 : Warning
|
||||
see q931errors.h for details.
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex)
|
||||
{
|
||||
L3INT CRV = Q931GetUniqueCRV(pTrunk);
|
||||
|
||||
return Q931AllocateCRV(pTrunk, CRV, callIndex);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931AllocateCRV
|
||||
|
||||
Description: Allocate a call table entry and assigns the given CRV value
|
||||
to it.
|
||||
|
||||
Parameters: pTrunk [IN] Trunk number
|
||||
iCRV [IN] Call Reference Value.
|
||||
callindex [OUT] return call table index.
|
||||
|
||||
Return Value: Error Code. 0 = No Error, < 0 :error, > 0 : Warning
|
||||
see q931errors.h for details.
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex)
|
||||
{
|
||||
L3INT x;
|
||||
for(x=0; x < Q931MAXCALLPERTRUNK; x++)
|
||||
{
|
||||
if(!pTrunk->call[x].InUse)
|
||||
{
|
||||
pTrunk->call[x].CRV = iCRV;
|
||||
pTrunk->call[x].BChan = 255;
|
||||
pTrunk->call[x].State = 0; /* null state - idle */
|
||||
pTrunk->call[x].TimerID = 0; /* no timer running */
|
||||
pTrunk->call[x].Timer = 0;
|
||||
pTrunk->call[x].InUse = 1; /* mark as used */
|
||||
*callIndex = x;
|
||||
return Q931E_NO_ERROR;
|
||||
}
|
||||
}
|
||||
return Q931E_TOMANYCALLS;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931GetCallState
|
||||
|
||||
Description: Look up CRV and return current call state. A non existing
|
||||
CRV is the same as state zero (0).
|
||||
|
||||
Parameters: pTrunk [IN] Trunk number.
|
||||
iCRV [IN] CRV
|
||||
|
||||
Return Value: Call State.
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV)
|
||||
{
|
||||
L3INT x;
|
||||
for(x=0; x < Q931MAXCALLPERTRUNK; x++)
|
||||
{
|
||||
if(!pTrunk->call[x].InUse)
|
||||
{
|
||||
if(pTrunk->call[x].CRV == iCRV)
|
||||
{
|
||||
return pTrunk->call[x].State;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0; /* assume state zero for non existing CRV's */
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931StartTimer
|
||||
|
||||
Description: Start a timer.
|
||||
|
||||
Parameters: pTrunk Trunk number
|
||||
callindex call index.
|
||||
iTimer timer id
|
||||
*****************************************************************************/
|
||||
L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iTimerID)
|
||||
{
|
||||
pTrunk->call[callIndex].Timer = Q931GetTime();
|
||||
pTrunk->call[callIndex].TimerID = iTimerID;
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3INT iTimerID)
|
||||
{
|
||||
if(pTrunk->call[callindex].TimerID == iTimerID)
|
||||
pTrunk->call[callindex].TimerID = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState)
|
||||
{
|
||||
pTrunk->call[callIndex].State = iState;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3ULONG Q931GetTime()
|
||||
{
|
||||
L3ULONG tNow;
|
||||
static L3ULONG tLast={0};
|
||||
if(Q931GetTimeProc != NULL)
|
||||
{
|
||||
tNow = Q931GetTimeProc();
|
||||
if(tNow < tLast) /* wrapped */
|
||||
{
|
||||
// todo
|
||||
}
|
||||
tLast = tNow;
|
||||
}
|
||||
return tNow;
|
||||
}
|
||||
|
||||
void Q931SetGetTimeCB(L3ULONG (*callback)())
|
||||
{
|
||||
Q931GetTimeProc = callback;
|
||||
}
|
||||
|
||||
L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex)
|
||||
{
|
||||
L3INT x;
|
||||
for(x=0; x < Q931MAXCALLPERTRUNK; x++)
|
||||
{
|
||||
if(!pTrunk->call[x].InUse)
|
||||
{
|
||||
if(pTrunk->call[x].CRV == crv)
|
||||
{
|
||||
*callindex = x;
|
||||
return Q931E_NO_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Q931E_INVALID_CRV;
|
||||
}
|
||||
|
||||
|
||||
void Q931AddDialect(L3UCHAR i, void (*callback)(L3UCHAR iD ))
|
||||
{
|
||||
if(i < Q931MAXDLCT)
|
||||
{
|
||||
Q931CreateDialectCB[i] = callback;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function: Q931AddStateEntry
|
||||
|
||||
Description: Find an empty entry in the dialects state table and add this
|
||||
entry.
|
||||
*****************************************************************************/
|
||||
void Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir)
|
||||
{
|
||||
int x;
|
||||
for(x=0; x < Q931MAXSTATE; x++)
|
||||
{
|
||||
if(Q931st[x].Message == 0)
|
||||
{
|
||||
Q931st[x].State = iState;
|
||||
Q931st[x].Message = iMes;
|
||||
Q931st[x].Direction = cDir;
|
||||
// TODO Sort table and use bsearch
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function: Q931IsEventLegal
|
||||
|
||||
Description: Check state table for matching criteria to indicate if this
|
||||
Message is legal in this state or not.
|
||||
|
||||
Note: Someone write a bsearch or invent something smart here
|
||||
please - sequensial is ok for now.
|
||||
*****************************************************************************/
|
||||
L3BOOL Q931IsEventLegal(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir)
|
||||
{
|
||||
int x;
|
||||
// TODO Sort table and use bsearch
|
||||
for(x=0; x < Q931MAXSTATE; x++)
|
||||
{
|
||||
if( Q931st[x].State == iState
|
||||
&& Q931st[x].Message == iMes
|
||||
&& Q931st[x].Direction == cDir)
|
||||
{
|
||||
return L3TRUE;
|
||||
}
|
||||
}
|
||||
return L3FALSE;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,614 @@
|
|||
/*****************************************************************************
|
||||
|
||||
FileName: Q931api.c
|
||||
|
||||
Contents: api (Application Programming Interface) functions.
|
||||
See q931.h for description.
|
||||
|
||||
License/Copyright:
|
||||
|
||||
Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
|
||||
email:janvb@caselaboratories.com
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the Case Labs, Ltd nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "Q931.h"
|
||||
#include "memory.h"
|
||||
|
||||
/*
|
||||
L3INT Q931CreateMesIndex(L3INT mc)
|
||||
{
|
||||
if(mc < 0 || mc > 127 )
|
||||
return Q931E_INTERNAL;
|
||||
|
||||
if(Q931MesCount >127)
|
||||
return Q931E_INTERNAL;
|
||||
|
||||
Q931MesIndex[mc] = Q931MesCount ++;
|
||||
|
||||
return Q931E_NO_ERROR;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
L3INT Q931CreateIEIndex(L3INT iec)
|
||||
{
|
||||
if(iec < 0 || iec > 127 )
|
||||
return Q931E_INTERNAL;
|
||||
|
||||
if(Q931IECount > 127)
|
||||
return Q931E_INTERNAL;
|
||||
|
||||
Q931IEIndex[iec] = Q931IECount ++;
|
||||
|
||||
return Q931E_NO_ERROR;
|
||||
}
|
||||
*/
|
||||
|
||||
void Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk)
|
||||
{
|
||||
int y;
|
||||
pTrunk->LastCRV = 0;
|
||||
pTrunk->Dialect = 0;
|
||||
pTrunk->Enabled = 0;
|
||||
pTrunk->TrunkType = Q931_TrType_E1;
|
||||
pTrunk->NetUser = Q931_TE;
|
||||
pTrunk->TrunkState = 0;
|
||||
for(y=0; y < Q931MAXCHPERTRUNK; y++)
|
||||
{
|
||||
pTrunk->ch[y].Available = 1;
|
||||
|
||||
/* Set up E1 scheme by default */
|
||||
if(y==0)
|
||||
{
|
||||
pTrunk->ch[y].ChanType = Q931_ChType_Sync;
|
||||
}
|
||||
else if(y==16)
|
||||
{
|
||||
pTrunk->ch[y].ChanType = Q931_ChType_D;
|
||||
}
|
||||
else
|
||||
{
|
||||
pTrunk->ch[y].ChanType = Q931_ChType_B;
|
||||
}
|
||||
}
|
||||
|
||||
for(y=0; y < Q931MAXCALLPERTRUNK; y++)
|
||||
{
|
||||
pTrunk->call[y].InUse = 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect,
|
||||
L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom),
|
||||
L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size),
|
||||
L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
|
||||
)
|
||||
{
|
||||
if(Q931ProcFunc != NULL)
|
||||
Q931Proc[dialect][mes] = Q931ProcFunc;
|
||||
if(Q931UmesFunc != NULL)
|
||||
Q931Umes[dialect][mes] = Q931UmesFunc;
|
||||
if(Q931PmesFunc != NULL)
|
||||
Q931Pmes[dialect][mes] = Q931PmesFunc;
|
||||
}
|
||||
|
||||
void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect,
|
||||
L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet),
|
||||
L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
|
||||
)
|
||||
{
|
||||
if(Q931PieProc != NULL)
|
||||
Q931Pie[dialect][iec] = Q931PieProc;
|
||||
if(Q931UieProc != NULL)
|
||||
Q931Uie[dialect][iec] = Q931UieProc;
|
||||
}
|
||||
|
||||
#define trampoline(x) {x * t = (x *)pm; s = &t->buf[0];}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931GetIEBuf
|
||||
|
||||
Description: Return a ptr to the buf used for IE in the message.
|
||||
|
||||
*****************************************************************************/
|
||||
L3UCHAR * Q931GetIEBuf(L3UCHAR *pm)
|
||||
{
|
||||
L3UCHAR * s=NULL;
|
||||
Q931mes_Alerting * pMes= (Q931mes_Alerting *)pm;
|
||||
switch(pMes->MesType)
|
||||
{
|
||||
case Q931mes_ALERTING :
|
||||
trampoline(Q931mes_Alerting);
|
||||
break;
|
||||
|
||||
case Q931mes_CALL_PROCEEDING :
|
||||
trampoline(Q931mes_CallProceeding);
|
||||
break;
|
||||
|
||||
case Q931mes_CONNECT :
|
||||
trampoline(Q931mes_Connect);
|
||||
break;
|
||||
|
||||
case Q931mes_CONNECT_ACKNOWLEDGE :
|
||||
trampoline(Q931mes_ConnectAck);
|
||||
break;
|
||||
|
||||
case Q931mes_PROGRESS :
|
||||
trampoline(Q931mes_Progress);
|
||||
break;
|
||||
|
||||
case Q931mes_SETUP :
|
||||
trampoline(Q931mes_Setup);
|
||||
break;
|
||||
|
||||
case Q931mes_SETUP_ACKNOWLEDGE :
|
||||
trampoline(Q931mes_SetupAck);
|
||||
break;
|
||||
|
||||
case Q931mes_RESUME :
|
||||
trampoline(Q931mes_Resume);
|
||||
break;
|
||||
|
||||
case Q931mes_RESUME_ACKNOWLEDGE :
|
||||
trampoline(Q931mes_ResumeAck);
|
||||
break;
|
||||
|
||||
case Q931mes_RESUME_REJECT :
|
||||
trampoline(Q931mes_ResumeReject);
|
||||
break;
|
||||
|
||||
case Q932mes_RETRIEVE :
|
||||
trampoline(Q932mes_Retrieve);
|
||||
break;
|
||||
|
||||
case Q932mes_RETRIEVE_ACKNOWLEDGE :
|
||||
trampoline(Q932mes_RetrieveAck);
|
||||
break;
|
||||
|
||||
case Q932mes_RETRIEVE_REJECT :
|
||||
trampoline(Q932mes_RetrieveReject);
|
||||
break;
|
||||
|
||||
case Q931mes_SUSPEND :
|
||||
trampoline(Q931mes_Suspend);
|
||||
break;
|
||||
|
||||
case Q931mes_SUSPEND_ACKNOWLEDGE :
|
||||
trampoline(Q931mes_SuspendAck);
|
||||
break;
|
||||
|
||||
case Q931mes_SUSPEND_REJECT :
|
||||
trampoline(Q931mes_SuspendReject);
|
||||
break;
|
||||
|
||||
case Q931mes_USER_INFORMATION :
|
||||
trampoline(Q931mes_UserInformation);
|
||||
break;
|
||||
|
||||
case Q931mes_DISCONNECT :
|
||||
trampoline(Q931mes_Disconnect);
|
||||
break;
|
||||
|
||||
case Q931mes_RELEASE :
|
||||
trampoline(Q931mes_Release);
|
||||
break;
|
||||
|
||||
case Q931mes_RELEASE_COMPLETE :
|
||||
trampoline(Q931mes_ReleaseComplete);
|
||||
break;
|
||||
|
||||
case Q931mes_RESTART :
|
||||
trampoline(Q931mes_Restart);
|
||||
break;
|
||||
|
||||
case Q931mes_RESTART_ACKNOWLEDGE :
|
||||
trampoline(Q931mes_RestartAck);
|
||||
break;
|
||||
|
||||
case Q931mes_CONGESTION_CONTROL :
|
||||
trampoline(Q931mes_CongestionControl);
|
||||
break;
|
||||
|
||||
// case Q931mes_FACILITY :
|
||||
// trampoline(Q931mes_Facility);
|
||||
// break;
|
||||
|
||||
case Q931mes_INFORMATION :
|
||||
trampoline(Q931mes_Information);
|
||||
break;
|
||||
|
||||
case Q931mes_NOTIFY :
|
||||
trampoline(Q931mes_Notify);
|
||||
break;
|
||||
|
||||
// case Q931mes_REGISTER :
|
||||
// trampoline(Q931mes_Register);
|
||||
// break;
|
||||
|
||||
case Q931mes_STATUS :
|
||||
trampoline(Q931mes_Status);
|
||||
break;
|
||||
|
||||
case Q931mes_STATUS_ENQUIRY :
|
||||
trampoline(Q931mes_StatusEnquiry);
|
||||
break;
|
||||
|
||||
case Q931mes_SEGMENT :
|
||||
trampoline(Q931mes_Segment);
|
||||
break;
|
||||
|
||||
default:
|
||||
s = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
L3INT Q931GetMesSize(L3UCHAR *pMes)
|
||||
{
|
||||
|
||||
L3UCHAR *p = Q931GetIEBuf(pMes);
|
||||
L3INT Size = (L3INT)(p - pMes);
|
||||
return Size;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: q931AppendIE
|
||||
|
||||
Description: Append IE to the message.
|
||||
|
||||
Parameters: pm Ptr to message.
|
||||
pi Ptr to information element
|
||||
|
||||
Return Value ie setting
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
ie Q931AppendIE( L3UCHAR *pm, L3UCHAR *pi)
|
||||
{
|
||||
ie IE = 0;
|
||||
Q931mes_Alerting * pMes= (Q931mes_Alerting *)pm;
|
||||
Q931ie_BearerCap * pIE= (Q931ie_BearerCap *)pi;
|
||||
L3INT iISize = pIE->Size;
|
||||
|
||||
L3UCHAR *pBuf = Q931GetIEBuf(pm);
|
||||
L3INT Off = pMes->Size - (pBuf - pm);
|
||||
IE = Off | 0x8000;
|
||||
|
||||
memcpy(&pm[pMes->Size], pi, iISize);
|
||||
|
||||
pMes->Size += iISize;
|
||||
|
||||
return IE;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
*****************************************************************************/
|
||||
L3INT Q931GetUniqueCRV(Q931_TrunkInfo *pTrunk)
|
||||
{
|
||||
static L3INT crv={1};
|
||||
return crv++;
|
||||
}
|
||||
|
||||
L3INT Q931InitMesSetup(Q931mes_Setup *pMes)
|
||||
{
|
||||
pMes->ProtDisc = 0x80;
|
||||
pMes->CRV = 0; /* CRV to be allocated, might be receive*/
|
||||
pMes->MesType = Q931mes_SETUP;
|
||||
|
||||
pMes->Size = Q931GetMesSize((L3UCHAR*)pMes);
|
||||
|
||||
pMes->SendComplete =0; /* Sending Complete */
|
||||
pMes->RepeatInd =0; /* Repeat Indicator */
|
||||
pMes->BearerCap =0; /* Bearer Capability */
|
||||
pMes->ChanID =0; /* Channel ID */
|
||||
pMes->ProgInd =0; /* Progress Indicator */
|
||||
pMes->NetFac =0; /* Network-specific facilities */
|
||||
pMes->Display =0; /* Display */
|
||||
pMes->DateTime =0; /* Date/Time */
|
||||
pMes->KeypadFac =0; /* Keypad Facility */
|
||||
pMes->Signal =0; /* Signal */
|
||||
pMes->CallingNum =0; /* Calling party number */
|
||||
pMes->CallingSub =0; /* Calling party sub address */
|
||||
pMes->CalledNum =0; /* Called party number */
|
||||
pMes->CalledSub =0; /* Called party sub address */
|
||||
pMes->TransNetSel =0; /* Transit network selection */
|
||||
pMes->LLRepeatInd =0; /* Repeat Indicator 2 LLComp */
|
||||
pMes->LLComp =0; /* Low layer compatibility */
|
||||
pMes->HLComp =0; /* High layer compatibility */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931InitMesResume(Q931mes_Resume * pMes)
|
||||
{
|
||||
pMes->ProtDisc = 0x80;
|
||||
pMes->CRV = 0; /* CRV to be allocated, might be receive*/
|
||||
pMes->MesType = Q931mes_RESUME;
|
||||
|
||||
pMes->Size = Q931GetMesSize((L3UCHAR*)pMes);
|
||||
pMes->CallID = 0; /* Channel Identification */
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931InitIEBearerCap(Q931ie_BearerCap *pIE)
|
||||
{
|
||||
pIE->IEId = Q931ie_BEARER_CAPABILITY;
|
||||
pIE->Size = sizeof(Q931ie_BearerCap);
|
||||
pIE->CodStand = 0;
|
||||
pIE->ITC = 0;
|
||||
pIE->TransMode = 0;
|
||||
pIE->ITR = 0x10;
|
||||
pIE->RateMul = 0;
|
||||
|
||||
pIE->Layer1Ident = 0;
|
||||
pIE->UIL1Prot = 0; /* User Information Layer 1 Protocol */
|
||||
pIE->SyncAsync = 0; /* Sync/Async */
|
||||
pIE->Negot = 0;
|
||||
pIE->UserRate = 0;
|
||||
pIE->InterRate = 0; /* Intermediate Rate */
|
||||
pIE->NIConTx = 0;
|
||||
pIE->NIConRx = 0;
|
||||
pIE->FlowCtlTx = 0; /* Flow control on Tx */
|
||||
pIE->FlowCtlRx = 0; /* Flow control on Rx */
|
||||
pIE->HDR = 0;
|
||||
pIE->MultiFrame = 0; /* Multi frame support */
|
||||
pIE->Mode = 0;
|
||||
pIE->LLInegot = 0;
|
||||
pIE->Assignor = 0; /* Assignor/assignee */
|
||||
pIE->InBandNeg = 0; /* In-band/out-band negot. */
|
||||
pIE->NumStopBits = 0; /* Number of stop bits */
|
||||
pIE->NumDataBits = 0; /* Number of data bits. */
|
||||
pIE->Parity = 0;
|
||||
pIE->DuplexMode = 0;
|
||||
pIE->ModemType = 0;
|
||||
pIE->Layer2Ident = 0;
|
||||
pIE->UIL2Prot = 0; /* User Information Layer 2 Protocol */
|
||||
pIE->Layer3Ident = 0;
|
||||
pIE->UIL3Prot = 0; /* User Information Layer 3 Protocol */
|
||||
pIE->AL3Info1 = 0;
|
||||
pIE->AL3Info2 = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931InitIEChanID(Q931ie_ChanID *pIE)
|
||||
{
|
||||
pIE->IEId = Q931ie_CHANNEL_IDENTIFICATION;
|
||||
pIE->Size = sizeof(Q931ie_ChanID);
|
||||
pIE->IntIDPresent = 0; /* Int. id. present */
|
||||
pIE->IntType = 0; /* Int. type */
|
||||
pIE->PrefExcl = 0; /* Pref./Excl. */
|
||||
pIE->DChanInd = 0; /* D-channel ind. */
|
||||
pIE->InfoChanSel = 0; /* Info. channel selection */
|
||||
pIE->InterfaceID = 0; /* Interface identifier */
|
||||
pIE->CodStand = 0; /* Code standard */
|
||||
pIE->NumMap = 0; /* Number/Map */
|
||||
pIE->ChanMapType = 0; /* Channel type/Map element type */
|
||||
pIE->ChanSlot = 0; /* Channel number/Slot map */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931InitIEProgInd(Q931ie_ProgInd * pIE)
|
||||
{
|
||||
pIE->IEId = Q931ie_PROGRESS_INDICATOR;
|
||||
pIE->Size = sizeof(Q931ie_ProgInd);
|
||||
pIE->CodStand = 0; /* Coding standard */
|
||||
pIE->Location = 0; /* Location */
|
||||
pIE->ProgDesc = 0; /* Progress description */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931InitIENetFac(Q931ie_NetFac * pIE)
|
||||
{
|
||||
pIE->IEId = Q931ie_NETWORK_SPECIFIC_FACILITIES;
|
||||
pIE->Size = sizeof(Q931ie_NetFac);
|
||||
pIE->LenNetID = 0; /* Length of network facilities id. */
|
||||
pIE->TypeNetID = 0; /* Type of network identification */
|
||||
pIE->NetIDPlan = 0; /* Network identification plan. */
|
||||
pIE->NetFac = 0; /* Network specific facility spec. */
|
||||
pIE->NetID[0] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931InitIEDisplay(Q931ie_Display * pIE)
|
||||
{
|
||||
pIE->IEId = Q931ie_DISPLAY;
|
||||
pIE->Size = sizeof(Q931ie_Display);
|
||||
pIE->Display[0] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931InitIEDateTime(Q931ie_DateTime * pIE)
|
||||
{
|
||||
pIE->IEId = Q931ie_DATETIME;
|
||||
pIE->Size = sizeof(Q931ie_DateTime);
|
||||
pIE->Year = 0; /* Year */
|
||||
pIE->Month = 0; /* Month */
|
||||
pIE->Day = 0; /* Day */
|
||||
pIE->Hour = 0; /* Hour */
|
||||
pIE->Minute = 0; /* Minute */
|
||||
pIE->Second = 0; /* Second */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931InitIEKeypadFac(Q931ie_KeypadFac * pIE)
|
||||
{
|
||||
pIE->IEId = Q931ie_KEYPAD_FACILITY;
|
||||
pIE->Size = sizeof(Q931ie_KeypadFac);
|
||||
pIE->KeypadFac[0] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931InitIESignal(Q931ie_Signal * pIE)
|
||||
{
|
||||
pIE->IEId = Q931ie_SIGNAL;
|
||||
pIE->Size = sizeof(Q931ie_Signal);
|
||||
pIE->Signal = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931InitIECallingNum(Q931ie_CallingNum * pIE)
|
||||
{
|
||||
pIE->IEId = Q931ie_CALLING_PARTY_NUMBER;
|
||||
pIE->Size = sizeof(Q931ie_CallingNum);
|
||||
pIE->TypNum = 0; /* Type of number */
|
||||
pIE->NumPlanID = 0; /* Numbering plan identification */
|
||||
pIE->PresInd = 0; /* Presentation indicator */
|
||||
pIE->ScreenInd = 0; /* Screening indicator */
|
||||
pIE->Digit[0] = 0; /* Number digits (IA5) */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931InitIECallingSub(Q931ie_CallingSub * pIE)
|
||||
{
|
||||
pIE->IEId = Q931ie_CALLING_PARTY_SUBADDRESS;
|
||||
pIE->Size = sizeof(Q931ie_CallingSub);
|
||||
pIE->TypNum = 0; /* Type of subaddress */
|
||||
pIE->OddEvenInd = 0; /* Odd/Even indicator */
|
||||
pIE->Digit[0] = 0; /* Digits */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931InitIECalledNum(Q931ie_CalledNum * pIE)
|
||||
{
|
||||
pIE->IEId = Q931ie_CALLED_PARTY_NUMBER;
|
||||
pIE->Size = sizeof(Q931ie_CalledNum);
|
||||
pIE->TypNum = 0; /* Type of Number */
|
||||
pIE->NumPlanID = 0; /* Numbering plan identification */
|
||||
pIE->Digit[0] = 0; /* Digit (IA5) */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931InitIECalledSub(Q931ie_CalledSub * pIE)
|
||||
{
|
||||
pIE->IEId = Q931ie_CALLED_PARTY_SUBADDRESS;
|
||||
pIE->Size = sizeof(Q931ie_CalledSub);
|
||||
pIE->TypNum = 0; /* Type of subaddress */
|
||||
pIE->OddEvenInd = 0; /* Odd/Even indicator */
|
||||
pIE->Digit[0] = 0; /* Digits */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931InitIETransNetSel(Q931ie_TransNetSel * pIE)
|
||||
{
|
||||
pIE->IEId = Q931ie_TRANSIT_NETWORK_SELECTION;
|
||||
pIE->Size = sizeof(Q931ie_TransNetSel);
|
||||
pIE->Type = 0; /* Type of network identifier */
|
||||
pIE->NetIDPlan = 0; /* Network idetification plan */
|
||||
pIE->NetID[0] = 0; /* Network identification(IA5) */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931InitIELLComp(Q931ie_LLComp * pIE)
|
||||
{
|
||||
pIE->IEId = Q931ie_LOW_LAYER_COMPATIBILITY;
|
||||
pIE->Size = sizeof(Q931ie_LLComp);
|
||||
|
||||
pIE->CodStand = 0; /* Coding standard */
|
||||
pIE->ITransCap = 0; /* Information transfer capability */
|
||||
pIE->NegotInd = 0; /* Negot indic. */
|
||||
pIE->TransMode = 0; /* Transfer Mode */
|
||||
pIE->InfoRate = 0; /* Information transfer rate */
|
||||
pIE->RateMul = 0; /* Rate multiplier */
|
||||
pIE->Layer1Ident = 0; /* Layer 1 ident. */
|
||||
pIE->UIL1Prot = 0; /* User information layer 1 protocol */
|
||||
pIE->SyncAsync = 0; /* Synch/asynch */
|
||||
pIE->Negot = 0; /* Negot */
|
||||
pIE->UserRate = 0; /* User rate */
|
||||
pIE->InterRate = 0; /* Intermediate rate */
|
||||
pIE->NIConTx = 0; /* NIC on Tx */
|
||||
pIE->NIConRx = 0; /* NIC on Rx */
|
||||
pIE->FlowCtlTx = 0; /* Flow control on Tx */
|
||||
pIE->FlowCtlRx = 0; /* Flow control on Rx */
|
||||
pIE->HDR = 0; /* Hdr/no hdr */
|
||||
pIE->MultiFrame = 0; /* Multiframe */
|
||||
pIE->ModeL1 = 0; /* Mode L1 */
|
||||
pIE->NegotLLI = 0; /* Negot. LLI */
|
||||
pIE->Assignor = 0; /* Assignor/Assignor ee */
|
||||
pIE->InBandNeg = 0; /* In-band negot. */
|
||||
pIE->NumStopBits = 0; /* Number of stop bits */
|
||||
pIE->NumDataBits = 0; /* Number of data bits */
|
||||
pIE->Parity = 0; /* Parity */
|
||||
pIE->DuplexMode = 0; /* Duplex Mode */
|
||||
pIE->ModemType = 0; /* Modem type */
|
||||
pIE->Layer2Ident = 0; /* Layer 2 ident. */
|
||||
pIE->UIL2Prot = 0; /* User information layer 2 protocol */
|
||||
pIE->ModeL2 = 0; /* ModeL2 */
|
||||
pIE->Q933use = 0; /* Q.9333 use */
|
||||
pIE->UsrSpcL2Prot = 0; /* User specified layer 2 protocol info */
|
||||
pIE->WindowSize = 0; /* Window size (k) */
|
||||
pIE->Layer3Ident = 0; /* Layer 3 ident */
|
||||
pIE->OptL3Info = 0; /* Optional layer 3 protocol info. */
|
||||
pIE->ModeL3 = 0; /* Mode of operation */
|
||||
// pIE->ModeX25op = 0; /* Mode of operation X.25 */
|
||||
pIE->DefPackSize = 0; /* Default packet size */
|
||||
pIE->PackWinSize = 0; /* Packet window size */
|
||||
pIE->AddL3Info = 0; /* Additional Layer 3 protocol info */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931InitIEHLComp(Q931ie_HLComp * pIE)
|
||||
{
|
||||
pIE->IEId = Q931ie_HIGH_LAYER_COMPATIBILITY;
|
||||
pIE->Size = sizeof(Q931ie_HLComp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931Disconnect(Q931_TrunkInfo *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo)
|
||||
{
|
||||
return 0;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,311 @@
|
|||
/*****************************************************************************
|
||||
|
||||
FileName: Q932mes.c
|
||||
|
||||
Contents: Q.932 Message Encoders/Decoders
|
||||
|
||||
License/Copyright:
|
||||
|
||||
Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
|
||||
email:janvb@caselaboratories.com
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the Case Labs, Ltd nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "Q931.h"
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q932Umes_Facility
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size)
|
||||
{
|
||||
L3INT i = IOff;
|
||||
L3INT ir=0;
|
||||
L3INT OOff=0;
|
||||
L3INT rc=Q931E_NO_ERROR;
|
||||
Q932mes_Facility *mes = (Q932mes_Facility*)IBuf;
|
||||
|
||||
//TODO
|
||||
|
||||
mes->Size = sizeof(Q932mes_Facility) - 1 + OOff;
|
||||
return Q931E_NO_ERROR;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931Pmes_Facility
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
|
||||
{
|
||||
L3BOOL RetCode = L3FALSE;
|
||||
|
||||
NoWarning(OBuf);
|
||||
NoWarning(IBuf);
|
||||
|
||||
return RetCode;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q932Umes_Hold
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size)
|
||||
{
|
||||
L3INT i = IOff;
|
||||
L3INT ir=0;
|
||||
L3INT OOff=0;
|
||||
Q932mes_Hold *mes = (Q932mes_Hold*)IBuf;
|
||||
|
||||
//TODO
|
||||
|
||||
mes->Size = sizeof(Q932mes_Hold) - 1 + OOff;
|
||||
return Q931E_NO_ERROR;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931Pmes_Hold
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
|
||||
{
|
||||
L3BOOL RetCode = L3FALSE;
|
||||
|
||||
NoWarning(OBuf);
|
||||
NoWarning(IBuf);
|
||||
|
||||
return RetCode;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q932Umes_HoldAck
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size)
|
||||
{
|
||||
L3INT i = IOff;
|
||||
L3INT ir=0;
|
||||
L3INT OOff=0;
|
||||
Q932mes_HoldAck *mes = (Q932mes_HoldAck*)IBuf;
|
||||
|
||||
//TODO
|
||||
|
||||
mes->Size = sizeof(Q932mes_HoldAck) - 1 + OOff;
|
||||
return Q931E_NO_ERROR;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931Pmes_HoldAck
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
|
||||
{
|
||||
L3BOOL RetCode = L3FALSE;
|
||||
|
||||
NoWarning(OBuf);
|
||||
NoWarning(IBuf);
|
||||
|
||||
return RetCode;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q932Umes_HoldReject
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size)
|
||||
{
|
||||
L3INT i = IOff;
|
||||
L3INT ir=0;
|
||||
L3INT OOff=0;
|
||||
Q932mes_HoldReject *mes = (Q932mes_HoldReject*)IBuf;
|
||||
|
||||
//TODO
|
||||
|
||||
mes->Size = sizeof(Q932mes_HoldReject) - 1 + OOff;
|
||||
return Q931E_NO_ERROR;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931Pmes_HoldReject
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
|
||||
{
|
||||
L3BOOL RetCode = L3FALSE;
|
||||
|
||||
NoWarning(OBuf);
|
||||
NoWarning(IBuf);
|
||||
|
||||
return RetCode;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q932Umes_Register
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size)
|
||||
{
|
||||
L3INT i = IOff;
|
||||
L3INT ir=0;
|
||||
L3INT OOff=0;
|
||||
Q932mes_Register *mes = (Q932mes_Register*)IBuf;
|
||||
|
||||
//TODO
|
||||
|
||||
mes->Size = sizeof(Q932mes_Register) - 1 + OOff;
|
||||
return Q931E_NO_ERROR;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931Pmes_Register
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
|
||||
{
|
||||
L3BOOL RetCode = L3FALSE;
|
||||
|
||||
NoWarning(OBuf);
|
||||
NoWarning(IBuf);
|
||||
|
||||
return RetCode;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q932Umes_Retrieve
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size)
|
||||
{
|
||||
L3INT i = IOff;
|
||||
L3INT ir=0;
|
||||
L3INT OOff=0;
|
||||
Q932mes_Retrieve *mes = (Q932mes_Retrieve*)IBuf;
|
||||
|
||||
//TODO
|
||||
|
||||
mes->Size = sizeof(Q932mes_Retrieve) - 1 + OOff;
|
||||
return Q931E_NO_ERROR;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931Pmes_Retrieve
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
|
||||
{
|
||||
L3BOOL RetCode = L3FALSE;
|
||||
|
||||
NoWarning(OBuf);
|
||||
NoWarning(IBuf);
|
||||
|
||||
return RetCode;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q932Umes_RetrieveAck
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size)
|
||||
{
|
||||
L3INT i = IOff;
|
||||
L3INT ir=0;
|
||||
L3INT OOff=0;
|
||||
Q932mes_RetrieveAck *mes = (Q932mes_RetrieveAck*)IBuf;
|
||||
|
||||
//TODO
|
||||
|
||||
mes->Size = sizeof(Q932mes_RetrieveAck) - 1 + OOff;
|
||||
return Q931E_NO_ERROR;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931Pmes_RetrieveAck
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
|
||||
{
|
||||
L3BOOL RetCode = L3FALSE;
|
||||
|
||||
NoWarning(OBuf);
|
||||
NoWarning(IBuf);
|
||||
|
||||
return RetCode;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q932Umes_RetrieveReject
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size)
|
||||
{
|
||||
L3INT i = IOff;
|
||||
L3INT ir=0;
|
||||
L3INT OOff=0;
|
||||
Q932mes_RetrieveReject *mes = (Q932mes_RetrieveReject*)IBuf;
|
||||
|
||||
//TODO
|
||||
|
||||
mes->Size = sizeof(Q932mes_RetrieveReject) - 1 + OOff;
|
||||
return Q931E_NO_ERROR;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: Q931Pmes_RetrieveReject
|
||||
|
||||
*****************************************************************************/
|
||||
L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
|
||||
{
|
||||
L3BOOL RetCode = L3FALSE;
|
||||
|
||||
NoWarning(OBuf);
|
||||
NoWarning(IBuf);
|
||||
|
||||
return RetCode;
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
/*****************************************************************************
|
||||
|
||||
FileName: q921.h
|
||||
|
||||
Description: Contains headers of a Q.921 protocol on top of the Comet
|
||||
Driver.
|
||||
|
||||
Most of the work required to execute a Q.921 protocol is
|
||||
taken care of by the Comet ship and it's driver. This layer
|
||||
will simply configure and make use of these features to
|
||||
complete a Q.921 implementation.
|
||||
|
||||
Note: This header file is the only include file that should be
|
||||
acessed by users of the Q.921 stack.
|
||||
|
||||
Interface: The Q.921 stack contains 2 layers.
|
||||
|
||||
- One interface layer.
|
||||
- One driver layer.
|
||||
|
||||
The interface layer contains the interface functions required
|
||||
for a layer 3 stack to be able to send and receive messages.
|
||||
|
||||
The driver layer will simply feed bytes into the ship as
|
||||
required and queue messages received out from the ship.
|
||||
|
||||
Q921TimeTick The Q.921 like any other blackbox
|
||||
modules contains no thread by it's own
|
||||
and must therefore be called regularly
|
||||
by an external 'thread' to do maintenance
|
||||
etc.
|
||||
|
||||
Q921Rx32 Receive message from layer 3. Called by
|
||||
the layer 3 stack to send a message.
|
||||
|
||||
Q921Tx23 Send a message to layer 3.
|
||||
|
||||
OnQ921Error Function called every if an error is
|
||||
deteceted.
|
||||
|
||||
OnQ921Log Function called if logging is active.
|
||||
|
||||
|
||||
<TODO> Maintenance/Configuration interface
|
||||
|
||||
Created: 27.dec.2000/JVB
|
||||
|
||||
License/Copyright:
|
||||
|
||||
Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
|
||||
email:janvb@caselaboratories.com
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the Case Labs, Ltd nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef _Q921
|
||||
#define _Q921
|
||||
|
||||
#define Q921MAXTRUNK 4
|
||||
#define Q921MAXHDLCSPACE 3000
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char HDLCInQueue[Q921MAXHDLCSPACE];
|
||||
unsigned char vs;
|
||||
unsigned char vr;
|
||||
int state;
|
||||
}Q921Data;
|
||||
|
||||
void Q921Init();
|
||||
void Q921SetHeaderSpace(int hspace);
|
||||
void Q921SetTx21CB(int (*callback)(int dev, unsigned char *, int));
|
||||
void Q921SetTx23CB(int (*callback)(int dev, unsigned char *, int));
|
||||
int Q921QueueHDLCFrame(int trunk, char *b, int size);
|
||||
int Q921Rx12(long trunk);
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,191 @@
|
|||
/*****************************************************************************
|
||||
|
||||
FileName: Q932.h
|
||||
|
||||
Contents: Header w/structs for Q932 Suplementary Services.
|
||||
|
||||
NB: Do NOT include this header directly, include Q931.h
|
||||
|
||||
License/Copyright:
|
||||
|
||||
Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
|
||||
email:janvb@caselaboratories.com
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the Case Labs, Ltd nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
Q.932 Additional Message codes
|
||||
*****************************************************************************/
|
||||
|
||||
#define Q932mes_HOLD 0x24 /* 0010 0100 */
|
||||
#define Q932mes_HOLD_ACKNOWLEDGE 0x28 /* 0010 1000 */
|
||||
#define Q932mes_HOLD_REJECT 0x30 /* 0011 0000 */
|
||||
#define Q932mes_RETRIEVE 0x31 /* 0011 0001 */
|
||||
#define Q932mes_RETRIEVE_ACKNOWLEDGE 0x33 /* 0011 0011 */
|
||||
#define Q932mes_RETRIEVE_REJECT 0x37 /* 0011 0111 */
|
||||
#define Q932mes_FACILITY 0x62 /* 0110 0010 */
|
||||
#define Q932mes_REGISTER 0x64 /* 0110 0100 */
|
||||
|
||||
/*****************************************************************************
|
||||
Q.932 Additional EI Codes
|
||||
*****************************************************************************/
|
||||
#define Q932ie_FACILITY 0x1c /* 0001 1100 */
|
||||
|
||||
/*****************************************************************************
|
||||
Struct: Q932ie_Facility
|
||||
*****************************************************************************/
|
||||
typedef struct
|
||||
{
|
||||
L3UINT Size; /* Size of message in bytes */
|
||||
L3UCHAR ProtDisc; /* Protocol Discriminator */
|
||||
L3UCHAR MesType; /* Message type */
|
||||
L3USHORT CRV; /* Call reference value */
|
||||
L3UCHAR buf[1]; /* Dynamic buffer */
|
||||
}Q932mes_Facility;
|
||||
|
||||
/*****************************************************************************
|
||||
Struct: Q932ie_Hold
|
||||
*****************************************************************************/
|
||||
typedef struct
|
||||
{
|
||||
L3UINT Size; /* Size of message in bytes */
|
||||
L3UCHAR ProtDisc; /* Protocol Discriminator */
|
||||
L3UCHAR MesType; /* Message type */
|
||||
L3USHORT CRV; /* Call reference value */
|
||||
L3UCHAR buf[1]; /* Dynamic buffer */
|
||||
}Q932mes_Hold;
|
||||
|
||||
/*****************************************************************************
|
||||
Struct: Q932ie_HoldAck
|
||||
*****************************************************************************/
|
||||
typedef struct
|
||||
{
|
||||
L3UINT Size; /* Size of message in bytes */
|
||||
L3UCHAR ProtDisc; /* Protocol Discriminator */
|
||||
L3UCHAR MesType; /* Message type */
|
||||
L3USHORT CRV; /* Call reference value */
|
||||
L3UCHAR buf[1]; /* Dynamic buffer */
|
||||
}Q932mes_HoldAck;
|
||||
|
||||
/*****************************************************************************
|
||||
Struct: Q932ie_HoldReject
|
||||
*****************************************************************************/
|
||||
typedef struct
|
||||
{
|
||||
L3UINT Size; /* Size of message in bytes */
|
||||
L3UCHAR ProtDisc; /* Protocol Discriminator */
|
||||
L3UCHAR MesType; /* Message type */
|
||||
L3USHORT CRV; /* Call reference value */
|
||||
L3UCHAR buf[1]; /* Dynamic buffer */
|
||||
}Q932mes_HoldReject;
|
||||
|
||||
/*****************************************************************************
|
||||
Struct: Q932ie_Register
|
||||
*****************************************************************************/
|
||||
typedef struct
|
||||
{
|
||||
L3UINT Size; /* Size of message in bytes */
|
||||
L3UCHAR ProtDisc; /* Protocol Discriminator */
|
||||
L3UCHAR MesType; /* Message type */
|
||||
L3USHORT CRV; /* Call reference value */
|
||||
L3UCHAR buf[1]; /* Dynamic buffer */
|
||||
}Q932mes_Register;
|
||||
|
||||
/*****************************************************************************
|
||||
Struct: Q932ie_Retrieve
|
||||
*****************************************************************************/
|
||||
typedef struct
|
||||
{
|
||||
L3UINT Size; /* Size of message in bytes */
|
||||
L3UCHAR ProtDisc; /* Protocol Discriminator */
|
||||
L3UCHAR MesType; /* Message type */
|
||||
L3USHORT CRV; /* Call reference value */
|
||||
L3UCHAR buf[1]; /* Dynamic buffer */
|
||||
}Q932mes_Retrieve;
|
||||
|
||||
/*****************************************************************************
|
||||
Struct: Q932ie_RetrieveAck
|
||||
*****************************************************************************/
|
||||
typedef struct
|
||||
{
|
||||
L3UINT Size; /* Size of message in bytes */
|
||||
L3UCHAR ProtDisc; /* Protocol Discriminator */
|
||||
L3UCHAR MesType; /* Message type */
|
||||
L3USHORT CRV; /* Call reference value */
|
||||
L3UCHAR buf[1]; /* Dynamic buffer */
|
||||
}Q932mes_RetrieveAck;
|
||||
|
||||
/*****************************************************************************
|
||||
Struct: Q932ie_RetrieveReject
|
||||
*****************************************************************************/
|
||||
typedef struct
|
||||
{
|
||||
L3UINT Size; /* Size of message in bytes */
|
||||
L3UCHAR ProtDisc; /* Protocol Discriminator */
|
||||
L3UCHAR MesType; /* Message type */
|
||||
L3USHORT CRV; /* Call reference value */
|
||||
L3UCHAR buf[1]; /* Dynamic buffer */
|
||||
}Q932mes_RetrieveReject;
|
||||
|
||||
/*****************************************************************************
|
||||
Function Prototypes.
|
||||
*****************************************************************************/
|
||||
L3INT Q932ProcFacilityTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom);
|
||||
L3INT Q932ProcHoldTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom);
|
||||
L3INT Q932ProcHoldAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom);
|
||||
L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom);
|
||||
L3INT Q932ProcRegisterTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom);
|
||||
L3INT Q932ProcRetrieveTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom);
|
||||
L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom);
|
||||
L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom);
|
||||
|
||||
L3INT Q932ProcFacilityNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom);
|
||||
L3INT Q932ProcHoldNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom);
|
||||
L3INT Q932ProcHoldAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom);
|
||||
L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom);
|
||||
L3INT Q932ProcRegisterNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom);
|
||||
L3INT Q932ProcRetrieveNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom);
|
||||
L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom);
|
||||
L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom);
|
||||
|
||||
L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
|
||||
L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
|
||||
L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
|
||||
L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
|
||||
L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
|
||||
L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
|
||||
L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
|
||||
L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize);
|
||||
|
||||
L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O);
|
||||
L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O);
|
||||
L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O);
|
||||
L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O);
|
||||
L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O);
|
||||
L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O);
|
||||
L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O);
|
||||
L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O);
|
|
@ -0,0 +1,83 @@
|
|||
/*****************************************************************************
|
||||
|
||||
Filename: mfifo.h
|
||||
|
||||
Contents: header for MFIFO
|
||||
|
||||
License/Copyright:
|
||||
|
||||
Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
|
||||
email:janvb@caselaboratories.com
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the Case Labs, Ltd nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
#ifndef _MFIFO
|
||||
#define _MFIFO
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Struct: MINDEX
|
||||
|
||||
Description: Message Index used to index a dynamic size Message FIFO.
|
||||
|
||||
*****************************************************************************/
|
||||
typedef struct _mindex
|
||||
{
|
||||
int offset; /* offset to message in buf */
|
||||
int size; /* size of message in bytes */
|
||||
}MINDEX;
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Struct: MFIFO
|
||||
|
||||
Description: Message FIFO. Provides a dynamic sized message based FIFO
|
||||
queue.
|
||||
|
||||
*****************************************************************************/
|
||||
typedef struct _mfifo
|
||||
{
|
||||
int first; /* first out */
|
||||
int last; /* last in + 1 */
|
||||
int bsize; /* buffer size */
|
||||
char *buf; /* ptr to start of buffer */
|
||||
int ixsize; /* index size */
|
||||
MINDEX ix[1]; /* message index */
|
||||
}MFIFO;
|
||||
|
||||
/*****************************************************************************
|
||||
Function prototypes.
|
||||
*****************************************************************************/
|
||||
int MFIFOCreate(char *buf, int size, int index);
|
||||
void MFIFOClear(char * buf);
|
||||
int MFIFOGetLBOffset(char *buf);
|
||||
int MFIFOGetFBOffset(char *buf);
|
||||
void MFIFOWriteIX(char *buf, char *mes, int size, int ix, int off);
|
||||
int MFIFOWriteMes(char *buf, char *mes, int size);
|
||||
char * MFIFOGetMesPtr(char *buf, int *size);
|
||||
void MFIFOKillNext(char *buf);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,296 @@
|
|||
/*****************************************************************************
|
||||
|
||||
Filename: mfifo.c
|
||||
|
||||
Description: mfifo is a message orriented fifo system with support of
|
||||
both message and byte per byte retriaval of messages.
|
||||
|
||||
The fifo has been designed with two usages in mind:
|
||||
|
||||
- Queueing of frames for hdlc and feeding out byte per byte
|
||||
with the possibility of re-sending of frames etc.
|
||||
|
||||
- fifo for messages of dynamic size.
|
||||
|
||||
The fifo is allocated on top of any buffer and creates an
|
||||
index of message in the queue. The user can write/read
|
||||
messages or write messages and read the message one byte
|
||||
at the time.
|
||||
|
||||
Interface:
|
||||
MFIFOCreate Create/reset/initialize fifo.
|
||||
MFIFOClear Clear FIFO.
|
||||
MFIFOWriteMes Write message into fifo
|
||||
* MFIFOReadMes Read message from fifo.
|
||||
MFIFOGetMesPtr Get ptr to next message.
|
||||
MFIFOKillNext Kill next message.
|
||||
|
||||
* currently not implemented.
|
||||
|
||||
Note: The message will always be saved continuously. If there is not
|
||||
sufficient space at the end of the buffer, the fifo will skip
|
||||
the last bytes and save the message at the top of the buffer.
|
||||
|
||||
This is required to allow direct ptr access to messages
|
||||
stored in the queue.
|
||||
|
||||
License/Copyright:
|
||||
|
||||
Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
|
||||
email:janvb@caselaboratories.com
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the Case Labs, Ltd nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "mfifo.h"
|
||||
#include <memory.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: MFIFOCreate
|
||||
|
||||
Description: Creates a fifo on top of an existing buffer.
|
||||
|
||||
Parameters: buf ptr to buffer.
|
||||
size size of buffer in bytes.
|
||||
index size of index entries (max no messages).
|
||||
|
||||
Return value: 0 if failure, 1 if ok.
|
||||
|
||||
*****************************************************************************/
|
||||
int MFIFOCreate(char *buf, int size, int index)
|
||||
{
|
||||
MFIFO * mf;
|
||||
mf = (MFIFO*)buf;
|
||||
|
||||
mf->first = mf->last = 0;
|
||||
mf->ixsize = index;
|
||||
mf->buf = &buf[sizeof(MFIFO) + (sizeof(MINDEX) * (index-1))];
|
||||
|
||||
if(mf->buf > & buf[size])
|
||||
return 0;
|
||||
|
||||
mf->bsize = size - sizeof(MFIFO) - (sizeof(MINDEX) * (index-1));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: MFIFOClear
|
||||
|
||||
Description: Clear the FIFO
|
||||
|
||||
Paremeters: buf ptr to fifo
|
||||
|
||||
Return Value: none
|
||||
|
||||
*****************************************************************************/
|
||||
void MFIFOClear(char * buf)
|
||||
{
|
||||
MFIFO * mf;
|
||||
mf = (MFIFO*)buf;
|
||||
mf->first = mf->last = 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: MFIFOGetLBOffset
|
||||
|
||||
Description: Helper function caclulating offset to the 'first out' byte.
|
||||
|
||||
Paremeters: buf ptr to fifo
|
||||
|
||||
Return Value: offset.
|
||||
|
||||
*****************************************************************************/
|
||||
int MFIFOGetLBOffset(char *buf)
|
||||
{
|
||||
MFIFO * mf;
|
||||
mf = (MFIFO*)buf;
|
||||
if(mf->last != mf->first)
|
||||
return mf->ix[mf->last].offset;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: MFIFOGetFBOffset
|
||||
|
||||
Description: Helper function calculating the offset to the 'first in'
|
||||
byte in the buffer. This is the position the next byte
|
||||
entering the fifo will occupy.
|
||||
|
||||
Paremeters: buf ptr to fifo
|
||||
|
||||
Return Value: offset
|
||||
|
||||
*****************************************************************************/
|
||||
int MFIFOGetFBOffset(char *buf)
|
||||
{
|
||||
int x;
|
||||
MFIFO * mf;
|
||||
mf = (MFIFO*)buf;
|
||||
if(mf->last == mf->first)
|
||||
return 0;
|
||||
x=mf->first;
|
||||
x--;
|
||||
if(x<0)
|
||||
x=mf->ixsize;
|
||||
return mf->ix[x].offset + mf->ix[x].size;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: MFIFOWriteIX
|
||||
|
||||
Description: Helper function writing a calculated entry. The function
|
||||
will perform a memcpy to move the message and set the index
|
||||
values as well as increase the 'first in' index.
|
||||
|
||||
Paremeters: buf ptr to fifo
|
||||
mes ptr to message
|
||||
size size of message in bytes.
|
||||
ix index to index entry.
|
||||
off offset to position to receive the message
|
||||
|
||||
Return Value: none
|
||||
|
||||
*****************************************************************************/
|
||||
void MFIFOWriteIX(char *buf, char *mes, int size, int ix, int off)
|
||||
{
|
||||
int x;
|
||||
MFIFO * mf;
|
||||
mf = (MFIFO*)buf;
|
||||
memcpy(&mf->buf[off],mes,size);
|
||||
mf->ix[ix].offset=off;
|
||||
mf->ix[ix].size=size;
|
||||
x = mf->first+1;
|
||||
if(x > mf->ixsize)
|
||||
x=0;
|
||||
mf->first=x;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: MFIFOWriteMes
|
||||
|
||||
Description:
|
||||
|
||||
Paremeters:
|
||||
|
||||
Return Value:
|
||||
|
||||
*****************************************************************************/
|
||||
int MFIFOWriteMes(char *buf, char *mes, int size)
|
||||
{
|
||||
int of,ol,x;
|
||||
MFIFO * mf;
|
||||
mf = (MFIFO*)buf;
|
||||
|
||||
x = mf->first+1;
|
||||
if(x > mf->ixsize)
|
||||
x=0;
|
||||
if(x == mf->last)
|
||||
return 0; /* full queue */
|
||||
|
||||
of = MFIFOGetFBOffset(buf);
|
||||
ol = MFIFOGetLBOffset(buf);
|
||||
if(mf->last == mf->first) /* empty queue */
|
||||
{
|
||||
mf->first = mf->last = 0; /* optimize */
|
||||
MFIFOWriteIX(buf, mes, size, mf->first, 0);
|
||||
return 1;
|
||||
}
|
||||
else if(of > ol)
|
||||
{
|
||||
if(mf->bsize - of >= size)
|
||||
{
|
||||
MFIFOWriteIX(buf,mes,size,mf->first,of);
|
||||
return 1;
|
||||
}
|
||||
else if(ol > size)
|
||||
{
|
||||
MFIFOWriteIX(buf,mes,size,mf->first,ol);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if(ol - of > size)
|
||||
{
|
||||
MFIFOWriteIX(buf,mes,size,mf->first,of);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: MFIFOGetMesPtr
|
||||
|
||||
Description:
|
||||
|
||||
Paremeters:
|
||||
|
||||
Return Value:
|
||||
|
||||
*****************************************************************************/
|
||||
char * MFIFOGetMesPtr(char *buf, int *size)
|
||||
{
|
||||
MFIFO * mf;
|
||||
mf = (MFIFO*)buf;
|
||||
if(mf->first==mf->last)
|
||||
return NULL;
|
||||
*size = mf->ix[mf->last].size;
|
||||
return &mf->buf[mf->ix[mf->last].offset];
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Function: MFIFOKillNext
|
||||
|
||||
Description:
|
||||
|
||||
Paremeters:
|
||||
|
||||
Return Value:
|
||||
|
||||
*****************************************************************************/
|
||||
void MFIFOKillNext(char *buf)
|
||||
{
|
||||
int x;
|
||||
MFIFO * mf;
|
||||
mf = (MFIFO*)buf;
|
||||
if(mf->first!=mf->last)
|
||||
{
|
||||
x = mf->last+1;
|
||||
if(x > mf->ixsize)
|
||||
x=0;
|
||||
mf->last=x;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue