TLVDecoder.h 3.77 KB
Newer Older
dukl's avatar
dukl committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the Apache License, Version 2.0  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

/*! \file TLVDecoder.h
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
23 24 25 26
 \brief
 \author Philippe MOREL, Sebastien ROUX, Lionel GAUTHIER
 \company Eurecom
 */
dukl's avatar
dukl committed
27 28 29 30 31 32 33

#ifndef FILE_TLV_DECODER_SEEN
#define FILE_TLV_DECODER_SEEN

#include "bstrlib.h"
#include "common_defs.h"

34 35
#define IES_DECODE_U8(bUFFER, dECODED, vALUE)                                  \
  DECODE_U8(bUFFER + dECODED, vALUE, dECODED)
dukl's avatar
dukl committed
36

37 38
#define IES_DECODE_U16(bUFFER, dECODED, vALUE)                                 \
  DECODE_U16(bUFFER + dECODED, vALUE, dECODED)
dukl's avatar
dukl committed
39

40 41
#define IES_DECODE_U24(bUFFER, dECODED, vALUE)                                 \
  DECODE_U24(bUFFER + dECODED, vALUE, dECODED)
dukl's avatar
dukl committed
42

43 44
#define IES_DECODE_U32(bUFFER, dECODED, vALUE)                                 \
  DECODE_U32(bUFFER + dECODED, vALUE, dECODED)
dukl's avatar
dukl committed
45 46 47

extern int errorCodeDecoder;

48 49 50
int decode_bstring(
    bstring* octetstring, const uint16_t pdulen, const uint8_t* const buffer,
    const uint32_t buflen);
dukl's avatar
dukl committed
51

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
52
bstring dump_bstring_xml(const bstring bstr);
dukl's avatar
dukl committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66

void tlv_decode_perror(void);

#define CHECK_PDU_POINTER_AND_LENGTH_DECODER(bUFFER, mINIMUMlENGTH, lENGTH)    \
  if (bUFFER == NULL) {                                                        \
    errorCodeDecoder = TLV_BUFFER_NULL;                                        \
    return TLV_BUFFER_NULL;                                                    \
  }                                                                            \
  if (lENGTH < mINIMUMlENGTH) {                                                \
    errorCodeDecoder = TLV_BUFFER_TOO_SHORT;                                   \
    return TLV_BUFFER_TOO_SHORT;                                               \
  }

#define CHECK_LENGTH_DECODER(bUFFERlENGTH, lENGTH)                             \
67 68 69 70
  if (bUFFERlENGTH < lENGTH) {                                                 \
    errorCodeDecoder = TLV_BUFFER_TOO_SHORT;                                   \
    return TLV_BUFFER_TOO_SHORT;                                               \
  }
dukl's avatar
dukl committed
71 72

#define CHECK_MESSAGE_TYPE(mESSAGE_tYPE, bUFFER)                               \
73 74 75 76 77 78
  {                                                                            \
    if (mESSAGE_tYPE != bUFFER) {                                              \
      errorCodeDecoder = TLV_WRONG_MESSAGE_TYPE;                               \
      return errorCodeDecoder;                                                 \
    }                                                                          \
  }
dukl's avatar
dukl committed
79 80

#define CHECK_IEI_DECODER(iEI, bUFFER)                                         \
81 82 83 84
  if (iEI != bUFFER) {                                                         \
    errorCodeDecoder = TLV_UNEXPECTED_IEI;                                     \
    return TLV_UNEXPECTED_IEI;                                                 \
  }
dukl's avatar
dukl committed
85 86

#endif /* define (FILE_TLV_DECODER_SEEN) */