提交 598d8df4 authored 作者: Michael Jerris's avatar Michael Jerris

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
上级 629ed3ef
......@@ -88,15 +88,7 @@ L3INT Q931L2HeaderSpace = {4}; /* Q921 header space, sapi, tei etc */
*****************************************************************************/
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. */
L3INT (*Q931ErrorProc)(Q931_TrunkInfo *pTrunk, L3INT,L3INT,L3INT);
Q931ErrorCB_t Q931ErrorProc;
/* callback for error messages. */
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
*****************************************************************************/
L3INT Q931ErrorDummy(Q931_TrunkInfo *pTrunk,L3INT a, L3INT b, L3INT c)
L3INT Q931ErrorDummy(void *priv, L3INT a, L3INT b, L3INT c)
{
return 0;
}
......@@ -235,8 +227,6 @@ 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, */
......@@ -360,7 +350,10 @@ L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, 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);
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;
......@@ -436,20 +433,14 @@ L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size)
*****************************************************************************/
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;
if (pTrunk->Q931ErrorCBProc) {
pTrunk->Q931ErrorCBProc(pTrunk->PrivateData, ErrID, ErrPar1, ErrPar2);
} else {
Q931ErrorProc(pTrunk->PrivateData, ErrID, ErrPar1, ErrPar2);
}
}
void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT))
void Q931SetDefaultErrorCB(Q931ErrorCB_t Q931ErrorPar)
{
Q931ErrorProc = Q931ErrorPar;
}
......
......@@ -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;
......@@ -95,6 +102,11 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931Dialect_t Dialect, Q931NetUs
return 0;
}
pTrunk->Q931Tx34CBProc = Q931Tx34CBProc;
pTrunk->Q931Tx32CBProc = Q931Tx32CBProc;
pTrunk->Q931ErrorCBProc = Q931ErrorCBProc;
pTrunk->PrivateData = PrivateData;
pTrunk->LastCRV = 0;
pTrunk->Dialect = Dialect;
pTrunk->Enabled = 0;
......
......@@ -2,13 +2,7 @@
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.
Description: Contains headers of a Q.921 protocol.
Note: This header file is the only include file that should be
acessed by users of the Q.921 stack.
......@@ -19,7 +13,7 @@
- One driver layer.
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
required and queue messages received out from the ship.
......@@ -33,7 +27,8 @@
Q921Rx32 Receive message from layer 3. Called by
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
deteceted.
......@@ -42,6 +37,10 @@
<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
......@@ -80,31 +79,10 @@
#ifndef _Q921
#define _Q921
#define Q921MAXTRUNK 4
#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 L2INT int /* Min 16 bit signed */
#ifdef Q921_HANDLE_STATIC
#define L2TRUNK long
#define L2TRUNKHANDLE(trunk) Q921DevSpace[trunk]
#else
#define L2TRUNK Q921Data *
#define L2TRUNKHANDLE(trunk) (*trunk)
#endif
#define L2TRUNK Q921Data_t *
typedef enum /* Network/User Mode. */
{
......@@ -112,8 +90,11 @@ typedef enum /* Network/User Mode. */
Q921_NT=1 /* 1 : Network Mode */
} Q921NetUser_t;
typedef struct Q921Data Q921Data_t;
typedef int (*Q921TxCB_t) (void *, L2UCHAR *, L2INT);
#define INITIALIZED_MAGIC 42
typedef struct
struct Q921Data
{
L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE];
L2INT initialized;
......@@ -123,15 +104,22 @@ typedef struct
L2UCHAR sapi;
L2UCHAR tei;
Q921NetUser_t NetUser;
}Q921Data;
void Q921Init();
void Q921_InitTrunk(L2TRUNK trunk, L2UCHAR sapi, L2UCHAR tei, Q921NetUser_t NetUser);
void Q921SetHeaderSpace(int hspace);
void Q921SetTx21CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int));
void Q921SetTx23CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int));
int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, int size);
Q921TxCB_t Q921Tx21Proc;
Q921TxCB_t Q921Tx23Proc;
void *PrivateData;
L2INT Q921HeaderSpace;
};
void Q921_InitTrunk(L2TRUNK trunk,
L2UCHAR sapi,
L2UCHAR tei,
Q921NetUser_t NetUser,
L2INT hsize,
Q921TxCB_t cb21,
Q921TxCB_t cb23,
void *priv);
int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size);
int Q921Rx12(L2TRUNK trunk);
int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size);
#endif
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论