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.

1537 lines
49 KiB

  1. //============================================================================
  2. //
  3. // Copyright (C) 2000 Microsoft Corporation
  4. //
  5. // FILE: PGM.c
  6. //
  7. // Description: Parses a PGM frame
  8. // Displays the PGM header
  9. // Displays the PGM options
  10. //
  11. // Note: info for this parser was gleaned from:
  12. // (PGM Documentation)
  13. //
  14. // Modification History
  15. //
  16. // Madhurima Pawar ([email protected]) 08/04/00 Created
  17. //============================================================================
  18. #include "PGM.h"
  19. //============================================================================
  20. //Global variables
  21. //============================================================================
  22. HPROTOCOL hPGM = NULL; //Handle to PGM's parser database properties
  23. DWORD PGMAttached = 0; //Number of times protocol instances that are running
  24. //====================================================================
  25. //External functions used to regester PGM. These function are exported to Netmon
  26. //By putting a _delspec the function is immediatly exported and does not have to
  27. //be exported through a .def file. This is useful when many parsers are in
  28. //one dll and some are included and some are not.
  29. //=================================================================================
  30. extern VOID _declspec(dllexport) WINAPI PGM_Register( HPROTOCOL hPGM);
  31. extern VOID _declspec(dllexport) WINAPI PGM_Deregister( HPROTOCOL hPGM);
  32. extern LPBYTE _declspec(dllexport) WINAPI PGM_RecognizeFrame( HFRAME hFrame,
  33. LPBYTE pMACFrame,
  34. LPBYTE pPGMFrame,
  35. DWORD PGMType,
  36. DWORD BytesLeft,
  37. HPROTOCOL hPrevProtocol,
  38. DWORD nPrevProtOffset,
  39. LPDWORD pProtocolStatus,
  40. LPHPROTOCOL phNextProtocol,
  41. PDWORD_PTR InstData);
  42. extern LPBYTE _declspec(dllexport) WINAPI PGM_AttachProperties( HFRAME hFrame,
  43. LPBYTE pMACFrame,
  44. LPBYTE pPGMFrame,
  45. DWORD PGMType,
  46. DWORD BytesLeft,
  47. HPROTOCOL hPrevProtocol,
  48. DWORD nPrevProtOffset,
  49. DWORD_PTR InstData);
  50. extern DWORD _declspec(dllexport) WINAPI PGM_FormatProperties( HFRAME hFrame,
  51. LPBYTE pMACFrame,
  52. LPBYTE pPGMFrame,
  53. DWORD nPropertyInsts,
  54. LPPROPERTYINST p);
  55. extern VOID WINAPIV PGM_FmtSummary( LPPROPERTYINST pPropertyInst );
  56. //============================================================================
  57. //Format functions customize the format of the data. Network Monitor
  58. //provides baic format structures such as IP version 4 address.
  59. //All other formats must be writen by the programmer.
  60. //============================================================================
  61. VOID WINAPIV PGM_FormatSummary( LPPROPERTYINST pPropertyInst);
  62. //============================================================================
  63. //Define the entry points that we will pass back to NetMon at dll
  64. //entry time
  65. //============================================================================
  66. ENTRYPOINTS PGMEntryPoints =
  67. {
  68. PGM_Register,
  69. PGM_Deregister,
  70. PGM_RecognizeFrame,
  71. PGM_AttachProperties,
  72. PGM_FormatProperties,
  73. };
  74. //====================================================================
  75. //Property Value Labels are tables that map numbers to strings.
  76. //====================================================================
  77. LABELED_BYTE PGMTypes[] = //The types of PGM
  78. {
  79. { 0, "SPM" },
  80. { 1, "POLL" },
  81. { 2, "POLR" },
  82. { 4, "ODATA" },
  83. { 5, "RDATA" },
  84. { 8, "NACK" },
  85. { 9, "NNACK" },
  86. { 10, "NCF" } ,
  87. };
  88. LABELED_BIT PGMHeaderOptions[] =
  89. {
  90. { 7, "Non-Parity ", "PARITY " },
  91. { 6, "Not a variable-length parity packet", "VARIABLE LENGTH PARITY PACKET" },
  92. { 1, "Not Network Significant ", "NETWORK SIGNIFICANT " },
  93. { 0, "No header Options ", "Packet header has options " },
  94. };
  95. LABELED_BIT PGMParityOptions[] =
  96. {
  97. { 1, "No Pro-Active Parity ", "PRO-ACTIVE Parity enabled" },
  98. { 0, "Selective NAKs Only ", "ON-DEMAND Parity enabled " },
  99. };
  100. //====================================================================
  101. //Make a set out of the above listings. The set contains the list
  102. //aswell as the size
  103. //====================================================================
  104. SET PGMTypesSET = {(sizeof(PGMTypes)/sizeof(LABELED_BYTE)), PGMTypes };
  105. SET PGMHeaderOptionsSET = {(sizeof(PGMHeaderOptions)/sizeof(LABELED_BIT)), PGMHeaderOptions };
  106. SET PGMParityOptionsSET = {(sizeof(PGMParityOptions)/sizeof(LABELED_BIT)), PGMParityOptions };
  107. //====================================================================
  108. //PGM Database (Properties Table). This table stores the properties
  109. //of each field in an PGM package. Each field property has a name,
  110. //size and format function. FormatPropertyInstance is the standard
  111. //NetMon formatter. The comment is the location of the property in
  112. //the table
  113. //====================================================================
  114. PROPERTYINFO PGMPropertyTable[] =
  115. {
  116. // PGM_SUMMARY (0)
  117. { 0, 0,
  118. "Summary",
  119. "Summary of the PGM Packet",
  120. PROP_TYPE_SUMMARY,
  121. PROP_QUAL_NONE,
  122. NULL,
  123. PGM_FMT_STR_SIZE,
  124. PGM_FmtSummary
  125. },
  126. // PGM_SOURCE_PORT (1)
  127. { 0, 0,
  128. "Source Port",
  129. "Source Port",
  130. PROP_TYPE_BYTESWAPPED_WORD,
  131. PROP_QUAL_NONE,
  132. NULL,
  133. PGM_FMT_STR_SIZE,
  134. FormatPropertyInstance
  135. },
  136. // PGM_DESTINATION_PORT (2)
  137. { 0, 0,
  138. "Destination Port",
  139. "Destination Port",
  140. PROP_TYPE_BYTESWAPPED_WORD,
  141. PROP_QUAL_NONE,
  142. NULL,
  143. PGM_FMT_STR_SIZE,
  144. FormatPropertyInstance
  145. },
  146. // PGM_TYPE (3)
  147. { 0, 0,
  148. "Type",
  149. "Type of PGM",
  150. PROP_TYPE_BYTE,
  151. PROP_QUAL_LABELED_SET,
  152. &PGMTypesSET,
  153. PGM_FMT_STR_SIZE,
  154. FormatPropertyInstance
  155. },
  156. // PGM_CHECKSUM (4)
  157. { 0, 0,
  158. "Checksum",
  159. "Checksum for PGM packet",
  160. PROP_TYPE_BYTESWAPPED_WORD,
  161. PROP_QUAL_NONE,
  162. NULL,
  163. PGM_FMT_STR_SIZE,
  164. FormatPropertyInstance
  165. },
  166. // PGM_GLOBAL_SOURCE_ID (5)
  167. { 0, 0,
  168. "Global Source Id",
  169. "Global Source Id for PGM session",
  170. PROP_TYPE_STRING,
  171. PROP_QUAL_NONE,
  172. NULL,
  173. PGM_FMT_STR_SIZE,
  174. FormatPropertyInstance
  175. },
  176. // PGM_TSDU_LENGTH (6)
  177. { 0, 0,
  178. "TSDU Length",
  179. "TSDU Length",
  180. PROP_TYPE_BYTESWAPPED_WORD,
  181. PROP_QUAL_NONE,
  182. NULL,
  183. PGM_FMT_STR_SIZE,
  184. FormatPropertyInstance
  185. },
  186. // PGM_SEQUENCE_NUMBER (7)
  187. { 0, 0,
  188. "Sequence Number",
  189. "Packet Sequence Number",
  190. PROP_TYPE_BYTESWAPPED_DWORD,
  191. PROP_QUAL_NONE,
  192. NULL,
  193. PGM_FMT_STR_SIZE,
  194. FormatPropertyInstance
  195. },
  196. // PGM_TRAILING_EDGE (8)
  197. { 0, 0,
  198. "Trailing Edge",
  199. "Trailing Edge Sequence Number",
  200. PROP_TYPE_BYTESWAPPED_DWORD,
  201. PROP_QUAL_NONE,
  202. NULL,
  203. PGM_FMT_STR_SIZE,
  204. FormatPropertyInstance
  205. },
  206. // PGM_LEADING_EDGE (9)
  207. { 0, 0,
  208. "Leading Edge",
  209. "Leading Edge Sequence Number",
  210. PROP_TYPE_BYTESWAPPED_DWORD,
  211. PROP_QUAL_NONE,
  212. NULL,
  213. PGM_FMT_STR_SIZE,
  214. FormatPropertyInstance
  215. },
  216. // PGM_NLA_TYPE_SOURCE (10)
  217. { 0, 0,
  218. "Source Path NLA",
  219. "Source Path NLA",
  220. PROP_TYPE_SUMMARY,
  221. PROP_QUAL_NONE,
  222. NULL,
  223. PGM_FMT_STR_SIZE,
  224. FormatPropertyInstance
  225. },
  226. // PGM_NLA_TYPE_MCAST_GROUP (11)
  227. { 0, 0,
  228. "MCAST Group NLA",
  229. "MCAST Group NLA",
  230. PROP_TYPE_SUMMARY,
  231. PROP_QUAL_NONE,
  232. NULL,
  233. PGM_FMT_STR_SIZE,
  234. FormatPropertyInstance
  235. },
  236. // PGM_NLA_AFI (12)
  237. { 0, 0,
  238. "NLA AFI",
  239. "NLA AFI",
  240. PROP_TYPE_BYTESWAPPED_WORD,
  241. PROP_QUAL_NONE,
  242. NULL,
  243. PGM_FMT_STR_SIZE,
  244. FormatPropertyInstance
  245. },
  246. // PGM_NLA_RESERVED (13)
  247. { 0, 0,
  248. "NLA RESERVED",
  249. "NLA RESERVED",
  250. PROP_TYPE_BYTESWAPPED_WORD,
  251. PROP_QUAL_NONE,
  252. NULL,
  253. PGM_FMT_STR_SIZE,
  254. FormatPropertyInstance
  255. },
  256. // PGM_NLA_IP (14)
  257. { 0, 0,
  258. "NLA ADDRESS",
  259. "NLA ADDRESS",
  260. PROP_TYPE_IP_ADDRESS,
  261. PROP_QUAL_NONE,
  262. NULL,
  263. PGM_FMT_STR_SIZE,
  264. FormatPropertyInstance
  265. },
  266. // PGM_OPTIONS (15)
  267. { 0, 0,
  268. "Options",
  269. "Options of PGM Packet",
  270. PROP_TYPE_BYTE,
  271. PROP_QUAL_NONE,
  272. NULL,
  273. PGM_FMT_STR_SIZE,
  274. FormatPropertyInstance
  275. },
  276. // PGM_OPTIONS_FLAGS (16)
  277. { 0, 0,
  278. "Options Flags",
  279. "Options Flags",
  280. PROP_TYPE_BYTE,
  281. PROP_QUAL_FLAGS,
  282. &PGMHeaderOptionsSET,
  283. PGM_FMT_STR_SIZE*4,
  284. FormatPropertyInstance
  285. },
  286. // PGM_HEADER_OPTIONS (17)
  287. { 0, 0,
  288. "Pgm Header Options",
  289. "Pgm Header Options",
  290. PROP_TYPE_SUMMARY,
  291. PROP_QUAL_NONE,
  292. NULL,
  293. PGM_FMT_STR_SIZE,
  294. FormatPropertyInstance
  295. },
  296. // PGM_OPTION_TYPE_NAK_SEQ (18)
  297. { 0, 0,
  298. "Nak / Ncf Sequences",
  299. "Nak / Ncf Sequences",
  300. PROP_TYPE_SUMMARY,
  301. PROP_QUAL_NONE,
  302. NULL,
  303. PGM_FMT_STR_SIZE,
  304. FormatPropertyInstance
  305. },
  306. // PGM_OPTION_TYPE_FRAGMENT (19)
  307. { 0, 0,
  308. "Message Fragment",
  309. "Message Fragment",
  310. PROP_TYPE_SUMMARY,
  311. PROP_QUAL_NONE,
  312. NULL,
  313. PGM_FMT_STR_SIZE,
  314. FormatPropertyInstance
  315. },
  316. // PGM_OPTION_TYPE_LATE_JOINER (20)
  317. { 0, 0,
  318. "Late Joiner",
  319. "Late Joiner",
  320. PROP_TYPE_SUMMARY,
  321. PROP_QUAL_NONE,
  322. NULL,
  323. PGM_FMT_STR_SIZE,
  324. FormatPropertyInstance
  325. },
  326. // PGM_OPTION_TYPE_SYN (21)
  327. { 0, 0,
  328. "Session SYN",
  329. "Session SYN",
  330. PROP_TYPE_SUMMARY,
  331. PROP_QUAL_NONE,
  332. NULL,
  333. PGM_FMT_STR_SIZE,
  334. FormatPropertyInstance
  335. },
  336. // PGM_OPTION_TYPE_FIN (22)
  337. { 0, 0,
  338. "Session FIN",
  339. "Session FIN",
  340. PROP_TYPE_SUMMARY,
  341. PROP_QUAL_NONE,
  342. NULL,
  343. PGM_FMT_STR_SIZE,
  344. FormatPropertyInstance
  345. },
  346. // PGM_OPTION_TYPE_RST (23)
  347. { 0, 0,
  348. "Session Reset",
  349. "Session Reset",
  350. PROP_TYPE_SUMMARY,
  351. PROP_QUAL_NONE,
  352. NULL,
  353. PGM_FMT_STR_SIZE,
  354. FormatPropertyInstance
  355. },
  356. // PGM_OPTION_TYPE_PARITY_PRM (24)
  357. { 0, 0,
  358. "Parity Parameters",
  359. "Parity Parameters",
  360. PROP_TYPE_SUMMARY,
  361. PROP_QUAL_NONE,
  362. NULL,
  363. PGM_FMT_STR_SIZE,
  364. FormatPropertyInstance
  365. },
  366. // PGM_OPTION_TYPE_PARITY_GRP (25)
  367. { 0, 0,
  368. "Parity Group Option Present",
  369. "Parity Group Option Present",
  370. PROP_TYPE_SUMMARY,
  371. PROP_QUAL_NONE,
  372. NULL,
  373. PGM_FMT_STR_SIZE,
  374. FormatPropertyInstance
  375. },
  376. // PGM_OPTION_TYPE_PARITY_TGSIZE (26)
  377. { 0, 0,
  378. "Parity Current TG Size Option Present",
  379. "Parity Current TG Size Option Present",
  380. PROP_TYPE_SUMMARY,
  381. PROP_QUAL_NONE,
  382. NULL,
  383. PGM_FMT_STR_SIZE,
  384. FormatPropertyInstance
  385. },
  386. // PGM_OPTIONS_FIELD_LENGTH (27)
  387. { 0, 0,
  388. "Options Length",
  389. "Options Length",
  390. PROP_TYPE_BYTESWAPPED_WORD,
  391. PROP_QUAL_NONE,
  392. NULL,
  393. PGM_FMT_STR_SIZE,
  394. FormatPropertyInstance
  395. },
  396. // PGM_OPTIONS_NAK_SEQ (28)
  397. { 0, 0,
  398. "Nak Sequence",
  399. "Nak Sequence",
  400. PROP_TYPE_BYTESWAPPED_DWORD,
  401. PROP_QUAL_NONE,
  402. NULL,
  403. PGM_FMT_STR_SIZE,
  404. FormatPropertyInstance
  405. },
  406. // PGM_OPTIONS_MESSAGE_FIRST_SEQUENCE (29)
  407. { 0, 0,
  408. "Message First Sequence",
  409. "Message First Sequence",
  410. PROP_TYPE_BYTESWAPPED_DWORD,
  411. PROP_QUAL_NONE,
  412. NULL,
  413. PGM_FMT_STR_SIZE,
  414. FormatPropertyInstance
  415. },
  416. // PGM_OPTIONS_MESSAGE_OFFSET (30)
  417. { 0, 0,
  418. "Message Offset",
  419. "Message Offset",
  420. PROP_TYPE_BYTESWAPPED_DWORD,
  421. PROP_QUAL_NONE,
  422. NULL,
  423. PGM_FMT_STR_SIZE,
  424. FormatPropertyInstance
  425. },
  426. // PGM_OPTIONS_MESSAGE_LENGTH (31)
  427. { 0, 0,
  428. "Message Length",
  429. "Message Length",
  430. PROP_TYPE_BYTESWAPPED_DWORD,
  431. PROP_QUAL_NONE,
  432. NULL,
  433. PGM_FMT_STR_SIZE,
  434. FormatPropertyInstance
  435. },
  436. // PGM_OPTIONS_LATE_JOINER (32)
  437. { 0, 0,
  438. "Late Joiner Sequence",
  439. "Late Joiner Sequence",
  440. PROP_TYPE_BYTESWAPPED_DWORD,
  441. PROP_QUAL_NONE,
  442. NULL,
  443. PGM_FMT_STR_SIZE,
  444. FormatPropertyInstance
  445. },
  446. // PGM_OPTIONS_PARITY_OPT (33)
  447. { 0, 0,
  448. "Parity Flags",
  449. "Parity Flags",
  450. PROP_TYPE_BYTE,
  451. PROP_QUAL_FLAGS,
  452. &PGMParityOptionsSET,
  453. PGM_FMT_STR_SIZE,
  454. FormatPropertyInstance
  455. },
  456. // PGM_OPTIONS_PARITY_PRM_GRP_SZ (34)
  457. { 0, 0,
  458. "Parity Group Size",
  459. "Parity Group Size",
  460. PROP_TYPE_BYTESWAPPED_DWORD,
  461. PROP_QUAL_NONE,
  462. NULL,
  463. PGM_FMT_STR_SIZE,
  464. FormatPropertyInstance
  465. },
  466. // PGM_OPTIONS_PARITY_GRP (35)
  467. { 0, 0,
  468. "Parity Group Number",
  469. "Parity Group Number",
  470. PROP_TYPE_BYTESWAPPED_DWORD,
  471. PROP_QUAL_NONE,
  472. NULL,
  473. PGM_FMT_STR_SIZE,
  474. FormatPropertyInstance
  475. },
  476. // PGM_OPTIONS_PARITY_TG_SZ (36)
  477. { 0, 0,
  478. "Parity TG Size",
  479. "Parity TG Size",
  480. PROP_TYPE_BYTESWAPPED_DWORD,
  481. PROP_QUAL_NONE,
  482. NULL,
  483. PGM_FMT_STR_SIZE,
  484. FormatPropertyInstance
  485. },
  486. // PGM_DATA (37)
  487. { 0,0,
  488. "Data",
  489. "Data contained in PGM packet",
  490. PROP_TYPE_RAW_DATA,
  491. PROP_QUAL_NONE,
  492. NULL,
  493. PGM_FMT_STR_SIZE,
  494. FormatPropertyInstance },
  495. };
  496. //====================================================================
  497. //Number of entries in the property table above
  498. //====================================================================
  499. DWORD nNumPGMProps = (sizeof(PGMPropertyTable)/sizeof(PROPERTYINFO));
  500. //============================================================================
  501. //
  502. // PGM_LoadParser - Tells Netmon which protocol precedes and follows PGM
  503. //
  504. // Modification history: June 30, 1999
  505. //
  506. // Madhurima Pawar 08/04/00 Created
  507. //============================================================================
  508. DWORD PGM_LoadParser(PPF_PARSERINFO pParserInfo)
  509. {
  510. DWORD NumberOfHandOffSets=1;
  511. //
  512. //This information is visible when the parser is selected in NetMon
  513. //
  514. wsprintf( pParserInfo->szProtocolName, "PGM" );
  515. wsprintf( pParserInfo->szComment, "Pragmatic General Multicast (PGM)" );
  516. wsprintf( pParserInfo->szHelpFile, "");
  517. //
  518. //Allocate memory for the handoffset and its two entries
  519. //
  520. pParserInfo->pWhoHandsOffToMe=(PPF_HANDOFFSET)
  521. HeapAlloc (GetProcessHeap(),
  522. HEAP_ZERO_MEMORY,
  523. sizeof (PF_HANDOFFSET) +
  524. sizeof (PF_HANDOFFENTRY) * (NumberOfHandOffSets));
  525. if(NULL==pParserInfo->pWhoHandsOffToMe)
  526. {
  527. //
  528. //Unable to create handoffset
  529. //
  530. return 1;
  531. }
  532. pParserInfo->pWhoHandsOffToMe->nEntries=NumberOfHandOffSets;
  533. //
  534. //Indicate the port that belong to PGM.
  535. //
  536. wsprintf (pParserInfo->pWhoHandsOffToMe->Entry[0].szIniFile, "TCPIP.INI");
  537. wsprintf (pParserInfo->pWhoHandsOffToMe->Entry[0].szIniSection, "IP_HandoffSet");
  538. wsprintf (pParserInfo->pWhoHandsOffToMe->Entry[0].szProtocol, "PGM");
  539. pParserInfo->pWhoHandsOffToMe->Entry[0].dwHandOffValue = PGM_PROTOCOL_NUMBER;
  540. pParserInfo->pWhoHandsOffToMe->Entry[0].ValueFormatBase = HANDOFF_VALUE_FORMAT_BASE_DECIMAL;
  541. return 0;
  542. }
  543. //============================================================================
  544. // Function: ParserAutoInstallInfo
  545. //
  546. // Description: Installs the parser into NetMon. Sets up the Handoff set
  547. // The handoffset indicates which protocol hands of to the parser and
  548. // who the parser hands of to.
  549. //
  550. //
  551. // Modification History
  552. //
  553. // Madhurima Pawar 08/04/00 Created
  554. //=============================================================================
  555. PPF_PARSERDLLINFO WINAPI ParserAutoInstallInfo()
  556. {
  557. PPF_PARSERDLLINFO pParserDllInfo;
  558. DWORD NumProtocols, Error;
  559. //The number of protocols in this parser is 1
  560. NumProtocols = 1;
  561. //Allocate memory for parser info:
  562. pParserDllInfo = (PPF_PARSERDLLINFO) HeapAlloc (GetProcessHeap(),
  563. HEAP_ZERO_MEMORY,
  564. sizeof (PF_PARSERDLLINFO) +
  565. (NumProtocols) * sizeof (PF_PARSERINFO));
  566. //Failed to allocate memory
  567. if( pParserDllInfo == NULL)
  568. {
  569. //
  570. //Unable to allocate memory
  571. //
  572. return NULL;
  573. }
  574. // fill in the parser DLL info
  575. pParserDllInfo->nParsers = NumProtocols;
  576. // fill in the individual parser infos...
  577. Error = PGM_LoadParser (&(pParserDllInfo->ParserInfo[0]));
  578. if(Error)
  579. {
  580. //
  581. //Unable to allocate memory
  582. //
  583. return(NULL);
  584. }
  585. //Return the parser information to netmon
  586. return (pParserDllInfo);
  587. }
  588. //============================================================================
  589. // Function: DLLEntry
  590. //
  591. // Description: Registers the parser with Netmon and creates the PGM
  592. // Properties table.
  593. //
  594. // Modification History
  595. //
  596. // Madhurima Pawar 08/04/00 Created
  597. //=============================================================================
  598. BOOL WINAPI DLLEntry( HANDLE hInstance, ULONG Command, LPVOID Reserved)
  599. {
  600. // what type of call is this
  601. switch( Command )
  602. {
  603. case DLL_PROCESS_ATTACH:
  604. // are we loading for the first time?
  605. if (PGMAttached == 0)
  606. {
  607. // the first time in we need to tell the kernel
  608. // about ourselves
  609. //Create PGM db it PGM added to Parser
  610. hPGM = CreateProtocol ("PGM", &PGMEntryPoints, ENTRYPOINTS_SIZE);
  611. }
  612. PGMAttached++;
  613. break;
  614. case DLL_PROCESS_DETACH:
  615. // are we detaching our last instance?
  616. PGMAttached--;
  617. if( PGMAttached == 0 )
  618. {
  619. // last guy out needs to clean up
  620. DestroyProtocol( hPGM);
  621. }
  622. break;
  623. }
  624. // Netmon parsers ALWAYS return TRUE.
  625. return TRUE;
  626. }
  627. //============================================================================
  628. // Function: PGM_Register
  629. //
  630. // Description: Create our property database and handoff sets.
  631. //
  632. // Modification History
  633. //
  634. // Madhurima Pawar 08/04/00 Created
  635. //============================================================================
  636. VOID BHAPI PGM_Register( HPROTOCOL hPGM)
  637. {
  638. WORD i;
  639. //
  640. // tell the kernel to make reserve some space for our property table
  641. //
  642. CreatePropertyDatabase (hPGM, nNumPGMProps);
  643. //
  644. // add our properties to the kernel's database
  645. //
  646. for (i = 0; i < nNumPGMProps; i++)
  647. {
  648. AddProperty (hPGM, &PGMPropertyTable[i]);
  649. }
  650. }
  651. //============================================================================
  652. // Function: PGM_Deregister
  653. //
  654. // Description: Destroy our property database and handoff set
  655. //
  656. // Modification History
  657. //
  658. // Madhurima Pawar 08/04/00 Created
  659. //============================================================================
  660. VOID WINAPI PGM_Deregister( HPROTOCOL hPGM)
  661. {
  662. // tell the kernel that it may now free our database
  663. DestroyPropertyDatabase (hPGM);
  664. }
  665. //============================================================================
  666. // Function: PGM_RecognizeFrame
  667. //
  668. // Description: Determine whether we exist in the frame at the spot
  669. // indicated. We also indicate who (if anyone) follows us
  670. // and how much of the frame we claim.
  671. //
  672. //============================================================================
  673. LPBYTE BHAPI PGM_RecognizeFrame( HFRAME hFrame,
  674. LPBYTE pMacFrame,
  675. LPBYTE pPGMFrame,
  676. DWORD MacType,
  677. DWORD BytesLeft,
  678. HPROTOCOL hPrevProtocol,
  679. DWORD nPrevProtOffset,
  680. LPDWORD pProtocolStatus,
  681. LPHPROTOCOL phNextProtocol,
  682. PDWORD_PTR InstData)
  683. {
  684. //
  685. // Since we do not know of any protocol currently on top of Pgm,
  686. // we do not need to do much here.
  687. //
  688. #if 0
  689. PPGM_COMMON_HDR pPGMHdr = (PPGM_COMMON_HDR) pPGMFrame;
  690. SPM_PACKET_HEADER *pSpm = (SPM_PACKET_HEADER *) pPGMFrame;
  691. DATA_PACKET_HEADER *pData = (DATA_PACKET_HEADER *) pPGMFrame;
  692. NAK_NCF_PACKET_HEADER *pNakNcf = (NAK_NCF_PACKET_HEADER *) pPGMFrame;
  693. DWORD BytesRequired = sizeof (PGM_COMMON_HDR);
  694. BYTE PacketType;
  695. tPACKET_OPTION_LENGTH UNALIGNED *pPacketExtension = NULL;
  696. // do we have the minimum header
  697. if (BytesLeft < BytesRequired)
  698. {
  699. //
  700. // This not a valid Pgm frame
  701. //
  702. *pProtocolStatus = PROTOCOL_STATUS_NOT_RECOGNIZED;
  703. return NULL;
  704. }
  705. PacketType = pPGMHdr->Type & 0x0f;
  706. switch (PacketType)
  707. {
  708. case (PACKET_TYPE_SPM):
  709. {
  710. BytesRequired = sizeof (SPM_PACKET_HEADER);
  711. pPacketExtension = (tPACKET_OPTION_LENGTH UNALIGNED *) (pSpm + 1);
  712. break;
  713. }
  714. case (PACKET_TYPE_ODATA):
  715. case (PACKET_TYPE_RDATA):
  716. {
  717. BytesRequired = sizeof (DATA_PACKET_HEADER);
  718. pPacketExtension = (tPACKET_OPTION_LENGTH UNALIGNED *) (pData + 1);
  719. break;
  720. }
  721. case (PACKET_TYPE_NAK):
  722. case (PACKET_TYPE_NCF):
  723. {
  724. BytesTaken = sizeof (NAK_NCF_PACKET_HEADER);
  725. pPacketExtension = (tPACKET_OPTION_LENGTH UNALIGNED *) (pNakNcf + 1);
  726. break;
  727. }
  728. default:
  729. {
  730. //
  731. // This not a recognized Pgm frame
  732. //
  733. *pProtocolStatus = PROTOCOL_STATUS_NOT_RECOGNIZED;
  734. return NULL;
  735. }
  736. }
  737. if ((pPGMHdr->Options & PACKET_HEADER_OPTIONS_PRESENT) &&
  738. (BytesLeft >= BytesRequired + (sizeof(tPACKET_OPTION_LENGTH) + sizeof(tPACKET_OPTION_GENERIC))))
  739. {
  740. BytesRequired += pPacketExtension->TotalOptionsLength;
  741. }
  742. // do we have a complete header
  743. if (BytesLeft < BytesRequired)
  744. {
  745. //
  746. // This not a valid Pgm frame
  747. //
  748. *pProtocolStatus = PROTOCOL_STATUS_NOT_RECOGNIZED;
  749. return NULL;
  750. }
  751. if (BytesLeft <= BytesRequired)
  752. {
  753. // No protocol follows us so claim whole packet
  754. *pProtocolStatus = PROTOCOL_STATUS_CLAIMED;
  755. return NULL;
  756. }
  757. *pProtocolStatus = PROTOCOL_STATUS_RECOGNIZED;
  758. return NULL;
  759. #endif // 0
  760. // this is a Pgm frame but we don't know the next protocol
  761. *pProtocolStatus = PROTOCOL_STATUS_CLAIMED;
  762. return NULL;
  763. }
  764. //============================================================================
  765. //============================================================================
  766. DWORD
  767. ProcessOptions(
  768. HFRAME hFrame,
  769. tPACKET_OPTION_LENGTH UNALIGNED *pPacketExtension,
  770. DWORD BytesLeft,
  771. BYTE PacketType
  772. )
  773. {
  774. tPACKET_OPTION_GENERIC UNALIGNED *pOptionHeader;
  775. USHORT TotalOptionsLength;
  776. DWORD BytesProcessed = 0;
  777. UCHAR i;
  778. if ((BytesLeft < ((sizeof(tPACKET_OPTION_LENGTH) + sizeof(tPACKET_OPTION_GENERIC)))) || // Ext+opt
  779. (pPacketExtension->Type != PACKET_OPTION_LENGTH) ||
  780. (pPacketExtension->Length != 4) ||
  781. (BytesLeft < (TotalOptionsLength = ntohs (pPacketExtension->TotalOptionsLength)))) // Verify length
  782. {
  783. //
  784. // Need to get at least our header from transport!
  785. //
  786. return (BytesProcessed);
  787. }
  788. AttachPropertyInstance (hFrame,
  789. PGMPropertyTable[PGM_HEADER_OPTIONS].hProperty,
  790. TotalOptionsLength,
  791. pPacketExtension,
  792. 0,1,0); // HELPID, Level, Errorflag
  793. AttachPropertyInstance (hFrame,
  794. PGMPropertyTable[PGM_OPTIONS_FIELD_LENGTH].hProperty,
  795. sizeof (WORD),
  796. &pPacketExtension->TotalOptionsLength,
  797. 0,2,0); // HELPID, Level, Errorflag
  798. pOptionHeader = (tPACKET_OPTION_GENERIC UNALIGNED *) (pPacketExtension + 1);
  799. BytesLeft -= PACKET_OPTION_LENGTH;
  800. BytesProcessed += PGM_PACKET_EXTENSION_LENGTH;
  801. do
  802. {
  803. if (pOptionHeader->Length > BytesLeft)
  804. {
  805. return (BytesProcessed);
  806. }
  807. switch (pOptionHeader->OptionType & ~PACKET_OPTION_TYPE_END_BIT)
  808. {
  809. case (PACKET_OPTION_NAK_LIST):
  810. {
  811. if (((PacketType != PACKET_TYPE_NAK) &&
  812. (PacketType != PACKET_TYPE_NCF) &&
  813. (PacketType != PACKET_TYPE_NNAK)) ||
  814. (pOptionHeader->Length < PGM_PACKET_OPT_MIN_NAK_LIST_LENGTH) ||
  815. (pOptionHeader->Length > PGM_PACKET_OPT_MAX_NAK_LIST_LENGTH))
  816. {
  817. return (BytesProcessed);
  818. }
  819. AttachPropertyInstance (hFrame,
  820. PGMPropertyTable[PGM_OPTION_TYPE_NAK_SEQ].hProperty,
  821. pOptionHeader->Length,
  822. pOptionHeader,
  823. 0,2,0); // HELPID, Level, Errorflag
  824. for (i=0; i < (pOptionHeader->Length-4)/4; i++)
  825. {
  826. AttachPropertyInstance (hFrame,
  827. PGMPropertyTable[PGM_OPTIONS_NAK_SEQ].hProperty,
  828. sizeof (DWORD),
  829. &((PULONG)(pOptionHeader+1))[i],
  830. 0,3,0); // HELPID, Level, Errorflag
  831. }
  832. break;
  833. }
  834. case (PACKET_OPTION_FRAGMENT):
  835. {
  836. if (pOptionHeader->Length != PGM_PACKET_OPT_FRAGMENT_LENGTH)
  837. {
  838. return (BytesProcessed);
  839. }
  840. AttachPropertyInstance (hFrame,
  841. PGMPropertyTable[PGM_OPTION_TYPE_FRAGMENT].hProperty,
  842. PGM_PACKET_OPT_FRAGMENT_LENGTH,
  843. pOptionHeader,
  844. 0,2,0); // HELPID, Level, Errorflag
  845. AttachPropertyInstance (hFrame,
  846. PGMPropertyTable[PGM_OPTIONS_MESSAGE_FIRST_SEQUENCE].hProperty,
  847. sizeof (DWORD),
  848. &((PULONG)(pOptionHeader+1))[0],
  849. 0,3,0); // HELPID, Level, Errorflag
  850. AttachPropertyInstance (hFrame,
  851. PGMPropertyTable[PGM_OPTIONS_MESSAGE_OFFSET].hProperty,
  852. sizeof (DWORD),
  853. &((PULONG)(pOptionHeader+1))[1],
  854. 0,3,0); // HELPID, Level, Errorflag
  855. AttachPropertyInstance (hFrame,
  856. PGMPropertyTable[PGM_OPTIONS_MESSAGE_LENGTH].hProperty,
  857. sizeof (DWORD),
  858. &((PULONG)(pOptionHeader+1))[2],
  859. 0,3,0); // HELPID, Level, Errorflag
  860. break;
  861. }
  862. case (PACKET_OPTION_JOIN):
  863. {
  864. if (pOptionHeader->Length != PGM_PACKET_OPT_JOIN_LENGTH)
  865. {
  866. return (BytesProcessed);
  867. }
  868. AttachPropertyInstance (hFrame,
  869. PGMPropertyTable[PGM_OPTION_TYPE_LATE_JOINER].hProperty,
  870. PGM_PACKET_OPT_JOIN_LENGTH,
  871. pOptionHeader,
  872. 0,2,0); // HELPID, Level, Errorflag
  873. AttachPropertyInstance (hFrame,
  874. PGMPropertyTable[PGM_OPTIONS_LATE_JOINER].hProperty,
  875. sizeof (DWORD),
  876. &((PULONG)(pOptionHeader+1))[0],
  877. 0,3,0); // HELPID, Level, Errorflag
  878. break;
  879. }
  880. case (PACKET_OPTION_SYN):
  881. {
  882. if (pOptionHeader->Length != PGM_PACKET_OPT_SYN_LENGTH)
  883. {
  884. return (BytesProcessed);
  885. }
  886. AttachPropertyInstance (hFrame,
  887. PGMPropertyTable[PGM_OPTION_TYPE_SYN].hProperty,
  888. PGM_PACKET_OPT_SYN_LENGTH,
  889. pOptionHeader,
  890. 0, 2, 0);
  891. break;
  892. }
  893. case (PACKET_OPTION_FIN):
  894. {
  895. if (pOptionHeader->Length != PGM_PACKET_OPT_FIN_LENGTH)
  896. {
  897. return (BytesProcessed);
  898. }
  899. AttachPropertyInstance (hFrame,
  900. PGMPropertyTable[PGM_OPTION_TYPE_FIN].hProperty,
  901. PGM_PACKET_OPT_FIN_LENGTH,
  902. pOptionHeader,
  903. 0, 2, 0);
  904. break;
  905. }
  906. case (PACKET_OPTION_RST):
  907. {
  908. if (pOptionHeader->Length != PGM_PACKET_OPT_RST_LENGTH)
  909. {
  910. return (BytesProcessed);
  911. }
  912. AttachPropertyInstance (hFrame,
  913. PGMPropertyTable[PGM_OPTION_TYPE_RST].hProperty,
  914. PGM_PACKET_OPT_RST_LENGTH,
  915. pOptionHeader,
  916. 0, 2, 0);
  917. break;
  918. }
  919. //
  920. // FEC options
  921. //
  922. case (PACKET_OPTION_PARITY_PRM):
  923. {
  924. if (pOptionHeader->Length != PGM_PACKET_OPT_PARITY_PRM_LENGTH)
  925. {
  926. return (BytesProcessed);
  927. }
  928. AttachPropertyInstance (hFrame,
  929. PGMPropertyTable[PGM_OPTION_TYPE_PARITY_PRM].hProperty,
  930. PGM_PACKET_OPT_PARITY_PRM_LENGTH,
  931. pOptionHeader,
  932. 0, 2, 0);
  933. AttachPropertyInstance (hFrame,
  934. PGMPropertyTable[PGM_OPTIONS_PARITY_OPT].hProperty,
  935. sizeof (BYTE),
  936. &pOptionHeader->OptionSpecific,
  937. 0,3,0); // HELPID, Level, Errorflag
  938. AttachPropertyInstance (hFrame,
  939. PGMPropertyTable[PGM_OPTIONS_PARITY_PRM_GRP_SZ].hProperty,
  940. sizeof (DWORD),
  941. &((PULONG)(pOptionHeader+1))[0],
  942. 0,3,0); // HELPID, Level, Errorflag
  943. break;
  944. }
  945. case (PACKET_OPTION_PARITY_GRP):
  946. {
  947. if (pOptionHeader->Length != PGM_PACKET_OPT_PARITY_GRP_LENGTH)
  948. {
  949. return (BytesProcessed);
  950. }
  951. AttachPropertyInstance (hFrame,
  952. PGMPropertyTable[PGM_OPTION_TYPE_PARITY_GRP].hProperty,
  953. PGM_PACKET_OPT_PARITY_GRP_LENGTH,
  954. pOptionHeader,
  955. 0, 2, 0);
  956. AttachPropertyInstance (hFrame,
  957. PGMPropertyTable[PGM_OPTIONS_PARITY_GRP].hProperty,
  958. sizeof (DWORD),
  959. &((PULONG)(pOptionHeader+1))[0],
  960. 0,3,0); // HELPID, Level, Errorflag
  961. break;
  962. }
  963. case (PACKET_OPTION_CURR_TGSIZE):
  964. {
  965. if (pOptionHeader->Length != PGM_PACKET_OPT_PARITY_CUR_TGSIZE_LENGTH)
  966. {
  967. return (BytesProcessed);
  968. }
  969. AttachPropertyInstance (hFrame,
  970. PGMPropertyTable[PGM_OPTION_TYPE_PARITY_TGSIZE].hProperty,
  971. PGM_PACKET_OPT_PARITY_CUR_TGSIZE_LENGTH,
  972. pOptionHeader,
  973. 0, 2, 0);
  974. AttachPropertyInstance (hFrame,
  975. PGMPropertyTable[PGM_OPTIONS_PARITY_TG_SZ].hProperty,
  976. sizeof (DWORD),
  977. &((PULONG)(pOptionHeader+1))[0],
  978. 0,3,0); // HELPID, Level, Errorflag
  979. break;
  980. }
  981. default:
  982. {
  983. return (BytesProcessed);
  984. }
  985. }
  986. BytesLeft -= pOptionHeader->Length;
  987. BytesProcessed += pOptionHeader->Length;
  988. if (pOptionHeader->OptionType & PACKET_OPTION_TYPE_END_BIT)
  989. {
  990. break;
  991. }
  992. pOptionHeader = (tPACKET_OPTION_GENERIC UNALIGNED *)
  993. (((UCHAR *) pOptionHeader) + pOptionHeader->Length);
  994. } while (BytesLeft >= sizeof(tPACKET_OPTION_GENERIC));
  995. return (BytesProcessed);
  996. }
  997. VOID
  998. PGM_FmtNLA(
  999. HFRAME hFrame,
  1000. NLA *pNLA,
  1001. BOOL fIsSourceNLA
  1002. )
  1003. {
  1004. //The type of the PGM frame
  1005. if (fIsSourceNLA)
  1006. {
  1007. AttachPropertyInstance (hFrame,
  1008. PGMPropertyTable[PGM_NLA_TYPE_SOURCE].hProperty,
  1009. sizeof (NLA),
  1010. pNLA,
  1011. 0,1,0); // HELPID, Level, Errorflag
  1012. }
  1013. else
  1014. {
  1015. AttachPropertyInstance (hFrame,
  1016. PGMPropertyTable[PGM_NLA_TYPE_MCAST_GROUP].hProperty,
  1017. sizeof (NLA),
  1018. pNLA,
  1019. 0,1,0); // HELPID, Level, Errorflag
  1020. }
  1021. AttachPropertyInstance (hFrame,
  1022. PGMPropertyTable[PGM_NLA_AFI].hProperty,
  1023. sizeof (WORD),
  1024. &pNLA->NLA_AFI,
  1025. 0,2,0); // HELPID, Level, Errorflag
  1026. AttachPropertyInstance (hFrame,
  1027. PGMPropertyTable[PGM_NLA_RESERVED].hProperty,
  1028. sizeof (WORD),
  1029. &pNLA->Reserved,
  1030. 0,2,0); // HELPID, Level, Errorflag
  1031. AttachPropertyInstance (hFrame,
  1032. PGMPropertyTable[PGM_NLA_IP].hProperty,
  1033. sizeof (DWORD),
  1034. &pNLA->IpAddress,
  1035. 0,2,0); // HELPID, Level, Errorflag
  1036. }
  1037. //============================================================================
  1038. // Function: PGM_AttachProperties
  1039. //
  1040. // Description: Indicate where in the frame each of our properties live.
  1041. //
  1042. // Modification History
  1043. //
  1044. // Madhurima Pawar 08/04/00 Created
  1045. //============================================================================
  1046. LPBYTE BHAPI PGM_AttachProperties( HFRAME hFrame,
  1047. LPBYTE pMacFrame,
  1048. LPBYTE pPGMFrame,
  1049. DWORD MacType,
  1050. DWORD BytesLeft,
  1051. HPROTOCOL hPrevProtocol,
  1052. DWORD nPrevProtOffset,
  1053. DWORD_PTR InstData)
  1054. {
  1055. PPGM_COMMON_HDR pPGMHdr = (PPGM_COMMON_HDR)pPGMFrame;
  1056. BYTE PacketType;
  1057. USHORT TSIPort;
  1058. UCHAR pGlobalSrcId [SOURCE_ID_LENGTH*2+1+sizeof(USHORT)*2+1];
  1059. SPM_PACKET_HEADER *pSpm = (SPM_PACKET_HEADER *) pPGMHdr;
  1060. DATA_PACKET_HEADER *pData = (DATA_PACKET_HEADER *) pPGMHdr;
  1061. NAK_NCF_PACKET_HEADER *pNakNcf = (NAK_NCF_PACKET_HEADER *) pPGMHdr;
  1062. tPACKET_OPTION_LENGTH *pOptionsHeader = NULL;
  1063. DWORD BytesTaken = 0;
  1064. DWORD OptionsLength = 0;
  1065. PUCHAR pPgmData;
  1066. PacketType = pPGMHdr->Type & 0x0f;
  1067. if ((PacketType == PACKET_TYPE_NAK) ||
  1068. (PacketType == PACKET_TYPE_NNAK) ||
  1069. (PacketType == PACKET_TYPE_SPMR) ||
  1070. (PacketType == PACKET_TYPE_POLR))
  1071. {
  1072. TSIPort = ntohs (pPGMHdr->DestPort);
  1073. }
  1074. else
  1075. {
  1076. TSIPort = ntohs (pPGMHdr->SrcPort);
  1077. }
  1078. wsprintf (pGlobalSrcId, "%02X%02X%02X%02X%02X%02X.%04X",
  1079. pPGMHdr->gSourceId[0],
  1080. pPGMHdr->gSourceId[1],
  1081. pPGMHdr->gSourceId[2],
  1082. pPGMHdr->gSourceId[3],
  1083. pPGMHdr->gSourceId[4],
  1084. pPGMHdr->gSourceId[5],
  1085. TSIPort);
  1086. //Add the PGM header information
  1087. //PGM summary information transaction ID and Message type
  1088. //Has a special formater PGM_FormatSummary
  1089. AttachPropertyInstance( hFrame,
  1090. PGMPropertyTable[PGM_SUMMARY].hProperty,
  1091. (WORD) BytesLeft,
  1092. (LPBYTE)pPGMFrame,
  1093. 0, 0, 0 );
  1094. //The source port of the PGM frame
  1095. AttachPropertyInstance (hFrame,
  1096. PGMPropertyTable[PGM_SOURCE_PORT].hProperty,
  1097. sizeof(WORD),
  1098. &pPGMHdr->SrcPort,
  1099. 0, 1, 0);
  1100. AttachPropertyInstance (hFrame,
  1101. PGMPropertyTable[PGM_DESTINATION_PORT].hProperty,
  1102. sizeof(WORD),
  1103. &pPGMHdr->DestPort,
  1104. 0, 1, 0);
  1105. //The type of the PGM frame
  1106. AttachPropertyInstanceEx( hFrame,
  1107. PGMPropertyTable[PGM_TYPE].hProperty,
  1108. sizeof(BYTE),
  1109. &pPGMHdr->Type,
  1110. sizeof(BYTE),
  1111. &PacketType,
  1112. 0, 1, 0);
  1113. AttachPropertyInstance (hFrame,
  1114. PGMPropertyTable[PGM_OPTIONS].hProperty,
  1115. sizeof (BYTE),
  1116. &pPGMHdr->Options,
  1117. 0,1,0); // HELPID, Level, Errorflag
  1118. AttachPropertyInstance (hFrame,
  1119. PGMPropertyTable[PGM_OPTIONS_FLAGS].hProperty,
  1120. sizeof (BYTE),
  1121. &pPGMHdr->Options,
  1122. 0,2,0); // HELPID, Level, Errorflag
  1123. //The checksum of the PGM frame
  1124. AttachPropertyInstance( hFrame,
  1125. PGMPropertyTable[PGM_CHECKSUM].hProperty,
  1126. sizeof(WORD),
  1127. &(pPGMHdr->Checksum),
  1128. 0, 1, 0);
  1129. //The Global Session Id
  1130. AttachPropertyInstanceEx (hFrame,
  1131. PGMPropertyTable[PGM_GLOBAL_SOURCE_ID].hProperty,
  1132. SOURCE_ID_LENGTH,
  1133. pPGMHdr->gSourceId,
  1134. (SOURCE_ID_LENGTH*2+1+sizeof(USHORT)*2+1),
  1135. pGlobalSrcId,
  1136. 0, 1, 0);
  1137. //The source port of the PGM frame
  1138. AttachPropertyInstance( hFrame,
  1139. PGMPropertyTable[PGM_TSDU_LENGTH].hProperty,
  1140. sizeof(WORD),
  1141. &pPGMHdr->TSDULength,
  1142. 0, 1, 0);
  1143. switch (PacketType)
  1144. {
  1145. case (PACKET_TYPE_SPM):
  1146. {
  1147. // Spm Sequence Number
  1148. AttachPropertyInstance (hFrame,
  1149. PGMPropertyTable[PGM_SEQUENCE_NUMBER].hProperty,
  1150. sizeof(DWORD),
  1151. &pSpm->SpmSequenceNumber,
  1152. 0, 1, 0);
  1153. // Sender's trailing edge
  1154. AttachPropertyInstance (hFrame,
  1155. PGMPropertyTable[PGM_TRAILING_EDGE].hProperty,
  1156. sizeof(DWORD),
  1157. &pSpm->TrailingEdgeSeqNumber,
  1158. 0, 1, 0);
  1159. // Sender's trailing edge
  1160. AttachPropertyInstance (hFrame,
  1161. PGMPropertyTable[PGM_LEADING_EDGE].hProperty,
  1162. sizeof(DWORD),
  1163. &pSpm->LeadingEdgeSeqNumber,
  1164. 0, 1, 0);
  1165. PGM_FmtNLA (hFrame, &pSpm->PathNLA, TRUE);
  1166. BytesTaken = sizeof (SPM_PACKET_HEADER);
  1167. pOptionsHeader = (tPACKET_OPTION_LENGTH *) (pSpm + 1);
  1168. break;
  1169. }
  1170. case (PACKET_TYPE_ODATA):
  1171. case (PACKET_TYPE_RDATA):
  1172. {
  1173. // Sender's sequence number
  1174. AttachPropertyInstance (hFrame,
  1175. PGMPropertyTable[PGM_SEQUENCE_NUMBER].hProperty,
  1176. sizeof(DWORD),
  1177. &pData->DataSequenceNumber,
  1178. 0, 1, 0);
  1179. // Sender's trailing edge
  1180. AttachPropertyInstance (hFrame,
  1181. PGMPropertyTable[PGM_TRAILING_EDGE].hProperty,
  1182. sizeof(DWORD),
  1183. &pData->TrailingEdgeSequenceNumber,
  1184. 0, 1, 0);
  1185. BytesTaken = sizeof (DATA_PACKET_HEADER);
  1186. pOptionsHeader = (tPACKET_OPTION_LENGTH *) (pData + 1);
  1187. break;
  1188. }
  1189. case (PACKET_TYPE_NAK):
  1190. case (PACKET_TYPE_NCF):
  1191. {
  1192. AttachPropertyInstance (hFrame,
  1193. PGMPropertyTable[PGM_SEQUENCE_NUMBER].hProperty,
  1194. sizeof(DWORD),
  1195. &pNakNcf->RequestedSequenceNumber,
  1196. 0, 1, 0);
  1197. PGM_FmtNLA (hFrame, &pNakNcf->SourceNLA, TRUE);
  1198. PGM_FmtNLA (hFrame, &pNakNcf->MCastGroupNLA, FALSE);
  1199. BytesTaken = sizeof (NAK_NCF_PACKET_HEADER);
  1200. pOptionsHeader = (tPACKET_OPTION_LENGTH *) (pNakNcf + 1);
  1201. break;
  1202. }
  1203. default:
  1204. {
  1205. break;
  1206. }
  1207. }
  1208. if ((pPGMHdr->Options & PACKET_HEADER_OPTIONS_PRESENT) &&
  1209. (pOptionsHeader))
  1210. {
  1211. OptionsLength = ProcessOptions (hFrame, pOptionsHeader, (BytesLeft-BytesTaken), PacketType);
  1212. }
  1213. if (((PacketType == PACKET_TYPE_ODATA) ||
  1214. (PacketType == PACKET_TYPE_RDATA)) &&
  1215. (BytesLeft > (BytesTaken+OptionsLength)))
  1216. {
  1217. BytesLeft -= (BytesTaken+OptionsLength);
  1218. pPgmData = ((PUCHAR) pPGMHdr) + BytesTaken + OptionsLength;
  1219. AttachPropertyInstance (hFrame,
  1220. PGMPropertyTable[PGM_DATA].hProperty,
  1221. BytesLeft,
  1222. pPgmData,
  1223. 0,1,0); // HELPID, Level, Errorflag
  1224. }
  1225. //Always returns NULL
  1226. return NULL;
  1227. }
  1228. //============================================================================
  1229. // Function: PGM_FormatProperties
  1230. //
  1231. // Description: Format the given properties on the given frame.
  1232. //
  1233. // Modification History
  1234. //
  1235. // Madhurima Pawar 08/04/00 Created
  1236. //============================================================================
  1237. DWORD BHAPI PGM_FormatProperties( HFRAME hFrame,
  1238. LPBYTE pMacFrame,
  1239. LPBYTE pPGMFrame,
  1240. DWORD nPropertyInsts,
  1241. LPPROPERTYINST p)
  1242. {
  1243. // loop through the property instances
  1244. while( nPropertyInsts-- > 0)
  1245. {
  1246. // and call the formatter for each
  1247. ( (FORMAT)(p->lpPropertyInfo->InstanceData) )( p);
  1248. p++;
  1249. }
  1250. return NMERR_SUCCESS;
  1251. }
  1252. //*****************************************************************************
  1253. //
  1254. // Name: PGM_FmtSummary
  1255. //
  1256. // Description:
  1257. //
  1258. // Parameters: LPPROPERTYINST lpPropertyInst: pointer to property instance.
  1259. //
  1260. // Return Code: VOID.
  1261. //
  1262. // History:
  1263. // 10/15/2000 MAlam Created.
  1264. //
  1265. //*****************************************************************************
  1266. VOID WINAPIV
  1267. PGM_FmtSummary(
  1268. LPPROPERTYINST pPropertyInst
  1269. )
  1270. {
  1271. LPBYTE pReturnedString = pPropertyInst->szPropertyText;
  1272. PPGM_COMMON_HDR pPgmHeader = (PPGM_COMMON_HDR) (pPropertyInst->lpData);
  1273. SPM_PACKET_HEADER *pSpm = (SPM_PACKET_HEADER *) pPgmHeader;
  1274. DATA_PACKET_HEADER *pData = (DATA_PACKET_HEADER *) pPgmHeader;
  1275. NAK_NCF_PACKET_HEADER *pNakNcf = (NAK_NCF_PACKET_HEADER *) pPgmHeader;
  1276. UCHAR PacketType = pPgmHeader->Type & 0x0f;
  1277. UCHAR *szPacketDesc = NULL;
  1278. USHORT TSIPort;
  1279. if ((PacketType == PACKET_TYPE_NAK) ||
  1280. (PacketType == PACKET_TYPE_NNAK) ||
  1281. (PacketType == PACKET_TYPE_SPMR) ||
  1282. (PacketType == PACKET_TYPE_POLR))
  1283. {
  1284. TSIPort = ntohs (pPgmHeader->DestPort);
  1285. }
  1286. else
  1287. {
  1288. TSIPort = ntohs (pPgmHeader->SrcPort);
  1289. }
  1290. szPacketDesc = LookupByteSetString (&PGMTypesSET, PacketType);
  1291. wsprintf (pReturnedString,
  1292. "%s%s:",
  1293. szPacketDesc, (pPgmHeader->Options & PACKET_HEADER_OPTIONS_PARITY ? " (P)" : ""));
  1294. switch (PacketType)
  1295. {
  1296. case (PACKET_TYPE_SPM):
  1297. {
  1298. wsprintf (&pReturnedString [strlen(pReturnedString)],
  1299. " Seq: %d, Window: %d-%d",
  1300. ntohl (pSpm->SpmSequenceNumber), ntohl (pSpm->TrailingEdgeSeqNumber), ntohl (pSpm->LeadingEdgeSeqNumber));
  1301. break;
  1302. }
  1303. case (PACKET_TYPE_ODATA):
  1304. case (PACKET_TYPE_RDATA):
  1305. {
  1306. wsprintf (&pReturnedString [strlen(pReturnedString)],
  1307. " Seq: %d, Trail: %d, DataBytes: %d",
  1308. ntohl (pData->DataSequenceNumber), ntohl (pData->TrailingEdgeSequenceNumber),
  1309. ((ULONG) ntohs (pPgmHeader->TSDULength)));
  1310. break;
  1311. }
  1312. case (PACKET_TYPE_NAK):
  1313. case (PACKET_TYPE_NCF):
  1314. {
  1315. wsprintf (&pReturnedString [strlen(pReturnedString)],
  1316. " Seq: %d%s",
  1317. ntohl (pNakNcf->RequestedSequenceNumber),
  1318. (pPgmHeader->Options & PACKET_HEADER_OPTIONS_PRESENT ? " ..." : ""));
  1319. break;
  1320. }
  1321. default:
  1322. {
  1323. break;
  1324. }
  1325. }
  1326. wsprintf (&pReturnedString [strlen(pReturnedString)],
  1327. " TSIPort = %hu", TSIPort);
  1328. }