rework 921/931 api.

Move the Tx callbacks on each to be trunk specific, not global so that we can set them per trunk.
Change prototypes for the Tx callbacks so that they pass a trunk specific private pointer to the Tx callbacks so that 921 and 931 can call each other directly.
change 921 so that it doesn't use a static array for it's trunk structure to match 931
use more enums.
more to come....

git-svn-id: http://svn.openzap.org/svn/openzap/trunk@96 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
Michael Jerris 2007-05-22 08:03:20 +00:00
parent 5daa050cb5
commit f59812b19c
5 changed files with 2580 additions and 2606 deletions

View File

@ -2,13 +2,7 @@
FileName: q921.c FileName: q921.c
Description: Contains the implementation of a Q.921 protocol on top of the Description: Contains the implementation of a Q.921 protocol
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 Created: 27.dec.2000/JVB
@ -47,75 +41,48 @@
#include <stdlib.h> #include <stdlib.h>
#include "mfifo.h" #include "mfifo.h"
/*****************************************************************************
Global Tables & Variables.
*****************************************************************************/
#ifdef Q921_HANDLE_STATIC
Q921Data Q921DevSpace[Q921MAXTRUNK];
#endif
int Q921HeaderSpace={0};
int (*Q921Tx21Proc)(L2TRUNK dev, L2UCHAR *, int)={NULL};
int (*Q921Tx23Proc)(L2TRUNK dev, L2UCHAR *, 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()
{
#ifdef Q921_HANDLE_STATIC
int x;
for(x=0; x<Q921MAXTRUNK;x++)
{
Q921_InitTrunk(x, 0, 0, Q921_TE);
}
#endif
}
/***************************************************************************** /*****************************************************************************
Function: Q921_InitTrunk Function: Q921_InitTrunk
Decription: Initialize a Q.921 trunk so it is ready for use. This Decription: Initialize a Q.921 trunk so it is ready for use. This
function should be called before you call the rx functions function MUST be called before you call any other functions.
if your trunk will not use hardcoded tei and sapi of 0 or
if your trunk is not TE (user) mode (i.e. NET).
*****************************************************************************/ *****************************************************************************/
void Q921_InitTrunk(L2TRUNK trunk, L2UCHAR sapi, L2UCHAR tei, Q921NetUser_t NetUser) void Q921_InitTrunk(L2TRUNK trunk,
L2UCHAR sapi,
L2UCHAR tei,
Q921NetUser_t NetUser,
L2INT hsize,
Q921TxCB_t cb21,
Q921TxCB_t cb23,
void *priv)
{ {
if (L2TRUNKHANDLE(trunk).initialized != INITIALIZED_MAGIC) { if (trunk->initialized != INITIALIZED_MAGIC) {
MFIFOCreate(L2TRUNKHANDLE(trunk).HDLCInQueue, Q921MAXHDLCSPACE, 10); MFIFOCreate(trunk->HDLCInQueue, Q921MAXHDLCSPACE, 10);
L2TRUNKHANDLE(trunk).initialized = INITIALIZED_MAGIC; trunk->initialized = INITIALIZED_MAGIC;
} }
L2TRUNKHANDLE(trunk).vr = 0; trunk->vr = 0;
L2TRUNKHANDLE(trunk).vs = 0; trunk->vs = 0;
L2TRUNKHANDLE(trunk).state = 0; trunk->state = 0;
L2TRUNKHANDLE(trunk).sapi = sapi; trunk->sapi = sapi;
L2TRUNKHANDLE(trunk).tei = tei; trunk->tei = tei;
L2TRUNKHANDLE(trunk).NetUser = NetUser; trunk->NetUser = NetUser;
trunk->Q921Tx21Proc = cb21;
trunk->Q921Tx23Proc = cb23;
trunk->PrivateData = priv;
trunk->Q921HeaderSpace = hsize;
} }
void Q921SetHeaderSpace(int hspace) static int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size)
{ {
Q921HeaderSpace=hspace; return trunk->Q921Tx21Proc(trunk->PrivateData, Msg, size);
} }
void Q921SetTx21CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)) int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size)
{ {
Q921Tx21Proc = callback; return trunk->Q921Tx23Proc(trunk->PrivateData, Msg, size);
}
void Q921SetTx23CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int))
{
Q921Tx23Proc = callback;
} }
/***************************************************************************** /*****************************************************************************
@ -137,9 +104,9 @@ void Q921SetTx23CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int))
size size of frame in bytes size size of frame in bytes
*****************************************************************************/ *****************************************************************************/
int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, int size) int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size)
{ {
return MFIFOWriteMes(L2TRUNKHANDLE(trunk).HDLCInQueue, b, size); return MFIFOWriteMes(trunk->HDLCInQueue, b, size);
} }
/***************************************************************************** /*****************************************************************************
@ -161,13 +128,13 @@ int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, int size)
Return Value: 0 if failed, 1 if Send. Return Value: 0 if failed, 1 if Send.
*****************************************************************************/ *****************************************************************************/
int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, int size) int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, L2INT size)
{ {
mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[trunk->Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02);
mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; mes[trunk->Q921HeaderSpace+1] = (Tei<<1) | 0x01;
mes[Q921HeaderSpace+2] = L2TRUNKHANDLE(trunk).vs<<1; mes[trunk->Q921HeaderSpace+2] = trunk->vs<<1;
mes[Q921HeaderSpace+3] = (L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01); mes[trunk->Q921HeaderSpace+3] = (trunk->vr<<1) | (pf & 0x01);
L2TRUNKHANDLE(trunk).vs++; trunk->vs++;
return Q921Tx21Proc(trunk, mes, size); return Q921Tx21Proc(trunk, mes, size);
} }
@ -175,9 +142,9 @@ int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHA
int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size) int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size)
{ {
return Q921SendI(trunk, return Q921SendI(trunk,
L2TRUNKHANDLE(trunk).sapi, trunk->sapi,
L2TRUNKHANDLE(trunk).NetUser == Q921_TE ? 0 : 1, trunk->NetUser == Q921_TE ? 0 : 1,
L2TRUNKHANDLE(trunk).tei, trunk->tei,
0, 0,
Mes, Mes,
Size); Size);
@ -202,12 +169,12 @@ int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf)
{ {
L2UCHAR mes[400]; L2UCHAR mes[400];
mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02));
mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01);
mes[Q921HeaderSpace+2] = (L2UCHAR)0x01; mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x01;
mes[Q921HeaderSpace+3] = (L2UCHAR)((L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01)); mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01));
return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+4);
} }
/***************************************************************************** /*****************************************************************************
@ -229,12 +196,12 @@ int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf)
{ {
L2UCHAR mes[400]; L2UCHAR mes[400];
mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02));
mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01);
mes[Q921HeaderSpace+2] = (L2UCHAR)0x05; mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x05;
mes[Q921HeaderSpace+3] = (L2UCHAR)((L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01)); mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01));
return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+4);
} }
/***************************************************************************** /*****************************************************************************
@ -256,12 +223,12 @@ int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf)
{ {
L2UCHAR mes[400]; L2UCHAR mes[400];
mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02));
mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01);
mes[Q921HeaderSpace+2] = (L2UCHAR)0x09; mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x09;
mes[Q921HeaderSpace+3] = (L2UCHAR)((L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01)); mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01));
return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+4);
} }
/***************************************************************************** /*****************************************************************************
@ -283,11 +250,11 @@ int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf)
{ {
L2UCHAR mes[400]; L2UCHAR mes[400];
mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02));
mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01);
mes[Q921HeaderSpace+2] = (L2UCHAR)(0x6f | ((pf<<4)&0x10)); mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x6f | ((pf<<4)&0x10));
return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3);
} }
/***************************************************************************** /*****************************************************************************
@ -309,11 +276,11 @@ int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf)
{ {
L2UCHAR mes[400]; L2UCHAR mes[400];
mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02));
mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01);
mes[Q921HeaderSpace+2] = (L2UCHAR)(0x0f | ((pf<<4)&0x10)); mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x0f | ((pf<<4)&0x10));
return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3);
} }
/***************************************************************************** /*****************************************************************************
@ -335,11 +302,11 @@ int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf)
{ {
L2UCHAR mes[400]; L2UCHAR mes[400];
mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02));
mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01);
mes[Q921HeaderSpace+2] = (L2UCHAR)(0x43 | ((pf<<4)&0x10)); mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x43 | ((pf<<4)&0x10));
return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3);
} }
/***************************************************************************** /*****************************************************************************
@ -361,21 +328,21 @@ int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf)
{ {
L2UCHAR mes[400]; L2UCHAR mes[400];
mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02));
mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01);
mes[Q921HeaderSpace+2] = (L2UCHAR)(0x63 | ((pf<<4)&0x10)); mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x63 | ((pf<<4)&0x10));
return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3);
} }
int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, int size) int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size)
{ {
/* TODO: Do we need these paramaters? */ /* TODO: Do we need these paramaters? */
(void)mes; (void)mes;
(void)size; (void)size;
L2TRUNKHANDLE(trunk).vr=0; trunk->vr=0;
L2TRUNKHANDLE(trunk).vs=0; trunk->vs=0;
return 1; return 1;
} }
@ -401,18 +368,18 @@ int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, int size)
int Q921Rx12(L2TRUNK trunk) int Q921Rx12(L2TRUNK trunk)
{ {
L2UCHAR *mes; L2UCHAR *mes;
int rs,size; /* receive size & Q921 frame size*/ L2INT rs,size; /* receive size & Q921 frame size*/
L2UCHAR *smes = MFIFOGetMesPtr(L2TRUNKHANDLE(trunk).HDLCInQueue, &size); L2UCHAR *smes = MFIFOGetMesPtr(trunk->HDLCInQueue, &size);
if(smes != NULL) if(smes != NULL)
{ {
rs = size - Q921HeaderSpace; rs = size - trunk->Q921HeaderSpace;
mes = &smes[Q921HeaderSpace]; mes = &smes[trunk->Q921HeaderSpace];
/* check for I frame */ /* check for I frame */
if((mes[2] & 0x01) == 0) if((mes[2] & 0x01) == 0)
{ {
if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */ if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */
{ {
L2TRUNKHANDLE(trunk).vr++; trunk->vr++;
Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01);
} }
else else
@ -451,7 +418,7 @@ int Q921Rx12(L2TRUNK trunk)
/* todo: REJ or FRMR */ /* todo: REJ or FRMR */
} }
MFIFOKillNext(L2TRUNKHANDLE(trunk).HDLCInQueue); MFIFOKillNext(trunk->HDLCInQueue);
return 1; return 1;
} }

View File

@ -88,15 +88,7 @@ L3INT Q931L2HeaderSpace = {4}; /* Q921 header space, sapi, tei etc */
*****************************************************************************/ *****************************************************************************/
L3INT (*Q931Tx34Proc)(Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); Q931ErrorCB_t Q931ErrorProc;
/* 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. */
L3INT (*Q931ErrorProc)(Q931_TrunkInfo *pTrunk, L3INT,L3INT,L3INT);
/* callback for error messages. */ /* callback for error messages. */
L3ULONG (*Q931GetTimeProc) ()=NULL; /* callback for func reading time in ms */ L3ULONG (*Q931GetTimeProc) ()=NULL; /* callback for func reading time in ms */
@ -210,7 +202,7 @@ L3INT Q931TxDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT n)
Description: Dummy function for error processing Description: Dummy function for error processing
*****************************************************************************/ *****************************************************************************/
L3INT Q931ErrorDummy(Q931_TrunkInfo *pTrunk,L3INT a, L3INT b, L3INT c) L3INT Q931ErrorDummy(void *priv, L3INT a, L3INT b, L3INT c)
{ {
return 0; return 0;
} }
@ -235,8 +227,6 @@ void Q931Initialize()
L3INT x,y; L3INT x,y;
/* Secure the callbacks to default procs */ /* Secure the callbacks to default procs */
Q931Tx34Proc = Q931TxDummy;
Q931Tx32Proc = Q931TxDummy;
Q931ErrorProc = Q931ErrorDummy; Q931ErrorProc = Q931ErrorDummy;
/* The user will only add the message handlers and IE handlers he need, */ /* The user will only add the message handlers and IE handlers he need, */
@ -360,7 +350,10 @@ L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT Size)
*****************************************************************************/ *****************************************************************************/
L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size)
{ {
return Q931Tx34Proc(pTrunk, Mes, Size); if (pTrunk->Q931Tx34CBProc) {
return pTrunk->Q931Tx34CBProc(pTrunk->PrivateData, Mes, Size);
}
return Q931E_MISSING_CB;
} }
/***************************************************************************** /*****************************************************************************
@ -415,7 +408,11 @@ L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size)
RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk,Mes,Size,&pTrunk->L2Buf[Q931L2HeaderSpace], &OSize); RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk,Mes,Size,&pTrunk->L2Buf[Q931L2HeaderSpace], &OSize);
if(RetCode >= Q931E_NO_ERROR) if(RetCode >= Q931E_NO_ERROR)
{ {
RetCode = Q931Tx32Proc(pTrunk, pTrunk->L2Buf, Size); if (pTrunk->Q931Tx32CBProc) {
RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData, pTrunk->L2Buf, Size);
} else {
RetCode = Q931E_MISSING_CB;
}
} }
return RetCode; return RetCode;
@ -436,20 +433,14 @@ L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size)
*****************************************************************************/ *****************************************************************************/
void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2) void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2)
{ {
Q931ErrorProc(pTrunk,ErrID, ErrPar1, ErrPar2); if (pTrunk->Q931ErrorCBProc) {
pTrunk->Q931ErrorCBProc(pTrunk->PrivateData, ErrID, ErrPar1, ErrPar2);
} else {
Q931ErrorProc(pTrunk->PrivateData, ErrID, ErrPar1, ErrPar2);
}
} }
void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)) void Q931SetDefaultErrorCB(Q931ErrorCB_t Q931ErrorPar)
{
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; Q931ErrorProc = Q931ErrorPar;
} }

