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.

353 lines
8.4 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. faxmodem.c
  5. Abstract:
  6. This module contains code to read the adaptive
  7. answer modem list from the faxsetup.inf file.
  8. Author:
  9. Wesley Witt (wesw) 22-Sep-1997
  10. Revision History:
  11. --*/
  12. #include <windows.h>
  13. #include <setupapi.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <tchar.h>
  17. #include <tapi.h>
  18. #include "faxreg.h"
  19. #include "faxutil.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. VOID
  24. CALLBACK
  25. lineCallbackFunc(
  26. DWORD hDevice,
  27. DWORD dwMsg,
  28. DWORD_PTR dwCallbackInstance,
  29. DWORD_PTR dwParam1,
  30. DWORD_PTR dwParam2,
  31. DWORD_PTR dwParam3
  32. )
  33. {
  34. UNREFERENCED_PARAMETER (hDevice);
  35. UNREFERENCED_PARAMETER (dwMsg);
  36. UNREFERENCED_PARAMETER (dwCallbackInstance);
  37. UNREFERENCED_PARAMETER (dwParam1);
  38. UNREFERENCED_PARAMETER (dwParam2);
  39. UNREFERENCED_PARAMETER (dwParam3);
  40. } // lineCallbackFunc
  41. LPLINEDEVCAPS
  42. SmartLineGetDevCaps(
  43. HLINEAPP hLineApp,
  44. DWORD dwDeviceId,
  45. DWORD dwAPIVersion
  46. )
  47. /*++
  48. Routine name : SmartLineGetDevCaps
  49. Routine description:
  50. Gets the line capabilities for a TAPI line
  51. Author:
  52. Eran Yariv (EranY), Jul, 2000
  53. Arguments:
  54. hLineApp [in] - Handle to TAPI
  55. dwDeviceId [in] - Line id
  56. dwAPIVersion [in] - Negotiated TAPI API version
  57. Return Value:
  58. Pointer to allocated lide device capabilities data
  59. --*/
  60. {
  61. DWORD dwLineDevCapsSize;
  62. LPLINEDEVCAPS lpLineDevCaps = NULL;
  63. DWORD dwRes = ERROR_SUCCESS;
  64. DEBUG_FUNCTION_NAME(TEXT("SmartLineGetDevCaps"))
  65. //
  66. // Allocate the initial linedevcaps structure
  67. //
  68. dwLineDevCapsSize = sizeof(LINEDEVCAPS) + 4096;
  69. lpLineDevCaps = (LPLINEDEVCAPS) MemAlloc( dwLineDevCapsSize );
  70. if (!lpLineDevCaps)
  71. {
  72. DebugPrintEx(
  73. DEBUG_ERR,
  74. TEXT("Can't allocate %ld bytes for LINEDEVCAPS"),
  75. dwLineDevCapsSize);
  76. return NULL;
  77. }
  78. lpLineDevCaps->dwTotalSize = dwLineDevCapsSize;
  79. dwRes = lineGetDevCaps(
  80. hLineApp,
  81. dwDeviceId,
  82. dwAPIVersion,
  83. 0, // Always refer to address 0
  84. lpLineDevCaps
  85. );
  86. if ((ERROR_SUCCESS != dwRes) && (LINEERR_STRUCTURETOOSMALL != dwRes))
  87. {
  88. DebugPrintEx(
  89. DEBUG_ERR,
  90. TEXT("lineGetDevCaps failed with 0x%08x"),
  91. dwRes);
  92. goto exit;
  93. }
  94. if (lpLineDevCaps->dwNeededSize > lpLineDevCaps->dwTotalSize)
  95. {
  96. //
  97. // Re-allocate the linedevcaps structure
  98. //
  99. dwLineDevCapsSize = lpLineDevCaps->dwNeededSize;
  100. MemFree( lpLineDevCaps );
  101. lpLineDevCaps = (LPLINEDEVCAPS) MemAlloc( dwLineDevCapsSize );
  102. if (!lpLineDevCaps)
  103. {
  104. DebugPrintEx(
  105. DEBUG_ERR,
  106. TEXT("Can't allocate %ld bytes for LINEDEVCAPS"),
  107. dwLineDevCapsSize);
  108. return NULL;
  109. }
  110. lpLineDevCaps->dwTotalSize = dwLineDevCapsSize;
  111. dwRes = lineGetDevCaps(
  112. hLineApp,
  113. dwDeviceId,
  114. dwAPIVersion,
  115. 0, // Always refer to address 0
  116. lpLineDevCaps
  117. );
  118. if (ERROR_SUCCESS != dwRes)
  119. {
  120. //
  121. // lineGetDevCaps() can fail with error code 0x8000004b
  122. // if a device has been deleted and tapi has not been
  123. // cycled. this is caused by the fact that tapi leaves
  124. // a phantom device in it's device list. the error is
  125. // benign and the device can safely be ignored.
  126. //
  127. DebugPrintEx(
  128. DEBUG_ERR,
  129. TEXT("lineGetDevCaps failed with 0x%08x"),
  130. dwRes);
  131. goto exit;
  132. }
  133. }
  134. exit:
  135. if (dwRes != ERROR_SUCCESS)
  136. {
  137. MemFree( lpLineDevCaps );
  138. lpLineDevCaps = NULL;
  139. SetLastError(dwRes);
  140. }
  141. return lpLineDevCaps;
  142. } // SmartLineGetDevCaps
  143. BOOL
  144. IsDeviceModem (
  145. LPLINEDEVCAPS lpLineCaps,
  146. LPCTSTR lpctstrUnimodemTspName
  147. )
  148. /*++
  149. Routine name : IsDeviceModem
  150. Routine description:
  151. Is a TAPI line a modem?
  152. Author:
  153. Eran Yariv (EranY), Jul, 2000
  154. Arguments:
  155. lpLineCaps [in] - Line capabilities buffer
  156. lpctstrUnimodemTspName [in] - Full name of the Unimodem TSP
  157. Return Value:
  158. TRUE if a TAPI line is a modem, FALSE otherwise.
  159. --*/
  160. {
  161. LPTSTR lptstrDeviceClassList;
  162. BOOL bRes = FALSE;
  163. DEBUG_FUNCTION_NAME(TEXT("IsDeviceModem"))
  164. if (lpLineCaps->dwDeviceClassesSize && lpLineCaps->dwDeviceClassesOffset)
  165. {
  166. //
  167. // Scan multi-string for modem class
  168. //
  169. lptstrDeviceClassList = (LPTSTR)((LPBYTE) lpLineCaps + lpLineCaps->dwDeviceClassesOffset);
  170. while (*lptstrDeviceClassList)
  171. {
  172. if (_tcscmp(lptstrDeviceClassList,TEXT("comm/datamodem")) == 0)
  173. {
  174. bRes = TRUE;
  175. break;
  176. }
  177. lptstrDeviceClassList += (_tcslen(lptstrDeviceClassList) + 1);
  178. }
  179. }
  180. if ((!(lpLineCaps->dwBearerModes & LINEBEARERMODE_VOICE)) ||
  181. (!(lpLineCaps->dwBearerModes & LINEBEARERMODE_PASSTHROUGH)))
  182. {
  183. //
  184. // Unacceptable modem device type
  185. //
  186. bRes = FALSE;
  187. }
  188. if (lpLineCaps->dwProviderInfoSize && lpLineCaps->dwProviderInfoOffset)
  189. {
  190. //
  191. // Provider (TSP) name is there
  192. //
  193. if (_tcscmp((LPTSTR)((LPBYTE) lpLineCaps + lpLineCaps->dwProviderInfoOffset),
  194. lpctstrUnimodemTspName) != 0)
  195. {
  196. //
  197. // Our T30 modem FSP only works with Unimodem TSP
  198. //
  199. bRes = FALSE;
  200. }
  201. }
  202. return bRes;
  203. } // IsDeviceModem
  204. DWORD
  205. GetFaxCapableTapiLinesCount (
  206. LPDWORD lpdwCount,
  207. LPCTSTR lpctstrUnimodemTspName
  208. )
  209. /*++
  210. Routine name : GetFaxCapableTapiLinesCount
  211. Routine description:
  212. Counter the number of Fax-capable TAPI lines in the system
  213. Author:
  214. Eran Yariv (EranY), Jul, 2000
  215. Arguments:
  216. lpdwCount [out] - Pointer to count of fax-capable Tapi lines
  217. lpctstrUnimodemTspName [in] - Full name of the Unimodem TSP
  218. Return Value:
  219. Standard Win32 error code
  220. --*/
  221. {
  222. DWORD dwRes;
  223. LINEINITIALIZEEXPARAMS LineInitializeExParams = {sizeof (LINEINITIALIZEEXPARAMS), 0, 0, 0, 0, 0};
  224. HLINEAPP hLineApp = NULL;
  225. DWORD dwTapiDevices;
  226. DWORD dwLocalTapiApiVersion = 0x00020000;
  227. DWORD dwCount = 0;
  228. DWORD dwIndex;
  229. DEBUG_FUNCTION_NAME(TEXT("GetFaxCapableTapiLinesCount"))
  230. dwRes = lineInitializeEx(
  231. &hLineApp,
  232. GetModuleHandle(NULL),
  233. lineCallbackFunc,
  234. FAX_SERVICE_DISPLAY_NAME,
  235. &dwTapiDevices,
  236. &dwLocalTapiApiVersion,
  237. &LineInitializeExParams
  238. );
  239. if (ERROR_SUCCESS != dwRes)
  240. {
  241. DebugPrintEx(
  242. DEBUG_ERR,
  243. TEXT("lineInitializeEx failed with %ld"),
  244. dwRes);
  245. goto exit;
  246. }
  247. for (dwIndex = 0; dwIndex < dwTapiDevices; dwIndex++)
  248. {
  249. //
  250. // For each device, get it's caps
  251. //
  252. LPLINEDEVCAPS lpLineCaps = SmartLineGetDevCaps (hLineApp, dwIndex, dwLocalTapiApiVersion);
  253. if (!lpLineCaps)
  254. {
  255. //
  256. // Couldn't get the device capabilities
  257. //
  258. dwRes = GetLastError ();
  259. DebugPrintEx(
  260. DEBUG_ERR,
  261. TEXT("SmartLineGetDevCaps failed with %ld"),
  262. dwRes);
  263. continue;
  264. }
  265. if ((
  266. (lpLineCaps->dwMediaModes & LINEMEDIAMODE_DATAMODEM) &&
  267. IsDeviceModem(lpLineCaps, lpctstrUnimodemTspName)
  268. )
  269. ||
  270. (lpLineCaps->dwMediaModes & LINEMEDIAMODE_G3FAX)
  271. )
  272. {
  273. //
  274. // This is a fax-capable device
  275. //
  276. dwCount++;
  277. }
  278. MemFree (lpLineCaps);
  279. }
  280. dwRes = ERROR_SUCCESS;
  281. exit:
  282. if (hLineApp)
  283. {
  284. lineShutdown (hLineApp);
  285. }
  286. if (ERROR_SUCCESS == dwRes)
  287. {
  288. *lpdwCount = dwCount;
  289. }
  290. return dwRes;
  291. } // GetFaxCapableTapiLinesCount
  292. #ifdef __cplusplus
  293. }
  294. #endif