root/src/isdn/nationalmes.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. nationalUmes_Setup
  2. nationalPmes_Setup

   1 /*****************************************************************************
   2 
   3   FileName:     nationalmes.c
   4 
   5   Contents:     Pack/Unpack functions. These functions will unpack a National ISDN
   6                 message from the bit packed original format into structs
   7                 that contains variables sized by the user. It will also pack
   8                 the struct back into a Q.931 message as required.
   9 
  10                 See national.h for description. 
  11 
  12   License/Copyright:
  13 
  14   Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
  15   email:janvb@caselaboratories.com  
  16 
  17   Copyright (c) 2007, Michael Jerris. All rights reserved.
  18   email:mike@jerris.com  
  19 
  20   Redistribution and use in source and binary forms, with or without 
  21   modification, are permitted provided that the following conditions are 
  22   met:
  23 
  24         * Redistributions of source code must retain the above copyright notice, 
  25           this list of conditions and the following disclaimer.
  26         * Redistributions in binary form must reproduce the above copyright notice, 
  27           this list of conditions and the following disclaimer in the documentation 
  28           and/or other materials provided with the distribution.
  29         * Neither the name of the Case Labs, Ltd nor the names of its contributors 
  30           may be used to endorse or promote products derived from this software 
  31           without specific prior written permission.
  32 
  33   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
  34   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
  35   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
  36   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
  37   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  38   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
  39   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
  40   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
  41   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  42   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
  43   POSSIBILITY OF SUCH DAMAGE.
  44 
  45 *****************************************************************************/
  46 
  47 #include "national.h"
  48 
  49 /*****************************************************************************
  50 
  51   Function:      nationalUmes_Setup
  52 
  53 *****************************************************************************/
  54 L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size)
  55 {
  56         L3INT ir = 0;
  57         L3INT OOff = 0;
  58         L3INT rc = Q931E_NO_ERROR;
  59         L3UCHAR last_codeset = 0, codeset = 0;
  60         L3UCHAR shift_lock = 1;
  61 
  62         while (IOff < Size) {
  63                 if (!shift_lock) {
  64                         codeset = last_codeset;
  65                 }
  66 
  67                 if ((IBuf[IOff] & 0xF0) == Q931ie_SHIFT ) {
  68                         shift_lock = (IBuf[IOff] & 0x08);
  69                         if (shift_lock) {
  70                                 last_codeset = codeset;
  71                         }
  72                         codeset = ((IBuf[IOff] & 0x07));
  73                         IOff++;
  74                 }
  75 
  76                 if (codeset == 0) {
  77                         switch (IBuf[IOff]) {
  78                         case Q931ie_SENDING_COMPLETE:
  79                         case Q931ie_BEARER_CAPABILITY:
  80                         case Q931ie_CHANNEL_IDENTIFICATION:
  81                         case Q931ie_PROGRESS_INDICATOR:
  82                         case Q931ie_NETWORK_SPECIFIC_FACILITIES:
  83                         case Q931ie_DISPLAY:
  84                         case Q931ie_DATETIME:
  85                         case Q931ie_KEYPAD_FACILITY:
  86                         case Q931ie_SIGNAL:
  87                         case Q931ie_CALLING_PARTY_NUMBER:
  88                         case Q931ie_CALLING_PARTY_SUBADDRESS:
  89                         case Q931ie_CALLED_PARTY_NUMBER:
  90                         case Q931ie_CALLED_PARTY_SUBADDRESS:
  91                         case Q931ie_TRANSIT_NETWORK_SELECTION:
  92                         case Q931ie_LOW_LAYER_COMPATIBILITY:
  93                         case Q931ie_HIGH_LAYER_COMPATIBILITY:
  94                         case Q931ie_FACILITY:
  95                         case Q931ie_REDIRECTING_NUMBER:
  96                                 rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
  97                                 if (rc != Q931E_NO_ERROR)
  98                                         return rc;
  99                                 break;
 100                         case Q931ie_REPEAT_INDICATOR:
 101                                 if (ir < 2) {
 102                                         rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
 103                                         ir++;
 104                                 } else {
 105                                         return Q931E_ILLEGAL_IE;
 106                                 }
 107                                 break;
 108                         default:
 109                                 return Q931E_ILLEGAL_IE;
 110                                 break;
 111                         }
 112                 } else if (codeset == 6) {
 113                         switch (IBuf[IOff]) {
 114                         case Q931ie_GENERIC_DIGITS:
 115                                 rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
 116                                 if (rc != Q931E_NO_ERROR) 
 117                                         return rc;
 118                                 break;
 119                         default:
 120                                 return Q931E_ILLEGAL_IE;
 121                                 break;
 122                         }
 123 
 124                 } else {
 125                         return Q931E_ILLEGAL_IE;
 126                 }
 127         }
 128         mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
 129         return Q931E_NO_ERROR;
 130 }
 131 
 132 /*****************************************************************************
 133 
 134   Function:      nationalPmes_Setup
 135 
 136   Decription:   Pack a Q931mes_Generic into a real Q.931 message. The user will
 137                                 set up a SETUP message and issue this to the stack where it
 138                                 is processed by Q931ProcSetup that processes and validates
 139                                 it before it actually sends it out. This function is called
 140                                 to compute the real Q.931 message.
 141 
 142   Parameters:   IBuf[IN]        Ptr to un-packed struct
 143                                 ISize[IN]       Size of input buffer (unpacked message).
 144                                 OBuf[OUT]       Ptr to packed 'octet' wise message.
 145                                 OSize[OUT]      Size of packed message.
 146 
 147   Called By:    Q931ProcSetup
 148 
 149 *****************************************************************************/
 150 L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
 151 {
 152         L3INT rc = Q931E_NO_ERROR;
 153         Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
 154         L3INT Octet = 0;
 155 
 156         /* Q931 Message Header */
 157         Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 158 
 159         /* Sending Complete */
 160         if (Q931IsIEPresent(pMes->SendComplete)) {
 161                 OBuf[Octet++]   = (L3UCHAR)(pMes->SendComplete & 0x00ff);
 162         }
 163 
 164         /* Repeat Indicator */
 165         if (Q931IsIEPresent(pMes->RepeatInd)) {
 166                 OBuf[Octet++]   = (L3UCHAR)(pMes->RepeatInd & 0x00ff);          
 167         }
 168 
 169         /* Bearer capability */
 170         if (Q931IsIEPresent(pMes->BearerCap)) {
 171                 if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_BEARER_CAPABILITY](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet)) != 0)
 172                         return rc;
 173         }
 174         else {
 175                 rc = Q931E_BEARERCAP;
 176         }
 177 
 178         /* Channel Identification */
 179         if (Q931IsIEPresent(pMes->ChanID)) {
 180                 if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CHANNEL_IDENTIFICATION](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet)) != 0)
 181                         return rc;
 182         }
 183 
 184         /* Progress indicator */
 185         if (Q931IsIEPresent(pMes->ProgInd)) {
 186                 if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_PROGRESS_INDICATOR](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet)) != 0)
 187                         return rc;
 188         }
 189 
 190         /* Network spesific facilities */
 191         if (Q931IsIEPresent(pMes->NetFac)) {
 192                 if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_NETWORK_SPECIFIC_FACILITIES](pTrunk, Q931GetIEPtr(pMes->NetFac,pMes->buf), OBuf, &Octet)) != 0)
 193                         return rc;
 194         }
 195 
 196         /* Display */
 197         if (Q931IsIEPresent(pMes->Display)) {
 198                 if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet)) != 0)
 199                         return rc;
 200         }
 201 
 202         /* Date/Time */
 203         if (Q931IsIEPresent(pMes->DateTime)) {
 204                 if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_DATETIME](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet)) != 0)
 205                         return rc;
 206         }
 207 
 208         /* Keypad Facility */
 209         if (Q931IsIEPresent(pMes->KeypadFac)) {
 210                 if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_KEYPAD_FACILITY](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet)) != 0)
 211                         return rc;
 212         }
 213 
 214         /* Signal */
 215         if (Q931IsIEPresent(pMes->Signal)) {
 216                 if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet)) != 0)
 217                         return rc;
 218         }
 219 
 220         /* Calling Party Number */
 221         if (Q931IsIEPresent(pMes->CallingNum)) {
 222                 if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLING_PARTY_NUMBER](pTrunk, Q931GetIEPtr(pMes->CallingNum,pMes->buf), OBuf, &Octet)) != 0)
 223                         return rc;
 224         }
 225 
 226         /* Calling Party Subaddress */
 227         if (Q931IsIEPresent(pMes->CallingSub)) {
 228                 if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLING_PARTY_SUBADDRESS](pTrunk, Q931GetIEPtr(pMes->CallingSub,pMes->buf), OBuf, &Octet)) != 0)
 229                         return rc;
 230         }
 231 
 232         /* Called Party number */
 233         if (Q931IsIEPresent(pMes->CalledNum)) {
 234                 if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLED_PARTY_NUMBER](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet)) != 0)
 235                         return rc;
 236         }
 237 
 238         /* Called party subaddress */
 239         if (Q931IsIEPresent(pMes->CalledSub)) {
 240                 if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_CALLED_PARTY_SUBADDRESS](pTrunk, Q931GetIEPtr(pMes->CalledSub,pMes->buf), OBuf, &Octet)) != 0)
 241                         return rc;
 242         }
 243 
 244         /* Transit network selection */
 245         if (Q931IsIEPresent(pMes->TransNetSel)) {
 246                 if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_TRANSIT_NETWORK_SELECTION](pTrunk, Q931GetIEPtr(pMes->TransNetSel,pMes->buf), OBuf, &Octet)) != 0)
 247                         return rc;
 248         }
 249 
 250         /* Repeat Indicator */
 251         if (Q931IsIEPresent(pMes->LLRepeatInd)) {
 252                 rc = Q931E_UNKNOWN_IE;/* TODO */
 253         }
 254 
 255         /* Low Layer Compatibility */
 256         if (Q931IsIEPresent(pMes->LLComp)) {
 257                 if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_LOW_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet)) != 0)
 258                         return rc;
 259         }
 260 
 261         /* High Layer Compatibility */
 262         if (Q931IsIEPresent(pMes->HLComp)) {
 263                 if ((rc = Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet)) != 0)
 264                         return rc;
 265         }
 266 
 267         *OSize = Octet; 
 268         return rc;
 269 }

/* [<][>][^][v][top][bottom][index][help] */