1 /***************************************************************************** 2 3 FileName: q921.h 4 5 Description: Contains headers of a Q.921 protocol. 6 7 Note: This header file is the only include file that should be 8 acessed by users of the Q.921 stack. 9 10 Interface: The Q.921 stack contains 2 layers. 11 12 - One interface layer. 13 - One driver layer. 14 15 The interface layer contains the interface functions required 16 for a layer 2 stack to be able to send and receive messages. 17 18 The driver layer will simply feed bytes into the ship as 19 required and queue messages received out from the ship. 20 21 Q921TimeTick The Q.921 like any other blackbox 22 modules contains no thread by it's own 23 and must therefore be called regularly 24 by an external 'thread' to do maintenance 25 etc. 26 27 Q921Rx32 Receive message from layer 3. Called by 28 the layer 3 stack to send a message. 29 30 31 NOTE: The following are not yet implemented 32 33 OnQ921Error Function called every if an error is 34 detected. 35 36 OnQ921Log Function called if logging is active. 37 38 39 <TODO> Maintenance/Configuration interface 40 <TODO> Logging 41 <TODO> DL_ message passing to layer 3 42 <TODO> Timers 43 <TODO> Api commands to tell 921 to stop and start for a trunk 44 45 Created: 27.dec.2000/JVB 46 47 License/Copyright: 48 49 Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved. 50 email:janvb@caselaboratories.com 51 52 Redistribution and use in source and binary forms, with or without 53 modification, are permitted provided that the following conditions are 54 met: 55 56 * Redistributions of source code must retain the above copyright notice, 57 this list of conditions and the following disclaimer. 58 * Redistributions in binary form must reproduce the above copyright notice, 59 this list of conditions and the following disclaimer in the documentation 60 and/or other materials provided with the distribution. 61 * Neither the name of the Case Labs, Ltd nor the names of its contributors 62 may be used to endorse or promote products derived from this software 63 without specific prior written permission. 64 65 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 66 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 67 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 68 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 69 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 70 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 71 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 72 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 73 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 74 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 75 POSSIBILITY OF SUCH DAMAGE. 76 77 *****************************************************************************/ 78 79 /**************************************************************************** 80 * Changes: 81 * 82 * - June,July 2008: Stefan Knoblich <s.knoblich@axsentis.de>: 83 * Add PTMP TEI management 84 * Add timers 85 * Add retransmit counters 86 * Add logging 87 * Various cleanups 88 * 89 ****************************************************************************/ 90 91 #ifndef _Q921 92 #define _Q921 93 94 #define Q921MAXHDLCSPACE 3000 95 #define L2UCHAR unsigned char /* Min 8 bit */ 96 #define L2USHORT unsigned short /* 16 bit */ 97 #define L2INT int /* Min 16 bit signed */ 98 #define L2ULONG unsigned long /* Min 32 bit */ 99 #define L2TRUNK Q921Data_t * 100 101 #define Q921_TEI_BCAST 127 102 #define Q921_TEI_MAX Q921_TEI_BCAST 103 104 #define Q921_TEI_DYN_MIN 64 105 #define Q921_TEI_DYN_MAX 126 106 107 108 typedef enum /* Network/User Mode */ 109 { 110 Q921_TE=0, /* 0 : User Mode */ 111 Q921_NT=1 /* 1 : Network Mode */ 112 } Q921NetUser_t; 113 114 typedef enum /* Type of connection */ 115 { 116 Q921_PTP=0, /* 0 : Point-To-Point */ 117 Q921_PTMP=1 /* 1 : Point-To-Multipoint */ 118 } Q921NetType_t; 119 120 typedef enum 121 { 122 Q921_LOG_NONE = -1, 123 Q921_LOG_EMERG = 0, 124 Q921_LOG_ALERT, 125 Q921_LOG_CRIT, 126 Q921_LOG_ERROR, 127 Q921_LOG_WARNING, 128 Q921_LOG_NOTICE, 129 Q921_LOG_INFO, 130 Q921_LOG_DEBUG 131 } Q921LogLevel_t; 132 133 134 /* 135 * Messages for L2 <-> L3 communication 136 */ 137 typedef enum { 138 Q921_DL_ESTABLISH = 0, 139 Q921_DL_ESTABLISH_CONFIRM, 140 Q921_DL_RELEASE, 141 Q921_DL_RELEASE_CONFIRM, 142 Q921_DL_DATA, 143 Q921_DL_UNIT_DATA 144 } Q921DLMsg_t; 145 146 typedef int (*Q921Tx21CB_t) (void *, L2UCHAR *, L2INT); 147 typedef int (*Q921Tx23CB_t) (void *, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *, L2INT); 148 typedef int (*Q921LogCB_t) (void *, Q921LogLevel_t, char *, L2INT); 149 150 struct Q921_Link; 151 152 typedef struct Q921Data 153 { 154 L2INT initialized; 155 156 L2UCHAR sapi; /*!< User assigned SAPI */ 157 L2UCHAR tei; /*!< User assigned TEI value */ 158 159 L2INT Q921HeaderSpace; 160 Q921NetUser_t NetUser; 161 Q921NetType_t NetType; 162 163 struct Q921_Link *context; /*!< per-TEI / link context space */ 164 165 /* timers */ 166 L2ULONG T202; /*!< PTMP TE mode TEI retransmit timer */ 167 L2ULONG T200Timeout; 168 L2ULONG T201Timeout; 169 L2ULONG T202Timeout; 170 L2ULONG T203Timeout; 171 172 L2ULONG TM01Timeout; 173 174 /* counters */ 175 L2ULONG N200Limit; /*!< max retransmit */ 176 177 L2ULONG N202; /*!< PTMP TE mode retransmit counter */ 178 L2ULONG N202Limit; /*!< PTMP TE mode max retransmit */ 179 180 L2ULONG N201Limit; /*!< max number of octets */ 181 L2ULONG k; /*!< max number of unacknowledged I frames */ 182 183 /* callbacks and callback data pointers */ 184 Q921Tx21CB_t Q921Tx21Proc; 185 Q921Tx23CB_t Q921Tx23Proc; 186 void *PrivateData21; 187 void *PrivateData23; 188 189 /* logging */ 190 Q921LogLevel_t loglevel; /*!< trunk loglevel */ 191 Q921LogCB_t Q921LogProc; /*!< log callback procedure */ 192 void *PrivateDataLog; /*!< private data pointer for log proc */ 193 194 /* tei mgmt */ 195 L2UCHAR tei_map[Q921_TEI_MAX]; /*!< */ 196 197 L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; /*!< HDLC input queue */ 198 } Q921Data_t; 199 200 /* 201 * Public functions 202 */ 203 int Q921_InitTrunk(L2TRUNK trunk, 204 L2UCHAR sapi, 205 L2UCHAR tei, 206 Q921NetUser_t NetUser, 207 Q921NetType_t NetType, 208 L2INT hsize, 209 Q921Tx21CB_t cb21, 210 Q921Tx23CB_t cb23, 211 void *priv21, 212 void *priv23); 213 int Q921Start(L2TRUNK trunk); 214 int Q921Stop(L2TRUNK trunk); 215 216 void Q921SetLogCB(L2TRUNK trunk, Q921LogCB_t func, void *priv); 217 void Q921SetLogLevel(L2TRUNK trunk, Q921LogLevel_t level); 218 219 int Q921Rx12(L2TRUNK trunk); 220 int Q921Rx32(L2TRUNK trunk, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR * Mes, L2INT Size); 221 222 int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size); 223 224 void Q921SetGetTimeCB(L2ULONG (*callback)(void)); 225 void Q921TimerTick(L2TRUNK trunk); 226 227 #endif