Sniffer.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed Sniffer (struct plc * plc);
  11. *
  12. * nda.h
  13. *
  14. * enable/disable sniffer mode on a powerline device;
  15. *
  16. * Contributor(s):
  17. * Charles Maier <cmaier@qca.qualcomm.com>
  18. *
  19. *--------------------------------------------------------------------*/
  20. #ifndef SNIFFER_SOURCE
  21. #define SNIFFER_SOURCE
  22. #include <memory.h>
  23. #include <errno.h>
  24. #include "../tools/memory.h"
  25. #include "../tools/error.h"
  26. #include "../tools/flags.h"
  27. #include "../ether/channel.h"
  28. #include "../mme/mme.h"
  29. #include "../plc/plc.h"
  30. signed Sniffer (struct plc * plc)
  31. {
  32. struct channel * channel = (struct channel *) (plc->channel);
  33. struct message * message = (struct message *) (plc->message);
  34. #ifndef __GNUC__
  35. #pragma pack (push,1)
  36. #endif
  37. struct __packed vs_sniffer_request
  38. {
  39. struct ethernet_hdr ethernet;
  40. struct qualcomm_hdr qualcomm;
  41. uint8_t SNIFFCTRL;
  42. }
  43. * request = (struct vs_sniffer_request *) (message);
  44. struct __packed vs_sniffer_confirm
  45. {
  46. struct ethernet_hdr ethernet;
  47. struct qualcomm_hdr qualcomm;
  48. uint8_t MSTATUS;
  49. uint8_t SNIFSTATE;
  50. uint8_t SNIFFER_DA [ETHER_ADDR_LEN];
  51. }
  52. * confirm = (struct vs_sniffer_confirm *) (message);
  53. #ifndef __GNUC__
  54. #pragma pack (pop)
  55. #endif
  56. ssize_t packetsize;
  57. memset (message, 0, sizeof (* message));
  58. EthernetHeader (& request->ethernet, channel->peer, channel->host, channel->type);
  59. QualcommHeader (& request->qualcomm, 0, (VS_SNIFFER | MMTYPE_REQ));
  60. request->SNIFFCTRL = plc->action;
  61. if (sendpacket (channel, message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) <= 0)
  62. {
  63. error (1, ECANCELED, CHANNEL_CANTSEND);
  64. }
  65. while ((packetsize = readpacket (channel, message, sizeof (* message))) > 0)
  66. {
  67. if (! UnwantedMessage (message, packetsize, 0, (VS_SNIFFER | MMTYPE_CNF)))
  68. {
  69. Display (plc, "SNIFFER %s", (confirm->SNIFSTATE)? "ON": "OFF");
  70. break;
  71. }
  72. }
  73. return (0);
  74. }
  75. #endif