MMEShow.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * void MMEShow (void const * memory, size_t length, FILE *fp);
  11. *
  12. * mme.h
  13. *
  14. * print a HomePlug AV frame header on stdout in human readable
  15. * format;
  16. *
  17. *
  18. * Contributor(s):
  19. * Charles Maier <cmaier@qca.qualcomm.com>
  20. *
  21. *--------------------------------------------------------------------*/
  22. #ifndef MMESHOW_SOURCE
  23. #define MMESHOW_SOURCE
  24. #include <stdio.h>
  25. #include <stdint.h>
  26. #include "../tools/memory.h"
  27. #include "../tools/number.h"
  28. #include "../mme/mme.h"
  29. #ifndef ETHER_ADDR_LEN
  30. #define ETHER_ADDR_LEN 6 /* normally defined in ethernet.h or if_ether.h */
  31. #endif
  32. void MMEShow (void const * memory, size_t extent, FILE * fp)
  33. {
  34. char address [ETHER_ADDR_LEN * 3];
  35. struct message * message = (struct message *) (memory);
  36. fprintf (fp, "%s ", hexstream (address, sizeof (address), message->ethernet.ODA, sizeof (message->ethernet.ODA)));
  37. fprintf (fp, "%s ", hexstream (address, sizeof (address), message->ethernet.OSA, sizeof (message->ethernet.OSA)));
  38. fprintf (fp, "%04X ", ntohs (message->ethernet.MTYPE));
  39. if (ntohs (message->ethernet.MTYPE) == ETH_P_HPAV)
  40. {
  41. struct homeplug_hdr * homeplug = (struct homeplug_hdr *) (& message->content);
  42. uint16_t mmtype = LE16TOH (homeplug->MMTYPE);
  43. if (mmtype < MMTYPE_VS)
  44. {
  45. if (homeplug->MMV == 0x00)
  46. {
  47. struct homeplug_hdr * homeplug = (struct homeplug_hdr *) (& message->content);
  48. mmtype = LE16TOH (homeplug->MMTYPE);
  49. fprintf (fp, "%02X ", homeplug->MMV);
  50. fprintf (fp, "%04X ", mmtype);
  51. fprintf (fp, "%s.%s\n", MMEName (mmtype), MMEMode (mmtype));
  52. return;
  53. }
  54. if (homeplug->MMV == 0x01)
  55. {
  56. struct homeplug_fmi * homeplug = (struct homeplug_fmi *) (& message->content);
  57. mmtype = LE16TOH (homeplug->MMTYPE);
  58. fprintf (fp, "%02X ", homeplug->MMV);
  59. fprintf (fp, "%04X ", mmtype);
  60. fprintf (fp, "%02X ", homeplug->FMID);
  61. fprintf (fp, "%02X ", homeplug->FMSN);
  62. fprintf (fp, "%s.%s\n", MMEName (mmtype), MMEMode (mmtype));
  63. return;
  64. }
  65. }
  66. if (mmtype < MMTYPE_XX)
  67. {
  68. if (homeplug->MMV == 0x00)
  69. {
  70. struct qualcomm_hdr * qualcomm = (struct qualcomm_hdr *) (& message->content);
  71. mmtype = LE16TOH (qualcomm->MMTYPE);
  72. fprintf (fp, "%02X ", qualcomm->MMV);
  73. fprintf (fp, "%04X ", mmtype);
  74. fprintf (fp, "%s ", hexstring (address, sizeof (address), qualcomm->OUI, sizeof (qualcomm->OUI)));
  75. fprintf (fp, "%s.%s\n", MMEName (mmtype), MMEMode (mmtype));
  76. return;
  77. }
  78. if (homeplug->MMV == 0x01)
  79. {
  80. struct qualcomm_fmi * qualcomm = (struct qualcomm_fmi *) (& message->content);
  81. mmtype = LE16TOH (qualcomm->MMTYPE);
  82. fprintf (fp, "%02X ", qualcomm->MMV);
  83. fprintf (fp, "%04X ", mmtype);
  84. fprintf (fp, "%02X ", qualcomm->FMID);
  85. fprintf (fp, "%02X ", qualcomm->FMSN);
  86. fprintf (fp, "%s ", hexstring (address, sizeof (address), qualcomm->OUI, sizeof (qualcomm->OUI)));
  87. fprintf (fp, "%s.%s\n", MMEName (mmtype), MMEMode (mmtype));
  88. return;
  89. }
  90. }
  91. }
  92. fprintf (fp, "UNKNOWN_MESSAGE_TYPE\n");
  93. return;
  94. }
  95. #endif