Leaked source code of windows server 2003
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.

6235 lines
223 KiB

  1. /****************************************************************************
  2. *
  3. * $Archive: S:/STURGEON/SRC/Q931/VCS/q931pdu.c_v $
  4. *
  5. * INTEL Corporation Prorietary Information
  6. *
  7. * This listing is supplied under the terms of a license agreement
  8. * with INTEL Corporation and may not be copied nor disclosed except
  9. * in accordance with the terms of that agreement.
  10. *
  11. * Copyright (c) 1996 Intel Corporation.
  12. *
  13. * $Revision: 1.67.1.0 $
  14. * $Date: 17 Mar 1997 19:44:52 $
  15. * $Author: MANDREWS $
  16. *
  17. * Deliverable:
  18. *
  19. * Abstract: Parser routines for Q931 PDUs
  20. *
  21. * Notes:
  22. *
  23. ***************************************************************************/
  24. #pragma comment (exestr, "$Workfile: q931pdu.c $ $Revision: 1.67.1.0 $")
  25. // [ ] Do another integration of own q931test area.
  26. // [ ] Alias values displayed in tracing routines.
  27. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  28. // STANDARDS ISSUES
  29. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  30. // [ ] !!! EndpointType contains MC info, so Setup_UUIE doesnt need MC field !!!
  31. // [ ] !!! Need to decide how CallType is to be used !!!
  32. // [ ] !!! ALERTING message is missing the ConferenceID field !!!
  33. // [ ] !!! Place needed for Caller and Callee transport addr, or else explanation of how this information is available round-trip !!!
  34. // [ ] !!! FACILITY message is missing the protocolIdentifier field !!!
  35. //------------------------------------------------------------------------------
  36. // Note: These parsing details have not yet been supported:
  37. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  38. // 1) variable octet fields having extending groups,
  39. // extending indications, or escape for extensions. (See 4.5.1)
  40. // 2) codeset recognition and exclusion based on SHIFT (See 4.5.2)
  41. // 3) correct ignoring of escapes for nationally specific message types.
  42. // 4) The call reference value is 2 bytes long sizeof(WORD).
  43. // A call reference of 0 means, the message pertains to all
  44. // calls on the same data link.
  45. //------------------------------------------------------------------------------
  46. #pragma warning ( disable : 4100 4115 4201 4214 4514 )
  47. #include "precomp.h"
  48. #include <string.h>
  49. #include "h225asn.h"
  50. #include "q931asn1.h"
  51. #include "common.h"
  52. #include "q931.h"
  53. #include "isrg.h"
  54. #include "utils.h"
  55. #include "q931pdu.h"
  56. #ifdef UNICODE_TRACE
  57. // We include this header to fix problems with macro expansion when Unicode is turned on.
  58. #include "unifix.h"
  59. #endif
  60. //==========================================================
  61. // CALLED PARTY FIELD DEFINITIONS
  62. //==========================================================
  63. // called party encoding bits...
  64. #define CALLED_PARTY_EXT_BIT 0x80
  65. // called party number type
  66. #define CALLED_PARTY_TYPE_UNKNOWN 0x00
  67. // ...other types are not defined because they are not used...
  68. // called party numbering plan
  69. #define CALLED_PARTY_PLAN_E164 0x01
  70. // ...other plans are not defined because they are not used...
  71. //==========================================================
  72. // BEARER FIELD DEFINITIONS
  73. //==========================================================
  74. // bearer encoding bits...
  75. #define BEAR_EXT_BIT 0x80
  76. // bearer coding standards...
  77. #define BEAR_CCITT 0x00
  78. // ...others not needed...
  79. // bearer information transfer capability...
  80. #define BEAR_UNRESTRICTED_DIGITAL 0x08
  81. // ...others not needed...
  82. // bearer transfer mode...
  83. #define BEAR_PACKET_MODE 0x40
  84. // ...others not needed...
  85. // bearer information transfer rate...
  86. #define BEAR_NO_CIRCUIT_RATE 0x00
  87. // ...others not needed...
  88. // bearer layer1 protocol...
  89. #define BEAR_LAYER1_INDICATOR 0x20
  90. #define BEAR_LAYER1_H221_H242 0x05
  91. // ...others not needed...
  92. static struct ObjectID_ ProtocolId1;
  93. static struct ObjectID_ ProtocolId2;
  94. static struct ObjectID_ ProtocolId3;
  95. static struct ObjectID_ ProtocolId4;
  96. static struct ObjectID_ ProtocolId5;
  97. static struct ObjectID_ ProtocolId6;
  98. static struct GatewayInfo_protocol TempProtocol;
  99. MESSAGEIDTYPE MessageSet[] =
  100. {
  101. ALERTINGMESSAGETYPE,
  102. PROCEEDINGMESSAGETYPE,
  103. CONNECTMESSAGETYPE,
  104. CONNECTACKMESSAGETYPE,
  105. PROGRESSMESSAGETYPE,
  106. SETUPMESSAGETYPE,
  107. SETUPACKMESSAGETYPE,
  108. RESUMEMESSAGETYPE,
  109. RESUMEACKMESSAGETYPE,
  110. RESUMEREJMESSAGETYPE,
  111. SUSPENDMESSAGETYPE,
  112. SUSPENDACKMESSAGETYPE,
  113. SUSPENDREJMESSAGETYPE,
  114. USERINFOMESSAGETYPE,
  115. DISCONNECTMESSAGETYPE,
  116. RELEASEMESSAGETYPE,
  117. RELEASECOMPLMESSAGETYPE,
  118. RESTARTMESSAGETYPE,
  119. RESTARTACKMESSAGETYPE,
  120. SEGMENTMESSAGETYPE,
  121. CONGCTRLMESSAGETYPE,
  122. INFORMATIONMESSAGETYPE,
  123. NOTIFYMESSAGETYPE,
  124. STATUSMESSAGETYPE,
  125. STATUSENQUIRYMESSAGETYPE,
  126. FACILITYMESSAGETYPE
  127. };
  128. #define Q931_PROTOCOL_ID1 0
  129. #define Q931_PROTOCOL_ID2 0
  130. #define Q931_PROTOCOL_ID3 8
  131. #define Q931_PROTOCOL_ID4 2250
  132. #define Q931_PROTOCOL_ID5 0
  133. //#define Q931_PROTOCOL_ID6 1
  134. #define Q931_PROTOCOL_ID6 2 // H.225 version 2!
  135. VOID Q931PduInit()
  136. {
  137. ProtocolId1.value = Q931_PROTOCOL_ID1;
  138. ProtocolId1.next = &ProtocolId2;
  139. ProtocolId2.value = Q931_PROTOCOL_ID2;
  140. ProtocolId2.next = &ProtocolId3;
  141. ProtocolId3.value = Q931_PROTOCOL_ID3;
  142. ProtocolId3.next = &ProtocolId4;
  143. ProtocolId4.value = Q931_PROTOCOL_ID4;
  144. ProtocolId4.next = &ProtocolId5;
  145. ProtocolId5.value = Q931_PROTOCOL_ID5;
  146. ProtocolId5.next = &ProtocolId6;
  147. ProtocolId6.value = Q931_PROTOCOL_ID6;
  148. ProtocolId6.next = NULL;
  149. // gateway protocol supported. For now, hard-coded to only 1: H323.
  150. TempProtocol.next = NULL;
  151. TempProtocol.value.choice = h323_chosen;
  152. }
  153. //====================================================================================
  154. //====================================================================================
  155. static CS_STATUS
  156. AliasToSeqof(struct Setup_UUIE_sourceAddress **ppTarget, PCC_ALIASNAMES pSource)
  157. {
  158. if (ppTarget == NULL)
  159. {
  160. return CS_BAD_PARAM;
  161. }
  162. *ppTarget = NULL;
  163. if (pSource == NULL)
  164. {
  165. return CS_OK;
  166. }
  167. if (pSource && (pSource->wCount))
  168. {
  169. struct Setup_UUIE_sourceAddress *ListHead = NULL;
  170. struct Setup_UUIE_sourceAddress *CurrentNode = NULL;
  171. LPWSTR pData = NULL; // UNICODE STRING
  172. int SourceItem;
  173. WORD x;
  174. for (SourceItem = pSource->wCount - 1; SourceItem >= 0; SourceItem--)
  175. {
  176. BOOL Cleanup = FALSE;
  177. // first do the required memory allocations...
  178. CurrentNode = (struct Setup_UUIE_sourceAddress *)MemAlloc(sizeof(struct Setup_UUIE_sourceAddress));
  179. if (CurrentNode == NULL)
  180. {
  181. Cleanup = TRUE;
  182. }
  183. else
  184. {
  185. if (pSource->pItems[SourceItem].wType == CC_ALIAS_H323_ID)
  186. {
  187. if ((pSource->pItems[SourceItem].wDataLength != 0) &&
  188. (pSource->pItems[SourceItem].pData != NULL))
  189. {
  190. pData = (LPWSTR)MemAlloc(pSource->pItems[SourceItem].wDataLength *
  191. sizeof(WCHAR));
  192. if (pData == NULL)
  193. {
  194. MemFree(CurrentNode);
  195. Cleanup = TRUE;
  196. }
  197. }
  198. }
  199. }
  200. if (Cleanup)
  201. {
  202. for (CurrentNode = ListHead; CurrentNode; CurrentNode = ListHead)
  203. {
  204. ListHead = CurrentNode->next;
  205. if (CurrentNode->value.choice == h323_ID_chosen)
  206. {
  207. if (CurrentNode->value.u.h323_ID.value)
  208. {
  209. MemFree(CurrentNode->value.u.h323_ID.value);
  210. }
  211. }
  212. MemFree(CurrentNode);
  213. }
  214. return CS_NO_MEMORY;
  215. }
  216. // then do the required memory copying.
  217. if (pSource->pItems[SourceItem].wType == CC_ALIAS_H323_ID)
  218. {
  219. CurrentNode->value.choice = h323_ID_chosen;
  220. if ((pSource->pItems[SourceItem].wDataLength != 0) &&
  221. (pSource->pItems[SourceItem].pData != NULL))
  222. {
  223. CurrentNode->value.u.h323_ID.length =
  224. pSource->pItems[SourceItem].wDataLength;
  225. for (x = 0; x < pSource->pItems[SourceItem].wDataLength; x++)
  226. {
  227. pData[x] = pSource->pItems[SourceItem].pData[x];
  228. }
  229. CurrentNode->value.u.h323_ID.value = pData;
  230. }
  231. else
  232. {
  233. CurrentNode->value.u.h323_ID.length = 0;
  234. CurrentNode->value.u.h323_ID.value = NULL;
  235. }
  236. }
  237. else if (pSource->pItems[SourceItem].wType == CC_ALIAS_H323_PHONE)
  238. {
  239. CurrentNode->value.choice = e164_chosen;
  240. if ((pSource->pItems[SourceItem].wDataLength != 0) &&
  241. (pSource->pItems[SourceItem].pData != NULL))
  242. {
  243. for (x = 0; x < pSource->pItems[SourceItem].wDataLength; x++)
  244. {
  245. CurrentNode->value.u.e164[x] = (BYTE)(pSource->pItems[SourceItem].pData[x]);
  246. }
  247. CurrentNode->value.u.e164[pSource->pItems[SourceItem].wDataLength] = '\0';
  248. }
  249. else
  250. {
  251. CurrentNode->value.u.e164[0] = '\0';
  252. }
  253. }
  254. CurrentNode->next = ListHead;
  255. ListHead = CurrentNode;
  256. }
  257. *ppTarget = ListHead;
  258. }
  259. return CS_OK;
  260. }
  261. //====================================================================================
  262. //====================================================================================
  263. static CS_STATUS
  264. AliasWithPrefixToSeqof(struct Setup_UUIE_sourceAddress **ppTarget, PCC_ALIASNAMES pSource)
  265. {
  266. if (ppTarget == NULL)
  267. {
  268. return CS_BAD_PARAM;
  269. }
  270. *ppTarget = NULL;
  271. if (pSource == NULL)
  272. {
  273. return CS_OK;
  274. }
  275. if (pSource && (pSource->wCount))
  276. {
  277. struct Setup_UUIE_sourceAddress *ListHead = NULL;
  278. struct Setup_UUIE_sourceAddress *CurrentNode = NULL;
  279. int SourceItem;
  280. for (SourceItem = pSource->wCount - 1; SourceItem >= 0; SourceItem--)
  281. {
  282. PCC_ALIASITEM pItem = &pSource->pItems[SourceItem];
  283. LPWSTR pData = NULL; // UNICODE STRING
  284. BOOL Cleanup = FALSE;
  285. unsigned uPrefixLength;
  286. unsigned uDataLength;
  287. unsigned x;
  288. if (pItem->pPrefix != NULL &&
  289. pItem->wPrefixLength > 0)
  290. {
  291. uPrefixLength = (unsigned) pItem->wPrefixLength;
  292. }
  293. else
  294. {
  295. uPrefixLength = 0;
  296. }
  297. if (pItem->pData != NULL &&
  298. pItem->wDataLength > 0)
  299. {
  300. uDataLength = (unsigned) pItem->wDataLength;
  301. }
  302. else
  303. {
  304. uDataLength = 0;
  305. }
  306. // first do the required memory allocations...
  307. CurrentNode = (struct Setup_UUIE_sourceAddress *)MemAlloc(sizeof(struct Setup_UUIE_sourceAddress));
  308. if (CurrentNode == NULL)
  309. {
  310. Cleanup = TRUE;
  311. }
  312. else
  313. {
  314. if (pItem->wType == CC_ALIAS_H323_ID)
  315. {
  316. #ifdef USE_PREFIX_FOR_H323_ID
  317. if (uPrefixLength != 0 || uDataLength != 0)
  318. {
  319. pData = (LPWSTR)MemAlloc((uPrefixLength + uDataLength) * sizeof(WCHAR));
  320. #else
  321. if (uDataLength != 0)
  322. {
  323. pData = (LPWSTR)MemAlloc((uDataLength) * sizeof(WCHAR));
  324. #endif
  325. if (pData == NULL)
  326. {
  327. MemFree(CurrentNode);
  328. Cleanup = TRUE;
  329. }
  330. }
  331. }
  332. }
  333. if (Cleanup)
  334. {
  335. for (CurrentNode = ListHead; CurrentNode; CurrentNode = ListHead)
  336. {
  337. ListHead = CurrentNode->next;
  338. if (CurrentNode->value.choice == h323_ID_chosen)
  339. {
  340. if (CurrentNode->value.u.h323_ID.value)
  341. {
  342. MemFree(CurrentNode->value.u.h323_ID.value);
  343. }
  344. }
  345. MemFree(CurrentNode);
  346. }
  347. return CS_NO_MEMORY;
  348. }
  349. // then do the required memory copying.
  350. switch (pItem->wType)
  351. {
  352. case CC_ALIAS_H323_ID:
  353. CurrentNode->value.choice = h323_ID_chosen;
  354. #ifdef USE_PREFIX_FOR_H323_ID
  355. if (uPrefixLength != 0 || uDataLength != 0)
  356. {
  357. CurrentNode->value.u.h323_ID.length = (WORD)(uPrefixLength + uDataLength);
  358. for (x = 0; x < uPrefixLength; ++x)
  359. {
  360. pData[x] = pItem->pPrefix[x];
  361. }
  362. for (x = 0; x < uDataLength; ++x)
  363. {
  364. pData[uPrefixLength + x] = pItem->pData[x];
  365. }
  366. #else
  367. if (uDataLength != 0)
  368. {
  369. CurrentNode->value.u.h323_ID.length = (WORD)(uDataLength);
  370. for (x = 0; x < uDataLength; ++x)
  371. {
  372. pData[x] = pItem->pData[x];
  373. }
  374. #endif
  375. CurrentNode->value.u.h323_ID.value = pData;
  376. }
  377. else
  378. {
  379. CurrentNode->value.u.h323_ID.length = 0;
  380. CurrentNode->value.u.h323_ID.value = NULL;
  381. }
  382. break;
  383. case CC_ALIAS_H323_PHONE:
  384. CurrentNode->value.choice = e164_chosen;
  385. for (x = 0; x < uPrefixLength; ++x)
  386. {
  387. CurrentNode->value.u.e164[x] = (BYTE)(pItem->pPrefix[x]);
  388. }
  389. for (x = 0; x < uDataLength; ++x)
  390. {
  391. CurrentNode->value.u.e164[uPrefixLength + x] = (BYTE)(pItem->pData[x]);
  392. }
  393. for (x = uDataLength + uPrefixLength; x < sizeof(CurrentNode->value.u.e164); ++x)
  394. {
  395. CurrentNode->value.u.e164[x] = 0;
  396. }
  397. break;
  398. default:
  399. MemFree(CurrentNode);
  400. for (CurrentNode = ListHead; CurrentNode; CurrentNode = ListHead)
  401. {
  402. ListHead = CurrentNode->next;
  403. if (CurrentNode->value.choice == h323_ID_chosen)
  404. {
  405. if (CurrentNode->value.u.h323_ID.value)
  406. {
  407. MemFree(CurrentNode->value.u.h323_ID.value);
  408. }
  409. }
  410. MemFree(CurrentNode);
  411. }
  412. return CS_BAD_PARAM;
  413. } // switch
  414. CurrentNode->next = ListHead;
  415. ListHead = CurrentNode;
  416. }
  417. *ppTarget = ListHead;
  418. }
  419. return CS_OK;
  420. }
  421. //====================================================================================
  422. //====================================================================================
  423. static CS_STATUS
  424. SeqofToAlias(PCC_ALIASNAMES *ppTarget, struct Setup_UUIE_sourceAddress *pSource)
  425. {
  426. struct Setup_UUIE_sourceAddress *ListHead = NULL;
  427. struct Setup_UUIE_sourceAddress *CurrentNode = NULL;
  428. WORD wCount;
  429. WORD x = 0;
  430. PCC_ALIASITEM p = NULL;
  431. CS_STATUS status = CS_OK;
  432. if (ppTarget == NULL)
  433. {
  434. return CS_BAD_PARAM;
  435. }
  436. *ppTarget = NULL;
  437. if (pSource == NULL)
  438. {
  439. return CS_OK;
  440. }
  441. wCount = 0;
  442. for (CurrentNode = pSource; CurrentNode; CurrentNode = CurrentNode->next)
  443. {
  444. wCount++;
  445. }
  446. *ppTarget = (PCC_ALIASNAMES)MemAlloc(sizeof(CC_ALIASNAMES));
  447. if (*ppTarget == NULL)
  448. {
  449. return CS_NO_MEMORY;
  450. }
  451. (*ppTarget)->pItems = (PCC_ALIASITEM)MemAlloc(wCount * sizeof(CC_ALIASITEM));
  452. if ((*ppTarget)->pItems == NULL)
  453. {
  454. MemFree(*ppTarget);
  455. *ppTarget = NULL;
  456. return CS_NO_MEMORY;
  457. }
  458. p = (*ppTarget)->pItems;
  459. for (CurrentNode = pSource; CurrentNode; CurrentNode = CurrentNode->next)
  460. {
  461. WORD y;
  462. p[x].wPrefixLength = 0;
  463. p[x].pPrefix = NULL;
  464. switch (CurrentNode->value.choice)
  465. {
  466. case h323_ID_chosen:
  467. p[x].wType = CC_ALIAS_H323_ID;
  468. if ((CurrentNode->value.u.h323_ID.length != 0) &&
  469. (CurrentNode->value.u.h323_ID.value != NULL))
  470. {
  471. p[x].wDataLength = (WORD) CurrentNode->value.u.h323_ID.length;
  472. p[x].pData = (LPWSTR)MemAlloc(CurrentNode->value.u.h323_ID.length * sizeof(p[x].pData[0]));
  473. if (p[x].pData != NULL)
  474. {
  475. for (y = 0; y < CurrentNode->value.u.h323_ID.length; y++)
  476. {
  477. p[x].pData[y] = (WCHAR)((CurrentNode->value.u.h323_ID.value)[y]);
  478. }
  479. x++;
  480. }
  481. else
  482. {
  483. status = CS_NO_MEMORY;
  484. }
  485. }
  486. break;
  487. case e164_chosen:
  488. p[x].wType = CC_ALIAS_H323_PHONE;
  489. p[x].wDataLength = (WORD)strlen(CurrentNode->value.u.e164);
  490. p[x].pData = (LPWSTR)MemAlloc((p[x].wDataLength+1) * sizeof(p[x].pData[0]));
  491. if (p[x].pData != NULL)
  492. {
  493. for (y = 0; y < p[x].wDataLength; y++)
  494. {
  495. p[x].pData[y] = CurrentNode->value.u.e164[y];
  496. }
  497. p[x].pData[p[x].wDataLength] = 0;
  498. x++;
  499. }
  500. else
  501. {
  502. status = CS_NO_MEMORY;
  503. }
  504. break;
  505. default:
  506. // we don't currently handle other alias types
  507. break;
  508. } // switch
  509. if (status != CS_OK)
  510. {
  511. // Free everything that has been allocated so far...
  512. for (y = 0; y < x; y++)
  513. {
  514. MemFree(p[y].pData);
  515. }
  516. MemFree(p);
  517. MemFree(*ppTarget);
  518. *ppTarget = NULL;
  519. return status;
  520. }
  521. }
  522. (*ppTarget)->wCount = x;
  523. return CS_OK;
  524. }
  525. //====================================================================================
  526. //====================================================================================
  527. static CS_STATUS
  528. FreeSeqof(struct Setup_UUIE_sourceAddress *pSource)
  529. {
  530. struct Setup_UUIE_sourceAddress *CurrentNode = NULL;
  531. for (CurrentNode = pSource; CurrentNode; CurrentNode = pSource)
  532. {
  533. pSource = CurrentNode->next;
  534. if (CurrentNode->value.choice == h323_ID_chosen)
  535. {
  536. if (CurrentNode->value.u.h323_ID.value)
  537. {
  538. MemFree(CurrentNode->value.u.h323_ID.value);
  539. }
  540. }
  541. MemFree(CurrentNode);
  542. }
  543. return CS_OK;
  544. }
  545. //====================================================================================
  546. //====================================================================================
  547. static CS_STATUS
  548. Q931CopyAliasItemToAliasAddr(AliasAddress *pTarget, PCC_ALIASITEM pSource)
  549. {
  550. AliasAddress *pNewAddress = NULL;
  551. WORD x;
  552. if (pTarget == NULL)
  553. {
  554. return CS_BAD_PARAM;
  555. }
  556. if (pSource == NULL)
  557. {
  558. return CS_BAD_PARAM;
  559. }
  560. pNewAddress = pTarget;
  561. if (pSource->wType == CC_ALIAS_H323_ID)
  562. {
  563. pNewAddress->choice = h323_ID_chosen;
  564. if ((pSource->wDataLength != 0) && (pSource->pData != NULL))
  565. {
  566. LPWSTR pData = NULL; // UNICODE STRING
  567. pData = (LPWSTR)MemAlloc(pSource->wDataLength * sizeof(WCHAR));
  568. if (pData == NULL)
  569. {
  570. return CS_NO_MEMORY;
  571. }
  572. pNewAddress->u.h323_ID.length = pSource->wDataLength;
  573. for (x = 0; x < pSource->wDataLength; x++)
  574. {
  575. pData[x] = pSource->pData[x];
  576. }
  577. pNewAddress->u.h323_ID.value = pData;
  578. }
  579. else
  580. {
  581. pNewAddress->u.h323_ID.length = 0;
  582. pNewAddress->u.h323_ID.value = NULL;
  583. }
  584. }
  585. else if (pSource->wType == CC_ALIAS_H323_PHONE)
  586. {
  587. pNewAddress->choice = e164_chosen;
  588. if ((pSource->wDataLength != 0) && (pSource->pData != NULL))
  589. {
  590. for (x = 0; x < pSource->wDataLength; x++)
  591. {
  592. pNewAddress->u.e164[x] = (BYTE)(pSource->pData[x]);
  593. }
  594. pNewAddress->u.e164[pSource->wDataLength] = '\0';
  595. }
  596. else
  597. {
  598. pNewAddress->u.e164[0] = '\0';
  599. }
  600. }
  601. return CS_OK;
  602. }
  603. //====================================================================================
  604. //====================================================================================
  605. static CS_STATUS
  606. Q931AliasAddrToAliasItem(PCC_ALIASITEM *ppTarget, AliasAddress *pSource)
  607. {
  608. PCC_ALIASITEM pNewItem = NULL;
  609. WORD y;
  610. if (ppTarget == NULL)
  611. {
  612. return CS_BAD_PARAM;
  613. }
  614. if (pSource == NULL)
  615. {
  616. *ppTarget = NULL;
  617. return CS_OK;
  618. }
  619. pNewItem = (PCC_ALIASITEM)MemAlloc(sizeof(CC_ALIASITEM));
  620. if (pNewItem == NULL)
  621. {
  622. *ppTarget = NULL;
  623. return CS_NO_MEMORY;
  624. }
  625. memset(pNewItem, 0, sizeof(*pNewItem));
  626. switch (pSource->choice)
  627. {
  628. case h323_ID_chosen:
  629. pNewItem->wType = CC_ALIAS_H323_ID;
  630. if ((pSource->u.h323_ID.length != 0) &&
  631. (pSource->u.h323_ID.value != NULL))
  632. {
  633. // convert the text from UNICODE to ascii.
  634. pNewItem->wDataLength = (WORD) pSource->u.h323_ID.length;
  635. pNewItem->pData = (LPWSTR)MemAlloc(pSource->u.h323_ID.length * sizeof(pNewItem->pData[0]));
  636. if (pNewItem->pData == NULL)
  637. {
  638. MemFree(pNewItem);
  639. return CS_NO_MEMORY;
  640. }
  641. for (y = 0; y < pSource->u.h323_ID.length; y++)
  642. {
  643. pNewItem->pData[y] = (WCHAR)((pSource->u.h323_ID.value)[y]);
  644. }
  645. }
  646. break;
  647. case e164_chosen:
  648. pNewItem->wType = CC_ALIAS_H323_PHONE;
  649. pNewItem->wDataLength = (WORD)strlen(pSource->u.e164);
  650. pNewItem->pData = (LPWSTR)MemAlloc((pNewItem->wDataLength + 1) * sizeof(pNewItem->pData[0]));
  651. if (pNewItem->pData == NULL)
  652. {
  653. MemFree(pNewItem);
  654. return CS_NO_MEMORY;
  655. }
  656. for (y = 0; y < pNewItem->wDataLength; y++)
  657. {
  658. pNewItem->pData[y] = pSource->u.e164[y];
  659. }
  660. pNewItem->pData[pNewItem->wDataLength] = 0;
  661. break;
  662. default:
  663. MemFree(pNewItem);
  664. *ppTarget = NULL;
  665. return CS_BAD_PARAM;
  666. } // switch
  667. *ppTarget = pNewItem;
  668. return CS_OK;
  669. }
  670. //====================================================================================
  671. //====================================================================================
  672. static CS_STATUS
  673. Q931ClearAliasAddr(AliasAddress *pSource)
  674. {
  675. if (pSource)
  676. {
  677. if (pSource->choice == h323_ID_chosen)
  678. {
  679. if (pSource->u.h323_ID.value)
  680. {
  681. MemFree(pSource->u.h323_ID.value);
  682. }
  683. }
  684. }
  685. return CS_OK;
  686. }
  687. //------------------------------------------------------------------------------
  688. // Parse and return a single octet encoded value, See Q931 section 4.5.1.
  689. //
  690. // Parameters:
  691. // BufferPtr Pointer to a descriptor of the buffer
  692. // containing the length and a pointer
  693. // to the raw bytes of the input stream.
  694. // Ident Pointer to space for field identifier
  695. // Value Pointer to space for field value
  696. //------------------------------------------------------------------------------
  697. static HRESULT
  698. ParseSingleOctetType1(
  699. PBUFFERDESCR BufferDescriptor,
  700. BYTE *Ident,
  701. BYTE *Value)
  702. {
  703. // There has to be at least 1 byte in the stream to be
  704. // able to parse the single octet value
  705. if (BufferDescriptor->Length < 1)
  706. {
  707. return CS_ENDOFINPUT;
  708. }
  709. // low bits (0, 1, 2, 3) of the byte are the value
  710. *Value = (BYTE)(*BufferDescriptor->BufferPtr & TYPE1VALUEMASK);
  711. // higher bits (4, 5, 6) are the identifier. bit 7 is always 1,
  712. // and is not returned as part of the id.
  713. *Ident = (BYTE)((*BufferDescriptor->BufferPtr & 0x70) >> 4);
  714. BufferDescriptor->BufferPtr++;
  715. BufferDescriptor->Length--;
  716. return CS_OK;
  717. }
  718. //------------------------------------------------------------------------------
  719. // Parse and return a single octet encoded value, See Q931 section 4.5.1.
  720. // This octet has no value, only an identifier.
  721. //
  722. // Parameters:
  723. // BufferPtr Pointer to a descriptor of the buffer containing the
  724. // length and a pointer to the raw bytes of the input stream.
  725. // Ident Pointer to space for field identifier
  726. //------------------------------------------------------------------------------
  727. static HRESULT
  728. ParseSingleOctetType2(
  729. PBUFFERDESCR BufferDescriptor,
  730. BYTE *Ident)
  731. {
  732. // There has to be at least 1 byte in the stream to be
  733. // able to parse the single octet value
  734. if (BufferDescriptor->Length < 1)
  735. {
  736. return CS_ENDOFINPUT;
  737. }
  738. // low 7 bits of the byte are the identifier
  739. *Ident = (BYTE)(*BufferDescriptor->BufferPtr & 0x7f);
  740. BufferDescriptor->BufferPtr++;
  741. BufferDescriptor->Length--;
  742. return CS_OK;
  743. }
  744. //------------------------------------------------------------------------------
  745. // Parse and return a variable length Q931 field see Q931 section 4.5.1.
  746. //
  747. // Parameters :
  748. // BufferPtr Pointer to a descriptor of the buffer
  749. // containing the length and a pointer
  750. // to the raw bytes of the input stream.
  751. // Ident Pointer to space for field identifier
  752. // Length Pointer to space for the length
  753. // Contents Pointer to space for the bytes of the field
  754. //------------------------------------------------------------------------------
  755. static HRESULT
  756. ParseVariableOctet(
  757. PBUFFERDESCR BufferDescriptor,
  758. BYTE *Ident,
  759. BYTE *Length,
  760. BYTE *Contents)
  761. {
  762. register int i;
  763. BYTE *Tempptr;
  764. // There has to be at least 2 bytes in order just to get
  765. // the length and the identifier
  766. // able to parse the single octet value
  767. if (BufferDescriptor->Length < 2)
  768. {
  769. return CS_ENDOFINPUT;
  770. }
  771. // low 7 bits of the first byte are the identifier
  772. *Ident= (BYTE)(*BufferDescriptor->BufferPtr & 0x7f);
  773. BufferDescriptor->BufferPtr++;
  774. BufferDescriptor->Length--;
  775. // The next byte is the length
  776. *Length = *BufferDescriptor->BufferPtr;
  777. BufferDescriptor->BufferPtr++;
  778. BufferDescriptor->Length--;
  779. ASSERT(*Length <= MAXVARFIELDLEN);
  780. if (MAXVARFIELDLEN < *Length)
  781. {
  782. return CS_INVALID_FIELD;
  783. }
  784. if (BufferDescriptor->Length < *Length)
  785. {
  786. return CS_ENDOFINPUT;
  787. }
  788. Tempptr = Contents;
  789. for (i = 0; i < *Length; i++)
  790. {
  791. // Copy the bytes out of the rest of the buffer
  792. *Tempptr = *BufferDescriptor->BufferPtr;
  793. BufferDescriptor->BufferPtr++;
  794. BufferDescriptor->Length--;
  795. Tempptr++;
  796. }
  797. return CS_OK;
  798. }
  799. //------------------------------------------------------------------------------
  800. // Parse and return a variable length Q931 field see Q931 section 4.5.1.
  801. //------------------------------------------------------------------------------
  802. static HRESULT
  803. ParseVariableASN(
  804. PBUFFERDESCR BufferDescriptor,
  805. BYTE *Ident,
  806. BYTE *ProtocolDiscriminator,
  807. WORD *UserInformationLength, // Length of the User Information.
  808. BYTE *UserInformation, // Bytes of the User Information.
  809. WORD cbMaxUserInformation)
  810. {
  811. register int i;
  812. BYTE *Tempptr;
  813. WORD ContentsLength; // Length of the full UserUser contents.
  814. *UserInformationLength = 0;
  815. // There has to be at least 4 bytes for the IE identifier,
  816. // the contents length, and the protocol discriminator (1 + 2 + 1).
  817. if (BufferDescriptor->Length < 4)
  818. {
  819. return CS_ENDOFINPUT;
  820. }
  821. // low 7 bits of the first byte are the identifier
  822. *Ident= (BYTE)(*BufferDescriptor->BufferPtr & 0x7f);
  823. BufferDescriptor->BufferPtr++;
  824. BufferDescriptor->Length--;
  825. // The next 2 bytes are the length
  826. ContentsLength = *(BufferDescriptor->BufferPtr);
  827. BufferDescriptor->BufferPtr++;
  828. BufferDescriptor->Length--;
  829. ContentsLength = (WORD)((ContentsLength << 8) + *BufferDescriptor->BufferPtr);
  830. BufferDescriptor->BufferPtr++;
  831. BufferDescriptor->Length--;
  832. if (BufferDescriptor->Length < ContentsLength)
  833. {
  834. return CS_ENDOFINPUT;
  835. }
  836. // The next byte is the protocol discriminator.
  837. *ProtocolDiscriminator = *BufferDescriptor->BufferPtr;
  838. BufferDescriptor->BufferPtr++;
  839. BufferDescriptor->Length--;
  840. if (ContentsLength > 0)
  841. {
  842. *UserInformationLength = (WORD)(ContentsLength - 1);
  843. }
  844. ASSERT(*UserInformationLength <= cbMaxUserInformation);
  845. if(cbMaxUserInformation < *UserInformationLength)
  846. {
  847. return CS_INVALID_FIELD;
  848. }
  849. Tempptr = UserInformation;
  850. for (i = 0; i < *UserInformationLength; i++)
  851. {
  852. // Copy the bytes out of the rest of the buffer
  853. *Tempptr = *BufferDescriptor->BufferPtr;
  854. BufferDescriptor->BufferPtr++;
  855. BufferDescriptor->Length--;
  856. Tempptr++;
  857. }
  858. return CS_OK;
  859. }
  860. //------------------------------------------------------------------------------
  861. // Get the identifier of the next field from the buffer and
  862. // return it. The buffer pointer is not incremented, To
  863. // parse the field and extract its values, the above functions
  864. // should be used. See Q931 table 4-3 for the encodings of the
  865. // identifiers.
  866. //
  867. // Parameters:
  868. // BufferPtr Pointer to the buffer space
  869. //------------------------------------------------------------------------------
  870. static BYTE
  871. GetNextIdent(
  872. void *BufferPtr)
  873. {
  874. FIELDIDENTTYPE Ident;
  875. // Extract the first byte from the buffer
  876. Ident= (*(FIELDIDENTTYPE *)BufferPtr);
  877. // This value can be returned as the identifier as long
  878. // as it is not a single Octet - Type 1 element.
  879. // Those items must have the value removed from them
  880. // before they can be returned.
  881. if ((Ident & 0x80) && ((Ident & TYPE1IDENTMASK) != 0xA0))
  882. {
  883. return (BYTE)(Ident & TYPE1IDENTMASK);
  884. }
  885. return Ident;
  886. }
  887. //------------------------------------------------------------------------------
  888. // Parse and return a protocol discriminator. See Q931 section 4.2.
  889. // The octet pointed to by **BufferPtr is the protocol Discriminator.
  890. //
  891. // Parameters:
  892. // BufferPtr Pointer to a descriptor of the buffer
  893. // containing the length and a pointer
  894. // to the raw bytes of the input stream.
  895. // Discrim Pointer to space for discriminator
  896. //------------------------------------------------------------------------------
  897. static HRESULT
  898. ParseProtocolDiscriminator(
  899. PBUFFERDESCR BufferDescriptor,
  900. PDTYPE *Discrim)
  901. {
  902. // There has to be at least enough bytes left in the
  903. // string for the operation
  904. if (BufferDescriptor->Length < sizeof(PDTYPE))
  905. {
  906. return CS_ENDOFINPUT;
  907. }
  908. *Discrim = *(PDTYPE *)BufferDescriptor->BufferPtr;
  909. if (*Discrim != Q931PDVALUE)
  910. {
  911. return CS_INVALID_PROTOCOL;
  912. }
  913. BufferDescriptor->BufferPtr += sizeof(PDTYPE);
  914. BufferDescriptor->Length -= sizeof(PDTYPE);
  915. return CS_OK;
  916. }
  917. //------------------------------------------------------------------------------
  918. // Parse and return a variable length Q931 call reference see
  919. // Q931 section 4.3.
  920. //
  921. // Parameters:
  922. // BufferPtr Pointer to a descriptor of the buffer
  923. // containing the length and a pointer
  924. // to the raw bytes of the input stream.
  925. // Length Pointer to space for the length
  926. // Contents Pointer to space for the bytes of the field
  927. //------------------------------------------------------------------------------
  928. static HRESULT
  929. ParseCallReference(
  930. PBUFFERDESCR BufferDescriptor,
  931. CRTYPE *CallReference)
  932. {
  933. register int i;
  934. BYTE Length;
  935. // There has to be at least enough bytes left in the
  936. // string for the length byte
  937. if (BufferDescriptor->Length < 1)
  938. {
  939. return CS_ENDOFINPUT;
  940. }
  941. // low 4 bits of the first byte are the length.
  942. // the rest of the bits are zeroes.
  943. Length = (BYTE)(*BufferDescriptor->BufferPtr & 0x0f);
  944. BufferDescriptor->BufferPtr++;
  945. BufferDescriptor->Length--;
  946. // There has to be at least enough bytes left in the
  947. // string for the operation
  948. if (BufferDescriptor->Length < Length)
  949. {
  950. return CS_ENDOFINPUT;
  951. }
  952. *CallReference = 0; // length can be 0, so initialize here first...
  953. for (i = 0; i < Length; i++)
  954. {
  955. if (i < sizeof(CRTYPE))
  956. {
  957. // Copy the bytes out of the rest of the buffer
  958. *CallReference = (WORD)((*CallReference << 8) +
  959. *BufferDescriptor->BufferPtr);
  960. }
  961. BufferDescriptor->BufferPtr++;
  962. BufferDescriptor->Length--;
  963. }
  964. // note: the high order bit of the value represents callee relationship.
  965. return CS_OK;
  966. }
  967. //------------------------------------------------------------------------------
  968. // Parse and return a message type. See Q931 section 4.4.
  969. // The octet pointed to by **BufferPtr is the message type.
  970. //
  971. // Parameters:
  972. // BufferPtr Pointer to a descriptor of the buffer
  973. // containing the length and a pointer
  974. // to the raw bytes of the input stream.
  975. // MessageType Pointer to space for message type
  976. //------------------------------------------------------------------------------
  977. static HRESULT
  978. ParseMessageType(
  979. PBUFFERDESCR BufferDescriptor,
  980. MESSAGEIDTYPE *MessageType)
  981. {
  982. register int i;
  983. // There has to be at least enough bytes left in the
  984. // string for the operation
  985. if (BufferDescriptor->Length < sizeof(MESSAGEIDTYPE))
  986. {
  987. return CS_ENDOFINPUT;
  988. }
  989. *MessageType = (BYTE)(*((MESSAGEIDTYPE *)BufferDescriptor->BufferPtr) & MESSAGETYPEMASK);
  990. for (i = 0; i < sizeof(MessageSet) / sizeof(MESSAGEIDTYPE); i++)
  991. {
  992. if (MessageSet[i] == *MessageType)
  993. {
  994. break;
  995. }
  996. }
  997. if (i >= sizeof(MessageSet) / sizeof(MESSAGEIDTYPE))
  998. {
  999. return CS_INVALID_MESSAGE_TYPE;
  1000. }
  1001. BufferDescriptor->BufferPtr += sizeof(MESSAGEIDTYPE);
  1002. BufferDescriptor->Length -= sizeof(MESSAGEIDTYPE);
  1003. return CS_OK;
  1004. }
  1005. //------------------------------------------------------------------------------
  1006. // Parse an optional shift field
  1007. //
  1008. // Parameters:
  1009. // BufferPtr Pointer to a descriptor of the buffer containing the
  1010. // length and a pointer to the raw bytes of the input stream.
  1011. // FieldStruct Pointer to space for parsed shift message information.
  1012. //------------------------------------------------------------------------------
  1013. static HRESULT
  1014. ParseShift(
  1015. PBUFFERDESCR BufferDescriptor,
  1016. PSHIFTIE FieldStruct)
  1017. {
  1018. BYTE Ident;
  1019. memset(FieldStruct, 0, sizeof(SHIFTIE));
  1020. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_SHIFT)
  1021. {
  1022. FieldStruct->Present = TRUE;
  1023. return ParseSingleOctetType1(BufferDescriptor,
  1024. &Ident, &FieldStruct->Value);
  1025. }
  1026. else
  1027. {
  1028. FieldStruct->Present = FALSE;
  1029. }
  1030. return CS_OK;
  1031. }
  1032. //------------------------------------------------------------------------------
  1033. // Parse an optional facility ie field
  1034. //
  1035. // Parameters:
  1036. // BufferPtr Pointer to a descriptor of the buffer
  1037. // containing the length and a pointer
  1038. // to the raw bytes of the input stream.
  1039. // FieldStruct Pointer to space for parsed facility
  1040. // information.
  1041. //------------------------------------------------------------------------------
  1042. static HRESULT
  1043. ParseFacility(
  1044. PBUFFERDESCR BufferDescriptor,
  1045. PFACILITYIE FieldStruct)
  1046. {
  1047. BYTE Ident;
  1048. memset(FieldStruct, 0, sizeof(FACILITYIE));
  1049. FieldStruct->Present = FALSE;
  1050. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_FACILITY)
  1051. {
  1052. HRESULT ParseResult;
  1053. ParseResult = ParseVariableOctet(BufferDescriptor,
  1054. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1055. if (ParseResult != CS_OK)
  1056. {
  1057. return ParseResult;
  1058. }
  1059. if (FieldStruct->Length > 0)
  1060. {
  1061. FieldStruct->Present = TRUE;
  1062. }
  1063. }
  1064. return CS_OK;
  1065. }
  1066. //------------------------------------------------------------------------------
  1067. // Parse an optional more data field
  1068. //
  1069. // Parameters:
  1070. // BufferPtr Pointer to a descriptor of the buffer
  1071. // containing the length and a pointer
  1072. // to the raw bytes of the input stream.
  1073. // FieldStruct Pointer to space for parsed field information
  1074. //------------------------------------------------------------------------------
  1075. static HRESULT
  1076. ParseMoreData(
  1077. PBUFFERDESCR BufferDescriptor,
  1078. PMOREDATAIE FieldStruct)
  1079. {
  1080. BYTE Ident;
  1081. memset(FieldStruct, 0, sizeof(MOREDATAIE));
  1082. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_MORE)
  1083. {
  1084. FieldStruct->Present = TRUE;
  1085. return ParseSingleOctetType2(BufferDescriptor, &Ident);
  1086. }
  1087. else
  1088. {
  1089. FieldStruct->Present = FALSE;
  1090. }
  1091. return CS_OK;
  1092. }
  1093. //------------------------------------------------------------------------------
  1094. // Parse an optional sending clomplete field. Q931 section 4.4.
  1095. // The octet pointed to by **BufferPtr is the message type.
  1096. //
  1097. // Parameters:
  1098. // BufferPtr Pointer to a descriptor of the buffer
  1099. // containing the length and a pointer
  1100. // to the raw bytes of the input stream.
  1101. // MessageType Pointer to space for message type
  1102. //------------------------------------------------------------------------------
  1103. static HRESULT
  1104. ParseSendingComplete(
  1105. PBUFFERDESCR BufferDescriptor,
  1106. PSENDCOMPLIE FieldStruct)
  1107. {
  1108. BYTE Ident;
  1109. memset(FieldStruct, 0, sizeof(SENDCOMPLIE));
  1110. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_SENDINGCOMPLETE)
  1111. {
  1112. FieldStruct->Present = TRUE;
  1113. return ParseSingleOctetType2(BufferDescriptor, &Ident);
  1114. }
  1115. else
  1116. {
  1117. FieldStruct->Present = FALSE;
  1118. }
  1119. return CS_OK;
  1120. }
  1121. //------------------------------------------------------------------------------
  1122. // Parse an optional congestion level field
  1123. //
  1124. // Parameters:
  1125. // BufferPtr Pointer to a descriptor of the buffer
  1126. // containing the length and a pointer
  1127. // to the raw bytes of the input stream.
  1128. // FieldStruct Pointer to space for parsed congestion
  1129. // level information.
  1130. //------------------------------------------------------------------------------
  1131. static HRESULT
  1132. ParseCongestionLevel(
  1133. PBUFFERDESCR BufferDescriptor,
  1134. PCONGESTIONIE FieldStruct)
  1135. {
  1136. BYTE Ident;
  1137. memset(FieldStruct, 0, sizeof(CONGESTIONIE));
  1138. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_CONGESTION)
  1139. {
  1140. FieldStruct->Present = TRUE;
  1141. return ParseSingleOctetType1(BufferDescriptor,
  1142. &Ident, &FieldStruct->Value);
  1143. }
  1144. else
  1145. {
  1146. FieldStruct->Present = FALSE;
  1147. }
  1148. return CS_OK;
  1149. }
  1150. //------------------------------------------------------------------------------
  1151. // Parse an optional repeat indicator field
  1152. //
  1153. // Parameters:
  1154. // BufferPtr Pointer to a descriptor of the buffer
  1155. // containing the length and a pointer
  1156. // to the raw bytes of the input stream.
  1157. // FieldStruct Pointer to space for parsed repeat
  1158. // information.
  1159. //------------------------------------------------------------------------------
  1160. static HRESULT
  1161. ParseRepeatIndicator(
  1162. PBUFFERDESCR BufferDescriptor,
  1163. PREPEATIE FieldStruct)
  1164. {
  1165. BYTE Ident;
  1166. memset(FieldStruct, 0, sizeof(REPEATIE));
  1167. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_REPEAT)
  1168. {
  1169. FieldStruct->Present = TRUE;
  1170. return ParseSingleOctetType1(BufferDescriptor,
  1171. &Ident, &FieldStruct->Value);
  1172. }
  1173. else
  1174. {
  1175. FieldStruct->Present = FALSE;
  1176. }
  1177. return CS_OK;
  1178. }
  1179. //------------------------------------------------------------------------------
  1180. // Parse an optional segmented message field
  1181. //
  1182. // Parameters:
  1183. // BufferPtr Pointer to a descriptor of the buffer
  1184. // containing the length and a pointer
  1185. // to the raw bytes of the input stream.
  1186. // FieldStruct Pointer to space for parsed segmented message
  1187. // information.
  1188. //------------------------------------------------------------------------------
  1189. static HRESULT
  1190. ParseSegmented(
  1191. PBUFFERDESCR BufferDescriptor,
  1192. PSEGMENTEDIE FieldStruct)
  1193. {
  1194. BYTE Ident;
  1195. memset(FieldStruct, 0, sizeof(SEGMENTEDIE));
  1196. FieldStruct->Present = FALSE;
  1197. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_SEGMENTED)
  1198. {
  1199. HRESULT ParseResult;
  1200. ParseResult = ParseVariableOctet(BufferDescriptor,
  1201. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1202. if (ParseResult != CS_OK)
  1203. {
  1204. return ParseResult;
  1205. }
  1206. if (FieldStruct->Length > 0)
  1207. {
  1208. FieldStruct->Present = TRUE;
  1209. }
  1210. }
  1211. return CS_OK;
  1212. }
  1213. //------------------------------------------------------------------------------
  1214. // Parse an optional bearer capability field
  1215. //
  1216. // Parameters:
  1217. // BufferPtr Pointer to a descriptor of the buffer
  1218. // containing the length and a pointer
  1219. // to the raw bytes of the input stream.
  1220. // FieldStruct Pointer to space for parsed bearer capability
  1221. // information.
  1222. //------------------------------------------------------------------------------
  1223. static HRESULT
  1224. ParseBearerCapability(
  1225. PBUFFERDESCR BufferDescriptor,
  1226. PBEARERCAPIE FieldStruct)
  1227. {
  1228. BYTE Ident;
  1229. memset(FieldStruct, 0, sizeof(BEARERCAPIE));
  1230. FieldStruct->Present = FALSE;
  1231. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_BEARERCAP)
  1232. {
  1233. HRESULT ParseResult;
  1234. ParseResult = ParseVariableOctet(BufferDescriptor,
  1235. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1236. if (ParseResult != CS_OK)
  1237. {
  1238. return ParseResult;
  1239. }
  1240. if (FieldStruct->Length > 0)
  1241. {
  1242. FieldStruct->Present = TRUE;
  1243. }
  1244. }
  1245. return CS_OK;
  1246. }
  1247. //------------------------------------------------------------------------------
  1248. // Parse an optional cause field
  1249. //
  1250. // Parameters:
  1251. // BufferPtr Pointer to a descriptor of the buffer
  1252. // containing the length and a pointer
  1253. // to the raw bytes of the input stream.
  1254. // FieldStruct Pointer to space for parsed cause
  1255. // information.
  1256. //------------------------------------------------------------------------------
  1257. static HRESULT
  1258. ParseCause(
  1259. PBUFFERDESCR BufferDescriptor,
  1260. PCAUSEIE FieldStruct)
  1261. {
  1262. BYTE Ident;
  1263. memset(FieldStruct, 0, sizeof(CAUSEIE));
  1264. FieldStruct->Present = FALSE;
  1265. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_CAUSE)
  1266. {
  1267. HRESULT ParseResult;
  1268. ParseResult = ParseVariableOctet(BufferDescriptor,
  1269. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1270. if (ParseResult != CS_OK)
  1271. {
  1272. return ParseResult;
  1273. }
  1274. if (FieldStruct->Length > 0)
  1275. {
  1276. FieldStruct->Present = TRUE;
  1277. }
  1278. }
  1279. return CS_OK;
  1280. }
  1281. //------------------------------------------------------------------------------
  1282. // Parse an optional call identity field
  1283. //
  1284. // Parameters:
  1285. // BufferPtr Pointer to a descriptor of the buffer
  1286. // containing the length and a pointer
  1287. // to the raw bytes of the input stream.
  1288. // FieldStruct Pointer to space for parsed call identity
  1289. // information.
  1290. //------------------------------------------------------------------------------
  1291. static HRESULT
  1292. ParseCallIdentity(
  1293. PBUFFERDESCR BufferDescriptor,
  1294. PCALLIDENTIE FieldStruct)
  1295. {
  1296. BYTE Ident;
  1297. memset(FieldStruct, 0, sizeof(CALLIDENTIE));
  1298. FieldStruct->Present = FALSE;
  1299. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_CALLIDENT)
  1300. {
  1301. HRESULT ParseResult;
  1302. ParseResult = ParseVariableOctet(BufferDescriptor,
  1303. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1304. if (ParseResult != CS_OK)
  1305. {
  1306. return ParseResult;
  1307. }
  1308. if (FieldStruct->Length > 0)
  1309. {
  1310. FieldStruct->Present = TRUE;
  1311. }
  1312. }
  1313. return CS_OK;
  1314. }
  1315. //------------------------------------------------------------------------------
  1316. // Parse an optional call state field
  1317. //
  1318. // Parameters:
  1319. // BufferPtr Pointer to a descriptor of the buffer
  1320. // containing the length and a pointer
  1321. // to the raw bytes of the input stream.
  1322. // FieldStruct Pointer to space for parsed call state
  1323. // information.
  1324. //------------------------------------------------------------------------------
  1325. static HRESULT
  1326. ParseCallState(
  1327. PBUFFERDESCR BufferDescriptor,
  1328. PCALLSTATEIE FieldStruct)
  1329. {
  1330. BYTE Ident;
  1331. memset(FieldStruct, 0, sizeof(CALLSTATEIE));
  1332. FieldStruct->Present = FALSE;
  1333. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_CALLSTATE)
  1334. {
  1335. HRESULT ParseResult;
  1336. ParseResult = ParseVariableOctet(BufferDescriptor,
  1337. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1338. if (ParseResult != CS_OK)
  1339. {
  1340. return ParseResult;
  1341. }
  1342. if (FieldStruct->Length > 0)
  1343. {
  1344. FieldStruct->Present = TRUE;
  1345. }
  1346. }
  1347. return CS_OK;
  1348. }
  1349. //------------------------------------------------------------------------------
  1350. // Parse an optional channel identification field
  1351. //
  1352. // Parameters:
  1353. // BufferPtr Pointer to a descriptor of the buffer
  1354. // containing the length and a pointer
  1355. // to the raw bytes of the input stream.
  1356. // FieldStruct Pointer to space for parsed channel identity
  1357. // information.
  1358. //------------------------------------------------------------------------------
  1359. static HRESULT
  1360. ParseChannelIdentification(
  1361. PBUFFERDESCR BufferDescriptor,
  1362. PCHANIDENTIE FieldStruct)
  1363. {
  1364. BYTE Ident;
  1365. memset(FieldStruct, 0, sizeof(CHANIDENTIE));
  1366. FieldStruct->Present = FALSE;
  1367. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_CHANNELIDENT)
  1368. {
  1369. HRESULT ParseResult;
  1370. ParseResult = ParseVariableOctet(BufferDescriptor,
  1371. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1372. if (ParseResult != CS_OK)
  1373. {
  1374. return ParseResult;
  1375. }
  1376. if (FieldStruct->Length > 0)
  1377. {
  1378. FieldStruct->Present = TRUE;
  1379. }
  1380. }
  1381. return CS_OK;
  1382. }
  1383. //------------------------------------------------------------------------------
  1384. // Parse an optional progress indication field
  1385. //
  1386. // Parameters:
  1387. // BufferPtr Pointer to a descriptor of the buffer
  1388. // containing the length and a pointer
  1389. // to the raw bytes of the input stream.
  1390. // FieldStruct Pointer to space for parsed progress
  1391. // information.
  1392. //------------------------------------------------------------------------------
  1393. static HRESULT
  1394. ParseProgress(
  1395. PBUFFERDESCR BufferDescriptor,
  1396. PPROGRESSIE FieldStruct)
  1397. {
  1398. BYTE Ident;
  1399. memset(FieldStruct, 0, sizeof(PROGRESSIE));
  1400. FieldStruct->Present = FALSE;
  1401. if ((GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_PROGRESS) ||
  1402. (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_PROGRESS2))
  1403. {
  1404. HRESULT ParseResult;
  1405. ParseResult = ParseVariableOctet(BufferDescriptor,
  1406. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1407. if (ParseResult != CS_OK)
  1408. {
  1409. return ParseResult;
  1410. }
  1411. if (FieldStruct->Length > 0)
  1412. {
  1413. FieldStruct->Present = TRUE;
  1414. }
  1415. }
  1416. return CS_OK;
  1417. }
  1418. //------------------------------------------------------------------------------
  1419. // Parse an optional network specific facilities field
  1420. //
  1421. // Parameters:
  1422. // BufferPtr Pointer to a descriptor of the buffer
  1423. // containing the length and a pointer
  1424. // to the raw bytes of the input stream.
  1425. // FieldStruct Pointer to space for parsed network facitlities
  1426. // information.
  1427. //------------------------------------------------------------------------------
  1428. static HRESULT
  1429. ParseNetworkSpec(
  1430. PBUFFERDESCR BufferDescriptor,
  1431. PNETWORKIE FieldStruct)
  1432. {
  1433. BYTE Ident;
  1434. memset(FieldStruct, 0, sizeof(NETWORKIE));
  1435. FieldStruct->Present = FALSE;
  1436. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_NETWORKSPEC)
  1437. {
  1438. HRESULT ParseResult;
  1439. ParseResult = ParseVariableOctet(BufferDescriptor,
  1440. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1441. if (ParseResult != CS_OK)
  1442. {
  1443. return ParseResult;
  1444. }
  1445. if (FieldStruct->Length > 0)
  1446. {
  1447. FieldStruct->Present = TRUE;
  1448. }
  1449. }
  1450. return CS_OK;
  1451. }
  1452. //------------------------------------------------------------------------------
  1453. // Parse an optional notification indicator field
  1454. //
  1455. // Parameters:
  1456. // BufferPtr Pointer to a descriptor of the buffer
  1457. // containing the length and a pointer
  1458. // to the raw bytes of the input stream.
  1459. // FieldStruct Pointer to space for parse notification indicator
  1460. // information.
  1461. //------------------------------------------------------------------------------
  1462. static HRESULT
  1463. ParseNotificationIndicator(
  1464. PBUFFERDESCR BufferDescriptor,
  1465. PNOTIFICATIONINDIE FieldStruct)
  1466. {
  1467. BYTE Ident;
  1468. memset(FieldStruct, 0, sizeof(NOTIFICATIONINDIE));
  1469. FieldStruct->Present = FALSE;
  1470. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_NOTIFICATION)
  1471. {
  1472. HRESULT ParseResult;
  1473. ParseResult = ParseVariableOctet(BufferDescriptor,
  1474. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1475. if (ParseResult != CS_OK)
  1476. {
  1477. return ParseResult;
  1478. }
  1479. if (FieldStruct->Length > 0)
  1480. {
  1481. FieldStruct->Present = TRUE;
  1482. }
  1483. }
  1484. return CS_OK;
  1485. }
  1486. //------------------------------------------------------------------------------
  1487. // Parse an optional display field
  1488. //
  1489. // Parameters:
  1490. // BufferPtr Pointer to a descriptor of the buffer
  1491. // containing the length and a pointer
  1492. // to the raw bytes of the input stream.
  1493. // FieldStruct Pointer to space for parsed display
  1494. // information.
  1495. //------------------------------------------------------------------------------
  1496. static HRESULT
  1497. ParseDisplay(
  1498. PBUFFERDESCR BufferDescriptor,
  1499. PDISPLAYIE FieldStruct)
  1500. {
  1501. BYTE Ident;
  1502. memset(FieldStruct, 0, sizeof(DISPLAYIE));
  1503. FieldStruct->Present = FALSE;
  1504. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_DISPLAY)
  1505. {
  1506. HRESULT ParseResult;
  1507. ParseResult = ParseVariableOctet(BufferDescriptor,
  1508. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1509. if (ParseResult != CS_OK)
  1510. {
  1511. return ParseResult;
  1512. }
  1513. if (FieldStruct->Length > 0)
  1514. {
  1515. FieldStruct->Present = TRUE;
  1516. }
  1517. }
  1518. return CS_OK;
  1519. }
  1520. //------------------------------------------------------------------------------
  1521. // Parse an optional date/time field
  1522. //
  1523. // Parameters:
  1524. // BufferPtr Pointer to a descriptor of the buffer
  1525. // containing the length and a pointer
  1526. // to the raw bytes of the input stream.
  1527. // FieldStruct Pointer to space for parsed date/time
  1528. // information.
  1529. //------------------------------------------------------------------------------
  1530. static HRESULT
  1531. ParseDate(
  1532. PBUFFERDESCR BufferDescriptor,
  1533. PDATEIE FieldStruct)
  1534. {
  1535. BYTE Ident;
  1536. memset(FieldStruct, 0, sizeof(DATEIE));
  1537. FieldStruct->Present = FALSE;
  1538. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_DATE)
  1539. {
  1540. HRESULT ParseResult;
  1541. ParseResult = ParseVariableOctet(BufferDescriptor,
  1542. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1543. if (ParseResult != CS_OK)
  1544. {
  1545. return ParseResult;
  1546. }
  1547. if (FieldStruct->Length > 0)
  1548. {
  1549. FieldStruct->Present = TRUE;
  1550. }
  1551. }
  1552. return CS_OK;
  1553. }
  1554. //------------------------------------------------------------------------------
  1555. // Parse an optional keypad field
  1556. //
  1557. // Parameters:
  1558. // BufferPtr Pointer to a descriptor of the buffer
  1559. // containing the length and a pointer
  1560. // to the raw bytes of the input stream.
  1561. // FieldStruct Pointer to space for parsed keypad
  1562. // information.
  1563. //------------------------------------------------------------------------------
  1564. static HRESULT
  1565. ParseKeypad(
  1566. PBUFFERDESCR BufferDescriptor,
  1567. PKEYPADIE FieldStruct)
  1568. {
  1569. BYTE Ident;
  1570. memset(FieldStruct, 0, sizeof(KEYPADIE));
  1571. FieldStruct->Present = FALSE;
  1572. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_KEYPAD)
  1573. {
  1574. HRESULT ParseResult;
  1575. ParseResult = ParseVariableOctet(BufferDescriptor,
  1576. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1577. if (ParseResult != CS_OK)
  1578. {
  1579. return ParseResult;
  1580. }
  1581. if (FieldStruct->Length > 0)
  1582. {
  1583. FieldStruct->Present = TRUE;
  1584. }
  1585. }
  1586. return CS_OK;
  1587. }
  1588. //------------------------------------------------------------------------------
  1589. // Parse an optional signal field
  1590. //
  1591. // Parameters:
  1592. // BufferPtr Pointer to a descriptor of the buffer
  1593. // containing the length and a pointer
  1594. // to the raw bytes of the input stream.
  1595. // FieldStruct Pointer to space for parsed signal
  1596. // information.
  1597. //------------------------------------------------------------------------------
  1598. static HRESULT
  1599. ParseSignal(
  1600. PBUFFERDESCR BufferDescriptor,
  1601. PSIGNALIE FieldStruct)
  1602. {
  1603. BYTE Ident;
  1604. memset(FieldStruct, 0, sizeof(SIGNALIE));
  1605. FieldStruct->Present = FALSE;
  1606. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_SIGNAL)
  1607. {
  1608. HRESULT ParseResult;
  1609. ParseResult = ParseVariableOctet(BufferDescriptor,
  1610. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1611. if (ParseResult != CS_OK)
  1612. {
  1613. return ParseResult;
  1614. }
  1615. if (FieldStruct->Length > 0)
  1616. {
  1617. FieldStruct->Present = TRUE;
  1618. }
  1619. }
  1620. return CS_OK;
  1621. }
  1622. //------------------------------------------------------------------------------
  1623. // Parse an optional information rate field
  1624. //
  1625. // Parameters:
  1626. // BufferPtr Pointer to a descriptor of the buffer
  1627. // containing the length and a pointer
  1628. // to the raw bytes of the input stream.
  1629. // FieldStruct Pointer to space for parsed information rate
  1630. // information.
  1631. //------------------------------------------------------------------------------
  1632. static HRESULT
  1633. ParseInformationRate(
  1634. PBUFFERDESCR BufferDescriptor,
  1635. PINFORATEIE FieldStruct)
  1636. {
  1637. BYTE Ident;
  1638. memset(FieldStruct, 0, sizeof(INFORATEIE));
  1639. FieldStruct->Present = FALSE;
  1640. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_INFORMATIONRATE)
  1641. {
  1642. HRESULT ParseResult;
  1643. ParseResult = ParseVariableOctet(BufferDescriptor,
  1644. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1645. if (ParseResult != CS_OK)
  1646. {
  1647. return ParseResult;
  1648. }
  1649. if (FieldStruct->Length > 0)
  1650. {
  1651. FieldStruct->Present = TRUE;
  1652. }
  1653. }
  1654. return CS_OK;
  1655. }
  1656. //------------------------------------------------------------------------------
  1657. // Parse an optional end to end transit delay field
  1658. //
  1659. // Parameters:
  1660. // BufferPtr Pointer to a descriptor of the buffer
  1661. // containing the length and a pointer
  1662. // to the raw bytes of the input stream.
  1663. // FieldStruct Pointer to space for parsed end to end
  1664. // information.
  1665. //------------------------------------------------------------------------------
  1666. static HRESULT
  1667. ParseEndToEndDelay(
  1668. PBUFFERDESCR BufferDescriptor,
  1669. PENDTOENDDELAYIE FieldStruct)
  1670. {
  1671. BYTE Ident;
  1672. memset(FieldStruct, 0, sizeof(ENDTOENDDELAYIE));
  1673. FieldStruct->Present = FALSE;
  1674. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_ENDTOENDDELAY)
  1675. {
  1676. HRESULT ParseResult;
  1677. ParseResult = ParseVariableOctet(BufferDescriptor,
  1678. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1679. if (ParseResult != CS_OK)
  1680. {
  1681. return ParseResult;
  1682. }
  1683. if (FieldStruct->Length > 0)
  1684. {
  1685. FieldStruct->Present = TRUE;
  1686. }
  1687. }
  1688. return CS_OK;
  1689. }
  1690. //------------------------------------------------------------------------------
  1691. // Parse an optional transit delay field
  1692. //
  1693. // Parameters:
  1694. // BufferPtr Pointer to a descriptor of the buffer
  1695. // containing the length and a pointer
  1696. // to the raw bytes of the input stream.
  1697. // FieldStruct Pointer to space for parsed transit delay
  1698. // information.
  1699. //------------------------------------------------------------------------------
  1700. static HRESULT
  1701. ParseTransitDelay(
  1702. PBUFFERDESCR BufferDescriptor,
  1703. PTRANSITDELAYIE FieldStruct)
  1704. {
  1705. BYTE Ident;
  1706. memset(FieldStruct, 0, sizeof(TRANSITDELAYIE));
  1707. FieldStruct->Present = FALSE;
  1708. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_TRANSITDELAY)
  1709. {
  1710. HRESULT ParseResult;
  1711. ParseResult = ParseVariableOctet(BufferDescriptor,
  1712. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1713. if (ParseResult != CS_OK)
  1714. {
  1715. return ParseResult;
  1716. }
  1717. if (FieldStruct->Length > 0)
  1718. {
  1719. FieldStruct->Present = TRUE;
  1720. }
  1721. }
  1722. return CS_OK;
  1723. }
  1724. //------------------------------------------------------------------------------
  1725. // Parse an optional packet layer binary params field
  1726. //
  1727. // Parameters:
  1728. // BufferPtr Pointer to a descriptor of the buffer
  1729. // containing the length and a pointer
  1730. // to the raw bytes of the input stream.
  1731. // FieldStruct Pointer to space for parsed
  1732. // information.
  1733. //------------------------------------------------------------------------------
  1734. static HRESULT
  1735. ParsePacketLayerParams(
  1736. PBUFFERDESCR BufferDescriptor,
  1737. PPLBINARYPARAMSIE FieldStruct)
  1738. {
  1739. BYTE Ident;
  1740. memset(FieldStruct, 0, sizeof(PLBINARYPARAMSIE));
  1741. FieldStruct->Present = FALSE;
  1742. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_PLBINARYPARAMS)
  1743. {
  1744. HRESULT ParseResult;
  1745. ParseResult = ParseVariableOctet(BufferDescriptor,
  1746. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1747. if (ParseResult != CS_OK)
  1748. {
  1749. return ParseResult;
  1750. }
  1751. if (FieldStruct->Length > 0)
  1752. {
  1753. FieldStruct->Present = TRUE;
  1754. }
  1755. }
  1756. return CS_OK;
  1757. }
  1758. //------------------------------------------------------------------------------
  1759. // Parse an optional packet layer window size field
  1760. //
  1761. // Parameters:
  1762. // BufferPtr Pointer to a descriptor of the buffer
  1763. // containing the length and a pointer
  1764. // to the raw bytes of the input stream.
  1765. // FieldStruct Pointer to space for parsed
  1766. // information.
  1767. //------------------------------------------------------------------------------
  1768. static HRESULT
  1769. ParsePacketLayerWindowSize(
  1770. PBUFFERDESCR BufferDescriptor,
  1771. PPLWINDOWSIZEIE FieldStruct)
  1772. {
  1773. BYTE Ident;
  1774. memset(FieldStruct, 0, sizeof(PLWINDOWSIZEIE));
  1775. FieldStruct->Present = FALSE;
  1776. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_PLWINDOWSIZE)
  1777. {
  1778. HRESULT ParseResult;
  1779. ParseResult = ParseVariableOctet(BufferDescriptor,
  1780. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1781. if (ParseResult != CS_OK)
  1782. {
  1783. return ParseResult;
  1784. }
  1785. if (FieldStruct->Length > 0)
  1786. {
  1787. FieldStruct->Present = TRUE;
  1788. }
  1789. }
  1790. return CS_OK;
  1791. }
  1792. //------------------------------------------------------------------------------
  1793. // Parse an optional packet size field
  1794. //
  1795. // Parameters:
  1796. // BufferPtr Pointer to a descriptor of the buffer
  1797. // containing the length and a pointer
  1798. // to the raw bytes of the input stream.
  1799. // FieldStruct Pointer to space for parse packet size
  1800. // information.
  1801. //------------------------------------------------------------------------------
  1802. static HRESULT
  1803. ParsePacketSize(
  1804. PBUFFERDESCR BufferDescriptor,
  1805. PPACKETSIZEIE FieldStruct)
  1806. {
  1807. BYTE Ident;
  1808. memset(FieldStruct, 0, sizeof(PACKETSIZEIE));
  1809. FieldStruct->Present = FALSE;
  1810. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_PACKETSIZE)
  1811. {
  1812. HRESULT ParseResult;
  1813. ParseResult = ParseVariableOctet(BufferDescriptor,
  1814. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1815. if (ParseResult != CS_OK)
  1816. {
  1817. return ParseResult;
  1818. }
  1819. if (FieldStruct->Length > 0)
  1820. {
  1821. FieldStruct->Present = TRUE;
  1822. }
  1823. }
  1824. return CS_OK;
  1825. }
  1826. //------------------------------------------------------------------------------
  1827. // Parse an optional closed user group field
  1828. //
  1829. // Parameters:
  1830. // BufferPtr Pointer to a descriptor of the buffer
  1831. // containing the length and a pointer
  1832. // to the raw bytes of the input stream.
  1833. // FieldStruct Pointer to space for parsed
  1834. // information.
  1835. //------------------------------------------------------------------------------
  1836. static HRESULT
  1837. ParseClosedUserGroup(
  1838. PBUFFERDESCR BufferDescriptor,
  1839. PCLOSEDUGIE FieldStruct)
  1840. {
  1841. BYTE Ident;
  1842. memset(FieldStruct, 0, sizeof(CLOSEDUGIE));
  1843. FieldStruct->Present = FALSE;
  1844. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_CLOSEDUG)
  1845. {
  1846. HRESULT ParseResult;
  1847. ParseResult = ParseVariableOctet(BufferDescriptor,
  1848. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1849. if (ParseResult != CS_OK)
  1850. {
  1851. return ParseResult;
  1852. }
  1853. if (FieldStruct->Length > 0)
  1854. {
  1855. FieldStruct->Present = TRUE;
  1856. }
  1857. }
  1858. return CS_OK;
  1859. }
  1860. //------------------------------------------------------------------------------
  1861. // Parse an optional reverse charge field
  1862. //
  1863. // Parameters:
  1864. // BufferPtr Pointer to a descriptor of the buffer
  1865. // containing the length and a pointer
  1866. // to the raw bytes of the input stream.
  1867. // FieldStruct Pointer to space for parsed
  1868. // information.
  1869. //------------------------------------------------------------------------------
  1870. static HRESULT
  1871. ParseReverseCharge(
  1872. PBUFFERDESCR BufferDescriptor,
  1873. PREVERSECHARGEIE FieldStruct)
  1874. {
  1875. BYTE Ident;
  1876. memset(FieldStruct, 0, sizeof(REVERSECHARGEIE));
  1877. FieldStruct->Present = FALSE;
  1878. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_REVCHARGE)
  1879. {
  1880. HRESULT ParseResult;
  1881. ParseResult = ParseVariableOctet(BufferDescriptor,
  1882. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1883. if (ParseResult != CS_OK)
  1884. {
  1885. return ParseResult;
  1886. }
  1887. if (FieldStruct->Length > 0)
  1888. {
  1889. FieldStruct->Present = TRUE;
  1890. }
  1891. }
  1892. return CS_OK;
  1893. }
  1894. //------------------------------------------------------------------------------
  1895. // Parse an optional calling party number field
  1896. //
  1897. // Parameters:
  1898. // BufferPtr Pointer to a descriptor of the buffer
  1899. // containing the length and a pointer
  1900. // to the raw bytes of the input stream.
  1901. // FieldStruct Pointer to space for parsed
  1902. // information.
  1903. //------------------------------------------------------------------------------
  1904. static HRESULT
  1905. ParseCallingPartyNumber(
  1906. PBUFFERDESCR BufferDescriptor,
  1907. PCALLINGNUMBERIE FieldStruct)
  1908. {
  1909. BYTE Ident;
  1910. memset(FieldStruct, 0, sizeof(CALLINGNUMBERIE));
  1911. FieldStruct->Present = FALSE;
  1912. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_CALLINGNUMBER)
  1913. {
  1914. HRESULT ParseResult;
  1915. ParseResult = ParseVariableOctet(BufferDescriptor,
  1916. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1917. if (ParseResult != CS_OK)
  1918. {
  1919. return ParseResult;
  1920. }
  1921. if (FieldStruct->Length > 0)
  1922. {
  1923. FieldStruct->Present = TRUE;
  1924. }
  1925. }
  1926. return CS_OK;
  1927. }
  1928. //------------------------------------------------------------------------------
  1929. // Parse an optional calling party subaddress field
  1930. //
  1931. // Parameters:
  1932. // BufferPtr Pointer to a descriptor of the buffer
  1933. // containing the length and a pointer
  1934. // to the raw bytes of the input stream.
  1935. // FieldStruct Pointer to space for parsed
  1936. // information.
  1937. //------------------------------------------------------------------------------
  1938. static HRESULT
  1939. ParseCallingPartySubaddress(
  1940. PBUFFERDESCR BufferDescriptor,
  1941. PCALLINGSUBADDRIE FieldStruct)
  1942. {
  1943. BYTE Ident;
  1944. memset(FieldStruct, 0, sizeof(CALLINGSUBADDRIE));
  1945. FieldStruct->Present = FALSE;
  1946. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_CALLINGSUBADDR)
  1947. {
  1948. HRESULT ParseResult;
  1949. ParseResult = ParseVariableOctet(BufferDescriptor,
  1950. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  1951. if (ParseResult != CS_OK)
  1952. {
  1953. return ParseResult;
  1954. }
  1955. if (FieldStruct->Length > 0)
  1956. {
  1957. FieldStruct->Present = TRUE;
  1958. }
  1959. }
  1960. return CS_OK;
  1961. }
  1962. //------------------------------------------------------------------------------
  1963. // Parse an optional called party number field
  1964. //
  1965. // Parameters:
  1966. // BufferPtr Pointer to a descriptor of the buffer
  1967. // containing the length and a pointer
  1968. // to the raw bytes of the input stream.
  1969. // FieldStruct Pointer to space for parsed
  1970. // information.
  1971. //------------------------------------------------------------------------------
  1972. static HRESULT
  1973. ParseCalledPartyNumber(
  1974. PBUFFERDESCR BufferDescriptor,
  1975. PCALLEDNUMBERIE FieldStruct)
  1976. {
  1977. memset(FieldStruct, 0, sizeof(PCALLEDNUMBERIE));
  1978. FieldStruct->Present = FALSE;
  1979. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_CALLEDNUMBER)
  1980. {
  1981. register int i;
  1982. BYTE RemainingLength = 0;
  1983. BYTE *Tempptr;
  1984. // Need 3 bytes for the ident (1), length (1),
  1985. // and type + plan (1) fields.
  1986. if (BufferDescriptor->Length < 3)
  1987. {
  1988. return CS_ENDOFINPUT;
  1989. }
  1990. // skip the ie identifier...
  1991. BufferDescriptor->BufferPtr++;
  1992. BufferDescriptor->Length--;
  1993. // Get the length of the contents following the length field.
  1994. RemainingLength = *BufferDescriptor->BufferPtr;
  1995. BufferDescriptor->BufferPtr++;
  1996. BufferDescriptor->Length--;
  1997. // make sure we have at least that much length left...
  1998. if (BufferDescriptor->Length < RemainingLength)
  1999. {
  2000. return CS_ENDOFINPUT;
  2001. }
  2002. // Get the type + plan fields.
  2003. if (*(BufferDescriptor->BufferPtr) & 0x80)
  2004. {
  2005. FieldStruct->NumberType =
  2006. (BYTE)(*BufferDescriptor->BufferPtr & 0xf0);
  2007. FieldStruct->NumberingPlan =
  2008. (BYTE)(*BufferDescriptor->BufferPtr & 0x0f);
  2009. BufferDescriptor->BufferPtr++;
  2010. BufferDescriptor->Length--;
  2011. RemainingLength--;
  2012. }
  2013. FieldStruct->PartyNumberLength = RemainingLength;
  2014. FieldStruct->Present = TRUE;
  2015. Tempptr = FieldStruct->PartyNumbers;
  2016. for (i = 0; i < RemainingLength; i++)
  2017. {
  2018. // Copy the bytes out of the rest of the buffer
  2019. *Tempptr = *(BufferDescriptor->BufferPtr);
  2020. BufferDescriptor->BufferPtr++;
  2021. BufferDescriptor->Length--;
  2022. Tempptr++;
  2023. }
  2024. *Tempptr = (BYTE)0;
  2025. }
  2026. return CS_OK;
  2027. }
  2028. //------------------------------------------------------------------------------
  2029. // Parse an optional called party subaddress field
  2030. //
  2031. // Parameters:
  2032. // BufferPtr Pointer to a descriptor of the buffer
  2033. // containing the length and a pointer
  2034. // to the raw bytes of the input stream.
  2035. // FieldStruct Pointer to space for parsed
  2036. // information.
  2037. //------------------------------------------------------------------------------
  2038. static HRESULT
  2039. ParseCalledPartySubaddress(
  2040. PBUFFERDESCR BufferDescriptor,
  2041. PCALLEDSUBADDRIE FieldStruct)
  2042. {
  2043. BYTE Ident;
  2044. memset(FieldStruct, 0, sizeof(CALLEDSUBADDRIE));
  2045. FieldStruct->Present = FALSE;
  2046. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_CALLEDSUBADDR)
  2047. {
  2048. HRESULT ParseResult;
  2049. ParseResult = ParseVariableOctet(BufferDescriptor,
  2050. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  2051. if (ParseResult != CS_OK)
  2052. {
  2053. return ParseResult;
  2054. }
  2055. if (FieldStruct->Length > 0)
  2056. {
  2057. FieldStruct->Present = TRUE;
  2058. }
  2059. }
  2060. return CS_OK;
  2061. }
  2062. //------------------------------------------------------------------------------
  2063. // Parse an optional redirecting number field
  2064. //
  2065. // Parameters:
  2066. // BufferPtr Pointer to a descriptor of the buffer
  2067. // containing the length and a pointer
  2068. // to the raw bytes of the input stream.
  2069. // FieldStruct Pointer to space for parsed
  2070. // information.
  2071. //------------------------------------------------------------------------------
  2072. static HRESULT
  2073. ParseRedirectingNumber(
  2074. PBUFFERDESCR BufferDescriptor,
  2075. PREDIRECTINGIE FieldStruct)
  2076. {
  2077. BYTE Ident;
  2078. memset(FieldStruct, 0, sizeof(REDIRECTINGIE));
  2079. FieldStruct->Present = FALSE;
  2080. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_REDIRECTING)
  2081. {
  2082. HRESULT ParseResult;
  2083. ParseResult = ParseVariableOctet(BufferDescriptor,
  2084. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  2085. if (ParseResult != CS_OK)
  2086. {
  2087. return ParseResult;
  2088. }
  2089. if (FieldStruct->Length > 0)
  2090. {
  2091. FieldStruct->Present = TRUE;
  2092. }
  2093. }
  2094. return CS_OK;
  2095. }
  2096. //------------------------------------------------------------------------------
  2097. // Parse an optional transit network selection field
  2098. //
  2099. // Parameters:
  2100. // BufferPtr Pointer to a descriptor of the buffer
  2101. // containing the length and a pointer
  2102. // to the raw bytes of the input stream.
  2103. // FieldStruct Pointer to space for parsed
  2104. // information.
  2105. //------------------------------------------------------------------------------
  2106. static HRESULT
  2107. ParseTransitNetwork(
  2108. PBUFFERDESCR BufferDescriptor,
  2109. PTRANSITNETIE FieldStruct)
  2110. {
  2111. BYTE Ident;
  2112. memset(FieldStruct, 0, sizeof(TRANSITNETIE));
  2113. FieldStruct->Present = FALSE;
  2114. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_TRANSITNET)
  2115. {
  2116. HRESULT ParseResult;
  2117. ParseResult = ParseVariableOctet(BufferDescriptor,
  2118. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  2119. if (ParseResult != CS_OK)
  2120. {
  2121. return ParseResult;
  2122. }
  2123. if (FieldStruct->Length > 0)
  2124. {
  2125. FieldStruct->Present = TRUE;
  2126. }
  2127. }
  2128. return CS_OK;
  2129. }
  2130. //------------------------------------------------------------------------------
  2131. // Parse an optional restart indicator field
  2132. //
  2133. // Parameters:
  2134. // BufferPtr Pointer to a descriptor of the buffer
  2135. // containing the length and a pointer
  2136. // to the raw bytes of the input stream.
  2137. // FieldStruct Pointer to space for parsed
  2138. // information.
  2139. //------------------------------------------------------------------------------
  2140. static HRESULT
  2141. ParseRestart(
  2142. PBUFFERDESCR BufferDescriptor,
  2143. PRESTARTIE FieldStruct)
  2144. {
  2145. BYTE Ident;
  2146. memset(FieldStruct, 0, sizeof(PRESTARTIE));
  2147. FieldStruct->Present = FALSE;
  2148. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_RESTART)
  2149. {
  2150. HRESULT ParseResult;
  2151. ParseResult = ParseVariableOctet(BufferDescriptor,
  2152. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  2153. if (ParseResult != CS_OK)
  2154. {
  2155. return ParseResult;
  2156. }
  2157. if (FieldStruct->Length > 0)
  2158. {
  2159. FieldStruct->Present = TRUE;
  2160. }
  2161. }
  2162. return CS_OK;
  2163. }
  2164. //------------------------------------------------------------------------------
  2165. // Parse an optional lower layer compatibility field
  2166. //
  2167. // Parameters:
  2168. // BufferPtr Pointer to a descriptor of the buffer
  2169. // containing the length and a pointer
  2170. // to the raw bytes of the input stream.
  2171. // FieldStruct Pointer to space for parsed
  2172. // information.
  2173. //------------------------------------------------------------------------------
  2174. static HRESULT
  2175. ParseLowLayerCompatibility(
  2176. PBUFFERDESCR BufferDescriptor,
  2177. PLLCOMPATIBILITYIE FieldStruct)
  2178. {
  2179. BYTE Ident;
  2180. memset(FieldStruct, 0, sizeof(LLCOMPATIBILITYIE));
  2181. FieldStruct->Present = FALSE;
  2182. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_LLCOMPATIBILITY)
  2183. {
  2184. HRESULT ParseResult;
  2185. ParseResult = ParseVariableOctet(BufferDescriptor,
  2186. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  2187. if (ParseResult != CS_OK)
  2188. {
  2189. return ParseResult;
  2190. }
  2191. if (FieldStruct->Length > 0)
  2192. {
  2193. FieldStruct->Present = TRUE;
  2194. }
  2195. }
  2196. return CS_OK;
  2197. }
  2198. //------------------------------------------------------------------------------
  2199. // Parse an optional higher layer compatibility field
  2200. //
  2201. // Parameters:
  2202. // BufferPtr Pointer to a descriptor of the buffer
  2203. // containing the length and a pointer
  2204. // to the raw bytes of the input stream.
  2205. // FieldStruct Pointer to space for parsed
  2206. // information.
  2207. //------------------------------------------------------------------------------
  2208. static HRESULT
  2209. ParseHighLayerCompatibility(
  2210. PBUFFERDESCR BufferDescriptor,
  2211. PHLCOMPATIBILITYIE FieldStruct)
  2212. {
  2213. BYTE Ident;
  2214. memset(FieldStruct, 0, sizeof(HLCOMPATIBILITYIE));
  2215. FieldStruct->Present = FALSE;
  2216. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_HLCOMPATIBILITY)
  2217. {
  2218. HRESULT ParseResult;
  2219. ParseResult = ParseVariableOctet(BufferDescriptor,
  2220. &Ident, &FieldStruct->Length, &FieldStruct->Contents[0]);
  2221. if (ParseResult != CS_OK)
  2222. {
  2223. return ParseResult;
  2224. }
  2225. if (FieldStruct->Length > 0)
  2226. {
  2227. FieldStruct->Present = TRUE;
  2228. }
  2229. }
  2230. return CS_OK;
  2231. }
  2232. //------------------------------------------------------------------------------
  2233. // Parse an optional user to user field
  2234. //
  2235. // Parameters:
  2236. // BufferPtr Pointer to a descriptor of the buffer
  2237. // containing the length and a pointer
  2238. // to the raw bytes of the input stream.
  2239. // FieldStruct Pointer to space for parsed
  2240. // information.
  2241. //------------------------------------------------------------------------------
  2242. static HRESULT
  2243. ParseUserToUser(
  2244. PBUFFERDESCR BufferDescriptor,
  2245. PUSERUSERIE FieldStruct)
  2246. {
  2247. BYTE Ident;
  2248. memset(FieldStruct, 0, sizeof(USERUSERIE));
  2249. FieldStruct->Present = FALSE;
  2250. if (GetNextIdent(BufferDescriptor->BufferPtr) == IDENT_USERUSER)
  2251. {
  2252. HRESULT ParseResult;
  2253. ParseResult = ParseVariableASN(BufferDescriptor,
  2254. &Ident, &(FieldStruct->ProtocolDiscriminator),
  2255. &(FieldStruct->UserInformationLength),
  2256. &(FieldStruct->UserInformation[0]),
  2257. sizeof(FieldStruct->UserInformation));
  2258. if (ParseResult != CS_OK)
  2259. {
  2260. return ParseResult;
  2261. }
  2262. if (FieldStruct->UserInformationLength > 0)
  2263. {
  2264. FieldStruct->Present = TRUE;
  2265. }
  2266. }
  2267. return CS_OK;
  2268. }
  2269. //------------------------------------------------------------------------------
  2270. // Parse the next Q931 field in the given message
  2271. //
  2272. // Parameters:
  2273. // BufferDescriptor Pointer to buffer descriptor of a
  2274. // the network packet of the 931 message
  2275. // Message Pointer to space for parsed information.
  2276. //------------------------------------------------------------------------------
  2277. static HRESULT
  2278. ParseQ931Field(
  2279. PBUFFERDESCR BufferDescriptor,
  2280. PQ931MESSAGE Message)
  2281. {
  2282. FIELDIDENTTYPE Ident;
  2283. Ident = GetNextIdent(BufferDescriptor->BufferPtr);
  2284. switch (Ident)
  2285. {
  2286. case IDENT_SHIFT:
  2287. return ParseShift(BufferDescriptor,
  2288. &Message->Shift);
  2289. case IDENT_FACILITY:
  2290. return ParseFacility(BufferDescriptor,
  2291. &Message->Facility);
  2292. case IDENT_MORE:
  2293. return ParseMoreData(BufferDescriptor,
  2294. &Message->MoreData);
  2295. case IDENT_SENDINGCOMPLETE:
  2296. return ParseSendingComplete(BufferDescriptor,
  2297. &Message->SendingComplete);
  2298. case IDENT_CONGESTION:
  2299. return ParseCongestionLevel(BufferDescriptor,
  2300. &Message->CongestionLevel);
  2301. case IDENT_REPEAT:
  2302. return ParseRepeatIndicator(BufferDescriptor,
  2303. &Message->RepeatIndicator);
  2304. case IDENT_SEGMENTED:
  2305. return ParseSegmented(BufferDescriptor,
  2306. &Message->SegmentedMessage);
  2307. case IDENT_BEARERCAP:
  2308. return ParseBearerCapability(BufferDescriptor,
  2309. &Message->BearerCapability);
  2310. case IDENT_CAUSE:
  2311. return ParseCause(BufferDescriptor,
  2312. &Message->Cause);
  2313. case IDENT_CALLIDENT:
  2314. return ParseCallIdentity(BufferDescriptor,
  2315. &Message->CallIdentity);
  2316. case IDENT_CALLSTATE:
  2317. return ParseCallState(BufferDescriptor,
  2318. &Message->CallState);
  2319. case IDENT_CHANNELIDENT:
  2320. return ParseChannelIdentification(BufferDescriptor,
  2321. &Message->ChannelIdentification);
  2322. case IDENT_PROGRESS:
  2323. case IDENT_PROGRESS2:
  2324. return ParseProgress(BufferDescriptor,
  2325. &Message->ProgressIndicator);
  2326. case IDENT_NETWORKSPEC:
  2327. return ParseNetworkSpec(BufferDescriptor,
  2328. &Message->NetworkFacilities);
  2329. case IDENT_NOTIFICATION:
  2330. return ParseNotificationIndicator(BufferDescriptor,
  2331. &Message->NotificationIndicator);
  2332. case IDENT_DISPLAY:
  2333. return ParseDisplay(BufferDescriptor,
  2334. &Message->Display);
  2335. case IDENT_DATE:
  2336. return ParseDate(BufferDescriptor,
  2337. &Message->Date);
  2338. case IDENT_KEYPAD:
  2339. return ParseKeypad(BufferDescriptor,
  2340. &Message->Keypad);
  2341. case IDENT_SIGNAL:
  2342. return ParseSignal(BufferDescriptor,
  2343. &Message->Signal);
  2344. case IDENT_INFORMATIONRATE:
  2345. return ParseInformationRate(BufferDescriptor,
  2346. &Message->InformationRate);
  2347. case IDENT_ENDTOENDDELAY:
  2348. return ParseEndToEndDelay(BufferDescriptor,
  2349. &Message->EndToEndTransitDelay);
  2350. case IDENT_TRANSITDELAY:
  2351. return ParseTransitDelay(BufferDescriptor,
  2352. &Message->TransitDelay);
  2353. case IDENT_PLBINARYPARAMS:
  2354. return ParsePacketLayerParams(BufferDescriptor,
  2355. &Message->PacketLayerBinaryParams);
  2356. case IDENT_PLWINDOWSIZE:
  2357. return ParsePacketLayerWindowSize(BufferDescriptor,
  2358. &Message->PacketLayerWindowSize);
  2359. case IDENT_PACKETSIZE:
  2360. return ParsePacketSize(BufferDescriptor,
  2361. &Message->PacketSize);
  2362. case IDENT_CLOSEDUG:
  2363. return ParseClosedUserGroup(BufferDescriptor,
  2364. &Message->ClosedUserGroup);
  2365. case IDENT_REVCHARGE:
  2366. return ParseReverseCharge(BufferDescriptor,
  2367. &Message->ReverseChargeIndication);
  2368. case IDENT_CALLINGNUMBER:
  2369. return ParseCallingPartyNumber(BufferDescriptor,
  2370. &Message->CallingPartyNumber);
  2371. case IDENT_CALLINGSUBADDR:
  2372. return ParseCallingPartySubaddress(BufferDescriptor,
  2373. &Message->CallingPartySubaddress);
  2374. case IDENT_CALLEDNUMBER:
  2375. return ParseCalledPartyNumber(BufferDescriptor,
  2376. &Message->CalledPartyNumber);
  2377. case IDENT_CALLEDSUBADDR:
  2378. return ParseCalledPartySubaddress(BufferDescriptor,
  2379. &Message->CalledPartySubaddress);
  2380. case IDENT_REDIRECTING:
  2381. return ParseRedirectingNumber(BufferDescriptor,
  2382. &Message->RedirectingNumber);
  2383. case IDENT_TRANSITNET:
  2384. return ParseTransitNetwork(BufferDescriptor,
  2385. &Message->TransitNetworkSelection);
  2386. case IDENT_RESTART:
  2387. return ParseRestart(BufferDescriptor,
  2388. &Message->RestartIndicator);
  2389. case IDENT_LLCOMPATIBILITY:
  2390. return ParseLowLayerCompatibility(BufferDescriptor,
  2391. &Message->LowLayerCompatibility);
  2392. case IDENT_HLCOMPATIBILITY:
  2393. return ParseHighLayerCompatibility(BufferDescriptor,
  2394. &Message->HighLayerCompatibility);
  2395. case IDENT_USERUSER:
  2396. return ParseUserToUser(BufferDescriptor,
  2397. &Message->UserToUser);
  2398. default:
  2399. return CS_INVALID_FIELD;
  2400. }
  2401. }
  2402. //------------------------------------------------------------------------------
  2403. // Parse a generic Q931 message and place the fields of the buffer
  2404. // into the appropriate structure fields.
  2405. //
  2406. // Parameters:
  2407. // BufferDescriptor Pointer to buffer descriptor of an
  2408. // input packet containing the 931 message.
  2409. // Message Pointer to space for parsed output information.
  2410. //------------------------------------------------------------------------------
  2411. HRESULT
  2412. Q931ParseMessage(
  2413. BYTE *CodedBufferPtr,
  2414. DWORD CodedBufferLength,
  2415. PQ931MESSAGE Message)
  2416. {
  2417. HRESULT Result;
  2418. BUFFERDESCR BufferDescriptor;
  2419. BufferDescriptor.Length = CodedBufferLength;
  2420. BufferDescriptor.BufferPtr = CodedBufferPtr;
  2421. memset(Message, 0, sizeof(Q931MESSAGE));
  2422. if ((Result = ParseProtocolDiscriminator(&BufferDescriptor,
  2423. &Message->ProtocolDiscriminator)) != CS_OK)
  2424. {
  2425. return Result;
  2426. }
  2427. if ((Result = ParseCallReference(&BufferDescriptor,
  2428. &Message->CallReference)) != CS_OK)
  2429. {
  2430. return Result;
  2431. }
  2432. if ((Result = ParseMessageType(&BufferDescriptor,
  2433. &Message->MessageType)) != CS_OK)
  2434. {
  2435. return Result;
  2436. }
  2437. while (BufferDescriptor.Length)
  2438. {
  2439. Result = ParseQ931Field(&BufferDescriptor, Message);
  2440. if (Result != CS_OK)
  2441. {
  2442. return Result;
  2443. }
  2444. }
  2445. return CS_OK;
  2446. }
  2447. //==============================================================================
  2448. //==============================================================================
  2449. //==============================================================================
  2450. // BELOW HERE ARE THE OUTPUT ROUTINES...
  2451. //==============================================================================
  2452. //==============================================================================
  2453. //==============================================================================
  2454. //------------------------------------------------------------------------------
  2455. // Write the protocol discriminator. See Q931 section 4.2.
  2456. //------------------------------------------------------------------------------
  2457. static HRESULT
  2458. WriteProtocolDiscriminator(
  2459. PBUFFERDESCR BufferDescriptor)
  2460. {
  2461. BufferDescriptor->Length += sizeof(PDTYPE);
  2462. if (BufferDescriptor->BufferPtr)
  2463. {
  2464. *(PDTYPE *)BufferDescriptor->BufferPtr = Q931PDVALUE;
  2465. BufferDescriptor->BufferPtr += sizeof(PDTYPE);
  2466. }
  2467. return CS_OK;
  2468. }
  2469. //------------------------------------------------------------------------------
  2470. // Write a variable length Q931 call reference. See Q931 section 4.3.
  2471. //------------------------------------------------------------------------------
  2472. static HRESULT
  2473. WriteCallReference(
  2474. PBUFFERDESCR BufferDescriptor,
  2475. CRTYPE *CallReference)
  2476. {
  2477. register int i;
  2478. // space for the length byte
  2479. BufferDescriptor->Length++;
  2480. // the length byte
  2481. if (BufferDescriptor->BufferPtr != NULL)
  2482. {
  2483. *BufferDescriptor->BufferPtr = (BYTE)sizeof(CRTYPE);
  2484. BufferDescriptor->BufferPtr++;
  2485. }
  2486. for (i = 0; i < sizeof(CRTYPE); i++)
  2487. {
  2488. // Copy the value bytes to the buffer
  2489. BufferDescriptor->Length++;
  2490. if (BufferDescriptor->BufferPtr != NULL)
  2491. {
  2492. *BufferDescriptor->BufferPtr =
  2493. (BYTE)(((*CallReference) >> ((sizeof(CRTYPE) - 1 -i) * 8)) & 0xff);
  2494. BufferDescriptor->BufferPtr++;
  2495. }
  2496. }
  2497. return CS_OK;
  2498. }
  2499. //------------------------------------------------------------------------------
  2500. // Write a Q931 message type. See Q931 section 4.4.
  2501. //------------------------------------------------------------------------------
  2502. static HRESULT
  2503. WriteMessageType(
  2504. PBUFFERDESCR BufferDescriptor,
  2505. MESSAGEIDTYPE *MessageType)
  2506. {
  2507. register int i;
  2508. for (i = 0; i < sizeof(MessageSet) / sizeof(MESSAGEIDTYPE); i++)
  2509. {
  2510. if (MessageSet[i] == *MessageType)
  2511. {
  2512. break;
  2513. }
  2514. }
  2515. if (i >= sizeof(MessageSet) / sizeof(MESSAGEIDTYPE))
  2516. {
  2517. return CS_INVALID_MESSAGE_TYPE;
  2518. }
  2519. BufferDescriptor->Length += sizeof(MESSAGEIDTYPE);
  2520. if (BufferDescriptor->BufferPtr != NULL)
  2521. {
  2522. *(MESSAGEIDTYPE *)(BufferDescriptor->BufferPtr) =
  2523. (BYTE)(*MessageType & MESSAGETYPEMASK);
  2524. BufferDescriptor->BufferPtr += sizeof(MESSAGEIDTYPE);
  2525. }
  2526. return CS_OK;
  2527. }
  2528. //------------------------------------------------------------------------------
  2529. // Write a single octet encoded value, See Q931 section 4.5.1.
  2530. //------------------------------------------------------------------------------
  2531. static HRESULT
  2532. WriteSingleOctetType1(
  2533. PBUFFERDESCR BufferDescriptor,
  2534. BYTE Ident,
  2535. BYTE Value)
  2536. {
  2537. BufferDescriptor->Length++;
  2538. if (BufferDescriptor->BufferPtr)
  2539. {
  2540. *BufferDescriptor->BufferPtr =
  2541. (BYTE)(0x80 | Ident | (Value & TYPE1VALUEMASK));
  2542. BufferDescriptor->BufferPtr++;
  2543. }
  2544. return CS_OK;
  2545. }
  2546. //------------------------------------------------------------------------------
  2547. // Write a single octet encoded value, See Q931 section 4.5.1.
  2548. //------------------------------------------------------------------------------
  2549. static HRESULT
  2550. WriteSingleOctetType2(
  2551. PBUFFERDESCR BufferDescriptor,
  2552. BYTE Ident)
  2553. {
  2554. BufferDescriptor->Length++;
  2555. if (BufferDescriptor->BufferPtr)
  2556. {
  2557. *BufferDescriptor->BufferPtr = (BYTE)(0x80 | Ident);
  2558. BufferDescriptor->BufferPtr++;
  2559. }
  2560. return CS_OK;
  2561. }
  2562. //------------------------------------------------------------------------------
  2563. // Parse and return a variable length Q931 field see Q931 section 4.5.1.
  2564. //------------------------------------------------------------------------------
  2565. static HRESULT
  2566. WriteVariableOctet(
  2567. PBUFFERDESCR BufferDescriptor,
  2568. BYTE Ident,
  2569. BYTE Length,
  2570. BYTE *Contents)
  2571. {
  2572. register int i;
  2573. BYTE *Tempptr;
  2574. if (Contents == NULL)
  2575. {
  2576. Length = 0;
  2577. }
  2578. // space for the length and the identifier bytes
  2579. BufferDescriptor->Length += 2;
  2580. // the id byte, then the length byte
  2581. if (BufferDescriptor->BufferPtr != NULL)
  2582. {
  2583. // low 7 bits of the first byte are the identifier
  2584. *BufferDescriptor->BufferPtr = (BYTE)(Ident & 0x7f);
  2585. BufferDescriptor->BufferPtr++;
  2586. *BufferDescriptor->BufferPtr = Length;
  2587. BufferDescriptor->BufferPtr++;
  2588. }
  2589. Tempptr = Contents;
  2590. for (i = 0; i < Length; i++)
  2591. {
  2592. // Copy the value bytes to the buffer
  2593. BufferDescriptor->Length++;
  2594. if (BufferDescriptor->BufferPtr != NULL)
  2595. {
  2596. *BufferDescriptor->BufferPtr = *Tempptr;
  2597. BufferDescriptor->BufferPtr++;
  2598. Tempptr++;
  2599. }
  2600. }
  2601. return CS_OK;
  2602. }
  2603. //------------------------------------------------------------------------------
  2604. //Write out the Party number.
  2605. //------------------------------------------------------------------------------
  2606. static HRESULT
  2607. WritePartyNumber(
  2608. PBUFFERDESCR BufferDescriptor,
  2609. BYTE Ident,
  2610. BYTE NumberType,
  2611. BYTE NumberingPlan,
  2612. BYTE PartyNumberLength,
  2613. BYTE *PartyNumbers)
  2614. {
  2615. register int i;
  2616. BYTE *Tempptr;
  2617. if (PartyNumbers == NULL)
  2618. {
  2619. PartyNumberLength = 0;
  2620. }
  2621. // space for the ident (1), length (1), and type + plan (1) fields.
  2622. BufferDescriptor->Length += 3;
  2623. // write the fields out.
  2624. if (BufferDescriptor->BufferPtr != NULL)
  2625. {
  2626. // low 7 bits of byte 1 are the ie identifier
  2627. *BufferDescriptor->BufferPtr = (BYTE)(Ident & 0x7f);
  2628. BufferDescriptor->BufferPtr++;
  2629. // byte 2 is the ie contents length following the length field.
  2630. *BufferDescriptor->BufferPtr = (BYTE)(PartyNumberLength + 1);
  2631. BufferDescriptor->BufferPtr++;
  2632. // byte 3 is the type and plan field.
  2633. *BufferDescriptor->BufferPtr = (BYTE)(NumberType | NumberingPlan);
  2634. BufferDescriptor->BufferPtr++;
  2635. }
  2636. Tempptr = PartyNumbers;
  2637. for (i = 0; i < PartyNumberLength; i++)
  2638. {
  2639. // Copy the value bytes to the buffer
  2640. BufferDescriptor->Length++;
  2641. if (BufferDescriptor->BufferPtr != NULL)
  2642. {
  2643. *BufferDescriptor->BufferPtr = *Tempptr;
  2644. BufferDescriptor->BufferPtr++;
  2645. Tempptr++;
  2646. }
  2647. }
  2648. return CS_OK;
  2649. }
  2650. //------------------------------------------------------------------------------
  2651. // Parse and return a variable length Q931 field see Q931 section 4.5.1.
  2652. //------------------------------------------------------------------------------
  2653. static HRESULT
  2654. WriteVariableASN(
  2655. PBUFFERDESCR BufferDescriptor,
  2656. BYTE Ident,
  2657. WORD UserInformationLength,
  2658. BYTE *UserInformation)
  2659. {
  2660. register int i;
  2661. BYTE *Tempptr;
  2662. WORD ContentsLength = (WORD)(UserInformationLength + 1);
  2663. // There has to be at least 4 bytes for the IE identifier,
  2664. // the contents length, and the protocol discriminator (1 + 2 + 1).
  2665. BufferDescriptor->Length += 4;
  2666. if (BufferDescriptor->BufferPtr != NULL)
  2667. {
  2668. // low 7 bits of the first byte are the identifier
  2669. *BufferDescriptor->BufferPtr = (BYTE)(Ident & 0x7f);
  2670. BufferDescriptor->BufferPtr++;
  2671. // write the contents length bytes.
  2672. *BufferDescriptor->BufferPtr = (BYTE)(ContentsLength >> 8);
  2673. BufferDescriptor->BufferPtr++;
  2674. *BufferDescriptor->BufferPtr = (BYTE)ContentsLength;
  2675. BufferDescriptor->BufferPtr++;
  2676. // write the protocol discriminator byte.
  2677. *(BufferDescriptor->BufferPtr) = Q931_PROTOCOL_X209;
  2678. BufferDescriptor->BufferPtr++;
  2679. }
  2680. Tempptr = UserInformation;
  2681. for (i = 0; i < UserInformationLength; i++)
  2682. {
  2683. // Copy the value bytes to the buffer
  2684. BufferDescriptor->Length++;
  2685. if (BufferDescriptor->BufferPtr != NULL)
  2686. {
  2687. *BufferDescriptor->BufferPtr = *Tempptr;
  2688. BufferDescriptor->BufferPtr++;
  2689. Tempptr++;
  2690. }
  2691. }
  2692. return CS_OK;
  2693. }
  2694. //------------------------------------------------------------------------------
  2695. // Write the Q931 fields to the encoding buffer.
  2696. //
  2697. // Parameters:
  2698. // BufferDescriptor Pointer to buffer descriptor for
  2699. // the encoded output buffer.
  2700. // Message Pointer to space for parsed input information.
  2701. //------------------------------------------------------------------------------
  2702. static HRESULT
  2703. WriteQ931Fields(
  2704. PBUFFERDESCR BufferDescriptor,
  2705. PQ931MESSAGE Message)
  2706. {
  2707. // write the required information elements...
  2708. WriteProtocolDiscriminator(BufferDescriptor);
  2709. WriteCallReference(BufferDescriptor,
  2710. &Message->CallReference);
  2711. WriteMessageType(BufferDescriptor,
  2712. &Message->MessageType);
  2713. // try to write all other information elements...
  2714. // don't write this message.
  2715. #if 0
  2716. if (Message->Shift.Present)
  2717. {
  2718. WriteSingleOctetType1(BufferDescriptor, IDENT_SHIFT,
  2719. Message->Shift.Value);
  2720. }
  2721. #endif
  2722. if (Message->Facility.Present)
  2723. {
  2724. WriteVariableOctet(BufferDescriptor, IDENT_FACILITY,
  2725. Message->Facility.Length,
  2726. Message->Facility.Contents);
  2727. }
  2728. if (Message->MoreData.Present)
  2729. {
  2730. WriteSingleOctetType2(BufferDescriptor, IDENT_MORE);
  2731. }
  2732. if (Message->SendingComplete.Present)
  2733. {
  2734. WriteSingleOctetType2(BufferDescriptor, IDENT_SENDINGCOMPLETE);
  2735. }
  2736. if (Message->CongestionLevel.Present)
  2737. {
  2738. WriteSingleOctetType1(BufferDescriptor, IDENT_CONGESTION,
  2739. Message->CongestionLevel.Value);
  2740. }
  2741. if (Message->RepeatIndicator.Present)
  2742. {
  2743. WriteSingleOctetType1(BufferDescriptor, IDENT_REPEAT,
  2744. Message->RepeatIndicator.Value);
  2745. }
  2746. if (Message->SegmentedMessage.Present &&
  2747. Message->SegmentedMessage.Length)
  2748. {
  2749. WriteVariableOctet(BufferDescriptor, IDENT_SEGMENTED,
  2750. Message->SegmentedMessage.Length,
  2751. Message->SegmentedMessage.Contents);
  2752. }
  2753. if (Message->BearerCapability.Present &&
  2754. Message->BearerCapability.Length)
  2755. {
  2756. WriteVariableOctet(BufferDescriptor, IDENT_BEARERCAP,
  2757. Message->BearerCapability.Length,
  2758. Message->BearerCapability.Contents);
  2759. }
  2760. if (Message->Cause.Present &&
  2761. Message->Cause.Length)
  2762. {
  2763. WriteVariableOctet(BufferDescriptor, IDENT_CAUSE,
  2764. Message->Cause.Length,
  2765. Message->Cause.Contents);
  2766. }
  2767. if (Message->CallIdentity.Present &&
  2768. Message->CallIdentity.Length)
  2769. {
  2770. WriteVariableOctet(BufferDescriptor, IDENT_CALLIDENT,
  2771. Message->CallIdentity.Length,
  2772. Message->CallIdentity.Contents);
  2773. }
  2774. if (Message->CallState.Present &&
  2775. Message->CallState.Length)
  2776. {
  2777. WriteVariableOctet(BufferDescriptor, IDENT_CALLSTATE,
  2778. Message->CallState.Length,
  2779. Message->CallState.Contents);
  2780. }
  2781. if (Message->ChannelIdentification.Present &&
  2782. Message->ChannelIdentification.Length)
  2783. {
  2784. WriteVariableOctet(BufferDescriptor, IDENT_CHANNELIDENT,
  2785. Message->ChannelIdentification.Length,
  2786. Message->ChannelIdentification.Contents);
  2787. }
  2788. if (Message->ProgressIndicator.Present &&
  2789. Message->ProgressIndicator.Length)
  2790. {
  2791. WriteVariableOctet(BufferDescriptor, IDENT_PROGRESS,
  2792. Message->ProgressIndicator.Length,
  2793. Message->ProgressIndicator.Contents);
  2794. }
  2795. if (Message->NetworkFacilities.Present &&
  2796. Message->NetworkFacilities.Length)
  2797. {
  2798. WriteVariableOctet(BufferDescriptor, IDENT_NETWORKSPEC,
  2799. Message->NetworkFacilities.Length,
  2800. Message->NetworkFacilities.Contents);
  2801. }
  2802. if (Message->NotificationIndicator.Present &&
  2803. Message->NotificationIndicator.Length)
  2804. {
  2805. WriteVariableOctet(BufferDescriptor, IDENT_NOTIFICATION,
  2806. Message->NotificationIndicator.Length,
  2807. Message->NotificationIndicator.Contents);
  2808. }
  2809. if (Message->Display.Present &&
  2810. Message->Display.Length)
  2811. {
  2812. WriteVariableOctet(BufferDescriptor, IDENT_DISPLAY,
  2813. Message->Display.Length,
  2814. Message->Display.Contents);
  2815. }
  2816. if (Message->Date.Present &&
  2817. Message->Date.Length)
  2818. {
  2819. WriteVariableOctet(BufferDescriptor, IDENT_DATE,
  2820. Message->Date.Length,
  2821. Message->Date.Contents);
  2822. }
  2823. if (Message->Keypad.Present &&
  2824. Message->Keypad.Length)
  2825. {
  2826. WriteVariableOctet(BufferDescriptor, IDENT_KEYPAD,
  2827. Message->Keypad.Length,
  2828. Message->Keypad.Contents);
  2829. }
  2830. if (Message->Signal.Present &&
  2831. Message->Signal.Length)
  2832. {
  2833. WriteVariableOctet(BufferDescriptor, IDENT_SIGNAL,
  2834. Message->Signal.Length,
  2835. Message->Signal.Contents);
  2836. }
  2837. if (Message->InformationRate.Present &&
  2838. Message->InformationRate.Length)
  2839. {
  2840. WriteVariableOctet(BufferDescriptor, IDENT_INFORMATIONRATE,
  2841. Message->InformationRate.Length,
  2842. Message->InformationRate.Contents);
  2843. }
  2844. if (Message->EndToEndTransitDelay.Present &&
  2845. Message->EndToEndTransitDelay.Length)
  2846. {
  2847. WriteVariableOctet(BufferDescriptor, IDENT_ENDTOENDDELAY,
  2848. Message->EndToEndTransitDelay.Length,
  2849. Message->EndToEndTransitDelay.Contents);
  2850. }
  2851. if (Message->TransitDelay.Present &&
  2852. Message->TransitDelay.Length)
  2853. {
  2854. WriteVariableOctet(BufferDescriptor, IDENT_TRANSITDELAY,
  2855. Message->TransitDelay.Length,
  2856. Message->TransitDelay.Contents);
  2857. }
  2858. if (Message->PacketLayerBinaryParams.Present &&
  2859. Message->PacketLayerBinaryParams.Length)
  2860. {
  2861. WriteVariableOctet(BufferDescriptor, IDENT_PLBINARYPARAMS,
  2862. Message->PacketLayerBinaryParams.Length,
  2863. Message->PacketLayerBinaryParams.Contents);
  2864. }
  2865. if (Message->PacketLayerWindowSize.Present &&
  2866. Message->PacketLayerWindowSize.Length)
  2867. {
  2868. WriteVariableOctet(BufferDescriptor, IDENT_PLWINDOWSIZE,
  2869. Message->PacketLayerWindowSize.Length,
  2870. Message->PacketLayerWindowSize.Contents);
  2871. }
  2872. if (Message->PacketSize.Present &&
  2873. Message->PacketSize.Length)
  2874. {
  2875. WriteVariableOctet(BufferDescriptor, IDENT_PACKETSIZE,
  2876. Message->PacketSize.Length,
  2877. Message->PacketSize.Contents);
  2878. }
  2879. if (Message->ClosedUserGroup.Present &&
  2880. Message->ClosedUserGroup.Length)
  2881. {
  2882. WriteVariableOctet(BufferDescriptor, IDENT_CLOSEDUG,
  2883. Message->ClosedUserGroup.Length,
  2884. Message->ClosedUserGroup.Contents);
  2885. }
  2886. if (Message->ReverseChargeIndication.Present &&
  2887. Message->ReverseChargeIndication.Length)
  2888. {
  2889. WriteVariableOctet(BufferDescriptor, IDENT_REVCHARGE,
  2890. Message->ReverseChargeIndication.Length,
  2891. Message->ReverseChargeIndication.Contents);
  2892. }
  2893. if (Message->CallingPartyNumber.Present &&
  2894. Message->CallingPartyNumber.Length)
  2895. {
  2896. WriteVariableOctet(BufferDescriptor, IDENT_CALLINGNUMBER,
  2897. Message->CallingPartyNumber.Length,
  2898. Message->CallingPartyNumber.Contents);
  2899. }
  2900. if (Message->CallingPartySubaddress.Present &&
  2901. Message->CallingPartySubaddress.Length)
  2902. {
  2903. WriteVariableOctet(BufferDescriptor, IDENT_CALLINGSUBADDR,
  2904. Message->CallingPartySubaddress.Length,
  2905. Message->CallingPartySubaddress.Contents);
  2906. }
  2907. if (Message->CalledPartyNumber.Present)
  2908. {
  2909. WritePartyNumber(BufferDescriptor, IDENT_CALLEDNUMBER,
  2910. Message->CalledPartyNumber.NumberType,
  2911. Message->CalledPartyNumber.NumberingPlan,
  2912. Message->CalledPartyNumber.PartyNumberLength,
  2913. Message->CalledPartyNumber.PartyNumbers);
  2914. }
  2915. if (Message->CalledPartySubaddress.Present &&
  2916. Message->CalledPartySubaddress.Length)
  2917. {
  2918. WriteVariableOctet(BufferDescriptor, IDENT_CALLEDSUBADDR,
  2919. Message->CalledPartySubaddress.Length,
  2920. Message->CalledPartySubaddress.Contents);
  2921. }
  2922. if (Message->RedirectingNumber.Present &&
  2923. Message->RedirectingNumber.Length)
  2924. {
  2925. WriteVariableOctet(BufferDescriptor, IDENT_REDIRECTING,
  2926. Message->RedirectingNumber.Length,
  2927. Message->RedirectingNumber.Contents);
  2928. }
  2929. if (Message->TransitNetworkSelection.Present &&
  2930. Message->TransitNetworkSelection.Length)
  2931. {
  2932. WriteVariableOctet(BufferDescriptor, IDENT_TRANSITNET,
  2933. Message->TransitNetworkSelection.Length,
  2934. Message->TransitNetworkSelection.Contents);
  2935. }
  2936. if (Message->RestartIndicator.Present &&
  2937. Message->RestartIndicator.Length)
  2938. {
  2939. WriteVariableOctet(BufferDescriptor, IDENT_RESTART,
  2940. Message->RestartIndicator.Length,
  2941. Message->RestartIndicator.Contents);
  2942. }
  2943. if (Message->LowLayerCompatibility.Present &&
  2944. Message->LowLayerCompatibility.Length)
  2945. {
  2946. WriteVariableOctet(BufferDescriptor, IDENT_LLCOMPATIBILITY,
  2947. Message->LowLayerCompatibility.Length,
  2948. Message->LowLayerCompatibility.Contents);
  2949. }
  2950. if (Message->HighLayerCompatibility.Present &&
  2951. Message->HighLayerCompatibility.Length)
  2952. {
  2953. WriteVariableOctet(BufferDescriptor, IDENT_HLCOMPATIBILITY,
  2954. Message->HighLayerCompatibility.Length,
  2955. Message->HighLayerCompatibility.Contents);
  2956. }
  2957. if (Message->UserToUser.Present &&
  2958. Message->UserToUser.UserInformationLength)
  2959. {
  2960. WriteVariableASN(BufferDescriptor,
  2961. IDENT_USERUSER,
  2962. Message->UserToUser.UserInformationLength,
  2963. Message->UserToUser.UserInformation);
  2964. }
  2965. return CS_OK;
  2966. }
  2967. //------------------------------------------------------------------------------
  2968. // Parse a generic Q931 message and place the fields of the
  2969. // of the buffer into the appropriate field structure.
  2970. //
  2971. // Parameters:
  2972. // BufferDescriptor Pointer to buffer descriptor of a
  2973. // the network packet of the 931 message
  2974. // Message Pointer to space for parsed information.
  2975. //------------------------------------------------------------------------------
  2976. HRESULT
  2977. Q931MakeEncodedMessage(
  2978. PQ931MESSAGE Message,
  2979. BYTE **CodedBufferPtr,
  2980. DWORD *CodedBufferLength)
  2981. {
  2982. BUFFERDESCR BufferDescriptor;
  2983. BYTE *OutBuffer = NULL;
  2984. DWORD Pass1Length = 0;
  2985. if ((CodedBufferPtr == NULL) || (CodedBufferLength == NULL))
  2986. {
  2987. return CS_BAD_PARAM;
  2988. }
  2989. BufferDescriptor.Length = 0;
  2990. BufferDescriptor.BufferPtr = NULL;
  2991. WriteQ931Fields(&BufferDescriptor, Message);
  2992. if (BufferDescriptor.Length == 0)
  2993. {
  2994. return CS_NO_FIELD_DATA;
  2995. }
  2996. Pass1Length = BufferDescriptor.Length;
  2997. OutBuffer = (BYTE *)MemAlloc(BufferDescriptor.Length + 1000);
  2998. if (OutBuffer == NULL)
  2999. {
  3000. return CS_NO_MEMORY;
  3001. }
  3002. BufferDescriptor.Length = 0;
  3003. BufferDescriptor.BufferPtr = OutBuffer;
  3004. WriteQ931Fields(&BufferDescriptor, Message);
  3005. if (Pass1Length != BufferDescriptor.Length)
  3006. {
  3007. // this is a serious error, since memory may have been overrun.
  3008. return CS_BAD_PARAM;
  3009. }
  3010. *CodedBufferPtr = OutBuffer;
  3011. *CodedBufferLength = BufferDescriptor.Length;
  3012. return CS_OK;
  3013. }
  3014. //-------------------------------------------------------------------------------------
  3015. //-------------------------------------------------------------------------------------
  3016. HRESULT
  3017. Q931SetupEncodePDU(
  3018. WORD wCallReference,
  3019. char *pszDisplay,
  3020. char *pszCalledPartyNumber,
  3021. BINARY_STRING *pUserUserData,
  3022. BYTE **CodedBufferPtr,
  3023. DWORD *CodedBufferLength)
  3024. {
  3025. Q931MESSAGE *pMessage;
  3026. HRESULT Result = CS_OK;
  3027. pMessage = (Q931MESSAGE *)MemAlloc(sizeof(Q931MESSAGE));
  3028. if (pMessage == NULL)
  3029. {
  3030. return CS_NO_MEMORY;
  3031. }
  3032. // fill in the required fields for the setup message.
  3033. memset(pMessage, 0, sizeof(Q931MESSAGE));
  3034. pMessage->ProtocolDiscriminator = Q931PDVALUE;
  3035. pMessage->CallReference = wCallReference;
  3036. pMessage->MessageType = SETUPMESSAGETYPE;
  3037. pMessage->BearerCapability.Present = TRUE;
  3038. pMessage->BearerCapability.Length = 3;
  3039. pMessage->BearerCapability.Contents[0] =
  3040. (BYTE)(BEAR_EXT_BIT | BEAR_CCITT | BEAR_UNRESTRICTED_DIGITAL);
  3041. pMessage->BearerCapability.Contents[1] =
  3042. (BYTE)(BEAR_EXT_BIT | BEAR_PACKET_MODE | BEAR_NO_CIRCUIT_RATE);
  3043. pMessage->BearerCapability.Contents[2] =
  3044. (BYTE)(BEAR_EXT_BIT | BEAR_LAYER1_INDICATOR | BEAR_LAYER1_H221_H242);
  3045. if (pszDisplay && *pszDisplay)
  3046. {
  3047. pMessage->Display.Present = TRUE;
  3048. pMessage->Display.Length = (BYTE)(strlen(pszDisplay) + 1);
  3049. strcpy((char *)pMessage->Display.Contents, pszDisplay);
  3050. }
  3051. if (pszCalledPartyNumber && *pszCalledPartyNumber)
  3052. {
  3053. WORD wLen = (WORD)strlen(pszCalledPartyNumber);
  3054. pMessage->CalledPartyNumber.Present = TRUE;
  3055. pMessage->CalledPartyNumber.NumberType =
  3056. (BYTE)(CALLED_PARTY_EXT_BIT | CALLED_PARTY_TYPE_UNKNOWN);
  3057. pMessage->CalledPartyNumber.NumberingPlan =
  3058. (BYTE)(CALLED_PARTY_PLAN_E164);
  3059. pMessage->CalledPartyNumber.PartyNumberLength = (BYTE)wLen;
  3060. memcpy(pMessage->CalledPartyNumber.PartyNumbers,
  3061. pszCalledPartyNumber, wLen);
  3062. }
  3063. if (pUserUserData && pUserUserData->ptr)
  3064. {
  3065. if (pUserUserData->length > sizeof(pMessage->UserToUser.UserInformation))
  3066. {
  3067. MemFree(pMessage);
  3068. return CS_BAD_PARAM;
  3069. }
  3070. pMessage->UserToUser.Present = TRUE;
  3071. pMessage->UserToUser.UserInformationLength = (pUserUserData->length);
  3072. memcpy(pMessage->UserToUser.UserInformation,
  3073. pUserUserData->ptr, pUserUserData->length);
  3074. }
  3075. Result = Q931MakeEncodedMessage(pMessage, CodedBufferPtr,
  3076. CodedBufferLength);
  3077. MemFree(pMessage);
  3078. return Result;
  3079. }
  3080. //-------------------------------------------------------------------------------------
  3081. //-------------------------------------------------------------------------------------
  3082. HRESULT
  3083. Q931ReleaseCompleteEncodePDU(
  3084. WORD wCallReference,
  3085. BYTE *pbCause,
  3086. BINARY_STRING *pUserUserData,
  3087. BYTE **CodedBufferPtr,
  3088. DWORD *CodedBufferLength)
  3089. {
  3090. Q931MESSAGE *pMessage;
  3091. HRESULT Result = CS_OK;
  3092. if (pbCause)
  3093. {
  3094. switch (*pbCause)
  3095. {
  3096. case CAUSE_VALUE_NORMAL_CLEAR:
  3097. case CAUSE_VALUE_USER_BUSY:
  3098. case CAUSE_VALUE_SECURITY_DENIED:
  3099. case CAUSE_VALUE_NO_ANSWER:
  3100. case CAUSE_VALUE_REJECTED:
  3101. case CAUSE_VALUE_NOT_IMPLEMENTED:
  3102. case CAUSE_VALUE_INVALID_CRV:
  3103. case CAUSE_VALUE_IE_MISSING:
  3104. case CAUSE_VALUE_IE_CONTENTS:
  3105. case CAUSE_VALUE_TIMER_EXPIRED:
  3106. break;
  3107. default:
  3108. return CS_BAD_PARAM;
  3109. break;
  3110. }
  3111. }
  3112. pMessage = (Q931MESSAGE *)MemAlloc(sizeof(Q931MESSAGE));
  3113. if (pMessage == NULL)
  3114. {
  3115. return CS_NO_MEMORY;
  3116. }
  3117. // fill in the required fields for the setup message.
  3118. memset(pMessage, 0, sizeof(Q931MESSAGE));
  3119. pMessage->ProtocolDiscriminator = Q931PDVALUE;
  3120. pMessage->CallReference = wCallReference;
  3121. pMessage->MessageType = RELEASECOMPLMESSAGETYPE;
  3122. if (pbCause)
  3123. {
  3124. pMessage->Cause.Present = TRUE;
  3125. pMessage->Cause.Length = 3;
  3126. pMessage->Cause.Contents[0] = (BYTE)(CAUSE_CODING_CCITT | CAUSE_LOCATION_USER);
  3127. pMessage->Cause.Contents[1] = (BYTE)(CAUSE_RECOMMENDATION_Q931);
  3128. pMessage->Cause.Contents[2] = (BYTE)(CAUSE_EXT_BIT | *pbCause);
  3129. }
  3130. else
  3131. {
  3132. pMessage->Cause.Present = FALSE;
  3133. }
  3134. if (pUserUserData && pUserUserData->ptr)
  3135. {
  3136. if (pUserUserData->length > sizeof(pMessage->UserToUser.UserInformation))
  3137. {
  3138. MemFree(pMessage);
  3139. return CS_BAD_PARAM;
  3140. }
  3141. pMessage->UserToUser.Present = TRUE;
  3142. pMessage->UserToUser.UserInformationLength = (pUserUserData->length);
  3143. memcpy(pMessage->UserToUser.UserInformation,
  3144. pUserUserData->ptr, pUserUserData->length);
  3145. }
  3146. Result = Q931MakeEncodedMessage(pMessage, CodedBufferPtr,
  3147. CodedBufferLength);
  3148. MemFree(pMessage);
  3149. return Result;
  3150. }
  3151. //-------------------------------------------------------------------------------------
  3152. //-------------------------------------------------------------------------------------
  3153. HRESULT
  3154. Q931ConnectEncodePDU(
  3155. WORD wCallReference,
  3156. char *pszDisplay,
  3157. BINARY_STRING *pUserUserData,
  3158. BYTE **CodedBufferPtr,
  3159. DWORD *CodedBufferLength)
  3160. {
  3161. Q931MESSAGE *pMessage;
  3162. HRESULT Result = CS_OK;
  3163. pMessage = (Q931MESSAGE *)MemAlloc(sizeof(Q931MESSAGE));
  3164. if (pMessage == NULL)
  3165. {
  3166. return CS_NO_MEMORY;
  3167. }
  3168. // fill in the required fields for the setup message.
  3169. memset(pMessage, 0, sizeof(Q931MESSAGE));
  3170. pMessage->ProtocolDiscriminator = Q931PDVALUE;
  3171. pMessage->CallReference = wCallReference;
  3172. pMessage->MessageType = CONNECTMESSAGETYPE;
  3173. pMessage->BearerCapability.Present = TRUE;
  3174. pMessage->BearerCapability.Length = 3;
  3175. pMessage->BearerCapability.Contents[0] =
  3176. (BYTE)(BEAR_EXT_BIT | BEAR_CCITT | BEAR_UNRESTRICTED_DIGITAL);
  3177. pMessage->BearerCapability.Contents[1] =
  3178. (BYTE)(BEAR_EXT_BIT | BEAR_PACKET_MODE | BEAR_NO_CIRCUIT_RATE);
  3179. pMessage->BearerCapability.Contents[2] =
  3180. (BYTE)(BEAR_EXT_BIT | BEAR_LAYER1_INDICATOR | BEAR_LAYER1_H221_H242);
  3181. if (pszDisplay && *pszDisplay)
  3182. {
  3183. pMessage->Display.Present = TRUE;
  3184. pMessage->Display.Length = (BYTE)strlen(pszDisplay);
  3185. strcpy((char *)pMessage->Display.Contents, pszDisplay);
  3186. }
  3187. if (pUserUserData && pUserUserData->ptr)
  3188. {
  3189. if (pUserUserData->length > sizeof(pMessage->UserToUser.UserInformation))
  3190. {
  3191. MemFree(pMessage);
  3192. return CS_BAD_PARAM;
  3193. }
  3194. pMessage->UserToUser.Present = TRUE;
  3195. pMessage->UserToUser.UserInformationLength = (pUserUserData->length);
  3196. memcpy(pMessage->UserToUser.UserInformation,
  3197. pUserUserData->ptr, pUserUserData->length);
  3198. }
  3199. Result = Q931MakeEncodedMessage(pMessage, CodedBufferPtr,
  3200. CodedBufferLength);
  3201. MemFree(pMessage);
  3202. return Result;
  3203. }
  3204. //-------------------------------------------------------------------------------------
  3205. //-------------------------------------------------------------------------------------
  3206. HRESULT
  3207. Q931ProceedingEncodePDU(
  3208. WORD wCallReference,
  3209. BINARY_STRING *pUserUserData,
  3210. BYTE **CodedBufferPtr,
  3211. DWORD *CodedBufferLength)
  3212. {
  3213. Q931MESSAGE *pMessage;
  3214. HRESULT Result = CS_OK;
  3215. pMessage = (Q931MESSAGE *)MemAlloc(sizeof(Q931MESSAGE));
  3216. if (pMessage == NULL)
  3217. {
  3218. return CS_NO_MEMORY;
  3219. }
  3220. // fill in the required fields for the setup message.
  3221. memset(pMessage, 0, sizeof(Q931MESSAGE));
  3222. pMessage->ProtocolDiscriminator = Q931PDVALUE;
  3223. pMessage->CallReference = wCallReference;
  3224. pMessage->MessageType = PROCEEDINGMESSAGETYPE;
  3225. if (pUserUserData && pUserUserData->ptr)
  3226. {
  3227. if (pUserUserData->length > sizeof(pMessage->UserToUser.UserInformation))
  3228. {
  3229. MemFree(pMessage);
  3230. return CS_BAD_PARAM;
  3231. }
  3232. pMessage->UserToUser.Present = TRUE;
  3233. pMessage->UserToUser.UserInformationLength = (pUserUserData->length);
  3234. memcpy(pMessage->UserToUser.UserInformation,
  3235. pUserUserData->ptr, pUserUserData->length);
  3236. }
  3237. Result = Q931MakeEncodedMessage(pMessage, CodedBufferPtr,
  3238. CodedBufferLength);
  3239. MemFree(pMessage);
  3240. return Result;
  3241. }
  3242. //-------------------------------------------------------------------------------------
  3243. //-------------------------------------------------------------------------------------
  3244. HRESULT
  3245. Q931AlertingEncodePDU(
  3246. WORD wCallReference,
  3247. BINARY_STRING *pUserUserData,
  3248. BYTE **CodedBufferPtr,
  3249. DWORD *CodedBufferLength)
  3250. {
  3251. Q931MESSAGE *pMessage;
  3252. HRESULT Result = CS_OK;
  3253. pMessage = (Q931MESSAGE *)MemAlloc(sizeof(Q931MESSAGE));
  3254. if (pMessage == NULL)
  3255. {
  3256. return CS_NO_MEMORY;
  3257. }
  3258. // fill in the required fields for the setup message.
  3259. memset(pMessage, 0, sizeof(Q931MESSAGE));
  3260. pMessage->ProtocolDiscriminator = Q931PDVALUE;
  3261. pMessage->CallReference = wCallReference;
  3262. pMessage->MessageType = ALERTINGMESSAGETYPE;
  3263. if (pUserUserData && pUserUserData->ptr)
  3264. {
  3265. if (pUserUserData->length > sizeof(pMessage->UserToUser.UserInformation))
  3266. {
  3267. MemFree(pMessage);
  3268. return CS_BAD_PARAM;
  3269. }
  3270. pMessage->UserToUser.Present = TRUE;
  3271. pMessage->UserToUser.UserInformationLength = (pUserUserData->length);
  3272. memcpy(pMessage->UserToUser.UserInformation,
  3273. pUserUserData->ptr, pUserUserData->length);
  3274. }
  3275. Result = Q931MakeEncodedMessage(pMessage, CodedBufferPtr,
  3276. CodedBufferLength);
  3277. MemFree(pMessage);
  3278. return Result;
  3279. }
  3280. //-------------------------------------------------------------------------------------
  3281. //-------------------------------------------------------------------------------------
  3282. HRESULT
  3283. Q931FacilityEncodePDU(
  3284. WORD wCallReference,
  3285. BINARY_STRING *pUserUserData,
  3286. BYTE **CodedBufferPtr,
  3287. DWORD *CodedBufferLength)
  3288. {
  3289. Q931MESSAGE *pMessage;
  3290. HRESULT Result = CS_OK;
  3291. pMessage = (Q931MESSAGE *)MemAlloc(sizeof(Q931MESSAGE));
  3292. if (pMessage == NULL)
  3293. {
  3294. return CS_NO_MEMORY;
  3295. }
  3296. // fill in the required fields for the setup message.
  3297. memset(pMessage, 0, sizeof(Q931MESSAGE));
  3298. pMessage->ProtocolDiscriminator = Q931PDVALUE;
  3299. pMessage->CallReference = wCallReference;
  3300. pMessage->MessageType = FACILITYMESSAGETYPE;
  3301. // The facility ie is encoded as present, but empty...
  3302. pMessage->Facility.Present = TRUE;
  3303. pMessage->Facility.Length = 0;
  3304. pMessage->Facility.Contents[0] = 0;
  3305. if (pUserUserData && pUserUserData->ptr)
  3306. {
  3307. if (pUserUserData->length > sizeof(pMessage->UserToUser.UserInformation))
  3308. {
  3309. MemFree(pMessage);
  3310. return CS_BAD_PARAM;
  3311. }
  3312. pMessage->UserToUser.Present = TRUE;
  3313. pMessage->UserToUser.UserInformationLength = (pUserUserData->length);
  3314. memcpy(pMessage->UserToUser.UserInformation,
  3315. pUserUserData->ptr, pUserUserData->length);
  3316. }
  3317. Result = Q931MakeEncodedMessage(pMessage, CodedBufferPtr,
  3318. CodedBufferLength);
  3319. MemFree(pMessage);
  3320. return Result;
  3321. }
  3322. //-------------------------------------------------------------------------------------
  3323. //-------------------------------------------------------------------------------------
  3324. HRESULT
  3325. Q931StatusEncodePDU(
  3326. WORD wCallReference,
  3327. char *pszDisplay,
  3328. BYTE bCause,
  3329. BYTE bCallState,
  3330. BYTE **CodedBufferPtr,
  3331. DWORD *CodedBufferLength)
  3332. {
  3333. Q931MESSAGE *pMessage;
  3334. HRESULT Result = CS_OK;
  3335. pMessage = (Q931MESSAGE *)MemAlloc(sizeof(Q931MESSAGE));
  3336. if (pMessage == NULL)
  3337. {
  3338. return CS_NO_MEMORY;
  3339. }
  3340. // fill in the required fields for the setup message.
  3341. memset(pMessage, 0, sizeof(Q931MESSAGE));
  3342. pMessage->ProtocolDiscriminator = Q931PDVALUE;
  3343. pMessage->CallReference = wCallReference;
  3344. pMessage->MessageType = STATUSMESSAGETYPE;
  3345. if (pszDisplay && *pszDisplay)
  3346. {
  3347. pMessage->Display.Present = TRUE;
  3348. pMessage->Display.Length = (BYTE)(strlen(pszDisplay) + 1);
  3349. strcpy((char *)pMessage->Display.Contents, pszDisplay);
  3350. }
  3351. pMessage->Cause.Present = TRUE;
  3352. pMessage->Cause.Length = 3;
  3353. pMessage->Cause.Contents[0] = (BYTE)(CAUSE_CODING_CCITT | CAUSE_LOCATION_USER);
  3354. pMessage->Cause.Contents[1] = (BYTE)(CAUSE_RECOMMENDATION_Q931);
  3355. pMessage->Cause.Contents[2] = (BYTE)(CAUSE_EXT_BIT | bCause);
  3356. pMessage->CallState.Present = TRUE;
  3357. pMessage->CallState.Length = 1;
  3358. pMessage->CallState.Contents[0] = (BYTE)(bCallState);
  3359. Result = Q931MakeEncodedMessage(pMessage, CodedBufferPtr,
  3360. CodedBufferLength);
  3361. MemFree(pMessage);
  3362. return Result;
  3363. }
  3364. #if(0)
  3365. //========================================================================
  3366. //========================================================================
  3367. //========================================================================
  3368. // THIS IS THE ASN PART...
  3369. //========================================================================
  3370. //========================================================================
  3371. //========================================================================
  3372. static ERROR_MAP EncodeErrorMap[] =
  3373. {
  3374. PDU_ENCODED, __TEXT("PDU successfully encoded"),
  3375. MORE_BUF, __TEXT("User-provided output buffer too small"),
  3376. PDU_RANGE, __TEXT("PDU specified out of range"),
  3377. BAD_ARG, __TEXT("Bad pointer was passed"),
  3378. BAD_VERSION, __TEXT("Versions of encoder and table do not match"),
  3379. OUT_MEMORY, __TEXT("Memory-allocation error"),
  3380. BAD_CHOICE, __TEXT("Unknown selector for a choice"),
  3381. BAD_OBJID, __TEXT("Object identifier conflicts with x.208"),
  3382. BAD_PTR, __TEXT("Unexpected NULL pointer in input buffer"),
  3383. BAD_TIME, __TEXT("Bad value in time type"),
  3384. MEM_ERROR, __TEXT("Memory violation signal trapped"),
  3385. BAD_TABLE, __TEXT("Table was bad, but not NULL"),
  3386. TOO_LONG, __TEXT("Type was longer than constraint"),
  3387. CONSTRAINT_VIOLATED, __TEXT("Constraint violation error occured"),
  3388. FATAL_ERROR, __TEXT("Serious internal error"),
  3389. ACCESS_SERIALIZATION_ERROR, __TEXT("Thread access to global data failed"),
  3390. NULL_TBL, __TEXT("NULL control table pointer"),
  3391. NULL_FCN, __TEXT("Encoder called via a NULL pointer"),
  3392. BAD_ENCRULES, __TEXT("Unknown encoding rules"),
  3393. UNAVAIL_ENCRULES, __TEXT("Encoding rules requested are not implemented"),
  3394. UNIMPLEMENTED, __TEXT("Type was not implemented yet"),
  3395. // LOAD_ERR, __TEXT("Unable to load DLL"),
  3396. CANT_OPEN_TRACE_FILE, __TEXT("Error when opening a trace file"),
  3397. TRACE_FILE_ALREADY_OPEN, __TEXT("Trace file has been opened"),
  3398. TABLE_MISMATCH, __TEXT("Control table mismatch"),
  3399. 0, NULL
  3400. };
  3401. static ERROR_MAP DecodeErrorMap[] =
  3402. {
  3403. PDU_DECODED, __TEXT("PDU successfully decoded"),
  3404. MORE_BUF, __TEXT("User-provided output buffer too small"),
  3405. NEGATIVE_UINTEGER, __TEXT("The first unsigned bit of the encoding is 1"),
  3406. PDU_RANGE, __TEXT("Pdu specified out of range"),
  3407. MORE_INPUT, __TEXT("Unexpected end of input buffer"),
  3408. DATA_ERROR, __TEXT("An error exists in the encoded data"),
  3409. BAD_VERSION, __TEXT("Versions of encoder and table do not match"),
  3410. OUT_MEMORY, __TEXT("Memory-allocation error"),
  3411. PDU_MISMATCH, __TEXT("The PDU tag does not match data"),
  3412. LIMITED, __TEXT("Size implementation limit exceeded"),
  3413. CONSTRAINT_VIOLATED, __TEXT("Constraint violation error occured"),
  3414. ACCESS_SERIALIZATION_ERROR, __TEXT("Thread access to global data failed"),
  3415. NULL_TBL, __TEXT("NULL control table pointer"),
  3416. NULL_FCN, __TEXT("Encoder called via a NULL pointer"),
  3417. BAD_ENCRULES, __TEXT("Unknown encoding rules"),
  3418. UNAVAIL_ENCRULES, __TEXT("Encoding rules requested are not implemented"),
  3419. UNIMPLEMENTED, __TEXT("The type was not implemented yet"),
  3420. // LOAD_ERR, __TEXT("Unable to load DLL"),
  3421. CANT_OPEN_TRACE_FILE, __TEXT("Error when opening a trace file"),
  3422. TRACE_FILE_ALREADY_OPEN, __TEXT("The trace file has been opened"),
  3423. TABLE_MISMATCH, __TEXT("Control table mismatch"),
  3424. 0, NULL
  3425. };
  3426. #endif // if(0)
  3427. //====================================================================================
  3428. //====================================================================================
  3429. #ifdef UNICODE_TRACE
  3430. LPWSTR
  3431. #else
  3432. LPSTR
  3433. #endif
  3434. ErrorToTextASN(ERROR_MAP *Map, int nErrorCode)
  3435. {
  3436. register int nIndex = 0;
  3437. if (Map != NULL)
  3438. {
  3439. for (nIndex = 0; Map[nIndex].pszErrorText; nIndex++)
  3440. {
  3441. if (Map[nIndex].nErrorCode == nErrorCode)
  3442. {
  3443. return Map[nIndex].pszErrorText;
  3444. }
  3445. }
  3446. }
  3447. return __TEXT("Unknown ASN.1 Error");
  3448. }
  3449. #if 0
  3450. //------------------------------------------------------------------------
  3451. //------------------------------------------------------------------------
  3452. int
  3453. ASN1LinePrint(FILE *stream, const char *format, ...)
  3454. {
  3455. va_list marker;
  3456. char buf[300];
  3457. int i;
  3458. va_start(marker, format);
  3459. i = wsprintf(buf, format, marker);
  3460. va_end(marker);
  3461. // TRACE the buf...
  3462. ISRTRACE(ghISRInst, buf, 0L);
  3463. return i;
  3464. }
  3465. #endif
  3466. #define USE_ASN1_ENCODING 5
  3467. //-------------------------------------------------------------------------------------
  3468. //-------------------------------------------------------------------------------------
  3469. HRESULT
  3470. Q931SetupEncodeASN(
  3471. PCC_NONSTANDARDDATA pNonStandardData,
  3472. CC_ADDR *pCallerAddr, // this data is not yet passed in the PDU...
  3473. CC_ADDR *pCalleeAddr,
  3474. WORD wGoal,
  3475. WORD wCallType,
  3476. BOOL bCallerIsMC,
  3477. CC_CONFERENCEID *pConferenceID,
  3478. PCC_ALIASNAMES pCallerAliasList,
  3479. PCC_ALIASNAMES pCalleeAliasList,
  3480. PCC_ALIASNAMES pExtraAliasList,
  3481. PCC_ALIASITEM pExtensionAliasItem,
  3482. PCC_VENDORINFO pVendorInfo,
  3483. BOOL bIsTerminal,
  3484. BOOL bIsGateway,
  3485. ASN1_CODER_INFO *pWorld,
  3486. BYTE **ppEncodedBuf,
  3487. DWORD *pdwEncodedLength,
  3488. LPGUID pCallIdentifier)
  3489. {
  3490. int rc;
  3491. H323_UserInformation UserInfo;
  3492. *ppEncodedBuf = NULL;
  3493. *pdwEncodedLength = 0;
  3494. memset(&UserInfo, 0, sizeof(H323_UserInformation));
  3495. // redundant! memset to zero ---> UserInfo.bit_mask = 0;
  3496. // make sure the user_data_present flag is turned off.
  3497. // redundant ---> UserInfo.bit_mask &= (~user_data_present);
  3498. if (pNonStandardData)
  3499. {
  3500. UserInfo.h323_uu_pdu.bit_mask |= H323_UU_PDU_nnStndrdDt_present;
  3501. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.choice =
  3502. H225NonStandardIdentifier_h221NonStandard_chosen;
  3503. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35CountryCode =
  3504. pNonStandardData->bCountryCode;
  3505. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35Extension =
  3506. pNonStandardData->bExtension;
  3507. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.manufacturerCode =
  3508. pNonStandardData->wManufacturerCode;
  3509. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.length =
  3510. pNonStandardData->sData.wOctetStringLength;
  3511. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.value =
  3512. pNonStandardData->sData.pOctetString;
  3513. }
  3514. else
  3515. {
  3516. UserInfo.h323_uu_pdu.bit_mask &= (~H323_UU_PDU_nnStndrdDt_present);
  3517. }
  3518. UserInfo.h323_uu_pdu.h323_message_body.choice = setup_chosen;
  3519. UserInfo.h323_uu_pdu.h323_message_body.u.setup.bit_mask = 0;
  3520. UserInfo.h323_uu_pdu.h323_message_body.u.setup.protocolIdentifier = &ProtocolId1;
  3521. if (pCallerAliasList)
  3522. {
  3523. CS_STATUS AliasResult = CS_OK;
  3524. AliasResult = AliasToSeqof((struct Setup_UUIE_sourceAddress **)&(UserInfo.h323_uu_pdu.
  3525. h323_message_body.u.setup.sourceAddress), pCallerAliasList);
  3526. if (AliasResult != CS_OK)
  3527. {
  3528. return CS_NO_MEMORY;
  3529. }
  3530. UserInfo.h323_uu_pdu.h323_message_body.u.setup.bit_mask |=
  3531. (sourceAddress_present);
  3532. }
  3533. else
  3534. {
  3535. UserInfo.h323_uu_pdu.h323_message_body.u.setup.bit_mask &=
  3536. (~sourceAddress_present);
  3537. }
  3538. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceInfo.bit_mask = 0;
  3539. if (pVendorInfo)
  3540. {
  3541. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceInfo.bit_mask |= vendor_present;
  3542. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceInfo.vendor.bit_mask = 0;
  3543. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceInfo.vendor.vendor.t35CountryCode = pVendorInfo->bCountryCode;
  3544. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceInfo.vendor.vendor.t35Extension = pVendorInfo->bExtension;
  3545. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceInfo.vendor.vendor.manufacturerCode = pVendorInfo->wManufacturerCode;
  3546. if (pVendorInfo->pProductNumber && pVendorInfo->pProductNumber->pOctetString &&
  3547. pVendorInfo->pProductNumber->wOctetStringLength)
  3548. {
  3549. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceInfo.vendor.bit_mask |= productId_present;
  3550. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceInfo.vendor.productId.length =
  3551. pVendorInfo->pProductNumber->wOctetStringLength;
  3552. memcpy(UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceInfo.vendor.productId.value,
  3553. pVendorInfo->pProductNumber->pOctetString,
  3554. pVendorInfo->pProductNumber->wOctetStringLength);
  3555. }
  3556. if (pVendorInfo->pVersionNumber && pVendorInfo->pVersionNumber->pOctetString &&
  3557. pVendorInfo->pVersionNumber->wOctetStringLength)
  3558. {
  3559. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceInfo.vendor.bit_mask |= versionId_present;
  3560. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceInfo.vendor.versionId.length =
  3561. pVendorInfo->pVersionNumber->wOctetStringLength;
  3562. memcpy(UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceInfo.vendor.versionId.value,
  3563. pVendorInfo->pVersionNumber->pOctetString,
  3564. pVendorInfo->pVersionNumber->wOctetStringLength);
  3565. }
  3566. }
  3567. if (bIsTerminal)
  3568. {
  3569. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceInfo.bit_mask |=
  3570. terminal_present;
  3571. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceInfo.terminal.bit_mask = 0;
  3572. }
  3573. if (bIsGateway)
  3574. {
  3575. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceInfo.bit_mask |=
  3576. gateway_present;
  3577. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceInfo.gateway.bit_mask = protocol_present;
  3578. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceInfo.gateway.protocol = &TempProtocol;
  3579. }
  3580. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceInfo.mc = (ASN1_BOOL)bCallerIsMC;
  3581. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceInfo.undefinedNode = 0;
  3582. if (pCalleeAliasList)
  3583. {
  3584. CS_STATUS AliasResult = CS_OK;
  3585. AliasResult = AliasWithPrefixToSeqof((struct Setup_UUIE_sourceAddress **)&(UserInfo.h323_uu_pdu.
  3586. h323_message_body.u.setup.destinationAddress), pCalleeAliasList);
  3587. if (AliasResult != CS_OK)
  3588. {
  3589. FreeSeqof((struct Setup_UUIE_sourceAddress *)UserInfo.h323_uu_pdu.
  3590. h323_message_body.u.setup.sourceAddress);
  3591. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceAddress = NULL;
  3592. return CS_NO_MEMORY;
  3593. }
  3594. UserInfo.h323_uu_pdu.h323_message_body.u.setup.bit_mask |=
  3595. (destinationAddress_present);
  3596. }
  3597. else
  3598. {
  3599. UserInfo.h323_uu_pdu.h323_message_body.u.setup.bit_mask &=
  3600. (~destinationAddress_present);
  3601. }
  3602. if (pExtraAliasList)
  3603. {
  3604. CS_STATUS AliasResult = CS_OK;
  3605. AliasResult = AliasWithPrefixToSeqof((struct Setup_UUIE_sourceAddress **)&(UserInfo.h323_uu_pdu.
  3606. h323_message_body.u.setup.destExtraCallInfo), pExtraAliasList);
  3607. if (AliasResult != CS_OK)
  3608. {
  3609. FreeSeqof((struct Setup_UUIE_sourceAddress *)UserInfo.h323_uu_pdu.h323_message_body.u.setup.destinationAddress);
  3610. UserInfo.h323_uu_pdu.h323_message_body.u.setup.destinationAddress = NULL;
  3611. FreeSeqof((struct Setup_UUIE_sourceAddress *)UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceAddress);
  3612. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceAddress = NULL;
  3613. return CS_NO_MEMORY;
  3614. }
  3615. UserInfo.h323_uu_pdu.h323_message_body.u.setup.bit_mask |=
  3616. (Setup_UUIE_destExtraCallInfo_present);
  3617. }
  3618. else
  3619. {
  3620. UserInfo.h323_uu_pdu.h323_message_body.u.setup.bit_mask &=
  3621. (~Setup_UUIE_destExtraCallInfo_present);
  3622. }
  3623. if (pCalleeAddr)
  3624. {
  3625. DWORD a = pCalleeAddr->Addr.IP_Binary.dwAddr;
  3626. UserInfo.h323_uu_pdu.h323_message_body.u.setup.destCallSignalAddress.choice = ipAddress_chosen;
  3627. UserInfo.h323_uu_pdu.h323_message_body.u.setup.destCallSignalAddress.u.ipAddress.ip.length = 4;
  3628. UserInfo.h323_uu_pdu.h323_message_body.u.setup.destCallSignalAddress.u.ipAddress.port =
  3629. pCalleeAddr->Addr.IP_Binary.wPort;
  3630. UserInfo.h323_uu_pdu.h323_message_body.u.setup.destCallSignalAddress.u.ipAddress.ip.value[0] =
  3631. ((BYTE *)&a)[3];
  3632. UserInfo.h323_uu_pdu.h323_message_body.u.setup.destCallSignalAddress.u.ipAddress.ip.value[1] =
  3633. ((BYTE *)&a)[2];
  3634. UserInfo.h323_uu_pdu.h323_message_body.u.setup.destCallSignalAddress.u.ipAddress.ip.value[2] =
  3635. ((BYTE *)&a)[1];
  3636. UserInfo.h323_uu_pdu.h323_message_body.u.setup.destCallSignalAddress.u.ipAddress.ip.value[3] =
  3637. ((BYTE *)&a)[0];
  3638. UserInfo.h323_uu_pdu.h323_message_body.u.setup.bit_mask |=
  3639. (Setup_UUIE_destCallSignalAddress_present);
  3640. }
  3641. else
  3642. {
  3643. UserInfo.h323_uu_pdu.h323_message_body.u.setup.bit_mask &=
  3644. (~Setup_UUIE_destCallSignalAddress_present);
  3645. }
  3646. UserInfo.h323_uu_pdu.h323_message_body.u.setup.activeMC = (ASN1_BOOL)bCallerIsMC;
  3647. if (pConferenceID != NULL)
  3648. {
  3649. UserInfo.h323_uu_pdu.h323_message_body.u.setup.conferenceID.length =
  3650. sizeof(UserInfo.h323_uu_pdu.h323_message_body.u.setup.conferenceID.value);
  3651. memcpy(UserInfo.h323_uu_pdu.h323_message_body.u.setup.conferenceID.value,
  3652. pConferenceID->buffer,
  3653. UserInfo.h323_uu_pdu.h323_message_body.u.setup.conferenceID.length);
  3654. }
  3655. switch (wGoal)
  3656. {
  3657. case CSG_INVITE:
  3658. UserInfo.h323_uu_pdu.h323_message_body.u.setup.conferenceGoal.choice = invite_chosen;
  3659. break;
  3660. case CSG_JOIN:
  3661. UserInfo.h323_uu_pdu.h323_message_body.u.setup.conferenceGoal.choice = join_chosen;
  3662. break;
  3663. default:
  3664. UserInfo.h323_uu_pdu.h323_message_body.u.setup.conferenceGoal.choice = create_chosen;
  3665. } // switch
  3666. switch (wCallType)
  3667. {
  3668. case CC_CALLTYPE_1_N:
  3669. UserInfo.h323_uu_pdu.h323_message_body.u.setup.callType.choice = oneToN_chosen;
  3670. break;
  3671. case CC_CALLTYPE_N_1:
  3672. UserInfo.h323_uu_pdu.h323_message_body.u.setup.callType.choice = nToOne_chosen;
  3673. break;
  3674. case CC_CALLTYPE_N_N:
  3675. UserInfo.h323_uu_pdu.h323_message_body.u.setup.callType.choice = nToN_chosen;
  3676. break;
  3677. default:
  3678. UserInfo.h323_uu_pdu.h323_message_body.u.setup.callType.choice = pointToPoint_chosen;
  3679. } // switch
  3680. if (pCallerAddr)
  3681. {
  3682. DWORD a = pCallerAddr->Addr.IP_Binary.dwAddr;
  3683. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceCallSignalAddress.choice = ipAddress_chosen;
  3684. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceCallSignalAddress.u.ipAddress.ip.length = 4;
  3685. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceCallSignalAddress.u.ipAddress.port =
  3686. pCallerAddr->Addr.IP_Binary.wPort;
  3687. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceCallSignalAddress.u.ipAddress.ip.value[0] =
  3688. ((BYTE *)&a)[3];
  3689. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceCallSignalAddress.u.ipAddress.ip.value[1] =
  3690. ((BYTE *)&a)[2];
  3691. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceCallSignalAddress.u.ipAddress.ip.value[2] =
  3692. ((BYTE *)&a)[1];
  3693. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceCallSignalAddress.u.ipAddress.ip.value[3] =
  3694. ((BYTE *)&a)[0];
  3695. UserInfo.h323_uu_pdu.h323_message_body.u.setup.bit_mask |=
  3696. (sourceCallSignalAddress_present);
  3697. }
  3698. else
  3699. {
  3700. UserInfo.h323_uu_pdu.h323_message_body.u.setup.bit_mask &=
  3701. (~sourceCallSignalAddress_present);
  3702. }
  3703. if (pExtensionAliasItem)
  3704. {
  3705. CS_STATUS AliasResult = CS_OK;
  3706. AliasResult = Q931CopyAliasItemToAliasAddr(&(UserInfo.h323_uu_pdu.
  3707. h323_message_body.u.setup.remoteExtensionAddress), pExtensionAliasItem);
  3708. if (AliasResult != CS_OK)
  3709. {
  3710. FreeSeqof((struct Setup_UUIE_sourceAddress *)UserInfo.h323_uu_pdu.h323_message_body.u.setup.destExtraCallInfo);
  3711. UserInfo.h323_uu_pdu.h323_message_body.u.setup.destExtraCallInfo = NULL;
  3712. FreeSeqof((struct Setup_UUIE_sourceAddress *)UserInfo.h323_uu_pdu.h323_message_body.u.setup.destinationAddress);
  3713. UserInfo.h323_uu_pdu.h323_message_body.u.setup.destinationAddress = NULL;
  3714. FreeSeqof((struct Setup_UUIE_sourceAddress *)UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceAddress);
  3715. UserInfo.h323_uu_pdu.h323_message_body.u.setup.sourceAddress = NULL;
  3716. return CS_NO_MEMORY;
  3717. }
  3718. UserInfo.h323_uu_pdu.h323_message_body.u.setup.bit_mask |=
  3719. (Setup_UUIE_remoteExtensionAddress_present);
  3720. }
  3721. else
  3722. {
  3723. UserInfo.h323_uu_pdu.h323_message_body.u.setup.bit_mask &=
  3724. (~Setup_UUIE_remoteExtensionAddress_present);
  3725. }
  3726. ASSERT(pCallIdentifier);
  3727. if(pCallIdentifier)
  3728. {
  3729. UserInfo.h323_uu_pdu.h323_message_body.u.setup.bit_mask |=
  3730. (Setup_UUIE_callIdentifier_present);
  3731. ASSERT(sizeof(GUID)
  3732. == sizeof(UserInfo.h323_uu_pdu.h323_message_body.u.setup.
  3733. callIdentifier.guid.value));
  3734. memcpy(&UserInfo.h323_uu_pdu.h323_message_body.u.setup.
  3735. callIdentifier.guid.value, pCallIdentifier,
  3736. sizeof(GUID));
  3737. UserInfo.h323_uu_pdu.h323_message_body.u.setup.
  3738. callIdentifier.guid.length = sizeof(GUID);
  3739. }
  3740. rc = Q931_Encode(pWorld,
  3741. (void *) &UserInfo,
  3742. H323_UserInformation_PDU,
  3743. ppEncodedBuf,
  3744. pdwEncodedLength);
  3745. // Free the alias name structures from the UserInfo area.
  3746. FreeSeqof((struct Setup_UUIE_sourceAddress *)UserInfo.h323_uu_pdu.h323_message_body.u.
  3747. setup.sourceAddress);
  3748. FreeSeqof((struct Setup_UUIE_sourceAddress *)UserInfo.h323_uu_pdu.h323_message_body.u.
  3749. setup.destinationAddress);
  3750. FreeSeqof((struct Setup_UUIE_sourceAddress *)UserInfo.h323_uu_pdu.h323_message_body.u.
  3751. setup.destExtraCallInfo);
  3752. Q931ClearAliasAddr(&(UserInfo.h323_uu_pdu.h323_message_body.u.setup.remoteExtensionAddress));
  3753. if (ASN1_FAILED(rc))
  3754. {
  3755. ASSERT(FALSE);
  3756. return CS_SUBSYSTEM_FAILURE;
  3757. }
  3758. return CS_OK;
  3759. }
  3760. //-------------------------------------------------------------------------------------
  3761. //-------------------------------------------------------------------------------------
  3762. void
  3763. Q931FreeEncodedBuffer(ASN1_CODER_INFO *pWorld, BYTE *pEncodedBuf)
  3764. {
  3765. ASN1_FreeEncoded(pWorld->pEncInfo, pEncodedBuf);
  3766. }
  3767. //-------------------------------------------------------------------------------------
  3768. //-------------------------------------------------------------------------------------
  3769. HRESULT
  3770. Q931ReleaseCompleteEncodeASN(
  3771. PCC_NONSTANDARDDATA pNonStandardData,
  3772. CC_CONFERENCEID *pConferenceID, // not passed in PDU!
  3773. BYTE *pbReason,
  3774. ASN1_CODER_INFO *pWorld,
  3775. BYTE **ppEncodedBuf,
  3776. DWORD *pdwEncodedLength,
  3777. LPGUID pCallIdentifier)
  3778. {
  3779. int rc;
  3780. H323_UserInformation UserInfo;
  3781. *ppEncodedBuf = NULL;
  3782. *pdwEncodedLength = 0;
  3783. memset(&UserInfo, 0, sizeof(H323_UserInformation));
  3784. UserInfo.bit_mask = 0;
  3785. // make sure the user_data_present flag is turned off.
  3786. UserInfo.bit_mask &= (~user_data_present);
  3787. UserInfo.h323_uu_pdu.bit_mask = 0;
  3788. if (pNonStandardData)
  3789. {
  3790. UserInfo.h323_uu_pdu.bit_mask |= H323_UU_PDU_nnStndrdDt_present;
  3791. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.choice
  3792. = H225NonStandardIdentifier_h221NonStandard_chosen;
  3793. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35CountryCode =
  3794. pNonStandardData->bCountryCode;
  3795. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35Extension =
  3796. pNonStandardData->bExtension;
  3797. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.manufacturerCode =
  3798. pNonStandardData->wManufacturerCode;
  3799. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.length =
  3800. pNonStandardData->sData.wOctetStringLength;
  3801. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.value =
  3802. pNonStandardData->sData.pOctetString;
  3803. }
  3804. else
  3805. {
  3806. UserInfo.h323_uu_pdu.bit_mask &= (~H323_UU_PDU_nnStndrdDt_present);
  3807. }
  3808. UserInfo.h323_uu_pdu.h323_message_body.choice = releaseComplete_chosen;
  3809. UserInfo.h323_uu_pdu.h323_message_body.u.releaseComplete.protocolIdentifier = &ProtocolId1;
  3810. if (pbReason)
  3811. {
  3812. unsigned short choice = 0;
  3813. UserInfo.h323_uu_pdu.h323_message_body.u.releaseComplete.bit_mask |=
  3814. (ReleaseComplete_UUIE_reason_present);
  3815. switch (*pbReason)
  3816. {
  3817. case CC_REJECT_NO_BANDWIDTH:
  3818. choice = noBandwidth_chosen;
  3819. break;
  3820. case CC_REJECT_GATEKEEPER_RESOURCES:
  3821. choice = gatekeeperResources_chosen;
  3822. break;
  3823. case CC_REJECT_UNREACHABLE_DESTINATION:
  3824. choice = unreachableDestination_chosen;
  3825. break;
  3826. case CC_REJECT_DESTINATION_REJECTION:
  3827. choice = destinationRejection_chosen;
  3828. break;
  3829. case CC_REJECT_INVALID_REVISION:
  3830. choice = ReleaseCompleteReason_invalidRevision_chosen;
  3831. break;
  3832. case CC_REJECT_NO_PERMISSION:
  3833. choice = noPermission_chosen;
  3834. break;
  3835. case CC_REJECT_UNREACHABLE_GATEKEEPER:
  3836. choice = unreachableGatekeeper_chosen;
  3837. break;
  3838. case CC_REJECT_GATEWAY_RESOURCES:
  3839. choice = gatewayResources_chosen;
  3840. break;
  3841. case CC_REJECT_BAD_FORMAT_ADDRESS:
  3842. choice = badFormatAddress_chosen;
  3843. break;
  3844. case CC_REJECT_ADAPTIVE_BUSY:
  3845. choice = adaptiveBusy_chosen;
  3846. break;
  3847. case CC_REJECT_USER_BUSY:
  3848. case CC_REJECT_IN_CONF:
  3849. choice = inConf_chosen;
  3850. break;
  3851. case CC_REJECT_SECURITY_DENIED:
  3852. choice = securityDenied_chosen;
  3853. break;
  3854. case CC_REJECT_CALL_DEFLECTION:
  3855. choice = facilityCallDeflection_chosen;
  3856. break;
  3857. case CC_REJECT_NORMAL_CALL_CLEARING:// normal = undefined reason
  3858. case CC_REJECT_UNDEFINED_REASON: // internal error = undefined reason
  3859. case CC_REJECT_INTERNAL_ERROR:
  3860. choice = RlsCmpltRsn_undfndRsn_chosen;
  3861. break;
  3862. default:
  3863. return CS_BAD_PARAM;
  3864. break;
  3865. }
  3866. UserInfo.h323_uu_pdu.h323_message_body.u.releaseComplete.reason.choice = choice;
  3867. }
  3868. ASSERT(pCallIdentifier);
  3869. if(pCallIdentifier)
  3870. {
  3871. UserInfo.h323_uu_pdu.h323_message_body.u.releaseComplete.bit_mask |=
  3872. (ReleaseComplete_UUIE_callIdentifier_present);
  3873. memcpy(&UserInfo.h323_uu_pdu.h323_message_body.u.releaseComplete.
  3874. callIdentifier.guid.value, pCallIdentifier,
  3875. sizeof(GUID));
  3876. UserInfo.h323_uu_pdu.h323_message_body.u.releaseComplete.
  3877. callIdentifier.guid.length = sizeof(GUID);
  3878. }
  3879. rc = Q931_Encode(pWorld,
  3880. (void *) &UserInfo,
  3881. H323_UserInformation_PDU,
  3882. ppEncodedBuf,
  3883. pdwEncodedLength);
  3884. if (ASN1_FAILED(rc))
  3885. {
  3886. ASSERT(FALSE);
  3887. return CS_SUBSYSTEM_FAILURE;
  3888. }
  3889. return CS_OK;
  3890. }
  3891. //-------------------------------------------------------------------------------------
  3892. //-------------------------------------------------------------------------------------
  3893. HRESULT
  3894. Q931ConnectEncodeASN(
  3895. PCC_NONSTANDARDDATA pNonStandardData,
  3896. CC_CONFERENCEID *pConferenceID, // must be able to support 16 byte conf id's!
  3897. CC_ADDR *h245Addr,
  3898. PCC_ENDPOINTTYPE pEndpointType,
  3899. ASN1_CODER_INFO *pWorld,
  3900. BYTE **ppEncodedBuf,
  3901. DWORD *pdwEncodedLength,
  3902. LPGUID pCallIdentifier
  3903. )
  3904. {
  3905. int rc;
  3906. H323_UserInformation UserInfo;
  3907. *ppEncodedBuf = NULL;
  3908. *pdwEncodedLength = 0;
  3909. memset(&UserInfo, 0, sizeof(H323_UserInformation));
  3910. UserInfo.bit_mask = 0;
  3911. // make sure the user_data_present flag is turned off.
  3912. UserInfo.bit_mask &= (~user_data_present);
  3913. UserInfo.h323_uu_pdu.bit_mask = 0;
  3914. if (pNonStandardData)
  3915. {
  3916. UserInfo.h323_uu_pdu.bit_mask |= H323_UU_PDU_nnStndrdDt_present;
  3917. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.choice
  3918. = H225NonStandardIdentifier_h221NonStandard_chosen;
  3919. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35CountryCode =
  3920. pNonStandardData->bCountryCode;
  3921. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35Extension =
  3922. pNonStandardData->bExtension;
  3923. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.manufacturerCode =
  3924. pNonStandardData->wManufacturerCode;
  3925. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.length =
  3926. pNonStandardData->sData.wOctetStringLength;
  3927. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.value =
  3928. pNonStandardData->sData.pOctetString;
  3929. }
  3930. else
  3931. {
  3932. UserInfo.h323_uu_pdu.bit_mask &= (~H323_UU_PDU_nnStndrdDt_present);
  3933. }
  3934. UserInfo.h323_uu_pdu.h323_message_body.choice = connect_chosen;
  3935. UserInfo.h323_uu_pdu.h323_message_body.u.connect.protocolIdentifier = &ProtocolId1;
  3936. if (h245Addr != NULL)
  3937. {
  3938. DWORD a = h245Addr->Addr.IP_Binary.dwAddr;
  3939. UserInfo.h323_uu_pdu.h323_message_body.u.connect.Cnnct_UUIE_h245Address.choice = ipAddress_chosen;
  3940. UserInfo.h323_uu_pdu.h323_message_body.u.connect.Cnnct_UUIE_h245Address.u.ipAddress.ip.length = 4;
  3941. UserInfo.h323_uu_pdu.h323_message_body.u.connect.Cnnct_UUIE_h245Address.u.ipAddress.port =
  3942. h245Addr->Addr.IP_Binary.wPort;
  3943. UserInfo.h323_uu_pdu.h323_message_body.u.connect.Cnnct_UUIE_h245Address.u.ipAddress.ip.value[0] =
  3944. ((BYTE *)&a)[3];
  3945. UserInfo.h323_uu_pdu.h323_message_body.u.connect.Cnnct_UUIE_h245Address.u.ipAddress.ip.value[1] =
  3946. ((BYTE *)&a)[2];
  3947. UserInfo.h323_uu_pdu.h323_message_body.u.connect.Cnnct_UUIE_h245Address.u.ipAddress.ip.value[2] =
  3948. ((BYTE *)&a)[1];
  3949. UserInfo.h323_uu_pdu.h323_message_body.u.connect.Cnnct_UUIE_h245Address.u.ipAddress.ip.value[3] =
  3950. ((BYTE *)&a)[0];
  3951. UserInfo.h323_uu_pdu.h323_message_body.u.connect.bit_mask |=
  3952. (Cnnct_UUIE_h245Address_present);
  3953. }
  3954. else
  3955. {
  3956. UserInfo.h323_uu_pdu.h323_message_body.u.connect.bit_mask &=
  3957. (~Cnnct_UUIE_h245Address_present);
  3958. }
  3959. UserInfo.h323_uu_pdu.h323_message_body.u.connect.destinationInfo.bit_mask = 0;
  3960. if (pEndpointType)
  3961. {
  3962. PCC_VENDORINFO pVendorInfo = pEndpointType->pVendorInfo;
  3963. if (pVendorInfo)
  3964. {
  3965. UserInfo.h323_uu_pdu.h323_message_body.u.connect.destinationInfo.bit_mask |= vendor_present;
  3966. UserInfo.h323_uu_pdu.h323_message_body.u.connect.destinationInfo.vendor.bit_mask = 0;
  3967. UserInfo.h323_uu_pdu.h323_message_body.u.connect.destinationInfo.vendor.vendor.t35CountryCode = pVendorInfo->bCountryCode;
  3968. UserInfo.h323_uu_pdu.h323_message_body.u.connect.destinationInfo.vendor.vendor.t35Extension = pVendorInfo->bExtension;
  3969. UserInfo.h323_uu_pdu.h323_message_body.u.connect.destinationInfo.vendor.vendor.manufacturerCode = pVendorInfo->wManufacturerCode;
  3970. if (pVendorInfo->pProductNumber && pVendorInfo->pProductNumber->pOctetString &&
  3971. pVendorInfo->pProductNumber->wOctetStringLength)
  3972. {
  3973. UserInfo.h323_uu_pdu.h323_message_body.u.connect.destinationInfo.vendor.bit_mask |= productId_present;
  3974. UserInfo.h323_uu_pdu.h323_message_body.u.connect.destinationInfo.vendor.productId.length =
  3975. pVendorInfo->pProductNumber->wOctetStringLength;
  3976. memcpy(UserInfo.h323_uu_pdu.h323_message_body.u.connect.destinationInfo.vendor.productId.value,
  3977. pVendorInfo->pProductNumber->pOctetString,
  3978. pVendorInfo->pProductNumber->wOctetStringLength);
  3979. }
  3980. if (pVendorInfo->pVersionNumber && pVendorInfo->pVersionNumber->pOctetString &&
  3981. pVendorInfo->pVersionNumber->wOctetStringLength)
  3982. {
  3983. UserInfo.h323_uu_pdu.h323_message_body.u.connect.destinationInfo.vendor.bit_mask |= versionId_present;
  3984. UserInfo.h323_uu_pdu.h323_message_body.u.connect.destinationInfo.vendor.versionId.length =
  3985. pVendorInfo->pVersionNumber->wOctetStringLength;
  3986. memcpy(UserInfo.h323_uu_pdu.h323_message_body.u.connect.destinationInfo.vendor.versionId.value,
  3987. pVendorInfo->pVersionNumber->pOctetString,
  3988. pVendorInfo->pVersionNumber->wOctetStringLength);
  3989. }
  3990. }
  3991. if (pEndpointType->bIsTerminal)
  3992. {
  3993. UserInfo.h323_uu_pdu.h323_message_body.u.connect.destinationInfo.bit_mask |=
  3994. terminal_present;
  3995. UserInfo.h323_uu_pdu.h323_message_body.u.connect.destinationInfo.terminal.bit_mask = 0;
  3996. }
  3997. if (pEndpointType->bIsGateway)
  3998. {
  3999. UserInfo.h323_uu_pdu.h323_message_body.u.connect.destinationInfo.bit_mask |=
  4000. gateway_present;
  4001. UserInfo.h323_uu_pdu.h323_message_body.u.connect.destinationInfo.gateway.bit_mask = protocol_present;
  4002. UserInfo.h323_uu_pdu.h323_message_body.u.connect.destinationInfo.gateway.protocol = &TempProtocol;
  4003. }
  4004. }
  4005. UserInfo.h323_uu_pdu.h323_message_body.u.connect.destinationInfo.mc = 0;
  4006. UserInfo.h323_uu_pdu.h323_message_body.u.connect.destinationInfo.undefinedNode = 0;
  4007. if (pConferenceID != NULL)
  4008. {
  4009. UserInfo.h323_uu_pdu.h323_message_body.u.connect.conferenceID.length =
  4010. sizeof(UserInfo.h323_uu_pdu.h323_message_body.u.connect.conferenceID.value);
  4011. memcpy(UserInfo.h323_uu_pdu.h323_message_body.u.connect.conferenceID.value,
  4012. pConferenceID->buffer,
  4013. UserInfo.h323_uu_pdu.h323_message_body.u.connect.conferenceID.length);
  4014. }
  4015. ASSERT(pCallIdentifier);
  4016. if(pCallIdentifier)
  4017. {
  4018. UserInfo.h323_uu_pdu.h323_message_body.u.connect.bit_mask |=
  4019. (Connect_UUIE_callIdentifier_present);
  4020. memcpy(&UserInfo.h323_uu_pdu.h323_message_body.u.connect.
  4021. callIdentifier.guid.value, pCallIdentifier,
  4022. sizeof(GUID));
  4023. UserInfo.h323_uu_pdu.h323_message_body.u.connect.
  4024. callIdentifier.guid.length = sizeof(GUID);
  4025. }
  4026. rc = Q931_Encode(pWorld,
  4027. (void *) &UserInfo,
  4028. H323_UserInformation_PDU,
  4029. ppEncodedBuf,
  4030. pdwEncodedLength);
  4031. if (ASN1_FAILED(rc))
  4032. {
  4033. ASSERT(FALSE);
  4034. return CS_SUBSYSTEM_FAILURE;
  4035. }
  4036. return CS_OK;
  4037. }
  4038. //-------------------------------------------------------------------------------------
  4039. //-------------------------------------------------------------------------------------
  4040. HRESULT
  4041. Q931AlertingEncodeASN(
  4042. PCC_NONSTANDARDDATA pNonStandardData,
  4043. CC_ADDR *h245Addr,
  4044. PCC_ENDPOINTTYPE pEndpointType,
  4045. ASN1_CODER_INFO *pWorld,
  4046. BYTE **ppEncodedBuf,
  4047. DWORD *pdwEncodedLength,
  4048. LPGUID pCallIdentifier)
  4049. {
  4050. int rc;
  4051. H323_UserInformation UserInfo;
  4052. *ppEncodedBuf = NULL;
  4053. *pdwEncodedLength = 0;
  4054. memset(&UserInfo, 0, sizeof(H323_UserInformation));
  4055. UserInfo.bit_mask = 0;
  4056. // make sure the user_data_present flag is turned off.
  4057. UserInfo.bit_mask &= (~user_data_present);
  4058. UserInfo.h323_uu_pdu.bit_mask = 0;
  4059. if (pNonStandardData)
  4060. {
  4061. UserInfo.h323_uu_pdu.bit_mask |= H323_UU_PDU_nnStndrdDt_present;
  4062. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.choice
  4063. = H225NonStandardIdentifier_h221NonStandard_chosen;
  4064. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35CountryCode =
  4065. pNonStandardData->bCountryCode;
  4066. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35Extension =
  4067. pNonStandardData->bExtension;
  4068. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.manufacturerCode =
  4069. pNonStandardData->wManufacturerCode;
  4070. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.length =
  4071. pNonStandardData->sData.wOctetStringLength;
  4072. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.value =
  4073. pNonStandardData->sData.pOctetString;
  4074. }
  4075. else
  4076. {
  4077. UserInfo.h323_uu_pdu.bit_mask &= (~H323_UU_PDU_nnStndrdDt_present);
  4078. }
  4079. UserInfo.h323_uu_pdu.h323_message_body.choice = alerting_chosen;
  4080. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.protocolIdentifier = &ProtocolId1;
  4081. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.destinationInfo.bit_mask = 0;
  4082. if (pEndpointType)
  4083. {
  4084. PCC_VENDORINFO pVendorInfo = pEndpointType->pVendorInfo;
  4085. if (pVendorInfo)
  4086. {
  4087. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.destinationInfo.bit_mask |= vendor_present;
  4088. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.destinationInfo.vendor.bit_mask = 0;
  4089. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.destinationInfo.vendor.vendor.t35CountryCode = pVendorInfo->bCountryCode;
  4090. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.destinationInfo.vendor.vendor.t35Extension = pVendorInfo->bExtension;
  4091. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.destinationInfo.vendor.vendor.manufacturerCode = pVendorInfo->wManufacturerCode;
  4092. if (pVendorInfo->pProductNumber && pVendorInfo->pProductNumber->pOctetString &&
  4093. pVendorInfo->pProductNumber->wOctetStringLength)
  4094. {
  4095. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.destinationInfo.vendor.bit_mask |= productId_present;
  4096. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.destinationInfo.vendor.productId.length =
  4097. pVendorInfo->pProductNumber->wOctetStringLength;
  4098. memcpy(UserInfo.h323_uu_pdu.h323_message_body.u.alerting.destinationInfo.vendor.productId.value,
  4099. pVendorInfo->pProductNumber->pOctetString,
  4100. pVendorInfo->pProductNumber->wOctetStringLength);
  4101. }
  4102. if (pVendorInfo->pVersionNumber && pVendorInfo->pVersionNumber->pOctetString &&
  4103. pVendorInfo->pVersionNumber->wOctetStringLength)
  4104. {
  4105. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.destinationInfo.vendor.bit_mask |= versionId_present;
  4106. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.destinationInfo.vendor.versionId.length =
  4107. pVendorInfo->pVersionNumber->wOctetStringLength;
  4108. memcpy(UserInfo.h323_uu_pdu.h323_message_body.u.alerting.destinationInfo.vendor.versionId.value,
  4109. pVendorInfo->pVersionNumber->pOctetString,
  4110. pVendorInfo->pVersionNumber->wOctetStringLength);
  4111. }
  4112. }
  4113. if (pEndpointType->bIsTerminal)
  4114. {
  4115. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.destinationInfo.bit_mask =
  4116. terminal_present;
  4117. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.destinationInfo.terminal.bit_mask = 0;
  4118. }
  4119. if (pEndpointType->bIsGateway)
  4120. {
  4121. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.destinationInfo.bit_mask =
  4122. gateway_present;
  4123. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.destinationInfo.gateway.bit_mask = protocol_present;
  4124. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.destinationInfo.gateway.protocol = &TempProtocol;
  4125. }
  4126. }
  4127. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.destinationInfo.mc = 0;
  4128. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.destinationInfo.undefinedNode = 0;
  4129. if (h245Addr != NULL)
  4130. {
  4131. DWORD a = h245Addr->Addr.IP_Binary.dwAddr;
  4132. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.CPg_UUIE_h245Addrss.choice = ipAddress_chosen;
  4133. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.CPg_UUIE_h245Addrss.u.ipAddress.ip.length = 4;
  4134. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.CPg_UUIE_h245Addrss.u.ipAddress.port =
  4135. h245Addr->Addr.IP_Binary.wPort;
  4136. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.CPg_UUIE_h245Addrss.u.ipAddress.ip.value[0] =
  4137. ((BYTE *)&a)[3];
  4138. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.CPg_UUIE_h245Addrss.u.ipAddress.ip.value[1] =
  4139. ((BYTE *)&a)[2];
  4140. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.CPg_UUIE_h245Addrss.u.ipAddress.ip.value[2] =
  4141. ((BYTE *)&a)[1];
  4142. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.CPg_UUIE_h245Addrss.u.ipAddress.ip.value[3] =
  4143. ((BYTE *)&a)[0];
  4144. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.bit_mask |=
  4145. (CPg_UUIE_h245Addrss_present);
  4146. }
  4147. else
  4148. {
  4149. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.bit_mask &=
  4150. (~CPg_UUIE_h245Addrss_present);
  4151. }
  4152. ASSERT(pCallIdentifier);
  4153. if(pCallIdentifier)
  4154. {
  4155. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.bit_mask |=
  4156. (Alerting_UUIE_callIdentifier_present);
  4157. memcpy(&UserInfo.h323_uu_pdu.h323_message_body.u.alerting.
  4158. callIdentifier.guid.value, pCallIdentifier,
  4159. sizeof(GUID));
  4160. UserInfo.h323_uu_pdu.h323_message_body.u.alerting.
  4161. callIdentifier.guid.length = sizeof(GUID);
  4162. }
  4163. rc = Q931_Encode(pWorld,
  4164. (void *) &UserInfo,
  4165. H323_UserInformation_PDU,
  4166. ppEncodedBuf,
  4167. pdwEncodedLength);
  4168. if (ASN1_FAILED(rc))
  4169. {
  4170. ASSERT(FALSE);
  4171. return CS_SUBSYSTEM_FAILURE;
  4172. }
  4173. return CS_OK;
  4174. }
  4175. //-------------------------------------------------------------------------------------
  4176. //-------------------------------------------------------------------------------------
  4177. HRESULT
  4178. Q931ProceedingEncodeASN(
  4179. PCC_NONSTANDARDDATA pNonStandardData,
  4180. CC_ADDR *h245Addr,
  4181. PCC_ENDPOINTTYPE pEndpointType,
  4182. ASN1_CODER_INFO *pWorld,
  4183. BYTE **ppEncodedBuf,
  4184. DWORD *pdwEncodedLength,
  4185. LPGUID pCallIdentifier)
  4186. {
  4187. int rc;
  4188. H323_UserInformation UserInfo;
  4189. *ppEncodedBuf = NULL;
  4190. *pdwEncodedLength = 0;
  4191. memset(&UserInfo, 0, sizeof(H323_UserInformation));
  4192. UserInfo.bit_mask = 0;
  4193. // make sure the user_data_present flag is turned off.
  4194. UserInfo.bit_mask &= (~user_data_present);
  4195. UserInfo.h323_uu_pdu.bit_mask = 0;
  4196. if (pNonStandardData)
  4197. {
  4198. UserInfo.h323_uu_pdu.bit_mask |= H323_UU_PDU_nnStndrdDt_present;
  4199. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.choice
  4200. = H225NonStandardIdentifier_h221NonStandard_chosen;
  4201. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35CountryCode =
  4202. pNonStandardData->bCountryCode;
  4203. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35Extension =
  4204. pNonStandardData->bExtension;
  4205. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.manufacturerCode =
  4206. pNonStandardData->wManufacturerCode;
  4207. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.length =
  4208. pNonStandardData->sData.wOctetStringLength;
  4209. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.value =
  4210. pNonStandardData->sData.pOctetString;
  4211. }
  4212. else
  4213. {
  4214. UserInfo.h323_uu_pdu.bit_mask &= (~H323_UU_PDU_nnStndrdDt_present);
  4215. }
  4216. UserInfo.h323_uu_pdu.h323_message_body.choice = callProceeding_chosen;
  4217. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.protocolIdentifier = &ProtocolId1;
  4218. if (h245Addr != NULL)
  4219. {
  4220. DWORD a = h245Addr->Addr.IP_Binary.dwAddr;
  4221. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.CPg_UUIE_h245Addrss.choice = ipAddress_chosen;
  4222. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.CPg_UUIE_h245Addrss.u.ipAddress.ip.length = 4;
  4223. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.CPg_UUIE_h245Addrss.u.ipAddress.port =
  4224. h245Addr->Addr.IP_Binary.wPort;
  4225. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.CPg_UUIE_h245Addrss.u.ipAddress.ip.value[0] =
  4226. ((BYTE *)&a)[3];
  4227. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.CPg_UUIE_h245Addrss.u.ipAddress.ip.value[1] =
  4228. ((BYTE *)&a)[2];
  4229. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.CPg_UUIE_h245Addrss.u.ipAddress.ip.value[2] =
  4230. ((BYTE *)&a)[1];
  4231. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.CPg_UUIE_h245Addrss.u.ipAddress.ip.value[3] =
  4232. ((BYTE *)&a)[0];
  4233. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.bit_mask |=
  4234. (CPg_UUIE_h245Addrss_present);
  4235. }
  4236. else
  4237. {
  4238. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.bit_mask &=
  4239. (~CPg_UUIE_h245Addrss_present);
  4240. }
  4241. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.destinationInfo.bit_mask = 0;
  4242. if (pEndpointType)
  4243. {
  4244. PCC_VENDORINFO pVendorInfo = pEndpointType->pVendorInfo;
  4245. if (pVendorInfo)
  4246. {
  4247. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.destinationInfo.bit_mask |= vendor_present;
  4248. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.destinationInfo.vendor.bit_mask = 0;
  4249. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.destinationInfo.vendor.vendor.t35CountryCode = pVendorInfo->bCountryCode;
  4250. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.destinationInfo.vendor.vendor.t35Extension = pVendorInfo->bExtension;
  4251. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.destinationInfo.vendor.vendor.manufacturerCode = pVendorInfo->wManufacturerCode;
  4252. if (pVendorInfo->pProductNumber && pVendorInfo->pProductNumber->pOctetString &&
  4253. pVendorInfo->pProductNumber->wOctetStringLength)
  4254. {
  4255. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.destinationInfo.vendor.bit_mask |= productId_present;
  4256. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.destinationInfo.vendor.productId.length =
  4257. pVendorInfo->pProductNumber->wOctetStringLength;
  4258. memcpy(UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.destinationInfo.vendor.productId.value,
  4259. pVendorInfo->pProductNumber->pOctetString,
  4260. pVendorInfo->pProductNumber->wOctetStringLength);
  4261. }
  4262. if (pVendorInfo->pVersionNumber && pVendorInfo->pVersionNumber->pOctetString &&
  4263. pVendorInfo->pVersionNumber->wOctetStringLength)
  4264. {
  4265. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.destinationInfo.vendor.bit_mask |= versionId_present;
  4266. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.destinationInfo.vendor.versionId.length =
  4267. pVendorInfo->pVersionNumber->wOctetStringLength;
  4268. memcpy(UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.destinationInfo.vendor.versionId.value,
  4269. pVendorInfo->pVersionNumber->pOctetString,
  4270. pVendorInfo->pVersionNumber->wOctetStringLength);
  4271. }
  4272. }
  4273. if (pEndpointType->bIsTerminal)
  4274. {
  4275. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.destinationInfo.bit_mask =
  4276. terminal_present;
  4277. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.destinationInfo.terminal.bit_mask = 0;
  4278. }
  4279. if (pEndpointType->bIsGateway)
  4280. {
  4281. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.destinationInfo.bit_mask =
  4282. gateway_present;
  4283. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.destinationInfo.gateway.bit_mask = protocol_present;
  4284. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.destinationInfo.gateway.protocol = &TempProtocol;
  4285. }
  4286. }
  4287. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.destinationInfo.mc = 0;
  4288. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.destinationInfo.undefinedNode = 0;
  4289. ASSERT(pCallIdentifier);
  4290. if(pCallIdentifier)
  4291. {
  4292. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.bit_mask |=
  4293. (CallProceeding_UUIE_callIdentifier_present);
  4294. memcpy(&UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.
  4295. callIdentifier.guid.value, pCallIdentifier,
  4296. sizeof(GUID));
  4297. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding.
  4298. callIdentifier.guid.length = sizeof(GUID);
  4299. }
  4300. rc = Q931_Encode(pWorld,
  4301. (void *) &UserInfo,
  4302. H323_UserInformation_PDU,
  4303. ppEncodedBuf,
  4304. pdwEncodedLength);
  4305. if (ASN1_FAILED(rc))
  4306. {
  4307. ASSERT(FALSE);
  4308. return CS_SUBSYSTEM_FAILURE;
  4309. }
  4310. return CS_OK;
  4311. }
  4312. //-------------------------------------------------------------------------------------
  4313. //-------------------------------------------------------------------------------------
  4314. HRESULT
  4315. Q931FacilityEncodeASN(
  4316. PCC_NONSTANDARDDATA pNonStandardData,
  4317. CC_ADDR *AlternativeAddr,
  4318. BYTE bReason,
  4319. CC_CONFERENCEID *pConferenceID,
  4320. PCC_ALIASNAMES pAlternativeAliasList,
  4321. ASN1_CODER_INFO *pWorld,
  4322. BYTE **ppEncodedBuf,
  4323. DWORD *pdwEncodedLength,
  4324. LPGUID pCallIdentifier)
  4325. {
  4326. int rc;
  4327. H323_UserInformation UserInfo;
  4328. *ppEncodedBuf = NULL;
  4329. *pdwEncodedLength = 0;
  4330. memset(&UserInfo, 0, sizeof(H323_UserInformation));
  4331. UserInfo.bit_mask = 0;
  4332. // make sure the user_data_present flag is turned off.
  4333. UserInfo.bit_mask &= (~user_data_present);
  4334. if (pNonStandardData)
  4335. {
  4336. UserInfo.h323_uu_pdu.bit_mask |= H323_UU_PDU_nnStndrdDt_present;
  4337. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.choice
  4338. = H225NonStandardIdentifier_h221NonStandard_chosen;
  4339. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35CountryCode =
  4340. pNonStandardData->bCountryCode;
  4341. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35Extension =
  4342. pNonStandardData->bExtension;
  4343. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.manufacturerCode =
  4344. pNonStandardData->wManufacturerCode;
  4345. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.length =
  4346. pNonStandardData->sData.wOctetStringLength;
  4347. UserInfo.h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.value =
  4348. pNonStandardData->sData.pOctetString;
  4349. }
  4350. else
  4351. {
  4352. UserInfo.h323_uu_pdu.bit_mask &= (~H323_UU_PDU_nnStndrdDt_present);
  4353. }
  4354. UserInfo.h323_uu_pdu.h323_message_body.choice = facility_chosen;
  4355. UserInfo.h323_uu_pdu.h323_message_body.u.facility.protocolIdentifier = &ProtocolId1;
  4356. if (AlternativeAddr != NULL)
  4357. {
  4358. DWORD a = AlternativeAddr->Addr.IP_Binary.dwAddr;
  4359. UserInfo.h323_uu_pdu.h323_message_body.u.facility.alternativeAddress.choice = ipAddress_chosen;
  4360. UserInfo.h323_uu_pdu.h323_message_body.u.facility.alternativeAddress.u.ipAddress.ip.length = 4;
  4361. UserInfo.h323_uu_pdu.h323_message_body.u.facility.alternativeAddress.u.ipAddress.port =
  4362. AlternativeAddr->Addr.IP_Binary.wPort;
  4363. UserInfo.h323_uu_pdu.h323_message_body.u.facility.alternativeAddress.u.ipAddress.ip.value[0] =
  4364. ((BYTE *)&a)[3];
  4365. UserInfo.h323_uu_pdu.h323_message_body.u.facility.alternativeAddress.u.ipAddress.ip.value[1] =
  4366. ((BYTE *)&a)[2];
  4367. UserInfo.h323_uu_pdu.h323_message_body.u.facility.alternativeAddress.u.ipAddress.ip.value[2] =
  4368. ((BYTE *)&a)[1];
  4369. UserInfo.h323_uu_pdu.h323_message_body.u.facility.alternativeAddress.u.ipAddress.ip.value[3] =
  4370. ((BYTE *)&a)[0];
  4371. UserInfo.h323_uu_pdu.h323_message_body.u.facility.bit_mask |=
  4372. (alternativeAddress_present);
  4373. }
  4374. else
  4375. {
  4376. UserInfo.h323_uu_pdu.h323_message_body.u.facility.bit_mask &=
  4377. (~alternativeAddress_present);
  4378. }
  4379. if (pAlternativeAliasList)
  4380. {
  4381. CS_STATUS AliasResult = CS_OK;
  4382. AliasResult = AliasToSeqof((struct Setup_UUIE_sourceAddress **)&(UserInfo.h323_uu_pdu.
  4383. h323_message_body.u.facility.alternativeAliasAddress), pAlternativeAliasList);
  4384. if (AliasResult != CS_OK)
  4385. {
  4386. return CS_NO_MEMORY;
  4387. }
  4388. UserInfo.h323_uu_pdu.h323_message_body.u.facility.bit_mask |=
  4389. (alternativeAliasAddress_present);
  4390. }
  4391. else
  4392. {
  4393. UserInfo.h323_uu_pdu.h323_message_body.u.facility.bit_mask &=
  4394. (~alternativeAliasAddress_present);
  4395. }
  4396. if (pConferenceID != NULL)
  4397. {
  4398. UserInfo.h323_uu_pdu.h323_message_body.u.facility.conferenceID.length =
  4399. sizeof(UserInfo.h323_uu_pdu.h323_message_body.u.facility.conferenceID.value);
  4400. memcpy(UserInfo.h323_uu_pdu.h323_message_body.u.facility.conferenceID.value,
  4401. pConferenceID->buffer,
  4402. UserInfo.h323_uu_pdu.h323_message_body.u.facility.conferenceID.length);
  4403. UserInfo.h323_uu_pdu.h323_message_body.u.facility.bit_mask |=
  4404. (Facility_UUIE_conferenceID_present);
  4405. }
  4406. else
  4407. {
  4408. UserInfo.h323_uu_pdu.h323_message_body.u.facility.bit_mask &=
  4409. (~Facility_UUIE_conferenceID_present);
  4410. }
  4411. switch (bReason)
  4412. {
  4413. case CC_REJECT_ROUTE_TO_GATEKEEPER:
  4414. UserInfo.h323_uu_pdu.h323_message_body.u.facility.reason.choice
  4415. = FacilityReason_routeCallToGatekeeper_chosen;
  4416. break;
  4417. case CC_REJECT_CALL_FORWARDED:
  4418. UserInfo.h323_uu_pdu.h323_message_body.u.facility.reason.choice
  4419. = callForwarded_chosen;
  4420. break;
  4421. case CC_REJECT_ROUTE_TO_MC:
  4422. UserInfo.h323_uu_pdu.h323_message_body.u.facility.reason.choice
  4423. = routeCallToMC_chosen;
  4424. break;
  4425. default:
  4426. UserInfo.h323_uu_pdu.h323_message_body.u.facility.reason.choice
  4427. = RlsCmpltRsn_undfndRsn_chosen;
  4428. } // switch
  4429. ASSERT(pCallIdentifier);
  4430. if(pCallIdentifier)
  4431. {
  4432. UserInfo.h323_uu_pdu.h323_message_body.u.facility.bit_mask |=
  4433. (Facility_UUIE_callIdentifier_present);
  4434. memcpy(&UserInfo.h323_uu_pdu.h323_message_body.u.facility.
  4435. callIdentifier.guid.value, pCallIdentifier,
  4436. sizeof(GUID));
  4437. UserInfo.h323_uu_pdu.h323_message_body.u.facility.
  4438. callIdentifier.guid.length = sizeof(GUID);
  4439. }
  4440. rc = Q931_Encode(pWorld,
  4441. (void *) &UserInfo,
  4442. H323_UserInformation_PDU,
  4443. ppEncodedBuf,
  4444. pdwEncodedLength);
  4445. // Free the alias name structures from the UserInfo area.
  4446. FreeSeqof((struct Setup_UUIE_sourceAddress *)UserInfo.h323_uu_pdu.h323_message_body.u.
  4447. facility.alternativeAliasAddress);
  4448. if (ASN1_FAILED(rc))
  4449. {
  4450. ASSERT(FALSE);
  4451. return CS_SUBSYSTEM_FAILURE;
  4452. }
  4453. return CS_OK;
  4454. }
  4455. //------------------------------------------------------------------------
  4456. //------------------------------------------------------------------------
  4457. BOOL
  4458. Q931ValidPduVersion(struct ObjectID_ *id)
  4459. {
  4460. // not sure what version checking to put here
  4461. #if 0
  4462. if ((id != NULL) && (id->value == 0) && (id->next != NULL) && (id->next->value <= 1))
  4463. {
  4464. return TRUE;
  4465. }
  4466. return FALSE;
  4467. #else
  4468. return TRUE;
  4469. #endif
  4470. }
  4471. //------------------------------------------------------------------------
  4472. //------------------------------------------------------------------------
  4473. HRESULT
  4474. Q931SetupParseASN(
  4475. ASN1_CODER_INFO *pWorld,
  4476. BYTE *pEncodedBuf,
  4477. DWORD dwEncodedLength,
  4478. Q931_SETUP_ASN *pParsedData)
  4479. {
  4480. int PDU = H323_UserInformation_PDU;
  4481. char *pDecodedBuf = NULL;
  4482. H323_UserInformation *pUserInfo;
  4483. struct ObjectID_ *id;
  4484. int Result;
  4485. if (pParsedData == NULL)
  4486. {
  4487. return CS_BAD_PARAM;
  4488. }
  4489. Result = Q931_Decode(pWorld,
  4490. (void **) &pDecodedBuf,
  4491. PDU,
  4492. pEncodedBuf,
  4493. dwEncodedLength);
  4494. if (ASN1_FAILED(Result) || (pDecodedBuf == NULL))
  4495. {
  4496. ASSERT(FALSE);
  4497. // trace and return an decoding error of some sort.
  4498. // Note: some values of Result should cause CS_SUBSYSTEM_FAILURE return.
  4499. return CS_BAD_PARAM;
  4500. }
  4501. // validate some basic things about the PDU...
  4502. pUserInfo = (H323_UserInformation *)pDecodedBuf;
  4503. // validate that this is a H323 PDU.
  4504. if (PDU != H323_UserInformation_PDU)
  4505. {
  4506. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4507. return CS_BAD_PARAM;
  4508. }
  4509. // validate that the PDU user-data uses ASN encoding.
  4510. if (((pUserInfo->bit_mask & user_data_present) != 0) &&
  4511. (pUserInfo->user_data.protocol_discriminator != USE_ASN1_ENCODING))
  4512. {
  4513. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4514. return CS_BAD_PARAM;
  4515. }
  4516. // validate that the PDU is H323 Setup information.
  4517. if (pUserInfo->h323_uu_pdu.h323_message_body.choice != setup_chosen)
  4518. {
  4519. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4520. return CS_BAD_PARAM;
  4521. }
  4522. id = pUserInfo->h323_uu_pdu.h323_message_body.u.setup.protocolIdentifier;
  4523. if (!Q931ValidPduVersion(id))
  4524. {
  4525. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4526. return CS_INCOMPATIBLE_VERSION;
  4527. }
  4528. // make sure that the conference id is formed correctly.
  4529. if (pUserInfo->h323_uu_pdu.h323_message_body.u.setup.conferenceID.length >
  4530. sizeof(pUserInfo->h323_uu_pdu.h323_message_body.u.setup.conferenceID.value))
  4531. {
  4532. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4533. return CS_BAD_PARAM;
  4534. }
  4535. #if 0
  4536. if (pUserInfo->h323_uu_pdu.h323_message_body.u.setup.conferenceGoal.choice != create_chosen)
  4537. {
  4538. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4539. return CS_OPTION_NOT_IMPLEMENTED;
  4540. }
  4541. if (pUserInfo->h323_uu_pdu.h323_message_body.u.setup.callType.choice != pointToPoint_chosen)
  4542. {
  4543. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4544. return CS_OPTION_NOT_IMPLEMENTED;
  4545. }
  4546. #endif
  4547. // parse the message contained in pUserInfo.
  4548. memset(pParsedData, 0, sizeof(Q931_SETUP_ASN));
  4549. pParsedData->SourceAddr.bMulticast = FALSE;
  4550. pParsedData->CallerAddr.bMulticast = FALSE;
  4551. pParsedData->CalleeDestAddr.bMulticast = FALSE;
  4552. pParsedData->CalleeAddr.bMulticast = FALSE;
  4553. // no validation of sourceInfo needed.
  4554. pParsedData->EndpointType.pVendorInfo = NULL;
  4555. if (pUserInfo->h323_uu_pdu.h323_message_body.u.setup.sourceInfo.bit_mask & (vendor_present))
  4556. {
  4557. pParsedData->EndpointType.pVendorInfo = &(pParsedData->VendorInfo);
  4558. pParsedData->VendorInfo.bCountryCode =
  4559. (BYTE)pUserInfo->h323_uu_pdu.h323_message_body.u.setup.sourceInfo.vendor.vendor.t35CountryCode;
  4560. pParsedData->VendorInfo.bExtension =
  4561. (BYTE)pUserInfo->h323_uu_pdu.h323_message_body.u.setup.sourceInfo.vendor.vendor.t35Extension;
  4562. pParsedData->VendorInfo.wManufacturerCode =
  4563. pUserInfo->h323_uu_pdu.h323_message_body.u.setup.sourceInfo.vendor.vendor.manufacturerCode;
  4564. if (pUserInfo->h323_uu_pdu.h323_message_body.u.setup.sourceInfo.vendor.bit_mask & (productId_present))
  4565. {
  4566. pParsedData->VendorInfo.pProductNumber = MemAlloc(sizeof(CC_OCTETSTRING));
  4567. if (pParsedData->VendorInfo.pProductNumber == NULL)
  4568. {
  4569. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4570. return CS_NO_MEMORY;
  4571. }
  4572. pParsedData->VendorInfo.pProductNumber->wOctetStringLength = (WORD)
  4573. min(pUserInfo->h323_uu_pdu.h323_message_body.u.setup.sourceInfo.vendor.productId.length,
  4574. CC_MAX_PRODUCT_LENGTH - 1);
  4575. memcpy(pParsedData->bufProductValue,
  4576. pUserInfo->h323_uu_pdu.h323_message_body.u.setup.sourceInfo.vendor.productId.value,
  4577. pParsedData->VendorInfo.pProductNumber->wOctetStringLength);
  4578. pParsedData->bufProductValue[pParsedData->VendorInfo.pProductNumber->wOctetStringLength] = '\0';
  4579. pParsedData->VendorInfo.pProductNumber->pOctetString = pParsedData->bufProductValue;
  4580. }
  4581. if (pUserInfo->h323_uu_pdu.h323_message_body.u.setup.sourceInfo.vendor.bit_mask & (versionId_present))
  4582. {
  4583. pParsedData->VendorInfo.pVersionNumber = MemAlloc(sizeof(CC_OCTETSTRING));
  4584. if (pParsedData->VendorInfo.pVersionNumber == NULL)
  4585. {
  4586. MemFree(pParsedData->VendorInfo.pProductNumber);
  4587. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4588. return CS_NO_MEMORY;
  4589. }
  4590. pParsedData->VendorInfo.pVersionNumber->wOctetStringLength = (WORD)
  4591. min(pUserInfo->h323_uu_pdu.h323_message_body.u.setup.sourceInfo.vendor.versionId.length,
  4592. CC_MAX_VERSION_LENGTH - 1);
  4593. memcpy(pParsedData->bufVersionValue,
  4594. pUserInfo->h323_uu_pdu.h323_message_body.u.setup.sourceInfo.vendor.versionId.value,
  4595. pParsedData->VendorInfo.pVersionNumber->wOctetStringLength);
  4596. pParsedData->bufVersionValue[pParsedData->VendorInfo.pVersionNumber->wOctetStringLength] = '\0';
  4597. pParsedData->VendorInfo.pVersionNumber->pOctetString = pParsedData->bufVersionValue;
  4598. }
  4599. }
  4600. pParsedData->EndpointType.bIsTerminal = FALSE;
  4601. if (pUserInfo->h323_uu_pdu.h323_message_body.u.setup.sourceInfo.bit_mask & (terminal_present))
  4602. {
  4603. pParsedData->EndpointType.bIsTerminal = TRUE;
  4604. }
  4605. pParsedData->EndpointType.bIsGateway = FALSE;
  4606. if (pUserInfo->h323_uu_pdu.h323_message_body.u.setup.sourceInfo.bit_mask & (gateway_present))
  4607. {
  4608. pParsedData->EndpointType.bIsGateway = TRUE;
  4609. }
  4610. if ((pUserInfo->h323_uu_pdu.bit_mask & H323_UU_PDU_nnStndrdDt_present) != 0)
  4611. {
  4612. pParsedData->NonStandardDataPresent = TRUE;
  4613. if (pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.choice
  4614. == H225NonStandardIdentifier_h221NonStandard_chosen)
  4615. {
  4616. pParsedData->NonStandardData.bCountryCode =
  4617. (BYTE)(pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35CountryCode);
  4618. pParsedData->NonStandardData.bExtension =
  4619. (BYTE)(pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35Extension);
  4620. pParsedData->NonStandardData.wManufacturerCode =
  4621. pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.manufacturerCode;
  4622. }
  4623. pParsedData->NonStandardData.sData.wOctetStringLength = (WORD)
  4624. pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.length;
  4625. pParsedData->NonStandardData.sData.pOctetString =
  4626. (BYTE *)MemAlloc(pParsedData->NonStandardData.sData.wOctetStringLength);
  4627. if (pParsedData->NonStandardData.sData.pOctetString == NULL)
  4628. {
  4629. MemFree(pParsedData->VendorInfo.pProductNumber);
  4630. MemFree(pParsedData->VendorInfo.pVersionNumber);
  4631. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4632. return CS_NO_MEMORY;
  4633. }
  4634. memcpy(pParsedData->NonStandardData.sData.pOctetString,
  4635. pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.value,
  4636. pParsedData->NonStandardData.sData.wOctetStringLength);
  4637. }
  4638. else
  4639. {
  4640. pParsedData->NonStandardDataPresent = FALSE;
  4641. }
  4642. //RMO. ignore the h245 address.
  4643. {
  4644. CS_STATUS AliasResult = CS_OK;
  4645. // parse the sourceAddress aliases here...
  4646. AliasResult = SeqofToAlias(&(pParsedData->pCallerAliasList),
  4647. (struct Setup_UUIE_sourceAddress *)pUserInfo->h323_uu_pdu.h323_message_body.u.setup.sourceAddress);
  4648. if (AliasResult != CS_OK)
  4649. {
  4650. if (pParsedData->NonStandardData.sData.pOctetString != NULL)
  4651. MemFree(pParsedData->NonStandardData.sData.pOctetString);
  4652. MemFree(pParsedData->VendorInfo.pProductNumber);
  4653. MemFree(pParsedData->VendorInfo.pVersionNumber);
  4654. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4655. return CS_NO_MEMORY;
  4656. }
  4657. // parse the destinationAddress aliases here...
  4658. AliasResult = SeqofToAlias(&(pParsedData->pCalleeAliasList),
  4659. (struct Setup_UUIE_sourceAddress *)pUserInfo->h323_uu_pdu.h323_message_body.u.setup.destinationAddress);
  4660. if (AliasResult != CS_OK)
  4661. {
  4662. Q931FreeAliasNames(pParsedData->pCallerAliasList);
  4663. if (pParsedData->NonStandardData.sData.pOctetString != NULL)
  4664. MemFree(pParsedData->NonStandardData.sData.pOctetString);
  4665. pParsedData->pCallerAliasList = NULL;
  4666. MemFree(pParsedData->VendorInfo.pProductNumber);
  4667. MemFree(pParsedData->VendorInfo.pVersionNumber);
  4668. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4669. return CS_NO_MEMORY;
  4670. }
  4671. // parse the destExtraCallInfo aliases here...
  4672. AliasResult = SeqofToAlias(&(pParsedData->pExtraAliasList),
  4673. (struct Setup_UUIE_sourceAddress *)pUserInfo->h323_uu_pdu.h323_message_body.u.setup.destExtraCallInfo);
  4674. if (AliasResult != CS_OK)
  4675. {
  4676. Q931FreeAliasNames(pParsedData->pCalleeAliasList);
  4677. Q931FreeAliasNames(pParsedData->pCallerAliasList);
  4678. if (pParsedData->NonStandardData.sData.pOctetString != NULL)
  4679. MemFree(pParsedData->NonStandardData.sData.pOctetString);
  4680. pParsedData->pCallerAliasList = NULL;
  4681. MemFree(pParsedData->VendorInfo.pProductNumber);
  4682. MemFree(pParsedData->VendorInfo.pVersionNumber);
  4683. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4684. return CS_NO_MEMORY;
  4685. }
  4686. // parse the remoteExtensionAddress aliases here...
  4687. if ((pUserInfo->h323_uu_pdu.h323_message_body.u.setup.bit_mask &
  4688. Setup_UUIE_remoteExtensionAddress_present) != 0)
  4689. {
  4690. AliasResult = Q931AliasAddrToAliasItem(&(pParsedData->pExtensionAliasItem),
  4691. &(pUserInfo->h323_uu_pdu.h323_message_body.u.setup.remoteExtensionAddress));
  4692. if (AliasResult != CS_OK)
  4693. {
  4694. Q931FreeAliasNames(pParsedData->pExtraAliasList);
  4695. Q931FreeAliasNames(pParsedData->pCalleeAliasList);
  4696. Q931FreeAliasNames(pParsedData->pCallerAliasList);
  4697. pParsedData->pCallerAliasList = NULL;
  4698. if (pParsedData->NonStandardData.sData.pOctetString != NULL)
  4699. MemFree(pParsedData->NonStandardData.sData.pOctetString);
  4700. MemFree(pParsedData->VendorInfo.pProductNumber);
  4701. MemFree(pParsedData->VendorInfo.pVersionNumber);
  4702. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4703. return CS_NO_MEMORY;
  4704. }
  4705. }
  4706. }
  4707. if ((pUserInfo->h323_uu_pdu.h323_message_body.u.setup.bit_mask &
  4708. Setup_UUIE_destCallSignalAddress_present) != 0)
  4709. {
  4710. BYTE *a = (BYTE *)(&(pParsedData->CalleeDestAddr.Addr.IP_Binary.dwAddr));
  4711. pParsedData->CalleeDestAddr.nAddrType = CC_IP_BINARY;
  4712. pParsedData->CalleeDestAddr.Addr.IP_Binary.wPort =
  4713. pUserInfo->h323_uu_pdu.h323_message_body.u.setup.destCallSignalAddress.u.ipAddress.port;
  4714. a[3] = pUserInfo->h323_uu_pdu.h323_message_body.u.setup.destCallSignalAddress.u.ipAddress.ip.value[0];
  4715. a[2] = pUserInfo->h323_uu_pdu.h323_message_body.u.setup.destCallSignalAddress.u.ipAddress.ip.value[1];
  4716. a[1] = pUserInfo->h323_uu_pdu.h323_message_body.u.setup.destCallSignalAddress.u.ipAddress.ip.value[2];
  4717. a[0] = pUserInfo->h323_uu_pdu.h323_message_body.u.setup.destCallSignalAddress.u.ipAddress.ip.value[3];
  4718. pParsedData->CalleeDestAddrPresent = TRUE;
  4719. }
  4720. if ((pUserInfo->h323_uu_pdu.h323_message_body.u.setup.bit_mask &
  4721. sourceCallSignalAddress_present) != 0)
  4722. {
  4723. BYTE *a = (BYTE *)(&(pParsedData->SourceAddr.Addr.IP_Binary.dwAddr));
  4724. pParsedData->SourceAddr.nAddrType = CC_IP_BINARY;
  4725. pParsedData->SourceAddr.Addr.IP_Binary.wPort =
  4726. pUserInfo->h323_uu_pdu.h323_message_body.u.setup.sourceCallSignalAddress.u.ipAddress.port;
  4727. a[3] = pUserInfo->h323_uu_pdu.h323_message_body.u.setup.sourceCallSignalAddress.u.ipAddress.ip.value[0];
  4728. a[2] = pUserInfo->h323_uu_pdu.h323_message_body.u.setup.sourceCallSignalAddress.u.ipAddress.ip.value[1];
  4729. a[1] = pUserInfo->h323_uu_pdu.h323_message_body.u.setup.sourceCallSignalAddress.u.ipAddress.ip.value[2];
  4730. a[0] = pUserInfo->h323_uu_pdu.h323_message_body.u.setup.sourceCallSignalAddress.u.ipAddress.ip.value[3];
  4731. pParsedData->SourceAddrPresent = TRUE;
  4732. }
  4733. pParsedData->bCallerIsMC = pUserInfo->h323_uu_pdu.h323_message_body.u.setup.activeMC;
  4734. memcpy(pParsedData->ConferenceID.buffer,
  4735. pUserInfo->h323_uu_pdu.h323_message_body.u.setup.conferenceID.value,
  4736. pUserInfo->h323_uu_pdu.h323_message_body.u.setup.conferenceID.length);
  4737. if ((pUserInfo->h323_uu_pdu.h323_message_body.u.setup.bit_mask &
  4738. Setup_UUIE_callIdentifier_present) != 0)
  4739. {
  4740. ASSERT(pUserInfo->h323_uu_pdu.h323_message_body.u.setup.callIdentifier.guid.length
  4741. <= sizeof(GUID));
  4742. memcpy(&pParsedData->CallIdentifier,
  4743. pUserInfo->h323_uu_pdu.h323_message_body.u.setup.callIdentifier.guid.value,
  4744. pUserInfo->h323_uu_pdu.h323_message_body.u.setup.callIdentifier.guid.length);
  4745. }
  4746. #if(0) // not yet implemented
  4747. if ((pUserInfo->h323_uu_pdu.h323_message_body.u.setup.bit_mask &
  4748. Setup_UUIE_fastStart_present) != 0)
  4749. {
  4750. }
  4751. if ((pUserInfo->h323_uu_pdu.h323_message_body.u.setup.bit_mask &
  4752. Setup_UUIE_fastCap_present) != 0)
  4753. {
  4754. }
  4755. #endif
  4756. switch (pUserInfo->h323_uu_pdu.h323_message_body.u.setup.conferenceGoal.choice)
  4757. {
  4758. case invite_chosen:
  4759. pParsedData->wGoal = CSG_INVITE;
  4760. break;
  4761. case join_chosen:
  4762. pParsedData->wGoal = CSG_JOIN;
  4763. break;
  4764. default:
  4765. pParsedData->wGoal = CSG_CREATE;
  4766. } // switch
  4767. switch (pUserInfo->h323_uu_pdu.h323_message_body.u.setup.callType.choice)
  4768. {
  4769. case oneToN_chosen:
  4770. pParsedData->wCallType = CC_CALLTYPE_1_N;
  4771. break;
  4772. case nToOne_chosen:
  4773. pParsedData->wCallType = CC_CALLTYPE_N_1;
  4774. break;
  4775. case nToN_chosen:
  4776. pParsedData->wCallType = CC_CALLTYPE_N_N;
  4777. break;
  4778. default:
  4779. pParsedData->wCallType = CC_CALLTYPE_PT_PT;
  4780. } // switch
  4781. // Free the PDU data.
  4782. Result = freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4783. ASSERT(ASN1_SUCCEEDED(Result));
  4784. return CS_OK;
  4785. }
  4786. //------------------------------------------------------------------------
  4787. //------------------------------------------------------------------------
  4788. HRESULT
  4789. Q931ReleaseCompleteParseASN(
  4790. ASN1_CODER_INFO *pWorld,
  4791. BYTE *pEncodedBuf,
  4792. DWORD dwEncodedLength,
  4793. Q931_RELEASE_COMPLETE_ASN *pParsedData)
  4794. {
  4795. int PDU = H323_UserInformation_PDU;
  4796. char *pDecodedBuf = NULL;
  4797. H323_UserInformation *pUserInfo;
  4798. struct ObjectID_ *id;
  4799. int Result;
  4800. if (pParsedData == NULL)
  4801. {
  4802. return CS_BAD_PARAM;
  4803. }
  4804. Result = Q931_Decode(pWorld,
  4805. (void **) &pDecodedBuf,
  4806. PDU,
  4807. pEncodedBuf,
  4808. dwEncodedLength);
  4809. if (ASN1_FAILED(Result) || (pDecodedBuf == NULL))
  4810. {
  4811. ASSERT(FALSE);
  4812. // trace and return an decoding error of some sort.
  4813. // Note: some values of Result should cause CS_SUBSYSTEM_FAILURE return.
  4814. return CS_BAD_PARAM;
  4815. }
  4816. // validate some basic things about the PDU...
  4817. pUserInfo = (H323_UserInformation *)pDecodedBuf;
  4818. // validate that this is a H323 PDU.
  4819. if (PDU != H323_UserInformation_PDU)
  4820. {
  4821. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4822. return CS_BAD_PARAM;
  4823. }
  4824. // validate that the PDU user-data uses ASN encoding.
  4825. if (((pUserInfo->bit_mask & user_data_present) != 0) &&
  4826. (pUserInfo->user_data.protocol_discriminator != USE_ASN1_ENCODING))
  4827. {
  4828. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4829. return CS_BAD_PARAM;
  4830. }
  4831. // validate that the PDU is H323 Release Complete information.
  4832. if (pUserInfo->h323_uu_pdu.h323_message_body.choice != releaseComplete_chosen)
  4833. {
  4834. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4835. return CS_BAD_PARAM;
  4836. }
  4837. id = pUserInfo->h323_uu_pdu.h323_message_body.u.releaseComplete.protocolIdentifier;
  4838. if (!Q931ValidPduVersion(id))
  4839. {
  4840. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4841. return CS_INCOMPATIBLE_VERSION;
  4842. }
  4843. // parse the message contained in pUserInfo.
  4844. memset(pParsedData, 0, sizeof(Q931_RELEASE_COMPLETE_ASN));
  4845. if ((pUserInfo->h323_uu_pdu.bit_mask & H323_UU_PDU_nnStndrdDt_present) != 0)
  4846. {
  4847. pParsedData->NonStandardDataPresent = TRUE;
  4848. if (pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.choice
  4849. == H225NonStandardIdentifier_h221NonStandard_chosen)
  4850. {
  4851. pParsedData->NonStandardData.bCountryCode =
  4852. (BYTE)(pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35CountryCode);
  4853. pParsedData->NonStandardData.bExtension =
  4854. (BYTE)(pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35Extension);
  4855. pParsedData->NonStandardData.wManufacturerCode =
  4856. pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.manufacturerCode;
  4857. }
  4858. pParsedData->NonStandardData.sData.wOctetStringLength = (WORD)
  4859. pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.length;
  4860. pParsedData->NonStandardData.sData.pOctetString =
  4861. (BYTE *)MemAlloc(pParsedData->NonStandardData.sData.wOctetStringLength);
  4862. if (pParsedData->NonStandardData.sData.pOctetString == NULL)
  4863. {
  4864. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4865. return CS_NO_MEMORY;
  4866. }
  4867. memcpy(pParsedData->NonStandardData.sData.pOctetString,
  4868. pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.value,
  4869. pParsedData->NonStandardData.sData.wOctetStringLength); }
  4870. else
  4871. {
  4872. pParsedData->NonStandardDataPresent = FALSE;
  4873. }
  4874. if ((pUserInfo->h323_uu_pdu.h323_message_body.u.releaseComplete.bit_mask &
  4875. ReleaseComplete_UUIE_callIdentifier_present) != 0)
  4876. {
  4877. ASSERT(pUserInfo->h323_uu_pdu.h323_message_body.u.releaseComplete.callIdentifier.guid.length
  4878. <= sizeof(GUID));
  4879. memcpy(&pParsedData->CallIdentifier,
  4880. pUserInfo->h323_uu_pdu.h323_message_body.u.releaseComplete.callIdentifier.guid.value,
  4881. pUserInfo->h323_uu_pdu.h323_message_body.u.releaseComplete.callIdentifier.guid.length);
  4882. }
  4883. if (pUserInfo->h323_uu_pdu.h323_message_body.u.releaseComplete.bit_mask
  4884. & ReleaseComplete_UUIE_reason_present)
  4885. {
  4886. switch (pUserInfo->h323_uu_pdu.h323_message_body.u.releaseComplete.reason.choice)
  4887. {
  4888. case noBandwidth_chosen:
  4889. pParsedData->bReason = CC_REJECT_NO_BANDWIDTH;
  4890. break;
  4891. case gatekeeperResources_chosen:
  4892. pParsedData->bReason = CC_REJECT_GATEKEEPER_RESOURCES;
  4893. break;
  4894. case unreachableDestination_chosen:
  4895. pParsedData->bReason = CC_REJECT_UNREACHABLE_DESTINATION;
  4896. break;
  4897. case destinationRejection_chosen:
  4898. pParsedData->bReason = CC_REJECT_DESTINATION_REJECTION;
  4899. break;
  4900. case ReleaseCompleteReason_invalidRevision_chosen:
  4901. pParsedData->bReason = CC_REJECT_INVALID_REVISION;
  4902. break;
  4903. case noPermission_chosen:
  4904. pParsedData->bReason = CC_REJECT_NO_PERMISSION;
  4905. break;
  4906. case unreachableGatekeeper_chosen:
  4907. pParsedData->bReason = CC_REJECT_UNREACHABLE_GATEKEEPER;
  4908. break;
  4909. case gatewayResources_chosen:
  4910. pParsedData->bReason = CC_REJECT_GATEWAY_RESOURCES;
  4911. break;
  4912. case badFormatAddress_chosen:
  4913. pParsedData->bReason = CC_REJECT_BAD_FORMAT_ADDRESS;
  4914. break;
  4915. case adaptiveBusy_chosen:
  4916. pParsedData->bReason = CC_REJECT_ADAPTIVE_BUSY;
  4917. break;
  4918. case inConf_chosen:
  4919. pParsedData->bReason = CC_REJECT_IN_CONF;
  4920. break;
  4921. case securityDenied_chosen:
  4922. pParsedData->bReason = CC_REJECT_SECURITY_DENIED;
  4923. break;
  4924. case facilityCallDeflection_chosen:
  4925. pParsedData->bReason = CC_REJECT_CALL_DEFLECTION;
  4926. break;
  4927. default:
  4928. pParsedData->bReason = CC_REJECT_UNDEFINED_REASON;
  4929. } // switch
  4930. }
  4931. else
  4932. {
  4933. pParsedData->bReason = CC_REJECT_UNDEFINED_REASON;
  4934. }
  4935. // Free the PDU data.
  4936. Result = freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4937. ASSERT(ASN1_SUCCEEDED(Result));
  4938. return CS_OK;
  4939. }
  4940. //------------------------------------------------------------------------
  4941. //------------------------------------------------------------------------
  4942. HRESULT
  4943. Q931ConnectParseASN(
  4944. ASN1_CODER_INFO *pWorld,
  4945. BYTE *pEncodedBuf,
  4946. DWORD dwEncodedLength,
  4947. Q931_CONNECT_ASN *pParsedData)
  4948. {
  4949. int PDU = H323_UserInformation_PDU;
  4950. char *pDecodedBuf = NULL;
  4951. H323_UserInformation *pUserInfo;
  4952. struct ObjectID_ *id;
  4953. int Result;
  4954. if (pParsedData == NULL)
  4955. {
  4956. return CS_BAD_PARAM;
  4957. }
  4958. Result = Q931_Decode(pWorld,
  4959. (void **) &pDecodedBuf,
  4960. PDU,
  4961. pEncodedBuf,
  4962. dwEncodedLength);
  4963. if (ASN1_FAILED(Result) || (pDecodedBuf == NULL))
  4964. {
  4965. ASSERT(FALSE);
  4966. // trace and return an decoding error of some sort.
  4967. // Note: some values of Result should cause CS_SUBSYSTEM_FAILURE return.
  4968. return CS_BAD_PARAM;
  4969. }
  4970. // validate some basic things about the PDU...
  4971. pUserInfo = (H323_UserInformation *)pDecodedBuf;
  4972. // validate that this is a H323 PDU.
  4973. if (PDU != H323_UserInformation_PDU)
  4974. {
  4975. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4976. return CS_BAD_PARAM;
  4977. }
  4978. // validate that the PDU user-data uses ASN encoding.
  4979. if (((pUserInfo->bit_mask & user_data_present) != 0) &&
  4980. (pUserInfo->user_data.protocol_discriminator != USE_ASN1_ENCODING))
  4981. {
  4982. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4983. return CS_BAD_PARAM;
  4984. }
  4985. // validate that the PDU is H323 Connect information.
  4986. if (pUserInfo->h323_uu_pdu.h323_message_body.choice != connect_chosen)
  4987. {
  4988. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4989. return CS_BAD_PARAM;
  4990. }
  4991. id = pUserInfo->h323_uu_pdu.h323_message_body.u.connect.protocolIdentifier;
  4992. if (!Q931ValidPduVersion(id))
  4993. {
  4994. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  4995. return CS_INCOMPATIBLE_VERSION;
  4996. }
  4997. // make sure that the conference id is formed correctly.
  4998. if (pUserInfo->h323_uu_pdu.h323_message_body.u.connect.conferenceID.length >
  4999. sizeof(pUserInfo->h323_uu_pdu.h323_message_body.u.connect.conferenceID.value))
  5000. {
  5001. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5002. return CS_BAD_PARAM;
  5003. }
  5004. // parse the message contained in pUserInfo.
  5005. memset(pParsedData, 0, sizeof(Q931_CONNECT_ASN));
  5006. pParsedData->h245Addr.bMulticast = FALSE;
  5007. if ((pUserInfo->h323_uu_pdu.bit_mask & H323_UU_PDU_nnStndrdDt_present) != 0)
  5008. {
  5009. pParsedData->NonStandardDataPresent = TRUE;
  5010. if (pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.choice ==
  5011. H225NonStandardIdentifier_h221NonStandard_chosen)
  5012. {
  5013. pParsedData->NonStandardData.bCountryCode =
  5014. (BYTE)(pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35CountryCode);
  5015. pParsedData->NonStandardData.bExtension =
  5016. (BYTE)(pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35Extension);
  5017. pParsedData->NonStandardData.wManufacturerCode =
  5018. pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.manufacturerCode;
  5019. }
  5020. pParsedData->NonStandardData.sData.wOctetStringLength = (WORD)
  5021. pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.length;
  5022. pParsedData->NonStandardData.sData.pOctetString =
  5023. (BYTE *)MemAlloc(pParsedData->NonStandardData.sData.wOctetStringLength);
  5024. if (pParsedData->NonStandardData.sData.pOctetString == NULL)
  5025. {
  5026. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5027. return CS_NO_MEMORY;
  5028. }
  5029. memcpy(pParsedData->NonStandardData.sData.pOctetString,
  5030. pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.value,
  5031. pParsedData->NonStandardData.sData.wOctetStringLength);
  5032. }
  5033. else
  5034. {
  5035. pParsedData->NonStandardDataPresent = FALSE;
  5036. }
  5037. if ((pUserInfo->h323_uu_pdu.h323_message_body.u.connect.bit_mask &
  5038. Cnnct_UUIE_h245Address_present) != 0)
  5039. {
  5040. BYTE *a = (BYTE *)(&(pParsedData->h245Addr.Addr.IP_Binary.dwAddr));
  5041. pParsedData->h245Addr.nAddrType = CC_IP_BINARY;
  5042. pParsedData->h245Addr.Addr.IP_Binary.wPort =
  5043. pUserInfo->h323_uu_pdu.h323_message_body.u.connect.Cnnct_UUIE_h245Address.u.ipAddress.port;
  5044. a[3] = pUserInfo->h323_uu_pdu.h323_message_body.u.connect.Cnnct_UUIE_h245Address.u.ipAddress.ip.value[0];
  5045. a[2] = pUserInfo->h323_uu_pdu.h323_message_body.u.connect.Cnnct_UUIE_h245Address.u.ipAddress.ip.value[1];
  5046. a[1] = pUserInfo->h323_uu_pdu.h323_message_body.u.connect.Cnnct_UUIE_h245Address.u.ipAddress.ip.value[2];
  5047. a[0] = pUserInfo->h323_uu_pdu.h323_message_body.u.connect.Cnnct_UUIE_h245Address.u.ipAddress.ip.value[3];
  5048. pParsedData->h245AddrPresent = TRUE;
  5049. }
  5050. else
  5051. {
  5052. pParsedData->h245AddrPresent = FALSE;
  5053. }
  5054. // no validation of destinationInfo needed.
  5055. pParsedData->EndpointType.pVendorInfo = NULL;
  5056. if (pUserInfo->h323_uu_pdu.h323_message_body.u.connect.destinationInfo.bit_mask & (vendor_present))
  5057. {
  5058. pParsedData->EndpointType.pVendorInfo = &(pParsedData->VendorInfo);
  5059. pParsedData->VendorInfo.bCountryCode =
  5060. (BYTE)pUserInfo->h323_uu_pdu.h323_message_body.u.connect.destinationInfo.vendor.vendor.t35CountryCode;
  5061. pParsedData->VendorInfo.bExtension =
  5062. (BYTE)pUserInfo->h323_uu_pdu.h323_message_body.u.connect.destinationInfo.vendor.vendor.t35Extension;
  5063. pParsedData->VendorInfo.wManufacturerCode =
  5064. pUserInfo->h323_uu_pdu.h323_message_body.u.connect.destinationInfo.vendor.vendor.manufacturerCode;
  5065. if (pUserInfo->h323_uu_pdu.h323_message_body.u.connect.destinationInfo.vendor.bit_mask & (productId_present))
  5066. {
  5067. pParsedData->VendorInfo.pProductNumber = MemAlloc(sizeof(CC_OCTETSTRING));
  5068. if (pParsedData->VendorInfo.pProductNumber == NULL)
  5069. {
  5070. if (pParsedData->NonStandardData.sData.pOctetString != NULL)
  5071. MemFree(pParsedData->NonStandardData.sData.pOctetString);
  5072. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5073. return CS_NO_MEMORY;
  5074. }
  5075. pParsedData->VendorInfo.pProductNumber->wOctetStringLength = (WORD)
  5076. min(pUserInfo->h323_uu_pdu.h323_message_body.u.connect.destinationInfo.vendor.productId.length,
  5077. CC_MAX_PRODUCT_LENGTH - 1);
  5078. memcpy(pParsedData->bufProductValue,
  5079. pUserInfo->h323_uu_pdu.h323_message_body.u.connect.destinationInfo.vendor.productId.value,
  5080. pParsedData->VendorInfo.pProductNumber->wOctetStringLength);
  5081. pParsedData->bufProductValue[pParsedData->VendorInfo.pProductNumber->wOctetStringLength] = '\0';
  5082. pParsedData->VendorInfo.pProductNumber->pOctetString = pParsedData->bufProductValue;
  5083. }
  5084. if (pUserInfo->h323_uu_pdu.h323_message_body.u.connect.destinationInfo.vendor.bit_mask & (versionId_present))
  5085. {
  5086. pParsedData->VendorInfo.pVersionNumber = MemAlloc(sizeof(CC_OCTETSTRING));
  5087. if (pParsedData->VendorInfo.pVersionNumber == NULL)
  5088. {
  5089. if (pParsedData->NonStandardData.sData.pOctetString != NULL)
  5090. MemFree(pParsedData->NonStandardData.sData.pOctetString);
  5091. MemFree(pParsedData->VendorInfo.pProductNumber);
  5092. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5093. return CS_NO_MEMORY;
  5094. }
  5095. pParsedData->VendorInfo.pVersionNumber->wOctetStringLength = (WORD)
  5096. min(pUserInfo->h323_uu_pdu.h323_message_body.u.connect.destinationInfo.vendor.versionId.length,
  5097. CC_MAX_VERSION_LENGTH - 1);
  5098. memcpy(pParsedData->bufVersionValue,
  5099. pUserInfo->h323_uu_pdu.h323_message_body.u.connect.destinationInfo.vendor.versionId.value,
  5100. pParsedData->VendorInfo.pVersionNumber->wOctetStringLength);
  5101. pParsedData->bufVersionValue[pParsedData->VendorInfo.pVersionNumber->wOctetStringLength] = '\0';
  5102. pParsedData->VendorInfo.pVersionNumber->pOctetString = pParsedData->bufVersionValue;
  5103. }
  5104. }
  5105. pParsedData->EndpointType.bIsTerminal = FALSE;
  5106. if (pUserInfo->h323_uu_pdu.h323_message_body.u.connect.destinationInfo.bit_mask & (terminal_present))
  5107. {
  5108. pParsedData->EndpointType.bIsTerminal = TRUE;
  5109. }
  5110. pParsedData->EndpointType.bIsGateway = FALSE;
  5111. if (pUserInfo->h323_uu_pdu.h323_message_body.u.connect.destinationInfo.bit_mask & (gateway_present))
  5112. {
  5113. pParsedData->EndpointType.bIsGateway = TRUE;
  5114. }
  5115. memcpy(pParsedData->ConferenceID.buffer,
  5116. pUserInfo->h323_uu_pdu.h323_message_body.u.connect.conferenceID.value,
  5117. pUserInfo->h323_uu_pdu.h323_message_body.u.connect.conferenceID.length);
  5118. if ((pUserInfo->h323_uu_pdu.h323_message_body.u.connect.bit_mask &
  5119. Connect_UUIE_callIdentifier_present) != 0)
  5120. {
  5121. ASSERT(pUserInfo->h323_uu_pdu.h323_message_body.u.connect.callIdentifier.guid.length
  5122. <= sizeof(GUID));
  5123. memcpy(&pParsedData->CallIdentifier,
  5124. pUserInfo->h323_uu_pdu.h323_message_body.u.connect.callIdentifier.guid.value,
  5125. pUserInfo->h323_uu_pdu.h323_message_body.u.connect.callIdentifier.guid.length);
  5126. }
  5127. // Free the PDU data.
  5128. Result = freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5129. ASSERT(ASN1_SUCCEEDED(Result));
  5130. return CS_OK;
  5131. }
  5132. //------------------------------------------------------------------------
  5133. //------------------------------------------------------------------------
  5134. HRESULT
  5135. Q931AlertingParseASN(
  5136. ASN1_CODER_INFO *pWorld,
  5137. BYTE *pEncodedBuf,
  5138. DWORD dwEncodedLength,
  5139. Q931_ALERTING_ASN *pParsedData)
  5140. {
  5141. int PDU = H323_UserInformation_PDU;
  5142. char *pDecodedBuf = NULL;
  5143. H323_UserInformation *pUserInfo;
  5144. struct ObjectID_ *id;
  5145. int Result;
  5146. if (pParsedData == NULL)
  5147. {
  5148. return CS_BAD_PARAM;
  5149. }
  5150. Result = Q931_Decode(pWorld,
  5151. (void **) &pDecodedBuf,
  5152. PDU,
  5153. pEncodedBuf,
  5154. dwEncodedLength);
  5155. if (ASN1_FAILED(Result) || (pDecodedBuf == NULL))
  5156. {
  5157. ASSERT(FALSE);
  5158. // trace and return an decoding error of some sort.
  5159. // Note: some values of Result should cause CS_SUBSYSTEM_FAILURE return.
  5160. return CS_BAD_PARAM;
  5161. }
  5162. // validate some basic things about the PDU...
  5163. pUserInfo = (H323_UserInformation *)pDecodedBuf;
  5164. // validate that this is a H323 PDU.
  5165. if (PDU != H323_UserInformation_PDU)
  5166. {
  5167. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5168. return CS_BAD_PARAM;
  5169. }
  5170. // validate that the PDU user-data uses ASN encoding.
  5171. if (((pUserInfo->bit_mask & user_data_present) != 0) &&
  5172. (pUserInfo->user_data.protocol_discriminator != USE_ASN1_ENCODING))
  5173. {
  5174. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5175. return CS_BAD_PARAM;
  5176. }
  5177. // validate that the PDU is H323 Alerting information.
  5178. if (pUserInfo->h323_uu_pdu.h323_message_body.choice != alerting_chosen)
  5179. {
  5180. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5181. return CS_BAD_PARAM;
  5182. }
  5183. id = pUserInfo->h323_uu_pdu.h323_message_body.u.alerting.protocolIdentifier;
  5184. if (!Q931ValidPduVersion(id))
  5185. {
  5186. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5187. return CS_INCOMPATIBLE_VERSION;
  5188. }
  5189. // parse the message contained in pUserInfo.
  5190. memset(pParsedData, 0, sizeof(Q931_ALERTING_ASN));
  5191. pParsedData->h245Addr.bMulticast = FALSE;
  5192. if ((pUserInfo->h323_uu_pdu.bit_mask & H323_UU_PDU_nnStndrdDt_present) != 0)
  5193. {
  5194. pParsedData->NonStandardDataPresent = TRUE;
  5195. if (pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.choice ==
  5196. H225NonStandardIdentifier_h221NonStandard_chosen)
  5197. {
  5198. pParsedData->NonStandardData.bCountryCode =
  5199. (BYTE)(pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35CountryCode);
  5200. pParsedData->NonStandardData.bExtension =
  5201. (BYTE)(pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35Extension);
  5202. pParsedData->NonStandardData.wManufacturerCode =
  5203. pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.manufacturerCode;
  5204. }
  5205. pParsedData->NonStandardData.sData.wOctetStringLength = (WORD)
  5206. pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.length;
  5207. pParsedData->NonStandardData.sData.pOctetString =
  5208. (BYTE *)MemAlloc(pParsedData->NonStandardData.sData.wOctetStringLength);
  5209. if (pParsedData->NonStandardData.sData.pOctetString == NULL)
  5210. {
  5211. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5212. return CS_NO_MEMORY;
  5213. }
  5214. memcpy(pParsedData->NonStandardData.sData.pOctetString,
  5215. pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.value,
  5216. pParsedData->NonStandardData.sData.wOctetStringLength);
  5217. }
  5218. else
  5219. {
  5220. pParsedData->NonStandardDataPresent = FALSE;
  5221. }
  5222. if ((pUserInfo->h323_uu_pdu.h323_message_body.u.alerting.bit_mask &
  5223. CPg_UUIE_h245Addrss_present) != 0)
  5224. {
  5225. BYTE *a = (BYTE *)(&(pParsedData->h245Addr.Addr.IP_Binary.dwAddr));
  5226. pParsedData->h245Addr.nAddrType = CC_IP_BINARY;
  5227. pParsedData->h245Addr.Addr.IP_Binary.wPort =
  5228. pUserInfo->h323_uu_pdu.h323_message_body.u.alerting.CPg_UUIE_h245Addrss.u.ipAddress.port;
  5229. a[3] = pUserInfo->h323_uu_pdu.h323_message_body.u.alerting.CPg_UUIE_h245Addrss.u.ipAddress.ip.value[0];
  5230. a[2] = pUserInfo->h323_uu_pdu.h323_message_body.u.alerting.CPg_UUIE_h245Addrss.u.ipAddress.ip.value[1];
  5231. a[1] = pUserInfo->h323_uu_pdu.h323_message_body.u.alerting.CPg_UUIE_h245Addrss.u.ipAddress.ip.value[2];
  5232. a[0] = pUserInfo->h323_uu_pdu.h323_message_body.u.alerting.CPg_UUIE_h245Addrss.u.ipAddress.ip.value[3];
  5233. }
  5234. if ((pUserInfo->h323_uu_pdu.h323_message_body.u.alerting.bit_mask &
  5235. Alerting_UUIE_callIdentifier_present) != 0)
  5236. {
  5237. ASSERT(pUserInfo->h323_uu_pdu.h323_message_body.u.alerting.callIdentifier.guid.length
  5238. <= sizeof(GUID));
  5239. memcpy(&pParsedData->CallIdentifier,
  5240. pUserInfo->h323_uu_pdu.h323_message_body.u.alerting.callIdentifier.guid.value,
  5241. pUserInfo->h323_uu_pdu.h323_message_body.u.alerting.callIdentifier.guid.length);
  5242. }
  5243. //RMO. ignore the destinationInfo field.
  5244. // Free the PDU data.
  5245. Result = freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5246. ASSERT(ASN1_SUCCEEDED(Result));
  5247. return CS_OK;
  5248. }
  5249. //------------------------------------------------------------------------
  5250. //------------------------------------------------------------------------
  5251. HRESULT
  5252. Q931ProceedingParseASN(
  5253. ASN1_CODER_INFO *pWorld,
  5254. BYTE *pEncodedBuf,
  5255. DWORD dwEncodedLength,
  5256. Q931_CALL_PROCEEDING_ASN *pParsedData)
  5257. {
  5258. int PDU = H323_UserInformation_PDU;
  5259. char *pDecodedBuf = NULL;
  5260. H323_UserInformation *pUserInfo;
  5261. struct ObjectID_ *id;
  5262. int Result;
  5263. if (pParsedData == NULL)
  5264. {
  5265. return CS_BAD_PARAM;
  5266. }
  5267. Result = Q931_Decode(pWorld,
  5268. (void **) &pDecodedBuf,
  5269. PDU,
  5270. pEncodedBuf,
  5271. dwEncodedLength);
  5272. if (ASN1_FAILED(Result) || (pDecodedBuf == NULL))
  5273. {
  5274. ASSERT(FALSE);
  5275. // trace and return an decoding error of some sort.
  5276. // Note: some values of Result should cause CS_SUBSYSTEM_FAILURE return.
  5277. return CS_BAD_PARAM;
  5278. }
  5279. // validate some basic things about the PDU...
  5280. pUserInfo = (H323_UserInformation *)pDecodedBuf;
  5281. // validate that this is a H323 PDU.
  5282. if (PDU != H323_UserInformation_PDU)
  5283. {
  5284. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5285. return CS_BAD_PARAM;
  5286. }
  5287. // validate that the PDU user-data uses ASN encoding.
  5288. if (((pUserInfo->bit_mask & user_data_present) != 0) &&
  5289. (pUserInfo->user_data.protocol_discriminator != USE_ASN1_ENCODING))
  5290. {
  5291. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5292. return CS_BAD_PARAM;
  5293. }
  5294. // validate that the PDU is H323 Call Proceeding information.
  5295. if (pUserInfo->h323_uu_pdu.h323_message_body.choice != callProceeding_chosen)
  5296. {
  5297. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5298. return CS_BAD_PARAM;
  5299. }
  5300. id = pUserInfo->h323_uu_pdu.h323_message_body.u.callProceeding.protocolIdentifier;
  5301. if (!Q931ValidPduVersion(id))
  5302. {
  5303. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5304. return CS_INCOMPATIBLE_VERSION;
  5305. }
  5306. // parse the message contained in pUserInfo.
  5307. memset(pParsedData, 0, sizeof(Q931_CALL_PROCEEDING_ASN));
  5308. pParsedData->h245Addr.bMulticast = FALSE;
  5309. if ((pUserInfo->h323_uu_pdu.bit_mask & H323_UU_PDU_nnStndrdDt_present) != 0)
  5310. {
  5311. pParsedData->NonStandardDataPresent = TRUE;
  5312. if (pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.choice ==
  5313. H225NonStandardIdentifier_h221NonStandard_chosen)
  5314. {
  5315. pParsedData->NonStandardData.bCountryCode =
  5316. (BYTE)(pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35CountryCode);
  5317. pParsedData->NonStandardData.bExtension =
  5318. (BYTE)(pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35Extension);
  5319. pParsedData->NonStandardData.wManufacturerCode =
  5320. pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.manufacturerCode;
  5321. }
  5322. pParsedData->NonStandardData.sData.wOctetStringLength = (WORD)
  5323. pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.length;
  5324. pParsedData->NonStandardData.sData.pOctetString =
  5325. (BYTE *)MemAlloc(pParsedData->NonStandardData.sData.wOctetStringLength);
  5326. if (pParsedData->NonStandardData.sData.pOctetString == NULL)
  5327. {
  5328. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5329. return CS_NO_MEMORY;
  5330. }
  5331. memcpy(pParsedData->NonStandardData.sData.pOctetString,
  5332. pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.value,
  5333. pParsedData->NonStandardData.sData.wOctetStringLength);
  5334. }
  5335. else
  5336. {
  5337. pParsedData->NonStandardDataPresent = FALSE;
  5338. }
  5339. if ((pUserInfo->h323_uu_pdu.h323_message_body.u.callProceeding.bit_mask &
  5340. CPg_UUIE_h245Addrss_present) != 0)
  5341. {
  5342. BYTE *a = (BYTE *)(&(pParsedData->h245Addr.Addr.IP_Binary.dwAddr));
  5343. pParsedData->h245Addr.nAddrType = CC_IP_BINARY;
  5344. pParsedData->h245Addr.Addr.IP_Binary.wPort =
  5345. pUserInfo->h323_uu_pdu.h323_message_body.u.callProceeding.CPg_UUIE_h245Addrss.u.ipAddress.port;
  5346. a[3] = pUserInfo->h323_uu_pdu.h323_message_body.u.callProceeding.CPg_UUIE_h245Addrss.u.ipAddress.ip.value[0];
  5347. a[2] = pUserInfo->h323_uu_pdu.h323_message_body.u.callProceeding.CPg_UUIE_h245Addrss.u.ipAddress.ip.value[1];
  5348. a[1] = pUserInfo->h323_uu_pdu.h323_message_body.u.callProceeding.CPg_UUIE_h245Addrss.u.ipAddress.ip.value[2];
  5349. a[0] = pUserInfo->h323_uu_pdu.h323_message_body.u.callProceeding.CPg_UUIE_h245Addrss.u.ipAddress.ip.value[3];
  5350. }
  5351. if ((pUserInfo->h323_uu_pdu.h323_message_body.u.callProceeding.bit_mask &
  5352. CallProceeding_UUIE_callIdentifier_present) != 0)
  5353. {
  5354. ASSERT(pUserInfo->h323_uu_pdu.h323_message_body.u.callProceeding.callIdentifier.guid.length
  5355. <= sizeof(GUID));
  5356. memcpy(&pParsedData->CallIdentifier,
  5357. pUserInfo->h323_uu_pdu.h323_message_body.u.callProceeding.callIdentifier.guid.value,
  5358. pUserInfo->h323_uu_pdu.h323_message_body.u.callProceeding.callIdentifier.guid.length);
  5359. }
  5360. //RMO. ignore the destinationInfo field.
  5361. // Free the PDU data.
  5362. Result = freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5363. ASSERT(ASN1_SUCCEEDED(Result));
  5364. return CS_OK;
  5365. }
  5366. //------------------------------------------------------------------------
  5367. //------------------------------------------------------------------------
  5368. HRESULT
  5369. Q931FacilityParseASN(
  5370. ASN1_CODER_INFO *pWorld,
  5371. BYTE *pEncodedBuf,
  5372. DWORD dwEncodedLength,
  5373. Q931_FACILITY_ASN *pParsedData)
  5374. {
  5375. int PDU = H323_UserInformation_PDU;
  5376. char *pDecodedBuf = NULL;
  5377. H323_UserInformation *pUserInfo;
  5378. int Result;
  5379. if (pParsedData == NULL)
  5380. {
  5381. return CS_BAD_PARAM;
  5382. }
  5383. Result = Q931_Decode(pWorld,
  5384. (void **) &pDecodedBuf,
  5385. PDU,
  5386. pEncodedBuf,
  5387. dwEncodedLength);
  5388. if (ASN1_FAILED(Result) || (pDecodedBuf == NULL))
  5389. {
  5390. ASSERT(FALSE);
  5391. // trace and return an decoding error of some sort.
  5392. // Note: some values of Result should cause CS_SUBSYSTEM_FAILURE return.
  5393. return CS_BAD_PARAM;
  5394. }
  5395. // validate some basic things about the PDU...
  5396. pUserInfo = (H323_UserInformation *)pDecodedBuf;
  5397. // validate that this is a H323 PDU.
  5398. if (PDU != H323_UserInformation_PDU)
  5399. {
  5400. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5401. return CS_BAD_PARAM;
  5402. }
  5403. // validate that the PDU user-data uses ASN encoding.
  5404. if (((pUserInfo->bit_mask & user_data_present) != 0) &&
  5405. (pUserInfo->user_data.protocol_discriminator != USE_ASN1_ENCODING))
  5406. {
  5407. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5408. return CS_BAD_PARAM;
  5409. }
  5410. // validate that the PDU is H323 Facility information.
  5411. if (pUserInfo->h323_uu_pdu.h323_message_body.choice != facility_chosen)
  5412. {
  5413. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5414. return CS_BAD_PARAM;
  5415. }
  5416. {
  5417. struct ObjectID_ *id;
  5418. id = pUserInfo->h323_uu_pdu.h323_message_body.u.facility.protocolIdentifier;
  5419. if (!Q931ValidPduVersion(id))
  5420. {
  5421. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5422. return CS_INCOMPATIBLE_VERSION;
  5423. }
  5424. }
  5425. // if there is a conference id, make sure that it is formed correctly.
  5426. if ((pUserInfo->h323_uu_pdu.h323_message_body.u.facility.bit_mask &
  5427. Facility_UUIE_conferenceID_present) != 0)
  5428. {
  5429. if (pUserInfo->h323_uu_pdu.h323_message_body.u.facility.conferenceID.length >
  5430. sizeof(pUserInfo->h323_uu_pdu.h323_message_body.u.facility.conferenceID.value))
  5431. {
  5432. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5433. return CS_BAD_PARAM;
  5434. }
  5435. }
  5436. // parse the message contained in pUserInfo.
  5437. memset(pParsedData, 0, sizeof(Q931_FACILITY_ASN));
  5438. pParsedData->AlternativeAddr.bMulticast = FALSE;
  5439. if ((pUserInfo->h323_uu_pdu.bit_mask & H323_UU_PDU_nnStndrdDt_present) != 0)
  5440. {
  5441. pParsedData->NonStandardDataPresent = TRUE;
  5442. if (pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.choice ==
  5443. H225NonStandardIdentifier_h221NonStandard_chosen)
  5444. {
  5445. pParsedData->NonStandardData.bCountryCode =
  5446. (BYTE)(pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35CountryCode);
  5447. pParsedData->NonStandardData.bExtension =
  5448. (BYTE)(pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.t35Extension);
  5449. pParsedData->NonStandardData.wManufacturerCode =
  5450. pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.nonStandardIdentifier.u.h221NonStandard.manufacturerCode;
  5451. }
  5452. pParsedData->NonStandardData.sData.wOctetStringLength = (WORD)
  5453. pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.length;
  5454. pParsedData->NonStandardData.sData.pOctetString =
  5455. (BYTE *)MemAlloc(pParsedData->NonStandardData.sData.wOctetStringLength);
  5456. if (pParsedData->NonStandardData.sData.pOctetString == NULL)
  5457. {
  5458. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5459. return CS_NO_MEMORY;
  5460. }
  5461. memcpy(pParsedData->NonStandardData.sData.pOctetString,
  5462. pUserInfo->h323_uu_pdu.H323_UU_PDU_nnStndrdDt.data.value,
  5463. pParsedData->NonStandardData.sData.wOctetStringLength);
  5464. }
  5465. else
  5466. {
  5467. pParsedData->NonStandardDataPresent = FALSE;
  5468. }
  5469. if ((pUserInfo->h323_uu_pdu.h323_message_body.u.facility.bit_mask &
  5470. alternativeAddress_present) != 0)
  5471. {
  5472. BYTE *a = (BYTE *)(&(pParsedData->AlternativeAddr.Addr.IP_Binary.dwAddr));
  5473. pParsedData->AlternativeAddr.nAddrType = CC_IP_BINARY;
  5474. pParsedData->AlternativeAddr.Addr.IP_Binary.wPort =
  5475. pUserInfo->h323_uu_pdu.h323_message_body.u.facility.alternativeAddress.u.ipAddress.port;
  5476. a[3] = pUserInfo->h323_uu_pdu.h323_message_body.u.facility.alternativeAddress.u.ipAddress.ip.value[0];
  5477. a[2] = pUserInfo->h323_uu_pdu.h323_message_body.u.facility.alternativeAddress.u.ipAddress.ip.value[1];
  5478. a[1] = pUserInfo->h323_uu_pdu.h323_message_body.u.facility.alternativeAddress.u.ipAddress.ip.value[2];
  5479. a[0] = pUserInfo->h323_uu_pdu.h323_message_body.u.facility.alternativeAddress.u.ipAddress.ip.value[3];
  5480. }
  5481. if ((pUserInfo->h323_uu_pdu.h323_message_body.u.facility.bit_mask &
  5482. alternativeAliasAddress_present) != 0)
  5483. {
  5484. CS_STATUS AliasResult = CS_OK;
  5485. // parse the sourceAddress aliases here...
  5486. AliasResult = SeqofToAlias(&(pParsedData->pAlternativeAliasList),
  5487. (struct Setup_UUIE_sourceAddress *)pUserInfo->h323_uu_pdu.h323_message_body.u.facility.alternativeAliasAddress);
  5488. if (AliasResult != CS_OK)
  5489. {
  5490. freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5491. return CS_NO_MEMORY;
  5492. }
  5493. }
  5494. if ((pUserInfo->h323_uu_pdu.h323_message_body.u.facility.bit_mask &
  5495. Facility_UUIE_conferenceID_present) != 0)
  5496. {
  5497. memcpy(pParsedData->ConferenceID.buffer,
  5498. pUserInfo->h323_uu_pdu.h323_message_body.u.facility.conferenceID.value,
  5499. pUserInfo->h323_uu_pdu.h323_message_body.u.facility.conferenceID.length);
  5500. pParsedData->ConferenceIDPresent = TRUE;
  5501. }
  5502. switch (pUserInfo->h323_uu_pdu.h323_message_body.u.facility.reason.choice)
  5503. {
  5504. case FacilityReason_routeCallToGatekeeper_chosen:
  5505. pParsedData->bReason = CC_REJECT_ROUTE_TO_GATEKEEPER;
  5506. break;
  5507. case callForwarded_chosen:
  5508. pParsedData->bReason = CC_REJECT_CALL_FORWARDED;
  5509. break;
  5510. case routeCallToMC_chosen:
  5511. pParsedData->bReason = CC_REJECT_ROUTE_TO_MC;
  5512. break;
  5513. default:
  5514. pParsedData->bReason = CC_REJECT_UNDEFINED_REASON;
  5515. } // switch
  5516. if ((pUserInfo->h323_uu_pdu.h323_message_body.u.facility.bit_mask &
  5517. Facility_UUIE_callIdentifier_present) != 0)
  5518. {
  5519. ASSERT(pUserInfo->h323_uu_pdu.h323_message_body.u.facility.callIdentifier.guid.length
  5520. <= sizeof(GUID));
  5521. memcpy(&pParsedData->CallIdentifier,
  5522. pUserInfo->h323_uu_pdu.h323_message_body.u.facility.callIdentifier.guid.value,
  5523. pUserInfo->h323_uu_pdu.h323_message_body.u.facility.callIdentifier.guid.length);
  5524. }
  5525. // Free the PDU data.
  5526. Result = freePDU(pWorld, PDU, pDecodedBuf, q931asn);
  5527. ASSERT(ASN1_SUCCEEDED(Result));
  5528. return CS_OK;
  5529. }
  5530. // THE FOLLOWING IS ADDED FOR TELES ASN.1 INTEGRATION
  5531. int H225_InitModule(void)
  5532. {
  5533. H225ASN_Module_Startup();
  5534. return (H225ASN_Module != NULL) ? ASN1_SUCCESS : ASN1_ERR_MEMORY;
  5535. }
  5536. int H225_TermModule(void)
  5537. {
  5538. H225ASN_Module_Cleanup();
  5539. return ASN1_SUCCESS;
  5540. }
  5541. int Q931_InitWorld(ASN1_CODER_INFO *pWorld)
  5542. {
  5543. int rc;
  5544. ZeroMemory(pWorld, sizeof(*pWorld));
  5545. if (H225ASN_Module == NULL)
  5546. {
  5547. return ASN1_ERR_BADARGS;
  5548. }
  5549. rc = ASN1_CreateEncoder(
  5550. H225ASN_Module, // ptr to mdule
  5551. &(pWorld->pEncInfo), // ptr to encoder info
  5552. NULL, // buffer ptr
  5553. 0, // buffer size
  5554. NULL); // parent ptr
  5555. if (rc == ASN1_SUCCESS)
  5556. {
  5557. ASSERT(pWorld->pEncInfo != NULL);
  5558. rc = ASN1_CreateDecoder(
  5559. H225ASN_Module, // ptr to mdule
  5560. &(pWorld->pDecInfo), // ptr to decoder info
  5561. NULL, // buffer ptr
  5562. 0, // buffer size
  5563. NULL); // parent ptr
  5564. ASSERT(pWorld->pDecInfo != NULL);
  5565. }
  5566. if (rc != ASN1_SUCCESS)
  5567. {
  5568. Q931_TermWorld(pWorld);
  5569. }
  5570. return rc;
  5571. }
  5572. int Q931_TermWorld(ASN1_CODER_INFO *pWorld)
  5573. {
  5574. if (H225ASN_Module == NULL)
  5575. {
  5576. return ASN1_ERR_BADARGS;
  5577. }
  5578. ASN1_CloseEncoder(pWorld->pEncInfo);
  5579. ASN1_CloseDecoder(pWorld->pDecInfo);
  5580. ZeroMemory(pWorld, sizeof(*pWorld));
  5581. return ASN1_SUCCESS;
  5582. }
  5583. int Q931_Encode(ASN1_CODER_INFO *pWorld, void *pStruct, int nPDU, BYTE **ppEncoded, DWORD *pcbEncodedSize)
  5584. {
  5585. ASN1encoding_t pEncInfo = pWorld->pEncInfo;
  5586. int rc = ASN1_Encode(
  5587. pEncInfo, // ptr to encoder info
  5588. pStruct, // pdu data structure
  5589. nPDU, // pdu id
  5590. ASN1ENCODE_ALLOCATEBUFFER, // flags
  5591. NULL, // do not provide buffer
  5592. 0); // buffer size if provided
  5593. if (ASN1_SUCCEEDED(rc))
  5594. {
  5595. *pcbEncodedSize = pEncInfo->len; // len of encoded data in buffer
  5596. *ppEncoded = pEncInfo->buf; // buffer to encode into
  5597. }
  5598. else
  5599. {
  5600. ASSERT(FALSE);
  5601. *pcbEncodedSize = 0;
  5602. *ppEncoded = NULL;
  5603. }
  5604. return rc;
  5605. }
  5606. int Q931_Decode(ASN1_CODER_INFO *pWorld, void **ppStruct, int nPDU, BYTE *pEncoded, DWORD cbEncodedSize)
  5607. {
  5608. ASN1decoding_t pDecInfo = pWorld->pDecInfo;
  5609. int rc = ASN1_Decode(
  5610. pDecInfo, // ptr to encoder info
  5611. ppStruct, // pdu data structure
  5612. nPDU, // pdu id
  5613. ASN1DECODE_SETBUFFER, // flags
  5614. pEncoded, // do not provide buffer
  5615. cbEncodedSize); // buffer size if provided
  5616. if (ASN1_FAILED(rc))
  5617. {
  5618. ASSERT(FALSE);
  5619. *ppStruct = NULL;
  5620. }
  5621. return rc;
  5622. }