View File

@ -68,7 +68,14 @@ L3INT Q931CreateIEIndex(L3INT iec)
} }
*/ */
L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType) L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk,
Q931Dialect_t Dialect,
Q931NetUser_t NetUser,
Q931_TrunkType_t TrunkType,
Q931TxCB_t Q931Tx34CBProc,
Q931TxCB_t Q931Tx32CBProc,
Q931ErrorCB_t Q931ErrorCBProc,
void *PrivateData)
{ {
int y, dchannel, maxchans, has_sync = 0; int y, dchannel, maxchans, has_sync = 0;
@ -95,6 +102,11 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931Dialect_t Dialect, Q931NetUs
return 0; return 0;
} }
pTrunk->Q931Tx34CBProc = Q931Tx34CBProc;
pTrunk->Q931Tx32CBProc = Q931Tx32CBProc;
pTrunk->Q931ErrorCBProc = Q931ErrorCBProc;
pTrunk->PrivateData = PrivateData;
pTrunk->LastCRV = 0; pTrunk->LastCRV = 0;
pTrunk->Dialect = Dialect; pTrunk->Dialect = Dialect;
pTrunk->Enabled = 0; pTrunk->Enabled = 0;

View File

@ -2,13 +2,7 @@
FileName: q921.h FileName: q921.h
Description: Contains headers of a Q.921 protocol on top of the Comet Description: Contains headers of a Q.921 protocol.
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 Note: This header file is the only include file that should be
acessed by users of the Q.921 stack. acessed by users of the Q.921 stack.
@ -19,7 +13,7 @@
- One driver layer. - One driver layer.
The interface layer contains the interface functions required The interface layer contains the interface functions required
for a layer 3 stack to be able to send and receive messages. for a layer 2 stack to be able to send and receive messages.
The driver layer will simply feed bytes into the ship as The driver layer will simply feed bytes into the ship as
required and queue messages received out from the ship. required and queue messages received out from the ship.
@ -33,7 +27,8 @@
Q921Rx32 Receive message from layer 3. Called by Q921Rx32 Receive message from layer 3. Called by
the layer 3 stack to send a message. the layer 3 stack to send a message.
Q921Tx23 Send a message to layer 3.
NOTE: The following are not yet implemented
OnQ921Error Function called every if an error is OnQ921Error Function called every if an error is
deteceted. deteceted.
@ -42,6 +37,10 @@
<TODO> Maintenance/Configuration interface <TODO> Maintenance/Configuration interface
<TODO> Logging
<TODO> DL_ message passing to layer 3
<TODO> Timers
<TODO> Api commands to tell 921 to stop and start for a trunk
Created: 27.dec.2000/JVB Created: 27.dec.2000/JVB
@ -80,31 +79,10 @@
#ifndef _Q921 #ifndef _Q921
#define _Q921 #define _Q921
#define Q921MAXTRUNK 4
#define Q921MAXHDLCSPACE 3000 #define Q921MAXHDLCSPACE 3000
/*****************************************************************************
Some speed optimization can be achieved by changing all variables to the
word size of your processor. A 32 bit processor have to do a lot of extra
work to read a packed 8 bit integer. Changing all fields to 32 bit integer
will ressult in usage of some extra space, but speed up the stack.
The stack have been designed to allow L3UCHAR etc. to be any size of 8 bit
or larger.
*****************************************************************************/
#define L2UCHAR unsigned char /* Min 8 bit */ #define L2UCHAR unsigned char /* Min 8 bit */
#define L2INT int /* Min 16 bit signed */ #define L2INT int /* Min 16 bit signed */
#define L2TRUNK Q921Data_t *
#ifdef Q921_HANDLE_STATIC
#define L2TRUNK long
#define L2TRUNKHANDLE(trunk) Q921DevSpace[trunk]
#else
#define L2TRUNK Q921Data *
#define L2TRUNKHANDLE(trunk) (*trunk)
#endif
typedef enum /* Network/User Mode. */ typedef enum /* Network/User Mode. */
{ {
@ -112,8 +90,11 @@ typedef enum /* Network/User Mode. */
Q921_NT=1 /* 1 : Network Mode */ Q921_NT=1 /* 1 : Network Mode */
} Q921NetUser_t; } Q921NetUser_t;
typedef struct Q921Data Q921Data_t;
typedef int (*Q921TxCB_t) (void *, L2UCHAR *, L2INT);
#define INITIALIZED_MAGIC 42 #define INITIALIZED_MAGIC 42
typedef struct struct Q921Data
{ {
L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE];
L2INT initialized; L2INT initialized;
@ -123,15 +104,22 @@ typedef struct
L2UCHAR sapi; L2UCHAR sapi;
L2UCHAR tei; L2UCHAR tei;
Q921NetUser_t NetUser; Q921NetUser_t NetUser;
Q921TxCB_t Q921Tx21Proc;
Q921TxCB_t Q921Tx23Proc;
void *PrivateData;
L2INT Q921HeaderSpace;
}Q921Data; };
void Q921Init(); void Q921_InitTrunk(L2TRUNK trunk,
void Q921_InitTrunk(L2TRUNK trunk, L2UCHAR sapi, L2UCHAR tei, Q921NetUser_t NetUser); L2UCHAR sapi,
void Q921SetHeaderSpace(int hspace); L2UCHAR tei,
void Q921SetTx21CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)); Q921NetUser_t NetUser,
void Q921SetTx23CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)); L2INT hsize,
int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, int size); Q921TxCB_t cb21,
Q921TxCB_t cb23,
void *priv);
int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size);
int Q921Rx12(L2TRUNK trunk); int Q921Rx12(L2TRUNK trunk);
int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size);
#endif #endif

