intiial commit

Dependencies:   MAX8614X USBDevice max32630hsp_test

Committer:
phonemacro
Date:
Fri Aug 17 00:11:10 2018 +0000
Revision:
21:0a4f90fb3451
Parent:
20:39857996a7c7
Child:
22:1be3a5f0223e
Clean the code a little bit

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 16:d0f8cf9f160d 42 void executeSha256(MAX8614X &m, uint8_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 21:0a4f90fb3451 60 #define CHALLENGE8_LEN 20
phonemacro 21:0a4f90fb3451 61 uint8_t challenge_A[CHALLENGE8_LEN] = { // 160 bit, no ROM
phonemacro 15:2616528b4007 62 0x00, 0x00, 0x00, 0x01,
phonemacro 15:2616528b4007 63 0x00, 0x00, 0x00, 0x00,
phonemacro 15:2616528b4007 64 0x00, 0x00, 0x00, 0x00,
phonemacro 15:2616528b4007 65 0x00, 0x00, 0x00, 0x00,
phonemacro 15:2616528b4007 66 0x00, 0x00, 0x00, 0x00
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 21:0a4f90fb3451 78 uint8_t challenge_1[CHALLENGE8_LEN] = { // 160 bit
phonemacro 10:0b940aff3bb8 79 0x5e, 0x81, 0x35, 0x24,
phonemacro 10:0b940aff3bb8 80 0x56, 0x63, 0xd6, 0x09,
phonemacro 10:0b940aff3bb8 81 0x99, 0x8d, 0x7b, 0x0d,
phonemacro 10:0b940aff3bb8 82 0x52, 0x12, 0x84, 0x65,
phonemacro 10:0b940aff3bb8 83 0xcd, 0x0d, 0xe3, 0x01
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 21:0a4f90fb3451 96 uint8_t challenge_2[CHALLENGE8_LEN] = { // 160 bit, no ROM
phonemacro 13:97854f761347 97 0xd2, 0xaa, 0x84, 0xc5,
phonemacro 13:97854f761347 98 0x72, 0x77, 0xf7, 0xe5,
phonemacro 13:97854f761347 99 0xdb, 0x8f, 0xd6, 0x12,
phonemacro 13:97854f761347 100 0x96, 0xce, 0x69, 0xf2,
phonemacro 13:97854f761347 101 0x4e, 0xc5, 0x7a, 0xe8
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 21:0a4f90fb3451 114 uint8_t challenge_3[CHALLENGE8_LEN] = { // 160 bit
phonemacro 20:39857996a7c7 115 0x21, 0x20, 0x22, 0x80,
phonemacro 20:39857996a7c7 116 0xcc, 0x9d, 0x45, 0xaa,
phonemacro 20:39857996a7c7 117 0xb8, 0x13, 0x3e, 0x96,
phonemacro 20:39857996a7c7 118 0xd6, 0x53, 0x38, 0x0d,
phonemacro 20:39857996a7c7 119 0x2a, 0xd5, 0xdd, 0x6b
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 21:0a4f90fb3451 131 uint8_t challenge_4[CHALLENGE8_LEN] = { // 160 bit, no ROM
phonemacro 20:39857996a7c7 132 0x4c, 0x3c, 0x0a, 0xca,
phonemacro 20:39857996a7c7 133 0x61, 0x8a, 0xbd, 0xf2,
phonemacro 20:39857996a7c7 134 0x34, 0xd8, 0xb3, 0x41,
phonemacro 20:39857996a7c7 135 0x12, 0x89, 0xf3, 0x78,
phonemacro 20:39857996a7c7 136 0x65, 0xb6, 0x0d, 0xeb
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 16:d0f8cf9f160d 148 uint32_t chip_response[RESPONSE_LEN32];
phonemacro 16:d0f8cf9f160d 149 bool valid = 0;
phonemacro 16:d0f8cf9f160d 150
phonemacro 7:5b7f7ec9efe0 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 21:0a4f90fb3451 161 executeSha256(m, challenge_A, CHALLENGE8_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 21:0a4f90fb3451 170 executeSha256(m, challenge_1, CHALLENGE8_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 21:0a4f90fb3451 178 executeSha256(m, challenge_2, CHALLENGE8_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 21:0a4f90fb3451 185 executeSha256(m, challenge_3, CHALLENGE8_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 21:0a4f90fb3451 192 executeSha256(m, challenge_4, CHALLENGE8_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 20:39857996a7c7 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 7:5b7f7ec9efe0 228
phonemacro 7:5b7f7ec9efe0 229
phonemacro 16:d0f8cf9f160d 230 void executeSha256(MAX8614X &m, uint8_t *challenge, unsigned int challengeLen, bool romID, uint32_t *response)
phonemacro 7:5b7f7ec9efe0 231 {
phonemacro 10:0b940aff3bb8 232 int i, j, k;
phonemacro 7:5b7f7ec9efe0 233 uint8_t macData[256];
phonemacro 7:5b7f7ec9efe0 234 uint8_t xData[256];
phonemacro 10:0b940aff3bb8 235 uint32_t x32Data[64];
phonemacro 7:5b7f7ec9efe0 236 uint32_t tmpData;
phonemacro 10:0b940aff3bb8 237 const unsigned int responseLen32 = 8;
phonemacro 7:5b7f7ec9efe0 238 uint8_t data[5];
phonemacro 11:ec7998257ec2 239
phonemacro 18:a0356b3e6ed9 240 //● Enable SHA_DONE Interrupt
phonemacro 7:5b7f7ec9efe0 241 m.writeRegister(MAX8614X::MAX8614X_INT_ENABLE2_REG, MAX8614X::MAX8614X_IE_SHA_DONE_EN);
phonemacro 7:5b7f7ec9efe0 242
phonemacro 7:5b7f7ec9efe0 243 m.writeRegister(MAX8614X::MAX8614X_INT_ENABLE1_REG, 0); // Disable all other interrupts
phonemacro 7:5b7f7ec9efe0 244
phonemacro 13:97854f761347 245 //- Enable SHA_EN bit.
phonemacro 7:5b7f7ec9efe0 246 m.writeRegister(MAX8614X::MAX8614X_SHA_CFG_REG,MAX8614X::MAX8614X_SHACFG_SHA_EN);
phonemacro 7:5b7f7ec9efe0 247
phonemacro 18:a0356b3e6ed9 248 //● Write 160-bit random challenge value to RAM using registers MEM_IDX and MEM_DATA.
phonemacro 7:5b7f7ec9efe0 249 // Enable Memory Write, Select Bank 0, address 0x00 to 0xFF
phonemacro 7:5b7f7ec9efe0 250 m.writeRegister(MAX8614X::MAX8614X_MEMORY_CONTROL_REG, MAX8614X::MAX8614X_MEMCNTRL_WR_EN_MASK | MAX8614X::MAX8614X_MEMCNTRL_BANK0_MASK);
phonemacro 7:5b7f7ec9efe0 251
phonemacro 21:0a4f90fb3451 252 #ifdef DEBUG_ON
phonemacro 7:5b7f7ec9efe0 253 printf("\r\n Raw Input Data\r\n\r\n");
phonemacro 7:5b7f7ec9efe0 254 for (i = 0; i < challengeLen; i++) {
phonemacro 10:0b940aff3bb8 255 if (!(i % 4))
phonemacro 10:0b940aff3bb8 256 printf("\r\n ");
phonemacro 10:0b940aff3bb8 257 printf("%02x", challenge[i]);
phonemacro 7:5b7f7ec9efe0 258 }
phonemacro 7:5b7f7ec9efe0 259 printf("\r\n");
phonemacro 10:0b940aff3bb8 260 #endif
phonemacro 10:0b940aff3bb8 261
phonemacro 10:0b940aff3bb8 262 transformData(challenge, xData, challengeLen);
phonemacro 7:5b7f7ec9efe0 263
phonemacro 21:0a4f90fb3451 264 #ifdef DEBUG_ON
phonemacro 7:5b7f7ec9efe0 265 printf("\r\n Transformed Input Data\r\n\r\n");
phonemacro 10:0b940aff3bb8 266 for (i = 0; i < challengeLen; i++) {
phonemacro 7:5b7f7ec9efe0 267 if (!(i % 4))
phonemacro 7:5b7f7ec9efe0 268 printf("\r\n ");
phonemacro 7:5b7f7ec9efe0 269 printf("%02x", xData[i]);
phonemacro 7:5b7f7ec9efe0 270 }
phonemacro 7:5b7f7ec9efe0 271 printf("\r\n ");
phonemacro 21:0a4f90fb3451 272 #endif
phonemacro 7:5b7f7ec9efe0 273
phonemacro 10:0b940aff3bb8 274 for (i = 0; i < (challengeLen); i++) {
phonemacro 7:5b7f7ec9efe0 275 m.writeRegister(MAX8614X::MAX8614X_MEMORY_INDEX_REG, i);
phonemacro 7:5b7f7ec9efe0 276 m.writeRegister(MAX8614X::MAX8614X_MEMORY_DATA_REG, xData[i]);
phonemacro 10:0b940aff3bb8 277 //}
phonemacro 10:0b940aff3bb8 278 }
phonemacro 21:0a4f90fb3451 279
phonemacro 7:5b7f7ec9efe0 280 // 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 281 // 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 282 // bits of ROM ID are programmable–8 bits each in metal and 8 bits each in OTP bits
phonemacro 21:0a4f90fb3451 283 //● Write command, with ROM ID (0x35) or without ROM ID (0x36), to SHA_CMD register
phonemacro 21:0a4f90fb3451 284 if (romID) {
phonemacro 12:fc888315e5fd 285 m.writeRegister(MAX8614X::MAX8614X_SHA_CMD_REG, MAX8614X::MAX8614X_SHACMD_MAC_ROM_ID);
phonemacro 21:0a4f90fb3451 286 }
phonemacro 12:fc888315e5fd 287 else
phonemacro 21:0a4f90fb3451 288 {
phonemacro 21:0a4f90fb3451 289 m.writeRegister(MAX8614X::MAX8614X_SHA_CMD_REG,MAX8614X::MAX8614X_SHACMD_MAC_NO_ROM_ID);
phonemacro 21:0a4f90fb3451 290 }
phonemacro 7:5b7f7ec9efe0 291
phonemacro 10:0b940aff3bb8 292 m.readRegister(MAX8614X::MAX8614X_SHA_CMD_REG, data, 1);
phonemacro 7:5b7f7ec9efe0 293 //● Write 1 to SHA_START and 1 to SHA_EN bit.
phonemacro 7:5b7f7ec9efe0 294 m.writeRegister(MAX8614X::MAX8614X_SHA_CFG_REG,MAX8614X::MAX8614X_SHACFG_SHA_EN | MAX8614X::MAX8614X_SHACFG_SHA_START);
phonemacro 7:5b7f7ec9efe0 295
phonemacro 18:a0356b3e6ed9 296 //● Wait for SHA_DONE.
phonemacro 7:5b7f7ec9efe0 297 data[0] = 0;
phonemacro 17:e260080d3468 298 k = 0;
phonemacro 17:e260080d3468 299 while(!data[0] && k < 100) {
phonemacro 7:5b7f7ec9efe0 300 m.readRegister(MAX8614X::MAX8614X_INT_STATUS2_REG, data, 1);
phonemacro 17:e260080d3468 301 k++;
phonemacro 7:5b7f7ec9efe0 302 }
phonemacro 7:5b7f7ec9efe0 303 // ● Read 256 MAC value from RAM using registers MEM_IDX and MEM_DATA.
phonemacro 21:0a4f90fb3451 304 #ifdef DEBUG_ON
phonemacro 10:0b940aff3bb8 305 printf("\r\n Raw Output\r\n\r\n");
phonemacro 21:0a4f90fb3451 306 #endif
phonemacro 7:5b7f7ec9efe0 307 for (i = 64; i < 64+32; i++) {
phonemacro 21:0a4f90fb3451 308 #ifdef DEBUG_ON
phonemacro 7:5b7f7ec9efe0 309 if (!(i % 4))
phonemacro 7:5b7f7ec9efe0 310 printf("\r\n ");
phonemacro 21:0a4f90fb3451 311 #endif
phonemacro 7:5b7f7ec9efe0 312 m.writeRegister(MAX8614X::MAX8614X_MEMORY_INDEX_REG, i);
phonemacro 7:5b7f7ec9efe0 313 m.readRegister(MAX8614X::MAX8614X_MEMORY_DATA_REG, data, 1);
phonemacro 10:0b940aff3bb8 314 xData[i-64] = data[0];
phonemacro 21:0a4f90fb3451 315 #ifdef DEBUG_ON
phonemacro 7:5b7f7ec9efe0 316 printf("%02x", data[0]);
phonemacro 21:0a4f90fb3451 317 #endif
phonemacro 7:5b7f7ec9efe0 318 }
phonemacro 21:0a4f90fb3451 319 #ifdef DEBUG_ON
phonemacro 10:0b940aff3bb8 320 printf("%\r\n");
phonemacro 21:0a4f90fb3451 321 #endif
phonemacro 10:0b940aff3bb8 322
phonemacro 10:0b940aff3bb8 323 transformData(xData,macData, 32);
phonemacro 21:0a4f90fb3451 324 #ifdef DEBUG_ON
phonemacro 10:0b940aff3bb8 325 printf("\r\n Formatted Response\r\n\r\n");
phonemacro 10:0b940aff3bb8 326 for (i = 0; i < 32; i++) {
phonemacro 10:0b940aff3bb8 327 if (!(i % 4))
phonemacro 10:0b940aff3bb8 328 printf("\r\n ");
phonemacro 10:0b940aff3bb8 329 printf("%02x", macData[i]);
phonemacro 10:0b940aff3bb8 330 }
phonemacro 10:0b940aff3bb8 331 printf("\r\n\r\n");
phonemacro 10:0b940aff3bb8 332
phonemacro 10:0b940aff3bb8 333 #endif
phonemacro 10:0b940aff3bb8 334 // transform data to Little-Endian
phonemacro 10:0b940aff3bb8 335 k = 0;
phonemacro 10:0b940aff3bb8 336 for (i = 0; i < (responseLen32); i++) {
phonemacro 10:0b940aff3bb8 337 x32Data[i] = 0;
phonemacro 10:0b940aff3bb8 338 for (j = 3; j >= 0; j--) {
phonemacro 10:0b940aff3bb8 339 x32Data[i] = x32Data[i] << 8;
phonemacro 10:0b940aff3bb8 340 x32Data[i] |= macData[k] & 0xFF;
phonemacro 10:0b940aff3bb8 341 k++;
phonemacro 10:0b940aff3bb8 342 }
phonemacro 10:0b940aff3bb8 343 }
phonemacro 10:0b940aff3bb8 344
phonemacro 21:0a4f90fb3451 345 #ifdef DEBUG_ON
phonemacro 10:0b940aff3bb8 346 printf("\r\n Formatted Response\r\n\r\n");
phonemacro 21:0a4f90fb3451 347 #endif
phonemacro 10:0b940aff3bb8 348 for (i = 0; i < responseLen32; i++) {
phonemacro 21:0a4f90fb3451 349 #ifdef DEBUG_ON
phonemacro 10:0b940aff3bb8 350 printf(" %08X \r\n",x32Data[i]);
phonemacro 21:0a4f90fb3451 351 #endif
phonemacro 16:d0f8cf9f160d 352 response[i] = x32Data[i];
phonemacro 10:0b940aff3bb8 353 }
phonemacro 7:5b7f7ec9efe0 354 }