atmel-ecc.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (c) 2017, Microchip Technology Inc.
  3. * Author: Tudor Ambarus <tudor.ambarus@microchip.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. */
  18. #ifndef __ATMEL_ECC_H__
  19. #define __ATMEL_ECC_H__
  20. #define ATMEL_ECC_PRIORITY 300
  21. #define COMMAND 0x03 /* packet function */
  22. #define SLEEP_TOKEN 0x01
  23. #define WAKE_TOKEN_MAX_SIZE 8
  24. /* Definitions of Data and Command sizes */
  25. #define WORD_ADDR_SIZE 1
  26. #define COUNT_SIZE 1
  27. #define CRC_SIZE 2
  28. #define CMD_OVERHEAD_SIZE (COUNT_SIZE + CRC_SIZE)
  29. /* size in bytes of the n prime */
  30. #define ATMEL_ECC_NIST_P256_N_SIZE 32
  31. #define ATMEL_ECC_PUBKEY_SIZE (2 * ATMEL_ECC_NIST_P256_N_SIZE)
  32. #define STATUS_RSP_SIZE 4
  33. #define ECDH_RSP_SIZE (32 + CMD_OVERHEAD_SIZE)
  34. #define GENKEY_RSP_SIZE (ATMEL_ECC_PUBKEY_SIZE + \
  35. CMD_OVERHEAD_SIZE)
  36. #define READ_RSP_SIZE (4 + CMD_OVERHEAD_SIZE)
  37. #define MAX_RSP_SIZE GENKEY_RSP_SIZE
  38. /**
  39. * atmel_ecc_cmd - structure used for communicating with the device.
  40. * @word_addr: indicates the function of the packet sent to the device. This
  41. * byte should have a value of COMMAND for normal operation.
  42. * @count : number of bytes to be transferred to (or from) the device.
  43. * @opcode : the command code.
  44. * @param1 : the first parameter; always present.
  45. * @param2 : the second parameter; always present.
  46. * @data : optional remaining input data. Includes a 2-byte CRC.
  47. * @rxsize : size of the data received from i2c client.
  48. * @msecs : command execution time in milliseconds
  49. */
  50. struct atmel_ecc_cmd {
  51. u8 word_addr;
  52. u8 count;
  53. u8 opcode;
  54. u8 param1;
  55. u16 param2;
  56. u8 data[MAX_RSP_SIZE];
  57. u8 msecs;
  58. u16 rxsize;
  59. } __packed;
  60. /* Status/Error codes */
  61. #define STATUS_SIZE 0x04
  62. #define STATUS_NOERR 0x00
  63. #define STATUS_WAKE_SUCCESSFUL 0x11
  64. static const struct {
  65. u8 value;
  66. const char *error_text;
  67. } error_list[] = {
  68. { 0x01, "CheckMac or Verify miscompare" },
  69. { 0x03, "Parse Error" },
  70. { 0x05, "ECC Fault" },
  71. { 0x0F, "Execution Error" },
  72. { 0xEE, "Watchdog about to expire" },
  73. { 0xFF, "CRC or other communication error" },
  74. };
  75. /* Definitions for eeprom organization */
  76. #define CONFIG_ZONE 0
  77. /* Definitions for Indexes common to all commands */
  78. #define RSP_DATA_IDX 1 /* buffer index of data in response */
  79. #define DATA_SLOT_2 2 /* used for ECDH private key */
  80. /* Definitions for the device lock state */
  81. #define DEVICE_LOCK_ADDR 0x15
  82. #define LOCK_VALUE_IDX (RSP_DATA_IDX + 2)
  83. #define LOCK_CONFIG_IDX (RSP_DATA_IDX + 3)
  84. /*
  85. * Wake High delay to data communication (microseconds). SDA should be stable
  86. * high for this entire duration.
  87. */
  88. #define TWHI_MIN 1500
  89. #define TWHI_MAX 1550
  90. /* Wake Low duration */
  91. #define TWLO_USEC 60
  92. /* Command execution time (milliseconds) */
  93. #define MAX_EXEC_TIME_ECDH 58
  94. #define MAX_EXEC_TIME_GENKEY 115
  95. #define MAX_EXEC_TIME_READ 1
  96. /* Command opcode */
  97. #define OPCODE_ECDH 0x43
  98. #define OPCODE_GENKEY 0x40
  99. #define OPCODE_READ 0x02
  100. /* Definitions for the READ Command */
  101. #define READ_COUNT 7
  102. /* Definitions for the GenKey Command */
  103. #define GENKEY_COUNT 7
  104. #define GENKEY_MODE_PRIVATE 0x04
  105. /* Definitions for the ECDH Command */
  106. #define ECDH_COUNT 71
  107. #define ECDH_PREFIX_MODE 0x00
  108. #endif /* __ATMEL_ECC_H__ */