1 // Copyright (c) 2010, Atmel Corporation. 2 // All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions are met: 6 // * Redistributions of source code must retain the above copyright 7 // notice, this list of conditions and the following disclaimer. 8 // * Redistributions in binary form must reproduce the above copyright 9 // notice, this list of conditions and the following disclaimer in the 10 // documentation and/or other materials provided with the distribution. 11 // * Neither the name of Atmel nor the 12 // names of its contributors may be used to endorse or promote products 13 // derived from this software without specific prior written permission. 14 // 15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 19 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 26 #ifndef SHA_COMMMARSHALLING_H 27 #define SHA_COMMMARSHALLING_H 28 29 #include <ctype.h> 30 #include "SHA_Comm.h" 31 32 // General Definitions 33 #define SENDBUF_SIZE 128 34 #define RECEIVEBUF_SIZE 128 35 36 37 // Command ordinal definitions 38 #define DERIVE_KEY 0x1C 39 #define DEVREV 0x30 40 #define GENDIG 0x15 41 #define HMAC 0x11 42 #define HOSTHMAC 0x21 43 #define HOSTMAC 0x28 44 #define LOCK 0x17 45 #define MAC 0x08 46 #define NONCE 0x16 47 #define PAUSE 0x01 48 #define RANDOM 0x1B 49 #define READ 0x02 50 #define TEMPSENSE 0x18 51 #define WRITE 0x12 52 53 54 55 56 /* Command Packet definition 57 58 Byte # Name Meaning 59 ------ ---- ------- 60 0 Count Number of bytes in the packet, includes the byte count, body and the checksum 61 1 Ordinal Command Opcode (Ordinal) 62 2 -> n Cmd Parameters Parameters for specific command 63 n+1 & n+2 Checksum Checksum of the command packet 64 65 */ 66 67 ////////////////////////////////////////////////////////////////////// 68 // General command indexes 69 #define COUNT_IDX 0 70 #define CMD_ORDINAL_IDX 1 71 72 ////////////////////////////////////////////////////////////////////// 73 // DriveKey command 74 #define DK_RANDOM_IDX 2 75 #define DK_TARGETKEY_IDX 3 76 #define DK_MAC_IDX 5 77 78 #define DK_COUNT_SMALL 7 79 #define DK_COUNT_LARGE 39 80 81 ////////////////////////////////////////////////////////////////////// 82 // DevRev command 83 #define DR_PARAM1_IDX 2 84 #define DR_PARAM2_IDX 3 85 86 #define DR_COUNT 7 87 88 ////////////////////////////////////////////////////////////////////// 89 // GenDig command 90 #define GD_ZONE_IDX 2 91 #define GD_KEYID_IDX 3 92 #define GD_DATA_IDX 5 93 94 #define GD_COUNT 7 95 #define GD_COUNT_DATA 11 96 97 ////////////////////////////////////////////////////////////////////// 98 // HMAC command 99 #define HM_MODE_IDX 2 100 #define HM_KEYID_IDX 3 101 102 #define HM_COUNT 7 103 104 ////////////////////////////////////////////////////////////////////// 105 // HostHMAC command 106 #define HHMAC_MODE_IDX 2 107 #define HHMAC_KEYID_IDX 3 108 #define HHMAC_CLIENTRSP 5 109 #define HHMAC_DATA 37 110 #define HHMAC_COUNT 52 111 112 ////////////////////////////////////////////////////////////////////// 113 // HostMAC command 114 #define HOSTMAC_MODE_IDX 2 115 #define HOSTMAC_KEYID_IDX 3 116 #define HOSTMAC_CLIENCHALL 5 117 #define HOSTMAC_CLIENTRSP 37 118 #define HOSTMAC_DATA 69 119 #define HOSTMAC_COUNT 84 120 121 ////////////////////////////////////////////////////////////////////// 122 // Lock command 123 #define LK_ZONE_IDX 2 124 #define LK_SUMMARY_IDX 3 125 126 #define LK_COUNT 5 127 128 ////////////////////////////////////////////////////////////////////// 129 // Mac command 130 #define MAC_MODE_IDX 2 131 #define MAC_KEYID_IDX 3 132 #define MAC_CHALL_IDX 5 133 134 #define MAC_COUNT_SHORT 7 135 #define MAC_COUNT_LARGE 39 136 137 ////////////////////////////////////////////////////////////////////// 138 // Nonce command 139 #define N_MODE_IDX 2 140 #define N_ZERO_IDX 3 141 #define N_NUMIN_IDX 5 142 143 #define N_COUNT_SHORT 27 144 #define N_COUNT_LONG 39 145 146 ////////////////////////////////////////////////////////////////////// 147 // Pause command 148 #define P_SELECT_IDX 2 149 #define P_ZERO_IDX 3 150 151 #define P_COUNT 7 152 153 ////////////////////////////////////////////////////////////////////// 154 // Random command 155 #define RAN_MODE_IDX 2 156 #define RAN_ZERO_IDX 3 157 158 #define RAN_COUNT 7 159 160 ////////////////////////////////////////////////////////////////////// 161 // Read command 162 #define READ_ZONE_IDX 2 163 #define READ_ADDR_IDX 3 164 165 #define READ_COUNT 7 166 167 ////////////////////////////////////////////////////////////////////// 168 // TempSense command 169 #define TS_ZERO1_IDX 2 170 #define TS_ZERO2_IDX 3 171 172 #define TS_COUNT 7 173 174 ////////////////////////////////////////////////////////////////////// 175 // Write command 176 #define W_ZONE_IDX 2 177 #define W_ADDR_IDX 3 178 #define W_VALUE_IDX 5 179 #define W_MAC_VS_IDX 9 180 #define W_MAC_VL_IDX 37 181 182 #define W_COUNT_SHORT 11 183 #define W_COUNT_LONG 39 184 #define W_COUNT_SHORT_MAC 43 185 #define W_COUNT_LONG_MAC 71 186 187 ////////////////////////////////////////////////////////////////////// 188 // Command Timming definitions 189 #define MACDELAY 30000 190 #define READDELAY 100000 191 #define ENCREADDELAY 100000 192 #define GENDIGDELAY 15000 193 #define WRITEDELAY 15000 194 #define ENCWRITEDELAY 15000 195 #define HMACDELAY 30000 196 #define SHORTRANDDELAY 15000 197 #define LONGRANDDELAY 15000 198 #define LOCKDELAY 15000 199 #define TEMPDELAY 10000 200 #define GENERALCMDDELAY 1000 201 202 203 ////////////////////////////////////////////////////////////////////// 204 // Function definitions 205 uint8_t SHAC_DeriveKey(uint8_t Random, uint16_t TargetKey, uint8_t *Data); 206 uint8_t SHAC_DevRev(); 207 uint8_t SHAC_GenDig(uint8_t Zone, uint16_t KeyID, uint8_t *Data); 208 uint8_t SHAC_HMAC(uint8_t Mode, uint16_t KeyID); 209 uint8_t SHAC_HostHMAC(uint8_t Mode, uint16_t KeyID, uint8_t *ClietResponse, uint8_t *OtherData); 210 uint8_t SHAC_HostMAC(uint8_t Mode, uint16_t KeyID, uint8_t *ClietChallenge, uint8_t *ClietResponse, uint8_t *OtherData); 211 uint8_t SHAC_Lock(uint8_t Zone, uint16_t Summary); 212 uint8_t SHAC_Mac(uint8_t Mode, uint16_t KeyID, uint8_t *Challenge); 213 uint8_t SHAC_Nonce(uint8_t Mode, uint8_t *Numin); 214 uint8_t SHAC_Pause(uint8_t Selector); 215 uint8_t SHAC_Random(uint8_t Mode); 216 uint8_t SHAC_Read(uint8_t Zone, uint16_t Address); 217 uint8_t SHAC_TempSense(uint8_t *Temp); 218 uint8_t SHAC_Write(uint8_t Zone, uint16_t Address, uint8_t *Value, uint8_t *MACData); 219 220 SHA_CommParameters* SHAC_GetData(void); 221 222 #endif 223