Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

787 lines
21 KiB

  1. /* Copyright (C) Boris Nikolaus, Germany, 1996-1997. All rights reserved. */
  2. /* Copyright (C) Microsoft Corporation, 1997-1998. All rights reserved. */
  3. #include "precomp.h"
  4. void ExamineBERType(AssignmentList_t ass, Type_t *type, char *ideref);
  5. void ExamineBERType_Boolean(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  6. void ExamineBERType_Integer(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  7. void ExamineBERType_Enumerated(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  8. void ExamineBERType_Real(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  9. void ExamineBERType_BitString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  10. void ExamineBERType_OctetString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  11. void ExamineBERType_UTF8String(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  12. void ExamineBERType_Null(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  13. void ExamineBERType_EmbeddedPdv(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  14. void ExamineBERType_External(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  15. void ExamineBERType_ObjectIdentifier(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  16. void ExamineBERType_BMPString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  17. void ExamineBERType_GeneralString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  18. void ExamineBERType_GraphicString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  19. void ExamineBERType_IA5String(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  20. void ExamineBERType_ISO646String(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  21. void ExamineBERType_NumericString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  22. void ExamineBERType_PrintableString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  23. void ExamineBERType_TeletexString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  24. void ExamineBERType_T61String(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  25. void ExamineBERType_UniversalString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  26. void ExamineBERType_VideotexString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  27. void ExamineBERType_VisibleString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  28. void ExamineBERType_UnrestrictedString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  29. void ExamineBERType_GeneralizedTime(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  30. void ExamineBERType_UTCTime(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  31. void ExamineBERType_ObjectDescriptor(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  32. void ExamineBERType_Open(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  33. void ExamineBERType_SequenceSet(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  34. void ExamineBERType_SequenceSetOf(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  35. void ExamineBERType_Choice(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  36. void ExamineBERType_InstanceOf(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  37. void ExamineBERType_Reference(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info);
  38. /* examine all types and extract informations needed for BER encoding */
  39. void
  40. ExamineBER(AssignmentList_t ass)
  41. {
  42. Assignment_t *a;
  43. /* examine all assignments */
  44. for (a = ass; a; a = a->Next) {
  45. /* examine types */
  46. switch (a->Type) {
  47. case eAssignment_Type:
  48. ExamineBERType(ass, a->U.Type.Type, GetName(a));
  49. break;
  50. }
  51. }
  52. }
  53. /* extract some type informations needed for BER encoding */
  54. void
  55. ExamineBERType(AssignmentList_t ass, Type_t *type, char *ideref)
  56. {
  57. BERTypeInfo_t *info;
  58. info = &type->BERTypeInfo;
  59. info->pPrivateDirectives = &type->PrivateDirectives;
  60. /* get tags to en-/decode */
  61. if (IsReferenceType(type) && IsStructuredType(GetType(ass, type))) {
  62. info->Tags = type->Tags;
  63. } else {
  64. info->Tags = type->AllTags;
  65. }
  66. /* get the type to be examined */
  67. if (IsReferenceType(type) && !IsStructuredType(GetType(ass, type)))
  68. type = GetType(ass, type);
  69. /* initialize the BER informations */
  70. info->Identifier = ideref;
  71. info->Rules = type->Rules;
  72. info->Flags = type->Flags;
  73. info->NOctets = 0;
  74. info->SubIdentifier = NULL;
  75. info->SubType = NULL;
  76. info->Data = eBERSTIData_Null;
  77. /* BER informations are type specific ... */
  78. switch (type->Type) {
  79. case eType_Boolean:
  80. ExamineBERType_Boolean(ass, type, info);
  81. break;
  82. case eType_Integer:
  83. ExamineBERType_Integer(ass, type, info);
  84. break;
  85. case eType_Enumerated:
  86. ExamineBERType_Enumerated(ass, type, info);
  87. break;
  88. case eType_Real:
  89. ExamineBERType_Real(ass, type, info);
  90. break;
  91. case eType_BitString:
  92. ExamineBERType_BitString(ass, type, info);
  93. break;
  94. case eType_OctetString:
  95. ExamineBERType_OctetString(ass, type, info);
  96. break;
  97. case eType_UTF8String:
  98. ExamineBERType_UTF8String(ass, type, info);
  99. break;
  100. case eType_Null:
  101. ExamineBERType_Null(ass, type, info);
  102. break;
  103. case eType_EmbeddedPdv:
  104. ExamineBERType_EmbeddedPdv(ass, type, info);
  105. break;
  106. case eType_External:
  107. ExamineBERType_External(ass, type, info);
  108. break;
  109. case eType_ObjectIdentifier:
  110. ExamineBERType_ObjectIdentifier(ass, type, info);
  111. break;
  112. case eType_BMPString:
  113. ExamineBERType_BMPString(ass, type, info);
  114. break;
  115. case eType_GeneralString:
  116. ExamineBERType_GeneralString(ass, type, info);
  117. break;
  118. case eType_GraphicString:
  119. ExamineBERType_GraphicString(ass, type, info);
  120. break;
  121. case eType_IA5String:
  122. ExamineBERType_IA5String(ass, type, info);
  123. break;
  124. case eType_ISO646String:
  125. ExamineBERType_ISO646String(ass, type, info);
  126. break;
  127. case eType_NumericString:
  128. ExamineBERType_NumericString(ass, type, info);
  129. break;
  130. case eType_PrintableString:
  131. ExamineBERType_PrintableString(ass, type, info);
  132. break;
  133. case eType_TeletexString:
  134. ExamineBERType_TeletexString(ass, type, info);
  135. break;
  136. case eType_T61String:
  137. ExamineBERType_T61String(ass, type, info);
  138. break;
  139. case eType_UniversalString:
  140. ExamineBERType_UniversalString(ass, type, info);
  141. break;
  142. case eType_VideotexString:
  143. ExamineBERType_VideotexString(ass, type, info);
  144. break;
  145. case eType_VisibleString:
  146. ExamineBERType_VisibleString(ass, type, info);
  147. break;
  148. case eType_CharacterString:
  149. ExamineBERType_UnrestrictedString(ass, type, info);
  150. break;
  151. case eType_GeneralizedTime:
  152. ExamineBERType_GeneralizedTime(ass, type, info);
  153. break;
  154. case eType_UTCTime:
  155. ExamineBERType_UTCTime(ass, type, info);
  156. break;
  157. case eType_ObjectDescriptor:
  158. ExamineBERType_ObjectDescriptor(ass, type, info);
  159. break;
  160. case eType_Open:
  161. ExamineBERType_Open(ass, type, info);
  162. break;
  163. case eType_Sequence:
  164. case eType_Set:
  165. ExamineBERType_SequenceSet(ass, type, info);
  166. break;
  167. case eType_SequenceOf:
  168. case eType_SetOf:
  169. ExamineBERType_SequenceSetOf(ass, type, info);
  170. break;
  171. case eType_Choice:
  172. ExamineBERType_Choice(ass, type, info);
  173. break;
  174. case eType_InstanceOf:
  175. ExamineBERType_InstanceOf(ass, type, info);
  176. break;
  177. case eType_RestrictedString:
  178. MyAbort(); /* may never happen */
  179. /*NOTREACHED*/
  180. case eType_Selection:
  181. MyAbort(); /* may never happen */
  182. /*NOTREACHED*/
  183. case eType_Undefined:
  184. MyAbort(); /* may never happen */
  185. /*NOTREACHED*/
  186. case eType_Reference:
  187. ExamineBERType_Reference(ass, type, info);
  188. break;
  189. case eType_FieldReference:
  190. MyAbort(); /* may never happen */
  191. /*NOTREACHED*/
  192. }
  193. }
  194. /*
  195. * Description of the fields of BERTypeInfo_t:
  196. * info.
  197. * Identifier complete name of the type
  198. * Rules encoding directive rules
  199. * Flags encoding flags
  200. * NOctets size of string characters/integer type
  201. * Data data type of value
  202. * SubIdentifier complete name of the subtype
  203. * SubType the subtype itself
  204. * Tags tag list of the type
  205. *
  206. * NOTES:
  207. * The encoding is mostly controlled by following arguments:
  208. * - Data, the type: one of:
  209. * eBERSTIData_Null, eBERSTIData_Boolean,
  210. * eBERSTIData_Integer, eBERSTIData_Unsigned,
  211. * eBERSTIData_Real, eBERSTIData_BitString, eBERSTIData_RZBBitString,
  212. * eBERSTIData_OctetString, eBERSTIData_SequenceOf, eBERSTIData_SetOf,
  213. * eBERSTIData_Sequence, eBERSTIData_Set, eBERSTIData_Choice,
  214. * eBERSTIData_ObjectIdentifier, eBERSTIData_ObjectIdEncoded, eBERSTIData_String,
  215. * eBERSTIData_ZeroString, eBERSTIData_Reference, eBERSTIData_External,
  216. * eBERSTIData_EmbeddedPdv, eBERSTIData_UnrestrictedString
  217. *
  218. * Following arguments contain variable/function names in the generated
  219. * code:
  220. * - Identifier, the name of the current type
  221. * - SubIdentifier, the name of the subtype
  222. *
  223. * Following values require additional arguments:
  224. * - Data == eBERSTIData_Reference
  225. * -> SubIdentifier, the name of the subtype
  226. * -> SubType, the subtype itself
  227. * - Data == eBERSTIData_*String
  228. * -> NOctets, the size of the string characters
  229. * - Data == eBERSTIData_Integer || Data == eBERSTIData_Unsigned ||
  230. * Data == eBERSTIData_Boolean || Data == eBERSTIData_Choice
  231. * -> NOctets, the size of the integer type
  232. * - Data == eBERSTIData_SequenceOf || Data == eBERSTIData_SetOf
  233. * -> SubIdentifier, the name of the subtype
  234. * -> SubType, the subtype itself
  235. * -> Rule, the encoding directive rules
  236. */
  237. /*
  238. * BOOLEAN:
  239. *
  240. * Data == eBERSTIData_Boolean
  241. *
  242. * Additional arguments:
  243. *
  244. * - Data == eBERSTIData_Integer || dat == eBERSTIData_Unsigned ||
  245. * Data == eBERSTIData_Boolean || dat == eBERSTIData_Choice
  246. * -> NOctets, the size of the integer type
  247. */
  248. void
  249. ExamineBERType_Boolean(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  250. {
  251. info->Data = eBERSTIData_Boolean;
  252. info->NOctets = GetOctets(GetBooleanType());
  253. }
  254. /*
  255. * INTEGER:
  256. *
  257. * Data == eBERSTIData_Integer ||
  258. * Data == eBERSTIData_Unsigned
  259. *
  260. * Additional arguments:
  261. *
  262. * - Data == eBERSTIData_Integer || dat == eBERSTIData_Unsigned ||
  263. * Data == eBERSTIData_Boolean || dat == eBERSTIData_Choice
  264. * -> NOctets, the size of the integer type
  265. */
  266. void
  267. ExamineBERType_Integer(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  268. {
  269. int32_t sign;
  270. /* calculate NOctets and Data depending on the used C-Type */
  271. info->NOctets = GetOctets(GetIntegerType(ass, type, &sign));
  272. info->Data = sign > 0 ? eBERSTIData_Unsigned : eBERSTIData_Integer;
  273. }
  274. /*
  275. * ENUMERATED:
  276. *
  277. * Data == eBERSTIData_Integer ||
  278. * Data == eBERSTIData_Unsigned
  279. *
  280. * Additional arguments:
  281. *
  282. * - Data == eBERSTIData_Integer || dat == eBERSTIData_Unsigned ||
  283. * Data == eBERSTIData_Boolean || dat == eBERSTIData_Choice
  284. * -> NOctets, the size of the integer type
  285. */
  286. void
  287. ExamineBERType_Enumerated(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  288. {
  289. int32_t sign;
  290. /* calculate NOctets and Data depending on the used C-Type */
  291. info->NOctets = GetOctets(GetEnumeratedType(ass, type, &sign));
  292. info->Data = sign > 0 ? eBERSTIData_Unsigned : eBERSTIData_Integer;
  293. }
  294. /*
  295. * REAL:
  296. *
  297. * Data == eBERSTIData_Real
  298. *
  299. * Additional arguments:
  300. *
  301. * none
  302. */
  303. void
  304. ExamineBERType_Real(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  305. {
  306. info->NOctets = GetOctets(GetRealType(type));
  307. info->Data = eBERSTIData_Real;
  308. }
  309. /*
  310. * BIT STRING:
  311. *
  312. * Data == eBERSTIData_BitString ||
  313. * Data == eBERSTIData_RZBBitString
  314. *
  315. * Additional arguments:
  316. *
  317. * none
  318. */
  319. void
  320. ExamineBERType_BitString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  321. {
  322. /* set Data to RZBBitString/BitString */
  323. if (type->U.BitString.NamedNumbers)
  324. info->Data = eBERSTIData_RZBBitString;
  325. else
  326. info->Data = eBERSTIData_BitString;
  327. }
  328. /*
  329. * OCTET STRING:
  330. *
  331. * Data == eBERSTIData_OctetString
  332. *
  333. * Additional arguments:
  334. *
  335. * none
  336. */
  337. void
  338. ExamineBERType_OctetString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  339. {
  340. /* set Data to OctetString */
  341. info->Data = eBERSTIData_OctetString;
  342. }
  343. void
  344. ExamineBERType_UTF8String(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  345. {
  346. /* set Data to UTF8String */
  347. info->Data = eBERSTIData_UTF8String;
  348. }
  349. /*
  350. * NULL:
  351. *
  352. * Data == eBERSTIData_Null
  353. *
  354. * Additional arguments:
  355. *
  356. * none
  357. */
  358. void
  359. ExamineBERType_Null(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  360. {
  361. info->Data = eBERSTIData_Null;
  362. }
  363. /*
  364. * EMBEDDED PDV:
  365. *
  366. * Data == eBERSTIData_EmbeddedPdv
  367. *
  368. * Additional arguments:
  369. *
  370. * none
  371. */
  372. void
  373. ExamineBERType_EmbeddedPdv(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  374. {
  375. info->Data = eBERSTIData_EmbeddedPdv;
  376. }
  377. /*
  378. * EXTERNAL:
  379. *
  380. * Data == eBERSTIData_External
  381. *
  382. * Additional arguments:
  383. *
  384. * none
  385. */
  386. void
  387. ExamineBERType_External(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  388. {
  389. info->Data = eBERSTIData_External;
  390. }
  391. /*
  392. * OBJECT IDENTIFIER:
  393. *
  394. * Data == eBERSTIData_ObjectIdEncoded || eBERSTIData_ObjectIdentifier
  395. *
  396. * Additional arguments:
  397. *
  398. * none
  399. */
  400. void
  401. ExamineBERType_ObjectIdentifier(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  402. {
  403. info->Data = type->PrivateDirectives.fOidPacked ? eBERSTIData_ObjectIdEncoded : eBERSTIData_ObjectIdentifier;
  404. }
  405. /*
  406. * *String:
  407. *
  408. * Data == eBERSTIData_String ||
  409. * Data == eBERSTIData_ZeroString
  410. *
  411. * Additional arguments:
  412. *
  413. * - Data == eBERSTIData_*String
  414. * -> NOctets, the size of the string characters
  415. */
  416. void
  417. ExamineBERType_BMPString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  418. {
  419. uint32_t zero;
  420. GetStringType(ass, type, &info->NOctets, &zero);
  421. info->Data = zero ? eBERSTIData_ZeroString : eBERSTIData_String;
  422. }
  423. void
  424. ExamineBERType_GeneralString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  425. {
  426. uint32_t zero;
  427. GetStringType(ass, type, &info->NOctets, &zero);
  428. info->Data = zero ? eBERSTIData_ZeroString : eBERSTIData_String;
  429. }
  430. void
  431. ExamineBERType_GraphicString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  432. {
  433. uint32_t zero;
  434. GetStringType(ass, type, &info->NOctets, &zero);
  435. info->Data = zero ? eBERSTIData_ZeroString : eBERSTIData_String;
  436. }
  437. void
  438. ExamineBERType_IA5String(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  439. {
  440. uint32_t zero;
  441. GetStringType(ass, type, &info->NOctets, &zero);
  442. info->Data = zero ? eBERSTIData_ZeroString : eBERSTIData_String;
  443. }
  444. void
  445. ExamineBERType_ISO646String(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  446. {
  447. uint32_t zero;
  448. GetStringType(ass, type, &info->NOctets, &zero);
  449. info->Data = zero ? eBERSTIData_ZeroString : eBERSTIData_String;
  450. }
  451. void
  452. ExamineBERType_NumericString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  453. {
  454. uint32_t zero;
  455. GetStringType(ass, type, &info->NOctets, &zero);
  456. info->Data = zero ? eBERSTIData_ZeroString : eBERSTIData_String;
  457. }
  458. void
  459. ExamineBERType_PrintableString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  460. {
  461. uint32_t zero;
  462. GetStringType(ass, type, &info->NOctets, &zero);
  463. info->Data = zero ? eBERSTIData_ZeroString : eBERSTIData_String;
  464. }
  465. void
  466. ExamineBERType_TeletexString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  467. {
  468. uint32_t noctets, zero;
  469. GetStringType(ass, type, &noctets, &zero); // to make hack directives become effective
  470. info->Data = eBERSTIData_MultibyteString;
  471. info->NOctets = 1;
  472. }
  473. void
  474. ExamineBERType_T61String(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  475. {
  476. uint32_t noctets, zero;
  477. GetStringType(ass, type, &noctets, &zero); // to make hack directives become effective
  478. info->Data = eBERSTIData_MultibyteString;
  479. info->NOctets = 1;
  480. }
  481. void
  482. ExamineBERType_UniversalString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  483. {
  484. uint32_t zero;
  485. GetStringType(ass, type, &info->NOctets, &zero);
  486. info->Data = zero ? eBERSTIData_ZeroString : eBERSTIData_String;
  487. }
  488. void
  489. ExamineBERType_VideotexString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  490. {
  491. uint32_t noctets, zero;
  492. GetStringType(ass, type, &noctets, &zero); // to make hack directives become effective
  493. info->Data = eBERSTIData_MultibyteString;
  494. info->NOctets = 1;
  495. }
  496. void
  497. ExamineBERType_VisibleString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  498. {
  499. uint32_t zero;
  500. GetStringType(ass, type, &info->NOctets, &zero);
  501. info->Data = zero ? eBERSTIData_ZeroString : eBERSTIData_String;
  502. }
  503. /*
  504. * CHARACTER STRING:
  505. *
  506. * Data == eBERSTIData_UnrestrictedString
  507. *
  508. * Additional arguments:
  509. *
  510. * - Data == eBERSTIData_EmbeddedPdv ||
  511. * Data == eBERSTIData_UnrestrictedString
  512. * -> Identification, the identification of the type if the type
  513. * is constraint to fixed identification or syntaxes identification
  514. * with single value
  515. */
  516. void
  517. ExamineBERType_UnrestrictedString(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  518. {
  519. info->Data = eBERSTIData_UnrestrictedString;
  520. }
  521. /*
  522. * GeneralizedTime:
  523. *
  524. * Data == eBERSTIData_GeneralizedTime
  525. *
  526. * Additional arguments:
  527. *
  528. * none
  529. */
  530. void
  531. ExamineBERType_GeneralizedTime(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  532. {
  533. info->Data = eBERSTIData_GeneralizedTime;
  534. }
  535. /*
  536. * UTCTime:
  537. *
  538. * Data == eBERSTIData_UTCTime
  539. *
  540. * Additional arguments:
  541. *
  542. * none
  543. */
  544. void
  545. ExamineBERType_UTCTime(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  546. {
  547. info->Data = eBERSTIData_UTCTime;
  548. }
  549. /*
  550. * ObjectDescriptor:
  551. *
  552. * Data == eBERSTIData_ZeroString
  553. *
  554. * Additional arguments:
  555. *
  556. * none
  557. */
  558. void
  559. ExamineBERType_ObjectDescriptor(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  560. {
  561. info->NOctets = 1;
  562. info->Data = eBERSTIData_ZeroString;
  563. }
  564. /*
  565. * OpenType:
  566. *
  567. * Data == eBERSTIData_Open
  568. *
  569. * Additional arguments:
  570. *
  571. * none
  572. */
  573. void
  574. ExamineBERType_Open(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  575. {
  576. info->NOctets = 1;
  577. info->Data = eBERSTIData_Open;
  578. }
  579. /*
  580. * SEQUENCE/SET:
  581. *
  582. * Data == eBERSTIData_Sequence ||
  583. * Data == eBERSTIData_Set
  584. *
  585. * Additional arguments:
  586. *
  587. * none
  588. */
  589. void
  590. ExamineBERType_SequenceSet(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  591. {
  592. Component_t *comp;
  593. NamedType_t *namedType;
  594. char idebuf[256];
  595. info->Data = (type->Type == eType_Sequence) ?
  596. eBERSTIData_Sequence : eBERSTIData_Set;
  597. /* examine types of components */
  598. for (comp = type->U.SSC.Components; comp; comp = comp->Next) {
  599. switch (comp->Type) {
  600. case eComponent_Normal:
  601. case eComponent_Optional:
  602. case eComponent_Default:
  603. namedType = comp->U.NOD.NamedType;
  604. sprintf(idebuf, "%s_%s", info->Identifier, namedType->Identifier);
  605. ExamineBERType(ass, namedType->Type, strdup(idebuf));
  606. break;
  607. }
  608. }
  609. }
  610. /*
  611. * SEQUENCE OF/SET OF:
  612. *
  613. * Data == eBERSTIData_SequenceOf ||
  614. * Data == eBERSTIData_SetOf
  615. *
  616. * Additional arguments:
  617. *
  618. * - Data == eBERSTIData_SequenceOf || dat == eBERSTIData_SetOf
  619. * -> SubIdentifier, the name of the subtype
  620. * -> SubType, the subtype itself
  621. * -> Rule, the encoding directive rules
  622. */
  623. void
  624. ExamineBERType_SequenceSetOf(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  625. {
  626. char idebuf[256];
  627. /* set data type and Alignment */
  628. info->Data = (type->Type == eType_SequenceOf ?
  629. eBERSTIData_SequenceOf : eBERSTIData_SetOf);
  630. /* set SubType, SubIdentifier */
  631. info->SubType = type->U.SS.Type;
  632. info->SubIdentifier = GetTypeName(ass, info->SubType);
  633. /* examine subtype */
  634. sprintf(idebuf, "%s_%s", info->Identifier,
  635. type->Type == eType_SequenceOf ? "Sequence" : "Set");
  636. ExamineBERType(ass, type->U.SS.Type, strdup(idebuf));
  637. }
  638. /*
  639. * CHOICE:
  640. *
  641. * Data == eBERSTIData_Choice
  642. *
  643. * Additional arguments:
  644. *
  645. * - Data == eBERSTIData_Integer || dat == eBERSTIData_Unsigned ||
  646. * Data == eBERSTIData_Boolean || dat == eBERSTIData_Choice
  647. * -> NOctets, the size of the integer type
  648. */
  649. void
  650. ExamineBERType_Choice(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  651. {
  652. Component_t *comp;
  653. NamedType_t *namedType;
  654. char idebuf[256];
  655. info->NOctets = GetOctets(GetChoiceType(type));
  656. info->Data = eBERSTIData_Choice;
  657. /* examine types of alternatives */
  658. for (comp = type->U.SSC.Components; comp; comp = comp->Next) {
  659. switch (comp->Type) {
  660. case eComponent_Normal:
  661. namedType = comp->U.NOD.NamedType;
  662. sprintf(idebuf, "%s_%s", info->Identifier, namedType->Identifier);
  663. ExamineBERType(ass, namedType->Type, strdup(idebuf));
  664. break;
  665. }
  666. }
  667. }
  668. /*
  669. * INSTANCE OF:
  670. *
  671. * Data == eBERSTIData_Sequence
  672. *
  673. * Additional arguments:
  674. *
  675. * none
  676. */
  677. void
  678. ExamineBERType_InstanceOf(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  679. {
  680. Component_t *comp;
  681. NamedType_t *namedType;
  682. char idebuf[256];
  683. info->Data = eBERSTIData_Sequence;
  684. /* examine types of components */
  685. for (comp = type->U.SSC.Components; comp; comp = comp->Next) {
  686. switch (comp->Type) {
  687. case eComponent_Normal:
  688. case eComponent_Optional:
  689. case eComponent_Default:
  690. namedType = comp->U.NOD.NamedType;
  691. sprintf(idebuf, "%s_%s", info->Identifier, namedType->Identifier);
  692. ExamineBERType(ass, namedType->Type, strdup(idebuf));
  693. break;
  694. }
  695. }
  696. }
  697. /*
  698. * Reference:
  699. *
  700. * Data == eBERSTIData_Reference
  701. *
  702. * Additional arguments:
  703. *
  704. * - Data == eBERSTIData_Reference
  705. * -> SubIdentifier, the name of the subtype
  706. * -> SubType, the subtype itself
  707. */
  708. void
  709. ExamineBERType_Reference(AssignmentList_t ass, Type_t *type, BERTypeInfo_t *info)
  710. {
  711. Assignment_t *a;
  712. info->Data = eBERSTIData_Reference;
  713. a = GetAssignment(ass, FindAssignment(ass, eAssignment_Type,
  714. type->U.Reference.Identifier, type->U.Reference.Module));
  715. info->SubIdentifier = GetName(a);
  716. info->SubType = a->U.Type.Type;
  717. }