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

343 lines
9.8 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. version.c
  5. Abstract:
  6. TAPI Service Provider functions related to negotiating version.
  7. TSPI_lineNegotiateTSPIVersion
  8. Environment:
  9. User Mode - Win32
  10. --*/
  11. ///////////////////////////////////////////////////////////////////////////////
  12. // //
  13. // Include files //
  14. // //
  15. ///////////////////////////////////////////////////////////////////////////////
  16. #include "globals.h"
  17. #include "provider.h"
  18. #include "version.h"
  19. #include "line.h"
  20. ///////////////////////////////////////////////////////////////////////////////
  21. // //
  22. // Private procedures //
  23. // //
  24. ///////////////////////////////////////////////////////////////////////////////
  25. BOOL
  26. H323NegotiateTSPIVersion(
  27. DWORD dwLowVersion,
  28. DWORD dwHighVersion,
  29. PDWORD pdwTSPIVersion
  30. )
  31. /*++
  32. Routine Description:
  33. This function determines whether or not specified TSPI version is
  34. supported by the service provider.
  35. Arguments:
  36. dwLowVersion - Specifies the lowest TSPI version number under which the
  37. TAPI DLL is willing to operate. The most-significant WORD is the
  38. major version number and the least-significant WORD is the minor
  39. version number.
  40. dwHighVersion - Specifies the highest TSPI version number under which
  41. the TAPI DLL is willing to operate. The most-significant WORD is the
  42. major version number and the least-significant WORD is the minor
  43. version number.
  44. pdwTSPIVersion - Specifies a far pointer to a DWORD. The service
  45. provider fills this location with the highest TSPI version number,
  46. within the range requested by the caller, under which the service
  47. provider is willing to operate. The most-significant WORD is the
  48. major version number and the least-significant WORD is the minor
  49. version number.
  50. Return Values:
  51. Returns true if successful.
  52. --*/
  53. {
  54. // validate extension version range
  55. if ((TSPI_VERSION_HI <= dwHighVersion) &&
  56. (TSPI_VERSION_HI >= dwLowVersion)) {
  57. // save negotiated version
  58. *pdwTSPIVersion = TSPI_VERSION_HI;
  59. // success
  60. return TRUE;
  61. } else if ((dwHighVersion <= TSPI_VERSION_HI) &&
  62. (dwHighVersion >= TSPI_VERSION_LO)) {
  63. // save negotiated version
  64. *pdwTSPIVersion = dwHighVersion;
  65. // success
  66. return TRUE;
  67. }
  68. H323DBG((
  69. DEBUG_LEVEL_ERROR,
  70. "failed to negotiate version.\n"
  71. ));
  72. // failure
  73. return FALSE;
  74. }
  75. ///////////////////////////////////////////////////////////////////////////////
  76. // //
  77. // Public procedures //
  78. // //
  79. ///////////////////////////////////////////////////////////////////////////////
  80. BOOL
  81. H323ValidateTSPIVersion(
  82. DWORD dwTSPIVersion
  83. )
  84. /*++
  85. Routine Description:
  86. This function determines whether or not specified TSPI version is
  87. supported by the service provider.
  88. Arguments:
  89. dwTSPIVersion - Specifies the TSPI version to validate.
  90. Return Values:
  91. Returns true if successful.
  92. --*/
  93. {
  94. // see if specified version is supported
  95. if ((dwTSPIVersion >= TSPI_VERSION_LO) &&
  96. (dwTSPIVersion <= TSPI_VERSION_HI)) {
  97. // success
  98. return TRUE;
  99. }
  100. H323DBG((
  101. DEBUG_LEVEL_ERROR,
  102. "do not support TSPI version %d.%d.\n",
  103. HIWORD(dwTSPIVersion),
  104. LOWORD(dwTSPIVersion)
  105. ));
  106. // failure
  107. return FALSE;
  108. }
  109. BOOL
  110. H323ValidateExtVersion(
  111. DWORD dwExtVersion
  112. )
  113. /*++
  114. Routine Description:
  115. This function determines whether or not specified extension version is
  116. supported by the service provider.
  117. Arguments:
  118. dwExtVersion - Specifies the extension version to validate.
  119. Return Values:
  120. Returns true if successful.
  121. --*/
  122. {
  123. // see if specified version is supported
  124. if ((dwExtVersion >= H323_VERSION_LO) &&
  125. (dwExtVersion <= H323_VERSION_HI)) {
  126. // success
  127. return TRUE;
  128. }
  129. H323DBG((
  130. DEBUG_LEVEL_ERROR,
  131. "do not support extension version %d.%d.\n",
  132. HIWORD(dwExtVersion),
  133. LOWORD(dwExtVersion)
  134. ));
  135. // failure
  136. return FALSE;
  137. }
  138. ///////////////////////////////////////////////////////////////////////////////
  139. // //
  140. // TSPI procedures //
  141. // //
  142. ///////////////////////////////////////////////////////////////////////////////
  143. LONG
  144. TSPIAPI
  145. TSPI_lineNegotiateTSPIVersion(
  146. DWORD dwDeviceID,
  147. DWORD dwLowVersion,
  148. DWORD dwHighVersion,
  149. PDWORD pdwTSPIVersion
  150. )
  151. /*++
  152. Routine Description:
  153. This function returns the highest SPI version the Service Provider is
  154. willing to operate under for this device given the range of possible
  155. SPI versions.
  156. The TAPI DLL typically calls this function early in the initialization
  157. sequence for each line device. In addition, it calls this with the
  158. value INITIALIZE_NEGOTIATION for dwDeviceID to negotiate an interface
  159. version for calling early initialization functions.
  160. Note that when dwDeviceID is INITIALIZE_NEGOTIATION, this function must
  161. not return LINEERR_OPERATIONUNAVAIL, since this function (with that value)
  162. is mandatory for negotiating the overall interface version even if the
  163. service provider supports no line devices.
  164. Negotiation of an Extension version is done through the separate
  165. procedure TSPI_lineNegotiateExtVersion.
  166. Arguments:
  167. dwDeviceID - Identifies the line device for which interface version
  168. negotiation is to be performed. In addition to device IDs within
  169. the range the Service Provider supports, this may be the value:
  170. INITIALIZE_NEGOTIATION - This value is used to signify that an overall
  171. interface version is to be negotiated. Such an interface version
  172. is required for functions that can be called early in the
  173. initialization sequence, i.e., before the device ID range has
  174. been set.
  175. dwLowVersion - Specifies the lowest TSPI version number under which the
  176. TAPI DLL is willing to operate. The most-significant WORD is the
  177. major version number and the least-significant WORD is the minor
  178. version number.
  179. dwHighVersion - Specifies the highest TSPI version number under which
  180. the TAPI DLL is willing to operate. The most-significant WORD is the
  181. major version number and the least-significant WORD is the minor
  182. version number.
  183. pdwTSPIVersion - Specifies a far pointer to a DWORD. The service
  184. provider fills this location with the highest TSPI version number,
  185. within the range requested by the caller, under which the service
  186. provider is willing to operate. The most-significant WORD is the
  187. major version number and the least-significant WORD is the minor
  188. version number. If the requested range does not overlap the range
  189. supported by the service provider, the function returns
  190. LINEERR_INCOMPATIBLEAPIVERSION.
  191. Return Values:
  192. Returns zero if the function is successful, or a negative error number
  193. if an error has occurred. Possible return values are as follows:
  194. LINEERR_BADDEVICEID - The specified device identifier or line device
  195. identifier (such as in a dwDeviceID parameter) is invalid or
  196. out of range.
  197. LINEERR_INCOMPATIBLEAPIVERSION - The application requested an API
  198. version or version range that is either incompatible or cannot
  199. be supported by the Telephony API implementation and/or
  200. corresponding service provider.
  201. LINEERR_OPERATIONFAILED - The operation failed for an unspecified
  202. or unknown reason.
  203. --*/
  204. {
  205. DWORD dwTSPIVersion = UNINITIALIZED;
  206. PH323_LINE pLine = NULL;
  207. // see if this is a init line device
  208. if ((DWORD_PTR)dwDeviceID == INITIALIZE_NEGOTIATION) {
  209. H323DBG((
  210. DEBUG_LEVEL_VERBOSE,
  211. "tapisrv supports tspi version %d.%d through %d.%d.\n",
  212. HIWORD(dwLowVersion),
  213. LOWORD(dwLowVersion),
  214. HIWORD(dwHighVersion),
  215. LOWORD(dwHighVersion)
  216. ));
  217. // perform version negotiation
  218. if (!H323NegotiateTSPIVersion(
  219. dwLowVersion,
  220. dwHighVersion,
  221. &dwTSPIVersion)) {
  222. // negotiated version not agreed upon
  223. return LINEERR_INCOMPATIBLEAPIVERSION;
  224. }
  225. // see if this is a valid line device
  226. } else if (H323GetLineFromIDAndLock(&pLine, (DWORD)dwDeviceID)) {
  227. // perform version negotiation
  228. if (!H323NegotiateTSPIVersion(
  229. dwLowVersion,
  230. dwHighVersion,
  231. &dwTSPIVersion)) {
  232. // release line device
  233. H323UnlockLine(pLine);
  234. // negotiated version not agreed upon
  235. return LINEERR_INCOMPATIBLEAPIVERSION;
  236. }
  237. // release line device
  238. H323UnlockLine(pLine);
  239. } else {
  240. // do not recognize device
  241. return LINEERR_BADDEVICEID;
  242. }
  243. // return negotiated version
  244. *pdwTSPIVersion = dwTSPIVersion;
  245. // success
  246. return NOERROR;
  247. }
  248.