comparison src/gpf/ccd/Ccdedit.c @ 0:4e78acac3d88

src/{condat,cs,gpf,nucleus}: import from Selenite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 06:23:26 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4e78acac3d88
1 /*
2 +-----------------------------------------------------------------------------
3 | Project :
4 | Modul : Ccdedit.c
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : Coder Decoder editfunctions for reading/writing the
18 | C-Structures of primitives and messages.
19 +-----------------------------------------------------------------------------
20 */
21
22 #define CCDEDIT_C
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 /*
29 * standard definitions like UCHAR, ERROR etc.
30 */
31 #include "typedefs.h"
32
33
34 /*
35 * Declaration of coder/decoder-tables
36 */
37 #include "ccdtable.h"
38 #include "ccddata.h"
39
40 #include "ccdedit.h"
41
42 typedef union
43 {
44 UBYTE buffer[4];
45 UBYTE b[4];
46 USHORT s[2];
47 ULONG l;
48 } T_CONV;
49
50 typedef enum
51 {
52 isvar,
53 isstruct,
54 isunion,
55 issdu,
56 isductrl
57 } T_ELEMTYPE;
58
59 /*
60 * strncpy() does not append a null chararcter to the copied string;
61 * This macro adds a terminating null following a call to strncpy()
62 * In Ccdedit.h the buffers are all len+1 bytes long.
63 */
64 #define STRNCPY(dest,source,len) {\
65 strncpy (dest, source, len);\
66 dest [len] = 0;\
67 }
68
69
70 static const T_CCD_CompTabEntry* mcomp;
71 static const T_CCD_CompTabEntry* pcomp;
72 static const T_CCD_VarTabEntry* pvar;
73 static const T_CCD_ElemTabEntry* pelem;
74 static const T_CCD_StrTabEntry* pstr;
75 static const T_CCD_VarTabEntry* mvar;
76 static const T_CCD_ElemTabEntry* melem;
77 static const T_CCD_StrTabEntry* mstr;
78 static const T_CCD_ValTabEntry* mval;
79 static const T_CCD_ValTabEntry* pval;
80 static int ccddata_num_of_entities;
81 static int ccddata_max_message_id;
82 static int ccddata_max_primitive_id;
83 static int ccddata_max_sap_num;
84
85
86 void CCDDATA_PREF(cde_init) ()
87 {
88 mcomp = ccddata_get_mcomp (0);
89 pcomp = ccddata_get_pcomp (0);
90 pvar = ccddata_get_pvar (0);
91 pelem = ccddata_get_pelem (0);
92 pstr = ccddata_get_pstr (0);
93 mvar = ccddata_get_mvar (0);
94 melem = ccddata_get_melem (0);
95 mstr = ccddata_get_mstr (0);
96 mval = ccddata_get_mval (0);
97 pval = ccddata_get_pval (0);
98 ccddata_num_of_entities = ccddata_get_num_of_entities ();
99 ccddata_max_message_id = ccddata_get_max_message_id ();
100 ccddata_max_primitive_id = ccddata_get_max_primitive_id ();
101 ccddata_max_sap_num = ccddata_get_max_sap_num ();
102 }
103
104 /*
105 +------------------------------------------------------------------------------
106 | Function : cde_val_iterate
107 +------------------------------------------------------------------------------
108 | Description : This function searches the values in [pm]val.cdg for
109 | a given value and depending on the value of the parameter
110 | 'copy' adds the "Comment" of the SAP-/MSG-catalogues
111 | to the member symbolicValue of a given T_CCDE_ELEM_DESCR.
112 |
113 | Parameters : elem_value - the actual value searched for
114 | edescr - the element descriptor
115 | copy - s.a.
116 |
117 | Return : -1 if no values are defined or if the value is not found;
118 | else: the ordinal of the value in relation to first valid
119 | value of the var
120 +------------------------------------------------------------------------------
121 */
122
123 static void cde_val_iterate (int elem_value,
124 T_CCDE_ELEM_DESCR* edescr)
125 {
126
127 S32 StartVal, EndVal;
128 BOOL IsDefault;
129 char *ValStr;
130 SHORT NumDefs;
131 USHORT ValueDef;
132 USHORT valdefstart;
133 const T_CCD_ValTabEntry* val;
134 const T_CCD_StrTabEntry* str;
135
136 if (edescr->ccdIndex == NO_REF)
137 return;
138
139 if (edescr->esource EQ FromMsg)
140 {
141 NumDefs = mvar[edescr->ccdIndex].numValueDefs;
142 ValueDef = mvar[edescr->ccdIndex].valueDefs;
143 val = mval;
144 str = mstr;
145 }
146 else
147 {
148 NumDefs = pvar[edescr->ccdIndex].numValueDefs;
149 ValueDef = pvar[edescr->ccdIndex].valueDefs;
150 val = pval;
151 str = pstr;
152 }
153
154 valdefstart = ValueDef;
155
156 edescr->valcheck = NumDefs ? -1 : 1;
157 while (NumDefs-- > 0)
158 {
159 IsDefault = val[ValueDef].isDefault;
160 ValStr = str[val[ValueDef].valStringRef];
161 StartVal = val[ValueDef].startValue;
162 EndVal = val[ValueDef].endValue;
163
164 if (IsDefault)
165 {
166 /* default definition */
167
168 STRNCPY (edescr->symbolicValue, ValStr, SYMBOLIC_VAL_LENGTH);
169 /*
170 * If IsDefault is 2 it is an ASN1 default value; StartVal and EndVal
171 * are set to the value. If IsDefault is 1, it means only a default
172 * symbolic value, but StartVal and EndVal are not set. In this case
173 * valcheck get the value 0.
174 */
175 if (IsDefault == 2)
176 {
177 if (elem_value == StartVal)
178 {
179 edescr->valcheck = 1;
180 return;
181 }
182 }
183 else
184 {
185 edescr->valcheck = 0;
186 }
187 }
188 else
189 {
190 if (elem_value == StartVal && elem_value == EndVal)
191 {
192 STRNCPY (edescr->symbolicValue, ValStr, SYMBOLIC_VAL_LENGTH);
193 edescr->valcheck = 1;
194 return;
195 }
196
197 if (elem_value >= StartVal AND elem_value <= EndVal)
198 {
199 /* found in range, but continue to search an exact match */
200 STRNCPY (edescr->symbolicValue, ValStr, SYMBOLIC_VAL_LENGTH);
201 edescr->valcheck = 1;
202 }
203 }
204 ValueDef++;
205 }
206 }
207
208 static void eval_elemtype (T_CCDE_ELEM_DESCR* edescr,
209 const T_CCD_ElemTabEntry* elem,
210 T_ELEMTYPE* elemtype,
211 BOOL* linked)
212 {
213 *linked = FALSE;
214
215 switch (elem->elemType)
216 {
217 case 'W':
218 case 'M':
219 case 'I':
220 *linked = TRUE;
221 /* fallthrough */
222 case 'V':
223 case 'R':
224 case 'F':
225 *elemtype = isvar;
226 break;
227
228 case 'Z':
229 case 'K':
230 case 'G':
231 *linked = TRUE;
232 /* fallthrough */
233 case 'C':
234 case 'P':
235 case 'D':
236 *elemtype = isstruct;
237 break;
238
239 case 'c':
240 case 'p':
241 case 'd':
242 *elemtype = issdu;
243 break;
244
245 case 'Y':
246 case 'L':
247 case 'H':
248 *linked = TRUE;
249 /* fallthrough */
250 case 'U':
251 case 'Q':
252 case 'E':
253 *elemtype = isunion;
254 break;
255 case '!':
256 *elemtype = isductrl;
257 break;
258 }
259 if ((elem->elemType >= 'P' && elem->elemType <= 'R') ||
260 (elem->elemType >= 'K' && elem->elemType <= 'M') ||
261 elem->elemType == 'p')
262 edescr->ptrtype = usptr;
263 else if((elem->elemType >= 'D' && elem->elemType <= 'F') ||
264 (elem->elemType >= 'G' && elem->elemType <= 'I') ||
265 elem->elemType == 'd')
266 edescr->ptrtype = ctptr;
267 else
268 edescr->ptrtype = noptr;
269 }
270
271
272 /*
273 +--------------------------------------------------------------------+
274 | PROJECT : CCD (6144) MODULE : CCDEDIT |
275 | STATE : code ROUTINE : cde_get_next_elem |
276 +--------------------------------------------------------------------+
277
278 PURPOSE :
279
280 */
281
282 static USHORT cde_get_next_elem (T_CCDE_HANDLE *handle,
283 UBYTE descent,
284 T_CCDE_ELEM_DESCR *edescr)
285 {
286 T_CCDE_CONTEXT * ctx;
287 BOOL isMsg;
288 BOOL linked;
289 BOOL validElemFound = FALSE;
290 const T_CCD_VarTabEntry *var;
291 const T_CCD_CompTabEntry *comp;
292 const T_CCD_ElemTabEntry *elem;
293 const T_CCD_StrTabEntry *str;
294 T_ELEMTYPE elemtype;
295
296 isMsg = handle->source == FromMsg;
297
298 if (isMsg)
299 /* var, str, and comp may become reset later */
300 {
301 comp = mcomp;
302 elem = melem;
303 str = mstr;
304 var = mvar;
305 }
306 else
307 {
308 comp = pcomp;
309 elem = pelem;
310 str = pstr;
311 var = pvar;
312 }
313
314 if (descent > handle->level AND handle->canDescent)
315 handle->level++;
316
317 handle->canDescent = FALSE;
318
319 ctx = &handle->context[handle->level];
320
321 do
322 {
323 if (ctx->numElems EQ 0)
324 {
325 /*
326 * end of composition or maybe of the entire message/primitive.
327 */
328 if (handle->level > 0)
329 {
330 /*
331 * end of substructured element.
332 * switch to the context of the previous level.
333 */
334 handle->level--;
335 ctx = &handle->context[handle->level];
336 }
337 else
338 {
339 edescr->offset = comp[ctx->structIdx].cSize
340 + handle->lenVarPart;
341 return isMsg ? CCDEDIT_END_OF_MSG : CCDEDIT_END_OF_PRIM;
342 }
343 }
344 /*
345 * skip the spare elements (do it only for messages)
346 */
347 if (ctx->numElems)
348 {
349 /*
350 * remember: primitives does not contain spare definitions
351 */
352 if (elem[ctx->elemIdx].elemType == 'S')
353 {
354 ctx->elemIdx++;
355 ctx->numElems--;
356 }
357 else
358 validElemFound = TRUE;
359 }
360 } while (!validElemFound);
361
362
363 eval_elemtype (edescr, &elem[ctx->elemIdx], &elemtype, &linked);
364
365 if (elemtype == isductrl)
366 {
367 edescr->btype = T_ductrl;
368 ctx->elemIdx++;
369 ctx->numElems--;
370 return CCDEDIT_OK;
371 }
372
373 if (linked)
374 {
375 /* element linked from pelem to mvar/mcomp */
376 edescr->esource = FromMsg;
377 comp = mcomp;
378 var = mvar;
379 str = mstr;
380 }
381 else
382 edescr->esource = handle->source;
383
384 if (ctx->state EQ TRAVERSE_ARRAY)
385 {
386 /*
387 * for every array element calculate the offset for the
388 * C-structure access.
389 * offset = leveloffset + (arrayIndex * csize) + 1
390 */
391 edescr->offset = elem[ctx->elemIdx].structOffs + ctx->levelOffset
392 + (ctx->arrayIndex
393 * ((elem[ctx->elemIdx].elemType NEQ 'C')
394 ? var[elem[ctx->elemIdx].elemRef].cSize
395 : comp[elem[ctx->elemIdx].elemRef].cSize
396 )
397 );
398 /*
399 + 1;
400 */
401 }
402 else
403 {
404 edescr->offset = elem[ctx->elemIdx].structOffs
405 + ctx->levelOffset;
406 }
407
408 edescr->level = handle->level;
409 edescr->maxRepeat = elem[ctx->elemIdx].maxRepeat;
410 edescr->index = NO_REF;
411 edescr->ccdIndex = NO_REF;
412 edescr->validRepeats = NO_REF;
413 edescr->isOptional = elem[ctx->elemIdx].optional;
414 edescr->arrayType = NoArray;
415 edescr->elemref = NO_REF;
416 edescr->u_member = FALSE;
417 edescr->u_ctrl = 0xffffffff;
418 edescr->bitstring = 0;
419 edescr->c_implicit = 1;
420 edescr->issigned = 0;
421 edescr->valcheck = 0;
422
423 if ( edescr->maxRepeat > 0
424 && elem[ctx->elemIdx].repType != 'b'
425 && elem[ctx->elemIdx].repType != 's'
426 && elem[ctx->elemIdx].elemType != 'E'
427 && ctx->state == TRAVERSE_STRUCTURE)
428 {
429 edescr->arrayType = ( elem[ctx->elemIdx].repType == 'v'
430 || elem[ctx->elemIdx].repType == 'i'
431 || elem[ctx->elemIdx].repType == 'J'
432 || elem[ctx->elemIdx].repType == 'j')
433 ? VarArray
434 : FixArray;
435
436 if (elem[ctx->elemIdx].repType == 'C'
437 || elem[ctx->elemIdx].repType == 'J')
438 edescr->bitstring = 1;
439
440 if (elem[ctx->elemIdx].repType == 'j'
441 || elem[ctx->elemIdx].repType == 'J')
442 edescr->c_implicit = 0;
443
444 if (handle->level < MAX_LEVELS)
445 {
446 T_CCDE_CONTEXT * new_ctx = ctx+1;
447
448 ctx->repeats = edescr->maxRepeat;
449
450 handle->canDescent = TRUE;
451
452 new_ctx->structIdx = ctx->structIdx;
453
454 new_ctx->elemIdx = ctx->elemIdx;
455 new_ctx->elemType = 0;
456 new_ctx->arrayIndex = 0;
457 new_ctx->numElems = edescr->maxRepeat;
458 new_ctx->levelOffset = ctx->levelOffset;
459 new_ctx->arrayType = edescr->arrayType;
460 new_ctx->state = TRAVERSE_ARRAY;
461 /*
462 * if the composition is optional, increment the offset
463 * because of the valid flag (v_xxx).
464 */
465 if (edescr->isOptional)
466 new_ctx->levelOffset++;
467 /*
468 * if the composition is a array with variable size,
469 * increment the offset because of the counter (c_xxx).
470 */
471 if (edescr->arrayType EQ VarArray)
472 new_ctx->levelOffset += edescr->maxRepeat >> 8 ? 2 : 1;
473 }
474 }
475
476 if (ctx->state EQ TRAVERSE_ARRAY)
477 {
478 /*
479 * if the size of the array is variable, mark the
480 * components of this array as optional. So we can later
481 * determine if the array component is valid
482 */
483 if (ctx->arrayType EQ VarArray)
484 edescr->isOptional = TRUE;
485 /*
486 * increment the array index
487 */
488 edescr->index = ctx->arrayIndex++;
489 }
490
491 if (elemtype == isvar)
492 {
493 /*
494 * basic element (var)
495 */
496 switch (var[elem[ctx->elemIdx].elemRef].cType)
497 {
498 case 'C':
499 edescr->issigned = 1;
500 /* fallthrough */
501 case 'B':
502 edescr->btype = T_byte;
503 break;
504 case 'T':
505 edescr->issigned = 1;
506 /* fallthrough */
507 case 'S':
508 edescr->btype = T_short;
509 break;
510 case 'M':
511 edescr->issigned = 1;
512 /* fallthrough */
513 case 'L':
514 edescr->btype = T_long;
515 break;
516 case 'X':
517 edescr->btype = T_buffer;
518 break;
519 }
520 edescr->bytelen = var[elem[ctx->elemIdx].elemRef].cSize;
521
522 #ifdef CCD_SYMBOLS
523 strcpy (edescr->aname, var[elem[ctx->elemIdx].elemRef].name);
524 strcpy (edescr->sname, ccddata_get_alias (ctx->elemIdx, (int) isMsg));
525 if (edescr->sname[0] == '\0')
526 strcpy (edescr->sname, var[elem[ctx->elemIdx].elemRef].name);
527 STRNCPY (edescr->lname, str[var[elem[ctx->elemIdx].elemRef].longNameRef],
528 LONG_NAME_LENGTH);
529 #else
530 strcpy (edescr->sname, "No name info avail.");
531 strcpy (edescr->aname, "No name info avail.");
532 strcpy (edescr->lname, "No name info avail.");
533 #endif
534 }
535 else if (elemtype == isunion)
536 {
537 /* union */
538 edescr->btype = T_union;
539 edescr->bytelen = comp[elem[ctx->elemIdx].elemRef].cSize;
540 edescr->elemref = elem[ctx->elemIdx].elemRef;
541
542 #ifdef CCD_SYMBOLS
543 strcpy (edescr->aname, comp[elem[ctx->elemIdx].elemRef].name);
544 strcpy (edescr->sname, ccddata_get_alias (ctx->elemIdx, (int) isMsg));
545 if (edescr->sname[0] == '\0')
546 strcpy (edescr->sname, comp[elem[ctx->elemIdx].elemRef].name);
547 STRNCPY (edescr->lname, str[comp[elem[ctx->elemIdx].elemRef].longNameRef],
548 LONG_NAME_LENGTH);
549 #else
550 strcpy (edescr->sname, "No name info avail.");
551 strcpy (edescr->aname, "No name info avail.");
552 strcpy (edescr->lname, "No name info avail.");
553 #endif
554 }
555 else
556 {
557 /*
558 * substructured info element
559 */
560 if (elemtype == issdu)
561 edescr->btype = T_issdu;
562 else
563 edescr->btype = T_struct;
564 edescr->bytelen = comp[elem[ctx->elemIdx].elemRef].cSize;
565 edescr->elemref = elem[ctx->elemIdx].elemRef;
566
567 #ifdef CCD_SYMBOLS
568 strcpy (edescr->aname, comp[elem[ctx->elemIdx].elemRef].name);
569 strcpy (edescr->sname, ccddata_get_alias (ctx->elemIdx, (int) isMsg));
570 if (edescr->sname[0] == '\0')
571 strcpy (edescr->sname, comp[elem[ctx->elemIdx].elemRef].name);
572 STRNCPY (edescr->lname, str[comp[elem[ctx->elemIdx].elemRef].longNameRef],
573 LONG_NAME_LENGTH);
574 #else
575 strcpy (edescr->sname, "No name info avail.");
576 strcpy (edescr->aname, "No name info avail.");
577 strcpy (edescr->lname, "No name info avail.");
578 #endif
579 if (edescr->arrayType EQ NoArray
580 AND handle->level < MAX_LEVELS)
581 {
582 T_CCDE_CONTEXT * new_ctx = ctx+1;
583
584 handle->canDescent = TRUE;
585
586 new_ctx->structIdx = elem[ctx->elemIdx].elemRef;
587
588 new_ctx->elemIdx = comp[new_ctx->structIdx].componentRef;
589 new_ctx->elemType = 0;
590 new_ctx->arrayIndex = 0;
591 new_ctx->numElems = comp[new_ctx->structIdx].numOfComponents;
592 new_ctx->levelOffset = edescr->offset;
593 /*
594 * if the composition is optional, increment the offset
595 * because of the valid flag (v_xxx).
596 */
597 if (edescr->isOptional)
598 new_ctx->levelOffset++;
599 /*
600 * if the composition is a array with variable size,
601 * increment the offset because of the counter (c_xxx).
602 */
603 if (edescr->arrayType EQ VarArray)
604 new_ctx->levelOffset++;
605
606 new_ctx->state = TRAVERSE_STRUCTURE;
607 }
608 }
609
610
611 if (edescr->arrayType EQ NoArray && elem[ctx->elemIdx].elemType == 'V'
612 AND var[elem[ctx->elemIdx].elemRef].numValueDefs > 0)
613 {
614 /*
615 * value definitions available
616 * store the index of this information element in the
617 * element descriptor for later value requests.
618 */
619 edescr->ccdIndex = elem[ctx->elemIdx].elemRef;
620 }
621
622 ctx->numElems--;
623
624 if (ctx->state EQ TRAVERSE_STRUCTURE)
625 ctx->elemIdx++;
626
627 return CCDEDIT_OK;
628 }
629
630 /*
631 +--------------------------------------------------------------------+
632 | PROJECT : CCD (6144) MODULE : CCDEDIT |
633 | STATE : code ROUTINE : cde_prim_first |
634 +--------------------------------------------------------------------+
635
636 PURPOSE :
637
638 */
639
640 USHORT CCDDATA_PREF(cde_prim_first) (T_CCDE_HANDLE * phandle,
641 ULONG primcode,
642 char * name)
643 {
644 USHORT SAP, Opcode, Direction, ThePrimitive;
645
646 if (primcode & 0x80000000)
647 {
648 SAP = (USHORT) (primcode & 0x3fff);
649 Opcode = (USHORT) ((primcode >> 16) & 0xff);
650 }
651 else
652 {
653 SAP = (USHORT) (((primcode & 0x3f00)>>8) & 0xff);
654 Opcode = (USHORT) (primcode & 0xff);
655 }
656 Direction = (USHORT) (((primcode & 0x4000)>>14) & 0x01);
657
658 if (SAP > ccddata_max_sap_num OR Opcode > ccddata_max_primitive_id)
659 return CCDEDIT_PRIM_NOT_FOUND;
660
661 if ((ThePrimitive = ccddata_get_pmtx(SAP,Opcode,Direction)) EQ NO_REF)
662 return CCDEDIT_PRIM_NOT_FOUND;
663
664 phandle->context[0].structIdx = ThePrimitive;
665
666 #ifdef CCD_SYMBOLS
667 strcpy (name, pcomp[phandle->context[0].structIdx].name);
668 #else
669 strcpy (name, "No name info avail.");
670 #endif
671
672 phandle->level = 0;
673 phandle->context[0].elemIdx = pcomp[phandle->context[0].structIdx].componentRef;
674 phandle->context[0].elemType = 0;
675 phandle->context[0].numElems = pcomp[phandle->context[0].structIdx].numOfComponents;
676 phandle->context[0].levelOffset = 0;
677 phandle->context[0].arrayIndex = 0;
678 phandle->context[0].state = TRAVERSE_STRUCTURE;
679 phandle->canDescent = FALSE;
680 phandle->source = FromPrim;
681 phandle->maxCSize = pcomp[phandle->context[0].structIdx].cSize;
682 phandle->lenVarPart = 0;
683
684 return CCDEDIT_OK;
685 }
686
687
688 /*
689 +--------------------------------------------------------------------+
690 | PROJECT : CCD (6144) MODULE : CCDEDIT |
691 | STATE : code ROUTINE : cde_prim_next |
692 +--------------------------------------------------------------------+
693
694 PURPOSE :
695
696 */
697
698
699 USHORT CCDDATA_PREF(cde_prim_next) (T_CCDE_HANDLE *phandle,
700 UBYTE descent,
701 T_CCDE_ELEM_DESCR *pdescr)
702 {
703 return cde_get_next_elem (phandle,
704 descent,
705 pdescr);
706 }
707
708 /*
709 +--------------------------------------------------------------------+
710 | PROJECT : CCD (6144) MODULE : CCDEDIT |
711 | STATE : code ROUTINE : cde_msg_first |
712 +--------------------------------------------------------------------+
713
714 PURPOSE :
715
716 */
717
718 USHORT CCDDATA_PREF(cde_msg_first) (T_CCDE_HANDLE * mhandle,
719 UBYTE type,
720 UBYTE direction,
721 UBYTE entity,
722 char * name)
723
724 {
725 USHORT TheMessage;
726
727 if (entity > ccddata_num_of_entities OR type > ccddata_max_message_id)
728 return CCDEDIT_MESSAGE_NOT_FOUND;
729
730 if ((TheMessage = ccddata_get_mmtx((USHORT) entity,
731 (USHORT) type,
732 (USHORT) direction)) EQ NO_REF)
733 return CCDEDIT_MESSAGE_NOT_FOUND;
734
735 mhandle->context[0].structIdx = TheMessage;
736
737 #ifdef CCD_SYMBOLS
738 strcpy (name, mcomp[mhandle->context[0].structIdx].name);
739 #else
740 strcpy (name, "No name info avail.");
741 #endif
742
743 mhandle->level = 0;
744 mhandle->context[0].elemIdx = mcomp[mhandle->context[0].structIdx].componentRef;
745 mhandle->context[0].elemType = 0;
746 mhandle->context[0].numElems = mcomp[mhandle->context[0].structIdx].numOfComponents;
747 mhandle->context[0].levelOffset = 0;
748 mhandle->context[0].arrayIndex = 0;
749 mhandle->context[0].state = TRAVERSE_STRUCTURE;
750 mhandle->canDescent = FALSE;
751 mhandle->source = FromMsg;
752 mhandle->maxCSize = mcomp[mhandle->context[0].structIdx].cSize;
753 mhandle->lenVarPart = 0;
754
755 return CCDEDIT_OK;
756 }
757
758
759 /*
760 +--------------------------------------------------------------------+
761 | PROJECT : CCD (6144) MODULE : CCDEDIT |
762 | STATE : code ROUTINE : cde_msg_next |
763 +--------------------------------------------------------------------+
764
765 PURPOSE :
766
767 */
768
769 USHORT CCDDATA_PREF(cde_msg_next) (T_CCDE_HANDLE *mhandle,
770 UBYTE descent,
771 T_CCDE_ELEM_DESCR *iedescr)
772 {
773 return cde_get_next_elem (mhandle,
774 descent,
775 iedescr);
776 }
777
778
779 /*
780 +------------------------------------------------------------------------------
781 | Function : cde_get_comp
782 +------------------------------------------------------------------------------
783 | Description : This function works with similar results like cde_comp_first,
784 | but not the whole comp table is searched for the name of the
785 | component. Instead the previous set elemref in the
786 | parameter edescr is taken to directly jump to the component.
787 | The component found is compared with the given name in
788 | edescr. If equal chandle is defined. Otherwise there is an
789 | error.
790 |
791 | Parameters : chandle - the handle for the component (returned)
792 | edescr - the element descriptor
793 |
794 | Return : CCDEDIT_OK on success, CCDEDIT_COMP_NOT_FOUND otherwise
795 +------------------------------------------------------------------------------
796 */
797
798 USHORT CCDDATA_PREF(cde_get_comp) (T_CCDE_HANDLE* chandle,
799 T_CCDE_ELEM_DESCR* edescr)
800 {
801 const T_CCD_CompTabEntry* comp;
802 USHORT index = edescr->elemref;
803
804 if (index == NO_REF)
805 return CCDEDIT_COMP_NOT_FOUND;
806
807 comp = edescr->esource == FromMsg ? &mcomp[index] : &pcomp[index];
808
809 #ifdef CCD_SYMBOLS
810 if (strcmp (comp->name, edescr->aname))
811 return CCDEDIT_COMP_NOT_FOUND;
812 #endif /* CCD_SYMBOLS */
813
814 chandle->context[0].structIdx = index;
815 chandle->level = 0;
816 chandle->context[0].elemIdx = comp->componentRef;
817 chandle->context[0].elemType = 0;
818 chandle->context[0].numElems = comp->numOfComponents;
819 chandle->context[0].levelOffset = 0;
820 chandle->context[0].arrayIndex = 0;
821 chandle->context[0].state = TRAVERSE_STRUCTURE;
822 chandle->canDescent = FALSE;
823 chandle->source = edescr->esource;
824 chandle->maxCSize = comp->cSize;
825 chandle->lenVarPart = 0;
826
827 return CCDEDIT_OK;
828 }
829
830 /*
831 +------------------------------------------------------------------------------
832 | Function : cde_comp_alias
833 +------------------------------------------------------------------------------
834 | Description : This function works with similar results like cde_comp_first,
835 | but not thewhole comp table is searched for the name of the
836 | component. Instead the alias name (as_name) from ?elem.cdg
837 | is taken for name comparison.
838 |
839 | Parameters : chandle - the handle for the component (returned)
840 | source - if message or primitve
841 | name - the name of the searched component
842 |
843 | Return : CCDEDIT_OK on success, CCDEDIT_COMP_NOT_FOUND otherwise
844 +------------------------------------------------------------------------------
845 */
846 USHORT cde_comp_alias (T_CCDE_HANDLE * chandle,
847 T_ELM_SRC source,
848 char * name)
849
850 {
851 const T_CCD_CompTabEntry* comp;
852 const T_CCD_ElemTabEntry* elem;
853 int found = 0;
854 USHORT index, cindex;
855
856 elem = source == FromMsg ? melem : pelem;
857
858 index = 0;
859 while (!found AND (ccddata_get_alias (index, source == FromMsg) != NULL))
860 {
861 /* name found */
862 if (elem[index].elemType == 'C' &&
863 !strcmp (ccddata_get_alias (index, source == FromMsg), name))
864 found = 1;
865 else
866 index++;
867 }
868 if (!found)
869 return CCDEDIT_COMP_NOT_FOUND;
870
871 cindex = elem[index].elemRef;
872 comp = source == FromMsg ? &mcomp[cindex] : &pcomp[cindex];
873 chandle->context[0].structIdx = cindex;
874 chandle->level = 0;
875 chandle->context[0].elemIdx = comp->componentRef;
876 chandle->context[0].elemType = 0;
877 chandle->context[0].numElems = comp->numOfComponents;
878 chandle->context[0].levelOffset = 0;
879 chandle->context[0].arrayIndex = 0;
880 chandle->context[0].state = TRAVERSE_STRUCTURE;
881 chandle->canDescent = FALSE;
882 chandle->source = source;
883 chandle->maxCSize = comp->cSize;
884 chandle->lenVarPart = 0;
885
886 return CCDEDIT_OK;
887 }
888
889 /*
890 +--------------------------------------------------------------------+
891 | PROJECT : CCD (6144) MODULE : CCDEDIT |
892 | STATE : code ROUTINE : cde_comp_first |
893 +--------------------------------------------------------------------+
894
895 PURPOSE :
896
897 */
898
899 USHORT CCDDATA_PREF(cde_comp_first) (T_CCDE_HANDLE * chandle,
900 T_ELM_SRC source,
901 char * compname)
902
903 {
904 USHORT index;
905 BOOL found = FALSE;
906
907 if (source EQ FromMsg)
908 {
909 /*
910 * search the mcomp-table for the given name
911 */
912 index = 0;
913 while (!found AND mcomp[index].name NEQ NULL)
914 {
915 /*
916 * composition name found
917 */
918 if (strcmp (mcomp[index].name, compname) EQ 0)
919 found = TRUE;
920 else
921 index++;
922 }
923 if (found)
924 chandle->context[0].structIdx = index;
925 else
926 return CCDEDIT_COMP_NOT_FOUND;
927
928 chandle->level = 0;
929 chandle->context[0].elemIdx = mcomp[index].componentRef;
930 chandle->context[0].elemType = 0;
931 chandle->context[0].numElems = mcomp[index].numOfComponents;
932 chandle->context[0].levelOffset = 0;
933 chandle->context[0].arrayIndex = 0;
934 chandle->context[0].state = TRAVERSE_STRUCTURE;
935 chandle->canDescent = FALSE;
936 chandle->source = FromMsg;
937 chandle->maxCSize = mcomp[index].cSize;
938 chandle->lenVarPart = 0;
939 }
940 else
941 {
942 /*
943 * search the pcomp-table for the given name
944 */
945 index = 0;
946 while (!found AND pcomp[index].name NEQ NULL)
947 {
948 /*
949 * composition name found
950 */
951 if (strcmp (pcomp[index].name, compname) EQ 0)
952 found = TRUE;
953 else
954 index++;
955 }
956 if (found)
957 chandle->context[0].structIdx = index;
958 else
959 return CCDEDIT_COMP_NOT_FOUND;
960
961 chandle->level = 0;
962 chandle->context[0].elemIdx = pcomp[index].componentRef;
963 chandle->context[0].elemType = 0;
964 chandle->context[0].numElems = pcomp[index].numOfComponents;
965 chandle->context[0].levelOffset = 0;
966 chandle->context[0].arrayIndex = 0;
967 chandle->context[0].state = TRAVERSE_STRUCTURE;
968 chandle->canDescent = FALSE;
969 chandle->source = FromPrim;
970 chandle->maxCSize = pcomp[index].cSize;
971 chandle->lenVarPart = 0;
972 }
973
974 return CCDEDIT_OK;
975 }
976
977 /*
978 +--------------------------------------------------------------------+
979 | PROJECT : CCD (6144) MODULE : CCDEDIT |
980 | STATE : code ROUTINE : cde_comp_next |
981 +--------------------------------------------------------------------+
982
983 PURPOSE :
984
985 */
986
987 USHORT CCDDATA_PREF(cde_comp_next) (T_CCDE_HANDLE *chandle,
988 UBYTE descent,
989 T_CCDE_ELEM_DESCR *descr)
990 {
991 return cde_get_next_elem (chandle,
992 descent,
993 descr);
994 }
995
996 /*
997 +------------------------------------------------------------------------------
998 | Function : cde_get_symval
999 +------------------------------------------------------------------------------
1000 | Description : This function adds the "Comment" of the SAP-/MSG-catalogues
1001 | to the member symbolicValue of a given T_CCDE_ELEM_DESCR.
1002 |
1003 | Parameters : elem_value - the actual value for that the comment
1004 | is searched for
1005 | edescr - the element descriptor
1006 |
1007 | Return : The string itself is returned which is a pointer to
1008 | '\0' if no comment was defined for that value.
1009 +------------------------------------------------------------------------------
1010 */
1011
1012 char* CCDDATA_PREF(cde_get_symval) (int elem_value, T_CCDE_ELEM_DESCR* edescr)
1013 {
1014 edescr->symbolicValue[0] = '\0';
1015
1016 cde_val_iterate (elem_value, edescr);
1017
1018 return edescr->symbolicValue;
1019 }
1020
1021 /*
1022 +--------------------------------------------------------------------+
1023 | PROJECT : CCD (6144) MODULE : CCDEDIT |
1024 | STATE : code ROUTINE : cde_read_elem |
1025 +--------------------------------------------------------------------+
1026
1027 PURPOSE : Reads the value of the element, referenced by the element
1028 descriptor edescr, out of the C-Structure cstruct. The
1029 value is stored in the memory area, addressed by the
1030 parameter value.
1031
1032 */
1033
1034 USHORT CCDDATA_PREF(cde_read_elem) (T_CCDE_HANDLE * handle,
1035 void * cstruct,
1036 T_CCDE_ELEM_DESCR * edescr,
1037 UBYTE * value)
1038 {
1039 T_CONV * cvp;
1040 U32 voffset;
1041 ULONG elem_value;
1042 UBYTE * cs = (UBYTE *) cstruct;
1043
1044 /*
1045 * if this element is optional and it is no array component
1046 * read the valid flag out of the C-structure.
1047 */
1048 if (edescr->isOptional && edescr->index == NO_REF && edescr->ptrtype != usptr)
1049 {
1050 voffset = edescr->offset++;
1051 edescr->isValid = (cs[voffset] EQ TRUE);
1052 }
1053 else
1054 {
1055 if (edescr->index NEQ NO_REF)
1056 {
1057 T_CCDE_CONTEXT *last_ctx;
1058
1059 last_ctx = &handle->context[handle->level-1];
1060 edescr->isValid = (edescr->index < last_ctx->repeats);
1061 }
1062 else
1063 edescr->isValid = TRUE;
1064 }
1065
1066 if (!edescr->isValid)
1067 return CCDEDIT_OK;
1068
1069 if (edescr->u_member)
1070 {
1071 edescr->u_ctrl = * (U32 *) &cs[edescr->offset];
1072 edescr->offset += sizeof (U32);
1073 }
1074
1075 if (edescr->arrayType NEQ NoArray)
1076 {
1077 T_CCDE_CONTEXT *ctx;
1078
1079 ctx = &handle->context[handle->level];
1080
1081 /*
1082 * array of message elements (info elements)
1083 */
1084
1085 if (edescr->arrayType EQ VarArray)
1086 {
1087 USHORT sz_of_len;
1088 sz_of_len = edescr->maxRepeat >> 8 ? 2 : 1; /* 1 or 2 bytes for len */
1089 if (sz_of_len == 1)
1090 {
1091 ctx->repeats = (USHORT) cs[edescr->offset];
1092 }
1093 else
1094 {
1095 ctx->repeats = * (USHORT *) &cs[edescr->offset];
1096 }
1097 edescr->offset += sz_of_len;
1098
1099 if (ctx->repeats > edescr->maxRepeat)
1100 ctx->repeats = edescr->maxRepeat;
1101 }
1102 else
1103 ctx->repeats = edescr->maxRepeat;
1104
1105 edescr->bytelen = edescr->bytelen * ctx->repeats;
1106 edescr->validRepeats = ctx->repeats;
1107 *value++ = (UBYTE) edescr->validRepeats;
1108 }
1109
1110 if (edescr->ptrtype != noptr)
1111 {
1112 cs = * (UBYTE **) &cs[edescr->offset];
1113 if (!cs)
1114 {
1115 edescr->isValid = FALSE;
1116 return CCDEDIT_OK;
1117 }
1118 }
1119 else
1120 cs += edescr->offset;
1121
1122 /*
1123 * read the current value from the C-structure
1124 */
1125 if ((edescr->btype == T_issdu) || (edescr->btype == T_buffer))
1126 {
1127 USHORT l_buf, o_buf, len;
1128
1129 /*
1130 * For the structure SDU perform a special handling.
1131 * The SDU contains l_buf and o_buf and the element
1132 * buf. This element is only defined as buf[1] because
1133 * the real length results of the encoded message and
1134 * must be calculated form l_buf and o_buf
1135 */
1136
1137 /*
1138 * read l_buf and o_buf (length and offset) out of the struct
1139 */
1140 memcpy ((UBYTE *)&l_buf, cs, sizeof (USHORT));
1141
1142 memcpy ((UBYTE *)&o_buf, cs+sizeof (USHORT), sizeof (USHORT));
1143
1144 len = ((l_buf+o_buf+7)/8);
1145 handle->lenVarPart += len;
1146 handle->canDescent = FALSE;
1147 if ((edescr->btype == T_issdu) &&
1148 ((len > (U32)(ccddata_get_max_bitstream_len()/8)) ||
1149 (len > 0x1FFF))) /* max bytes: 0xFFFF/8 = 0x1FFF */
1150 {
1151 return CCDEDIT_MESSAGE_ERROR;
1152 }
1153 edescr->bytelen = (2 * sizeof (USHORT)) + len;
1154 }
1155
1156 memcpy (value, cs, edescr->bytelen);
1157
1158 cvp = (T_CONV *) cs;
1159
1160 switch (edescr->btype)
1161 {
1162 case T_byte:
1163 elem_value = (ULONG) cvp->b[0];
1164 break;
1165 case T_short:
1166 elem_value = (ULONG) cvp->s[0];
1167 break;
1168 case T_long:
1169 elem_value = (ULONG) cvp->l;
1170 break;
1171 default:
1172 return CCDEDIT_OK;
1173 }
1174
1175 (void) CCDDATA_PREF(cde_get_symval) (elem_value, edescr);
1176
1177 return CCDEDIT_OK;
1178 }
1179
1180 /*
1181 +------------------------------------------------------------------------------
1182 | Function : cde_write_prepare
1183 +------------------------------------------------------------------------------
1184 | Description : This function prepares the writing of elements, by setting
1185 | valid flag, union controller and length of vaiable arrays
1186 | if necessary. Current version: only valid flag and union
1187 | controller.
1188 |
1189 | Parameters : same as cde_write_elem except value
1190 |
1191 | Return : -
1192 +------------------------------------------------------------------------------
1193 */
1194
1195 void CCDDATA_PREF(cde_write_prepare) (T_CCDE_HANDLE * handle,
1196 void * cstruct,
1197 T_CCDE_ELEM_DESCR * edescr)
1198 {
1199 UBYTE * cs = (UBYTE *) cstruct;
1200
1201 /*
1202 * if this element is optional and it is no array component
1203 * set the corresponding valid flag in the C-structure.
1204 */
1205 if (edescr->isOptional && edescr->ptrtype != usptr)
1206 {
1207 cs[edescr->offset++] = TRUE;
1208 }
1209
1210 if (edescr->u_member)
1211 {
1212 * (U32 *) &cs[edescr->offset] = (UBYTE) edescr->u_ctrl;
1213 edescr->offset += sizeof (U32);
1214 }
1215 }
1216
1217
1218 /*
1219 +--------------------------------------------------------------------+
1220 | PROJECT : CCD (6144) MODULE : CCDEDIT |
1221 | STATE : code ROUTINE : cde_write_elem |
1222 +--------------------------------------------------------------------+
1223
1224 PURPOSE : Write the value wich is stored in the memory area,
1225 addressed by the parameter value, into the C-Structure
1226 element, referenced by the element descriptor edescr.
1227
1228 */
1229
1230 USHORT CCDDATA_PREF(cde_write_elem) (T_CCDE_HANDLE * handle,
1231 void * cstruct,
1232 T_CCDE_ELEM_DESCR * edescr,
1233 UBYTE * value)
1234 {
1235 char *cs = (UBYTE *) cstruct;
1236 char *vb;
1237 U32 len;
1238
1239 CCDDATA_PREF(cde_write_prepare) (handle, cs, edescr);
1240
1241 if ((edescr->arrayType != NoArray) && (edescr->btype != T_struct))
1242 {
1243 T_CCDE_CONTEXT *ctx;
1244 T_CCDE_CONTEXT _ctx;
1245
1246 ctx = handle ? &handle->context[handle->level] : &_ctx;
1247
1248 /*
1249 * Array of message elements (info elements) or
1250 * parameter.
1251 * In case of variable sized arrays, store the
1252 * amount of elements into the corresponding c_xxx variable
1253 */
1254 if (edescr->arrayType EQ VarArray)
1255 {
1256 /*
1257 * array with a variable number of elements
1258 * set the c_xxx variable in the C-Structure
1259 */
1260 USHORT sz_of_len;
1261 sz_of_len = edescr->maxRepeat >> 8 ? 2 : 1; /* 1 or 2 bytes for len */
1262 if (sz_of_len == 1)
1263 {
1264 cs[edescr->offset] = (UBYTE) edescr->validRepeats;
1265 }
1266 else
1267 {
1268 * (USHORT *) &cs[edescr->offset] = edescr->validRepeats;
1269 }
1270 edescr->offset += sz_of_len;
1271 }
1272 ctx->repeats = edescr->validRepeats;
1273 if (edescr->bitstring)
1274 {
1275 ctx->repeats = (ctx->repeats+7)/8;
1276 }
1277
1278 edescr->bytelen = edescr->bytelen * ctx->repeats;
1279 }
1280
1281 if (edescr->ptrtype != noptr)
1282 {
1283 char* pointer = value;
1284 vb = (char*) &pointer;
1285 len = sizeof (char*);
1286 }
1287 else
1288 {
1289 vb = (char*) value;
1290 len = edescr->bytelen;
1291
1292 if ((edescr->btype == T_issdu) || (edescr->btype == T_buffer))
1293 {
1294 USHORT l_buf, o_buf;
1295
1296 /*
1297 * For the structure SDU perform a special handling.
1298 * The SDU contains l_buf and o_buf and the element
1299 * buf. This element is only defined as buf[1] because
1300 * the real length results of the encoded message and
1301 * must be calculated form l_buf and o_buf
1302 */
1303
1304 /*
1305 * read l_buf and o_buf (length and offset) out of the value
1306 */
1307 memcpy ((UBYTE *)&l_buf, vb, sizeof (USHORT));
1308
1309 memcpy ((UBYTE *)&o_buf, vb+sizeof (USHORT), sizeof (USHORT));
1310
1311 len = (2 * sizeof (USHORT)) + ((l_buf+o_buf+7)/8);
1312 if (handle)
1313 {
1314 if (edescr->ptrtype == noptr)
1315 handle->lenVarPart += (USHORT) len;
1316 else
1317 handle->lenVarPart += sizeof (void*);
1318 }
1319 edescr->bytelen = len;
1320 }
1321 }
1322
1323 /*
1324 * write the value into the C-structure
1325 */
1326 memcpy (cs+edescr->offset, vb, len);
1327
1328 return CCDEDIT_OK;
1329 }
1330
1331 /*
1332 +--------------------------------------------------------------------+
1333 | PROJECT : CCD (6144) MODULE : CCDEDIT |
1334 | STATE : code ROUTINE : cde_get_type |
1335 +--------------------------------------------------------------------+
1336
1337 PURPOSE : Requests the type (primitive or message) for a given
1338 name. The type is stored in the return parameter type.
1339
1340 */
1341
1342 USHORT CCDDATA_PREF(cde_get_type) (char *name,
1343 T_ELM_SRC *type)
1344 {
1345 #ifdef CCD_SYMBOLS
1346 USHORT SAP, Opcode, Direction, Entity;
1347
1348 /*
1349 * check the primitive table first. Look in all SAPs ands for
1350 * all direction alls opcodes to find the name as a primitve
1351 * name.
1352 */
1353
1354 for (SAP = 0; SAP <= ccddata_max_sap_num; SAP++)
1355 for (Direction = 0; Direction <= 1; Direction++)
1356 for (Opcode = 0; Opcode <= ccddata_max_primitive_id; Opcode++)
1357 if (ccddata_get_pmtx(SAP, Opcode, Direction) NEQ NO_REF)
1358 {
1359 if (!strcmp (name,
1360 pcomp[ccddata_get_pmtx(SAP, Opcode, Direction)].name))
1361 {
1362 *type = FromPrim;
1363 return CCDEDIT_OK;
1364 }
1365 }
1366
1367 /*
1368 * check the message table second. Look in all entities ands for
1369 * all direction alls opcodes to find the name as a message
1370 * name.
1371 */
1372
1373 for (Entity = 0; Entity < ccddata_num_of_entities; Entity++)
1374 for (Direction = 0; Direction <= 1; Direction++)
1375 for (Opcode = 0; Opcode <= ccddata_max_message_id; Opcode++)
1376 if (ccddata_get_mmtx(Entity, Opcode, Direction) NEQ NO_REF)
1377 {
1378 if (!strcmp (name,
1379 mcomp[ccddata_get_mmtx(Entity, Opcode, Direction)].name))
1380 {
1381 *type = FromPrim;
1382 return CCDEDIT_OK;
1383 }
1384 }
1385
1386 #endif
1387
1388 return CCDEDIT_PRIM_NOT_FOUND;
1389 }
1390
1391 /*
1392 +--------------------------------------------------------------------+
1393 | PROJECT : CCD (6144) MODULE : CCDEDIT |
1394 | STATE : code ROUTINE : cde_get_primcode |
1395 +--------------------------------------------------------------------+
1396
1397 PURPOSE : Requests the opcode of the primitive for a given
1398 name. The opcode is stored in the return parameter primcode.
1399
1400 */
1401
1402 USHORT CCDDATA_PREF(cde_get_primcode) (char *name,
1403 ULONG *primcode)
1404 {
1405 #ifdef CCD_SYMBOLS
1406 USHORT SAP, Opcode, Direction;
1407
1408 /*
1409 * check the primitive table. Look in all SAPs ands for
1410 * all direction alls opcodes to find the name as a primitve
1411 * name.
1412 */
1413
1414 for (SAP = 0; SAP <= ccddata_max_sap_num; SAP++)
1415 for (Direction = 0; Direction <= 1; Direction++)
1416 for (Opcode = 0; Opcode <= ccddata_max_primitive_id; Opcode++)
1417 if (ccddata_get_pmtx(SAP, Opcode, Direction) NEQ NO_REF)
1418 {
1419 if (!strcmp (name, pcomp[ccddata_get_pmtx(SAP, Opcode, Direction)].name))
1420 {
1421 *primcode = ((Direction & 0x01) << 14);
1422 *primcode |= (SAP & 0x3fff);
1423 *primcode |= ((Opcode & 0xff) << 16);
1424 *primcode |= 0x80000000;
1425
1426 return CCDEDIT_OK;
1427 }
1428 }
1429 #endif
1430
1431 return CCDEDIT_PRIM_NOT_FOUND;
1432 }
1433
1434
1435 /*
1436 +--------------------------------------------------------------------+
1437 | PROJECT : CCD (6144) MODULE : CCDEDIT |
1438 | STATE : code ROUTINE : cde_get_msgcode |
1439 +--------------------------------------------------------------------+
1440
1441 PURPOSE : Requests the opcode, the direction and the entity-number
1442 of the message for a given name.
1443 The opcode is stored in the return parameters .
1444
1445 */
1446
1447 USHORT CCDDATA_PREF(cde_get_msgcode) (char *name,
1448 UBYTE *type,
1449 UBYTE *direction,
1450 UBYTE *entity)
1451 {
1452 #ifdef CCD_SYMBOLS
1453 USHORT Opcode, Direction, Entity;
1454
1455 /*
1456 * check the message table. Look in all entities ands for
1457 * all direction alls opcodes to find the name as a message
1458 * name.
1459 */
1460
1461 for (Entity = 0; Entity < ccddata_num_of_entities; Entity++)
1462 for (Direction = 0; Direction <= 1; Direction++)
1463 for (Opcode = 0; Opcode <= ccddata_max_message_id; Opcode++)
1464 if (ccddata_get_mmtx(Entity, Opcode, Direction) NEQ NO_REF)
1465 {
1466 if (!strcmp (name,
1467 mcomp[ccddata_get_mmtx(Entity, Opcode, Direction)].name))
1468 {
1469 *type = (UBYTE) Opcode;
1470 *direction = (UBYTE) Direction;
1471 *entity = (UBYTE) Entity;
1472 return CCDEDIT_OK;
1473 }
1474 }
1475
1476 #endif
1477
1478 return CCDEDIT_MESSAGE_NOT_FOUND;
1479 }
1480
1481 /*
1482 +------------------------------------------------------------------------------
1483 | Function : cde_get_is_downlink
1484 +------------------------------------------------------------------------------
1485 | Description : This function finds out if an AIM is a downlink or uplink.
1486 |
1487 | Parameters : comp_index.
1488 |
1489 | Return : False if uplink otherwise true (downlink or both).
1490 +------------------------------------------------------------------------------
1491 */
1492 int CCDDATA_PREF(cde_get_is_downlink) (ULONG comp_index)
1493 {
1494 UBYTE ent;
1495 UBYTE msg_id;
1496
1497 for(ent = 0; ent < ccddata_num_of_entities ; ent++)
1498 {
1499 for(msg_id = 0; msg_id <= ccddata_max_message_id ; msg_id++)
1500 {
1501 if(ccddata_get_mmtx (ent, msg_id, 1) == (USHORT)comp_index)
1502 return 1;
1503 }
1504 }
1505 return 0;
1506 }
1507
1508 /*
1509 * The following functions are copied from ..\TAP\tdc_interface.c and
1510 * renamed to get the cde_ prefix instead of tdc_.
1511 * It should be checked if instead of these functions the usual approach
1512 * to ccdedit by the functions pairs cde_comp_first/cde_comp_next
1513 * (respectively their prim/msg pendants) can be used (maybe in combination
1514 * with cde_get_comp). If the check confirms to use the usual approach,
1515 * those 3 functions here should be deleted again
1516 */
1517 /*
1518 +------------------------------------------------------------------------------
1519 | Function : cde_get_comp_index
1520 +------------------------------------------------------------------------------
1521 | Description : This function searches the comp index in either pcomp or mcomp
1522 |
1523 | Parameters : name and table type.
1524 |
1525 | Return : The table entry, if non found it returns 0xffffffff;
1526 +------------------------------------------------------------------------------
1527 */
1528
1529 ULONG CCDDATA_PREF(cde_get_comp_index) (CHAR* comp_name, T_ELM_SRC table)
1530 {
1531 ULONG comp_index;
1532 BOOL found = FALSE;
1533
1534 if (table == FromMsg)
1535 {
1536 /*
1537 * search the mcomp-table for the given name
1538 */
1539 comp_index = 0;
1540 while (!found AND mcomp[comp_index].name NEQ NULL)
1541 {
1542 /*
1543 * composition name found
1544 */
1545 if (strcmp (mcomp[comp_index].name, comp_name) EQ 0)
1546 found = TRUE;
1547 else
1548 comp_index++;
1549 }
1550 if(found)
1551 return comp_index;
1552 else
1553 return NO_ENTRY_FOUND;
1554 }
1555 else
1556 {
1557 /*
1558 * search the pcomp-table for the given name
1559 */
1560 comp_index = 0;
1561 while (!found AND pcomp[comp_index].name NEQ NULL)
1562 {
1563 /*
1564 * composition name found
1565 */
1566 if (strcmp (pcomp[comp_index].name, comp_name) EQ 0)
1567 found = TRUE;
1568 else
1569 comp_index++;
1570 }
1571 if(found)
1572 return comp_index;
1573 else
1574 return NO_ENTRY_FOUND;
1575 }
1576 }
1577
1578 /*
1579 +------------------------------------------------------------------------------
1580 | Function : cde_get_element_name
1581 +------------------------------------------------------------------------------
1582 | Description : This function gets the element name for a given index + offset.
1583 |
1584 | Parameters : comp_index, offset and table type.
1585 |
1586 | Return : The element name.
1587 +------------------------------------------------------------------------------
1588 */
1589
1590 CHAR* CCDDATA_PREF(cde_get_element_name) (ULONG comp_index, USHORT elem_off , T_ELM_SRC table)
1591 {
1592 if (table == FromMsg)
1593 {
1594 if (mcomp[comp_index].componentRef == -1 || elem_off >= mcomp[comp_index].numOfComponents)
1595 return NULL;
1596 return ccddata_get_alias ((USHORT) (mcomp[comp_index].componentRef + elem_off), table == FromMsg);
1597 }
1598 else
1599 if (pcomp[comp_index].componentRef == -1 || elem_off >= pcomp[comp_index].numOfComponents)
1600 return NULL;
1601 return ccddata_get_alias ((USHORT) (pcomp[comp_index].componentRef + elem_off), table == FromMsg);
1602 }
1603
1604 /*
1605 +------------------------------------------------------------------------------
1606 | Function : cde_get_array_kind
1607 +------------------------------------------------------------------------------
1608 | Description : This function gets the array kind - e.g. the cSize of the
1609 | arrays (byte, short og long).
1610 |
1611 | Parameters : Name of the base type (var_name) and table type.
1612 |
1613 | Return : The cSize of the var_name. If not found it returns 0xffffffff
1614 +------------------------------------------------------------------------------
1615 */
1616
1617 ULONG CCDDATA_PREF(cde_get_array_kind) (CHAR* var_name, T_ELM_SRC table)
1618 {
1619 ULONG var_index;
1620 BOOL found = FALSE;
1621
1622 if (table == FromMsg)
1623 {
1624 /*
1625 * search the mvar-table for the given name
1626 */
1627 var_index = 0;
1628 while (!found AND mvar[var_index].name NEQ NULL)
1629 {
1630 /*
1631 * name found
1632 */
1633 if (strcmp (mvar[var_index].name, var_name) EQ 0)
1634 found = TRUE;
1635 else
1636 var_index++;
1637 }
1638 if(found)
1639 return (ULONG) mvar[var_index].cSize;
1640 else
1641 return NO_ENTRY_FOUND;
1642 }
1643 else
1644 {
1645 /*
1646 * search the pvar-table for the given name
1647 */
1648 var_index = 0;
1649 while (!found AND pvar[var_index].name NEQ NULL)
1650 {
1651 /*
1652 * name found
1653 */
1654 if (strcmp (pvar[var_index].name, var_name) EQ 0)
1655 found = TRUE;
1656 else
1657 var_index++;
1658 }
1659 if(found)
1660 return (ULONG) pvar[var_index].cSize;
1661 else
1662 return NO_ENTRY_FOUND;
1663 }
1664 }