ResetDevice.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed ResetDevice (struct plc * plc);
  11. *
  12. * plc.h
  13. *
  14. * This plugin for program plc and plcrate resets the device
  15. * using a VS_RS_DEV message; resetting can take several seconds
  16. * after this function returns to the caller;
  17. *
  18. * Contributor(s):
  19. * Charles Maier <cmaier@qca.qualcomm.com>
  20. *
  21. *
  22. *--------------------------------------------------------------------*/
  23. #ifndef RESETDEVICE1_SOURCE
  24. #define RESETDEVICE1_SOURCE
  25. #include <stdint.h>
  26. #include <memory.h>
  27. #include "../plc/plc.h"
  28. #include "../tools/error.h"
  29. #include "../tools/flags.h"
  30. #include "../tools/memory.h"
  31. signed ResetDevice (struct plc * plc)
  32. {
  33. struct channel * channel = (struct channel *) (plc->channel);
  34. struct message * message = (struct message *) (plc->message);
  35. #ifndef __GNUC__
  36. #pragma pack (push,1)
  37. #endif
  38. struct __packed vs_rs_dev_request
  39. {
  40. struct ethernet_hdr ethernet;
  41. struct qualcomm_hdr qualcomm;
  42. uint32_t RSVD;
  43. uint8_t CFM_ACT;
  44. uint32_t RSVD_1;
  45. uint8_t BT_SRC;
  46. uint32_t RSVD_2;
  47. }
  48. * request = (struct vs_rs_dev_request *) (message);
  49. struct __packed vs_rs_dev_confirm
  50. {
  51. struct ethernet_hdr ethernet;
  52. struct qualcomm_hdr qualcomm;
  53. uint8_t MSTATUS;
  54. uint32_t RSVD;
  55. uint8_t CFM_ACT;
  56. uint32_t RSVD_1;
  57. uint8_t BT_SRC;
  58. uint32_t RSVD_2;
  59. }
  60. * confirm = (struct vs_rs_dev_confirm *) (message);
  61. #ifndef __GNUC__
  62. #pragma pack (pop)
  63. #endif
  64. Request (plc, "Reset Device");
  65. memset (message, 0, sizeof (* message));
  66. EthernetHeader (& request->ethernet, channel->peer, channel->host, channel->type);
  67. QualcommHeader (& request->qualcomm, 0, (VS_RS_DEV | MMTYPE_REQ));
  68. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  69. if (_anyset (plc->flag2, PLC_FLAG2_CFM_ACT))
  70. {
  71. request->CFM_ACT = 1;
  72. }
  73. if (_anyset (plc->flag2, PLC_FLAG2_BT_SRC))
  74. {
  75. request->BT_SRC = 1;
  76. }
  77. if (SendMME (plc) <= 0)
  78. {
  79. error ((plc->flags & PLC_BAILOUT), errno, CHANNEL_CANTSEND);
  80. return (-1);
  81. }
  82. if (_anyset (plc->flag2, PLC_FLAG2_CFM_ACT))
  83. {
  84. return (0);
  85. }
  86. while (ReadMME (plc, 0, (VS_RS_DEV | MMTYPE_CNF)) > 0)
  87. {
  88. if (confirm->MSTATUS)
  89. {
  90. Failure (plc, PLC_WONTDOIT);
  91. continue;
  92. }
  93. Confirm (plc, "Resetting ...");
  94. }
  95. return (0);
  96. }
  97. #endif