diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index bdac9b8416..b36c76965d 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -47,19 +47,14 @@ #include #include "mfifo.h" -#ifdef _MSC_VER -/* temporary disable */ -#pragma warning(disable: 4244) -#endif - /***************************************************************************** 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}; +int (*Q921Tx21Proc)(int dev, L2UCHAR *, int)={NULL}; +int (*Q921Tx23Proc)(int dev, L2UCHAR *, int)={NULL}; /***************************************************************************** @@ -87,12 +82,12 @@ void Q921SetHeaderSpace(int hspace) Q921HeaderSpace=hspace; } -void Q921SetTx21CB(int (*callback)(int dev, unsigned char *, int)) +void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)) { Q921Tx21Proc = callback; } -void Q921SetTx23CB(int (*callback)(int dev, unsigned char *, int)) +void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)) { Q921Tx23Proc = callback; } @@ -116,7 +111,7 @@ void Q921SetTx23CB(int (*callback)(int dev, unsigned char *, int)) size size of frame in bytes *****************************************************************************/ -int Q921QueueHDLCFrame(int trunk, unsigned char *b, int size) +int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size) { return MFIFOWriteMes(Q921DevSpace[trunk].HDLCInQueue, b, size); } @@ -140,7 +135,7 @@ int Q921QueueHDLCFrame(int trunk, unsigned char *b, int size) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendI(int trunk, unsigned char Sapi, char cr, unsigned char Tei, char pf, unsigned char *mes, int size) +int Q921SendI(int trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, int size) { mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; @@ -169,12 +164,12 @@ int Q921SendI(int trunk, unsigned char Sapi, char cr, unsigned char Tei, char pf int Q921SendRR(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR 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); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)0x01; + mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); } @@ -196,12 +191,12 @@ int Q921SendRR(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendRNR(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR 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); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)0x05; + mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); } @@ -223,12 +218,12 @@ int Q921SendRNR(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendREJ(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR 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); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)0x09; + mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); } @@ -250,11 +245,11 @@ int Q921SendREJ(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendSABME(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = 0x6f | ((pf<<4)&0x10); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x6f | ((pf<<4)&0x10)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); } @@ -276,11 +271,11 @@ int Q921SendSABME(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendDM(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = 0x0f | ((pf<<4)&0x10); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x0f | ((pf<<4)&0x10)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); } @@ -302,11 +297,11 @@ int Q921SendDM(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendDISC(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = 0x43 | ((pf<<4)&0x10); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x43 | ((pf<<4)&0x10)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); } @@ -328,16 +323,16 @@ int Q921SendDISC(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendUA(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = 0x63 | ((pf<<4)&0x10); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x63 | ((pf<<4)&0x10)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); } -int Q921ProcSABME(int trunk, unsigned char *mes, int size) +int Q921ProcSABME(int trunk, L2UCHAR *mes, int size) { /* TODO: Do we need these paramaters? */ (void)mes; @@ -369,9 +364,9 @@ int Q921ProcSABME(int trunk, unsigned char *mes, int size) *****************************************************************************/ int Q921Rx12(long trunk) { - unsigned char *mes; + L2UCHAR *mes; int rs,size; /* receive size & Q921 frame size*/ - unsigned char *smes = MFIFOGetMesPtr(Q921DevSpace[trunk].HDLCInQueue, &size); + L2UCHAR *smes = MFIFOGetMesPtr(Q921DevSpace[trunk].HDLCInQueue, &size); if(smes != NULL) { rs = size - Q921HeaderSpace; diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h index 5537a17aeb..3a0e1b02ac 100644 --- a/libs/openzap/src/isdn/include/Q921.h +++ b/libs/openzap/src/isdn/include/Q921.h @@ -83,19 +83,34 @@ #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 */ + typedef struct { - unsigned char HDLCInQueue[Q921MAXHDLCSPACE]; - unsigned char vs; - unsigned char vr; + L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; + L2UCHAR vs; + L2UCHAR 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, unsigned char *b, int size); +void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)); +void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)); +int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size); int Q921Rx12(long trunk); #endif