Monitor.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed Monitor (struct plc * plc, signed colon, signed space);
  11. *
  12. * nda.h
  13. *
  14. * capture and print VS_SNIFFER indication messages from powerline
  15. * devices in sniffer mode which may be enabled and disabled using
  16. * a VS_SNIFFER request message;
  17. *
  18. *--------------------------------------------------------------------*/
  19. #ifndef MONITOR_SOURCE
  20. #define MONITOR_SOURCE
  21. #include "../nda/nda.h"
  22. #include "../plc/plc.h"
  23. signed Monitor (struct plc * plc, signed colon, signed space)
  24. {
  25. struct channel * channel = (struct channel *) (plc->channel);
  26. struct message * message = (struct message *) (plc->message);
  27. #ifndef __GNUC__
  28. #pragma pack (push,1)
  29. #endif
  30. struct __packed vs_sniffer_ind
  31. {
  32. struct ethernet_hdr ethernet;
  33. struct qualcomm_hdr qualcomm;
  34. uint8_t SNIFFTYPE;
  35. struct vs_sniffer_ind_data
  36. {
  37. uint8_t DIRECTION [1];
  38. uint8_t SYSTIME [8];
  39. uint8_t BEACONTIME [4];
  40. uint8_t FRAMECTRL [16];
  41. uint8_t BEACONBODY [136];
  42. }
  43. SNIFFERDATA;
  44. }
  45. * indicate = (struct vs_sniffer_ind *) (message);
  46. #ifndef __GNUC__
  47. #pragma pack (pop)
  48. #endif
  49. signed length;
  50. Request (plc, "Listening");
  51. while ((length = readpacket (channel, message, sizeof (* message))) >= 0)
  52. {
  53. if (! length)
  54. {
  55. continue;
  56. }
  57. if (ntohs (indicate->ethernet.MTYPE) != ETH_P_HPAV)
  58. {
  59. continue;
  60. }
  61. if (indicate->qualcomm.MMV != 0)
  62. {
  63. continue;
  64. }
  65. if (LE16TOH (indicate->qualcomm.MMTYPE) != (VS_SNIFFER | MMTYPE_IND))
  66. {
  67. continue;
  68. }
  69. #if 0
  70. /*
  71. * print sniffer data to stdout in binary only if stdout is not the console or a tty device.
  72. */
  73. if (! isatty (STDOUT_FILENO))
  74. {
  75. write (STDOUT_FILENO, & indicate->SNIFFERDATA, sizeof (indicate->SNIFFERDATA));
  76. continue;
  77. }
  78. #endif
  79. hexout (indicate->SNIFFERDATA.DIRECTION, sizeof (indicate->SNIFFERDATA.DIRECTION), colon, space, stdout);
  80. hexout (indicate->SNIFFERDATA.SYSTIME, sizeof (indicate->SNIFFERDATA.SYSTIME), colon, space, stdout);
  81. hexout (indicate->SNIFFERDATA.BEACONTIME, sizeof (indicate->SNIFFERDATA.BEACONTIME), colon, space, stdout);
  82. hexout (indicate->SNIFFERDATA.FRAMECTRL, sizeof (indicate->SNIFFERDATA.FRAMECTRL), colon, space, stdout);
  83. hexout (indicate->SNIFFERDATA.BEACONBODY, sizeof (indicate->SNIFFERDATA.BEACONBODY), colon, '\n', stdout);
  84. fflush (stdout);
  85. }
  86. return (0);
  87. }
  88. #endif