Q921priv.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   FileName:     Q921priv.h
00004 
00005   Description:  Private declarations
00006 
00007   Created:      08.Aug.2008/STKN
00008 
00009   License/Copyright:
00010 
00011   Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
00012   email:janvb@caselaboratories.com  
00013 
00014   Copyright (c) 2008, Stefan Knoblich, axsentis GmbH. All rights reserved.
00015   email:s.knoblich@axsentis.de  
00016 
00017   Redistribution and use in source and binary forms, with or without 
00018   modification, are permitted provided that the following conditions are 
00019   met:
00020 
00021     * Redistributions of source code must retain the above copyright notice, 
00022           this list of conditions and the following disclaimer.
00023     * Redistributions in binary form must reproduce the above copyright notice, 
00024           this list of conditions and the following disclaimer in the documentation 
00025           and/or other materials provided with the distribution.
00026     * Neither the name of the Case Labs, Ltd nor the names of its contributors 
00027           may be used to endorse or promote products derived from this software 
00028           without specific prior written permission.
00029 
00030   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00031   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00032   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
00033   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
00034   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00035   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00036   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00037   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00038   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00039   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00040   POSSIBILITY OF SUCH DAMAGE.
00041 
00042 *****************************************************************************/
00043 #ifndef _Q921_PRIV_H_
00044 #define _Q921_PRIV_H_
00045 
00046 #ifdef _MSC_VER
00047 #ifndef __inline__
00048 #define __inline__ __inline
00049 #endif
00050 #if (_MSC_VER >= 1400)                  /* VC8+ */
00051 #ifndef _CRT_SECURE_NO_DEPRECATE
00052 #define _CRT_SECURE_NO_DEPRECATE
00053 #endif
00054 #ifndef _CRT_NONSTDC_NO_DEPRECATE
00055 #define _CRT_NONSTDC_NO_DEPRECATE
00056 #endif
00057 #endif
00058 #ifndef strcasecmp
00059 #define strcasecmp(s1, s2) _stricmp(s1, s2)
00060 #endif
00061 #ifndef strncasecmp
00062 #define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
00063 #endif
00064 #ifndef snprintf
00065 #define snprintf _snprintf
00066 #endif
00067 #endif
00068 
00069 typedef enum                    /* Q.921 States */
00070 {
00071         Q921_STATE_STOPPED = 0,                 /* Trunk stopped */
00072         Q921_STATE_TEI_UNASSIGNED = 1,          /* TEI unassigned */
00073         Q921_STATE_TEI_AWAITING,                /* Assign awaiting TEI */
00074         Q921_STATE_TEI_ESTABLISH,               /* Establish awaiting TEI */
00075         Q921_STATE_TEI_ASSIGNED,                /* TEI assigned */
00076         Q921_STATE_AWAITING_ESTABLISHMENT,      /* Awaiting establishment */
00077         Q921_STATE_AWAITING_RELEASE,            /* Awaiting release */
00078         Q921_STATE_MULTIPLE_FRAME_ESTABLISHED,  /* Multiple frame established */
00079         Q921_STATE_TIMER_RECOVERY,              /* Timer recovery */
00080 
00081         Q921_STATE_MAX
00082 } Q921State_t;
00083 
00084 /*
00085  * Flags
00086  */
00087 enum Q921_Flags {
00088         Q921_FLAG_L3_INITIATED = (1 << 0),
00089 
00090         Q921_FLAG_UI_FRAME_QUEUED = (1 << 1),
00091         Q921_FLAG_I_FRAME_QUEUED  = (1 << 2),
00092 
00093         Q921_FLAG_ACK_PENDING = (1 << 3),
00094         Q921_FLAG_REJECT      = (1 << 4),
00095 
00096         Q921_FLAG_RECV_BUSY      = (1 << 5),
00097         Q921_FLAG_PEER_RECV_BUSY = (1 << 6)
00098 };
00099 
00100 #define Q921_SET_FLAG(x, f)     ((x)->flags |= f)
00101 #define Q921_CHECK_FLAG(x, f)   ((x)->flags & f)
00102 #define Q921_CLEAR_FLAG(x, f)   ((x)->flags &= ~f)
00103 
00104 
00105 /*
00106  * dynamic TEI handling
00107  */
00108 #define Q921_SAPI_TEI           63      /* SAPI for all TEI Messages */
00109 #define Q921_LAYER_ENT_ID_TEI   0x0f    /* UN Layer Management Entity ID for TEI Mgmt */
00110 #define Q921_LAYER_ENT_ID_Q931  0x08    /* Q.931 Layer Management Entity ID */
00111 
00112 
00113 typedef enum {
00114         Q921_TEI_ID_REQUEST = 1,
00115         Q921_TEI_ID_ASSIGNED,
00116         Q921_TEI_ID_DENIED,
00117         Q921_TEI_ID_CHECKREQ,
00118         Q921_TEI_ID_CHECKRESP,
00119         Q921_TEI_ID_REMOVE,
00120         Q921_TEI_ID_VERIFY
00121 } Q921TeiMessageType_t;
00122 
00123 #ifdef Q921_STATISTICS
00124 
00127 typedef struct Q921Stats
00128 {
00129         unsigned int counter[Q921_STATS_MAX];
00130 } Q921Stats_t;
00131 #endif
00132 
00136 struct Q921_Link {
00137         L2UCHAR tei;            
00139         L2UCHAR va;
00140         L2UCHAR vs;
00141         L2UCHAR vr;
00142 
00143         L2INT flags;
00144         Q921State_t state;
00145 
00146         L2ULONG N202;           
00147         L2ULONG N200;           
00149         L2ULONG TM01;           
00151         L2ULONG T200;
00152         L2ULONG T201;           
00153         L2ULONG T203;
00154 
00155         L2USHORT ri;            
00157 #ifdef Q921_STATISTICS
00158         /* Statistics */
00159         Q921Stats_t stats;      
00160 #endif
00161 
00162         /* I + UI Frame queue */
00163         L2UCHAR UIFrameQueue[Q921MAXHDLCSPACE];
00164         L2UCHAR  IFrameQueue[Q921MAXHDLCSPACE];
00165         L2UCHAR  IFrameResendQueue[Q921MAXHDLCSPACE];
00166 };
00167 
00168 
00169 #define Q921_LINK_CONTEXT(tr, tei) \
00170         (Q921_IS_PTMP_NT(tr) && tei != Q921_TEI_BCAST) ? ((struct Q921_Link *)&(tr)->context[tei]) : (tr)->context
00171 
00172 #define Q921_TRUNK_CONTEXT(tr) \
00173         (tr)->context
00174 
00175 #define Q921_LOGBUFSIZE         2000
00176 #define INITIALIZED_MAGIC       42
00177 
00178 /*
00179  * Helper macros
00180  */
00181 #define Q921_INC_COUNTER(x)             (x = (x + 1) % 128)
00182 #define Q921_DEC_COUNTER(x)             (x = (x) ? (x - 1) : 127)
00183 
00184 #define Q921_UFRAME_HEADER_SIZE         3
00185 #define Q921_UFRAME_DATA_OFFSET(tr)     ((tr)->Q921HeaderSpace + Q921_UFRAME_HEADER_SIZE)
00186 
00187 #define Q921_SFRAME_HEADER_SIZE         4
00188 #define Q921_SFRAME_DATA_OFFSET(tr)     ((tr)->Q921HeaderSpace + Q921_SFRAME_HEADER_SIZE)
00189 
00190 #define Q921_IFRAME_HEADER_SIZE         4
00191 #define Q921_IFRAME_DATA_OFFSET(tr)     ((tr)->Q921HeaderSpace + Q921_IFRAME_HEADER_SIZE)
00192 
00193 #define Q921_IS_TE(x)                   ((x)->NetUser == Q921_TE)
00194 #define Q921_IS_NT(x)                   ((x)->NetUser == Q921_NT)
00195 
00196 #define Q921_IS_STOPPED(tr)             ((tr)->state == Q921_STATE_STOPPED)
00197 
00198 /* TODO: rework this one */
00199 #define Q921_IS_READY(tr)               ((tr)->state >= Q921_STATE_TEI_ASSIGNED)
00200 
00201 #define Q921_IS_PTMP(x)                 ((x)->NetType == Q921_PTMP)
00202 #define Q921_IS_PTMP_TE(x)              ((x)->NetType == Q921_PTMP && (x)->NetUser == Q921_TE)
00203 #define Q921_IS_PTMP_NT(x)              ((x)->NetType == Q921_PTMP && (x)->NetUser == Q921_NT)
00204 
00205 #define Q921_IS_PTP(x)                  ((x)->NetType == Q921_PTP)
00206 #define Q921_IS_PTP_TE(x)               ((x)->NetType == Q921_PTP && (x)->NetUser == Q921_TE)
00207 #define Q921_IS_PTP_NT(x)               ((x)->NetType == Q921_PTP && (x)->NetUser == Q921_NT)
00208 
00209 /* Make life a little easier */
00210 #define Q921_COMMAND(x)                 ((x)->NetUser == Q921_TE ? 0 : 1)
00211 #define Q921_RESPONSE(x)                ((x)->NetUser == Q921_TE ? 1 : 0)
00212 
00213 #define Q921_IS_COMMAND(tr, x)          ((x) == (Q921_IS_TE(tr) ? 1 : 0))
00214 #define Q921_IS_RESPONSE(tr, x)         ((x) == (Q921_IS_TE(tr) ? 0 : 1))
00215 
00216 
00217 /*******************************************************************************
00218  * Private functions
00219  *******************************************************************************/
00220 
00221 /*
00222  * L1 / L2 Interface
00223  */
00224 static int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size);
00225 static int Q921Tx23Proc(L2TRUNK trunk, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *Msg, L2INT size);
00226 
00227 
00228 /*
00229  * Timers
00230  */
00231 static L2ULONG Q921GetTime(void);
00232 
00233 static void Q921T200TimerStart(L2TRUNK trunk, L2UCHAR tei);
00234 static void Q921T200TimerStop(L2TRUNK trunk, L2UCHAR tei);
00235 static void Q921T200TimerReset(L2TRUNK trunk, L2UCHAR tei);
00236 static void Q921T200TimerExpire(L2TRUNK trunk, L2UCHAR tei);
00237 
00238 static void Q921T201TimerStart(L2TRUNK trunk, L2UCHAR tei);
00239 static void Q921T201TimerStop(L2TRUNK trunk, L2UCHAR tei);
00240 /* static void Q921T201TimerReset(L2TRUNK trunk, L2UCHAR tei); - Unused for now */
00241 static void Q921T201TimerExpire(L2TRUNK trunk, L2UCHAR tei);
00242 
00243 static void Q921T202TimerStart(L2TRUNK trunk);
00244 static void Q921T202TimerStop(L2TRUNK trunk);
00245 static void Q921T202TimerReset(L2TRUNK trunk);
00246 static void Q921T202TimerExpire(L2TRUNK trunk);
00247 
00248 static void Q921T203TimerStart(L2TRUNK trunk, L2UCHAR tei);
00249 static void Q921T203TimerStop(L2TRUNK trunk, L2UCHAR tei);
00250 static void Q921T203TimerReset(L2TRUNK trunk, L2UCHAR tei);
00251 static void Q921T203TimerExpire(L2TRUNK trunk, L2UCHAR tei);
00252 
00253 static void Q921TM01TimerStart(L2TRUNK trunk, L2UCHAR tei);
00254 /* static void Q921TM01TimerStop(L2TRUNK trunk, L2UCHAR tei); - Unused for now */
00255 static void Q921TM01TimerReset(L2TRUNK trunk, L2UCHAR tei);
00256 /* static void Q921TM01TimerExpire(L2TRUNK trunk, L2UCHAR tei); - Unused for now */
00257 
00258 /*
00259  * Frame encoding
00260  */
00261 static int Q921SendS(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR sv, L2UCHAR *mes, L2INT size);
00262 static int Q921SendU(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR m, L2UCHAR *mes, L2INT size);
00263 
00264 static int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf);
00265 static int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf);
00266 static int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf);
00267 static int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf);
00268 static int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf);
00269 static int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf);
00270 static int Q921SendUN(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf, L2UCHAR *mes, L2INT size);
00271 static int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf);
00272 
00273 /*
00274  * Frame decoding
00275  */
00276 static int Q921ProcIFrame(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
00277 static int Q921ProcSFrame(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
00278 static int Q921ProcUFrame(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
00279 
00280 static int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
00281 static int Q921ProcDM(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
00282 static int Q921ProcUA(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
00283 static int Q921ProcDISC(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
00284 static int Q921ProcRR(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
00285 static int Q921ProcRNR(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
00286 static int Q921ProcREJ(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
00287 
00288 
00289 /*
00290  * (Common) procedures defined in the Q.921 SDL
00291  */
00292 static int Q921SendEnquiry(L2TRUNK trunk, L2UCHAR tei);
00293 static int Q921SendEnquiryResponse(L2TRUNK trunk, L2UCHAR tei);
00294 static void Q921ResetExceptionConditions(L2TRUNK trunk, L2UCHAR tei);
00295 static int Q921EstablishDataLink(L2TRUNK trunk, L2UCHAR tei);
00296 static int Q921NrErrorRecovery(L2TRUNK trunk, L2UCHAR tei);
00297 static int Q921InvokeRetransmission(L2TRUNK trunk, L2UCHAR tei, L2UCHAR nr);
00298 static int Q921AcknowledgePending(L2TRUNK trunk, L2UCHAR tei);
00299 /*
00300 static int Q921SetReceiverBusy(L2TRUNK trunk);
00301 static int Q921ClearReceiverBusy(L2TRUNK trunk);
00302 */
00303 
00304 /*
00305  * Queueing
00306  */
00307 static int Q921SendQueuedIFrame(L2TRUNK trunk, L2UCHAR tei);
00308 static int Q921EnqueueI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, L2INT size);
00309 
00310 /*
00311  * TEI management
00312  */
00313 static int Q921TeiSendAssignRequest(L2TRUNK trunk);
00314 static int Q921TeiProcAssignResponse(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
00315 static int Q921TeiSendVerifyRequest(L2TRUNK trunk);
00316 static int Q921TeiProcCheckRequest(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
00317 static int Q921TeiProcRemoveRequest(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
00318 static int Q921TeiProcAssignRequest(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
00319 static int Q921TeiProcCheckResponse(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
00320 static int Q921TeiProcVerifyRequest(L2TRUNK trunk, L2UCHAR *mes, L2INT size);
00321 static int Q921TeiSendRemoveRequest(L2TRUNK trunk, L2UCHAR tei);
00322 static int Q921TeiSendDenyResponse(L2TRUNK trunk, L2UCHAR tei, L2USHORT ri);
00323 static int Q921TeiSendAssignedResponse(L2TRUNK trunk, L2UCHAR tei, L2USHORT ri);
00324 static int Q921TeiSendCheckRequest(L2TRUNK trunk, L2UCHAR tei);
00325 
00326 /*
00327  * Logging
00328  */
00329 static int Q921Log(L2TRUNK trunk, Q921LogLevel_t level, const char *fmt, ...);
00330 static int Q921LogMesg(L2TRUNK trunk, Q921LogLevel_t level, L2UCHAR received, L2UCHAR *mes, L2INT size, const char *fmt, ...);
00331 
00332 /*
00333  * State handling
00334  */
00335 static int Q921ChangeState(L2TRUNK trunk, Q921State_t state, L2UCHAR tei);
00336 
00337 #ifdef Q921_STATISTICS
00338 /*
00339  * Statistics
00340  */
00341 static void Q921StatsIncrementCounter(struct Q921_Link *link, const int counter);
00342 
00343 #endif
00344 #endif

Generated on Tue Apr 7 17:38:19 2009 for mod_ssh by  doxygen 1.5.4