EraseFlashSector.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed EraseFlashSector (struct plc * plc);
  11. *
  12. * nda.h
  13. *
  14. * erase a specific sector of flash memory when the DAK is known;
  15. * the sector is passed in plc->modulecode as an 8 bit value so
  16. * make sure that plc->modulecode is not being used by another
  17. * function such as function Flash () in module FlashPTS;
  18. *
  19. * See the Atheros HomePlug AV Firmware Technical Reference Manual
  20. * for more information;
  21. *
  22. * Contributor(s):
  23. * Charles Maier <cmaier@qca.qualcomm.com>
  24. *
  25. *--------------------------------------------------------------------*/
  26. #ifndef ERASEFLASHSECTOR_SOURCE
  27. #define ERASEFLASHSECTOR_SOURCE
  28. #include <stdint.h>
  29. #include <memory.h>
  30. #include "../tools/memory.h"
  31. #include "../tools/error.h"
  32. #include "../plc/plc.h"
  33. #include "../nda/nda.h"
  34. signed EraseFlashSector (struct plc * plc)
  35. {
  36. struct channel * channel = (struct channel *) (plc->channel);
  37. struct message * message = (struct message *) (plc->message);
  38. #ifndef __GNUC__
  39. #pragma pack (push,1)
  40. #endif
  41. struct __packed vs_flash_erase_request
  42. {
  43. struct ethernet_hdr ethernet;
  44. struct qualcomm_hdr qualcomm;
  45. uint8_t SECTOR;
  46. uint8_t DAK [HPAVKEY_DAK_LEN];
  47. }
  48. * request = (struct vs_flash_erase_request *) (message);
  49. struct __packed vs_flash_erase_confirm
  50. {
  51. struct ethernet_hdr ethernet;
  52. struct qualcomm_hdr qualcomm;
  53. uint8_t STATUS;
  54. uint8_t SECTOR;
  55. }
  56. * confirm = (struct vs_flash_erase_confirm *) (message);
  57. #ifndef __GNUC__
  58. #pragma pack (pop)
  59. #endif
  60. Request (plc, "Erase Flash Memory Sector");
  61. memset (message, 0, sizeof (* message));
  62. EthernetHeader (& request->ethernet, channel->peer, channel->host, channel->type);
  63. QualcommHeader (& request->qualcomm, 0, (VS_FLASH_ERASE | MMTYPE_REQ));
  64. request->SECTOR = plc->sector;
  65. memcpy (request->DAK, plc->DAK, sizeof (request->DAK));
  66. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  67. if (SendMME (plc) <= 0)
  68. {
  69. error (PLC_EXIT (plc), ECANCELED, CHANNEL_CANTSEND);
  70. return (-1);
  71. }
  72. if (ReadMME (plc, 0, (VS_FLASH_ERASE | MMTYPE_CNF)) <= 0)
  73. {
  74. error (PLC_EXIT (plc), ECANCELED, CHANNEL_CANTREAD);
  75. return (-1);
  76. }
  77. if (confirm->STATUS)
  78. {
  79. Failure (plc, PLC_WONTDOIT);
  80. return (-1);
  81. }
  82. Confirm (plc, "Erased Sector %d", confirm->SECTOR);
  83. return (0);
  84. }
  85. #endif