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.

407 lines
12 KiB

  1. //++
  2. //
  3. // Copyright (C) Microsoft Corporation, 1987 - 1999
  4. //
  5. // Module Name:
  6. //
  7. // modemtst.c
  8. //
  9. // Abstract:
  10. //
  11. // Queries into network drivers
  12. //
  13. // Author:
  14. //
  15. // Anilth - 4-20-1998
  16. //
  17. // Environment:
  18. //
  19. // User mode only.
  20. // Contains NT-specific code.
  21. //
  22. // Revision History:
  23. //
  24. //--
  25. #include "precomp.h"
  26. #undef IsEqualGUID
  27. #include <ras.h>
  28. #include <tapi.h>
  29. #include <unimodem.h>
  30. #define PRINT_MODEM( _i, _ids, _mdm) \
  31. PrintMessage(pParams, _ids, \
  32. MAP_ON_OFF(pResults->Modem.pModemDevice[_i].dwModemOptions & _mdm))
  33. void GetLineId(NETDIAG_RESULT *pResults,
  34. int cModems,
  35. HLINEAPP hLineApp,
  36. DWORD dwDeviceID);
  37. HRESULT
  38. ModemTest(NETDIAG_PARAMS* pParams, NETDIAG_RESULT* pResults)
  39. //
  40. // Description:
  41. //
  42. // This function performs diagnostics on all the line devices
  43. //
  44. // Arguments
  45. // None
  46. //
  47. // Return:
  48. // None
  49. {
  50. LONG lReturn;
  51. DWORD dwNumDevs = 0;
  52. DWORD dwAPIVersion = TAPI_CURRENT_VERSION;
  53. HLINEAPP hLineApp = 0;
  54. DWORD dwDeviceID;
  55. // char pszDeviceClass[] = "tapi/line/diagnostics";
  56. char pszDeviceClass[] = "comm";
  57. LPVARSTRING lpVarString = NULL;
  58. VARSTRING varStringT;
  59. DWORD dwSize;
  60. LINEINITIALIZEEXPARAMS lineParams;
  61. int cModems = 0;
  62. PUMDEVCFG lpDevConfig = NULL;
  63. LPMODEMSETTINGS lpModemSettings = NULL;
  64. LPCOMMCONFIG lpCommConfig = NULL;
  65. HRESULT hr = hrOK;
  66. PrintStatusMessage(pParams, 4, IDS_MODEM_STATUS_MSG);
  67. ZeroMemory(&lineParams, sizeof(lineParams));
  68. lineParams.dwTotalSize = sizeof(lineParams);
  69. lineParams.dwOptions = LINEINITIALIZEEXOPTION_USEEVENT;
  70. pResults->Modem.fPerformed = TRUE;
  71. lReturn = lineInitializeEx(
  72. &hLineApp,
  73. NULL,
  74. NULL,
  75. "NetDiag",
  76. &dwNumDevs,
  77. &dwAPIVersion,
  78. &lineParams);
  79. //
  80. // Check whether this version can support our calls.
  81. //
  82. if (lReturn != 0)
  83. {
  84. SetMessage(&pResults->Modem.ndOutput,
  85. Nd_Quiet,
  86. IDS_MODEM_LINEINIT_FAILED,
  87. lReturn);
  88. pResults->Modem.hr = E_FAIL;
  89. return S_FALSE;
  90. }
  91. if (dwNumDevs == 0)
  92. {
  93. SetMessage(&pResults->Modem.ndOutput,
  94. Nd_ReallyVerbose,
  95. IDS_MODEM_NO_DEVICES);
  96. pResults->Modem.hr = hrOK;
  97. pResults->Modem.fPerformed = FALSE; //test is skipped
  98. return hrOK;
  99. }
  100. // Need to allocate a device structure for each device
  101. Free(pResults->Modem.pModemDevice);
  102. pResults->Modem.pModemDevice = (MODEM_DEVICE *) Malloc(
  103. sizeof(MODEM_DEVICE) * dwNumDevs);
  104. if (pResults->Modem.pModemDevice == NULL)
  105. return E_OUTOFMEMORY;
  106. ZeroMemory(pResults->Modem.pModemDevice,
  107. sizeof(MODEM_DEVICE) * dwNumDevs);
  108. pResults->Modem.cModems = dwNumDevs;
  109. //
  110. // Get the line device configuration settings
  111. //
  112. for (dwDeviceID = 0; dwDeviceID < dwNumDevs ; dwDeviceID++)
  113. {
  114. Free(lpVarString);
  115. lpVarString = NULL;
  116. // Get the proper size for the structure
  117. ZeroMemory(&varStringT, sizeof(VARSTRING));
  118. varStringT.dwTotalSize = sizeof(VARSTRING);
  119. lReturn = lineGetDevConfig(dwDeviceID,
  120. &varStringT,
  121. pszDeviceClass);
  122. if ((lReturn != 0) && (lReturn != LINEERR_STRUCTURETOOSMALL))
  123. continue;
  124. // dwSize = varStringT.dwNeededSize + sizeof(VARSTRING);
  125. dwSize = varStringT.dwNeededSize;
  126. lpVarString = (VARSTRING *) Malloc(dwSize);
  127. ZeroMemory(lpVarString, dwSize);
  128. lpVarString->dwTotalSize = dwSize;
  129. lpVarString->dwStringFormat = STRINGFORMAT_BINARY;
  130. lReturn = lineGetDevConfig(dwDeviceID,
  131. lpVarString,
  132. pszDeviceClass);
  133. if (lReturn != 0)
  134. {
  135. DebugMessage2("Error: lineGetDevConfig for line id %d\n",lReturn);
  136. continue;
  137. }
  138. //
  139. // Interpret the results
  140. //
  141. if (lpVarString->dwStringFormat == STRINGFORMAT_BINARY
  142. && lpVarString->dwStringSize > sizeof(UMDEVCFG))
  143. {
  144. lpDevConfig = (PUMDEVCFG) ((LPBYTE) lpVarString + lpVarString->dwStringOffset);
  145. lpCommConfig = &lpDevConfig->commconfig;
  146. if (lpCommConfig->dwProviderSubType == PST_MODEM)
  147. {
  148. lpModemSettings = (LPMODEMSETTINGS)((LPBYTE) lpCommConfig + lpCommConfig->dwProviderOffset);
  149. GetLineId(pResults, cModems, hLineApp, dwDeviceID);
  150. pResults->Modem.pModemDevice[cModems].dwNegotiatedSpeed =
  151. lpModemSettings->dwNegotiatedDCERate;
  152. pResults->Modem.pModemDevice[cModems].dwModemOptions =
  153. lpModemSettings->dwNegotiatedModemOptions;
  154. pResults->Modem.pModemDevice[cModems].dwDeviceID = dwDeviceID;
  155. cModems++;
  156. }
  157. }
  158. }
  159. pResults->Modem.cModems = cModems;
  160. Free(lpVarString);
  161. //
  162. // Shutdown TAPI
  163. //
  164. lReturn = lineShutdown(hLineApp);
  165. if (lReturn != 0)
  166. {
  167. // if (pParams->fDebugVerbose)
  168. // printf("Error : lineShutdown!\n");
  169. pResults->Modem.hr = S_FALSE;
  170. return S_FALSE;
  171. }
  172. pResults->Modem.hr = hrOK;
  173. return hrOK;
  174. }
  175. /*!--------------------------------------------------------------------------
  176. ModemGlobalPrint
  177. -
  178. Author: KennT
  179. ---------------------------------------------------------------------------*/
  180. void ModemGlobalPrint( NETDIAG_PARAMS* pParams,
  181. NETDIAG_RESULT* pResults)
  182. {
  183. int i;
  184. if (pParams->fVerbose || !FHrOK(pResults->Modem.hr))
  185. {
  186. PrintNewLine(pParams, 2);
  187. PrintTestTitleResult(pParams, IDS_MODEM_LONG, IDS_MODEM_SHORT, pResults->Modem.fPerformed,
  188. pResults->Modem.hr, 0);
  189. PrintNdMessage(pParams, &pResults->Modem.ndOutput);
  190. if (pParams->fReallyVerbose)
  191. {
  192. for ( i=0; i<pResults->Modem.cModems; i++)
  193. {
  194. PrintNewLine(pParams, 1);
  195. PrintMessage(pParams, IDS_MODEM_NAME,
  196. pResults->Modem.pModemDevice[i].pszName);
  197. PrintMessage(pParams, IDS_MODEM_DEVICEID,
  198. pResults->Modem.pModemDevice[i].dwDeviceID);
  199. PrintMessage(pParams, IDS_MODEM_PORT,
  200. pResults->Modem.pModemDevice[i].pszPort);
  201. PrintMessage(pParams, IDS_MODEM_NEGOTIATED_SPEED,
  202. pResults->Modem.pModemDevice[i].dwNegotiatedSpeed);
  203. PRINT_MODEM( i, IDS_MODEM_COMPRESSION, MDM_COMPRESSION);
  204. PRINT_MODEM( i, IDS_MODEM_ERROR_CONTROL, MDM_ERROR_CONTROL);
  205. PRINT_MODEM( i, IDS_MODEM_FORCED_EC, MDM_FORCED_EC);
  206. PRINT_MODEM( i, IDS_MODEM_CELLULAR, MDM_CELLULAR);
  207. PRINT_MODEM( i, IDS_MODEM_FLOWCONTROL_HARD, MDM_FLOWCONTROL_HARD);
  208. PRINT_MODEM( i, IDS_MODEM_FLOWCONTROL_SOFT, MDM_FLOWCONTROL_SOFT);
  209. PRINT_MODEM( i, IDS_MODEM_CCITT_OVERRIDE, MDM_CCITT_OVERRIDE);
  210. PRINT_MODEM( i, IDS_MODEM_SPEED_ADJUST, MDM_SPEED_ADJUST);
  211. PRINT_MODEM( i, IDS_MODEM_TONE_DIAL, MDM_TONE_DIAL);
  212. PRINT_MODEM( i, IDS_MODEM_BLIND_DIAL, MDM_BLIND_DIAL);
  213. PRINT_MODEM( i, IDS_MODEM_V23_OVERRIDE, MDM_V23_OVERRIDE);
  214. }
  215. }
  216. }
  217. }
  218. /*!--------------------------------------------------------------------------
  219. ModemPerInterfacePrint
  220. -
  221. Author: KennT
  222. ---------------------------------------------------------------------------*/
  223. void ModemPerInterfacePrint( NETDIAG_PARAMS* pParams,
  224. NETDIAG_RESULT* pResults,
  225. INTERFACE_RESULT *pInterfaceResults)
  226. {
  227. // no per-interface results
  228. }
  229. /*!--------------------------------------------------------------------------
  230. ModemCleanup
  231. -
  232. Author: KennT
  233. ---------------------------------------------------------------------------*/
  234. void ModemCleanup( NETDIAG_PARAMS* pParams, NETDIAG_RESULT* pResults)
  235. {
  236. int i;
  237. ClearMessage(&pResults->Modem.ndOutput);
  238. for (i=0; i<pResults->Modem.cModems; i++)
  239. {
  240. Free(pResults->Modem.pModemDevice[i].pszPort);
  241. pResults->Modem.pModemDevice[i].pszPort = NULL;
  242. }
  243. Free(pResults->Modem.pModemDevice);
  244. pResults->Modem.pModemDevice = NULL;
  245. pResults->Modem.cModems = 0;
  246. }
  247. void GetLineId(NETDIAG_RESULT *pResults,
  248. int cModems,
  249. HLINEAPP hLineApp,
  250. DWORD dwDeviceID)
  251. {
  252. HLINE hLine = 0;
  253. LONG lReturn;
  254. VARSTRING varString;
  255. VARSTRING * lpVarString;
  256. LINEDEVCAPS lineDevCaps;
  257. LINEDEVCAPS * pLineDevCaps = NULL;
  258. lReturn = lineOpen(hLineApp,
  259. dwDeviceID,
  260. &hLine,
  261. TAPI_CURRENT_VERSION,
  262. 0,
  263. 0,
  264. LINECALLPRIVILEGE_NONE,
  265. LINEMEDIAMODE_UNKNOWN,
  266. NULL);
  267. if (lReturn == 0)
  268. {
  269. ZeroMemory(&varString, sizeof(VARSTRING));
  270. varString.dwTotalSize = sizeof(VARSTRING);
  271. lReturn = lineGetID(hLine, 0, 0, LINECALLSELECT_LINE,
  272. &varString, "comm/datamodem/portname");
  273. if ((lReturn == 0) || (lReturn == LINEERR_STRUCTURETOOSMALL))
  274. {
  275. lpVarString = (VARSTRING *) Malloc(varString.dwNeededSize);
  276. if (lpVarString)
  277. {
  278. ZeroMemory(lpVarString, varString.dwNeededSize);
  279. lpVarString->dwTotalSize = varString.dwNeededSize;
  280. lReturn = lineGetID(hLine, 0, 0, LINECALLSELECT_LINE,
  281. lpVarString, "comm/datamodem/portname");
  282. pResults->Modem.pModemDevice[cModems].pszPort =
  283. StrDupTFromA((char *) (lpVarString + 1));
  284. Free(lpVarString);
  285. }
  286. }
  287. lineClose(hLine);
  288. }
  289. // Get the name of this line
  290. ZeroMemory(&lineDevCaps, sizeof(lineDevCaps));
  291. lineDevCaps.dwTotalSize = sizeof(LINEDEVCAPS);
  292. lineDevCaps.dwStringFormat = STRINGFORMAT_UNICODE;
  293. lReturn = lineGetDevCaps(hLineApp,
  294. dwDeviceID,
  295. TAPI_CURRENT_VERSION,
  296. 0,
  297. &lineDevCaps);
  298. if ((lReturn == 0) || (lReturn == LINEERR_STRUCTURETOOSMALL))
  299. {
  300. pLineDevCaps = (LINEDEVCAPS *) Malloc(lineDevCaps.dwNeededSize);
  301. if (pLineDevCaps)
  302. {
  303. ZeroMemory(pLineDevCaps, lineDevCaps.dwNeededSize);
  304. pLineDevCaps->dwTotalSize = lineDevCaps.dwNeededSize;
  305. pLineDevCaps->dwStringFormat = STRINGFORMAT_UNICODE;
  306. lReturn = lineGetDevCaps(hLineApp,
  307. dwDeviceID,
  308. TAPI_CURRENT_VERSION,
  309. 0,
  310. pLineDevCaps);
  311. if (lReturn == 0)
  312. {
  313. if (pLineDevCaps->dwStringFormat == STRINGFORMAT_UNICODE)
  314. {
  315. pResults->Modem.pModemDevice[cModems].pszName =
  316. StrDupTFromW((WCHAR *) (((BYTE *) pLineDevCaps) +
  317. pLineDevCaps->dwLineNameOffset));
  318. }
  319. else
  320. {
  321. pResults->Modem.pModemDevice[cModems].pszName =
  322. StrDupTFromA((char *) (((BYTE *) pLineDevCaps) +
  323. pLineDevCaps->dwLineNameOffset));
  324. }
  325. }
  326. }
  327. }
  328. if (pLineDevCaps)
  329. Free(pLineDevCaps);
  330. }