intiial commit

Dependencies:   MAX8614X USBDevice max32630hsp_test

Committer:
phonemacro
Date:
Fri Aug 17 02:46:36 2018 +0000
Revision:
23:4afef8872432
Parent:
22:1be3a5f0223e
Child:
24:3981488a0abd
update to use uint32 inputs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phonemacro 0:9e5a4f845510 1 /**********************************************************************
phonemacro 1:854f8a89a527 2 * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
phonemacro 0:9e5a4f845510 3 *
phonemacro 0:9e5a4f845510 4 * Permission is hereby granted, free of charge, to any person obtaining a
phonemacro 0:9e5a4f845510 5 * copy of this software and associated documentation files (the "Software"),
phonemacro 0:9e5a4f845510 6 * to deal in the Software without restriction, including without limitation
phonemacro 0:9e5a4f845510 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
phonemacro 0:9e5a4f845510 8 * and/or sell copies of the Software, and to permit persons to whom the
phonemacro 0:9e5a4f845510 9 * Software is furnished to do so, subject to the following conditions:
phonemacro 0:9e5a4f845510 10 *
phonemacro 0:9e5a4f845510 11 * The above copyright notice and this permission notice shall be included
phonemacro 0:9e5a4f845510 12 * in all copies or substantial portions of the Software.
phonemacro 0:9e5a4f845510 13 *
phonemacro 0:9e5a4f845510 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
phonemacro 0:9e5a4f845510 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
phonemacro 0:9e5a4f845510 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
phonemacro 0:9e5a4f845510 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
phonemacro 0:9e5a4f845510 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
phonemacro 0:9e5a4f845510 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
phonemacro 0:9e5a4f845510 20 * OTHER DEALINGS IN THE SOFTWARE.
phonemacro 0:9e5a4f845510 21 *
phonemacro 0:9e5a4f845510 22 * Except as contained in this notice, the name of Maxim Integrated
phonemacro 0:9e5a4f845510 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
phonemacro 0:9e5a4f845510 24 * Products, Inc. Branding Policy.
phonemacro 0:9e5a4f845510 25 *
phonemacro 0:9e5a4f845510 26 * The mere transfer of this software does not imply any licenses
phonemacro 0:9e5a4f845510 27 * of trade secrets, proprietary technology, copyrights, patents,
phonemacro 0:9e5a4f845510 28 * trademarks, maskwork rights, or any other form of intellectual
phonemacro 0:9e5a4f845510 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
phonemacro 0:9e5a4f845510 30 * ownership rights.
phonemacro 0:9e5a4f845510 31 **********************************************************************/
phonemacro 0:9e5a4f845510 32
phonemacro 0:9e5a4f845510 33
phonemacro 0:9e5a4f845510 34 #include "mbed.h"
phonemacro 0:9e5a4f845510 35 //#include "max32630fthr.h"
phonemacro 0:9e5a4f845510 36 #include "max32630hsp.h"
phonemacro 0:9e5a4f845510 37 #include "MAX8614X.h"
phonemacro 0:9e5a4f845510 38 #include "USBSerial.h"
phonemacro 21:0a4f90fb3451 39
phonemacro 21:0a4f90fb3451 40 //#define DEBUG_ON 1
phonemacro 21:0a4f90fb3451 41
phonemacro 22:1be3a5f0223e 42 void executeSha256(MAX8614X &m, uint32_t *challenge, unsigned int challengeLen, bool romID, uint32_t *response);
phonemacro 16:d0f8cf9f160d 43 bool isTheChipAuthenicated(uint32_t *expectedResponse, uint32_t *chipResponse);
phonemacro 7:5b7f7ec9efe0 44
phonemacro 16:d0f8cf9f160d 45 #define RESPONSE_LEN32 8
phonemacro 0:9e5a4f845510 46
phonemacro 0:9e5a4f845510 47 MAX32630HSP icarus(MAX32630HSP::VIO_1V8);
phonemacro 0:9e5a4f845510 48 // MAX32630FTHR mbed_board(MAX32630FTHR::VIO_1V8);
phonemacro 0:9e5a4f845510 49 SPI spi(P5_1, P5_2, P5_0); /* mosi, miso, sclk */
phonemacro 3:2272f89aad7e 50 DigitalOut cs(P5_3);
phonemacro 18:a0356b3e6ed9 51 PinName interrupt_pin = P3_2;
phonemacro 0:9e5a4f845510 52 // Virtual serial port over USB
phonemacro 0:9e5a4f845510 53 USBSerial microUSB;
phonemacro 0:9e5a4f845510 54
phonemacro 0:9e5a4f845510 55 DigitalOut rLED(LED1);
phonemacro 0:9e5a4f845510 56 DigitalOut gLED(LED2);
phonemacro 0:9e5a4f845510 57 DigitalOut bLED(LED3);
phonemacro 0:9e5a4f845510 58 int main()
phonemacro 0:9e5a4f845510 59 {
phonemacro 23:4afef8872432 60 #define CHALLENGE32_LEN 5
phonemacro 23:4afef8872432 61 uint32_t challenge_A[CHALLENGE32_LEN] = { // 160 bit, no ROM
phonemacro 23:4afef8872432 62 0x00000001,
phonemacro 23:4afef8872432 63 0x00000000,
phonemacro 23:4afef8872432 64 0x00000000,
phonemacro 23:4afef8872432 65 0x00000000,
phonemacro 23:4afef8872432 66 0x00000000
phonemacro 15:2616528b4007 67 };
phonemacro 20:39857996a7c7 68 uint32_t expectedResponse_A_romID[RESPONSE_LEN32] = { // 160 bit, no ROM
phonemacro 20:39857996a7c7 69 0xf987d79a,
phonemacro 20:39857996a7c7 70 0xeb778ec7,
phonemacro 20:39857996a7c7 71 0x33861bc8,
phonemacro 20:39857996a7c7 72 0x745d4082,
phonemacro 20:39857996a7c7 73 0x921e02fe,
phonemacro 20:39857996a7c7 74 0x727d93c8,
phonemacro 20:39857996a7c7 75 0x218e53ee,
phonemacro 20:39857996a7c7 76 0x904e0c6b
phonemacro 20:39857996a7c7 77 };
phonemacro 23:4afef8872432 78 uint32_t challenge_1[CHALLENGE32_LEN] = { // 160 bit
phonemacro 23:4afef8872432 79 0x5e813524,
phonemacro 23:4afef8872432 80 0x5663d609,
phonemacro 23:4afef8872432 81 0x998d7b0d,
phonemacro 23:4afef8872432 82 0x52128465,
phonemacro 23:4afef8872432 83 0xcd0de301
phonemacro 4:46919eec2c28 84 };
phonemacro 20:39857996a7c7 85 uint32_t expectedResponse_1_romID[RESPONSE_LEN32] = { // 160 bit
phonemacro 20:39857996a7c7 86 0xfe3f805f,
phonemacro 20:39857996a7c7 87 0x0af066bc,
phonemacro 20:39857996a7c7 88 0xda0f55e2,
phonemacro 20:39857996a7c7 89 0x0020ac16,
phonemacro 20:39857996a7c7 90 0x13fa3406,
phonemacro 20:39857996a7c7 91 0x59d0e5ae,
phonemacro 20:39857996a7c7 92 0x79def309,
phonemacro 20:39857996a7c7 93 0x685981a3
phonemacro 20:39857996a7c7 94 };
phonemacro 4:46919eec2c28 95
phonemacro 23:4afef8872432 96 uint32_t challenge_2[CHALLENGE32_LEN] = { // 160 bit, no ROM
phonemacro 23:4afef8872432 97 0xd2aa84c5,
phonemacro 23:4afef8872432 98 0x7277f7e5,
phonemacro 23:4afef8872432 99 0xdb8fd612,
phonemacro 23:4afef8872432 100 0x96ce69f2,
phonemacro 23:4afef8872432 101 0x4ec57ae8
phonemacro 13:97854f761347 102 };
phonemacro 14:1939758a03cf 103
phonemacro 17:e260080d3468 104 uint32_t expectedResponse_2_noRomID[RESPONSE_LEN32] = { // 160 bit, no ROM
phonemacro 17:e260080d3468 105 0x1a7135a2,
phonemacro 17:e260080d3468 106 0x51b99ca8,
phonemacro 17:e260080d3468 107 0xbdd9245e,
phonemacro 17:e260080d3468 108 0xb9c8e758,
phonemacro 17:e260080d3468 109 0x770ec1c4,
phonemacro 17:e260080d3468 110 0x474ffcc7,
phonemacro 17:e260080d3468 111 0x828afe4d,
phonemacro 17:e260080d3468 112 0x9cb3de6d
phonemacro 17:e260080d3468 113 };
phonemacro 23:4afef8872432 114 uint32_t challenge_3[CHALLENGE32_LEN] = { // 160 bit
phonemacro 23:4afef8872432 115 0x21202280,
phonemacro 23:4afef8872432 116 0xcc9d45aa,
phonemacro 23:4afef8872432 117 0xb8133e96,
phonemacro 23:4afef8872432 118 0xd653380d,
phonemacro 23:4afef8872432 119 0x2ad5dd6b
phonemacro 20:39857996a7c7 120 };
phonemacro 20:39857996a7c7 121 uint32_t expectedResponse_3_romID[RESPONSE_LEN32] = { // 160 bit
phonemacro 20:39857996a7c7 122 0xe7750b8d,
phonemacro 20:39857996a7c7 123 0xe29d9279,
phonemacro 20:39857996a7c7 124 0x7cdc7053,
phonemacro 20:39857996a7c7 125 0xa9f92519,
phonemacro 20:39857996a7c7 126 0xa1e59d93,
phonemacro 20:39857996a7c7 127 0x19cd930d,
phonemacro 20:39857996a7c7 128 0xfb0fc974,
phonemacro 20:39857996a7c7 129 0x2da0781e
phonemacro 20:39857996a7c7 130 };
phonemacro 23:4afef8872432 131 uint32_t challenge_4[CHALLENGE32_LEN] = { // 160 bit, no ROM
phonemacro 22:1be3a5f0223e 132 0x4c3c0aca,
phonemacro 22:1be3a5f0223e 133 0x618abdf2,
phonemacro 22:1be3a5f0223e 134 0x34d8b341,
phonemacro 22:1be3a5f0223e 135 0x1289f378,
phonemacro 22:1be3a5f0223e 136 0x65b60deb
phonemacro 20:39857996a7c7 137 };
phonemacro 20:39857996a7c7 138 uint32_t expectedResponse_4_noRomID[RESPONSE_LEN32] = { // 160 bit, no ROM
phonemacro 20:39857996a7c7 139 0xae740f91,
phonemacro 20:39857996a7c7 140 0x8d6f2d58,
phonemacro 20:39857996a7c7 141 0x7486b0ba,
phonemacro 20:39857996a7c7 142 0xe9a84580,
phonemacro 20:39857996a7c7 143 0xfe9ce593,
phonemacro 20:39857996a7c7 144 0x58d66c7d,
phonemacro 20:39857996a7c7 145 0xc993d165,
phonemacro 20:39857996a7c7 146 0xe5ae5983
phonemacro 20:39857996a7c7 147 };
phonemacro 22:1be3a5f0223e 148
phonemacro 16:d0f8cf9f160d 149 uint32_t chip_response[RESPONSE_LEN32];
phonemacro 16:d0f8cf9f160d 150 bool valid = 0;
phonemacro 16:d0f8cf9f160d 151
phonemacro 21:0a4f90fb3451 152 rLED = LED_OFF;
phonemacro 0:9e5a4f845510 153 gLED = LED_ON;
phonemacro 0:9e5a4f845510 154 bLED = LED_OFF;
phonemacro 0:9e5a4f845510 155
phonemacro 1:854f8a89a527 156 printf("\r\n\rmax86140 authenication software\r\n");
phonemacro 11:ec7998257ec2 157 MAX8614X m(spi,cs,interrupt_pin);
phonemacro 18:a0356b3e6ed9 158 m.init();
phonemacro 3:2272f89aad7e 159
phonemacro 17:e260080d3468 160 //● Compare MAC from MAX86140 wth Host's precalculated MAC.
phonemacro 23:4afef8872432 161 executeSha256(m, challenge_A, CHALLENGE32_LEN, 1, chip_response);
phonemacro 20:39857996a7c7 162 //● Check PASS or FAIL.
phonemacro 20:39857996a7c7 163 valid = isTheChipAuthenicated(chip_response, expectedResponse_A_romID);
phonemacro 20:39857996a7c7 164 if (valid)
phonemacro 20:39857996a7c7 165 printf("\r\n Challenge A passed\r\n\r\n");
phonemacro 20:39857996a7c7 166 else
phonemacro 20:39857996a7c7 167 printf("\r\n Challenge A failed\r\n\r\n");
phonemacro 17:e260080d3468 168
phonemacro 20:39857996a7c7 169 //● Compare MAC from MAX86140 wth Host's precalculated MAC.
phonemacro 23:4afef8872432 170 executeSha256(m, challenge_1, CHALLENGE32_LEN, 1, chip_response);
phonemacro 17:e260080d3468 171 //● Check PASS or FAIL.
phonemacro 16:d0f8cf9f160d 172 valid = isTheChipAuthenicated(chip_response, expectedResponse_1_romID);
phonemacro 16:d0f8cf9f160d 173 if (valid)
phonemacro 16:d0f8cf9f160d 174 printf("\r\n Challenge 1 passed\r\n\r\n");
phonemacro 16:d0f8cf9f160d 175 else
phonemacro 16:d0f8cf9f160d 176 printf("\r\n Challenge 1 failed\r\n\r\n");
phonemacro 17:e260080d3468 177
phonemacro 23:4afef8872432 178 executeSha256(m, challenge_2, CHALLENGE32_LEN, 0, chip_response);
phonemacro 17:e260080d3468 179 valid = isTheChipAuthenicated(chip_response, expectedResponse_2_noRomID);
phonemacro 17:e260080d3468 180 if (valid)
phonemacro 17:e260080d3468 181 printf("\r\n Challenge 2 passed\r\n\r\n");
phonemacro 17:e260080d3468 182 else
phonemacro 17:e260080d3468 183 printf("\r\n Challenge 2 failed\r\n\r\n");
phonemacro 20:39857996a7c7 184
phonemacro 23:4afef8872432 185 executeSha256(m, challenge_3, CHALLENGE32_LEN, 1, chip_response);
phonemacro 20:39857996a7c7 186 valid = isTheChipAuthenicated(chip_response, expectedResponse_3_romID);
phonemacro 20:39857996a7c7 187 if (valid)
phonemacro 20:39857996a7c7 188 printf("\r\n Challenge 3 passed\r\n\r\n");
phonemacro 20:39857996a7c7 189 else
phonemacro 20:39857996a7c7 190 printf("\r\n Challenge 3 failed\r\n\r\n");
phonemacro 20:39857996a7c7 191
phonemacro 23:4afef8872432 192 executeSha256(m, challenge_4, CHALLENGE32_LEN, 0, chip_response);
phonemacro 20:39857996a7c7 193 valid = isTheChipAuthenicated(chip_response, expectedResponse_4_noRomID);
phonemacro 20:39857996a7c7 194 if (valid)
phonemacro 20:39857996a7c7 195 printf("\r\n Challenge 4 passed\r\n\r\n");
phonemacro 20:39857996a7c7 196 else
phonemacro 20:39857996a7c7 197 printf("\r\n Challenge 4 failed\r\n\r\n");
phonemacro 23:4afef8872432 198
phonemacro 17:e260080d3468 199 //● Disable SHA_EN bit ( Write 0 to SHA_EN bit).
phonemacro 18:a0356b3e6ed9 200 m.writeRegister(MAX8614X::MAX8614X_SHA_CFG_REG, 0);
phonemacro 0:9e5a4f845510 201 while(1) {
phonemacro 1:854f8a89a527 202 gLED = !gLED;
phonemacro 0:9e5a4f845510 203 wait(1.0);
phonemacro 0:9e5a4f845510 204 }
phonemacro 0:9e5a4f845510 205 }
phonemacro 0:9e5a4f845510 206
phonemacro 16:d0f8cf9f160d 207 bool isTheChipAuthenicated(uint32_t *expectedResponse, uint32_t * chipResponse)
phonemacro 16:d0f8cf9f160d 208 {
phonemacro 16:d0f8cf9f160d 209 int i;
phonemacro 16:d0f8cf9f160d 210 for (i = 0; i < RESPONSE_LEN32; i++) {
phonemacro 16:d0f8cf9f160d 211 if (expectedResponse[i] != chipResponse[i])
phonemacro 16:d0f8cf9f160d 212 return 0;
phonemacro 16:d0f8cf9f160d 213 }
phonemacro 16:d0f8cf9f160d 214 return 1;
phonemacro 16:d0f8cf9f160d 215 }
phonemacro 16:d0f8cf9f160d 216
phonemacro 7:5b7f7ec9efe0 217 void transformData(uint8_t *inData, uint8_t *outData, unsigned int challengeLen)
phonemacro 7:5b7f7ec9efe0 218 {
phonemacro 7:5b7f7ec9efe0 219 int i, j, k;
phonemacro 7:5b7f7ec9efe0 220 k = 0;
phonemacro 7:5b7f7ec9efe0 221 for (i = 0; i < (challengeLen/4); i++) {
phonemacro 7:5b7f7ec9efe0 222 for (j = 3; j >= 0; j--) {
phonemacro 7:5b7f7ec9efe0 223 outData[j+(i*4)] = inData[k];
phonemacro 7:5b7f7ec9efe0 224 k++;
phonemacro 7:5b7f7ec9efe0 225 }
phonemacro 7:5b7f7ec9efe0 226 }
phonemacro 7:5b7f7ec9efe0 227 }
phonemacro 22:1be3a5f0223e 228 void executeSha256(MAX8614X &m, uint32_t *challenge, unsigned int challengeLen, bool romID, uint32_t *response)
phonemacro 7:5b7f7ec9efe0 229 {
phonemacro 10:0b940aff3bb8 230 int i, j, k;
phonemacro 7:5b7f7ec9efe0 231 uint8_t macData[256];
phonemacro 7:5b7f7ec9efe0 232 uint8_t xData[256];
phonemacro 10:0b940aff3bb8 233 uint32_t x32Data[64];
phonemacro 7:5b7f7ec9efe0 234 uint32_t tmpData;
phonemacro 10:0b940aff3bb8 235 const unsigned int responseLen32 = 8;
phonemacro 7:5b7f7ec9efe0 236 uint8_t data[5];
phonemacro 11:ec7998257ec2 237
phonemacro 18:a0356b3e6ed9 238 //● Enable SHA_DONE Interrupt
phonemacro 7:5b7f7ec9efe0 239 m.writeRegister(MAX8614X::MAX8614X_INT_ENABLE2_REG, MAX8614X::MAX8614X_IE_SHA_DONE_EN);
phonemacro 7:5b7f7ec9efe0 240
phonemacro 7:5b7f7ec9efe0 241 m.writeRegister(MAX8614X::MAX8614X_INT_ENABLE1_REG, 0); // Disable all other interrupts
phonemacro 7:5b7f7ec9efe0 242
phonemacro 13:97854f761347 243 //- Enable SHA_EN bit.
phonemacro 7:5b7f7ec9efe0 244 m.writeRegister(MAX8614X::MAX8614X_SHA_CFG_REG,MAX8614X::MAX8614X_SHACFG_SHA_EN);
phonemacro 7:5b7f7ec9efe0 245
phonemacro 18:a0356b3e6ed9 246 //● Write 160-bit random challenge value to RAM using registers MEM_IDX and MEM_DATA.
phonemacro 7:5b7f7ec9efe0 247 // Enable Memory Write, Select Bank 0, address 0x00 to 0xFF
phonemacro 7:5b7f7ec9efe0 248 m.writeRegister(MAX8614X::MAX8614X_MEMORY_CONTROL_REG, MAX8614X::MAX8614X_MEMCNTRL_WR_EN_MASK | MAX8614X::MAX8614X_MEMCNTRL_BANK0_MASK);
phonemacro 7:5b7f7ec9efe0 249
phonemacro 22:1be3a5f0223e 250 for (i = 0; i < 5; i++) {
phonemacro 22:1be3a5f0223e 251 x32Data[i] = challenge[i];
phonemacro 22:1be3a5f0223e 252 for (j = 0; j <= 3; j++) {
phonemacro 22:1be3a5f0223e 253 xData[(i*4)+j] = x32Data[i] & 0xFF;
phonemacro 22:1be3a5f0223e 254 x32Data[i] = x32Data[i] >> 8;
phonemacro 22:1be3a5f0223e 255 k++;
phonemacro 22:1be3a5f0223e 256 }
phonemacro 22:1be3a5f0223e 257 }
phonemacro 22:1be3a5f0223e 258
phonemacro 23:4afef8872432 259 #ifdef DEBUG_ON
phonemacro 7:5b7f7ec9efe0 260 printf("\r\n Raw Input Data\r\n\r\n");
phonemacro 7:5b7f7ec9efe0 261 for (i = 0; i < challengeLen; i++) {
phonemacro 23:4afef8872432 262 printf("%08x\r\n", challenge[i]);
phonemacro 7:5b7f7ec9efe0 263 }
phonemacro 7:5b7f7ec9efe0 264 printf("\r\n");
phonemacro 10:0b940aff3bb8 265 #endif
phonemacro 10:0b940aff3bb8 266
phonemacro 22:1be3a5f0223e 267 //transformData(challenge, xData, challengeLen);
phonemacro 7:5b7f7ec9efe0 268
phonemacro 21:0a4f90fb3451 269 #ifdef DEBUG_ON
phonemacro 7:5b7f7ec9efe0 270 printf("\r\n Transformed Input Data\r\n\r\n");
phonemacro 23:4afef8872432 271 for (i = 0; i < challengeLen*4; i++) {
phonemacro 7:5b7f7ec9efe0 272 if (!(i % 4))
phonemacro 7:5b7f7ec9efe0 273 printf("\r\n ");
phonemacro 7:5b7f7ec9efe0 274 printf("%02x", xData[i]);
phonemacro 7:5b7f7ec9efe0 275 }
phonemacro 7:5b7f7ec9efe0 276 printf("\r\n ");
phonemacro 21:0a4f90fb3451 277 #endif
phonemacro 7:5b7f7ec9efe0 278
phonemacro 23:4afef8872432 279 for (i = 0; i < (challengeLen*4); i++) {
phonemacro 7:5b7f7ec9efe0 280 m.writeRegister(MAX8614X::MAX8614X_MEMORY_INDEX_REG, i);
phonemacro 7:5b7f7ec9efe0 281 m.writeRegister(MAX8614X::MAX8614X_MEMORY_DATA_REG, xData[i]);
phonemacro 10:0b940aff3bb8 282 //}
phonemacro 10:0b940aff3bb8 283 }
phonemacro 21:0a4f90fb3451 284
phonemacro 7:5b7f7ec9efe0 285 // The message block consists of a 160-bit secret, a 160-bit challenge and 192 bits of constant data. Optionally, the 64-bit
phonemacro 7:5b7f7ec9efe0 286 // ROM ID replaces 64 of the 192 bits of constant data used in the hash operation. 16 bits out of the 160-bit secret and 16
phonemacro 7:5b7f7ec9efe0 287 // bits of ROM ID are programmable–8 bits each in metal and 8 bits each in OTP bits
phonemacro 21:0a4f90fb3451 288 //● Write command, with ROM ID (0x35) or without ROM ID (0x36), to SHA_CMD register
phonemacro 21:0a4f90fb3451 289 if (romID) {
phonemacro 12:fc888315e5fd 290 m.writeRegister(MAX8614X::MAX8614X_SHA_CMD_REG, MAX8614X::MAX8614X_SHACMD_MAC_ROM_ID);
phonemacro 21:0a4f90fb3451 291 }
phonemacro 12:fc888315e5fd 292 else
phonemacro 21:0a4f90fb3451 293 {
phonemacro 21:0a4f90fb3451 294 m.writeRegister(MAX8614X::MAX8614X_SHA_CMD_REG,MAX8614X::MAX8614X_SHACMD_MAC_NO_ROM_ID);
phonemacro 21:0a4f90fb3451 295 }
phonemacro 7:5b7f7ec9efe0 296
phonemacro 10:0b940aff3bb8 297 m.readRegister(MAX8614X::MAX8614X_SHA_CMD_REG, data, 1);
phonemacro 7:5b7f7ec9efe0 298 //● Write 1 to SHA_START and 1 to SHA_EN bit.
phonemacro 7:5b7f7ec9efe0 299 m.writeRegister(MAX8614X::MAX8614X_SHA_CFG_REG,MAX8614X::MAX8614X_SHACFG_SHA_EN | MAX8614X::MAX8614X_SHACFG_SHA_START);
phonemacro 7:5b7f7ec9efe0 300
phonemacro 18:a0356b3e6ed9 301 //● Wait for SHA_DONE.
phonemacro 7:5b7f7ec9efe0 302 data[0] = 0;
phonemacro 17:e260080d3468 303 k = 0;
phonemacro 17:e260080d3468 304 while(!data[0] && k < 100) {
phonemacro 7:5b7f7ec9efe0 305 m.readRegister(MAX8614X::MAX8614X_INT_STATUS2_REG, data, 1);
phonemacro 17:e260080d3468 306 k++;
phonemacro 7:5b7f7ec9efe0 307 }
phonemacro 7:5b7f7ec9efe0 308 // ● Read 256 MAC value from RAM using registers MEM_IDX and MEM_DATA.
phonemacro 21:0a4f90fb3451 309 #ifdef DEBUG_ON
phonemacro 10:0b940aff3bb8 310 printf("\r\n Raw Output\r\n\r\n");
phonemacro 21:0a4f90fb3451 311 #endif
phonemacro 7:5b7f7ec9efe0 312 for (i = 64; i < 64+32; i++) {
phonemacro 21:0a4f90fb3451 313 #ifdef DEBUG_ON
phonemacro 7:5b7f7ec9efe0 314 if (!(i % 4))
phonemacro 7:5b7f7ec9efe0 315 printf("\r\n ");
phonemacro 21:0a4f90fb3451 316 #endif
phonemacro 7:5b7f7ec9efe0 317 m.writeRegister(MAX8614X::MAX8614X_MEMORY_INDEX_REG, i);
phonemacro 7:5b7f7ec9efe0 318 m.readRegister(MAX8614X::MAX8614X_MEMORY_DATA_REG, data, 1);
phonemacro 10:0b940aff3bb8 319 xData[i-64] = data[0];
phonemacro 21:0a4f90fb3451 320 #ifdef DEBUG_ON
phonemacro 7:5b7f7ec9efe0 321 printf("%02x", data[0]);
phonemacro 21:0a4f90fb3451 322 #endif
phonemacro 7:5b7f7ec9efe0 323 }
phonemacro 21:0a4f90fb3451 324 #ifdef DEBUG_ON
phonemacro 10:0b940aff3bb8 325 printf("%\r\n");
phonemacro 21:0a4f90fb3451 326 #endif
phonemacro 10:0b940aff3bb8 327
phonemacro 10:0b940aff3bb8 328 transformData(xData,macData, 32);
phonemacro 21:0a4f90fb3451 329 #ifdef DEBUG_ON
phonemacro 10:0b940aff3bb8 330 printf("\r\n Formatted Response\r\n\r\n");
phonemacro 23:4afef8872432 331 for (i = 0; i < responseLen32*4; i++) {
phonemacro 10:0b940aff3bb8 332 if (!(i % 4))
phonemacro 10:0b940aff3bb8 333 printf("\r\n ");
phonemacro 10:0b940aff3bb8 334 printf("%02x", macData[i]);
phonemacro 10:0b940aff3bb8 335 }
phonemacro 10:0b940aff3bb8 336 printf("\r\n\r\n");
phonemacro 10:0b940aff3bb8 337
phonemacro 10:0b940aff3bb8 338 #endif
phonemacro 10:0b940aff3bb8 339 // transform data to Little-Endian
phonemacro 10:0b940aff3bb8 340 k = 0;
phonemacro 10:0b940aff3bb8 341 for (i = 0; i < (responseLen32); i++) {
phonemacro 10:0b940aff3bb8 342 x32Data[i] = 0;
phonemacro 10:0b940aff3bb8 343 for (j = 3; j >= 0; j--) {
phonemacro 10:0b940aff3bb8 344 x32Data[i] = x32Data[i] << 8;
phonemacro 10:0b940aff3bb8 345 x32Data[i] |= macData[k] & 0xFF;
phonemacro 10:0b940aff3bb8 346 k++;
phonemacro 10:0b940aff3bb8 347 }
phonemacro 10:0b940aff3bb8 348 }
phonemacro 10:0b940aff3bb8 349
phonemacro 21:0a4f90fb3451 350 #ifdef DEBUG_ON
phonemacro 10:0b940aff3bb8 351 printf("\r\n Formatted Response\r\n\r\n");
phonemacro 21:0a4f90fb3451 352 #endif
phonemacro 10:0b940aff3bb8 353 for (i = 0; i < responseLen32; i++) {
phonemacro 21:0a4f90fb3451 354 #ifdef DEBUG_ON
phonemacro 10:0b940aff3bb8 355 printf(" %08X \r\n",x32Data[i]);
phonemacro 21:0a4f90fb3451 356 #endif
phonemacro 16:d0f8cf9f160d 357 response[i] = x32Data[i];
phonemacro 10:0b940aff3bb8 358 }
phonemacro 22:1be3a5f0223e 359 }