Q921.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   FileName:     q921.h
00004 
00005   Description:  Contains headers of a Q.921 protocol.
00006 
00007   Note:         This header file is the only include file that should be 
00008                 acessed by users of the Q.921 stack.
00009 
00010   Interface:    The Q.921 stack contains 2 layers. 
00011 
00012                 -   One interface layer.
00013                 -   One driver layer.
00014 
00015                 The interface layer contains the interface functions required 
00016                 for a layer 2 stack to be able to send and receive messages.
00017 
00018                 The driver layer will simply feed bytes into the ship as
00019                 required and queue messages received out from the ship.
00020 
00021                 Q921TimeTick        The Q.921 like any other blackbox 
00022                                     modules contains no thread by it's own
00023                                     and must therefore be called regularly 
00024                                     by an external 'thread' to do maintenance
00025                                     etc.
00026 
00027                 Q921Rx32            Receive message from layer 3. Called by
00028                                     the layer 3 stack to send a message.
00029 
00030 
00031                                 NOTE: The following are not yet implemented
00032 
00033                 OnQ921Error         Function called every if an error is 
00034                                     detected.
00035 
00036                 OnQ921Log           Function called if logging is active.
00037 
00038 
00039                 <TODO> Maintenance/Configuration interface
00040                                 <TODO> Logging
00041                                 <TODO> DL_ message passing to layer 3
00042                                 <TODO> Timers
00043                                 <TODO> Api commands to tell 921 to stop and start for a trunk
00044 
00045   Created:      27.dec.2000/JVB
00046 
00047   License/Copyright:
00048 
00049   Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
00050   email:janvb@caselaboratories.com  
00051 
00052   Redistribution and use in source and binary forms, with or without 
00053   modification, are permitted provided that the following conditions are 
00054   met:
00055 
00056     * Redistributions of source code must retain the above copyright notice, 
00057           this list of conditions and the following disclaimer.
00058     * Redistributions in binary form must reproduce the above copyright notice, 
00059           this list of conditions and the following disclaimer in the documentation 
00060           and/or other materials provided with the distribution.
00061     * Neither the name of the Case Labs, Ltd nor the names of its contributors 
00062           may be used to endorse or promote products derived from this software 
00063           without specific prior written permission.
00064 
00065   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00066   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00067   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
00068   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
00069   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00070   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00071   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00072   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00073   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00074   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00075   POSSIBILITY OF SUCH DAMAGE.
00076 
00077 *****************************************************************************/
00078 
00079 /****************************************************************************
00080  * Changes:
00081  *
00082  * - June,July 2008: Stefan Knoblich <s.knoblich@axsentis.de>:
00083  *     Add PTMP TEI management
00084  *     Add timers
00085  *     Add retransmit counters
00086  *     Add logging
00087  *     Various cleanups
00088  *
00089  ****************************************************************************/
00090 
00091 #ifndef _Q921
00092 #define _Q921
00093 
00094 #define Q921_STATISTICS
00095 #define Q921_STATISTICS_VERBOSE
00096 
00097 #define Q921MAXHDLCSPACE 3000
00098 #define L2UCHAR         unsigned char           /* Min 8 bit                    */
00099 #define L2USHORT        unsigned short          /* 16 bit                       */
00100 #define L2INT           int                     /* Min 16 bit signed            */
00101 #define L2ULONG         unsigned long           /* Min 32 bit                   */
00102 #define L2TRUNK         Q921Data_t *
00103 
00104 #define Q921_TEI_BCAST          127
00105 #define Q921_TEI_MAX            Q921_TEI_BCAST
00106 
00107 #define Q921_TEI_DYN_MIN        64
00108 #define Q921_TEI_DYN_MAX        126
00109 
00110 
00114 typedef enum
00115 {
00116         Q921_TE = 0,            
00117         Q921_NT = 1             
00118 } Q921NetUser_t;
00119 
00123 typedef enum
00124 {
00125         Q921_PTP  = 0,          
00126         Q921_PTMP = 1           
00127 } Q921NetType_t;
00128 
00132 typedef enum
00133 {
00134         Q921_LOG_NONE  = 0,
00135         Q921_LOG_EMERG,
00136         Q921_LOG_ALERT,
00137         Q921_LOG_CRIT,
00138         Q921_LOG_ERROR,
00139         Q921_LOG_WARNING,
00140         Q921_LOG_NOTICE,
00141         Q921_LOG_INFO,
00142         Q921_LOG_DEBUG
00143 } Q921LogLevel_t;
00144 
00145 
00146 /*
00147  * Messages for L2 <-> L3 communication
00148  */
00149 typedef enum {
00150         Q921_DL_ESTABLISH = 0,
00151         Q921_DL_ESTABLISH_CONFIRM,
00152         Q921_DL_RELEASE,
00153         Q921_DL_RELEASE_CONFIRM,
00154         Q921_DL_DATA,
00155         Q921_DL_UNIT_DATA
00156 } Q921DLMsg_t;
00157 
00158 typedef int (*Q921Tx21CB_t) (void *, L2UCHAR *, L2INT);
00159 typedef int (*Q921Tx23CB_t) (void *, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *, L2INT);
00160 typedef int (*Q921LogCB_t)  (void *, Q921LogLevel_t, char *, L2INT);
00161 
00162 struct Q921_Link;
00163 
00164 #ifdef Q921_STATISTICS
00165 enum {
00166         Q921_STATS_NONE = 0,
00167 
00168         /* state changes */
00169         Q921_STATS_ST01,
00170         Q921_STATS_ST02,
00171         Q921_STATS_ST03,
00172         Q921_STATS_ST04,
00173         Q921_STATS_ST05,
00174         Q921_STATS_ST06,
00175         Q921_STATS_ST07,
00176         Q921_STATS_ST08,
00177 
00178         /* timer events */
00179         Q921_STATS_T200,
00180         Q921_STATS_T201,
00181         Q921_STATS_T202,
00182         Q921_STATS_T203,
00183 
00184         Q921_STATS_TM01,
00185 
00186         /* limit / counter overruns */
00187         Q921_STATS_N200,
00188         Q921_STATS_N201,
00189         Q921_STATS_N202,
00190 
00191 #ifdef Q921_STATISTICS_VERBOSE
00192         /* packet send counters */
00193         Q921_STATS_SEND_S,
00194         Q921_STATS_SEND_U,
00195         Q921_STATS_SEND_I,
00196 
00197         Q921_STATS_SEND_RR,
00198         Q921_STATS_SEND_RNR,
00199         Q921_STATS_SEND_REJ,
00200         Q921_STATS_SEND_SABME,
00201         Q921_STATS_SEND_DM,
00202         Q921_STATS_SEND_DISC,
00203         Q921_STATS_SEND_UA,
00204         Q921_STATS_SEND_UN,
00205 
00206         /* packet receive counters */
00207         Q921_STATS_RECV_S,
00208         Q921_STATS_RECV_U,
00209         Q921_STATS_RECV_I,
00210 
00211         Q921_STATS_RECV_INVALID_S,
00212         Q921_STATS_RECV_INVALID_U,
00213         Q921_STATS_RECV_INVALID_I,
00214 
00215         Q921_STATS_RECV_SABME,
00216         Q921_STATS_RECV_DM,
00217         Q921_STATS_RECV_UA,
00218         Q921_STATS_RECV_DISC,
00219         Q921_STATS_RECV_RR,
00220         Q921_STATS_RECV_REJ,
00221         Q921_STATS_RECV_RNR,
00222 #endif
00223         /* don't touch */
00224         Q921_STATS_MAX
00225 };
00226 #endif
00227 
00232 typedef struct Q921Data
00233 {
00234         L2INT initialized;
00235 
00236         L2UCHAR sapi;                   
00237         L2UCHAR tei;                    
00239         L2INT Q921HeaderSpace;
00240         Q921NetUser_t NetUser;
00241         Q921NetType_t NetType;
00242 
00243         struct Q921_Link *context;      
00245         /* timers */
00246         L2ULONG T202;                   
00247         L2ULONG T200Timeout;
00248         L2ULONG T201Timeout;
00249         L2ULONG T202Timeout;
00250         L2ULONG T203Timeout;
00251 
00252         L2ULONG TM01Timeout;
00253 
00254         /* counters */
00255         L2ULONG N200Limit;              
00257         L2ULONG N202;                   
00258         L2ULONG N202Limit;              
00260         L2ULONG N201Limit;              
00261         L2ULONG k;                      
00263         /* callbacks and callback data pointers */
00264         Q921Tx21CB_t Q921Tx21Proc;
00265         Q921Tx23CB_t Q921Tx23Proc;
00266         void *PrivateData21;
00267         void *PrivateData23;
00268 
00269         /* logging */
00270         Q921LogLevel_t  loglevel;       
00271         Q921LogCB_t     Q921LogProc;    
00272         void *PrivateDataLog;           
00274         /* tei mgmt */
00275         L2UCHAR tei_map[Q921_TEI_MAX];  
00277         L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE];  
00278 } Q921Data_t;
00279 
00287 int Q921_InitTrunk(L2TRUNK trunk,
00288                                         L2UCHAR sapi,
00289                                         L2UCHAR tei,
00290                                         Q921NetUser_t NetUser,
00291                                         Q921NetType_t NetType,
00292                                         L2INT hsize,
00293                                         Q921Tx21CB_t cb21,
00294                                         Q921Tx23CB_t cb23,
00295                                         void *priv21,
00296                                         void *priv23);
00300 int Q921Start(L2TRUNK trunk);
00301 
00305 int Q921Stop(L2TRUNK trunk);
00306 
00310 void Q921SetLogCB(L2TRUNK trunk, Q921LogCB_t func, void *priv);
00311 
00315 void Q921SetLogLevel(L2TRUNK trunk, Q921LogLevel_t level);
00316 
00320 int Q921Rx12(L2TRUNK trunk);
00321 
00325 int Q921Rx32(L2TRUNK trunk, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR * Mes, L2INT Size);
00326 
00330 int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size);
00331 
00335 void Q921SetGetTimeCB(L2ULONG (*callback)(void));
00336 
00340 void Q921TimerTick(L2TRUNK trunk);
00341 
00342 
00348 #ifdef Q921_STATISTICS
00349 
00350 unsigned int Q921StatsGetCounter(const L2TRUNK trunk, const int id, const int tei);
00351 
00352 #define Q921StatsGetCounterSum(tr, st) \
00353         Q921StatsGetCounter(tr, st, Q921_TEI_BCAST)
00354 
00355 /* Reset all counters to zero */
00356 void Q921StatsResetCounters(L2TRUNK trunk);
00357 
00358 /* counter meta-information */
00359 const char *Q921StatsCounterGetName(const int id);
00360 const char *Q921StatsCounterGetDescription(const int id);
00361 int Q921StatsCounterIsGlobal(const int id);
00362 
00363 /* Dump report to log */
00364 int Q921StatsReport(const L2TRUNK trunk, const int tei);
00365 
00366 #endif
00367 
00369 #endif

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