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.

296 lines
8.1 KiB

  1. //*************************************************************
  2. //
  3. // File name: GccData.c
  4. //
  5. // Description: Contains routines to support GCC
  6. // user data manipulation
  7. //
  8. // Microsoft Confidential
  9. // Copyright (c) Microsoft Corporation 1991-1997
  10. // All rights reserved
  11. //
  12. //*************************************************************
  13. #include <_tgcc.h>
  14. #include <stdio.h>
  15. //gccDecodeUserData must have input data size at least 21
  16. #define GCC_MINIMUM_DATASIZE 21
  17. //*************************************************************
  18. //
  19. // gccDecodeUserData()
  20. //
  21. // Purpose: Decodes BER data into GCCUserData
  22. //
  23. // Parameters: IN [pData] -- Ptr to BER data
  24. // IN [DataLength] -- BER data length
  25. // OUT [pUserData] -- Ptr to GCCUserData
  26. //
  27. // Return: MCSError
  28. //
  29. // History: 08-10-97 BrianTa Created
  30. //
  31. //*************************************************************
  32. MCSError
  33. gccDecodeUserData(IN PBYTE pData,
  34. IN UINT DataLength,
  35. OUT GCCUserData *pUserData)
  36. {
  37. MCSError mcsError;
  38. PBYTE pBerData;
  39. UINT UserDataLength, DataLengthValidate;
  40. TRACE((DEBUG_GCC_DBFLOW,
  41. "GCC: gccDecodeUserData entry\n"));
  42. TS_ASSERT(pData);
  43. TS_ASSERT(DataLength > 0);
  44. mcsError = MCS_NO_ERROR;
  45. // TRACE((DEBUG_GCC_DBDEBUG,
  46. // "GCC: gccDecodeUserData\n"));
  47. // TSMemoryDump(pData, DataLength);
  48. //DataLength must be at least GCC_MINIMUM_DATASIZE
  49. if (DataLength < GCC_MINIMUM_DATASIZE)
  50. {
  51. TRACE((DEBUG_GCC_DBERROR,
  52. "GCC: Send data size is too small\n"));
  53. return MCS_SEND_SIZE_TOO_SMALL;
  54. }
  55. DataLengthValidate = GCC_MINIMUM_DATASIZE;
  56. pBerData = pData;
  57. // T.124 identifier
  58. ASSERT(*pBerData == 0x00);
  59. pBerData++;
  60. ASSERT(*pBerData == 0x05);
  61. pBerData++;
  62. // Chosen object
  63. pBerData += 5;
  64. // PDU length
  65. if (*pBerData & 0x80)
  66. {
  67. pBerData++;
  68. DataLengthValidate++;
  69. }
  70. pBerData++;
  71. // Connect GCC PDU
  72. ASSERT(*pBerData == 0x00);
  73. pBerData++;
  74. ASSERT(*pBerData == 0x08);
  75. pBerData++;
  76. // Conference name, etc.
  77. pBerData += 6;
  78. // Key
  79. TS_ASSERT(strncmp(pBerData, "Duca", 4) == 0);
  80. pUserData->key.key_type = GCC_H221_NONSTANDARD_KEY;
  81. pUserData->key.u.h221_non_standard_id.octet_string_length = 4;
  82. pUserData->key.u.h221_non_standard_id.octet_string = pBerData;
  83. // octet_string
  84. pBerData += 4;
  85. UserDataLength = *pBerData++;
  86. if (UserDataLength & 0x80)
  87. {
  88. UserDataLength = ((UserDataLength & 0x7f) << 8) + *pBerData++;
  89. DataLengthValidate++;
  90. }
  91. //Adjust used datalength
  92. DataLengthValidate += UserDataLength;
  93. //Validate the data length
  94. if (DataLengthValidate > DataLength)
  95. {
  96. TRACE((DEBUG_GCC_DBERROR,
  97. "GCC: Send data size is too small\n"));
  98. return MCS_SEND_SIZE_TOO_SMALL;
  99. }
  100. TS_ASSERT(UserDataLength > 0);
  101. if (UserDataLength)
  102. {
  103. pUserData->octet_string = TSHeapAlloc(0,
  104. sizeof(*pUserData->octet_string),
  105. TS_HTAG_GCC_USERDATA_IN);
  106. if (pUserData->octet_string)
  107. {
  108. pUserData->octet_string->octet_string_length =
  109. (USHORT)UserDataLength;
  110. pUserData->octet_string->octet_string = pBerData;
  111. }
  112. else
  113. {
  114. TRACE((DEBUG_GCC_DBWARN,
  115. "GCC: Cannot allocate octet_string buffer\n"));
  116. mcsError = MCS_ALLOCATION_FAILURE;
  117. }
  118. }
  119. else
  120. {
  121. TRACE((DEBUG_GCC_DBERROR,
  122. "GCC: UserDataLength is zero\n"));
  123. mcsError = MCS_SEND_SIZE_TOO_SMALL;
  124. }
  125. TRACE((DEBUG_GCC_DBFLOW,
  126. "GCC: gccDecodeUserData (len=0x%x) exit - 0x%x\n",
  127. UserDataLength, mcsError));
  128. return (mcsError);
  129. }
  130. //*************************************************************
  131. //
  132. // gccEncodeUserData()
  133. //
  134. // Purpose: Encodes BER data from GCCUserData
  135. //
  136. // Parameters: IN [usMembers] -- Member count
  137. // IN [ppDataList] -- Ptr to GCCUserData array
  138. // OUT [pUserData] -- Ptr to BER data
  139. // OUT [pUserDataLength] -- Ptr to BER data length
  140. //
  141. // Return: MCSError
  142. //
  143. // History: 08-10-97 BrianTa Created
  144. //
  145. //*************************************************************
  146. MCSError
  147. gccEncodeUserData(IN USHORT usMembers,
  148. IN GCCUserData **ppDataList,
  149. OUT PBYTE *pUserData,
  150. OUT UINT *pUserDataLength)
  151. {
  152. MCSError mcsError;
  153. PBYTE pBerData;
  154. UINT UserDataLength;
  155. UINT len;
  156. TRACE((DEBUG_GCC_DBFLOW,
  157. "GCC: gccEncodeUserData entry\n"));
  158. mcsError = MCS_NO_ERROR;
  159. *pUserData = NULL;
  160. *pUserDataLength = 0;
  161. if (ppDataList)
  162. {
  163. len = (*ppDataList)->octet_string->octet_string_length;
  164. pBerData = TSHeapAlloc(0,
  165. len + 32,
  166. TS_HTAG_GCC_USERDATA_OUT);
  167. if (pBerData)
  168. {
  169. UserDataLength = 0;
  170. pBerData[UserDataLength++] = 0x00;
  171. pBerData[UserDataLength++] = 0x05;
  172. pBerData[UserDataLength++] = 0x00;
  173. pBerData[UserDataLength++] = 0x14;
  174. pBerData[UserDataLength++] = 0x7c;
  175. pBerData[UserDataLength++] = 0x00;
  176. pBerData[UserDataLength++] = 0x01;
  177. pBerData[UserDataLength++] = 0x2a;
  178. pBerData[UserDataLength++] = 0x14;
  179. pBerData[UserDataLength++] = 0x76;
  180. pBerData[UserDataLength++] = 0x0a;
  181. pBerData[UserDataLength++] = 0x01;
  182. pBerData[UserDataLength++] = 0x01;
  183. pBerData[UserDataLength++] = 0x00;
  184. pBerData[UserDataLength++] = 0x01;
  185. pBerData[UserDataLength++] = 0xc0;
  186. pBerData[UserDataLength++] = 0x00;
  187. pBerData[UserDataLength++] = (*ppDataList)->key.u.h221_non_standard_id.octet_string[0];
  188. pBerData[UserDataLength++] = (*ppDataList)->key.u.h221_non_standard_id.octet_string[1];
  189. pBerData[UserDataLength++] = (*ppDataList)->key.u.h221_non_standard_id.octet_string[2];
  190. pBerData[UserDataLength++] = (*ppDataList)->key.u.h221_non_standard_id.octet_string[3];
  191. if (len >= 128)
  192. pBerData[UserDataLength++] = (0x80 | (len >> 8));
  193. pBerData[UserDataLength++] =
  194. ((*ppDataList)->octet_string->octet_string_length) & 0xff;
  195. memcpy(&pBerData[UserDataLength],
  196. (*ppDataList)->octet_string->octet_string, len);
  197. *pUserData = (PBYTE) pBerData;
  198. *pUserDataLength = len + UserDataLength;
  199. // TRACE((DEBUG_GCC_DBDEBUG,
  200. // "GCC: gccEncodeUserData\n"));
  201. // TSHeapDump(TS_HEAP_DUMP_ALL,
  202. // *pUserData, *pUserDataLength);
  203. mcsError = MCS_NO_ERROR;
  204. }
  205. else
  206. {
  207. TRACE((DEBUG_GCC_DBWARN,
  208. "GCC: Cannot allocate BER data buffer\n"));
  209. mcsError = MCS_ALLOCATION_FAILURE;
  210. }
  211. }
  212. TRACE((DEBUG_GCC_DBFLOW,
  213. "GCC: gccEncodeUserData exit - 0x%x\n",
  214. mcsError));
  215. return (mcsError);
  216. }
  217. //*************************************************************
  218. //
  219. // gccFreeUserData()
  220. //
  221. // Purpose: Frees prev allocated GCCUserData
  222. //
  223. // Parameters: IN [pUserData] -- Ptr to GCCUserData
  224. //
  225. // History: 08-10-97 BrianTa Created
  226. //
  227. //*************************************************************
  228. VOID
  229. gccFreeUserData(IN GCCUserData *pUserData)
  230. {
  231. if (pUserData->octet_string)
  232. TShareFree(pUserData->octet_string);
  233. }