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.

204 lines
6.4 KiB

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