FactoryDefaults.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed FactoryDefaults (struct plc * plc);
  11. *
  12. * plc.h
  13. *
  14. * This plug-in for program plc restores factory defaults using
  15. * a VS_FAC_DEFAULTS message;
  16. *
  17. * Contributor(s):
  18. * Nathaniel Houghton, nhoughto@qca.qualcomm.com
  19. *
  20. *--------------------------------------------------------------------*/
  21. #ifndef FACTORYDEFAULTS_SOURCE
  22. #define FACTORYDEFAULTS_SOURCE
  23. #include <stdint.h>
  24. #include <memory.h>
  25. #include "../plc/plc.h"
  26. #include "../tools/memory.h"
  27. #include "../tools/error.h"
  28. signed FactoryDefaults (struct plc * plc)
  29. {
  30. struct channel * channel = (struct channel *) (plc->channel);
  31. struct message * message = (struct message *) (plc->message);
  32. #ifndef __GNUC__
  33. #pragma pack (push,1)
  34. #endif
  35. struct __packed vs_fac_defaults_request
  36. {
  37. struct ethernet_hdr ethernet;
  38. struct qualcomm_hdr qualcomm;
  39. }
  40. * request = (struct vs_fac_defaults_request *) (message);
  41. struct __packed vs_fac_defaults_confirm
  42. {
  43. struct ethernet_hdr ethernet;
  44. struct qualcomm_hdr qualcomm;
  45. uint8_t MSTATUS;
  46. }
  47. * confirm = (struct vs_fac_defaults_confirm *) (message);
  48. #ifndef __GNUC__
  49. #pragma pack (pop)
  50. #endif
  51. Request (plc, "Restore Factory Defaults");
  52. memset (message, 0, sizeof (* message));
  53. EthernetHeader (& request->ethernet, channel->peer, channel->host, channel->type);
  54. QualcommHeader (& request->qualcomm, 0, (VS_FAC_DEFAULTS | MMTYPE_REQ));
  55. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  56. if (SendMME (plc) <= 0)
  57. {
  58. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  59. return (-1);
  60. }
  61. while (ReadMME (plc, 0, (VS_FAC_DEFAULTS | MMTYPE_CNF)) > 0)
  62. {
  63. if (confirm->MSTATUS)
  64. {
  65. Failure (plc, PLC_WONTDOIT);
  66. continue;
  67. }
  68. Confirm (plc, "Restoring ...");
  69. }
  70. return (0);
  71. }
  72. #endif