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.

435 lines
9.3 KiB

  1. /*++
  2. Copyright (c) 1989-1994 Microsoft Corporation
  3. Module Name:
  4. rtnetcfg.c
  5. Abstract:
  6. Helper routines to read PortUsage and other information
  7. from registry.
  8. Author:
  9. Rao Salapaka (raos) 29-Mar-97
  10. Revision History:
  11. --*/
  12. #ifndef UNICODE
  13. #define UNICODE
  14. #endif
  15. #ifndef _UNICODE
  16. #define _UNICODE
  17. #endif
  18. #include <nt.h>
  19. #include <ntrtl.h>
  20. #include <nturtl.h>
  21. #include <windows.h>
  22. #include <tchar.h>
  23. #include <rtutils.h>
  24. #include <rasman.h>
  25. #include <reghelp.h>
  26. #define REGISTRY_NUMBEROFRINGS TEXT("NumberOfRings")
  27. #define RNETCFG_RASCLI 1
  28. #define RNETCFG_RASSRV 2
  29. #define RNETCFG_ROUTER 4
  30. DWORD g_dwRasComponent = 0;
  31. #define TRACESETTINGS (0x00010000 \
  32. | TRACE_USE_MASK \
  33. | TRACE_USE_MSEC)
  34. DWORD dwTraceId;
  35. DWORD dwGetNumberOfRings ( PDWORD pdwRings );
  36. DWORD dwGetPortUsage(DWORD *pdwPortUsage);
  37. LONG lrIsModemRasEnabled(HKEY hkey,
  38. BOOL *pfRasEnabled,
  39. BOOL *pfRouterEnabled);
  40. DeviceInfo * GetDeviceInfo (PBYTE pbGuid );
  41. /*++
  42. Routine Description:
  43. Reads the value specified by lpcszValue parameter in the
  44. hkeyRas location of registry and returns the data assoc.
  45. with it. It is assumed that the data is a REG_DWORD. Side
  46. effect is that this key is created if not already present
  47. and defaults the value to the fEnable passed in.
  48. Arguments:
  49. hkeyRas - handle of the registry key where this value is
  50. to be checked.
  51. lpcszValue - Const. string representing the value to be
  52. read.
  53. pfEnabled - pointer to a BOOL where the value read from
  54. the registry is to be returned.
  55. fEnable - the default value to set if the value is not
  56. present and this routine creates it.
  57. Return Value:
  58. Values from the registry apis.
  59. --*/
  60. LONG
  61. lrCheckValue(
  62. HKEY hkeyRas,
  63. LPCTSTR lpcszValue,
  64. BOOL *pfEnabled,
  65. BOOL fEnable)
  66. {
  67. DWORD dwdata = 0;
  68. DWORD dwtype;
  69. DWORD dwsize = sizeof(DWORD);
  70. LONG lr;
  71. *pfEnabled = FALSE;
  72. if(ERROR_FILE_NOT_FOUND == (lr = RegQueryValueEx(
  73. hkeyRas,
  74. lpcszValue,
  75. 0,
  76. &dwtype,
  77. (PBYTE) &dwdata,
  78. &dwsize)))
  79. {
  80. TracePrintfExA(dwTraceId,
  81. TRACESETTINGS,
  82. "lrCheckValue: value %ws not found",
  83. lpcszValue);
  84. if(lr = lrRasEnableDevice(hkeyRas,
  85. (LPTSTR) lpcszValue,
  86. fEnable))
  87. {
  88. TracePrintfExA(
  89. dwTraceId,
  90. TRACESETTINGS,
  91. "lrCheckValue: Couldn't set value %ws. 0x%x",
  92. lpcszValue,
  93. lr);
  94. goto done;
  95. }
  96. *pfEnabled = fEnable;
  97. goto done;
  98. }
  99. *pfEnabled = dwdata;
  100. done:
  101. return lr;
  102. }
  103. /*++
  104. Routine Description:
  105. This routine is called only for modems. It checks the
  106. registry and determines if the modem is registered
  107. for RasDialIn and Routing. These values in registry
  108. are created if they are not already present and
  109. are defaulted appropriately.
  110. Arguments:
  111. hkey - handle to the modems instance key in registry.
  112. pfRasEnabled - address where the data indicating if
  113. the modem is enabled for ras dialin is
  114. stored. If the key for this value doesn't
  115. exist this value determines the default
  116. value as an in parameter.
  117. pfRouterEnabled - address where the data indicating if
  118. the modem is enabled for routing is
  119. enabled.
  120. Return Value:
  121. Return values from the registry apis.
  122. --*/
  123. LONG
  124. lrIsModemRasEnabled(HKEY hkey,
  125. BOOL *pfRasEnabled,
  126. BOOL *pfRouterEnabled)
  127. {
  128. DWORD dwdata;
  129. DWORD dwsize = sizeof ( DWORD );
  130. DWORD dwtype;
  131. LONG lr;
  132. HKEY hkeyRas = NULL;
  133. DWORD dwDisposition;
  134. BOOL fDefaultForRasEnabled = *pfRasEnabled;
  135. *pfRasEnabled =
  136. *pfRouterEnabled = FALSE;
  137. //
  138. // Open the RAS key and if the key is not present
  139. // create the key.
  140. //
  141. if (lr = RegCreateKeyEx(
  142. hkey,
  143. TEXT("Clients\\Ras"),
  144. 0, NULL, 0,
  145. KEY_ALL_ACCESS,
  146. NULL,
  147. &hkeyRas,
  148. &dwDisposition))
  149. {
  150. TracePrintfExA(
  151. dwTraceId,
  152. TRACESETTINGS,
  153. "dwFindModemPortUsage: Failed to create/open"
  154. " RAS key under modem class. 0x%x",
  155. lr);
  156. goto done;
  157. }
  158. //
  159. // Check to see if the modem is enabled for ras dialin
  160. // Enable the modem for dialin by default to whatever
  161. // value is passed in
  162. //
  163. if(lr = lrCheckValue(
  164. hkeyRas,
  165. TEXT("EnableForRas"),
  166. pfRasEnabled,
  167. fDefaultForRasEnabled))
  168. {
  169. TracePrintfExA(
  170. dwTraceId,
  171. TRACESETTINGS,
  172. "dwFindModemPortUsage: lrCheckValue failed for "
  173. "RasEnabled. %d",
  174. lr );
  175. lr = ERROR_SUCCESS;
  176. }
  177. if (!*pfRasEnabled)
  178. {
  179. TracePrintfExA(
  180. dwTraceId,
  181. TRACESETTINGS,
  182. "dwFindModemPortUsage: Modem is not "
  183. "enabled for RAS");
  184. }
  185. //
  186. // Check to see if the modem is enabled for routing
  187. // disable the modem for routing by default
  188. //
  189. if(lr = lrCheckValue(
  190. hkeyRas,
  191. TEXT("EnableForRouting"),
  192. pfRouterEnabled,
  193. FALSE))
  194. {
  195. TracePrintfExA(
  196. dwTraceId,
  197. TRACESETTINGS,
  198. "dwFindModemPortUsage: lrCheckValue failed for "
  199. "RouterEnabled. %d",
  200. lr );
  201. lr = ERROR_SUCCESS;
  202. }
  203. if (!*pfRouterEnabled)
  204. {
  205. TracePrintfExA(
  206. dwTraceId,
  207. TRACESETTINGS,
  208. "dwFindModemPortUsage: Modem is not "
  209. "enabled for Routing");
  210. }
  211. done:
  212. if(hkeyRas)
  213. {
  214. RegCloseKey(hkeyRas);
  215. }
  216. return (DWORD) lr;
  217. }
  218. /*++
  219. Routine Description:
  220. Gets the default port usage for the device. The default
  221. is if ras server is installed, the port is enabled for
  222. ras dialin and routing. The device is always enabled for
  223. dialout.
  224. Arguments:
  225. pdwUsage - buffer to receive the port usage.
  226. Return Value:
  227. ERROR_SUCCESS.
  228. --*/
  229. DWORD
  230. dwGetPortUsage(DWORD *pdwUsage)
  231. {
  232. HKEY hkey = NULL;
  233. DWORD dwRetCode = ERROR_SUCCESS;
  234. static const TCHAR c_szRemoteAccess[] =
  235. TEXT("System\\CurrentControlSet\\Services\\RemoteAccess");
  236. TracePrintfExA(dwTraceId,
  237. TRACESETTINGS,
  238. "dwGetPorTUsage:...");
  239. if(0 == g_dwRasComponent)
  240. {
  241. //
  242. // Check to see if Ras Server is installed
  243. //
  244. g_dwRasComponent = RNETCFG_RASCLI;
  245. if (RegOpenKeyEx(
  246. HKEY_LOCAL_MACHINE,
  247. c_szRemoteAccess,
  248. 0, KEY_QUERY_VALUE,
  249. &hkey))
  250. {
  251. TracePrintfExA(
  252. dwTraceId,
  253. TRACESETTINGS,
  254. "dwAssignDefaultPortUsage: RemoteAccess"
  255. " not installed");
  256. }
  257. else
  258. {
  259. g_dwRasComponent = RNETCFG_RASSRV;
  260. }
  261. }
  262. *pdwUsage = CALL_OUT;
  263. *pdwUsage |= ((g_dwRasComponent & RNETCFG_RASSRV) ?
  264. (CALL_IN | CALL_ROUTER) : 0);
  265. if(NULL != hkey)
  266. {
  267. RegCloseKey(hkey);
  268. }
  269. return dwRetCode;
  270. }
  271. /*++
  272. Routine Description:
  273. Gets the information from registry about how many
  274. rings to wait for before picking up an incoming
  275. call.
  276. Arguments:
  277. pdwRings - buffer to receive the number of rings
  278. read from registry.
  279. Return Value:
  280. Return Values from registry apis.
  281. --*/
  282. DWORD
  283. dwGetNumberOfRings (PDWORD pdwRings)
  284. {
  285. LONG lr = ERROR_SUCCESS;
  286. HKEY hkey = NULL;
  287. DWORD dwsize = sizeof(DWORD);
  288. DWORD dwtype;
  289. TCHAR c_szRasmanParam[] =
  290. TEXT("SYSTEM\\CurrentControlSet\\Services\\Rasman\\Parameters");
  291. if(lr = RegOpenKeyEx(
  292. HKEY_LOCAL_MACHINE,
  293. c_szRasmanParam,
  294. 0, KEY_READ,
  295. &hkey))
  296. {
  297. TracePrintfExA(
  298. dwTraceId,
  299. TRACESETTINGS,
  300. "dwGetNumberOfRings: failed to open rasman key"
  301. " in registry. 0x%x",
  302. lr);
  303. goto done;
  304. }
  305. if(lr = RegQueryValueEx(
  306. hkey,
  307. TEXT("NumberOfRings"),
  308. 0, &dwtype,
  309. (PBYTE) pdwRings,
  310. &dwsize))
  311. {
  312. *pdwRings = 2;
  313. }
  314. if (*pdwRings > 20)
  315. {
  316. *pdwRings = 2;
  317. }
  318. done:
  319. if(hkey)
  320. {
  321. RegCloseKey(hkey);
  322. }
  323. TracePrintfExA(
  324. dwTraceId,
  325. TRACESETTINGS,
  326. "dwGetNumberOfRings: dwRings=%d. lr=0x%x",
  327. *pdwRings,
  328. lr);
  329. return (DWORD) lr;
  330. }