FreeCalypso > hg > freecalypso-sw
changeset 648:970d6199f2c5
gsm-fw/ccd/*.[ch]: initial import from the LoCosto source
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/Ccdedit.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,1664 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : Ccdedit.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Coder Decoder editfunctions for reading/writing the +| C-Structures of primitives and messages. ++----------------------------------------------------------------------------- +*/ + +#define CCDEDIT_C + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +/* + * standard definitions like UCHAR, ERROR etc. + */ +#include "typedefs.h" + + +/* + * Declaration of coder/decoder-tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#include "ccdedit.h" + +typedef union +{ + UBYTE buffer[4]; + UBYTE b[4]; + USHORT s[2]; + ULONG l; +} T_CONV; + +typedef enum +{ + isvar, + isstruct, + isunion, + issdu, + isductrl +} T_ELEMTYPE; + +/* + * strncpy() does not append a null chararcter to the copied string; + * This macro adds a terminating null following a call to strncpy() + * In Ccdedit.h the buffers are all len+1 bytes long. + */ +#define STRNCPY(dest,source,len) {\ + strncpy (dest, source, len);\ + dest [len] = 0;\ + } + + +static const T_CCD_CompTabEntry* mcomp; +static const T_CCD_CompTabEntry* pcomp; +static const T_CCD_VarTabEntry* pvar; +static const T_CCD_ElemTabEntry* pelem; +static const T_CCD_StrTabEntry* pstr; +static const T_CCD_VarTabEntry* mvar; +static const T_CCD_ElemTabEntry* melem; +static const T_CCD_StrTabEntry* mstr; +static const T_CCD_ValTabEntry* mval; +static const T_CCD_ValTabEntry* pval; +static int ccddata_num_of_entities; +static int ccddata_max_message_id; +static int ccddata_max_primitive_id; +static int ccddata_max_sap_num; + + +void CCDDATA_PREF(cde_init) () +{ + mcomp = ccddata_get_mcomp (0); + pcomp = ccddata_get_pcomp (0); + pvar = ccddata_get_pvar (0); + pelem = ccddata_get_pelem (0); + pstr = ccddata_get_pstr (0); + mvar = ccddata_get_mvar (0); + melem = ccddata_get_melem (0); + mstr = ccddata_get_mstr (0); + mval = ccddata_get_mval (0); + pval = ccddata_get_pval (0); + ccddata_num_of_entities = ccddata_get_num_of_entities (); + ccddata_max_message_id = ccddata_get_max_message_id (); + ccddata_max_primitive_id = ccddata_get_max_primitive_id (); + ccddata_max_sap_num = ccddata_get_max_sap_num (); +} + +/* ++------------------------------------------------------------------------------ +| Function : cde_val_iterate ++------------------------------------------------------------------------------ +| Description : This function searches the values in [pm]val.cdg for +| a given value and depending on the value of the parameter +| 'copy' adds the "Comment" of the SAP-/MSG-catalogues +| to the member symbolicValue of a given T_CCDE_ELEM_DESCR. +| +| Parameters : elem_value - the actual value searched for +| edescr - the element descriptor +| copy - s.a. +| +| Return : -1 if no values are defined or if the value is not found; +| else: the ordinal of the value in relation to first valid +| value of the var ++------------------------------------------------------------------------------ +*/ + +static void cde_val_iterate (int elem_value, + T_CCDE_ELEM_DESCR* edescr) +{ + + S32 StartVal, EndVal; + BOOL IsDefault; + char *ValStr; + SHORT NumDefs; + USHORT ValueDef; + USHORT valdefstart; + const T_CCD_ValTabEntry* val; + const T_CCD_StrTabEntry* str; + + if (edescr->ccdIndex == NO_REF) + return; + + if (edescr->esource EQ FromMsg) + { + NumDefs = mvar[edescr->ccdIndex].numValueDefs; + ValueDef = mvar[edescr->ccdIndex].valueDefs; + val = mval; + str = mstr; + } + else + { + NumDefs = pvar[edescr->ccdIndex].numValueDefs; + ValueDef = pvar[edescr->ccdIndex].valueDefs; + val = pval; + str = pstr; + } + + valdefstart = ValueDef; + + edescr->valcheck = NumDefs ? -1 : 1; + while (NumDefs-- > 0) + { + IsDefault = val[ValueDef].isDefault; + ValStr = str[val[ValueDef].valStringRef]; + StartVal = val[ValueDef].startValue; + EndVal = val[ValueDef].endValue; + + if (IsDefault) + { + /* default definition */ + + STRNCPY (edescr->symbolicValue, ValStr, SYMBOLIC_VAL_LENGTH); + /* + * If IsDefault is 2 it is an ASN1 default value; StartVal and EndVal + * are set to the value. If IsDefault is 1, it means only a default + * symbolic value, but StartVal and EndVal are not set. In this case + * valcheck get the value 0. + */ + if (IsDefault == 2) + { + if (elem_value == StartVal) + { + edescr->valcheck = 1; + return; + } + } + else + { + edescr->valcheck = 0; + } + } + else + { + if (elem_value == StartVal && elem_value == EndVal) + { + STRNCPY (edescr->symbolicValue, ValStr, SYMBOLIC_VAL_LENGTH); + edescr->valcheck = 1; + return; + } + + if (elem_value >= StartVal AND elem_value <= EndVal) + { + /* found in range, but continue to search an exact match */ + STRNCPY (edescr->symbolicValue, ValStr, SYMBOLIC_VAL_LENGTH); + edescr->valcheck = 1; + } + } + ValueDef++; + } +} + +static void eval_elemtype (T_CCDE_ELEM_DESCR* edescr, + const T_CCD_ElemTabEntry* elem, + T_ELEMTYPE* elemtype, + BOOL* linked) +{ + *linked = FALSE; + + switch (elem->elemType) + { + case 'W': + case 'M': + case 'I': + *linked = TRUE; + /* fallthrough */ + case 'V': + case 'R': + case 'F': + *elemtype = isvar; + break; + + case 'Z': + case 'K': + case 'G': + *linked = TRUE; + /* fallthrough */ + case 'C': + case 'P': + case 'D': + *elemtype = isstruct; + break; + + case 'c': + case 'p': + case 'd': + *elemtype = issdu; + break; + + case 'Y': + case 'L': + case 'H': + *linked = TRUE; + /* fallthrough */ + case 'U': + case 'Q': + case 'E': + *elemtype = isunion; + break; + case '!': + *elemtype = isductrl; + break; + } + if ((elem->elemType >= 'P' && elem->elemType <= 'R') || + (elem->elemType >= 'K' && elem->elemType <= 'M') || + elem->elemType == 'p') + edescr->ptrtype = usptr; + else if((elem->elemType >= 'D' && elem->elemType <= 'F') || + (elem->elemType >= 'G' && elem->elemType <= 'I') || + elem->elemType == 'd') + edescr->ptrtype = ctptr; + else + edescr->ptrtype = noptr; +} + + +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCDEDIT | +| STATE : code ROUTINE : cde_get_next_elem | ++--------------------------------------------------------------------+ + + PURPOSE : + +*/ + +static USHORT cde_get_next_elem (T_CCDE_HANDLE *handle, + UBYTE descent, + T_CCDE_ELEM_DESCR *edescr) +{ + T_CCDE_CONTEXT * ctx; + BOOL isMsg; + BOOL linked; + BOOL validElemFound = FALSE; + const T_CCD_VarTabEntry *var; + const T_CCD_CompTabEntry *comp; + const T_CCD_ElemTabEntry *elem; + const T_CCD_StrTabEntry *str; + T_ELEMTYPE elemtype; + + isMsg = handle->source == FromMsg; + + if (isMsg) + /* var, str, and comp may become reset later */ + { + comp = mcomp; + elem = melem; + str = mstr; + var = mvar; + } + else + { + comp = pcomp; + elem = pelem; + str = pstr; + var = pvar; + } + + if (descent > handle->level AND handle->canDescent) + handle->level++; + + handle->canDescent = FALSE; + + ctx = &handle->context[handle->level]; + + do + { + if (ctx->numElems EQ 0) + { + /* + * end of composition or maybe of the entire message/primitive. + */ + if (handle->level > 0) + { + /* + * end of substructured element. + * switch to the context of the previous level. + */ + handle->level--; + ctx = &handle->context[handle->level]; + } + else + { + edescr->offset = comp[ctx->structIdx].cSize + + handle->lenVarPart; + return isMsg ? CCDEDIT_END_OF_MSG : CCDEDIT_END_OF_PRIM; + } + } + /* + * skip the spare elements (do it only for messages) + */ + if (ctx->numElems) + { + /* + * remember: primitives does not contain spare definitions + */ + if (elem[ctx->elemIdx].elemType == 'S') + { + ctx->elemIdx++; + ctx->numElems--; + } + else + validElemFound = TRUE; + } + } while (!validElemFound); + + + eval_elemtype (edescr, &elem[ctx->elemIdx], &elemtype, &linked); + + if (elemtype == isductrl) + { + edescr->btype = T_ductrl; + ctx->elemIdx++; + ctx->numElems--; + return CCDEDIT_OK; + } + + if (linked) + { + /* element linked from pelem to mvar/mcomp */ + edescr->esource = FromMsg; + comp = mcomp; + var = mvar; + str = mstr; + } + else + edescr->esource = handle->source; + + if (ctx->state EQ TRAVERSE_ARRAY) + { + /* + * for every array element calculate the offset for the + * C-structure access. + * offset = leveloffset + (arrayIndex * csize) + 1 + */ + edescr->offset = elem[ctx->elemIdx].structOffs + ctx->levelOffset + + (ctx->arrayIndex + * ((elem[ctx->elemIdx].elemType NEQ 'C') + ? var[elem[ctx->elemIdx].elemRef].cSize + : comp[elem[ctx->elemIdx].elemRef].cSize + ) + ); +/* + + 1; + */ + } + else + { + edescr->offset = elem[ctx->elemIdx].structOffs + + ctx->levelOffset; + } + + edescr->level = handle->level; + edescr->maxRepeat = elem[ctx->elemIdx].maxRepeat; + edescr->index = NO_REF; + edescr->ccdIndex = NO_REF; + edescr->validRepeats = NO_REF; + edescr->isOptional = elem[ctx->elemIdx].optional; + edescr->arrayType = NoArray; + edescr->elemref = NO_REF; + edescr->u_member = FALSE; + edescr->u_ctrl = 0xffffffff; + edescr->bitstring = 0; + edescr->c_implicit = 1; + edescr->issigned = 0; + edescr->valcheck = 0; + + if ( edescr->maxRepeat > 0 + && elem[ctx->elemIdx].repType != 'b' + && elem[ctx->elemIdx].repType != 's' + && elem[ctx->elemIdx].elemType != 'E' + && ctx->state == TRAVERSE_STRUCTURE) + { + edescr->arrayType = ( elem[ctx->elemIdx].repType == 'v' + || elem[ctx->elemIdx].repType == 'i' + || elem[ctx->elemIdx].repType == 'J' + || elem[ctx->elemIdx].repType == 'j') + ? VarArray + : FixArray; + + if (elem[ctx->elemIdx].repType == 'C' + || elem[ctx->elemIdx].repType == 'J') + edescr->bitstring = 1; + + if (elem[ctx->elemIdx].repType == 'j' + || elem[ctx->elemIdx].repType == 'J') + edescr->c_implicit = 0; + + if (handle->level < MAX_LEVELS) + { + T_CCDE_CONTEXT * new_ctx = ctx+1; + + ctx->repeats = edescr->maxRepeat; + + handle->canDescent = TRUE; + + new_ctx->structIdx = ctx->structIdx; + + new_ctx->elemIdx = ctx->elemIdx; + new_ctx->elemType = 0; + new_ctx->arrayIndex = 0; + new_ctx->numElems = edescr->maxRepeat; + new_ctx->levelOffset = ctx->levelOffset; + new_ctx->arrayType = edescr->arrayType; + new_ctx->state = TRAVERSE_ARRAY; + /* + * if the composition is optional, increment the offset + * because of the valid flag (v_xxx). + */ + if (edescr->isOptional) + new_ctx->levelOffset++; + /* + * if the composition is a array with variable size, + * increment the offset because of the counter (c_xxx). + */ + if (edescr->arrayType EQ VarArray) + new_ctx->levelOffset += edescr->maxRepeat >> 8 ? 2 : 1; + } + } + + if (ctx->state EQ TRAVERSE_ARRAY) + { + /* + * if the size of the array is variable, mark the + * components of this array as optional. So we can later + * determine if the array component is valid + */ + if (ctx->arrayType EQ VarArray) + edescr->isOptional = TRUE; + /* + * increment the array index + */ + edescr->index = ctx->arrayIndex++; + } + + if (elemtype == isvar) + { + /* + * basic element (var) + */ + switch (var[elem[ctx->elemIdx].elemRef].cType) + { + case 'C': + edescr->issigned = 1; + /* fallthrough */ + case 'B': + edescr->btype = T_byte; + break; + case 'T': + edescr->issigned = 1; + /* fallthrough */ + case 'S': + edescr->btype = T_short; + break; + case 'M': + edescr->issigned = 1; + /* fallthrough */ + case 'L': + edescr->btype = T_long; + break; + case 'X': + edescr->btype = T_buffer; + break; + } + edescr->bytelen = var[elem[ctx->elemIdx].elemRef].cSize; + +#ifdef CCD_SYMBOLS + strcpy (edescr->aname, var[elem[ctx->elemIdx].elemRef].name); + strcpy (edescr->sname, ccddata_get_alias (ctx->elemIdx, (int) isMsg)); + if (edescr->sname[0] == '\0') + strcpy (edescr->sname, var[elem[ctx->elemIdx].elemRef].name); + STRNCPY (edescr->lname, str[var[elem[ctx->elemIdx].elemRef].longNameRef], + LONG_NAME_LENGTH); +#else + strcpy (edescr->sname, "No name info avail."); + strcpy (edescr->aname, "No name info avail."); + strcpy (edescr->lname, "No name info avail."); +#endif + } + else if (elemtype == isunion) + { + /* union */ + edescr->btype = T_union; + edescr->bytelen = comp[elem[ctx->elemIdx].elemRef].cSize; + edescr->elemref = elem[ctx->elemIdx].elemRef; + +#ifdef CCD_SYMBOLS + strcpy (edescr->aname, comp[elem[ctx->elemIdx].elemRef].name); + strcpy (edescr->sname, ccddata_get_alias (ctx->elemIdx, (int) isMsg)); + if (edescr->sname[0] == '\0') + strcpy (edescr->sname, comp[elem[ctx->elemIdx].elemRef].name); + STRNCPY (edescr->lname, str[comp[elem[ctx->elemIdx].elemRef].longNameRef], + LONG_NAME_LENGTH); +#else + strcpy (edescr->sname, "No name info avail."); + strcpy (edescr->aname, "No name info avail."); + strcpy (edescr->lname, "No name info avail."); +#endif + } + else + { + /* + * substructured info element + */ + if (elemtype == issdu) + edescr->btype = T_issdu; + else + edescr->btype = T_struct; + edescr->bytelen = comp[elem[ctx->elemIdx].elemRef].cSize; + edescr->elemref = elem[ctx->elemIdx].elemRef; + +#ifdef CCD_SYMBOLS + strcpy (edescr->aname, comp[elem[ctx->elemIdx].elemRef].name); + strcpy (edescr->sname, ccddata_get_alias (ctx->elemIdx, (int) isMsg)); + if (edescr->sname[0] == '\0') + strcpy (edescr->sname, comp[elem[ctx->elemIdx].elemRef].name); + STRNCPY (edescr->lname, str[comp[elem[ctx->elemIdx].elemRef].longNameRef], + LONG_NAME_LENGTH); +#else + strcpy (edescr->sname, "No name info avail."); + strcpy (edescr->aname, "No name info avail."); + strcpy (edescr->lname, "No name info avail."); +#endif + if (edescr->arrayType EQ NoArray + AND handle->level < MAX_LEVELS) + { + T_CCDE_CONTEXT * new_ctx = ctx+1; + + handle->canDescent = TRUE; + + new_ctx->structIdx = elem[ctx->elemIdx].elemRef; + + new_ctx->elemIdx = comp[new_ctx->structIdx].componentRef; + new_ctx->elemType = 0; + new_ctx->arrayIndex = 0; + new_ctx->numElems = comp[new_ctx->structIdx].numOfComponents; + new_ctx->levelOffset = edescr->offset; + /* + * if the composition is optional, increment the offset + * because of the valid flag (v_xxx). + */ + if (edescr->isOptional) + new_ctx->levelOffset++; + /* + * if the composition is a array with variable size, + * increment the offset because of the counter (c_xxx). + */ + if (edescr->arrayType EQ VarArray) + new_ctx->levelOffset++; + + new_ctx->state = TRAVERSE_STRUCTURE; + } + } + + + if (edescr->arrayType EQ NoArray && elem[ctx->elemIdx].elemType == 'V' + AND var[elem[ctx->elemIdx].elemRef].numValueDefs > 0) + { + /* + * value definitions available + * store the index of this information element in the + * element descriptor for later value requests. + */ + edescr->ccdIndex = elem[ctx->elemIdx].elemRef; + } + + ctx->numElems--; + + if (ctx->state EQ TRAVERSE_STRUCTURE) + ctx->elemIdx++; + + return CCDEDIT_OK; +} + +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCDEDIT | +| STATE : code ROUTINE : cde_prim_first | ++--------------------------------------------------------------------+ + + PURPOSE : + +*/ + +USHORT CCDDATA_PREF(cde_prim_first) (T_CCDE_HANDLE * phandle, + ULONG primcode, + char * name) +{ + USHORT SAP, Opcode, Direction, ThePrimitive; + + if (primcode & 0x80000000) + { + SAP = (USHORT) (primcode & 0x3fff); + Opcode = (USHORT) ((primcode >> 16) & 0xff); + } + else + { + SAP = (USHORT) (((primcode & 0x3f00)>>8) & 0xff); + Opcode = (USHORT) (primcode & 0xff); + } + Direction = (USHORT) (((primcode & 0x4000)>>14) & 0x01); + + if (SAP > ccddata_max_sap_num OR Opcode > ccddata_max_primitive_id) + return CCDEDIT_PRIM_NOT_FOUND; + + if ((ThePrimitive = ccddata_get_pmtx(SAP,Opcode,Direction)) EQ NO_REF) + return CCDEDIT_PRIM_NOT_FOUND; + + phandle->context[0].structIdx = ThePrimitive; + +#ifdef CCD_SYMBOLS + strcpy (name, pcomp[phandle->context[0].structIdx].name); +#else + strcpy (name, "No name info avail."); +#endif + + phandle->level = 0; + phandle->context[0].elemIdx = pcomp[phandle->context[0].structIdx].componentRef; + phandle->context[0].elemType = 0; + phandle->context[0].numElems = pcomp[phandle->context[0].structIdx].numOfComponents; + phandle->context[0].levelOffset = 0; + phandle->context[0].arrayIndex = 0; + phandle->context[0].state = TRAVERSE_STRUCTURE; + phandle->canDescent = FALSE; + phandle->source = FromPrim; + phandle->maxCSize = pcomp[phandle->context[0].structIdx].cSize; + phandle->lenVarPart = 0; + + return CCDEDIT_OK; +} + + +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCDEDIT | +| STATE : code ROUTINE : cde_prim_next | ++--------------------------------------------------------------------+ + + PURPOSE : + +*/ + + +USHORT CCDDATA_PREF(cde_prim_next) (T_CCDE_HANDLE *phandle, + UBYTE descent, + T_CCDE_ELEM_DESCR *pdescr) +{ + return cde_get_next_elem (phandle, + descent, + pdescr); +} + +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCDEDIT | +| STATE : code ROUTINE : cde_msg_first | ++--------------------------------------------------------------------+ + + PURPOSE : + +*/ + +USHORT CCDDATA_PREF(cde_msg_first) (T_CCDE_HANDLE * mhandle, + UBYTE type, + UBYTE direction, + UBYTE entity, + char * name) + +{ + USHORT TheMessage; + + if (entity > ccddata_num_of_entities OR type > ccddata_max_message_id) + return CCDEDIT_MESSAGE_NOT_FOUND; + + if ((TheMessage = ccddata_get_mmtx((USHORT) entity, + (USHORT) type, + (USHORT) direction)) EQ NO_REF) + return CCDEDIT_MESSAGE_NOT_FOUND; + + mhandle->context[0].structIdx = TheMessage; + +#ifdef CCD_SYMBOLS + strcpy (name, mcomp[mhandle->context[0].structIdx].name); +#else + strcpy (name, "No name info avail."); +#endif + + mhandle->level = 0; + mhandle->context[0].elemIdx = mcomp[mhandle->context[0].structIdx].componentRef; + mhandle->context[0].elemType = 0; + mhandle->context[0].numElems = mcomp[mhandle->context[0].structIdx].numOfComponents; + mhandle->context[0].levelOffset = 0; + mhandle->context[0].arrayIndex = 0; + mhandle->context[0].state = TRAVERSE_STRUCTURE; + mhandle->canDescent = FALSE; + mhandle->source = FromMsg; + mhandle->maxCSize = mcomp[mhandle->context[0].structIdx].cSize; + mhandle->lenVarPart = 0; + + return CCDEDIT_OK; +} + + +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCDEDIT | +| STATE : code ROUTINE : cde_msg_next | ++--------------------------------------------------------------------+ + + PURPOSE : + +*/ + +USHORT CCDDATA_PREF(cde_msg_next) (T_CCDE_HANDLE *mhandle, + UBYTE descent, + T_CCDE_ELEM_DESCR *iedescr) +{ + return cde_get_next_elem (mhandle, + descent, + iedescr); +} + + +/* ++------------------------------------------------------------------------------ +| Function : cde_get_comp ++------------------------------------------------------------------------------ +| Description : This function works with similar results like cde_comp_first, +| but not the whole comp table is searched for the name of the +| component. Instead the previous set elemref in the +| parameter edescr is taken to directly jump to the component. +| The component found is compared with the given name in +| edescr. If equal chandle is defined. Otherwise there is an +| error. +| +| Parameters : chandle - the handle for the component (returned) +| edescr - the element descriptor +| +| Return : CCDEDIT_OK on success, CCDEDIT_COMP_NOT_FOUND otherwise ++------------------------------------------------------------------------------ +*/ + +USHORT CCDDATA_PREF(cde_get_comp) (T_CCDE_HANDLE* chandle, + T_CCDE_ELEM_DESCR* edescr) +{ + const T_CCD_CompTabEntry* comp; + USHORT index = edescr->elemref; + + if (index == NO_REF) + return CCDEDIT_COMP_NOT_FOUND; + + comp = edescr->esource == FromMsg ? &mcomp[index] : &pcomp[index]; + +#ifdef CCD_SYMBOLS + if (strcmp (comp->name, edescr->aname)) + return CCDEDIT_COMP_NOT_FOUND; +#endif /* CCD_SYMBOLS */ + + chandle->context[0].structIdx = index; + chandle->level = 0; + chandle->context[0].elemIdx = comp->componentRef; + chandle->context[0].elemType = 0; + chandle->context[0].numElems = comp->numOfComponents; + chandle->context[0].levelOffset = 0; + chandle->context[0].arrayIndex = 0; + chandle->context[0].state = TRAVERSE_STRUCTURE; + chandle->canDescent = FALSE; + chandle->source = edescr->esource; + chandle->maxCSize = comp->cSize; + chandle->lenVarPart = 0; + + return CCDEDIT_OK; +} + +/* ++------------------------------------------------------------------------------ +| Function : cde_comp_alias ++------------------------------------------------------------------------------ +| Description : This function works with similar results like cde_comp_first, +| but not thewhole comp table is searched for the name of the +| component. Instead the alias name (as_name) from ?elem.cdg +| is taken for name comparison. +| +| Parameters : chandle - the handle for the component (returned) +| source - if message or primitve +| name - the name of the searched component +| +| Return : CCDEDIT_OK on success, CCDEDIT_COMP_NOT_FOUND otherwise ++------------------------------------------------------------------------------ +*/ +USHORT cde_comp_alias (T_CCDE_HANDLE * chandle, + T_ELM_SRC source, + char * name) + +{ + const T_CCD_CompTabEntry* comp; + const T_CCD_ElemTabEntry* elem; + int found = 0; + USHORT index, cindex; + + elem = source == FromMsg ? melem : pelem; + + index = 0; + while (!found AND (ccddata_get_alias (index, source == FromMsg) != NULL)) + { + /* name found */ + if (elem[index].elemType == 'C' && + !strcmp (ccddata_get_alias (index, source == FromMsg), name)) + found = 1; + else + index++; + } + if (!found) + return CCDEDIT_COMP_NOT_FOUND; + + cindex = elem[index].elemRef; + comp = source == FromMsg ? &mcomp[cindex] : &pcomp[cindex]; + chandle->context[0].structIdx = cindex; + chandle->level = 0; + chandle->context[0].elemIdx = comp->componentRef; + chandle->context[0].elemType = 0; + chandle->context[0].numElems = comp->numOfComponents; + chandle->context[0].levelOffset = 0; + chandle->context[0].arrayIndex = 0; + chandle->context[0].state = TRAVERSE_STRUCTURE; + chandle->canDescent = FALSE; + chandle->source = source; + chandle->maxCSize = comp->cSize; + chandle->lenVarPart = 0; + + return CCDEDIT_OK; +} + +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCDEDIT | +| STATE : code ROUTINE : cde_comp_first | ++--------------------------------------------------------------------+ + + PURPOSE : + +*/ + +USHORT CCDDATA_PREF(cde_comp_first) (T_CCDE_HANDLE * chandle, + T_ELM_SRC source, + char * compname) + +{ + USHORT index; + BOOL found = FALSE; + + if (source EQ FromMsg) + { + /* + * search the mcomp-table for the given name + */ + index = 0; + while (!found AND mcomp[index].name NEQ NULL) + { + /* + * composition name found + */ + if (strcmp (mcomp[index].name, compname) EQ 0) + found = TRUE; + else + index++; + } + if (found) + chandle->context[0].structIdx = index; + else + return CCDEDIT_COMP_NOT_FOUND; + + chandle->level = 0; + chandle->context[0].elemIdx = mcomp[index].componentRef; + chandle->context[0].elemType = 0; + chandle->context[0].numElems = mcomp[index].numOfComponents; + chandle->context[0].levelOffset = 0; + chandle->context[0].arrayIndex = 0; + chandle->context[0].state = TRAVERSE_STRUCTURE; + chandle->canDescent = FALSE; + chandle->source = FromMsg; + chandle->maxCSize = mcomp[index].cSize; + chandle->lenVarPart = 0; + } + else + { + /* + * search the pcomp-table for the given name + */ + index = 0; + while (!found AND pcomp[index].name NEQ NULL) + { + /* + * composition name found + */ + if (strcmp (pcomp[index].name, compname) EQ 0) + found = TRUE; + else + index++; + } + if (found) + chandle->context[0].structIdx = index; + else + return CCDEDIT_COMP_NOT_FOUND; + + chandle->level = 0; + chandle->context[0].elemIdx = pcomp[index].componentRef; + chandle->context[0].elemType = 0; + chandle->context[0].numElems = pcomp[index].numOfComponents; + chandle->context[0].levelOffset = 0; + chandle->context[0].arrayIndex = 0; + chandle->context[0].state = TRAVERSE_STRUCTURE; + chandle->canDescent = FALSE; + chandle->source = FromPrim; + chandle->maxCSize = pcomp[index].cSize; + chandle->lenVarPart = 0; + } + + return CCDEDIT_OK; +} + +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCDEDIT | +| STATE : code ROUTINE : cde_comp_next | ++--------------------------------------------------------------------+ + + PURPOSE : + +*/ + +USHORT CCDDATA_PREF(cde_comp_next) (T_CCDE_HANDLE *chandle, + UBYTE descent, + T_CCDE_ELEM_DESCR *descr) +{ + return cde_get_next_elem (chandle, + descent, + descr); +} + +/* ++------------------------------------------------------------------------------ +| Function : cde_get_symval ++------------------------------------------------------------------------------ +| Description : This function adds the "Comment" of the SAP-/MSG-catalogues +| to the member symbolicValue of a given T_CCDE_ELEM_DESCR. +| +| Parameters : elem_value - the actual value for that the comment +| is searched for +| edescr - the element descriptor +| +| Return : The string itself is returned which is a pointer to +| '\0' if no comment was defined for that value. ++------------------------------------------------------------------------------ +*/ + +char* CCDDATA_PREF(cde_get_symval) (int elem_value, T_CCDE_ELEM_DESCR* edescr) +{ + edescr->symbolicValue[0] = '\0'; + + cde_val_iterate (elem_value, edescr); + + return edescr->symbolicValue; +} + +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCDEDIT | +| STATE : code ROUTINE : cde_read_elem | ++--------------------------------------------------------------------+ + + PURPOSE : Reads the value of the element, referenced by the element + descriptor edescr, out of the C-Structure cstruct. The + value is stored in the memory area, addressed by the + parameter value. + +*/ + +USHORT CCDDATA_PREF(cde_read_elem) (T_CCDE_HANDLE * handle, + void * cstruct, + T_CCDE_ELEM_DESCR * edescr, + UBYTE * value) +{ + T_CONV * cvp; + U32 voffset; + ULONG elem_value; + UBYTE * cs = (UBYTE *) cstruct; + + /* + * if this element is optional and it is no array component + * read the valid flag out of the C-structure. + */ + if (edescr->isOptional && edescr->index == NO_REF && edescr->ptrtype != usptr) + { + voffset = edescr->offset++; + edescr->isValid = (cs[voffset] EQ TRUE); + } + else + { + if (edescr->index NEQ NO_REF) + { + T_CCDE_CONTEXT *last_ctx; + + last_ctx = &handle->context[handle->level-1]; + edescr->isValid = (edescr->index < last_ctx->repeats); + } + else + edescr->isValid = TRUE; + } + + if (!edescr->isValid) + return CCDEDIT_OK; + + if (edescr->u_member) + { + edescr->u_ctrl = * (U32 *) &cs[edescr->offset]; + edescr->offset += sizeof (U32); + } + + if (edescr->arrayType NEQ NoArray) + { + T_CCDE_CONTEXT *ctx; + + ctx = &handle->context[handle->level]; + + /* + * array of message elements (info elements) + */ + + if (edescr->arrayType EQ VarArray) + { + USHORT sz_of_len; + sz_of_len = edescr->maxRepeat >> 8 ? 2 : 1; /* 1 or 2 bytes for len */ + if (sz_of_len == 1) + { + ctx->repeats = (USHORT) cs[edescr->offset]; + } + else + { + ctx->repeats = * (USHORT *) &cs[edescr->offset]; + } + edescr->offset += sz_of_len; + + if (ctx->repeats > edescr->maxRepeat) + ctx->repeats = edescr->maxRepeat; + } + else + ctx->repeats = edescr->maxRepeat; + + edescr->bytelen = edescr->bytelen * ctx->repeats; + edescr->validRepeats = ctx->repeats; + *value++ = (UBYTE) edescr->validRepeats; + } + + if (edescr->ptrtype != noptr) + { + cs = * (UBYTE **) &cs[edescr->offset]; + if (!cs) + { + edescr->isValid = FALSE; + return CCDEDIT_OK; + } + } + else + cs += edescr->offset; + + /* + * read the current value from the C-structure + */ + if ((edescr->btype == T_issdu) || (edescr->btype == T_buffer)) + { + USHORT l_buf, o_buf, len; + + /* + * For the structure SDU perform a special handling. + * The SDU contains l_buf and o_buf and the element + * buf. This element is only defined as buf[1] because + * the real length results of the encoded message and + * must be calculated form l_buf and o_buf + */ + + /* + * read l_buf and o_buf (length and offset) out of the struct + */ + memcpy ((UBYTE *)&l_buf, cs, sizeof (USHORT)); + + memcpy ((UBYTE *)&o_buf, cs+sizeof (USHORT), sizeof (USHORT)); + + len = ((l_buf+o_buf+7)/8); + handle->lenVarPart += len; + handle->canDescent = FALSE; + if ((edescr->btype == T_issdu) && + ((len > (U32)(ccddata_get_max_bitstream_len()/8)) || + (len > 0x1FFF))) /* max bytes: 0xFFFF/8 = 0x1FFF */ + { + return CCDEDIT_MESSAGE_ERROR; + } + edescr->bytelen = (2 * sizeof (USHORT)) + len; + } + + memcpy (value, cs, edescr->bytelen); + + cvp = (T_CONV *) cs; + + switch (edescr->btype) + { + case T_byte: + elem_value = (ULONG) cvp->b[0]; + break; + case T_short: + elem_value = (ULONG) cvp->s[0]; + break; + case T_long: + elem_value = (ULONG) cvp->l; + break; + default: + return CCDEDIT_OK; + } + + (void) CCDDATA_PREF(cde_get_symval) (elem_value, edescr); + + return CCDEDIT_OK; +} + +/* ++------------------------------------------------------------------------------ +| Function : cde_write_prepare ++------------------------------------------------------------------------------ +| Description : This function prepares the writing of elements, by setting +| valid flag, union controller and length of vaiable arrays +| if necessary. Current version: only valid flag and union +| controller. +| +| Parameters : same as cde_write_elem except value +| +| Return : - ++------------------------------------------------------------------------------ +*/ + +void CCDDATA_PREF(cde_write_prepare) (T_CCDE_HANDLE * handle, + void * cstruct, + T_CCDE_ELEM_DESCR * edescr) +{ + UBYTE * cs = (UBYTE *) cstruct; + + /* + * if this element is optional and it is no array component + * set the corresponding valid flag in the C-structure. + */ + if (edescr->isOptional && edescr->ptrtype != usptr) + { + cs[edescr->offset++] = TRUE; + } + + if (edescr->u_member) + { + * (U32 *) &cs[edescr->offset] = (UBYTE) edescr->u_ctrl; + edescr->offset += sizeof (U32); + } +} + + +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCDEDIT | +| STATE : code ROUTINE : cde_write_elem | ++--------------------------------------------------------------------+ + + PURPOSE : Write the value wich is stored in the memory area, + addressed by the parameter value, into the C-Structure + element, referenced by the element descriptor edescr. + +*/ + +USHORT CCDDATA_PREF(cde_write_elem) (T_CCDE_HANDLE * handle, + void * cstruct, + T_CCDE_ELEM_DESCR * edescr, + UBYTE * value) +{ + char *cs = (UBYTE *) cstruct; + char *vb; + U32 len; + + CCDDATA_PREF(cde_write_prepare) (handle, cs, edescr); + + if ((edescr->arrayType != NoArray) && (edescr->btype != T_struct)) + { + T_CCDE_CONTEXT *ctx; + T_CCDE_CONTEXT _ctx; + + ctx = handle ? &handle->context[handle->level] : &_ctx; + + /* + * Array of message elements (info elements) or + * parameter. + * In case of variable sized arrays, store the + * amount of elements into the corresponding c_xxx variable + */ + if (edescr->arrayType EQ VarArray) + { + /* + * array with a variable number of elements + * set the c_xxx variable in the C-Structure + */ + USHORT sz_of_len; + sz_of_len = edescr->maxRepeat >> 8 ? 2 : 1; /* 1 or 2 bytes for len */ + if (sz_of_len == 1) + { + cs[edescr->offset] = (UBYTE) edescr->validRepeats; + } + else + { + * (USHORT *) &cs[edescr->offset] = edescr->validRepeats; + } + edescr->offset += sz_of_len; + } + ctx->repeats = edescr->validRepeats; + if (edescr->bitstring) + { + ctx->repeats = (ctx->repeats+7)/8; + } + + edescr->bytelen = edescr->bytelen * ctx->repeats; + } + + if (edescr->ptrtype != noptr) + { + char* pointer = value; + vb = (char*) &pointer; + len = sizeof (char*); + } + else + { + vb = (char*) value; + len = edescr->bytelen; + + if ((edescr->btype == T_issdu) || (edescr->btype == T_buffer)) + { + USHORT l_buf, o_buf; + + /* + * For the structure SDU perform a special handling. + * The SDU contains l_buf and o_buf and the element + * buf. This element is only defined as buf[1] because + * the real length results of the encoded message and + * must be calculated form l_buf and o_buf + */ + + /* + * read l_buf and o_buf (length and offset) out of the value + */ + memcpy ((UBYTE *)&l_buf, vb, sizeof (USHORT)); + + memcpy ((UBYTE *)&o_buf, vb+sizeof (USHORT), sizeof (USHORT)); + + len = (2 * sizeof (USHORT)) + ((l_buf+o_buf+7)/8); + if (handle) + { + if (edescr->ptrtype == noptr) + handle->lenVarPart += (USHORT) len; + else + handle->lenVarPart += sizeof (void*); + } + edescr->bytelen = len; + } + } + + /* + * write the value into the C-structure + */ + memcpy (cs+edescr->offset, vb, len); + + return CCDEDIT_OK; +} + +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCDEDIT | +| STATE : code ROUTINE : cde_get_type | ++--------------------------------------------------------------------+ + + PURPOSE : Requests the type (primitive or message) for a given + name. The type is stored in the return parameter type. + +*/ + +USHORT CCDDATA_PREF(cde_get_type) (char *name, + T_ELM_SRC *type) +{ +#ifdef CCD_SYMBOLS + USHORT SAP, Opcode, Direction, Entity; + + /* + * check the primitive table first. Look in all SAPs ands for + * all direction alls opcodes to find the name as a primitve + * name. + */ + + for (SAP = 0; SAP <= ccddata_max_sap_num; SAP++) + for (Direction = 0; Direction <= 1; Direction++) + for (Opcode = 0; Opcode <= ccddata_max_primitive_id; Opcode++) + if (ccddata_get_pmtx(SAP, Opcode, Direction) NEQ NO_REF) + { + if (!strcmp (name, + pcomp[ccddata_get_pmtx(SAP, Opcode, Direction)].name)) + { + *type = FromPrim; + return CCDEDIT_OK; + } + } + + /* + * check the message table second. Look in all entities ands for + * all direction alls opcodes to find the name as a message + * name. + */ + + for (Entity = 0; Entity < ccddata_num_of_entities; Entity++) + for (Direction = 0; Direction <= 1; Direction++) + for (Opcode = 0; Opcode <= ccddata_max_message_id; Opcode++) + if (ccddata_get_mmtx(Entity, Opcode, Direction) NEQ NO_REF) + { + if (!strcmp (name, + mcomp[ccddata_get_mmtx(Entity, Opcode, Direction)].name)) + { + *type = FromPrim; + return CCDEDIT_OK; + } + } + +#endif + + return CCDEDIT_PRIM_NOT_FOUND; +} + +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCDEDIT | +| STATE : code ROUTINE : cde_get_primcode | ++--------------------------------------------------------------------+ + + PURPOSE : Requests the opcode of the primitive for a given + name. The opcode is stored in the return parameter primcode. + +*/ + +USHORT CCDDATA_PREF(cde_get_primcode) (char *name, + ULONG *primcode) +{ +#ifdef CCD_SYMBOLS + USHORT SAP, Opcode, Direction; + + /* + * check the primitive table. Look in all SAPs ands for + * all direction alls opcodes to find the name as a primitve + * name. + */ + + for (SAP = 0; SAP <= ccddata_max_sap_num; SAP++) + for (Direction = 0; Direction <= 1; Direction++) + for (Opcode = 0; Opcode <= ccddata_max_primitive_id; Opcode++) + if (ccddata_get_pmtx(SAP, Opcode, Direction) NEQ NO_REF) + { + if (!strcmp (name, pcomp[ccddata_get_pmtx(SAP, Opcode, Direction)].name)) + { + *primcode = ((Direction & 0x01) << 14); + *primcode |= (SAP & 0x3fff); + *primcode |= ((Opcode & 0xff) << 16); + *primcode |= 0x80000000; + + return CCDEDIT_OK; + } + } +#endif + + return CCDEDIT_PRIM_NOT_FOUND; +} + + +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCDEDIT | +| STATE : code ROUTINE : cde_get_msgcode | ++--------------------------------------------------------------------+ + + PURPOSE : Requests the opcode, the direction and the entity-number + of the message for a given name. + The opcode is stored in the return parameters . + +*/ + +USHORT CCDDATA_PREF(cde_get_msgcode) (char *name, + UBYTE *type, + UBYTE *direction, + UBYTE *entity) +{ +#ifdef CCD_SYMBOLS + USHORT Opcode, Direction, Entity; + + /* + * check the message table. Look in all entities ands for + * all direction alls opcodes to find the name as a message + * name. + */ + + for (Entity = 0; Entity < ccddata_num_of_entities; Entity++) + for (Direction = 0; Direction <= 1; Direction++) + for (Opcode = 0; Opcode <= ccddata_max_message_id; Opcode++) + if (ccddata_get_mmtx(Entity, Opcode, Direction) NEQ NO_REF) + { + if (!strcmp (name, + mcomp[ccddata_get_mmtx(Entity, Opcode, Direction)].name)) + { + *type = (UBYTE) Opcode; + *direction = (UBYTE) Direction; + *entity = (UBYTE) Entity; + return CCDEDIT_OK; + } + } + +#endif + + return CCDEDIT_MESSAGE_NOT_FOUND; +} + +/* ++------------------------------------------------------------------------------ +| Function : cde_get_is_downlink ++------------------------------------------------------------------------------ +| Description : This function finds out if an AIM is a downlink or uplink. +| +| Parameters : comp_index. +| +| Return : False if uplink otherwise true (downlink or both). ++------------------------------------------------------------------------------ +*/ +int CCDDATA_PREF(cde_get_is_downlink) (ULONG comp_index) +{ + UBYTE ent; + UBYTE msg_id; + + for(ent = 0; ent < ccddata_num_of_entities ; ent++) + { + for(msg_id = 0; msg_id <= ccddata_max_message_id ; msg_id++) + { + if(ccddata_get_mmtx (ent, msg_id, 1) == (USHORT)comp_index) + return 1; + } + } + return 0; +} + +/* + * The following functions are copied from ..\TAP\tdc_interface.c and + * renamed to get the cde_ prefix instead of tdc_. + * It should be checked if instead of these functions the usual approach + * to ccdedit by the functions pairs cde_comp_first/cde_comp_next + * (respectively their prim/msg pendants) can be used (maybe in combination + * with cde_get_comp). If the check confirms to use the usual approach, + * those 3 functions here should be deleted again + */ +/* ++------------------------------------------------------------------------------ +| Function : cde_get_comp_index ++------------------------------------------------------------------------------ +| Description : This function searches the comp index in either pcomp or mcomp +| +| Parameters : name and table type. +| +| Return : The table entry, if non found it returns 0xffffffff; ++------------------------------------------------------------------------------ +*/ + +ULONG CCDDATA_PREF(cde_get_comp_index) (CHAR* comp_name, T_ELM_SRC table) +{ + ULONG comp_index; + BOOL found = FALSE; + + if (table == FromMsg) + { + /* + * search the mcomp-table for the given name + */ + comp_index = 0; + while (!found AND mcomp[comp_index].name NEQ NULL) + { + /* + * composition name found + */ + if (strcmp (mcomp[comp_index].name, comp_name) EQ 0) + found = TRUE; + else + comp_index++; + } + if(found) + return comp_index; + else + return NO_ENTRY_FOUND; + } + else + { + /* + * search the pcomp-table for the given name + */ + comp_index = 0; + while (!found AND pcomp[comp_index].name NEQ NULL) + { + /* + * composition name found + */ + if (strcmp (pcomp[comp_index].name, comp_name) EQ 0) + found = TRUE; + else + comp_index++; + } + if(found) + return comp_index; + else + return NO_ENTRY_FOUND; + } +} + +/* ++------------------------------------------------------------------------------ +| Function : cde_get_element_name ++------------------------------------------------------------------------------ +| Description : This function gets the element name for a given index + offset. +| +| Parameters : comp_index, offset and table type. +| +| Return : The element name. ++------------------------------------------------------------------------------ +*/ + +CHAR* CCDDATA_PREF(cde_get_element_name) (ULONG comp_index, USHORT elem_off , T_ELM_SRC table) +{ + if (table == FromMsg) + { + if (mcomp[comp_index].componentRef == -1 || elem_off >= mcomp[comp_index].numOfComponents) + return NULL; + return ccddata_get_alias ((USHORT) (mcomp[comp_index].componentRef + elem_off), table == FromMsg); + } + else + if (pcomp[comp_index].componentRef == -1 || elem_off >= pcomp[comp_index].numOfComponents) + return NULL; + return ccddata_get_alias ((USHORT) (pcomp[comp_index].componentRef + elem_off), table == FromMsg); +} + +/* ++------------------------------------------------------------------------------ +| Function : cde_get_array_kind ++------------------------------------------------------------------------------ +| Description : This function gets the array kind - e.g. the cSize of the +| arrays (byte, short og long). +| +| Parameters : Name of the base type (var_name) and table type. +| +| Return : The cSize of the var_name. If not found it returns 0xffffffff ++------------------------------------------------------------------------------ +*/ + +ULONG CCDDATA_PREF(cde_get_array_kind) (CHAR* var_name, T_ELM_SRC table) +{ + ULONG var_index; + BOOL found = FALSE; + + if (table == FromMsg) + { + /* + * search the mvar-table for the given name + */ + var_index = 0; + while (!found AND mvar[var_index].name NEQ NULL) + { + /* + * name found + */ + if (strcmp (mvar[var_index].name, var_name) EQ 0) + found = TRUE; + else + var_index++; + } + if(found) + return (ULONG) mvar[var_index].cSize; + else + return NO_ENTRY_FOUND; + } + else + { + /* + * search the pvar-table for the given name + */ + var_index = 0; + while (!found AND pvar[var_index].name NEQ NULL) + { + /* + * name found + */ + if (strcmp (pvar[var_index].name, var_name) EQ 0) + found = TRUE; + else + var_index++; + } + if(found) + return (ULONG) pvar[var_index].cSize; + else + return NO_ENTRY_FOUND; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/asn1_bitstr.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,170 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : asn1_bitstr.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for ASN1_BITSTRING +| elements ++----------------------------------------------------------------------------- +*/ + +/* + * Standard definitions like UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_bitstring_decode | ++--------------------------------------------------------------------+ + + PURPOSE : UNALIGNED PER decoding of the bit string type (UMTS) + The coded bits are preceded by a length indicator, if + they are not of fixed length. The length indicator is + decoded as an ASN1_INTEGER type. +*/ + +SHORT cdc_bitstring_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat; + U8 *old_pstruct = NULL; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_asn1_bitstring_decode()"); + #else + TRACE_CCD (globs, "cdc_asn1_bitstring_decode() '%s'", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + /* + * Set pstrcutOffs and maxRep. + * Check the valid flag in case of optional elements. + */ + if (PER_CommonBegin (e_ref, &repeat, globs) NEQ ccdOK) + return 1; + +#ifdef DYNAMIC_ARRAYS + /* + * Check for pointer types, and allocate memory if necessary. + * May overwrite globs->pstruct (and initialize globs->pstructOffs to 0). + */ + if ( is_pointer_type(e_ref) ) { + old_pstruct = globs->pstruct; + if ( PER_allocmem_and_update(e_ref, (USHORT) ((repeat >> 3) +1), globs) NEQ ccdOK) + /* No memory - Return. Error already set in function call above. */ + return 1; + } +#endif + + bf_readBitStr_PER ((USHORT) repeat, globs); + +#ifdef DYNAMIC_ARRAYS + if (old_pstruct NEQ NULL) + globs->pstruct = old_pstruct; +#endif + + return 1; +} + +#endif /* !RUN_INT_RAM */ +#ifndef RUN_INT_RAM + +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_bitstring_encode | ++--------------------------------------------------------------------+ + + PURPOSE : UNALIGNED PER encoding of the bit string type (UMTS) + The coded bits are preceded by a length indicator, if + they are not of fixed length. The length indicator is + decoded as an ASN1_INTEGER type. +*/ + +SHORT cdc_bitstring_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat; + U8 *old_pstruct = NULL; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_asn1_bitstring_encode()"); + #else + TRACE_CCD (globs, "cdc_asn1_bitstring_encode() '%s'", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + /* + * Set pstructOffs and maxRep. + * Check the valid flag in case of optional elements. + */ + if (PER_CommonBegin (e_ref, &repeat, globs) NEQ ccdOK) + return 1; + +#ifdef DYNAMIC_ARRAYS + if ( is_pointer_type(e_ref) ) { + old_pstruct = globs->pstruct; + globs->pstruct = *(U8 **)(globs->pstruct + globs->pstructOffs); + + if (ccd_check_pointer(globs->pstruct) == ccdOK) + { + globs->pstructOffs = 0; + } + else + { + ccd_recordFault (globs, ERR_INVALID_PTR, BREAK, (USHORT) e_ref, + &globs->pstruct[globs->pstructOffs]); + return 1; + } + } +#endif + + bf_writeBitStr_PER ((USHORT) repeat, globs); + +#ifdef DYNAMIC_ARRAYS + if ( old_pstruct NEQ NULL ) + globs->pstruct = old_pstruct; +#endif + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/asn1_choice.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,320 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : asn1_choice.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for ASN1_CHOICE +| elements ++----------------------------------------------------------------------------- +*/ + +/* + * Standard definitions like UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes and constants in the common part of ccd + */ +#include "ccd.h" +#include "ccd_codingtypes.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +EXTERN T_FUNC_POINTER codec[MAX_CODEC_ID+1][2]; + +#ifndef RUN_INT_RAM +const UBYTE bitSize[] = {0, 1, 1, 2, 2, 3, 3, 3, 3, + 4, 4, 4, 4, 4, 4, 4, 4, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6}; +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : asn1_choice | +| STATE : code ROUTINE : PER_Decode_ASN1_CHOICE_altervative | ++--------------------------------------------------------------------+ + + PURPOSE : Decode a chosen alternative of an ASN.1 CHOICE type + Use the parameter union tag bit-size to read the CHOICE + index. Because of the ascending enumeration of union tags + it is easy to calculate the e_ref for the chosen element + which is to be decoded. Then the appropriate decoding + function for the chosen element is called. + + No actions for pointer types (dynamic arrays), as CHOICE + clauses contain no information in themselves. Memory is + allocated in the containing SEQUENCE instead. +*/ +void PER_Decode_ASN1_CHOICE_alterative (const ULONG e_ref, T_ENUM UnionTag, T_CCD_Globs *globs) +{ + UBYTE *old_pstruct; + ULONG elem_ref, c_ref; + + c_ref = (ULONG) melem[e_ref].elemRef; + + /* + * Calculate the elem_ref for the chosen element. + * Write the CHOICE tag value in the C-structure. + */ + elem_ref = mcomp[c_ref].componentRef + (ULONG) UnionTag; + *(T_ENUM *) (globs->pstruct+globs->pstructOffs) = (T_ENUM) UnionTag; + + /* + * Prepare for decoding next element. + * Store the current value of the C-structure pointer. After decoding the CHOICE component + * we will set the pointer to this stored value. Then we will use pstructOffs for pointing + * to the next element. + */ + old_pstruct = globs->pstruct; + globs->pstruct += (globs->pstructOffs + sizeof(T_ENUM)); + +#ifdef DYNAMIC_ARRAYS + /* + * Allocate memory for this whole composition, if elemType is + * one of the pointer types. + */ + if ( is_pointer_type(e_ref) AND + PER_allocmem_and_update(e_ref, 1, globs) NEQ ccdOK ) { + return; + } else +#endif + + /* + * Call the decode function for the chosen element. + */ + (void) codec[melem[elem_ref].codingType][DECODE_FUN] + (c_ref, elem_ref, globs); + /* + * Prepare for decoding the next element. + */ + globs->pstruct = old_pstruct; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : asn1_choice | +| STATE : code ROUTINE : cdc_asn1_choice_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decode ASN.1 CHOICE type according to PER + CHOICE index is read from the message bit string. Its + bit-size can be extracted from the number of CHOICE + alternatives. + For decoding the CHOICE alternative itself, call the same + function as for extensible CHOICE types. +*/ +SHORT cdc_asn1_choice_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + T_ENUM UnionTag=0; /* default: only one alternative */ + ULONG num_of_comps, mcomp_ref; + + mcomp_ref = (ULONG) melem[e_ref].elemRef; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_asn1_choice_decode()"); + #else + TRACE_CCD (globs, "cdc_asn1_choice_decode() %s", mcomp[mcomp_ref].name); + #endif +#endif + + /* Don't do anything for empty choices */ + if (mcomp[mcomp_ref].numOfComponents == 0) + { + return 1; + } + + globs->pstructOffs = melem[e_ref].structOffs; + + /* For optional elements we have already set the valid flag in the + * C-structure. We have done it while processing ASN1_SEQ. + */ + if ( ! cdc_isPresent(e_ref, globs) ) { + return 1; + } + + /* + * Get the bit size of the CHOICE index. + * Then read the bits representing the index in the air message. + */ + num_of_comps = (ULONG) mcomp[mcomp_ref].numOfComponents; + /* CHOICE index is encoded only if there are more than one alternatives. */ + if (num_of_comps NEQ 1) + { + UnionTag = bf_getBits ((U32)bitSize[num_of_comps], globs); + /* + * Check correctness of the read CHOICE index. + */ + if ((ULONG)UnionTag >= num_of_comps) + { + ccd_recordFault (globs, ERR_ASN1_ENCODING, BREAK, (USHORT) e_ref, globs->pstruct+globs->pstructOffs); + } + } + PER_Decode_ASN1_CHOICE_alterative (e_ref, UnionTag, globs); + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : asn1_choice | +| STATE : code ROUTINE : PER_Encode_ASN1_CHOICE_altervative | ++--------------------------------------------------------------------+ + + PURPOSE : Encode a chosen alternative of an ASN.1 CHOICE type. + + Because of ascending enumeration of union tags it is + easy to calculate the e_ref for the chosen element to be + encoded. Then the appropriate encoding function for the + chosen element is called. + + No actions for pointer types (dynamic arrays), as CHOICE + clauses contain no information in themselves. Memory is + allocated in the containing SEQUENCE instead. +*/ +void PER_Encode_ASN1_CHOICE_alterative (const ULONG e_ref, T_ENUM UnionTag, T_CCD_Globs *globs) +{ + UBYTE *old_pstruct; + ULONG elem_ref, c_ref; + + c_ref = (ULONG) melem[e_ref].elemRef; + + /* + * Prepare for encoding next element. + * Store the current value of the C-structure pointer. After encoding + * the CHOICE component we will set the pointer to this stored value. + * Then we will use pstructOffs for pointing to the next element. + */ + old_pstruct = globs->pstruct; + globs->pstruct += (globs->pstructOffs + sizeof(T_ENUM)); + +#ifdef DYNAMIC_ARRAYS + /* + * Dereference pointer if this is a pointer types (dynamic arrays) + * globs->pstruct was saved above, so no need to do it again. + */ + if ( is_pointer_type(e_ref) ) { + if (ccd_check_pointer(*(U8 **)(globs->pstruct)) == ccdOK) + globs->pstruct = *(U8 **)(globs->pstruct); + else { + ccd_recordFault (globs, ERR_INVALID_PTR, BREAK, (USHORT) e_ref, + &globs->pstruct[globs->pstructOffs]); + return; + } + } +#endif + + elem_ref = mcomp[c_ref].componentRef + (USHORT) UnionTag; + + /* + * Call the decode function for the chosen element. + */ + (void) codec[melem[elem_ref].codingType][ENCODE_FUN] + (c_ref, elem_ref, globs); + /* + * Prepare for encoding the next element. + */ + globs->pstruct = old_pstruct; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : asn1_choice | +| STATE : code ROUTINE : cdc_asn1_choice_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of CHOICE type for UMTS + The size of the union tag must be calculated. Then its value + is written in the air message. + For encoding the CHOICE alternative itself, call the same + function as for extensible CHOICE types. +*/ +SHORT cdc_asn1_choice_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + T_ENUM UnionTag=0; /* default: only one alternative */ + ULONG num_of_comps, mcomp_ref; + + mcomp_ref = (ULONG) melem[e_ref].elemRef; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_asn1_choice_encode()"); + #else + TRACE_CCD (globs, "cdc_asn1_choice_encode() %s", mcomp[mcomp_ref].name); + #endif +#endif + + /* Don't do anything for empty choices */ + if (mcomp[mcomp_ref].numOfComponents == 0) + { + return 1; + } + + globs->pstructOffs = melem[e_ref].structOffs; + + /* For optional elements we have already set the valid flag in the + * C-structure. We have done it while processing ASN1_SEQ. + */ + if ( ! cdc_isPresent(e_ref, globs) ) + return 1; + + /* + * Get the value of CHOICE index (= union controller) from the C-structure. + * Check its correctness. Write it in the air message. + * Afterwards encode the chosen CHOICE altervative. + */ + num_of_comps = mcomp[mcomp_ref].numOfComponents; + /* CHOICE index is encoded only if there are more than one alternatives. */ + if (num_of_comps NEQ 1) + { + UnionTag = *(T_ENUM *) (globs->pstruct+globs->pstructOffs); + if (UnionTag >= (T_ENUM)num_of_comps) + { + ccd_recordFault (globs, ERR_ASN1_ENCODING, BREAK, (USHORT) e_ref, + globs->pstruct+globs->pstructOffs); + } + bf_writeVal ((ULONG) UnionTag, (ULONG) bitSize[num_of_comps], globs); + } + PER_Encode_ASN1_CHOICE_alterative (e_ref, UnionTag, globs); + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/asn1_choice_ext.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,323 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : asn1_choice_ext.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Encoding and decoding functions for ASN1_CHOICE_EXTENSIBLE type ++----------------------------------------------------------------------------- +*/ + +/* + * Standard definitions like UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes and constants in the common part of ccd + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : asn1_choice_ext | +| STATE : code ROUTINE : cdc_asn1_choice_ext_decode | ++------------------------------------------------------------------------+ + + PURPOSE : Decode PER extensible CHOICE type + + The value of the union tag must be calculated from the encoded + CHOICE index in the air message. + For CHOICE alternatives within the extension root: the index + bit-size relates to max index value in the extension root. + For CHOICE alternatives within the extension part: the index + is encoded as a normally small non-negative whole number. + + For decoding the CHOICE alternative itself, call the same + function as for non-extensible CHOICE types. +*/ +SHORT cdc_asn1_choice_ext_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + U32 extensionBegin; + T_ENUM UnionTag; /* default: only one alternative */ + ULONG calc_ref = calcidx[melem[e_ref].calcIdxRef].condCalcRef; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_asn1_choice_ext_decode()"); + #else + TRACE_CCD (globs, "cdc_asn1_choice_ext_decode() %s", mcomp[melem[e_ref].elemRef].name); + #endif +#endif + + /* Don't do anything for empty choices */ + if (mcomp[melem[e_ref].elemRef].numOfComponents == 0) + { + return 1; + } + + globs->pstructOffs = melem[e_ref].structOffs; + + /* For optional elements we have already set the valid flag in the + * C-structure. We have done it while processing ASN1_SEQ. + */ + if ( ! cdc_isPresent(e_ref, globs) ) { + return 1; + } + + /* + * Get max value of CHOICE index within the extension root. + */ + if (calc_ref EQ NO_REF + OR + calc[calc_ref].operation NEQ 'P') + { + ccd_recordFault (globs, ERR_DEFECT_CCDDATA, BREAK, (USHORT) e_ref, + globs->pstruct+globs->pstructOffs); + return 1; + } + else + { + extensionBegin = calc[calc_ref].operand; + } + + /* + * Read the extensinon bit. + * If set to 1, read the CHOICE index as a normally samll + * non-negative whole number. Otherwise read it according + * to the bitSize of index in the extension root. + */ + if (bf_readBit (globs) EQ 0) + { + /* CHOICE index is encoded only if there are more than one alternatives. */ + if (mcomp[melem[e_ref].elemRef].numOfComponents > 1) + { + UnionTag = (T_ENUM)bf_getBits (bitSize[extensionBegin], globs); + } + else + UnionTag = 0; + + if (UnionTag >= (T_ENUM)extensionBegin) + { + ccd_recordFault (globs, ERR_ASN1_ENCODING, BREAK, (USHORT) e_ref, + globs->pstruct+globs->pstructOffs); + } + PER_Decode_ASN1_CHOICE_alterative (e_ref, UnionTag, globs); + } + else + { + U32 finalBP=0; + UnionTag = (T_ENUM)Read_NormallySmallNonNegativeWholeNr (globs); + UnionTag += extensionBegin; + finalBP = Read_OpenTpye_Length (globs)*8; + finalBP += globs->bitpos; + + /* + * For unknown extension skip over the octets. + */ + if (UnionTag <= (T_ENUM)mcomp[melem[e_ref].elemRef].numOfComponents) + { + PER_Decode_ASN1_CHOICE_alterative (e_ref, UnionTag, globs); + } + else + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "Unknown extension with CHOICE index = %ld...skipped to the bit %ld", UnionTag, finalBP); +#endif + } + bf_setBitpos (finalBP, globs); + } + + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : asn1_choice_ext | +| STATE : code ROUTINE : cdc_asn1_choice_ext_encode | ++------------------------------------------------------------------------+ + + PURPOSE : Encode PER extensible CHOICE type + + Evaluate the union controller. + 1) It refers to a CHOICE alternative within the extension root: + Set the extension bit to 0. + Write the CHOICE index. + Then encode the chosen alternative. + ------------------------------------ + | extension | CHOICE | encoded | + | bit | index | alternative | + ------------------------------------ + + 2) It refers to a CHOICE alternative within the extension list: + Set the extension bit to 1. + Encode the CHOICE index as a normally small non-negative whole nr. + Skip over 6 bits dedicated to length determinant. + Encode the chosen alternative. + Calculate the bit size of the encoded alternative. + Encode the calculated bit size into the field of length + determinant. Right shift the encoded alternative, if 6 bits + are not enough for the length determinant. + ------------------------------------------------ + | extension | CHOICE | length | encoded | + | bit | index | determinant | alternative | + ------------------------------------------------ + + For encoding the CHOICE alternative itself, call the same + function as for non-extensible CHOICE types. +*/ +SHORT cdc_asn1_choice_ext_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + U16 startBitpos, Len, EndBitPos; + T_ENUM UnionTag; /* default: only one alternative */ + U32 extensionBegin; + ULONG calc_ref= calcidx[melem[e_ref].calcIdxRef].condCalcRef; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_asn1_choice_ext_encode()"); + #else + TRACE_CCD (globs, "cdc_asn1_choice_ext_encode() %s", mcomp[melem[e_ref].elemRef].name); + #endif +#endif + + /* Don't do anything for empty choices */ + if (mcomp[melem[e_ref].elemRef].numOfComponents == 0) + { + return 1; + } + + globs->pstructOffs = melem[e_ref].structOffs; + + /* For optional elements we have already set the valid flag in the + * C-structure. We have done it while processing ASN1_SEQ. + */ + if ( ! cdc_isPresent(e_ref, globs) ) + return 1; + + /* + * Get max value of CHOICE index within the extension root. + */ + if (calc_ref EQ NO_REF + OR + calc[calc_ref].operation NEQ 'P') + { + ccd_recordFault (globs, ERR_DEFECT_CCDDATA, BREAK,(USHORT) e_ref, + globs->pstruct+globs->pstructOffs); + return 1; + } + else + { + extensionBegin = calc[calc_ref].operand; + } + + /* + * Get the value of chosen index (= union controller). + */ + UnionTag = *(T_ENUM *) (globs->pstruct+globs->pstructOffs); + + /* + * The chosen alternative belongs to the extension list. + */ + if ((U32)UnionTag >= extensionBegin) + { + /* Encode the extension bit first */ + bf_writeBit (1, globs); + /* Encode the CHOICE index. */ + Write_NormallySmallNonNegativeWholeNr (((U32)UnionTag - extensionBegin), globs); + + /* Skip over the bits estimated for the length determinant. */ + bf_incBitpos (8, globs); + startBitpos = globs->bitpos; + PER_Encode_ASN1_CHOICE_alterative (e_ref, UnionTag, globs); + + /* + * Check if zero padding bits are necessary. If encoding + * consumed no bits, insert a zero-octet in the bit string. + * Then calculate length of the encoded open type in octets. + */ + if ((Len = globs->bitpos - startBitpos) EQ 0) + { + bf_writeVal (0, 8, globs); + Len = 1; + } + else + { + if ((Len&7) NEQ 0) + bf_incBitpos (8 - (Len&7), globs); + Len = (U16)(globs->bitpos - startBitpos) >> 3; + } + EndBitPos = globs->bitpos; + + /* + * Encode the length determinant. + */ + if (Len < 128) + { + bf_setBitpos (startBitpos-8, globs); + Write_OpenTpye_Length ((U32)Len, globs); + } + /* + * This case does not seem to happen very often. + */ + else + { + ccd_recordFault (globs, ERR_ASN1_ENCODING, BREAK,(USHORT) e_ref, + globs->pstruct+globs->pstructOffs); + } + /* + * Encoding for the extensible choice is finished. + * Set the bit position pointer to the end of encoded open type. + */ + bf_setBitpos (EndBitPos, globs); + } + /* + * The chosen alternative belongs to the extension root. + */ + else + { + bf_writeBit (0, globs); + /* CHOICE index is encoded only if there are more than one alternatives. */ + if (mcomp[melem[e_ref].elemRef].numOfComponents > 1) + { + bf_writeVal ((ULONG) UnionTag, (ULONG) bitSize[extensionBegin], globs); + } + PER_Encode_ASN1_CHOICE_alterative (e_ref, UnionTag, globs); + } + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/asn1_integ.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,512 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : asn1_integ.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for ASN1_INTEGER +| elements ++----------------------------------------------------------------------------- +*/ + +/* + * Standard definitions like UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : asn1_integ | +| STATE : code ROUTINE : Read_unique_Integer | ++--------------------------------------------------------------------+ + + PURPOSE : Decode integer with only one possible value. + Such a value is never encoded. +*/ +void Read_unique_Integer (const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG varRef, valRef; + U8 *value; + + varRef = (ULONG) melem[e_ref].elemRef; + valRef = (ULONG) mvar[varRef].valueDefs; +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "Read_unique_Integer()"); + #else + TRACE_CCD (globs, "Read_unique_Integer() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + if (mval[valRef].startValue EQ 0) + { + /* + * Do not do anything for empty sequences and NULL elements. + * (Hint: Integers with only one possible value equal to 0 are + * automatically processed through memory reset of the C-structure + * at the beginning of decode activities or after each dynamic + * memory allocation.) + */ + return; + } + else + { + /* + * For optional elements we have already set the valid flag in the + * C-structure while processing ASN1_SEQ. + */ + if (melem[e_ref].optional) + { + if (globs->pstruct[globs->pstructOffs++] EQ FALSE) + return; + } + +#ifdef DYNAMIC_ARRAYS + if ( is_pointer_type(e_ref) ) + { + value = PER_allocmem(e_ref, 1, globs); + + if (value EQ (U8 *)ccdError) + return; + + /* + * Store pointer to allocated memory in c structure. + */ + *(U8 **)(globs->pstruct + globs->pstructOffs) = value; + } + else +#endif + value = globs->pstruct + globs->pstructOffs; + + switch (mvar[varRef].cType) + { + case 'B': + *(U8*) value = (U8) mval[valRef].startValue; + break; + case 'C': + *(S8*) value = (S8) mval[valRef].startValue; + break; + case 'S': + *(U16*) value = (U16) mval[valRef].startValue; + break; + case 'T': + *(S16*) value = (S16) mval[valRef].startValue; + break; + case 'L': + *(U32*) value = (U32) mval[valRef].startValue; + break; + case 'M': + *(S32*) value = (S32) mval[valRef].startValue; + break; + default: + ccd_recordFault (globs,ERR_DEFECT_CCDDATA, BREAK, (USHORT) e_ref, value); + break; + } + return; + } +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : asn1_integ | +| STATE : code ROUTINE : cdc_asn1_integ_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the PER integer type for UMTS + PER-visible constraints restrict the integer value to be a + constrained whole number. This gives a lower and an upper + bound for the integer. The lb is also called offset. The + encoded value is the difference between the actual and the + offset value. + A possible and meant default value is never encoded. +*/ +SHORT cdc_asn1_integ_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat=1, maxRep=1, varRef, valRef; + BOOL DefaultFound= FALSE; + S32 IfnotPresent; + UBYTE *value, *old_pstruct = NULL; + + varRef = (ULONG) melem[e_ref].elemRef; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_asn1_integ_decode()"); + #else + TRACE_CCD (globs, "cdc_asn1_integ_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + /* + * Set the offset in the C-structure on the value for this element. + */ + globs->pstructOffs = melem[e_ref].structOffs; + + /* + * Decode an empty sequence, a NULL element or an integer of constant value. + */ + if (mvar[varRef].bSize EQ 0) + { + Read_unique_Integer (e_ref, globs); + return 1; + } + valRef = (ULONG) mvar[varRef].valueDefs; + + /* + * Set pstrcutOffs and maxRep. Check the valid flag in case of optional elements. + */ + if (PER_CommonBegin (e_ref, &maxRep, globs) NEQ ccdOK) + return 1; + +#ifdef DYNAMIC_ARRAYS + /* + * Allocate memory if this is a pointer type (dynamic array) + */ + if ( is_pointer_type(e_ref) ) { + old_pstruct = globs->pstruct; + if ( PER_allocmem_and_update(e_ref, maxRep, globs) NEQ ccdOK) + /* No memory - Return. Error already set in function call above. */ + return 1; + } +#endif + + /* + * Check if there is a default value for the element. + * If yes, just set it aside for a later comparision. + */ + if (mval[valRef+1].isDefault EQ 2) + { + IfnotPresent = mval[valRef+1].startValue; + DefaultFound = TRUE; + } + + /* + * Decode all elements of the array. + */ + while ( repeat <= maxRep) + { + + value = globs->pstruct + globs->pstructOffs; + + /* + * There is a default value for this integer elment. + * While decoding of the ASN1-SEQUENCE contiaing this integer + * we have used a particular byte of C-structure to signalize + * the decoding of a default value (byte set to 0). + */ + if (DefaultFound AND !globs->pstruct[melem[e_ref].structOffs]) + { + switch (mvar[varRef].cType) + { + case 'B': + *(U8*) value = (U8) IfnotPresent; + break; + case 'C': + *(S8*) value = (S8) IfnotPresent; + break; + case 'S': + *(U16*) value = (U16) IfnotPresent; + break; + case 'T': + *(S16*) value = (S16) IfnotPresent; + break; + case 'L': + *(U32*) value = (U32) IfnotPresent; + break; + case 'M': + *(S32*) value = (S32) IfnotPresent; + break; + default: + ccd_recordFault (globs,ERR_DEFECT_CCDDATA, BREAK, (USHORT) e_ref, value); + return 1; + } + } + /* + * There is no default value defined for this integer elment. + * Read the value from the bit buffer. + */ + else + { + U32 ub, lb; + ULONG readBits; + U32 DecodedValue; + + lb = mval[valRef].startValue; + ub = mval[valRef].endValue; + + /* + * Read the non-negative value from the air message. + */ + readBits = bf_getBits (mvar[varRef].bSize, globs); + + + if (readBits <= (U32)(ub - lb)) + { + DecodedValue = lb + readBits; + /* + * Add the offset to the read value to get the actual one. + + */ + switch (mvar[varRef].cType) + { + case 'B': + *(U8*) value = (U8) DecodedValue; + break; + case 'C': + *(S8*) value = (S8) DecodedValue; + break; + case 'S': + *(U16*) value = (U16) DecodedValue; + break; + case 'T': + *(S16*) value = (S16) DecodedValue; + break; + case 'L': + *(U32*) value = (U32) DecodedValue; + break; + case 'M': + *(S32*) value = (S32) DecodedValue; + break; + default: + ccd_recordFault (globs,ERR_DEFECT_CCDDATA, BREAK, (USHORT) e_ref, value); + break; + } + } + else + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "integer out of range! %ld require: %ld .. %ld ", DecodedValue, lb, ub); +#endif + if (melem[e_ref].optional) + ccd_recordFault (globs, ERR_ASN1_OPT_IE, CONTINUE, (USHORT) e_ref, value); + else + ccd_recordFault (globs, ERR_ASN1_MAND_IE, CONTINUE, (USHORT) e_ref, value); + } + } + repeat ++; + globs->pstructOffs += mvar[varRef].cSize; + }/*while*/ + +#ifdef DYNAMIC_ARRAYS + if (old_pstruct NEQ NULL) + globs->pstruct = old_pstruct; +#endif + + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : asn1_integ | +| STATE : code ROUTINE : cdc_asn1_integ_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the PER integer type for UMTS + PER-visible constraints restrict the integer value to be a + constrained whole number. This gives a lower and an upper + bound for the integer. The lb is also called offset. The + encoded value is the difference between the actual and the + offset value. Hence encoded values are non-negative. + A possible and meant default value is never encoded. +*/ +SHORT cdc_asn1_integ_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat=1, maxRep=1, varRef, valRef; + BOOL DefaultFound= FALSE; + S32 IfnotPresent; + U8 *base_pstruct; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_asn1_integ_encode()"); + #else + TRACE_CCD (globs, "cdc_asn1_integ_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + varRef = (ULONG) melem[e_ref].elemRef; + valRef = (ULONG) mvar[varRef].valueDefs; + + /* + * Don't do anything for empty sequences, NULL elements or integers of constant value. + */ + if (mvar[varRef].bSize EQ 0) + return 1; + + /* + * Set pstrcutOffs and maxRep. Check the valid flag in case of optional elements. + */ + if (PER_CommonBegin (e_ref, &maxRep, globs) NEQ ccdOK) + return 1; + + /* + * Check if there is a default value for the element. + * If yes, just set it aside for a later comparision. + */ + if (mval[valRef+1].isDefault EQ 2) + { + IfnotPresent = mval[valRef+1].startValue; + DefaultFound = TRUE; + } + +#ifdef DYNAMIC_ARRAYS + if ( is_pointer_type(e_ref) ) + { + base_pstruct = *(U8 **)(globs->pstruct + globs->pstructOffs); + if (ccd_check_pointer(base_pstruct) == ccdOK) + { + globs->pstructOffs = 0; + } + else + { + ccd_recordFault (globs, ERR_INVALID_PTR, BREAK, (USHORT) e_ref, + &globs->pstruct[globs->pstructOffs]); + return 1; + } + } + else +#endif + base_pstruct = globs->pstruct; + + /* + * Encode all elements of the array. + */ + while ( repeat <= maxRep) + { + S32 ub, lb, value; + UBYTE *p; + + /* + * setup the read pointer to the element in the C-structure + */ + p = base_pstruct + globs->pstructOffs; + + switch (mvar[varRef].cType) + { + case 'B': + value = (S32)*(UBYTE *) p; + break; + case 'C': + value = (S32)*(S8 *) p; + break; + case 'S': + value = (S32)*(USHORT *) p; + break; + case 'T': + value = (S32)*(S16 *) p; + break; + case 'L': + /* + * This type casting can be critical. + * Thus the case of bSize=32 will be handled separately. + */ + if (mvar[varRef].bSize < 32) + { + value = (S32)*(U32 *) p; + } + break; + case 'M': + value = *(S32 *) p; + break; + default: + ccd_recordFault (globs, ERR_DEFECT_CCDDATA, BREAK, (USHORT) e_ref, p); + return 1; + } + + if (mvar[varRef].cType EQ 'L' AND + (mvar[varRef].bSize EQ 32)) + { + ULONG CriticalValue; + U32 lb, ub; + CriticalValue = *(U32 *) p; + if (!DefaultFound OR (U32)IfnotPresent NEQ CriticalValue) + { + lb = (U32) mval[valRef].startValue; + ub = (U32) mval[valRef].endValue; + if (lb <= CriticalValue && CriticalValue <= ub) + { + bf_writeVal (CriticalValue - lb, mvar[varRef].bSize, globs); + } + } + else + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "integer out of range! %ld require: %ld .. %ld ", + value, lb, ub); +#endif + ccd_recordFault (globs, ERR_INT_VALUE, CONTINUE, (USHORT) e_ref, p); + } + } + else + { + /* + * Encode only non-default values. + */ + if (!DefaultFound OR IfnotPresent NEQ value) + { + /* + * A non-negative-binary-integer will be encoded since the offset must + * be subtracted from the value read from the C-structure. + */ + lb = mval[valRef].startValue; + ub = mval[valRef].endValue; + if (lb <= value AND value <= ub) + { + bf_writeVal ((ULONG)(value - lb), mvar[varRef].bSize, globs); + } + else + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "integer out of range! %ld require: %ld .. %ld ", value, lb, ub); +#endif + ccd_recordFault (globs, ERR_INT_VALUE, CONTINUE, (USHORT) e_ref, p); + } + } + } + repeat ++; + globs->pstructOffs += mvar[varRef].cSize; + }/* while-loop */ + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/asn1_integ_ext.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,497 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : asn1_integ_ext.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Encoding and decoding functions for ASN1_INTEGER_EXTENSIBLE type ++----------------------------------------------------------------------------- +*/ + +/* + * Standard definitions like UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes and constants in the common part of ccd + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : asn1_integ_ext | +| STATE : code ROUTINE : cdc_asn1_integ_ext_decode | ++------------------------------------------------------------------------+ + + PURPOSE : Decode UNALIGNED PER extensible ENUMERATED and INTEGER type + PER-visible constraints restrict the integer value to be a + constrained whole number. This gives a lower and an upper + bound for the integer. The lb is also called offset. The + encoded value is the difference between the actual and the + offset value. + A possible and meant default value is never encoded. + + If the value is in the extension root, it will be encoded as + a normally small non-negative whole number. Otherwise it will + be encoded in the smalles number of bits needed to express + every enumeration. +*/ +SHORT cdc_asn1_integ_ext_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat=1, max_rep=1, var_ref, val_ref; + BOOL DefaultFound= FALSE; + S32 IfnotPresent; + UBYTE *value, *old_pstruct = NULL; + + var_ref = (ULONG) melem[e_ref].elemRef; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_asn1_integ_ext_decode()"); + #else + TRACE_CCD (globs, "cdc_asn1_integ_ext_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + /* + * For integer with only one possible value in the extension root: + * If the extensinon bit is 0, the encoded value is in the extension root. + * In this case no arrays are expected. + * For other types: + * The extension bit and the value will be read in the while-loop below. + */ + if (mvar[var_ref].bSize EQ 0) + { + if (bf_readBit (globs) EQ FALSE) + { + Read_unique_Integer (e_ref, globs); + return 1; + } + else + { + bf_incBitpos (-1, globs); + } + } + + val_ref = (ULONG) mvar[var_ref].valueDefs; + /* + * Set pstrcutOffs and max_rep. Check the valid flag in case of optional elements. + */ + if (PER_CommonBegin (e_ref, &max_rep, globs) NEQ ccdOK) + return 1; + +#ifdef DYNAMIC_ARRAYS + /* + * Allocate memory if this is a pointer type (dynamic array) + */ + if ( is_pointer_type(e_ref) ) { + old_pstruct = globs->pstruct; + if ( PER_allocmem_and_update(e_ref, max_rep, globs) NEQ ccdOK) + /* No memory - Return. Error already set in function call above. */ + return 1; + } +#endif + + /* + * Check if there is a default value for the element. + * If yes, just set it aside for a later comparision. + */ + if (mval[val_ref+1].isDefault EQ 2) + { + IfnotPresent = mval[val_ref+1].startValue; + DefaultFound = TRUE; + } + + /* + * Decode all elements of the array. + */ + while ( repeat <= max_rep) + { + + value = globs->pstruct + globs->pstructOffs; + + /* + * There is a default value for this integer elment. + * While decoding of the ASN1-SEQUENCE contiaing this integer + * we have used a particular byte of C-structure to signalize + * the decoding of a default value (byte set to 0). + */ + if (DefaultFound AND !globs->pstruct[melem[e_ref].structOffs]) + { + switch (mvar[var_ref].cType) + { + case 'B': + *(U8*) value = (U8) IfnotPresent; + break; + case 'C': + *(S8*) value = (S8) IfnotPresent; + break; + case 'S': + *(U16*) value = (U16) IfnotPresent; + break; + case 'T': + *(S16*) value = (S16) IfnotPresent; + break; + case 'L': + *(U32*) value = (U32) IfnotPresent; + break; + case 'M': + *(S32*) value = (S32) IfnotPresent; + break; + default: + ccd_recordFault (globs,ERR_DEFECT_CCDDATA, BREAK, (USHORT) e_ref, value); + break; + } + } + /* + * There is no default value defined for this integer elment. + * Read the value from the bit buffer. + */ + else + { + U32 ub, lb; + ULONG readBits; + U32 DecodedValue; + + lb = mval[val_ref].startValue; + ub = mval[val_ref].endValue; + /* + * Read first the extensinon bit. + * Then the non-negative value from the air message. + */ + if (bf_readBit (globs) EQ FALSE) + { + readBits = bf_getBits (mvar[var_ref].bSize, globs); + } + /* Value out of the extension root. */ + else + { + U16 calcRef = calcidx[melem[e_ref].calcIdxRef].condCalcRef; + /* + * Get max value of integer within the extension root. + */ + if (calcRef EQ NO_REF + OR + calc[calcRef].operation NEQ 'P') + { + ccd_recordFault (globs, ERR_DEFECT_CCDDATA, BREAK, (USHORT) + e_ref, globs->pstruct+globs->pstructOffs); + } + else + { + lb = calc[calcRef].operand; + } + readBits = Read_NormallySmallNonNegativeWholeNr (globs); + } + + + if (readBits <= (U32)(ub - lb)) + { + DecodedValue = lb + readBits; + /* + * Add the offset to the read value to get the actual one. + */ + switch (mvar[var_ref].cType) + { + case 'B': + *(U8*) value = (U8) DecodedValue; + break; + case 'C': + *(S8*) value = (S8) DecodedValue; + break; + case 'S': + *(U16*) value = (U16) DecodedValue; + break; + case 'T': + *(S16*) value = (S16) DecodedValue; + break; + case 'L': + *(U32*) value = (U32) DecodedValue; + break; + case 'M': + *(S32*) value = (S32) DecodedValue; + break; + default: + ccd_recordFault (globs,ERR_DEFECT_CCDDATA, BREAK, (USHORT) e_ref, value); + break; + } + } + else + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "integer out of range! %ld require: %ld .. %ld ", DecodedValue, lb, ub); +#endif + if (melem[e_ref].optional) + ccd_recordFault (globs, ERR_ASN1_OPT_IE, CONTINUE, (USHORT) e_ref, value); + else + ccd_recordFault (globs, ERR_ASN1_MAND_IE, CONTINUE, (USHORT) e_ref, value); + } + } + repeat ++; + globs->pstructOffs += mvar[var_ref].cSize; + }/*while*/ + +#ifdef DYNAMIC_ARRAYS + if (old_pstruct NEQ NULL) + globs->pstruct = old_pstruct; +#endif + + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : asn1_integ_ext | +| STATE : code ROUTINE : cdc_asn1_integ_ext_encode | ++------------------------------------------------------------------------+ + + PURPOSE : UNALIGNED PER extensible ENUMERATED and INTEGER type + PER-visible constraints restrict the integer value to be a + constrained whole number. This gives a lower and an upper + bound for the integer. The lb is also called offset. The + encoded value is the difference between the actual and the + offset value. + A possible and meant default value is never encoded. + + If the value is in the extension root, it will be encoded as + a normally small non-negative whole number. Otherwise it will + be encoded in the smalles number of bits needed to express + every enumeration. + + ----------------------------------------------- + | extension | value encoded as a normally | + | bit = 1 | non-negtive integer whole number | + ----------------------------------------------- + + ----------------------------------------------- + | extension | value encoded in the bit size | + | bit = 0 | needed to express ub - lb | + ----------------------------------------------- +*/ +SHORT cdc_asn1_integ_ext_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat=1, max_rep=1, var_ref, val_ref; + BOOL DefaultFound= FALSE; + S32 IfnotPresent; + U8 *base_pstruct; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_asn1_integ_ext_encode()"); + #else + TRACE_CCD (globs, "cdc_asn1_integ_ext_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + var_ref = (ULONG) melem[e_ref].elemRef; + val_ref = (ULONG) mvar[var_ref].valueDefs; + + /* + * Set pstrcutOffs and max_rep. Check the valid flag in case of optional elements. + */ + if (PER_CommonBegin (e_ref, &max_rep, globs) NEQ ccdOK) + return 1; + /* + * Check if there is a default value for the element. + * If yes, just set it aside for a later comparision. + */ + if (mval[val_ref+1].isDefault EQ 2) + { + IfnotPresent = mval[val_ref+1].startValue; + DefaultFound = TRUE; + } + +#ifdef DYNAMIC_ARRAYS + if ( is_pointer_type(e_ref) ) + { + base_pstruct = *(U8 **)(globs->pstruct + globs->pstructOffs); + if (ccd_check_pointer(base_pstruct) == ccdOK) + { + globs->pstructOffs = 0; + } + else + { + ccd_recordFault (globs, ERR_INVALID_PTR, BREAK, (USHORT) e_ref, + &globs->pstruct[globs->pstructOffs]); + return 1; + } + } + else +#endif + base_pstruct = globs->pstruct; + + /* + * Encode all elements of the array. + */ + while ( repeat <= max_rep) + { + S32 ub, lb, value; + U32 extension_lb; + UBYTE *p; + U16 calcRef = calcidx[melem[e_ref].calcIdxRef].condCalcRef; + /* + * Get offset value of integer in the extension addition. + */ + if (calcRef EQ NO_REF + OR + calc[calcRef].operation NEQ 'P') + { + ccd_recordFault (globs, ERR_DEFECT_CCDDATA, BREAK,(USHORT) e_ref, + globs->pstruct+globs->pstructOffs); + return 1; + } + else + { + extension_lb = calc[calcRef].operand; + } + /* + * setup the read pointer to the element in the C-structure + */ + p = base_pstruct + globs->pstructOffs; + + switch (mvar[var_ref].cType) + { + case 'B': + value = (S32)*(UBYTE *) p; + break; + case 'C': + value = (S32)*(S8 *) p; + break; + case 'S': + value = (S32)*(USHORT *) p; + break; + case 'T': + value = (S32)*(S16 *) p; + break; + case 'L': + /* + * This type casting can be critical. + * Thus the case of bSize=32 will be handled separately. + */ + if (mvar[var_ref].bSize < 32) + { + value = (S32)*(U32 *) p; + } + break; + case 'M': + value = *(S32 *) p; + break; + default: + ccd_recordFault (globs,ERR_DEFECT_CCDDATA, BREAK, (USHORT) e_ref, p); + return 1; + } + + if (mvar[var_ref].cType EQ 'L' AND + (mvar[var_ref].bSize EQ 32)) + { + U32 CriticalValue; + CriticalValue = *(U32 *) p; + if (CriticalValue >= extension_lb) + { + bf_writeBit (1, globs); + if (!DefaultFound OR (U32)IfnotPresent NEQ CriticalValue) + Write_NormallySmallNonNegativeWholeNr (CriticalValue - extension_lb, globs); + } + else + { + bf_writeBit (0, globs); + if (!DefaultFound OR (U32)IfnotPresent NEQ CriticalValue) + { + U32 lb, ub; + lb = (U32) mval[val_ref].startValue; + ub = (U32) mval[val_ref].endValue; + if (lb <= CriticalValue && CriticalValue <= ub) + { + bf_writeVal (CriticalValue - lb, mvar[var_ref].bSize, globs); + } + else + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "integer out of range! %ld require: %ld .. %ld ", + value, lb, ub); +#endif + ccd_recordFault (globs, ERR_INT_VALUE, CONTINUE, (USHORT) e_ref, p); + } + } + } + } + else + { + /* + * Encode only non-default values. + */ + if (!DefaultFound OR IfnotPresent NEQ value) + { + /* + * Set the extension bit to 0 if the value belongs to the extension root. + * Otherwise set it to 1. + * A non-negative-binary-integer will be encoded since the offset must + * be subtracted from the value read from the C-structure. + */ + lb = mval[val_ref].startValue; + ub = mval[val_ref].endValue; + + if (value >= (S32)extension_lb AND value <= ub) + { + bf_writeBit (1, globs); + Write_NormallySmallNonNegativeWholeNr ((U32)value - extension_lb, globs); + } + else if (lb <= value AND value <= ub) + { + bf_writeBit (0, globs); + /* + * Do not encode single valued extension roots. + */ + if (mvar[var_ref].bSize NEQ 0) + bf_writeVal ((ULONG)(value-lb), mvar[var_ref].bSize, globs); + } + else + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "integer out of range! %ld require: %ld .. %ld ", value, lb, ub); +#endif + ccd_recordFault (globs, ERR_INT_VALUE, CONTINUE, (USHORT) e_ref, p); + } + } + } /* value not critical*/ + repeat ++; + globs->pstructOffs += mvar[var_ref].cSize; + }/* while-loop */ + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/asn1_objid.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,141 @@ + +/* ++------------------------------------------------------------------------------ +| File: asn1_objid.c ++------------------------------------------------------------------------------ +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG. +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++------------------------------------------------------------------------------ +| Purpose: Encoding and decoding functions for ASN1_OBJ_ID type +| +| $Identity:$ ++------------------------------------------------------------------------------ +*/ + +/* + * Standard definitions like UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes and constants in the common part of ccd + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : asn1_objid | +| STATE : code ROUTINE : cdc_asn1_obj_id_decode | ++------------------------------------------------------------------------+ + + PURPOSE : Decode PER OBJECT IDENTIFIER type + + The PER encoding of an object identifier type uses the + content octets of BER preceded by a length determinant + that will in practice be a single octet. +*/ +SHORT cdc_asn1_obj_id_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + U8 BER_Len; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_asn1_obj_id_decode()"); + #else + TRACE_CCD (globs, "cdc_asn1_obj_id_decode() %s", mcomp[melem[e_ref].elemRef].name); + #endif +#endif + + globs->pstructOffs = melem[e_ref].structOffs; + + /* For optional elements we have already set the valid flag in the + * C-structure. We have done it while processing ASN1_SEQ. + */ + if ( ! cdc_isPresent(e_ref, globs) ) { + return 1; + } + + /* + * Skip over PER length octet and BER tag octet. + */ + bf_incBitpos (16, globs); + + /* + * For unknown extension read the length and skip over the octets. + */ + BER_Len = (U8) bf_getBits (8, globs); + *(U8 *)(globs->pstruct + globs->pstructOffs++) = BER_Len; + + /* + * Copy the content of object identifier bytes into the C-Structure. + */ +#ifdef _TMS470 + bf_incBitpos (8 * BER_Len, globs); +#else + { + int i; + for (i=0; i < BER_Len; i++) + *(U8 *)(globs->pstruct + globs->pstructOffs++) = (U8) bf_getBits (8, globs); + } +#endif + + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : asn1_objid | +| STATE : code ROUTINE : cdc_asn1_obj_id_encode | ++------------------------------------------------------------------------+ + + PURPOSE : Encode PER OBJECT IDENTIFIER type + + The PER encoding of an object identifier type uses the + content octets of BER preceded by a length determinant + that will in practice be a single octet. +*/ +SHORT cdc_asn1_obj_id_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_asn1_obj_id_encode()"); + #else + TRACE_CCD (globs, "cdc_asn1_obj_id_encode() %s", mcomp[melem[e_ref].elemRef].name); + #endif +#endif + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/asn1_octet.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,168 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : asn1_octet.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for ASN1_OCTET +| elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_asn1_octet_decode | ++--------------------------------------------------------------------+ + + PURPOSE : UNALIGNED PER decoding for the octet string type (UMTS) + The coded octets are preceded by a length indicator, if + they are not of fixed length. The length indicator is + decoded as an ASN1_INTEGER type. +*/ +SHORT cdc_asn1_octet_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat; + U8 *old_pstruct = NULL; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_asn1_octet_decode()"); + #else + TRACE_CCD (globs, "cdc_asn1_octet_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + /* + * Set pstrcutOffs and maxRep. + * Check the valid flag in case of optional elements. + */ + if (PER_CommonBegin (e_ref, &repeat, globs) NEQ ccdOK) + return 1; + +#ifdef DYNAMIC_ARRAYS + /* + * Check for pointer types, and allocate memory if necessary. + * May overwrite globs->pstruct (and initialize globs->pstructOffs to 0). + */ + if ( is_pointer_type(e_ref) ) + { + old_pstruct = globs->pstruct; + if ( PER_allocmem_and_update(e_ref, repeat, globs) NEQ ccdOK) + /* No memory - Return. Error already set in function call above. */ + return 1; + } +#endif + + bf_readBitStr_PER ((USHORT)(repeat << 3), globs); + +#ifdef DYNAMIC_ARRAYS + if (old_pstruct NEQ NULL) + globs->pstruct = old_pstruct; +#endif + + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_asn1_octet_encode | ++--------------------------------------------------------------------+ + + PURPOSE : UNALIGNED PER encoding for the octet string type (UMTS) + The coded octets are preceded by a length indicator, if + they are not of fixed length. The length indicator is + encoded as an ASN1_INTEGER type. +*/ +SHORT cdc_asn1_octet_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat; + U8 *old_pstruct = NULL; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_asn1_octet_encode()"); + #else + TRACE_CCD (globs, "cdc_asn1_octet_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + /* + * Set pstrcutOffs and maxRep. Check the valid flag in case of optional elements. + */ + if (PER_CommonBegin (e_ref, &repeat, globs) NEQ ccdOK) + return 1; + +#ifdef DYNAMIC_ARRAYS + if ( is_pointer_type(e_ref) ) { + old_pstruct = globs->pstruct; + globs->pstruct = *(U8 **)(globs->pstruct + globs->pstructOffs); + + if (ccd_check_pointer(globs->pstruct) == ccdOK) + { + globs->pstructOffs = 0; + } + else + { + ccd_recordFault (globs, ERR_INVALID_PTR, BREAK, (USHORT) e_ref, + &globs->pstruct[globs->pstructOffs]); + return 1; + } + } +#endif + + bf_writeBitStr_PER ((USHORT)(repeat << 3), globs); + +#ifdef DYNAMIC_ARRAYS + if ( old_pstruct NEQ NULL ) + globs->pstruct = old_pstruct; +#endif + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/asn1_opentype.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,139 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : asn1_opentype.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Encoding and decoding functions for ASN1_OPEN_TYPE type ++----------------------------------------------------------------------------- +*/ + +/* + * Standard definitions like UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes and constants in the common part of ccd + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : asn1_opentype | +| STATE : code ROUTINE : cdc_asn1_open_type_decode | ++------------------------------------------------------------------------+ + + PURPOSE : Decode PER OBJECT IDENTIFIER type + + The PER encoding of an open type is preceded by a length + determinant (1 or 2 bytes as long as no data fragmentation is + necessary). The bit field of the encoded open type itself is + octet aligned octet string. + If the result of encoding the outermost value is an empty bit + string, the bit string must be replaced with a single octet + with all bits set to 0. +*/ +SHORT cdc_asn1_open_type_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + U8 BER_Len; + +#ifdef DEBUG_CCD +#ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_asn1_open_type_decode()"); +#else + TRACE_CCD (globs, "cdc_asn1_open_type_decode() %s", mcomp[melem[e_ref].elemRef].name); +#endif +#endif + + globs->pstructOffs = melem[e_ref].structOffs; + + /* For optional elements we have already set the valid flag in the + * C-structure. We have done it while processing ASN1_SEQ. + */ + if ( ! cdc_isPresent(e_ref, globs) ) { + return 1; + } + + /* + * For unknown extension read the length and skip over the octets. + */ + BER_Len = (U8) Read_OpenTpye_Length (globs); + bf_incBitpos (8 * BER_Len, globs); + + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : asn1_opentype | +| STATE : code ROUTINE : cdc_asn1_open_type_encode | ++------------------------------------------------------------------------+ + + PURPOSE : PER encoding of open types + + The PER encoding of an open type is preceded by a length + determinant (1 or 2 bytes as long as no data fragmentation is + necessary). The bit field of the encoded open type itself is + octet aligned octet string. + If the result of encoding the outermost value is an empty bit + string, the bit string must be replaced with a single octet + with all bits set to 0. +*/ +SHORT cdc_asn1_open_type_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD +#ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_asn1_open_type_encode()"); +#else + TRACE_CCD (globs, "cdc_asn1_open_type_encode() %s", mcomp[melem[e_ref].elemRef].name); +#endif +#endif + + /* For optional elements we have already set the valid flag in the + * C-structure. We have done it while processing ASN1_SEQ. + */ + if ( ! cdc_isPresent(e_ref, globs) ) + return 1; +#ifdef DEBUG_CCD + else + { + TRACE_CCD (globs, "Please set valid flag to 0 for open type element."); + } +#endif + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/asn1_seq.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,615 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : asn1_seq.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for ASN1_SEQUENCE +| elements ++----------------------------------------------------------------------------- +*/ + +#define ASN1_SEQ_C + +/* + * Standard definitions like UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes and constants in the common part of ccd + */ +#include "ccd.h" +#include "ccd_codingtypes.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +EXTERN T_FUNC_POINTER codec[MAX_CODEC_ID+1][2]; + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : asn1_seq | +| STATE : code ROUTINE : Read_SEQ_BitMap | ++--------------------------------------------------------------------+ + + PURPOSE : Decode the bit-map preamble for OPTIONAL elements + or those with DEFAULT value. +*/ +void Read_SEQ_BitMap (const ULONG first_elem, const ULONG last_elem, T_CCD_Globs *globs) +{ + ULONG elem = first_elem; + while (elem < last_elem) + { + if (melem[elem].optional) + { + /* + * For optional elements read the corresponding bit in the preamble + * and set the valid flag in the C-Structure to it. + */ + if (melem[elem].elemType < 'P' OR melem[elem].elemType > 'R') + { + globs->pstruct[melem[elem].structOffs] = (UBYTE) bf_readBit(globs); + } + else + { + if(bf_readBit(globs)) /*elemType P, Q or R*/ + { + /*If present set the pointer to -1 (0xFFFF) - anything else than NULL, because the + element is present*/ + *(void**) &globs->pstruct[melem[elem].structOffs] = (void *) 0xFFFF; + } + else /*Not present set the pointer to NULL*/ + *(void**) &globs->pstruct[melem[elem].structOffs] = NULL; + + } + } + /* + * For optional elements read the corresponding bit in the preamble + * and set the valid flag in the C-structure to it. + */ + else if (melem[elem].codingType EQ CCDTYPE_ASN1_INTEGER) + { + /* + * Check if this variable has a default value. + * As long as the DEFAULT values are given with ranges it is right to + * look for isDefault in the second entry in mval.cdg. + * There is no valid flag for elements with default value. But we use + * the first byte of this element within the C-structure for giving a + * signal to this function. The only simple type which has DEFAULT is INTEGER. + */ + if (mval[mvar[melem[elem].elemRef].valueDefs+1].isDefault EQ 2) + { + globs->pstruct[melem[elem].structOffs] = (UBYTE) bf_readBit(globs); + } + } + elem++; + } +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_asn1_seq_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the SEQUENCE and SEQUENCE OF type for UMTS + The element can be a field of fixed or variable length. + It can contain OPTIONAL elements or integer elements with + a DEFAULT value. + A special case is when the element is a so called msg_data. + According to CCDDATA a message is made of a msg_type and + a msg_data part. If the msg_data has a coding type of + ASN1_SEQUENCE this function is called. + In this case CCD needs to pass over the msg_type by + incrementing globs->pstruct. A msg_data sequence can not + be optional. Nor it can be an array of msg_data. + If the sequence is not a msg_data this function is called + as an equivalent to ccd_decodeComposition. Hence the + increment on globs->ccd_recurs_level. A non-msg_data + sequence can be optional or an array. +*/ +SHORT cdc_asn1_seq_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat=1, max_rep=1; + ULONG cSize, first_elem, last_elem, elem; + UBYTE *old_pstruct; +#ifdef DEBUG_CCD + static S8 trace_nesting_level = -1; +#endif + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_asn1_seq_decode()"); + #else + TRACE_CCD (globs, "cdc_asn1_seq_decode() %s", mcomp[melem[e_ref].elemRef].name); + #endif +#endif + + /* + * This function is called as an equivalent to ccd_decodeComposition. + * Hence the increment on globs->ccd_recurs_level. + */ + globs->ccd_recurs_level ++; + + /* + * Set pstrcutOffs and max_rep. + * Check the valid flag in case of optional elements. + */ + if (PER_CommonBegin (e_ref, &max_rep, globs) NEQ ccdOK) + { + globs->ccd_recurs_level --; + return 1; + } + + /* + * Prepare for decoding of the same sequence type up to max_rep times. + * Set the upper and lower bound of elemRef for processing of each repeatition. + * Read the C-size to go ahead in the C-structure after each repeatition. + */ + switch (melem[e_ref].elemType) + { + case 'C': + case 'D': + case 'E': + case 'P': + case 'Q': + elem = (ULONG) melem[e_ref].elemRef; + first_elem = (ULONG) mcomp[elem].componentRef; + last_elem = first_elem + mcomp[elem].numOfComponents; + cSize = (ULONG) mcomp[elem].cSize; + break; + case 'F': + case 'R': + first_elem = e_ref; + last_elem = e_ref + 1; + cSize = (ULONG) mvar[e_ref].cSize; + break; + default: + ccd_setError (globs, ERR_DEFECT_CCDDATA, BREAK, + (USHORT) (globs->bitpos), (USHORT) -1); + return 1; + + }; + /* + * Store the current value of the C-structure pointer. + * After decoding the SEQUENCE component we will set the pointer + * to this stored value. Then we will use pstructOffs for pointing + * to the next element. + */ + old_pstruct = globs->pstruct; +#ifdef DYNAMIC_ARRAYS + /* + * Allocate memory for this whole composition, if elemType is + * one of the pointer types. + */ + if ( is_pointer_type(e_ref)) + { + if ( PER_allocmem_and_update(e_ref, max_rep, globs) NEQ ccdOK ) + { + /* No memory - Return. Error already set in function call above. */ + globs->ccd_recurs_level --; + return 1; + } + + } +#endif + globs->pstruct += globs->pstructOffs; + + /* + * Decode all elements of the field. + */ + while (repeat <= max_rep) + { + Read_SEQ_BitMap (first_elem, last_elem, globs); + elem = first_elem; + + /* + * Decode all elements of the array + */ +#ifdef DEBUG_CCD + trace_nesting_level++; +#endif + while (elem < last_elem) + { +#ifdef ERR_TRC_STK_CCD + /* + * Save the value for tracing in error case. + */ + globs->error_stack[globs->ccd_recurs_level] = (USHORT) elem; +#endif /* ERR_TRC_STK_CCD */ + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "decoding level %d element %d", trace_nesting_level, elem - first_elem); + #else + TRACE_CCD (globs, "decoding level %d element %d '%s'",trace_nesting_level, elem - first_elem, ccddata_get_alias((USHORT) elem, 1)); + #endif +#endif + + /* + * Use the jump-table for selecting the decode function. + * Possible types are 0, ASN1_INTEGER, BITSTRING, ASN1_CHOICE and + * ASN1_SEQUENCE. In case of 0 function cdc_STD_decode will be called. + */ + (void) codec[melem[elem].codingType][DECODE_FUN] + (c_ref, elem, globs); + elem ++; + } +#ifdef DEBUG_CCD + trace_nesting_level--; +#endif + + /* + * Set the pointer of the C-structure on the next element. + */ + globs->pstruct += cSize; + + repeat ++; + } + + /* + * Prepare for decoding the next element. + */ + globs->pstruct = old_pstruct; + globs->ccd_recurs_level--; + + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : asn1_seq | +| STATE : code ROUTINE : Write_SEQ_BitMap | ++--------------------------------------------------------------------+ + + PURPOSE : Encode the bit-map preamble for OPTIONAL elements + or those with DEFAULT value. +*/ +void Write_SEQ_BitMap (const ULONG first_elem, const ULONG last_elem, T_CCD_Globs *globs) +{ + ULONG elem = first_elem; + while (elem < last_elem) + { + if (melem[elem].optional) + { + /* + * For optional elements read the valid flag in the C-Structure + * and overwrite the corresponding bit in the preamble. + */ + +#if defined _TOOLS_ + int patch; + U16 stelem; + stelem = globs->error_stack[globs->ccd_recurs_level]; + globs->error_stack[globs->ccd_recurs_level] = (USHORT) elem; + patch = ccd_patch (globs, 1); + globs->error_stack[globs->ccd_recurs_level] = stelem; + if (patch) + { + bf_writeBit(1, globs); + elem++; + continue; + } +#endif /* _TOOLS_ */ + +#ifdef DYNAMIC_ARRAYS + if ( is_pointer_type(elem) ) + { + BOOL present; + /* + * Check for NULL pointer (== notPresent/not valid) for this element. + */ + present = (*(U8 **)(globs->pstruct + melem[elem].structOffs) NEQ NULL); + /* + * Double check for 'D' to 'F' types. Both NULL pointer and + * valid flag. (Strictly not necessary, but may catch uninitialized + * flags/pointers). + */ + if (present AND (melem[elem].elemType >= 'D' AND + melem[elem].elemType <= 'F')) + { + present = (BOOL)globs->pstruct[melem[elem].structOffs]; + } + bf_writeBit(present, globs); + } + else +#endif + bf_writeBit((BOOL)globs->pstruct[melem[elem].structOffs], globs); + } + else if (melem[elem].codingType EQ CCDTYPE_ASN1_INTEGER) + { + /* + * Check if this variable has a default value. + * As long as the DEFAULT values are given with ranges it is right to + * look for isDefault in the second entry in mval.cdg. + * There is no valid flag for elements with default value. So we need + * to read the value from C-structure and compare it with the DEFAULT + * value given in the mval table. The only simple type which has + * DEFAULT is INTEGER. + */ + if (mval[mvar[melem[elem].elemRef].valueDefs+1].isDefault EQ 2) + { + U32 value=0; + UBYTE *p; + /* + * setup the read pointer to the element in the C-structure + */ +#ifdef DYNAMIC_ARRAYS + if ( is_pointer_type(elem) ) + { + /* + * NULL pointers should be caught as part of the optionality + * check in PER_CommonBegin() + */ + p = *(U8 **)(globs->pstruct + globs->pstructOffs); + if (ccd_check_pointer(p) != ccdOK) + { + ccd_recordFault (globs, ERR_INVALID_PTR, BREAK, (USHORT) elem, + &globs->pstruct[globs->pstructOffs]); + return; + } + } + else +#endif + p = globs->pstruct + melem[elem].structOffs; + /* + * Default values are all positive and small values (< 64K) + * in the current version of umts. The cases 'L' and 'C' are added + * to be ready for a future change where we need also a check of + * possible errors through type casting. + */ + switch (mvar[melem[elem].elemRef].cType) + { + case 'B': + value = (U32)*(UBYTE *) p; + break; + case 'C': + value = (U32)(S32)*(S8 *) p; + break; + case 'S': + value = (U32)(*(USHORT *) p); + break; + case 'T': + value = (U32)(S32)*(S16 *) p; + break; + case 'L': + value = (U32)*(S32 *) p; + break; + case 'M': + value = (U32)*(U32 *) p; + break; + default: + ccd_setError (globs, ERR_DEFECT_CCDDATA, BREAK, (USHORT) -1); + break; + } + /* + * Compare the value to be encoded with the default value. + * Write the presence flag into the preamble. + */ + if (value EQ (U32)mval[mvar[melem[elem].elemRef].valueDefs+1].startValue) + { + bf_writeBit(0, globs); + } + else + { + bf_writeBit(1, globs); + } + } + } + elem++; + } +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_asn1_seq_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the SEQUENCE and SEQUENCE OF type for UMTS + The element can be a field of fixed or variable length. + It can contain OPTIONAL elements or integer elements with + a DEFAULT value. + A special case is when the element is a so called msg_data. + According to CCDDATA a message is made of a msg_type and + a msg_data part. If the msg_data has a coding type of + ASN1_SEQUENCE this function is called. + In this case CCD needs to pass over the msg_type by + incrementing globs->pstruct. A msg_data sequence can not + be optional. Nor it can be an array of msg_data. + If the sequence is not a msg_data this function is called + as an equivalent to ccd_encodeComposition. Hence the + increment on globs->ccd_recurs_level. A non-msg_data + sequence can be optional or an array. +*/ +SHORT cdc_asn1_seq_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat=1, max_rep=1; + ULONG cSize, first_elem, last_elem, elem; + UBYTE *old_pstruct; +#ifdef DEBUG_CCD + static S8 trace_nesting_level = -1; +#endif + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_asn1_seq_encode()"); + #else + TRACE_CCD (globs, "cdc_asn1_seq_encode() %s", mcomp[melem[e_ref].elemRef].name); + #endif +#endif + + /* + * This function is called as an equivalent to ccd_encodeComposition. + * Hence the increment on globs->ccd_recurs_level. + */ + globs->ccd_recurs_level ++; + + /* + * Set pstrcutOffs and max_rep. + * Check the valid flag in case of optional elements. + */ + if (PER_CommonBegin (e_ref, &max_rep, globs) NEQ ccdOK) + { + globs->ccd_recurs_level --; + return 1; + } + + /* + * Prepare for encoding of the same sequence type up to max_rep times. + * Set the upper and lower bound of elemRef for processing of each repeatition. + * Read the C-size to go ahead in the C-structure after each repeatition. + */ + switch (melem[e_ref].elemType) + { + case 'C': + case 'D': + case 'E': + case 'P': + case 'Q': + { + elem = (ULONG) melem[e_ref].elemRef; + first_elem = (ULONG) mcomp[elem].componentRef; + last_elem = first_elem + mcomp[elem].numOfComponents; + cSize = (ULONG) mcomp[elem].cSize; + break; + } + case 'F': + case 'R': + { + first_elem = e_ref; + last_elem = e_ref + 1; + cSize = (ULONG) mvar[e_ref].cSize; + break; + } + default: + ccd_setError (globs, ERR_DEFECT_CCDDATA, BREAK, + (USHORT) (globs->bitpos), (USHORT) -1); + return 1; + + } + /* + * Store the current value of the C-structure pointer. + * After encoding the SEQUENCE component we will set the pointer + * to this stored value. Then we will use pstructOffs for pointing + * to the next element. + */ + old_pstruct = globs->pstruct; + globs->pstruct += globs->pstructOffs; + +#ifdef DYNAMIC_ARRAYS + if ( is_pointer_type(e_ref) ) { + if (ccd_check_pointer(*(U8 **)globs->pstruct) == ccdOK) + { + globs->pstruct = *(U8 **) globs->pstruct; + } + else + { + ccd_recordFault (globs, ERR_INVALID_PTR, BREAK, (USHORT) e_ref, + &globs->pstruct[globs->pstructOffs]); + return 1; + } + } +#endif + + + /* + * Encode all elements of the field. + */ + while (repeat <= max_rep) + { + Write_SEQ_BitMap (first_elem, last_elem, globs); + + /* + * Encode all elements + */ +#ifdef DEBUG_CCD + trace_nesting_level++; +#endif + + elem = first_elem; + while (elem < last_elem) + { +#ifdef ERR_TRC_STK_CCD + /* + * Save the value for tracing in error case. + */ + globs->error_stack[globs->ccd_recurs_level] = (USHORT) elem; +#endif /* ERR_TRC_STK_CCD */ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "encoding level %d element %d", trace_nesting_level, elem - first_elem); + #else + TRACE_CCD (globs, "encoding level %d element %d '%s'", trace_nesting_level, elem - first_elem ,ccddata_get_alias((USHORT) elem, 1)); + #endif +#endif + +#if defined _TOOLS_ + if (!ccd_patch (globs, 0)) +#endif /* _TOOLS_ */ + /* + * Use the jump-table for selecting the code function. + * Possible types are 0, ASN1_INTEGER, BITSTRING, ASN1_CHOICE and + * ASN1_SEQUENCE. In case of 0 function cdc_STD_encode will be called. + */ + (void) codec[melem[elem].codingType][ENCODE_FUN] + (c_ref, elem, globs); + /* + * Set the elemRef to the next element. + */ + elem ++; + } +#ifdef DEBUG_CCD + trace_nesting_level--; +#endif + /* + * Set the pointer of the C-structure on the next element. + */ + globs->pstruct += cSize; + + repeat ++; + } + + /* + * Prepare for encoding the next element. + */ + globs->pstruct = old_pstruct; + globs->ccd_recurs_level--; + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/asn1_seq_ext.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,706 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : asn1_seq_ext.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Encoding and decoding functions for ASN1_SEQ_EXTENSIBLE type +| This module has some issues in common with asn1_seq.c. ++----------------------------------------------------------------------------- +*/ + +/* + * Standard definitions like UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes and constants in the common part of ccd + */ +#include "ccd.h" +#include "ccd_codingtypes.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +EXTERN T_FUNC_POINTER codec[MAX_CODEC_ID+1][2]; + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : asn1_seq_ext | +| STATE : code ROUTINE : cdc_asn1_seq_ext_decode | ++------------------------------------------------------------------------+ + + PURPOSE : Decode basic UNALIGNED PER for extensible SEQUENCE type and + SEQUENCE OF. + + The element can be a field of fixed or variable length. + It can contain OPTIONAL elements or integer elements with + a DEFAULT value. The so called nonCriticalExtensions or empty + sequences belong to the category of bit strings of fixed length + which is set to 0. + + First the extension bit is decoded, then the elements of the + extension root. Finally the elements of the extension addition. + See also comments to the encoding function. +*/ + +SHORT cdc_asn1_seq_ext_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat=1, max_rep=1, first_elem, last_elem, elem, ext_begin; + ULONG c_size; + UBYTE *old_pstruct; + BOOL extPresent=FALSE; + ULONG calc_ref = calcidx[melem[e_ref].calcIdxRef].condCalcRef; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_asn1_seq_ext_decode()"); + #else + TRACE_CCD (globs, "cdc_asn1_seq_ext_decode() %s", mcomp[melem[e_ref].elemRef].name); + #endif +#endif + + /* + * This function is called as an equivalent to ccd_decodeComposition. + * Hence the increment on globs->ccd_recurs_level. + */ + globs->ccd_recurs_level ++; + + /* + * Set pstrcutOffs and max_rep. + * Check the valid flag in case of optional elements. + */ + if (PER_CommonBegin (e_ref, &max_rep, globs) NEQ ccdOK) + { + globs->ccd_recurs_level --; + return 1; + } + + /* + * Prepare for decoding of the same sequence type up to max_rep times. + * Set the upper and lower bound of elemRef for processing of each repeatition. + * Read the C-size to go ahead in the C-structure after each repeatition. + */ + switch (melem[e_ref].elemType) + { + case 'C': + case 'D': + case 'E': + case 'P': + case 'Q': + elem = (ULONG) melem[e_ref].elemRef; + first_elem = (ULONG) mcomp[elem].componentRef; + last_elem = first_elem + mcomp[elem].numOfComponents; + c_size = (ULONG) mcomp[elem].cSize; + break; + case 'F': + case 'R': + first_elem = e_ref; + last_elem = e_ref + 1; + c_size = mvar[e_ref].cSize; + break; + default: + ccd_setError (globs, ERR_DEFECT_CCDDATA, BREAK, + (USHORT) (globs->bitpos), (USHORT) -1); + return 1; + + }; + +#ifdef WIN32 + if (calc_ref EQ NO_REF OR calc[calc_ref].operation NEQ 'P') + { + ccd_recordFault (globs, ERR_DEFECT_CCDDATA, BREAK, (USHORT) e_ref, + globs->pstruct+globs->pstructOffs); + return 0; + } +#endif + + /* + * Get max index for elements within the extension root. + */ + ext_begin = (ULONG) calc[calc_ref].operand; + + /* + * Store the current value of the C-structure pointer. + * After decoding the SEQUENCE component we will set the pointer + * to this stored value. Then we will use pstructOffs for pointing + * to the next element. + */ + old_pstruct = globs->pstruct; +#ifdef DYNAMIC_ARRAYS + /* + * Allocate memory for this whole composition, if elemType is + * one of the pointer types. + */ + if ( is_pointer_type(e_ref)) + { + if ( PER_allocmem_and_update(e_ref, max_rep, globs) NEQ ccdOK ) + { + /* No memory - Return. Error already set in function call above. */ + globs->ccd_recurs_level --; + return 1; + } + + } +#endif + globs->pstruct += globs->pstructOffs; + + /* + * Decode all elements of the field for SEQUENCE (SIZE) OF . + */ + while (repeat <= max_rep) + { + /* + * Read the extensinon bit for each array SEQUENCE. + */ + if (bf_readBit (globs) EQ 1) + { + extPresent = TRUE; + } + + /* + * Decode the bit-map preamble for the extension root. + */ + Read_SEQ_BitMap (first_elem, ext_begin, globs); + + + /* + * Decode elements in the extension root for each array SEQUENCE. + */ + for (elem = first_elem; elem < ext_begin; elem++) + { +#ifdef ERR_TRC_STK_CCD + /* + * Save the value for tracing in error case. + */ + globs->error_stack[globs->ccd_recurs_level] = (USHORT) elem; +#endif /* ERR_TRC_STK_CCD */ + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "decoding level %d element %d", globs->ccd_recurs_level, elem - first_elem); + #else + TRACE_CCD (globs, "decoding level %d element %d '%s'",globs->ccd_recurs_level, elem - first_elem, ccddata_get_alias((USHORT) elem, 1)); + #endif +#endif + /* + * Use the jump-table for selecting the decode function. + * Possible types are 0, BITSTRING, ASN1_OCTET, ASN1_INTEGER(_EXTENSIBLE), + * ASN1_CHOICE(_EXTENSIBLE) andASN1_SEQUENCE(_EXTENSIBLE). + * In case of 0 function cdc_STD_decode will be called. + */ + (void) codec[melem[elem].codingType][DECODE_FUN] + (c_ref, elem, globs); + } +/* ############################################### */ + /* + * Decode extension elements if anyone present + */ + if (extPresent) + { + int unknownExt_nr=0; + ULONG bmp_len=0; + + /* + * Read length of bit-map for the encoded extension additions. + */ + bmp_len = Read_NormallySmallNonNegativeWholeNr (globs) + 1; + + /* + * Decode the bit-map for the encoded extension additions. + */ + for (elem = ext_begin; elem < last_elem AND unknownExt_nr < (int)bmp_len; elem++) + { + if (melem[elem].optional) + { + unknownExt_nr++; + if (melem[elem].elemType < 'P' OR melem[elem].elemType > 'R') + { + globs->pstruct[melem[elem].structOffs] = (UBYTE) bf_readBit(globs); + } + else + { + if(bf_readBit(globs)) /*elemType P, Q or R*/ + { + *(void**) &globs->pstruct[melem[elem].structOffs] = (void *) 0xFFFF; + } + else /*Not present set the pointer to NULL*/ + *(void**) &globs->pstruct[melem[elem].structOffs] = NULL; + } + } + else if (melem[elem].codingType EQ CCDTYPE_ASN1_INTEGER) + { + if (mval[mvar[melem[elem].elemRef].valueDefs+1].isDefault EQ 2) + { + unknownExt_nr++; + globs->pstruct[melem[elem].structOffs] = (UBYTE) bf_readBit(globs); + } + } + } + + /* + * Decode the bit-map part for unknown extension additions. + */ + if ((unknownExt_nr = (int) bmp_len - (last_elem - ext_begin)) > 0) + { + UBYTE tmp_bmp_len=0; + while (unknownExt_nr--) + { + if (bf_readBit(globs)) + tmp_bmp_len++; + } + unknownExt_nr = (int)tmp_bmp_len; + } + + /* + * Decode elements in the extension root for each array SEQUENCE + */ + for (elem = ext_begin; elem < last_elem; elem ++) + { + U32 finalBP; +#ifdef ERR_TRC_STK_CCD + /* + * Save the value for tracing in error case. + */ + globs->error_stack[globs->ccd_recurs_level] = (USHORT) elem; +#endif /* ERR_TRC_STK_CCD */ + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "decoding level %d element %d", globs->ccd_recurs_level, elem - first_elem); + #else + TRACE_CCD (globs, "decoding level %d element %d '%s'",globs->ccd_recurs_level, elem - first_elem, ccddata_get_alias((USHORT) elem, 1)); + #endif +#endif + + /* Decode only present extensions. */ + globs->pstructOffs = melem[elem].structOffs; + if ( cdc_isPresent(elem, globs) ) + { + finalBP = 8*Read_OpenTpye_Length (globs); + finalBP += globs->bitpos; + + /* + * Use the jump-table for selecting the decode function. + * Possible types are 0, BITSTRING, ASN1_OCTET, ASN1_INTEGER(_EXTENSIBLE), + * ASN1_CHOICE(_EXTENSIBLE) andASN1_SEQUENCE(_EXTENSIBLE). + * In case of 0 function cdc_STD_decode will be called. + */ + (void) codec[melem[elem].codingType][DECODE_FUN] + (c_ref, elem, globs); + if (globs->bitpos > finalBP) + { + /* ccd_recordFault (globs, ERR_ASN1_ENCODING, BREAK, (USHORT) e_ref, + globs->pstruct+melem[e_ref].structOffs);*/ + } + bf_setBitpos (finalBP, globs); + } + } /* for: SEQUENCE extensions */ + + /* For unknown extensions skip over open type and its length determinant */ + while (unknownExt_nr--) + { + U32 opLen = Read_OpenTpye_Length (globs); + bf_incBitpos (8 * opLen, globs); +#ifdef DEBUG_CCD +TRACE_CCD (globs, "Unknown extension for SEQUENCE type...skipped over %ld bytes", opLen); +#endif + } /*if: unknown extension */ + } /*if: extPresent*/ + + /* + * Set the pointer of the C-structure on the next element. + */ + globs->pstruct += c_size; + + extPresent = FALSE; + repeat ++; + } /* while: SEQUENCE field*/ + + /* + * Prepare for decoding the next element. + */ + globs->pstruct = old_pstruct; + globs->ccd_recurs_level--; + + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : asn1_seq_ext | +| STATE : code ROUTINE : cdc_asn1_seq_ext_encode | ++------------------------------------------------------------------------+ + + PURPOSE : Encode basic UNALIGNED PER for extensible SEQUENCE type and + SEQUENCE OF. + + The element can be a field of fixed or variable length. + It can contain OPTIONAL elements or integer elements with + a DEFAULT value. The so called nonCriticalExtensions or empty + sequences belong to the category of bit strings of fixed length + which is set to 0. + + First the extension bit is encoded, then the elements of the + extension root, finally the elements of the extension addition. + One of the following scenarios is possible: + + ---------------------------------------- + | extension | encoded extension root of | + | bit = 0 | including bitmap preamble | + ---------------------------------------- + ----------------------------------------------------------------------------- +| extension | | encoded | encoded elment | encoded elment | | +| bit = 1 | | bitmap | x of the | y of the | | +| | | including | extension part | extension part | | +| | | its | as an open type | as an open type | ... | +| | | length | including | including | | +| | | | its length | its length | | + ----------------------------------------------------------------------------- + ----------------------------------------------------------------------------- +| extension | encoded | encoded | encoded elment | encoded elment | | +| bit = 1 | extension | bitmap | x of the | y of the | | +| | root | including | extension part | extension part | | +| | including | its | as an open type | as an open type | ... | +| | bitmap | length | including | including | | +| | preamble | | its length | its length | | + ----------------------------------------------------------------------------- +*/ +SHORT cdc_asn1_seq_ext_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat=1, max_rep=1, first_elem, last_elem, elem, ext_begin; + U16 ext_BitPos, ext_bmpLenBP, ext_bmpEndBP; + ULONG c_size, Len; + UBYTE *old_pstruct; + ULONG calc_ref = calcidx[melem[e_ref].calcIdxRef].condCalcRef; + +#ifdef DEBUG_CCD +#ifndef CCD_SYMBOLS +TRACE_CCD (globs, "cdc_asn1_seq_ext_encode()"); +#else +TRACE_CCD (globs, "cdc_asn1_seq_ext_encode() %s", mcomp[melem[e_ref].elemRef].name); +#endif +#endif + + /* + * SEQUENCE contains nested elements. + */ + globs->ccd_recurs_level ++; + + /* + * Set pstrcutOffs and max_rep. + * Check the valid flag in case of optional elements. + */ + if (PER_CommonBegin (e_ref, &max_rep, globs) NEQ ccdOK) + { + globs->ccd_recurs_level --; + return 1; + } + + /* + * Prepare for encoding of the same sequence type up to max_rep times. + * Set the upper and lower bound of elemRef for processing of each repeatition. + * Read the C-size to go ahead in the C-structure after each repeatition. + */ + switch (melem[e_ref].elemType) + { + case 'C': + case 'D': + case 'E': + case 'P': + case 'Q': + { + elem = (ULONG) melem[e_ref].elemRef; + first_elem = (ULONG) mcomp[elem].componentRef; + last_elem = first_elem + mcomp[elem].numOfComponents; + c_size = (ULONG) mcomp[elem].cSize; + break; + } + case 'F': + case 'R': + { + first_elem = e_ref; + last_elem = e_ref + 1; + c_size = mvar[e_ref].cSize; + break; + } + default: + ccd_setError (globs, ERR_DEFECT_CCDDATA, BREAK, + (USHORT) (globs->bitpos), (USHORT) -1); + return 1; + } + /* + * Store the current value of the C-structure pointer. + * After encoding the SEQUENCE component we will set the pointer + * to this stored value. Then we will use pstructOffs for pointing + * to the next element. + */ + old_pstruct = globs->pstruct; + globs->pstruct += globs->pstructOffs; + +#ifdef DYNAMIC_ARRAYS + if ( is_pointer_type(e_ref) ) { + if ( ccd_check_pointer(*(U8 **)globs->pstruct) == ccdOK ) + globs->pstruct = *(U8 **) globs->pstruct; + else + { + ccd_recordFault (globs, ERR_INVALID_PTR, BREAK, (USHORT) e_ref, + &globs->pstruct[globs->pstructOffs]); + return 1; + } + } +#endif + +#ifdef WIN32 + if (calc_ref EQ NO_REF OR calc[calc_ref].operation NEQ 'P') + { + ccd_recordFault (globs, ERR_DEFECT_CCDDATA, BREAK, (USHORT) e_ref, + globs->pstruct+globs->pstructOffs); + return 0; + } +#endif + + /* + * Get max index for elements within the extension root. + */ + ext_begin = (ULONG) calc[calc_ref].operand; + + /* + * Decode all elements of the field for SEQUENCE (SIZE) OF. + */ + while (repeat <= max_rep) + { + /* + * Prepare for a later encoding of the extension bit. + */ + ext_BitPos = globs->bitpos; + bf_incBitpos (1, globs); + + /* + * Encode the bit-map preamble for elements with the extension root. + */ + Write_SEQ_BitMap (first_elem, ext_begin, globs); + + /* + * Encode present elements of the extension root. + */ + for (elem = first_elem; elem < ext_begin; elem++) + { +#ifdef ERR_TRC_STK_CCD + /* + * Save the value for tracing in error case. + */ + globs->error_stack[globs->ccd_recurs_level] = (USHORT) elem; +#endif /* ERR_TRC_STK_CCD */ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "encoding level %d element %d", globs->ccd_recurs_level, elem - first_elem); + #else + TRACE_CCD (globs, "encoding level %d element %d '%s'", globs->ccd_recurs_level, elem - first_elem ,ccddata_get_alias((USHORT) elem, 1)); + #endif +#endif + +#if defined _TOOLS_ + if (!ccd_patch (globs, 0)) +#endif /* _TOOLS_ */ + /* + * Use the jump-table for selecting the code function. + * Possible types are 0, ASN1_INTEGER, BITSTRING, ASN1_CHOICE and + * ASN1_SEQUENCE. In case of 0 function cdc_STD_encode will be called. + */ + (void) codec[melem[elem].codingType][ENCODE_FUN] + (c_ref, elem, globs); + } + + ext_bmpLenBP = globs->bitpos; + /* + * Set the extension bit to 0, if extension part is empty. + */ + if (ext_begin EQ last_elem) + { + bf_setBitpos (ext_BitPos, globs); + bf_writeBit (0, globs); + bf_setBitpos (ext_bmpLenBP, globs); + } + else + { + /* + * Prepare for a later encoding of the bitmap length. + */ + + bf_incBitpos (7, globs); + + /* + * Write the bitmap preamble for the extension part. + */ + Write_SEQ_BitMap (ext_begin, last_elem, globs); + ext_bmpEndBP = globs->bitpos; + Len = last_elem - ext_begin; // equivalent to: globs->bitpos - ext_bmpLenBP -7; + + /* Check any of the extension elements is present. */ + bf_setBitpos (ext_bmpLenBP+7, globs); + if (bf_getBits (Len, globs) EQ 0) + { /* Hint: the following two lines can be deleted because of ccd general memset. */ + bf_setBitpos (ext_BitPos, globs); + bf_writeBit (0, globs); + bf_setBitpos (ext_bmpLenBP, globs); + } + else + { + /* + * Write the extension bit. + */ + bf_setBitpos (ext_BitPos, globs); + bf_writeBit (1, globs); + + /* + * Write the bitmap length assuming small bitmaps as common case. + * Lower bound of the length is 1. + / + if (Len < 64) + { */ + bf_setBitpos (ext_bmpLenBP, globs); + Write_NormallySmallNonNegativeWholeNr (Len-1, globs); + bf_setBitpos (ext_bmpEndBP, globs); + /* + } else + { + encode_bmp_len_as_NormallySmallNonNegativeWholeNr (...); + shift_the_bitStr (...); + }*/ + + /* + * Encode present elements of the extension part. + */ + for (elem = ext_begin; elem < last_elem; elem++) + { + U16 startBitPos, endBitPos; +#ifdef ERR_TRC_STK_CCD + /* + * Save the value for tracing in error case. + */ + globs->error_stack[globs->ccd_recurs_level] = (USHORT) elem; +#endif /* ERR_TRC_STK_CCD */ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS +TRACE_CCD (globs, "encoding level %d element %d", globs->ccd_recurs_level, elem - first_elem); + #else +TRACE_CCD (globs, "encoding level %d element %d '%s'", globs->ccd_recurs_level, elem - first_elem ,ccddata_get_alias((USHORT) elem, 1)); + #endif +#endif + /* Decode only present extensions. */ + globs->pstructOffs = melem[elem].structOffs; + if ( cdc_isPresent(elem, globs) ) + { + /* + * Prepare for a later encoding of the length for each open type + */ + bf_incBitpos (8, globs); + startBitPos = globs->bitpos; + +#if defined _TOOLS_ + if (!ccd_patch (globs, 0)) +#endif /* _TOOLS_ */ + + /* + * Use the jump-table for selecting the code function. + * Possible types are 0, ASN1_INTEGER, BITSTRING, ASN1_CHOICE and + * ASN1_SEQUENCE. In case of 0 function cdc_STD_encode will be called. + */ + (void) codec[melem[elem].codingType][ENCODE_FUN] + (c_ref, elem, globs); + + /* + * Complete open type encoding. Check if zero padding bits + * are necessary. If encoding consumed no bits, insert a + * zero-octet in the bit string. + * Then calculate length of the encoded open type in octets. + */ + if ((Len = globs->bitpos - startBitPos) EQ 0) + { + bf_writeVal (0, 8, globs); + Len = 1; + } + else + { + if ((Len&7) NEQ 0) + bf_incBitpos (8 - (Len&7), globs); + Len = (U32)(globs->bitpos - startBitPos) >> 3; + } + + endBitPos = globs->bitpos; + + /* + * Encode the length determinant. + */ + if (Len < 128) + { + bf_setBitpos (startBitPos-8, globs); + Write_OpenTpye_Length ((U32)Len, globs); + } + /* + * This case does not seem to happen very often. + * We could let an error report lead us to the need for total implementation. + */ + else + { + /*ccd_recordFault (globs, ERR_ASN1_ENCODING, BREAK,(USHORT) e_ref, + globs->pstruct+globs->pstructOffs);*/ + } + /* + * Encoding for the sequence sub element is finished. For further encoding + * set the bit position pointer to the end of the encoded open type. + */ + bf_setBitpos (endBitPos, globs); + } + } + }/* if ext present or not */ + } /* if any extension defined or not*/ + + /* + * Set the pointer of the C-structure on the next element. + */ + globs->pstruct += c_size; + + repeat ++; + } /* while: SEQUENCE field*/ + + /* + * Prepare for encoding the next element. + */ + globs->pstruct = old_pstruct; + globs->ccd_recurs_level--; + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/bcd_mnc.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,361 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : bcd_mnc.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for BCD_MNC elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_bcd_mnc_decode | ++--------------------------------------------------------------------+ + + PURPOSE : decoding a byte array, that contains a Mobile Network Code, + from the bitstream: + + MSBit LSBit + 7 8 6 5 4 3 2 1 + DIGIT_3 XXXXXXX Octett n-1 + DIGIT_2 DIGIT_1 Octett n + + The current decoding position is expected after Octett n-1 + The byte array should be of dimension [2..3] (preferred) + or [3] or [2] (also supported) + +*/ + + +SHORT cdc_bcd_mnc_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat, max_rep; + BOOL is_variable; + UBYTE digBuffer[3]; + UBYTE *addr_c_xxx; + ULONG i; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + register UBYTE *digits; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_bcd_mnc_decode()"); + #else + TRACE_CCD (globs, "cdc_bcd_mnc_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * if this element is conditional, check the condition + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + /* + * if this element have a defined Prolog + * we have to process it before decoding the bitstream + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + /* + * if this element is repeatable, and the number of + * repeats depends on another element, calculate the repeater + */ + if (melem[e_ref].repType NEQ ' ') + { + is_variable = ccd_calculateRep (e_ref, &repeat, &max_rep, globs); + } + else + { + repeat = 1; + is_variable = FALSE; + } + + /* + * setup the offset into the C-structure for this element + */ + globs->pstructOffs = melem[e_ref].structOffs; + + if (melem[e_ref].optional) + { + /* + * for optional elements set the valid-flag + */ + globs->pstruct[globs->pstructOffs++] = (UBYTE) TRUE; + } + + if (is_variable) + { + if (max_rep < 2 OR max_rep > 3) + { + ccd_setError (globs, ERR_INVALID_TYPE, BREAK, (USHORT) (globs->bitpos), + (USHORT) -1); + } + /* + * for variable sized elements store the min-value + * as counter into the C-Structure (c_xxx). + */ + addr_c_xxx = (UBYTE *) (globs->pstruct + globs->pstructOffs++); + if (max_rep > 255) + globs->pstructOffs++; + } + else + addr_c_xxx = NULL; + + digits = (UBYTE *) (globs->pstruct + globs->pstructOffs); + + bf_setBitpos ((globs->bitpos - 8), globs); + + /* + * read the BCD digits out of the bitstream. + * The read order is 3,X,2,1 + */ + digBuffer[2] = bf_decodeByteNumber (4, globs); + bf_incBitpos (4, globs); + + digBuffer[1] = bf_decodeByteNumber (4, globs); + digBuffer[0] = bf_decodeByteNumber (4, globs); + + if (addr_c_xxx NEQ NULL) + { + /* + * store the number of digits into the + * c_xxx variable if there is one. + */ + repeat = (ULONG) ((digBuffer[2] EQ 0x0f) ? 2 : 3); + if (max_rep > 65535) + { + ULONG *addr_c_xxx_u32; + addr_c_xxx_u32 = (ULONG *)addr_c_xxx; + *addr_c_xxx_u32 = repeat; + } + else if (max_rep > 255) + { + USHORT *addr_c_xxx_u16; + addr_c_xxx_u16 = (USHORT *)addr_c_xxx; + *addr_c_xxx_u16 = (USHORT) repeat; + } + else + *addr_c_xxx = (UBYTE) repeat; + } + else + { + if (max_rep EQ 2 AND digBuffer[2] NEQ 0xf) + ccd_setError (globs, ERR_PATTERN_MISMATCH, + CONTINUE, + (USHORT) (globs->bitpos-16), + (USHORT) -1); + + repeat = max_rep; + } + /* + * store the digits into the C-Structure variable + */ + for (i=0; i<repeat; i++) + digits[i] = digBuffer[i]; + + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_bcd_mnc_encode | ++--------------------------------------------------------------------+ + + PURPOSE : encoding a byte array, that contains a Mobile Network Code, + into the bitstream: + + MSBit LSBit + 7 8 6 5 4 3 2 1 + DIGIT_3 XXXXXXX Octett n-1 + DIGIT_2 DIGIT_1 Octett n + + The current coding position is expected after Octett n-1 +*/ + + +SHORT cdc_bcd_mnc_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat; + UBYTE dig3; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + register UBYTE *digits; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_bcd_mnc_encode()"); + #else + TRACE_CCD (globs, "cdc_bcd_mnc_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * if this element is conditional, check the condition + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + /* + * if this element have a defined Prolog + * we have to process it before decoding the bitstream + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + /* + * setup the offset into the C-structure for this element + */ + globs->pstructOffs = melem[e_ref].structOffs; + + if (melem[e_ref].optional) + { + /* + * for optional elements check the valid-flag + */ + if (globs->pstruct[globs->pstructOffs++] == FALSE) + { + return 1; + } +#ifdef DEBUG_CCD + else if (globs->pstruct [melem[e_ref].structOffs] != TRUE) + { + TRACE_CCD (globs, "Ambiguous value for valid flag!\n...assumed 1 for ccdID=%d", + e_ref); + } +#endif + } + + /* + * if this element is repeatable, and the number of + * repeats depends on another element, calculate the repeater + */ + if (melem[e_ref].repType EQ 'v' OR melem[e_ref].repType EQ 'i') + { + /* + * for variable sized elements read the amount + * of repeats out of the C-Structure (c_xxx). + * If the number of repeats given by the C-Structure + * exceeds the allowed value (max_repeat) CCD gives a warning! + */ + if (melem[e_ref].maxRepeat > 255) + { + ULONG count = (ULONG) (* (USHORT *)(globs->pstruct + globs->pstructOffs++)); + repeat = MINIMUM (count, (ULONG)melem[e_ref].maxRepeat); + if (repeat < count) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + else + { + repeat = (ULONG) MINIMUM (globs->pstruct[globs->pstructOffs], + melem[e_ref].maxRepeat); + if ( repeat < (ULONG) (globs->pstruct[globs->pstructOffs]) ) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + + globs->pstructOffs++; + } + else + if (melem[e_ref].repType EQ 'c') + repeat = (ULONG) melem[e_ref].maxRepeat; + else + repeat = 1; + + /* + * setup the read pointer to the byte array that contain + * the BCD number. + */ + digits = (UBYTE *) (globs->pstruct + globs->pstructOffs); + + if (repeat EQ 2) + dig3 = 0x0f; + else if (repeat EQ 3) + dig3 = digits[2]; + else + { + ccd_setError (globs, ERR_INVALID_TYPE, + BREAK, + (USHORT) (globs->bitpos), + (USHORT) -1); + return 1; + } + + bf_setBitpos ((globs->bitpos-8), globs); + bf_codeByteNumber (4, dig3, globs); + bf_incBitpos (4, globs); + bf_codeByteNumber (4, digits[1], globs); + bf_codeByteNumber (4, digits[0], globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "skipping back 8 bits"); + TRACE_CCD (globs, "BCD digit (%X) written", (USHORT) dig3); + TRACE_CCD (globs, "skipping 4 bits"); + TRACE_CCD (globs, "BCD digit (%X) written", (USHORT) digits[1]); + TRACE_CCD (globs, "BCD digit (%X) written", (USHORT) digits[0]); +#endif + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/bcd_nofill.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,102 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : bcd_nofill.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for BCD_NOFILL elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_bcd_nofill_decode | ++--------------------------------------------------------------------+ + + PURPOSE : + +*/ + + +SHORT cdc_bcd_nofill_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_bcd_nofill_decode()"); + #else + TRACE_CCD (globs, "cdc_bcd_nofill_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + cdc_BCD_decode (e_ref, 2, globs); + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_bcd_nofill_encode | ++--------------------------------------------------------------------+ + + PURPOSE : encoding a Bytearray, that contain a BCD Number, into + the bitstream. without the filling nibble +*/ + + +SHORT cdc_bcd_nofill_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_bcd_nofill_encode()"); + #else + TRACE_CCD (globs, "cdc_bcd_nofill_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + cdc_BCD_encode (e_ref, 2, globs); + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/bcdeven.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,102 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : bcdeven.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for BCDEVEN elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_bcdeven_decode | ++--------------------------------------------------------------------+ + + PURPOSE : + +*/ + + +SHORT cdc_bcdeven_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_bcdeven_decode()"); + #else + TRACE_CCD (globs, "cdc_bcdeven_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + cdc_BCD_decode (e_ref, 0, globs); + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_bcdeven_encode | ++--------------------------------------------------------------------+ + + PURPOSE : encoding a Bytearray, that contain a BCD Number, into + the bitstream. +*/ + + +SHORT cdc_bcdeven_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_bcdeven_encode()"); + #else + TRACE_CCD (globs, "cdc_bcdeven_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + cdc_BCD_encode (e_ref, 0, globs); + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/bcdodd.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,101 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : bcdodd.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for BCDODD elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_bcdodd_decode | ++--------------------------------------------------------------------+ + + PURPOSE : + +*/ + +SHORT cdc_bcdodd_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_bcdodd_decode()"); + #else + TRACE_CCD (globs, "cdc_bcdodd_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + cdc_BCD_decode (e_ref, 1, globs); + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_bcdodd_encode | ++--------------------------------------------------------------------+ + + PURPOSE : encoding a Bytearray, that contain a BCD Number, into + the bitstream. +*/ + + +SHORT cdc_bcdodd_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_bcdodd_encode()"); + #else + TRACE_CCD (globs, "cdc_bcdodd_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + cdc_BCD_encode (e_ref, 1, globs); + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/bitfun.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,1649 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : bitfun.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of constants, types and global variables and bit +| stream manipulation functions for CCD ++----------------------------------------------------------------------------- +*/ + +#define __BITFUN_C__ + + + +#ifdef DEBUG_CCD +#include <stdio.h> +#endif + +#include "typedefs.h" +#include "header.h" + +#include "string.h" +#include "ccd_globs.h" +#include "bitfun.h" +#include "ccd.h" + + +EXTERN int abs(int); + +#ifndef RUN_FLASH +/* + * For each bitlength between 0 and 32 this table contains the + * valid masks for right-justificated values + */ + +const ULONG ccd_bitfun_mask[] = +{ + 0x00000000, + 0x00000001, 0x00000003, 0x00000007, 0x0000000f, + 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, + 0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff, + 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff, + 0x0001ffff, 0x0003ffff, 0x0007ffff, 0x000fffff, + 0x001fffff, 0x003fffff, 0x007fffff, 0x00ffffff, + 0x01ffffff, 0x03ffffff, 0x07ffffff, 0x0fffffff, + 0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff +}; + +/* + * Table of one-bit values (2^X) + */ + +const UBYTE ccd_bitfun_shift[] = +{ + 128, 64, 32, 16, 8, 4, 2, 1 +}; +#else +extern const ULONG ccd_bitfun_mask[]; +extern const UBYTE ccd_bitfun_shift[]; +#endif + +/* + * maschine-dependent implementation + * define M_INTEL or M_MOTOROLA dependend on the target system + */ + +#ifdef M_INTEL +#define MSB_POS 1 +#define LSB_POS 0 +#define MSW_POS 2 +#define LSW_POS 0 +#else +#ifdef M_MOTOROLA +#define MSB_POS 0 +#define LSB_POS 1 +#define MSW_POS 0 +#define LSW_POS 2 +#endif +#endif + + +typedef union +{ /* Conversion structure */ + UBYTE c[2]; /* 2 bytes <-> USHORT */ + USHORT s; +} +t_conv16; + +typedef union +{ /* Conversion structure */ + UBYTE c[4]; /* 4 Byte <-> ULONG */ + ULONG l; +} +t_conv32; + +#ifndef RUN_FLASH +#ifdef DEBUG_CCD +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : ccd_BITIMAGE | ++--------------------------------------------------------------------+ + + PURPOSE : convert a ULONG value to a ascii-bitstring with the + length len. +*/ + + +char *ccd_BITIMAGE (ULONG val, ULONG len, T_CCD_Globs *globs) +{ + + int i; + for (i=31; i >= 0; i--) + { + globs->buf [i] = (char)(val & 1)+'0'; + val >>= 1; + } + globs->buf [32] = '\0'; + + return globs->buf+(32-len); +} + +#endif +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : fmemcpy | ++--------------------------------------------------------------------+ + + PURPOSE : copies len bytes from source to dest + for FAR addresses. +*/ + +void fmemcpy (UBYTE * d, UBYTE *s, USHORT len) +{ + while (len--) + *d++ = *s++; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_writeBitChunk | ++--------------------------------------------------------------------+ + + PURPOSE : The global pointer globs->pstruct+globs->pstructOffs references + a buffer struct containing the len, offset and content + of a bitbuffer. This funtions copies the bits to the + bitstream buffer at the actual position. +*/ + +void bf_writeBitChunk (ULONG len, T_CCD_Globs *globs) +{ + ULONG offs; + ULONG bytesToCopy=0; + signed char theShift; + U8 *MsgStruct = (U8*)(globs->pstruct + globs->pstructOffs); + U8 ByteOffs = globs->byteoffs; + U8 *MsgBuf = (U8*)(globs->bitbuf + globs->bytepos); + + /* + * Read the length of the buffer (the l_buf component) and + * compare it with the parameter given. + */ + len = MINIMUM (len, *((USHORT *)MsgStruct)); + if (!len) + return; + bytesToCopy = (ULONG) ((len + ByteOffs + 7)>> 3); + offs = (ULONG)(*(USHORT *)(MsgStruct + 2)); + theShift = (signed char) (offs - ByteOffs); + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "reading 2+2+%ld bytes from struct %08X, writing %d bits at byte %d.%d", + bytesToCopy, MsgStruct + 4, len, globs->bytepos, globs->byteoffs); +#endif + + if ((abs(theShift) & 7) EQ 0) + { + MsgStruct += (4+(offs>>3)); + /* + * the bits in the Buffer are in the right position + * -> quick memcopy. + */ + /* + * write the first byte, clean the leading bits + */ + *MsgBuf |= (*MsgStruct & (UBYTE) ccd_bitfun_mask[8 - (offs&7)]); + /* + * copy the remaining bytes + */ + if (bytesToCopy) + { + memcpy ((UBYTE *) &MsgBuf[1], + MsgStruct + 1, + (size_t)bytesToCopy-1); + } + if ((ByteOffs+len)&7) + { + MsgBuf[bytesToCopy-1] &= ~ccd_bitfun_mask[8-((ByteOffs+len)&7)]; + } + } + else + { + t_conv16 conv; + /* + * shift every single byte + */ + MsgStruct += (4+(offs>>3)); + if (bytesToCopy > 1) + { + --bytesToCopy; + } + if (theShift > 0) + { + /* + * shift all bytes leftwise + */ + /* + * the first byte must be masked + */ + theShift &= 7; + conv.c[MSB_POS] = *MsgStruct++ & (UBYTE) ccd_bitfun_mask[8-(offs&7)]; + conv.c[LSB_POS] = *MsgStruct; + conv.s <<= theShift; + *MsgBuf++ |= conv.c[MSB_POS]; + *MsgBuf = conv.c[LSB_POS]; + --bytesToCopy; + + while (bytesToCopy) + { + conv.c[MSB_POS] = *MsgStruct++; + conv.c[LSB_POS] = *MsgStruct; + conv.s <<= theShift; + *MsgBuf++ |= conv.c[MSB_POS]; + *MsgBuf = conv.c[LSB_POS]; + --bytesToCopy; + } + + conv.c[MSB_POS] = *MsgStruct++; + conv.c[LSB_POS] = *MsgStruct; + conv.s <<= theShift; + *MsgBuf |= conv.c[MSB_POS]; + + if ((ByteOffs+len)&7) + { + *MsgBuf &= ~ccd_bitfun_mask[8-((ByteOffs+len)&7)]; + } + } + else + { + /* + * shift all bytes rightwise + */ + /* + * the first byte must be masked, we dont want to store the + * leading garbage before the valid bits + */ + theShift = (-theShift & 7); + conv.c[MSB_POS] = *MsgStruct++ & (UBYTE) ccd_bitfun_mask[8-(offs&7)]; + conv.c[LSB_POS] = *MsgStruct; + conv.s >>= theShift; + *MsgBuf++ |= conv.c[MSB_POS]; + *MsgBuf = conv.c[LSB_POS]; + --bytesToCopy; + + while (bytesToCopy) + { + conv.c[MSB_POS] = *MsgStruct++; + conv.c[LSB_POS] = *MsgStruct; + conv.s >>= theShift; + *MsgBuf++ |= conv.c[MSB_POS]; + *MsgBuf = conv.c[LSB_POS]; + --bytesToCopy; + } + + conv.c[MSB_POS] = *MsgStruct++; + conv.c[LSB_POS] = *MsgStruct; + conv.s >>= theShift; + *MsgBuf |= conv.c[MSB_POS]; + + if ((ByteOffs+len)&7) + { + *MsgBuf &= ~ccd_bitfun_mask[8-((ByteOffs+len)&7)]; + } + } + } + bf_incBitpos (len, globs); + globs->pstructOffs = MsgStruct - globs->pstruct - 1; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_writeBits | ++--------------------------------------------------------------------+ + + PURPOSE : The pointer globs->pstruct + globs->pstructOffs refers to + a var in the message C-structure. This function writes the + numeric content of the var into the bit stream referenced + by globs->bitbuf. According to the required lenght + (len) the type of the var is interpreted as BYTE/SHORT + or LONG. +*/ + +void bf_writeBits (ULONG len, T_CCD_Globs *globs) +{ + /* + * Bit field is given by its lenght, offset bit and buffer. + */ + if (len > 32) + { + bf_writeBitChunk (len, globs); + return; + } + else + { + UBYTE *MsgStruct = (UBYTE*)(globs->pstruct + globs->pstructOffs); + U8 ByteOffs = globs->byteoffs; + UBYTE *MsgBuf = (UBYTE*)(globs->bitbuf + globs->bytepos); + U32 wBits; + + wBits = len + ByteOffs; + + if (len > 24) + { + t_conv32 conv32; + UBYTE FirstByte; + + conv32.l = *((ULONG *) MsgStruct); + conv32.l &= (ULONG) ccd_bitfun_mask[len]; + conv32.l <<= (32-len); + + FirstByte = conv32.c[MSW_POS + MSB_POS]; + FirstByte >>= ByteOffs; + FirstByte &= (UBYTE) ccd_bitfun_mask[8-ByteOffs]; + *MsgBuf++ |= FirstByte; + + conv32.l <<= (8-ByteOffs); + + *MsgBuf++ = conv32.c[MSW_POS + MSB_POS] ; + *MsgBuf++ = conv32.c[MSW_POS + LSB_POS] ; + *MsgBuf++ = conv32.c[LSW_POS + MSB_POS] ; + + if (wBits > 32) + *MsgBuf = conv32.c[LSW_POS + LSB_POS] ; + } + /* + * Bit field given in a C variable is shorter than a USHORT. + */ +#ifdef DEBUG_CCD + TRACE_CCD (globs, "write %d bits at byte %d.%d", len, globs->bytepos, ByteOffs); +#endif + if (len > 8) + { + t_conv32 conv; + + conv.l = (len > 16) ? *(ULONG *) MsgStruct + : (ULONG) * (USHORT *) MsgStruct; + conv.l &= ccd_bitfun_mask[len]; +#ifdef DEBUG_CCD + TRACE_CCD (globs, " (.%s)", ccd_BITIMAGE (conv.l, len, globs)); +#endif + conv.l <<= (32 - wBits); + *MsgBuf |= conv.c[MSW_POS + MSB_POS]; + MsgBuf[1] |= conv.c[MSW_POS + LSB_POS]; + if (wBits > 16) + { + MsgBuf[2] |= conv.c[LSW_POS + MSB_POS]; + if (wBits > 24) + { + MsgBuf[3] |= conv.c[LSW_POS + LSB_POS]; + } + } + } + else + { + t_conv16 conv; + + conv.s = (USHORT) (*MsgStruct); + conv.s &= (USHORT) ccd_bitfun_mask[len]; +#ifdef DEBUG_CCD + TRACE_CCD (globs, " (.%s)", ccd_BITIMAGE ((ULONG) conv.s, len, globs)); +#endif + conv.s <<= (16 - wBits); + *MsgBuf |= conv.c[MSB_POS]; + + if (wBits > 8) + { + MsgBuf[1] |= conv.c[LSB_POS]; + } + } + bf_incBitpos (len, globs); + } +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_writeBitStr_PER | ++--------------------------------------------------------------------+ + + PURPOSE : The pointer globs->pstruct + globs->pstructOffs refers to + a var in the message C-structure. This function writes the + numeric content of the var into the bit stream referenced + by globs->bitbuf. +*/ + +void bf_writeBitStr_PER (USHORT len, T_CCD_Globs *globs) +{ + USHORT bytesToCopy; + t_conv16 Last2Bytes; + U8 *MsgStruct = (U8*)(globs->pstruct + globs->pstructOffs); + U8 ByteOffs = globs->byteoffs; + U8 *MsgBuf; + MsgBuf = (U8*)(globs->bitbuf + globs->bytepos + ((ByteOffs + len) >> 3)); + /* + * Store the data for a later compensation of buffer overwritting. + * bytepos is always greater than 1, since the first byte with bytepos=0 + * is dedicated to message identifier. + */ + Last2Bytes.c[MSB_POS] = MsgBuf[0]; + Last2Bytes.c[LSB_POS] = MsgBuf[1]; + + MsgBuf -= (ByteOffs + len) >> 3; + bytesToCopy = (len+7) >> 3; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "copying %d byte(s) from struct 0x%08X, writing %d bits at byte %d.%d", + bytesToCopy, MsgStruct, len, globs->bytepos, globs->byteoffs); + { + int i=0; + int j=0; + char s[64], c[4]; + int leftBytes = bytesToCopy; + + TRACE_CCD (globs, " Bit string to be encoded:"); + + s[0] = '\0'; + for (i = 0; leftBytes > 0 ; i++) + { + for (j = 0; (j < 16 && (leftBytes-- > 0)) ; j++) + { + sprintf(c, " %02x", *(MsgStruct+(16*i)+j)); + strcat (s, c); + } + TRACE_CCD (globs, "%s", s); + s[0] = '\0'; + } + } +#endif + + /* + * The bits will be appended to the bit buffer at byte boundary. + */ + if (ByteOffs EQ 0) + { + /* + * CCD assumes that the bits to be copied are left adjusted + * int their place in the C-structure. + */ + memcpy ((UBYTE *) MsgBuf, + MsgStruct, + (size_t)bytesToCopy); + MsgBuf += bytesToCopy; + } + else + { + t_conv16 conv; + + /* + * Write byte for byte while compensating non-zero value of globs->byteoffs. + */ + while (bytesToCopy--) + { + conv.c[MSB_POS] = *MsgStruct++; + conv.c[LSB_POS] = *MsgStruct; + conv.s >>= ByteOffs; + conv.s &= (USHORT) ccd_bitfun_mask[16-ByteOffs]; + *MsgBuf++ |= conv.c[MSB_POS]; + *MsgBuf |= conv.c[LSB_POS]; + } + } + + bf_incBitpos (len, globs); + + /* + * Undo overwriting of bits which do not belong to the bit string. + */ + MsgBuf = (U8*)(globs->bitbuf + globs->bytepos); + MsgBuf[0] &= ~ccd_bitfun_mask[8-globs->byteoffs]; + Last2Bytes.c[MSB_POS] &= (UBYTE) ccd_bitfun_mask[8-globs->byteoffs]; + MsgBuf[0] |= Last2Bytes.c[MSB_POS]; + MsgBuf[1] = Last2Bytes.c[LSB_POS]; + +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_writePadBits | ++--------------------------------------------------------------------+ + + PURPOSE : The global pointer globs->bitbuf points to the bit stream + buffer. This function adds 0-7 zero bits to the bit stream + from the point globs->byteoffs refer to. +*/ + +void bf_writePadBits (T_CCD_Globs *globs) +{ + if (globs->byteoffs NEQ 0) + { + globs->bitbuf[globs->bytepos] &= + (UBYTE) ~ccd_bitfun_mask[8-globs->byteoffs]; +#ifdef DEBUG_CCD + TRACE_CCD (globs, "writing %d pad bit(s) at byte %d.%d", + 8-globs->byteoffs, globs->bytepos, globs->byteoffs); +#endif + + bf_incBitpos (8-globs->byteoffs, globs); + } +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_readBit | ++--------------------------------------------------------------------+ + + PURPOSE : The global pointer globs->bitbuf points to the bit stream + buffer. This function reads the bit to which the global + positioning pointers are pointing to. +*/ + +BOOL bf_readBit (T_CCD_Globs *globs) +{ + UBYTE ret; + + ret = globs->bitbuf[globs->bytepos] & ccd_bitfun_shift[globs->byteoffs]; + bf_incBitpos (1, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "reading 1 bit (%d) at byte %d.%d", (ret>0)?1:0, globs->bytepos, globs->byteoffs); +#endif + + return (ret > 0); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_writeBit | ++--------------------------------------------------------------------+ + + PURPOSE : The global pointer globs->bitbuf points to the bit stream + buffer. This function writes a given value into the bit + to which the global positioning pointers are pointing to. +*/ + +void bf_writeBit (BOOL Bit, T_CCD_Globs *globs) +{ + globs->bitbuf[globs->bytepos] = Bit ? (globs->bitbuf[globs->bytepos] | + ccd_bitfun_shift[globs->byteoffs]) + : (globs->bitbuf[globs->bytepos] & ~ccd_bitfun_shift[globs->byteoffs]); + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "writing 1 bit (%d) at byte %d.%d", Bit, globs->bytepos, globs->byteoffs); +#endif + + bf_incBitpos (1, globs); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_rShift8Bit | ++--------------------------------------------------------------------+ + + PURPOSE : shifts a bitfield in the bitstream by 8 bits rightwise. + The function is used only for octet aligned types. + Hence offset is not involved in calculation. +*/ +void bf_rShift8Bit + ( + USHORT srcBitPos, + USHORT bitLen, + T_CCD_Globs *globs + ) +{ + register UBYTE bytesToCopy; + USHORT bytepos; + + /* + * destination > source -> start with last byte + */ + bytepos = srcBitPos >> 3; + bytesToCopy = bitLen >> 3; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "shifting %d bits rightwise for 8 bits", bitLen); +#endif + + while (bytesToCopy) + { + globs->bitbuf[bytepos+bytesToCopy] = globs->bitbuf[bytepos+bytesToCopy-1]; + bytesToCopy--; + } + globs->bitbuf[bytepos] = 0; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_readBitChunk | ++--------------------------------------------------------------------+ + + PURPOSE : reads (len) Bits from the Bitsream (globs->bitbuf) and + stores them to the T_MSGBUF struct, containig the len + the offset and a bitbuffer. +*/ + +void bf_readBitChunk (ULONG len, T_CCD_Globs *globs) +{ + ULONG bytesToCopy; + U8 *MsgStruct = (U8*)(globs->pstruct + globs->pstructOffs); + U8 ByteOffs = globs->byteoffs; + U8 *MsgBuf = (U8*)(globs->bitbuf + globs->bytepos); + + *(U16*) (MsgStruct) = (U16) len; + MsgStruct += 2; + *(U16*) (MsgStruct) = (U16)ByteOffs; + MsgStruct += 2; + bytesToCopy = (ULONG) ((len >> 3)+(len&7?1:0)+(ByteOffs?1:0)); + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "reading %ld bits from byte %d.%d, writing 2+2+%ld bytes to struct %08X", + len, globs->bytepos, globs->byteoffs, bytesToCopy, MsgStruct); +#endif + memcpy ((UBYTE *) MsgStruct, + MsgBuf, + (size_t)bytesToCopy); + +#if 0 +#ifdef DEBUG_CCD + { + int i; + for (i=0; i<bytesToCopy; i++) + { + TRACE_CCD (globs, "buf[%d] = 0x%02x", i, MsgStruct[i]); + } + } +#endif +#endif + /* + * cutoff the leading and trailing bits wich are obsolete + */ + *MsgStruct &= ccd_bitfun_mask [8-ByteOffs]; + if ((len+ByteOffs)&7) + { + MsgStruct += (bytesToCopy-1); + *MsgStruct &= ~ccd_bitfun_mask [8-((len+ByteOffs)&7)]; + } + +#if 0 +#ifdef DEBUG_CCD + { + int i; + for (i=0; i<bytesToCopy; i++) + { + TRACE_CCD (globs, "buf[%d] = 0x%02x", i, MsgStruct[i]); + } + } +#endif +#endif + bf_incBitpos (len, globs); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_readBitStr_PER | ++--------------------------------------------------------------------+ + + PURPOSE : The pointer globs->pstruct + globs->pstructOffs refers to + a var in the message C-structure. This function reads len + bits from the bit stream (globs->bitbuf) and stores them + left adjusted to the bytes in the message C-structure. +*/ + +void bf_readBitStr_PER (USHORT len, T_CCD_Globs *globs) +{ + USHORT bytesToCopy; + t_conv16 Last2Bytes; + U8 *MsgStruct = (U8*)(globs->pstruct + globs->pstructOffs); + U8 *MsgStructEnd = (U8*)(globs->pstruct + globs->pstructOffs + (len >> 3)); + U8 ByteOffs = globs->byteoffs; + U8 *MsgBuf = (U8*)(globs->bitbuf + globs->bytepos); + + bytesToCopy = (len+7) >> 3; + + /* + * Store the data for a later compensation of buffer overwritting. + */ + Last2Bytes.c[MSB_POS] = MsgStructEnd[0]; + Last2Bytes.c[LSB_POS] = MsgStructEnd[1]; + + /* + * The bits will be read from the bit buffer at byte boundary. + */ + if (ByteOffs EQ 0) + { + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "reading %d bits from byte %d.%d, copying %d bytes to struct at 0x%08X", + len, globs->bytepos, globs->byteoffs, bytesToCopy, MsgStruct); +#endif + + /* + * CCD assumes that the caller function needs the bit string to be + * left adjusted in the C-structure. + */ + memcpy ((UBYTE *) MsgStruct,//(globs->pstruct + globs->pstructOffs), + MsgBuf, + (size_t)bytesToCopy); + } + else + { + t_conv16 conv; + + /* + * Read byte for byte while compensating the non-zero globs->byteoffs. + */ + while (bytesToCopy--) + { + conv.c[MSB_POS] = *MsgBuf++; + conv.c[LSB_POS] = *MsgBuf; + conv.s <<= ByteOffs; + conv.s &= (USHORT) ~ccd_bitfun_mask[8-(len&7)]; + *MsgStruct++ = conv.c[MSB_POS]; + *MsgStruct = conv.c[LSB_POS]; + } + } + + /* + * Undo overwriting in C-Structure. This is specially necessary + * for later reading of valid flags for optional elments. + */ + MsgStructEnd[0] &= (UBYTE) ~ccd_bitfun_mask[8-(len&7)]; + Last2Bytes.c[MSB_POS] &= (UBYTE) ccd_bitfun_mask[8-(len&7)]; + MsgStructEnd[0] |= Last2Bytes.c[MSB_POS]; + MsgStructEnd[1] = Last2Bytes.c[LSB_POS]; + +#ifdef DEBUG_CCD + { + int i=0; + int j=0; + char s[64], c[4]; + int leftBytes = (len+7) >> 3;; + + MsgStruct = (U8*)(globs->pstruct + globs->pstructOffs); + TRACE_CCD (globs, " Decoded bit string:"); + + s[0] = '\0'; + for (i = 0; leftBytes > 0 ; i++) + { + for (j = 0; (j < 16 && (leftBytes-- > 0)) ; j++) + { + sprintf(c, " %02x", *(MsgStruct+(16*i)+j)); + strcat (s, c); + } + TRACE_CCD (globs, "%s", s); + s[0] = '\0'; + } + } +#endif + + globs->pstructOffs += ((len+7) >> 3); + bf_incBitpos (len, globs); +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_readBits | ++--------------------------------------------------------------------+ + + PURPOSE : reads (len) Bits from the Bitsream (globs->bitbuf) and + stores them typed (dependent on the length) to vars in + the C-struct referenced by the global var + globs->pstruct+globs->pstructOff. +*/ + +void bf_readBits (ULONG len, T_CCD_Globs *globs) +{ + /* + * Bit field is given by its lenght, offset bit and buffer. + */ + if (len > 32) + { + bf_readBitChunk (len, globs); + return; + } + else + { + t_conv16 conv16; + t_conv32 conv32; + U8 *MsgStruct = (U8*)(globs->pstruct + globs->pstructOffs); + U8 ByteOffs = globs->byteoffs; + U8 *MsgBuf = (U8*)(globs->bitbuf + globs->bytepos); + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "reading %d bits form byte %d.%d,", len, globs->bytepos, globs->byteoffs); +#endif + + /* + * Bit field is given in a C variable shorter than a USHORT. + */ + if (len <= 8) + { + if (globs->lastbytepos16 != globs->bytepos) + { + conv16.c[MSB_POS] = *MsgBuf++; + conv16.c[LSB_POS] = *MsgBuf; + globs->lastbytepos16 = globs->bytepos; + globs->last16Bit = conv16.s; + } + else + conv16.s = globs->last16Bit; + conv16.s >>= (16 - (ByteOffs + len)); + conv16.s &= (USHORT) ccd_bitfun_mask[len]; + *MsgStruct = (UBYTE) conv16.s; +#ifdef DEBUG_CCD + TRACE_CCD (globs, "writing 1 bytes (%0X) to struct %08X", *MsgStruct, MsgStruct); +#endif + } + else if (len + ByteOffs <= 32) + { + if (globs->lastbytepos32 != globs->bytepos) + { + conv32.c[MSW_POS + MSB_POS] = *MsgBuf++; + conv32.c[MSW_POS + LSB_POS] = *MsgBuf++; + conv32.c[LSW_POS + MSB_POS] = *MsgBuf++; + conv32.c[LSW_POS + LSB_POS] = *MsgBuf; + globs->lastbytepos32 = globs->bytepos; + globs->last32Bit = conv32.l; + } + else + conv32.l = globs->last32Bit; + conv32.l >>= (32 - (ByteOffs + len)); + conv32.l &= ccd_bitfun_mask[len]; + if (len > 16) + { + *((ULONG *) MsgStruct) = conv32.l; +#ifdef DEBUG_CCD + TRACE_CCD (globs, "writing 4 bytes (%08X) to struct %08X", + conv32.l, + MsgStruct); +#endif + } + else + { + *((USHORT *) MsgStruct) = (USHORT) conv32.l; +#ifdef DEBUG_CCD + TRACE_CCD (globs, "writing 2 bytes (%04X) to struct %08X", + (USHORT) conv32.l, + MsgStruct); +#endif + } + } + else + { + UBYTE FirstByte; + + FirstByte = *MsgBuf++; + FirstByte <<= ByteOffs; + FirstByte &= (UBYTE) ~ccd_bitfun_mask[ByteOffs]; + + if (globs->lastbytepos32 != globs->bytepos) + { + conv32.c[MSW_POS + MSB_POS] = *MsgBuf++; + conv32.c[MSW_POS + LSB_POS] = *MsgBuf++; + conv32.c[LSW_POS + MSB_POS] = *MsgBuf++; + conv32.c[LSW_POS + LSB_POS] = *MsgBuf; + globs->lastbytepos32 = globs->bytepos; + globs->last32Bit = conv32.l; + } + else + { + conv32.l = globs->last32Bit; + } + if (!ByteOffs) + { + conv32.l >>= 8; + } + else + { + conv32.l >>= (8-ByteOffs); + } + conv32.c[MSW_POS + MSB_POS] &= (UBYTE) ccd_bitfun_mask[ByteOffs]; + conv32.c[MSW_POS + MSB_POS] |= FirstByte; + conv32.l >>= (32-len); + conv32.l &= (ULONG) ccd_bitfun_mask[len]; + + *((ULONG *) MsgStruct) = conv32.l; +#ifdef DEBUG_CCD + TRACE_CCD ( globs, "writing 4 bytes (%08X) to struct %08X", + conv32.l, + MsgStruct); +#endif + } + bf_incBitpos (len, globs); return; + } +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_writeVal | ++--------------------------------------------------------------------+ + + PURPOSE : writes value into the next (bSize) bits of the air message + buffer(globs->bitbuf). This function does not use the data + in the C-structure. This is done by the caller function + while calculating value. +*/ +void bf_writeVal (ULONG value, ULONG bSize, T_CCD_Globs *globs) +{ + ULONG BitSum; + U8 *MsgBuf = (U8*)(globs->bitbuf + globs->bytepos); + U8 ByteOffs = globs->byteoffs; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "writeVal %d bits at byte %d.%d", bSize, globs->bytepos, ByteOffs); +#endif + /* + * value will be written into a temporary buffer. This buffer will + * then be prepared for an ORing with the bit buffer of air message. + * BitSum is helpful to find out the right size for temporary buffer. + */ + BitSum = bSize + (ULONG)ByteOffs; + + /* + * Write in 1 to 8 bits (bSize is 1-8). + */ + if (BitSum <= 8) + { + UBYTE TmpBuf; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, " (.%s)", ccd_BITIMAGE ((ULONG)(value & ccd_bitfun_mask[bSize]), bSize, globs)); +#endif + TmpBuf = (UBYTE) value; + TmpBuf &= (UBYTE) ccd_bitfun_mask[bSize]; + TmpBuf <<= (8 - BitSum); + *MsgBuf |= TmpBuf; + } + else + { + /* + * Write in 9 to 16 bits (bSize is 9-16). + */ + if (BitSum <= 16) + { + t_conv16 conv; + + conv.s = (USHORT) value; + conv.s &= (USHORT) ccd_bitfun_mask[bSize]; +#ifdef DEBUG_CCD + TRACE_CCD (globs, " (.%s)", ccd_BITIMAGE ((ULONG) conv.s, bSize, globs)); +#endif + conv.s <<= (16 - BitSum); + MsgBuf[0] |= conv.c[MSB_POS]; + MsgBuf[1] |= conv.c[LSB_POS]; + } + + /* + * Write in 17 to 25 bits (bSize is 17-25). + */ + else if (BitSum <= 32) + { + t_conv32 conv; + + conv.l = value; + conv.l &= ccd_bitfun_mask[bSize]; +#ifdef DEBUG_CCD + TRACE_CCD (globs, " (.%s)", ccd_BITIMAGE ((ULONG)conv.l, bSize, globs)); +#endif + conv.l <<= (32 - BitSum); + MsgBuf[0] |= conv.c[MSW_POS + MSB_POS]; + MsgBuf[1] |= conv.c[MSW_POS + LSB_POS]; + MsgBuf[2] |= conv.c[LSW_POS + MSB_POS]; + if (BitSum > 24) + { + MsgBuf[3] |= conv.c[LSW_POS + LSB_POS]; + } + } + /* + * Write in 25 to 32 bits (bSize is 25-32). + */ + else if ( BitSum < 40) + { + UBYTE FirstByte; + t_conv32 conv; + + conv.l = value; + conv.l <<= (32 - bSize); + FirstByte = conv.c[MSW_POS + MSB_POS]; + FirstByte >>= ByteOffs; + FirstByte &= (UBYTE) ccd_bitfun_mask[8-ByteOffs]; + MsgBuf[0] |= FirstByte; + + conv.l <<= (8 - ByteOffs); + MsgBuf[1] |= conv.c[MSW_POS + MSB_POS]; + MsgBuf[2] |= conv.c[MSW_POS + LSB_POS]; + MsgBuf[3] |= conv.c[LSW_POS + MSB_POS]; + MsgBuf[4] |= conv.c[LSW_POS + LSB_POS]; +#ifdef DEBUG_CCD + conv.l &= (ULONG) ~ccd_bitfun_mask[24-ByteOffs]; + TRACE_CCD (globs, " (.%s)", ccd_BITIMAGE ((ULONG) FirstByte, (ULONG)(8-ByteOffs), globs)); + TRACE_CCD (globs, " (.%s)", ccd_BITIMAGE (conv.l, (ULONG)(24-ByteOffs), globs)); +#endif + } + /* + * This case is currently not supported. + * Integer values are written to and read from up to 32 bits. + */ + else + { + return; + } + } + + bf_incBitpos (bSize, globs); +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_getBits | ++--------------------------------------------------------------------+ + + PURPOSE : reads len Bits from the Bitstream (globs->bitbuf) and + stores them in a variable. The caller function can now + interpret or process the content of the returned variable. +*/ + +ULONG bf_getBits (ULONG len, T_CCD_Globs *globs) +{ + U8 ByteOffs = globs->byteoffs; + U8 *MsgBuf = (U8*)(globs->bitbuf + globs->bytepos); + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "reading %ld bits form byte %d.%d,", len, globs->bytepos, globs->byteoffs); +#endif + + /* + * Read up to 8 bits from the air message buffer. + */ + if (len <= 8) + { + t_conv16 conv16; + + if (globs->lastbytepos16 != globs->bytepos) + { + conv16.c[MSB_POS] = *MsgBuf++; + conv16.c[LSB_POS] = *MsgBuf; + globs->lastbytepos16 = globs->bytepos; + globs->last16Bit = conv16.s; + } + else + { + conv16.s = globs->last16Bit; + } + conv16.s >>= (16 - (ByteOffs + len)); + conv16.s &= (USHORT) ccd_bitfun_mask[len]; +#ifdef DEBUG_CCD + TRACE_CCD (globs, "read value: %d", conv16.s); +#endif + bf_incBitpos (len, globs); + return (ULONG) conv16.s; + } + + /* + * Read between 8 and 24 bits from the air message buffer. + */ + else if (len <= 24) + { + t_conv32 conv32; + + if (globs->lastbytepos32 != globs->bytepos) + { + conv32.c[MSW_POS + MSB_POS] = *MsgBuf++; + conv32.c[MSW_POS + LSB_POS] = *MsgBuf++; + conv32.c[LSW_POS + MSB_POS] = *MsgBuf++; + conv32.c[LSW_POS + LSB_POS] = *MsgBuf; + globs->lastbytepos32 = globs->bytepos; + globs->last32Bit = conv32.l; + } + else + { + conv32.l = globs->last32Bit; + } + conv32.l >>= (32 - (ByteOffs + len)); + conv32.l &= ccd_bitfun_mask[len]; +#ifdef DEBUG_CCD + TRACE_CCD (globs, "read value: %ld", conv32.l); +#endif + bf_incBitpos (len, globs); + return conv32.l; + } + + /* + * Read between 24 and 32 bits from the air message buffer. + */ + else if ( len <= 32) + { + UBYTE FirstByte; + t_conv32 conv; + + FirstByte = *MsgBuf++; + FirstByte <<= ByteOffs; + FirstByte &= (UBYTE) ~ccd_bitfun_mask[ByteOffs]; + + if (globs->lastbytepos32 != globs->bytepos) + { + conv.c[MSW_POS + MSB_POS] = *MsgBuf++; + conv.c[MSW_POS + LSB_POS] = *MsgBuf++; + conv.c[LSW_POS + MSB_POS] = *MsgBuf++; + conv.c[LSW_POS + LSB_POS] = *MsgBuf; + globs->lastbytepos32 = globs->bytepos; + globs->last32Bit = conv.l; + } + else + { + conv.l = globs->last32Bit; + } + if (!ByteOffs) + { + conv.l >>= 8; + } + else + { + conv.l >>= (8-ByteOffs); + } + conv.c[MSW_POS + MSB_POS] &= (UBYTE) ccd_bitfun_mask[ByteOffs]; + conv.c[MSW_POS + MSB_POS] |= FirstByte; + conv.l >>= (32-len); + conv.l &= (ULONG) ccd_bitfun_mask[len]; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "read value: %ld", conv.l); +#endif + bf_incBitpos (len, globs); + return conv.l; + } + + /* + * This case is currently not supported. + * Integer values are written to and read from up to 32 bits. + */ + else + { + return 0; + } +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_decodeLongNumber | ++--------------------------------------------------------------------+ + + PURPOSE : reads (len) Bits from the Bitsream (globs->bitbuf) and + return this number as a 32 Bit number. The Position + of the readpointer of the bitstream is incremented by + the len. +*/ + +ULONG bf_decodeLongNumber (UBYTE len, T_CCD_Globs *globs) +{ + U32 number; + t_conv16 conv16; + t_conv32 conv32; + U8 ByteOffs = globs->byteoffs; + U8 *MsgBuf = (U8*)(globs->bitbuf + globs->bytepos); + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "reading %d bits form byte %d.%d,", len, globs->bytepos, globs->byteoffs); +#endif + + if (len <= 8) + { + if (globs->lastbytepos16 != globs->bytepos) + { + conv16.c[MSB_POS] = *MsgBuf++; + conv16.c[LSB_POS] = *MsgBuf; + globs->lastbytepos16 = globs->bytepos; + globs->last16Bit = conv16.s; + } + else + conv16.s = globs->last16Bit; + conv16.s >>= (16 - (ByteOffs + len)); + conv16.s &= (USHORT) ccd_bitfun_mask[len]; + number = (ULONG) conv16.s; + } + else + { + if (globs->lastbytepos32 != globs->bytepos) + { + conv32.c[MSW_POS + MSB_POS] = *MsgBuf++; + conv32.c[MSW_POS + LSB_POS] = *MsgBuf++; + conv32.c[LSW_POS + MSB_POS] = *MsgBuf++; + conv32.c[LSW_POS + LSB_POS] = *MsgBuf; + globs->lastbytepos32 = globs->bytepos; + globs->last32Bit = conv32.l; + } + else + conv32.l = globs->last32Bit; + conv32.l >>= (32 - (ByteOffs + len)); + conv32.l &= ccd_bitfun_mask[len]; + number = conv32.l; + } + + bf_incBitpos (len, globs); + +#ifdef DEBUG_CCD + TRACE_CCD (globs, " (%08X)", number); +#endif + + return number; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_decodeShortNumber| ++--------------------------------------------------------------------+ + + PURPOSE : reads (len) Bits from the Bitsream (globs->bitbuf) and + returns the resulting value as an ULONG. +*/ + +ULONG bf_decodeShortNumber (const ULONG len, T_CCD_Globs *globs) +{ + UBYTE *p; + t_conv32 conv32; + + p = globs->bitbuf + globs->bytepos; + + conv32.c[MSW_POS + MSB_POS] = *p++; + conv32.c[MSW_POS + LSB_POS] = *p++; + conv32.c[LSW_POS + MSB_POS] = *p++; + conv32.c[LSW_POS + LSB_POS] = *p; + conv32.l >>= (32 - (globs->byteoffs + len)); + conv32.l &= ccd_bitfun_mask[len]; + bf_incBitpos (len, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "reading %d bits as LONG (%d) at byte %d.%d", len, (ULONG) conv32.l, globs->bytepos, globs->byteoffs); +#endif + return (ULONG) conv32.l; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_decodeByteNumber | ++--------------------------------------------------------------------+ + + PURPOSE : reads (len) Bits from the Bitsream (globs->bitbuf) and + returns the resulting value as an UBYTE. +*/ + +UBYTE bf_decodeByteNumber (const ULONG len, T_CCD_Globs *globs) +{ + UBYTE *p; + t_conv16 conv16; + + p = globs->bitbuf + globs->bytepos; + + conv16.c[MSB_POS] = *p++; + conv16.c[LSB_POS] = *p; + conv16.s >>= (16 - (globs->byteoffs + len)); + conv16.s &= (USHORT) ccd_bitfun_mask[len]; + bf_incBitpos (len, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "reading %d bits as BYTE (%d) at byte %d.%d", len, (UBYTE) conv16.s, globs->bytepos, globs->byteoffs); +#endif + return (UBYTE) conv16.s; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_codeShortNumber | ++--------------------------------------------------------------------+ + + PURPOSE : Converts the value (val) into a MSB/LSB-Bitstring and + writes it to the aktual position into the bitstream + globs->bitbuf. The maximum value of (len) is 16. + If the value of (val) is greater then (2^len)-1 it + will be truncated. +*/ + +void bf_codeShortNumber (UBYTE len, USHORT val, T_CCD_Globs *globs) +{ + UBYTE *p; + t_conv32 conv32; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "codeShortNumber: writing %d bits (.%s) at byte %d.%d", + len, ccd_BITIMAGE (val, (ULONG) len, globs), globs->bytepos, globs->byteoffs); +#endif + p = globs->bitbuf + globs->bytepos; + conv32.l = (ULONG) val; + conv32.l <<= (32 - len - globs->byteoffs); + *p++ |= conv32.c[MSW_POS + MSB_POS]; + *p = conv32.c[MSW_POS + LSB_POS]; + if ((globs->byteoffs + len) > 16) + *++p = conv32.c[LSW_POS + MSB_POS]; + bf_incBitpos (len, globs); +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_recodeShortNumber| ++--------------------------------------------------------------------+ + + PURPOSE: Converts the value (val) into a MSB/LSB-Bitstring and + writes it at the position (pos) into the bitstream + globs->bitbuf. The rest of the bitstream and the actual + position will not changed. The maximum value of (len) + is 16. + If the value of (val) is greater then (2^len)-1 + it will be truncated. +*/ + +void bf_recodeShortNumber (USHORT pos, UBYTE len, USHORT val, T_CCD_Globs *globs) +{ + UBYTE *p; + USHORT oldbitpos; + t_conv32 conv32; + USHORT wBits; + + oldbitpos = globs->bitpos; + bf_setBitpos (pos, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "bf_recodeShortNumber:rewriting %d bits (.%s) at byte %d.%d", + len, ccd_BITIMAGE ((ULONG) val, len, globs), globs->bytepos, globs->byteoffs); +#endif + wBits = len + globs->byteoffs; + p = globs->bitbuf + globs->bytepos; + conv32.l = (ULONG) val; + conv32.l <<= (32 - wBits); + + /* + * Since the bits to write are cleared (memclr) in the bitstream, + * it is ok to perform an OR operation on them. + */ + *p++ |= conv32.c[MSW_POS + MSB_POS]; + if (wBits > 8) + { + *p++ |= conv32.c[MSW_POS + LSB_POS]; + if (wBits > 16) + { + *p++ |= conv32.c[LSW_POS + MSB_POS]; + if (wBits > 24) + *p |= conv32.c[LSW_POS + LSB_POS]; + } + } + + bf_setBitpos (oldbitpos, globs); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_recodeByteNumber | ++--------------------------------------------------------------------+ + + PURPOSE: Converts the value (val) into a MSB/LSB-Bitstring and + writes it at the position (pos) into the bitstream + globs->bitbuf. The rest of the bitstream and the actual + position will not changed. The maximum value of (len) + is 8. + If the value of (val) is greater then (2^len)-1 + it will be truncated. +*/ + +void bf_recodeByteNumber (USHORT pos, UBYTE len, UBYTE val, T_CCD_Globs *globs) +{ + UBYTE *p; + USHORT oldbitpos; + t_conv16 conv16; + + oldbitpos = globs->bitpos; + bf_setBitpos (pos, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "bf_recodeByteNumber:rewriting %d bits (.%s) at byte %d.%d", + len, ccd_BITIMAGE ((ULONG) val, len, globs), globs->bytepos, globs->byteoffs); +#endif + p = globs->bitbuf + globs->bytepos; + conv16.s = (USHORT) val; + conv16.s <<= (16 - len - globs->byteoffs); + /* + * if the bits to write are cleared (memclr) in the bitstream + * we can perform an OR operation on it + */ + *p++ |= conv16.c[MSB_POS]; + if ((len + globs->byteoffs) > 8) + *p |= conv16.c[LSB_POS]; + + bf_setBitpos (oldbitpos, globs); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_recodeBit | ++--------------------------------------------------------------------+ + + PURPOSE: Writes the value of (Bit) at the position (pos) + into the bitstream globs->bitbuf. The rest of the bitstream + and the actual position will not changed. +*/ + +void bf_recodeBit (USHORT pos, UBYTE Bit, T_CCD_Globs *globs) +{ + U16 oldbitpos = globs->bitpos;; + + bf_setBitpos (pos, globs); + globs->bitbuf[globs->bytepos] = Bit ? (globs->bitbuf[globs->bytepos] | + ccd_bitfun_shift[globs->byteoffs]) + : (globs->bitbuf[globs->bytepos] & + ~ccd_bitfun_shift[globs->byteoffs]); + bf_setBitpos (oldbitpos, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "recode 1 bit (.%d) at bitpos %d", Bit, pos); +#endif +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_codeByteNumber | ++--------------------------------------------------------------------+ + + PURPOSE: Converts the value (val) into a Bitstring with the + length (len) and writes it at the actual position + into the bitstream globs->bitbuf. The maximum value of + (len) is 8. + If the value is greater then (2^len)-1 it will be + truncated. + +*/ + +void bf_codeByteNumber (UBYTE len, UBYTE val, T_CCD_Globs *globs) +{ + UBYTE *p; + t_conv16 conv16; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "codeByteNumber:writing %d bits (.%s) at byte %d.%d", + len, ccd_BITIMAGE (val, (ULONG) len, globs), globs->bytepos, globs->byteoffs); +#endif + p = globs->bitbuf + globs->bytepos; + + conv16.s = (USHORT) val; + conv16.s <<= (16 - len - globs->byteoffs); + *p++ |= conv16.c[MSB_POS]; + if ((globs->byteoffs + len) > 8) + *p |= conv16.c[LSB_POS]; + bf_incBitpos (len, globs); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_codeLongNumber | ++--------------------------------------------------------------------+ + + PURPOSE : This funtion writes the numeric content of + the var to the aktual position into the bitstream + referenced by globs->bitbuf. +*/ + +void bf_codeLongNumber (UBYTE len, ULONG val, T_CCD_Globs *globs) +{ + UBYTE wBits = len + globs->byteoffs; + U8 *MsgBuf = (U8*)(globs->bitbuf + globs->bytepos); + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "codeLongNumber: writing %d bits (.%s) at byte %d.%d", + len, ccd_BITIMAGE (val, (ULONG) len, globs), globs->bytepos, globs->byteoffs); +#endif + + if (len > 8) + { + t_conv32 conv; + + conv.l = val; + conv.l &= ccd_bitfun_mask[len]; + conv.l <<= (32 - wBits); + MsgBuf[0] |= conv.c[MSW_POS + MSB_POS]; + MsgBuf[1] = conv.c[MSW_POS + LSB_POS]; + if (wBits > 16) + { + MsgBuf[2] = conv.c[LSW_POS + MSB_POS]; + if (wBits > 24) + { + MsgBuf[3] = conv.c[LSW_POS + LSB_POS]; + } + } + } + else + { + t_conv16 conv; + + conv.s = (USHORT) val; + conv.s &= (USHORT) ccd_bitfun_mask[len]; + conv.s <<= (16 - wBits); + MsgBuf[0] |= conv.c[MSB_POS]; + if (wBits > 8) + { + MsgBuf[1] = conv.c[LSB_POS]; + } + } + + bf_incBitpos (len, globs); +} +#endif /* !RUN_FLASH */ + +#if 0 /* not used - maybe for the future */ +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : BITFUN | +| STATE : code ROUTINE : bf_swapBits | ++--------------------------------------------------------------------+ + + PURPOSE : reads (len) Bits from the Bitsream (1-8) and swap + this part with the next (len) bits in the bitstream. + The read/write pointer of the bitstream left unchanged. + This function is used for swapping the nibbles in some + ugly coded GSM messages. +*/ + +void bf_swapBits (ULONG len, T_CCD_Globs *globs) +{ + UBYTE s1, s2; + USHORT s21; + USHORT startpos = globs->bitpos; + UBYTE *p; + t_conv32 conv32; + + if (len > 0 AND len <= 8) + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "swapping %d bits", len); +#endif + + /* + * read bitstring#1 + */ + s1 = bf_decodeByteNumber (len, globs); + /* + * read bitstring#2 + */ + s2 = bf_decodeByteNumber (len, globs); + /* + * concat bitstring#2 and bitstring#1 + */ + s21 = (USHORT) s2 <<len; + s21 |= s1; + + /* + * recode it into the bitstream + */ + bf_setBitpos (startpos, globs); + p = globs->bitbuf + globs->bytepos; + conv32.l = (ULONG) s21; + conv32.l <<= (32 - len) - globs->byteoffs; + *p++ |= conv32.c[MSW_POS + MSB_POS]; + *p++ |= conv32.c[MSW_POS + LSB_POS]; + *p++ |= conv32.c[LSW_POS + MSB_POS]; + *p |= conv32.c[LSW_POS + LSB_POS]; + + bf_setBitpos (startpos, globs); + bf_recodeShortNumber (startpos, (UBYTE) (len<<1), s21, globs); + bf_setBitpos (startpos, globs); + } +} + +#endif /* !RUN_FLASH */ +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/bitfun.h Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,68 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : bitfun.h ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Condat Coder Decoder +| Prototypes of the elementary bit manipulation functions ++----------------------------------------------------------------------------- +*/ + + +#ifndef __BITFUN +#define __BITFUN + + +#ifndef __BITFUN_C__ + +EXTERN void bf_writePadBits (T_CCD_Globs *globs); +EXTERN void bf_writeVal (ULONG value, ULONG bSize, T_CCD_Globs *globs); +EXTERN ULONG bf_getBits (ULONG len, T_CCD_Globs *globs); +EXTERN void bf_writeBitStr_PER (USHORT len, T_CCD_Globs *globs); +EXTERN void bf_readBitStr_PER (USHORT len, T_CCD_Globs *globs); +EXTERN void bf_writeBits (ULONG len, T_CCD_Globs *globs); +EXTERN void bf_readBits (ULONG len, T_CCD_Globs *globs); +EXTERN void bf_writeBitChunk (ULONG len, T_CCD_Globs *globs); +EXTERN void bf_readBitChunk (ULONG len, T_CCD_Globs *globs); +EXTERN BOOL bf_readBit (T_CCD_Globs *globs); +EXTERN void bf_writeBit (BOOL Bit, T_CCD_Globs *globs); +EXTERN UBYTE bf_decodeByteNumber (const ULONG len, T_CCD_Globs *globs); +EXTERN ULONG bf_decodeShortNumber (const ULONG len, T_CCD_Globs *globs); +EXTERN ULONG bf_decodeLongNumber (UBYTE len, T_CCD_Globs *globs); +EXTERN void bf_codeShortNumber (UBYTE len, USHORT val, T_CCD_Globs *globs); +EXTERN void bf_codeByteNumber (UBYTE len, UBYTE val, T_CCD_Globs *globs); +EXTERN void bf_codeLongNumber (UBYTE len, ULONG val, T_CCD_Globs *globs); +EXTERN void bf_recodeShortNumber (USHORT pos, UBYTE len, USHORT val, T_CCD_Globs *globs); +EXTERN void bf_recodeByteNumber (USHORT pos, UBYTE len, UBYTE val, T_CCD_Globs *globs); +EXTERN void bf_recodeBit (USHORT pos, UBYTE Bit, T_CCD_Globs *globs); +EXTERN void bf_rShift8Bit (USHORT srcBitPos, USHORT bitLen, T_CCD_Globs *globs); + +#endif /* __BITFUN_C__ */ + +/* a Macro for incrementing the position in the bitbuffer */ +/* _bitpos, _bytepos and _byteoffs are recalculated */ + +#define bf_incBitpos(A, globs) globs->bitpos = (USHORT)(globs->bitpos+(A));\ + globs->bytepos = (USHORT)(globs->bitpos >> 3);\ + globs->byteoffs = (UBYTE)(globs->bitpos & 7) +#define bf_setBitpos(A, globs) globs->bitpos = (USHORT)(A);\ + globs->bytepos = (USHORT)(globs->bitpos >> 3);\ + globs->byteoffs = (UBYTE)(globs->bitpos & 7) + +/* + * end of bitstream if we can not read almost 4 bits + */ +#define bf_endOfBitstream(globs) (globs->bitpos >= globs->maxBitpos) + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/break_cond.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,238 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : break_cond.c ++----------------------------------------------------------------------------- +| Copyright 2004 Texas Instruments Deutschland GmbH +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for BREAK_COND +| elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++-----------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_break_cond_decode | ++-----------------------------------------------------------------------------+ + + PURPOSE : Decoding of the BREAK_COND element. This element consists of a V + component with a variable bit length and must be connected with a + special condition. This condition has to be a simple value, which + matches to the value range of BREAK_COND element itself. + This function performs a standard decoding for a given elem table + entry. This means for non structured elements that 1-n bits are + read from the bitstream and write to a C-Variable in a machine + dependent format. + After decoding of the requested number of bits the resulting value + will be compared with the constant given by the condition. In case + of equality the global variable globs->continue_array is set to + FALSE. This breaks decoding of the current superior composition + and finishes the array. +*/ +SHORT cdc_break_cond_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + U8 break_ind = FALSE; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_break_cond_decode()"); + #else + TRACE_CCD (globs, "cdc_break_cond_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * if this element is conditional, check the condition + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + /* + * if this element has a defined prologue + * we have to process it before decoding the bitstream + * If there are some epilogue expressions to be processed for this element + * (rare cases) the result here will be a reading of 0 to an internal + * register. The valid processing of expression takes place after the + * decoding of the element. + */ + if (num_prolog_steps) + { + if (calc[prolog_step_ref].operation EQ 'P') + { + break_ind = TRUE; + } + + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + globs->pstructOffs = melem[e_ref].structOffs; + + + if (globs->bitpos < globs->maxBitpos) + { + + if (mvar[melem[e_ref].elemRef].cType EQ 'X') + bf_readBitChunk (mvar[melem[e_ref].elemRef].bSize, globs); + else + bf_readBits (mvar[melem[e_ref].elemRef].bSize, globs); + + if ( ( break_ind == TRUE ) && (num_prolog_steps > 0)) + { + if ( calc[prolog_step_ref].operand == + (U16) *(globs->pstruct + globs->pstructOffs) ) + { + globs->continue_array = FALSE; + } + } + + globs->pstructOffs += mvar[melem[e_ref].elemRef].cSize; + } + else + ccd_recordFault ( globs, + ERR_ELEM_LEN, + BREAK, + (USHORT) e_ref, + globs->pstruct + globs->pstructOffs); + + /* + * process the epilogue expression for this element if there is any + */ + if (num_prolog_steps) + { + if ( (calc[prolog_step_ref+1].operation EQ 'K') + || (calc[prolog_step_ref+1].operation EQ 'C') + || (calc[prolog_step_ref+1].operation EQ 's')) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + } + + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++-----------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_break_cond_encode | ++-----------------------------------------------------------------------------+ + + PURPOSE : encoding of the BREAK_COND element. This element consists of a V + component with a variable bit length and must be connected with a + special condition. This condition has to be a simple value, which + matches to the value range of BREAK_COND element itself. + +*/ + +SHORT cdc_break_cond_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + U8 break_ind = FALSE; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_break_cond_encode()"); + #else + TRACE_CCD (globs, "cdc_break_cond_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * if this element is conditional, check the condition + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + /* + * if this element have a defined Prolog + * we have to process it before decoding the bitstream + */ + if (num_prolog_steps) + { + if (calc[prolog_step_ref].operation EQ 'P') + { + break_ind = TRUE; + } + + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + /* + * Element is not a SPARE. + * Setup the readpointer into the C-structure for this element + */ + globs->pstructOffs = melem[e_ref].structOffs; + + if (mvar[melem[e_ref].elemRef].cType EQ 'X') + bf_writeBitChunk (mvar[melem[e_ref].elemRef].bSize, globs); + else + bf_writeBits (mvar[melem[e_ref].elemRef].bSize, globs); + + if ( ( break_ind == TRUE ) && (num_prolog_steps > 0)) + { + if ( calc[prolog_step_ref].operand == + (U16) *(globs->pstruct + globs->pstructOffs) ) + { + globs->continue_array = FALSE; + } + } + + globs->pstructOffs += mvar[melem[e_ref].elemRef].cSize; + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccd.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,3424 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccd.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Condat Conder Decoder - +| Definition of encoding and decoding functions of +| air interface messages ++----------------------------------------------------------------------------- +*/ + +#define CCD_C + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <setjmp.h> + +#ifdef _MSDOS + #include <dos.h> + #include <conio.h> +#endif + +/* + * Standard definitions like UCHAR, ERROR etc. + */ + +#include "typedefs.h" +#include "header.h" + +/* + * Types and constants used by CCD + */ +#include "ccd_globs.h" + +/* + * Type definitions for CCD data tables + */ +#include "ccdtable.h" + +/* + * Function prototypes of CCD-CCDDATA interface + */ +#include "ccddata.h" + +/* + * Error codes and prototypes of exported functions by CCD + * (USE_DRIVER EQ undef) + * For prototypes only look at ccdapi.h. + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "bitfun.h" + + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +#if !(defined (CCD_TEST)) +#include "vsi.h" +#include "os.h" +#endif + +#ifdef SHARED_VSI + #define VSI_CALLER 0, +#else + #define VSI_CALLER +#endif + +#ifndef RUN_FLASH +/* task_null is used in ccd_signup. It must have the same RUN_... setting. */ +static T_CCD_TASK_TABLE task_null; +#endif /* !RUN_FLASH */ + +//TISH modified for MSIM +#if defined (CCD_TEST) || defined (_TOOLS_) || defined (WIN32) +/* For the DLL and for all simple environment define the task list locally */ +/* 10 entries should be more than enough */ +#define MAX_ENTITIES 10 +T_CCD_TASK_TABLE* ccd_task_list[MAX_ENTITIES]; +#else +extern T_CCD_TASK_TABLE* ccd_task_list[]; +#endif + +#ifndef RUN_FLASH +const T_CCD_VarTabEntry* mvar; +const T_CCD_SpareTabEntry* spare; +const T_CCD_CalcTabEntry* calc; +const T_CCD_CompTabEntry* mcomp; +const T_CCD_ElemTabEntry* melem; +const T_CCD_CalcIndex* calcidx; +const T_CCD_ValTabEntry* mval; +#else +extern const T_CCD_VarTabEntry* mvar; +extern const T_CCD_SpareTabEntry* spare; +extern const T_CCD_CalcTabEntry* calc; +extern const T_CCD_CompTabEntry* mcomp; +extern const T_CCD_ElemTabEntry* melem; +extern const T_CCD_CalcIndex* calcidx; +extern const T_CCD_ValTabEntry* mval; +#endif + +#ifndef RUN_FLASH +/* + * Attention: if one of the following static data shall be used in + * both, internal as well as external RAM, they must be made global. + */ +static USHORT max_message_id; + +/* + * CCD internal buffer for decoded message + */ +static UBYTE *ccd_decMsgBuffer; +/* + * Layer-specific cache for the bitlength of the message-identifier; + * A value of 0 indicates an empty (undetermined) entry + */ +static UBYTE *mi_length; + +/* + * CCD internal variables used in each call to code or decode message + */ + +static U8 aim_rrc_rcm; +static U8 aim_rrlp; +static U8 aim_sat; + +static T_CCD_Globs globs_all; +#endif /* !RUN_FLASH */ + +/* + * CCD will call its encoding/decoding functions through a jump table. + */ +#include "ccd_codingtypes.h" +#ifndef RUN_FLASH +T_FUNC_POINTER codec[MAX_CODEC_ID+1][2]; +#else +extern T_FUNC_POINTER codec[MAX_CODEC_ID+1][2]; +#endif + +#ifndef RUN_FLASH +/* initialized is used in ccd_signup. It must have the same RUN_... setting. */ +/* + * Initialising flag + */ +BOOL initialized = FALSE; +#endif /* !RUN_FLASH */ + +#ifdef SHARED_CCD + /* + * If CCD is used in a premptive multithreaded system we need + * a semaphore to protect the coding and decoding sections. + */ + #ifndef RUN_FLASH + T_HANDLE semCCD_Codec, semCCD_Buffer; + #else + extern T_HANDLE semCCD_Codec, semCCD_Buffer; + #endif /* RUN_FLASH */ +#endif /* SHARED_CCD */ + +static U8* mempat; +#define LOWSEGMASK 0xFFFFF000 + +#ifndef RUN_FLASH +#ifdef DEBUG_CCD +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : TRACE_CCD | ++--------------------------------------------------------------------+ + + PURPOSE : Error processing of the CCD. + +*/ + +void TRACE_CCD (T_CCD_Globs *globs, char *format, ...) +{ + va_list varpars; + char trace_buf[256]; + int i=0; + + if (!globs->TraceIt) + return; + + va_start (varpars, format); /* Initialize variable arguments. */ +#if defined CCD_TEST + /* + * use vsi_o_trace - prefix the tracestring with [CCD] + * so the PCO can display it in a CCD window + */ + strcpy (trace_buf, "~CCD~"); + i = 5; +#endif /* CCD_TEST */ + vsprintf (trace_buf+i, format, varpars); + va_end (varpars); /* Reset variable arguments. */ + +#ifdef CCD_TEST + printf ("\n%s\n", trace_buf); +#else + vsi_o_ttrace (globs->me, TC_CCD, trace_buf); +#endif /* CCD_TEST */ + +} +#endif /* !RUN_FLASH */ + +#endif + +/* + * Stack operations + */ +#define ST_CLEAR(globs) globs->SP=0;globs->StackOvfl=FALSE; + +#define ST_OK(globs) (globs->StackOvfl EQ FALSE) + +#define ST_CHECK(A, globs) {if (!(globs->StackOvfl) AND globs->SP < MAX_UPN_STACK_SIZE)\ + {(A);}\ + else\ + {globs->StackOvfl = TRUE;}} + +#define ST_PUSH(A, globs) ST_CHECK ((globs->Stack[globs->SP++] = (A)), globs) + +#define ST_POP(A, globs) ST_CHECK ((A = globs->Stack[--(globs->SP)]), globs) + +#define ST_TOP(A, globs) ST_CHECK ((A = globs->Stack[globs->SP-1]), globs) + +#ifndef RUN_FLASH +/* + * Attention: if the static function calcUPN shall be used in + * both, internal as well as external RAM, it must be made global. + */ +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : calcUPN | ++--------------------------------------------------------------------+ + + PURPOSE : calculates the UPN-term for an element. + +*/ +LOCAL BOOL calcUPN (ULONG op, + ULONG num_ops, + ULONG *result, + T_CCD_Globs *globs) +{ + BOOL opError; + ULONG op1=0,op2=0; + + opError = FALSE; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "Calculation of UPN-term "); +#endif + + while (num_ops-- AND !opError AND ST_OK(globs)) + { + switch (calc[op].operation) + { + case '+': + /* + * get the upper two elements from the stack, add them + * and push the result on the stack + */ + if (globs->SP >= 2) + { + ST_POP(op2, globs); + ST_POP(op1, globs); + ST_PUSH ((op1 + op2), globs); + } +#ifdef DEBUG_CCD + else + TRACE_CCD (globs, "Control parameter '+' causes invalid calculation"); +#endif + break; + case '-': + /* + * get the upper two elements from the stack, subtract them + * and push the result on the stack + */ + if (globs->SP >= 2) + { + ST_POP(op2, globs); + ST_POP(op1, globs); + ST_PUSH ((op1 - op2), globs); + } +#ifdef DEBUG_CCD + else + TRACE_CCD (globs, "Control parameter '-' causes invalid calculation"); +#endif + break; + case '*': + /* + * get the upper two elements from the stack, multiply them + * and push the result on the stack + */ + if (globs->SP >= 2) + { + ST_POP(op2, globs); + ST_POP(op1, globs); + ST_PUSH ((op1 * op2), globs); + } +#ifdef DEBUG_CCD + else + TRACE_CCD (globs, "Control parameter '*' causes invalid calculation"); +#endif + break; + case '/': + /* + * get the upper two elements from the stack, divide them + * and push the result on the stack + */ + if (globs->SP >= 2) + { + ST_POP(op2, globs); + if (!op2) + { + ccd_setError (globs, ERR_DEFECT_CCDDATA, BREAK, + (USHORT) (globs->bitpos), (USHORT) -1); + } + else + { + ST_POP(op1, globs); + ST_PUSH ((op1 / op2), globs); + } + } +#ifdef DEBUG_CCD + else + TRACE_CCD (globs, "Control parameter '/' causes invalid calculation"); +#endif + break; + case '&': + /* + * get the upper two elements from the stack, perform a + * binary AND + * and push the result on the stack + */ + if (globs->SP >= 2) + { + ST_POP(op2, globs); + ST_POP(op1, globs); + ST_PUSH ((op1 & op2), globs); + } +#ifdef DEBUG_CCD + else + TRACE_CCD (globs, "Control parameter '&' causes invalid calculation"); +#endif + break; + case '|': + /* + * get the upper two elements from the stack, perform a + * binary OR + * and push the result on the stack + */ + if (globs->SP >= 2) + { + ST_POP(op2, globs); + ST_POP(op1, globs); + ST_PUSH ((op1 | op2), globs); + } +#ifdef DEBUG_CCD + else + TRACE_CCD (globs, "Control parameter '|' causes invalid calculation"); +#endif + break; + case 'A': + /* + * get the upper two elements from the stack, perform a + * logical AND + * and push a TRUE or FALSE on the stack + */ + if (globs->SP >= 2) + { + ST_POP(op2, globs); + ST_POP(op1, globs); + ST_PUSH ((op1 AND op2), globs); + } +#ifdef DEBUG_CCD + else + TRACE_CCD (globs, "Control parameter 'AND' causes invalid calculation"); +#endif + break; + case 'O': + /* + * get the upper two elements from the stack, perform a + * logical OR + * and push a TRUE or FALSE on the stack + */ + if (globs->SP >= 2) + { + ST_POP(op2, globs); + ST_POP(op1, globs); + ST_PUSH ((op1 OR op2), globs); + } +#ifdef DEBUG_CCD + else + TRACE_CCD (globs, "Control parameter 'OR' causes invalid calculation"); +#endif + break; + case 'X': + /* + * get the upper two elements from the stack, perform a + * logical XOR + * and push a TRUE or FALSE on the stack + */ + if (globs->SP >= 2) + { + ST_POP(op2, globs); + ST_POP(op1, globs); + ST_PUSH ( ((op1 AND !op2) OR (!op1 AND op2)) , globs); + } +#ifdef DEBUG_CCD + else + TRACE_CCD (globs, "Control parameter 'XOR' causes invalid calculation"); +#endif + break; + case '=': + /* + * get the upper two elements from the stack, look if they + * are equal + * and push a TRUE or FALSE on the stack + */ + if (globs->SP >= 2) + { + ST_POP(op2, globs); + ST_POP(op1, globs); + ST_PUSH ((op1 EQ op2), globs); + } +#ifdef DEBUG_CCD + else + TRACE_CCD (globs, "Control parameter '=' causes invalid calculation"); +#endif + break; + case '#': + /* + * get the upper two elements from the stack, look if they + * are different + * and push a TRUE or FALSE on the stack + */ + if (globs->SP >= 2) + { + ST_POP(op2, globs); + ST_POP(op1, globs); + ST_PUSH ((op1 NEQ op2), globs); + } +#ifdef DEBUG_CCD + else + TRACE_CCD (globs, "Control parameter '#' causes invalid calculation"); +#endif + break; + case '>': + /* + * get the upper two elements from the stack, look if + * op1 > op2 + * and push a TRUE or FALSE on the stack + */ + if (globs->SP >= 2) + { + ST_POP(op2, globs); + ST_POP(op1, globs); + ST_PUSH ((op1 > op2), globs); + } +#ifdef DEBUG_CCD + else + TRACE_CCD (globs, "Control parameter '>' causes invalid calculation"); +#endif + break; + case '<': + /* + * get the upper two elements from the stack, look if + * op1 < op2 + * and push a TRUE or FALSE on the stack + */ + if (globs->SP >= 2) + { + ST_POP(op2, globs); + ST_POP(op1, globs); + ST_PUSH ((op1 < op2), globs); + } +#ifdef DEBUG_CCD + else + TRACE_CCD (globs, "Control parameter '<' causes invalid calculation"); +#endif + break; + case 'P': + /* + * push a constant on the stack + */ + ST_PUSH (calc[op].operand, globs); +#ifdef DEBUG_CCD + if (globs->StackOvfl == TRUE) + TRACE_CCD (globs, "Constant can't be pused on UPN stack"); +#endif + break; + case ':': + /* + * duplicate the upper element on the stack + */ + if (globs->SP >= 1) + { + ST_TOP (op1, globs); + ST_PUSH (op1, globs); + } +#ifdef DEBUG_CCD + else + TRACE_CCD (globs, "No UPN stack element to duplicate"); +#endif + break; + case 'R': + /* + * push the content of a C-structure variable on the stack + */ + { + /* if no register available some compilers may react with + a warning like this: identifier p not bound to register + */ + UBYTE *p; + ULONG value; + + /* + * normaly we have to check if the element is a VAR + * and not an array/substructure. + * - but this must be done by ccdgen + */ + + /* + * setup the read pointer to the element in the C-structure + */ + p = globs->pstruct + melem[(USHORT) calc[op].operand].structOffs; + + /* + * Get the element table entry from the element to read. + * if the element of the condition is conditional too + * then look for the valid flag of this element. + * if the element is not valid, + * we dont need to check the contents of it + */ + if (melem[(USHORT) calc[op].operand].optional) + { + if (*(UBYTE *) p EQ FALSE) + { + ST_PUSH (0L, globs); + break; + } + else + p++; + } + + /* + * read the contents of the element + */ + switch (mvar[melem[(USHORT) calc[op].operand].elemRef].cType) + { + case 'B': + value = (ULONG) * p; + break; + case 'S': + value = (ULONG) * (USHORT *) p; + break; + case 'L': + value = *(ULONG *) p; + break; + default: + value = 0L; + } + ST_PUSH (value, globs); + break; + } + case 'S': + /* + * get the upper element from the stack an + * set the position of the bitstream pointer to this + * value + */ + if (globs->SP >= 1) + { + ST_POP(op1, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "SETBITPOS %d (byte %d.%d)", + (USHORT) op1, (USHORT) (op1 / 8), (USHORT) (op1 % 8)); +#endif + bf_setBitpos ((USHORT) op1, globs); + } +#ifdef DEBUG_CCD + else + TRACE_CCD (globs, "Control parameter 'SETBITPOS' causes invalid calculation"); +#endif + break; + case 'G': + /* + * push the position of the bitstream pointer on the + * stack + */ + ST_PUSH ((ULONG) globs->bitpos, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "GETBITPOS %d (byte %d.%d)", + (USHORT) globs->bitpos, globs->bytepos, globs->byteoffs); +#endif + break; + case '^': + /* + * swap the upper two elements of the stack + */ + if (globs->SP >= 2) + { + ST_POP(op1, globs); + ST_POP(op2, globs); + ST_PUSH(op1, globs); + ST_PUSH(op2, globs); + } +#ifdef DEBUG_CCD + else + TRACE_CCD (globs, "Control parameter '^' causes invalid calculation"); +#endif + break; + case 'K': + /* + * Keep a value in the KEEP register. + */ + if (globs->SP >= 1) + { + ST_POP(op1, globs); + globs->KeepReg[calc[op].operand] = op1; + } +#ifdef DEBUG_CCD + else + TRACE_CCD (globs, "Control parameter 'KEEP' causes invalid calculation"); +#endif + break; + case 'L': + /* + * Copy the L part of a TLV element from the KEEP register to the UPN stack. + */ + ST_PUSH(globs->KeepReg[0]*8, globs); +#ifdef DEBUG_CCD + if (globs->StackOvfl == TRUE) + TRACE_CCD (globs, "Control parameter 'LTAKE' causes invalid calculation"); +#endif + break; + case 'T': + /* + * Take a value from the KEEP register and push it on the UPN stack. + */ + ST_PUSH(globs->KeepReg[calc[op].operand], globs); +#ifdef DEBUG_CCD + if (globs->StackOvfl == TRUE) + TRACE_CCD (globs, "Control parameter 'TAKE' causes invalid calculation"); +#endif + break; + case 'C': + /* + * Compare the value on the UPN stack with the one stored in the KEEP register. + * Push the higher value in the KEEP register. + */ + if (globs->SP >= 1) + { + ST_POP(op1, globs); + if ((globs->KeepReg[calc[op].operand]) < op1) + { + globs->KeepReg[calc[op].operand] = op1; + } + } +#ifdef DEBUG_CCD + else + TRACE_CCD (globs, "Control parameter 'MAX' causes invalid calculation"); +#endif + break; + case 'Z': + /* + * Used to mark presence of an address information part error label + */ + globs->errLabel = ERR_ADDR_INFO_PART; + break; + case 'D': + /* + * Used to mark presence of a distribution part error label + */ + globs->errLabel = ERR_DISTRIB_PART; + break; + case 'N': + /* + * Used to mark presence of a non distribution part error label + */ + globs->errLabel = ERR_NON_DISTRIB_PART; + break; + case 'M': + /* + * Used to mark presence of a message escape error label + */ + globs->errLabel = ERR_MESSAGE_ESCAPE; + break; + case 'I': + /* + * Used to mark presence of an ignore error label + */ + globs->errLabel = ERR_IGNORE; + break; + case 'l': + /* + * Take a value from the CCD STO register and push it on the UPN stack. + */ + opError = ccd_getStore (globs, calc[op].operand, &op1); + if (!opError) + { + ST_PUSH(op1, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "Push CCD STORE register [%d] value to UPN stack", + calc[op].operand); + } + else + { + TRACE_CCD (globs, "Reading from CCD STORE register [%d] impossible", + calc[op].operand); +#endif + } + break; + case 's': + /* + * Store a value in the CCD STO register. + */ + if (globs->SP >= 1) + { + ST_POP(op1, globs); + opError = ccd_writeStore (globs, calc[op].operand, op1); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "Store value in CCD STO register [%d]", + calc[op].operand); + } + else + { + TRACE_CCD (globs, "Control parameter 'STORE' causes invalid calculation"); +#endif + } + break; + + default: + opError = TRUE; + break; + } + op++; + } + + if (!opError AND ST_OK(globs)) + { + if (result NEQ (ULONG *) NULL) + ST_POP (*result, globs); + return (ST_OK(globs)); + } + else + { +#ifdef DEBUG_CCD + if(opError) + TRACE_CCD (globs, "Calculation of UPN-term failed "); + else + TRACE_CCD (globs, "Calculation of UPN-term failed due to stack overflow"); +#endif + return FALSE; + } +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_conditionOK | ++--------------------------------------------------------------------+ + + PURPOSE : Check if the conditions for an element are true. + The elemRef references an element entry from the elem tab. + The function returns TRUE if the defined + conditions are TRUE. + +*/ + +BOOL ccd_conditionOK (const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG result, cond_calc_ref, num_cond_calcs, cix_ref; + + cix_ref = melem[e_ref].calcIdxRef; + num_cond_calcs = calcidx[cix_ref].numCondCalcs; + cond_calc_ref = calcidx[cix_ref].condCalcRef; + + + if (! calcUPN (cond_calc_ref, + num_cond_calcs, + &result, + globs)) + return FALSE; + + return (result EQ TRUE); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_calculateRep | ++--------------------------------------------------------------------+ + + PURPOSE : For a given element (referenced by elemRef) calculate the + repeat value. + +*/ + +BOOL ccd_calculateRep (const ULONG e_ref, + ULONG *repeat, + ULONG *max_repeat, + T_CCD_Globs *globs) +{ + ULONG cix_ref, result; + ULONG remaining_repeats=0; + ULONG rep_calc_ref, num_rep_calcs; + + BOOL is_variable; + + cix_ref = melem[e_ref].calcIdxRef; + num_rep_calcs = calcidx[cix_ref].numRepCalcs; + rep_calc_ref = calcidx[cix_ref].repCalcRef; + + *max_repeat = (ULONG) melem[e_ref].maxRepeat; + + if (num_rep_calcs EQ 0) + { + if (melem[e_ref].repType EQ 'i') + { + switch (melem[e_ref].elemType) + { + case 'S': + remaining_repeats = (ULONG)((globs->maxBitpos-globs->bitpos) + / spare[melem[e_ref].elemRef].bSize); + break; + case 'F': /* Code transparent pointer to base type */ + case 'R': /* Pointer to base type */ + case 'V': + remaining_repeats = (ULONG)((globs->maxBitpos-globs->bitpos) + / mvar[melem[e_ref].elemRef].bSize); + break; + case 'D': /* Code transparent pointer to composition */ + case 'P': /* Pointer to composition */ + case 'C': + /* for repeated compositions the remaining repeats + are set to the max repeats because of the unknown + size of one composition */ + remaining_repeats = (ULONG) melem[e_ref].maxRepeat; + break; + default: + ccd_setError (globs, ERR_INVALID_CALC, BREAK, (USHORT) -1); + break; + } + + *repeat = MINIMUM (*max_repeat, remaining_repeats); + is_variable = TRUE; + } + else + { + if (melem[e_ref].repType EQ 'b') + { + remaining_repeats = (ULONG)(globs->maxBitpos-globs->bitpos); + *repeat = MINIMUM (*max_repeat, remaining_repeats); + } + else + { + *repeat = MINIMUM (*max_repeat, + (ULONG) calcidx[cix_ref].repCalcRef); + if (*repeat < (ULONG) calcidx[cix_ref].repCalcRef) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + is_variable = FALSE; + } + } + else + { + is_variable = FALSE; + if (! calcUPN (rep_calc_ref, + num_rep_calcs, + &result, + globs)) + { + *repeat = *max_repeat = 0; + + ccd_setError (globs, ERR_INVALID_CALC, BREAK, (USHORT) -1); + } + else + { + if ((melem[e_ref].repType != 'b') && (melem[e_ref].repType != 's')) + { + is_variable = TRUE; + } + if (melem[e_ref].repType EQ 'i') + { + switch (melem[e_ref].elemType) + { + case 'S': + remaining_repeats = (ULONG)((globs->maxBitpos-globs->bitpos) + / spare[melem[e_ref].elemRef].bSize); + break; + case 'F': /* Code transparent pointer to base type */ + case 'R': /* Pointer to base type */ + case 'V': + remaining_repeats = (ULONG)((globs->maxBitpos-globs->bitpos) + / mvar[melem[e_ref].elemRef].bSize); + break; + default: + ccd_setError (globs, ERR_INVALID_CALC, BREAK, (USHORT) -1); + break; + } + *repeat = MINIMUM (result, remaining_repeats); + } + else + { + *repeat = MINIMUM (result, *max_repeat); + if (*repeat < result) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + } + } + return (is_variable); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_performOperations | ++--------------------------------------------------------------------+ + + PURPOSE : Perform the operation for an element. This operations + are executed before an element is encoded or decoded. + The Operations work with the UPN-Stack. + +*/ + +void ccd_performOperations (ULONG num_of_ops, + ULONG op_def_ref, + T_CCD_Globs *globs) +{ + if (! calcUPN (op_def_ref, + num_of_ops, + NULL, + globs)) + ccd_setError (globs, ERR_INVALID_CALC, BREAK, (USHORT) -1); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* + * Attention: if the static function ccd_isOptional shall be used in + * both, internal as well as external RAM, it must be made global. + */ +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_isOptional | ++--------------------------------------------------------------------+ + + PURPOSE : Checks if a given element is optional. If the element is + not optional and is a composition, + a recursive call is performed in order to check + if the composition contains only optional elements. + In this case the whole composition is optional. + + In case of components concatenated with a CSN1 coding + rules the meaning of the word <optional> differs from the + traditional TI tool chain conventions. So far some coding + types (like tagged types, e.g. GSM3_TV) characterise + optional elements inherently. The value of their valid + flag indicates the presence or absence of such an element. + Components concatenated with a CSN1 coding type cause + these valid flags in the C header structure too. If you + find a bit in the received message stream indicating + optional values not included in the message (e. g. a + CSN1_S1 element is represented by ??, CCD will set the + valid flag to zero. But the whole element represented by + the flag is present; only the value is absent! Therefor + the valid flag in the C structure is not an indication of + an element’s absence. +*/ + +LOCAL BOOL ccd_isOptional (ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG cix_ref; + + switch (melem[e_ref].codingType) + { + case CCDTYPE_CSN1_S1: /* Fall through. */ + case CCDTYPE_CSN1_S0: + case CCDTYPE_CSN1_SHL: + + cix_ref = melem[e_ref].calcIdxRef; + /* + * If this element is conditional, check the condition. + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return TRUE; + + if (melem[e_ref].repType == 'i' AND + calcidx[melem[e_ref].calcIdxRef].repCalcRef == 0) + return TRUE; + else + return FALSE; +// break; +// PATCH FROM M18 + case CCDTYPE_CSN1_CONCAT: + return TRUE; + + default: + break; + } + + if (! melem[e_ref].optional) + { + /* + * if the element is an array with an interval [0..x] + * it can be handled like an optional element + */ + if ( ! (melem[e_ref].repType EQ 'i' + AND calcidx[melem[e_ref].calcIdxRef].repCalcRef EQ 0)) + { + /* + * if the element is not optional but it is a composition + * we check recursive if the composition consists only of + * optional elements + */ + if (melem[e_ref].elemType EQ 'C' OR + melem[e_ref].elemType EQ 'D' OR + melem[e_ref].elemType EQ 'P') + { + ULONG el, lel, c_ref; + + c_ref = melem[e_ref].elemRef; + + el = (ULONG) mcomp[c_ref].componentRef; + lel = el + mcomp[c_ref].numOfComponents; + + while (el < lel) + { + if (! ccd_isOptional (el, globs)) + return FALSE; + el++; + } + } + else + return FALSE; + } + } + return TRUE; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_decodeComposition | ++--------------------------------------------------------------------+ + + PURPOSE : decodes the bitstream to a C-Structure.The decoding + rules contains the element definitions for the + elements of this message. + This function may called recursivly because of a + substructured element definition. +*/ + +void ccd_decodeComposition (const ULONG c_ref, T_CCD_Globs *globs) +{ + /* + * index in table melem + */ + ULONG e_ref; /* element reference */ + ULONG l_ref; /* reference to the last element of a component */ + SHORT codecRet; + BOOL ExtendedGroupActive = FALSE; + BOOL GroupExtended = FALSE; + BOOL MoreData; + BOOL SetPosExpected = FALSE; + int i; + ULONG act_err_label; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "ccd_decodeComposition()"); + #else + TRACE_CCD (globs, "ccd_decodeComposition(): Composition = %s", + mcomp[c_ref].name); + #endif +#endif + + act_err_label = (ULONG) globs->errLabel; + globs->ccd_recurs_level++; + + /* + * setup the index in the melem table for this composition. + * If this function is called for the first time + * (ccd_recurs_level == 1) the elem-table entry for the msg_type + * was skipped. + */ + + l_ref = mcomp[c_ref].componentRef + + mcomp[c_ref].numOfComponents; + + e_ref = mcomp[c_ref].componentRef + + ((globs->ccd_recurs_level EQ 1) ? 1 : 0); + + /* + * decode all elements + */ + while (e_ref < l_ref) + { +#ifdef ERR_TRC_STK_CCD + /* save the value for tracing in error case */ + globs->error_stack[globs->ccd_recurs_level] = (USHORT) e_ref; +#endif /* ERR_TRC_STK_CCD */ + + if (melem[e_ref].extGroup != ' ' && GroupExtended && !ExtendedGroupActive) + { + /* + * the last read extension bit signals an + * extension of the group but there are no + * more elements defined for this group. + * This indicates a protocol extension, that must be + * skipped by ccd. + */ + + do + { + /* + * read the ext-bit to determine the extension + * of this group + */ + GroupExtended = (bf_readBit (globs) EQ 0); + /* + * skip to next octett + */ +#ifdef DEBUG_CCD + TRACE_CCD (globs, "skipping 7 bits"); +#endif + bf_incBitpos (7, globs); + } while (GroupExtended); + } + + /* + * check if the bitstream has ended + */ + if (bf_endOfBitstream(globs) AND !globs->TagPending) + { + ULONG cix_ref, num_prolog_steps; + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + + /* End of the bit stream is not reached if a call to bf_setBitpos() + * is expected for the next element of the current substructure. + * An instructive example is an empty "mob_id" + */ + if (num_prolog_steps) + { + ULONG prolog_step_ref = calcidx[cix_ref].prologStepRef; + + i = (int) (prolog_step_ref + num_prolog_steps); + + while (i >= (int) prolog_step_ref) + { + if (calc[i].operation == 'S') + { + SetPosExpected = TRUE; + break; + } + i--; + } + } + + if (SetPosExpected EQ FALSE) + { + /* + * no more bits to decode. + * If at least one mandatory element is to decode + * generate an error. + */ + + while (e_ref < l_ref) + { + if (! ccd_isOptional (e_ref, globs)) + ccd_setError (globs, ERR_MAND_ELEM_MISS, BREAK, (USHORT) -1); + + e_ref++; + } + /* after the while loop the recursion level will be decremented. */ + break; + } + } + + /* + * look for extension group processing + */ + if (melem[e_ref].extGroup NEQ ' ') + { + /* + * extended group symbol found + */ + switch (melem[e_ref].extGroup) + { + case '+': + /* + * start of an extended group + */ + ExtendedGroupActive = TRUE; + /* + * read the extension bit to determine the extension + * of this group + */ + GroupExtended = (bf_readBit (globs) EQ 0); + /* + * use the jump-table for selecting the decode function + */ + codecRet = + codec[melem[e_ref].codingType][DECODE_FUN](c_ref, + (USHORT)e_ref, globs); + if (codecRet NEQ 0x7f) + { + /* + * set the e_ref to the next or the same element + */ + e_ref += codecRet; + } + break; + + case '-': + /* + * end of one extension, + * decode first and the read the extension bit. + */ + /* + * use the jump-table for selecting the decode function + */ + codecRet = + codec[melem[e_ref].codingType][DECODE_FUN](c_ref, + (USHORT)e_ref, globs); + if (codecRet NEQ 0x7f) + { + /* + * set the e_ref to the next or the same element + */ + e_ref += codecRet; + } + + /* + * look if the previously readed extension bit + * alows an extension of this group + */ + if (!GroupExtended) + { + + ExtendedGroupActive = FALSE; + /* + * overread the following elements in the group + */ + /* + * search the last element of the extended group + */ + while (e_ref < l_ref + AND melem[e_ref].extGroup NEQ '*') + { +#ifdef DEBUG_CCD +#ifdef CCD_SYMBOLS + if (melem[e_ref].elemType EQ 'V') + TRACE_CCD (globs, "Skipping ext-group element %s", + ccddata_get_alias((USHORT) e_ref, 1)); + else if (melem[e_ref].elemType EQ 'C') + TRACE_CCD (globs, "Skipping ext-group element %s", + mcomp[melem[e_ref].elemRef].name); + else + TRACE_CCD (globs, "Skipping ext-group spare"); +#else + TRACE_CCD (globs, "Skipping ext-group element %c-%d", + melem[e_ref].elemType, + e_ref); + +#endif +#endif + e_ref++; + } + /* + * skip the last element + */ + e_ref++; + } + else + { + /* + * read the extension bit to determine if the group + * extension holds on + */ + GroupExtended = (bf_readBit (globs) EQ 0); + } + break; + + case '*': + if (!ExtendedGroupActive) + { + /* + * this is a single element extended group + * often used for later extension of the protocol + */ + /* + * read the extension bit to determine if a group + * extension is present + */ + GroupExtended = (bf_readBit (globs) EQ 0); + } + ExtendedGroupActive = FALSE; + + /* + * use the jump-table for selecting the decode function + */ + codecRet = + codec[melem[e_ref].codingType][DECODE_FUN](c_ref, e_ref, globs); + if (codecRet NEQ 0x7f) + { + /* + * set the e_ref to the next or the same element + */ + e_ref += codecRet; + } + break; + + case '!': /* Moredata bit */ + case '#': + if ((MoreData = bf_readBit (globs)) EQ 1) + { + /* + * moredata-bit is set to 1 + * process this element. + */ + + /* + * use the jump-table for selecting the decode function + */ + codecRet = + codec[melem[e_ref].codingType][DECODE_FUN](c_ref, e_ref, globs); + + if (melem[e_ref].extGroup EQ '#') + { + /* + * if more data are signaled with an additional + * bit but there are no + * more elements defined for this group. + * This indicates a protocol extension, that must be + * skipped by ccd. + */ + + do + { + /* + * read the ext-bit to determine the extension + * of this group + */ + GroupExtended = (bf_readBit (globs) EQ 1); + /* + * skip to next octett + */ + #ifdef DEBUG_CCD + TRACE_CCD (globs, "skipping 7 bits"); + #endif + bf_incBitpos (7, globs); + } while (!bf_endOfBitstream(globs) AND GroupExtended); + + } + + if (codecRet NEQ 0x7f) + { + /* + * set the elemRef to the next or the same element(USHORT) + */ + e_ref += codecRet; + } + } + + if (!MoreData) + { + /* + * more data bit is cleared, + * overread the following elements in the group + * search the last element of the extended group + */ + while (e_ref < l_ref + AND melem[e_ref].extGroup NEQ '#') + { +#ifdef DEBUG_CCD +#ifdef CCD_SYMBOLS + if (melem[e_ref].elemType EQ 'V') + TRACE_CCD (globs, "Skipping ext-group element %s", + ccddata_get_alias((USHORT) e_ref, 1)); + else if (melem[e_ref].elemType EQ 'C') + TRACE_CCD (globs, "Skipping ext-group element %s", + mcomp[melem[e_ref].elemRef].name); + else + TRACE_CCD (globs, "Skipping ext-group spare"); +#else + TRACE_CCD (globs, "Skipping ext-group element %c-%d", + melem[e_ref].elemType, + e_ref); + +#endif +#endif + e_ref++; + } + + /* + * skip the last element of the moredata group + */ + e_ref++; + } + break; + default: + ccd_setError (globs, ERR_DEFECT_CCDDATA, BREAK, + (USHORT) (globs->bitpos), (USHORT) -1); + break; + } + } + else + { + /* + * no processing action for an extended group + */ + + /* + * use the jump-table for selecting the decode function + */ + codecRet = + codec[melem[e_ref].codingType][DECODE_FUN](c_ref, e_ref, globs); + if (codecRet NEQ 0x7f) + { + /* + * set the e_ref to the next or the same element + */ + e_ref += codecRet; + } + } + } + + /* Reset indicator of exhaustion in the IEI table*/ + for (i = 0; globs->iei_ctx[globs->ccd_recurs_level].iei_table[i].valid== TRUE; i++) + { + globs->iei_ctx[globs->ccd_recurs_level].iei_table[i].exhausted = FALSE; + globs->iei_ctx[globs->ccd_recurs_level].iei_table[i].act_amount = 0; + + } + + globs->iei_ctx[globs->ccd_recurs_level].countSkipped = 0; + globs->ccd_recurs_level--; + globs->errLabel = (U8) act_err_label; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* + * Attention: if this static function shall be used in + * both, internal as well as external RAM, it must be made global. + */ +static void SkipExtensionOctets (ULONG *e_ref, ULONG l_ref) +{ + /* The extended group is terminated. Skip over its IEs. */ + while (*e_ref < l_ref && melem[*e_ref].extGroup != '*') + (*e_ref)++; + if (*e_ref < l_ref) + (*e_ref)++; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* + * Attention: if this static function shall be used in + * both, internal as well as external RAM, it must be made global. + */ +LOCAL BOOL CheckBP_RecodeXB (ULONG ExtBitPos1, ULONG ExtBitPos2, + ULONG ExtBitPos3, T_CCD_Globs *globs) +{ + /* Absence due to validity flag, condition or a ccdWarning. */ + if (ExtBitPos3 == globs->bitpos ) + { + globs->bitpos --; + if (ExtBitPos1 NEQ ExtBitPos2) + bf_recodeBit ((USHORT) ExtBitPos1, 1, globs); + return FALSE; + } + return TRUE; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_encodeComposition | ++--------------------------------------------------------------------+ + + PURPOSE : codes the content of a C-Structure into a bitstream. + This function may be called recursivly if an IE in the + structure is itself a structured IE. + + For extended octet groups the following rules apply. + + Any IE within an extension octet is characterised by its + extGroup which is one of the following: + + + '+' octet begins with this IE. + ' ' octet continues with this IE or a new octet begins. + '-' octet ends with this IE. + '*' octet group ends with this IE. + + An octet may begin with '+', '-', ' ' or '*'. + An octet beginning with '-' or '*' is made of only one IE (7 bits). + A group made of one octet has only one IE with '*'. + If '+' is present, next IEs ending with '*' or '-' are present too. + If the beginning IE with ' ' is not IE + + Examples of extended group configurations. + _ _ _ _ _ + | | | | | | | + |+|*| |+| |*| one octet + |_|_| |_|_|_| + + _ _ _ _ _ _ _ _ _ _ _ + | | | | | | | | | | | | | | + |+|-| |*| |+|-|*| |+| |-|*| two octets + |_|_|_|_| |_|_|_| |_|_|_|_| + + + _ _ _ _ _ _ _ _ _ _ + | | | | | | | | | | | + |+| | |-| |-| |-| |*| four octets + |_|_|_|_|_|_|_|_|_|_| + + Also groups after groups are possible. + _ _ _ _ _ _ _ _ _ + | | | | | | | | | | + |+| |-| |*|+|*|*|*| + |_|_|_|_|_|_|_|_|_| + + The status of encoding is given as follows: + + ExtendedGroupActive is set to 1 if '+' is present in the encoding. + ExtendedGroupActive is changed from 1 to 0 when encoding '*'. + ExtendedGroupActive is set to 0 if an octet beginning with ' ' is + not present. + OpenNewOctet is set to 1 after encoding an IE with '-'. + ExtBitPos1 is set to the globs->bitpos when writing extension bit: + 1) for '+' or + 2) for ' ' after '-' + + Extension bit is set to 0 if a further octet is encoded for + the group. If an octet is the last one within a group, the + extension bit is set to 1. + + While processing the first IE of an octet (e.g. for '+'), + if the IE is absent, CCD will skip over all IEs up to the + ending '*'. + When processing IEs with ' ' and for ExtendedGroupActive=1 the valid + flag is set to 1 in order to compensate probable mistakes in PS. + +*/ + +void ccd_encodeComposition (const ULONG c_ref, T_CCD_Globs *globs) +{ + ULONG e_ref; + ULONG l_ref; + BOOL ExtendedGroupActive = FALSE, OpenNewOctet = FALSE; + ULONG ext_bit_pos1=0, ext_bit_pos2=0, ext_bit_pos3=0, more_data_bit_pos=0; + int ext_bit_pending=0; + UBYTE codecRet; + + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "ccd_encodeComposition()"); + #else + TRACE_CCD (globs, "ccd_encodeComposition(): Composition = %s", + mcomp[c_ref].name); + #endif +#endif + + globs->ccd_recurs_level++; + + /* + * setup the index in the melem table for this composition. + * If this function is called for the first time + * (ccd_recurs_level == 1) the elem-table entry for the msg_type + * was skipped. + */ + + l_ref = (USHORT)(mcomp[c_ref].componentRef + + mcomp[c_ref].numOfComponents); + + e_ref = (USHORT)(mcomp[c_ref].componentRef + + ((globs->ccd_recurs_level EQ 1) ? 1 : 0)); + + /* + * code all elements + */ + while (e_ref < l_ref) + { +#ifdef ERR_TRC_STK_CCD + /* + * Save the value for tracing in error case. + */ + globs->error_stack[globs->ccd_recurs_level] = (USHORT) e_ref; +#endif /* ERR_TRC_STK_CCD */ + + /* + * look for extension group processing + */ + if (melem[e_ref].extGroup NEQ ' ') + { + /* + * extended group symbol found + */ + switch (melem[e_ref].extGroup) + { + case '+': + + /* + * remember the position of the extension bit + * because we maybe have to recode it. + */ + ext_bit_pos1 = ext_bit_pos2 = (ULONG) globs->bitpos; + + + /* + * write the extension bit. It may overwritten + * later. (ext=0 -> group extended) + */ + bf_writeBit (0, globs); + ext_bit_pos3 = (USHORT) globs->bitpos; + +#if defined(_TOOLS_) + if (ccd_patch (globs, 0)) + codecRet = 1; + else +#endif /* _TOOLS_ */ + /* Use the jump-table for selecting encode function. */ + codecRet = (UBYTE) + codec[melem[e_ref].codingType][ENCODE_FUN](c_ref, e_ref, globs); + + /* Absence due to validity flag, conditions or a ccdWarning. */ + if (!CheckBP_RecodeXB (ext_bit_pos1, ext_bit_pos2, ext_bit_pos3, globs)) + { + ExtendedGroupActive = FALSE; + SkipExtensionOctets (&e_ref, l_ref); + continue; + } + /* Start of an extended group */ + else + { + OpenNewOctet = FALSE; + } + + ExtendedGroupActive = TRUE; + ext_bit_pending = 1; + + if (codecRet NEQ 0x7f) + { + /* Set the elemRef to the next or the same element. */ + e_ref += codecRet; + } + break; + + /* End of one extension octet. */ + case '-': + /* IE must be present if the previous one was not with '-'. */ + if (OpenNewOctet == FALSE) + { +#ifdef DEBUG_CCD + if (globs->pstruct [melem[e_ref].structOffs] != TRUE) + { + TRACE_CCD (globs, "Wrong value for valid flag!\n...changed to 1 for ccdID=%d", + e_ref); + } +#endif + /* IE has to be present. Don't trust PS code. */ + globs->pstruct [melem[e_ref].structOffs] = TRUE; + } + ext_bit_pos3 = (USHORT) globs->bitpos; + +#if defined(_TOOLS_) + if (ccd_patch (globs, 0)) + codecRet = 1; + else +#endif /* _TOOLS_ */ + /* Use the jump-table for selecting encode function. */ + codecRet = (UBYTE) + codec[melem[e_ref].codingType][ENCODE_FUN](c_ref, e_ref, globs); + + if (OpenNewOctet == TRUE) + { + /* Absence due to validity flag, conditions or a ccdWarning. */ + if (!CheckBP_RecodeXB (ext_bit_pos1, ext_bit_pos2, ext_bit_pos3, globs)) + { + ExtendedGroupActive = FALSE; + SkipExtensionOctets (&e_ref, l_ref); + continue; + } + } + + if (codecRet NEQ 0x7f) + { + /* Set the elemRef to the next or the same element. */ + e_ref += codecRet; + } + + /* IE with '-' belongs to the first octet. */ + if (ext_bit_pending EQ 1) + { + ext_bit_pending++; + } + /* + * At least one octet has been encoded for the current group. + * Swap the stored positions of the extension bits. + */ + else + { + ext_bit_pos1 = ext_bit_pos2; + } + + /* + * Store the position of the extension bit + * because we maybe have to recode it. + */ + ext_bit_pos2 = (ULONG) globs->bitpos; + /* + * write the extension bit. It may overwritten + * later. (ext=0 -> group extended) + */ + bf_writeBit (0, globs); + OpenNewOctet = TRUE; + + break; + + case '*': + if (!ExtendedGroupActive) + { + /* + * This is a single element extended group, often + * used for later extension of the protocol + * Write '1' in extension bit since group is not extended yet. + */ + bf_writeBit (1, globs); + ext_bit_pos3 = (USHORT) globs->bitpos; + +#if defined(_TOOLS_) + if (ccd_patch (globs, 0)) + codecRet = 1; + else +#endif /* _TOOLS_ */ + /* Use the jump-table for selecting encode function. */ + codecRet = (UBYTE) + codec[melem[e_ref].codingType][ENCODE_FUN](c_ref, e_ref, globs); + /* Absence due to the valid flag or a ccdWarning. */ + if (ext_bit_pos3 == globs->bitpos) + { + globs->bitpos --; + } + + if (codecRet NEQ 0x7f) + { + /* Set the elemRef to the next or the same element. */ + e_ref += codecRet; + } + } + else + { + ExtendedGroupActive = FALSE; + /* IE must be present if the previous one was not with '-'. */ + if (OpenNewOctet == FALSE) + { +#ifdef DEBUG_CCD + if (globs->pstruct [melem[e_ref].structOffs] != TRUE) + { + TRACE_CCD (globs, "Wrong value for valid flag!\n...changed to 1 for ccdID=%d", + e_ref); + } +#endif + /* IE has to be present. Don't trust PS code. */ + globs->pstruct [melem[e_ref].structOffs] = TRUE; + } + +#if defined(_TOOLS_) + if (ccd_patch (globs, 0)) + codecRet = 1; + else +#endif /* _TOOLS_ */ + /* Use the jump-table for selecting the encode function. */ + codecRet = (UBYTE) + codec[melem[e_ref].codingType][ENCODE_FUN](c_ref, e_ref, globs); + ext_bit_pos3 = (USHORT) globs->bitpos; + + if (codecRet NEQ 0x7f) + { + /* Set the elemRef to the next or the same element. */ + e_ref += codecRet; + } + + if ((ext_bit_pos3-1) NEQ ext_bit_pos2) + { + /* + * if the writepointer (ext_bit_pos3) have incremented + * since the first extension bit (NEQ ext_bit_pos1) + * at least one element of this group is valid + * and written into the bitstream. + */ + /* + * the extended group is terminated, + * so we have to switch the previously written + * extBit from 0 to 1 + */ + bf_recodeBit ((USHORT) ext_bit_pos2, 1, globs); + } + else + { + /* + * break of an extended group, no element are coded + * since the last extension bit. + */ + /* + * the extended group is terminated, + * so we have to switch the previously written + * extBit from 0 to 1 + */ + if (ext_bit_pos1 NEQ ext_bit_pos2) + { + bf_recodeBit ((USHORT) ext_bit_pos1, 1, globs); + } + /* + * delete the written ext-bit because the extended + * group ended. + */ + bf_setBitpos ((USHORT) ext_bit_pos2, globs); + } + } + break; + case '!': + case '#': + more_data_bit_pos = (ULONG) globs->bitpos; + bf_writeBit (1, globs); + +#if defined(_TOOLS_) + if (ccd_patch (globs, 0)) + codecRet = 1; + else +#endif /* _TOOLS_ */ + /* + * use the jump-table for selecting the encode function + */ + codecRet = (UBYTE) + codec[melem[e_ref].codingType][ENCODE_FUN](c_ref, e_ref, globs); + if (codecRet NEQ 0x7f) + { + if (more_data_bit_pos+1 EQ globs->bitpos) + { + /* + * rewrite the written moredata bit to 0 + */ + bf_setBitpos (more_data_bit_pos, globs); + bf_writeBit (0, globs); + /* + * no coding performed -> extension group ended + * We skip all elements in this group + */ + while (melem[e_ref].extGroup EQ '!') + e_ref++; + + if (melem[e_ref].extGroup EQ '#') + e_ref++; + } + else + { + if (melem[e_ref].extGroup EQ '#') + { + /* + * code a zero bit for the last element + */ + bf_writeBit (0, globs); + } + e_ref++; + } + } + break; + default: + ccd_setError (globs, ERR_DEFECT_CCDDATA, BREAK, + (USHORT) (globs->bitpos), (USHORT) -1); + break; + } + } + else + { + if (ExtendedGroupActive) + { + ext_bit_pos3 = (USHORT) globs->bitpos; + + /* IE in the middle part of an ext-octet. */ + if (OpenNewOctet == FALSE) + { +#ifdef DEBUG_CCD + if (globs->pstruct [melem[e_ref].structOffs] != TRUE) + { + TRACE_CCD (globs, "Wrong value for valid flag!\n...changed to 1 for ccdID=%d", + e_ref); + } +#endif + globs->pstruct [melem[e_ref].structOffs] = TRUE; + } + } + +#if defined(_TOOLS_) + if (ccd_patch (globs, 0)) + codecRet = 1; + else +#endif /* _TOOLS_ */ + /* Use the jump-table for selecting encode function. */ + codecRet = (UBYTE) + codec[melem[e_ref].codingType][ENCODE_FUN](c_ref, e_ref, globs); + + /* The following is only meant for IEs after an IE with '-'. */ + if (ExtendedGroupActive) + { + if (OpenNewOctet == TRUE) + { + /* Absence due to validity flag, conditions or a ccdWarning. */ + if (!CheckBP_RecodeXB (ext_bit_pos1, ext_bit_pos2, ext_bit_pos3, globs)) + { + ExtendedGroupActive = FALSE; + SkipExtensionOctets (&e_ref, l_ref); + continue; + } + /* Start of an extension octet */ + else + { + OpenNewOctet = FALSE; + } + } + } + + if (codecRet NEQ 0x7f) + { + /* Set the elemRef to the next or the same element. */ + e_ref += codecRet; + } + } + } + + globs->ccd_recurs_level--; +} +#endif /* !RUN_FLASH */ + +/* ---------------------------------------------------------------- */ +/* GLOBAL FUNCTIONS */ +/* ---------------------------------------------------------------- */ + +#ifndef RUN_FLASH +/* ++------------------------------------------------------------------------------ +| Function : ccd_check_pointer ++------------------------------------------------------------------------------ +| Description : This function checks the validity of a pointer +| +| Parameters : ptr - the pointer +| +| Return : ccdOK if pointer valid, otherwise ccdError ++------------------------------------------------------------------------------ +*/ +int ccd_check_pointer (U8* ptr) +{ + if (!ptr || ptr == mempat +#ifdef WIN32 + /* For windows: check also if ptr is too small */ + || !(ptr && LOWSEGMASK) +#endif + ) + { + return ccdError; + } + return ccdOK; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_begin | ++--------------------------------------------------------------------+ + + + PARAMETERS: none + + PURPOSE: Returns the address of the CCD buffer for decoded + messages and locks it until ccd_end() is called + +*/ + +UBYTE* CCDDATA_PREF(ccd_begin) (void) +{ +#ifdef SHARED_CCD + /* + * if the CCD is used in a premptive multithreaded system + * we must lock this critical section + */ + vsi_s_get (VSI_CALLER semCCD_Buffer); +#endif + +#ifdef DEBUG_CCD +{ + #ifndef _TMS470 + T_CCD_Globs globs; + globs.me = 0; + globs.TraceIt = 1; + TRACE_CCD (&globs, "CCD Begin"); + #endif +} +#endif + return ccd_decMsgBuffer; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_end | ++--------------------------------------------------------------------+ + + + PARAMETERS: none + + PURPOSE: Unlocks the CCD buffer for decoded + messages + +*/ + +void CCDDATA_PREF(ccd_end) (void) +{ +#ifdef SHARED_CCD + /* + * if the CCD is used in a premptive multithreaded system + * we must unlock this critical section of accessing the + * decoded message buffer + */ + vsi_s_release (VSI_CALLER semCCD_Buffer); +#endif +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_GetGlobVars | ++--------------------------------------------------------------------+ + + + PARAMETERS: + + PURPOSE: Determines which set of global variables to use + and locks the CCD buffer (semaphore) if necessary. + +*/ +T_CCD_Globs* ccd_GetGlobVars (T_CCD_ERR_LIST_HEAD** eentry, T_CCD_STORE_LIST** stoentry) +{ + T_CCD_TASK_TABLE* tentry; +#ifndef SHARED_CCD + int me = 0; +#else + T_HANDLE me; + me = vsi_e_handle (0, NULL); + if (me == VSI_ERROR) + me = 0; +#endif /* !SHARED_CCD */ + + tentry = ccd_task_list[me]; + tentry->ccd_globs->me = me; + *eentry = tentry->ccd_err_list; + *stoentry = tentry->ccd_store; +#ifdef SHARED_CCD + if (tentry->ccd_globs == &globs_all) + { + /* + * if the CCD is used in a premptive multithreaded system + * we must lock this critical section + */ + vsi_s_get (VSI_CALLER semCCD_Codec); + } +#endif /* SHARED_CCD */ + return tentry->ccd_globs; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_FreeGlobVars | ++--------------------------------------------------------------------+ + + + PARAMETERS: none + + PURPOSE: Unlocks the CCD buffer for decoded messages + if the entity is not GRR and if + the CCD is used in a premptive multithreaded system. + +*/ +void ccd_FreeGlobVars (T_CCD_Globs* globs) +{ +#ifdef SHARED_CCD + if (globs == &globs_all) + { + vsi_s_release (VSI_CALLER semCCD_Codec); + } +#endif /* SHARED_CCD */ +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +#ifdef DEBUG_CCD +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_dump_msg | ++--------------------------------------------------------------------+ + + PARAMETERS: U16 l_buf + - Number of bits in the encoded message or IE. + + U16 o_buf + - Offset of the bitstream buffer in bits. + + U8 *buf + - Bitstream buffer of the encoded message or IE. + + T_CCD_Globs globs + - Pointer to global variables + + PURPOSE: Dump contents of air interface message - for debugging + +*/ +void ccd_dump_msg (U16 l_buf, U16 o_buf, U8 *buf, T_CCD_Globs *globs) +{ + + if (!globs->TraceIt) + return; + else + { + int i, j, buflen; + char s[64], c[4]; + + buflen = (l_buf + o_buf + 7) >> 3; + TRACE_CCD (globs, "-------------------------------------------------"); + TRACE_CCD (globs, " CCD: Decode Message"); + TRACE_CCD (globs, " Before DECODING: lbuf= %d, obuf= %d", l_buf, o_buf); + TRACE_CCD (globs, " Hex dump of message to be decoded:"); + + s[0] = '\0'; + for (i = o_buf>>3; i < buflen; i+=16) + { + for (j = 0; j < 16; j++) + { + if ((i+j) < buflen) + { + sprintf(c, " %02x", buf[i+j]); + strcat (s, c); + } + } + TRACE_CCD (globs, "%s", s); + s[0] = '\0'; + } + } +} +#endif /* DEBUG_CCD */ +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_common_decode_init| ++--------------------------------------------------------------------+ + + PARAMETERS: + + PURPOSE: Perform common CCD initialization before message decode. + +*/ +void ccd_common_decode_init(U16 l_buf, U16 o_buf, U8 *buf, T_CCD_Globs *globs) +{ +#if defined (DEBUG_CCD) + /* to avoid the vsprintf if the traces won't appear anyhow */ + ULONG mask; + if (vsi_gettracemask (globs->me, globs->me, &mask) != VSI_ERROR) + { + globs->TraceIt = mask & TC_CCD; + } +#endif + + /* + * no call to setjmp() done. So ccd_Error performs no longjmp in + * case of an error + */ + globs->jmp_mark_set = FALSE; + + /* setup the bitbuffer */ + globs->bitbuf = buf; + globs->bitpos = 0; + + /* cleanup the read-caches */ + globs->lastbytepos16 = globs->lastbytepos32 = 0xffff; + + /* setup the bitoffset */ + globs->bitoffs = o_buf; + + + bf_incBitpos (o_buf, globs); + + /* + * calclate the max bitpos to read + */ + globs->buflen = l_buf + o_buf; + globs->maxBitpos = globs->buflen; + globs->msgLen = globs->buflen; + globs->errLabel = 0; + globs->continue_array = TRUE; + globs->SeekTLVExt = TRUE; + + globs->ccd_recurs_level = 0; + globs->CCD_Error = ccdOK; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* + * Attention: if this static function shall be used in + * both, internal as well as external RAM, it must be made global. + */ +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : SeekForGSMExtensions | ++--------------------------------------------------------------------+ + + PURPOSE: Check if there are elements left in the air message + without being decoded. Assume that the next IE has the + type T, TV or a TLV. Seek for Comprehension Required + extensions. + 1) Rules to distinguish between the types: + handling of unknown IEs (GSM 04.07, section 11.2.4) + "Bit 8 of the IEI octet is set to "1" indicates a TV + formatted type 1 standard IE or a T formatted type 2 + IEs, and to "0" indicates a TLV formatted type 4 IE. + Hence, a 1 valued bit 8 indicates that the whole IE is + one octet long, and a 0 valued bit 8 indicates that the + following octet is a length octet. + 1) Rules to read the length: + For TLV4 encode L in one byte. + For TLV5 and ASN.1 encode in one byte or more. Use + 0x81, 0x82 etc in the first byte to say L is encoded + in one, two etc bytes. + For ASN.1 BER type use 0x80 in the first byte and + two otets of 0 bits after the encoded IE. + For all the three types it is possible to encode L + in only one byte. + TLV6 is not supported. TLV6 is not a GSM standard + type. It has been defined in g23net software. +*/ +static void SeekForGSMExtensions (U8 entity, T_CCD_Globs *globs) +{ + U8 *MsgBuf = (U8*)globs->bitbuf; + U16 BP = globs->bytepos; + U16 OctNr = (globs->buflen+7) >> 3; + U16 errPos = 0; + U8 errTag = 0xFF; + U8 errCode; + +#ifdef DEBUG_CCD + TRACE_CCD( globs, "SeekForGSMExtensions..."); +#endif + while (BP < OctNr) + { + U8 T = MsgBuf[BP]; + BOOL tlv5 = FALSE; + + /* Expecting a CCDTYPE_GSM5_TLV type we get an unknown tag with MSB set. + * Expecting other types than CCDTYPE_GSM5_TLV we get an unknown tag with + * comprehension required bits (5, 6, 7 and 8 of IEI according to GSM0407) + * are set to zero. + */ + tlv5 = (aim_sat == entity); + if ( (tlv5 && ((T & 0x80) == 0x80)) + || + (!tlv5 && ((T & 0xf0) == 0)) ) + { + errTag = T; + errPos = BP*8; + errCode = ERR_COMPREH_REQUIRED; + /* Report error. Do not analyse the rest. */ + break; + } + else + { + errTag = T; + errPos = BP*8; + errCode = ERR_IE_NOT_EXPECTED; + } + + /* The type is TLV or ASN.1. */ + if ((T & 0x80) NEQ 0x80) + { + /* BP points to the first L byte */ + U16 L = MsgBuf[++BP]; + switch (L) + { + /* End Of Content (ASN.1 BER) */ + case 0x80: + do + { + BP++; + } while ((*(U16*)&MsgBuf[BP]) != 0 && BP < OctNr); + BP++; + L = 0; + break; + + /* Length encoding in two bytes */ + case 0x81: + L = MsgBuf[++BP]; + break; + + /* Length encoding in three bytes */ + case 0x82: + L = (MsgBuf[++BP]) << 8; + L |= MsgBuf[++BP]; + break; + + /* Length encoding in one byte. */ + default: + break; + } + + /* Skip over the bytes. */ + while (L > 0 && BP < OctNr) + { + --L; + ++BP; + } + + } /* if TLV */ + /* else: The type is T or TV. Skip one byte (see next step). */ + + /* + * BP points to the last byte of the skipped IE, + * move to the next IE. + */ + BP++; + }/* while bytes left unread */ + + /* Report the summary of the found erros. */ + if (errTag != 0xFF) + { + ccd_setError (globs, errCode, + (U8)((errCode == ERR_COMPREH_REQUIRED) ? BREAK : CONTINUE), + errTag, + errPos, + (USHORT) -1); + } +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_decodeMsg | ++--------------------------------------------------------------------+ + + + PARAMETERS: UBYTE entity + - specifies the calling entity of CCD. The Constants + for each valid entity is defined in MCONST.CDG + + UBYTE direction + - specifies wether the message goes UPLINK or DOWNLINK. + This is nessesary because there are same PDU-Type + codes for different messages. + + T_MSGBUF * mBuf + - specifies the bitstream buffer of the message. The + struct contains the l_buf and the o_buf elements. + These elements specifies the length and offset in bits + of the bitstream in the T_MSGBUF component buf. + + UBYTE * mStruct + - reference to the C-Structure of the decoded message. + The type may differ so the Pointer is always typed as + UBYTE* and must be casted after decoding. If this parameter + is NULL CCD uses his internal buffer wich must be + protected via ccd_begin() in a multithread environment. + + UBYTE mId + - specifies the PDU-Type of the bitstream. If this + parameter is not equal 0xff the CCD does not decode + the pdu-type from the bitstream to decide wich decoding + rules to select. Normaly this param is set to 0xff. + + PURPOSE: decodes a bitstream, containing a valid TETRA-Message + of the Air-Interface to a corresponding C-Structure. + +*/ + +BYTE CCDDATA_PREF(ccd_decodeMsg) (UBYTE entity, + UBYTE direction, + T_MSGBUF *mBuf, + UBYTE *mStruct, + UBYTE mId) +{ + UBYTE theMsgId; + USHORT mcompRef; + int jmp_ret; + T_CCD_Globs *globs; + T_CCD_ERR_LIST_HEAD* eentry; + T_CCD_STORE_LIST* stoentry; + + globs = ccd_GetGlobVars (&eentry, &stoentry); + + /* + * setup the structure-buffer + * + * if the parameter of the decoded message buffer address is NULL + * we use the internal one + */ + globs->pstruct = (mStruct EQ NULL) ? ccd_decMsgBuffer : mStruct; + globs->pstructOffs = 0; + + ccd_common_decode_init(mBuf->l_buf, mBuf->o_buf, mBuf->buf, globs); + ccd_err_reset (eentry); + globs->errLabel = 0; + globs->continue_array = TRUE; + + #ifdef DEBUG_CCD + ccd_dump_msg(mBuf->l_buf, mBuf->o_buf, mBuf->buf, globs); + #endif + + if (mId NEQ 0xff AND mId NEQ 0xfe) + globs->pstruct[0] = theMsgId = mId; + else + { + /* Read the message identifier */ + globs->pstruct[0] = bf_decodeByteNumber ((ULONG) mi_length[entity], globs); + theMsgId = globs->pstruct[0]; + } + + /* Get entry in mmtx table for this message */ + mcompRef = ccddata_get_mmtx(entity,theMsgId,direction); + + /* Check the message identifier */ + if (theMsgId > max_message_id OR mcompRef EQ NO_REF) + { + #ifdef ERR_TRC_STK_CCD + globs->ccd_recurs_level = 255; + #endif /* ERR_TRC_STK_CCD */ + ccd_setError (globs, ERR_INVALID_MID, BREAK, + (USHORT) theMsgId, (USHORT) -1); + ccd_FreeGlobVars (globs); + ccd_err_free (eentry); + return (BYTE)globs->CCD_Error; + } + #ifdef ERR_TRC_STK_CCD + /* save the value for tracing in error case */ + globs->error_stack[0] = mcompRef; + #endif /* ERR_TRC_STK_CCD */ + + #ifdef DEBUG_CCD + #ifdef CCD_SYMBOLS + TRACE_CCD (globs, "CCD decode: Message = %s", + mcomp[mcompRef].name); + #else + TRACE_CCD (globs, "CCD decode: MessageId = %x", theMsgId); + #endif + #endif + + /* + * Clean up the entite C-structure before decoding. + * Do not overwrite the MsgId (1. Byte) + */ + #ifdef DEBUG_CCD + TRACE_CCD (globs, "CCD Cleaning struct %ld bytes", + mcomp[mcompRef].cSize-1); + #endif + memset ((UBYTE *) &globs->pstruct[1], 0, + (size_t)(mcomp[mcompRef].cSize - 1)); + + /* + * clear the UPN stack + */ + ST_CLEAR(globs); + memset ((ULONG *) &(globs->KeepReg[0]), 0, MAX_KEEP_REG_SIZE); + + /* + * inform the GSM-CODEC about the begin of a new message + */ + cdc_GSM_start (globs); + + jmp_ret = setjmp (globs->jmp_mark); + + if (jmp_ret EQ 0) + { + globs->jmp_mark_set = TRUE; + ccd_decodeComposition ((ULONG) mcompRef, globs); + + /* + * The coding rules and the data tables must be able to lead CCD to + * understand the bit buffer, element by element. If for some reason + * the bit pointer points to a place after the message limit, the + * encoding action is not trustworthy. Nevertheless CCD reports a + * WARNING and not error. + * In development phase it is helpful to detect such cases. + * Otherwise the caller can supposedly still use the message. + */ + if (globs->bitpos > globs->buflen) + { + ccd_recordFault (globs, ERR_MSG_LEN, CONTINUE, mcompRef, NULL); + } + /* + * Seek for GSM extensions with types T, TV and TLV. + * (GRR, RCM/RRC and RRLP assume other extension mechanisms.) + * Check only at octet border. + */ + else if ((globs->SeekTLVExt) && !globs->byteoffs) + { + SeekForGSMExtensions (entity, globs); + } + } + + + #ifdef DEBUG_CCD + TRACE_CCD (globs, "CCD-ERROR = %d", globs->CCD_Error); + TRACE_CCD (globs, "-------------------------------------------------"); + #endif /* DEBUG_CCD */ + + ccd_FreeGlobVars (globs); + ccd_err_free (eentry); + + return (BYTE) globs->CCD_Error; + } /* end ccd_decodeMsg () */ +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH + /* + +--------------------------------------------------------------------+ + | PROJECT : CCD (6144) MODULE : CCD | + | STATE : code ROUTINE : ccd_decodeMsgPtr | + +--------------------------------------------------------------------+ + + + PARAMETERS: U8 entity + - specifies the calling entity of CCD. The Constants + for each valid entity is defined in MCONST.CDG + + U8 direction + - specifies wether the message goes UPLINK or DOWNLINK. + This is nessesary because there are same PDU-Type + codes for different messages. + + U16 l_buf + - Lenght of the bitstrem to be decoded. + + U16 o_buf + - specifies the bitstream buffer of the message. The + struct contains the l_buf and the o_buf elements. + These elements specifies the length and offset in bits + of the bitstream in the T_MSGBUF component buf. + + U8 *buf + - specifies the bitstream buffer of the message. + + U8 ** mStructPtr + - points to the pointer on the C-structure of the + decoded message. The buffer containing this message + structure will be allocated by CCD. After decoding + the first element in the message C-structure contains + the message (PDU) type as a UBYTE. + + U8 mId + - specifies the PDU-Type of the bitstream. If this + parameter is not equal 0xff the CCD does not decode + the pdu-type from the bitstream to decide wich decoding + rules to select. Normaly this param is set to 0xff. + + PURPOSE: Like ccd_decodeMsg, this function decodes a bitstream + containing a valid TETRA-Message from the Air-Interface + to a corresponding C-Structure, only this function + allows the use of pointer types in the C-structure. + + */ + #if defined DYNAMIC_ARRAYS || defined _TOOLS_ +S8 CCDDATA_PREF(ccd_decodeMsgPtr) (U8 entity, + U8 direction, + U16 l_buf, + U16 o_buf, + U8* buf, + U8** mStructPtr, + U8 mId) +{ + /* + * Make a dummy for the DLLs, even if DYNAMIC_ARRAYS is not defined to + * keep the ccd.def unique + */ + #ifndef DYNAMIC_ARRAYS + return -1; +} + #else /* DYNAMIC_ARRAYS */ + UBYTE theMsgId; + int jmp_ret; + U32 msgsize; + USHORT mcompRef; + T_CCD_Globs *globs; + T_CCD_ERR_LIST_HEAD* eentry; + T_CCD_STORE_LIST* stoentry; + + globs = ccd_GetGlobVars (&eentry, &stoentry); + ccd_common_decode_init(l_buf, o_buf, buf, globs); + ccd_err_reset (eentry); + globs->errLabel = 0; + globs->continue_array = TRUE; + globs->alloc_head = *mStructPtr = NULL; + + #ifdef DEBUG_CCD + TRACE_CCD( globs, "======================================================"); + TRACE_CCD( globs, "ccd_decodeMsgPtr: Decoding message with pointer types."); + ccd_dump_msg(l_buf, o_buf, buf, globs); + #endif + + /* Read the message identifier. */ + if (mId NEQ 0xff AND mId NEQ 0xfe) + theMsgId = mId; + else + theMsgId = bf_decodeByteNumber ((ULONG) mi_length[entity], globs); + + /* Get the entry in mmtx table for this message */ + mcompRef = ccddata_get_mmtx (entity,theMsgId,direction); + + /* Check the validity of the message identifier */ + if (theMsgId > max_message_id OR mcompRef EQ NO_REF) + { + #ifdef ERR_TRC_STK_CCD + globs->ccd_recurs_level = 255; + #endif /* ERR_TRC_STK_CCD */ + ccd_setError (globs, ERR_INVALID_MID, BREAK, (USHORT) theMsgId, (USHORT) -1); + ccd_FreeGlobVars (globs); + ccd_err_free (eentry); + return (BYTE) globs->CCD_Error; + } + + #ifdef ERR_TRC_STK_CCD + /* save the value for tracing in error case */ + globs->error_stack[0] = mcompRef; + #endif /* ERR_TRC_STK_CCD */ + + #ifdef DEBUG_CCD + #ifdef CCD_SYMBOLS + TRACE_CCD (globs, "CCD decode: Message = %s", + mcomp[mcompRef].name); + #else + TRACE_CCD (globs, "CCD decode: MessageId = %x", theMsgId); + #endif + #endif + + /* + * Setup the structure-buffer. + * Make a first simple estimation of much memory to allocate. + * It is twice as much as the air interface message, rounded up + * to the nearest kilobyte boundary. + */ + msgsize = mcomp[mcompRef].cSize; + + #ifdef DEBUG_CCD + TRACE_CCD( globs, "Allocating %ld bytes for msg.", msgsize); + #endif + + globs->alloc_head = (U8 *) DRP_ALLOC(msgsize, DP_NO_FRAME_GUESS); + + if (globs->alloc_head == NULL) + { + ccd_setError (globs, ERR_NO_MEM, BREAK, (USHORT) theMsgId, (USHORT) -1); + ccd_FreeGlobVars (globs); + ccd_err_free (eentry); + return (BYTE) globs->CCD_Error; + } + *mStructPtr = globs->alloc_head; + globs->pstruct = globs->alloc_head; + globs->pstructOffs = 0; + + /*Write the MSG ID in the buffer*/ + globs->pstruct[0] = theMsgId; + + /* + * Clean up the entite C-structure before decoding. + * Do not overwrite the MsgId (1. Byte) + */ + #ifdef DEBUG_CCD + TRACE_CCD (globs, "CCD Cleaning struct %ld bytes", mcomp[mcompRef].cSize); + #endif + memset ((U8 *)globs->pstruct, 0, (size_t)(msgsize)); + + /* + * Write the message identifier into the C-structure. + */ + globs->pstruct[0] = theMsgId; + + /* + * clear the UPN stack + */ + ST_CLEAR(globs); + memset ((ULONG *) &(globs->KeepReg[0]), 0, MAX_KEEP_REG_SIZE); + + /* + * inform the GSM-CODEC about the begin of a new message + */ + cdc_GSM_start (globs); + + jmp_ret = setjmp (globs->jmp_mark); + + if (jmp_ret EQ 0) + { + globs->jmp_mark_set = TRUE; + ccd_decodeComposition ((ULONG) mcompRef, globs); + if (globs->byteoffs NEQ 0) + { + bf_incBitpos (8-globs->byteoffs, globs); + + /* There are more bits to be decoded than ccddata expects. + * The additional bits may belong to unknown non-critical extensions. + */ + if (globs->bitpos > globs->buflen) + { + ccd_recordFault (globs, ERR_UNEXPECT_PAD, CONTINUE, mcompRef, NULL); + } + /* + * Seek for GSM extensions with types T, TV and TLV. + * (GRR, RCM/RRC and RRLP assume other extension mechanisms.) + * Check only at octet border. + */ + else if ((entity != aim_rrc_rcm) + && (entity != aim_rrlp) + && (globs->SeekTLVExt) + && !globs->byteoffs) + { + SeekForGSMExtensions (entity, globs); + } + } + else + { + if (globs->bitpos > globs->buflen) + { + ccd_recordFault (globs, ERR_MSG_LEN, CONTINUE, mcompRef, NULL); + } + /* + * Seek for GSM extensions with types T, TV and TLV. + * (GRR, RCM/RRC and RRLP assume other extension mechanisms.) + * Check only at octet border. + */ + else if ((entity != aim_rrc_rcm) + && (entity != aim_rrlp) + && (globs->SeekTLVExt) + && !globs->byteoffs) + { + SeekForGSMExtensions (entity, globs); + } + } + } + + #ifdef DEBUG_CCD + TRACE_CCD (globs, "CCD-ERROR = %d", globs->CCD_Error); + TRACE_CCD (globs, "-----------------------------------------------------"); + #endif /* DEBUG_CCD */ + + ccd_FreeGlobVars (globs); + ccd_err_free (eentry); + + return (BYTE) globs->CCD_Error; +} /* end ccd_decodeMsgPtr () */ + #endif /* !DYNAMIC_ARRAYS */ + #endif /* DYNAMIC_ARRAYS || _TOOLS_ */ +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH + /* + +--------------------------------------------------------------------+ + | PROJECT : CCD (6144) MODULE : CCD | + | STATE : code ROUTINE : ccd_codeMsgPtr | + +--------------------------------------------------------------------+ + + PARAMETERS: UBYTE entity + - specifies the calling entity of CCD. The Constants + for each valid entity is defined in MCONST.CDG + + UBYTE direction + - specifies wether the message goes UPLINK or DOWNLINK. + This is nessesary because there are same PDU-Type + codes for different messages. + + T_MSGBUF * mBuf + - specifies the bitstream buffer of the message. The + struct contains the l_buf and the o_buf elements. + These elements specifies the length and offset in bits + of the bitstream in the T_MSGBUF component buf. + The o_buf component must be specified by the caller, + the l_buf component is calculated by CCD. + + UBYTE * mStruct + - reference to the C-Structure containing the + C-Representation of the decoded message. + The type should be casted to UBYTE*. If this parameter + is NULL CCD uses his internal buffer wich must be + protected via ccd_begin() in a multithread environment. + + UBYTE mId + - specifies the PDU-Type of the bitstream. If this + parameter is not equal 0xff the CCD does not read + the pdu-type from the structure component pt + to decide wich decoding rules to select. + Normaly this param is set to 0xff. + + PURPOSE: encodes a C-Structure containing the C-Representation of + a valid Air-interface message to a bitstream. + + */ + +S8 CCDDATA_PREF(ccd_codeMsgPtr)(U8 entity, + U8 direction, + U16* l_buf, + U16 o_buf, + U8 *buf, + U8* mStruct, + U8 mId) +{ + UBYTE theMsgId; + int jmp_ret; + USHORT maxBytes, mcompRef; + T_CCD_Globs *globs; + T_CCD_ERR_LIST_HEAD* eentry; + T_CCD_STORE_LIST* stoentry; + + globs = ccd_GetGlobVars (&eentry, &stoentry); + ccd_err_reset (eentry); + + #if defined (DEBUG_CCD) + { + /* to avoid the vsprintf if the traces won't appear anyhow */ + ULONG mask; + if (vsi_gettracemask (globs->me, globs->me, &mask) != VSI_ERROR) + { + globs->TraceIt = mask & TC_CCD; + } + } + #endif + + /* + * Set a sign that no call to setjmp() is done. So ccd_setError + * performs no longjmp in case of an error. + */ + globs->jmp_mark_set = FALSE; + + /* Setup the bitbuffer. */ + globs->bitbuf = buf; + globs->bitpos = 0; + + /* and the structure-buffer */ + globs->pstruct = (mStruct EQ NULL) ? ccd_decMsgBuffer : mStruct; + globs->pstructOffs = 0; + + /* Cleanup the read-caches. */ + globs->lastbytepos16 = globs->lastbytepos32 = 0xffff; + + /* Setup the bitoffset. */ + globs->bitoffs = o_buf; + + + bf_incBitpos (o_buf, globs); + + globs->bitbuf[globs->bytepos] = 0; + + globs->ccd_recurs_level = 0; + + globs->CCD_Error = ccdOK; + + globs->continue_array = TRUE; + + if (mId NEQ 0xff AND mId NEQ 0xfe) + theMsgId = mId; + else + { + theMsgId = globs->pstruct[0]; + } + + mcompRef = ccddata_get_mmtx(entity,theMsgId,direction); + /* Check the validity of the given message identifier. */ + if (theMsgId > max_message_id OR mcompRef EQ NO_REF) + { + #ifdef ERR_TRC_STK_CCD + globs->ccd_recurs_level = 255; + #endif /* ERR_TRC_STK_CCD */ + ccd_setError (globs, ERR_INVALID_MID, BREAK, (USHORT) theMsgId, (USHORT) -1); + ccd_FreeGlobVars (globs); + ccd_err_free (eentry); + return (BYTE) globs->CCD_Error; + } + + #ifdef ERR_TRC_STK_CCD + /* save the value for tracing in error case */ + globs->error_stack[0] = mcompRef; + #endif /* ERR_TRC_STK_CCD */ + + maxBytes = (*l_buf + 7)>>3; + globs->msgLen = *l_buf; + + #ifdef DEBUG_CCD + TRACE_CCD (globs, "-------------------------------------------------"); + TRACE_CCD (globs, "CCD: Code Message"); + TRACE_CCD (globs, "Cleaning %d bits (%d bytes) of the bitstream", + mcomp[mcompRef].bSize, maxBytes); + #endif + + /* + * Clean up the bit buffer for the encoded message before encoding. + */ + memset ((U8 *) &buf[(o_buf>>3)], 0, (size_t) maxBytes); + /* Store the length of ereased buffer to support error handling. */ + globs->buflen = *l_buf; + + if (mId EQ 0xff) + { + /* Write the message identifier. */ + bf_writeBits ((U32)mi_length[entity], globs); + } + + #ifdef DEBUG_CCD + #ifdef CCD_SYMBOLS + TRACE_CCD (globs, "CCD encode: Message = %s", mcomp[mcompRef].name); + #else + TRACE_CCD (globs, "CCD encode: MessageId = %x", theMsgId); + #endif + #endif + + /* + * Clear the UPN stack. + */ + ST_CLEAR(globs); + memset ((ULONG *) &(globs->KeepReg[0]), 0, MAX_KEEP_REG_SIZE); + + /* + * Inform the GSM-CODEC about the begin of a new message. + */ + cdc_GSM_start (globs); + + jmp_ret = setjmp (globs->jmp_mark); + + if (jmp_ret EQ 0) + { + /* + * no call to setjmp() done. So ccd_Error performs no longjmp in + * case of an error + */ + globs->jmp_mark_set = TRUE; + ccd_encodeComposition ((ULONG) mcompRef, globs); + if (globs->bitpos > o_buf + *l_buf) + { + ccd_setError (globs, ERR_BUFFER_OF, CONTINUE, (USHORT) -1); + } + bf_writePadBits (globs); + } + + *l_buf = (USHORT) globs->bitpos - (USHORT) o_buf; + + #ifdef DEBUG_CCD + { + int i, j, buflen; + char s[64], c[4]; + + buflen = (*l_buf + o_buf + 7) >> 3; + + TRACE_CCD (globs, "-------------------------------------------------"); + TRACE_CCD (globs, " After ENCODING: lbuf= %d, obuf= %d", *l_buf, o_buf); + TRACE_CCD (globs, " Hex dump of encoded message:"); + + s[0] = '\0'; + for (i = o_buf >> 3; i < buflen; i+=16) + { + for (j = 0; j < 16; j++) + { + if ((i+j) < buflen) + { + sprintf(c, " %02x", buf[i+j]); + strcat (s, c); + } + } + TRACE_CCD (globs, "%s", s); + s[0] = '\0'; + } + } + #endif + + #ifdef DEBUG_CCD + TRACE_CCD (globs, "CCD-ERROR = %d", globs->CCD_Error); + TRACE_CCD (globs, "-------------------------------------------------"); + #endif + + ccd_FreeGlobVars (globs); + ccd_err_free (eentry); + + return (BYTE)globs->CCD_Error; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH + /* + +--------------------------------------------------------------------+ + | PROJECT : CCD (6144) MODULE : CCD | + | STATE : code ROUTINE : ccd_codeMsg | + +--------------------------------------------------------------------+ + + PARAMETERS: UBYTE entity + - specifies the calling entity of CCD. The Constants + for each valid entity is defined in MCONST.CDG + + UBYTE direction + - specifies wether the message goes UPLINK or DOWNLINK. + This is nessesary because there are same PDU-Type + codes for different messages. + + T_MSGBUF * mBuf + - specifies the bitstream buffer of the message. The + struct contains the l_buf and the o_buf elements. + These elements specifies the length and offset in bits + of the bitstream in the T_MSGBUF component buf. + The o_buf component must be specified by the caller, + the l_buf component is calculated by CCD. + + UBYTE * mStruct + - reference to the C-Structure containing the + C-Representation of the decoded message. + The type should be casted to UBYTE*. If this parameter + is NULL CCD uses his internal buffer wich must be + protected via ccd_begin() in a multithread environment. + + UBYTE mId + - specifies the PDU-Type of the bitstream. If this + parameter is not equal 0xff the CCD does not read + the pdu-type from the structure component pt + to decide wich decoding rules to select. + Normaly this param is set to 0xff. + + PURPOSE: encodes a C-Structure containing the C-Representation of + a valid Air-interface message to a bitstream. + + */ + +BYTE CCDDATA_PREF(ccd_codeMsg) (UBYTE entity, + UBYTE direction, + T_MSGBUF *mBuf, + UBYTE *mStruct, + UBYTE mId) +{ + return CCDDATA_PREF(ccd_codeMsgPtr) (entity, direction, &mBuf->l_buf, + mBuf->o_buf, mBuf->buf, mStruct, mId); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++------------------------------------------------------------------------------ +| Function : ccd_init_ccddata ++------------------------------------------------------------------------------ +| Description : Initialize local tables. +| +| Parameters : - +| +| Return : ccdOK, ccdWarning, or ccdError depending on the success. ++------------------------------------------------------------------------------ +*/ +ULONG CCDDATA_PREF(ccd_init_ccddata) (void) +{ + const T_CCD_CompTabEntry *msg; + USHORT mcompRef; + UBYTE ret, entity, num_of_entities; + USHORT messageId; +#ifdef DEBUG_CCD + T_CCD_Globs *globs = &globs_all; +#endif + + aim_rrc_rcm = (U8)ccddata_get_ccdent ("UMTS_AS_ASN1_MSG"); + aim_rrlp = (U8)ccddata_get_ccdent ("RRLP_ASN1_MSG"); + aim_sat = (U8)ccddata_get_ccdent ("SAT"); + + mcomp = ccddata_get_mcomp (0); + mvar = ccddata_get_mvar (0); + mval = ccddata_get_mval (0); + melem = ccddata_get_melem (0); + spare = ccddata_get_spare (0); + calc = ccddata_get_calc (0); + calcidx = ccddata_get_calcidx (0); + + mi_length = ccddata_get_mi_length(); + ccd_decMsgBuffer = ALIGN_BUF(ccddata_get_decmsgbuffer()); + max_message_id = (USHORT) ccddata_get_max_message_id(); + +#ifdef CCD_SYMBOLS + if (!ccddata_mccd_symbols()) + { +#ifdef CCD_TEST + printf ("CCD_SYMBOLS is not set in ccddata\n"); +#else /* CCD_TEST */ + vsi_o_assert( VSI_CALLER OS_SYST_ERR, __FILE__, __LINE__, + "CCD_SYMBOLS is not set in ccddata" ); +#endif /* CCD_TEST */ + } + +#else /* CCD_SYMBOLS */ + if (ccddata_mccd_symbols()) + { +#ifdef CCD_TEST + printf ("Undefine CCD_SYMBOLS in ccddata\n"); +#else /* CCD_TEST */ + vsi_o_assert( VSI_CALLER OS_SYST_ERR, __FILE__, __LINE__, + "Undefine CCD_SYMBOLS in ccddata" ); +#endif /* CCD_TEST */ + } +#endif /* CCD_SYMBOLS */ + +#ifdef DEBUG_CCD + /* Only for TRACE_CCD call in ccd_init. */ + globs->me = 0; + globs->TraceIt = 1; +#endif /* DEBUG_CCD */ + + num_of_entities = (UBYTE) ccddata_get_num_of_entities(); + for (entity = 0; entity < num_of_entities; entity++) + { + /* + * Point to the first defined Message, to get the length + * of the message identifier + */ + msg = NULL; + messageId = 0; + while (msg EQ NULL AND messageId <= max_message_id) + { + /* + * If there is no UPLINK-decoding, try the DOWNLINK. + */ + if ((mcompRef = ccddata_get_mmtx(entity, messageId, UPLINK)) NEQ NO_REF) + msg = (T_CCD_CompTabEntry *) &mcomp[mcompRef]; + else + if ((mcompRef = ccddata_get_mmtx(entity, messageId, DOWNLINK)) NEQ NO_REF) + msg = (T_CCD_CompTabEntry *) &mcomp[mcompRef]; + else + messageId++; + } + if (msg NEQ NULL + AND melem[msg->componentRef].elemType EQ 'V' + AND melem[msg->componentRef].elemRef NEQ NO_REF) + { + /* + * if there is a message for this layer - get the length + * of the first element (msg_type or pdu_type) + */ + mi_length[entity] =(UBYTE) (mvar[melem[msg->componentRef].elemRef].bSize); + } + else + mi_length[entity] = 0; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "MI-LEN [ENTITY %d] = %d", entity, mi_length[entity]); +#endif + } + + /* + * Register all needed coding/decoding functions in the jump table. + */ + ret = cdc_init (codec); + + if (ret EQ ccdError) + return ccdError; + +#ifdef DEBUG_CCD + if (ret EQ ccdWarning) + { + TRACE_CCD (globs, "CCD: Mismatch between CCD and CCDDATA. Check the codec list.");//return ccdWarning; + } +#endif + + return ccdOK; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++------------------------------------------------------------------------------ +| Function : ccd_signup ++------------------------------------------------------------------------------ +| Description : This function sets up the local CCD data for the calling +| entity. +| +| Parameters : ccd_reg - set if called by ccd_register, not set if called +| by ccd_init +| decmsgbuf_size - further enhancement: size of the entity's +| decoded msg buffer size +| +| Return : ccdErr or ccdOK depending on the success ++------------------------------------------------------------------------------ +*/ + +static int ccd_signup (int ccd_reg, int decmsgbuf_size) +{ +#ifndef _TOOLS_ + UBYTE ret; +#endif + #ifdef SHARED_CCD + T_HANDLE me; + #else + int me = 0; + #endif + T_CCD_TASK_TABLE* tentry; + +#ifdef SHARED_CCD + me = vsi_e_handle (0, NULL); + if (me == VSI_ERROR) + { + me = 0; + tentry = ccd_task_list[0] = &task_null; + task_null.ccd_globs = &globs_all; +#ifdef DEBUG_CCD + TRACE_CCD (&globs_all, "Ccd initialization: task could not be identified. Try to continue with a non reentrant init"); +#endif + } + else + { + if (!ccd_task_list[me]) + { + ccd_task_list[me] = D_ALLOC (sizeof (T_CCD_TASK_TABLE)); + if (!ccd_task_list[me]) + { + vsi_o_assert( VSI_CALLER OS_SYST_ERR, __FILE__, __LINE__, + "Could not allocate memory for ccd task table entry" ); + } + else + { + ccd_task_list[me]->ccd_globs = NULL; + ccd_task_list[me]->ccd_err_list = NULL; + ccd_task_list[me]->ccd_store = NULL; + } + } + tentry = ccd_task_list[me]; + tentry->decmsgbuf = NULL; + if (ccd_reg) + { + if (!tentry->ccd_globs) + { + if (decmsgbuf_size != CCD_REENTRANT) + { +#ifdef DEBUG_CCD + TRACE_CCD (tentry->ccd_globs, "Ccd_register (task %d): ignore %d for parameter decmsgbuf_size. Make non reentrant ccd_init instead.", me, decmsgbuf_size); +#endif + tentry->ccd_globs = &globs_all; + } + else + { + tentry->ccd_globs = D_ALLOC (sizeof(T_CCD_Globs)); + if (!tentry->ccd_globs) + { + vsi_o_assert( VSI_CALLER OS_SYST_ERR, __FILE__, __LINE__, + "Could not allocate memory for ccd_globs" ); + } + } + } + } + else + { + tentry->ccd_globs = &globs_all; + } + } +#else /* SHARED_CCD */ + tentry = ccd_task_list[0] = &task_null; + task_null.ccd_globs = &globs_all; +#endif + + tentry->ccd_globs->me = me; + if (ccd_err_init (&tentry->ccd_err_list)) + { + #ifdef CCD_TEST + printf ("Cannot initialize error list: out of memory\n"); + #else /* CCD_TEST */ + vsi_o_assert( VSI_CALLER OS_SYST_ERR, __FILE__, __LINE__, + "Cannot initialize error list: out of memory" ); + #endif /* CCD_TEST */ + return ccdError; + } + + if (ccd_store_init (&tentry->ccd_store)) + { +#ifdef CCD_TEST + printf ("Cannot initialize store register: out of memory\n"); +#else /* CCD_TEST */ + vsi_o_assert( VSI_CALLER OS_SYST_ERR, __FILE__, __LINE__, + "Cannot initialize store register: out of memory" ); +#endif /* CCD_TEST */ + return ccdError; + } + + if (!initialized) + { +#ifdef SHARED_CCD + /* + * if the CCD is used in a premptive multithreaded system + * we must create a semaphore for the coding and decoding + */ + semCCD_Codec = vsi_s_open (VSI_CALLER "CCD_COD",1); + semCCD_Buffer = vsi_s_open (VSI_CALLER "CCD_BUF",1); + +#endif /* SHARED_CCD */ + +#ifndef _TOOLS_ + ret = (UBYTE)ccd_init_ccddata (); + if (ret != ccdOK) + return ret; + +#endif /* !_TOOLS_ */ + initialized = TRUE; + /* save memory init pattern */ + mempat = (U8*) CCDDATA_PREF(ccd_get_numFaults ()); + } + return ccdOK; +} + +BYTE CCDDATA_PREF(ccd_init) (void) +{ + return (BYTE) ccd_signup (0, 0); +} + +/* ++------------------------------------------------------------------------------ +| Function : ccd_register ++------------------------------------------------------------------------------ +| Description : This function sets up the local CCD data for the calling +| entity. +| Entities calling this function with a parameter 0 will +| get an own set of CCD local data, i.e., they don't have to +| synchronize with other entities to use CCD. +| +| Parameters : decmsgbuf_size - further enhancement: size of the entity's +| decoded msg buffer size +| +| Return : ccdErr or ccdOK depending on the success ++------------------------------------------------------------------------------ +*/ + +int ccd_register (int decmsgbuf_size) +{ + return ccd_signup (1, decmsgbuf_size); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_exit | ++--------------------------------------------------------------------+ + + PURPOSE: performs a shutdown of CCD. + +*/ + +int CCDDATA_PREF(ccd_exit) (void) +{ +#ifdef SHARED_CCD + T_CCD_TASK_TABLE* tentry; + T_HANDLE me = vsi_e_handle (0, NULL); + if (me == VSI_ERROR) + return ccdError; + tentry = ccd_task_list[me]; + if (tentry->ccd_globs && (tentry->ccd_globs != &globs_all)) + { + D_FREE (tentry->ccd_globs); + tentry->ccd_globs = 0; + } + ccd_store_exit(); + ccd_err_exit (); + D_FREE (ccd_task_list[me]); + ccd_task_list[me] = NULL; +#else + ccd_store_exit(); + ccd_err_exit (); +#endif /* SHARED_CCD */ + return ccdOK; +} +#endif /* !RUN_FLASH */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccd.h Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,413 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccd.h ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Condat Coder Decoder +| Global function prototypes ++----------------------------------------------------------------------------- +*/ + + +#ifndef CCD_H +#define CCD_H + +/* Start addresses of ccddata tables */ +#ifndef CCD_C +extern const T_CCD_VarTabEntry* mvar; +extern const T_CCD_SpareTabEntry* spare; +extern const T_CCD_CalcTabEntry* calc; +extern const T_CCD_CompTabEntry* mcomp; +extern const T_CCD_ElemTabEntry* melem; +extern const T_CCD_CalcIndex* calcidx; +extern const T_CCD_ValTabEntry* mval; +#endif /* !CCD_C */ + +/* + * Chain of error information. + */ +typedef struct ccd_error_list +{ + T_CCD_ERR_ENTRY entry; + struct ccd_error_list *next; +} T_CCD_ERR_LIST; + +/* + * Head of the error information chain. + */ +typedef struct ccd_err_list_head +{ + T_CCD_ERR_LIST *first_error; + T_CCD_ERR_LIST **act_error; + int num_errors; +} T_CCD_ERR_LIST_HEAD; + +typedef struct ccd_store_list +{ + ULONG store[3]; + /* for future use to extend register capacity */ + /* T_CCD_STORE_LIST *next; */ +} T_CCD_STORE_LIST; + +/* + * CCD list of all tasks + */ +typedef struct ccd_task_table +{ + T_CCD_Globs* ccd_globs; + U8* decmsgbuf; + T_CCD_ERR_LIST_HEAD* ccd_err_list; + T_CCD_STORE_LIST* ccd_store; +} T_CCD_TASK_TABLE; + +/* + * Macros for forcing n-byte aligned addresses to byte arrays + */ +#ifndef BUFFER_ALIGNMENT + #define BUFFER_ALIGNMENT 3 +#endif + +#define ALIGN_BUF(uabuf) (UBYTE*) ((((U32)uabuf) + BUFFER_ALIGNMENT) & \ + (~BUFFER_ALIGNMENT)) + +/* + * Error behaviour to use with ccd_setError() + */ +#ifdef BREAK +#undef BREAK +#endif + +#define BREAK 0 +#define CONTINUE 1 + +#define END_OF_COMPOSITION 0x7e + +/* + * Functions defined in ccd.c + */ +EXTERN BOOL ccd_conditionOK (const ULONG e_ref, + T_CCD_Globs *globs); + +EXTERN BOOL ccd_calculateRep (const ULONG e_ref, + ULONG *repeat, + ULONG *max_repeat, + T_CCD_Globs *globs); + +EXTERN void ccd_performOperations (ULONG num_of_ops, + ULONG op_def_ref, + T_CCD_Globs *globs); + +EXTERN void ccd_encodeComposition (const ULONG c_ref, + T_CCD_Globs *globs); + +EXTERN void ccd_decodeComposition (const ULONG c_ref, + T_CCD_Globs *globs); +extern int ccd_check_pointer (U8* ptr); + +/* from ccd_err.c */ +extern void ccd_setError (T_CCD_Globs *globs, + UBYTE ErrCode, + UBYTE Action, + USHORT first_par, ...); +extern void ccd_recordFault (T_CCD_Globs *globs, + UBYTE ErrCode, + UBYTE Action, + T_ERR_INFO error_info, + U8 *err_IEaddr); +extern void ccd_err_reset (T_CCD_ERR_LIST_HEAD* eentry); +extern void ccd_err_free (T_CCD_ERR_LIST_HEAD* eentry); +extern int ccd_err_init (T_CCD_ERR_LIST_HEAD** eentry); +extern void ccd_err_exit (void); +extern T_CCD_Globs* ccd_GetGlobVars (T_CCD_ERR_LIST_HEAD** eentry, + T_CCD_STORE_LIST** stoentry); +extern void ccd_FreeGlobVars (T_CCD_Globs* globs); +extern void ccd_common_decode_init (U16 l_buf, + U16 o_buf, + U8 *buf, + T_CCD_Globs *globs); +extern void ccd_dump_msg (U16 l_buf, + U16 o_buf, + U8 *buf, + T_CCD_Globs *globs); +/* from ccd_store.c */ +extern void ccd_store_exit (void); +extern UBYTE ccd_writeStore (T_CCD_Globs *globs, ULONG regNo, ULONG value); +extern UBYTE ccd_getStore (T_CCD_Globs *globs, ULONG regNo, ULONG *value); +extern int ccd_store_init (T_CCD_STORE_LIST** stoentry); + +/* from ccd_patch.c */ +extern int ccd_patch (T_CCD_Globs* globs, int validflag); + /* + * + * Functions defined in cdc_std.c + */ +/* + * STANDARD codecs + */ +EXTERN SHORT cdc_std_decode (const ULONG c_ref, + const ULONG e_ref, + T_CCD_Globs *globs); + +EXTERN SHORT cdc_std_encode (const ULONG c_ref, + const ULONG e_ref, + T_CCD_Globs *globs); + +EXTERN void cdc_decodeElemvalue (ULONG e_ref, + ULONG *repeat, + T_CCD_Globs *globs); + +EXTERN void cdc_encodeElemvalue (ULONG e_ref, + ULONG repeat, + T_CCD_Globs *globs); + +#ifdef DEBUG_CCD +EXTERN void TRACE_CCD (T_CCD_Globs *globs, + char *format, ...); +#endif + + +typedef struct +{ + BOOL gotTag; + BOOL gotLen; +} T_TLV_SORT; + +/* + * Functions defined in cdc_com.c + */ +EXTERN void cdc_BCD_decode (const ULONG e_ref, + UBYTE startDigit, + T_CCD_Globs *globs); + +EXTERN void cdc_BCD_encode (const ULONG e_ref, + UBYTE startDigit, + T_CCD_Globs *globs); + +EXTERN SHORT cdc_tlv_decode (const ULONG c_ref, + const ULONG e_ref, + const T_TLV_SORT *tlv_inf, + T_CCD_Globs *globs); + +EXTERN void cdc_tlv_encode (const ULONG e_ref, + UBYTE lenT, + UBYTE lenL, + T_CCD_Globs *globs); + +EXTERN void cdc_GSM_start (T_CCD_Globs *globs); + +EXTERN U16 cdc_isPresent (const ULONG e_ref, + T_CCD_Globs *globs); + +EXTERN BOOL is_pointer_type (const ULONG e_ref); +EXTERN BOOL is_variable_type (const ULONG e_ref); + +EXTERN SHORT PER_CommonBegin (const ULONG e_ref, + ULONG *maxRep, + T_CCD_Globs *globs); + +EXTERN U8 *PER_allocmem (const ULONG e_ref, + ULONG repeat, + T_CCD_Globs *globs); + +EXTERN USHORT PER_allocmem_and_update (const ULONG e_ref, + ULONG repeat, + T_CCD_Globs *globs); + +/* + * Rest of the CCD coding functions e.g. GSM4_TLV, CSN1_S1 + */ + +/* + * Functions used for standard IEs of GSM + */ +EXTERN SHORT cdc_gsm1v_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm1v_encode (const ULONG c_Ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm1tv_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm1tv_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm2t_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm2t_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm3v_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm3v_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm3tv_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm3tv_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm4lv_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm4lv_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm4tlv_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm4tlv_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm5v_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm5v_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm5tv_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm5tv_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm5tlv_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm5tlv_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm6tlv_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm6tlv_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm7lv_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm7lv_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); + +/* + * Functions used for BCD digits + */ +EXTERN SHORT cdc_bcdodd_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_bcdodd_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_bcdeven_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_bcdeven_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_bcd_nofill_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_bcd_nofill_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_bcd_mnc_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_bcd_mnc_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); + +/* + * Functions used for ASN1 BER + */ +EXTERN SHORT cdc_gsm1asn_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_gsm1asn_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); + +/* + * Functions used for rest octets + */ +EXTERN const UBYTE padding_bits[]; +EXTERN const UBYTE padding_bits_prev[]; +#define GET_HL(bit) (padding_bits[globs->bitpos%8] ^ bit) +#define GET_HL_PREV(bit) (padding_bits_prev[globs->bitpos%8] ^ bit) +EXTERN SHORT cdc_csn1_s1_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_csn1_s1_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_csn1_s0_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_csn1_s0_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_csn1_shl_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_csn1_shl_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_padd_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_padd_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_padd_0_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_padd_0_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_hl_flag_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_hl_flag_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_csn1_concat_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_csn1_concat_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_break_cond_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_break_cond_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_csn1_choice1_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_csn1_choice1_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_csn1_choice2_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_csn1_choice2_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_csn1_shl_opt_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_csn1_shl_opt_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_csn1_s1_opt_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_csn1_s1_opt_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_csn1_s0_opt_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_csn1_s0_opt_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); + +/* + * Functions used for fax and data + */ +EXTERN SHORT cdc_t30_ident_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_t30_ident_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); + +/* + * Functions and types used for decoding frequency lists, fdd_cell_information + * and tdd_cell_information + */ +#if defined CCD_TEST +#include <stdlib.h> +#define MALLOC(P,S) P = (void*)malloc(S) +#define MFREE(P) free(P) +#endif + +typedef struct +{ + U8 length; + U8 count; +} T_W_PARAM; + +EXTERN const T_W_PARAM param_1024[]; +EXTERN const T_W_PARAM param_512[]; + +#define BITOFFSET_LIST 1024 +#define T_LIST_MAX_SIZE 128 /* 1024/8 = 128 */ + +typedef struct +{ + U8 channels [T_LIST_MAX_SIZE]; +} T_LIST; + +#define FDD_CI_LIST 1 +#define TDD_CI_LIST 2 +#define FREQUENCY_LIST 3 +EXTERN U8 ByteBitMask[]; +EXTERN long for_modulo (long a, long b); +EXTERN void cdc_decode_param (const T_W_PARAM *param,short *w, U16 ListLength, T_CCD_Globs *globs); +EXTERN void cdc_decode_frequencies (short original_range, short *w, short offset, U8 callerID, T_CCD_Globs *globs); +EXTERN SHORT cdc_freq_list_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_freq_list_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_fdd_ci_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_fdd_ci_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_tdd_ci_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_tdd_ci_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); + +/* + * Functions used for ASN1 PER + */ +EXTERN void PER_Decode_ASN1_CHOICE_alterative (const ULONG e_ref, T_ENUM UnionTag, T_CCD_Globs *globs); +EXTERN void PER_Encode_ASN1_CHOICE_alterative (const ULONG e_ref, T_ENUM UnionTag, T_CCD_Globs *globs); +EXTERN SHORT cdc_asn1_choice_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_asn1_choice_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_asn1_integ_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_asn1_integ_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_asn1_octet_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_asn1_octet_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_asn1_seq_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_asn1_seq_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_bitstring_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_bitstring_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); + +/* + * Functions used for ASN1 PER extensible + */ +EXTERN const UBYTE bitSize[]; +EXTERN U32 Read_NormallySmallNonNegativeWholeNr (T_CCD_Globs *globs); +EXTERN void Write_NormallySmallNonNegativeWholeNr (U32 Value, T_CCD_Globs *globs); +EXTERN U32 Read_OpenTpye_Length (T_CCD_Globs *globs); +EXTERN void Write_OpenTpye_Length (U32 Value, T_CCD_Globs *globs); + +EXTERN SHORT cdc_asn1_choice_ext_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_asn1_choice_ext_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); + +EXTERN void Read_unique_Integer (const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_asn1_integ_ext_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_asn1_integ_ext_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); + +EXTERN void Read_SEQ_BitMap (const ULONG first_elem, const ULONG last_elem, T_CCD_Globs *globs); +EXTERN void Write_SEQ_BitMap (const ULONG first_elem, const ULONG last_elem, T_CCD_Globs *globs); +EXTERN SHORT cdc_asn1_seq_ext_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_asn1_seq_ext_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); + +EXTERN SHORT cdc_asn1_obj_id_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_asn1_obj_id_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); + +EXTERN SHORT cdc_asn1_open_type_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_asn1_open_type_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +/* + * Extra functions + */ +EXTERN SHORT cdc_no_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_no_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); + +/* + * Functions used for umts message extensions + */ +EXTERN SHORT cdc_noncritical_ext_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_noncritical_ext_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_critical_ext_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +EXTERN SHORT cdc_critical_ext_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs); +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccd_config.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,362 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccd_config.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Deutschland GmbH +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Deutschland GmbH +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Deutschland GmbH. ++----------------------------------------------------------------------------- +| Purpose : Definition of codec for CCD based on Ccddata ++----------------------------------------------------------------------------- +*/ + +#define CCD_CONFIG_C + +/* + * standard definitions like UCHAR, ERROR etc. + */ +#include "typedefs.h" + +/* MAX_ERRORS and T_CCD_ERR_ENTRY are defined in ccd_globs.h */ +#include "ccd_globs.h" +#include "ccdtable.h" +#include "ccddata.h" +/* prototypes of the exported functions are given in ccd.h */ +#include "ccd.h" + +/* + * all coding types with their constant enumeration are given in ccd_codingtypes.h + */ +#include "ccd_codingtypes.h" + +#ifndef CCD_MK +#include "mconst.cdg" +#endif + +/* + * ccdError and ccdWarning are defined in ccdapi.h + */ +#include "ccdapi.h" + +#if defined CCD_MK || !defined _TOOLS_ +UBYTE cdc_init (T_FUNC_POINTER codec[MAX_CODEC_ID+1][2]) +{ + int i, j; + + for (i = 0; i <= MAX_CODEC_ID; i++) + { + codec[i][0] = cdc_std_encode; + codec[i][1] = cdc_std_decode; + } + + i = 0; + j = 1; +#if defined GSM1_V || defined _TOOLS_ + codec[CCDTYPE_GSM1_V][0] = cdc_gsm1v_encode; + codec[CCDTYPE_GSM1_V][1] = cdc_gsm1v_decode; +#endif + + j++; +#if defined GSM1_TV || defined _TOOLS_ + codec[CCDTYPE_GSM1_TV][0] = cdc_gsm1tv_encode; + codec[CCDTYPE_GSM1_TV][1] = cdc_gsm1tv_decode; +#endif + + j++; +#if defined GSM2_T || defined _TOOLS_ + codec[CCDTYPE_GSM2_T][0] = cdc_gsm2t_encode; + codec[CCDTYPE_GSM2_T][1] = cdc_gsm2t_decode; +#endif + + j++; +#if defined GSM3_V || defined _TOOLS_ + codec[CCDTYPE_GSM3_V][0] = cdc_gsm3v_encode; + codec[CCDTYPE_GSM3_V][1] = cdc_gsm3v_decode; +#endif + + j++; +#if defined GSM3_TV || defined _TOOLS_ + codec[CCDTYPE_GSM3_TV][0] = cdc_gsm3tv_encode; + codec[CCDTYPE_GSM3_TV][1] = cdc_gsm3tv_decode; +#endif + + j++; +#if defined GSM4_LV || defined _TOOLS_ + codec[CCDTYPE_GSM4_LV][0] = cdc_gsm4lv_encode; + codec[CCDTYPE_GSM4_LV][1] = cdc_gsm4lv_decode; +#endif + + j++; +#if defined GSM4_TLV || defined _TOOLS_ + codec[CCDTYPE_GSM4_TLV][0] = cdc_gsm4tlv_encode; + codec[CCDTYPE_GSM4_TLV][1] = cdc_gsm4tlv_decode; +#endif + + j++; +#if defined GSM5_V || defined _TOOLS_ + codec[CCDTYPE_GSM5_V][0] = cdc_gsm5v_encode; + codec[CCDTYPE_GSM5_V][1] = cdc_gsm5v_decode; +#endif + + j++; +#if defined GSM5_TLV || defined _TOOLS_ + codec[CCDTYPE_GSM5_TLV][0] = cdc_gsm5tlv_encode; + codec[CCDTYPE_GSM5_TLV][1] = cdc_gsm5tlv_decode; +#endif + + j++; +#if defined GSM6_TLV || defined _TOOLS_ + codec[CCDTYPE_GSM6_TLV][0] = cdc_gsm6tlv_encode; + codec[CCDTYPE_GSM6_TLV][1] = cdc_gsm6tlv_decode; +#endif + + j++; +#if defined GSM7_LV || defined _TOOLS_ + codec[CCDTYPE_GSM7_LV][0] = cdc_gsm7lv_encode; + codec[CCDTYPE_GSM7_LV][1] = cdc_gsm7lv_decode; +#endif + + j++; +#if defined GSM1_ASN || defined _TOOLS_ + codec[CCDTYPE_GSM1_ASN][0] = cdc_gsm1asn_encode; + codec[CCDTYPE_GSM1_ASN][1] = cdc_gsm1asn_decode; +#endif + + j++; +#if defined BCDODD || defined _TOOLS_ + codec[CCDTYPE_BCDODD][0] = cdc_bcdodd_encode; + codec[CCDTYPE_BCDODD][1] = cdc_bcdodd_decode; +#endif + + j++; +#if defined BCDEVEN || defined _TOOLS_ + codec[CCDTYPE_BCDEVEN][0] = cdc_bcdeven_encode; + codec[CCDTYPE_BCDEVEN][1] = cdc_bcdeven_decode; +#endif + + j++; +#if defined BCD_NOFILL || defined _TOOLS_ + codec[CCDTYPE_BCD_NOFILL][0] = cdc_bcd_nofill_encode; + codec[CCDTYPE_BCD_NOFILL][1] = cdc_bcd_nofill_decode; +#endif + + j++; +#if defined BCD_MNC || defined _TOOLS_ + codec[CCDTYPE_BCD_MNC][0] = cdc_bcd_mnc_encode; + codec[CCDTYPE_BCD_MNC][1] = cdc_bcd_mnc_decode; +#endif + + j++; +#if defined CSN1_S1 || defined _TOOLS_ + codec[CCDTYPE_CSN1_S1][0] = cdc_csn1_s1_encode; + codec[CCDTYPE_CSN1_S1][1] = cdc_csn1_s1_decode; +#endif + + j++; +#if defined CSN1_SHL || defined _TOOLS_ + codec[CCDTYPE_CSN1_SHL][0] = cdc_csn1_shl_encode; + codec[CCDTYPE_CSN1_SHL][1] = cdc_csn1_shl_decode; +#endif + + j++; +#if defined S_PADDING || defined _TOOLS_ + codec[CCDTYPE_S_PADDING][0] = cdc_padd_encode; + codec[CCDTYPE_S_PADDING][1] = cdc_padd_decode; +#endif + + j++; +#if defined T30_IDENT || defined _TOOLS_ + codec[CCDTYPE_T30_IDENT][0] = cdc_t30_ident_encode; + codec[CCDTYPE_T30_IDENT][1] = cdc_t30_ident_decode; +#endif + + j++; +#if defined BITSTRING || defined _TOOLS_ + codec[CCDTYPE_BITSTRING][0] = cdc_bitstring_encode; + codec[CCDTYPE_BITSTRING][1] = cdc_bitstring_decode; +#endif + + j++; +#if defined ASN1_INTEGER || defined _TOOLS_ + codec[CCDTYPE_ASN1_INTEGER][0] = cdc_asn1_integ_encode; + codec[CCDTYPE_ASN1_INTEGER][1] = cdc_asn1_integ_decode; +#endif + + j++; +#if defined ASN1_SEQUENCE || defined _TOOLS_ + codec[CCDTYPE_ASN1_SEQUENCE][0] = cdc_asn1_seq_encode; + codec[CCDTYPE_ASN1_SEQUENCE][1] = cdc_asn1_seq_decode; +#endif + + j++; +#if defined ASN1_CHOICE || defined _TOOLS_ + codec[CCDTYPE_ASN1_CHOICE][0] = cdc_asn1_choice_encode; + codec[CCDTYPE_ASN1_CHOICE][1] = cdc_asn1_choice_decode; +#endif + + j++; +#if defined ASN1_OCTET || defined _TOOLS_ + codec[CCDTYPE_ASN1_OCTET][0] = cdc_asn1_octet_encode; + codec[CCDTYPE_ASN1_OCTET][1] = cdc_asn1_octet_decode; +#endif + + j++; +#if defined NO_CODE || defined _TOOLS_ + codec[CCDTYPE_NO_CODE][0] = cdc_no_encode; + codec[CCDTYPE_NO_CODE][1] = cdc_no_decode; +#endif + + j++; +#if defined ASN1_INTEGER_EXTENSIBLE || defined _TOOLS_ + codec[CCDTYPE_ASN1_INTEGER_EXTENSIBLE][0] = cdc_asn1_integ_ext_encode; + codec[CCDTYPE_ASN1_INTEGER_EXTENSIBLE][1] = cdc_asn1_integ_ext_decode; +#endif + + j++; +#if defined ASN1_SEQUENCE_EXTENSIBLE || defined _TOOLS_ + codec[CCDTYPE_ASN1_SEQUENCE_EXTENSIBLE][0] = cdc_asn1_seq_ext_encode; + codec[CCDTYPE_ASN1_SEQUENCE_EXTENSIBLE][1] = cdc_asn1_seq_ext_decode; +#endif + + j++; +#if defined ASN1_CHOICE_EXTENSIBLE || defined _TOOLS_ + codec[CCDTYPE_ASN1_CHOICE_EXTENSIBLE][0] = cdc_asn1_choice_ext_encode; + codec[CCDTYPE_ASN1_CHOICE_EXTENSIBLE][1] = cdc_asn1_choice_ext_decode; +#endif + + j++; +#if defined ASN1_OBJ_ID || defined _TOOLS_ + codec[CCDTYPE_ASN1_OBJ_ID][0] = cdc_asn1_obj_id_encode; + codec[CCDTYPE_ASN1_OBJ_ID][1] = cdc_asn1_obj_id_decode; +#endif + + j++; +#if defined ASN1_OPEN_TYPE || defined _TOOLS_ + codec[CCDTYPE_ASN1_OPEN_TYPE][0] = cdc_asn1_open_type_encode; + codec[CCDTYPE_ASN1_OPEN_TYPE][1] = cdc_asn1_open_type_decode; +#endif + + j++; +#if defined NONCRITICAL_EXT || defined _TOOLS_ + codec[CCDTYPE_NONCRITICAL_EXT][0] = cdc_noncritical_ext_encode; + codec[CCDTYPE_NONCRITICAL_EXT][1] = cdc_noncritical_ext_decode; +#endif + + j++; +#if defined CRITICAL_EXT || defined _TOOLS_ + codec[CCDTYPE_CRITICAL_EXT][0] = cdc_critical_ext_encode; + codec[CCDTYPE_CRITICAL_EXT][1] = cdc_critical_ext_decode; +#endif + + j++; +#if defined S_PADDING_0 || defined _TOOLS_ + codec[CCDTYPE_S_PADDING_0][0] = cdc_padd_0_encode; + codec[CCDTYPE_S_PADDING_0][1] = cdc_padd_0_decode; +#endif + + j++; +#if defined CSN1_S0 || defined _TOOLS_ + codec[CCDTYPE_CSN1_S0][0] = cdc_csn1_s0_encode; + codec[CCDTYPE_CSN1_S0][1] = cdc_csn1_s0_decode; +#endif + + + j++; +#if defined HL_FLAG || defined _TOOLS_ + codec[CCDTYPE_HL_FLAG][0] = cdc_hl_flag_encode; + codec[CCDTYPE_HL_FLAG][1] = cdc_hl_flag_decode; +#endif + + j++; + +#if defined FDD_CI || defined _TOOLS_ + codec[CCDTYPE_FDD_CI][0] = cdc_fdd_ci_encode; + codec[CCDTYPE_FDD_CI][1] = cdc_fdd_ci_decode; +#endif + + j++; + +#if defined TDD_CI || defined _TOOLS_ + codec[CCDTYPE_TDD_CI][0] = cdc_tdd_ci_encode; + codec[CCDTYPE_TDD_CI][1] = cdc_tdd_ci_decode; +#endif + + j++; + +#if defined FREQ_LIST || defined _TOOLS_ + codec[CCDTYPE_FREQ_LIST][0] = cdc_freq_list_encode; + codec[CCDTYPE_FREQ_LIST][1] = cdc_freq_list_decode; +#endif + + j++; +#if defined CSN1_CONCAT || defined _TOOLS_ + codec[CCDTYPE_CSN1_CONCAT][0] = cdc_csn1_concat_encode; + codec[CCDTYPE_CSN1_CONCAT][1] = cdc_csn1_concat_decode; +#endif + + j++; +#if defined CCDTYPE_BREAK_COND || defined _TOOLS_ + codec[CCDTYPE_BREAK_COND][0] = cdc_break_cond_encode; + codec[CCDTYPE_BREAK_COND][1] = cdc_break_cond_decode; +#endif + + j++; +#if defined GSM5_TV || defined _TOOLS_ + codec[CCDTYPE_GSM5_TV][0] = cdc_gsm5tv_encode; + codec[CCDTYPE_GSM5_TV][1] = cdc_gsm5tv_decode; +#endif + + j++; +#if defined CSN1_CHOICE1 || defined _TOOLS_ + codec[CCDTYPE_CSN1_CHOICE1][0] = cdc_csn1_choice1_encode; + codec[CCDTYPE_CSN1_CHOICE1][1] = cdc_csn1_choice1_decode; +#endif + + j++; +#if defined CSN1_CHOICE2 || defined _TOOLS_ + codec[CCDTYPE_CSN1_CHOICE2][0] = cdc_csn1_choice2_encode; + codec[CCDTYPE_CSN1_CHOICE2][1] = cdc_csn1_choice2_decode; +#endif + + j++; +#if defined CSN1_SHL_OPT || defined _TOOLS_ + codec[CCDTYPE_CSN1_SHL_OPT][0] = cdc_csn1_shl_opt_encode; + codec[CCDTYPE_CSN1_SHL_OPT][1] = cdc_csn1_shl_opt_decode; +#endif + + j++; +#if defined CSN1_S1_OPT || defined _TOOLS_ + codec[CCDTYPE_CSN1_S1_OPT][0] = cdc_csn1_s1_opt_encode; + codec[CCDTYPE_CSN1_S1_OPT][1] = cdc_csn1_s1_opt_decode; +#endif + + j++; +#if defined CSN1_S0_OPT || defined _TOOLS_ + codec[CCDTYPE_CSN1_S0_OPT][0] = cdc_csn1_s0_opt_encode; + codec[CCDTYPE_CSN1_S0_OPT][1] = cdc_csn1_s0_opt_decode; +#endif + + /* + * CCD has more co/dec functions than used in the table above. + * Look in ccd_codingtypes.h. + */ + /*lint -e774 + * The follwing instruction checks if it was forgotten to initialize + * the codec when the number of coding types was increased; if everything + * was OK, the if evaluates for sure to false, causing the lint error + */ + if (j < MAX_CODEC_ID) + return ccdWarning; + /*lint +e774*/ + + return ccdOK; +} +#endif /* CCD_MK || !_TOOLS_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccd_elem.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,335 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccd_elem.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Condat Conder Decoder - +| Definition of encoding and decoding functions of +| information elements of air interface messages ++----------------------------------------------------------------------------- +*/ + +#define CCD_ELEM_C + +#include <stdio.h> +#include <string.h> + +#include "typedefs.h" +#include "ccd_globs.h" +#include "ccd.h" +#include "ccdtable.h" +#include "ccddata.h" +#include "ccdapi.h" +#include "bitfun.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : ccd_elem | +| STATE : code ROUTINE : ccd_decodeElem | ++--------------------------------------------------------------------+ + + PARAMETERS: ULONG ccdid + - Enumeration of the information element to be + decoded in the file ccdid.h. This number is also + the reference number of the IE in the melem table. + + USHORT l_buf + - Number of bits in the encoded IE. + + USHORT o_buf + - Offset of the bitstream buffer in bits. + + U8 *buf + - Bitstream buffer of the encoded IE. + + U8 *eStruct + - reference to the C-Structure containing the + C-Representation of the decoded IE. + + PURPOSE: decodes a bitstream containing an encoded information + element. The results are written to a corresponding + C-Structure, the C-Representation of the IE. +*/ +int CCDDATA_PREF(ccd_decodeElem) (ULONG ccdid, + USHORT l_buf, + USHORT o_buf, + UCHAR* buf, + UCHAR* eStruct) +{ + int jmp_ret; + USHORT mcompRef; + T_CCD_Globs *globs; + T_CCD_ERR_LIST_HEAD* eentry; + T_CCD_STORE_LIST* stoentry; + + globs = ccd_GetGlobVars (&eentry, &stoentry); + +#ifdef DEBUG_CCD + ccd_dump_msg(l_buf, o_buf, buf, globs); +#endif + + /* + * setup the structure-buffer. */ + globs->pstruct = eStruct; + globs->pstructOffs = 0; + + ccd_common_decode_init(l_buf, o_buf, buf, globs); + ccd_err_reset (eentry); + globs->ccd_recurs_level =1; + + if ((mcompRef = melem[ccdid].elemRef) EQ NO_REF) + { + ccd_recordFault (globs, ERR_INVALID_CCDID, BREAK, ccdid, NULL); + ccd_FreeGlobVars (globs); + ccd_err_free (eentry); + return (BYTE)globs->CCD_Error; + } + + +#ifdef DEBUG_CCD +#ifdef CCD_SYMBOLS + TRACE_CCD (globs, "CCD decode: Element = %s", + mcomp[mcompRef].name); +#else + TRACE_CCD (globs, "CCD decode: CCD_Id = %x", ccdid); +#endif +#endif + +#ifdef ERR_TRC_STK_CCD + /* save the value for tracing in error case */ + globs->error_stack[0] = mcompRef; +#endif /* ERR_TRC_STK_CCD */ + +/* + * Clean up the entite C-structure before decoding. + * Do not overwrite the MsgId (1. Byte) + */ +#ifdef DEBUG_CCD + TRACE_CCD (globs, "CCD Cleaning struct %ld bytes", + mcomp[mcompRef].cSize); +#endif + memset ((UBYTE *) globs->pstruct, 0, + (size_t)(mcomp[mcompRef].cSize)); + + /* + * clear the UPN stack + */ + globs->SP=0; + globs->StackOvfl=FALSE; + globs->KeepReg[0] = 0; + + /* + * inform the GSM-CODEC about the begin of a new message + */ + cdc_GSM_start (globs); + + jmp_ret = setjmp (globs->jmp_mark); + + if (jmp_ret EQ 0) + { + globs->jmp_mark_set = TRUE; + ccd_decodeComposition ((ULONG) mcompRef, globs); + } + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "CCD-ERROR = %d", globs->CCD_Error); + TRACE_CCD (globs, "-------------------------------------------------"); +#endif /* DEBUG_CCD */ + + ccd_FreeGlobVars (globs); + ccd_err_free (eentry); + + return (BYTE) globs->CCD_Error; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : ccd_elem | +| STATE : code ROUTINE : ccd_encodeElem | ++--------------------------------------------------------------------+ + + PARAMETERS: ULONG ccdid + - Enumeration of the information element to be + encoded in the file ccdid.h. This number is also + the reference number of the IE in the melem table + + USHORT l_buf + - Number of bits in the encoded IE. + + USHORT o_buf + - Offset of the bitstream buffer in bits. + + U8 *buf + - Bitstream buffer of the encoded IE. + + UBYTE * eStruct + - reference to the C-Structure containing the + C-Representation of the decoded IE. + + PURPOSE: encodes a C-Structure containing the C-Representation of + an information element to a bitstream. +*/ +int CCDDATA_PREF(ccd_encodeElem) (ULONG ccdid, + USHORT* l_buf, + USHORT o_buf, + UCHAR* buf, + UCHAR* eStruct) +{ + int jmp_ret; + USHORT maxBytes, mcompRef; + T_CCD_Globs *globs; + T_CCD_ERR_LIST_HEAD* eentry; + T_CCD_STORE_LIST* stoentry; + + globs = ccd_GetGlobVars (&eentry, &stoentry); + ccd_err_reset (eentry); + +#ifdef DEBUG_CCD + { + /* to avoid the vsprintf if the traces won't appear anyhow */ + ULONG mask; + if (vsi_gettracemask (globs->me, globs->me, &mask) != VSI_ERROR) + { + globs->TraceIt = mask & TC_CCD; + } + } +#endif + + /* + * Set a sign that no call to setjmp() is done. So ccd_setError + * performs no longjmp in case of an error. + */ + globs->jmp_mark_set = FALSE; + + /* Setup the bitbuffer. */ + globs->bitbuf = buf; + globs->bitpos = 0; + + /* Setup the structure-buffer. */ + globs->pstruct = eStruct; + globs->pstructOffs = 0; + + /* Cleanup the read-caches. */ + globs->lastbytepos16 = globs->lastbytepos32 = 0xffff; + + /* Setup the bitoffset. */ + globs->bitoffs = o_buf; + bf_incBitpos (o_buf, globs); + globs->bitbuf[globs->bytepos] = 0; + + globs->CCD_Error = ccdOK; + globs->ccd_recurs_level =1; + + if ((mcompRef = melem[ccdid].elemRef) EQ NO_REF) + { + ccd_recordFault (globs, ERR_INVALID_CCDID, BREAK, ccdid, NULL); + ccd_FreeGlobVars (globs); + ccd_err_free (eentry); + return (BYTE)globs->CCD_Error; + } + +#ifdef DEBUG_CCD +#ifdef CCD_SYMBOLS + TRACE_CCD (globs, "CCD encode: Element = %s", + mcomp[mcompRef].name); +#else + TRACE_CCD (globs, "CCD encode: CCD_Id = %x", ccdid); +#endif +#endif + +#ifdef ERR_TRC_STK_CCD + /* Save the value for tracing in error case. */ + globs->error_stack[0] = mcompRef; +#endif + + maxBytes = (USHORT) (mcomp[mcompRef].bSize+7)>>3; + #ifdef DEBUG_CCD + TRACE_CCD (globs, "-------------------------------------------------"); + TRACE_CCD (globs, "CCD: Code Elem"); + TRACE_CCD (globs, "Cleaning %d bits (%d bytes) of the bitstream", + mcomp[mcompRef].bSize, maxBytes); +#endif + + /* + * Clean up the bit buffer for the encoded message before encoding. + */ + memset ((U8 *) &buf[o_buf>>3], 0, (size_t) maxBytes); + + /* Store the length of ereased buffer to support error handling. */ + globs->buflen = (USHORT) mcomp[mcompRef].bSize; + + /* + * Clear the UPN stack. + */ + globs->SP=0; + globs->StackOvfl=FALSE; + globs->KeepReg[0] = 0; + + /* + * Inform the GSM-CODEC about the begin of a new message. + */ + cdc_GSM_start (globs); + + jmp_ret = setjmp (globs->jmp_mark); + + if (jmp_ret EQ 0) + { + globs->jmp_mark_set = TRUE; + ccd_encodeComposition ((ULONG) mcompRef, globs); + } + + *l_buf = (USHORT)(globs->bitpos - globs->bitoffs); + +#ifdef DEBUG_CCD +{ + int i, j, buflen; + char s[64], c[4]; + + buflen = (*l_buf + o_buf + 7) >> 3; + + TRACE_CCD (globs, "-------------------------------------------------"); + TRACE_CCD (globs, " After ENCODING: lbuf= %d, obuf= %d", *l_buf, o_buf); + TRACE_CCD (globs, " Hex dump of encoded message:"); + + s[0] = '\0'; + for (i = o_buf >> 3; i < buflen; i+=16) + { + for (j = 0; j < 16; j++) + { + if ((i+j) < buflen) + { + sprintf(c, " %02x", buf[i+j]); + strcat (s, c); + } + } + TRACE_CCD (globs, "%s", s); + s[0] = '\0'; + } +} +#endif + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "CCD-ERROR = %d", globs->CCD_Error); + TRACE_CCD (globs, "-------------------------------------------------"); +#endif /* DEBUG_CCD */ + + ccd_FreeGlobVars (globs); + ccd_err_free (eentry); + + return (BYTE) globs->CCD_Error; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccd_err.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,739 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccd_err.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : CCD - Definition of error handling routines ++----------------------------------------------------------------------------- +*/ + +#define CCD_ERR_C + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <setjmp.h> + +/* + * Standard definitions like UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Types and constants used by CCD + */ +#include "ccd_globs.h" + +/* + * Type definitions for CCD data tables + */ +#include "ccdtable.h" + +/* + * Function prototypes of CCD-CCDDATA interface + */ +#include "ccddata.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Definition of CCD Error table + */ +#include "ccd_err.h" + +extern T_CCD_TASK_TABLE* ccd_task_list[]; + +#ifdef CCD_TEST + #define CCD_ERR_TRC_P1(A,B,C) {printf("\n"); printf(B, C);} + #define CCD_ERR_TRC_P2(A,B,C,D) {printf("\n"); printf(B, C, D);} +#else + #define CCD_ERR_TRC_P1(A,B,C) vsi_o_ttrace(A, TC_ERROR, B, C); + #define CCD_ERR_TRC_P2(A,B,C,D) vsi_o_ttrace(A, TC_ERROR, B, C, D); +#endif + +/* + * backwards compatibility with the new style for error information container + */ +#define errPar para.para_list.err_list +#define numErrPar para.para_list.num_para + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------------ +| Function : ccd_err_reset ++------------------------------------------------------------------------------ +| Description : This function resets the task related error entry in +| ccd_task_list with each coding/decoding action. +| +| Parameters : eentry - the task related error entry in ccd_task_list +| +| Return : - ++------------------------------------------------------------------------------ +*/ +void ccd_err_reset (T_CCD_ERR_LIST_HEAD* eentry) +{ + eentry->act_error = &(eentry->first_error); + eentry->num_errors = 0; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------------ +| Function : ccd_err_alloc ++------------------------------------------------------------------------------ +| Description : This function allocates a new T_CCD_ERR_LIST and +| set its next pointer to 0. +| +| Parameters : - +| +| Return : - ++------------------------------------------------------------------------------ +*/ +static T_CCD_ERR_LIST* ccd_err_alloc () +{ + T_CCD_ERR_LIST* entry; +#if defined (CCD_TEST) + entry = malloc (sizeof(T_CCD_ERR_LIST)); +#else + entry = D_ALLOC (sizeof(T_CCD_ERR_LIST)); +#endif + if (entry) + { + entry->next = 0; + return entry; + } + return 0; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------------ +| Function : ccd_err_free ++------------------------------------------------------------------------------ +| Description : This function frees the task related error list. +| The freeing starts with the act_error entry, i.e. +| either it is called at the end of a code/decode action +| and concerns only those list entries that were allocated +| by a former actions and are now not used anymore, or it +| can be called by ccd_free_errors and than the whole list +| is freed. +| +| Parameters : eentry - the task related error entry in ccd_task_list +| +| Return : - ++------------------------------------------------------------------------------ +*/ +void ccd_err_free (T_CCD_ERR_LIST_HEAD* entry) +{ + T_CCD_ERR_LIST* it = *entry->act_error; + T_CCD_ERR_LIST* next; + + while (it) + { + next = it->next; +#if defined (CCD_TEST) + free (it); +#else + D_FREE (it); +#endif + it = next; + } + *entry->act_error = 0; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------------ +| Function : ccd_err_init ++------------------------------------------------------------------------------ +| Description : This function initializes the entity's error entry +| The members of the entry not set here, +| are reset with each coding/decoding action. +| +| Parameters : eentry - pointing to the entity's error entry +| +| Return : 1 in case of error, 0 otherwise ++------------------------------------------------------------------------------ +*/ +int ccd_err_init (T_CCD_ERR_LIST_HEAD** eentry) +{ + if (!*eentry) + { +#if defined (CCD_TEST) + *eentry = malloc (sizeof(T_CCD_ERR_LIST_HEAD)); +#else + *eentry = D_ALLOC (sizeof(T_CCD_ERR_LIST_HEAD)); +#endif + } + else + { + ccd_err_reset(*eentry); + ccd_err_free(*eentry); + } + + if (*eentry) + { + (*eentry)->first_error = 0; + return 0; + } + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------------ +| Function : ccd_err_exit ++------------------------------------------------------------------------------ +| Description : This function frees the task related error entry in +| ccd_task_list. +| +| Parameters : - +| +| Return : - ++------------------------------------------------------------------------------ +*/ +void ccd_err_exit (void) +{ + T_CCD_ERR_LIST_HEAD** entry; +#if defined (CCD_TEST) + entry = &ccd_task_list[0]->ccd_err_list; + if (*entry) + { + ccd_err_reset(*entry); + ccd_err_free(*entry); + free (*entry); + } +#else + T_HANDLE me = vsi_e_handle (0, NULL); + if (me == VSI_ERROR) + me = 0; + entry = &ccd_task_list[me]->ccd_err_list; + if (*entry) + { + ccd_err_reset(*entry); + ccd_err_free(*entry); + D_FREE (*entry); + } +#endif + *entry = 0; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------------ +| Function : ccd_trace_err_stk ++------------------------------------------------------------------------------ +| Description : This function traces the error stack. +| +| Parameters : globs - the current variable set +| +| Return : - ++------------------------------------------------------------------------------ +*/ +#ifdef ERR_TRC_STK_CCD +static void ccd_trace_err_stk (T_CCD_Globs *globs) +{ + int i=1; + + if (globs->ccd_recurs_level NEQ 255) + { +#ifdef CCD_SYMBOLS + CCD_ERR_TRC_P1(globs->me, "CCD Error: in message %s", + mcomp[globs->error_stack[0]].name) + if (globs->ccd_recurs_level > 5) + { + CCD_ERR_TRC_P1(globs->me, "CCD Error: %s", "... ->"); + i = (int) (globs->ccd_recurs_level - 5); + } + while (i <= globs->ccd_recurs_level) + { + CCD_ERR_TRC_P1(globs->me, "CCD Error: -> %s", + ccddata_get_alias (globs->error_stack[i], 1)) + i++; + } +#else /* CCD_SYMBOLS */ + + CCD_ERR_TRC_P1(globs->me, "CCD Error: in message with mcompRef=%d!", + globs->error_stack[0]) + for (i=1; i <= globs->ccd_recurs_level; i++) + CCD_ERR_TRC_P1(globs->me, "CCD Error: -> %d", globs->error_stack[i]) +#endif /* CCD_SYMBOLS */ + } +} +#endif /* ERR_TRC_STK_CCD */ +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_setError | ++--------------------------------------------------------------------+ + + PURPOSE : Error processing of the CCD. + +*/ + +void ccd_setError (T_CCD_Globs *globs, + UBYTE ErrCode, + UBYTE Action, + USHORT first_par, + ...) +{ + USHORT par; + UBYTE parnum; + va_list varpars; + T_CCD_ERR_LIST_HEAD* entry = ccd_task_list[globs->me]->ccd_err_list; + T_CCD_ERR_LIST** it = entry->act_error; + char *err_msg = NULL; + + if (globs->errLabel) + { + Action = BREAK; + ErrCode = globs->errLabel; + } + +#if defined (ERR_TRACE_CCD) || defined (DEBUG_CCD) + +#if defined (DEBUG_CCD) + if (Action EQ BREAK) + CCD_ERR_TRC_P2(globs->me, "CCD Error: %s (errCode %d); stopped processing", + ccdErrCodeTable[ErrCode], ErrCode) + else + CCD_ERR_TRC_P2(globs->me, "CCD Error: %s (errCode %d); yet continued processing", + ccdErrCodeTable[ErrCode], ErrCode) +#else + if (Action EQ BREAK) + CCD_ERR_TRC_P1(globs->me, "CCD Error: errCode %d; stopped processing", + ErrCode) + else + CCD_ERR_TRC_P1(globs->me, "CCD Error: errCode %d; yet continued processing", + ErrCode) +#endif /* DEBUG_CCD */ + +#endif /* (ERR_TRACE_CCD) || defined (DEBUG_CCD) */ + + if (!*it) + { + *it = ccd_err_alloc (); + } + + if (*it) + { + /* + * Memory allocation from dynamic partitions should not fail. + * Nevertheless, if it fails, this is not particularly handled here + */ + (*it)->entry.error = ErrCode; + (*it)->entry.kind = CCD_ERR_KIND_PARA_LIST; + + va_start (varpars, first_par); /* Initialize variable arguments. */ + par = first_par; + parnum = 0; + while ((par != 0xffff) AND (parnum < MAX_ERR_PAR)) + { + (*it)->entry.errPar[parnum++] = par; +#if defined (ERR_TRACE_CCD) || defined (DEBUG_CCD) + CCD_ERR_TRC_P1(globs->me, "CCD Error: saved parameter %d to errList", par) +#endif + par = (USHORT) va_arg (varpars, int); + } + (*it)->entry.numErrPar = parnum; + va_end (varpars); /* Reset variable arguments. */ + + entry->act_error = &(*it)->next; + } + + entry->num_errors++; + +#ifdef ERR_TRC_STK_CCD + ccd_trace_err_stk (globs); +#endif /* ERR_TRC_STK_CCD */ + + /* + * if the action say break, perform a longjump to terminate ccd. + */ + if (Action EQ BREAK) + { + globs->CCD_Error = ccdError; + if (globs->jmp_mark_set) + longjmp (globs->jmp_mark, -1); + } + else + globs->CCD_Error = ccdWarning; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------------ +| Function : ccd_get_error ++------------------------------------------------------------------------------ +| Description : This function copies the next error information of the +| classical parameter list kind to the user. +| +| Parameters : item - the task's current error entry +| entry - the returned pointer +| +| Return : the error code if there was still an error, ccdOK otherwise ++------------------------------------------------------------------------------ +*/ +static ULONG ccd_get_error (T_CCD_ERR_LIST_HEAD* head, USHORT *parlist) +{ + T_CCD_ERR_LIST** item; + int i; + if (head) + { + item = head->act_error; + if (*item) + { + if ((*item)->entry.kind == CCD_ERR_KIND_PARA_LIST) + { + for (i=0; i < (*item)->entry.numErrPar; i++) + *parlist++ = (*item)->entry.errPar[i]; + } + head->act_error = &(*item)->next; + return (ULONG) (*item)->entry.error; + } + return ccdOK; + } + return ccdOK; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_getNextError | ++--------------------------------------------------------------------+ + + PURPOSE : if an error is stored in the errorlist, this function + stores the additional stored error parameter + into the given parlist and returns the errorcode. + If no error occured this function returns 0. + +*/ + +UBYTE CCDDATA_PREF(ccd_getNextError) (UBYTE entity, USHORT *parlist) +/* + * The parameter entity is not used anymore, but the function interface + * should remain the same. + */ +{ + T_CCD_ERR_LIST_HEAD* head; +#if defined (CCD_TEST) + head = ccd_task_list[0]->ccd_err_list; +#else + T_HANDLE me = vsi_e_handle (0, NULL); + if (me == VSI_ERROR) + me = 0; + head = ccd_task_list[me]->ccd_err_list; +#endif + + return (UBYTE) ccd_get_error (head, parlist); +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_getFirstError | ++--------------------------------------------------------------------+ + + PURPOSE : if an error is stored in the errorlist, this function + stores the additional stored error parameter + into the given parlist and returns the errorcode. + If no error occured this function returns 0. + +*/ + +UBYTE CCDDATA_PREF(ccd_getFirstError) (UBYTE entity, USHORT *parlist) +{ +/* + * The parameter entity is not used anymore, but the function interface + * should remain the same. + */ + T_CCD_ERR_LIST_HEAD* head; +#if defined (CCD_TEST) + head = ccd_task_list[0]->ccd_err_list; +#else + T_HANDLE me = vsi_e_handle (0, NULL); + if (me == VSI_ERROR) + me = 0; + head = ccd_task_list[me]->ccd_err_list; +#endif + + head->act_error = &(head->first_error); + + return (UBYTE) ccd_get_error (head, parlist); + +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------------ +| Function : ccd_get_numFaults ++------------------------------------------------------------------------------ +| Description : This function delivers the task related number of +| errors/faults of the last coding/decoding action. +| +| Parameters : - +| +| Return : the number of occurred errors ++------------------------------------------------------------------------------ +*/ + +int CCDDATA_PREF(ccd_get_numFaults) () +{ + T_CCD_ERR_LIST_HEAD* head; +#if defined (CCD_TEST) + head = ccd_task_list[0]->ccd_err_list; +#else + T_HANDLE me = vsi_e_handle (0, NULL); + if (me == VSI_ERROR) + me = 0; + head = ccd_task_list[me]->ccd_err_list; +#endif + + if (head) + return head->num_errors; + else + return 0; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------------ +| Function : ccd_free_faultlist ++------------------------------------------------------------------------------ +| Description : This function frees any allocated error/fault inforamtion +| of the current task. +| +| Parameters : - +| +| Return : - ++------------------------------------------------------------------------------ +*/ + +void CCDDATA_PREF(ccd_free_faultlist) () +{ +#if defined (CCD_TEST) + int me = 0; +#else + T_HANDLE me; + me = vsi_e_handle (0, NULL); + if (me == VSI_ERROR) + me = 0; +#endif + ccd_err_reset (ccd_task_list[me]->ccd_err_list); + ccd_err_free (ccd_task_list[me]->ccd_err_list); +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_recordFault | ++--------------------------------------------------------------------+ + + PURPOSE : Record of information on an detected error to support + entity fault diagnosis activities. + +*/ + +void ccd_recordFault (T_CCD_Globs *globs, + UBYTE ErrCode, + UBYTE Action, + T_ERR_INFO err_info, + U8 *err_IEaddr) +{ + char *err_msg = NULL; + T_CCD_ERR_LIST_HEAD* entry = ccd_task_list[globs->me]->ccd_err_list; + T_CCD_ERR_LIST** it = entry->act_error; + + if (globs->errLabel) + { + Action = BREAK; + ErrCode = globs->errLabel; + } + + if (!*it) + { + *it = ccd_err_alloc (); + } + + if (*it) + { + /* + * Memory allocation from dynamic partitions should not fail. + * Nevertheless, if it fails, this is not particularly handled here + */ + (*it)->entry.error = ErrCode; + (*it)->entry.kind = CCD_ERR_KIND_IE_TYPE; + (*it)->entry.para.err_type.err_info = err_info; + (*it)->entry.para.err_type.err_IEaddr = (U32)err_IEaddr; + entry->act_error = &(*it)->next; + } + + entry->num_errors++; + +#if defined (ERR_TRACE_CCD) || defined (DEBUG_CCD) + +#if defined (DEBUG_CCD) + if (Action EQ BREAK) + CCD_ERR_TRC_P2(globs->me, "CCD Error: %s (errCode %d); stopped processing", + ccdErrCodeTable[ErrCode], ErrCode) + else + CCD_ERR_TRC_P2(globs->me, "CCD Error: %s (errCode %d); yet continued processing", + ccdErrCodeTable[ErrCode], ErrCode) +#else + if (Action EQ BREAK) + CCD_ERR_TRC_P1(globs->me, "CCD Error: errCode %d; stopped processing", + ErrCode) + else + CCD_ERR_TRC_P1(globs->me, "CCD Error: errCode %d; yet continued processing", + ErrCode) +#endif /* DEBUG_CCD */ + +#endif /* (ERR_TRACE_CCD) || defined (DEBUG_CCD) */ + +#ifdef ERR_TRC_STK_CCD + ccd_trace_err_stk (globs); +#endif /* ERR_TRC_STK_CCD */ + + /* + * if the action say break, perform a longjump to terminate ccd. + */ + if (Action EQ BREAK) + { + globs->CCD_Error = ccdError; + if (globs->jmp_mark_set) + longjmp (globs->jmp_mark, -1); + } + else + globs->CCD_Error = ccdWarning; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------------ +| Function : ccd_get_fault ++------------------------------------------------------------------------------ +| Description : This function copies the next error information to +| the user (no matter which kind). +| +| Parameters : item - the task's current error entry +| entry - the returned pointer +| +| Return : the error code if there was still an error, ccdOK otherwise ++------------------------------------------------------------------------------ +*/ +static ULONG ccd_get_fault (T_CCD_ERR_LIST_HEAD* head, T_CCD_ERR_ENTRY **entry) +{ + T_CCD_ERR_LIST** item; + if (head) + { + item = head->act_error; + if (*item) + { + *entry = &(*item)->entry; + head->act_error = &(*item)->next; + return (ULONG) (*entry)->error; + } + return ccdOK; + } + return ccdOK; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_getNextFault | ++--------------------------------------------------------------------+ + + PURPOSE : If an error is stored in the errorlist, this function + copies information on the error into the function parameter. + This information is made of error number, error-union type, + ccd_id for the faulty element and the address of this + element in the C-structure of the decoded message. + If no error occured this function returns 0. + +*/ + +ULONG CCDDATA_PREF(ccd_getNextFault) (T_CCD_ERR_ENTRY **ccd_err_entry) +{ + T_CCD_ERR_LIST_HEAD* head; +#if defined (CCD_TEST) + head = ccd_task_list[0]->ccd_err_list; +#else + T_HANDLE me = vsi_e_handle (0, NULL); + if (me == VSI_ERROR) + me = 0; + head = ccd_task_list[me]->ccd_err_list; +#endif + + return ccd_get_fault (head, ccd_err_entry); +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_getFirstFault | ++--------------------------------------------------------------------+ + + PURPOSE : If an error is stored in the errorlist, this function + copies information on the error into the function parameter. + This information is made of error number, error-union type, + ccd_id for the faulty element and the address of this + element in the C-structure of the decoded message. + If no error occured this function returns 0. +*/ + +ULONG CCDDATA_PREF(ccd_getFirstFault) (T_CCD_ERR_ENTRY **ccd_err_entry) +{ + T_CCD_ERR_LIST_HEAD* head; +#if defined (CCD_TEST) + head = ccd_task_list[0]->ccd_err_list; +#else + T_HANDLE me = vsi_e_handle (0, NULL); + if (me == VSI_ERROR) + me = 0; + head = ccd_task_list[me]->ccd_err_list; +#endif + + head->act_error = &(head->first_error); + + return ccd_get_fault (head, ccd_err_entry); +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccd_err.h Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,83 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccd_err.h ++----------------------------------------------------------------------------- +| Copyright 2004 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Condat Coder Decoder +| Definition of CCD Error table ++----------------------------------------------------------------------------- +*/ + +#ifndef __CCD_ERR_H +#define __CCD_ERR_H + +#include "ccdapi.h" + +#define ERR_TXT_LEN 30 +#if defined (DEBUG_CCD) + +/* + * CCD Error table + */ + +char* ccdErrCodeTable[] = +{ + "ERR_NO_MORE_ERROR", + "ERR_INVALID_CALC", + "ERR_PATTERN_MISMATCH", + "ERR_COMPREH_REQUIRED", + "ERR_IE_NOT_EXPECTED", + "ERR_IE_SEQUENCE", + "ERR_MAX_IE_EXCEED", + "ERR_MAND_ELEM_MISS", + "ERR_EOC_TAG_MISSING", + "ERR_INVALID_MID", + "ERR_INVALID_TYPE", + "ERR_MAX_REPEAT", + "ERR_NO_MEM", + "ERR_ADDRESS_INFOMATION_PART", + "ERR_DISTRIBUTION_PART", + "ERR_NON_DISTRIBUTION_PART", + "ERR_MESSAGE_ESCAPE", + "ERR_IGNORE", + "ERR_DUMMY", + "ERR_DUMMY", + "ERR_INTERNAL_ERROR", + "ERR_DEFECT_CCDDATA", + "ERR_END_OF_BUF", + "ERR_INT_VALUE", + "ERR_LONG_MSG", + "ERR_ASN1_ENCODING", + "ERR_ASN1_MAND_IE", + "ERR_ASN1_OPT_IE", + "ERR_ASN1_COND_IE", + "ERR_COND_ELEM_MISS", + "ERR_BUFFER_OF", + "ERR_NONCRITICAL_EXT", + "ERR_CRITICAL_EXT", + "ERR_INVALID_CCDID", + "ERR_MSG_LEN", + "ERR_INVALID_PTR", + "ERR_PROTOCOL_EXTENSION", + "ERR_BITSTR_COMP", + "ERR_ELEM_LEN", + "ERR_LEN_MISMATCH", + "ERR_CONCAT_LEN", + "ERR_UNEXPECT_PAD", + "ERR_CSN1_CHOICE", + "MAX_CCD_ERROR" +}; +#endif /* DEBUG_CCD */ + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccd_globs.h Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,187 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccd_globs.h ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Condat Coder Decoder +| Definition of C struct containing ccd internal global variables ++----------------------------------------------------------------------------- +*/ + +#ifndef __CCD_GLOBS_H +#define __CCD_GLOBS_H + +#include <setjmp.h> +#include "ccdtable.h" +/* + * Constants needed for ccd_globs.h + */ +#include "ccdapi.h" + +#if !defined (CCDDATA_DYN) && !defined (CCD_TEST) +#include "vsi.h" +#endif + +/* + * stack size for the UPN calculator + */ +#define MAX_UPN_STACK_SIZE 20 +#define MAX_KEEP_REG_SIZE 15 + +/* + * the two constants give the size of the iei table + */ +#define MAX_IE_PER_MSG 40 +#define MAX_RECURSIONS_PER_MSG 8 + +#ifdef CCD_GPRS_ONLY +#define CCD_ERR_STK_SZ (MAX_RECURSIONS_PER_MSG+2) +#else +#define CCD_ERR_STK_SZ 50 +#endif + +/* + * constants and types needed for error handling + */ +#define MAX_ERRORS 10 + +#define ENCODE_FUN 0 +#define DECODE_FUN 1 + +/* + * declare a table for the iei processing. This table + * contains for each iei a low and high boundary of + * valid repeats and the actual number of repeats + */ +typedef struct +{ + unsigned valid:4; + unsigned multiple:2; + unsigned exhausted:2; /* for GSM1_ASN elements */ +/* BOOL choice; version does not use GSM1_ASNCHC */ +/* UBYTE min_amount; seams to be an unused variable */ + UBYTE max_amount; + UBYTE act_amount; + UBYTE ident; +} T_IEI_TABLE; + + +/* + * for each msg an initialisation of e.g. the iei_table is to + * perform. See cdc_GSM_start(); + */ + +typedef struct +{ + unsigned valid:4; + unsigned EOCPending:4; /* for ASN1-BER elements only */ + UBYTE countSkipped; /* for GSM1_ASN elements */ + USHORT melemStart; + USHORT melemLast; + USHORT ieTableLen; + T_IEI_TABLE iei_table[MAX_IE_PER_MSG]; +} T_IEI_CONTEXT; + + + +typedef struct +{ +#if defined (CCDDATA_DYN) || defined (CCD_TEST) + int me; +#else + T_HANDLE me; /* entity calling CCD */ +#endif + SHORT CCD_Error; /* return variable overwritten by ccd_setError */ + + /* + * variable used for processing of nested information elements + */ + UBYTE ccd_recurs_level; + + /* + * ccd uses setjmp() and longjmp to process some error cases. + */ + BOOL jmp_mark_set; + jmp_buf jmp_mark; + +#ifdef DYNAMIC_ARRAYS + /* + * Pointer to head of allocation chain for primitives with pointer types. + */ + U8 *alloc_head; +#endif + + /* + * variables used for bit buffering and manipulation of a message + */ + UBYTE *bitbuf; + UBYTE *pstruct; + ULONG pstructOffs; + USHORT bitpos; + USHORT bytepos; + USHORT buflen; + USHORT bitoffs; + USHORT lastbytepos16; + USHORT lastbytepos32; + USHORT maxBitpos; + UBYTE byteoffs; + /* + * variables used by the UPN caculator + */ + UBYTE SP; + ULONG Stack[MAX_UPN_STACK_SIZE]; + ULONG KeepReg[MAX_KEEP_REG_SIZE]; + BOOL StackOvfl; + + /* + * variable used when detecting unknown extensions + * of IEs of type CCDTYPE_GSM5_TLV. + */ + BOOL SeekTLVExt; + + /* + * variables used as cash to keep data on octet boundaries + */ + USHORT last16Bit; + ULONG last32Bit; + +#ifdef ERR_TRC_STK_CCD + U16 error_stack[CCD_ERR_STK_SZ];/*??*/ +#endif /* ERR_TRC_STK_CCD */ + U8 errLabel; + U8 continue_array; + U16 msgLen; + + /* + * variables used by the modules in cdc_gsm.c + */ + T_IEI_CONTEXT iei_ctx[MAX_RECURSIONS_PER_MSG]; + USHORT RefBeforeError; + USHORT akt1VPos; + USHORT next1VPos; + BOOL TagPending; + UBYTE PendingTag; + BOOL SequenceError; + BOOL Swap1V_inProgress; + UBYTE last_level; + UBYTE numEOCPending; + +#ifdef DEBUG_CCD + BOOL TraceIt; + char buf[33]; +#endif + +} T_CCD_Globs; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccd_patch.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,147 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccd_patch.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : CCD - routines for patching msg elements with given values ++----------------------------------------------------------------------------- +*/ + +#define CCD_PATCH_C + +/*==== INCLUDES ==============================================================*/ +#include <stdio.h> +#include <string.h> + +#include "typedefs.h" +#include "ccd_globs.h" +#include "Bitfun.h" +#include "ccddata.h" +#include "ccd.h" + +/*==== CONSTS ================================================================*//*==== TYPES =================================================================*/ +/*==== LOCALS ================================================================*/ +static T_patch_info* pi; + +/*==== PRIVATE FUNCTIONS =====================================================*/ +/*==== PUBLIC FUNCTIONS ======================================================*/ + +/* ++------------------------------------------------------------------------------ +| Function : ccd_set_patch_infos ++------------------------------------------------------------------------------ +| Description : This function submits a list of patch records to CCD +| +| Parameters : pinfo - the list +| +| Return : ccdOK on success, otherwise ccdError ++------------------------------------------------------------------------------ +*/ +int CCDDATA_PREF(ccd_set_patch_infos) (T_patch_info* pinfo) +{ + pi = pinfo; + return ccdOK; +} + +/* ++------------------------------------------------------------------------------ +| Function : ccd_patch ++------------------------------------------------------------------------------ +| Description : This function checks if the element is to be patched +| and patches if yes. +| +| Parameters : globs - entity/code information (containing nesting stack) +| validflag - set if called from valid flag coding +| +| Return : FALSE if real coding function is to be called, TRUE otherwise +| if validflag is set, TRUE means, the element is identified +| in the patch list ++------------------------------------------------------------------------------ +*/ + +int ccd_patch (T_CCD_Globs* globs, int validflag) +{ + int i = 0; + USHORT elem; + if (pi) + { + while (pi[i].numelems) + { + if (!memcmp (pi[i].elemid, globs->error_stack, + (pi[i].numelems+1) * sizeof (U16))) + { + elem = pi[i].elemid[pi[i].numelems]; + if (validflag) + { + if (pi[i].errorcode != CCDP_NOT_FOUND) + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "ccd_patch(): invalid error code (%d) for %s", + pi[i].errorcode, ccddata_get_alias (elem, 1)); +#endif + } + else + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "ccd_patch(): checked valid flag for %s", + ccddata_get_alias (elem, 1)); +#endif + pi[i].errorcode = CCDP_VALIDFLAG_SEEN; + } + return TRUE; + } + else + { + if ((pi[i].errorcode != CCDP_NOT_FOUND) && + (pi[i].errorcode != CCDP_VALIDFLAG_SEEN)) + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "ccd_patch(): invalid error code (%d) for %s", + pi[i].errorcode, ccddata_get_alias (elem, 1)); +#endif + } + else + { + UBYTE* pstruct = globs->pstruct; + ULONG offset = globs->pstructOffs; +#ifdef DEBUG_CCD + int j, len; + char out[32]; + len = (pi[i].bitwidth+7)/8; + TRACE_CCD (globs, "ccd_patch(): patching %s with 0x%x bits", + ccddata_get_alias (elem, 1), pi[i].bitwidth); + for (j=0; j<len; j++) + { + sprintf (&out[(3*j)%24], "%02x \0", pi[i].bits[j]); + if (!((j+1)%8)) + TRACE_CCD (globs, out); + } + if (((j+1)%8)) + TRACE_CCD (globs, out); +#endif + globs->pstruct = pi[i].bits; + globs->pstructOffs = 0; + bf_writeBitChunk (pi[i].bitwidth, globs); + globs->pstruct = pstruct; + globs->pstructOffs = offset; + pi[i].errorcode = CCDP_NO_ERROR; + } + return TRUE; + } + } + i++; + } + } + return FALSE; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccd_store.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,332 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccd_store.c ++----------------------------------------------------------------------------- +| Copyright 2004 Texas Instruments Deutschland, GmbH +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : CCD - Definition of store handling routines ++----------------------------------------------------------------------------- +*/ + +#define CCD_STO_C + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <setjmp.h> + +/* + * Standard definitions like UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Types and constants used by CCD + */ +#include "ccd_globs.h" + +/* + * Type definitions for CCD data tables + */ +#include "ccdtable.h" + +/* + * Function prototypes of CCD-CCDDATA interface + */ +#include "ccddata.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + + +extern T_CCD_TASK_TABLE* ccd_task_list[]; + +#ifndef RUN_INT_RAM +/* Attention for RUN_...: static function */ +/* ++------------------------------------------------------------------------------ +| Function : ccd_store_alloc ++------------------------------------------------------------------------------ +| Description : This function allocates a the entity's store entry and +| set its next pointer to 0. +| The members of the entry must not reset with each +| coding/decoding action. +| +| Parameters : - +| +| Return : pointer to struct of type T_CCD_STORE_LIST ++------------------------------------------------------------------------------ +*/ +static T_CCD_STORE_LIST* ccd_store_alloc () +{ + T_CCD_STORE_LIST* stoentry; + int i; +#if defined (CCD_TEST) + stoentry = malloc (sizeof(T_CCD_STORE_LIST)); +#else + stoentry = D_ALLOC (sizeof(T_CCD_STORE_LIST)); +#endif + /* for future use to extend register capacity */ + /* stoentry->next = NULL */ + if (stoentry) + { + for (i = 0; i < 3; i++) + { + stoentry->store[i] = 0; + } + /* for future use to extend register capacity */ + /* (*stoentry)->next = NULL */ + } + return stoentry; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------------ +| Function : ccd_store_init ++------------------------------------------------------------------------------ +| Description : This function initializes the entity's store entry +| +| Parameters : eentry - pointing to the entity's error entry +| +| Return : 1 in case of error, 0 otherwise ++------------------------------------------------------------------------------ +*/ +int ccd_store_init (T_CCD_STORE_LIST** stoentry) +{ + if (!*stoentry) + { +#if defined (CCD_TEST) + *stoentry = malloc (sizeof(T_CCD_STORE_LIST)); +#else + *stoentry = D_ALLOC (sizeof(T_CCD_STORE_LIST)); +#endif + } + if (*stoentry) + { + int i; + for (i = 0; i < 3; i++) + { + (*stoentry)->store[i] = 0; + } + /* for future use to extend register capacity */ + /* (*stoentry)->next = NULL */ + return 0; + } + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------------ +| Function : ccd_store_exit ++------------------------------------------------------------------------------ +| Description : This function frees the task related store entry in +| ccd_task_list. +| +| Parameters : - +| +| Return : - ++------------------------------------------------------------------------------ +*/ +void ccd_store_exit (void) +{ + T_CCD_STORE_LIST** entry; +#if defined (CCD_TEST) + entry = &ccd_task_list[0]->ccd_store; + if (*entry) + { + /* for future use: This function frees the task related store list in case */ + /* of extended register capacity */ + /* ccd_sto_free(*stoentry); */ + free (*entry); + } +#else + T_HANDLE me = vsi_e_handle (0, NULL); + if (me == VSI_ERROR) + me = 0; + entry = &ccd_task_list[me]->ccd_store; + if (*entry) + { + /* for future use: This function frees the task related store list in case */ + /* of extended register capacity */ + /* ccd_sto_free(*stoentry); */ + D_FREE (*entry); + } +#endif + *entry = 0; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------------ +| Function : ccd_writeStore ++------------------------------------------------------------------------------ +| Description : This function copies information to the register +| retaining its entries after CCD actions are finished. +| +| Parameters : globs - the current variable set +| regNo - to select one of the CCD STORE Registers +| value - information to write to CCD STORE Register +| +| Return : 1 in case of error, 0 otherwise ++------------------------------------------------------------------------------ +*/ + +UBYTE ccd_writeStore (T_CCD_Globs *globs, ULONG regNo, ULONG value) +{ + T_CCD_STORE_LIST* it; +/* +#if defined (CCD_TEST) + it = ccd_task_list[0]->ccd_store; +#else + T_HANDLE me = vsi_e_handle (0, NULL); + if (me == VSI_ERROR) + me = 0; + it = ccd_task_list[me]->ccd_store; +#endif +*/ + it = ccd_task_list[globs->me]->ccd_store; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "Writing %x to STO[%d] ", value, regNo); +#endif + + if (regNo < 3) + { + if (!it) + { + it = ccd_store_alloc (); + } + + if (it) + { + it->store[regNo] = value; + } + + else + { + /* Memory allocation failed */ +#ifdef DEBUG_CCD + TRACE_CCD (globs, "Memory allocation failed!"); +#endif + return 1; + } + } + + else + { + /* for future use: extended register capacity requested */ +#ifdef DEBUG_CCD + TRACE_CCD (globs, "Invalid register number STO[%d] ", regNo); +#endif + return 1; + } + + return 0; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------------ +| Function : ccd_setStore ++------------------------------------------------------------------------------ +| Description : This function copies information from the user to the CCD +| STORE Register. It retains its entries after CCD actions +| are finished. +| +| Parameters : regNo - to select one of the CCD STORE Registers +| value - information to write to CCD STORE Register +| +| Return : 1 in case of error, 0 otherwise ++------------------------------------------------------------------------------ +*/ + +UBYTE ccd_setStore ( ULONG regNo, ULONG value) +{ + T_CCD_Globs* entry; +#if defined (CCD_TEST) + entry = ccd_task_list[0]->ccd_globs; +#else + T_HANDLE me = vsi_e_handle (0, NULL); + if (me == VSI_ERROR) + me = 0; + entry = ccd_task_list[me]->ccd_globs; + entry->me = me; +#endif + + return ccd_writeStore (entry, regNo, value); +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------------ +| Function : ccd_getStore ++------------------------------------------------------------------------------ +| Description : This function reads information from the CCD STORE Register +| and provides it to CCD. +| (CCD STORE Register retains its entries after CCD actions +| are finished.) +| +| Parameters : globs - the current variable set +| regNo - to select one of the CCD STORE Registers +| value - information to write to CCD STORE Register +| +| Return : 1 in case of error, 0 otherwise ++------------------------------------------------------------------------------ +*/ + +UBYTE ccd_getStore (T_CCD_Globs *globs, ULONG regNo, ULONG *value) +{ + T_CCD_STORE_LIST* it = ccd_task_list[globs->me]->ccd_store; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "Reading from STO[%d] ", regNo); +#endif + + if (regNo < 3) + { + if (it) + { + *value = it->store[regNo]; + } + else + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "No CCD STORE Register persent!"); +#endif + return 1; + } + } + + else + { + /* for future use: extended register capacity requested */ +#ifdef DEBUG_CCD + TRACE_CCD (globs, "Invalid register number STO[%d] ", regNo); +#endif + return 1; + } + + return 0; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccddata.h Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,140 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccddata.h ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Exports of the Ccddata Lib/Dll. ++----------------------------------------------------------------------------- +*/ + +#ifndef CCDDATA_H +#define CCDDATA_H + +/*==== INCLUDES =============================================================*/ +#include "pdi.h" + +/*==== CONSTS ===============================================================*/ +#define CCDDATA_CCDENT_INVALID -1 +#define CCDDATA_MCONST_ERROR -1 +#define CCDDATA_PCONST_ERROR -1 + +#define CCDDATA_DLL_OK 0 +#define CCDDATA_DLL_ALREADY -10 +#define CCDDATA_DLL_LOADLIB -11 +#define CCDDATA_DLL_LOADFUN -12 +#define CCDDATA_DLL_REGISTER -13 + +/*==== TYPES =================================================================*/ +#if defined __CCD_GLOBS_H +typedef SHORT (*T_FUNC_POINTER)(const ULONG cref, const ULONG eref, T_CCD_Globs *globs); +typedef struct +{ + T_FUNC_POINTER enc; + T_FUNC_POINTER dec; +} T_FUNC_STRUCT; +#endif + +typedef struct +{ + int p1; + int p2; +} T_COMENDPOINTS; +/*==== EXPORTS ===============================================================*/ + +/* Use CCDDATA_DLL_FUNC only for optmizations. The extern declarations + * also work if the function are in a dll. + */ +#ifndef CCDDATA_DLL_FUNC + #define CCDDATA_IMPORT_FUNC extern +#else /* CCDDATA_DLL_FUNC */ + #define CCDDATA_IMPORT_FUNC extern __declspec(dllimport) +#endif /* CCDDATA_DLL_FUNC */ + +/* ccddata_load.c */ +extern int ccddata_init (const char* dllname, + int reload, + void (*ccddata_init_notify)(void), + void (*ccddata_exit_notify)(void)); +extern int ccddata_exit (void); +extern char* ccddata_dllname (void); + +/* ccd_config.c */ +#if defined(CCD_C) || defined(PDI_C) +UBYTE* ccddata_get_mi_length (void); +#endif +#ifdef CCD_C +UBYTE cdc_init (T_FUNC_POINTER codec[][2]); +UBYTE* ccddata_get_decmsgbuffer (void); +#endif + +/* ccddata_pdi.c */ +CCDDATA_IMPORT_FUNC int ccddata_get_pdi_dinfo (const T_PDI_DECODEINFO* (*dinfo) ); +/* ccddata_mconst.c */ +CCDDATA_IMPORT_FUNC int ccddata_get_num_of_entities(void); +CCDDATA_IMPORT_FUNC int ccddata_get_max_message_id(void); +CCDDATA_IMPORT_FUNC int ccddata_get_max_bitstream_len(void); +CCDDATA_IMPORT_FUNC int ccddata_get_max_mstruct_len(void); +CCDDATA_IMPORT_FUNC int ccddata_mccd_symbols(void); +/* ccddata_pconst.c */ +CCDDATA_IMPORT_FUNC int ccddata_get_max_sap_num(void); +CCDDATA_IMPORT_FUNC int ccddata_get_max_primitive_id(void); +CCDDATA_IMPORT_FUNC int ccddata_get_max_pstruct_len(void); +/* ccddata_ccdmtab.c */ +CCDDATA_IMPORT_FUNC const T_CCD_VarTabEntry* ccddata_get_mvar (USHORT idx); +CCDDATA_IMPORT_FUNC const T_CCD_SpareTabEntry* ccddata_get_spare (USHORT idx); +CCDDATA_IMPORT_FUNC const T_CCD_CalcTabEntry* ccddata_get_calc (USHORT idx); +CCDDATA_IMPORT_FUNC const T_CCD_CompTabEntry* ccddata_get_mcomp (USHORT idx); +CCDDATA_IMPORT_FUNC const T_CCD_ElemTabEntry* ccddata_get_melem (USHORT idx); +CCDDATA_IMPORT_FUNC const T_CCD_CalcIndex* ccddata_get_calcidx (USHORT idx); +CCDDATA_IMPORT_FUNC USHORT ccddata_get_mmtx (USHORT entity, + USHORT msgid, + USHORT index); +/* ccddata_ccdptab.c */ +CCDDATA_IMPORT_FUNC const T_CCD_VarTabEntry* ccddata_get_pvar (USHORT idx); +CCDDATA_IMPORT_FUNC const T_CCD_CompTabEntry* ccddata_get_pcomp (USHORT idx); +CCDDATA_IMPORT_FUNC const T_CCD_ElemTabEntry* ccddata_get_pelem (USHORT idx); +CCDDATA_IMPORT_FUNC USHORT ccddata_get_pmtx (USHORT sap, + USHORT primid, + USHORT index); +/* ccddata_cdemval.c */ +CCDDATA_IMPORT_FUNC const T_CCD_ValTabEntry* ccddata_get_mval (USHORT idx); +CCDDATA_IMPORT_FUNC const T_CCD_StrTabEntry* ccddata_get_mstr (USHORT idx); +/* ccddata_cdepval.c */ +CCDDATA_IMPORT_FUNC const T_CCD_ValTabEntry* ccddata_get_pval (USHORT idx); +CCDDATA_IMPORT_FUNC const T_CCD_StrTabEntry* ccddata_get_pstr (USHORT idx); + +/* ccddata_ccdent.c */ +#ifndef CCDDATA_CCDENT_C +CCDDATA_IMPORT_FUNC short ccddata_get_ccdent (char* entname); +CCDDATA_IMPORT_FUNC const char * ccddata_get_entname (short ccdent); +#endif /* !CCDDATA_CCDENT_C*/ + +/* ccddata_alias.c */ +CCDDATA_IMPORT_FUNC char* ccddata_get_alias (USHORT idx, int from_msg); + +/* ccddata_version.c */ +CCDDATA_IMPORT_FUNC char* ccddata_get_version (); +CCDDATA_IMPORT_FUNC int ccddata_get_table_version (); + +/* ccddata_eg.c */ +#ifndef CCDDATA_EG_C +CCDDATA_IMPORT_FUNC int ccddata_eg_nodes (void); +CCDDATA_IMPORT_FUNC char** ccddata_eg_nodenames (void); +CCDDATA_IMPORT_FUNC char* ccddata_eg_adjacent (int idx); +CCDDATA_IMPORT_FUNC int ccddata_eg_saps (void); +CCDDATA_IMPORT_FUNC char** ccddata_eg_sapnames (void); +CCDDATA_IMPORT_FUNC T_COMENDPOINTS* ccddata_eg_comendpoints (int idx); +#endif /* !CCDDATA_EG_C */ + +#endif /* !CCDDATA_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccddata_alias.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,62 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccddata_alias.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Ccddata abstraction for use in lib/dll. The table ccdent.cdg +| genereraed by ccdgen is included. +| The exported function ccddata_get_ccdent delivers a mapping +| from an entitiy name (like e.g. "RR") to the generated +| entity number (CCDENT_RR). ++----------------------------------------------------------------------------- +*/ + +#define CCDDATA_ALIAS_C +#include <string.h> +#include "typedefs.h" +#include "ccdtable.h" + +static char* nullstr = ""; + +static T_CCD_ALIASTABLE maliastbl [] = +{ +#ifndef CCDDATA_NO_ALIAS +#include "malias.cdg" +#else /* CCDDATA_NO_ALIAS */ +{ "" } +#endif /* CCDDATA_NO_ALIAS */ +}; + +static T_CCD_ALIASTABLE paliastbl [] = +{ +#ifndef CCDDATA_NO_ALIAS +#include "palias.cdg" +#else /* CCDDATA_NO_ALIAS */ +{ "" } +#endif /* CCDDATA_NO_ALIAS */ +}; + +char* ccddata_get_alias (USHORT idx, int from_msg) +{ +#ifndef CCDDATA_NO_ALIAS + USHORT entries = (USHORT) (from_msg ? + sizeof (maliastbl) / sizeof (T_CCD_ALIASTABLE) : + sizeof (paliastbl) / sizeof (T_CCD_ALIASTABLE)); + if (idx >= entries) + return nullstr; + return from_msg ? maliastbl[idx].as_name : paliastbl[idx].as_name; +#else /* CCDDATA_NO_ALIAS */ + return nullstr;; +#endif /* CCDDATA_NO_ALIAS */ +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccddata_ccd.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,49 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccddata_ccd.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of variables exported from CCDDATA to CCD ++----------------------------------------------------------------------------- +*/ + +/* + * standard definitions like UCHAR, ERROR etc. + */ +#include "typedefs.h" + +/* BUFFER_ALIGNMENT is defined in ccd.h, requiring ccd_globs.h */ +#include "ccd_globs.h" +#include "ccd.h" + +#include "mconst.cdg" + +/* + * export information about the value of constants to ccd.lib + * NUM_OF_ENTITIES and MAX_MSTRUCT_LEN are defined in mconst.cdg + */ + +UBYTE decMsgBuffer[MAX_MSTRUCT_LEN + BUFFER_ALIGNMENT]; + +UBYTE* ccddata_get_decmsgbuffer (void) +{ + return decMsgBuffer; +} + +UBYTE mi_length[NUM_OF_ENTITIES]; + +UBYTE* ccddata_get_mi_length (void) +{ + return mi_length; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccddata_ccdent.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,74 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccddata_ccdent.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Ccddata abstraction for use in lib/dll. The table ccdent.cdg +| genereraed by ccdgen is included. +| The exported function ccddata_get_ccdent delivers a mapping +| from an entitiy name (like e.g. "RR") to the generated +| entity number (CCDENT_RR). ++----------------------------------------------------------------------------- +*/ + +#define CCDDATA_CCDENT_C +#include <string.h> +#include "typedefs.h" +#include "mconst.cdg" +#include "ccdtable.h" +#include "ccddata.h" + +static struct +{ + char* entname; + int ccdent; +} ccdenttbl [] = +{ +#ifndef CCDDATA_NO_CCDENT +#include "ccdent.cdg" +#endif /* CCDDATA_NO_CCDENT */ +{ (char *) NULL , 65535 } +}; + +short ccddata_get_ccdent (char* entname) +{ + int i = 0; + + for (;;) + { + if (!ccdenttbl[i].entname) + return CCDDATA_CCDENT_INVALID; + if (!strcmp (ccdenttbl[i].entname, entname)) + return ccdenttbl[i].ccdent; + ++i; + } +} + +const char * ccddata_get_entname (short ccdent) +{ + int i = 0; + + for (;;) + { + if (!ccdenttbl[i].entname) + { + return NULL; + } + if (ccdenttbl[i].ccdent==ccdent) + { + return ccdenttbl[i].entname; + } + ++i; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccddata_ccdmtab.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,107 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccddata_ccdmtab.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Ccddata abstraction for use in lib/dll. The six tables +| mvar, spare, calc, mcomp, melem, and mmtx, genererated by ccdgen +| (in ccdmtab.cdg) are supplied as well as the table calcidx +| (generated in an extra file). In addition, corresponding +| functions deliver specified elements of the tables. For +| mmtx the function must be used, because this three-dimesional +| array cannot be declared as extern without knowing the constants +| at compile time. ++----------------------------------------------------------------------------- +*/ + +#include "typedefs.h" +#include "mconst.cdg" +#include "ccdtable.h" + +static const T_CCD_VarTabEntry ccddata_mvar [] = +{ +#include "mvar.cdg" +}; + +static const T_CCD_SpareTabEntry ccddata_spare [] = +{ +#include "spare.cdg" +}; + +static const T_CCD_CalcTabEntry ccddata_calc [] = +{ +#include "calc.cdg" +}; + +static const T_CCD_CompTabEntry ccddata_mcomp [] = +{ +#include "mcomp.cdg" +}; + +static const T_CCD_ElemTabEntry ccddata_melem [] = +{ +#include "melem.cdg" +}; + +static const USHORT ccddata_mmtx [MAX_MMTX_SIZE] = +{ +#include "mmtxval.cdg" +}; + +static const T_CCD_CalcIndex ccddata_calcidx [] = +{ +#include "calcidx.cdg" +}; + +const T_CCD_MTXIDX ccddata_mmtx_idx [] = +{ +#include "mmtxidx.cdg" +}; + +const T_CCD_CalcIndex* ccddata_get_calcidx (USHORT idx) +{ + return &ccddata_calcidx[idx]; +} + +const T_CCD_VarTabEntry* ccddata_get_mvar (USHORT idx) +{ + return &ccddata_mvar[idx]; +} + +const T_CCD_SpareTabEntry* ccddata_get_spare (USHORT idx) +{ + return &ccddata_spare[idx]; +} + +const T_CCD_CalcTabEntry* ccddata_get_calc (USHORT idx) +{ + return &ccddata_calc[idx]; +} + +const T_CCD_CompTabEntry* ccddata_get_mcomp (USHORT idx) +{ + return &ccddata_mcomp[idx]; +} + +const T_CCD_ElemTabEntry* ccddata_get_melem (USHORT idx) +{ + return &ccddata_melem[idx]; +} + +USHORT ccddata_get_mmtx (USHORT entity, USHORT msgid, USHORT index) +{ + if ((entity >= NUM_OF_ENTITIES) || (msgid >= ccddata_mmtx_idx[entity].numitems)) + return NO_REF; + return ccddata_mmtx[2*(ccddata_mmtx_idx[entity].idx + msgid) + index]; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccddata_ccdptab.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,76 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccddata_ccdptab.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Ccddata abstraction for use in lib/dll. The four tables +| pvar, pcomp, pelem, and pmtx, genereraed by ccdgen +| (in ccdptab.cdg) are supplied. In addition, corresponding +| functions deliver specified elements of the tables. For +| pmtx the function must be used, because this three-dimesional +| array cannot be declared as extern without knowing the constants +| at compile time. ++----------------------------------------------------------------------------- +*/ + +#include "typedefs.h" +#include "pconst.cdg" +#include "ccdtable.h" + +static const T_CCD_VarTabEntry ccddata_pvar [] = +{ +#include "pvar.cdg" +}; + +static const T_CCD_CompTabEntry ccddata_pcomp [] = +{ +#include "pcomp.cdg" +}; + +static const T_CCD_ElemTabEntry ccddata_pelem [] = +{ +#include "pelem.cdg" +}; + +static const USHORT ccddata_pmtx [MAX_PMTX_SIZE] = +{ +#include "pmtxval.cdg" +}; + +const T_CCD_MTXIDX ccddata_pmtx_idx [] = +{ +#include "pmtxidx.cdg" +}; + +const T_CCD_VarTabEntry* ccddata_get_pvar (USHORT idx) +{ + return &ccddata_pvar[idx]; +} + +const T_CCD_CompTabEntry* ccddata_get_pcomp (USHORT idx) +{ + return &ccddata_pcomp[idx]; +} + +const T_CCD_ElemTabEntry* ccddata_get_pelem (USHORT idx) +{ + return &ccddata_pelem[idx]; +} + +USHORT ccddata_get_pmtx (USHORT sap, USHORT primid, USHORT index) +{ + if ((sap > MAX_SAP_NUM) || (primid >= ccddata_pmtx_idx[sap].numitems)) + return NO_REF; + return ccddata_pmtx[2*(ccddata_pmtx_idx[sap].idx + primid) + index]; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccddata_cdemstr.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,38 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccddata_cdemstr.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Ccddata abstraction for use in lib/dll. The two tables +| mval and mstr, genereraed by ccdgen (in cdemval.cdg) +| are supplied. In addition, corresponding functions deliver +| specified elements of the tables. ++----------------------------------------------------------------------------- +*/ + +#ifndef CCDDATA_NO_CDEMSTR + +#include "typedefs.h" +#include "ccdtable.h" + +static const T_CCD_StrTabEntry ccddata_mstr [] = +{ +#include "mstr.cdg" +}; + +const T_CCD_StrTabEntry* ccddata_get_mstr (USHORT idx) +{ + return &ccddata_mstr[idx]; +} +#endif /* CCDDATA_NO_CDEMSTR */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccddata_cdemval.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,47 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccddata_cdemval.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Ccddata abstraction for use in lib/dll. The two tables +| mval and mstr, genereraed by ccdgen (in cdemval.cdg) +| are supplied. In addition, corresponding functions deliver +| specified elements of the tables. ++----------------------------------------------------------------------------- +*/ + +#include "typedefs.h" +#include "ccdtable.h" + +static const T_CCD_ValTabEntry ccddata_mval [] = +{ +#include "mval.cdg" +}; + +const T_CCD_ValTabEntry* ccddata_get_mval (USHORT idx) +{ + return &ccddata_mval[idx]; +} + +//TISH modified for MSIM +//Begin +#ifndef WIN32 +#ifdef CCDDATA_NO_CDEMSTR +const T_CCD_StrTabEntry* ccddata_get_mstr (USHORT idx) +{ + return &ccddata_mstr[idx]; +} +#endif /* CCDDATA_NO_CDEMSTR */ +#endif +//End
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccddata_cdepval.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,45 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccddata_cdepval.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Ccddata abstraction for use in lib/dll. The two tables +| pval and pstr, genereraed by ccdgen (in cdepval.cdg) +| are supplied. In addition, corresponding functions deliver +| specified elements of the tables. ++----------------------------------------------------------------------------- +*/ + +#include "typedefs.h" +#include "ccdtable.h" + +static const T_CCD_ValTabEntry ccddata_pval [] = +{ +#include "pval.cdg" +}; + +static const T_CCD_StrTabEntry ccddata_pstr [] = +{ +#include "pstr.cdg" +}; + +const T_CCD_ValTabEntry* ccddata_get_pval (USHORT idx) +{ + return &ccddata_pval[idx]; +} + +const T_CCD_StrTabEntry* ccddata_get_pstr (USHORT idx) +{ + return &ccddata_pstr[idx]; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccddata_eg.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,566 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccddata_eg.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : This module handles the entity graph functionality in ccddata. ++----------------------------------------------------------------------------- +*/ + +#define CCDDATA_EG_C + +/*==== INCLUDES ==============================================================*/ +#include "typedefs.h" +#include "ccdtable.h" +#include "ccddata.h" +/*==== CONSTS ================================================================*/ +#define MAXNODE 29 +#define MAXSAPS 157 +#define MAXCOMPAIRS 5 + +#define ENAME(e_index) #e_index + +#define MMI 0 +#define SIM 1 +#define SMS 2 +#define CC 3 +#define SM 4 +#define SS 5 +#define MM 6 +#define GMM 7 +#define RR 8 +#define GRR 9 +#define DL 10 +#define PL 11 +#define L2R 12 +#define T30 13 +#define RLP 14 +#define FAD 15 +#define LLC 16 +#define SND 17 +#define PPP 18 +#define UART 19 +#define PKT 20 +#define LC 21 +#define RRLP 22 +#define WAP 23 +#define UDP 24 +#define IP 25 +#define L1 26 +#define GRLC 27 +#define UPM 28 +/*==== TYPES =================================================================*/ +/*==== LOCALS ================================================================*/ +static char* sapnames[MAXSAPS] = +{ +/* 0 */ "MPHC", +/* 1 */ "PH", +/* 2 */ "MPHP", +/* 3 */ "DL", +/* 4 */ "MDL", +/* 5 */ "SIM", +/* 6 */ "RR", +/* 7 */ "MMCC", +/* 8 */ "MMSS", +/* 9 */ "MMSMS", +/* 10 */ "MMREG", +/* 11 */ "MNCC", +/* 12 */ "MNSS", +/* 13 */ "MNSMS", +/* 14 */ "MMI", +/* 15 */ "MON", +/* 16 */ "RA", +/* 17 */ "RLP", +/* 18 */ "L2R", +/* 19 */ "FAD", +/* 20 */ "T30", +/* 21 */ "ACI", +/* 22 */ "CST", +/* 23 */ "MPH", +/* 24 */ "TB", +/* 25 */ "TRA", +/* 26 */ "DMI", +/* 27 */ "IDA", +/* 28 */ "DCM", +/* 29 */ "unused", +/* 30 */ "FRM", +/* 31 */ "GMMRR", +/* 32 */ "GRR", +/* 33 */ "LLGMM", +/* 34 */ "LL", +/* 35 */ "GMMSMS", +/* 36 */ "GMMSM", +/* 37 */ "unused", +/* 38 */ "SMREG", +/* 39 */ "SNSM", +/* 40 */ "SN", +/* 41 */ "GSIM, to be removed", +/* 42 */ "unused", +/* 43 */ "unused", +/* 44 */ "unused", +/* 45 */ "RRGRR", +/* 46 */ "MMGMM", +/* 47 */ "unused", +/* 48 */ "unused", +/* 49 */ "unused", +/* 50 */ "MAC", +/* 51 */ "GMMREG", +/* 52 */ "UART", +/* 53 */ "PPP", +/* 54 */ "CCI", +/* 55 */ "DTI", +/* 56 */ "PPC", +/* 57 */ /* ??? "TOM/IP" */ "IP", +/* 58 */ "BTP", +/* 59 */ "UDPA", +/* 60 */ "IPA", +/* 61 */ "WAP", +/* 62 */ "EM", +/* 63 */ "EXTDSPL/GTI", +/* 64 */ "RRLC", +/* 65 */ "RRRRLP", +/* 66 */ "RRLP", +/* 67 */ "CSRLC", +/* 68 */ "MNLC", +/* 69 */ /* "PKTIO", */ "PKT", +/* 70 */ "UDP", +/* 71 */ "AAA", +/* 72 */ "TCPIP", +/* 73 */ "unused", +/* 74 */ "unused", +/* 75 */ "unused", +/* 76 */ "unused", +/* 77 */ "unused", +/* 78 */ "unused", +/* 79 */ "unused", +/* 80 */ "customer 6379", +/* 81 */ "customer 6379", +/* 82 */ "customer 6379", +/* 83 */ "customer 6379", +/* 84 */ "customer 6379", +/* 85 */ "customer 6379", +/* 86 */ "customer 6379", +/* 87 */ "customer 6379", +/* 88 */ "customer 6379", +/* 89 */ "customer 6379", +/* 90 */ "customer 6379", +/* 91 */ "unused", +/* 92 */ "unused", +/* 93 */ "unused", +/* 94 */ "unused", +/* 95 */ "unused", +/* 96 */ "unused", +/* 97 */ "unused", +/* 98 */ "unused", +/* 99 */ "unused", +/* 100 */ "unused", +/* 101 */ "unused", +/* 102 */ "unused", +/* 103 */ "unused", +/* 104 */ "unused", +/* 105 */ "unused", +/* 106 */ "unused", +/* 107 */ "unused", +/* 108 */ "unused", +/* 109 */ "unused", +/* 110 */ "unused", +/* 111 */ "unused", +/* 112 */ "unused", +/* 113 */ "unused", +/* 114 */ "unused", +/* 115 */ "unused", +/* 116 */ "unused", +/* 117 */ "unused", +/* 118 */ "unused", +/* 119 */ "unused", +/* 120 */ "unused", +/* 121 */ "unused", +/* 122 */ "unused", +/* 123 */ "unused", +/* 124 */ "unused", +/* 125 */ "unused", +/* 126 */ "unused", +/* 127 */ "unused", +/* 128 */ "CPHY", +/* 129 */ "PHY", +/* 130 */ "CUMAC", +/* 131 */ "UMAC", +/* 132 */ "CRLC", +/* 133 */ "RLC", +/* 134 */ "CBM", +/* 135 */ "HC", +/* 136 */ "CPDCP", +/* 137 */ "PDCP", +/* 138 */ "RRC", +/* 139 */ "MEM", +/* 140 */ "RRRRC", +/* 141 */ "GRRRRC", +/* 142 */ "RCM", +/* 143 */ "GMMRABM", +/* 144 */ "SM", +/* 145 */ "PMMSMS", +/* 146 */ "PHYSTUB", +/* 147 */ "PHYTEST", +/* 148 */ "MMREG", +/* 149 */ "MMCM", +/* 150 */ "MMPM", +/* 151 */ "GRLC", +/* 152 */ "CGRLC", +/* 153 */ "EINFO", +/* 154 */ "SL2", +/* 155 */ "L1TEST", +/* 156 */ "CL" +}; + +static T_COMENDPOINTS com_endpoints[MAXSAPS][MAXCOMPAIRS] = +{ +/* 0 (MPHC) */ { {PL, L1}, {RR, L1}, {-1, -1} }, +/* 1 (PH) */ { {DL, L1}, {-1, -1} }, +/* 2 (MPHP) */ { {GRR, L1}, {RR, L1}, {-1, -1} }, +/* 3 (DL) */ { {RR, DL}, {-1, -1} }, +/* 4 (MDL) */ { {MM, DL}, {-1, -1} }, +/* 5 (SIM) */ { {MMI, SIM}, {MM, SIM}, {GMM, SIM}, {SMS, SIM}, {-1, -1} }, +/* 6 (RR) */ { {MM, RR}, {-1, -1} }, +/* 7 (MMCC) */ { {CC, MM}, {-1, -1} }, +/* 8 (MMSS) */ { {SS, MM}, {-1, -1} }, +/* 9 (MMSMS) */ { {SMS, MM}, {-1, -1} }, +/* 10 (MMREG) */ { {MMI, MM}, {-1, -1} }, +/* 11 (MNCC) */ { {MMI, CC}, {-1, -1} }, +/* 12 (MNSS) */ { {MMI, SS}, {-1, -1} }, +/* 13 (MNSMS) */ { {MMI, SMS}, {-1, -1} }, +/* 14 (MMI) */ { /* {???, ???}, */ {-1, -1} }, +/* 15 (MON) */ { /* {???, ???}, */ {-1, -1} }, +/* 16 (RA) */ { {RLP, L1}, {FAD, L1}, {-1, -1} }, +/* 17 (RLP) */ { {L2R, RLP}, {-1, -1} }, +/* 18 (L2R) */ { {MMI, L2R}, {-1, -1} }, +/* 19 (FAD) */ { {T30, FAD}, {-1, -1} }, +/* 20 (T30) */ { {MMI, T30}, {-1, -1} }, +/* 21 (ACI) */ { /* {???, ???}, */ {-1, -1} }, +/* 22 (CST) */ { /* {???, ???}, */ {-1, -1} }, +/* 23 (MPH) */ { {RR, PL}, {-1, -1} }, +/* 24 (TB) */ { {GRR, PL}, {-1, -1} }, +/* 25 (TRA) */ { /* {???, ???}, */ {-1, -1} }, +/* 26 (DMI) */ { /* {???, ???}, */ {-1, -1} }, +/* 27 (IDA) */ { /* {???, ???}, */ {-1, -1} }, +/* 28 (DCM) */ { /* {???, ???}, */ {-1, -1} }, +/* 29 (unused) */ { {-1, -1} }, +/* 30 (FRM) */ { /* {???, ???}, */ {-1, -1} }, +/* 31 (GMMRR) */ { {GMM, GRR}, {-1, -1} }, +/* 32 (GRR) */ { {LLC, GRR}, {-1, -1} }, +/* 33 (LLGMM) */ { {GMM, LLC}, {MM, LLC}, {-1, -1} }, +/* 34 (LL) */ { {GMM, LLC}, {SMS, LLC}, {SND, LLC}, {MM, LLC}, {-1, -1} }, +/* 35 (GMMSMS) */ { {SMS, GMM}, {-1, -1} }, +/* 36 (GMMSM) */ { {SM, GMM}, {-1, -1} }, +/* 37 (unused) */ { {-1, -1} }, +/* 38 (SMREG) */ { {MMI, SM}, {-1, -1} }, +/* 39 (SNSM) */ { {SND, SM}, {-1, -1} }, +/* 40 (SN) */ { {MMI, SND}, {-1, -1} }, +/* 41 (GSIM, to be removed) */ { /* {???, ???}, */ {-1, -1} }, +/* 42 (unused) */ { {-1, -1} }, +/* 43 (unused) */ { {-1, -1} }, +/* 44 (unused) */ { {-1, -1} }, +/* 45 (RRGRR) */ { {RR, GRR}, {-1, -1} }, +/* 46 (MMGMM) */ { {MM, GMM}, {-1, -1} }, +/* 47 (unused) */ { {-1, -1} }, +/* 48 (unused) */ { {-1, -1} }, +/* 49 (unused) */ { {-1, -1} }, +/* 50 (MAC) */ { /* {???, ???}, */ {-1, -1} }, +/* 51 (GMMREG) */ { {MMI, GMM}, {-1, -1} }, +/* 52 (UART) */ { {MMI, UART}, {-1, -1} }, +/* 53 (PPP) */ { {MMI, PPP}, {-1, -1} }, +/* 54 (CCI) */ { /* {???, ???}, */ {-1, -1} }, +/* 55 (DTI) */ { /* {???, ???}, */ {-1, -1} }, +/* 56 (PPC) */ { /* {???, ???}, */ {-1, -1} }, +/* 57 (TOM/IP) */ { {UDP, IP}, {-1, -1} }, +/* 58 (BTP) */ { /* {???, ???}, */ {-1, -1} }, +/* 59 (UDPA) */ { {MMI, UDP}, {-1, -1} }, +/* 60 (IPA) */ { {MMI, IP}, {-1, -1} }, +/* 61 (WAP) */ { {MMI, WAP}, {-1, -1} }, +/* 62 (EM) */ { /* {???, ???}, */ {-1, -1} }, +/* 63 (EXTDSPL/GTI) */ { /* {???, ???}, */ {-1, -1} }, +/* 64 (RRLC) */ { {LC, RR}, {-1, -1} }, +/* 65 (RRRRLP) */ { {RRLP, RR}, {-1, -1} }, +/* 66 (RRLP) */ { /* {???, ???}, */ {-1, -1} }, +/* 67 (CSRLC) */ { /* {???, ???}, */ {-1, -1} }, +/* 68 (MNLC) */ { {MM, LC}, {-1, -1} }, +/* 69 (PKTIO) */ { {MMI, PKT}, {-1, -1} }, +/* 70 (UDP) */ { {WAP, UDP}, {SIM, UDP}, {-1, -1} }, +/* 71 (AAA) */ { /* {???, ???}, */ {-1, -1} }, +/* 72 (TCPIP) */ { /* {???, ???}, */ {-1, -1} }, +/* 73 (unused) */ { {-1, -1} }, +/* 74 (unused) */ { {-1, -1} }, +/* 75 (unused) */ { {-1, -1} }, +/* 76 (unused) */ { {-1, -1} }, +/* 77 (unused) */ { {-1, -1} }, +/* 78 (unused) */ { {-1, -1} }, +/* 79 (unused) */ { {-1, -1} }, +/* 80 (customer 6379) */ { /* {???, ???}, */ {-1, -1} }, +/* 81 (customer 6379) */ { /* {???, ???}, */ {-1, -1} }, +/* 82 (customer 6379) */ { /* {???, ???}, */ {-1, -1} }, +/* 83 (customer 6379) */ { /* {???, ???}, */ {-1, -1} }, +/* 84 (customer 6379) */ { /* {???, ???}, */ {-1, -1} }, +/* 85 (customer 6379) */ { /* {???, ???}, */ {-1, -1} }, +/* 86 (customer 6379) */ { /* {???, ???}, */ {-1, -1} }, +/* 87 (customer 6379) */ { /* {???, ???}, */ {-1, -1} }, +/* 88 (customer 6379) */ { /* {???, ???}, */ {-1, -1} }, +/* 89 (customer 6379) */ { /* {???, ???}, */ {-1, -1} }, +/* 90 (customer 6379) */ { /* {???, ???}, */ {-1, -1} }, +/* 91 (unused) */ { {-1, -1} }, +/* 92 (unused) */ { {-1, -1} }, +/* 93 (unused) */ { {-1, -1} }, +/* 94 (unused) */ { {-1, -1} }, +/* 95 (unused) */ { {-1, -1} }, +/* 96 (unused) */ { {-1, -1} }, +/* 97 (unused) */ { {-1, -1} }, +/* 98 (unused) */ { {-1, -1} }, +/* 99 (unused) */ { {-1, -1} }, +/* 100 (unused) */ { {-1, -1} }, +/* 101 (unused) */ { {-1, -1} }, +/* 102 (unused) */ { {-1, -1} }, +/* 103 (unused) */ { {-1, -1} }, +/* 104 (unused) */ { {-1, -1} }, +/* 105 (unused) */ { {-1, -1} }, +/* 106 (unused) */ { {-1, -1} }, +/* 107 (unused) */ { {-1, -1} }, +/* 108 (unused) */ { {-1, -1} }, +/* 109 (unused) */ { {-1, -1} }, +/* 110 (unused) */ { {-1, -1} }, +/* 111 (unused) */ { {-1, -1} }, +/* 112 (unused) */ { {-1, -1} }, +/* 113 (unused) */ { {-1, -1} }, +/* 114 (unused) */ { {-1, -1} }, +/* 115 (unused) */ { {-1, -1} }, +/* 116 (unused) */ { {-1, -1} }, +/* 117 (unused) */ { {-1, -1} }, +/* 118 (unused) */ { {-1, -1} }, +/* 119 (unused) */ { {-1, -1} }, +/* 120 (unused) */ { {-1, -1} }, +/* 121 (unused) */ { {-1, -1} }, +/* 122 (unused) */ { {-1, -1} }, +/* 123 (unused) */ { {-1, -1} }, +/* 124 (unused) */ { {-1, -1} }, +/* 125 (unused) */ { {-1, -1} }, +/* 126 (unused) */ { {-1, -1} }, +/* 127 (unused) */ { {-1, -1} }, +/* 128 (CPHY) */ { /* {???, ???}, */ {-1, -1} }, +/* 129 (PHY) */ { /* {???, ???}, */ {-1, -1} }, +/* 130 (CUMAC) */ { /* {???, ???}, */ {-1, -1} }, +/* 131 (UMAC) */ { /* {???, ???}, */ {-1, -1} }, +/* 132 (CRLC) */ { /* {???, ???}, */ {-1, -1} }, +/* 133 (RLC) */ { /* {???, ???}, */ {-1, -1} }, +/* 134 (CBM) */ { /* {???, ???}, */ {-1, -1} }, +/* 135 (HC) */ { /* {???, ???}, */ {-1, -1} }, +/* 136 (CPDCP) */ { /* {???, ???}, */ {-1, -1} }, +/* 137 (PDCP) */ { /* {???, ???}, */ {-1, -1} }, +/* 138 (RRC) */ { /* {???, ???}, */ {-1, -1} }, +/* 139 (MEM) */ { /* {???, ???}, */ {-1, -1} }, +/* 140 (RRRRC) */ { /* {???, ???}, */ {-1, -1} }, +/* 141 (GRRRRC) */ { /* {???, ???}, */ {-1, -1} }, +/* 142 (RCM) */ { /* {???, ???}, */ {-1, -1} }, +/* 143 (GMMRABM) */ { /* {???, ???}, */ {-1, -1} }, +/* 144 (SM) */ { /* {???, ???}, */ {-1, -1} }, +/* 145 (PMMSMS) */ { /* {???, ???}, */ {-1, -1} }, +/* 146 (PHYSTUB) */ { /* {???, ???}, */ {-1, -1} }, +/* 147 (PHYTEST) */ { /* {???, ???}, */ {-1, -1} }, +/* 148 (MMREG) */ { /* {???, ???}, */ {-1, -1} }, +/* 149 (MMCM) */ { /* {???, ???}, */ {-1, -1} }, +/* 150 (MMPM) */ { {MM, SM}, {-1, -1} }, +/* 151 (GRLC) */ { {LLC, GRLC}, {-1, -1} }, +/* 152 (CGRLC) */ { {GMM, GRLC}, {GRR, GRLC}, {MM, GRLC}, {RR, GRLC}, {-1, -1}}, +/* 153 (EINFO) */ { /* {???, ???}, */ {-1, -1} }, +/* 154 (SL2) */ { /* {???, ???}, */ {-1, -1} }, +/* 155 (L1TEST) */ { /* {???, ???}, */ {-1, -1} }, +/* 156 (CL) */ { /* {???, ???}, */ {-1, -1} } +}; + +static char* node[MAXNODE] = +{ + ENAME(MMI), + ENAME(SIM), + ENAME(SMS), + ENAME(CC), + ENAME(SM), + ENAME(SS), + ENAME(MM), + ENAME(GMM), + ENAME(RR), + ENAME(GRR), + ENAME(DL), + ENAME(PL), + ENAME(L2R), + ENAME(T30), + ENAME(RLP), + ENAME(FAD), + ENAME(LLC), + ENAME(SND), + ENAME(PPP), + ENAME(UART), + ENAME(PKT), + ENAME(LC), + ENAME(RRLP), + ENAME(WAP), + ENAME(UDP), + ENAME(IP), + ENAME(L1), + ENAME(GRLC), + ENAME(UPM) +}; + +/* adjacence matrix. 1 = directly connected, 0 = not + here symmtric = undirected graph, + could later be changed to a directed graph */ + +static char ad[MAXNODE][MAXNODE] = +{ /* M S S C S S M G R G D P L T R F L S P U P L R W U I L G U + M I M C M S M M R R L L 2 3 L A L N P A K C R A D P 1 R P + I M S M R R 0 P D C D P R T L P P L M + T P C + */ +/* MMI */ 1,1,1,1,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,1,0,0,1,1,1,1,0,1, +/* SIM */ 1,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0, +/* SMS */ 1,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0, +/* CC */ 1,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +/* SM */ 1,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1, +/* SS */ 1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +/* MM */ 1,1,1,1,1,1,1,1,1,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0, +/* GMM */ 1,1,1,0,1,0,1,1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1, +/* RR */ 0,0,0,0,0,0,1,0,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0, +/* GRR */ 0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0, +/* DL */ 0,0,0,0,0,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0, +/* PL */ 1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0, +/* L2R */ 1,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0, +/* T30 */ 1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, +/* RLP */ 0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0, +/* FAD */ 0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0, +/* LLC */ 0,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,0, +/* SND */ 1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,0,0,0,0,0,0,0,1, +/* PPP */ 1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,1,0,0,0,0,0,1,0,0,0, +/* UART */ 1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0, +/* PKT */ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0, +/* LC */ 0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0, +/* RRLP */ 0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0, +/* WAP */ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0, +/* UDP */ 1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0, +/* IP */ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,0,0,0, +/* L1 */ 1,0,0,0,0,0,0,0,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0, +/* GRLC */ 0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0, +/* UPM */ 1,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1, +}; + +/*==== PRIVATE FUNCTIONS =====================================================*/ +/*==== PUBLIC FUNCTIONS ======================================================*/ + +/* ++------------------------------------------------------------------------------ +| Function : ccddata_eg_nodes ++------------------------------------------------------------------------------ +| Description : Returns the number of nodes in the entity graph. +| +| Parameters : - +| +| Return : The number of nodes. +| ++------------------------------------------------------------------------------ +*/ + +int ccddata_eg_nodes (void) +{ + return MAXNODE; +} + +/* ++------------------------------------------------------------------------------ +| Function : ccddata_eg_nodenames ++------------------------------------------------------------------------------ +| Description : Returns a pointer to the node name table. +| +| Parameters : - +| +| Return : The address of the nodename table. +| ++------------------------------------------------------------------------------ +*/ +char** ccddata_eg_nodenames (void) +{ + return node; +} + +/* ++------------------------------------------------------------------------------ +| Function : ccddata_eg_adjacent ++------------------------------------------------------------------------------ +| Description : Returns a pointer to one row in the adjacence matrix. +| +| Parameters : idx - line in matrix (0..nodes-1). +| +| Return : The address of the selected row. +| ++------------------------------------------------------------------------------ +*/ +char* ccddata_eg_adjacent (int idx) +{ + return ad[idx]; +} + +/* ++------------------------------------------------------------------------------ +| Function : ccddata_eg_saps ++------------------------------------------------------------------------------ +| Description : Returns the number of SAPs (including gaps). +| +| Parameters : - +| +| Return : The number of SAPs. +| ++------------------------------------------------------------------------------ +*/ + +int ccddata_eg_saps (void) +{ + return MAXSAPS; +} + +/* ++------------------------------------------------------------------------------ +| Function : ccddata_eg_sapnames ++------------------------------------------------------------------------------ +| Description : Returns a pointer to the SAP name table. +| +| Parameters : - +| +| Return : The address of the sapname table. +| ++------------------------------------------------------------------------------ +*/ +char** ccddata_eg_sapnames (void) +{ + return sapnames; +} + +/* ++------------------------------------------------------------------------------ +| Function : ccddata_eg_comendpoints ++------------------------------------------------------------------------------ +| Description : Returns a pointer to one row in the comendpoint list. +| +| Parameters : idx - line in list (0..SAPs-1). +| +| Return : The address of the selected row. +| ++------------------------------------------------------------------------------ +*/ +T_COMENDPOINTS* ccddata_eg_comendpoints (int idx) +{ + return com_endpoints[idx]; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccddata_load.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,3790 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccddata_load.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Manage the explicit dynamic loading of ccddata. ++----------------------------------------------------------------------------- +*/ + +/*==== INCLUDES ==============================================================*/ +#include <windows.h> +#include <string.h> +#include <stdio.h> +#include "typedefs.h" +#include "vsi.h" +#include "ccdtable.h" +#include "ccdapi.h" +#include "pdi.h" +#include "pcon.h" +#include "ccdedit.h" +#include "ccddata.h" +#include "ccddata_tap_priv.h" +/*==== CONSTS ================================================================*/ +#define MAXPROC 16 +/*==== TYPES =================================================================*/ +/* pcon.c */ +typedef ULONG (*T_pcon_init_prim_coding)(T_HANDLE caller, UBYTE format); +typedef ULONG (*T_pcon_decodePrim)(ULONG opc, + void ** decoded_prim, + void * coded_prim, + ULONG * length, + ULONG woff); +typedef ULONG (*T_pcon_codePrim)(ULONG opc, + void * decoded_prim, + void ** coded_prim, + ULONG * length, + ULONG woff, + char* receiver); +typedef ULONG (*T_pcon_init_ccddata)(void); +typedef ULONG (*T_pcon_make_filter)(char* string, void** prim); +typedef ULONG (*T_pcon_filter_decode_prim)(ULONG opc, + void** decoded_prim, + void* coded_prim, + ULONG* length, + ULONG woff, + void** shadow_prim); +/* ccddata_pdi.c */ +typedef int (*T_ccddata_get_pdi_dinfo)(const T_PDI_DECODEINFO* (*dinfo) ); +/* ccddata_mconst.c */ +typedef int (*T_ccddata_get_num_of_entities)(void); +typedef int (*T_ccddata_get_max_message_id)(void); +typedef int (*T_ccddata_get_max_bitstream_len)(void); +typedef int (*T_ccddata_get_max_mstruct_len)(void); +typedef int (*T_ccddata_get_max_mstruct_len)(void); +typedef int (*T_ccddata_mccd_symbols)(void); +/* ccddata_pconst.c */ +typedef int (*T_ccddata_get_max_sap_num)(void); +typedef int (*T_ccddata_get_max_primitive_id)(void); +typedef int (*T_ccddata_get_max_pstruct_len)(void); +/* ccddata_ccdmtab.c */ +typedef const T_CCD_VarTabEntry* (*T_ccddata_get_mvar) (USHORT idx); +typedef const T_CCD_SpareTabEntry* (*T_ccddata_get_spare) (USHORT idx); +typedef const T_CCD_CalcTabEntry* (*T_ccddata_get_calc) (USHORT idx); +typedef const T_CCD_CompTabEntry* (*T_ccddata_get_mcomp) (USHORT idx); +typedef const T_CCD_ElemTabEntry* (*T_ccddata_get_melem) (USHORT idx); +typedef const T_CCD_CalcIndex* (*T_ccddata_get_calcidx) (USHORT idx); +typedef USHORT (*T_ccddata_get_mmtx) (USHORT entity, USHORT msgid, USHORT idx); +/* ccddata_ccdptab.c */ +typedef const T_CCD_VarTabEntry* (*T_ccddata_get_pvar) (USHORT idx); +typedef const T_CCD_CompTabEntry* (*T_ccddata_get_pcomp) (USHORT idx); +typedef const T_CCD_ElemTabEntry* (*T_ccddata_get_pelem) (USHORT idx); +typedef USHORT (*T_ccddata_get_pmtx) (USHORT sap, USHORT primid, USHORT idx); +/* ccddata_cdemval.c */ +typedef const T_CCD_ValTabEntry* (*T_ccddata_get_mval) (USHORT idx); +/* ccddata_cdemstr.c */ +typedef const T_CCD_StrTabEntry* (*T_ccddata_get_mstr) (USHORT idx); +/* ccddata_cdepval.c */ +typedef const T_CCD_ValTabEntry* (*T_ccddata_get_pval) (USHORT idx); +typedef const T_CCD_StrTabEntry* (*T_ccddata_get_pstr) (USHORT idx); +/* ccddata_ccdent.c */ +typedef short (*T_ccddata_get_ccdent) (char* entname); +typedef const char * (*T_ccddata_get_entname) (short ccdent); +/* ccddata_alias.c */ +typedef char* (*T_ccddata_get_alias) (USHORT idx, int from_msg); +/* ccddata_version.c */ +typedef char* (*T_ccddata_get_version) (); +typedef int (*T_ccddata_get_table_version) (); +/* ccd_config.c */ +typedef UBYTE* (*T_ccddata_get_mi_length) (void); +typedef UBYTE* (*T_ccddata_get_decmsgbuffer) (void); +/* ccddata_tap_priv.c */ +typedef int (*T_ccddata_tap_get_pd) (UCHAR comp); +typedef int (*T_ccddata_tap_check_pd) (UCHAR comp, UCHAR pd); +/* ccddata_eg.c */ +typedef int (*T_ccddata_eg_nodes) (void); +typedef char** (*T_ccddata_eg_nodenames) (void); +typedef char* (*T_ccddata_eg_adjacent) (int idx); +typedef int (*T_ccddata_eg_saps) (void); +typedef char** (*T_ccddata_eg_sapnames) (void); +typedef T_COMENDPOINTS* (*T_ccddata_eg_comendpoints) (int idx); +/* ccdedit.c */ +typedef void (*T_cde_init) (void); +typedef USHORT (*T_cde_get_comp) (T_CCDE_HANDLE* chandle, + T_CCDE_ELEM_DESCR* edescr); +typedef USHORT (*T_cde_prim_first) (T_CCDE_HANDLE* phandle, + ULONG primcode, + char* name); +typedef USHORT (*T_cde_prim_next) (T_CCDE_HANDLE* phandle, + UBYTE descent, + T_CCDE_ELEM_DESCR* pdescr); +typedef USHORT (*T_cde_msg_first) (T_CCDE_HANDLE* mhandle, + UBYTE type, + UBYTE direction, + UBYTE entity, + char* name); +typedef USHORT (*T_cde_msg_next) (T_CCDE_HANDLE* mhandle, + UBYTE descent, + T_CCDE_ELEM_DESCR* iedesrc); +typedef USHORT (*T_cde_comp_first) (T_CCDE_HANDLE* chandle, + T_ELM_SRC source, + char* compname); +typedef USHORT (*T_cde_comp_next) (T_CCDE_HANDLE* chandle, + UBYTE descent, + T_CCDE_ELEM_DESCR* descr); +typedef char* (*T_cde_get_symval) (int elem_value, + T_CCDE_ELEM_DESCR* descr); +typedef USHORT (*T_cde_read_elem) (T_CCDE_HANDLE* handle, + void* cstruct, + T_CCDE_ELEM_DESCR* descr, + UBYTE* value); +typedef void (*T_cde_write_prepare) (T_CCDE_HANDLE* handle, + void* cstruct, + T_CCDE_ELEM_DESCR* descr); +typedef USHORT (*T_cde_write_elem) (T_CCDE_HANDLE* handle, + void* cstruct, + T_CCDE_ELEM_DESCR* descr, + UBYTE* value); +typedef USHORT (*T_cde_get_type) (char* name, T_ELM_SRC* source); +typedef USHORT (*T_cde_get_primcode) (char* name, ULONG* primcode); +typedef USHORT (*T_cde_get_msgcode) (char* name, + UBYTE* type, + UBYTE* direction, + UBYTE* entity); +typedef int (*T_cde_get_is_downlink) (ULONG comp_index); +typedef ULONG (*T_cde_get_comp_index) (char* comp_name, T_ELM_SRC table); +typedef char* (*T_cde_get_element_name) (ULONG comp_index, + USHORT elem_off, + T_ELM_SRC table); +typedef ULONG (*T_cde_get_array_kind) (char* var_name, T_ELM_SRC table); +/* pdi.c */ +typedef T_PDI_CONTEXT* (*T_pdi_createDefContext) (); +typedef T_PDI_CONTEXT* (*T_pdi_createContext) (const T_PDI_DECODEINFO* dinfop, + unsigned int dicount); +typedef void (*T_pdi_destroyContext) (T_PDI_CONTEXT* context); +typedef void (*T_pdi_startPrim) (T_PDI_CONTEXT* context, ULONG opc); +typedef void (*T_pdi_getDecodeInfo) (T_PDI_CONTEXT* context, + const char* ename, + char* evalue, + int evlen, + T_PDI* decinfo); +typedef short (*T_pdi_getEntityByPD) (const T_PDI_CONTEXT* context, + unsigned char pd); +typedef const char* (*T_pdi_pd2name) (unsigned char pd); +/* ccd.c */ +typedef int (*T_ccd_set_patch_infos) (T_patch_info* pinfo); +typedef BYTE (*T_ccd_init) (void); +typedef int (*T_ccd_exit) (void); +typedef UBYTE* (*T_ccd_begin) (void); +typedef void (*T_ccd_end) (void); +typedef BYTE (*T_ccd_decodeMsg) (UBYTE entity, + UBYTE direction, + T_MSGBUF *mBuf, + UBYTE *mStruct, + UBYTE pt); +typedef S8 (*T_ccd_decodeMsgPtr) (U8 entity, + U8 direction, + U16 l_buf, + U16 o_buf, + U8 *buf, + U8 **mStructPtr, + U8 pt); +typedef BYTE (*T_ccd_codeMsg) (UBYTE entity, + UBYTE direction, + T_MSGBUF *mBuf, + UBYTE *mStruct, + UBYTE pt); +typedef BYTE (*T_ccd_codeMsgPtr) (U8 entity, + U8 direction, + U16 *l_buf, + U16 o_buf, + U8 *buf, + U8 *mStruct, + U8 pt); +typedef ULONG (*T_ccd_init_ccddata) (void); +/* cdc_std.c */ +typedef BYTE (*T_ccd_decodeByte) (UBYTE *bitstream, + USHORT startbit, + USHORT bitlen, + UBYTE *value); +typedef BYTE (*T_ccd_codeByte) (UBYTE *bitstream, + USHORT startbit, + USHORT bitlen, + UBYTE val); +typedef BYTE (*T_ccd_codeLong) (UBYTE *bitstream, + USHORT startbit, + USHORT bitlen, + ULONG value); +typedef BYTE (*T_ccd_decodeLong) (UBYTE *bitstream, + USHORT startbit, + USHORT bitlen, + ULONG *value); +typedef void (*T_ccd_bitcopy) (UBYTE *dest, + UBYTE *source, + USHORT bitlen, + USHORT offset); +/* ccd_err.c */ +typedef UBYTE (*T_ccd_getFirstError) (UBYTE entity, USHORT *parlist); +typedef UBYTE (*T_ccd_getNextError) (UBYTE entity, USHORT *parlist); +typedef ULONG (*T_ccd_getFirstFault) (T_CCD_ERR_ENTRY **ccd_err_entry); +typedef ULONG (*T_ccd_getNextFault) (T_CCD_ERR_ENTRY **ccd_err_entry); +typedef void (*T_ccd_free_faultlist) (void); +typedef int (*T_ccd_get_numFaults) (void); +/* ccd_elem.c */ +typedef int (*T_ccd_encodeElem) (ULONG ccdid, + USHORT *l_buf, + USHORT o_buf, + UCHAR *buf, + UCHAR *eStruct); + +typedef int (*T_ccd_decodeElem) (ULONG ccdid, + USHORT l_buf, + USHORT o_buf, + UCHAR *buf, + UCHAR *eStruct); +/*==== LOCALS ================================================================*/ +static int me = -1; +static HANDLE initlock; +static void (*ccddata_i_notify)(void)=NULL; +static void (*ccddata_x_notify)(void)=NULL; + +static int ccddata_attach (int i); + +#pragma data_seg(".shared") +static char lastdll[MAX_PATH] = { 0 }; +static DWORD ptrindex[MAXPROC] = {0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 }; +static HINSTANCE cdll[MAXPROC] = {0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 }; +static HANDLE mut[MAXPROC] = {0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 }; +static T_pcon_init_prim_coding ptr_pcon_init_prim_coding[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_pcon_decodePrim ptr_pcon_decodePrim[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_pcon_codePrim ptr_pcon_codePrim[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_pcon_init_ccddata ptr_pcon_init_ccddata[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_pcon_make_filter ptr_pcon_make_filter[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_pcon_filter_decode_prim ptr_pcon_filter_decode_prim[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_pdi_dinfo ptr_ccddata_get_pdi_dinfo[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_num_of_entities ptr_ccddata_get_num_of_entities[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_max_message_id ptr_ccddata_get_max_message_id[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_max_bitstream_len + ptr_ccddata_get_max_bitstream_len[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_max_mstruct_len ptr_ccddata_get_max_mstruct_len[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_mccd_symbols ptr_ccddata_mccd_symbols[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_max_sap_num ptr_ccddata_get_max_sap_num[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_max_primitive_id ptr_ccddata_get_max_primitive_id[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_max_pstruct_len ptr_ccddata_get_max_pstruct_len[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_mvar ptr_ccddata_get_mvar[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_spare ptr_ccddata_get_spare[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_calc ptr_ccddata_get_calc[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_mcomp ptr_ccddata_get_mcomp[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_melem ptr_ccddata_get_melem[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_calcidx ptr_ccddata_get_calcidx[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_mmtx ptr_ccddata_get_mmtx[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_pvar ptr_ccddata_get_pvar[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_pcomp ptr_ccddata_get_pcomp[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_pelem ptr_ccddata_get_pelem[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_pmtx ptr_ccddata_get_pmtx[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_mval ptr_ccddata_get_mval[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_mstr ptr_ccddata_get_mstr[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_pval ptr_ccddata_get_pval[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_pstr ptr_ccddata_get_pstr[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_ccdent ptr_ccddata_get_ccdent[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_entname ptr_ccddata_get_entname[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_alias ptr_ccddata_get_alias[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_version ptr_ccddata_get_version[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_table_version ptr_ccddata_get_table_version[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_mi_length ptr_ccddata_get_mi_length[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static UBYTE* mi_length[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_get_decmsgbuffer ptr_ccddata_get_decmsgbuffer[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static UBYTE* decmsgbuffer[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_tap_check_pd ptr_ccddata_tap_check_pd[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_tap_get_pd ptr_ccddata_tap_get_pd[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_eg_nodes ptr_ccddata_eg_nodes[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_eg_nodenames ptr_ccddata_eg_nodenames[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_eg_adjacent ptr_ccddata_eg_adjacent[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_eg_saps ptr_ccddata_eg_saps[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_eg_sapnames ptr_ccddata_eg_sapnames[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccddata_eg_comendpoints ptr_ccddata_eg_comendpoints[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_cde_init ptr_cde_init[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_cde_get_comp ptr_cde_get_comp[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_cde_prim_first ptr_cde_prim_first[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_cde_prim_next ptr_cde_prim_next[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_cde_msg_first ptr_cde_msg_first[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_cde_msg_next ptr_cde_msg_next[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_cde_comp_first ptr_cde_comp_first[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_cde_comp_next ptr_cde_comp_next[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_cde_get_symval ptr_cde_get_symval[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_cde_read_elem ptr_cde_read_elem[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_cde_write_prepare ptr_cde_write_prepare[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_cde_write_elem ptr_cde_write_elem[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_cde_get_type ptr_cde_get_type[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_cde_get_primcode ptr_cde_get_primcode[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_cde_get_msgcode ptr_cde_get_msgcode[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_cde_get_is_downlink ptr_cde_get_is_downlink[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_cde_get_comp_index ptr_cde_get_comp_index[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_cde_get_element_name ptr_cde_get_element_name[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_cde_get_array_kind ptr_cde_get_array_kind[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_pdi_createDefContext ptr_pdi_createDefContext[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_pdi_createContext ptr_pdi_createContext[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_pdi_destroyContext ptr_pdi_destroyContext[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_pdi_startPrim ptr_pdi_startPrim[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_pdi_getDecodeInfo ptr_pdi_getDecodeInfo[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_pdi_getEntityByPD ptr_pdi_getEntityByPD[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_pdi_pd2name ptr_pdi_pd2name[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_set_patch_infos ptr_ccd_set_patch_infos[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_init ptr_ccd_init[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_exit ptr_ccd_exit[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_begin ptr_ccd_begin[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_end ptr_ccd_end[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_decodeMsg ptr_ccd_decodeMsg[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_decodeMsgPtr ptr_ccd_decodeMsgPtr[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_codeMsg ptr_ccd_codeMsg[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_codeMsgPtr ptr_ccd_codeMsgPtr[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_init_ccddata ptr_ccd_init_ccddata[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_decodeByte ptr_ccd_decodeByte[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_codeByte ptr_ccd_codeByte[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_codeLong ptr_ccd_codeLong[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_decodeLong ptr_ccd_decodeLong[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_bitcopy ptr_ccd_bitcopy[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_getFirstError ptr_ccd_getFirstError[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_getNextError ptr_ccd_getNextError[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_getFirstFault ptr_ccd_getFirstFault[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_getNextFault ptr_ccd_getNextFault[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_free_faultlist ptr_ccd_free_faultlist[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_get_numFaults ptr_ccd_get_numFaults[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_encodeElem ptr_ccd_encodeElem[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static T_ccd_decodeElem ptr_ccd_decodeElem[MAXPROC] + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +#pragma data_seg() + + +/*==== HANDLER FOR FUNCTIONS UNSUPPORTED BY LOADED DLL =======================*/ +int cddl_ccddata_get_pdi_dinfo (const T_PDI_DECODEINFO* (*dinfo) ) +{ + dinfo=NULL; + return 0; +} + +int cddl_ccddata_eg_nodes (void) +{ + return 0; +} + +char** cddl_ccddata_eg_nodenames (void) +{ + return NULL; +} + +char* cddl_ccddata_eg_adjacent (int idx) +{ + return NULL; +} + +int cddl_ccddata_eg_saps (void) +{ + return 0; +} + +char** cddl_ccddata_eg_sapnames (void) +{ + return NULL; +} + +T_COMENDPOINTS* cddl_ccddata_eg_comendpoints (int idx) +{ + return NULL; +} + +char* cddl_ccddata_get_version (void) +{ + return "OLD"; +} + +int cddl_ccddata_get_table_version (void) +{ + return 0; +} + +const char * cddl_ccddata_get_entname (short ccdent) +{ + return NULL; +} +/*==== PRIVATE FUNCTIONS =====================================================*/ +/* ++------------------------------------------------------------------------------ +| Function : ccddata_init_lock ++------------------------------------------------------------------------------ +| Description : Synchronize calls of ccddata_init +| +| Parameters : - +| +| Return : 0 on success, otherwise error code ++------------------------------------------------------------------------------ +*/ +static HANDLE ccddata_init_lock (void) +{ + char* mname = "ccddata_init_lock"; + HANDLE tmp; + if ((tmp = CreateMutex (NULL, FALSE, mname)) == 0) + { + return 0; + } + if ((initlock = OpenMutex (MUTEX_ALL_ACCESS, FALSE, mname)) == 0) + { + return 0; + } + CloseHandle (tmp); + WaitForSingleObject (initlock, INFINITE); + return initlock; +} + +/* ++------------------------------------------------------------------------------ +| Function : ccddata_register ++------------------------------------------------------------------------------ +| Description : Register process in ccddata load dll +| +| Parameters : - +| +| Return : Index to ptrindex on success, otherwise -1 ++------------------------------------------------------------------------------ +*/ +static int ccddata_register (void) +{ + if (me >= 0) + { + return me; + } + for (me=0; me<MAXPROC; me++) + { + if (!ptrindex[me]) + { + char mname[32]; + HANDLE tmp; + ptrindex[me] = GetCurrentProcessId (); + sprintf (mname, "ccddata_%d", ptrindex[me]); + tmp = CreateMutex (NULL, FALSE, mname); + mut[me] = OpenMutex (MUTEX_ALL_ACCESS, FALSE, mname); + CloseHandle (tmp); + return me; + } + } + me = -1; + return me; +} + +/* ++------------------------------------------------------------------------------ +| Function : ccddata_detach ++------------------------------------------------------------------------------ +| Description : Unload ccddata dll and clean pointer to the functions +| +| Parameters : i - index to pointer list +| exit_all - if set, call ccd_exit and call FreeLibrary +| +| Return : - ++------------------------------------------------------------------------------ +*/ +static void ccddata_detach (int i, int exit_all) +{ + char mname[32]; + HANDLE mutex; + + if (!cdll[i]) + return; + + if (ccddata_x_notify != NULL && exit_all) + { + // make sure all functions are available again + if (ptr_ccd_init[i] != NULL || ccddata_attach(i)==CCDDATA_DLL_OK) + { + (*ccddata_x_notify)(); + } + } + + if (ptr_ccd_init[i] != NULL) + { + // clean all function pointers except ccd_exit + if (!exit_all) + { + sprintf (mname, "ccddata_%d", ptrindex[i]); + mutex = OpenMutex (MUTEX_ALL_ACCESS, FALSE, mname); + WaitForSingleObject (mutex, INFINITE); + } + + ptr_pcon_init_prim_coding[i] = NULL; + ptr_pcon_decodePrim[i] = NULL; + ptr_pcon_codePrim[i] = NULL; + ptr_pcon_init_ccddata[i] = NULL; + ptr_pcon_make_filter[i] = NULL; + ptr_pcon_filter_decode_prim[i] = NULL; + ptr_ccddata_get_pdi_dinfo[i] = NULL; + ptr_ccddata_get_num_of_entities[i] = NULL; + ptr_ccddata_get_max_message_id[i] = NULL; + ptr_ccddata_get_max_bitstream_len[i] = NULL; + ptr_ccddata_get_max_mstruct_len[i] = NULL; + ptr_ccddata_mccd_symbols[i] = NULL; + ptr_ccddata_get_max_sap_num[i] = NULL; + ptr_ccddata_get_max_primitive_id[i] = NULL; + ptr_ccddata_get_max_pstruct_len[i] = NULL; + ptr_ccddata_get_mvar[i] = NULL; + ptr_ccddata_get_spare[i] = NULL; + ptr_ccddata_get_calc[i] = NULL; + ptr_ccddata_get_mcomp[i] = NULL; + ptr_ccddata_get_melem[i] = NULL; + ptr_ccddata_get_calcidx[i] = NULL; + ptr_ccddata_get_mmtx[i] = NULL; + ptr_ccddata_get_pvar[i] = NULL; + ptr_ccddata_get_pcomp[i] = NULL; + ptr_ccddata_get_pelem[i] = NULL; + ptr_ccddata_get_pmtx[i] = NULL; + ptr_ccddata_get_mval[i] = NULL; + ptr_ccddata_get_mstr[i] = NULL; + ptr_ccddata_get_pval[i] = NULL; + ptr_ccddata_get_pstr[i] = NULL; + ptr_ccddata_get_ccdent[i] = NULL; + ptr_ccddata_get_entname[i] = NULL; + ptr_ccddata_get_alias[i] = NULL; + ptr_ccddata_get_version[i] = NULL; + ptr_ccddata_get_table_version[i] = NULL; + ptr_ccddata_get_mi_length[i] = NULL; + mi_length[i] = NULL; + ptr_ccddata_get_decmsgbuffer[i] = NULL; + decmsgbuffer[i] = NULL; + ptr_ccddata_tap_check_pd[i] = NULL; + ptr_ccddata_tap_get_pd[i] = NULL; + ptr_ccddata_eg_nodes[i] = NULL; + ptr_ccddata_eg_nodenames[i] = NULL; + ptr_ccddata_eg_adjacent[i] = NULL; + ptr_ccddata_eg_saps[i] = NULL; + ptr_ccddata_eg_sapnames[i] = NULL; + ptr_ccddata_eg_comendpoints[i] = NULL; + + ptr_cde_init[i] = NULL; + ptr_cde_get_comp[i] = NULL; + ptr_cde_prim_first[i] = NULL; + ptr_cde_prim_next[i] = NULL; + ptr_cde_msg_first[i] = NULL; + ptr_cde_msg_next[i] = NULL; + ptr_cde_comp_first[i] = NULL; + ptr_cde_comp_next[i] = NULL; + ptr_cde_get_symval[i] = NULL; + ptr_cde_read_elem[i] = NULL; + ptr_cde_write_prepare[i] = NULL; + ptr_cde_write_elem[i] = NULL; + ptr_cde_get_type[i] = NULL; + ptr_cde_get_primcode[i] = NULL; + ptr_cde_get_msgcode[i] = NULL; + ptr_cde_get_is_downlink[i] = NULL; + ptr_cde_get_comp_index[i] = NULL; + ptr_cde_get_element_name[i] = NULL; + ptr_cde_get_array_kind[i] = NULL; + + ptr_pdi_createDefContext[i] = NULL; + ptr_pdi_createContext[i] = NULL; + ptr_pdi_destroyContext[i] = NULL; + ptr_pdi_startPrim[i] = NULL; + ptr_pdi_getDecodeInfo[i] = NULL; + ptr_pdi_getEntityByPD[i] = NULL; + ptr_pdi_pd2name[i] = NULL; + + ptr_ccd_set_patch_infos[i] = NULL; + ptr_ccd_begin[i] = NULL; + ptr_ccd_end[i] = NULL; + ptr_ccd_decodeMsg[i] = NULL; + ptr_ccd_decodeMsgPtr[i] = NULL; + ptr_ccd_codeMsg[i] = NULL; + ptr_ccd_codeMsgPtr[i] = NULL; + ptr_ccd_init_ccddata[i] = NULL; + ptr_ccd_decodeByte[i] = NULL; + ptr_ccd_codeByte[i] = NULL; + ptr_ccd_codeLong[i] = NULL; + ptr_ccd_decodeLong[i] = NULL; + ptr_ccd_bitcopy[i] = NULL; + ptr_ccd_getFirstError[i] = NULL; + ptr_ccd_getNextError[i] = NULL; + ptr_ccd_getFirstFault[i] = NULL; + ptr_ccd_getNextFault[i] = NULL; + ptr_ccd_free_faultlist[i] = NULL; + ptr_ccd_get_numFaults[i] = NULL; + ptr_ccd_encodeElem[i] = NULL; + ptr_ccd_decodeElem[i] = NULL; + ptr_ccd_init[i] = NULL; + + if (!exit_all) + { + ReleaseMutex (mutex); + CloseHandle (mutex); + } + } + + if (exit_all) + { + if (ptr_ccd_exit[i]) + { + (void)(*ptr_ccd_exit[i])(); + ptr_ccd_exit[i] = NULL; + } + (void) FreeLibrary (cdll[i]); + cdll[i] = 0; + } +} + +/* ++------------------------------------------------------------------------------ +| Function : ccddata_clean ++------------------------------------------------------------------------------ +| Description : Free own instance of ccddata dll and clean the pointers +| of the other processes. +| +| Parameters : - +| +| Return : CCDDATA_DLL_REGISTER, if the process is not registered +| or has not yet called ccddata_exit; CCDDATA_DLL_OK otherwise ++------------------------------------------------------------------------------ +*/ +static int ccddata_clean (void) +{ + int i; + + if (me < 0) + { + return CCDDATA_DLL_REGISTER; + } + + for (i=0; i<MAXPROC; i++) + { + if (me != i) + { + ccddata_detach (i, 0); + } + } + + return CCDDATA_DLL_OK; +} + +/* ++------------------------------------------------------------------------------ +| Function : ccddata_attach ++------------------------------------------------------------------------------ +| Description : Unload ccddata dll and clean pointer to the functions +| +| Parameters : i - index to pointer list +| +| Return : CCDDATA_DLL_OK or error code ++------------------------------------------------------------------------------ +*/ +static int ccddata_attach (int i) +{ + int already_loaded=(cdll[i]!=0); + if (!already_loaded) + { + cdll[i] = LoadLibrary (lastdll); + if (cdll[i] == NULL) + { + return CCDDATA_DLL_LOADLIB; + } + } + + ptr_pcon_init_prim_coding[i] = (T_pcon_init_prim_coding) + GetProcAddress (cdll[i], "cddl_pcon_init_prim_coding"); + ptr_pcon_decodePrim[i] = (T_pcon_decodePrim) + GetProcAddress (cdll[i], "cddl_pcon_decodePrim"); + ptr_pcon_codePrim[i] = (T_pcon_codePrim) + GetProcAddress (cdll[i], "cddl_pcon_codePrim"); + ptr_pcon_init_ccddata[i] = (T_pcon_init_ccddata) + GetProcAddress (cdll[i], "cddl_pcon_init_ccddata"); + ptr_pcon_make_filter[i] = (T_pcon_make_filter) + GetProcAddress (cdll[i], "cddl_pcon_make_filter"); + ptr_pcon_filter_decode_prim[i] = (T_pcon_filter_decode_prim) + GetProcAddress (cdll[i], "cddl_pcon_filter_decode_prim"); + + if ( + ptr_pcon_init_prim_coding[i] == NULL || + ptr_pcon_decodePrim[i] == NULL || + ptr_pcon_codePrim[i] == NULL || + ptr_pcon_init_ccddata[i] == NULL || + ptr_pcon_make_filter[i] == NULL || + ptr_pcon_filter_decode_prim[i] == NULL) + { + ptr_pcon_init_prim_coding[i] = cddl_pcon_init_prim_coding; + ptr_pcon_decodePrim[i] = cddl_pcon_decodePrim; + ptr_pcon_codePrim[i] = cddl_pcon_codePrim; + ptr_pcon_init_ccddata[i] = cddl_pcon_init_ccddata; + ptr_pcon_make_filter[i] = cddl_pcon_make_filter; + ptr_pcon_filter_decode_prim[i] = cddl_pcon_filter_decode_prim; + } + + ptr_ccd_init[i] = (T_ccd_init) + GetProcAddress (cdll[i], "cddl_ccd_init"); + ptr_ccd_exit[i] = (T_ccd_exit) + GetProcAddress (cdll[i], "cddl_ccd_exit"); + ptr_ccd_begin[i] = (T_ccd_begin) + GetProcAddress (cdll[i], "cddl_ccd_begin"); + ptr_ccd_end[i] = (T_ccd_end) + GetProcAddress (cdll[i], "cddl_ccd_end"); + ptr_ccd_decodeMsg[i] = (T_ccd_decodeMsg) + GetProcAddress (cdll[i], "cddl_ccd_decodeMsg"); + ptr_ccd_decodeMsgPtr[i] = (T_ccd_decodeMsgPtr) + GetProcAddress (cdll[i], "cddl_ccd_decodeMsgPtr"); + ptr_ccd_codeMsg[i] = (T_ccd_codeMsg) + GetProcAddress (cdll[i], "cddl_ccd_codeMsg"); + ptr_ccd_codeMsgPtr[i] = (T_ccd_codeMsgPtr) + GetProcAddress (cdll[i], "cddl_ccd_codeMsgPtr"); + ptr_ccd_init_ccddata[i] = (T_ccd_init_ccddata) + GetProcAddress (cdll[i], "cddl_ccd_init_ccddata"); + ptr_ccd_decodeByte[i] = (T_ccd_decodeByte) + GetProcAddress (cdll[i], "cddl_ccd_decodeByte"); + ptr_ccd_codeByte[i] = (T_ccd_codeByte) + GetProcAddress (cdll[i], "cddl_ccd_codeByte"); + ptr_ccd_codeLong[i] = (T_ccd_codeLong) + GetProcAddress (cdll[i], "cddl_ccd_codeLong"); + ptr_ccd_decodeLong[i] = (T_ccd_decodeLong) + GetProcAddress (cdll[i], "cddl_ccd_decodeLong"); + ptr_ccd_bitcopy[i] = (T_ccd_bitcopy) + GetProcAddress (cdll[i], "cddl_ccd_bitcopy"); + ptr_ccd_getFirstError[i] = (T_ccd_getFirstError) + GetProcAddress (cdll[i], "cddl_ccd_getFirstError"); + ptr_ccd_getNextError[i] = (T_ccd_getNextError) + GetProcAddress (cdll[i], "cddl_ccd_getNextError"); + ptr_ccd_getFirstFault[i] = (T_ccd_getFirstFault) + GetProcAddress (cdll[i], "cddl_ccd_getFirstFault"); + ptr_ccd_getNextFault[i] = (T_ccd_getNextFault) + GetProcAddress (cdll[i], "cddl_ccd_getNextFault"); + ptr_ccd_free_faultlist[i] = (T_ccd_free_faultlist) + GetProcAddress (cdll[i], "cddl_ccd_free_faultlist"); + ptr_ccd_get_numFaults[i] = (T_ccd_get_numFaults) + GetProcAddress (cdll[i], "cddl_ccd_get_numFaults"); + ptr_ccd_encodeElem[i] = (T_ccd_encodeElem) + GetProcAddress (cdll[i], "cddl_ccd_encodeElem"); + ptr_ccd_decodeElem[i] = (T_ccd_decodeElem) + GetProcAddress (cdll[i], "cddl_ccd_decodeElem"); + if ( + ptr_ccd_init[i] == NULL || + ptr_ccd_exit[i] == NULL || + ptr_ccd_begin[i] == NULL || + ptr_ccd_end[i] == NULL || + ptr_ccd_decodeMsg[i] == NULL || + ptr_ccd_decodeMsgPtr[i] == NULL || + ptr_ccd_codeMsg[i] == NULL || + ptr_ccd_codeMsgPtr[i] == NULL || + ptr_ccd_init_ccddata[i] == NULL || + ptr_ccd_decodeByte[i] == NULL || + ptr_ccd_codeByte[i] == NULL || + ptr_ccd_codeLong[i] == NULL || + ptr_ccd_decodeLong[i] == NULL || + ptr_ccd_bitcopy[i] == NULL || + ptr_ccd_getFirstError[i] == NULL || + ptr_ccd_getNextError[i] == NULL || + ptr_ccd_getFirstFault[i] == NULL || + ptr_ccd_getNextFault[i] == NULL || + ptr_ccd_free_faultlist[i] == NULL || + ptr_ccd_get_numFaults[i] == NULL || + ptr_ccd_encodeElem[i] == NULL || + ptr_ccd_decodeElem[i] == NULL) + { + ptr_ccd_init[i] = cddl_ccd_init; + ptr_ccd_exit[i] = cddl_ccd_exit; + ptr_ccd_begin[i] = cddl_ccd_begin; + ptr_ccd_end[i] = cddl_ccd_end; + ptr_ccd_decodeMsg[i] = cddl_ccd_decodeMsg; + ptr_ccd_decodeMsgPtr[i] = cddl_ccd_decodeMsgPtr; + ptr_ccd_codeMsg[i] = cddl_ccd_codeMsg; + ptr_ccd_codeMsgPtr[i] = cddl_ccd_codeMsgPtr; + ptr_ccd_init_ccddata[i] = cddl_ccd_init_ccddata; + ptr_ccd_decodeByte[i] = cddl_ccd_decodeByte; + ptr_ccd_codeByte[i] = cddl_ccd_codeByte; + ptr_ccd_codeLong[i] = cddl_ccd_codeLong; + ptr_ccd_decodeLong[i] = cddl_ccd_decodeLong; + ptr_ccd_bitcopy[i] = cddl_ccd_bitcopy; + ptr_ccd_getFirstError[i] = cddl_ccd_getFirstError; + ptr_ccd_getNextError[i] = cddl_ccd_getNextError; + ptr_ccd_getFirstFault[i] = cddl_ccd_getFirstFault; + ptr_ccd_getNextFault[i] = cddl_ccd_getNextFault; + ptr_ccd_free_faultlist[i] = cddl_ccd_free_faultlist; + ptr_ccd_get_numFaults[i] = cddl_ccd_get_numFaults; + ptr_ccd_encodeElem[i] = cddl_ccd_encodeElem; + ptr_ccd_decodeElem[i] = cddl_ccd_decodeElem; + } + ptr_ccd_set_patch_infos[i] = (T_ccd_set_patch_infos) + GetProcAddress (cdll[i], "cddl_ccd_set_patch_infos"); + if (ptr_ccd_set_patch_infos[i] == NULL) + { + ptr_ccd_set_patch_infos[i] = cddl_ccd_set_patch_infos; + } + + ptr_ccddata_eg_nodes[i] = (T_ccddata_eg_nodes) + GetProcAddress (cdll[i], "ccddata_eg_nodes"); + ptr_ccddata_eg_nodenames[i] = (T_ccddata_eg_nodenames) + GetProcAddress (cdll[i], "ccddata_eg_nodenames"); + ptr_ccddata_eg_adjacent[i] = (T_ccddata_eg_adjacent) + GetProcAddress (cdll[i], "ccddata_eg_adjacent"); + if ( + ptr_ccddata_eg_nodes[i] == NULL || + ptr_ccddata_eg_nodenames[i] == NULL || + ptr_ccddata_eg_adjacent[i] == NULL) + { + ptr_ccddata_eg_nodes[i] = cddl_ccddata_eg_nodes; + ptr_ccddata_eg_nodenames[i] = cddl_ccddata_eg_nodenames; + ptr_ccddata_eg_adjacent[i] = cddl_ccddata_eg_adjacent; + } + + ptr_ccddata_eg_saps[i] = (T_ccddata_eg_saps) + GetProcAddress (cdll[i], "ccddata_eg_saps"); + ptr_ccddata_eg_sapnames[i] = (T_ccddata_eg_sapnames) + GetProcAddress (cdll[i], "ccddata_eg_sapnames"); + ptr_ccddata_eg_comendpoints[i] = (T_ccddata_eg_comendpoints) + GetProcAddress (cdll[i], "ccddata_eg_comendpoints"); + if ( + ptr_ccddata_eg_saps[i] == NULL || + ptr_ccddata_eg_sapnames[i] == NULL || + ptr_ccddata_eg_comendpoints[i] == NULL) + { + ptr_ccddata_eg_saps[i] = cddl_ccddata_eg_saps; + ptr_ccddata_eg_sapnames[i] = cddl_ccddata_eg_sapnames; + ptr_ccddata_eg_comendpoints[i] = cddl_ccddata_eg_comendpoints; + } + + ptr_cde_init[i] = (T_cde_init) + GetProcAddress (cdll[i], "cddl_cde_init"); + ptr_cde_get_comp[i] = (T_cde_get_comp) + GetProcAddress (cdll[i], "cddl_cde_get_comp"); + ptr_cde_prim_first[i] = (T_cde_prim_first) + GetProcAddress (cdll[i], "cddl_cde_prim_first"); + ptr_cde_prim_next[i] = (T_cde_prim_next) + GetProcAddress (cdll[i], "cddl_cde_prim_next"); + ptr_cde_msg_first[i] = (T_cde_msg_first) + GetProcAddress (cdll[i], "cddl_cde_msg_first"); + ptr_cde_msg_next[i] = (T_cde_msg_next) + GetProcAddress (cdll[i], "cddl_cde_msg_next"); + ptr_cde_comp_first[i] = (T_cde_comp_first) + GetProcAddress (cdll[i], "cddl_cde_comp_first"); + ptr_cde_comp_next[i] = (T_cde_comp_next) + GetProcAddress (cdll[i], "cddl_cde_comp_next"); + ptr_cde_get_symval[i] = (T_cde_get_symval) + GetProcAddress (cdll[i], "cddl_cde_get_symval"); + ptr_cde_read_elem[i] = (T_cde_read_elem) + GetProcAddress (cdll[i], "cddl_cde_read_elem"); + ptr_cde_write_prepare[i] = (T_cde_write_prepare) + GetProcAddress (cdll[i], "cddl_cde_write_prepare"); + ptr_cde_write_elem[i] = (T_cde_write_elem) + GetProcAddress (cdll[i], "cddl_cde_write_elem"); + ptr_cde_get_type[i] = (T_cde_get_type) + GetProcAddress (cdll[i], "cddl_cde_get_type"); + ptr_cde_get_primcode[i] = (T_cde_get_primcode) + GetProcAddress (cdll[i], "cddl_cde_get_primcode"); + ptr_cde_get_msgcode[i] = (T_cde_get_msgcode) + GetProcAddress (cdll[i], "cddl_cde_get_msgcode"); + ptr_cde_get_is_downlink[i] = (T_cde_get_is_downlink) + GetProcAddress (cdll[i], "cddl_cde_get_is_downlink"); + ptr_cde_get_comp_index[i] = (T_cde_get_comp_index) + GetProcAddress (cdll[i], "cddl_cde_get_comp_index"); + ptr_cde_get_element_name[i] = (T_cde_get_element_name) + GetProcAddress (cdll[i], "cddl_cde_get_element_name"); + ptr_cde_get_array_kind[i] = (T_cde_get_array_kind) + GetProcAddress (cdll[i], "cddl_cde_get_array_kind"); + if ( + ptr_cde_init[i] == NULL || + ptr_cde_get_comp[i] == NULL || + ptr_cde_prim_first[i] == NULL || + ptr_cde_prim_next[i] == NULL || + ptr_cde_msg_first[i] == NULL || + ptr_cde_msg_next[i] == NULL || + ptr_cde_comp_first[i] == NULL || + ptr_cde_comp_next[i] == NULL || + ptr_cde_get_symval[i] == NULL || + ptr_cde_read_elem[i] == NULL || + ptr_cde_write_prepare[i] == NULL || + ptr_cde_write_elem[i] == NULL || + ptr_cde_get_type[i] == NULL || + ptr_cde_get_primcode[i] == NULL || + ptr_cde_get_msgcode[i] == NULL || + ptr_cde_get_is_downlink[i] == NULL || + ptr_cde_get_comp_index[i] == NULL || + ptr_cde_get_element_name[i] == NULL || + ptr_cde_get_array_kind[i] == NULL) + { + ptr_cde_init[i] = cddl_cde_init; + ptr_cde_get_comp[i] = cddl_cde_get_comp; + ptr_cde_prim_first[i] = cddl_cde_prim_first; + ptr_cde_prim_next[i] = cddl_cde_prim_next; + ptr_cde_msg_first[i] = cddl_cde_msg_first; + ptr_cde_msg_next[i] = cddl_cde_msg_next; + ptr_cde_comp_first[i] = cddl_cde_comp_first; + ptr_cde_comp_next[i] = cddl_cde_comp_next; + ptr_cde_get_symval[i] = cddl_cde_get_symval; + ptr_cde_read_elem[i] = cddl_cde_read_elem; + ptr_cde_write_prepare[i] = cddl_cde_write_prepare; + ptr_cde_write_elem[i] = cddl_cde_write_elem; + ptr_cde_get_type[i] = cddl_cde_get_type; + ptr_cde_get_primcode[i] = cddl_cde_get_primcode; + ptr_cde_get_msgcode[i] = cddl_cde_get_msgcode; + ptr_cde_get_is_downlink[i] = cddl_cde_get_is_downlink; + ptr_cde_get_comp_index[i] = cddl_cde_get_comp_index; + ptr_cde_get_element_name[i] = cddl_cde_get_element_name; + ptr_cde_get_array_kind[i] = cddl_cde_get_array_kind; + } + + ptr_pdi_createDefContext[i] = (T_pdi_createDefContext) + GetProcAddress (cdll[i], "cddl_pdi_createDefContext"); + ptr_pdi_createContext[i] = (T_pdi_createContext) + GetProcAddress (cdll[i], "cddl_pdi_createContext"); + ptr_pdi_destroyContext[i] = (T_pdi_destroyContext) + GetProcAddress (cdll[i], "cddl_pdi_destroyContext"); + ptr_pdi_startPrim[i] = (T_pdi_startPrim) + GetProcAddress (cdll[i], "cddl_pdi_startPrim"); + ptr_pdi_getDecodeInfo[i] = (T_pdi_getDecodeInfo) + GetProcAddress (cdll[i], "cddl_pdi_getDecodeInfo"); + ptr_pdi_getEntityByPD[i] = (T_pdi_getEntityByPD) + GetProcAddress (cdll[i], "cddl_pdi_getEntityByPD"); + ptr_pdi_pd2name[i] = (T_pdi_pd2name) + GetProcAddress (cdll[i], "cddl_pdi_pd2name"); + if ( + ptr_pdi_createDefContext[i] == NULL || + ptr_pdi_createContext[i] == NULL || + ptr_pdi_destroyContext[i] == NULL || + ptr_pdi_startPrim[i] == NULL || + ptr_pdi_getDecodeInfo[i] == NULL || + ptr_pdi_getEntityByPD[i] == NULL || + ptr_pdi_pd2name[i] == NULL) + { + ptr_pdi_createDefContext[i]=cddl_pdi_createDefContext; + ptr_pdi_createContext[i] =cddl_pdi_createContext; + ptr_pdi_destroyContext[i] = cddl_pdi_destroyContext; + ptr_pdi_startPrim[i] = cddl_pdi_startPrim; + ptr_pdi_getDecodeInfo[i] = cddl_pdi_getDecodeInfo; + ptr_pdi_getEntityByPD[i] = cddl_pdi_getEntityByPD; + ptr_pdi_pd2name[i] = cddl_pdi_pd2name; + } + + ptr_ccddata_get_pdi_dinfo[i] = (T_ccddata_get_pdi_dinfo) + GetProcAddress (cdll[i], "ccddata_get_pdi_dinfo"); + if (ptr_ccddata_get_pdi_dinfo[i] == NULL) + { + ptr_ccddata_get_pdi_dinfo[i] = cddl_ccddata_get_pdi_dinfo; + } + ptr_ccddata_get_num_of_entities[i] = (T_ccddata_get_num_of_entities) + GetProcAddress (cdll[i], "ccddata_get_num_of_entities"); + ptr_ccddata_get_max_message_id[i] = (T_ccddata_get_max_message_id) + GetProcAddress (cdll[i], "ccddata_get_max_message_id"); + ptr_ccddata_get_max_bitstream_len[i] = (T_ccddata_get_max_bitstream_len) + GetProcAddress (cdll[i], "ccddata_get_max_bitstream_len"); + ptr_ccddata_get_max_mstruct_len[i] = (T_ccddata_get_max_mstruct_len) + GetProcAddress (cdll[i], "ccddata_get_max_mstruct_len"); + ptr_ccddata_mccd_symbols[i] = (T_ccddata_mccd_symbols) + GetProcAddress (cdll[i], "ccddata_mccd_symbols"); + ptr_ccddata_get_max_sap_num[i] = (T_ccddata_get_max_sap_num) + GetProcAddress (cdll[i], "ccddata_get_max_sap_num"); + ptr_ccddata_get_max_primitive_id[i] = (T_ccddata_get_max_primitive_id) + GetProcAddress (cdll[i], "ccddata_get_max_primitive_id"); + ptr_ccddata_get_max_pstruct_len[i] = (T_ccddata_get_max_pstruct_len) + GetProcAddress (cdll[i], "ccddata_get_max_pstruct_len"); + ptr_ccddata_get_mvar[i] = (T_ccddata_get_mvar) + GetProcAddress (cdll[i], "ccddata_get_mvar"); + ptr_ccddata_get_spare[i] = (T_ccddata_get_spare) + GetProcAddress (cdll[i], "ccddata_get_spare"); + ptr_ccddata_get_calc[i] = (T_ccddata_get_calc) + GetProcAddress (cdll[i], "ccddata_get_calc"); + ptr_ccddata_get_mcomp[i] = (T_ccddata_get_mcomp) + GetProcAddress (cdll[i], "ccddata_get_mcomp"); + ptr_ccddata_get_melem[i] = (T_ccddata_get_melem) + GetProcAddress (cdll[i], "ccddata_get_melem"); + ptr_ccddata_get_calcidx[i] = (T_ccddata_get_calcidx) + GetProcAddress (cdll[i], "ccddata_get_calcidx"); + ptr_ccddata_get_mmtx[i] = (T_ccddata_get_mmtx) + GetProcAddress (cdll[i], "ccddata_get_mmtx"); + ptr_ccddata_get_pvar[i] = (T_ccddata_get_pvar) + GetProcAddress (cdll[i], "ccddata_get_pvar"); + ptr_ccddata_get_pcomp[i] = (T_ccddata_get_pcomp) + GetProcAddress (cdll[i], "ccddata_get_pcomp"); + ptr_ccddata_get_pelem[i] = (T_ccddata_get_pelem) + GetProcAddress (cdll[i], "ccddata_get_pelem"); + ptr_ccddata_get_pmtx[i] = (T_ccddata_get_pmtx) + GetProcAddress (cdll[i], "ccddata_get_pmtx"); + ptr_ccddata_get_mval[i] = (T_ccddata_get_mval) + GetProcAddress (cdll[i], "ccddata_get_mval"); + ptr_ccddata_get_mstr[i] = (T_ccddata_get_mstr) + GetProcAddress (cdll[i], "ccddata_get_mstr"); + ptr_ccddata_get_pval[i] = (T_ccddata_get_pval) + GetProcAddress (cdll[i], "ccddata_get_pval"); + ptr_ccddata_get_pstr[i] = (T_ccddata_get_pstr) + GetProcAddress (cdll[i], "ccddata_get_pstr"); + ptr_ccddata_get_ccdent[i] = (T_ccddata_get_ccdent) + GetProcAddress (cdll[i], "ccddata_get_ccdent"); + ptr_ccddata_get_entname[i] = (T_ccddata_get_entname) + GetProcAddress (cdll[i], "ccddata_get_entname"); + if (ptr_ccddata_get_entname[i] == NULL) + { + ptr_ccddata_get_entname[i] = cddl_ccddata_get_entname; + } + ptr_ccddata_get_alias[i] = (T_ccddata_get_alias) + GetProcAddress (cdll[i], "ccddata_get_alias"); + ptr_ccddata_get_version[i] = (T_ccddata_get_version) + GetProcAddress (cdll[i], "ccddata_get_version"); + if (ptr_ccddata_get_version[i] == NULL) + { + ptr_ccddata_get_version[i] = cddl_ccddata_get_version; + } + ptr_ccddata_get_table_version[i] = (T_ccddata_get_table_version) + GetProcAddress (cdll[i], "ccddata_get_table_version"); + if (ptr_ccddata_get_table_version[i] == NULL) + { + ptr_ccddata_get_table_version[i] = cddl_ccddata_get_table_version; + } + ptr_ccddata_get_mi_length[i] = (T_ccddata_get_mi_length) + GetProcAddress (cdll[i], "ccddata_get_mi_length"); + if (ptr_ccddata_get_mi_length[i] == NULL) + { + mi_length[i] = (UBYTE*) GetProcAddress (cdll[i], "mi_length"); + } + ptr_ccddata_get_decmsgbuffer[i] = (T_ccddata_get_decmsgbuffer) + GetProcAddress (cdll[i], "ccddata_get_decmsgbuffer"); + if (ptr_ccddata_get_decmsgbuffer[i] == NULL) + { + decmsgbuffer[i] = (UBYTE*) GetProcAddress (cdll[i], "decMsgBuffer"); + } + ptr_ccddata_tap_check_pd[i] = (T_ccddata_tap_check_pd) + GetProcAddress (cdll[i], "ccddata_tap_check_pd"); + ptr_ccddata_tap_get_pd[i] = (T_ccddata_tap_get_pd) + GetProcAddress (cdll[i], "ccddata_tap_get_pd"); + if ( + ptr_ccddata_get_pdi_dinfo[i] == NULL || + ptr_ccddata_get_num_of_entities[i] == NULL || + ptr_ccddata_get_max_message_id[i] == NULL || + ptr_ccddata_get_max_bitstream_len[i] == NULL || + ptr_ccddata_get_max_mstruct_len[i] == NULL || + ptr_ccddata_mccd_symbols[i] == NULL || + ptr_ccddata_get_max_sap_num[i] == NULL || + ptr_ccddata_get_max_primitive_id[i] == NULL || + ptr_ccddata_get_max_pstruct_len[i] == NULL || + ptr_ccddata_get_mvar[i] == NULL || + ptr_ccddata_get_spare[i] == NULL || + ptr_ccddata_get_calc[i] == NULL || + ptr_ccddata_get_mcomp[i] == NULL || + ptr_ccddata_get_melem[i] == NULL || + ptr_ccddata_get_calcidx[i] == NULL || + ptr_ccddata_get_mmtx[i] == NULL || + ptr_ccddata_get_pvar[i] == NULL || + ptr_ccddata_get_pcomp[i] == NULL || + ptr_ccddata_get_pelem[i] == NULL || + ptr_ccddata_get_pmtx[i] == NULL || + ptr_ccddata_get_mval[i] == NULL || + ptr_ccddata_get_mstr[i] == NULL || + ptr_ccddata_get_pval[i] == NULL || + ptr_ccddata_get_pstr[i] == NULL || + ptr_ccddata_get_ccdent[i] == NULL || + ptr_ccddata_get_entname[i] == NULL || + ptr_ccddata_get_alias[i] == NULL || + ptr_ccddata_get_version[i] == NULL || + ptr_ccddata_get_table_version[i] == NULL || + ((ptr_ccddata_get_mi_length[i] == NULL) && (mi_length[i] == NULL)) || + ((ptr_ccddata_get_decmsgbuffer[i] == NULL) && + (decmsgbuffer[i] == NULL)) || + ptr_ccddata_tap_check_pd[i] == NULL || + ptr_ccddata_tap_get_pd[i] == NULL) + { + (void) ccddata_exit (); + return CCDDATA_DLL_LOADFUN; + } + + (void) (*ptr_ccd_init_ccddata[i]) (); + (void) (*ptr_ccd_init[i]) (); + (void) (*ptr_cde_init[i]) (); + (void) (*ptr_pcon_init_ccddata[i]) (); + (void) (*ptr_pcon_init_prim_coding[i]) (0, PCON_LITTLE); + + if (!already_loaded && ccddata_i_notify != NULL) + { + (*ccddata_i_notify)(); + } + + return CCDDATA_DLL_OK; +} + +/* ++------------------------------------------------------------------------------ +| Function : ccddata_ehandler ++------------------------------------------------------------------------------ +| Description : Handle NULL pointer; if we had loaded a ccddata dll +| but any other process had loaded another one in the +| meantime, the old one is unloaded and the new one is +< attached to. +| +| Parameters : - +| +| Return : An error code or the return value of ccddata_attach ++------------------------------------------------------------------------------ +*/ +static int ccddata_ehandler (void) +{ + if (me < 0) + { + return CCDDATA_DLL_REGISTER; + } + + // functions not loaded -> reattach + ccddata_detach (me, 1); + return ccddata_attach (me); +} +/*==== PUBLIC FUNCTIONS ======================================================*/ + +/* pcon_init_prim_coding ==================================================== */ +ULONG pcon_init_prim_coding (T_HANDLE caller, UBYTE format) +{ + ULONG ret = PCON_DLLFUNC_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_pcon_init_prim_coding[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_pcon_init_prim_coding[me]) (caller, format); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* pcon_decodePrim ========================================================== */ +ULONG pcon_decodePrim (ULONG opc, + void ** decoded_prim, + void * coded_prim, + ULONG * length, + ULONG woff) +{ + ULONG ret = PCON_DLLFUNC_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_pcon_decodePrim[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_pcon_decodePrim[me])(opc, decoded_prim, coded_prim, length, + woff); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* pcon_codePrim ============================================================*/ +ULONG pcon_codePrim (ULONG opc, + void * decoded_prim, + void ** coded_prim, + ULONG * length, + ULONG woff, + char* receiver) +{ + ULONG ret = PCON_DLLFUNC_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_pcon_codePrim[me] != NULL) || (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_pcon_codePrim[me])(opc, decoded_prim, coded_prim, length, + woff, receiver); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* pcon_init_ccddata ========================================================*/ +ULONG pcon_init_ccddata (void) +{ + ULONG ret = PCON_DLLFUNC_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_pcon_init_ccddata[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_pcon_init_ccddata[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* pcon_make_filter =========================================================*/ +ULONG pcon_make_filter (char* string, void** prim) +{ + ULONG ret = PCON_DLLFUNC_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_pcon_make_filter[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_pcon_make_filter[me])(string, prim); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* pcon_filter_decode_prim ===================================================*/ +ULONG pcon_filter_decode_prim (ULONG opc, + void** decoded_prim, + void* coded_prim, + ULONG* length, + ULONG woff, + void** shadow_prim) +{ + ULONG ret = PCON_DLLFUNC_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_pcon_filter_decode_prim[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_pcon_filter_decode_prim[me])(opc, decoded_prim, coded_prim, + length, woff, shadow_prim); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* pcon_codePrim ============================================================*/ +/* ccddata_get_num_of_entities ==============================================*/ +int ccddata_get_num_of_entities (void) +{ + int ret = 0; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_num_of_entities[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_num_of_entities[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_pdi_dinfo ==============================================*/ +int ccddata_get_pdi_dinfo (const T_PDI_DECODEINFO* (*dinfo) ) +{ + int ret = 0; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_pdi_dinfo[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_pdi_dinfo[me])(dinfo); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_max_message_id ===============================================*/ +int ccddata_get_max_message_id (void) +{ + int ret = 0; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_max_message_id[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_max_message_id[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_max_bitstream_len ============================================*/ +int ccddata_get_max_bitstream_len (void) +{ + int ret = CCDDATA_MCONST_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_max_bitstream_len[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_max_bitstream_len[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_max_mstruct_len ==============================================*/ +int ccddata_get_max_mstruct_len (void) +{ + int ret = CCDDATA_MCONST_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_max_mstruct_len[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_max_mstruct_len[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_mccd_symbols =====================================================*/ +int ccddata_mccd_symbols (void) +{ + int ret = CCDDATA_MCONST_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_mccd_symbols[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_mccd_symbols[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_max_sap_num ==================================================*/ +int ccddata_get_max_sap_num (void) +{ + int ret = 0; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_max_sap_num[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_max_sap_num[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_max_primitive_id =============================================*/ +int ccddata_get_max_primitive_id (void) +{ + int ret = 0; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_max_primitive_id[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_max_primitive_id[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_max_pstruct_len ==============================================*/ +int ccddata_get_max_pstruct_len (void) +{ + int ret = CCDDATA_PCONST_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_max_pstruct_len[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_max_pstruct_len[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_calcidx ======================================================*/ +const T_CCD_CalcIndex* ccddata_get_calcidx (USHORT idx) +{ + const T_CCD_CalcIndex* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_calcidx[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_calcidx[me])(idx); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_mvar =========================================================*/ +const T_CCD_VarTabEntry* ccddata_get_mvar (USHORT idx) +{ + const T_CCD_VarTabEntry* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_mvar[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_mvar[me])(idx); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_spare ========================================================*/ +const T_CCD_SpareTabEntry* ccddata_get_spare (USHORT idx) +{ + const T_CCD_SpareTabEntry* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_spare[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_spare[me])(idx); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_calc =========================================================*/ +const T_CCD_CalcTabEntry* ccddata_get_calc (USHORT idx) +{ + const T_CCD_CalcTabEntry* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_calc[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_calc[me])(idx); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_mcomp ========================================================*/ +const T_CCD_CompTabEntry* ccddata_get_mcomp (USHORT idx) +{ + const T_CCD_CompTabEntry* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_mcomp[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_mcomp[me])(idx); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_melem ========================================================*/ +const T_CCD_ElemTabEntry* ccddata_get_melem (USHORT idx) +{ + const T_CCD_ElemTabEntry* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_melem[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_melem[me])(idx); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_mmtx =========================================================*/ +USHORT ccddata_get_mmtx (USHORT entity, USHORT msgid, USHORT index) +{ + USHORT ret = NO_REF; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_mmtx[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_mmtx[me])(entity, msgid, index); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_pvar =========================================================*/ +const T_CCD_VarTabEntry* ccddata_get_pvar (USHORT idx) +{ + const T_CCD_VarTabEntry* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_pvar[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_pvar[me])(idx); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_pcomp ========================================================*/ +const T_CCD_CompTabEntry* ccddata_get_pcomp (USHORT idx) +{ + const T_CCD_CompTabEntry* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_pcomp[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_pcomp[me])(idx); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_pelem ========================================================*/ +const T_CCD_ElemTabEntry* ccddata_get_pelem (USHORT idx) +{ + const T_CCD_ElemTabEntry* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_pelem[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_pelem[me])(idx); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_pmtx =========================================================*/ +USHORT ccddata_get_pmtx (USHORT sap, USHORT primid, USHORT index) +{ + USHORT ret = NO_REF; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_pmtx[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_pmtx[me])(sap, primid, index); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_mval =========================================================*/ +const T_CCD_ValTabEntry* ccddata_get_mval (USHORT idx) +{ + const T_CCD_ValTabEntry* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_mval[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_mval[me])(idx); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_mstr =========================================================*/ +const T_CCD_StrTabEntry* ccddata_get_mstr (USHORT idx) +{ + const T_CCD_StrTabEntry* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_mstr[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_mstr[me])(idx); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_pval =========================================================*/ +const T_CCD_ValTabEntry* ccddata_get_pval (USHORT idx) +{ + const T_CCD_ValTabEntry* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_pval[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_pval[me])(idx); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_pstr =========================================================*/ +const T_CCD_StrTabEntry* ccddata_get_pstr (USHORT idx) +{ + const T_CCD_StrTabEntry* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_pstr[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_pstr[me])(idx); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_ccdent =======================================================*/ +short ccddata_get_ccdent (char* entname) +{ + short ret = CCDDATA_CCDENT_INVALID; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_ccdent[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_ccdent[me])(entname); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_entname =======================================================*/ +const char * ccddata_get_entname (short ccdent) +{ + const char * ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_entname[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_entname[me])(ccdent); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_alias ========================================================*/ +char* ccddata_get_alias (USHORT idx, int from_msg) +{ + char* ret = ""; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_alias[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_alias[me])(idx, from_msg); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_version ======================================================*/ +char* ccddata_get_version (void) +{ + char* ret = ""; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_version[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_version[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_table_version ================================================*/ +int ccddata_get_table_version (void) +{ + int ret = 0; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_get_table_version[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_get_table_version[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_decmsgbuffer =================================================*/ +UBYTE* ccddata_get_decmsgbuffer (void) +{ + UBYTE* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if (ptr_ccddata_get_decmsgbuffer[me] == NULL) + { + if (decmsgbuffer[me] != NULL) + { + ret = decmsgbuffer[me]; + } + else if (ccddata_ehandler() == CCDDATA_DLL_OK) + { + ret = ccddata_get_decmsgbuffer (); + } + else + { + ; + } + } + else + { + __try + { + ret = (*ptr_ccddata_get_decmsgbuffer[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_get_mi_length ====================================================*/ +UBYTE* ccddata_get_mi_length (void) +{ + UBYTE* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if (ptr_ccddata_get_mi_length[me] == NULL) + { + if (mi_length[me] != NULL) + { + ret = mi_length[me]; + } + else if (ccddata_ehandler() == CCDDATA_DLL_OK) + { + ret = ccddata_get_mi_length (); + } + else + { + ; + } + } + else + { + __try + { + ret = (*ptr_ccddata_get_mi_length[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_tap_get_pd =======================================================*/ +int ccddata_tap_get_pd (UCHAR comp) +{ + int ret = TAP_PD_INVALID; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_tap_get_pd[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_tap_get_pd[me])(comp); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_tap_check_pd =====================================================*/ +int ccddata_tap_check_pd (UCHAR comp, UCHAR pd) +{ + int ret = TAP_PD_INVALID; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_tap_check_pd[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_tap_check_pd[me])(comp, pd); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_eg_nodes =========================================================*/ +int ccddata_eg_nodes (void) +{ + int ret = 0; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_eg_nodes[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_eg_nodes[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_eg_nodenames =====================================================*/ +char** ccddata_eg_nodenames (void) +{ + char** ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_eg_nodenames[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_eg_nodenames[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_eg_adjacent ======================================================*/ +char* ccddata_eg_adjacent (int idx) +{ + char* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_eg_adjacent[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_eg_adjacent[me])(idx); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_eg_saps ==========================================================*/ +int ccddata_eg_saps (void) +{ + int ret = 0; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_eg_saps[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_eg_saps[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_eg_sapnames ======================================================*/ +char** ccddata_eg_sapnames (void) +{ + char** ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_eg_sapnames[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_eg_sapnames[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccddata_eg_comendpoints ==================================================*/ +T_COMENDPOINTS* ccddata_eg_comendpoints (int idx) +{ + T_COMENDPOINTS* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccddata_eg_comendpoints[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccddata_eg_comendpoints[me])(idx); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* cde_init =================================================================*/ +void cde_init (void) +{ + if (me < 0) + { + return; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_cde_init[me] != NULL) || (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + (*ptr_cde_init[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); +} + +/* cde_get_comp =============================================================*/ +USHORT cde_get_comp (T_CCDE_HANDLE* chandle, + T_CCDE_ELEM_DESCR* edescr) +{ + USHORT ret = CCDEDIT_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_cde_get_comp[me] != NULL) || (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_cde_get_comp[me])(chandle, edescr); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* cde_prim_first ===========================================================*/ +USHORT cde_prim_first (T_CCDE_HANDLE * phandle, + ULONG primcode, + char * name) +{ + USHORT ret = CCDEDIT_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_cde_prim_first[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_cde_prim_first[me])(phandle, primcode, name); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* cde_prim_next ============================================================*/ +USHORT cde_prim_next (T_CCDE_HANDLE *phandle, + UBYTE descent, + T_CCDE_ELEM_DESCR *pdescr) +{ + USHORT ret = CCDEDIT_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_cde_prim_next[me] != NULL) || (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_cde_prim_next[me])(phandle, descent, pdescr); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* cde_msg_first ============================================================*/ +USHORT cde_msg_first (T_CCDE_HANDLE * mhandle, + UBYTE type, + UBYTE direction, + UBYTE entity, + char * name) + +{ + USHORT ret = CCDEDIT_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_cde_msg_first[me] != NULL) || (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_cde_msg_first[me])(mhandle, type, direction, entity, name); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* cde_msg_next =============================================================*/ +USHORT cde_msg_next (T_CCDE_HANDLE *mhandle, + UBYTE descent, + T_CCDE_ELEM_DESCR *iedescr) +{ + USHORT ret = CCDEDIT_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_cde_msg_next[me] != NULL) || (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_cde_msg_next[me])(mhandle, descent, iedescr); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* cde_comp_first ===========================================================*/ +USHORT cde_comp_first (T_CCDE_HANDLE * chandle, + T_ELM_SRC source, + char * compname) + +{ + USHORT ret = CCDEDIT_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_cde_comp_first[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_cde_comp_first[me])(chandle, source, compname); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* cde_comp_next ============================================================*/ +USHORT cde_comp_next (T_CCDE_HANDLE *chandle, + UBYTE descent, + T_CCDE_ELEM_DESCR *descr) +{ + USHORT ret = CCDEDIT_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_cde_comp_next[me] != NULL) || (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_cde_comp_next[me])(chandle, descent, descr); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* cde_get_symval ===========================================================*/ +char* cde_get_symval (int elem_value, T_CCDE_ELEM_DESCR* edescr) +{ + char* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_cde_get_symval[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_cde_get_symval[me])(elem_value, edescr); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* cde_read_elem ============================================================*/ +USHORT cde_read_elem (T_CCDE_HANDLE * handle, + void * cstruct, + T_CCDE_ELEM_DESCR * edescr, + UBYTE * value) +{ + USHORT ret = CCDEDIT_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_cde_read_elem[me] != NULL) || (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_cde_read_elem[me])(handle, cstruct, edescr, value); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* cde_write_prepare ========================================================*/ +void cde_write_prepare (T_CCDE_HANDLE * handle, + void * cstruct, + T_CCDE_ELEM_DESCR * edescr) +{ + if (me < 0) + { + return; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_cde_write_prepare[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + (*ptr_cde_write_prepare[me])(handle, cstruct, edescr); + } + ReleaseMutex (mut[me]); +} + +/* cde_write_elem ===========================================================*/ +USHORT cde_write_elem (T_CCDE_HANDLE * handle, + void * cstruct, + T_CCDE_ELEM_DESCR * edescr, + UBYTE * value) +{ + USHORT ret = CCDEDIT_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_cde_write_elem[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_cde_write_elem[me])(handle, cstruct, edescr, value); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* cde_get_type ===========================================================*/ +USHORT cde_get_type (char *name, + T_ELM_SRC *type) +{ + USHORT ret = CCDEDIT_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_cde_get_type[me] != NULL) || (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_cde_get_type[me])(name, type); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* cde_get_primcode =========================================================*/ +USHORT cde_get_primcode (char *name, + ULONG *primcode) +{ + USHORT ret = CCDEDIT_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_cde_get_primcode[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_cde_get_primcode[me])(name, primcode); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* cde_get_msgcode ==========================================================*/ +USHORT cde_get_msgcode (char *name, + UBYTE *type, + UBYTE *direction, + UBYTE *entity) +{ + USHORT ret = CCDEDIT_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_cde_get_msgcode[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_cde_get_msgcode[me])(name, type, direction, entity); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* cde_get_is_downlink ======================================================*/ +int cde_get_is_downlink (ULONG comp_index) +{ + int ret = CCDEDIT_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_cde_get_is_downlink[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_cde_get_is_downlink[me])(comp_index); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* cde_get_comp_index =======================================================*/ +ULONG cde_get_comp_index (char* comp_name, T_ELM_SRC table) +{ + ULONG ret = CCDEDIT_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_cde_get_comp_index[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_cde_get_comp_index[me])(comp_name, table); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* cde_get_element_name =====================================================*/ +char* cde_get_element_name (ULONG comp_index, USHORT elem_off, T_ELM_SRC table) +{ + char* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_cde_get_element_name[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_cde_get_element_name[me])(comp_index, elem_off, table); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* cde_get_array_kind =======================================================*/ +ULONG cde_get_array_kind (char* var_name, T_ELM_SRC table) +{ + ULONG ret = (ULONG)CCDEDIT_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_cde_get_array_kind[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_cde_get_array_kind[me])(var_name, table); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_set_patch_infos ======================================================*/ +int ccd_set_patch_infos (T_patch_info* pinfo) +{ + int ret = CCD_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_set_patch_infos[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_set_patch_infos[me])(pinfo); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_init =================================================================*/ +BYTE ccd_init (void) +{ + BYTE ret = CCD_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_init[me] != NULL) || (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_init[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_exit =================================================================*/ +int ccd_exit (void) +{ + int ret = CCD_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_exit[me] != NULL) || (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_exit[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_begin ================================================================*/ +UBYTE* ccd_begin (void) +{ + UBYTE* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_begin[me] != NULL) || (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_begin[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_end ==================================================================*/ +void ccd_end (void) +{ + if (me < 0) + { + return; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_end[me] != NULL) || (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + (*ptr_ccd_end[me])(); + } + ReleaseMutex (mut[me]); +} + +/* ccd_decodeMsg ============================================================*/ +BYTE ccd_decodeMsg (UBYTE entity, + UBYTE direction, + T_MSGBUF *mBuf, + UBYTE *mStruct, + UBYTE mId) +{ + BYTE ret = CCD_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_decodeMsg[me] != NULL) || (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_decodeMsg[me])(entity, direction, mBuf, mStruct, mId); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_decodeMsgPtr =========================================================*/ +S8 ccd_decodeMsgPtr (U8 entity, + U8 direction, + U16 l_buf, + U16 o_buf, + U8* buf, + U8** mStructPtr, + U8 mId) +{ + S8 ret = CCD_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_decodeMsgPtr[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_decodeMsgPtr[me])(entity, direction, l_buf, o_buf, buf, + mStructPtr, mId); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_codeMsg ========================)=====================================*/ +BYTE ccd_codeMsg (UBYTE entity, + UBYTE direction, + T_MSGBUF *mBuf, + UBYTE *mStruct, + UBYTE mId) +{ + BYTE ret = CCD_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_codeMsg[me] != NULL) || (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_codeMsg[me])(entity, direction, mBuf, mStruct, mId); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_codeMsgPtr =========================)=================================*/ +S8 ccd_codeMsgPtr(U8 entity, + U8 direction, + U16* l_buf, + U16 o_buf, + U8* buf, + U8* mStruct, + U8 mId) +{ + S8 ret = CCD_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_codeMsgPtr[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_codeMsgPtr[me])(entity, direction, l_buf, o_buf, buf, + mStruct, mId); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_init_ccddata =========================================================*/ +ULONG ccd_init_ccddata (void) +{ + ULONG ret = CCD_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_init_ccddata[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_init_ccddata[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_decodeByte ===========================================================*/ +BYTE ccd_decodeByte (UBYTE* bitstream, USHORT startbit, + USHORT bitlen, UBYTE* value) +{ + BYTE ret = CCD_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_decodeByte[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_decodeByte[me])(bitstream, startbit, bitlen, value); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_codeByte =============================)===============================*/ +BYTE ccd_codeByte (UBYTE* bitstream, USHORT startbit, + USHORT bitlen, UBYTE value) +{ + BYTE ret = CCD_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_codeByte[me] != NULL) || (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_codeByte[me])(bitstream, startbit, bitlen, value); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_codeLong ===)=========================================================*/ +BYTE ccd_codeLong (UBYTE* bitstream, USHORT startbit, + USHORT bitlen, ULONG value) +{ + BYTE ret = CCD_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_codeLong[me] != NULL) || (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_codeLong[me])(bitstream, startbit, bitlen, value); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_decodeLong ===========================================================*/ +BYTE ccd_decodeLong (UBYTE* bitstream, USHORT startbit, + USHORT bitlen, ULONG *value) +{ + BYTE ret = CCD_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_decodeLong[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_decodeLong[me])(bitstream, startbit, bitlen, value); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_bitcopy ============================)=================================*/ +void ccd_bitcopy (UBYTE *dest, + UBYTE *source, + USHORT bitlen, + USHORT offset) +{ + if (me < 0) + { + return; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_bitcopy[me] != NULL) || (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + (*ptr_ccd_bitcopy[me])(dest, source, bitlen, offset); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); +} + +/* ccd_getFirstError ========================================================*/ +UBYTE ccd_getFirstError (UBYTE entity, USHORT *parlist) +{ + UBYTE ret = CCD_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_getFirstError[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_getFirstError[me])(entity, parlist); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_getNextError =========================================================*/ +UBYTE ccd_getNextError (UBYTE entity, USHORT *parlist) +{ + UBYTE ret = CCD_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_getNextError[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_getNextError[me])(entity, parlist); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_getFirstFault ========================================================*/ +ULONG ccd_getFirstFault (T_CCD_ERR_ENTRY **ccd_err_entry) +{ + ULONG ret = CCD_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_getFirstFault[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_getFirstFault[me])(ccd_err_entry); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_getNextFault =========================================================*/ +ULONG ccd_getNextFault (T_CCD_ERR_ENTRY **ccd_err_entry) +{ + ULONG ret = CCD_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_getNextFault[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_getNextFault[me])(ccd_err_entry); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_free_faultlist =======================================================*/ +void ccd_free_faultlist (void) +{ + if (me < 0) + { + return; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_free_faultlist[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + (*ptr_ccd_free_faultlist[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); +} + +/* ccd_get_numFaults ========================================================*/ +int ccd_get_numFaults () +{ + int ret = CCD_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_get_numFaults[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_get_numFaults[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_encodeElem ===========================================================*/ +int ccd_encodeElem (ULONG ccdid, + USHORT* l_buf, + USHORT o_buf, + UCHAR* buf, + UCHAR* eStruct) +{ + int ret = CCD_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_encodeElem[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_encodeElem[me])(ccdid, l_buf, o_buf, buf, eStruct); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ccd_decodeElem ===========================================================*/ +int ccd_decodeElem (ULONG ccdid, + USHORT l_buf, + USHORT o_buf, + UCHAR* buf, + UCHAR* eStruct) +{ + int ret = CCD_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_ccd_decodeElem[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_ccd_decodeElem[me])(ccdid, l_buf, o_buf, buf, eStruct); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* pdi_createDefContext =====================================================*/ +T_PDI_CONTEXT* pdi_createDefContext() +{ + T_PDI_CONTEXT* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_pdi_createDefContext[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_pdi_createDefContext[me])(); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* pdi_createContext ========================================================*/ +T_PDI_CONTEXT* pdi_createContext(const T_PDI_DECODEINFO* dinfo, + unsigned int dicount) +{ + T_PDI_CONTEXT* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_pdi_createContext[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_pdi_createContext[me])(dinfo, dicount); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* pdi_destroyContext =======================================================*/ +void pdi_destroyContext(T_PDI_CONTEXT *context) +{ + if (me < 0) + { + return; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_pdi_destroyContext[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + (*ptr_pdi_destroyContext[me])(context); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); +} + +/* pdi_startPrim ============================================================*/ +void pdi_startPrim(T_PDI_CONTEXT *context, ULONG opc) +{ + if (me < 0) + { + return; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_pdi_startPrim[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + (*ptr_pdi_startPrim[me])(context, opc); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); +} + +/* pdi_getDecodeInfo ========================================================*/ +void pdi_getDecodeInfo(T_PDI_CONTEXT *context, const char *ename, + char *evalue, int evlen, T_PDI *decinfo) +{ + if (me < 0) + { + return; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_pdi_getDecodeInfo[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + (*ptr_pdi_getDecodeInfo[me])(context, ename, evalue, evlen, decinfo); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); +} + +/* pdi_getEntityByPD ========================================================*/ +short pdi_getEntityByPD(T_PDI_CONTEXT *context, unsigned char pd) +{ + short ret = PDI_DLL_ERROR; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_pdi_getEntityByPD[me] != NULL) || + (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_pdi_getEntityByPD[me])(context, pd); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* pdi_pd2name ==============================================================*/ +const char* pdi_pd2name(unsigned char pd) +{ + const char* ret = NULL; + if (me < 0) + { + return ret; + } + WaitForSingleObject (mut[me], INFINITE); + if ((ptr_pdi_pd2name[me] != NULL) || (ccddata_ehandler() == CCDDATA_DLL_OK)) + { + __try + { + ret = (*ptr_pdi_pd2name[me])(pd); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + // acces violation -> possibly wrong ccddata-DLL + } + } + ReleaseMutex (mut[me]); + return ret; +} + +/* ++------------------------------------------------------------------------------ +| Function : ccddata_dllname ++------------------------------------------------------------------------------ +| Description : Deliver name of currently loaded dll +| +| Parameters : - +| +| Return : lastdll ++------------------------------------------------------------------------------ +*/ +char* ccddata_dllname (void) +{ + return lastdll; +} + +/* ++------------------------------------------------------------------------------ +| Function : ccddata_exit ++------------------------------------------------------------------------------ +| Description : Unload ccddata dll and clean pointer to the functions +| +| Parameters : - +| +| Return : 0 on success, otherwise error code ++------------------------------------------------------------------------------ +*/ + +int ccddata_exit (void) +{ + if (me < 0) + { + return CCDDATA_DLL_REGISTER; + } + + ccddata_detach (me, 1); + + CloseHandle (mut[me]); + CloseHandle (initlock); + ptrindex[me] = 0; + me = -1; + + return CCDDATA_DLL_OK; +} + +/* ++------------------------------------------------------------------------------ +| Function : ccddata_init ++------------------------------------------------------------------------------ +| Description : Load ccddata dll and initialize pointer to the functions +| +| Parameters : dllname - name of the ccddata dll or NULL +| reload - if set, the ccddata dll will be switched +| +| Return : 0 on success, otherwise error code ++------------------------------------------------------------------------------ +*/ + +int ccddata_init (const char* dllname, + int reload, + void (*ccddata_init_notify)(void), + void (*ccddata_exit_notify)(void)) +{ + int ret = CCDDATA_DLL_OK; + + if (cdll[me] && !reload) + { + return CCDDATA_DLL_ALREADY; + } + + if ((initlock = ccddata_init_lock ()) == 0) + { + return CCDDATA_DLL_REGISTER; + } + + if (ccddata_register () < 0) + { + ret = CCDDATA_DLL_REGISTER; + } + else + { + ccddata_i_notify = ccddata_init_notify; + ccddata_x_notify = ccddata_exit_notify; + + if (dllname) + { + /* build full path of DLL */ + char name[MAX_PATH+1]; + LPTSTR filepart; + DWORD len=SearchPath( + NULL, // pointer to search path + dllname, // pointer to filename + NULL, // pointer to extension + MAX_PATH, // size, in characters, of buffer + name, // pointer to buffer for found filename + &filepart // pointer to pointer to file component + ); + if (!len) + { + strcpy(name, dllname); + } + + if (!lastdll[0]) + { + // no DLL has been loaded yet + reload=1; + } + else if (strcmp (lastdll, name)==0) + { + // the correct DLL is already in use + reload=0; + } + + if (reload) + { + // we want to load a new DLL but save the current one ... just in case + char old_dll[MAX_PATH]=""; + strcpy (old_dll, lastdll); + strcpy (lastdll, name); + (void) ccddata_detach (me, 1); + ret = ccddata_attach (me); + if (ret == CCDDATA_DLL_OK) + { + // now inform the other applications + (void)ccddata_clean (); + } + else + { + // upps, didn't work + strcpy (lastdll, old_dll); + (void) ccddata_attach (me); + } + } + else + { + // we just attach to the already loaded DLL + ret = ccddata_attach (me); + } + + } + } + + ReleaseMutex (initlock); + + return ret; +} +/*==== END OF FILE ===========================================================*/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccddata_mconst.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,59 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccddata_mconst.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Ccddata abstraction for use in lib/dll. The four defines (MAX... +| from mconst.cdg are supplied as constants. In addition, +| corresponding functions deliver these constants. ++----------------------------------------------------------------------------- +*/ + +#include "mconst.cdg" + +#ifdef CCD_SYMBOLS +static int ccddata_ccdsymbols = 1; +#else /* CCD_SYMBOLS */ +static int ccddata_ccdsymbols = 0; +#endif /* CCD_SYMBOLS */ + +const int ccddata_num_of_entities = NUM_OF_ENTITIES; +const int ccddata_max_message_id = MAX_MESSAGE_ID; +const int ccddata_max_bitstream_len = MAX_BITSTREAM_LEN; +const int ccddata_max_mstruct_len = MAX_MSTRUCT_LEN; + +int ccddata_get_num_of_entities () +{ + return ccddata_num_of_entities; +} + +int ccddata_get_max_message_id () +{ + return ccddata_max_message_id; +} + +int ccddata_get_max_bitstream_len () +{ + return ccddata_max_bitstream_len; +} + +int ccddata_get_max_mstruct_len () +{ + return ccddata_max_mstruct_len; +} + +int ccddata_mccd_symbols () +{ + return ccddata_ccdsymbols; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccddata_pconst.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,42 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccddata_pconst.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Ccddata abstraction for use in lib/dll. The three defines (MAX... +| from pconst.cdg are supplied as constants. In addition, +| corresponding functions deliver these constants. ++----------------------------------------------------------------------------- +*/ + +#include "pconst.cdg" + +const int ccddata_max_sap_num = MAX_SAP_NUM; +const int ccddata_max_primitive_id = MAX_PRIMITIVE_ID; +const int ccddata_max_pstruct_len = MAX_PSTRUCT_LEN; + +int ccddata_get_max_sap_num () +{ + return ccddata_max_sap_num; +} + +int ccddata_get_max_primitive_id () +{ + return ccddata_max_primitive_id; +} + +int ccddata_get_max_pstruct_len () +{ + return ccddata_max_pstruct_len; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccddata_pdi.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,363 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccddata_pdi.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : contains table with information to decode airmessages +| depending on the carrier-primitive ++----------------------------------------------------------------------------- +*/ + +#include "pdi.h" +#include "ccdtable.h" +#include "mconst.cdg" +#include "pconst.cdg" + +/* declaration of special ccdmsg preparation handlers */ +int invoke_ccd_setStore(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len); +int mphX_checker(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len); +int mphp_sing_block_req_checker(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len); +int mphp_sing_block_con_checker(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len); +int mphp_sing_block_con_edge_checker(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len); +int mphp_polling_resp_checker(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len); +int mac_data_checker(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len); +int mac_poll_checker(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len); +int rlc_data_0_checker(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len); +int rlc_data_1_checker(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len); + +/* declaration of primitive members to be collected */ +static char* ccd_loadstore_elements[]= +{ + "loadstore_val0", + "loadstore_val1", + NULL +}; + +static char* mphX_constrainer[]= +{ + "error_flag", + NULL +}; + +static char* mphp_sing_block_constrainer[]= +{ + "purpose", + NULL +}; + +static char* mphp_sing_block_con_edge_constrainer[]= +{ + "purpose", + "sb_status", + "dl_error", + NULL +}; + +static char* mphp_polling_resp_constrainer[] = +{ + "poll_resp_type", + NULL +}; + +static char* mac_data_constrainer[] = +{ + "block_status", + NULL +}; + +static char* rlc_data_constrainer[] = +{ + "rlc_id", + NULL +}; + + +/* decode info filter */ +static T_PDI_DECODEINFO m_dinfo[]={ + /* type */ /* attrib */ /* prim */ /* entity */ /* mt */ /* pdi_prepare_ccdmsg */ /* primmbr */ + {PDI_DECODETYPE_L3PDU_N, "sdu", "PH_*", "", 0xff, NULL, NULL}, + {PDI_DECODETYPE_L3PDU_N, "sdu", "MPH_*", "", 0xff, NULL, NULL}, + {PDI_DECODETYPE_RR_SHORT, "sdu", "DL_SHORT*", "RR_SHORT", 0xff, NULL, NULL}, +#ifdef DL_DATA_REQ +#if (DL_DATA_REQ & 0x4000) + /* Toggle direction for old-style DL_* primtives */ + {PDI_DECODETYPE_L3PDU_N, "sdu", "DL_*", "", 0xff, NULL, NULL}, +#endif +#endif + + {PDI_DECODETYPE_NOPD_N, "sdu", "XX_CCD_ASN1_DECODE_REQ", "ASN1_MSG", 0xff, NULL, NULL}, + {PDI_DECODETYPE_NOPD, "sdu", "XX_CCD_ASN1_CODE_IND", "ASN1_MSG", 0xff, NULL, NULL}, + {PDI_DECODETYPE_NOPD_N, "sdu", "XX_DYNARR_DECODE_REQ", "ASN1_MSG", 0xff, NULL, NULL}, + {PDI_DECODETYPE_NOPD, "sdu", "XX_DYNARR_CODE_IND", "ASN1_MSG", 0xff, NULL, NULL}, + {PDI_DECODETYPE_MAC_H_CHECK, "dl_block", "MAC_DATA_IND", "GRR", 0xff, + mac_data_checker, mac_data_constrainer}, + {PDI_DECODETYPE_MAC_H_CHECK, "dl_block", "MAC_DATA_IND_EGPRS", "GRR", 0xff, + mac_data_checker, mac_data_constrainer}, + {PDI_DECODETYPE_MAC_H_CHECK, "ul_block", "MAC_EGPRS_DATA_REQ", "GRR", 0xff, + mac_data_checker, mac_data_constrainer}, + {PDI_DECODETYPE_MAC_H_CHECK, "ul_block", "MAC_DATA_REQ", "GRR", 0xff, + mac_data_checker, mac_data_constrainer}, + {PDI_DECODETYPE_MAC_H_CHECK, "ul_block", "MAC_POLL_REQ", "GRR", 0xff, + mac_poll_checker, mac_data_constrainer}, + {PDI_DECODETYPE_NOPD, "sdu", "RRGRR_GPRS_SI13_IND", "RR", 0xff, NULL, NULL}, + {PDI_DECODETYPE_NOPD, "sdu", "RRGRR_IA_IND", "RR", 0xff, NULL, NULL}, + {PDI_DECODETYPE_NOPD, "sdu", "RRGRR_DATA_IND", "RR", 0xff, NULL, NULL}, + {PDI_DECODETYPE_NOPD, "sdu", "RRGRR_IA_DOWNLINK_IND", "RR", 0xff, NULL, NULL}, + {PDI_DECODETYPE_NOPD_N, "sdu", "RRGRR_SI_STATUS_IND", "GRR", 0xff, NULL, NULL}, + {PDI_DECODETYPE_NOPD_N, "sdu", "TB_NCELL_SI_DATA_IND", "RR", 0xff, NULL, NULL}, + {PDI_DECODETYPE_NOPD, "sdu", "RRGRR_IAEXT_IND", "RR", 0xff, NULL, NULL}, + {PDI_DECODETYPE_NOPD, "sdu", "RRGRR_DATA_REQ", "RR", 0xff, NULL, NULL}, + {PDI_DECODETYPE_NOPD_N, "sdu", "TB_SCELL_SI_DATA_IND", "RR", 0xff, NULL, NULL}, +#ifdef MPHP_DATA_IND +/* toggle direction for old 16bit MPHP* */ +#if (MPHP_DATA_IND & 0x80000000) + {PDI_DECODETYPE_MAC_H_CHECK, "frame_array", "MPHP_DATA_IND", "GRR", 0xff, + mphX_checker, mphX_constrainer}, + {PDI_DECODETYPE_MAC_H_CHECK, "data_array", "MPHP_SINGLE_BLOCK_CON", "GRR", + 0xff, NULL, NULL}, + {PDI_DECODETYPE_MAC_H_CHECK, "data_array", "MPHP_SINGLE_BLOCK_REQ", "GRR", + 0xff, mphp_sing_block_req_checker, + mphp_sing_block_constrainer}, +#else + {PDI_DECODETYPE_MAC_H_N_CHECK, "l2_frame", "MPHP_DATA_IND", "GRR", 0xff, + mphX_checker, mphX_constrainer}, + {PDI_DECODETYPE_MAC_H_N_CHECK, "l2_frame", "MPHP_SINGLE_BLOCK_CON", "GRR", + 0xff, mphp_sing_block_con_edge_checker, + mphp_sing_block_con_edge_constrainer}, + {PDI_DECODETYPE_MAC_H_CHECK, "l2_frame", "MPHP_SINGLE_BLOCK_REQ", "GRR", + 0xff, mphp_sing_block_req_checker, + mphp_sing_block_constrainer}, +#endif + {PDI_DECODETYPE_MAC_H_CHECK, "poll_data", "MPHP_POLLING_RESPONSE_REQ", + "GRR", 0xff, mphp_polling_resp_checker, + mphp_polling_resp_constrainer}, +#endif +#ifdef MPHC_DATA_IND +/* toggle direction for old 16bit MPHC* */ +#if (MPHC_DATA_IND & 0x80000000) + {PDI_DECODETYPE_AIM_CHECK, "l2_frame", "MPHC_NCELL_BCCH_IND", "RR", 0xff, + mphX_checker, mphX_constrainer}, + {PDI_DECODETYPE_AIM_CHECK, "l2_frame", "MPHC_DATA_IND", "RR", 0xff, + mphX_checker, mphX_constrainer}, +#else + {PDI_DECODETYPE_AIM_N_CHECK, "l2_frame", "MPHC_NCELL_BCCH_IND", "RR", 0xff, + mphX_checker, mphX_constrainer}, + {PDI_DECODETYPE_AIM_N_CHECK, "l2_frame", "MPHC_DATA_IND", "RR", 0xff, + mphX_checker, mphX_constrainer}, +#endif +#endif + {PDI_DECODETYPE_MAC_H, "data_array", "CGRLC_DATA_*", "GRR", 0xff, NULL, NULL}, + +#ifdef CCDENT_UMTS_AS_ASN1_MSG + +// real sdu in test primitives + // UMTS_AS_ASN1_UL_DCCH_MSG_MSG + {PDI_DECODETYPE_NOPD_NOTYPE, "sdu", "RLC_TEST_SDU_UM_DATA_REQ", "UMTS_AS_ASN1_MSG", UMTS_AS_ASN1_UL_DCCH_MSG_MSG, rlc_data_1_checker, rlc_data_constrainer}, + {PDI_DECODETYPE_NOPD_NOTYPE, "sdu", "RLC_UM_DATA_REQ", "UMTS_AS_ASN1_MSG", UMTS_AS_ASN1_UL_DCCH_MSG_MSG, rlc_data_1_checker, rlc_data_constrainer}, //rlc_id=1 + {PDI_DECODETYPE_NOPD_NOTYPE, "sdu", "RLC_UM_DATA_IND", "UMTS_AS_ASN1_MSG", UMTS_AS_ASN1_DL_DCCH_MSG_MSG, NULL, NULL}, + {PDI_DECODETYPE_NOPD_NOTYPE, "sdu", "RLC_TEST_SDU_AM_DATA_REQ", "UMTS_AS_ASN1_MSG", UMTS_AS_ASN1_UL_DCCH_MSG_MSG, NULL, NULL}, + {PDI_DECODETYPE_NOPD_NOTYPE, "sdu", "RLC_TEST_SDU_AM_DATA_IND", "UMTS_AS_ASN1_MSG", UMTS_AS_ASN1_DL_DCCH_MSG_MSG, NULL, NULL}, + {PDI_DECODETYPE_NOPD_NOTYPE, "sdu", "RLC_AM_DATA_REQ", "UMTS_AS_ASN1_MSG", UMTS_AS_ASN1_UL_DCCH_MSG_MSG, NULL, NULL}, + {PDI_DECODETYPE_NOPD_NOTYPE, "sdu", "RLC_AM_DATA_IND", "UMTS_AS_ASN1_MSG", UMTS_AS_ASN1_DL_DCCH_MSG_MSG, NULL, NULL}, + {PDI_DECODETYPE_NOPD_NOTYPE, "sdu", "RLC_TEST_SDU_UM_DATA_REQ", "UMTS_AS_ASN1_MSG", UMTS_AS_ASN1_UL_CCCH_MSG_MSG, rlc_data_0_checker, rlc_data_constrainer}, + {PDI_DECODETYPE_NOPD_NOTYPE, "sdu", "RLC_UM_DATA_REQ", "UMTS_AS_ASN1_MSG", UMTS_AS_ASN1_UL_CCCH_MSG_MSG, rlc_data_0_checker, rlc_data_constrainer}, //rlc_id=0 + {PDI_DECODETYPE_NOPD_NOTYPE, "sdu", "RLC_TEST_SDU_TR_DATA_REQ", "UMTS_AS_ASN1_MSG", UMTS_AS_ASN1_UL_CCCH_MSG_MSG, NULL, NULL}, + {PDI_DECODETYPE_NOPD_NOTYPE, "sdu", "RLC_TR_DATA_REQ", "UMTS_AS_ASN1_MSG", UMTS_AS_ASN1_UL_CCCH_MSG_MSG, NULL, NULL}, + {PDI_DECODETYPE_NOPD_NOTYPE, "sdu", "RLC_TR_DATA_IND", "UMTS_AS_ASN1_MSG", UMTS_AS_ASN1_DL_CCCH_MSG_MSG, NULL, NULL}, + //RLC_AM_RETRANSMIT_CNF + //RLC_CTCH_DATA_IND + +// only as mem handles, not suported yet + // UMTS_AS_ASN1_DL_CCCH_MSG_MSG + // UMTS_AS_ASN1_BCCH_BCH_MSG_MSG + // UMTS_AS_ASN1_DL_DCCH_MSG_MSG + // UMTS_AS_ASN1_DL_SHCCH_MSG_MSG + // UMTS_AS_ASN1_UL_SHCCH_MSG_MSG + // UMTS_AS_ASN1_PCCH_MSG_MSG + // UMTS_AS_ASN1_HO_TO_UTRANCOMMAND_MSG + // UMTS_AS_ASN1_MASTER_INFO_BLOCK_MSG + // UMTS_AS_ASN1_BCCH_FACH_MSG_MSG + // UMTS_AS_ASN1_PDSCH_SYS_INFO_LIST_MSG + // UMTS_AS_ASN1_PUSCH_SYS_INFO_LIST_MSG + +/* the following make little sence to decode since they always + comes cutted up in small peaces inside a UMTS_AS_ASN1_BCCH_BCH_MSG_MSG */ + // UMTS_AS_ASN1_SYS_INFO_TYPE_1_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_2_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_3_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_4_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_5_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_6_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_7_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_8_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_9_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_10_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_11_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_12_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_13_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_13_1_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_13_2_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_13_3_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_13_4_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_14_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_15_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_15_1_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_15_2_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_15_3_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_15_4_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_16_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_17_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_18_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_SB_1_MSG + // UMTS_AS_ASN1_SYS_INFO_TYPE_SB_2_MSG +#endif /* CCDENT_UMTS_AS_ASN1_MSG */ + + /* test stack primitives */ + {PDI_DECODETYPE_L3PDU_N, "sdu", "XX_TAP*", "", 0xff, NULL, NULL}, + {PDI_DECODETYPE_NOPD_N, "sdu", "XX_LOADSTORE_*", "XX_CSN1", 0xff, invoke_ccd_setStore, ccd_loadstore_elements}, + {PDI_DECODETYPE_NOPD_N, "sdu", "XX_CCD_2*", "XX_CSN1", 0xff, NULL, NULL}, + {PDI_DECODETYPE_NOPD_N, "sdu", "XX_*", "XX", 0xff, NULL, NULL}, + + /* all other primitives */ + {PDI_DECODETYPE_L3PDU, "sdu", "*", "", 0xff, NULL, NULL} +}; +#define DINFO_COUNT (sizeof(m_dinfo) / sizeof(*m_dinfo)) + +int ccddata_get_pdi_dinfo (const T_PDI_DECODEINFO* (*dinfo) ) +{ + *dinfo=m_dinfo; + return DINFO_COUNT; +} + +/* definition of special ccdmsg preparation handlers */ +int invoke_ccd_setStore(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len) +{ + int q; + for (q=0; q<len; q++) + { + ccd_setStore(q,values[q]); + } + + return PDI_CCDMSG; +} + +int mphX_checker(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len) +{ + if (len >= 1 && values[0] == 0) //error_flag + { + return PDI_CCDMSG; + } + else + { + return PDI_NONE; + } +} + +int mphp_sing_block_req_checker(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len) +{ + if (len >= 1 && (values[0] == 4 || values[0] == 5)) //purpose + { + return PDI_CCDMSG; + } + else + { + return PDI_NONE; + } +} + +int mphp_sing_block_con_checker(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len) +{ + if (len >= 1 && values[0] == 3) //purpose + { + return PDI_CCDMSG; + } + else + { + return PDI_NONE; + } +} + +int mphp_polling_resp_checker(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len) +{ + if (len >= 1 && values[0] == 3) //poll_resp_type + { + return PDI_CCDMSG; + } + else + { + return PDI_NONE; + } +} + +int mphp_sing_block_con_edge_checker(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len) +{ + if (len >= 3 && values[0] == 3 //purpose + && values[1] == 3 //sb_status + && values[2] == 0) //dl_error + { + return PDI_CCDMSG; + } + else + { + return PDI_NONE; + } +} + +int mac_data_checker(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len) +{ + if (len >= 1 && values[0] == 2) //block_status + { + return PDI_CCDMSG; + } + else + { + return PDI_NONE; + } +} + +int mac_poll_checker(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len) +{ + if (len >= 1 && values[0] == 3) //block_status + { + return PDI_CCDMSG; + } + else + { + return PDI_NONE; + } +} + +int rlc_data_0_checker(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len) +{ + if (len >= 1 && values[0] == 0) //rlc_id + { + return PDI_CCDMSG; + } + else + { + return PDI_NONE; + } +} + +int rlc_data_1_checker(T_PDI_CCDMSG* ccdmsg, ULONG values[], int len) +{ + if (len >= 1 && values[0] == 1) //rlc_id + { + return PDI_CCDMSG; + } + else + { + return PDI_NONE; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccddata_tap_priv.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,199 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccddata_tap_priv.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Ccddata abstraction for use in lib/dll. This function belongs +| logically to tap_tdl.c, but is based on constants from mconst.cdg. ++----------------------------------------------------------------------------- +*/ + +#define CCDDATA_TAP_PRIV_C + +#include "typedefs.h" +#include "mconst.cdg" +#include "ccddata_tap_priv.h" + +/* ++------------------------------------------------------------------------------ +| Function : ccddata_tap_get_pd ++------------------------------------------------------------------------------ +| Description : This function returns the protocol discriminator to a +| given entity number generated by ccdgen. +| +| Parameters : comp - entity number. +| +| Return : The protocol discriminator or the error condition +| TAP_PD_INVALID (= -1) if the entity is not known. ++------------------------------------------------------------------------------ +*/ +int ccddata_tap_get_pd (UCHAR comp) +{ + switch (comp) + { +#ifdef CCDENT_XX_CSN1 + case CCDENT_XX_CSN1: + return TAP_NOPD_MT; +#endif +#ifdef CCDENT_XX_TDC + case CCDENT_XX_TDC: + return TAP_NOPD_MT; +#endif +#ifdef CCDENT_RR_SHORT_PD + case CCDENT_RR_SHORT_PD: + return TAP_RR_SHORT; +#endif +#ifdef CCDENT_RR_SHORT + case CCDENT_RR_SHORT: + return TAP_RR_SHORT; +#endif +#ifdef CCDENT_UMTS_AS_ASN1_MSG + case CCDENT_UMTS_AS_ASN1_MSG: + return TAP_NOPD_NOMT; +#endif +#ifdef CCDENT_RRLP_ASN1_MSG + case CCDENT_RRLP_ASN1_MSG: + return TAP_NOPD_NOMT; +#endif +#ifdef CCDENT_ASN1_MSG + case CCDENT_ASN1_MSG: + return TAP_NOPD_MT; +#endif +#ifdef CCDENT_CLT + case CCDENT_CLT: + return TAP_NOPD_MT; +#endif +#ifdef CCDENT_CC + case CCDENT_CC: + return TAP_PD_CC; +#endif +#ifdef CCDENT_MM + case CCDENT_MM: + return TAP_PD_MM; +#endif +#ifdef CCDENT_GMM + case CCDENT_GMM: + return TAP_PD_GMM; +#endif +#ifdef CCDENT_SM + case CCDENT_SM: + return TAP_PD_SM; +#endif +#ifdef CCDENT_RR + case CCDENT_RR: + return TAP_PD_RR; +#endif +#ifdef CCDENT_SS + case CCDENT_SS: + return TAP_PD_SS; +#endif +#ifdef CCDENT_SMS + case CCDENT_SMS: + return TAP_PD_SMS; +#endif +#ifdef CCDENT_TST + case CCDENT_TST: + return TAP_PD_TST; +#endif +#ifdef CCDENT_XX + case CCDENT_XX: + return TAP_PD_XX; +#endif +#ifdef CCDENT_ABIS + case CCDENT_ABIS: + return TAP_PD_ABIS; +#endif +#ifdef CCDENT_GRR + /* special treatment: no pd in GRR-messages */ + case CCDENT_GRR: + return TAP_PD_OK; +#endif + default: + return TAP_PD_INVALID; + } +} + +/* ++------------------------------------------------------------------------------ +| Function : ccddata_tap_check_pd ++------------------------------------------------------------------------------ +| Description : This function checks if a protocol discriminator belongs to +| an entity number generated by ccdgen. +| +| Parameters : comp - entity number. +| pd - protocol discriminator. +| +| Return : The protocol discriminator. The error condition +| TAP_PD_INVALID (= -1) is returned if the given comination +| does not match. It is not an error if the entity is not +| known. ++------------------------------------------------------------------------------ +*/ +int ccddata_tap_check_pd (UCHAR comp, UCHAR pd) +{ + switch (comp) + { +#ifdef CCDENT_CC + case CCDENT_CC: + if (pd == TAP_PD_CC) + return TAP_PD_CC; + break; +#endif +#ifdef CCDENT_MM + case CCDENT_MM: + if (pd == TAP_PD_MM) + return TAP_PD_MM; + break; +#endif +#ifdef CCDENT_GMM + case CCDENT_GMM: + if (pd == TAP_PD_GMM) + return TAP_PD_GMM; + break; +#endif +#ifdef CCDENT_SM + case CCDENT_SM: + if (pd == TAP_PD_SM) + return TAP_PD_SM; + break; +#endif +#ifdef CCDENT_RR + case CCDENT_RR: + if (pd == TAP_PD_RR) + return TAP_PD_RR; + break; +#endif +#ifdef CCDENT_SS + case CCDENT_SS: + if (pd == TAP_PD_SS) + return TAP_PD_SS; + break; +#endif +#ifdef CCDENT_SMS + case CCDENT_SMS: + if (pd == TAP_PD_SMS) + return TAP_PD_SMS; + break; +#endif +#ifdef CCDENT_XX + case CCDENT_XX: + if (pd == TAP_PD_XX) + return TAP_PD_XX; + break; +#endif + default: + return pd; + } + return TAP_PD_INVALID; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccddata_tap_priv.h Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,58 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccddata_priv.h ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Function that belongs to tap_tdl.c, but is are based +| on the constants (CCDENT_...) generated by ccdgen +| (mconst.cdg). Therefore it must be placed in the ccddata_dll. ++----------------------------------------------------------------------------- +*/ + +#ifndef CCDDATA_TAP_PRIV_H +#define CCDDATA_TAP_PRIV_H + +/*==== INCLUDES =============================================================*/ + +/*==== CONSTS ===============================================================*/ + +#define TAP_PD_CC 3 +#define TAP_PD_MM 5 +#define TAP_PD_GMM 8 +#define TAP_PD_SM 10 +#define TAP_PD_RR 6 +#define TAP_PD_SS 11 +#define TAP_PD_SMS 9 +#define TAP_PD_TST 15 +#define TAP_PD_XX 1 + +#define TAP_PD_ABIS 0 +#define TAP_PD_OK 128 +#define TAP_PD_INVALID -1 +#define TAP_NOPD_NOMT 70 +#define TAP_NOPD_MT 80 +#define TAP_RR_SHORT 90 + +/*==== TYPES =================================================================*/ + +/*==== EXPORTS ===============================================================*/ + +#ifndef CCDDATA_TAP_PRIV_C + +CCDDATA_IMPORT_FUNC int ccddata_tap_get_pd (UCHAR comp); +CCDDATA_IMPORT_FUNC int ccddata_tap_check_pd (UCHAR comp, UCHAR pd); + +#endif /* !CCDDATA_TAP_PRIV_C*/ + +#endif /* !CCDDATA_TAP_PRIV_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccddata_version.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,73 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccddata_version.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : This files supplies function delivering version information +| about ccddata and the tables. ++----------------------------------------------------------------------------- +*/ + +/*==== INCLUDES =============================================================*/ +static char* +#include "ccddata_version.h" +; + +#include "typedefs.h" +#include "ccdtable.h" + +/*==== CONSTS ================================================================*//*==== TYPES =================================================================*/ +/*==== LOCALS ================================================================*/ +/*==== PRIVATE FUNCTIONS =====================================================*/ +/*==== PUBLIC FUNCTIONS ======================================================*/ + +/* ++------------------------------------------------------------------------------ +| Function : ccddata_get_version ++------------------------------------------------------------------------------ +| Description : Deliver the version of ccddata. In ccddata_version.h the +| variable CCDDATA_VERSION defines a string containing the +| version information. This file may only contain one line +| CCDDATA_VERSION="X.Y.Z" +| because it is also used by ccddata.mk. +| +| Parameters : none +| +| Return : The string containing the version information. ++------------------------------------------------------------------------------ +*/ + +char* ccddata_get_version () +{ + return CCDDATA_VERSION; +} + +/* ++------------------------------------------------------------------------------ +| Function : ccddata_get_table_version ++------------------------------------------------------------------------------ +| Description : Deliver the version of ccddata tables. +| The version is a constant from ccdtable.h and is increased +| if the tables format changes. +| +| Parameters : none +| +| Return : The version number. ++------------------------------------------------------------------------------ +*/ + +int ccddata_get_table_version () +{ + return CCDDATA_TABLE_VERSION; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccddata_version.h Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,1 @@ +CCDDATA_VERSION="1.8.5A"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/ccdtable.h Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,150 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : ccdtable.h ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Condat Conder Decoder +| Type definitions for the coding/decoding tables +| The tables are generated by CCDGEN. ++----------------------------------------------------------------------------- +*/ + + +#ifndef __CCDTABLE +#define __CCDTABLE + +#define CCDDATA_TABLE_VERSION 3 + +#ifdef WIN32 + #ifndef CCDDATA_U32 + #define CCDDATA_U32 + #endif +#endif + +/* + * Table entry for a variable + */ +typedef struct +{ +#ifdef CCD_SYMBOLS + char *name; + USHORT longNameRef; +#endif + USHORT bSize; + USHORT cSize; + char cType; + UBYTE numValueDefs; + USHORT valueDefs; +} T_CCD_VarTabEntry; + +/* + * Table entry for a spare + */ +typedef struct +{ + ULONG value; + UBYTE bSize; +} T_CCD_SpareTabEntry; + +/* + * Table entry for an element + */ +typedef struct +{ + UBYTE codingType; + BOOL optional; + char extGroup; + char repType; + USHORT calcIdxRef; + USHORT maxRepeat; +#ifdef CCDDATA_U32 + U32 structOffs; +#else /* CCDDATA_U32 */ + USHORT structOffs; +#endif /* CCDDATA_U32 */ + USHORT ident; + char elemType; + USHORT elemRef; +} T_CCD_ElemTabEntry; + +/* + * Table entry for a calculation index + */ +typedef struct +{ + UBYTE numCondCalcs; + USHORT condCalcRef; + UBYTE numPrologSteps; + USHORT prologStepRef; + USHORT numRepCalcs; + USHORT repCalcRef; +} T_CCD_CalcIndex; + + +/* + * Definition entry for a composition + */ +typedef struct +{ +#ifdef CCD_SYMBOLS + char *name; + USHORT longNameRef; +#endif +#ifdef CCDDATA_U32 + U32 cSize; + U32 bSize; +#else /* CCDDATA_U32 */ + USHORT cSize; + USHORT bSize; +#endif /* CCDDATA_U32 */ + USHORT numOfComponents; + USHORT componentRef; +} T_CCD_CompTabEntry; + +/* + * Definition entry for a calculation + */ +typedef struct +{ + char operation; + U16 operand; +} T_CCD_CalcTabEntry; + +/* + * Definition entry for a value + */ +typedef struct +{ + USHORT valStringRef; + UBYTE isDefault; + S32 startValue; + S32 endValue; +} T_CCD_ValTabEntry; + +typedef char * T_CCD_StrTabEntry; + +typedef struct +{ + char* as_name; +} T_CCD_ALIASTABLE; + +typedef struct +{ + USHORT numitems; + USHORT idx; +} T_CCD_MTXIDX; + +#define NO_REF 0xffff + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/cdc_com.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,3304 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : cdc_com.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Condat Conder Decoder +| Definitions of common functions for encoding and decoding of +| GSM, GPRS or UMTS air interface messages ++----------------------------------------------------------------------------- +*/ + +#ifdef _MSDOS +#include <dos.h> +#include <conio.h> +#endif + +/* + * standard definitions like UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" +#include <string.h> +#include <stdlib.h> + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Declaration of coder/decoder-tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +/* + * Prototypes and constants in the common part of ccd + */ +#include "ccd.h" +#include "ccd_codingtypes.h" + +/* + * Need memory allocation functions for dynamic arrays (pointers) + */ +#ifdef DYNAMIC_ARRAYS +#include "vsi.h" +#endif + +#ifndef RUN_FLASH +const UBYTE padding_bits[8] = {0, 0, 1, 0, 1, 0, 1, 1}; +const UBYTE padding_bits_prev[8] = {1, 0, 0, 1, 0, 1, 0, 1}; +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* Attention for RUN_...: static data (used in cdc_skipElem) */ +static UBYTE dummy[256]; +#endif /* !RUN_FLASH */ + +typedef struct unknownTag +{ + U8 errCode; + U8 tag; + U16 bitpos; + struct unknownTag *next; +}T_UNKNOWN_TAG; + + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : cdc_init_ctx_table | ++--------------------------------------------------------------------+ + + PURPOSE : init the iei_ctx table. This must be done before decoding + a message. + +*/ + +static void cdc_init_ctx_table (T_CCD_Globs *globs) +{ + int i; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "CONTEXT table init"); +#endif + + for (i=0; i<MAX_RECURSIONS_PER_MSG; i++) + { + globs->iei_ctx[i].valid = FALSE; + } + globs->numEOCPending = 0; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_BCD_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of an bitstream containing a BCD string + with k digits. If the first digit in the bitstream + is DIGIT_2, the digits are ordered + in the Bitstream as follow: + + MSBit LSBit + 8 7 6 5 4 3 2 1 + DIGIT_2 DIGIT_1 Octett n + DIGIT_4 DIGIT_3 Octett n+1 + : : : : : : : : + DIGIT_Z DIGIT_X Octett n+m + + if the number of the digits is odd, the last + Octett contains the bit pattern 1111 in the + most significant nibble. + + : : : : : : : : + 1 1 1 1 DIGIT_X Octett n+m + + NOTE: If the first digit in the bitstream is DIGIT_1, + the digits are ordered in a different way: + + MSBit LSBit + 8 7 6 5 4 3 2 1 + DIGIT_1 XXXXXXX Octett n + DIGIT_3 DIGIT_2 Octett n+1 + DIGIT_5 DIGIT_4 Octett n+2 + : : : : : : : : + DIGIT_Z DIGIT_X Octett n+m + + In this case, if the number of the digits + is even, the last octett contains the bit + pattern 1111 in the most significant nibble. + + : : : : : : : : + 1 1 1 1 DIGIT_X Octett n+m + + The amount of digits may be constant or variable. + + NOTE: A special case (type BCD_NOFILL) is the encoding and + decoding of a BCD string starting with DIGIT_2 but + without setting/checking the most significant nibble + of Octet n+m. This nibble belongs to the next IE + (usual coded by type BCD_MNC). + Type BCD_NOFILL is coded by startDigit EQ 2. +*/ + +void cdc_BCD_decode (const ULONG e_ref, UBYTE startDigit, T_CCD_Globs *globs) +{ + BOOL is_variable; + UBYTE *digits; + UBYTE *addr_c_xxx; + ULONG i, max_rep, nibbles_to_read, repeat; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + int k; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_BCD_decode()"); + #else + TRACE_CCD (globs, "cdc_BCD_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * if this element is conditional, check the condition + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return; + + /* + * if this element have a defined Prolog + * we have to process it before decoding the bitstream + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + /* + * if this element is repeatable, and the number of + * repeats depends on another element, calculate the repeater + */ + + if (melem[e_ref].repType NEQ ' ') + { + is_variable = ccd_calculateRep (e_ref, &repeat, &max_rep, globs); + } + else + { + repeat = 1; + is_variable = FALSE; + } + + /* + * setup the offset into the C-structure for this element + */ + globs->pstructOffs = melem[e_ref].structOffs; + + if (melem[e_ref].optional) + { + /* + * for optional elements set the valid-flag + */ + globs->pstruct[globs->pstructOffs++] = (UBYTE) TRUE; + } + + + if (is_variable) + { + /* + * for variable sized elements store the min-value + * as counter into the C-Structure (c_xxx). + */ + addr_c_xxx = (UBYTE *) (globs->pstruct + globs->pstructOffs++); + if (max_rep > 255) + globs->pstructOffs++; + } + else + addr_c_xxx = NULL; + + digits = (UBYTE *) (globs->pstruct + globs->pstructOffs); + + + if (startDigit EQ 1) + { + /* + * read the BCD digits out of the bitstream. + * The read order is 1,X,3,2,5,4 ... + */ + /* + * if the first digit is digit_1 read it and skip + * the next 4 bits, because they do not belong to + * the BCD stream. + */ + digits[0] = bf_decodeByteNumber (4, globs); + bf_incBitpos (4, globs); + /* + * make a correction on the repeatvalue + */ + if (melem[e_ref].repType NEQ ' ') + { + is_variable = ccd_calculateRep (e_ref, &repeat, &max_rep, globs); + } + + k = 2; + + for (i=0; i<repeat; i++) + { + digits[k] = bf_decodeByteNumber (4, globs); + #ifdef DEBUG_CCD + TRACE_CCD (globs, "BCD digit (%X) read", (USHORT) digits[k]); + #endif + k = ((k&1) EQ 0) ? (k-1) : (k+3); + } + } + else + { + /* + * read the BCD digits out of the bitstream. + * The read order is 2,1,4,3,6,5 ... + */ + k = 1; + + nibbles_to_read = repeat; + + if (repeat & 1) + nibbles_to_read++; + + for (i=0; i<nibbles_to_read; i++) + { + digits[k] = bf_decodeByteNumber (4, globs); + #ifdef DEBUG_CCD + TRACE_CCD (globs, "BCD digit (%X) read", (USHORT) digits[k]); + #endif + k = ((k&1) EQ 1) ? (k-1) : (k+3); + } + } + + /* + * check the 1111 pattern and the even odd criteria + */ + + if (startDigit EQ 1) + { + if ((repeat & 1) EQ 0) + { + /* even number of digits */ + if (digits[repeat] NEQ 0xf) + repeat++; + } + } + else + { + if ((repeat & 1) EQ 1) + { + /* odd number of digits */ + if (digits[repeat] NEQ 0xf AND startDigit EQ 0) + { + /* + * if there is no 1111 pattern generate an error + */ + ccd_setError (globs, ERR_PATTERN_MISMATCH, + CONTINUE, + (USHORT) (globs->bitpos-8), (USHORT) -1); + } + } + + else + { + /* even number of digits - the last may be 0xf */ + if (digits[repeat-1] EQ 0xf) + repeat--; /* 0x0f dosn't belong to the coded digit string */ + } + } + + if (addr_c_xxx NEQ NULL) + { + /* + * store the number of digits into the + * c_xxx variable if there is one. + */ + if (max_rep > 65535) + { + ULONG *addr_c_xxx_u32; + addr_c_xxx_u32 = (ULONG *)addr_c_xxx; + *addr_c_xxx_u32 = repeat; + } + else if (max_rep > 255) + { + USHORT *addr_c_xxx_u16; + addr_c_xxx_u16 = (USHORT *)addr_c_xxx; + *addr_c_xxx_u16 = (USHORT) repeat; + } + else + *addr_c_xxx = (UBYTE) repeat; + } +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_BCD_encode | ++--------------------------------------------------------------------+ + + PURPOSE : encoding a Bytearray, that contain a BCD Number, into + bitstream. + The digits coded in the following order + into the Bitstream: + + MSBit LSBit + 7 8 6 5 4 3 2 1 + DIGIT_2 DIGIT_1 Octett n + DIGIT_4 DIGIT_3 Octett n+1 + : : : : : : : : + DIGIT_Z DIGIT_X Octett n+m + + if the number of the digits are odd, the bit pattern 1111 + will be coded in the most significant nibble of + the last Octett. + + : : : : : : : : + 1 1 1 1 DIGIT_X Octett n+m + + The amount of digits may be constant or variable. +*/ +void cdc_BCD_encode (const ULONG e_ref, UBYTE startDigit, T_CCD_Globs *globs) +{ + ULONG repeat; + int k; + register UBYTE *digits; + BOOL fullBitsNeeded=FALSE; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_BCD_encode()"); + #else + TRACE_CCD (globs, "cdc_BCD_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * if this element is conditional, check the condition + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return; + + /* + * if this element have a defined Prolog + * we have to process it before decoding the bitstream + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + /* + * setup the offset into the C-structure for this element + */ + globs->pstructOffs = melem[e_ref].structOffs; + + if (melem[e_ref].optional) + { + /* + * for optional elements check the valid-flag + */ + if (globs->pstruct[globs->pstructOffs++] == FALSE) + return; +#ifdef DEBUG_CCD + else if (globs->pstruct [melem[e_ref].structOffs] != TRUE) + { + TRACE_CCD (globs, "Ambiguous value for valid flag!\n...assumed 1 for ccdID=%d", + e_ref); + } +#endif + } + + /* + * if this element is repeatable, and the number of + * repeats depends on another element, calculate the repeater + */ + if (melem[e_ref].repType EQ 'v' OR melem[e_ref].repType EQ 'i') + { + /* + * for variable sized elements read the amount + * of repeats out of the C-Structure (c_xxx). + * If the number of repeats given by the C-Structure + * exceeds the allowed value (maxRepeat) CCD gives a warning! + */ + if (melem[e_ref].maxRepeat > 255) + { + ULONG count = (ULONG) (* (USHORT *)(globs->pstruct + globs->pstructOffs++)); + repeat = MINIMUM (count, (ULONG) melem[e_ref].maxRepeat); + if (repeat < count) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + e_ref, globs->pstruct + globs->pstructOffs); + } + else + { + repeat = (ULONG)MINIMUM (globs->pstruct[globs->pstructOffs], + melem[e_ref].maxRepeat); + if ( repeat < (ULONG) (globs->pstruct[globs->pstructOffs]) ) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + globs->pstructOffs++; + } + else + if (melem[e_ref].repType EQ 'c') + repeat = (ULONG) melem[e_ref].maxRepeat; + else + repeat = 1; + + /* There seems to exist cases where address contains no digits. */ + if (repeat EQ 0) + return; + + /* + * setup the read pointer to the byte array that contain + * the BCD number. + */ + digits = (UBYTE *) (globs->pstruct + globs->pstructOffs); + + if (startDigit EQ 1) + { + /* + * write the BCD digits into the bitstream. + * The write order is 1,X,3,2,5,4 ... + */ + if ((repeat & 1) EQ 0) + { + /* + * for even digits store the 1111 pattern at last digit + */ + fullBitsNeeded = TRUE; + } + /* + * if the first digit is digit_1 write it and skip + * the next 4 bits, because they does not belong to + * the BCD stream. + */ + bf_codeByteNumber (4, digits[0], globs); + + #ifdef DEBUG_CCD + TRACE_CCD (globs, "BCD digit (%X) written", (USHORT) digits[0]); + TRACE_CCD (globs, "skipping 4 bits"); + #endif + + bf_incBitpos (4, globs); + k = 2; + + while (--repeat>1) + { + bf_codeByteNumber (4, digits[k], globs); + #ifdef DEBUG_CCD + TRACE_CCD (globs, "BCD digit (%X) written", (USHORT) digits[k]); + #endif + k = ((k&1) EQ 0) ? (k-1) : (k+3); + } + if (repeat) + { + if (fullBitsNeeded) + { + bf_codeByteNumber (4, 0xf, globs); + k = ((k&1) EQ 0) ? (k-1) : (k+3); + } + bf_codeByteNumber (4, digits[k], globs); + } + + } + else + { + /* + * store the BCD digits into the bitstream. + * The write order is 2,1,4,3,6,5 ... + */ + if (repeat & 1) + { + /* + * for odd digits store the 1111 pattern at last digit + * in case of type BCD_NOFILL use 0 instead + */ + fullBitsNeeded = TRUE; + } + + k = 1; + + while ( repeat-- > 1) + { + bf_codeByteNumber (4, digits[k], globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "BCD digit (%X) written", (USHORT) digits[k]); +#endif + k = ((k&1) EQ 1) ? (k-1) : (k+3); + } + if (fullBitsNeeded) + { + bf_codeByteNumber (4, (UBYTE)((startDigit NEQ 2) ? 0xf : 0), globs); + k = ((k&1) EQ 1) ? (k-1) : (k+3); + } + bf_codeByteNumber (4, digits[k], globs); + } +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_FLASH +/* Attention for RUN_...: static function */ +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : cdc_init_table | ++--------------------------------------------------------------------+ + + PURPOSE : init the iei_table for each new msg that is to be decoded. + The c_ref references a composition (msg). The function + initialises the table entrys only for the used iei for + this message. + +*/ + +static void cdc_init_table (const ULONG c_ref, T_CCD_Globs *globs) + +{ + ULONG look_up; + ULONG num_elems; + ULONG ie_table_idx; + ULONG rlevel = globs->ccd_recurs_level; + + if (globs->iei_ctx[rlevel].valid AND rlevel < (ULONG) globs->last_level) + { + int i; + /* + * this iei context has been initialized before, so + * no action for this. All deeper levels must be set + * to invalid; + */ + for (i=globs->last_level; i<MAX_RECURSIONS_PER_MSG; i++) + globs->iei_ctx[i].valid = FALSE; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "TAG table init for old level %d", rlevel); +#endif + } + else + { + /* + * this iei context has not been initialized before, so + * initialize the iei_table for this. + */ +#ifdef DEBUG_CCD + TRACE_CCD (globs, "TAG table init for new level %d", rlevel); +#endif + look_up = (ULONG) mcomp[c_ref].componentRef; + num_elems = (ULONG) mcomp[c_ref].numOfComponents; + + /* + * store the startposition of the corresponding melem table and + * the number of elements in the IEtable + */ + globs->iei_ctx[rlevel].melemStart = (USHORT) look_up; + globs->iei_ctx[rlevel].ieTableLen = (USHORT) num_elems; + globs->iei_ctx[rlevel].EOCPending = FALSE; + globs->iei_ctx[rlevel].countSkipped = 0; + + /* + * for each element with an iei (ident) setup the + * the iei_table-entry. + */ + ie_table_idx = 0; + + /* + * if the number of IE in this message is greater than + * the allocated IEItable, generate an error. + */ + if (num_elems > MAX_IE_PER_MSG) + ccd_setError (globs, ERR_INTERNAL_ERROR, BREAK, (USHORT) -1); + + while (num_elems--) + { + if (melem[look_up].ident NEQ 0xffff) + { + globs->iei_ctx[rlevel].iei_table[ie_table_idx].ident = (UBYTE) melem[look_up].ident; + + /* + * GSM1TV elements have only a 4 bit Tag (T). For this + * elements we have to shift the ident into the upper nibble + * and set the lower nibble to zero. For GSM2T elements and + * GSM1TV elements set the MSBit (Bit7). + */ + if (melem[look_up].codingType EQ CCDTYPE_GSM1_TV) + { + /* + * shift into the upper nibble, clear the lower nibble + * and set the MSBit. + */ + globs->iei_ctx[rlevel].iei_table[ie_table_idx].ident <<= 4; + globs->iei_ctx[rlevel].iei_table[ie_table_idx].ident |= 0x80; + globs->iei_ctx[rlevel].iei_table[ie_table_idx].ident &= 0xf0; + } + else + { + if (melem[look_up].codingType EQ CCDTYPE_GSM2_T) + { + /* + * Set the MSBit. + */ + globs->iei_ctx[rlevel].iei_table[ie_table_idx].ident |= 0x80; + } + } + globs->iei_ctx[rlevel].iei_table[ie_table_idx].act_amount = 0; + globs->iei_ctx[rlevel].iei_table[ie_table_idx].exhausted = FALSE; + + switch (melem[look_up].codingType) + { + case CCDTYPE_GSM1_TV: + + case CCDTYPE_GSM2_T: + + case CCDTYPE_GSM3_TV: + + case CCDTYPE_GSM4_TLV: + + case CCDTYPE_GSM5_TV: + + case CCDTYPE_GSM5_TLV: + + case CCDTYPE_GSM1_ASN: + + case CCDTYPE_GSM6_TLV: + + globs->iei_ctx[rlevel].iei_table[ie_table_idx].valid = TRUE; + break; + + default: + globs->iei_ctx[rlevel].iei_table[ie_table_idx].valid = FALSE; + break; + } + } + else + globs->iei_ctx[rlevel].iei_table[ie_table_idx].valid = FALSE; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "iei_table[%d] v=%d ident=%x level=%d", + ie_table_idx, + globs->iei_ctx[rlevel].iei_table[ie_table_idx].valid, + globs->iei_ctx[rlevel].iei_table[ie_table_idx].ident, + rlevel); +#endif + + look_up++; + ie_table_idx++; + } + globs->iei_ctx[rlevel].valid = TRUE; + } +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* Attention for RUN_...: static function */ +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : cdc_search_table | ++--------------------------------------------------------------------+ + + PURPOSE : search on the iei_table for the given TAG (T). + if the TAG can be found (and - in case of CCDTYPE_GSM1_ASN - + if the information element isn't exhausted), the table + index was returned as a difference between the found index + and the aktIndex, -127 otherwise. + +*/ + +static int cdc_search_table + ( + int akt_index, + ULONG t, + BOOL limited, + BOOL *nonTaggedFound, + T_CCD_Globs *globs + ) +{ + int tab_idx; + ULONG iei; + int ret = -127; + ULONG rec_level = globs->ccd_recurs_level; + + /* + * search from the akt position to the end of the table. + * This is faster, because in correct messages the found Tag + * is at a later position in the table. + */ + tab_idx = akt_index; + + *nonTaggedFound = FALSE; + + while (tab_idx < (int) globs->iei_ctx[rec_level].ieTableLen) + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "looking for Tag(%x) iei_table[%d] v=%d ident=%x level=%d", + t, tab_idx, + globs->iei_ctx[rec_level].iei_table[tab_idx].valid, + globs->iei_ctx[rec_level].iei_table[tab_idx].ident, + rec_level); +#endif + + if (globs->iei_ctx[rec_level].iei_table[tab_idx].valid) + { + if (limited) + { + iei= (ULONG)(globs->iei_ctx[rec_level].iei_table[tab_idx].ident & 0x7f); + } + else + { + iei= (ULONG)(globs->iei_ctx[rec_level].iei_table[tab_idx].ident); + } + if ( iei EQ t ) + { + if ( globs->iei_ctx[rec_level].iei_table[tab_idx].exhausted EQ FALSE ) + { + return (tab_idx-akt_index); + } + else if ( (globs->iei_ctx[rec_level].melemStart + akt_index) + EQ (int) globs->iei_ctx[rec_level].melemLast) + { + /* + * allows multiple appearance of the repeated element is coded as + * TLV0 TLV1 TLV2 .... + */ + return (tab_idx-akt_index); + } + else + { + ret = (tab_idx-akt_index); + } + } + } + else + *nonTaggedFound = TRUE; + tab_idx++; + } + + tab_idx = 0; + + while (tab_idx < akt_index) + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "looking for Tag(%x) iei_table[%d] v=%d ident=%x level=%d", + t, tab_idx, + globs->iei_ctx[rec_level].iei_table[tab_idx].valid, + globs->iei_ctx[rec_level].iei_table[tab_idx].ident, + rec_level); +#endif + if (limited) + { + iei= (ULONG)(globs->iei_ctx[rec_level].iei_table[tab_idx].ident & 0x7f); + } + else + { + iei= (ULONG) globs->iei_ctx[rec_level].iei_table[tab_idx].ident; + } + if (globs->iei_ctx[rec_level].iei_table[tab_idx].valid + AND (iei EQ t) ) + { + if ( globs->iei_ctx[rec_level].iei_table[tab_idx].exhausted EQ FALSE ) + { + return (tab_idx-akt_index); + } + else + { + ret = (tab_idx-akt_index); + } + } + tab_idx++; + } + + if (ret != -127) + { + globs->SequenceError = TRUE; + } + + return ret; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* Attention for RUN_...: static function */ +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : cdc_decode_L | ++--------------------------------------------------------------------+ + + PURPOSE : Decode the length element of TLV and LV values +*/ + +static ULONG cdc_decode_L (const ULONG e_ref, const ULONG len_l, T_CCD_Globs *globs) +{ + ULONG l; + + switch (melem[e_ref].codingType) + { + case CCDTYPE_GSM1_ASN: + l = (ULONG) bf_decodeByteNumber (8, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "decoding 8 bits, l = (%x)", l); +#endif + if (l EQ 0x80) + l = 0xFFFF; + else if (l EQ 0x81) + { + l = (ULONG) bf_decodeByteNumber (8, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "decoding 8 bits after 0x81, l = (%x)", l); +#endif + } + else if (l EQ 0x82) + { + l = bf_decodeShortNumber (16, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "decoding 16 bits after 0x82, l = (%x)", l); +#endif + } + break; + + case CCDTYPE_GSM5_TLV: + l = (ULONG) bf_decodeByteNumber (8, globs); + + if (l EQ 0x81) + { + l = (ULONG) bf_decodeByteNumber (8, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "decoding 8 bits after 0x81, l = (%x)", l); + } + else + { + TRACE_CCD (globs, "decoding 8 bits, l = (%x)", l); +#endif + } + break; + + case CCDTYPE_GSM6_TLV: + l = bf_decodeShortNumber (16, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "decoding 16 bits, l = (%x)", l); +#endif + break; + + default: + l = (ULONG) bf_decodeByteNumber (len_l, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "decoding %d bits, l = (%x)", len_l, l); +#endif + break; + } + + /* + * Write the value of l at the end of UPN Stack. + * this could be read by an IE of the coding type NO_CODE. + */ + globs->KeepReg[0] = l ; + return l; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* Attention for RUN_...: static function */ +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : cdc_tagged_LV_decode| ++--------------------------------------------------------------------+ + + PURPOSE : If the parameter lenL is set to a positive value, + this function decodes the L-component. + After this it decodes the element referenced + by eRef out of the bitstream into the C-Structure + (globs->pstruct) at position globs->pstructOffs. + If a repeat value is defined for this element, + this function decodes only one appeareance + of the element because it is a tagged + element. In this case the decoded element is stored in + an array wich is indexed by eIndex; +*/ + +static BOOL cdc_tagged_LV_decode (const ULONG e_ref, + ULONG e_index, + const ULONG len_l, + T_CCD_Globs *globs) +{ + ULONG amount, l; + USHORT act_maxBP, tmp_maxBP; + BOOL endOfComposition = FALSE; + BOOL asn1=FALSE; + U32 offset=0; +#ifdef DYNAMIC_ARRAYS + U8 *old_pstruct = NULL; +#endif + + if (melem[e_ref].codingType EQ CCDTYPE_GSM1_ASN) + asn1 = TRUE; + + if (melem[e_ref].elemType NEQ 'S') + { + /* + * set the offset into the C-structure for this element. + */ + if (melem[e_ref].optional) + { + globs->pstruct[globs->pstructOffs++] = (UBYTE) TRUE; + } + + if (melem[e_ref].repType EQ 'i') + { + /* + * The number of appearance of all repeatable IEs may + * differ in a message. So we have to store the number + * in a c_xxx counter into the C-Structure. + */ + if (melem[e_ref].maxRepeat > 65535) + *(ULONG *) (globs->pstruct + globs->pstructOffs++) = e_index; + else if (melem[e_ref].maxRepeat > 255) + *(USHORT *) (globs->pstruct + globs->pstructOffs++) = (USHORT) e_index; + else + globs->pstruct[globs->pstructOffs] = (UBYTE) e_index; + + globs->pstructOffs++; + + /* + * Recalculate the struct offset for repeatable IEs. + * New pointer types 'R' and 'F' are equivalent to 'V'. + */ +#ifdef DYNAMIC_ARRAYS + offset = (e_index-1) * ((melem[e_ref].elemType EQ 'V' + OR melem[e_ref].elemType EQ 'R' + OR melem[e_ref].elemType EQ 'F' + ) ? mvar[melem[e_ref].elemRef].cSize + : mcomp[melem[e_ref].elemRef].cSize + ); +#else + offset = (e_index-1) * ((melem[e_ref].elemType EQ 'V') + ? mvar[melem[e_ref].elemRef].cSize + : mcomp[melem[e_ref].elemRef].cSize + ); +#endif + } + } + /* + * If len_l > 0 read the l-Component out of the bistream. + */ + if (len_l) + { + if( len_l <= (ULONG) (globs->maxBitpos - globs->bitpos) ) + { + act_maxBP = globs->maxBitpos; + l = cdc_decode_L (e_ref, len_l, globs); + + if (l EQ 0xFFFF) + { + /* + * For ASN1-BER encoding we must look for the special + * length 0x80 because it indicates the indefinite + * length. This needs a special handling with later EOC tags. + * + */ + globs->iei_ctx[globs->ccd_recurs_level].EOCPending = TRUE; + globs->numEOCPending++; + + #ifdef DEBUG_CCD + TRACE_CCD (globs, "implicit ASN1 length - EOC is pending"); + #endif + } + else + { + /* + * Calculate the max bitpos for this element + */ + tmp_maxBP = (USHORT) (globs->bitpos + (l*8)); + if (globs->buflen < tmp_maxBP) + { + ccd_recordFault (globs, ERR_MSG_LEN, CONTINUE, (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + else if (globs->maxBitpos < tmp_maxBP) + { + ccd_recordFault (globs, ERR_ELEM_LEN, BREAK, (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + globs->maxBitpos = (USHORT)MINIMUM (globs->buflen, tmp_maxBP); + tmp_maxBP = globs->maxBitpos; + } + } + else + { + ccd_recordFault (globs, ERR_ELEM_LEN, BREAK, (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + } +#ifdef DYNAMIC_ARRAYS + /* + * Check for pointer types; allocate memory if necessary. + */ + if ((melem[e_ref].elemType >= 'P' AND melem[e_ref].elemType <= 'R') OR + (melem[e_ref].elemType >= 'D' AND melem[e_ref].elemType <= 'F')) + { + U32 cSize; + U8 *addr; + + /* + * Find size to allocate; + * - Read from mcomp or mvar according to type + */ + cSize = (ULONG)((melem[e_ref].elemType EQ 'V' OR + melem[e_ref].elemType EQ 'R') + ? mvar[melem[e_ref].elemRef].cSize + : mcomp[melem[e_ref].elemRef].cSize + ); + + /* + * Allocate additional memory + */ + addr = (U8 *)DP_ALLOC( cSize, globs->alloc_head, DP_NO_FRAME_GUESS); + + /* If no memory, log error and return immediately */ + if (addr EQ NULL) { + ccd_setError (globs, ERR_NO_MEM, + BREAK, + (USHORT) -1); + return endOfComposition; + } + else + memset (addr, 0, (size_t)(cSize)); + + /* + * Memory allocated; + * 1. Save old "globs->pstruct" variables + * 2. Store pointer to freshly allocated memory area in structure + * 3. Initialize pstruct to point to the freshly allocated memory area. + * 4. Initialize pstructOffs to 0 to start decoding at offset 0 + * in the new memory area. + */ + old_pstruct = globs->pstruct; + *(U8 **)(globs->pstruct + globs->pstructOffs) = addr; + globs->pstruct = addr; + globs->pstructOffs = 0; + } + else + { + globs->pstructOffs += offset; + } +#else /* DYNAMIC_ARRAYS */ + globs->pstructOffs += offset; +#endif /* DYNAMIC_ARRAYS */ + + + /* + * Decode the value. Keep caution with BER encoding of ASN1 integers. + * All other types can be decoded by a generic function. + */ + if (asn1 AND melem[e_ref].elemType EQ 'V' + AND + melem[e_ref].repType EQ ' ' + AND + l NEQ 0xFFFF + ) + { +#ifdef DEBUG_CCD +#ifdef CCD_SYMBOLS + TRACE_CCD (globs, "BER decoding of ASN.1 integer %s", + ccddata_get_alias((USHORT) e_ref, 1)); +#else + TRACE_CCD (globs, "BER decoding of ASN.1 integer; e_ref = %d", melem[e_ref].elemRef); +#endif +#endif + + if (mvar[melem[e_ref].elemRef].cType EQ 'X') + bf_readBitChunk (l*8, globs); + else + bf_readBits (l*8, globs); + } + else + { + amount = 1; + if (len_l) + { + if (l > 0) + { + cdc_decodeElemvalue (e_ref, &amount, globs); + } + else + { + amount = 0; + } + } + else + { + if (melem[e_ref].codingType != CCDTYPE_GSM2_T) + cdc_decodeElemvalue (e_ref, &amount, globs); + } + } +#ifdef DYNAMIC_ARRAYS + /* + * Restore globs->pstruct for possible use below + */ + if (old_pstruct NEQ NULL) + globs->pstruct = old_pstruct; +#endif + + if (asn1 AND globs->numEOCPending AND !bf_endOfBitstream(globs)) + { + UBYTE T = bf_decodeByteNumber (8, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "looking for EOC decoding 8 bits T = (%x)", T); +#endif + + if (T EQ 0) + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "First EOC octet found"); +#endif + + if (globs->iei_ctx[globs->ccd_recurs_level].EOCPending) + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "End of ASN1 TLV"); +#endif + /* + * Skip the second EOC octet. + */ + bf_incBitpos (8, globs); + globs->iei_ctx[globs->ccd_recurs_level].EOCPending = FALSE; + globs->numEOCPending--; + } + else + { + /* + * The read first EOC octet belongs to an ASN1 TLV of a + * higher recursion level. Let it be read and evalauted later + * again for that IE. + */ + bf_setBitpos (globs->bitpos-8, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "End of higer level ASN1 TLV"); + TRACE_CCD (globs, "Decrementing bitpos by 8 to %d", globs->bitpos); +#endif + endOfComposition = TRUE; + } + } + else + { + if (globs->iei_ctx[globs->ccd_recurs_level].EOCPending) + { + /* + * EOC element is pending but not found. + */ + ccd_setError (globs, ERR_EOC_TAG_MISSING, + BREAK, + (USHORT) T, + globs->bitpos-8, + (USHORT) -1); + + bf_setBitpos (globs->bitpos-8, globs); + } + else + { + /* + * normal TAG leave it in the bitstream + */ +#ifdef DEBUG_CCD + TRACE_CCD (globs, "Normal TAG - Decrementing bitpos by 8 to %d", globs->bitpos); +#endif + bf_setBitpos (globs->bitpos-8, globs); + } + } + } + + if (len_l) + { + if (!asn1) + { + if (globs->bitpos > tmp_maxBP) + { + ccd_recordFault (globs, ERR_ELEM_LEN, CONTINUE, (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + else + { + /* + * set the bitpos to the end of the LV or TLV element + */ + bf_setBitpos (tmp_maxBP, globs); + } + } + /* + * set the maxBitpos to the next octet boundary if the + * last non-spare IE does not end at an octet boundary. + * This is necessary for avoiding an early end of decoding. + */ +/* + globs->maxBitpos = globs->buflen; +*/ + globs->maxBitpos = act_maxBP; + } + + return endOfComposition; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* Attention for RUN_...: static function */ +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : cdc_normal_LV_decode| ++--------------------------------------------------------------------+ + + PURPOSE : If the parameter lenL is set, this function + decodes the L-component. After this it decodes + the element referenced by eRef from the + bitstream into the C-Structure (globs->pstruct) + at position globs->pstructOffs. + If a repeat value is defined for this element + this function decodes the V-component multiple and stores + the values into an array. +*/ + +static BOOL cdc_normal_LV_decode (const ULONG e_ref, + const ULONG len_l, + T_CCD_Globs *globs) +{ + ULONG l, repeat, amount, max_rep; + USHORT act_maxBP, tmp_maxBP; + BOOL is_variable; + BOOL endOfComposition = FALSE; + BOOL asn1; + BOOL length_in_bits; +#ifdef DYNAMIC_ARRAYS + U8 *old_pstruct = NULL; +#endif + + switch (melem[e_ref].codingType) + { + case CCDTYPE_GSM1_ASN: + asn1 = TRUE; + length_in_bits = FALSE; + break; + + case CCDTYPE_GSM7_LV: + asn1 = FALSE; + length_in_bits = TRUE; + break; + + default: + asn1 = FALSE; + length_in_bits = FALSE; + break; + } + + /* + * if this element is repeatable, and the number of + * repeats depends on another element, calculate the repeater + */ + if (melem[e_ref].repType NEQ ' ') + { + is_variable = ccd_calculateRep (e_ref, &repeat, &max_rep, globs); + } + else + { + repeat = 1; + is_variable = FALSE; + } + + if (melem[e_ref].elemType NEQ 'S') + { + /* + * Element is not a SPARE. + * Setup the offset into the C-structure for this element + */ + if (melem[e_ref].optional) + { + globs->pstruct[globs->pstructOffs++] = (UBYTE) TRUE; + } + + if (is_variable) + { + /* + * for variable sized elements store the min-value + * as counter into the C-Structure (c_xxx). + */ + if (max_rep > 65535) + *(ULONG *) (globs->pstruct + globs->pstructOffs++) = repeat; + else if (max_rep > 255) + *(USHORT *) (globs->pstruct + globs->pstructOffs++) = (USHORT) repeat; + else + globs->pstruct[globs->pstructOffs] = (UBYTE) repeat; + + globs->pstructOffs++; + } + } + + /* + * if len_l > 0 read the l-Component out of the bistream. + */ + if (len_l) + { + if( len_l <= (ULONG)(globs->maxBitpos - globs->bitpos) ) + { + act_maxBP = globs->maxBitpos; + + l = cdc_decode_L (e_ref, len_l, globs); + + if (l EQ 0xFFFF) + { + /* + * for ASN1 element coding we must look for the special + * length 0x80 because it indicates the indefinite + * length. This needs a special handling with later EOC tags. + */ + globs->iei_ctx[globs->ccd_recurs_level].EOCPending = TRUE; + + globs->numEOCPending++; + + #ifdef DEBUG_CCD + TRACE_CCD (globs, "implicit ASN1 length - EOC is pending"); + #endif + } + else + { + /* + * calculate the max bitpos for this element + */ + if (!length_in_bits) + l *= 8; + + tmp_maxBP = (USHORT) (globs->bitpos + l); + + if (globs->buflen < tmp_maxBP) + { + ccd_recordFault (globs, ERR_MSG_LEN, CONTINUE, (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + else if (globs->maxBitpos < tmp_maxBP) + { + ccd_recordFault (globs, ERR_ELEM_LEN, BREAK, (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + globs->maxBitpos = (USHORT)MINIMUM (globs->buflen, tmp_maxBP); + tmp_maxBP = globs->maxBitpos; + + /* + * for bitfields which appear in TLV or LV elements + * we must calculate the length (repeat) from the l values + */ + if (melem[e_ref].repType EQ 'b') + repeat = l; + } + } + else + { + ccd_recordFault (globs, ERR_ELEM_LEN, BREAK, (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + } +#ifdef DYNAMIC_ARRAYS + /* + * MVJ: Dynamic array addition. + * Check for pointer types; allocate memory if necessary. + */ + if ((melem[e_ref].elemType >= 'P' AND melem[e_ref].elemType <= 'R') OR + (melem[e_ref].elemType >= 'D' AND melem[e_ref].elemType <= 'F')) { + ULONG cSize, rep; + U8 *addr; + + /* + * Find size to allocate; + * - Read from mcomp or mvar according to type + * - Unbounded (0-terminated) ASN1-types are allocated with MAX repeat + */ + if (globs->iei_ctx[globs->ccd_recurs_level].EOCPending) { + rep = (ULONG) melem[e_ref].maxRepeat; + } else { + rep = repeat; + } + cSize = (ULONG)((melem[e_ref].elemType EQ 'V' OR + melem[e_ref].elemType EQ 'R') + ? mvar[melem[e_ref].elemRef].cSize + : mcomp[melem[e_ref].elemRef].cSize + ) * rep; + + /* + * Allocate additional memory + */ + addr = (U8 *)DP_ALLOC( cSize, globs->alloc_head, DP_NO_FRAME_GUESS); + + /* If no memory, log error and return immediately */ + if (addr EQ NULL) { + ccd_setError (globs, ERR_NO_MEM, + BREAK, + (USHORT) -1); + return endOfComposition; + } + else + memset (addr, 0, (size_t)cSize); + + /* + * Memory allocated; + * 1. Save old "globs->pstruct" variables + * 2. Store pointer to freshly allocated memory area in structure + * 3. Initialize pstruct to point to the freshly allocated memory area. + * 4. Initialize pstructOffs to 0 to start decoding at offset 0 + * in the new memory area. + */ + old_pstruct = globs->pstruct; + *(U8 **)(globs->pstruct + globs->pstructOffs) = addr; + globs->pstruct = addr; + globs->pstructOffs = 0; + } +#endif + + /* + * Decode the value. Keep caution with BER encoding of ASN1 integers. + * All other types can be decoded by a generic function. + */ + if (asn1 AND melem[e_ref].elemType EQ 'V' + AND + melem[e_ref].repType EQ ' ' + AND + l NEQ 0xFFFF + ) + { +#ifdef DEBUG_CCD +#ifdef CCD_SYMBOLS + TRACE_CCD (globs, "BER decoding of ASN.1 integer %s", + ccddata_get_alias((USHORT) e_ref, 1)); +#else + TRACE_CCD (globs, "BER decoding of ASN.1 integer; e_ref = %d", melem[e_ref].elemRef); +#endif +#endif + amount = l; + if (mvar[melem[e_ref].elemRef].cType EQ 'X') + bf_readBitChunk (l, globs); + else + bf_readBits (l, globs); + } + else + { + amount = repeat; + if (len_l) + { + if (l > 0) + { + cdc_decodeElemvalue (e_ref, &amount, globs); + } + else + { + amount = 0; + } + } + else + { + if (melem[e_ref].codingType != CCDTYPE_GSM2_T) + cdc_decodeElemvalue (e_ref, &amount, globs); + } + } + +#ifdef DYNAMIC_ARRAYS + /* + * Restore globs->pstruct for possible use below + */ + if (old_pstruct NEQ NULL) { + globs->pstruct = old_pstruct; + } +#endif + + if (amount NEQ repeat AND is_variable) + { + /* + * If the number of decoded elements is not equal to the given + * repeat value, because the bitstream or the IE ended, + * store the new c_xxx value. + */ + globs->pstructOffs = melem[e_ref].structOffs; + + if (melem[e_ref].optional) + globs->pstructOffs++; + + globs->pstruct[globs->pstructOffs] = (UBYTE) amount; + + if (melem[e_ref].repType NEQ 'i') + { + /* + * if this element is not of the repeat style 'interval' + * ([X..Y] where X and Y are constants) we have to generate + * an ccd error because some outstanding repeats are missing. + */ + ccd_setError (globs, ERR_MAND_ELEM_MISS, + CONTINUE, + (USHORT) -1); + } + } + + if (asn1 AND globs->numEOCPending AND !bf_endOfBitstream(globs)) + { + UBYTE T = bf_decodeByteNumber (8, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "looking for EOC decoding 8 bits T = (%x)", T); +#endif + + if (T EQ 0) + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "First EOC octet found"); +#endif + + if (globs->iei_ctx[globs->ccd_recurs_level].EOCPending) + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "End of ASN1 TLV"); +#endif + /* + * Skip the second EOC octet. + */ + bf_incBitpos (8, globs); + globs->iei_ctx[globs->ccd_recurs_level].EOCPending = FALSE; + globs->numEOCPending--; + } + else + { + /* + * The read first EOC octet belongs to an ASN1 TLV of a + * higher recursion level. Let it be read and evalauted later + * again for that IE. + */ + bf_setBitpos (globs->bitpos-8, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "End of higer level ASN1 TLV"); + TRACE_CCD (globs, "Decrementing bitpos by 8 to %d", globs->bitpos); +#endif + endOfComposition = TRUE; + } + } + else + { + if (globs->iei_ctx[globs->ccd_recurs_level].EOCPending) + { + /* + * EOC element is pending but not found. + */ + ccd_setError (globs, ERR_EOC_TAG_MISSING, + BREAK, + (USHORT) T, + globs->bitpos-8, + (USHORT) -1); + + bf_setBitpos (globs->bitpos-8, globs); + } + else + { + /* + * normal TAG leave it in the bitstream + */ +#ifdef DEBUG_CCD + TRACE_CCD (globs, "Normal TAG - Decrementing bitpos by 8 to %d", globs->bitpos); +#endif + bf_setBitpos (globs->bitpos-8, globs); + } + } + } + + if (len_l) + { + if (!asn1) + { + if (globs->bitpos > tmp_maxBP) + { + ccd_recordFault (globs, ERR_ELEM_LEN, CONTINUE, (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + else + { + /* + * set the bitpos to the end of the LV or TLV element + */ + bf_setBitpos (tmp_maxBP, globs); + } + } + + /* + * set the maxBitpos to the next octet boundary if the + * last non-spare IE does not end at an octet boundary. + * This is necessary for avoiding an early end of decoding. + */ +/* + globs->maxBitpos = globs->buflen; +*/ + globs->maxBitpos = act_maxBP; + } + + return endOfComposition; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* Attention for RUN_...: static function */ +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : cdc_skipElem | ++--------------------------------------------------------------------+ + + PURPOSE : Skip an element referenced by eRef. This function + perform a decoding of this element, but not into + the target C-Structure. A dummy C-Structure is used + instead. + The complete decoding is necesary, because there is + no information about the length of this element. + B.t.w. for mandatory elements with fixed length, we can + calculate the length, for optional elements or for + variable sized arrays or bitbuffers it is impossible + without decoding the entire element. +*/ + +static void cdc_skipElem (const ULONG e_ref, const ULONG len_l, T_CCD_Globs *globs) +{ + UBYTE *ActStructAddr; + U32 ActStructOffs; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "skipping element %d", + melem[e_ref].elemRef); +#endif + + ActStructAddr = globs->pstruct; + ActStructOffs = globs->pstructOffs; + + globs->pstruct = dummy; + globs->pstructOffs = 0; + + cdc_tagged_LV_decode (e_ref, 1, len_l, globs); + + globs->pstruct = ActStructAddr; + globs->pstructOffs = ActStructOffs; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : cdc_tlv_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the T-components of T TV and TLV typed + information elements. The len determines the + length of the T component. This function returns the + index (reference) of the rigth element. If the + iei is not known in this composition (msg or submsg) + an error handling is done and NO_REF is returned. + +*/ + +SHORT cdc_tlv_decode (const ULONG c_ref, + const ULONG e_ref, + const T_TLV_SORT *tlv_inf, + T_CCD_Globs *globs) +{ + ULONG repeat, max_rep; + ULONG ie_amount, l, len_l, len_t, t; + BOOL is_variable, nonTagged, limitSearch=FALSE; + UBYTE CR=FALSE; + SHORT IdxOffset = 0; + int ieTableIdx; + BOOL asn1, non_std_tag; + SHORT ret; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + /* .../src/linux/include/asm/current.h defines a macro 'current' */ + T_UNKNOWN_TAG *first, *currentTag; + + + /* + * Set the flag for the type of extension which is to expect + * at the end of the message. + */ + globs->SeekTLVExt = TRUE; + + /* Set ref number for calcidx table. */ + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * if this element is conditional, check the condition + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + len_t = 8; + switch (melem[e_ref].codingType) + { + case CCDTYPE_GSM1_ASN: + asn1 = TRUE; + non_std_tag = FALSE; + len_l = 8; + break; + + case CCDTYPE_GSM5_TV: + case CCDTYPE_GSM5_TLV: + non_std_tag = TRUE; + asn1 = FALSE; + len_l = 8; + break; + + case CCDTYPE_GSM6_TLV: + non_std_tag = FALSE; + asn1 = FALSE; + len_l = 16; + break; + + case CCDTYPE_GSM7_LV: + non_std_tag = FALSE; + asn1 = FALSE; + len_l = 7; + break; + + default: + asn1 = FALSE; + non_std_tag = FALSE; + len_l = 8; + break; + } + + /* + * if this element have a defined Prolog + * we have to process it before decoding the bitstream + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + if (tlv_inf->gotTag) + { + /* + * tagged element + */ + len_t = 8; + /* + * initialize the iei_table for each new message + */ + if (globs->ccd_recurs_level NEQ globs->last_level) + { + cdc_init_table (c_ref, globs); + globs->TagPending = FALSE; + globs->SequenceError = FALSE; + globs->last_level = globs->ccd_recurs_level; + } + + /* + * calculate the index into the ieTable for this element + */ + ieTableIdx = (int)(e_ref - globs->iei_ctx[globs->ccd_recurs_level].melemStart); + + if (globs->TagPending) + { + /* + * if we previously read a t value and does not processed it + * get this pending tag. + */ + t = (ULONG) globs->PendingTag; + globs->TagPending = FALSE; + } + else + { + /* + * read the information element identifier out of the bitstream. + * If the first bit (MSBit) of the t-component is set, it is + * a Tag of a TYPE1 or TYPE2 element. + */ + + t = (ULONG) bf_decodeByteNumber (8, globs); + + + + if (!asn1 AND !non_std_tag AND (t & 0x80) EQ 0x80 AND (t & 0xA0) NEQ 0xA0) + { + ULONG Tag4 = t & 0xf0; + /* + * MSBit is set. We have to check if the Tag value can + * be found as a 4 bit or 8 bit value in the IEI-table. + */ + if (cdc_search_table (ieTableIdx, Tag4, limitSearch, &nonTagged, globs) NEQ -127) + { + /* + * Tag found as a 4 bit value. Decrement the readpointer + * of the bitstream by 4, because we have read out 4 bits + * to much. + */ + bf_setBitpos (globs->bitpos-4, globs); + t = Tag4; + len_t =4; +#ifdef DEBUG_CCD + TRACE_CCD (globs, "4 bit Tag decrementing bitpos by 4 to %d", globs->bitpos); +#endif + } + } + } + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "reading t = 0x%X", t); +#endif + + if (melem[e_ref].codingType EQ CCDTYPE_GSM5_TLV) + { + limitSearch = TRUE; + CR = (UBYTE) (((t & 0x80) EQ 0x80) ? TRUE : FALSE); + t &= 0x7f; + } + + + if (asn1 AND t EQ 0x00) + { + /* + * This is for ASN1 element coding the special + * End Of Component Tag (EOC). The following length must be zero. + */ + bf_setBitpos (globs->bitpos-8, globs); + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "ASN1 End of Component found belongs to higher TLV"); + TRACE_CCD (globs, "leaving this level and decrementing bitpos by 8 to %d", globs->bitpos); +#endif + + return END_OF_COMPOSITION; /* skip the remaining elements in this level */ + } /* asn1 and EOC */ + else + { + if ((IdxOffset = (SHORT) cdc_search_table (ieTableIdx, t, limitSearch, &nonTagged, globs)) == -127) + { + /* + * t (iei) not defined in this composition (msg or submsg) + */ + if (asn1) + { + if (melem[mcomp[c_ref].componentRef + mcomp[c_ref].numOfComponents -1].codingType == CCDTYPE_GSM5_V) + { + /* Restore the old bitposition (before the 'TAG') and return + * IdxOffset to jump to last element of the composition. + * The coding type of this elements is CCDTYPE_GSM5_V + */ + bf_setBitpos (globs->bitpos-8, globs); + IdxOffset = (SHORT)(mcomp[c_ref].numOfComponents - ieTableIdx - 1); + return (IdxOffset); + } + + /* + * for recursive ASN.1 structs it is possible that the foreign + * tag belongs to a upper level composition of element. + * + * + * Restore the old bitposition (before the TAG) and return + * END_OF_COMPOSITION to leave this composition level + */ + bf_setBitpos (globs->bitpos-8, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "Unknown Tag. It may belong to upper ASN.1 comp -> dec. bitpos by 8 to %d", globs->bitpos); +#endif + + return END_OF_COMPOSITION; /* skip the remaining elements in this level */ + } + else if (nonTagged) + { + U16 actBitpos; + actBitpos = globs->bitpos-8; + + if (melem[mcomp[c_ref].componentRef + mcomp[c_ref].numOfComponents -1].codingType == CCDTYPE_GSM5_V && + melem[e_ref].codingType EQ CCDTYPE_GSM5_TLV) + { +#if defined (CCD_TEST) + currentTag = (T_UNKNOWN_TAG *) malloc(sizeof(T_UNKNOWN_TAG)); +#else + currentTag = (T_UNKNOWN_TAG *) D_ALLOC(sizeof(T_UNKNOWN_TAG)); +#endif + first = currentTag; + currentTag->bitpos = globs->bitpos-8; + currentTag->errCode = ERR_NO_MORE_ERROR; + currentTag->next = NULL; + + /* unknown GSM Type TLV -> skip 'l' bytes */ + /* at least 8 bits must remain for following expeceted tagged element */ + while (globs->maxBitpos - 8 - globs->bitpos >= 8) + { + currentTag->bitpos = globs->bitpos-8; + currentTag->tag = (UBYTE) t; + + /* + * Expecting a CCDTYPE_GSM5_TLV type we get an unknown tag with MSB set. + * Store bitpos and t for the application (SAT) for the handling of + * comprehension required elements. + */ + + if (CR) + { // save (ERR_COMPREH_REQUIRED; globs->bitpos-len_t) + currentTag->errCode = ERR_COMPREH_REQUIRED; + } + else + { // save (ERR_IE_NOT_EXPECTED; globs->bitpos-len_t) + currentTag->errCode = ERR_IE_NOT_EXPECTED; + } + + l = (ULONG) bf_decodeByteNumber (8, globs); + bf_incBitpos ((l << 3) , globs); + + t = (ULONG) bf_decodeByteNumber (8, globs); + + limitSearch = TRUE; + CR = (UBYTE) (((t & 0x80) EQ 0x80) ? TRUE : FALSE); + t &= 0x7f; + + if (cdc_search_table (ieTableIdx, t, limitSearch, &nonTagged, globs) != -127) + { + bf_setBitpos (globs->bitpos-8, globs); + // set all ccd Errors + do + { + currentTag = first; + ccd_setError (globs, currentTag->errCode, + CONTINUE, + (USHORT) currentTag->tag, + currentTag->bitpos, + (USHORT) -1); + first = currentTag->next; +#if defined (CCD_TEST) + free(currentTag); +#else + D_FREE(currentTag); +#endif + } + while (first != NULL ); + + return 0; + } + else + { +#if defined (CCD_TEST) + currentTag->next = (T_UNKNOWN_TAG *) malloc(sizeof(T_UNKNOWN_TAG)); +#else + currentTag->next = (T_UNKNOWN_TAG *) D_ALLOC(sizeof(T_UNKNOWN_TAG)); +#endif + currentTag = currentTag->next; + currentTag->next = NULL; + } + } + + do + { + currentTag = first; + first = currentTag->next; +#if defined (CCD_TEST) + free(currentTag); +#else + D_FREE(currentTag); +#endif + } + while (first != NULL ); + } + + /* + * a non tagged element is possible in the message. If the tag + * can not be found, the tag may be the beginning of the non tagged + * element. E.g. rest octetts in sysinfo 4 + * + * Restore the old bitposition (before the TAG) and return 1 to + * go to the next element. + */ + + bf_setBitpos (actBitpos, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "Unknown Tag but mand. IE possible -> dec. bitpos by 8 to %d", globs->bitpos); +#endif + + return 1; + } + + + /* + * Otherwise look if it is a type 1,2 or 4 Element + */ + if ((t & 0x80) EQ 0x80) + { + /* MSBit set -> GSM Type 1 or Type2 -> skip 1 byte */ + /* position already incremented by decoding the TAG value */ + } + /* Just another reason for getting IdxOffset equal to 0. */ + else if (globs->ccd_recurs_level >= MAX_RECURSIONS_PER_MSG) + { + ccd_setError (globs, ERR_INTERNAL_ERROR, BREAK, (USHORT) -1); + } + else + { + /* + * Expecting a CCDTYPE_GSM5_TLV type we get an unknown tag with MSB set. + * Store bitpos and t for the application (SAT) for the handling of + * comprehension required elements. + */ + if (CR) + { + ccd_setError (globs, ERR_COMPREH_REQUIRED, + CONTINUE, + (USHORT) t, + (USHORT) globs->bitpos-len_t, + (USHORT) -1); + } + /* + * Expecting other types than CCDTYPE_GSM5_TLV we get an unknown tag with + * comprehension required bits (5, 6, 7 and 8 of IEI according to GSM0407) + * are set to zero. + * Store bitpos and t for the application for the handling of comprehension + * required elements. + */ + else if ((t & 0x70) EQ 0 AND + melem[e_ref].codingType NEQ CCDTYPE_GSM5_TLV) + { + ccd_setError (globs, ERR_COMPREH_REQUIRED, + CONTINUE, + (USHORT) t, + (USHORT) globs->bitpos-len_t, + (USHORT) -1); + } + /* + * We get an unknown tag and any sort of comprehension required flag is set. + * Store bitpos and t for the application + */ + else + { + ccd_setError (globs, ERR_IE_NOT_EXPECTED, + CONTINUE, + (USHORT) t, + (USHORT) globs->bitpos-len_t, + (USHORT) -1); + } + + /* MSBit cleared -> GSM Type TLV -> skip 'l' bytes */ + if (globs->maxBitpos - globs->bitpos >= 8) + { + l = (ULONG) bf_decodeByteNumber (8, globs); + bf_incBitpos ((l << 3) , globs); + } + else + { + ccd_recordFault (globs, + ERR_ELEM_LEN, + BREAK, + (USHORT) e_ref, + globs->pstruct + globs->pstructOffs); + } + } + + /* + * return 0 -> that means try it again with this actual element + * referenced by e_ref + */ + return 0; + } /* tag not found */ + else + { + T_IEI_TABLE *iei_tbl = &globs->iei_ctx[globs->ccd_recurs_level].iei_table[ieTableIdx]; + /* + * element definition for this iei found + */ + if (IdxOffset NEQ 0) + { + /* + * found index differs from the actual index + */ + globs->TagPending = TRUE; + globs->PendingTag = (UBYTE) t; + + if (!asn1 AND IdxOffset < 0) + { + /* + * found an element in wrong sequence + * (for ASN1 elements the sequence order is not relevant) + */ + ccd_setError (globs, ERR_IE_SEQUENCE, + (UBYTE) ((asn1) ? BREAK : CONTINUE), + (USHORT) t, + (USHORT) globs->bitpos-len_t, + (USHORT) -1); + + globs->SequenceError = TRUE; + } + if (globs->SequenceError) + { + globs->RefBeforeError = (USHORT) e_ref; + } + if (asn1) + { + globs->iei_ctx[globs->ccd_recurs_level].countSkipped += IdxOffset; + } + /* + * skip to the found element + */ + return (IdxOffset); + } + else + { + globs->iei_ctx[globs->ccd_recurs_level].melemLast = (USHORT) e_ref; + + if (iei_tbl->act_amount == 0) + { + /* + * first apearance of this iei + * calculate the upper and lower boundaries and the + * facility of multiple appearance of this tagged element + * in the bitstream. + */ + + /* + * The element is repeatable. There are three kinds of + * repeat definitions valid for standard elements: + * [5] - The element is repeated 5 times. + * [0..5] - The element is repeated 0 to 5 times. + * [a..5] - The element is repeated "the value of a" times. + * + * For tagged elements the following processing is defined: + * + * [5] - The t-Component is decoded + * (maybe the l-Component too (if defined one). + * After this the V-component of the element + * is decoded 5 times. + * + * [0..5] - The t- and maybe the l-Component are decoded. + * After this one V-Component is decoded and it + * is stored as an array entry into + * the target C-Structure. In this case the + * parameter ieIndex gives the index into + * this array, where the element has to + * be written into. + * + * [a..5] - The t- and maybe the l-Component are decoded. + * After this one V-Component is decoded + * "a" times and is stored into the C-Structure + * as an array. + * + */ + switch (melem[e_ref+IdxOffset].repType) + { + case 'i': + /* + * multiapearance of this element. The V-component is + * repeated once + */ + is_variable = ccd_calculateRep (e_ref+IdxOffset, + &repeat, + &max_rep, + globs); + + iei_tbl->max_amount = (UBYTE) max_rep; + iei_tbl->multiple = TRUE; + break; + + case 'v': + case 'b': + default: + /* + * if this element is repeatable, and the number of + * repeats depends on another element, the valid amount + * of this element is 1 and the V-component will be + * repeated. + */ + iei_tbl->max_amount = 1; + iei_tbl->multiple = FALSE; + break; + } + iei_tbl->act_amount = 1; + } + + if (iei_tbl->act_amount <= iei_tbl->max_amount) + { + /* + * process only the max_amount appearances of each element. + * All additional IEs are ignored. + */ + ie_amount = (ULONG)(iei_tbl->act_amount)++; + } + else + { + if (asn1) + { + /* For ASN1 elements the sequence order is not relevant. + * It is possible that the tag belongs to an upper level + * composition of elements. + * Restore the old bitposition (before the TAG) and return + * END_OF_COMPOSITION to leave this composition level + */ + bf_setBitpos (globs->bitpos-8, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "Tag may belong to upper ASN.1 comp -> dec. bitpos by 8 to %d", globs->bitpos); +#endif + + return END_OF_COMPOSITION; /* skip the remaining elements in this level */ + } + else + { + ie_amount = 0; + ccd_setError (globs, ERR_MAX_IE_EXCEED, + CONTINUE, + (USHORT) t, + (USHORT) globs->bitpos-len_t, + (USHORT) -1); + } + } + + /* + * The t-component matches with the defined identifier for + * the actual element definition (e_ref). + */ + + if (globs->SequenceError) + { + globs->SequenceError = FALSE; + + if (asn1) + { + /* For ASN1 elements the sequence order is not relevant. + * It is possible that the tag belongs to an upper level + * composition of elements. + * Restore the old bitposition (before the TAG) and return + * END_OF_COMPOSITION to leave this composition level + */ + bf_setBitpos (globs->bitpos-8, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "Tag may belong to upper ASN.1 comp -> dec. bitpos by 8 to %d", globs->bitpos); +#endif + + return END_OF_COMPOSITION; /* skip the remaining elements in this level */ + } + else + { + /* found an element in wrong sequence */ + + cdc_skipElem (e_ref, (tlv_inf->gotLen ? len_l:0), globs); + return (SHORT)(globs->RefBeforeError - e_ref); + } + } + + /* + * if this element is conditional, check the condition + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + { + /* + * if the condition for this element is not valid + * but this element appears in the message, generate + * an error and skip the element + */ + ccd_setError (globs, ERR_IE_NOT_EXPECTED, + CONTINUE, + (USHORT) t, + (USHORT) globs->bitpos-len_t, + (USHORT) -1); + + cdc_skipElem (e_ref, (tlv_inf->gotLen ? len_l:0), globs); + + return 0; + } + + /* + * check for a valid index + */ + if (ie_amount EQ 0) + { + /* + * The max number of repeats are reached + * In this case we must skip this element. + */ + cdc_skipElem (e_ref, (tlv_inf->gotLen ? len_l:0), globs); + + return 0; + } + + + if (iei_tbl->multiple) + { + if (melem[e_ref].elemType NEQ 'S') + { + /* + * Element is not a SPARE + * Setup the offset into the C-structure for this element + */ + globs->pstructOffs = melem[e_ref].structOffs; + } + ret = cdc_tagged_LV_decode (e_ref, ie_amount, + (tlv_inf->gotLen ? len_l:0), globs); + } + else + { + if (melem[e_ref].elemType NEQ 'S') + { /* + * Element is not a SPARE + * Setup the offset into the C-structure for this element + */ + globs->pstructOffs = melem[e_ref].structOffs; + } + ret = cdc_normal_LV_decode (e_ref, + (tlv_inf->gotLen ? len_l:0), globs); + } + globs->SeekTLVExt = TRUE; + iei_tbl->exhausted = TRUE; + + if (ret) + return END_OF_COMPOSITION; + + /* + * if more then one IE of this type are allowed, a ret of 0 + * indicates the calling function (ccd_decodeComposition()) + * to leave the pointer to the actual element definition on + * this element. If the value of ret is greater then 0 the + * calling function will increment the pointer by the value + * of ret. + * cdc_T_decode() has found the expected element definition. + * Go to the next definition or stay at this definition, + * if the occurance of this element is more than one. + */ + if (iei_tbl->act_amount > iei_tbl->max_amount) + { + iei_tbl->act_amount = 0; + } + if (iei_tbl->max_amount > 1) + { + return (0); + } + else + { + if (globs->iei_ctx[globs->ccd_recurs_level].countSkipped) + { + ret = (-1) * (globs->iei_ctx[globs->ccd_recurs_level].countSkipped); + (globs->iei_ctx[globs->ccd_recurs_level].countSkipped) = 0; + return (ret); + } + else + { + return (1); + } + } + } /* IdxOffset == 0 */ + } /* tag found */ + } /* no asn1, no EOC */ + } /* got tag */ + else + { + /* + * element has no t-component, process the l- and V-components + */ + if (melem[e_ref].elemType NEQ 'S') + { /* + * Element is not a SPARE + * Setup the offset into the C-structure for this element + */ + globs->pstructOffs = melem[e_ref].structOffs; + } + ret = cdc_normal_LV_decode (e_ref, len_l, globs) ? END_OF_COMPOSITION : 1; + globs->SeekTLVExt = TRUE; + return ret; + } +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : cdc_tlv_encode | ++--------------------------------------------------------------------+ + + PURPOSE : if T_len > 0 this function encodes the T-Component of + this element. If L_len > 0 it encodes the number + of bytes uses for this element. After all the function + encodes the V-component referenced by eRef from the + C-Structure (globs->pstruct) at position globs->pstructOffs + into the bitstream. + +*/ + +void cdc_tlv_encode (const ULONG e_ref, + UBYTE lenT, + UBYTE lenL, + T_CCD_Globs *globs) +{ + ULONG posL=0, t_repeat, v_repeat, repeat; + ULONG cSize, startOffset=0; + BOOL multAppear; + U8 *old_pstruct = NULL; + ULONG i; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * If this element is conditional, check the condition. + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return; + + /* + * If this element have a defined Prolog, + * we have to process it before decoding the bit stream. + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + if (melem[e_ref].elemType NEQ 'S') + { + /* + * Element is not a SPARE. + * Setup the offset into the C-structure for this element. + * In case of pointer types, the pstructOffs must be + * the offset into the memory area pointed to. CCDGEN must + * ensure this holds true. + */ + globs->pstructOffs = melem[e_ref].structOffs; + + if ( ! cdc_isPresent(e_ref, globs) ) + return; + + if (melem[e_ref].repType EQ 'v' OR melem[e_ref].repType EQ 'i') + { + /* + * for variable sized elements read the amount + * of repeats out of the C-Structure (c_xxx). + * If the number of repeats given by the C-Structure + * exceeds the allowed value (maxRepeat) CCD gives a warning! + */ + if (melem[e_ref].maxRepeat > 255) + { + ULONG count = (ULONG) (* (USHORT *)(globs->pstruct + globs->pstructOffs++)); + repeat = MINIMUM (count, (ULONG) melem[e_ref].maxRepeat); + if (repeat < count) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + else + { + repeat = (ULONG) MINIMUM (globs->pstruct[globs->pstructOffs], + melem[e_ref].maxRepeat); + if ( repeat < (ULONG) (globs->pstruct[globs->pstructOffs]) ) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, (USHORT) e_ref, + globs->pstruct + globs->pstructOffs); + } + + globs->pstructOffs++; + + multAppear = (melem[e_ref].repType EQ 'i'); + } + else + { + /* + * Field of constant length: repType EQ 'c' + * or bit-field allocated with + * given maximum length: repType EQ 'b' (often cType='X') + */ + repeat = (ULONG)((melem[e_ref].repType EQ 'c' + OR melem[e_ref].repType EQ 'b') + ? melem[e_ref].maxRepeat + : 1 ); + multAppear = FALSE; + } + + /* + * Perform pointer dereference for pointer types. + * Also, check optionality for these types. + */ +#ifdef DYNAMIC_ARRAYS + if ((melem[e_ref].elemType >= 'P' AND melem[e_ref].elemType <= 'R') OR + (melem[e_ref].elemType >= 'D' AND melem[e_ref].elemType <= 'F')) + { + U8 *deref_pstruct; + + /* Get pointer value */ + deref_pstruct = *(U8 **)(globs->pstruct + globs->pstructOffs); + + /* + * Strictly speaking the 'D' to 'F' types should not need this + * check (should have returned after the optionality check above), + * but it will catch stray NULL pointers (or uninitialized + * valid flags) + */ + if (ccd_check_pointer(deref_pstruct) != ccdOK) + { + ccd_recordFault (globs, ERR_INVALID_PTR, BREAK, (USHORT) e_ref, + &globs->pstruct[globs->pstructOffs]); + return; + } + + /* + * Pointer not NULL; + * 1. Save old globs->pstruct and assign pointer to globs->pstruct + * as new base. + * 2. Set pstructOffs to 0 (zero) as the next offset will start + * in the new memory area. + */ + old_pstruct = globs->pstruct; + globs->pstruct = deref_pstruct; + globs->pstructOffs = 0; + } +#endif + + /* + * 20010621 MVJ: Dynamic array addition. + * Types 'R' and 'F' point to base types (just as type 'V') and + * read sizes from the same table. + */ + cSize = (ULONG)((melem[e_ref].elemType EQ 'V' +#ifdef DYNAMIC_ARRAYS + OR melem[e_ref].elemType EQ 'R' + OR melem[e_ref].elemType EQ 'F' +#endif + ) ? mvar[melem[e_ref].elemRef].cSize + : mcomp[melem[e_ref].elemRef].cSize + ); + + startOffset = globs->pstructOffs; + } + else + { + repeat = (ULONG)((melem[e_ref].repType EQ 'c') + ? melem[e_ref].maxRepeat + : 1); + + multAppear = FALSE; + + cSize = 0; + } + + if (multAppear AND lenT) + { + /* + * multiple appearance of the repeated element is coded as + * TLV0 TLV1 TLV2 .... + */ + t_repeat = repeat; + v_repeat = 1; + } + else + { + t_repeat = 1; + v_repeat = repeat; + } + + /* + * single appearance of the repeated element is coded as + * TLV0V1V2V3 .... + */ + + for (i=0; i < t_repeat; i++) + { + if (lenT) + { + /* + * encode the T-component + */ + bf_codeByteNumber (lenT, (UBYTE) melem[e_ref].ident, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "encoding %d bits T-value (%x)", lenT, melem[e_ref].ident); +#endif + } + + /* + * if lenL > 0 remember the position of the L-component, because + * we know it after encoding the entire element. for GSM5TLV elements + * it could be necessary to use 2 bytes for the length information. + */ + if (lenL) + { + posL = (ULONG) globs->bitpos; + bf_incBitpos (lenL, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "skipping %d bits for L-value at byte %d.%d", lenL, globs->bytepos, globs->byteoffs); +#endif + } + + if (cSize) + { + /* + * calculate the offset if it is not a spare + */ + globs->pstructOffs = (ULONG)(startOffset + (i * cSize)); + } + + /* + * Encode the value. Keep caution with BER encoding of ASN1 integers. + * All other types can be encoded by a generic function. + */ + if (melem[e_ref].codingType EQ CCDTYPE_GSM1_ASN + AND + melem[e_ref].elemType EQ 'V' + AND melem[e_ref].repType EQ ' ' + ) + { +#ifdef DEBUG_CCD +#ifdef CCD_SYMBOLS + TRACE_CCD (globs, "BER encoding of ASN.1 integer %s", + ccddata_get_alias((USHORT) e_ref, 1)); +#else + TRACE_CCD (globs, "BER encoding of ASN.1 integer; e_ref= %d", melem[e_ref].elemRef); +#endif +#endif + + switch (mvar[melem[e_ref].elemRef].cType) + { + case 'B': bf_writeBits (8, globs); + break; + case 'S': + { + if (*(U16 *) (globs->pstruct+globs->pstructOffs) <= (U16)0xFF) + bf_writeBits (8, globs); + else + bf_writeBits (16, globs); + } + break; + case 'L': + { + U32 tmpVal= *(U32 *) (globs->pstruct+globs->pstructOffs); + + if ( tmpVal <= (U32)0xFF) + bf_writeBits (8, globs); + else if ( tmpVal <= (U32)0xFFFF) + bf_writeBits (16, globs); + else if ( tmpVal <= (U32)0xFFFFFF) + bf_writeBits (24, globs); + else + bf_writeBits (32, globs); + } + break; + case 'X': + { + U16 ValLen= *(U16 *) (globs->pstruct+globs->pstructOffs); + + if ( mvar[melem[e_ref].elemRef].bSize >= ValLen) + bf_writeBitChunk (ValLen, globs); + else + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "value length (%d) exceeds defined bSize!", ValLen); +#endif + } + + } + break; + } + } + else + { + cdc_encodeElemvalue (e_ref, v_repeat, globs); + } + + /* + * calculate the bitlen if it is an TLV element and write the + * L-value. + */ + + if (lenL) + { + switch (melem[e_ref].codingType) + { + case CCDTYPE_GSM5_TLV: + { + USHORT L = (((USHORT)((globs->bitpos - posL)-lenL)+7) >> 3); + + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "recoding the 8 bit L-value (%d)", L); +#endif + + if (L > 127) + { + /* + * if the length is > 127 we code the first byte to + * 0x81, shift the whole stuff rightwise by 8 and + * encode the length in the next byte (16 bits for L) + */ + bf_rShift8Bit ((USHORT) (posL+8), (USHORT) (L<<3), globs); + bf_incBitpos (8, globs); + bf_recodeByteNumber ((USHORT) posL, lenL, (UBYTE) 0x81, globs); + bf_recodeByteNumber ((USHORT) (posL+8), lenL, (UBYTE) L, globs); + /* + * set the bitpos to a 8 bit aligned position + * corresponding the L value + */ + bf_setBitpos (posL+(L*8)+16, globs); + } + else + { + bf_recodeByteNumber ((USHORT) posL, lenL, (UBYTE) L, globs); + /* + * set the bitpos to a 8 bit aligned position + * corresponding the L value + */ + bf_setBitpos (posL+(L*8)+8, globs); + } + break; + } + + case CCDTYPE_GSM6_TLV: + { + USHORT L = ((USHORT)(((globs->bitpos - posL)-lenL)+7) >> 3); + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "recoding the 16 bit L-value (%d)", L); +#endif + bf_recodeShortNumber ((USHORT)posL, lenL, L, globs); + /* + * set the bitpos to a 8 bit aligned position + * corresponding the L value + */ + bf_setBitpos (posL+(L*8)+16, globs); + break; + } + + case CCDTYPE_GSM7_LV: + { + USHORT L = (USHORT) ((globs->bitpos - posL)-lenL); + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "recoding the 7 bit L-value (bitlength) (%d)", L); +#endif + bf_recodeShortNumber ((USHORT)posL, lenL, L, globs); + + bf_setBitpos (posL+L+7, globs); + break; + } + + default: + { + USHORT L = ((USHORT)(((globs->bitpos - posL)-lenL)+7) >> 3); + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "recoding the 8 bit L-value (%d)", L); +#endif + bf_recodeByteNumber ((USHORT)posL, lenL, (UBYTE) L, globs); + /* + * Set the bitpos to a 8 bit aligned position + * corresponding the L value + */ + bf_setBitpos (posL+(L*8)+8, globs); + break; + } + } + } + } + + /* + * Restore globs->pstruct if overwritten by pointer dereference. + */ + if (old_pstruct) + globs->pstruct = old_pstruct; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : cdc_GSM_start | ++--------------------------------------------------------------------+ + + PURPOSE : Initialize the GSM specific codec part for each msg. + +*/ + +void cdc_GSM_start (T_CCD_Globs *globs) +{ + globs->Swap1V_inProgress = FALSE; + globs->last_level = 255; + cdc_init_ctx_table (globs); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : cdc_isPresent | ++--------------------------------------------------------------------+ + + PURPOSE : For optional elements check the valid-flag in the C-struct. + Spare elements in PER do not have a corresponding valid flag. + In case of Dynamic Arrays: + Postpone optional check for non-code transparent pointer + types ('P', 'Q', 'R'). + For these types, the optional flag is the pointer itself. + These types cannot be checked yet, as the pointer may be + preceeded by a counter octet, a union tag id octet etc. +*/ +U16 cdc_isPresent (const ULONG e_ref, T_CCD_Globs *globs) +{ + if (melem[e_ref].optional) + { +#ifdef DYNAMIC_ARRAYS + if (melem[e_ref].elemType < 'P' OR melem[e_ref].elemType > 'R') + { + if(globs->pstruct[globs->pstructOffs++] == FALSE) + return FALSE; +#ifdef DEBUG_CCD + else if (globs->pstruct [melem[e_ref].structOffs] != TRUE) + { + TRACE_CCD (globs, "Ambiguous value for valid flag!\n...assumed 1 for ccdID=%d", + e_ref); + } +#endif + } + else + { /*If elemType is P, Q or R - check the pointer value*/ + if(*(void**) &globs->pstruct[globs->pstructOffs] == NULL) + return FALSE; + } +#else + if (globs->pstruct[globs->pstructOffs++] == FALSE) + return FALSE; +#ifdef DEBUG_CCD + else if (globs->pstruct [melem[e_ref].structOffs] != TRUE) + { + TRACE_CCD (globs, "Ambiguous value for valid flag!\n...assumed 1 for ccdID=%d", + e_ref); + } +#endif +#endif + } + return TRUE; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : is_pointer_type | ++--------------------------------------------------------------------+ + + PURPOSE : Return TRUE for pointer elements. + +*/ +BOOL is_pointer_type (const ULONG e_ref) +{ + return ((melem[e_ref].elemType >= 'P' AND melem[e_ref].elemType <= 'R') OR + (melem[e_ref].elemType >= 'D' AND melem[e_ref].elemType <= 'F')); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : is_variable_type | ++--------------------------------------------------------------------+ + + PURPOSE : Return TRUE for elements with variable character. + +*/ +BOOL is_variable_type (const ULONG e_ref) +{ + return ((melem[e_ref].elemType == 'F') || ( melem[e_ref].elemType == 'R') || + (melem[e_ref].elemType == 'V')); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : PER_CommonBegin | ++--------------------------------------------------------------------+ + + PURPOSE : Common settings done by most of the encoding or decoding + functions for UNALIGNED PER (UMTS). + It handles position of pointer to the C-structure, + valid flag for optional elements and length determinant + for array of elements. +*/ +SHORT PER_CommonBegin (const ULONG e_ref, ULONG *max_rep, T_CCD_Globs *globs) +{ + /* + * Set the offset in the C-structure on the value for this element + */ + globs->pstructOffs = melem[e_ref].structOffs; + + /* For optional elements we have already set the valid flag in the + * C-structure while processing ASN1_SEQ. + */ + if ( ! cdc_isPresent(e_ref, globs) ) + return (SHORT)ccdError; + + switch (melem[e_ref].repType) + { + case ' ': + /* + * Element is not an array. + */ + *max_rep = 1; + break; + case 'c': + case 'C': + /* + * Read the size for an array of fixed length. + */ + *max_rep = (ULONG) melem[e_ref].maxRepeat; + break; + case 'j': + case 'J': + { + /* + * Read the size for an array of variable length. + * Read the value of the last encoded element. It is the length + * indicator. + * Hint 1: globs->pstruct[melem[e_ref-1].structOffs is 0, since + * fields of variable length are projected on a COMP made of an + * ASN1_INTEGER for the lenght indicator and the field elements + * (sequences, integers, octets or bits). + * Hint 2: The current version of UMTS does not use length + * indicators larger than 64K. Hence the use of USHORT for repeat. + */ + switch (mvar[melem[e_ref-1].elemRef].cType) + { + case 'B': *max_rep = (ULONG) globs->pstruct[melem[e_ref-1].structOffs]; + break; + case 'S': *max_rep = (ULONG) *(USHORT *) (globs->pstruct+melem[e_ref-1].structOffs); + break; + default: *max_rep = 0; + break; + } + break; + } + default: + ccd_recordFault (globs, ERR_DEFECT_CCDDATA, BREAK, (USHORT) e_ref, + globs->pstruct + globs->pstructOffs); + break; + } + + /* + * There is nothing to be encoded. + */ + if (*max_rep EQ 0) + { + return (SHORT)ccdError; + } + /* + * Check the validity of the lenght information. + */ + else if (melem[e_ref].maxRepeat AND *max_rep > melem[e_ref].maxRepeat) + { + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, (USHORT) e_ref, + globs->pstruct + globs->pstructOffs); + } + + return (SHORT)ccdOK; +} +#endif /* !RUN_INT_RAM */ + + +#ifdef DYNAMIC_ARRAYS +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : PER_allocmem | ++--------------------------------------------------------------------+ + + PURPOSE : Allocate memory for pointer types (dynamic array addition) + Returns address of freshly allocated memory + or ccdError in case no memory is available. +*/ +U8 *PER_allocmem(const ULONG e_ref, ULONG repeat, T_CCD_Globs *globs) +{ + /* + * Check for pointer types; allocate memory if necessary. + */ + if ( is_pointer_type(e_ref) ) { + ULONG cSize; + U8 *addr; + + /* + * Find size to allocate. + * Read from mcomp or mvar according to type. + */ + cSize = (ULONG)((melem[e_ref].elemType EQ 'V' OR + melem[e_ref].elemType EQ 'R' + OR melem[e_ref].elemType EQ 'F') + ? mvar[melem[e_ref].elemRef].cSize + : mcomp[melem[e_ref].elemRef].cSize + ); + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "PER_allocmem(): alloc%5d x%5d bytes (type '%c'); " + "elem%5d ('%s')", + repeat, cSize, melem[e_ref].elemType, e_ref, +#ifdef CCD_SYMBOLS + mcomp[melem[e_ref].elemRef].name +#else + "" +#endif + ); +#endif + /* + * Allocate additional memory - append to existing mem chain + */ + + cSize *= repeat; + addr = (U8 *)DP_ALLOC( cSize, globs->alloc_head, DP_NO_FRAME_GUESS); + + /* If no memory, log error and return immediately */ + if (addr EQ NULL) { + ccd_setError (globs, ERR_NO_MEM, + BREAK, + (USHORT) -1); + return (U8 *)ccdError; + } + else + memset (addr, 0, (size_t)cSize); + return addr; + } + return (U8 *)ccdError; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : PER_allocmem_and_update| ++--------------------------------------------------------------------+ + + PURPOSE : Allocate memory for pointer types (dynamic array addition) + Updates global variables after allocation + (globs->pstruct and globs->pstructOffs). + Assumes that these global variables are saved by the + calling function. + Returns ccdOK or ccdError in case no memory is available. +*/ +USHORT PER_allocmem_and_update(const ULONG e_ref, ULONG repeat, T_CCD_Globs *globs) +{ + U8 *addr; + + /* Allocate memory */ + addr = PER_allocmem(e_ref, repeat, globs); + + /* No memory ? */ + if ( addr != (U8 *)ccdError ) { + /* + * Memory allocated; + * 1. Store pointer to freshly allocated memory area in structure + * 2. Initialize pstruct to point to the freshly allocated memory area. + * 3. Initialize pstructOffs to 0 to start decoding at offset 0 + * in the new memory area. + * Assumes that globs->pstruct is saved in the calling function. + */ + *(U8 **)(globs->pstruct + globs->pstructOffs) = addr; + globs->pstruct = addr; + globs->pstructOffs = 0; + return ccdOK; + } else { + /* No memory - Return error */ + return ccdError; + } +} +#endif /* !RUN_INT_RAM */ +#endif + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : Read_NormallySmallNonNegativeWholeNr| ++--------------------------------------------------------------------+ + + PURPOSE : Read a normally small non-negative whole number as defined + by ASN.1 PER. Function is used to read elements such as: + a) bit-map field of SEQUENCE extensions, + b) index of CHOICE extension or + c) extension value of extensible INTEGER or ENUMERATED. +*/ +U32 Read_NormallySmallNonNegativeWholeNr (T_CCD_Globs *globs) +{ + U32 value_length=0; + + /* Read the first bit. If set to 0 it means the value is encoded + * in the following five bits. Else read a normally small ...nr. + */ + if (bf_readBit (globs) EQ 0) + { + return ((U32) bf_getBits (6, globs)); + } + else + { + /* + * Do not handle the theoretical case that value length + * needs more than 63 bits. + */ + bf_incBitpos (1, globs); + + /* + * Read the value length first. + * Then use the length to read the value. + */ + value_length = (U32) bf_getBits (6, globs); + return ((U32) bf_getBits (value_length, globs)); + } +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : Write_NormallySmallNonNegativeWholeNr| ++--------------------------------------------------------------------+ + + PURPOSE : Write a normally small non-negative whole number as defined + by ASN.1 PER. Function is used to encode elements such as: + a) bit-map field of SEQUENCE extensions, + b) index of CHOICE extension or + c) extension value of extensible INTEGER or ENUMERATED. +*/ +void Write_NormallySmallNonNegativeWholeNr (U32 Value, T_CCD_Globs *globs) +{ + /* For small numbers write 0 in the first bit. + * Then encode that number in the succeeding five bits. + */ + if (Value < 64) + { + bf_writeBit (0, globs); + bf_writeVal (Value, 6, globs); + } + /* + * Encode the number under the assumption that its length is + * given by less than 63 bits. Hence encode also the length as a + * normally small... + */ + else + { + /* Set flag bits: + * 1 means "length determinant encoded before the value itself" + * 0 means "length determinant encoded only in five bits" + */ + bf_writeVal (2, 2, globs); + bf_writeVal (bitSize[Value], 5, globs); + + /* Encode the number itself */ + bf_writeVal (Value, bitSize[Value], globs); + } + + return; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : Read_OpenTpye_Length | ++--------------------------------------------------------------------+ + + PURPOSE : Read length of an ASN.1 open type. + Open types are normally found in encoding of + parametrized information objects and extension types. +*/ +U32 Read_OpenTpye_Length (T_CCD_Globs *globs) +{ + U32 Value; + + /* + * Flag bit is 0 for "Value < 128" which means + * "encoding fits in the current octet" + */ + if (bf_readBit (globs) EQ 0) + { + Value = bf_getBits (7, globs); + } + /* + * Flag bits are 10 for 128 "< Value < 16K". + * 1 means "encoding does not fit in the current octet". + * 0 means "encoding needs only one further octet". + */ + else if (bf_readBit (globs) EQ 0) + { + Value = bf_getBits (14, globs); + } + /* Currently no support for bigger values is required. */ + else + { + /* force error detection */ + Value = 0; + } + + return Value; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_COM | +| STATE : code ROUTINE : Write_OpenTpye_Length | ++--------------------------------------------------------------------+ + + PURPOSE : Write length of an ASN.1 open type. + Open types are normally found in encoding of + parametrized information objects and extension types. +*/ +void Write_OpenTpye_Length (U32 Value, T_CCD_Globs *globs) +{ + + if (Value < 128) + { + bf_writeVal (Value, 8, globs); + } + else if (Value < 0x8000) + { + /* Set flag bits: + * 1 means "encoding does not fit in the current octet" + * 0 means "encoding needs only one further octet" + */ + bf_writeVal (2, 2, globs); + bf_writeVal (Value, 14, globs); + } + /* Currently no support for bigger values is required. */ + else + {} + + return; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/cdc_std.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,1204 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : cdc_std.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Condat Conder Decoder +| Definitions of non protocol specific encoding and decoding +| functions ++----------------------------------------------------------------------------- +*/ + +#define CCD_STD_C + +#ifdef _MSDOS +#include <dos.h> +#include <conio.h> +#endif + +/* + * standard definitions like UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" +#include <string.h> + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h. + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Declaration of coder/decoder tables and/or functions to access them + */ +#include "ccdtable.h" +#include "ccddata.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Need memory allocation functions for dynamic arrays (pointers) + */ +#ifdef DYNAMIC_ARRAYS +#include "vsi.h" +#endif + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_decodeElemvalue | ++--------------------------------------------------------------------+ + + PURPOSE : Performs a standard decoding for a given elem table entry. + This means for non structured elements that 1-n bits are + read from the bitstream and write to a C-Variable + in a machine dependent format. For structured elements + an (indirect) recursive call to cc_decodeComposition() + is performed. If the element is a bitbuffer with variable + size, the repeat value gives the number of bits to read + from the bitstream into the buffer. The maxBitpos + indicates the maximum valid position for the + readpointer of the bitstream while decoding this element. + If the readpointer break this boundary, this element will + not be decoded. +*/ + +void cdc_decodeElemvalue (ULONG e_ref, ULONG *repeat, T_CCD_Globs *globs) +{ + UBYTE *ActStructpos; + ULONG i; + UBYTE spareLen; + + /* + * element is a bit field of variable length + */ + if ((melem[e_ref].repType == 'b') || (melem[e_ref].repType == 's')) + { + if (*repeat > (ULONG) (globs->maxBitpos-globs->bitpos)) + { + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + *repeat = MINIMUM (*repeat, (ULONG) (globs->maxBitpos-globs->bitpos)); + } + if (melem[e_ref].repType == 'b') + { + if (mvar[melem[e_ref].elemRef].cType EQ 'X') + bf_readBitChunk (*repeat, globs); + else + bf_readBits (*repeat, globs); + } + else + { + U16 finalBP = globs->bitpos + (USHORT) *repeat; + /* Store the limit. This comp may contain other comps as bitstring. */ + globs->maxBitpos = finalBP; + ActStructpos = globs->pstruct; + globs->pstruct += globs->pstructOffs; +#ifdef DEBUG_CCD +#ifdef CCD_SYMBOLS + TRACE_CCD (globs, "decoding composition %s as a bit array", + mcomp[melem[e_ref].elemRef].name); +#else + TRACE_CCD (globs, "decoding composition %d", melem[e_ref].elemRef); +#endif +#endif + + ccd_decodeComposition ((ULONG) (melem[e_ref].elemRef), globs); + if (finalBP < globs->bitpos) + { + ccd_recordFault (globs, ERR_BITSTR_COMP, CONTINUE, (USHORT) e_ref, + globs->pstruct + globs->pstructOffs); + } + bf_setBitpos (finalBP, globs); + /* Update maxBitpos to avoid an early end of decoding. */ + globs->maxBitpos = globs->buflen; + globs->pstruct = ActStructpos; + } + } + else + { + /* + * For pointer types, globs->pstruct is already set to point to + * the new memory area, and these types are not treated differently + * from non-pointer types. + */ + i=0; + switch (melem[e_ref].elemType) + { + case 'R': /* Pointer to (possible array of) basetype */ + case 'F': /* Code-transparent pointer to (possible array of) basetype */ + case 'V': + while (i < *repeat) + { + if (globs->bitpos < globs->maxBitpos) + { +#ifdef DEBUG_CCD +#ifdef CCD_SYMBOLS + TRACE_CCD (globs, "decoding var %s", + ccddata_get_alias((USHORT) e_ref, 1)); +#else + TRACE_CCD (globs, "decoding var %d", melem[e_ref].elemRef); +#endif +#endif + if (mvar[melem[e_ref].elemRef].cType EQ 'X') + bf_readBitChunk (mvar[melem[e_ref].elemRef].bSize, globs); + else + bf_readBits (mvar[melem[e_ref].elemRef].bSize, globs); + + globs->pstructOffs += mvar[melem[e_ref].elemRef].cSize; + + i++; + } + else + { + if (melem[e_ref].repType != 'i') + { + ccd_recordFault (globs, ERR_ELEM_LEN, CONTINUE, (USHORT) e_ref, + globs->pstruct + globs->pstructOffs); + } + break; + } + } + break; + + case 'D': /* Pointer to a composition */ + case 'P': /* Code transparent pointer to a comp */ + case 'C': /* Element is a composition. */ + case 'U': /* Element is a union. */ + /* + * Store the actual structure position. + */ + ActStructpos = globs->pstruct; + + globs->pstruct += globs->pstructOffs; + + while (i < *repeat) + { + if (globs->bitpos < globs->maxBitpos) + { +#ifdef DEBUG_CCD +#ifdef CCD_SYMBOLS + TRACE_CCD (globs, "decoding composition %s", + mcomp[melem[e_ref].elemRef].name); +#else + TRACE_CCD (globs, "decoding composition %d", melem[e_ref].elemRef); +#endif +#endif + /* + * recursiv call + */ + ccd_decodeComposition ((ULONG) (melem[e_ref].elemRef), globs); + globs->pstruct += mcomp[melem[e_ref].elemRef].cSize; + + i++; + } + else + { + if (melem[e_ref].repType != 'i') + { + ccd_recordFault (globs, ERR_ELEM_LEN, CONTINUE, (USHORT) e_ref, + globs->pstruct + globs->pstructOffs); + } + break; + } + } + /* + * restore the write pointer + */ + globs->pstruct = ActStructpos; + break; + + case 'S': /* Element is a spare. */ + { + spareLen = spare[melem[e_ref].elemRef].bSize; + /* + * Do not decode padding bits. They are not relevant. + * Just adjust the position pointer in the bit stream buffer. + */ + while (i < *repeat) + { + if (globs->bitpos < globs->maxBitpos) + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "decoding spare"); +#endif + bf_incBitpos (spareLen, globs); + i++; + } + else + break; + } + break; + } + } + *repeat = i; + } +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_encodeElemvalue | ++--------------------------------------------------------------------+ + + PURPOSE : Performs a standard encoding for a given elem table entry. + This means for non structured elements that 1-n bits are + read from the bitstream and write to a C-Variable + in a machine dependent format. For structured elements + an (indirect) recursive call to cc_decodeComposition() + is performed. If the element is a bitbuffer with variable + size, the repeat value gives the number of bits to write + from the buffer into the bitstream. +*/ + +void cdc_encodeElemvalue (ULONG e_ref, ULONG repeat, T_CCD_Globs *globs) +{ + UBYTE *ActStructpos = NULL; + ULONG i; + UBYTE spareLen; + + /* + * Element is a bit field of variable length. + */ + if (melem[e_ref].repType == 'b') + { + if (mvar[melem[e_ref].elemRef].cType EQ 'X') + bf_writeBitChunk (repeat, globs); + else + bf_writeBits (repeat, globs); + } + /* + * Element is a structured IE defined as bit string. + */ + else if (melem[e_ref].repType == 's') + { + U16 finalBP = (USHORT) (globs->bitpos + repeat); + ActStructpos = globs->pstruct; + globs->pstruct += globs->pstructOffs; +#ifdef DEBUG_CCD +#ifdef CCD_SYMBOLS + TRACE_CCD (globs, "encoding composition %s as a bit array", + mcomp[melem[e_ref].elemRef].name); +#else + TRACE_CCD (globs, "encoding composition %d", melem[e_ref].elemRef); +#endif +#endif + + ccd_encodeComposition ((ULONG) melem[e_ref].elemRef, globs); + if (finalBP < globs->bitpos) + { + ccd_recordFault (globs, ERR_BITSTR_COMP, CONTINUE, (USHORT) e_ref, + globs->pstruct + globs->pstructOffs); + } + bf_setBitpos (finalBP, globs); + globs->pstruct = ActStructpos; + } + else + { + /* + * For pointer types, globs->pstruct is already set to point to + * the new memory area, and these types are not treated differently + * from non-pointer types. + */ + switch(melem[e_ref].elemType) + { + case 'R': /* Pointer to (possible array of) basetype */ + case 'F': /* Code-transparent pointer to (possible array of) basetype */ + case 'V': + for (i=0; i<repeat; i++) + { + #ifdef DEBUG_CCD + #ifdef CCD_SYMBOLS + TRACE_CCD (globs, "encoding var %s", + ccddata_get_alias((USHORT) e_ref, 1)); + #else + TRACE_CCD (globs, "encoding var %s", melem[e_ref].elemRef); + #endif + #endif + if (mvar[melem[e_ref].elemRef].cType EQ 'X') + bf_writeBitChunk (mvar[melem[e_ref].elemRef].bSize, globs); + else + bf_writeBits (mvar[melem[e_ref].elemRef].bSize, globs); + + globs->pstructOffs += mvar[melem[e_ref].elemRef].cSize; + } + break; + + case 'D': /* Pointer to a composition (already dereferenced) */ + case 'P': /* Code transparent pointer to a comp (already dereferenced) */ + case 'C': /* Element is a composition. */ + case 'U': /* Element is a union. */ + /* + * store the actual structure position + */ + ActStructpos = globs->pstruct; + + globs->pstruct += globs->pstructOffs; + + for (i=0; i<repeat; i++) + { + #ifdef DEBUG_CCD + #ifdef CCD_SYMBOLS + TRACE_CCD (globs, "encoding composition %s", + mcomp[melem[e_ref].elemRef].name); + #else + TRACE_CCD (globs, "encoding composition %d", melem[e_ref].elemRef); + #endif + #endif + ccd_encodeComposition ((ULONG) melem[e_ref].elemRef, globs); /* recursiv call */ + globs->pstruct += mcomp[melem[e_ref].elemRef].cSize; + } + /* + * restore the write pointer + */ + globs->pstruct = ActStructpos; + break; + + case 'S': /* element is a spare */ + { + spareLen = spare[melem[e_ref].elemRef].bSize; + + /* + * encode the spare + */ + for (i=0; i < repeat; i++) + { + #ifdef DEBUG_CCD + TRACE_CCD (globs, "encoding spare"); + #endif + bf_codeLongNumber (spareLen, spare[melem[e_ref].elemRef].value, globs); + } + break; + } + } + } +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_STD_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Performs a standard decoding for a given elem table entry. + This means for non structured elements that 1-n bits are + read from the bitstream and write to a C-Variable + in a machine dependent format. For structured elements + an (indirect) recursive call to cc_decodeComposition() + is performed. + The element may be conditional and/or repeatable. +*/ + +SHORT cdc_std_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat, amount, act_offset; + BOOL is_variable; + U8 *old_pstruct = NULL; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_std_decode()"); + #else + TRACE_CCD (globs, "cdc_std_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * if this element is conditional, check the condition + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + /* + * if this element has a defined prologue + * we have to process it before decoding the bitstream + * If there are some epilogue expressions to be processed for this element + * (rare cases) the result here will be a reading of 0 to an internal + * register. The valid processing of expression takes place after the + * decoding of the element. + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + /* + * if this element is repeatable, and the number of + * repeats depends on another element, calculate the repeater + */ + if (melem[e_ref].repType NEQ ' ') + { + is_variable = ccd_calculateRep (e_ref, &repeat, &act_offset, globs); + } + else + { + repeat = 1; + is_variable = FALSE; + } + + if (melem[e_ref].elemType NEQ 'S') + { + /* + * Element is not a SPARE. + * Setup the offset into the C-structure for this element + */ + globs->pstructOffs = melem[e_ref].structOffs; + + if (melem[e_ref].optional) + { + /* 20010621 MVJ: Dynamic array addition. + * Postpone optional flag setting for non-code transparent + * pointer types ('P', 'Q', 'R'). + * For these types, the optional flag is the pointer itself. + * These types cannot be set yet, as the pointer may be + * preceeded by a counter octet, a union tag id octet etc. + */ + if (melem[e_ref].elemType < 'P' OR melem[e_ref].elemType > 'R') + globs->pstruct[globs->pstructOffs++] = (UBYTE) TRUE; + } + + if (is_variable) + { + /* + * for variable sized elements store the min-value + * as counter into the C-Structure (c_xxx). + */ + if (act_offset > 65535) + *(ULONG *) (globs->pstruct + globs->pstructOffs++) = repeat; + else if (act_offset > 255) + *(USHORT *) (globs->pstruct + globs->pstructOffs++) = (USHORT) repeat; + else + globs->pstruct[globs->pstructOffs] = (UBYTE) repeat; + + globs->pstructOffs++; + } + } + #ifdef DYNAMIC_ARRAYS + /* + * MVJ: Dynamic array addition. + * Check for pointer types; allocate memory if necessary. + */ + if ( is_pointer_type(e_ref) ) { + U32 cSize; + U8 *addr; + + /* + * Find size to allocate; + * - Read from mcomp or mvar according to type + */ + cSize = (ULONG)((melem[e_ref].elemType EQ 'V' OR + melem[e_ref].elemType EQ 'R') + ? mvar[melem[e_ref].elemRef].cSize + : mcomp[melem[e_ref].elemRef].cSize + ) * repeat; + + /* + * Allocate additional memory + */ + addr = (U8 *)DP_ALLOC( cSize, globs->alloc_head, DP_NO_FRAME_GUESS); + + /* If no memory, log error and return immediately */ + if (addr EQ NULL) { + ccd_setError (globs, ERR_NO_MEM, + BREAK, + (USHORT) -1); + return 1; + } + else + memset (addr, 0, (size_t)cSize); + + /* + * Memory allocated; + * 1. Save old "globs->pstruct" variables + * 2. Store pointer to freshly allocated memory area in structure + * 3. Initialize pstruct to point to the freshly allocated memory area. + * 4. Initialize pstructOffs to 0 to start decoding at offset 0 + * in the new memory area. + */ + old_pstruct = globs->pstruct; + *(U8 **)(globs->pstruct + globs->pstructOffs) = addr; + globs->pstruct = addr; + globs->pstructOffs = 0; + } +#endif + + amount = repeat; + + cdc_decodeElemvalue (e_ref, &amount, globs); + + /* + * process the epilogue expression for this element if there is any + */ + if (num_prolog_steps) + { + if ( (calc[prolog_step_ref+1].operation EQ 'K') + || (calc[prolog_step_ref+1].operation EQ 'C') + || (calc[prolog_step_ref+1].operation EQ 's')) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + } + +#ifdef DYNAMIC_ARRAYS + /* + * Restore globs->pstruct for possible use below + */ + if (old_pstruct NEQ NULL) + { + globs->pstruct = old_pstruct; + } +#endif + if (amount NEQ repeat AND is_variable) + { + /* + * if the decoded elements are not equal the specified + * repeat value, because the bitstream or the IE ended, + * store the new c_xxx value. + */ + globs->pstructOffs = melem[e_ref].structOffs; + + if (melem[e_ref].optional) + globs->pstructOffs++; + + if (act_offset > 65535) + *(ULONG *) (globs->pstruct + globs->pstructOffs) = amount; + else if (act_offset > 255) + *(USHORT *) (globs->pstruct + globs->pstructOffs) = (USHORT) amount; + else + globs->pstruct[globs->pstructOffs] = (UBYTE) amount; + + if (melem[e_ref].repType NEQ 'i') + { + /* + * if this element is not of the repeat style 'interval' + * ([X..Y] where X and Y are constants) we have to generate + * an ccd error because some outstanding repeats are missing. + */ + ccd_setError (globs, ERR_MAND_ELEM_MISS, CONTINUE, (USHORT) -1); + } + } + + return 1; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_std_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Performs a standard encoding for a given elem table entry. + This means for non structured elements that m bytes read + from the C-Variable, converted to MSB-first format and + write 1-n bits at the end of the bitstream. + For structured elements an (indirect) recursive call + to ccd_encodeComposition() is performed. + The element may be conditional and/or repeatable. +*/ + +SHORT cdc_std_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat, max_rep; + BOOL is_variable; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; +#ifdef DYNAMIC_ARRAYS + U8 *old_pstruct = NULL; +#endif + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_std_encode()"); + #else + TRACE_CCD (globs, "cdc_std_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + /* + * if this element is conditional, check the condition + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + /* + * if this element have a defined Prolog + * we have to process it before decoding the bitstream + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + if (melem[e_ref].elemType NEQ 'S') + { + /* + * Element is not a SPARE. + * Setup the readpointer into the C-structure for this element + * MVJ: In case of pointer types, the pstructOffs must be + * the offset into the memory area pointed to. CCDGEN must + * ensure this holds true. + */ + globs->pstructOffs = melem[e_ref].structOffs; + + if (melem[e_ref].optional) + { + /* + * for optional elements check the valid-flag in the C-struct. + * Spare elements does not have a corresponding valid flag. For + * the spare elements we have to calculate and check the + * condition to decide if this elements have to be coded. + */ + /* 20010621 MVJ: Dynamic array addition. + * Postpone optional check for non-code transparent pointer + * types ('P', 'Q', 'R'). + * For these types, the optional flag is the pointer itself. + * These types cannot be checked yet, as the pointer may be + * preceeded by a counter octet, a union tag id octet etc. + */ + if (melem[e_ref].elemType < 'P' OR melem[e_ref].elemType > 'R') + { + if (globs->pstruct[globs->pstructOffs++] == FALSE) + { + return 1; + } +#ifdef DEBUG_CCD + else if (globs->pstruct [melem[e_ref].structOffs] != TRUE) + { + TRACE_CCD (globs, "Ambiguous value for valid flag!\n...assumed 1 for ccdID=%d", + e_ref); + } +#endif + } + } + + if ((melem[e_ref].repType EQ 'v' OR melem[e_ref].repType EQ 'i')) + { + /* + * for variable sized elements read the amount + * of repeats out of the C-Structure (c_xxx). + * If the number of repeats given by the C-Structure + * exceeds the allowed value (maxRepeat) CCD gives a warning! + */ + if (melem[e_ref].maxRepeat > 255) + { + ULONG count = (ULONG) (* (USHORT *)(globs->pstruct + globs->pstructOffs++)); + repeat = MINIMUM (count, (ULONG) melem[e_ref].maxRepeat); + if (repeat < count) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + else + { + repeat = (ULONG)MINIMUM (globs->pstruct[globs->pstructOffs], + melem[e_ref].maxRepeat); + if ( repeat < (ULONG) (globs->pstruct[globs->pstructOffs]) ) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + globs->pstructOffs++; + } + else + if (melem[e_ref].repType EQ 'c') + { + repeat = (ULONG) melem[e_ref].maxRepeat; + } + else + if (melem[e_ref].repType == 's' || melem[e_ref].repType == 'b') + { + switch (melem[e_ref].elemType) + { + case 'R': /* Pointer to (possible array of) basetype */ + case 'F': /* Code-transparent pointer to (possible array of) basetype */ + case 'V': + globs->maxBitpos = globs->bitpos + mvar[melem[e_ref].elemRef].bSize; + break; + case 'D': /* Pointer to a composition */ + case 'P': /* Code transparent pointer to a comp */ + case 'C': /* Element is a composition. */ + case 'E': /* Pointer to a union */ + case 'Q': /* Code transparent pointer to a union */ + case 'U': /* Element is a union. */ + globs->maxBitpos = globs->bitpos + mcomp[melem[e_ref].elemRef].bSize; + break; + } + + is_variable = ccd_calculateRep (e_ref, &repeat, &max_rep, globs); + } + else + repeat = 1; + + /* 20010621 MVJ: Dynamic array addition. + * Check for non-code transparent pointer types ('P', 'Q', 'R'). + * For these types, the optional flag is the pointer itself. + * ASSUMPTION: The pointer may be preceeded by a counter octet, + * a union tag id octet etc., but it is up to CCDGEN to ensure + * word alignment (by inserting alignment bytes). Therefore + * we just read from globs->pstruct[globs->pstructOffs]. + */ +#ifdef DEBUG_CCD + /* Check pointer alignment and re-align if necessary (should never happen) */ + if ( is_pointer_type(e_ref) AND ((globs->pstructOffs & 3) NEQ 0)) { + TRACE_CCD (globs, "cdc_STD_encode(): Pointer misaligned! pstruct=0x08x," + " pstructOffs=0x%08x", globs->pstruct, globs->pstructOffs); + globs->pstructOffs = (globs->pstructOffs + 3) & 3; + } +#endif +#ifdef DYNAMIC_ARRAYS + /* + * MVJ: Perform pointer dereference for pointer types. + * Also, check optionality for these types. + */ + if ( is_pointer_type(e_ref) ) { + U8 *deref_pstruct; + + /* Get pointer value */ + deref_pstruct = *(U8 **)&globs->pstruct[globs->pstructOffs]; + + /* + * Strictly speaking the 'D' to 'F' types should not need this + * check (should have returned after the optionality check above), + * but it will catch stray NULL pointers (or uninitialized + * valid flags) + */ + if (ccd_check_pointer(deref_pstruct) != ccdOK ) + { + ccd_recordFault (globs, ERR_INVALID_PTR, BREAK, (USHORT) e_ref, + &globs->pstruct[globs->pstructOffs]); + return 1; + } + /* + * Pointer not NULL; + * 1. Save old globs->pstruct and assign pointer to globs->pstruct + * as new base. + * 2. Set pstructOffs to 0 (zero) as the next offset will start + * in the new memory area. + */ + old_pstruct = globs->pstruct; + globs->pstruct = deref_pstruct; + globs->pstructOffs = 0; + } +#endif /* DYNAMIC_ARRAYS */ + } + else + { + /* + * for spare elements we have to calculate the conditions + * and the repetitions because there are no valid-flags and + * c_xxx variables in the C-structure to read. + */ + if (melem[e_ref].optional) + { + /* + * Spare elements does not have a corresponding valid flag. + * For the spare elements we have to calculate and check the + * condition to decide if this elements have to be coded. + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + } + /* + * if this spare is repeatable, calculate the amount of + * repeats because there is no corresponding c_xxx element + * in the C-Structure. + */ + if (melem[e_ref].repType NEQ ' ') + { + globs->maxBitpos = globs->bitpos + spare[melem[e_ref].elemRef].bSize; + is_variable = ccd_calculateRep (e_ref, &repeat, &max_rep, globs); + } + else + repeat = 1; + } + + cdc_encodeElemvalue (e_ref, repeat, globs); + +#ifdef DYNAMIC_ARRAYS + if ( old_pstruct NEQ NULL ) + globs->pstruct = old_pstruct; +#endif + + return 1; +} +#endif /* !RUN_FLASH */ + +/* + * some elementary bitfunctions + */ + +/* LSB,MSB Definitions for the CPUs */ + +#ifdef M_INTEL +#define MSB_POS 1 +#define LSB_POS 0 +#define MSW_POS 2 +#define LSW_POS 0 +#else /* M_INTEL */ +#ifdef M_MOTOROLA +#define MSB_POS 0 +#define LSB_POS 1 +#define MSW_POS 0 +#define LSW_POS 2 +#endif /* M_MOTOROLA */ +#endif /* M_INTEL */ + +extern const ULONG ccd_bitfun_mask[]; + +/* + * Table of one-bit values (2^X) + * This unused variable is commented now in order to avoid some compiler + * warnings like: variable "shift" (line xxx) is not used + +LOCAL const UBYTE shift[] = +{ + 128, 64, 32, 16, 8, 4, 2, 1 +}; + */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_codeByte | ++--------------------------------------------------------------------+ + + PURPOSE: encodes the value of (value) into a CPU-dependent + bitstring. The length of the bitstring is specified + throu (bitlen). The function copies the bitstring into + the buffer (bitstream) at bit position (startbit). + The bitlen may be between 1 and 8. + +*/ + +BYTE CCDDATA_PREF(ccd_codeByte) (UBYTE * bitstream, + USHORT startbit, + USHORT bitlen, + UBYTE value) +{ + union + { /* Conversion structure 2 Byte <-> unsigned short */ + UBYTE c[2]; + USHORT s; + } + conv; + + UBYTE *p, lshift; + + USHORT m; + + p = bitstream + (startbit >> 3); + + lshift = (16 - ((startbit & 7) + bitlen)); + + conv.c[MSB_POS] = p[0]; + + conv.c[LSB_POS] = p[1]; + + m = ((USHORT) ccd_bitfun_mask[bitlen]) << lshift; + + conv.s &= ~m; + + conv.s |= ((value << lshift) & m); + + p[0] = conv.c[MSB_POS]; + + p[1] = conv.c[LSB_POS]; + + return ccdOK; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_decodeByte | ++--------------------------------------------------------------------+ + + PURPOSE: decodes (bitlen) bits from the (bitstream) at position + (startbit) and converts them to a numeric value (value) + The bitlen may be between 1 and 8. + +*/ + +BYTE CCDDATA_PREF(ccd_decodeByte) (UBYTE *bitstream, + USHORT startbit, + USHORT bitlen, + UBYTE *value) +{ + union + { /* Conversion structure 2 Byte <-> unsigned short */ + UBYTE c[2]; + USHORT s; + } + conv; + + UBYTE *p; + + p = bitstream + (startbit >> 3); + + conv.c[MSB_POS] = *p++; + + conv.c[LSB_POS] = *p; + + conv.s >>= (16 - ((startbit & 7) + bitlen)); + + conv.s &= (USHORT) ccd_bitfun_mask[bitlen]; + + *value = (UBYTE) conv.s; + + return ccdOK; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_codeLong | ++--------------------------------------------------------------------+ + + PURPOSE: encodes the value of (value) into a CPU-dependent + bitstring. The length of the bitstring is specified + throu (bitlen). The function copies the bitstring into + the buffer (bitstream) at bit position (startbit). + The bitlen may be between 1 and 32. + +*/ + +BYTE CCDDATA_PREF(ccd_codeLong) (UBYTE *bitstream, + USHORT startbit, + USHORT bitlen, + ULONG value) +{ + UBYTE *p; + + union + { /* Conversion structure 4 Byte <-> unsigned long */ + UBYTE c[4]; + ULONG l; + } + conv; + + p = bitstream + (startbit >> 3); + startbit &= 7; + + conv.l = value & ccd_bitfun_mask[bitlen]; + conv.l <<= (32-bitlen-startbit); + + p[0] &= (UCHAR)~ccd_bitfun_mask[8-startbit]; + + switch ((USHORT)(startbit+bitlen-1) >> 3) + { + case 0: + p[0] |= conv.c[MSW_POS+MSB_POS]; + break; + case 1: + p[0] |= conv.c[MSW_POS+MSB_POS]; + p[1] = conv.c[MSW_POS+LSB_POS]; + break; + case 2: + p[0] |= conv.c[MSW_POS+MSB_POS]; + p[1] = conv.c[MSW_POS+LSB_POS]; + p[2] = conv.c[LSW_POS+MSB_POS]; + break; + case 3: + p[0] |= conv.c[MSW_POS+MSB_POS]; + p[1] = conv.c[MSW_POS+LSB_POS]; + p[2] = conv.c[LSW_POS+MSB_POS]; + p[3] = conv.c[LSW_POS+LSB_POS]; + break; + default: + p[0] |= conv.c[MSW_POS+MSB_POS]; + p[1] = conv.c[MSW_POS+LSB_POS]; + p[2] = conv.c[LSW_POS+MSB_POS]; + p[3] = conv.c[LSW_POS+LSB_POS]; + p[4] = (UBYTE) ((value & 0xff) << (8-startbit)); + break; + } + return ccdOK; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_decodeLong | ++--------------------------------------------------------------------+ + + PURPOSE: decodes (bitlen) bits from the (bitstream) at position + (startbit) and converts them to a numeric value (value) + The bitlen may be between 1 and 32. + +*/ + +BYTE CCDDATA_PREF(ccd_decodeLong) (UBYTE *bitstream, + USHORT startbit, + USHORT bitlen, + ULONG *value) +{ + UBYTE *p; + + union + { /* Conversion structure 4 Byte <-> unsigned long */ + UBYTE c[4]; + ULONG l; + } + conv; + + p = bitstream + (startbit >> 3); + startbit &= 7; + + conv.l = 0L; + switch ((USHORT)(startbit+bitlen-1) >> 3) + { + case 0: + conv.c[MSW_POS+MSB_POS] = p[0]; + conv.l <<= startbit; + conv.l >>= (32-bitlen); + break; + case 1: + conv.c[MSW_POS+MSB_POS] = p[0]; + conv.c[MSW_POS+LSB_POS] = p[1]; + conv.l <<= startbit; + conv.l >>= (32-bitlen); + break; + case 2: + conv.c[MSW_POS+MSB_POS] = p[0]; + conv.c[MSW_POS+LSB_POS] = p[1]; + conv.c[LSW_POS+MSB_POS] = p[2]; + conv.l <<= startbit; + conv.l >>= (32-bitlen); + break; + case 3: + conv.c[MSW_POS+MSB_POS] = p[0]; + conv.c[MSW_POS+LSB_POS] = p[1]; + conv.c[LSW_POS+MSB_POS] = p[2]; + conv.c[LSW_POS+LSB_POS] = p[3]; + conv.l <<= startbit; + conv.l >>= (32-bitlen); + break; + default: + conv.c[MSW_POS+MSB_POS] = p[0]; + conv.c[MSW_POS+LSB_POS] = p[1]; + conv.c[LSW_POS+MSB_POS] = p[2]; + conv.c[LSW_POS+LSB_POS] = p[3]; + conv.l <<= startbit; + conv.l >>= (32-bitlen); + conv.c[LSW_POS+LSB_POS] |= (p[4] >> (8-startbit)); + break; + } + *value = conv.l & ccd_bitfun_mask[bitlen]; + return ccdOK; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : ccd_bitcopy | ++--------------------------------------------------------------------+ + + PURPOSE: copys bitlen bits from the source buffer to the destination + buffer. offset contains the position of the first bit in + the source bitfield. This function may perform a leftshift + to adjust the most significant bit on byte boundarys of the + first byte in dest. + +*/ + +void CCDDATA_PREF(ccd_bitcopy) (UBYTE *dest, + UBYTE *source, + USHORT bitlen, + USHORT offset) +{ + union + { /* Conversion structure 2 Byte <-> unsigned short */ + UBYTE c[2]; + USHORT s; + } + conv; + + USHORT l_shift = offset & 7; + USHORT bytes_to_copy = (bitlen >> 3); + + /* + * go to the byte that contains the first valid bit. + */ + source += (offset >> 3); + + + if (l_shift) + { + /* + * shift and copy each byte + */ + while (bytes_to_copy--) + { + conv.c[MSB_POS] = *source; + source++; + conv.c[LSB_POS] = *source; + conv.s <<= l_shift; + *dest = conv.c[MSB_POS]; + dest++; + } + } + else + { + /* + * no shift operation, do a memcopy; + */ + while (bytes_to_copy--) + { + *dest = *source; + dest++; + source++; + } + } + /* + * cutoff the garbage at the end of the bitstream + */ + + *(dest-1) &= (UCHAR)(~ccd_bitfun_mask[(8-(bitlen&7))&7]); +} +#endif /* !RUN_FLASH */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/cdt.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,158 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : cdt.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Ccddata tool. Delivers informations from ccddata_dll.dll. ++----------------------------------------------------------------------------- +*/ + +/*==== INCLUDES =============================================================*/ +#include "typedefs.h" +#include "ccdtable.h" +#include "ccddata.h" + +#include <stdio.h> +#include <string.h> + +static char* +#include "ccddata_version.h" +; + +/*==== CONSTS ================================================================*//*==== TYPES =================================================================*/ +/*==== LOCALS ================================================================*/ +static int ccddata_version; +static int ccddata_table_version; +static char* cdt_ccddata_dllname; +/*==== PRIVATE FUNCTIONS =====================================================*/ +/* ++------------------------------------------------------------------------------ +| Function : parse_cmdline ++------------------------------------------------------------------------------ +| Description : Checks options and parameters. +| +| Parameters : Argc and argv from main. +| +| Return : 0 if correct cmdline, -1 otherwise. +| ++------------------------------------------------------------------------------ +*/ +static int parse_cmdline (int argc, char* argv[]) +{ + int ac = 1; + + if (argc < 2) + return -1; + + while (ac < argc) + { + char* av; + av = argv[ac]; + switch (av[0]) + { + case '-': + if (!strcmp (&av[1], "cdv")) /* Ccddata version */ + { + ccddata_version = 1; + } + else if (!strcmp (&av[1], "tv")) /* Table version */ + { + ccddata_table_version = 1; + } + else if (!strcmp (&av[1], "l")) /* Cccdata dll */ + { + ++ac; + cdt_ccddata_dllname = argv[ac]; + } + else + { + fprintf (stderr, "Unknown option: %s\n", av); + return -1; + } + break; + default: + return -1; + } + ac++; + } + return 0; +} + + +/* ++------------------------------------------------------------------------------ +| Function : usage ++------------------------------------------------------------------------------ +| Description : Print usage information. +| +| Parameters : tapname - The name of the tap executable. +| +| Return : - +| ++------------------------------------------------------------------------------ +*/ + +static void usage (char* cdtname) +{ + fprintf (stderr, "Usage: %s [options]\n", cdtname); + fprintf (stderr, " Options:\n"); + fprintf (stderr, " -cdv: print version of ccddata dll\n"); + fprintf (stderr, " -tv: print version ccddata tables\n"); + fprintf (stderr, " -l <ccddata-dll>: select dedicated ccddata dll\n"); +} + +/*==== PUBLIC FUNCTIONS ======================================================*/ + +/* ++------------------------------------------------------------------------------ +| Function : main ++------------------------------------------------------------------------------ +| Description : The start into happiness. +| +| Parameters : As usual. See parse_cmdline() and usage() for details. +| +| Return : 0 +| ++------------------------------------------------------------------------------ +*/ + +int main (int argc, char** argv) +{ + printf ("Ccddata tool %s\n", CCDDATA_VERSION); + + if (parse_cmdline (argc, argv) < 0) + { + char *cdtbase; + cdtbase = strrchr (argv[0], '\\'); + if (!cdtbase) + cdtbase = strrchr (argv[0], '/'); + usage (cdtbase ? cdtbase+1 : argv[0]); + return -1; + } + + if (ccddata_init (cdt_ccddata_dllname, 0, NULL, NULL) != CCDDATA_DLL_OK) + { + fprintf (stderr, "Cannot load ccddata dll"); + return -1; + } + + if (ccddata_version) + printf ("Version: %s\n", ccddata_get_version()); + if (ccddata_table_version) + printf ("Table version: %d\n", ccddata_get_table_version()); + + ccddata_exit (); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/critical_ext.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,177 @@ + +/* ++------------------------------------------------------------------------------ +| File: critical_ext.c ++------------------------------------------------------------------------------ +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG. +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++------------------------------------------------------------------------------ +| Purpose: Encoding and decoding functions for criticalExtensions +| +| $Identity:$ ++------------------------------------------------------------------------------ +*/ + +/* + * Standard definitions like UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes and constants in the common part of ccd + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : critical_ext | +| STATE : code ROUTINE : cdc_critical_ext_decode | ++------------------------------------------------------------------------+ + + PURPOSE : Decode elements of type criticalExtensions + + An element of this type should never be encoded or decoded. + If the coder faces an IE of this type, it should report an + error report and abort. + Whenever a criticalExtensions-IE is extended from NULL or + SEQUENCE {} to another type, its CCD coding type will change + and the functions in this file will not be called for that IE + any more. + + According to 3GPP TS25.331 V3.6.0, 10.1.1.2.2: + Since messages including critical extensions are rejected by + receivers not comprehending them, these messages can be + modified completely, e.g. IEs may be inserted at any place + and IEs may be removed or redefined. + See also 3GPP TS25.921 V4.3.0, 10.4. +*/ +SHORT cdc_critical_ext_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_critical_ext_decode()"); + #else + TRACE_CCD (globs, "cdc_critical_ext_decode() %s", mcomp[melem[e_ref].elemRef].name); + #endif +#endif + + globs->pstructOffs = melem[e_ref].structOffs; + + /* For optional elements we have already set the valid flag in the + * C-structure. We have done it while processing ASN1_SEQ. + */ + if ( ! cdc_isPresent(e_ref, globs) ) { + return 1; + } + + if (melem[e_ref].elemType EQ 'V' AND mvar[melem[e_ref].elemRef].bSize EQ 0) + { + ccd_recordFault (globs, + ERR_CRITICAL_EXT, + BREAK, + (USHORT) e_ref, + globs->pstruct + melem[e_ref].structOffs + ); + return 0; + } + /* + * Currently CCD tool chain does not support extensions of this type. + * This else-implementation is just an outlook. + * + else + { + U16 compRef = melem[e_ref].elemRef; + U16 elemRef = mcomp[compRef].componentRef; + (void) codec[melem[Elem].codingType][DECODE_FUN] + (compRef, elemRef, globs); + }*/ + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : critical_ext | +| STATE : code ROUTINE : cdc_critical_ext_encode | ++------------------------------------------------------------------------+ + + PURPOSE : Encode elements of type criticalExtensions + + An element of this type should never be encoded or decoded. + If the coder faces an IE of this type, it should report an + error report and abort. +*/ +SHORT cdc_critical_ext_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_critical_ext_encode()"); + #else + TRACE_CCD (globs, "cdc_critical_ext_encode() %s", mcomp[melem[e_ref].elemRef].name); + #endif +#endif + + globs->pstructOffs = melem[e_ref].structOffs; + + /* For optional elements we have already set the valid flag in the + * C-structure. We have done it while processing ASN1_SEQ. + */ + if ( ! cdc_isPresent(e_ref, globs) ) { + return 1; + } + + if (melem[e_ref].elemType EQ 'V' AND mvar[melem[e_ref].elemRef].bSize EQ 0) + { + ccd_recordFault (globs, + ERR_CRITICAL_EXT, + BREAK, + (USHORT) e_ref, + globs->pstruct + melem[e_ref].structOffs + ); + return 0; + } + /* + * Currently CCD tool chain does not support extensions of this type. + * This else-implementation is just an outlook. + * + else + { + U16 compRef = melem[e_ref].elemRef; + U16 elemRef = mcomp[compRef].componentRef; + (void) codec[melem[Elem].codingType][ENCODE_FUN] + (compRef, elemRef, globs); + }*/ + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/csn1_choice_1.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,113 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : csn1_choice_1.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for CSN1_S1 elements ++----------------------------------------------------------------------------- +*/ +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +extern SHORT cdc_csn1_choice_x_decode (const ULONG c_ref, const ULONG e_ref, + ULONG num, T_CCD_Globs *globs); +extern SHORT cdc_csn1_choice_x_encode (const ULONG c_ref, const ULONG e_ref, + ULONG num, T_CCD_Globs *globs); + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_csn1_choice1_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type CSN1 CHOICE1 element. This element + consists of a 1 bit CHOICE index and a value part of an + union type. The item of the union type represents the + CHOICE alternatives. +*/ + +SHORT cdc_csn1_choice1_decode (const ULONG c_ref, const ULONG e_ref, + T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_choice1_decode()"); + #else + TRACE_CCD (globs, "cdc_csn1_choice1_decode() %s", + ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_csn1_choice_x_decode (c_ref, e_ref, 1, globs); +} +#endif /* !RUN_INT_RAM */ + + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_csn1_choice1_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type CSN1 CHOICE1 element. This element + consists of a 1 bit CHOICE index and a value part of an + union type. The item of the union type represents the + CHOICE alternatives. +*/ + +SHORT cdc_csn1_choice1_encode (const ULONG c_ref, const ULONG e_ref, + T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_choice1_encode()"); + #else + TRACE_CCD (globs, "cdc_csn1_choice1_encode() %s", + ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_csn1_choice_x_encode (c_ref, e_ref, 1, globs); +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/csn1_choice_2.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,113 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : csn1_choice_2.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for CSN1_S1 elements ++----------------------------------------------------------------------------- +*/ +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +extern SHORT cdc_csn1_choice_x_decode (const ULONG c_ref, const ULONG e_ref, + ULONG num, T_CCD_Globs *globs); +extern SHORT cdc_csn1_choice_x_encode (const ULONG c_ref, const ULONG e_ref, + ULONG num, T_CCD_Globs *globs); + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_csn1_choice2_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type CSN1 CHOICE1 element. This element + consists of 2 bits CHOICE index and a value part of an + union type. The item of the union type represents the + CHOICE alternatives. +*/ + +SHORT cdc_csn1_choice2_decode (const ULONG c_ref, const ULONG e_ref, + T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_choice2_decode()"); + #else + TRACE_CCD (globs, "cdc_csn1_choice2_decode() %s", + ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_csn1_choice_x_decode (c_ref, e_ref, 2, globs); +} +#endif /* !RUN_INT_RAM */ + + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_csn1_choice2_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type CSN1 CHOICE1 element. This element + consists of 2 bits CHOICE index and a value part of an + union type. The item of the union type represents the + CHOICE alternatives. +*/ + +SHORT cdc_csn1_choice2_encode (const ULONG c_ref, const ULONG e_ref, + T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_choice2_encode()"); + #else + TRACE_CCD (globs, "cdc_csn1_choice2_encode() %s", + ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_csn1_choice_x_encode (c_ref, e_ref, 2, globs); +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/csn1_choice_x.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,433 @@ +/* ++----------------------------------------------------------------------------- +| Project : CCD +| Modul : csn1_choice_x.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for CSN1_CHOICE2 +| elements ++----------------------------------------------------------------------------- +*/ +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" +#include "ccd_codingtypes.h" +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +EXTERN T_FUNC_POINTER codec[MAX_CODEC_ID+1][2]; + +#ifndef RUN_INT_RAM +/* Attention for RUN_...: static function */ + +static void decode_csn1_choice_alternative(const ULONG e_ref, T_ENUM union_tag, + T_CCD_Globs *globs); +static void encode_csn1_choice_alternative(const ULONG e_ref, T_ENUM union_tag, + T_CCD_Globs *globs); +#endif /* !RUN_INT_RAM */ + + +#ifndef RUN_INT_RAM +/* Attention for RUN_...: static function */ +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : csn1_choice1 | +| STATE : code ROUTINE : decode_csn1_choice_alternative | ++--------------------------------------------------------------------+ + + PURPOSE : Decode a chosen alternative of a CSN.1 CHOICE type + Use the parameter union_tag to read the CHOICE index. + Because of union_tag it is easy to calculate the elemRef + for the chosen element which is to be decoded. Then the + appropriate decoding function for the chosen element is + called. +*/ +static void decode_csn1_choice_alternative(const ULONG e_ref, T_ENUM union_tag, + T_CCD_Globs *globs) +{ + ULONG elem_ref, mcomp_ref; + UBYTE *act_structpos; + + mcomp_ref= melem[e_ref].elemRef; + /* + * Write the CHOICE tag value in the C-structure. + * Calculate the elem_ref for the chosen element. + */ + *(T_ENUM *) (globs->pstruct+globs->pstructOffs) = union_tag; + elem_ref = mcomp[mcomp_ref].componentRef + (ULONG) union_tag; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "decode_csn1_choice_alternative()"); + #else + TRACE_CCD (globs, "decode_csn1_choice_alternative() %s", ccddata_get_alias((USHORT)e_ref, 1)); + #endif +#endif + + /* + * Store the actual structure position. + */ + act_structpos = globs->pstruct; + globs->pstruct += (globs->pstructOffs + sizeof(T_ENUM)); + /* + * Use the jump-table for selecting the decode function + * Call the decode function for the chosen element. + */ + (void) codec[melem[elem_ref].codingType][DECODE_FUN] + (mcomp_ref, elem_ref, globs); + /* + * Restore the write pointer to prepare decoding of the next element + */ + globs->pstruct = act_structpos; +} +#endif /* !RUN_INT_RAM */ + + +#ifndef RUN_INT_RAM +/* Attention for RUN_...: static function */ +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : csn1_choice1 | +| STATE : code ROUTINE : encode_csn1_choice_alternative | ++--------------------------------------------------------------------+ + + PURPOSE : Encode a chosen alternative of a CSN.1 CHOICE type. + + Because of union_tag it is easy to calculate the e_ref for + the chosen element to be encoded. Then the appropriate + encoding function for the chosen element is called. +*/ +static void encode_csn1_choice_alternative (const ULONG e_ref, T_ENUM union_tag, + T_CCD_Globs *globs) +{ + ULONG elem_ref, mcomp_ref; + UBYTE *act_structpos; + + mcomp_ref= melem[e_ref].elemRef; + + /* + * Calculate the elem_ref for the chosen element. + */ + elem_ref = mcomp[mcomp_ref].componentRef + (ULONG) union_tag; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "encode_csn1_choice_alternative()"); + #else + TRACE_CCD (globs, "encode_csn1_choice_alternative() %s", ccddata_get_alias((USHORT)e_ref, 1)); + #endif +#endif + + /* + * Store the actual structure position. + */ + act_structpos = globs->pstruct; + globs->pstruct += (globs->pstructOffs + sizeof(T_ENUM)); + /* + * Use the jump-table for selecting the encode function + * Call the encode function for the chosen element. + */ + (void) codec[melem[elem_ref].codingType][ENCODE_FUN] + (mcomp_ref, elem_ref, globs); + /* + * Restore the write pointer to prepare decoding of the next element + */ + globs->pstruct = act_structpos; +} +#endif /* !RUN_INT_RAM */ + + +#ifndef RUN_INT_RAM/* ++-----------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_csn1_choice_x_decode | ++-----------------------------------------------------------------------+ + + PURPOSE : Decode CSN.1 CHOICE type + In the header file the structure containing an element of + coding type CSN1_CHOICE is represented by a structure + type declaration. + This structure type is composed at least of a control item + preceding an item of an union type. The control item + indicates the CHOICE index. The item of the union type + represents the CHOICE alternatives. + The CHOICE index is "num" bits long. It is read from the + message bit string and the result is written to the control + item. CCD determes "elemRef" depending on this control item + and processes the union element according to table entry + of "elemRef" . +*/ + +SHORT cdc_csn1_choice_x_decode (const ULONG c_ref, const ULONG e_ref, + ULONG num, T_CCD_Globs *globs) +{ + ULONG union_tag, num_of_alt, num_of_comps; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_choice1_decode()"); + #else + TRACE_CCD (globs, "cdc_csn1_choice1_decode() %s", ccddata_get_alias((USHORT)e_ref, 1)); + #endif +#endif + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * If this element is conditional, check the condition. + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + /* + * If this element has a defined prologue + * we have to process it before decoding the bitstream. + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + globs->pstructOffs = melem[e_ref].structOffs; + + if (melem[e_ref].optional) + { + /* Postpone optional flag setting for non-code transparent + * pointer types ('P', 'Q', 'R'). + * For these types, the optional flag is the pointer itself. + * These types cannot be set yet, as the pointer may be + * preceeded by a counter octet, a union tag id octet etc. + */ + if (melem[e_ref].elemType < 'P' OR melem[e_ref].elemType > 'R') + globs->pstruct[globs->pstructOffs++] = (UBYTE) TRUE; + } + + /* + * Get the number of alternatives from the C-structure. + */ + num_of_comps = mcomp[melem[e_ref].elemRef].numOfComponents; + /* Determine number of possible alternatives */ + num_of_alt = num <<1; + + /* read the bit representing the CHOICE index*/ + union_tag = bf_getBits(num, globs); + + /* Check number of alternatives */ + if (!num_of_comps) + { + /* Don't do anything for empty choices */ + return 1; + } + else if (num_of_comps != num_of_alt) + { + /* if the number of components doesn't match to number of possible + * examine whether the CHOICE index demands an impossible alternative + */ + if (union_tag > num_of_comps) + { + /* if CHOICE index demands an impossible alternative + * return an error and break decoding + */ + ccd_recordFault (globs, ERR_CSN1_CHOICE, BREAK, (USHORT) e_ref, + globs->pstruct+globs->pstructOffs); + } + else + { + ccd_recordFault (globs, ERR_CSN1_CHOICE, CONTINUE, (USHORT) e_ref, + globs->pstruct+globs->pstructOffs); + } + } + + /* + * Decode a chosen alternative of an CSN.1 CHOICE type + */ + decode_csn1_choice_alternative(e_ref, (T_ENUM) union_tag, globs); + return 1; +} +#endif /* !RUN_INT_RAM */ + + + +#ifndef RUN_INT_RAM + +/* ++----------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : csn1_choice1 | +| STATE : code ROUTINE : cdc_csn1_choice_x_encode | ++----------------------------------------------------------------------+ + + PURPOSE : Encoding of CHOICE1 type for UMTS + In the header file the structure containing an element of + coding type CSN1_CHOICE is represented by a structure + type declaration. + This structure type is composed at least of a control item + preceding an item of an union type. The control item + indicates the CHOICE index. The item of the union type + represents the CHOICE alternatives. + The CHOICE index is "num" bit long. Tts value is read + from the message structureand the result is written to the + bit string. CCD determines "elemRef" depending on this index + and processes the union element according to table entry + of "elemRef" . +*/ +SHORT cdc_csn1_choice_x_encode (const ULONG c_ref, const ULONG e_ref, + ULONG num, T_CCD_Globs *globs) +{ + ULONG union_tag, num_of_alt, num_of_comps; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_choice_encode()"); + #else + TRACE_CCD (globs, "cdc_csn1_choice_encode() %s", + mcomp[melem[e_ref].elemRef].name); + #endif +#endif + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * If this element is conditional, check the condition. + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + /* + * If this element has a defined prologue + * we have to process it before decoding the bitstream. + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + /* + * Setup the offset into the C-structure for this element + */ + globs->pstructOffs = melem[e_ref].structOffs; + + if (melem[e_ref].optional) + { + /* + * For optional elements check the valid-flag in the C-struct. + * Postpone optional flag setting for non-code transparent + * pointer types ('P', 'Q', 'R'). + * For these types, the optional flag is the pointer itself. + * These types cannot be set yet, as the pointer may be + * preceeded by a counter octet, a union tag id octet etc. + */ + if (melem[e_ref].elemType < 'P' OR melem[e_ref].elemType > 'R') + { + if (globs->pstruct[globs->pstructOffs++] EQ FALSE) + return 1; + } + } + /* + * Get the number of alternatives from the C-structure. + */ + num_of_comps = mcomp[melem[e_ref].elemRef].numOfComponents; + /* Determine number of possible alternatives */ + num_of_alt = num <<1; + /* + * Get the value of CHOICE index (= union controller) from the C-structure. + * Check its correctness. Write it in the air message. + * Afterwards encode the chosen CHOICE altervative. + */ + union_tag = (ULONG) globs->pstruct[globs->pstructOffs]; + /* + * Check its correctness. + */ + if (union_tag >= num_of_alt) + { + /* + * CHOICE index goes beyond the number of alternatives determined by + * selected coding type => return Error and break encoding process + */ + ccd_recordFault (globs, ERR_CSN1_CHOICE, BREAK, + (USHORT) e_ref, globs->pstruct+globs->pstructOffs); + } + + /* + * Write the CHOICE tag value in the C-structure. + */ + bf_writeVal (union_tag, num, globs); + + /* Check number of alternatives */ + if (!num_of_comps) + { + /* Don't do anything for empty choices */ + return 1; + } + else if (num_of_comps != num_of_alt) + { + /* if the number of components doesn't match to number of possible + alternatives return a warning */ + ccd_recordFault (globs, ERR_CSN1_CHOICE, CONTINUE, + (USHORT) e_ref, globs->pstruct+globs->pstructOffs); + if (union_tag > num_of_comps) + { + /* if the CHOICE index demands an impossible one handle this choice + as no_code element */ + #ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_No_encode()"); + #else + TRACE_CCD (globs, "cdc_No_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif + #endif + return 1; + } + } + + /* + * Encode a chosen alternative of an CSN.1 CHOICE type + */ + encode_csn1_choice_alternative (e_ref, (T_ENUM) union_tag, globs); + + return 1; +} +#endif /* !RUN_INT_RAM */ + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/csn1_concat.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,415 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : csn1_concat.c ++----------------------------------------------------------------------------- +| Copyright 2004 Texas Instruments Deutschland GmbH +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Deutschland GmbH +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Deutschland GmbH. ++----------------------------------------------------------------------------- +| Purpose : Condat Conder Decoder - +| Definition of encoding and decoding functions of +| CSN1 truncated concatenation elements ++----------------------------------------------------------------------------- +*/ + + +/* + * Standard definitions like GLOBAL, UCHAR, ERROR etc. + */ + +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" +#include "ccd_codingtypes.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +EXTERN T_FUNC_POINTER codec[MAX_CODEC_ID+1][2]; + +#ifndef RUN_FLASH +/* ++---------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_csn1_concat_decode | ++---------------------------------------------------------------------+ + + PURPOSE : decodes the bitstream to a C-Structure.The decoding + rules contains the element definitions for the + elements of this message. + This function may called recursivly because of a + substructured element definition. +*/ + +SHORT cdc_csn1_concat_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + /* + * index in table melem + */ + ULONG elem_ref, last_elem, start_elem; + SHORT codecRet; + U8 *actStructpos; + U8 actErrLabel; + U16 actMaxBitpos, finalBitPos; + U8 *pnumConcatElem = NULL; + ULONG i, num_concat_elem; + BOOL SetPosExpected = FALSE; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_concat_decode()"); + #else + TRACE_CCD (globs, "cdc_csn1_concat_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + actErrLabel = globs->errLabel; + + /* Set ref number for calcidx table. */ + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * If this element is conditional, check the condition. + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + /* + * if this element have a defined Prolog + * we have to process it before decoding the bitstream + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + globs->ccd_recurs_level++; + + if (globs->bitpos < globs->maxBitpos) + { + if (melem[e_ref].repType == 's') + { + BOOL is_variable; + ULONG max_rep, repeat; + + is_variable = ccd_calculateRep (e_ref, &repeat, &max_rep, globs); + if (repeat > (ULONG) (globs->maxBitpos-globs->bitpos)) + { + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + repeat = MINIMUM (repeat, (ULONG) (globs->maxBitpos-globs->bitpos)); + } + + finalBitPos = (USHORT) (globs->bitpos + repeat); + + #ifdef DEBUG_CCD + #ifdef CCD_SYMBOLS + TRACE_CCD (globs, "decoding of concatenation %s as a bit array", + mcomp[melem[e_ref].elemRef].name); + #else + TRACE_CCD (globs, "decoding of concatenation %d as a bit array", melem[e_ref].elemRef); + #endif + #endif + /* Store the limit. The truncated concatenation may contain + other compositions as bitstring. */ + actMaxBitpos = globs->maxBitpos; + globs->maxBitpos = finalBitPos; + } + else + { + #ifdef DEBUG_CCD + #ifdef CCD_SYMBOLS + TRACE_CCD (globs, "decoding concatenation %s", + mcomp[melem[e_ref].elemRef].name); + #else + TRACE_CCD (globs, "decoding concatenation %d", melem[e_ref].elemRef); + #endif + #endif + } + + /* + * Store the actual structure position. + */ + actStructpos = globs->pstruct; + globs->pstructOffs = melem[e_ref].structOffs; + globs->pstruct += globs->pstructOffs; + /* + * setup the index in the melem table for this composition. + */ + elem_ref = (ULONG) mcomp[melem[e_ref].elemRef].componentRef; + last_elem = elem_ref + mcomp[melem[e_ref].elemRef].numOfComponents; + /* + * It is recommended to use a leading element of coding type NO_CODE + * in the message description which is used to count the existing + * elements of the truncated concatenation. If this element is missing + * the decoding process will proceed but the CCD user is forced to + * evaluate all of the valid flags. + */ + + if (melem[elem_ref].codingType == CCDTYPE_NO_CODE) + { + pnumConcatElem = globs->pstruct; + elem_ref++; + + num_concat_elem = (ULONG) (mcomp[melem[e_ref].elemRef].numOfComponents - 1); + } + + start_elem = elem_ref; + /* + * decode all elements + */ + while (elem_ref < last_elem) + + { + #ifdef ERR_TRC_STK_CCD + /* save the value for tracing in error case */ + globs->error_stack[globs->ccd_recurs_level] = (USHORT) elem_ref; + #endif /* ERR_TRC_STK_CCD */ + + /* + * check if the bitstream has ended + */ + if (bf_endOfBitstream(globs) AND !globs->TagPending) + { + /* End of the bit stream is not reached if a call to bf_setBitpos() + * is expected for the next element of the current substructure. + * An instructive example is an empty "mob_id" + */ + cix_ref = melem[elem_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + if (num_prolog_steps) + { + i = prolog_step_ref + num_prolog_steps; + + while (i >= prolog_step_ref) + { + if (calc[i].operation == 'S') + { + SetPosExpected = TRUE; + break; + } + i--; + } + } + + if (SetPosExpected EQ FALSE) + { + num_concat_elem = elem_ref - start_elem; + /* after the while loop the recursion level will be decremented. */ + break; + } + + }//if end of bit string + + /* + * use the jump-table for selecting the decode function + */ + codecRet = + codec[melem[elem_ref].codingType][DECODE_FUN](melem[e_ref].elemRef, + elem_ref, globs); + if (codecRet NEQ 0x7f) + { + /* + * set the elem_ref to the next or the same element + */ + elem_ref += codecRet; + } + } + + if (pnumConcatElem != NULL) + { + *pnumConcatElem = (UBYTE) num_concat_elem; + } + + + if (melem[e_ref].repType == 's') + { + if (globs->bitpos > finalBitPos) + { + ccd_recordFault (globs, ERR_CONCAT_LEN, CONTINUE, (USHORT) elem_ref, + globs->pstruct + globs->pstructOffs); + } + bf_setBitpos (finalBitPos, globs); + /* Update maxBitpos to avoid an early end of decoding. */ + globs->maxBitpos = actMaxBitpos; + } + + /* + * restore the write pointer + */ + globs->pstruct = actStructpos; + } + + globs->errLabel = actErrLabel; + /* Reset indicator of exhaustion in the IEI table*/ + for (i = 0; globs->iei_ctx[globs->ccd_recurs_level].iei_table[i].valid == TRUE; i++) + { + globs->iei_ctx[globs->ccd_recurs_level].iei_table[i].exhausted = FALSE; + } + globs->ccd_recurs_level--; + + return 1; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++---------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_csn1_concat_encode | ++---------------------------------------------------------------------+ + + PURPOSE : codes the content of a C-Structure into a bitstream. + This function may be called recursivly if an IE in the + structure is itself a structured IE. +*/ + +SHORT cdc_csn1_concat_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) + +{ + ULONG cix_ref, elem_ref, last_elem; + U8 codecRet; + U16 actBitpos; + U8 actByteOffs; + U8 *actStructpos; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_concat_encode()"); + #else + TRACE_CCD (globs, "cdc_csn1_concat_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cix_ref = melem[e_ref].calcIdxRef; + + /* + * If this element is conditional, check the condition. + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + globs->ccd_recurs_level++; + + actStructpos = globs->pstruct; + globs->pstructOffs = melem[e_ref].structOffs; + globs->pstruct += globs->pstructOffs; + + elem_ref = (ULONG) mcomp[melem[e_ref].elemRef].componentRef; + last_elem = elem_ref + mcomp[melem[e_ref].elemRef].numOfComponents; + + /* + * It is recommended to use a leading element of coding type NO_CODE + * in the message description which is used to count the existing + * elements of the truncated concatenation in case of decoding. + * In case of encoding this element must be skipped. + */ + + if (melem[elem_ref].codingType == CCDTYPE_NO_CODE) + { + elem_ref++; + /* last_elem = elem_ref + *globs->pstruct; + + * Encoding act on the assumption that all elements of the truncated + * concatenation should be encoded. CCD will skip tagged elements + * but in case of CSN1 coding CCD will write the flag indicating absent + * elements. Values of mandatory elements without valid flags are coded + * according to their assignments in the C-structure. + * If more bits are written than the component l_buf of the message buffer + * suggested CCD generates a warning (error code ERR_BUFFER_OF). It is up + * to the user to analyse the consequences of this warning and to choose + * adequate procedures. + */ + } + + /* + * code all elements + */ + while ((elem_ref < last_elem) && (globs->bitpos < globs->msgLen)) + { +#ifdef ERR_TRC_STK_CCD + /* + * Save the value for tracing in error case. + */ + globs->error_stack[globs->ccd_recurs_level] = (USHORT) elem_ref; +#endif /* ERR_TRC_STK_CCD */ + +#if defined _TOOLS_ + if (ccd_patch (globs, 0)) + codecRet = 1; + else +#endif /* _TOOLS_ */ + + actBitpos = globs->bitpos; + actByteOffs = globs->byteoffs; + + /* Use the jump-table for selecting encode function. */ + codecRet = (UBYTE) + codec[melem[elem_ref].codingType][ENCODE_FUN](melem[e_ref].elemRef, + elem_ref, globs); + + if (globs->bitpos < globs->msgLen) + { + if (codecRet NEQ 0x7f) + { + /* Set the elem_ref to the next or the same element. */ + elem_ref += codecRet; + } + } + else + { + if (globs->bitpos > globs->msgLen) + { + globs->bitpos = actBitpos; + globs->byteoffs = actByteOffs; + ccd_recordFault (globs, ERR_CONCAT_LEN, CONTINUE, (USHORT) elem_ref, + globs->pstruct + globs->pstructOffs); + } + break; + } + } + + globs->pstruct += mcomp[melem[e_ref].elemRef].cSize; + /* + * restore the read pointer + */ + globs->pstruct = actStructpos; + globs->ccd_recurs_level--; + return 1; +} +#endif /* !RUN_FLASH */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/csn1_s0.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,118 @@ +/* ++----------------------------------------------------------------------------- +| Project : CCD +| Modul : csn1_s0.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for CSN1_S0 elements ++----------------------------------------------------------------------------- +*/ + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +extern SHORT cdc_csn1_sx_decode (int flag, const ULONG e_ref, T_CCD_Globs *globs); +extern SHORT cdc_csn1_sx_encode (int flag, const ULONG e_ref, T_CCD_Globs *globs); + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_csn1_s0_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the non-standard type CSN1 S0 element. + The encoding rule for this type is very similar to the + CSN.1 type. Except for the presence flag which is 0 in + this case. + The encoded IE consists of one bit for presence flag and + a value part. Only if the flag bit is equal 0 the value + part will follow it. +*/ + +SHORT cdc_csn1_s0_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_s0_decode()"); + #else + TRACE_CCD (globs, "cdc_csn1_s0_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_csn1_sx_decode (0, e_ref, globs); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_csn1_s0_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the non-standard type CSN1 S0 element. + The encoding rule for this type is very similar to CSN.1 + type. Except for the presence flag which is 0 in this + case. The encoded bit pattern consists of a 0 bit as + valid flag and a value part. If the element is present + (the v_xxx component is TRUE in the decoded message) + a 0 bit will be coded followed by the encoded value part. + Otherwise a 1 bit will be encoded. + Possible array types are given by melem[e_ref].repType: + 0) ' ' => {0| IE} (no array) + 1) 'i' => {0 IE} ** 1 (many repeations up to a 1 bit) + 2) 'v' => {0|1 IE}* val (val is another IE) + 3) 'c' => {0|1 IE}* 3 (3 is an example) +*/ + +SHORT cdc_csn1_s0_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_s0_encode()"); + #else + TRACE_CCD (globs, "cdc_csn1_s0_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_csn1_sx_encode (0, e_ref, globs); +} +#endif /* !RUN_FLASH */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/csn1_s0_opt.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,123 @@ +/* ++----------------------------------------------------------------------------- +| Project : CCD +| Modul : csn1_s0_opt.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for CSN1_S0 elements ++----------------------------------------------------------------------------- +*/ + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +extern SHORT cdc_csn1_sx_decode (int flag, const ULONG e_ref, T_CCD_Globs *globs); +extern SHORT cdc_csn1_sx_encode (int flag, const ULONG e_ref, T_CCD_Globs *globs); + +#ifndef RUN_FLASH +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_csn1_s0_opt_decode | ++------------------------------------------------------------------------+ + + PURPOSE : Decoding of the non-standard type CSN1 S0 element. + The encoding rule for this type is very similar to the + CSN.1 type. Except for the presence flag which is 0 in + this case. + The encoded IE consists of one bit for presence flag and + a value part. Only if the flag bit is equal 0 the value + part will follow it. + + The element value can be present, then it is preceded by the + flag value 0. If the element is represented by the flag 1 only + the value is absent! Besides the absence of the whole element + is allowed. +*/ + +SHORT cdc_csn1_s0_opt_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_s0_opt_decode()"); + #else + TRACE_CCD (globs, "cdc_csn1_s0_opt_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_csn1_sx_decode (0, e_ref, globs); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_csn1_s0_opt_encode | ++------------------------------------------------------------------------+ + + PURPOSE : Encoding of the non-standard type CSN1 S0 element. + The encoding rule for this type is very similar to CSN.1 + type. Except for the presence flag which is 0 in this + case. The encoded bit pattern consists of a 0 bit as + valid flag and a value part. If the element is present + (the v_xxx component is TRUE in the decoded message) + a 0 bit will be coded followed by the encoded value part. + Otherwise a 1 bit will be encoded. + Possible array types are given by melem[e_ref].repType: + 0) ' ' => {0| IE} (no array) + 1) 'i' => {0 IE} ** 1 (many repeations up to a 1 bit) + 2) 'v' => {0|1 IE}* val (val is another IE) + 3) 'c' => {0|1 IE}* 3 (3 is an example) +*/ + +SHORT cdc_csn1_s0_opt_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_s0_opt_encode()"); + #else + TRACE_CCD (globs, "cdc_csn1_s0_opt_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_csn1_sx_encode (0, e_ref, globs); +} +#endif /* !RUN_FLASH */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/csn1_s1.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,110 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : csn1_s1.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for CSN1_S1 elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +extern SHORT cdc_csn1_sx_decode (int flag, const ULONG e_ref, T_CCD_Globs *globs); +extern SHORT cdc_csn1_sx_encode (int flag, const ULONG e_ref, T_CCD_Globs *globs); + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_csn1_s1_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type CSN1 S1 element. This element + consists of a 1 bit valid flag and a value part. + Only if the valid bit is equal 1 the value part follows. + +*/ + +SHORT cdc_csn1_s1_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_s1_decode()"); + #else + TRACE_CCD (globs, "cdc_csn1_s1_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_csn1_sx_decode (1, e_ref, globs); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_csn1_s1_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type CSN1 S1 element. This element + consists of a 1 bit valid flag and a value part. If the + element is valid (the v_xxx components is TRUE in the + decoded message) a 1 bit will be coded followed by the + coding of the value part. Otherwise a 0 bit will be + coded. + +*/ + +SHORT cdc_csn1_s1_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_s1_encode()"); + #else + TRACE_CCD (globs, "cdc_csn1_s1_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_csn1_sx_encode (1, e_ref, globs); +} +#endif /* !RUN_FLASH */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/csn1_s1_opt.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,114 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : csn1_s1_opt.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for CSN1_S1 elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +extern SHORT cdc_csn1_sx_decode (int flag, const ULONG e_ref, T_CCD_Globs *globs); +extern SHORT cdc_csn1_sx_encode (int flag, const ULONG e_ref, T_CCD_Globs *globs); + +#ifndef RUN_FLASH +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_csn1_s1_opt_decode | ++------------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type CSN1 S1 element. This element + consists of a 1 bit valid flag and a value part. + Only if the valid bit is equal 1 the value part follows. + + The element value can be present, then it is preceded by the + flag value 0. If the element is represented by the flag 1 only + the value is absent! Besides the absence of the whole element + is allowed. +*/ + +SHORT cdc_csn1_s1_opt_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_s1_opt_decode()"); + #else + TRACE_CCD (globs, "cdc_csn1_s1_opt_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_csn1_sx_decode (1, e_ref, globs); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_csn1_s1_opt_encode | ++------------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type CSN1 S1 element. This element + consists of a 1 bit valid flag and a value part. If the + element is valid (the v_xxx components is TRUE in the + decoded message) a 1 bit will be coded followed by the + coding of the value part. Otherwise a 0 bit will be + coded. + +*/ + +SHORT cdc_csn1_s1_opt_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_s1_opt_encode()"); + #else + TRACE_CCD (globs, "cdc_csn1_s1_opt_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_csn1_sx_encode (1, e_ref, globs); +} +#endif /* !RUN_FLASH */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/csn1_sh.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,112 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : csn1_sh.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for CSN1_SH elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + + +extern SHORT cdc_csn1_sx_decode (int flag, const ULONG e_ref, T_CCD_Globs *globs); +extern SHORT cdc_csn1_sx_encode (int flag, const ULONG e_ref, T_CCD_Globs *globs); + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_csn1_shl_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type CSN1 SHL element. This element + consists of a 1 bit valid flag and a value part. + Only if the valid bit is equal H the value part follows. + +*/ + +SHORT cdc_csn1_shl_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_shl_decode()"); + #else + TRACE_CCD (globs, "cdc_csn1_shl_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_csn1_sx_decode (0xFF, e_ref, globs); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_csn1_shl_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type CSN1 SHL element. This element + consists of a 1 bit valid flag and a value part. If the + element is valid (the v_xxx components is TRUE in the + decoded message) a H bit will be coded followed by the + coding of the value part. Otherwise a L bit will be + coded. + +*/ + +SHORT cdc_csn1_shl_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_shl_encode()"); + #else + TRACE_CCD (globs, "cdc_csn1_shl_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_csn1_sx_encode (0xFF, e_ref, globs); +} +#endif /* !RUN_FLASH */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/csn1_sh_opt.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,122 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : csn1_sh_opt.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for CSN1_SH_OPT +| elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + + +extern SHORT cdc_csn1_sx_decode (int flag, const ULONG e_ref, T_CCD_Globs *globs); +extern SHORT cdc_csn1_sx_encode (int flag, const ULONG e_ref, T_CCD_Globs *globs); + +#ifndef RUN_FLASH +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_csn1_shl_opt_decode | ++------------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type CSN1 SHL OPT element. + This coding type enhances the GSM Type CSN1 SHL. It supports + previous behaviour of CSN1_SHL and the lack of the whole + element. + The coding type CSN1_SHL_OPT is suitable for elements which + structures match to the following common definition: + { null | L | H { 0 | 1 < value part > } + + The element value can be present, then it is preceded by the + flag value H. If the element is represented by the flag L only + the value is absent! Besides the absence of the whole element + is allowed. +*/ + +SHORT cdc_csn1_shl_opt_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_shl_opt_decode()"); + #else + TRACE_CCD (globs, "cdc_csn1_shl_opt_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_csn1_sx_decode (0xFF, e_ref, globs); +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_csn1_shl_opt_encode | ++------------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type CSN1 SHL OPT element doesn't differ + from encoding of the GSM Type CSN1 SHL. + This element consists of a 1 bit valid flag and a value part. + If the element is valid (the v_xxx components is TRUE in the + decoded message) a H bit will be coded followed by the + coding of the value part. Otherwise a L bit will be + coded. + +*/ + +SHORT cdc_csn1_shl_opt_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_shl_opt_encode()"); + #else + TRACE_CCD (globs, "cdc_csn1_shl_opt_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_csn1_sx_encode (0xFF, e_ref, globs); +} +#endif /* !RUN_FLASH */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/csn1_sx.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,687 @@ +/* ++----------------------------------------------------------------------------- +| Project : CCD +| Modul : csn1_sx.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for CSN1_S0 elements ++----------------------------------------------------------------------------- +*/ +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +/* + * Need memory allocation functions for dynamic arrays (pointers) + */ +#ifdef DYNAMIC_ARRAYS +#include "vsi.h" +#include <string.h> +#endif + + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_csn1_sx_decode | ++--------------------------------------------------------------------+ + + PURPOSE : The encoded IE consists of one bit for presence flag and + a value part. + In case of CSN1_S1 only if the flag bit is equal 1 the + value part will follow it. + In case of CSN1_S0 only if the flag bit is equal 0 the + value part will follow it. +*/ + +SHORT cdc_csn1_sx_decode (int flag, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat, max_rep, act_offset; + ULONG amount = 1; + BOOL is_variable; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; +#ifdef DYNAMIC_ARRAYS + U8 *old_pstruct = NULL; + U8 *addr = NULL; +#endif + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_sx_decode()"); + #else + TRACE_CCD (globs, "cdc_csn1_sx_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + globs->SeekTLVExt = FALSE; + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * If this element is conditional, check the condition. + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + /* + * If this element has a defined prologue + * we have to process it before decoding the bitstream. + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + if (melem[e_ref].repType NEQ ' ') + { + is_variable = ccd_calculateRep (e_ref, &repeat, &max_rep, globs); + /* Structured IE is to be handeled as bitstring.*/ + if (melem[e_ref].repType == 's') + { + repeat--; + } + } + else + { + is_variable = FALSE; + repeat = 1; + } + +#ifdef DYNAMIC_ARRAYS + /* + * Check for pointer types; allocate memory if necessary. + * May overwrite globs->pstruct (and initialize globs->pstructOffs to 0). + */ + if ( is_pointer_type(e_ref) ) + { + U32 cSize; + + /* + * Find size to allocate; + * - Read from mcomp or mvar according to type + */ + cSize = (ULONG)((melem[e_ref].elemType EQ 'F' OR + melem[e_ref].elemType EQ 'R') + ? mvar[melem[e_ref].elemRef].cSize + : mcomp[melem[e_ref].elemRef].cSize + ) * repeat; + + /* + * Allocate additional memory + */ + addr = (U8 *)DP_ALLOC( cSize, globs->alloc_head, DP_NO_FRAME_GUESS); + + /* If no memory, log error and return immediately */ + if (addr EQ NULL) { + ccd_setError (globs, ERR_NO_MEM, + BREAK, + (USHORT) -1); + return 1; + } + else + memset (addr, 0, (size_t)cSize); + + /* + * Memory allocated; + */ + } +#endif + + if (melem[e_ref].elemType NEQ 'S') + { + /* + * Element is not a SPARE. Setup the struct pointer. + */ + globs->pstructOffs = melem[e_ref].structOffs; + + + if (is_variable) + { + UBYTE *addr_v_xxx = NULL; + UBYTE *addr_c_xxx; + UBYTE act_continue_array; + + + if (melem[e_ref].optional) + { + /* + * For optional elements we must set the valid-flag, + * if there is at least one element in the message. + * Therefore we store the address of the valid flag. + */ + /* Dynamic array addition. + * Postpone optional flag setting for non-code transparent + * pointer types ('P', 'Q', 'R'). + * For these types, the optional flag is the pointer itself. + * These types cannot be set yet, as the pointer may be + * preceeded by a counter octet, a union tag id octet etc. + */ + if (melem[e_ref].elemType < 'P' OR melem[e_ref].elemType > 'R') + addr_v_xxx = (UBYTE *) (globs->pstruct + globs->pstructOffs++); + } + /* + * For variable sized elements store the min-value + * as counter into the C-Structure (c_xxx). + */ + addr_c_xxx = (UBYTE *) (globs->pstruct + globs->pstructOffs++); + if (max_rep > 255) + globs->pstructOffs++; + + /* + * Store the initial offset + */ + + act_offset = (ULONG) globs->pstructOffs; + +#ifdef DYNAMIC_ARRAYS + if ( is_pointer_type(e_ref) ) + { + /* + * 1. Save old "globs->pstruct" variables + * 2. Store pointer to freshly allocated memory area in structure + * 3. Initialize pstruct to point to the freshly allocated memory area. + * 4. Initialize pstructOffs to 0 to start decoding at offset 0 + * in the new memory area. + */ + old_pstruct = globs->pstruct; + *(U8 **)(globs->pstruct + globs->pstructOffs) = addr; + globs->pstruct = addr; + globs->pstructOffs = 0; + } +#endif + + /* + * repType ='i': + * Repeat this element (if it is an array) until we detect a + * flag indicating absence. + * + * repType ='v' and 'c': + * Repeat the IE and leave the loop. + * + * In both cases we expect a 0 at first. + */ + if ((melem[e_ref].repType == 'v') || (melem[e_ref].repType == 'c')) + { + amount = repeat; + } + repeat = 0; + act_continue_array = globs->continue_array; + globs->continue_array = TRUE; + + while (globs->continue_array) + { + if (flag == 0xFF) /* CSN1_SH type*/ + { + if (bf_readBit(globs) != GET_HL_PREV(1)) + break; + } + else + { + if (bf_readBit(globs) != flag) + break; + } + /* + * Flag is set, we must decode the element + */ + + cdc_decodeElemvalue (e_ref, &amount, globs); + + if (++repeat > max_rep) + { + /* + * Too many repetitions means error in encoded message. + */ + ccd_setError (globs, ERR_MAX_REPEAT, + BREAK, + (USHORT) (globs->bitpos), + (USHORT) -1); + return 1; + } + else if (melem[e_ref].repType EQ 'v') + { + repeat = amount; + break; + } + /* + * Recalculate the struct offset for repeatable IEs. + */ + if (is_variable_type(e_ref)) + { + globs->pstructOffs = (USHORT)(act_offset + + (repeat * mvar[melem[e_ref].elemRef].cSize)); + } + else + { + globs->pstructOffs = (USHORT)(act_offset + + (repeat * mcomp[melem[e_ref].elemRef].cSize)); + } + } + globs->continue_array = act_continue_array; + +#ifdef DYNAMIC_ARRAYS + /* + * Restore globs->pstruct + */ + if (old_pstruct NEQ NULL) + { + globs->pstruct = old_pstruct; + } +#endif + + if (addr_v_xxx NEQ NULL) + { + /* + * For optional elements set the valid-flag + * In this case the pointer addr_c_xxx does not mark + * the counter. It points to the valid flag. + */ + if (repeat > 0) + *addr_v_xxx++ = (UBYTE) TRUE; + } + /* + * Store the number of digits into the c_xxx variable if there is one. + */ + if (max_rep > 65535) + { + ULONG *addr_c_xxx_u32; + addr_c_xxx_u32 = (ULONG *)addr_c_xxx; + *addr_c_xxx_u32 = repeat; + } + else if (max_rep > 255) + { + USHORT *addr_c_xxx_u16; + addr_c_xxx_u16 = (USHORT *)addr_c_xxx; + *addr_c_xxx_u16 = (USHORT) repeat; + } + else + *addr_c_xxx = (UBYTE) repeat; + } + /* + * IE is not defined as an array. + */ + else + { + BOOL elemPresent; + + if (flag == 0xFF) + elemPresent = (bf_readBit(globs) EQ GET_HL_PREV(1)); + else + elemPresent = (bf_readBit(globs) == flag); + + if (elemPresent) + { + if (melem[e_ref].optional) + { + /* + * For optional elements set the valid-flag. + */ + globs->pstruct[globs->pstructOffs++] = (UBYTE) TRUE; + } + + /* + * Flag is set, we must decode the element. + */ + cdc_decodeElemvalue (e_ref, &repeat, globs); + /* + * process the epilogue expression for this element if there is any + */ + if (num_prolog_steps) + { + if ( (calc[prolog_step_ref+1].operation EQ 'K') + || (calc[prolog_step_ref+1].operation EQ 'C') + || (calc[prolog_step_ref+1].operation EQ 's')) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + } + } + } + } + + return 1; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_csn1_sx_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the CSN1 element. + 1) GSM Type CSN1 S1 element + This element consists of a 1 bit valid flag and a + value part. If the element is valid (the v_xxx + components is TRUE in the decoded message) a 1 bit will + be coded followed by the coding of the value part. + Otherwise a 0 bit will be coded. + + 2) GSM Type CSN1 S0 element + This element consists of a single bit valid flag and a + value part, too. But in this case the presence flag is + set to 0. If the element is present (the v_xxx component + is TRUE in the decoded message) a 0 bit will be coded + followed by the encoded value part. Otherwise a 1 bit + will be encoded. +*/ + +SHORT cdc_csn1_sx_encode (int flag, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG i, repeat=1, amount=1; + USHORT cSize = 0, startOffset; + int elemPresent; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; +#ifdef DYNAMIC_ARRAYS + U8 *old_pstruct = NULL; +#endif + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_csn1_sx_encode()"); + #else + TRACE_CCD (globs, "cdc_csn1_sx_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + /* + * If this element is conditional, check the condition. + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + /* + * If this element has a defined prologue + * we have to process it before decoding the bitstream. + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + if (melem[e_ref].elemType NEQ 'S') + { + UBYTE act_continue_array; + + act_continue_array = globs->continue_array; + globs->continue_array = TRUE; + /* + * Element is not a SPARE. + * Setup the offset into the C-structure for this element + */ + globs->pstructOffs = melem[e_ref].structOffs; + + if (melem[e_ref].optional) + { + /* + * For optional elements check the valid-flag in the C-struct. + * Spare elements does not have a corresponding valid flag. + */ + /* Dynamic array addition. + * Postpone optional flag setting for non-code transparent + * pointer types ('P', 'Q', 'R'). + * For these types, the optional flag is the pointer itself. + * These types cannot be set yet, as the pointer may be + * preceeded by a counter octet, a union tag id octet etc. + */ + if (melem[e_ref].elemType < 'P' OR melem[e_ref].elemType > 'R') + { + if (globs->pstruct[globs->pstructOffs++] == FALSE) + { + /* + * The IE should not be present in the message so we code + * a single bit + * for CSN1_S1 as 0, + * for CSN1_S0 as 1 and + * for CSN1_SH as GET_HL(0) + */ + if (flag == 0xFF) + elemPresent = GET_HL(0); + else + elemPresent = flag ^ 0x00000001; + bf_writeBit (elemPresent, globs); + return 1; + } +#ifdef DEBUG_CCD + else if (globs->pstruct [melem[e_ref].structOffs] != TRUE) + { + TRACE_CCD (globs, "Ambiguous value for valid flag!\n...assumed 1 for ccdID=%d", + e_ref); + } +#endif + } + } + + /* As a default amount =1 due to initialization. */ + if (melem[e_ref].repType EQ 'i') + { + /* The actual number of elements belonging to the array is unknown. + * The user should have written the desired number to the C-Structure + * (c_xxx). CCD reads the number of these variable repeatable elements + * out of this C-Structure (c_xxx) and encodes each element with a + * preceeding bit set to '0'. The last element is followed by a bit + * set to '1' to indicate the end of this array. + * If the number of repeats given by the C-Structure exceeds the + * allowed value (maxRepeat) CCD gives a warning! + */ + if (melem[e_ref].maxRepeat > 255) + { + ULONG count = (ULONG) (* (USHORT *)(globs->pstruct + globs->pstructOffs++)); + repeat = MINIMUM (count, (ULONG) melem[e_ref].maxRepeat); + if (repeat < count) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + else + { + repeat = (ULONG) MINIMUM (globs->pstruct[globs->pstructOffs], + melem[e_ref].maxRepeat); + if ( repeat < (ULONG) (globs->pstruct[globs->pstructOffs]) ) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + amount = 1; + globs->pstructOffs++; + } + else + if (melem[e_ref].repType EQ 'v') + { + /* The number of elements belonging to the array depends on the value + * of another element. The user should have written this number to the + * C-Structure (c_xxx). + * CCD reads the number of these variable repeatable elements out of + * this C-Structure (c_xxx). + * If the number of repetitions given by the C-Structure exceeds the + * allowed value (maxRepeat) CCD gives a warning! + */ + if (melem[e_ref].maxRepeat > 255) + { + ULONG count = (ULONG) (* (USHORT *)(globs->pstruct + globs->pstructOffs++)); + amount = MINIMUM (count, (ULONG) melem[e_ref].maxRepeat); + if (amount < count) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + else + { + amount = (ULONG)MINIMUM (globs->pstruct[globs->pstructOffs], + melem[e_ref].maxRepeat); + if ( amount < (ULONG) (globs->pstruct[globs->pstructOffs]) ) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + repeat = 1; + globs->pstructOffs++; + } + else + if (melem[e_ref].repType EQ 'c') + { + amount = (ULONG) melem[e_ref].maxRepeat; + repeat = 1; + } + else + if (melem[e_ref].repType == 's') + { + BOOL is_variable; + ULONG max_rep; + + is_variable = ccd_calculateRep (e_ref, &repeat, &max_rep, globs); + /* Substract one bit which will be spent on the (CSN.1) flag. */ + amount = repeat - 1; + repeat = 1; + } + if (melem[e_ref].repType EQ 'v' OR melem[e_ref].repType EQ 'i') + { + cSize = (USHORT)((melem[e_ref].elemType EQ 'V' OR + melem[e_ref].elemType EQ 'R' OR melem[e_ref].elemType EQ 'F') + ? mvar[melem[e_ref].elemRef].cSize + : mcomp[melem[e_ref].elemRef].cSize + ); + + startOffset = (USHORT) globs->pstructOffs; + } + + /* Dynamic array addition. + * Check for non-code transparent pointer types ('P', 'Q', 'R'). + * For these types, the optional flag is the pointer itself. + * ASSUMPTION: The pointer may be preceeded by a counter octet, + * a union tag id octet etc., but it is up to CCDGEN to ensure + * word alignment (by inserting alignment bytes). Therefore + * we just read from globs->pstruct[globs->pstructOffs]. + */ +#ifdef DEBUG_CCD + /* Check pointer alignment and re-align if necessary (should never happen) */ + if ( is_pointer_type(e_ref) AND ((globs->pstructOffs & 3) NEQ 0)) { + TRACE_CCD (globs, "cdc_csn1_sx_encode(): Pointer misaligned! pstruct=0x08x," + " pstructOffs=0x%08x", globs->pstruct, globs->pstructOffs); + globs->pstructOffs = (globs->pstructOffs + 3) & 3; + } +#endif +#ifdef DYNAMIC_ARRAYS + /* + * Perform pointer dereference for pointer types. + * Also, check optionality for these types. + */ + if ( is_pointer_type(e_ref) ) { + U8 *deref_pstruct; + + /* Get pointer value */ + deref_pstruct = *(U8 **)&globs->pstruct[globs->pstructOffs]; + + /* + * Strictly speaking the 'D' to 'F' types should not need this + * check (should have returned after the optionality check above), + * but it will catch stray NULL pointers (or uninitialized + * valid flags) + */ + if (ccd_check_pointer(deref_pstruct) != ccdOK ) + { + ccd_recordFault (globs, ERR_INVALID_PTR, BREAK, (USHORT) e_ref, + &globs->pstruct[globs->pstructOffs]); + return 1; + } + /* + * Pointer not NULL; + * 1. Save old globs->pstruct and assign pointer to globs->pstruct + * as new base. + * 2. Set pstructOffs to 0 (zero) as the next offset will start + * in the new memory area. + */ + old_pstruct = globs->pstruct; + globs->pstruct = deref_pstruct; + startOffset = 0; + } +#endif /* DYNAMIC_ARRAYS */ + + for (i=0; i < repeat; i++) + { + /* + * The IE should be present in the message so we code 0 bit. + */ + if (flag == 0xFF) + elemPresent = GET_HL(1); + else + elemPresent = flag; + + bf_writeBit (elemPresent, globs); + if (cSize) + { + /* + * Calculate the offset if it is an array. + */ + globs->pstructOffs = (USHORT)(startOffset + (i * cSize)); + } + /* + * Encode the value. + */ + cdc_encodeElemvalue (e_ref, amount, globs); + } + +#ifdef DYNAMIC_ARRAYS + if ( old_pstruct NEQ NULL ) + globs->pstruct = old_pstruct; +#endif + + if ((melem[e_ref].repType == 'i') && (globs->continue_array == TRUE)) + { + /* + * For fields of variable length we code a 1 flag + * to mark the end of the array. + */ + if (flag == 0xFF) + elemPresent = GET_HL(0); + else + elemPresent = flag ^ 0x00000001; + bf_writeBit (elemPresent, globs); + } + globs->continue_array = act_continue_array; + } + + return 1; +} +#endif /* !RUN_FLASH */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/fdd_ci.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,210 @@ +/* ++----------------------------------------------------------------------------- +| Project : CCD +| Modul : fdd_ci.c ++----------------------------------------------------------------------------- +| Copyright 2004 Texas Instruments Deutschland GmbH +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Deutschland GmbH +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Deutschland GmbH. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for FDD_CI type ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +/* + * Function prototypes of CCD-CCDDATA interface + */ +#include "ccddata.h" + + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" +#include "bitfun.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" + +#if !(defined (CCD_TEST)) +#include "vsi.h" +#endif + +#ifndef RUN_INT_RAM +/* Attention: static data, only used in cdc_fdd_ci_decode */ +static const U8 params_bSize[17] = +{ + 0, + 10, + 19, 28, + 36, 44, 52, 60, + 67, 74, 81, 88, 95, 102, 109, 116, + 122 +}; +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD MODULE : cdc_fdd_ci_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the FDD_CELL_INFORMATION Field reusing + RANGE 1024 format of frequency list information. + The IE is preceded by FDD_Indic0(1 bit) and made of the + following two IEs: + 1) NR_OF_FDD_CELLS(5 bit field), + 2) FDD_CELL_INFORMATION information parameters + + FDD_Indic0 indicates if the parameter value '0000000000' + is a member of the set. + + FDD_CELL_INFORMATION or "Scrambling Codes and Diversity + Field" is a bit filed of length + p(Number_of_Scrambling_Codes_and_Diversity), + whereas the function p(x) is defined by the table below + with n = Number_of_Scrambling_Codes_and_Diversity. + n p n p n p n p + 0 0 5 44 10 81 15 116 + 1 10 6 52 11 88 16 122 + 2 19 7 60 12 95 17-31 0 + 3 28 8 67 13 102 + 4 36 9 74 14 109 + + The message is sent from net to MS and a MS supporting + enhanced measurements has to understand it. + + The space this IE takes in the C-structure is made of a + counter for the number of decoded parameter and an array + of them. +*/ + +SHORT cdc_fdd_ci_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + U8 ListSize = 0; + U16 ListBitLen = 0; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + short *w; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "cdc_fdd_ci_decode()"); +#ifdef CCD_SYMBOLS + TRACE_CCD (globs, "decoding list %s with range 1024 format", + ccddata_get_alias((USHORT) e_ref, 1)); +#else + TRACE_CCD (globs, "decoding elem %d with range 1024 format", melem[e_ref].elemRef); +#endif +#endif + + globs->SeekTLVExt = FALSE; + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * if this element have a defined Prolog + * we have to process it before decoding the bitstream + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + /* + * First read NR_OF_FDD_CELLS (5 bits). + */ + globs->pstructOffs = melem[e_ref].structOffs;; + bf_readBits (5, globs); + ListSize = globs->pstruct[globs->pstructOffs++]; + + /* If n=0 there is nothing to do for this IE. */ + if (!ListSize) + { + return 1; + } + + /* Read the corresponding bit number or suppose the maximum length. */ + if (ListSize <= 16) + { + ListBitLen = params_bSize [ListSize]; + } + else + { + /* If n>17 there is nothing to do for this IE. */ + return 1; + } + /* + * Bit size for params is bigger than the size of unread bits in the + * message buffer. Danger: buffer overwriting! + */ + if ( ListBitLen > globs->maxBitpos - globs->bitpos) + { + ccd_recordFault (globs, ERR_ELEM_LEN, BREAK, (USHORT) e_ref, + globs->pstruct + globs->pstructOffs); + ListBitLen = (U16)(globs->maxBitpos - globs->bitpos); + } + + /* + * Use dynamic memory for calculation instead of global memory or stack. + */ + MALLOC (w, 257 * sizeof (U16)); + + /* Decode the W-parameter. */ + cdc_decode_param (param_1024, w, ListBitLen, globs); + + /* + * Decode and set the remaining channel number according the + * algorithm described in GSM 4.08. + */ + cdc_decode_frequencies (1023, &w[0], 0, FDD_CI_LIST, globs); + + /* Free the dynamic allocated memory. */ + MFREE (w); + + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD MODULE : cdc_fdd_ci_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding function is not needed, since this message is + sent only from net to MS. + It could be only useful for testing procedure if there + were an encoder function at this place. + This will be a future work. +*/ + +SHORT cdc_fdd_ci_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "cdc_fdd_ci_encode()"); +#endif +#ifdef TARGET_WIN32 + /* TBD */ +#endif + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/freq_list.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,500 @@ +/* ++----------------------------------------------------------------------------- +| Project : CCD +| Modul : freq_list.c ++----------------------------------------------------------------------------- +| Copyright 2004 Texas Instruments Deutschland GmbH +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Deutschland GmbH +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Deutschland GmbH. ++----------------------------------------------------------------------------- +| Purpose : Definition of decoding function for FREQ_LIST type ++----------------------------------------------------------------------------- +*/ + +#define FREQ_LIST_C + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +#include "string.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +/* + * Function prototypes of CCD-CCDDATA interface + */ +#include "ccddata.h" + + +#if !(defined (CCD_TEST)) +#include "vsi.h" +#endif + +#ifndef RUN_INT_RAM +/* + * Attention: in this file all static and global functions as well as + * the static data are controlled by one RUN_.. clause. + * The static data and functions are currently only used in the decode + * function, whereas encoding is not yet available. + */ +static U16 first; +static U16 last; +static U16 num; + + +/* + * The W-parameter in the 256 range start from bit 7 of the + * information element. The following table indicate the number + * of W-parameters and their length in bits. A length of zero + * indicated the end of the table. + */ +static const T_W_PARAM param_256[10] = +{ + /* + * length count + */ + 10, 1, + 8, 1, + 7, 2, + 6, 4, + 5, 8, + 4, 16, + 3, 32, + 2, 64, + 1, 128, + 0, 0 +}; + +/* + * The W-parameter in the 128 range start from bit 7 of the + * information element. The following table indicate the number + * of W-parameters and their length in bits. A length of zero + * indicated the end of the table. +*/ + +static const T_W_PARAM param_128[9] = +{ + /* + * length count + */ + 10, 1, + 7, 1, + 6, 2, + 5, 4, + 4, 8, + 3, 16, + 2, 32, + 1, 64, + 0, 0 +}; + +/* + * Compare results of the first channel with those of the others + * to find the dimensions. + */ +static void completeAddInfo (U8 *BitmapInStruct) +{ + *(U16*) (BitmapInStruct - 2) += num; + if (*(U16*) (BitmapInStruct - 6) > first) + *(U16*) (BitmapInStruct - 6) = first; + if (*(U16*) (BitmapInStruct - 4) < last) + *(U16*) (BitmapInStruct - 6) = last; +} + +static void setFirstChanNr (U8 *BitmapInStruct, short w0) +{ + U16 bitposition; + bitposition = (w0 == 0) ? 0 : (U16)(BITOFFSET_LIST - w0); + BitmapInStruct[bitposition >> 3] |= ByteBitMask[bitposition & 7]; + first = bitposition; + last = bitposition; + num = 1; +} +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD MODULE : cdc_freq_list_decode | ++--------------------------------------------------------------------+ + PURPOSE : The function creates a frequency hopping list from one of + the following information elements according GSM 4.08: + + cell channel description + frequency list + frequency short list + neighbour cell description + + The format identifier of the information element is defined as: + + FORMAT-ID, Format Identifier + + Bit Bit Bit Bit Bit format notation + 8 7 4 3 2 + + 0 0 X X X bit map 0 + 1 0 0 X X 1024 range + 1 0 1 0 0 512 range + 1 0 1 0 1 256 range + 1 0 1 1 0 128 range + 1 0 1 1 1 variable bit map + + The space this IE takes in the C-structure is depicted in the + example below: + typedef struct + { + U16 first; + U16 last; + U16 num; + U8 bitmap[128]; + } BMP_arfcn_list; + + The member bitmap stores a list of frequencies in a range of + 0 - 1023 (GSM), where some of the frequencies are not yet used. +*/ + +SHORT cdc_freq_list_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + U8 *FirstByte = globs->bitbuf + globs->bytepos; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "cdc_freq_list_decode()"); +#ifdef CCD_SYMBOLS + TRACE_CCD (globs, "decoding list %s with range 1024 format", + ccddata_get_alias((USHORT) e_ref, 1)); +#else + TRACE_CCD (globs, "decoding list %d of range 1024 format", melem[e_ref].elemRef); +#endif +#endif + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * if this element have a defined Prolog + * we have to process it before decoding the bitstream + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + globs->SeekTLVExt = FALSE; + globs->pstructOffs = melem[e_ref].structOffs; + + /* + * Bitmap 0 format + * only for GSM 900 or GSM 850 bands !!!! + * std = STD_900, STD_EGSM, STD_DUAL, STD_DUAL_EGSM, STD_850, STD_DUAL_US + * No check of std for being PCS 1900 or DCS 1800 is implemented. + */ + if ((*FirstByte & 0x80) == 0) + { + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "bitmap 0 format"); +#endif + /* + * Copy only the first 16 bytes. According to section 10.5.2.1b.2 of + * GSM04.08, 124 bits are dedicated to ARFCN and two bits to the Format-ID. + * Two bits are spare. + */ + FirstByte = globs->pstruct + globs->pstructOffs; + /* first bit */ + *(U16 *) FirstByte = 896;//T_LIST_MAX_SIZE - 16; + /* last bit */ + *(U16 *) (FirstByte+2) = T_LIST_MAX_SIZE; + /* number of entries */ + *(U16 *) (FirstByte+4) = 124; + memcpy (FirstByte + T_LIST_MAX_SIZE - 10, //FirstByte + 6 + T_LIST_MAX_SIZE - 16, + globs->bitbuf + globs->bytepos, 16); + } + else + { + U16 ListLength = mvar[melem[e_ref].elemRef].bSize; + U8 *BitmapInStruct = globs->pstruct + globs->pstructOffs; + first = 0; + last = 0; + num = 0; + /* + * RANGE 128, + */ + if ((*FirstByte & 0x8E) == 0x8C) + { + /* + * Use dynamic memory for calculation instead of global memory or stack. + */ + short *w; + MALLOC (w, 129 * sizeof (U16)); + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "range 128 format"); +#endif + + /* + * The algorithm for several ranges is the same with different + * tables. The W-parameter start with bit 7. Skip over offset. + */ + bf_incBitpos (7, globs); + cdc_decode_param (param_128, w, ListLength, globs); + + /* + * W[0] contains the first channel number + */ + setFirstChanNr (BitmapInStruct, w[0]); + + /* + * Decode and set the remaining channel number according the + * algorithm described in GSM 4.08. + */ + cdc_decode_frequencies (127, &w[1], w[0], FREQUENCY_LIST, globs); + completeAddInfo (BitmapInStruct); + + /* + * free the dynamic allocated memory. + */ + MFREE (w); + } + /* + * RANGE 256 + */ + if ((*FirstByte & 0x8E) == 0x8A) + { + /* + * Use dynamic memory for calculation instead of global memory or stack. + */ + short *w; + MALLOC (w, 257 * sizeof (U16)); + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "range 256 format"); +#endif + + /* + * Decode the W-parameter. The W-parameter start with bit 7. + */ + bf_incBitpos (7, globs); + cdc_decode_param (param_256, w, ListLength, globs); + + /* + * W[0] contains the first channel number + */ + setFirstChanNr (BitmapInStruct, w[0]); + + /* + * decode and set the remaining channel number according the + * algorithm described in GSM 4.08. + */ + cdc_decode_frequencies (255, &w[1], w[0], FREQUENCY_LIST, globs); + completeAddInfo (BitmapInStruct); + + /* + * free the dynamic allocated memory. + */ + MFREE (w); + } + /* + * RANGE 512 + */ + if ((*FirstByte & 0x8E) == 0x88) + { + /* + * Use dynamic memory for calculation instead of global memory or stack. + */ + short *w; + MALLOC (w, 257 * sizeof (U16)); + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "range 512 format"); +#endif + + /* + * the algorithm for the several ranges is the same with different + * tables. The W-parameter start with bit 7. Skip over offset. + */ + bf_incBitpos (7, globs); + cdc_decode_param (param_512, w, ListLength, globs); + + /* + * W[0] contains the first channel number + */ + setFirstChanNr (BitmapInStruct, w[0]); + + /* + * decode and set the remaining channel number according the + * algorithm described in GSM 4.08. + */ + cdc_decode_frequencies (511, &w[1], w[0], FREQUENCY_LIST, globs); + completeAddInfo (BitmapInStruct); + + /* + * free the dynamic allocated memory. + */ + MFREE (w); + } + + if ((*FirstByte & 0x88) == 0x80) + { + /* + * RANGE 1024 + * + * Use dynamic memory for calculation instead of global memory or stack. + */ + U8 f0; + U8 offset; + + short *w; + MALLOC (w, 257 * sizeof (U16)); + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "range 1024 format"); +#endif + + /* + * Get the f0 indicator. It indicates whether channel 0 is part + * of the frequency hopping list or not. + */ + /* The following lines are equal to: + * ccd_decodeByte (FirstByte, (U16)(globs->byteoffs+5), 1, &f0); + */ + offset = globs->byteoffs+5; + if (offset < 8) + { + f0 = FirstByte[0] << offset; + f0 &= 0x80; + } + else + { + U16 tmpvar; + tmpvar = *(U16*) FirstByte; + tmpvar <<= offset; + f0 = tmpvar & 0x8000; + } + + /* + * The algorithm for the several ranges is the same with different + * tables. The W-parameter start with bit 6. Skip over offset. + */ + bf_incBitpos (6, globs); + cdc_decode_param (param_1024, w, ListLength, globs); + + /* + * If indicated add channel 0 to the list + */ + if (f0) + { + /* The following is equal to setFirstChanNr(0); */ + BitmapInStruct[0] |= 0x80; + num = 1; + } + + /* + * decode and set the remaining channel number according the + * algorithm described in GSM 4.08. + */ + cdc_decode_frequencies (1023, &w[0], 0, FREQUENCY_LIST, globs); + completeAddInfo (BitmapInStruct); + + /* + * free the dynamic allocated memory. + */ + MFREE (w); + } + /* + * RANGE variable + */ + if ((*FirstByte & 0x8E) == 0x8E) + { + /* + * The format is similar to the bitmap 0 format. The + * calculation starts from a base channel number svalue + * instead of channel number 1. + */ + U32 lvalue; + U16 svalue; + U32 i; + U16 bitposition; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "range variable format"); +#endif + + /* Get the first channel number. */ + bf_incBitpos (7, globs); + lvalue = bf_getBits (10, globs); + + /* Copy lvalue to svalue to set the correct channel. */ + svalue = (U16)lvalue; + setFirstChanNr (BitmapInStruct, svalue); + first = svalue; + num = 1; + for (i = 1; i < 112; i++) + { + /* + * Get the value of the next bit. + * If the bit is set, set channel i+svalue + */ + if (bf_readBit (globs)) + { + U16 channel = (U16)for_modulo(i+svalue, 1024); + + bitposition = (channel == 0) ? 0 : (U16)(BITOFFSET_LIST - channel); + BitmapInStruct[bitposition >> 3] |= ByteBitMask[bitposition & 7]; + last = bitposition; + num++; + } + } + completeAddInfo (BitmapInStruct); + } + } + + return 1; +} + +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD MODULE : cdc_freq_list_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding function is not needed, since this message is + sent from net to MS. + It could be only useful for testing procedure if there + were an encoder function at this place. + This will be a future work. +*/ + +SHORT cdc_freq_list_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "cdc_freq_list_encode()"); +#endif +#ifdef TARGET_WIN32 + /* TBD */ +#endif + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/freq_list_com.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,421 @@ +/* ++----------------------------------------------------------------------------- +| Project : CCD +| Modul : freq_list_com.c ++----------------------------------------------------------------------------- +| Copyright 2004 Texas Instruments Deutschland GmbH +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Deutschland GmbH +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Deutschland GmbH. ++----------------------------------------------------------------------------- +| Purpose : Definitions of common functions for decoding of types FDD_CI, +| TDD_CI and FREQ_LIST. ++----------------------------------------------------------------------------- +*/ + +#define CDC_FREQ_LIST_COM_C + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Error codes and prototypes of exported functions by CCD + */ +#include "ccdapi.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +#ifndef RUN_INT_RAM +U8 ByteBitMask[]= {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x1}; +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* + * The following table indicates the number of W-parameters and their + * length in bits. A length of zero indicates the end of the table. + * For frequency lists the W-parameter in the 1024 range starts from + * bit 6 of the information element. + */ +const T_W_PARAM param_1024[9] = +{ + /* + * length count + */ + 10, 1, + 9, 2, + 8, 4, + 7, 8, + 6, 16, + 5, 32, + 4, 64, + 3, 128, + 0, 0 +}; +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* + * The following table indicates the number of W-parameters and their + * length in bits. A length of zero indicates the end of the table. + * For frequency lists the W-parameter in the 512 range starts from + * bit 7 of the information element. + */ +const T_W_PARAM param_512[10] = +{ + /* + * length count + */ + 10, 1, + 9, 1, + 8, 2, + 7, 4, + 6, 8, + 5, 16, + 4, 32, + 3, 64, + 2, 128, + 0, 0 +}; +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* Attention for RUN_...: static function */ +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD FUNCTION : for_modulo | ++--------------------------------------------------------------------+ + + PURPOSE : A modulo calculation function. The standard C-Operator + fails for negative values! (e.g. -4 mod 6 is 2 and not 4). + +*/ + +/* static */ long for_modulo (long a, long b) +{ + long result; + + /* Use standard C-Operator for calculation. */ + result = a % b; + + /* Correct the result for negative values. */ + if (result < 0) + { + result += b; + } + + return result; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* Attention for RUN_...: static function */ +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD FUNCTION : for_smodulo | ++--------------------------------------------------------------------+ + + PURPOSE : Similar to the modulo operator, but 0 smod n is n and + not 0. Same problem for negative values with the standard + C-Operator. + +*/ +static long for_smodulo (long a, long b) +{ + long result; + + /* Use standard C-Operator for calculation. */ + result = a % b; + + /* Correct the result for negative values. */ + if (result < 0) + { + result += b; + } + + /* Special handling for result equal 0 */ + if (result EQ 0) + { + result = b; + } + + return result; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* Attention for RUN_...: static function */ +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD FUNCTION : for_get_generation | ++--------------------------------------------------------------------+ + + PURPOSE : The function calculates the greatest power of 2 of the given + value. The algorithm simply looks to the position of the + highest bit. + +*/ + +static U16 for_get_generation (U16 value) +{ + int result = 0; + int i; + + + /* Check all 16 bit positions. */ + for (i = 0; i < 16; i++) + { + /* If bit is set, store the position. */ + if (value & 1) + { + result = i + 1; + } + + /* Shift value to have the next bit for comparision. */ + value = value >> 1; + } + + /* Return the highest position. */ + return result; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD FUNCTION : cdc_decode_frequencies | ++--------------------------------------------------------------------+ + + PURPOSE : The algorithm is according GSM 4.08 Annex J. It calculates + a frequency hopping list from the W-parameter. + +*/ +void cdc_decode_frequencies (short original_range, + short *w, + short offset, + U8 callerID, + T_CCD_Globs *globs) +{ + short g; + short k; + short j; + short index; + short n; + short range; + U16 channel; + U16 bitposition; + U8 *BitmapInStruct = globs->pstruct + globs->pstructOffs; + U16 first = 0; + U16 last = BITOFFSET_LIST; + U16 num = 0; + BOOL ReadW = TRUE; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "cdc_decode_frequencies()"); +#endif + + if (callerID != TDD_CI_LIST && w[0] == 0) + ReadW = FALSE; + for (k = 1; ReadW; k++) + { + ReadW = (w[k-1] != 0) ? 1 : 0; + /* + * The next loop follows the tree from child to parent, + * from the node of index K to the root (index 1). For each iteration the + * node of index INDEX is tackled. The corresponding range is RANGE, and N + * is the value of the element in the range defined by the node. + * + * The data are set to their initial values + */ + index = k; + n = w[index-1]; + g = for_get_generation (index); + j = (1 << (g-1)); + range = original_range / j; + + while (index > 1) + { + /* + * Due to the assumption that the original range is a power of two minus one, + * the range for the parent node can be easily computed, and does not depend + * upon whether the current node is a left or right child + */ + g = for_get_generation (index); + j = (1 << (g-1)); + range = 2 * range + 1; + + /* + * Let us note J := 2 g-1 , g being the generation of node INDEX. We have J = + * GREATEST_POWER_OF_2_LESSER_OR_EQUAL_TO(INDEX). The numbering used in the tree + * is such that the nodes of index J to J + J/2 - 1 are left children, and the nodes + * of index J/2 to J+J-1 are right children. Hence an easy test to + * distinguish left and right children: + */ + if (2 * index < 3 * j) + { + /* + * The next computation gives the index of the parent node of the node of index + * INDEX, for a left child : + */ + index = index - j / 2; + + /* + * The next formula is the inverse of the renumbering appearing in the encoding + * for a left child. It gives the value of the parent node in the range defined + * by the grand-parent node: + */ + n = (short)for_smodulo (n + w[index-1] + (range-1) / 2, range); + } + else + { + /* + * The next computation gives the index of the parent node of the node of index + * INDEX, for a right child : + */ + index = index - j; + + /* + * The next formula is the inverse of the renumbering appearing in the encoding + * for a right child: + */ + n = (short)for_smodulo (n + w[index-1], range); + } + } + + /* + * Write the calculated number for non-frequency types. + * For TDD_CI and TDD_CI: offset = 0 and original_range = 1023. + */ + channel = (U16)for_modulo (n+offset, 1024); + if (callerID == FDD_CI_LIST || callerID == TDD_CI_LIST) + { + *(U16*)(globs->pstruct + globs->pstructOffs) = (U16)channel; + globs->pstructOffs += 2; + } + /* Set the calculated channel number for frequency channel list.*/ + else + { + if (channel == 0) + { + bitposition = 0; + } + else + { + bitposition = (U16)(BITOFFSET_LIST - channel); + } + if (first > bitposition) + first = bitposition; + if (last < bitposition) + last = bitposition; + num++; + BitmapInStruct[bitposition >> 3] |= ByteBitMask[bitposition & 7]; + } + } + + /* For the bitmap type print the helpful information into the structure. */ + if (callerID == FREQUENCY_LIST) + { + *(U16*) (BitmapInStruct - 6) = first; + *(U16*) (BitmapInStruct - 6) = last; + *(U16*) (BitmapInStruct - 2) = num; + } +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD FUNCTION : cdc_decode_param | ++--------------------------------------------------------------------+ + + PURPOSE : The information element contains a list of W-parameter. + The table param indicates how many W-parameter from each + length shall be inside. The function converts the bitstream + of the W-parameter to an array of W-parameter 16 bit values. + +*/ + +void cdc_decode_param (const T_W_PARAM *param, + short *w, + U16 ListLength, + T_CCD_Globs *globs) +{ + U8 end_detected = FALSE; + U16 w_index = 0; + U16 length = ListLength; + U16 act_length = param->length; + U16 act_counter = param->count; + U32 lvalue; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "cdc_decode_param()"); +#endif + + /* + * Decode values in the list until the end of the IE is detected. + */ + while (!end_detected) + { + /* + * If the length of the next W-parameter is greater than eight bits, + * use ccd_decodeLong function. For smaller length use the + * ccd_decodeByte function to extract the W-parameter from the bitstream. + */ + lvalue = bf_getBits (act_length, globs); + w[w_index++] = (short)lvalue; + + /* + * w = 0 is equal to end of list if it is not the w(0) !!! + * (The case w(0)=0 possible for frequency list, but maybe not for other + * cases this algorithm is invoked. + */ + if (w_index != 1 && w[w_index-1] == 0) + { + end_detected = TRUE; + } + + /* End of buffer is equal to end of list. */ + if (length > act_length) + { + length -= act_length; + } + else + { + end_detected = TRUE; + } + + /* Check if all w parameters of one size are read. */ + if (--act_counter == 0) + { + param++; + act_length = param->length; + act_counter = param->count; + } + /* End of parameter table */ + if ((act_length == 0) || (length < act_length)) + { + end_detected = TRUE; + } + } + + /* Add an end identifier. */ + w[w_index++] = 0; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/gsm1_asn.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,120 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : gsm1_asn.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for GSM1_ASN elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm1asn_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type ASN1 element. This element + consists of a 8 bit T component a + 8 Bit L component and a V component wich + length depends on the value of the L component. The value + of L may be coded fix as 0x80. In this case a end of + content tag must follow the V component to identify the + end of this element (implicit length) + +*/ + +SHORT cdc_gsm1asn_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + T_TLV_SORT tlv_inf; + + tlv_inf.gotTag = TRUE; + tlv_inf.gotLen = TRUE; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm1asn_decode()"); + #else + TRACE_CCD (globs, "cdc_gsm1asn_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_tlv_decode (c_ref, e_ref, &tlv_inf, globs); +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm1asn_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type ASN1 element. This element + consists of a 8 bit T component a + 8 Bit L component and a V component wich + length depends on the value of the L component. The value + of L may be coded fix as 0x80. In this case a end of + content tag must follow the V component to identify the + end of this element (implicit length) + +*/ + +SHORT cdc_gsm1asn_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm1asn_encode()"); + #else + TRACE_CCD (globs, "cdc_gsm1asn_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cdc_tlv_encode (e_ref, 8, 8, globs); + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/gsm1_tv.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,112 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : gsm1_tv.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for GSM1_TV elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER + +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm1tv_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type TV element. This element + consists of a 4 Bit T component and a V component with + max. 4 Bit length. +*/ + +SHORT cdc_gsm1tv_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + T_TLV_SORT tlv_inf; + + tlv_inf.gotTag = TRUE; + tlv_inf.gotLen = FALSE; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm1tv_decode()"); + #else + TRACE_CCD (globs, "cdc_gsm1tv_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_tlv_decode (c_ref, e_ref, &tlv_inf, globs); +} +#endif /* !RUN_INT_RAM */ + + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm1tv_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type TV element. This element + consists of a 4 Bit T component and a V component with + max. 4 Bit length. +*/ + +SHORT cdc_gsm1tv_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm1tv_encode()"); + #else + TRACE_CCD (globs, "cdc_gsm1tv_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cdc_tlv_encode (e_ref, 4, 0, globs); + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/gsm1_v.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,247 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : gsm1_v.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for GSM1_V elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm1v_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type 1V element. This element + consists of a V component with max. 4 Bit length. +*/ + +SHORT cdc_gsm1v_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + SHORT ret; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm1v_decode()"); + #else + TRACE_CCD (globs, "cdc_gsm1v_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * if this element have a defined Prolog + * we have to process it before decoding the bitstream + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + if (!globs->Swap1V_inProgress) + { + /* + * check if the next element is a GSM1V too + */ + if ((ULONG)(mcomp[c_ref].componentRef + +mcomp[c_ref].numOfComponents) > e_ref + AND (melem[e_ref].codingType EQ melem[e_ref+1].codingType + OR melem[e_ref+1].elemType EQ 'S')) + { + if (melem[e_ref+1].elemType EQ 'S') + { + /* + * if the next element is a spare then skip the next 4 bits + * do not decode the spare bits. + */ + bf_setBitpos ((globs->bitpos+4), globs); + + ret = cdc_std_decode (c_ref, e_ref, globs); + + if (ret EQ 1) + ret++; + + return ret; + } + else + { + /* + * another 1V-element follow. We have to swap the nibbles. + */ + globs->Swap1V_inProgress = TRUE; + /* + * store the akt position + */ + globs->akt1VPos = (USHORT)(globs->bitpos+4); + globs->next1VPos = globs->bitpos; + + bf_setBitpos (globs->akt1VPos, globs); + ret = cdc_std_decode (c_ref, e_ref, globs); + /* + * increment the globs->maxBitpos by 1 so the bf_endOfBitstream + * will return FALSE + */ + globs->maxBitpos++; + + return ret; + } + } + ret = cdc_std_decode (c_ref, e_ref, globs); + + } + else + { + globs->akt1VPos = globs->next1VPos; + globs->next1VPos = globs->bitpos; + + bf_setBitpos (globs->akt1VPos, globs); + + /* + * decrement the globs->maxBitpos by 1 so the bf_endOfBitstream + * will return TRUE if the bitstream ended + */ + globs->maxBitpos--; + + ret = cdc_std_decode (c_ref, e_ref, globs); + + bf_setBitpos (globs->next1VPos, globs); + + globs->Swap1V_inProgress = FALSE; + + } + return ret; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm1v_encode | ++--------------------------------------------------------------------+ + + PURPOSE : encoding of the GSM Type 1V element. This element + consists of a V component with max. 4 Bit length. +*/ + +SHORT cdc_gsm1v_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm1v_encode()"); + #else + TRACE_CCD (globs, "cdc_gsm1v_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + if (!globs->Swap1V_inProgress) + { + /* + * check if the next element is a GSM1V too + */ + if ((ULONG)(mcomp[c_ref].componentRef + +mcomp[c_ref].numOfComponents) > e_ref + AND (melem[e_ref].codingType EQ melem[e_ref+1].codingType + OR melem[e_ref+1].elemType EQ 'S')) + { + if (melem[e_ref+1].elemType EQ 'S') + { + SHORT ret; + /* + * if the next element is a spare then skip the next 4 bits + * do not code the spare bits because the bitstream is cleared. + */ + bf_setBitpos (globs->bitpos+4, globs); + + ret = cdc_std_encode (c_ref, e_ref, globs); + + if (ret EQ 1) + ret++; + + return ret; + } + else + { + /* + * another 1V-element follow. We have to swap the nibbles. + */ + globs->Swap1V_inProgress = TRUE; + /* + * store the akt position + */ + globs->akt1VPos = (USHORT)(globs->bitpos+4); + globs->next1VPos = globs->bitpos; + + bf_setBitpos (globs->akt1VPos, globs); + } + } + return cdc_std_encode (c_ref, e_ref, globs); + } + else + { + SHORT ret; + + globs->akt1VPos = globs->next1VPos; + globs->next1VPos = globs->bitpos; + + bf_setBitpos (globs->akt1VPos, globs); + + ret = cdc_std_encode (c_ref, e_ref, globs); + + bf_setBitpos (globs->next1VPos, globs); + + globs->Swap1V_inProgress = FALSE; + + return ret; + } +} +#endif /* !RUN_FLASH */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/gsm2_t.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,109 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : gsm2_t.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for GSM2_T elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm2t_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type 2T element. This element + consists only of a 8 Bit T component. + +*/ + +SHORT cdc_gsm2t_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + T_TLV_SORT tlv_inf; + + tlv_inf.gotTag = TRUE; + tlv_inf.gotLen = FALSE; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm2t_decode()"); + #else + TRACE_CCD (globs, "cdc_gsm2t_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_tlv_decode (c_ref, e_ref, &tlv_inf, globs); +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm2t_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type 2T element. This element + consists only of a 8 Bit T component. + +*/ + +SHORT cdc_gsm2t_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm2t_encode()"); + #else + TRACE_CCD (globs, "cdc_gsm2t_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cdc_tlv_encode (e_ref, 8, 0, globs); + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/gsm3_tv.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,109 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : gsm3_tv.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for GSM3_TV elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm3tv_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type 3TV element. This element + consists of a 8 Bit T component and a V component with + variable length. +*/ + +SHORT cdc_gsm3tv_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + T_TLV_SORT tlv_inf; + + tlv_inf.gotTag = TRUE; + tlv_inf.gotLen = FALSE; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm3tv_decode()"); + #else + TRACE_CCD (globs, "cdc_gsm3tv_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_tlv_decode (c_ref, e_ref, &tlv_inf, globs); +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm3tv_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type 3TV element. This element + consists of a 8 Bit T component and a V component with + variable length. +*/ + +SHORT cdc_gsm3tv_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm3tv_encode()"); + #else + TRACE_CCD (globs, "cdc_gsm3tv_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cdc_tlv_encode (e_ref, 8, 0, globs); + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/gsm3_v.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,103 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : gsm3_v.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for GSM3_V elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm3v_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type 1V element. This element + consists of a V component with min. 8 Bit length. + +*/ +SHORT cdc_gsm3v_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm3v_decode()"); + #else + TRACE_CCD (globs, "cdc_gsm3v_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_std_decode (c_ref, e_ref, globs); +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm3v_encode | ++--------------------------------------------------------------------+ + + PURPOSE : encoding of the GSM Type 3V element. This element + consists of a V component with min 8 Bit length. + +*/ + +SHORT cdc_gsm3v_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm3v_encode()"); + #else + TRACE_CCD (globs, "cdc_gsm3v_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + /* + * align the bitposition to byte boundaries + */ + return cdc_std_encode (c_ref, e_ref, globs); +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/gsm4_lv.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,111 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : gsm4_lv.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for GSM4_LV elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm4lv_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type 4LV element. This element + consists of a 8 Bit L component and a V component wich + length depends on the value of the L component. + +*/ + +SHORT cdc_gsm4lv_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + T_TLV_SORT tlv_inf; + + tlv_inf.gotTag = FALSE; + tlv_inf.gotLen = TRUE; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm4lv_decode()"); + #else + TRACE_CCD (globs, "cdc_gsm4lv_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_tlv_decode (c_ref, e_ref, &tlv_inf, globs); +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm4lv_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type 4LV element. This element + consists of a 8 Bit L component and a V component wich + length depends on the value of the L component. + +*/ + +SHORT cdc_gsm4lv_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm4lv_encode()"); + #else + TRACE_CCD (globs, "cdc_gsm4lv_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cdc_tlv_encode (e_ref, 0, 8, globs); + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/gsm4_tlv.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,113 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : gsm4_tlv.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for GSM4_TLV elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm4tlv_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type 4TLV element. This element + consists of a 8 bit T component a + 8 Bit L component and a V component wich + length depends on the value of the L component. + +*/ + +SHORT cdc_gsm4tlv_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + T_TLV_SORT tlv_inf; + + tlv_inf.gotTag = TRUE; + tlv_inf.gotLen = TRUE; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm4tlv_decode()"); + #else + TRACE_CCD (globs, "cdc_gsm4tlv_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_tlv_decode (c_ref, e_ref, &tlv_inf, globs); +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm4tlv_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type 4TLV element. This element + consists of a 8 bit T component a + 8 Bit L component and a V component wich + length depends on the value of the L component. + +*/ + +SHORT cdc_gsm4tlv_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm4tlv_encode()"); + #else + TRACE_CCD (globs, "cdc_gsm4tlv_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cdc_tlv_encode (e_ref, 8, 8, globs); + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/gsm5_tlv.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,124 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : gsm5_tlv.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for GSM5_TLV elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm5tlv_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type 5TLV element. This element + consists of a 8 bit T component a + 8 or 16 Bit L component and a V component wich + length depends on the value of the L component. + If the length is in the range 0x00-0x7f the L component + consist of one byte. For bigger length 0x80-0xff the + L component consists of two bytes. The first byte is + tied to 0x81 and the second byte contains a value in the + range 0x80 to 0xff. + + +*/ + +SHORT cdc_gsm5tlv_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + T_TLV_SORT tlv_inf; + + tlv_inf.gotTag = TRUE; + tlv_inf.gotLen = TRUE; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm5tlv_decode()"); + #else + TRACE_CCD (globs, "cdc_gsm5tlv_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_tlv_decode (c_ref, e_ref, &tlv_inf, globs); +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm5tlv_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type 5TLV element. This element + consists of a 8 bit T component a + 8 or 16 Bit L component and a V component wich + length depends on the value of the L component. + If the length is in the range 0x00-0x7f the L component + consist of one byte. For bigger length 0x80-0xff the + L component consists of two bytes. The first byte is + tied to 0x81 and the second byte contains a value in the + range 0x80 to 0xff. + +*/ + +SHORT cdc_gsm5tlv_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm5tlv_encode()"); + #else + TRACE_CCD (globs, "cdc_gsm5tlv_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cdc_tlv_encode (e_ref, 8, 8, globs); + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/gsm5_tv.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,111 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : gsm5_tv.c ++----------------------------------------------------------------------------- +| Copyright 2004 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for GSM5_TV elements +| GSM5_TV is very similar to GSM3_TV but doesn't support tags with +| length 4 bits (needed in case of IEI = 0x80 with 8 bit tag) ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm5tv_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type 5TV element. This element + consists of a 8 Bit T component and a V component with + fixed length. +*/ + +SHORT cdc_gsm5tv_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + T_TLV_SORT tlv_inf; + + tlv_inf.gotTag = TRUE; + tlv_inf.gotLen = FALSE; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm5tv_decode()"); + #else + TRACE_CCD (globs, "cdc_gsm5tv_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_tlv_decode (c_ref, e_ref, &tlv_inf, globs); +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm5tv_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type 5TV element. This element + consists of a 8 Bit T component and a V component with + fixed length. +*/ + +SHORT cdc_gsm5tv_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm5tv_encode()"); + #else + TRACE_CCD (globs, "cdc_gsm5tv_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cdc_tlv_encode (e_ref, 8, 0, globs); + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/gsm5_v.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,210 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : gsm5_v.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for GSM5_V elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm5v_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type 5V element. This element + consists of the not decoded bits of the bitstream. + In the target C-structure this element is a bitbuffer + (T_xxx_BUF) in wich the bitstream content are written. + +*/ + +SHORT cdc_gsm5v_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm5v_decode()"); + #else + TRACE_CCD (globs, "cdc_gsm5v_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + if (globs->bitpos >= globs->buflen) + { + return 1; + } + else + { + ULONG cix_ref; + + cix_ref = melem[e_ref].calcIdxRef; + + /* + * if this element is conditional, check the condition + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + { + return 1; + } + else + { + ULONG bits_to_read; + ULONG num_prolog_steps, prolog_step_ref; + + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* If there is a prologue given for this element, process it. */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + /* + * Setup the offset into the C-structure for this element + */ + globs->pstructOffs = melem[e_ref].structOffs; + + if (melem[e_ref].optional) + { + /* + * for optional elements set the valid-flag in the C-struct. + */ + globs->pstruct[globs->pstructOffs++] = TRUE; + } + + if (globs->maxBitpos < globs->buflen - 16*globs->numEOCPending) + { + ccd_recordFault (globs, ERR_LEN_MISMATCH, CONTINUE, (USHORT) e_ref, + globs->pstruct + globs->pstructOffs); + } + + bits_to_read = (ULONG)(globs->buflen - globs->bitpos - 16*globs->numEOCPending); + bf_readBitChunk (bits_to_read, globs); + } + } + + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm5v_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type 5V element. This element + consists of the not decoded bits of the bitstream. + In the target C-structure this element is a bitbuffer + (T_xxx_BUF) from wich the bitstream content is read. + +*/ + +SHORT cdc_gsm5v_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm5v_encode()"); + #else + TRACE_CCD (globs, "cdc_gsm5v_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * if this element is conditional, check the condition + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + /* + * if this element have a defined Prolog + * we have to process it before decoding the bitstream + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + /* + * Setup the offset into the C-structure for this element + */ + globs->pstructOffs = melem[e_ref].structOffs; + + if (melem[e_ref].optional) + { + /* + * for optional elements check the valid-flag in the C-struct. + * Spare elements does not have a corresponding valid flag. + */ + if (globs->pstruct[globs->pstructOffs++] == FALSE) + { + return 1; + } +#ifdef DEBUG_CCD + else if (globs->pstruct [melem[e_ref].structOffs] != TRUE) + { + TRACE_CCD (globs, "Ambiguous value for valid flag!\n...assumed 1 for ccdID=%d", + e_ref); + } +#endif + } + + bf_writeBitChunk (mvar[melem[e_ref].elemRef].bSize, globs); + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/gsm6_tlv.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,112 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : gsm6_tlv.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for GSM6_TLV elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm6tlv_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type 6TLV element. This element + consists of a 8 bit T component a + 16 Bit L component and a V component wich + length depends on the value of the L component. +*/ + +SHORT cdc_gsm6tlv_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + T_TLV_SORT tlv_inf; + + tlv_inf.gotTag = TRUE; + tlv_inf.gotLen = TRUE; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm6tlv_decode()"); + #else + TRACE_CCD (globs, "cdc_gsm6tlv_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_tlv_decode (c_ref, e_ref, &tlv_inf, globs); +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm6tlv_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type 6TLV element. This element + consists of a 8 bit T component a + 16 Bit L component and a V component wich + length depends on the value of the L component. + +*/ + +SHORT cdc_gsm6tlv_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm6tlv_encode()"); + #else + TRACE_CCD (globs, "cdc_gsm6tlv_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cdc_tlv_encode (e_ref, 8, 16, globs); + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/gsm7_lv.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,112 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : gsm7_lv.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for GSM7_LV elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm7lv_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type 7LV element. This element + consists of a 7 bit L component which defines the length + of the following V value in bits and a V component wich + length depends on the value of the L component. +*/ + +SHORT cdc_gsm7lv_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + T_TLV_SORT tlv_inf; + + tlv_inf.gotTag = FALSE; + tlv_inf.gotLen = TRUE; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm7lv_decode()"); + #else + TRACE_CCD (globs, "cdc_gsm7lv_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + return cdc_tlv_decode (c_ref, e_ref, &tlv_inf, globs); +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_gsm7lv_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type 7LV element. This element + consists of a 7 bit L component which defines the length + of the following V value in bits and a V component wich + length depends on the value of the L component. + +*/ + +SHORT cdc_gsm7lv_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_gsm7lv_encode()"); + #else + TRACE_CCD (globs, "cdc_gsm7lv_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cdc_tlv_encode (e_ref, 0, 7, globs); + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/hl_flag.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,345 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : hl_flag.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Inc. +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for HL_FLAG elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_hl_flag_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type HL_FLAG element. This element + consists of a single bit only. The decoded value will be 0 + if the encoded value is L respectively 1 if the encoded + value is H. + +*/ + +SHORT cdc_hl_flag_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat, max_rep; + BOOL is_variable = FALSE; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_hl_flag_decode()"); + #else + TRACE_CCD (globs, "cdc_hl_flag_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + globs->SeekTLVExt = FALSE; + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + repeat = 1; + + if (cix_ref != 0) + { + /* + * if this element is conditional, check the condition + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + /* + * if this element have a defined Prolog + * we have to process it before decoding the bitstream + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + if (melem[e_ref].repType NEQ ' ') + { + is_variable = ccd_calculateRep (e_ref, &repeat, &max_rep, globs); + } + } + /* + * Element is not a SPARE. Setup the struct pointer + */ + globs->pstructOffs = melem[e_ref].structOffs; + + + if (melem[e_ref].optional) + { + /* + * for optional elements we must set the valid-flag + * ??. + * Therefore we store the address of the valid flag. + */ + *(globs->pstruct + globs->pstructOffs++) = TRUE; + + } + + globs->pstruct[globs->pstructOffs++] = (UBYTE) (bf_readBit(globs) == GET_HL_PREV(1)); +#ifdef DEBUG_CCD +#ifdef CCD_SYMBOLS + TRACE_CCD (globs, "decoding var %s",ccddata_get_alias((USHORT) e_ref, 1)); +#else + TRACE_CCD (globs, "decoding var %d", melem[e_ref].elemRef); +#endif +#endif + + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_hl_flag_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type HL_FLAG element. This element + consists of a single bit only. If the element is set to 1 + a H bit will be coded. Otherwise a L bit will be coded if + the element value to encode is set to 0. + +*/ + +SHORT cdc_hl_flag_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat=1, amount=1; + USHORT cSize = 0, startOffset; + ULONG i; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_hl_flag_encode()"); + #else + TRACE_CCD (globs, "cdc_hl_flag_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + if (cix_ref != 0) + { + /* + * if this element is conditional, check the condition + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + /* + * if this element have a defined Prolog + * we have to process it before decoding the bitstream + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + } + + if (melem[e_ref].elemType NEQ 'S') + { + /* + * Element is not a SPARE. + * Setup the offset into the C-structure for this element + */ + globs->pstructOffs = melem[e_ref].structOffs; + + if (melem[e_ref].optional) + { + /* + * for optional elements check the valid-flag in the C-struct. + * Spare elements does not have a corresponding valid flag. + */ + if (globs->pstruct[globs->pstructOffs++] == FALSE) + { + /* + * element is invalid so we must code a 0 bit + */ + bf_writeBit (GET_HL(0), globs); + + return 1; + } + + else + { +#ifdef DEBUG_CCD + if (globs->pstruct [melem[e_ref].structOffs] != TRUE) + { + TRACE_CCD (globs, "Ambiguous value for valid flag!\n...assumed 1 for ccdID=%d", + e_ref); + } +#endif + /* + * element is valid so we must code a 1 bit + */ + bf_writeBit (GET_HL(1), globs); + } + } + + if (melem[e_ref].repType NEQ ' ') + { + /* As a default amount =1 due to initialization. */ + if (melem[e_ref].repType EQ 'i') + { + /* + * for variable repeatable elements read the amount + * of repeats out of the C-Structure (c_xxx). + * If the number of repeats given by the C-Structure + * exceeds the allowed value CCD gives a warning! + */ + if (melem[e_ref].maxRepeat > 255) + { + ULONG count = (ULONG) (* (USHORT *)(globs->pstruct + globs->pstructOffs++)); + repeat = MINIMUM (count, (ULONG) melem[e_ref].maxRepeat); + if (repeat < count) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + else + { + repeat = (ULONG) MINIMUM (globs->pstruct[globs->pstructOffs], + melem[e_ref].maxRepeat); + if ( repeat < (ULONG)(globs->pstruct[globs->pstructOffs]) ) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + globs->pstructOffs++; + } + else + if (melem[e_ref].repType EQ 'v') + { + /* + * for variable repeatable elements read the amount + * of repeats out of the C-Structure (c_xxx). + * If the number of repetitions given by the C-Structure + * exceeds the allowed value (maxRepeat) CCD gives a warning! + */ + if (melem[e_ref].maxRepeat > 255) + { + ULONG count = (ULONG) (* (USHORT *)(globs->pstruct + globs->pstructOffs++)); + amount = MINIMUM (count, (ULONG) melem[e_ref].maxRepeat); + if (amount < count) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + else + { + amount = (ULONG) MINIMUM (globs->pstruct[globs->pstructOffs], + melem[e_ref].maxRepeat); + if ( amount < (ULONG) (globs->pstruct[globs->pstructOffs]) ) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + globs->pstructOffs++; + } + else + if (melem[e_ref].repType EQ 'c') + { + amount = (ULONG) melem[e_ref].maxRepeat; + } + + if (melem[e_ref].repType EQ 'v' OR melem[e_ref].repType EQ 'i') + { + cSize = (USHORT)(((melem[e_ref].elemType EQ 'V') + ? mvar[melem[e_ref].elemRef].cSize + : mcomp[melem[e_ref].elemRef].cSize + )); + startOffset = (USHORT) globs->pstructOffs; + } + } + + for (i=0; i < repeat; i++) + { + if (cSize) + { + /* + * calculate the offset if it is an array + */ + globs->pstructOffs = (USHORT)(startOffset + (i * cSize)); + } + /* + * encode the value + */ + if (globs->pstruct[globs->pstructOffs++] EQ FALSE) + { + /* + * element is 0 so we must signalize L + */ + bf_writeBit (GET_HL(0), globs); + } + else + { + /* + * element is 1 so we must signalize H + */ + bf_writeBit (GET_HL(1), globs); + } + + globs->pstructOffs += mvar[melem[e_ref].elemRef].cSize; + } + + if (melem[e_ref].repType EQ 'i') + { + /* + * for variable CNS1 fields we code a 0 flag to mark the end of the + * arrays + */ + bf_writeBit (GET_HL(0), globs); + } + } + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/no_code.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,180 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : no_code.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for NO_CODE elements ++----------------------------------------------------------------------------- +*/ + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_no_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Either reading a value from the stack and writing it into + the C structure or processing the error branch in case of + a message escape error label. + An IE of this type does not occur in the air message. + + EXAMPLE (reading stack value): + The first usage of this type is the IE "tlv_len" in a + Multi Rate Configuration. In this case "tlv_len" is to be + used for evaluating conditions which decide for the content + of Multi Rate Configuration IE. + + EXMAPLE (message escape): + A part of a message, which depends on a certain protocol + status, is marked by the 'Message escape' error label. It + is preceeded by an amount of bits given by the specification. + Some of these bit combinations are concatenated with a + well-defined message structure. All the rest of combinations + are expected to provide an escape + -> use coding type 'NO_CODE'. +*/ + +SHORT cdc_no_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + U16 cixRef = melem[e_ref].calcIdxRef; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_no_decode()"); + #endif +#endif + + /* + * if this element is conditional, check the condition + */ + if (calcidx[cixRef].numCondCalcs != 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + if (calcidx[cixRef].numPrologSteps) + { + switch (calc[calcidx[cixRef].prologStepRef].operation) + { + case 'Z': /* address information part error */ + globs->errLabel = ERR_ADDR_INFO_PART; + break; + + case 'D': /* distribution part error */ + globs->errLabel = ERR_DISTRIB_PART; + break; + + case 'N': /* non distribution part error */ + globs->errLabel = ERR_NON_DISTRIB_PART; + break; + + case 'M': /* message escape */ + globs->errLabel = ERR_MESSAGE_ESCAPE; + break; + + default: + break; + } + } + + if (globs->errLabel) + { +#ifdef DEBUG_CCD + #ifdef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_no_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + ccd_setError (globs, globs->errLabel, BREAK, globs->bitpos, (USHORT) -1); + } + + else + { +#ifdef DEBUG_CCD + #ifdef CCD_SYMBOLS + if (calcidx[cixRef].numPrologSteps == 0) + TRACE_CCD (globs, "writing 2 bytes (%ld) to struct", globs->KeepReg[0]); + else + TRACE_CCD (globs, "cdc_no_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + + #endif +#endif + + globs->pstructOffs = melem[e_ref].structOffs; + *(U16*) (globs->pstruct + globs->pstructOffs) = (U16) globs->KeepReg[0]; + } + + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_no_encode | ++--------------------------------------------------------------------+ + + PURPOSE : An IE of this type does not occure in the air message. + Nevertheless the variable in the C structure must be + written by the caller entity. + EXAMPLE: + The first usage of this type is the IE "tlv_len" in a + Multi Rate Configuration. In this case "tlv_len" is to be used + for evaluating conditions which decide for the content of + Multi Rate Configuration IE. + +*/ + +SHORT cdc_no_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_no_encode()"); + #else + TRACE_CCD (globs, "cdc_no_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/noncritical_ext.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,166 @@ + +/* ++------------------------------------------------------------------------------ +| File: noncritical_ext.c ++------------------------------------------------------------------------------ +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG. +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++------------------------------------------------------------------------------ +| Purpose: Encoding and decoding functions for nonCriticalExtensions elements +| +| $Identity:$ ++------------------------------------------------------------------------------ +*/ + +/* + * Standard definitions like UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes and constants in the common part of ccd + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : noncritical_ext | +| STATE : code ROUTINE : cdc_noncritical_ext_decode | ++------------------------------------------------------------------------+ + + PURPOSE : Decode elements of type nonCriticalExtensions + + An element of this type should never be encoded or decoded. + If the coder faces an IE of this type, it should report a + warning and continue decoding. + Whenever a nonCriticalExtensions-IE is extended from NULL or + SEQUENCE {} to another type, its CCD coding type will change + and the functions in this file will not be called for that IE + any more. + + According to 3GPP TS25.331 V3.6.0, 10.1.1.1: + Information elements applicable to choices reserved for future + releases of the protocol shall be added to the end of the message. + In future releases non critical informaion elements ... shall + be appended at the end of the message. + See also 3GPP TS25.921 V4.3.0, 10.4. + +*/ +SHORT cdc_noncritical_ext_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ +#ifdef DEBUG_CCD +#ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_noncritical_ext_decode()"); +#else + TRACE_CCD (globs, "cdc_noncritical_ext_decode() %s", mcomp[melem[e_ref].elemRef].name); +#endif +#endif + + globs->pstructOffs = melem[e_ref].structOffs; + + /* For optional elements we have already set the valid flag in the + * C-structure. We have done it while processing ASN1_SEQ. + */ + if ( ! cdc_isPresent(e_ref, globs) ) { + return 1; + } + + if (melem[e_ref].elemType EQ 'V' AND mvar[melem[e_ref].elemRef].bSize EQ 0) + { + return 0; + } + /* + * Currently CCD tool chain does not support extensions of this type. + * This else-implementation is just an outlook. + * + else + { + U16 compRef = melem[e_ref].elemRef; + U16 elemRef = mcomp[compRef].componentRef; + (void) codec[melem[Elem].codingType][DECODE_FUN] + (compRef, elemRef, globs); + }*/ + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++------------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : noncritical_ext | +| STATE : code ROUTINE : cdc_noncritical_ext_encode | ++------------------------------------------------------------------------+ + + PURPOSE : Encode elements of type nonCriticalExtensions + + An element of this type should never be encoded or decoded. + If the coder faces an IE of this type, it should report an + error report and abort. +*/ +SHORT cdc_noncritical_ext_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + +#ifdef DEBUG_CCD +#ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_noncritical_ext_encode()"); +#else + TRACE_CCD (globs, "cdc_noncritical_ext_encode() %s", mcomp[melem[e_ref].elemRef].name); +#endif +#endif + + globs->pstructOffs = melem[e_ref].structOffs; + + /* For optional elements we have already set the valid flag in the + * C-structure. We have done it while processing ASN1_SEQ. + */ + if ( ! cdc_isPresent(e_ref, globs) ) { + return 1; + } + + if (melem[e_ref].elemType EQ 'V' AND mvar[melem[e_ref].elemRef].bSize EQ 0) + { + return 0; + } + /* + * Currently CCD tool chain does not support extensions of this type. + * This else-implementation is just an outlook. + * + else + { + U16 compRef = melem[e_ref].elemRef; + U16 elemRef = mcomp[compRef].componentRef; + (void) codec[melem[Elem].codingType][ENCODE_FUN] + (compRef, elemRef, globs); + }*/ + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/pdi.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,541 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : pdi.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : ++----------------------------------------------------------------------------- +*/ + +#define PDI_C + +#include "typedefs.h" +#include "ccdapi.h" +#include "ccdtable.h" +#include "ccddata.h" +#include <malloc.h> +#include <memory.h> +#include <string.h> +#include "pdi.h" + +#define GET_PD(m) ((m)->buf[((m)->o_buf)>>3] & 0x0f) +#define GET_TI(m) ((m)->buf[((m)->o_buf)>>3] >> 4) + +/* Constants borrowed from grr.h */ +#define CTRL_BLK_NO_OPT 1 +#define CTRL_BLK_OPT 2 + +static T_PDI_DECODEINFO* g_DummyDecodeInfo = NULL; + +static T_PDI_DECODEINFO m_def_dinfo[]={ + /* type */ /* attrib */ /* prim */ /* entity */ /* mt */ /* pdi_prepare_ccdmsg */ /* primmbr */ + {PDI_DECODETYPE_L3PDU_N, "sdu", "PH_*", "", 0xff, NULL, NULL}, + {PDI_DECODETYPE_L3PDU_N, "sdu", "MPH_*", "", 0xff, NULL, NULL}, + {PDI_DECODETYPE_L3PDU_N, "sdu", "DL_*", "", 0xff, NULL, NULL}, + {PDI_DECODETYPE_L3PDU, "sdu", "XX_TAP*", "", 0xff, NULL, NULL}, + {PDI_DECODETYPE_NOPD, "sdu", "XX_*", "XX", 0xff, NULL, NULL}, + {PDI_DECODETYPE_L3PDU, "sdu", "*", "", 0xff, NULL, NULL} +}; +#define DEF_DINFO_COUNT (sizeof(m_def_dinfo) / sizeof(*m_def_dinfo)) + +static UBYTE pdi_readmtype (T_MSGBUF* msg, UBYTE len) +{ + UBYTE mt = msg->buf[msg->o_buf>>3] >> (8-len); + msg->l_buf -= len; + msg->o_buf += len; + return mt; +} + +#define PDI_MBUFLEN 1024 +static struct +{ + U16 l_buf; + U16 o_buf; + char buf[PDI_MBUFLEN]; +} pdi_msgbuf; + +static int pdi_rmac_hdr (T_PDI_CCDMSG* ccdmsg, char* evalue, int evlen) +{ + char* ptr_blk; + UBYTE payload, rrbp, sp; + evalue++; /* Assume it is an array and skip length delivered from ccdedit */ + memcpy (pdi_msgbuf.buf, evalue, evlen > PDI_MBUFLEN ? PDI_MBUFLEN : evlen); + ptr_blk = evalue; + pdi_msgbuf.l_buf = evlen * 8; + pdi_msgbuf.o_buf = 0; + ccdmsg->mbuf = (T_MSGBUF*) &pdi_msgbuf; + + /* the following is borrowed from grlc_gfff.c */ + payload = (ptr_blk[0] & 0xC0) >> 6; + rrbp = (ptr_blk[0] & 0x30) >> 4; + sp = (ptr_blk[0] & 0x08) >> 3; + + if (payload == CTRL_BLK_NO_OPT) + { + /* msg starts at byte #2 */ + pdi_msgbuf.l_buf -= 8; + pdi_msgbuf.o_buf += 8; + } + else if ((payload == CTRL_BLK_OPT) && + !(ptr_blk[1] & 0x01) && + !(ptr_blk[1] & 0x80) && + (ptr_blk[1] & 0x02)) + { + /* msg starts at byte #3 */ + pdi_msgbuf.l_buf -= 16; + pdi_msgbuf.o_buf += 16; + } + else if ((payload == CTRL_BLK_OPT) && + (ptr_blk[1] & 0x01) && + !(ptr_blk[1] & 0x80) && + (ptr_blk[1] & 0x02)) + { + /* msg starts at byte #4 */ + pdi_msgbuf.l_buf -= 24; + pdi_msgbuf.o_buf += 24; + } + else + { + return PDI_NONE; + } + return PDI_CCDMSG; +} + +T_PDI_CONTEXT* CCDDATA_PREF(pdi_createDefContext)() +{ + const T_PDI_DECODEINFO* dinfo; + int dinfo_count=ccddata_get_pdi_dinfo(&dinfo); + if (dinfo_count==0) + { + dinfo_count=DEF_DINFO_COUNT; + dinfo=m_def_dinfo; + } + return CCDDATA_PREF(pdi_createContext)(dinfo,dinfo_count); +} + + +T_PDI_CONTEXT* CCDDATA_PREF(pdi_createContext)(const T_PDI_DECODEINFO *dinfo, unsigned int dicount) +{ + int i; + USHORT sap, opc, dir, di; + USHORT pmtx; + T_PDI_DECODEINFO* decodeInfo[1024]; + int decodeInfoCount; + int len; + + T_PDI_CONTEXT *context; + + if (context = (T_PDI_CONTEXT*)malloc(sizeof(T_PDI_CONTEXT))) + { + // copy dinfo + if (!(context->dinfo = (T_PDI_DECODEINFO*)malloc(sizeof(T_PDI_DECODEINFO)*dicount))) + { + free(context); + return NULL; + } + memcpy(context->dinfo, dinfo, sizeof(T_PDI_DECODEINFO)*dicount); + + // PD -> CCDENT + memset(context->PdEntityTable, -1, sizeof(T_PDI_PdEntityTable)); + context->PdEntityTable[PD_XX] = ccddata_get_ccdent("XX"); + context->PdEntityTable[PD_CC] = ccddata_get_ccdent("CC"); + context->PdEntityTable[PD_MM] = ccddata_get_ccdent("MM"); + context->PdEntityTable[PD_RR] = ccddata_get_ccdent("RR"); + context->PdEntityTable[PD_GMM] = ccddata_get_ccdent("GMM"); + context->PdEntityTable[PD_SMS] = ccddata_get_ccdent("SMS"); + context->PdEntityTable[PD_SS] = ccddata_get_ccdent("SS"); + context->PdEntityTable[PD_SM] = ccddata_get_ccdent("SM"); + context->PdEntityTable[PD_TST] = ccddata_get_ccdent("TST"); + + /* initialize mi_length */ + context->mi_length = ccddata_get_mi_length (); + + // count pcomp + i = 0; + while (ccddata_get_pcomp((USHORT)i)->name != NULL) i++; + context->PrimDecodeInfo = (T_PDI_DECODEINFO***)malloc(i*sizeof(T_PDI_DECODEINFO**)); + memset(context->PrimDecodeInfo, 0, i*sizeof(int*)); + + // search all primitives + for (sap = 0; sap <= ccddata_get_max_sap_num(); sap++) + for (opc = 0; opc <= (USHORT)ccddata_get_max_primitive_id(); opc++) + for (dir = 0; dir <= 1; dir++) + if ((pmtx = ccddata_get_pmtx(sap, opc, dir)) != NO_REF) + { + const char* pname; + pname = ccddata_get_pcomp(pmtx)->name; + + decodeInfoCount = 0; + for (di = 0; di < dicount; di++) + { + int wildcard; + len = strlen(context->dinfo[di].prim); + if (context->dinfo[di].prim[len-1] == '*') + { + wildcard = 1; + len--; + } + else + { + wildcard = 0; + len = strlen(pname); + } + + if (wildcard) + { + if (!strncmp(context->dinfo[di].prim, pname, len)) + { + decodeInfo[decodeInfoCount] = &context->dinfo[di]; + decodeInfoCount++; + } + } + else + { + if (!strcmp(context->dinfo[di].prim, pname)) + { + decodeInfo[decodeInfoCount] = &context->dinfo[di]; + decodeInfoCount++; + } + } + } + + // store decodeInfo for this primitive + if (decodeInfoCount != 0) + { + decodeInfo[decodeInfoCount] = g_DummyDecodeInfo; + decodeInfoCount++; + context->PrimDecodeInfo[pmtx] = (T_PDI_DECODEINFO**) + malloc(decodeInfoCount*sizeof(T_PDI_DECODEINFO*)); + if (context->PrimDecodeInfo+pmtx) + { + memcpy(context->PrimDecodeInfo[pmtx], &decodeInfo, + decodeInfoCount*sizeof(T_PDI_DECODEINFO*)); + + } + else + context->PrimDecodeInfo[pmtx] = &g_DummyDecodeInfo; + } + else + context->PrimDecodeInfo[pmtx] = &g_DummyDecodeInfo; + + } // endif (pmtx != NO_REF) + } + + return context; +} + + + +void CCDDATA_PREF(pdi_destroyContext)(T_PDI_CONTEXT *context) +{ + int i = 0; + + if (context==NULL) return; + + while (ccddata_get_pcomp((USHORT)i)->name != NULL) + { + if ((context->PrimDecodeInfo[i] != NULL) && + (context->PrimDecodeInfo[i][0] != NULL)) + free(context->PrimDecodeInfo[i]); + i++; + } + if (context->PrimDecodeInfo != NULL) + free(context->PrimDecodeInfo); + + free(context->dinfo); + + free(context); +} + + + +void CCDDATA_PREF(pdi_startPrim)(T_PDI_CONTEXT *context, ULONG opc) +{ + context->sapi = 0; + + if (opc & 0x80000000) + { + context->sap = (USHORT) (opc & 0x3fff); + context->opc = (USHORT) ((opc >> 16) & 0xff); + } + else + { + context->sap = (USHORT) (((opc & 0x3f00)>>8) & 0xff); + context->opc = (USHORT) (opc & 0xff); + } + context->dir = (UBYTE) (((opc & 0x4000)>>14) & 0x01); + + context->pmtx = ccddata_get_pmtx(context->sap, context->opc, context->dir); + context->mtypenum = 0; +} + +void CCDDATA_PREF(pdi_getDecodeInfo)(T_PDI_CONTEXT *context, const char *ename, + char *evalue, int evlen, T_PDI *decinfo) +{ + int i=0; + T_PDI_DECODEINFO* di; + + decinfo->decodetype = PDI_NONE; + + while (di = context->PrimDecodeInfo[context->pmtx][i++]) + { + if ((di->type == PDI_DECODETYPE_SAPI) && (strcmp(ename, "sapi") == 0)) + { + context->sapi = evalue[0]; + } + + if (!strcmp(ename, di->attrib)) + { + decinfo->pdi.ccdmsg.msg_type = 0xff; + + if (di->pdi_prepare_ccdmsg) + { + decinfo->decodetype = (*di->pdi_prepare_ccdmsg) + (&decinfo->pdi.ccdmsg, context->mtypeval, + context->mtypenum); + if (decinfo->decodetype == PDI_NONE) + { + continue; + } + } + + switch (di->type) + { + case PDI_DECODETYPE_AIM: + case PDI_DECODETYPE_AIM_N: + case PDI_DECODETYPE_AIM_CHECK: + case PDI_DECODETYPE_AIM_N_CHECK: + decinfo->decodetype = PDI_CCDMSG; + memcpy (pdi_msgbuf.buf, evalue, + evlen > PDI_MBUFLEN ? PDI_MBUFLEN : evlen); + pdi_msgbuf.l_buf = evlen * 8; + pdi_msgbuf.o_buf = 0; + + /* first byte: don't care */ + pdi_msgbuf.l_buf -= 8; + pdi_msgbuf.o_buf += 8; + decinfo->pdi.ccdmsg.mbuf = (T_MSGBUF*) &pdi_msgbuf; + decinfo->pdi.ccdmsg.pd = GET_PD (decinfo->pdi.ccdmsg.mbuf); + if (strcmp (di->entity, + CCDDATA_PREF(pdi_pd2name)(decinfo->pdi.ccdmsg.pd))) + { + /* pd does not match the configured entity */ + decinfo->decodetype = PDI_CCDMSG; + continue; + } + else + { + pdi_msgbuf.l_buf -= 8; + pdi_msgbuf.o_buf += 8; + } + //decinfo->pdi.ccdmsg.ti = GET_TI (decinfo->pdi.ccdmsg.mbuf); + decinfo->pdi.ccdmsg.dir = (di->type == PDI_DECODETYPE_AIM) || + (di->type == PDI_DECODETYPE_AIM_CHECK) ? + context->dir : (~context->dir)&1; + decinfo->pdi.ccdmsg.entity = (UBYTE)ccddata_get_ccdent(di->entity); + decinfo->pdi.ccdmsg.msg_type = pdi_readmtype ( + decinfo->pdi.ccdmsg.mbuf, + context->mi_length[decinfo->pdi.ccdmsg.entity]); + break; + case PDI_DECODETYPE_L3PDU_N: + case PDI_DECODETYPE_L3PDU: + decinfo->decodetype = PDI_CCDMSG; + + decinfo->pdi.ccdmsg.pd = GET_PD ((T_MSGBUF*) evalue); + decinfo->pdi.ccdmsg.ti = GET_TI ((T_MSGBUF*) evalue); + decinfo->pdi.ccdmsg.dir = (di->type == PDI_DECODETYPE_L3PDU) ? + context->dir : (~context->dir)&1; + + decinfo->pdi.ccdmsg.mbuf = (T_MSGBUF*)evalue; + + if (CCDDATA_PREF(pdi_getEntityByPD)(context, decinfo->pdi.ccdmsg.pd)==-1) + { + decinfo->decodetype = PDI_NONE; + } + else + { + decinfo->pdi.ccdmsg.entity = (UBYTE)CCDDATA_PREF(pdi_getEntityByPD)(context, decinfo->pdi.ccdmsg.pd); + + ((T_MSGBUF*)evalue)->o_buf += 8; + ((T_MSGBUF*)evalue)->l_buf -= 8; + + decinfo->pdi.ccdmsg.msg_type = pdi_readmtype ((T_MSGBUF*)evalue, + context->mi_length[decinfo->pdi.ccdmsg.entity]); + } + + /* remove SSN bit */ + if (!strcmp ("DL_DATA_REQ", ccddata_get_pcomp (context->pmtx)->name)) + { + if (decinfo->pdi.ccdmsg.pd == PD_CC || + decinfo->pdi.ccdmsg.pd == PD_MM || + decinfo->pdi.ccdmsg.pd == PD_SS) + { + decinfo->pdi.ccdmsg.msg_type &= ~0x40; + } + } + break; + + case PDI_DECODETYPE_NOPD: + case PDI_DECODETYPE_NOPD_N: + case PDI_DECODETYPE_RR_SHORT: + decinfo->decodetype = PDI_CCDMSG; + + decinfo->pdi.ccdmsg.pd = 0; + decinfo->pdi.ccdmsg.ti = 0; + decinfo->pdi.ccdmsg.dir = (di->type == PDI_DECODETYPE_NOPD) ? + context->dir : (~context->dir)&1; + + decinfo->pdi.ccdmsg.mbuf = (T_MSGBUF*)evalue; + decinfo->pdi.ccdmsg.entity = (UBYTE)ccddata_get_ccdent(di->entity); + decinfo->pdi.ccdmsg.msg_type = pdi_readmtype ((T_MSGBUF*)evalue, + context->mi_length[decinfo->pdi.ccdmsg.entity]); + break; + + case PDI_DECODETYPE_NOPD_NOTYPE: + case PDI_DECODETYPE_NOPD_NOTYPE_N: + decinfo->decodetype = PDI_CCDMSG; + + decinfo->pdi.ccdmsg.pd = 0; + decinfo->pdi.ccdmsg.ti = 0; + decinfo->pdi.ccdmsg.dir = (di->type == PDI_DECODETYPE_NOPD_NOTYPE) ? + context->dir : (~context->dir)&1; + + decinfo->pdi.ccdmsg.mbuf = (T_MSGBUF*)evalue; + + if (decinfo->pdi.ccdmsg.msg_type == 0xff) + { + decinfo->pdi.ccdmsg.msg_type = di->msg_type; + } + + decinfo->pdi.ccdmsg.entity = (UBYTE)ccddata_get_ccdent(di->entity); + break; + + case PDI_DECODETYPE_MAC_H: + case PDI_DECODETYPE_MAC_H_N: + case PDI_DECODETYPE_MAC_H_CHECK: + case PDI_DECODETYPE_MAC_H_N_CHECK: + if ((decinfo->decodetype = pdi_rmac_hdr (&decinfo->pdi.ccdmsg, + evalue, evlen)) == PDI_CCDMSG) + { + decinfo->pdi.ccdmsg.pd = 0; + decinfo->pdi.ccdmsg.ti = 0; + decinfo->pdi.ccdmsg.dir = ((di->type == PDI_DECODETYPE_MAC_H) || + (di->type == PDI_DECODETYPE_MAC_H_CHECK)) + ? context->dir : (~context->dir)&1; + decinfo->pdi.ccdmsg.entity = (UBYTE)ccddata_get_ccdent(di->entity); + decinfo->pdi.ccdmsg.msg_type = + pdi_readmtype (decinfo->pdi.ccdmsg.mbuf, + context->mi_length[decinfo->pdi.ccdmsg.entity]); + } + break; + + case PDI_DECODETYPE_SAPI: + decinfo->decodetype = PDI_NONE; + if (context->sapi == 1) // only sapi1 (GMM) has data for ccd + { + decinfo->decodetype = PDI_CCDMSG; + + decinfo->pdi.ccdmsg.pd = GET_PD ((T_MSGBUF*) evalue); + decinfo->pdi.ccdmsg.ti = GET_TI ((T_MSGBUF*) evalue); + decinfo->pdi.ccdmsg.dir = context->dir; + +/* !!! TBD !!! */ + /* find msg_type*/ +/* !!! TBD !!! */ + + decinfo->pdi.ccdmsg.mbuf = (T_MSGBUF*)evalue; + + ((T_MSGBUF*)evalue)->o_buf += 8; + ((T_MSGBUF*)evalue)->l_buf -= 8; + + if (CCDDATA_PREF(pdi_getEntityByPD)(context, decinfo->pdi.ccdmsg.pd)==-1) + { + decinfo->decodetype = PDI_NONE; + } + else + { + decinfo->pdi.ccdmsg.entity = (UBYTE)CCDDATA_PREF(pdi_getEntityByPD)(context, decinfo->pdi.ccdmsg.pd); + } + } + break; + + default: + decinfo->decodetype = PDI_NONE; + } + + break; + } /* endif (strcmp) */ + else + { + if (evlen > 4 || evlen < 0 || evlen == 3) + { + /* don't check prim members for non base types */ + continue; + } + /* check for prim members later needed for finding out msg type */ + if (di->primmbr) + { + int i; + for (i=0; di->primmbr[i] && context->mtypenum<PDI_MAXPMEMFORMTYPE; i++) + { + if (!strcmp(ename, di->primmbr[i])) + { + switch (evlen) + { + case 1: + context->mtypeval[context->mtypenum++] = + (ULONG) * (UBYTE*) evalue; + break; + case 2: + context->mtypeval[context->mtypenum++] = + (ULONG) * (USHORT*) evalue; + break; + case 4: + default: + context->mtypeval[context->mtypenum++] = * (ULONG*) evalue; + break; + } + } + } + } + } + } /* endwhile */ + +} + +short CCDDATA_PREF(pdi_getEntityByPD)(const T_PDI_CONTEXT *context, unsigned char pd) +{ + if ((pd > 16) || (context->PdEntityTable == NULL)) + return -1; + else + return context->PdEntityTable[pd]; +} + + +const char* CCDDATA_PREF(pdi_pd2name)(unsigned char pd) +{ + switch (pd) { + case PD_XX: return "XX"; + case PD_CC: return "CC"; + case PD_MM: return "MM"; + case PD_RR: return "RR"; + case PD_GMM: return "GMM"; + case PD_SMS: return "SMS"; + case PD_SS: return "SS"; + case PD_SM: return "SM"; + case PD_TST: return "TST"; + + default: return "??"; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/s_padding.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,183 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : s_padding.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for S_PADDING elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_padd_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type CSN1 spare padding. + This function does not evaluate the encoded bits, since + their content is irrelevant. +*/ + +SHORT cdc_padd_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + USHORT cixRef; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "cdc_padd_decode()"); +#endif + + /* + * Do not decode padding bits. They are not relevant. + * Just adjust the position pointer in the bit stream buffer. + * Either to the next octet boundary or to the message end, if necessary. + */ + bf_incBitpos (8-(globs->bitpos & 7), globs); + + /* First assume padding bits up to an octet boundary. In this case + * message extension could be made of T, TV or TLV types. + */ + globs->SeekTLVExt = TRUE; + + cixRef = melem[e_ref].calcIdxRef; + if (calcidx[cixRef].numPrologSteps > 0) + { + USHORT msgEnd = (USHORT) calc[calcidx[cixRef].prologStepRef].operand * 8; + if (msgEnd) + { + msgEnd += globs->bitoffs; + msgEnd = (USHORT)MINIMUM(globs->maxBitpos, msgEnd); + bf_setBitpos (msgEnd, globs); + /* + * Padding bytes exclude the presence of message extension. + */ + globs->SeekTLVExt = FALSE; + } + } + + return 1; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CDC_GSM | +| STATE : code ROUTINE : cdc_padd_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type CSN1 spare padding. + Supported padding values are 0x00 and 0x2B, if first prolog + step is a value msg_len, padding is done until globs->bitpos is + msg_len*8, else until octet boundary +*/ + +SHORT cdc_padd_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + UBYTE padd_bit = 0; + USHORT cixRef; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "cdc_padd_encode()"); +#endif + + cixRef = melem[e_ref].calcIdxRef; + + /* + * if this element is conditional, check the condition + */ + if (calcidx[cixRef].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + if (melem[e_ref].elemType EQ 'S' AND spare[melem[e_ref].elemRef].bSize EQ 8) + { + UBYTE spareVal = (UBYTE)(spare[melem[e_ref].elemRef].value); + /* + * Element is a SPARE of length 8. + */ + while (globs->bitpos % 8 NEQ 0) + { + switch(spareVal) + { + case 0: + break; + case 0x2B: + padd_bit = (UBYTE)GET_HL(0); + break; + default: + ccd_setError (globs, ERR_INTERNAL_ERROR, + BREAK, + (USHORT) (globs->bitpos), + (USHORT) -1); + } + bf_writeBit (padd_bit, globs); + } + if (calcidx[cixRef].numPrologSteps > 0) + { + if (calc[calcidx[cixRef].prologStepRef].operation NEQ 'P') + ccd_setError (globs, ERR_INTERNAL_ERROR, BREAK, (USHORT) -1); + else + { + USHORT msgLen = (USHORT)(calc[calcidx[cixRef].prologStepRef].operand * 8); + + while (globs->bitpos - globs->bitoffs < msgLen ) + { + bf_codeLongNumber (8, (ULONG) spareVal, globs); + } + } + } + } + else + { + ccd_setError (globs, ERR_INVALID_TYPE, + BREAK, + (USHORT) (globs->bitpos), + (USHORT) -1); + } + + return 1; +} +#endif /* !RUN_FLASH */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/s_padding_0.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,213 @@ +/* ++----------------------------------------------------------------------------- +| Project : CCD +| Modul : s_padding_0.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for S_PADDING_0 ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD MODULE : s_padding_0 | +| STATE : code ROUTINE : cdc_padd_0_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the GSM Type CSN1 spare padding which is + preceded by a 0 bit. + If that bit is read as 1 then a protocol extension is + assumed by CCD. + This function does not evaluate the encoded bits, since + their content is irrelevant. +*/ + +SHORT cdc_padd_0_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + U16 cixRef; +#ifdef DEBUG_CCD + TRACE_CCD (globs, "cdc_padd_0_decode()"); +#endif + + if (bf_readBit(globs) == 1) + { + ccd_recordFault (globs, ERR_PROTOCOL_EXTENSION, CONTINUE, (USHORT) e_ref, NULL); + } + + /* + * Do not decode padding bits. They are not relevant. + * Just adjust the position pointer in the bit stream buffer. + * Either to the next octet boundary or to the message end, if necessary. + */ + bf_incBitpos (8-(globs->bitpos & 7), globs); + + /* First assume padding bits up to an octet boundary. In this case + * message extension could be made of T, TV or TLV types. + */ + globs->SeekTLVExt = TRUE; + + cixRef = melem[e_ref].calcIdxRef; + if (calcidx[cixRef].numPrologSteps > 0) + { + U16 msgEnd = (USHORT) calc[calcidx[cixRef].prologStepRef].operand * 8; + if (msgEnd) + { + msgEnd += globs->bitoffs; + msgEnd = (USHORT)MINIMUM(globs->maxBitpos, msgEnd); + bf_setBitpos (msgEnd, globs); + /* + * Padding bytes exclude the presence of message extension. + */ + globs->SeekTLVExt = FALSE; + } + } + return 1; +} +#endif /* !RUN_FLASH */ + +#ifndef RUN_FLASH +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD MODULE : s_padding_0.c | +| STATE : code ROUTINE : cdc_padd_0_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding of the GSM Type CSN1 spare padding which is + preceded by a 0 bit. + Supported padding values are 0x00 and 0x2B. + If the first prologue step is a value msg_len, padding + is done until globs->bitpos is msg_len*8. + Otherwise until the octet boundary. +*/ + +SHORT cdc_padd_0_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + U8 padd_bit = 0; + U16 cixRef; + U16 msgLen = globs->buflen; + BOOL paddingOctets = FALSE; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "cdc_padd_0_encode()"); +#endif + + cixRef = melem[e_ref].calcIdxRef; + + /* + * if this element is conditional, check the condition + */ + if (calcidx[cixRef].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + if (calcidx[cixRef].numPrologSteps > 0) + { + if (calc[calcidx[cixRef].prologStepRef].operation NEQ 'P') + ccd_setError (globs, ERR_INTERNAL_ERROR, BREAK, (USHORT) -1); + else + { + msgLen = (USHORT)(calc[calcidx[cixRef].prologStepRef].operand * 8); + paddingOctets = TRUE; + } + } + + /* + * If there is some space left for spare padding, we will code them. + * If the bit pos pointer goes beyond the message border, ccd will detect + * this later and bring a warning. But not here. Reason: saving room. + */ + if (globs->bitpos - globs->bitoffs < msgLen ) + { + /* + * The IE should be present in the message so we code 0 bit. + */ + bf_writeBit (0, globs); + + if (melem[e_ref].elemType EQ 'S' AND spare[melem[e_ref].elemRef].bSize EQ 8) + { + ULONG spareVal = spare[melem[e_ref].elemRef].value; + /* + * Element is a SPARE of length 8. + */ + while (globs->bitpos % 8 NEQ 0) + { + switch(spareVal) + { + case 0: + break; + case 0x2B: + padd_bit = (UBYTE)GET_HL(0); + break; + default: + ccd_setError (globs, ERR_INTERNAL_ERROR, + BREAK, + (USHORT) (globs->bitpos), + (USHORT) -1); + } + bf_writeBit (padd_bit, globs); + } + + /* Write spare padding octets. */ + if (paddingOctets) + { + while (globs->bitpos - globs->bitoffs < msgLen ) + { + bf_codeLongNumber (8, spareVal, globs); + } + } + } + + else + { + ccd_setError (globs, ERR_INVALID_TYPE, + BREAK, + (USHORT) (globs->bitpos), + (USHORT) -1); + } + } + + return 1; +} +#endif /* !RUN_FLASH */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/t30_ident.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,429 @@ +/* ++----------------------------------------------------------------------------- +| Project : +| Modul : t30_ident.c ++----------------------------------------------------------------------------- +| Copyright 2002 Texas Instruments Berlin, AG +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Berlin, AG +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Berlin, AG. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for T30_IDENT elements ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only + * look at ccdapi.h + */ +#undef USE_DRIVER +#include "ccdapi.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" +#include "bitfun.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +#include "ccddata.h" + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_t30_ident_decode | ++--------------------------------------------------------------------+ + + PURPOSE : + +*/ + +SHORT cdc_t30_ident_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG max_rep; + BOOL is_variable; + UBYTE digBuffer[30], bit, digT30, digASCII; + UBYTE *addr_c_xxx; + int i, repeat; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + register UBYTE *ident; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_t30_ident_decode()"); + #else + TRACE_CCD (globs, "cdc_t30_ident_decode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * if this element is conditional, check the condition + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + /* + * if this element have a defined Prolog + * we have to process it before decoding the bitstream + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + /* + * if this element is repeatable, and the number of + * repeats depends on another element, calculate the repeater + */ + + if (melem[e_ref].repType NEQ ' ') + { + ULONG rep; + is_variable = ccd_calculateRep (e_ref, &rep, &max_rep, globs); + repeat = rep; + } + else + { + repeat = 1; + is_variable = FALSE; + } + + /* + * setup the offset into the C-structure for this element + */ + globs->pstructOffs = melem[e_ref].structOffs; + + if (melem[e_ref].optional) + { + /* + * for optional elements set the valid-flag + */ + globs->pstruct[globs->pstructOffs++] = (UBYTE) TRUE; + } + + + if (is_variable) + { + /* + * for variable sized elements store the min-value + * as counter into the C-Structure (c_xxx). + */ + addr_c_xxx = (UBYTE *) (globs->pstruct + globs->pstructOffs++); + if (max_rep > 255) + globs->pstructOffs++; + } + else + addr_c_xxx = NULL; + + /* + * calculate the address of the Most Significant Digit + * of the T30_IDENT element in the C-struct + */ + ident = (UBYTE *) (globs->pstruct + globs->pstructOffs); + + + /* + * now read 'repeat' T30_IDENT digits and convert them + * into ASCII. + */ + i=0; + + while (!bf_endOfBitstream(globs) AND i<repeat) + { + digT30 = bf_decodeByteNumber (8, globs); +#ifdef DEBUG_CCD + TRACE_CCD (globs, "T30 digit (%X) read", digT30); +#endif + /* + * conversion T30->ASCII + * reverse the bitorder of each byte + */ + digASCII = 0; + + for (bit = 0; bit < 8; bit++) + { + digASCII <<= 1; + digASCII |= (digT30 & 0x01); + digT30 >>= 1; + } + + digBuffer[i] = digASCII; +#ifdef DEBUG_CCD + TRACE_CCD (globs, " converted to %X = %c", digBuffer[i], digBuffer[i]); +#endif + i++; + } + + /* + * eleminate leading spaces + */ + while (i > 0 AND digBuffer[i-1] EQ ' ') + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "eliminating leading space"); +#endif + i--; + } + + repeat = i; + + + if (addr_c_xxx NEQ NULL) + { + /* + * store the number of digits into the + * c_xxx variable if there is one. + */ + if (max_rep > 65535) + { + ULONG *addr_c_xxx_u32; + addr_c_xxx_u32 = (ULONG *)addr_c_xxx; + *addr_c_xxx_u32 = (ULONG) repeat; +#ifdef DEBUG_CCD + TRACE_CCD (globs, "storing %d into counter var at (%lx)", + repeat, addr_c_xxx_u32); +#endif + } + else if (max_rep > 255) + { + USHORT *addr_c_xxx_u16; + addr_c_xxx_u16 = (USHORT *)addr_c_xxx; + *addr_c_xxx_u16 = (USHORT) repeat; +#ifdef DEBUG_CCD + TRACE_CCD (globs, "storing %d into counter var at (%lx)", + repeat, addr_c_xxx_u16); +#endif + } + else + { + *addr_c_xxx = (UBYTE) repeat; +#ifdef DEBUG_CCD + TRACE_CCD (globs, "storing %d into counter var at (%lx)", + repeat, + addr_c_xxx); +#endif + } + } + + /* + * store the digits in reverse order + * into the C-Structure variable + */ +#ifdef DEBUG_CCD + TRACE_CCD (globs, "storing %d digits into cstruct at (%lx)", + repeat, + ident); +#endif + + for (i=0; i<repeat; i++) + ident[i] = digBuffer[(repeat-1)-i]; + + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD (6144) MODULE : CCD | +| STATE : code ROUTINE : cdc_t30_ident_encode | ++--------------------------------------------------------------------+ + + PURPOSE : + +*/ + + +SHORT cdc_t30_ident_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + ULONG repeat, max_rep; + UBYTE digBuffer[30], bit, digT30, digASCII; + ULONG i; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + register UBYTE *ident; + +#ifdef DEBUG_CCD + #ifndef CCD_SYMBOLS + TRACE_CCD (globs, "cdc_t30_ident_encode()"); + #else + TRACE_CCD (globs, "cdc_t30_ident_encode() %s", ccddata_get_alias((USHORT) e_ref, 1)); + #endif +#endif + + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * if this element is conditional, check the condition + */ + if (calcidx[cix_ref].numCondCalcs NEQ 0 + AND ! ccd_conditionOK (e_ref, globs)) + return 1; + + /* + * if this element have a defined Prolog + * we have to process it before encoding + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + /* + * setup the offset into the C-structure for this element + */ + globs->pstructOffs = melem[e_ref].structOffs; + + if (melem[e_ref].optional) + { + /* + * for optional elements check the valid-flag + */ + if (globs->pstruct[globs->pstructOffs++] == FALSE) + { + return 1; + } +#ifdef DEBUG_CCD + else if (globs->pstruct [melem[e_ref].structOffs] != TRUE) + { + TRACE_CCD (globs, "Ambiguous value for valid flag!\n...assumed 1 for ccdID=%d", + e_ref); + } +#endif + } + + /* + * if this element is repeatable, and the number of + * repeats depends on another element, calculate the repeater + */ + if (melem[e_ref].repType EQ 'v' OR melem[e_ref].repType EQ 'i') + { + /* + * for variable sized elements read the amount + * of repeats out of the C-Structure (c_xxx). + * If the number of repeats given by the C-Structure + * exceeds the allowed value (maxRepeat) CCD gives a warning! + */ + if (melem[e_ref].maxRepeat > 255) + { + ULONG count = (ULONG) (* (USHORT *)(globs->pstruct + globs->pstructOffs++)); + repeat = MINIMUM (count, (ULONG) melem[e_ref].maxRepeat); + if (repeat < count) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + else + { + repeat = (ULONG) MINIMUM (globs->pstruct[globs->pstructOffs], + melem[e_ref].maxRepeat); + if ( repeat < (ULONG) (globs->pstruct[globs->pstructOffs]) ) + ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE, + (USHORT) e_ref, globs->pstruct + globs->pstructOffs); + } + globs->pstructOffs++; + max_rep = (ULONG) melem[e_ref].maxRepeat; + } + else + if (melem[e_ref].repType EQ 'c') + { + repeat = (ULONG) melem[e_ref].maxRepeat; + max_rep = (ULONG) melem[e_ref].maxRepeat; + } + else + { + repeat = 1; + max_rep = 1; + } + + /* + * setup the read pointer to the byte array that contain + * the ident number. + */ + ident = (UBYTE *) (globs->pstruct + globs->pstructOffs); + + /* + * read the digits in reverse order out of the C-Structure variable. + * (filled up with blanks to the maxRepeat) + */ + + i=0; + + while (i < max_rep) + { + if (i < repeat) + digBuffer[i] = ident[(repeat-1)-i]; + else + { +#ifdef DEBUG_CCD + TRACE_CCD (globs, "appending space char"); +#endif + digBuffer[i] = ' '; + } + i++; + } + + /* + * now read 'repeat' T30_IDENT digits and convert them + * into ASCII. + */ + i=0; + + while (i < max_rep) + { + digASCII = digBuffer[i]; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "ASCII digit (%X) = %c ", (USHORT) digASCII, digASCII); +#endif + /* + * conversion ASCII->T30 + * reverse the bitorder of each byte + */ + digT30 = 0; + + for (bit = 0; bit < 8; bit++) + { + digT30 <<= 1; + digT30 |= (digASCII & 0x01); + digASCII >>= 1; + } + +#ifdef DEBUG_CCD + TRACE_CCD (globs, " converted to %X", (USHORT) digT30); +#endif + bf_codeByteNumber (8, digT30, globs); + + i++; + } + + return 1; +} +#endif /* !RUN_INT_RAM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gsm-fw/ccd/tdd_ci.c Thu Sep 04 05:48:57 2014 +0000 @@ -0,0 +1,213 @@ +/* ++----------------------------------------------------------------------------- +| Project : CCD +| Modul : tdd_ci.c ++----------------------------------------------------------------------------- +| Copyright 2004 Texas Instruments Deutschland GmbH +| All rights reserved. +| +| This file is confidential and a trade secret of Texas +| Instruments Deutschland GmbH +| The receipt of or possession of this file does not convey +| any rights to reproduce or disclose its contents or to +| manufacture, use, or sell anything it may describe, in +| whole, or in part, without the specific written consent of +| Texas Instruments Deutschland GmbH. ++----------------------------------------------------------------------------- +| Purpose : Definition of encoding and decoding functions for TDD_CI type ++----------------------------------------------------------------------------- +*/ + + +/* + * standard definitions like GLOBAL, UCHAR, ERROR etc. + */ +#include "typedefs.h" +#include "header.h" + +/* + * Types and functions for bit access and manipulation + */ +#include "ccd_globs.h" + +/* + * Prototypes of ccd internal functions + */ +#include "ccd.h" +#include "bitfun.h" + +/* + * Declaration of coder/decoder tables + */ +#include "ccdtable.h" +/* + * Function prototypes of CCD-CCDDATA interface + */ +#include "ccddata.h" + + +#if !(defined (CCD_TEST)) +#include "vsi.h" +#endif + +#ifndef RUN_INT_RAM +/* Attention: static data, only used in cdc_tdd_ci_decode */ +static const U8 params_bSize[21] = +{ + 0, + 9, + 17, 25, + 32, 39, 46, 53, + 59, 65, 71, 77, 83, 89, 95, 101, + 106, 111, 116, 121, 126 +}; +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD MODULE : cdc_tdd_ci_decode | ++--------------------------------------------------------------------+ + + PURPOSE : Decoding of the TDD_CELL_INFORMATION Field reusing + RANGE 511 format of frequency lists (with w0=0.). + This field allows to compute a set of 9-bit-long + TDD_CELL_INFORMATION aprameters. + The IE is preceded by TDD_Indic0(1 bit) and made of the + following two IEs: + 1) NR_OF_TDD_CELLS(5 bit field), + 2) TDD_CELL_INFORMATION information parameters + + TDD_Indic0 indicates if the parameter value '0000000000' + is a member of the set. + The total number of bits q of this field depends on the + value of the parameter NR_OF_TDD_CELLS = m + as follows (with q=0 if m=0): + m q m q m q m q m q + 0 0 5 39 10 71 15 101 20 126 + 1 9 6 46 11 77 16 106 21-31 0 + 2 17 7 53 12 83 17 111 + 3 25 8 59 13 89 18 116 + 4 32 9 65 14 95 19 121 + + The message is sent from net to MS and a MS supporting + enhanced measurements has to understand it. + + The space this IE takes in the C-structure is made of a + counter for the number of decoded parameter and an array + of them. +*/ + +SHORT cdc_tdd_ci_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + U8 ListSize = 0; + U16 ListBitLen = 0; + ULONG cix_ref, num_prolog_steps, prolog_step_ref; + short *w; + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "cdc_tdd_ci_decode()"); +#ifdef CCD_SYMBOLS + TRACE_CCD (globs, "decoding list %s with range 512 format", + ccddata_get_alias((USHORT) e_ref, 1)); +#else + TRACE_CCD (globs, "decoding list %d of range 512 format", melem[e_ref].elemRef); +#endif +#endif + + globs->SeekTLVExt = FALSE; + cix_ref = melem[e_ref].calcIdxRef; + num_prolog_steps = calcidx[cix_ref].numPrologSteps; + prolog_step_ref = calcidx[cix_ref].prologStepRef; + + /* + * if this element have a defined Prolog + * we have to process it before decoding the bitstream + */ + if (num_prolog_steps) + { + ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); + } + + /* + * First read NR_OF_TDD_CELLS (5 bits). + */ + globs->pstructOffs = melem[e_ref].structOffs;; + bf_readBits (5, globs); + ListSize = globs->pstruct[globs->pstructOffs++]; + + /* If n=0 there is nothing to do for this IE. */ + if (!ListSize) + { + return 1; + } + + /* Read the corresponding bit number or suppose the maximum length. */ + if (ListSize <= 20) + { + ListBitLen = params_bSize [ListSize]; + } + else + { + /* If n>20 there is nothing to do for this IE. */ + return 1; + } + /* + * Bit size for params is bigger than the size of unread bits in the + * message buffer. Danger: buffer overwriting! + */ + if ( ListBitLen > globs->maxBitpos - globs->bitpos) + { + ccd_recordFault (globs, ERR_ELEM_LEN, BREAK, (USHORT) e_ref, + globs->pstruct + globs->pstructOffs); + ListBitLen = (U16)(globs->maxBitpos - globs->bitpos); + } + /* + * Use dynamic memory for calculation instead of global memory or stack. + */ + MALLOC (w, 257 * sizeof (U16)); + + + /* + * Decode the W-parameter. + * As a rule for this type w(0) must be 0. + */ + w[0] = 0; + cdc_decode_param (param_512+1, &w[1], ListBitLen, globs); + + /* + * Decode and set the remaining channel number according the + * algorithm described in GSM 4.08. + */ + cdc_decode_frequencies (511, &w[1], 0, TDD_CI_LIST, globs); + + /* Free the dynamic allocated memory. */ + MFREE (w); + + return 1; +} +#endif /* !RUN_INT_RAM */ + +#ifndef RUN_INT_RAM +/* ++--------------------------------------------------------------------+ +| PROJECT : CCD MODULE : cdc_tdd_ci_encode | ++--------------------------------------------------------------------+ + + PURPOSE : Encoding function is not needed, since this message is + sent from net to MS. + It could be only useful for testing procedure if there + were an encoder function at this place. + This will be a future work. + +*/ + +SHORT cdc_tdd_ci_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) +{ + +#ifdef DEBUG_CCD + TRACE_CCD (globs, "cdc_tdd_ci_encode()"); +#endif +#ifdef TARGET_WIN32 + /* TBD */ +#endif + return 1; +} +#endif /* !RUN_INT_RAM */