View File

@ -1917,6 +1917,10 @@ typedef struct
the trunk Info entry. the trunk Info entry.
*****************************************************************************/ *****************************************************************************/
typedef struct Q931_TrunkInfo Q931_TrunkInfo;
typedef L3INT (*Q931TxCB_t) (void *,L3UCHAR *, L3INT);
typedef L3INT (*Q931ErrorCB_t) (void *,L3INT,L3INT,L3INT);
typedef enum /* Network/User Mode. */ typedef enum /* Network/User Mode. */
{ {
@ -1953,7 +1957,7 @@ typedef enum {
Q931_ChType_Sync=3 /* Sync Channel */ Q931_ChType_Sync=3 /* Sync Channel */
} Q931_ChanType_t; } Q931_ChanType_t;
typedef struct struct Q931_TrunkInfo
{ {
Q931NetUser_t NetUser; /* Network/User Mode. */ Q931NetUser_t NetUser; /* Network/User Mode. */
@ -1961,6 +1965,11 @@ typedef struct
Q931_TrunkType_t TrunkType; /* Trunk Line Type. */ Q931_TrunkType_t TrunkType; /* Trunk Line Type. */
Q931TxCB_t Q931Tx34CBProc;
Q931TxCB_t Q931Tx32CBProc;
Q931ErrorCB_t Q931ErrorCBProc;
void *PrivateData;
L3UCHAR Enabled; /* Enabled/Disabled */ L3UCHAR Enabled; /* Enabled/Disabled */
/* 0 = Disabled */ /* 0 = Disabled */
/* 1 = Enabled */ /* 1 = Enabled */
@ -2033,7 +2042,7 @@ typedef struct
}call[Q931MAXCALLPERTRUNK]; }call[Q931MAXCALLPERTRUNK];
}Q931_TrunkInfo; };
/***************************************************************************** /*****************************************************************************
@ -2365,9 +2374,9 @@ L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size);
L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size);
L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size);
void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2); void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2);
void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size));
void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); void Q931SetDefaultErrorCB(Q931ErrorCB_t Q931ErrorPar);
void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT));
void Q931CreateTE(L3UCHAR i); void Q931CreateTE(L3UCHAR i);
void Q931CreateNT(L3UCHAR i); void Q931CreateNT(L3UCHAR i);
void Q931SetMesCreateCB(L3INT (*callback)()); void Q931SetMesCreateCB(L3INT (*callback)());
@ -2424,6 +2433,13 @@ L3INT Q931InitIEHLComp(Q931ie_HLComp * pIE);
L3INT Q931Disconnect(Q931_TrunkInfo *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); L3INT Q931Disconnect(Q931_TrunkInfo *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause);
L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo); L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo);
L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType); L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk,
Q931Dialect_t Dialect,
Q931NetUser_t NetUser,
Q931_TrunkType_t TrunkType,
Q931TxCB_t Q931Tx34CBProc,
Q931TxCB_t Q931Tx32CBProc,
Q931ErrorCB_t Q931ErrorCBProc,
void *PrivateData);
#endif /* _Q931_NL */ #endif /* _Q931_NL */