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.

414 lines
14 KiB

  1. #pragma once
  2. #include <ncxbase.h>
  3. #include <ncatlps.h>
  4. #include <nceh.h>
  5. #include <ncsetup.h>
  6. #include <notifval.h>
  7. #include <winsock2.h>
  8. #include "resource.h"
  9. extern const WCHAR c_szEmpty[];
  10. // AppleTalk Globally visible strings
  11. extern const WCHAR c_chAt;
  12. // Define the possible media types (Used also as array indices)
  13. #define MEDIATYPE_ETHERNET 1
  14. #define MEDIATYPE_TOKENRING 2
  15. #define MEDIATYPE_FDDI 3
  16. #define MEDIATYPE_WAN 4
  17. #define MEDIATYPE_LOCALTALK 5
  18. #define MAX_ZONES 255
  19. #define ZONELISTSIZE 2048
  20. #define MAX_ZONE_NAME_LEN 32
  21. #define MAX_RANGE_ALLOWED 65279
  22. #define MIN_RANGE_ALLOWED 1
  23. #define ZONEBUFFER_LEN 32*255
  24. // Seed Info Validation returns
  25. #define NO_SEED_INFO 0x0
  26. #define VALID_SEED_INFO 0x1
  27. #define INVALID_SEED_INFO 0x2
  28. typedef enum
  29. {
  30. AT_PNP_SWITCH_ROUTING = 0,
  31. AT_PNP_SWITCH_DEFAULT_ADAPTER,
  32. AT_PNP_RECONFIGURE_PARMS
  33. } ATALK_PNP_MSGTYPE;
  34. typedef struct _ATALK_PNP_EVENT
  35. {
  36. ATALK_PNP_MSGTYPE PnpMessage;
  37. } ATALK_PNP_EVENT, *PATALK_PNP_EVENT;
  38. // Class Forwards
  39. class CATlkObj;
  40. class CATLKEnv;
  41. class CAdapterInfo;
  42. // Define a structure for reading/writing all information necessary about an adapter
  43. typedef struct
  44. {
  45. DWORD m_dwAarpRetries;
  46. DWORD m_dwDdpCheckSums;
  47. DWORD m_dwNetworkRangeLowerEnd;
  48. DWORD m_dwNetworkRangeUpperEnd;
  49. DWORD m_dwRouterPramNode;
  50. DWORD m_dwSeedingNetwork;
  51. DWORD m_dwUserPramNode1;
  52. DWORD m_dwUserPramNode2;
  53. DWORD m_dwMediaType;
  54. WCHAR* m_szDefaultZone;
  55. WCHAR* m_szPortName;
  56. } ATLK_ADAPTER;
  57. typedef list<CAdapterInfo *> ATLK_ADAPTER_INFO_LIST;
  58. // Class: CAdapters
  59. //
  60. // Purpose: Contain all information necessary about a single adapter instance
  61. //
  62. class CAdapterInfo
  63. {
  64. friend class CATLKEnv;
  65. public:
  66. CAdapterInfo();
  67. ~CAdapterInfo();
  68. // Make a duplicate copy of 'this'
  69. HRESULT HrCopy(CAdapterInfo ** ppAI);
  70. void SetDeletePending(BOOL f) {m_fDeletePending = f;}
  71. BOOL FDeletePending() {return m_fDeletePending;}
  72. void SetDisabled(BOOL f) {m_fDisabled = f;}
  73. BOOL FDisabled() {return m_fDisabled;}
  74. void SetCharacteristics(DWORD dw) {m_dwCharacteristics = dw;}
  75. DWORD GetCharacteristics() {return m_dwCharacteristics;}
  76. BOOL FHidden() {return !!(NCF_HIDDEN & m_dwCharacteristics);}
  77. void SetMediaType(DWORD dw) {m_AdapterInfo.m_dwMediaType = dw;}
  78. DWORD DwMediaType() {return m_AdapterInfo.m_dwMediaType;}
  79. void SetDisplayName(PCWSTR psz) {m_strDisplayName = psz;}
  80. PCWSTR SzDisplayName() {return m_strDisplayName.c_str();}
  81. void SetBindName(PCWSTR psz) {m_strBindName = psz;}
  82. PCWSTR SzBindName() {return m_strBindName.c_str();}
  83. ATLK_ADAPTER* PAdapterInfo() {return &m_AdapterInfo;}
  84. void SetPortName(PCWSTR psz);
  85. PCWSTR SzPortName() {return m_AdapterInfo.m_szPortName ?
  86. m_AdapterInfo.m_szPortName :
  87. c_szEmpty;}
  88. void SetDefaultZone(PCWSTR psz);
  89. PCWSTR SzDefaultZone() {return m_AdapterInfo.m_szDefaultZone ?
  90. m_AdapterInfo.m_szDefaultZone :
  91. c_szEmpty;}
  92. list<tstring*> &LstpstrZoneList() {return m_lstpstrZoneList;}
  93. list<tstring*> &LstpstrDesiredZoneList() {return m_lstpstrDesiredZoneList;}
  94. void SetSeedingNetwork(BOOL fSeeding)
  95. {m_AdapterInfo.m_dwSeedingNetwork = (fSeeding ? 1 : 0);}
  96. DWORD FSeedingNetwork() {return (1 == m_AdapterInfo.m_dwSeedingNetwork);}
  97. void SetRouterOnNetwork(BOOL f) {m_fRouterOnNetwork = f;}
  98. BOOL FRouterOnNetwork() {return m_fRouterOnNetwork;}
  99. void SetExistingNetRange(DWORD dwLower, DWORD dwUpper)
  100. {m_dwNetworkLower = dwLower;
  101. m_dwNetworkUpper = dwUpper;}
  102. DWORD DwQueryNetworkUpper() {return m_dwNetworkUpper;}
  103. DWORD DwQueryNetworkLower() {return m_dwNetworkLower;}
  104. void SetAdapterNetRange(DWORD dwLower, DWORD dwUpper)
  105. {m_AdapterInfo.m_dwNetworkRangeLowerEnd = dwLower;
  106. m_AdapterInfo.m_dwNetworkRangeUpperEnd = dwUpper;}
  107. DWORD DwQueryNetRangeUpper() {return m_AdapterInfo.m_dwNetworkRangeUpperEnd;}
  108. DWORD DwQueryNetRangeLower() {return m_AdapterInfo.m_dwNetworkRangeLowerEnd;}
  109. void SetNetDefaultZone(PCWSTR psz) {m_strNetDefaultZone = psz;}
  110. PCWSTR SzNetDefaultZone() {return m_strNetDefaultZone.c_str();}
  111. HRESULT HrConvertZoneListAndAddToPortInfo(CHAR * szZoneList, ULONG NumZones);
  112. HRESULT HrGetAndSetNetworkInformation(SOCKET, PCWSTR);
  113. VOID SetInstanceGuid(GUID guid) {memcpy(&m_guidInstance, &guid, sizeof(GUID));}
  114. GUID * PInstanceGuid() {return &m_guidInstance;}
  115. BOOL IsDirty() {return m_fDirty;}
  116. VOID SetDirty(BOOL f) {m_fDirty = f;}
  117. BOOL IsRasAdapter() {return m_fRasAdapter;}
  118. VOID SetRasAdapter(BOOL f) {m_fRasAdapter = f;}
  119. VOID ZeroSpecialParams() {m_AdapterInfo.m_dwUserPramNode1 = 0;
  120. m_AdapterInfo.m_dwUserPramNode2 = 0;
  121. m_AdapterInfo.m_dwRouterPramNode = 0; }
  122. // m_guidInstance is the instance guid of the adapter
  123. GUID m_guidInstance;
  124. // m_lstpstrZoneList is the REG_MULTI_SZ value found under
  125. // AppleTalk\Parameters\Adapters\<adapter>\ZoneList
  126. list<tstring*> m_lstpstrZoneList;
  127. // Desired zone will be choosen from this list
  128. list<tstring*> m_lstpstrDesiredZoneList;
  129. // m_AdapterInfo is the collection of values found under
  130. // AppleTalk\Parameters\Adapters\<adapter> with the exception of the
  131. // ZoneList : REG_MULTI_SZ value which is stored in m_lstpstrZoneList above.
  132. ATLK_ADAPTER m_AdapterInfo;
  133. private:
  134. // m_fDisabled is a boolean that, when TRUE, indicates this adapter
  135. // is currently disabled
  136. BOOL m_fDisabled;
  137. // If true, this adapter's info has changed
  138. BOOL m_fDirty;
  139. // m_fDeletePending is a boolean that, when TRUE, indicates this adapter
  140. // is being removed from the adapter list (eventually)
  141. BOOL m_fDeletePending;
  142. // If true, the zone list contents are considered valid
  143. BOOL m_fZoneListValid;
  144. // If true, this adapter exposes ndiswanatlk
  145. BOOL m_fRasAdapter;
  146. // m_dwCharacteristics contains the adapter's characteristic settings
  147. DWORD m_dwCharacteristics;
  148. // m_strBindName is the BindName for the adapter
  149. tstring m_strBindName;
  150. // m_strDisplayName is the display name of the adapter
  151. tstring m_strDisplayName;
  152. // Default zone returned by stack
  153. tstring m_strNetDefaultZone;
  154. // Router network state
  155. BOOL m_fRouterOnNetwork;
  156. DWORD m_dwNetworkUpper; // existing network # returned by stack
  157. DWORD m_dwNetworkLower; // existing network # returned by stack
  158. };
  159. // Define a structure for reading/writing AppleTalk\Parameters values
  160. typedef struct
  161. {
  162. DWORD dwEnableRouter;
  163. WCHAR* szDefaultPort;
  164. WCHAR* szDesiredZone;
  165. } ATLK_PARAMS;
  166. // Class: CATLKEnv
  167. //
  168. // Purpose: Contains the "Known" enviroment state regarding AppleTalk Params/Settings
  169. //
  170. class CATLKEnv
  171. {
  172. private:
  173. CATLKEnv(CATlkObj *pmsc);
  174. public:
  175. // Automatic two-phase constructor
  176. static HRESULT HrCreate(CATLKEnv **, CATlkObj *);
  177. ~CATLKEnv();
  178. HRESULT HrCopy(CATLKEnv **ppEnv);
  179. HRESULT HrReadAppleTalkInfo();
  180. HRESULT HrGetAppleTalkInfoFromNetwork(CAdapterInfo * pAI);
  181. HRESULT HrGetAdapterInfo();
  182. HRESULT HrGetOneAdaptersInfo(INetCfgComponent*, CAdapterInfo **);
  183. HRESULT HrAddAdapter(INetCfgComponent * pnccFound);
  184. void SetDefaultPort(PCWSTR psz);
  185. PCWSTR SzDefaultPort() {return (NULL != m_Params.szDefaultPort ?
  186. m_Params.szDefaultPort :
  187. c_szEmpty);}
  188. void SetDesiredZone(PCWSTR psz);
  189. PCWSTR SzDesiredZone() {return (NULL != m_Params.szDesiredZone ?
  190. m_Params.szDesiredZone :
  191. c_szEmpty);}
  192. DWORD DwDefaultAdaptersMediaType() {return m_dwDefaultAdaptersMediaType;}
  193. void SetDefaultMediaType(DWORD dw) {m_dwDefaultAdaptersMediaType = dw;}
  194. void EnableRouting(BOOL f) {m_Params.dwEnableRouter = (f ? 1 : 0);}
  195. BOOL FRoutingEnabled() {return (1 == m_Params.dwEnableRouter);}
  196. ATLK_ADAPTER_INFO_LIST &AdapterInfoList() {return m_lstpAdapters;}
  197. BOOL FIsAppleTalkRunning() {return m_fATrunning;}
  198. void SetATLKRunning(BOOL fRunning) {m_fATrunning = fRunning;}
  199. HRESULT HrUpdateRegistry();
  200. HRESULT HrWriteOneAdapter(CAdapterInfo *pAI);
  201. DWORD DwMediaPriority(DWORD dwMediaType);
  202. void InitDefaultPort();
  203. BOOL FRouterChanged() {return m_fRouterChanged;}
  204. VOID SetRouterChanged(BOOL f) {m_fRouterChanged = f;}
  205. BOOL FDefAdapterChanged() {return m_fDefAdapterChanged;}
  206. VOID SetDefAdapterChanged(BOOL f) {m_fDefAdapterChanged = f;}
  207. CAdapterInfo * PAIFindDefaultPort();
  208. ATLK_ADAPTER_INFO_LIST m_lstpAdapters;
  209. private:
  210. CATlkObj * m_pmsc;
  211. BOOL m_fRouterChanged;
  212. BOOL m_fDefAdapterChanged;
  213. BOOL m_fATrunning;
  214. DWORD m_dwDefaultAdaptersMediaType;
  215. ATLK_PARAMS m_Params;
  216. };
  217. // Class: CATLKGeneralDlg
  218. //
  219. // Purpose: Manage the "General" property page
  220. //
  221. class CATLKGeneralDlg: public CPropSheetPage
  222. {
  223. public:
  224. BEGIN_MSG_MAP(CATLKGeneralDlg)
  225. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  226. MESSAGE_HANDLER(WM_CONTEXTMENU, OnContextMenu)
  227. MESSAGE_HANDLER(WM_HELP, OnHelp)
  228. NOTIFY_CODE_HANDLER(PSN_APPLY, OnOk)
  229. COMMAND_ID_HANDLER(CHK_GENERAL_DEFAULT, HandleChkBox)
  230. END_MSG_MAP()
  231. CATLKGeneralDlg(CATlkObj *pmsc, CATLKEnv * pATLKEnv);
  232. ~CATLKGeneralDlg();
  233. LRESULT HandleChkBox(WORD wNotifyCode, WORD wID,
  234. HWND hWndCtl, BOOL& bHandled);
  235. LRESULT OnInitDialog(UINT uMsg, WPARAM wParam,
  236. LPARAM lParam, BOOL& bHandled);
  237. LRESULT OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& Handled);
  238. LRESULT OnHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  239. LRESULT OnOk(INT idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  240. BOOL FAddZoneListToControl(list<tstring*> * plstpstr);
  241. VOID RefreshZoneCombo();
  242. private:
  243. CATlkObj * m_pmsc;
  244. CATLKEnv * m_pATLKEnv;
  245. };
  246. /////////////////////////////////////////////////////////////////////////////
  247. // CATlkObj
  248. class ATL_NO_VTABLE CATlkObj :
  249. public CComObjectRoot,
  250. public CComCoClass<CATlkObj, &CLSID_CATlkObj>,
  251. public INetCfgComponentControl,
  252. public INetCfgComponentSetup,
  253. public INetCfgComponentPropertyUi,
  254. public INetCfgComponentNotifyBinding
  255. {
  256. public:
  257. CATlkObj();
  258. ~CATlkObj();
  259. BEGIN_COM_MAP(CATlkObj)
  260. COM_INTERFACE_ENTRY(INetCfgComponentControl)
  261. COM_INTERFACE_ENTRY(INetCfgComponentSetup)
  262. COM_INTERFACE_ENTRY(INetCfgComponentPropertyUi)
  263. COM_INTERFACE_ENTRY(INetCfgComponentNotifyBinding)
  264. END_COM_MAP()
  265. // DECLARE_NOT_AGGREGATABLE(CATlkObj)
  266. // Remove the comment from the line above if you don't want your object to
  267. // support aggregation. The default is to support it
  268. DECLARE_REGISTRY_RESOURCEID(IDR_REG_ATLKCFG)
  269. // Install Action (Unknown, Install, Remove)
  270. enum INSTALLACTION {eActUnknown, eActInstall, eActRemove};
  271. // INetCfgComponentControl
  272. STDMETHOD (Initialize) (
  273. IN INetCfgComponent* pIComp,
  274. IN INetCfg* pINetCfg,
  275. IN BOOL fInstalling);
  276. STDMETHOD (ApplyRegistryChanges) ();
  277. STDMETHOD (ApplyPnpChanges) (
  278. IN INetCfgPnpReconfigCallback* pICallback) { return S_OK; }
  279. STDMETHOD (CancelChanges) ();
  280. STDMETHOD (Validate) ();
  281. // INetCfgComponentSetup
  282. STDMETHOD (Install) (DWORD dwSetupFlags);
  283. STDMETHOD (Upgrade) (DWORD dwSetupFlags,
  284. DWORD dwUpgradeFromBuildNo) {return S_OK;}
  285. STDMETHOD (ReadAnswerFile) (PCWSTR pszAnswerFile,
  286. PCWSTR pszAnswerSection);
  287. STDMETHOD (Removing) ();
  288. // INetCfgProperties
  289. STDMETHOD (QueryPropertyUi) (
  290. IN IUnknown* pUnk) { return S_OK; }
  291. STDMETHOD (SetContext) (
  292. IN IUnknown* pUnk);
  293. STDMETHOD (MergePropPages) (
  294. IN OUT DWORD* pdwDefPages,
  295. OUT LPBYTE* pahpspPrivate,
  296. OUT UINT* pcPrivate,
  297. IN HWND hwndParent,
  298. OUT PCWSTR* pszStartPage);
  299. STDMETHOD (ValidateProperties) (
  300. HWND hwndSheet);
  301. STDMETHOD (CancelProperties) ();
  302. STDMETHOD (ApplyProperties) ();
  303. // INetCfgNotifyBinding
  304. STDMETHOD (QueryBindingPath) (DWORD dwChangeFlag, INetCfgBindingPath* pncbp);
  305. STDMETHOD (NotifyBindingPath) (DWORD dwChangeFlag, INetCfgBindingPath* pncbp);
  306. INetCfg * PNetCfg() {return m_pNetCfg;}
  307. INetCfgComponent * PNCComponent() {return m_pNCC;}
  308. HRESULT HrCommitInstall();
  309. HRESULT HrCommitRemove();
  310. CATLKEnv * PATLKEnv() {return m_pATLKEnv;}
  311. VOID MarkAdapterListChanged() {m_fAdapterListChanged = TRUE;};
  312. private:
  313. VOID CleanupPropPages();
  314. HRESULT HrProcessAnswerFile(PCWSTR pszAnswerFile,
  315. PCWSTR pszAnswerSection);
  316. HRESULT HrReadAdapterAnswerFileSection(CSetupInfFile * pcsif,
  317. PCWSTR pszSection);
  318. HRESULT HrAtlkReconfig();
  319. private:
  320. INetCfgComponent* m_pNCC;
  321. INetCfg* m_pNetCfg;
  322. INSTALLACTION m_eInstallAction;
  323. CPropSheetPage * m_pspObj;
  324. CATLKEnv * m_pATLKEnv;
  325. CATLKEnv * m_pATLKEnv_PP; // Used by prop pages only
  326. IUnknown * m_pUnkPropContext;
  327. INT m_nIdxAdapterSelected; // Used by Prop Pages only
  328. BOOL m_fAdapterListChanged;
  329. BOOL m_fPropertyChange;
  330. BOOL m_fFirstTimeInstall;
  331. };