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.

184 lines
5.8 KiB

  1. #include <windows.h>
  2. #include <wtypes.h>
  3. #include <cfgapi.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <setupapi.h>
  7. #include <basetyps.h>
  8. #include <devguid.h>
  9. #include <tapi.h>
  10. //
  11. // The code below is stolen from private/net/ras/src/ui/setup/src/tapiconf.cxx
  12. //
  13. #define REGISTRY_INSTALLED_TAPI SZ("HARDWARE\\DEVICEMAP\\TAPI DEVICES\\")
  14. #define REGISTRY_ALTERNATE_TAPI SZ("SOFTWARE\\MICROSOFT\\TAPI DEVICES\\")
  15. // note that this definition DOES NOT have trailing \\, because DeleteTree
  16. // doesn't like it.
  17. #define REGISTRY_CONFIGURED_TAPI SZ("SOFTWARE\\MICROSOFT\\RAS\\TAPI DEVICES")
  18. #define TAPI_MEDIA_TYPE SZ("Media Type")
  19. #define TAPI_PORT_ADDRESS SZ("Address")
  20. #define TAPI_PORT_NAME SZ("Friendly Name")
  21. #define TAPI_PORT_USAGE SZ("Usage")
  22. #define LOW_MAJOR_VERSION 0x0001
  23. #define LOW_MINOR_VERSION 0x0003
  24. #define HIGH_MAJOR_VERSION 0x0002
  25. #define HIGH_MINOR_VERSION 0x0000
  26. #define LOW_VERSION ((LOW_MAJOR_VERSION << 16) | LOW_MINOR_VERSION)
  27. #define HIGH_VERSION ((HIGH_MAJOR_VERSION << 16) | HIGH_MINOR_VERSION)
  28. #define MAX_DEVICE_TYPES 64
  29. VOID FAR PASCAL RasTapiCallback (HANDLE, DWORD, DWORD, DWORD, DWORD, DWORD);
  30. DWORD EnumerateTapiModemPorts(DWORD dwBytes, LPTSTR szPortsBuf,
  31. BOOL bWithDelay = FALSE);
  32. DWORD
  33. EnumerateTapiModemPorts(DWORD dwBytes, LPTSTR szPortsBuf, BOOL bWithDelay) {
  34. LINEINITIALIZEEXPARAMS params;
  35. LINEADDRESSCAPS *lineaddrcaps ;
  36. LINEDEVCAPS *linedevcaps ;
  37. LINEEXTENSIONID extensionid ;
  38. HLINEAPP RasLine ;
  39. HINSTANCE RasInstance = GetModuleHandle(TEXT("ICFGNT.DLL"));
  40. DWORD NegotiatedApiVersion ;
  41. DWORD NegotiatedExtVersion = 0;
  42. WORD i, k ;
  43. DWORD lines = 0 ;
  44. BYTE buffer[1000] ;
  45. DWORD totaladdress = 0;
  46. TCHAR *address ;
  47. TCHAR szregkey[512];
  48. LONG lerr;
  49. DWORD dwApiVersion = HIGH_VERSION;
  50. LPTSTR szPorts = szPortsBuf;
  51. *szPorts = '\0';
  52. dwBytes--;
  53. ZeroMemory(&params, sizeof(params));
  54. params.dwTotalSize = sizeof(params);
  55. params.dwOptions = LINEINITIALIZEEXOPTION_USEEVENT;
  56. /* the sleep is necessary here because if this routine is called just after a modem
  57. ** has been added from modem.cpl & unimdm.tsp is running,
  58. ** then a new modem added doesn't show up in the tapi enumeration.
  59. */
  60. //
  61. // We should not always sleep here - should sleep only if ModemWizard was
  62. // launched recently -- VetriV
  63. //
  64. if (bWithDelay)
  65. Sleep(1000L);
  66. if (lerr = lineInitializeExW (&RasLine,
  67. RasInstance,
  68. (LINECALLBACK) RasTapiCallback,
  69. NULL,
  70. &lines,
  71. &dwApiVersion,
  72. &params))
  73. {
  74. return lerr;
  75. }
  76. // Go through all lines to see if we can find a modem
  77. for (i=0; i<lines; i++)
  78. { // for all lines we are interested in get the addresses -> ports
  79. if (lineNegotiateAPIVersion(RasLine, i, LOW_VERSION, HIGH_VERSION, &NegotiatedApiVersion, &extensionid))
  80. {
  81. continue ;
  82. }
  83. memset (buffer, 0, sizeof(buffer)) ;
  84. linedevcaps = (LINEDEVCAPS *)buffer ;
  85. linedevcaps->dwTotalSize = sizeof (buffer) ;
  86. // Get a count of all addresses across all lines
  87. //
  88. if (lineGetDevCapsW (RasLine, i, NegotiatedApiVersion, NegotiatedExtVersion, linedevcaps))
  89. {
  90. continue ;
  91. }
  92. // is this a modem?
  93. if ( linedevcaps->dwMediaModes & LINEMEDIAMODE_DATAMODEM ) {
  94. // first convert all nulls in the device class string to non nulls.
  95. //
  96. DWORD j ;
  97. WCHAR *temp ;
  98. for (j=0, temp = (WCHAR*)((BYTE *)linedevcaps+linedevcaps->dwDeviceClassesOffset); j<linedevcaps->dwDeviceClassesSize; j++, temp++)
  99. {
  100. if (*temp == L'\0')
  101. *temp = L' ' ;
  102. }
  103. //
  104. // select only those devices that have comm/datamodem as a device class
  105. //
  106. LPWSTR wszClassString = wcsstr((WCHAR*)((CHAR *)linedevcaps+linedevcaps->dwDeviceClassesOffset), L"comm/datamodem");
  107. if(wszClassString == NULL)
  108. continue;
  109. }
  110. LONG lRet;
  111. HLINE lhLine = 0;
  112. lRet = lineOpen(RasLine, i, &lhLine, dwApiVersion, 0, 0, LINECALLPRIVILEGE_NONE, 0, NULL);
  113. if(lRet != 0)
  114. continue;
  115. LPVARSTRING lpVarString;
  116. TCHAR buf[1000];
  117. lpVarString = (LPVARSTRING) buf;
  118. lpVarString->dwTotalSize = 1000;
  119. lRet = lineGetID(lhLine, 0, 0, LINECALLSELECT_LINE,
  120. (LPVARSTRING) lpVarString, TEXT("comm/datamodem/portname"));
  121. if(lRet != 0)
  122. continue;
  123. LPTSTR szPortName;
  124. if (lpVarString->dwStringSize)
  125. szPortName = (LPTSTR) ((LPBYTE) lpVarString + ((LPVARSTRING) lpVarString) -> dwStringOffset);
  126. //
  127. // Append port name to port list
  128. //
  129. UINT len = lstrlen(szPortName) + 1;
  130. if(dwBytes < len)
  131. return(ERROR_SUCCESS);
  132. lstrcpy(szPorts, szPortName);
  133. szPorts += len;
  134. *szPorts = '\0';
  135. if (lhLine) lineClose(lhLine);
  136. }
  137. lineShutdown(RasLine);
  138. return ERROR_SUCCESS ;
  139. }
  140. VOID FAR PASCAL
  141. RasTapiCallback (HANDLE context, DWORD msg, DWORD instance, DWORD param1, DWORD param2, DWORD param3)
  142. {
  143. // dummy callback routine because the full blown TAPI now demands that
  144. // lineinitialize provide this routine.
  145. }