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.

1390 lines
27 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. ipfwadm.c -- actually calls down the the ip/1394 arp module.
  5. Revision History:
  6. Who When What
  7. -------- -------- ---------------------------------------------
  8. josephj 04-12-1999 Created
  9. --*/
  10. #include "common.h"
  11. #define NUM_ARPENTRIES_TO_GET 10
  12. #define PROGRAM "ipfwadm"
  13. typedef struct
  14. {
  15. ARP1394_IOCTL_COMMAND Cmd;
  16. // MUST IMMEDIATELY follow Cmd -- space for Cmd.GetArpCache.Entries
  17. //
  18. ARP1394_ARP_ENTRY Reserved[NUM_ARPENTRIES_TO_GET];
  19. } OPTIONS;
  20. HANDLE
  21. OpenDevice(
  22. CHAR *pDeviceName
  23. );
  24. VOID
  25. CloseDevice(
  26. HANDLE DeviceHandle
  27. );
  28. BOOL
  29. ParseCmdLine(
  30. int argc,
  31. char * argv[]
  32. );
  33. BOOL
  34. ParseIpAddress(
  35. PCHAR buf,
  36. PULONG pIpAddress
  37. );
  38. BOOL
  39. ParseHwAddress(
  40. PCHAR buf,
  41. PARP1394_IOCTL_HW_ADDRESS pHwAddr
  42. );
  43. BOOL
  44. ValidateCommand(PARP1394_IOCTL_COMMAND pCmd);
  45. BOOL
  46. ParsePacket(
  47. PCHAR buf,
  48. UCHAR *data,
  49. UINT cbData,
  50. UINT *pcbPacketSize
  51. );
  52. BOOL
  53. ParseAdapter(
  54. PCHAR buf,
  55. UCHAR *data,
  56. UINT cbData,
  57. UINT *pcbAdapterSize
  58. );
  59. OPTIONS g;
  60. void
  61. Usage(void);
  62. VOID __cdecl
  63. main(
  64. INT argc,
  65. CHAR *argv[]
  66. )
  67. {
  68. //
  69. // Parse args, determine if this is concerns the arp client or server.
  70. //
  71. if (!ParseCmdLine(argc, argv))
  72. {
  73. return;
  74. }
  75. DoCmd(&g.Cmd);
  76. }
  77. void
  78. Usage(void)
  79. {
  80. //
  81. // Also hidden compat options: -s, -d, -g
  82. //
  83. printf( "\nWindows 2000 IP/1394 Utility\n\n");
  84. printf(
  85. PROGRAM " -a\n"
  86. PROGRAM " -add inet_addr hw_addr [-n if_addr]\n"
  87. PROGRAM " -del inet_addr [-n if_addr]\n"
  88. PROGRAM " -stats [arp|call|pkts|tsks] [-n if_addr]\n"
  89. PROGRAM " -resetstats [-n if_addr]\n"
  90. PROGRAM " -purgecache [-n if_addr]\n"
  91. PROGRAM " -reinit [-n if_addr]\n"
  92. PROGRAM " -send pkt [-n if_addr]\n"
  93. PROGRAM " -recv pkt [-n if_addr]\n"
  94. PROGRAM " -bstart adapter\n"
  95. PROGRAM " -bstop adapter\n"
  96. PROGRAM " -nicinfo [a|n node|c channel|reset] [-n if_addr]\n"
  97. PROGRAM " -- [-n if_addr]\n"
  98. PROGRAM " -euidmap\n"
  99. "\n"
  100. );
  101. printf(
  102. " -a Displays current ARP entries. If more than one ip/1394 network\n"
  103. " interface exist, entries for each ARP table are displayed.\n"
  104. );
  105. printf(
  106. " -add Adds the host and associates the Internet address inet_addr\n"
  107. " with the Physical address hw_addr. The entry is permanent.\n"
  108. );
  109. printf(
  110. " -del Deletes the host specified by inet_addr.\n"
  111. );
  112. printf(
  113. " -stats Displays arp/call/packet/task statistics.\n"
  114. );
  115. printf(
  116. " -resetstats Resets statistics collection.\n"
  117. );
  118. printf(
  119. " -purgecache Deletes all dynamic arp entries.\n"
  120. );
  121. printf(
  122. " -reinit Deactivates and then reactivates the interface.\n"
  123. );
  124. printf(
  125. " -send pkt Sends the specified packet on the broadcast channel.\n"
  126. );
  127. printf(
  128. " -recv pkt Simulates a receive of the specified packet on the.\n"
  129. " broadcast channel.\n"
  130. );
  131. printf(
  132. " -nicinfo Displays information about the 1394 network adapter.\n"
  133. " -a displays adapter-wide information\n"
  134. " -n node displays information about the node with node ID \"node\"\n"
  135. " -c channel displays information about channel \"channel\"\n"
  136. );
  137. printf(
  138. " -bstart adapter Starts Ethernet emulation (bridging) on the specified adapter.\n"
  139. );
  140. printf(
  141. " -bstop adapter Stops Ethernet emulation (bridging) on the specified adapter.\n"
  142. );
  143. printf(
  144. " -- Takes commands from standard input. Commands are options\n"
  145. " without the '-' prefix. Use ^C or 'q' to exit the program.\n"
  146. );
  147. printf(
  148. " -n if_addr Displays information for the network interface specified\n"
  149. " by if_addr. If not present, the first applicable interface will\n"
  150. " be used.\n"
  151. );
  152. printf(
  153. " inet_addr Specifies an internet address.\n"
  154. );
  155. printf(
  156. " hw_addr Specifies a physical address (64-bit Unique ID). The Physical\n"
  157. " address is given as 8 hexadecimal bytes separated by hyphens.\n"
  158. );
  159. printf(
  160. " pkt Specifies the key name under the [Packets] section of\n"
  161. " " PROGRAM ".INI. The value of the key contains the packet data.\n"
  162. );
  163. printf(
  164. " euidmap Prints The Euid, Node Address and Fake Mac Address \n"
  165. " assigned to a Remote Node\n"
  166. );
  167. printf(
  168. "\nExample:\n"
  169. " > " PROGRAM " -s 157.55.85.212 00-aa-00-62-c6-09-01-02 .... Adds a static entry.\n"
  170. " > " PROGRAM " -a .... Displays the arp table.\n"
  171. " > " PROGRAM " -stats arp -n 10.0.0.1 .... Displays arp statistics\n"
  172. " for interface 10.0.0.1.\n"
  173. );
  174. }
  175. UINT FindOption(
  176. char *lptOpt,
  177. char **ppVal,
  178. BOOL fCmdLine
  179. );
  180. enum
  181. {
  182. DO_DISP_HELP,
  183. DO_GET_ARPCACHE,
  184. DO_ADD_ARPENTRY,
  185. DO_DEL_ARPENTRY,
  186. DO_GET_STATS,
  187. DO_RESET_STATS,
  188. DO_REINIT_IF,
  189. DO_SWITCH_TO_STDIN,
  190. DO_SPECIFIC_IF,
  191. DO_GET_NICINFO,
  192. DO_X_ARP,
  193. DO_X_CALL,
  194. DO_X_TSKS,
  195. DO_X_PKTS,
  196. DO_X_ALL,
  197. DO_NI_CHANNELINFO,
  198. DO_BSTART,
  199. DO_BSTOP,
  200. DO_EUIDMAP,
  201. UNKNOWN_OPTION,
  202. // Put the at the end
  203. //
  204. DO_NI_BUSINFO = DO_GET_ARPCACHE, // Because both are "a"
  205. DO_NI_NODEINFO = DO_SPECIFIC_IF,
  206. };
  207. struct _CmdOptions {
  208. char * lptOption;
  209. UINT uOpt;
  210. } CmdOptions[] =
  211. {
  212. {"?" , DO_DISP_HELP },
  213. {"a" , DO_GET_ARPCACHE }, // Also DO_NI_BUSINFO
  214. {"s" , DO_ADD_ARPENTRY },
  215. {"g" , DO_ADD_ARPENTRY },
  216. {"add" , DO_ADD_ARPENTRY },
  217. {"del" , DO_DEL_ARPENTRY },
  218. {"stats" , DO_GET_STATS },
  219. {"resetstats" , DO_RESET_STATS },
  220. {"reinit" , DO_REINIT_IF },
  221. {"-" , DO_SWITCH_TO_STDIN },
  222. {"n" , DO_SPECIFIC_IF }, // Also DO_NI_NODEINFO
  223. {"nicinfo" , DO_GET_NICINFO },
  224. {"bstart" , DO_BSTART },
  225. {"bstop" , DO_BSTOP },
  226. {"euidmap" , DO_EUIDMAP },
  227. // Following are sub-options of /stats...
  228. //
  229. {"arp" , DO_X_ARP },
  230. {"call" , DO_X_CALL },
  231. {"tsks" , DO_X_TSKS },
  232. {"pkts" , DO_X_PKTS },
  233. {"pkt" , DO_X_PKTS },
  234. // Following are sub-options of /nicinfo...
  235. //
  236. // {"b" , DO_NI_BUSINFO },
  237. // {"n" , DO_NI_NODEINFO },
  238. {"c" , DO_NI_CHANNELINFO }
  239. };
  240. INT iCmdOptionsCounts = sizeof(CmdOptions)/sizeof(struct _CmdOptions);
  241. BOOL
  242. ParseCmdLine(
  243. int argc,
  244. char * argv[]
  245. )
  246. {
  247. BOOL bRetVal = TRUE;
  248. int iIndx=1;
  249. UINT uOpt;
  250. char *pVal;
  251. ZeroMemory(&g.Cmd, sizeof(g.Cmd));
  252. ZeroMemory(&g.Reserved, sizeof(g.Reserved));
  253. while(bRetVal && iIndx < argc)
  254. {
  255. uOpt = FindOption(argv[iIndx++], &pVal, TRUE);
  256. switch(uOpt)
  257. {
  258. case DO_GET_ARPCACHE:
  259. //
  260. // "arp13 -a\n"
  261. //
  262. {
  263. PARP1394_IOCTL_GET_ARPCACHE pGetCacheCmd = &g.Cmd.GetArpCache;
  264. if (argc != 2)
  265. {
  266. printf("Too many arguments for '-a'\n");
  267. bRetVal = FALSE;
  268. break;
  269. }
  270. pGetCacheCmd->Hdr.Version = ARP1394_IOCTL_VERSION;
  271. pGetCacheCmd->Hdr.Op = ARP1394_IOCTL_OP_GET_ARPCACHE;
  272. pGetCacheCmd->NumEntriesAvailable = NUM_ARPENTRIES_TO_GET;
  273. }
  274. break;
  275. case DO_ADD_ARPENTRY:
  276. //
  277. // "arp13 -add inet_addr hw_addr"
  278. //
  279. {
  280. PARP1394_IOCTL_ADD_ARP_ENTRY pAddCmd = &g.Cmd.AddArpEntry;
  281. bRetVal = FALSE;
  282. if ((iIndx+1) < argc)
  283. {
  284. bRetVal = ParseIpAddress(argv[iIndx++], &pAddCmd->IpAddress);
  285. if (!bRetVal) break;
  286. bRetVal = ParseHwAddress(argv[iIndx++], &pAddCmd->HwAddress);
  287. }
  288. else
  289. {
  290. printf("Not enough arguments for '-add'\n");
  291. }
  292. if (!bRetVal) break;
  293. pAddCmd->Hdr.Version = ARP1394_IOCTL_VERSION;
  294. pAddCmd->Hdr.Op = ARP1394_IOCTL_OP_ADD_STATIC_ENTRY;
  295. }
  296. break;
  297. case DO_DEL_ARPENTRY:
  298. //
  299. // "arp13 -del inet_addr"
  300. //
  301. {
  302. PARP1394_IOCTL_DEL_ARP_ENTRY pDelCmd = &g.Cmd.DelArpEntry;
  303. bRetVal = FALSE;
  304. if (iIndx < argc)
  305. {
  306. bRetVal = ParseIpAddress(argv[iIndx++], &pDelCmd->IpAddress);
  307. }
  308. else
  309. {
  310. printf("Not enough arguments for '-del'\n");
  311. }
  312. if (!bRetVal) break;
  313. pDelCmd->Hdr.Version = ARP1394_IOCTL_VERSION;
  314. pDelCmd->Hdr.Op = ARP1394_IOCTL_OP_DEL_STATIC_ENTRY;
  315. }
  316. break;
  317. case DO_GET_STATS:
  318. //
  319. // "arp13 -stats [arp|call|tsks|pkts]"
  320. //
  321. {
  322. PARP1394_IOCTL_COMMAND pCmd = &g.Cmd;
  323. INT StatsOp;
  324. if (iIndx >= argc)
  325. {
  326. StatsOp = DO_X_ARP;
  327. }
  328. else
  329. {
  330. StatsOp = FindOption(argv[iIndx++], &pVal, FALSE);
  331. }
  332. pCmd->Hdr.Version = ARP1394_IOCTL_VERSION;
  333. switch(StatsOp)
  334. {
  335. case DO_X_ARP:
  336. pCmd->Hdr.Op = ARP1394_IOCTL_OP_GET_ARPCACHE_STATS;
  337. break;
  338. case DO_X_CALL:
  339. pCmd->Hdr.Op = ARP1394_IOCTL_OP_GET_CALL_STATS;
  340. break;
  341. break;
  342. case DO_X_TSKS:
  343. pCmd->Hdr.Op = ARP1394_IOCTL_OP_GET_TASK_STATS;
  344. break;
  345. break;
  346. case DO_X_PKTS:
  347. pCmd->Hdr.Op = ARP1394_IOCTL_OP_GET_PACKET_STATS;
  348. break;
  349. default:
  350. // Assume default and put parsed value back.
  351. //
  352. StatsOp = DO_X_ARP;
  353. iIndx--;
  354. break;
  355. }
  356. }
  357. break;
  358. case DO_RESET_STATS:
  359. //
  360. // "arp13 -resetstats"
  361. //
  362. {
  363. PARP1394_IOCTL_RESET_STATS pResetStatsCmd = &g.Cmd.ResetStats;
  364. pResetStatsCmd->Hdr.Version = ARP1394_IOCTL_VERSION;
  365. pResetStatsCmd->Hdr.Op = ARP1394_IOCTL_OP_RESET_STATS;
  366. }
  367. break;
  368. case DO_REINIT_IF:
  369. //
  370. // "arp13 -reinit"
  371. //
  372. {
  373. PARP1394_IOCTL_REINIT_INTERFACE pReinitIfCmd;
  374. pReinitIfCmd = &g.Cmd.ReinitInterface;
  375. pReinitIfCmd->Hdr.Version = ARP1394_IOCTL_VERSION;
  376. pReinitIfCmd->Hdr.Op = ARP1394_IOCTL_OP_REINIT_INTERFACE;
  377. }
  378. break;
  379. case DO_BSTART:
  380. case DO_BSTOP:
  381. //
  382. // "arp13 -bstart adapter"
  383. //
  384. {
  385. UINT Size;
  386. PARP1394_IOCTL_ETHERNET_NOTIFICATION pEthCmd =
  387. &g.Cmd.EthernetNotification;
  388. bRetVal = FALSE;
  389. if (iIndx < argc)
  390. {
  391. bRetVal = ParseAdapter(
  392. argv[iIndx++],
  393. (PUCHAR) pEthCmd->AdapterName,
  394. sizeof(pEthCmd->AdapterName)-sizeof(WCHAR),
  395. &Size
  396. );
  397. pEthCmd->AdapterName[Size/2]=0;
  398. }
  399. else
  400. {
  401. printf("Not enough arguments for '-send pkt'\n");
  402. }
  403. if (!bRetVal) break;
  404. pEthCmd->Hdr.Version = ARP1394_IOCTL_VERSION;
  405. if (uOpt == DO_BSTART)
  406. {
  407. // printf("BRIDGE START\n");
  408. pEthCmd->Hdr.Op = ARP1394_IOCTL_OP_ETHERNET_START_EMULATION;
  409. }
  410. else
  411. {
  412. // printf("BRIDGE STOP\n");
  413. pEthCmd->Hdr.Op = ARP1394_IOCTL_OP_ETHERNET_STOP_EMULATION;
  414. }
  415. }
  416. break;
  417. case DO_GET_NICINFO:
  418. //
  419. // ipfwadm -nicinfo [a|n node_id |c channel_number]
  420. //
  421. {
  422. PNIC1394_NICINFO pNi = &g.Cmd.IoctlNicInfo.Info;
  423. INT NicOp;
  424. UINT Num;
  425. if (iIndx >= argc)
  426. {
  427. NicOp = DO_NI_BUSINFO; // Default
  428. }
  429. else
  430. {
  431. NicOp = FindOption(argv[iIndx++], &pVal, FALSE);
  432. }
  433. g.Cmd.Hdr.Version = ARP1394_IOCTL_VERSION;
  434. g.Cmd.Hdr.Op = ARP1394_IOCTL_OP_GET_NICINFO;
  435. pNi->Hdr.Version = NIC1394_NICINFO_VERSION;
  436. //
  437. // Parse the sub-command
  438. //
  439. switch(NicOp)
  440. {
  441. default:
  442. // Assume default and put parsed value back.
  443. //
  444. iIndx--;
  445. // FALL THROUGH
  446. case DO_NI_BUSINFO:
  447. pNi->Hdr.Op = NIC1394_NICINFO_OP_BUSINFO;
  448. break;
  449. case DO_NI_NODEINFO:
  450. pNi->Hdr.Op = NIC1394_NICINFO_OP_REMOTENODEINFO;
  451. // Read mandatory node number
  452. //
  453. bRetVal = FALSE;
  454. if (iIndx < argc)
  455. {
  456. if (sscanf(argv[iIndx++], "%d", &Num)==1)
  457. {
  458. bRetVal = TRUE;
  459. }
  460. }
  461. if (bRetVal)
  462. {
  463. pNi->RemoteNodeInfo.NodeAddress = (USHORT) Num;
  464. }
  465. else
  466. {
  467. printf("Missing node id\n");
  468. }
  469. break;
  470. case DO_NI_CHANNELINFO:
  471. pNi->Hdr.Op = NIC1394_NICINFO_OP_CHANNELINFO;
  472. // Read mandatory channel number
  473. //
  474. bRetVal = FALSE;
  475. if (iIndx < argc)
  476. {
  477. if (sscanf(argv[iIndx++], "%d", &Num)==1)
  478. {
  479. bRetVal = TRUE;
  480. }
  481. }
  482. if (bRetVal)
  483. {
  484. pNi->ChannelInfo.Channel = Num;
  485. }
  486. else
  487. {
  488. printf("Missing channel number\n");
  489. }
  490. break;
  491. }
  492. }
  493. break;
  494. case DO_EUIDMAP:
  495. {
  496. PARP1394_IOCTL_EUID_NODE_MAC_INFO pMapInfo = &g.Cmd.EuidNodeMacInfo;
  497. pMapInfo->Hdr.Version = ARP1394_IOCTL_VERSION;
  498. pMapInfo->Hdr.Op = ARP1394_IOCTL_OP_GET_EUID_NODE_MAC_TABLE;
  499. printf("Receved EuidMap");
  500. }
  501. break;
  502. case DO_SWITCH_TO_STDIN:
  503. //
  504. // "arp13 --"
  505. //
  506. printf("Switch to stdin UNIMPLEMENTED.\n");
  507. bRetVal = FALSE;
  508. break;
  509. case DO_SPECIFIC_IF:
  510. //
  511. // "-n if_addr"
  512. //
  513. {
  514. PARP1394_IOCTL_HEADER pHdr = &g.Cmd.Hdr;
  515. bRetVal = ParseIpAddress(argv[iIndx++], &pHdr->IfIpAddress);
  516. if (!bRetVal) break;
  517. }
  518. break;
  519. default:
  520. printf("Unknown option: %s\n", argv[iIndx-1]); // fall through
  521. //
  522. // FALL THROUGH...
  523. //
  524. case DO_DISP_HELP:
  525. Usage();
  526. bRetVal = FALSE;
  527. break;
  528. }
  529. }
  530. if (argc<=1)
  531. {
  532. //
  533. // Display help...
  534. //
  535. Usage();
  536. }
  537. if (bRetVal)
  538. {
  539. bRetVal = ValidateCommand(&g.Cmd);
  540. }
  541. return bRetVal;
  542. }
  543. UINT FindOption(
  544. char *lptOpt,
  545. char **ppVal,
  546. BOOL fCmdLine
  547. )
  548. {
  549. int i;
  550. UINT iLen;
  551. char c = *lptOpt;
  552. // if (fCmdLine), expect, and skip past the '-', or '/'...
  553. //
  554. if (fCmdLine)
  555. {
  556. if (c == '-' || c == '/')
  557. {
  558. lptOpt++;
  559. }
  560. else
  561. {
  562. return UNKNOWN_OPTION; // EARLY RETURN
  563. }
  564. }
  565. for(i = 0; i < iCmdOptionsCounts; i++)
  566. {
  567. if(strlen(lptOpt) >= (iLen = strlen(CmdOptions[i].lptOption)))
  568. {
  569. if(0 == strcmp(lptOpt, CmdOptions[i].lptOption))
  570. {
  571. *ppVal = lptOpt + iLen;
  572. return CmdOptions[i].uOpt;
  573. }
  574. }
  575. }
  576. return UNKNOWN_OPTION;
  577. }
  578. BOOL
  579. ParseIpAddress(
  580. PCHAR buf,
  581. PULONG pIpAddress
  582. )
  583. /*++
  584. Routine Description:
  585. Parse IP address in buf the form a.b.c.d and return the parsed value
  586. in *pIpAddress in network byte order.
  587. Return Value:
  588. TRUE iff correctly formed IP address. False otherwise.
  589. --*/
  590. {
  591. BOOL fRet = FALSE;
  592. do
  593. {
  594. INT rgi[4];
  595. INT i;
  596. i = sscanf(buf, "%d.%d.%d.%d", rgi+0, rgi+1, rgi+2, rgi+3);
  597. if (i<4) break;
  598. fRet = TRUE;
  599. for (i=0; i<4; i++)
  600. {
  601. INT iTmp = rgi[i];
  602. if (iTmp == -1)
  603. {
  604. iTmp = 255;
  605. }
  606. if (iTmp<0 || iTmp>255)
  607. {
  608. fRet = FALSE;
  609. break;
  610. }
  611. rgi[i] = iTmp;
  612. }
  613. if (!fRet) break;
  614. // Construct IP address in network byte order.
  615. //
  616. {
  617. ULONG u = (ULONG) rgi[0];
  618. u |= ((ULONG)rgi[1])<<8;
  619. u |= ((ULONG)rgi[2])<<16;
  620. u |= ((ULONG)rgi[3])<<24;
  621. *pIpAddress = u;
  622. }
  623. #if 0
  624. printf(
  625. "(%d.%d.%d.%d)->0x%08lx\n",
  626. rgi[0], rgi[1], rgi[2], rgi[3], *pIpAddress
  627. );
  628. #endif // 0
  629. } while (FALSE);
  630. if (!fRet)
  631. {
  632. printf("Invalid IP address: %s\n", buf);
  633. }
  634. return fRet;
  635. }
  636. BOOL
  637. ParseHwAddress(
  638. PCHAR buf,
  639. PARP1394_IOCTL_HW_ADDRESS pHwAddr
  640. )
  641. /*++
  642. Routine Description:
  643. Parse IEEE1394 HW address in buf the form of 8 bytes separated by hyphens.
  644. Return the parsed value in *pHwAddr in network byte order.
  645. Return Value:
  646. TRUE iff correctly formed HW address. False otherwise.
  647. --*/
  648. {
  649. BOOL fRet = FALSE;
  650. do
  651. {
  652. ULONG rgu[8];
  653. INT i;
  654. i = sscanf(
  655. buf,
  656. "%lx-%lx-%lx-%lx-%lx-%lx-%lx-%lx",
  657. rgu+0, rgu+1, rgu+2, rgu+3,
  658. rgu+4, rgu+5, rgu+6, rgu+7
  659. );
  660. if (i<8) break;
  661. fRet = TRUE;
  662. for (i=0; i<8; i++)
  663. {
  664. ULONG u = rgu[i];
  665. if (u>255)
  666. {
  667. fRet = FALSE;
  668. break;
  669. }
  670. ((PUCHAR)(&pHwAddr->UniqueID))[i] = (UCHAR) u;
  671. }
  672. if (!fRet) break;
  673. #if 0
  674. printf(
  675. "(%d-%d-%d-%d-%d-%d-%d-%d) -> 0x%08lx:0x%08lx\n",
  676. rgu[0], rgu[1], rgu[2], rgu[3],
  677. rgu[4], rgu[5], rgu[6], rgu[7],
  678. ((PULONG)(&pHwAddr->UniqueID))[0],
  679. ((PULONG)(&pHwAddr->UniqueID))[1]
  680. );
  681. #endif // 0
  682. } while (FALSE);
  683. if (!fRet)
  684. {
  685. printf("Invalid HW address: %s\n", buf);
  686. }
  687. return fRet;
  688. }
  689. BOOL
  690. ValidateCommand(PARP1394_IOCTL_COMMAND pCmd)
  691. {
  692. BOOL fRet = FALSE;
  693. if (pCmd->Hdr.Version != ARP1394_IOCTL_VERSION) return FALSE; // EARLY RETURN
  694. switch(pCmd->Hdr.Op)
  695. {
  696. case ARP1394_IOCTL_OP_GET_ARPCACHE:
  697. {
  698. PARP1394_IOCTL_GET_ARPCACHE pGetCacheCmd = &pCmd->GetArpCache;
  699. #if 0
  700. printf(
  701. "CMD = \n{"
  702. " Op = GET_ARPCACHE;\n"
  703. " IpIf = 0x%08lx;\n"
  704. " NumAvail = %lu;\n"
  705. "};\n",
  706. pGetCacheCmd->Hdr.IfIpAddress,
  707. pGetCacheCmd->NumEntriesAvailable
  708. );
  709. #endif // 0
  710. fRet = TRUE;
  711. }
  712. break;
  713. case ARP1394_IOCTL_OP_ADD_STATIC_ENTRY:
  714. {
  715. PARP1394_IOCTL_ADD_ARP_ENTRY pAddCmd = &pCmd->AddArpEntry;
  716. #if 0
  717. printf(
  718. "CMD = \n{"
  719. " Op = ADD_ENTRY;\n"
  720. " IpIf = 0x%08lx;\n"
  721. " IpAddress = 0x%08lx;\n"
  722. " HwAddress = 0x%08lx:0x%08lx;\n"
  723. "};\n",
  724. pAddCmd->Hdr.IfIpAddress,
  725. pAddCmd->IpAddress,
  726. ((PULONG)&pAddCmd->HwAddress)[0],
  727. ((PULONG)&pAddCmd->HwAddress)[1]
  728. );
  729. #endif // 0
  730. fRet = TRUE;
  731. }
  732. break;
  733. case ARP1394_IOCTL_OP_DEL_STATIC_ENTRY:
  734. {
  735. PARP1394_IOCTL_DEL_ARP_ENTRY pDelCmd = &pCmd->DelArpEntry;
  736. #if 0
  737. printf(
  738. "CMD = \n{"
  739. " Op = DEL_ENTRY;\n"
  740. " IpIf = 0x%08lx;\n"
  741. " IpAddress = 0x%08lx;\n"
  742. "};\n",
  743. pDelCmd->Hdr.IfIpAddress,
  744. pDelCmd->IpAddress
  745. );
  746. #endif // 0
  747. fRet = TRUE;
  748. }
  749. break;
  750. case ARP1394_IOCTL_OP_GET_PACKET_STATS:
  751. {
  752. PARP1394_IOCTL_GET_PACKET_STATS pStatsCmd = &pCmd->GetPktStats;
  753. #if 0
  754. printf(
  755. "CMD = \n{"
  756. " Op = GET_PACKET_STATS;\n"
  757. " IpIf = 0x%08lx;\n"
  758. "};\n",
  759. pStatsCmd->Hdr.IfIpAddress
  760. );
  761. #endif // 0
  762. fRet = TRUE;
  763. }
  764. break;
  765. case ARP1394_IOCTL_OP_GET_TASK_STATS:
  766. {
  767. PARP1394_IOCTL_GET_TASK_STATS pStatsCmd = &pCmd->GetTaskStats;
  768. #if 0
  769. printf(
  770. "CMD = \n{"
  771. " Op = GET_TASK_STATS;\n"
  772. " IpIf = 0x%08lx;\n"
  773. "};\n",
  774. pStatsCmd->Hdr.IfIpAddress
  775. );
  776. #endif // 0
  777. fRet = TRUE;
  778. }
  779. break;
  780. case ARP1394_IOCTL_OP_GET_ARPCACHE_STATS:
  781. {
  782. PARP1394_IOCTL_GET_ARPCACHE_STATS pStatsCmd = &pCmd->GetArpStats;
  783. #if 0
  784. printf(
  785. "CMD = \n{"
  786. " Op = GET_ARPCACHE_STATS;\n"
  787. " IpIf = 0x%08lx;\n"
  788. "};\n",
  789. pStatsCmd->Hdr.IfIpAddress
  790. );
  791. #endif // 0
  792. fRet = TRUE;
  793. }
  794. break;
  795. case ARP1394_IOCTL_OP_GET_CALL_STATS:
  796. {
  797. PARP1394_IOCTL_GET_CALL_STATS pStatsCmd = &pCmd->GetCallStats;
  798. #if 0
  799. printf(
  800. "CMD = \n{"
  801. " Op = GET_CALL_STATS;\n"
  802. " IpIf = 0x%08lx;\n"
  803. "};\n",
  804. pStatsCmd->Hdr.IfIpAddress
  805. );
  806. #endif // 0
  807. fRet = TRUE;
  808. }
  809. break;
  810. case ARP1394_IOCTL_OP_RESET_STATS:
  811. {
  812. PARP1394_IOCTL_RESET_STATS pStatsCmd = &pCmd->ResetStats;
  813. #if 0
  814. printf(
  815. "CMD = \n{"
  816. " Op = GET_RESET_STATS;\n"
  817. " IpIf = 0x%08lx;\n"
  818. "};\n",
  819. pStatsCmd->Hdr.IfIpAddress
  820. );
  821. #endif // 0
  822. fRet = TRUE;
  823. }
  824. break;
  825. case ARP1394_IOCTL_OP_REINIT_INTERFACE:
  826. {
  827. PARP1394_IOCTL_REINIT_INTERFACE pReinitCmd = &pCmd->ReinitInterface;
  828. #if 0
  829. printf(
  830. "CMD = \n{"
  831. " Op = GET_REINIT_INTERFACE;\n"
  832. " IpIf = 0x%08lx;\n"
  833. "};\n",
  834. pReinitCmd->Hdr.IfIpAddress
  835. );
  836. #endif // 0
  837. fRet = TRUE;
  838. }
  839. break;
  840. case ARP1394_IOCTL_OP_ETHERNET_START_EMULATION:
  841. case ARP1394_IOCTL_OP_ETHERNET_STOP_EMULATION:
  842. {
  843. fRet = TRUE;
  844. }
  845. break;
  846. case ARP1394_IOCTL_OP_GET_NICINFO:
  847. {
  848. PARP1394_IOCTL_NICINFO pNicInfoCmd = &pCmd->IoctlNicInfo;
  849. #if 0
  850. printf(
  851. "CMD = \n{"
  852. " Op = NICINFO;\n"
  853. " IpIf = 0x%08lx;\n"
  854. "};\n",
  855. pNicInfoCmd->Hdr.IfIpAddress
  856. );
  857. #endif // 0
  858. fRet = TRUE;
  859. }
  860. break;
  861. case ARP1394_IOCTL_OP_GET_EUID_NODE_MAC_TABLE:
  862. {
  863. fRet = TRUE;
  864. }
  865. default:
  866. break;
  867. }
  868. return fRet;
  869. };
  870. CHAR *g_szPacketName;
  871. BOOL
  872. ParsePacket(
  873. PCHAR buf,
  874. UCHAR *data,
  875. UINT cbData,
  876. UINT *pcbPacketSize
  877. )
  878. {
  879. char Path[256];
  880. UINT u;
  881. BOOL fRet = FALSE;
  882. g_szPacketName = buf;
  883. u = GetCurrentDirectory(sizeof(Path), Path);
  884. if (u==0)
  885. {
  886. printf("Couldn't get current directory.\n");
  887. return FALSE;
  888. }
  889. strcat(Path, "\\");
  890. strcat(Path, PROGRAM);
  891. strcat(Path, ".ini");
  892. // printf("INI file location = %s\n", Path);
  893. fRet = GetBinaryData(
  894. Path,
  895. "Packets",
  896. buf,
  897. data,
  898. cbData,
  899. pcbPacketSize
  900. );
  901. #if 0
  902. static IP1394_MCAP_PKT Pkt =
  903. {
  904. {
  905. H2N_USHORT(0), // Node id
  906. H2N_USHORT(NIC1394_ETHERTYPE_MCAP)
  907. },
  908. H2N_USHORT(
  909. sizeof(IP1394_MCAP_PKT) - sizeof(NIC1394_UNFRAGMENTED_HEADER)),
  910. 0, // reserved
  911. IP1394_MCAP_OP_ADVERTISE, // IP1394_MCAP_OP_SOLICIT
  912. {
  913. sizeof(IP1394_MCAP_GD),
  914. IP1394_MCAP_GD_TYPE_V1,
  915. 0, // reserved;
  916. 60, // expiration;
  917. 2, // channel
  918. 2, // speed
  919. 0, // reserved2;
  920. 0, // bandwidth;
  921. 0x010000e1 // IP multicast group address 225.0.0.1
  922. }
  923. };
  924. PIP1394_MCAP_PKT pPkt;
  925. pPkt = &Pkt;
  926. if (cbData >= sizeof(Pkt))
  927. {
  928. printf ("ParsePacket: MCAP packet of size %lu.\n", sizeof(Pkt));
  929. *(PIP1394_MCAP_PKT) data = *pPkt;
  930. *pcbPacketSize = sizeof (Pkt);
  931. fRet = TRUE;
  932. }
  933. else
  934. {
  935. printf ("ParsePacket: buffer size too small.\n");
  936. }
  937. #endif // 0
  938. return fRet;
  939. }
  940. BOOL
  941. ParseAdapter(
  942. PCHAR buf,
  943. UCHAR *data,
  944. UINT cbData,
  945. UINT *pcbAdapterSize
  946. )
  947. {
  948. char Path[256];
  949. UINT u;
  950. BOOL fRet = FALSE;
  951. g_szPacketName = buf;
  952. u = GetCurrentDirectory(sizeof(Path), Path);
  953. if (u==0)
  954. {
  955. printf("Couldn't get current directory.\n");
  956. return FALSE;
  957. }
  958. strcat(Path, "\\");
  959. strcat(Path, PROGRAM);
  960. strcat(Path, ".ini");
  961. // printf("INI file location = %s\n", Path);
  962. fRet = GetBinaryData(
  963. Path,
  964. "Adapters",
  965. buf,
  966. data,
  967. cbData,
  968. pcbAdapterSize
  969. );
  970. return fRet;
  971. }
  972. typedef struct
  973. {
  974. IP1394_MCAP_PKT Pkt;
  975. IP1394_MCAP_GD Gd2;
  976. } MYPKT2;
  977. typedef struct
  978. {
  979. IP1394_MCAP_PKT Pkt;
  980. IP1394_MCAP_GD Gd2;
  981. IP1394_MCAP_GD Gd3;
  982. } MYPKT3;
  983. typedef struct
  984. {
  985. IP1394_MCAP_PKT Pkt;
  986. IP1394_MCAP_GD Gd2;
  987. IP1394_MCAP_GD Gd3;
  988. IP1394_MCAP_GD Gd4;
  989. } MYPKT4;
  990. #define SWAPBYTES_USHORT(Val) \
  991. ((((Val) & 0xff) << 8) | (((Val) & 0xff00) >> 8))
  992. #define H2N_USHORT(Val) SWAPBYTES_USHORT(Val)
  993. IP1394_MCAP_PKT Pkt1 =
  994. {
  995. {
  996. H2N_USHORT(0), // Node id
  997. H2N_USHORT(NIC1394_ETHERTYPE_MCAP)
  998. },
  999. H2N_USHORT(
  1000. sizeof(IP1394_MCAP_PKT) - sizeof(NIC1394_UNFRAGMENTED_HEADER)),
  1001. 0, // reserved
  1002. IP1394_MCAP_OP_ADVERTISE, // IP1394_MCAP_OP_SOLICIT
  1003. {
  1004. sizeof(IP1394_MCAP_GD),
  1005. IP1394_MCAP_GD_TYPE_V1,
  1006. 0, // reserved;
  1007. 60, // expiration;
  1008. 2, // channel
  1009. 2, // speed
  1010. 0, // reserved2;
  1011. 0, // bandwidth;
  1012. 0x010000e1 // IP multicast group address 225.0.0.1
  1013. }
  1014. };
  1015. MYPKT2 Pkt2 =
  1016. {
  1017. {
  1018. {
  1019. H2N_USHORT(0), // Node id
  1020. H2N_USHORT(NIC1394_ETHERTYPE_MCAP)
  1021. },
  1022. H2N_USHORT(
  1023. sizeof(MYPKT2) - sizeof(NIC1394_UNFRAGMENTED_HEADER)),
  1024. 0, // reserved
  1025. IP1394_MCAP_OP_ADVERTISE, // IP1394_MCAP_OP_SOLICIT
  1026. {
  1027. sizeof(IP1394_MCAP_GD),
  1028. IP1394_MCAP_GD_TYPE_V1,
  1029. 0, // reserved;
  1030. 60, // expiration;
  1031. 2, // channel
  1032. 2, // speed
  1033. 0, // reserved2;
  1034. 0, // bandwidth;
  1035. 0x010000e1 // IP multicast group address 225.0.0.1
  1036. }
  1037. },
  1038. {
  1039. sizeof(IP1394_MCAP_GD),
  1040. IP1394_MCAP_GD_TYPE_V1,
  1041. 0, // reserved;
  1042. 60, // expiration;
  1043. 2, // channel
  1044. 2, // speed
  1045. 0, // reserved2;
  1046. 0, // bandwidth;
  1047. 0x020000e1 // IP multicast group address 225.0.0.2
  1048. }
  1049. };
  1050. MYPKT3 Pkt3 =
  1051. {
  1052. {
  1053. {
  1054. H2N_USHORT(0), // Node id
  1055. H2N_USHORT(NIC1394_ETHERTYPE_MCAP)
  1056. },
  1057. H2N_USHORT(
  1058. sizeof(MYPKT3) - sizeof(NIC1394_UNFRAGMENTED_HEADER)),
  1059. 0, // reserved
  1060. IP1394_MCAP_OP_ADVERTISE, // IP1394_MCAP_OP_SOLICIT
  1061. {
  1062. sizeof(IP1394_MCAP_GD),
  1063. IP1394_MCAP_GD_TYPE_V1,
  1064. 0, // reserved;
  1065. 60, // expiration;
  1066. 2, // channel
  1067. 2, // speed
  1068. 0, // reserved2;
  1069. 0, // bandwidth;
  1070. 0x010000e1 // IP multicast group address 225.0.0.1
  1071. }
  1072. },
  1073. {
  1074. sizeof(IP1394_MCAP_GD),
  1075. IP1394_MCAP_GD_TYPE_V1,
  1076. 0, // reserved;
  1077. 60, // expiration;
  1078. 2, // channel
  1079. 2, // speed
  1080. 0, // reserved2;
  1081. 0, // bandwidth;
  1082. 0x020000e1 // IP multicast group address 225.0.0.2
  1083. },
  1084. {
  1085. sizeof(IP1394_MCAP_GD),
  1086. IP1394_MCAP_GD_TYPE_V1,
  1087. 0, // reserved;
  1088. 60, // expiration;
  1089. 2, // channel
  1090. 2, // speed
  1091. 0, // reserved2;
  1092. 0, // bandwidth;
  1093. 0x030000e1 // IP multicast group address 225.0.0.3
  1094. }
  1095. };
  1096. MYPKT4 Pkt4 =
  1097. {
  1098. {
  1099. {
  1100. H2N_USHORT(0), // Node id
  1101. H2N_USHORT(NIC1394_ETHERTYPE_MCAP)
  1102. },
  1103. H2N_USHORT(
  1104. sizeof(MYPKT4) - sizeof(NIC1394_UNFRAGMENTED_HEADER)),
  1105. 0, // reserved
  1106. IP1394_MCAP_OP_ADVERTISE, // IP1394_MCAP_OP_SOLICIT
  1107. {
  1108. sizeof(IP1394_MCAP_GD),
  1109. IP1394_MCAP_GD_TYPE_V1,
  1110. 0, // reserved;
  1111. 60, // expiration;
  1112. 2, // channel
  1113. 2, // speed
  1114. 0, // reserved2;
  1115. 0, // bandwidth;
  1116. 0x010000e1 // IP multicast group address 225.0.0.1
  1117. }
  1118. },
  1119. {
  1120. sizeof(IP1394_MCAP_GD),
  1121. IP1394_MCAP_GD_TYPE_V1,
  1122. 0, // reserved;
  1123. 60, // expiration;
  1124. 2, // channel
  1125. 2, // speed
  1126. 0, // reserved2;
  1127. 0, // bandwidth;
  1128. 0x020000e1 // IP multicast group address 225.0.0.2
  1129. },
  1130. {
  1131. sizeof(IP1394_MCAP_GD),
  1132. IP1394_MCAP_GD_TYPE_V1,
  1133. 0, // reserved;
  1134. 60, // expiration;
  1135. 2, // channel
  1136. 2, // speed
  1137. 0, // reserved2;
  1138. 0, // bandwidth;
  1139. 0x030000e1 // IP multicast group address 225.0.0.3
  1140. },
  1141. {
  1142. sizeof(IP1394_MCAP_GD),
  1143. IP1394_MCAP_GD_TYPE_V1,
  1144. 0, // reserved;
  1145. 60, // expiration;
  1146. 2, // channel
  1147. 2, // speed
  1148. 0, // reserved2;
  1149. 0, // bandwidth;
  1150. 0x040000e1 // IP multicast group address 225.0.0.4
  1151. }
  1152. };