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.

464 lines
10 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <ntddser.h>
  5. #include <windows.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <memory.h>
  9. #include <malloc.h>
  10. #include <rasman.h>
  11. #include <rasddm.h>
  12. #include <ipxrtdef.h>
  13. // [pmay] this will no longer be neccessary when the ipx router
  14. // is converted to use MprInfo api's.
  15. typedef RTR_INFO_BLOCK_HEADER IPX_INFO_BLOCK_HEADER, *PIPX_INFO_BLOCK_HEADER;
  16. VOID
  17. MibTest(VOID);
  18. VOID
  19. DbgAdapterEmulation(ULONG AdapterStatus,
  20. ULONG AdapterIndex,
  21. ULONG InterfaceIndex,
  22. ULONG NdisMedium);
  23. VOID
  24. DbgConnectionRequest(ULONG ifindex);
  25. DDM_ROUTER_INTERFACE ddmif;
  26. struct _DBG_IF {
  27. IPX_INFO_BLOCK_HEADER header;
  28. IPX_TOC_ENTRY toc[5];
  29. IPX_IF_INFO ipxifinfo;
  30. RIP_IF_INFO ripifinfo;
  31. SAP_IF_INFO sapifinfo;
  32. IPXWAN_IF_INFO ipxwanifinfo;
  33. IPX_ADAPTER_INFO adapterinfo;
  34. WCHAR adaptername[4];
  35. IPX_STATIC_ROUTE_INFO routeinfo[10];
  36. } dbgif;
  37. struct _DBG_IF dbgif1;
  38. #define ipxtoc dbgif.header.TocEntry[0]
  39. #define riptoc dbgif.toc[0]
  40. #define saptoc dbgif.toc[1]
  41. #define ipxwantoc dbgif.toc[2]
  42. #define adaptertoc dbgif.toc[3]
  43. #define routetoc dbgif.toc[4]
  44. WCHAR MainAdapterName[5] = { L'A', L'B', L'C', L'D', L'\0' };
  45. WCHAR MainInterfaceName[5] = { L'X', L'Y', L'Z', L'0', L'\0' };
  46. ULONG MainInterfaceType = ROUTER_IF_TYPE_DEDICATED;
  47. HANDLE MainInterfaceHandle;
  48. VOID
  49. MainAddInterface(VOID)
  50. {
  51. PIPX_IF_INFO ipxinfop;
  52. PRIP_IF_INFO ripinfop;
  53. PSAP_IF_INFO sapinfop;
  54. PIPXWAN_IF_INFO ipxwaninfop;
  55. PIPX_ADAPTER_INFO adapterinfop;
  56. PIPX_STATIC_ROUTE_INFO routeinfop;
  57. BOOL Enabled;
  58. int i,j;
  59. BOOL str; // static routes info
  60. printf("Enter interface number:");
  61. scanf("%d", &i);
  62. printf("Enter interface type (0,1,2 - wan, 3 - lan, 4 - internal):");
  63. scanf("%d", &MainInterfaceType);
  64. if(MainInterfaceType == 2) {
  65. str = TRUE;
  66. }
  67. else
  68. {
  69. str = FALSE;
  70. }
  71. dbgif.header.Version = IPX_ROUTER_VERSION_1;
  72. dbgif.header.Size = sizeof(dbgif);
  73. if (str)
  74. dbgif.header.TocEntriesCount = 6;
  75. else
  76. dbgif.header.TocEntriesCount = 5;
  77. ipxtoc.InfoType = IPX_INTERFACE_INFO_TYPE;
  78. ipxtoc.InfoSize = sizeof(IPX_IF_INFO);
  79. ipxtoc.Count = 1;
  80. ipxtoc.Offset = (ULONG)((PUCHAR)&dbgif.ipxifinfo - (PUCHAR)&dbgif);
  81. riptoc.InfoType = RIP_INTERFACE_INFO_TYPE;
  82. riptoc.InfoSize = sizeof(RIP_IF_INFO);
  83. riptoc.Count = 1;
  84. riptoc.Offset = ipxtoc.Offset + sizeof(IPX_IF_INFO);
  85. saptoc.InfoType = SAP_INTERFACE_INFO_TYPE;
  86. saptoc.InfoSize = sizeof(SAP_IF_INFO);
  87. saptoc.Count = 1;
  88. saptoc.Offset = riptoc.Offset + sizeof(RIP_IF_INFO);
  89. ipxwantoc.InfoType = IPXWAN_INTERFACE_INFO_TYPE;
  90. ipxwantoc.InfoSize = sizeof(IPXWAN_IF_INFO);
  91. ipxwantoc.Count = 1;
  92. ipxwantoc.Offset = saptoc.Offset + sizeof(SAP_IF_INFO);
  93. adaptertoc.InfoType = IPX_ADAPTER_INFO_TYPE;
  94. adaptertoc.InfoSize = sizeof(IPX_ADAPTER_INFO) + wcslen(MainAdapterName) * sizeof(WCHAR);
  95. adaptertoc.Count = 1;
  96. adaptertoc.Offset = ipxwantoc.Offset + ipxwantoc.InfoSize;
  97. if (str) {
  98. routetoc.InfoType = IPX_STATIC_ROUTE_INFO_TYPE;
  99. routetoc.InfoSize = sizeof(IPX_STATIC_ROUTE_INFO);
  100. routetoc.Count = 3;
  101. routetoc.Offset = adaptertoc.Offset + adaptertoc.InfoSize;
  102. }
  103. ipxinfop = (PIPX_IF_INFO)((PUCHAR)&dbgif + ipxtoc.Offset);
  104. ipxinfop->AdminState = IF_ADMIN_STATE_ENABLED;
  105. ipxinfop->NetbiosAccept = IF_ADMIN_STATE_ENABLED;
  106. ipxinfop->NetbiosDeliver = IF_ADMIN_STATE_DISABLED;
  107. MainAdapterName[3] = L'0' + i;
  108. adapterinfop = (PIPX_ADAPTER_INFO)((PUCHAR)&dbgif + adaptertoc.Offset);
  109. adapterinfop->PacketType = 1;
  110. adapterinfop->AdapterNameLen = (wcslen(MainAdapterName) + 1) * sizeof(WCHAR);
  111. memcpy(adapterinfop->AdapterName, MainAdapterName, adapterinfop->AdapterNameLen);
  112. if (str) {
  113. routeinfop = dbgif.routeinfo;
  114. for(j=0; j <3; j++, routeinfop++)
  115. {
  116. memset(routeinfop->Network, 0, 4);
  117. routeinfop->Network[3] = i * 0x10 + j;
  118. routeinfop->HopCount = 1;
  119. routeinfop->TickCount = 1;
  120. memset(routeinfop->NextHopMacAddress, i * 0x10 + j, 6);
  121. }
  122. }
  123. MainInterfaceName[3] = L'0' + i;
  124. MainInterfaceHandle = (*ddmif.AddInterface)(MainInterfaceName,
  125. &dbgif,
  126. NULL,
  127. MainInterfaceType,
  128. TRUE,
  129. &Enabled);
  130. printf("main: AddInterface returned 0x%x\n", MainInterfaceHandle);
  131. }
  132. VOID
  133. MainDeleteInterface(VOID)
  134. {
  135. ULONG ii;
  136. printf("Enter interface index:");
  137. scanf("%d", &ii);
  138. (*ddmif.DeleteInterface)((HANDLE)ii);
  139. }
  140. VOID
  141. MainGetInterface(VOID)
  142. {
  143. ULONG ii;
  144. ULONG IfInfoSize;
  145. ULONG FilterInfoSize;
  146. IPX_INFO_BLOCK_HEADER FilterInfo;
  147. DWORD rc;
  148. printf("Enter interface index:");
  149. scanf("%d", &ii);
  150. rc = (*ddmif.GetInterfaceInfo)((HANDLE)ii,
  151. NULL,
  152. &IfInfoSize,
  153. NULL,
  154. &FilterInfoSize);
  155. if(rc != ERROR_INSUFFICIENT_BUFFER) {
  156. printf("MainGetInterface: bad error code rc= %d in first GetInterfaceInfo\n", rc);
  157. return;
  158. }
  159. printf("MainGetInterface: If info len = %d, Filter Info len = %d\n",
  160. IfInfoSize, FilterInfoSize);
  161. rc = (*ddmif.GetInterfaceInfo)((HANDLE)ii,
  162. &dbgif1,
  163. &IfInfoSize,
  164. NULL,
  165. &FilterInfoSize);
  166. if(rc != NO_ERROR) {
  167. printf("MainGetInterface: bad error code rc= %d in second GetInterfaceInfo\n", rc);
  168. }
  169. }
  170. VOID
  171. MainSetInterface(VOID)
  172. {
  173. ULONG ii;
  174. PIPX_IF_INFO ipxinfop;
  175. PRIP_IF_INFO ripinfop;
  176. PSAP_IF_INFO sapinfop;
  177. PIPXWAN_IF_INFO ipxwaninfop;
  178. PIPX_ADAPTER_INFO adapterinfop;
  179. PIPX_STATIC_ROUTE_INFO routeinfop;
  180. BOOL Enabled;
  181. int j, ri;
  182. DWORD rc;
  183. printf("Enter if index:");
  184. scanf("%d", &ii);
  185. printf("Enter 3-no modif, 4- add a new route, 2- delete a route:");
  186. scanf("%d", &ri);
  187. dbgif.header.Version = IPX_ROUTER_VERSION_1;
  188. dbgif.header.Size = sizeof(dbgif);
  189. dbgif.header.TocEntriesCount = 6;
  190. ipxtoc.InfoType = IPX_INTERFACE_INFO_TYPE;
  191. ipxtoc.InfoSize = sizeof(IPX_IF_INFO);
  192. ipxtoc.Count = 1;
  193. ipxtoc.Offset = (ULONG)((PUCHAR)&dbgif.ipxifinfo - (PUCHAR)&dbgif);
  194. riptoc.InfoType = RIP_INTERFACE_INFO_TYPE;
  195. riptoc.InfoSize = sizeof(RIP_IF_INFO);
  196. riptoc.Count = 1;
  197. riptoc.Offset = ipxtoc.Offset + sizeof(IPX_IF_INFO);
  198. saptoc.InfoType = SAP_INTERFACE_INFO_TYPE;
  199. saptoc.InfoSize = sizeof(SAP_IF_INFO);
  200. saptoc.Count = 1;
  201. saptoc.Offset = riptoc.Offset + sizeof(RIP_IF_INFO);
  202. ipxwantoc.InfoType = IPXWAN_INTERFACE_INFO_TYPE;
  203. ipxwantoc.InfoSize = sizeof(IPXWAN_IF_INFO);
  204. ipxwantoc.Count = 1;
  205. ipxwantoc.Offset = saptoc.Offset + sizeof(SAP_IF_INFO);
  206. adaptertoc.InfoType = IPX_ADAPTER_INFO_TYPE;
  207. adaptertoc.InfoSize = sizeof(IPX_ADAPTER_INFO) + wcslen(MainAdapterName) * sizeof(WCHAR);
  208. adaptertoc.Count = 1;
  209. adaptertoc.Offset = ipxwantoc.Offset + ipxwantoc.InfoSize;
  210. routetoc.InfoType = IPX_STATIC_ROUTE_INFO_TYPE;
  211. routetoc.InfoSize = sizeof(IPX_STATIC_ROUTE_INFO);
  212. routetoc.Count = ri;
  213. routetoc.Offset = adaptertoc.Offset + adaptertoc.InfoSize;
  214. ipxinfop = (PIPX_IF_INFO)((PUCHAR)&dbgif + ipxtoc.Offset);
  215. ipxinfop->AdminState = IF_ADMIN_STATE_ENABLED;
  216. ipxinfop->NetbiosAccept = IF_ADMIN_STATE_ENABLED;
  217. ipxinfop->NetbiosDeliver = IF_ADMIN_STATE_DISABLED;
  218. MainAdapterName[3] = L'0' + (UCHAR)ii;
  219. adapterinfop = (PIPX_ADAPTER_INFO)((PUCHAR)&dbgif + adaptertoc.Offset);
  220. adapterinfop->PacketType = 1;
  221. adapterinfop->AdapterNameLen = (wcslen(MainAdapterName) + 1) * sizeof(WCHAR);
  222. memcpy(adapterinfop->AdapterName, MainAdapterName, adapterinfop->AdapterNameLen);
  223. routeinfop = dbgif.routeinfo;
  224. for(j=0; j <ri; j++, routeinfop++)
  225. {
  226. memset(routeinfop->Network, 0, 4);
  227. routeinfop->Network[3] = (UCHAR)ii * 0x10 + j;
  228. routeinfop->HopCount = 1;
  229. routeinfop->TickCount = 1;
  230. memset(routeinfop->NextHopMacAddress, ii * 0x10 + j, 6);
  231. }
  232. rc = (*ddmif.SetInterfaceInfo)((HANDLE)ii,
  233. &dbgif,
  234. NULL,
  235. &Enabled);
  236. printf("main: SetInterface returned 0x%x\n", rc);
  237. }
  238. VOID
  239. MainEmulateAdapter(VOID)
  240. {
  241. ULONG ai, ii, as, nm;
  242. printf("Enter adapter index:");
  243. scanf("%d", &ai);
  244. printf("Enter interface index:");
  245. scanf("%d", &ii);
  246. printf("Enter adapter status (1 - create, 2-delete, 3-connect, 4-disc):");
  247. scanf("%d", &as);
  248. printf("Enter adapter medium (0- LAN, 1 - WAN):");
  249. scanf("%d", &nm);
  250. DbgAdapterEmulation(as, ai, ii, nm);
  251. }
  252. VOID
  253. MainConnReq(VOID)
  254. {
  255. ULONG ii;
  256. printf("Enter interface index to request connection:");
  257. scanf("%d", &ii);
  258. DbgConnectionRequest(ii);
  259. }
  260. VOID
  261. RouterStarted(DWORD protid)
  262. {
  263. printf("main: RouterStarted: protid 0x%x\n", protid);
  264. }
  265. VOID
  266. RouterStopped(DWORD protid,
  267. DWORD err)
  268. {
  269. printf("main: RouterStopped: protid 0x%x err 0x%x\n", protid, err);
  270. }
  271. DWORD
  272. ConnectInterface(LPWSTR InterfaceNamep,
  273. ULONG pid)
  274. {
  275. printf("Main: ConnectInterface: request to connect if %S\n", InterfaceNamep);
  276. return NO_ERROR;
  277. }
  278. VOID _cdecl
  279. main(
  280. IN WORD argc,
  281. IN LPSTR argv[]
  282. )
  283. {
  284. DWORD rc;
  285. int i;
  286. ddmif.RouterStarted = RouterStarted;
  287. ddmif.RouterStopped = RouterStopped;
  288. ddmif.ConnectInterface = ConnectInterface;
  289. rc = InitializeRouter(&ddmif);
  290. printf("main: InitializeRouter returned %x\n", rc);
  291. for(;;) {
  292. printf("Router Manager Test Menu:\n");
  293. printf("1. Start router\n");
  294. printf("2. Stop router\n");
  295. printf("3. Add interface\n");
  296. printf("4. Delete interface\n");
  297. printf("5. Get interface\n");
  298. printf("6. Set interface\n");
  299. printf("7. Emulate adapters - create, connect, disconnect, delete\n");
  300. printf("8. Clear dbgif1\n");
  301. printf("9. MIB Test\n");
  302. printf("10. Connection request test\n");
  303. printf("99. Exit\n");
  304. printf("Enter your option:");
  305. scanf("%d", &i);
  306. switch(i) {
  307. case 1:
  308. rc = (*ddmif.StartRouter)();
  309. printf("main: StartRouter rc=0x%x\n", rc);
  310. break;
  311. case 2:
  312. (*ddmif.StopRouter)();
  313. printf("main: StopRouter \n");
  314. break;
  315. case 3:
  316. MainAddInterface();
  317. break;
  318. case 4:
  319. MainDeleteInterface();
  320. break;
  321. case 5:
  322. MainGetInterface();
  323. break;
  324. case 6:
  325. MainSetInterface();
  326. break;
  327. case 7:
  328. MainEmulateAdapter();
  329. break;
  330. case 8:
  331. memset(&dbgif1, 0, sizeof(dbgif1));
  332. break;
  333. case 9:
  334. MibTest();
  335. break;
  336. case 10:
  337. MainConnReq();
  338. break;
  339. case 99:
  340. printf("exit\n");
  341. goto Exit;
  342. default:
  343. break;
  344. }
  345. }
  346. Exit:
  347. ExitProcess(0);
  348. }