Central Heating controller using the real time clock, PHY module for internet, 1-wire interface for temperature sensors, a system log and a configuration file

Dependencies:   net 1-wire lpc1768 crypto clock web fram log

/media/uploads/andrewboyson/heating.sch

/media/uploads/andrewboyson/heating.brd

/media/uploads/andrewboyson/eagle.epf

Committer:
andrewboyson
Date:
Sun Sep 01 18:15:50 2019 +0000
Revision:
71:9edbc59d6f64
Parent:
70:c7d0d3d926e1
Child:
72:13bc405bd40b
Updated libraries

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 49:9491c966dc60 1 #include <stdio.h>
andrewboyson 67:2d379b0c5f05 2 #include <string.h>
andrewboyson 49:9491c966dc60 3
andrewboyson 49:9491c966dc60 4 #include "http.h"
andrewboyson 53:c1bf7d9db507 5 #include "web-nav-this.h"
andrewboyson 51:c7c6ce0d57ad 6 #include "web-add.h"
andrewboyson 67:2d379b0c5f05 7 #include "log.h"
andrewboyson 63:ae264156d655 8 #include "bignum.h"
andrewboyson 69:ca9010196c6e 9 #include "sha256.h"
andrewboyson 67:2d379b0c5f05 10 #include "hmac-sha-256.h"
andrewboyson 69:ca9010196c6e 11 #include "tls-prf.h"
andrewboyson 71:9edbc59d6f64 12 #include "aes128.h"
andrewboyson 71:9edbc59d6f64 13 #include "sha1.h"
andrewboyson 49:9491c966dc60 14
andrewboyson 49:9491c966dc60 15 void WebSystemHtml()
andrewboyson 49:9491c966dc60 16 {
andrewboyson 49:9491c966dc60 17 HttpOk("text/html; charset=UTF-8", "no-cache", NULL, NULL);
andrewboyson 51:c7c6ce0d57ad 18 WebAddHeader("System", "settings.css", "system.js");
andrewboyson 51:c7c6ce0d57ad 19 WebAddNav(SYSTEM_PAGE);
andrewboyson 51:c7c6ce0d57ad 20 WebAddH1("System");
andrewboyson 49:9491c966dc60 21
andrewboyson 51:c7c6ce0d57ad 22 WebAddH2("TFTP");
andrewboyson 51:c7c6ce0d57ad 23 WebAddAjaxInput ("Server url", 5, "ajax-server-name", "tftpserver" );
andrewboyson 51:c7c6ce0d57ad 24 WebAddAjaxInput ("File (strftime)", 11, "ajax-file-name", "tftpfilename" );
andrewboyson 51:c7c6ce0d57ad 25 WebAddAjaxInput ("Interval (secs) 0=no", 5, "ajax-read-interval", "tftpreadint" );
andrewboyson 51:c7c6ce0d57ad 26 WebAddAjaxInput ("Records per backup 0=no", 5, "ajax-write-size", "tftpwriteint" );
andrewboyson 51:c7c6ce0d57ad 27 WebAddAjaxLabelled("Count", "ajax-count" );
andrewboyson 51:c7c6ce0d57ad 28 WebAddAjaxLabelled("Started", "ajax-start-time" );
andrewboyson 49:9491c966dc60 29
andrewboyson 51:c7c6ce0d57ad 30 WebAddH2("FRAM");
andrewboyson 51:c7c6ce0d57ad 31 WebAddAjaxLabelled("Used", "ajax-fram-used" );
andrewboyson 49:9491c966dc60 32
andrewboyson 51:c7c6ce0d57ad 33 WebAddH2("Compiler");
andrewboyson 51:c7c6ce0d57ad 34 WebAddLabelledInt("Version Vvvbbbb", __ARMCC_VERSION);
andrewboyson 71:9edbc59d6f64 35
andrewboyson 71:9edbc59d6f64 36 WebAddH2("AES 128 test");
andrewboyson 71:9edbc59d6f64 37 uint8_t aeskey[] = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c };
andrewboyson 71:9edbc59d6f64 38 uint8_t in[] = { 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46, 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
andrewboyson 71:9edbc59d6f64 39 0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee, 0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2,
andrewboyson 71:9edbc59d6f64 40 0x73, 0xbe, 0xd6, 0xb8, 0xe3, 0xc1, 0x74, 0x3b, 0x71, 0x16, 0xe6, 0x9e, 0x22, 0x22, 0x95, 0x16,
andrewboyson 71:9edbc59d6f64 41 0x3f, 0xf1, 0xca, 0xa1, 0x68, 0x1f, 0xac, 0x09, 0x12, 0x0e, 0xca, 0x30, 0x75, 0x86, 0xe1, 0xa7 };
andrewboyson 71:9edbc59d6f64 42 uint8_t iv[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
andrewboyson 71:9edbc59d6f64 43 /*
andrewboyson 71:9edbc59d6f64 44 uint8_t out[] = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
andrewboyson 71:9edbc59d6f64 45 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
andrewboyson 71:9edbc59d6f64 46 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
andrewboyson 71:9edbc59d6f64 47 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 };
andrewboyson 71:9edbc59d6f64 48 */
andrewboyson 71:9edbc59d6f64 49 struct AES_ctx ctx;
andrewboyson 71:9edbc59d6f64 50
andrewboyson 71:9edbc59d6f64 51 AES_init_ctx_iv(&ctx, aeskey, iv);
andrewboyson 71:9edbc59d6f64 52 AES_CBC_decrypt_buffer(&ctx, in, 64);
andrewboyson 67:2d379b0c5f05 53 HttpAddText("<code>");
andrewboyson 71:9edbc59d6f64 54 HttpAddBytesAsHex(in, sizeof(in));
andrewboyson 69:ca9010196c6e 55 HttpAddText("</code>");
andrewboyson 69:ca9010196c6e 56
andrewboyson 69:ca9010196c6e 57 WebAddH2("SHA 256 stream test");
andrewboyson 71:9edbc59d6f64 58 uint8_t hash[32];
andrewboyson 71:9edbc59d6f64 59 char* input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
andrewboyson 69:ca9010196c6e 60 struct Sha256State sha256state;
andrewboyson 69:ca9010196c6e 61 Sha256Start (&sha256state);
andrewboyson 69:ca9010196c6e 62 Sha256Add (&sha256state, (uint8_t*)input, strlen(input));
andrewboyson 69:ca9010196c6e 63 Sha256Finish(&sha256state, (uint8_t*)hash);
andrewboyson 69:ca9010196c6e 64
andrewboyson 69:ca9010196c6e 65 HttpAddText("<code>");
andrewboyson 70:c7d0d3d926e1 66 HttpAddBytesAsHex(hash, sizeof(hash));
andrewboyson 67:2d379b0c5f05 67 HttpAddText("</code>");
andrewboyson 67:2d379b0c5f05 68
andrewboyson 71:9edbc59d6f64 69 WebAddH2("SHA1 stream test");
andrewboyson 71:9edbc59d6f64 70 struct sha1_ctx sha1state;
andrewboyson 71:9edbc59d6f64 71 sha1_init (&sha1state);
andrewboyson 71:9edbc59d6f64 72 sha1_update(&sha1state, (uint8_t*)input, strlen(input));
andrewboyson 71:9edbc59d6f64 73 sha1_final (&sha1state);
andrewboyson 71:9edbc59d6f64 74
andrewboyson 71:9edbc59d6f64 75 HttpAddText("<code>");
andrewboyson 71:9edbc59d6f64 76 HttpAddBytesAsHex(sha1state.buf.b, 20);
andrewboyson 71:9edbc59d6f64 77 HttpAddText("</code>");
andrewboyson 71:9edbc59d6f64 78
andrewboyson 67:2d379b0c5f05 79 WebAddH2("HMAC SHA 256 test");
andrewboyson 67:2d379b0c5f05 80 char* key = "Jefe";
andrewboyson 67:2d379b0c5f05 81 char* msg = "what do ya want for nothing?";
andrewboyson 69:ca9010196c6e 82 uint8_t mac[32];
andrewboyson 69:ca9010196c6e 83 HmacSha256((uint8_t*)key, strlen(key), (uint8_t*)msg, strlen(msg), mac);
andrewboyson 69:ca9010196c6e 84 HttpAddText("<code>");
andrewboyson 70:c7d0d3d926e1 85 HttpAddBytesAsHex(mac, sizeof(mac));
andrewboyson 69:ca9010196c6e 86 HttpAddText("</code>");
andrewboyson 69:ca9010196c6e 87
andrewboyson 69:ca9010196c6e 88 WebAddH2("HMAC SHA 256 stream test");
andrewboyson 69:ca9010196c6e 89 struct HmacSha256Struct hmacState;
andrewboyson 69:ca9010196c6e 90 HmacSha256Start (&hmacState, (uint8_t*)key, strlen(key));
andrewboyson 69:ca9010196c6e 91 HmacSha256Add (&hmacState, (uint8_t*)msg, strlen(msg));
andrewboyson 69:ca9010196c6e 92 HmacSha256Finish(&hmacState, mac);
andrewboyson 67:2d379b0c5f05 93 HttpAddText("<code>");
andrewboyson 70:c7d0d3d926e1 94 HttpAddBytesAsHex(mac, sizeof(mac));
andrewboyson 67:2d379b0c5f05 95 HttpAddText("</code>");
andrewboyson 67:2d379b0c5f05 96
andrewboyson 69:ca9010196c6e 97 WebAddH2("Verify data test");
andrewboyson 69:ca9010196c6e 98 uint8_t masterSecret [48] = {0x91, 0x6a, 0xbf, 0x9d, 0xa5, 0x59, 0x73, 0xe1,
andrewboyson 69:ca9010196c6e 99 0x36, 0x14, 0xae, 0x0a, 0x3f, 0x5d, 0x3f, 0x37,
andrewboyson 69:ca9010196c6e 100 0xb0, 0x23, 0xba, 0x12, 0x9a, 0xee, 0x02, 0xcc,
andrewboyson 69:ca9010196c6e 101 0x91, 0x34, 0x33, 0x81, 0x27, 0xcd, 0x70, 0x49,
andrewboyson 69:ca9010196c6e 102 0x78, 0x1c, 0x8e, 0x19, 0xfc, 0x1e, 0xb2, 0xa7,
andrewboyson 69:ca9010196c6e 103 0x38, 0x7a, 0xc0, 0x6a, 0xe2, 0x37, 0x34, 0x4c};
andrewboyson 69:ca9010196c6e 104
andrewboyson 69:ca9010196c6e 105 uint8_t hashHandshakes[32] = {0xb2, 0x01, 0x7b, 0xa2, 0x8d, 0x0e, 0x27, 0xf0,
andrewboyson 69:ca9010196c6e 106 0x3a, 0xe3, 0x27, 0x45, 0x6b, 0x6f, 0xf0, 0x0b,
andrewboyson 69:ca9010196c6e 107 0x4d, 0x5b, 0xbf, 0x0e, 0xf7, 0xcd, 0xa8, 0x3c,
andrewboyson 69:ca9010196c6e 108 0xe1, 0x02, 0x9b, 0x52, 0x1c, 0x3e, 0x7c, 0x35};
andrewboyson 69:ca9010196c6e 109 uint8_t verifyData[12];
andrewboyson 71:9edbc59d6f64 110 TlsPrfServerFinished(masterSecret, hashHandshakes, verifyData);
andrewboyson 69:ca9010196c6e 111
andrewboyson 69:ca9010196c6e 112 HttpAddText("<code>");
andrewboyson 70:c7d0d3d926e1 113 HttpAddBytesAsHex(verifyData, sizeof(verifyData));
andrewboyson 69:ca9010196c6e 114 HttpAddText("</code>");
andrewboyson 69:ca9010196c6e 115
andrewboyson 69:ca9010196c6e 116
andrewboyson 71:9edbc59d6f64 117 WebAddH2("Key test");
andrewboyson 71:9edbc59d6f64 118
andrewboyson 71:9edbc59d6f64 119 uint8_t clientRandom[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
andrewboyson 71:9edbc59d6f64 120 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
andrewboyson 71:9edbc59d6f64 121 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
andrewboyson 71:9edbc59d6f64 122 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f };
andrewboyson 71:9edbc59d6f64 123
andrewboyson 71:9edbc59d6f64 124 uint8_t serverRandom[] = { 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
andrewboyson 71:9edbc59d6f64 125 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
andrewboyson 71:9edbc59d6f64 126 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
andrewboyson 71:9edbc59d6f64 127 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f };
andrewboyson 71:9edbc59d6f64 128
andrewboyson 71:9edbc59d6f64 129 uint8_t client_MAC_key_20[20];
andrewboyson 71:9edbc59d6f64 130 uint8_t server_MAC_key_20[20];
andrewboyson 71:9edbc59d6f64 131 uint8_t client_key_16[16];
andrewboyson 71:9edbc59d6f64 132 uint8_t server_key_16[16];
andrewboyson 71:9edbc59d6f64 133 TlsPrfKeys(masterSecret, clientRandom, serverRandom, client_MAC_key_20, server_MAC_key_20, client_key_16, server_key_16);
andrewboyson 71:9edbc59d6f64 134 HttpAddText("<code>");
andrewboyson 71:9edbc59d6f64 135 HttpAddBytesAsHex(client_MAC_key_20, sizeof(client_MAC_key_20));
andrewboyson 71:9edbc59d6f64 136 HttpAddBytesAsHex(server_MAC_key_20, sizeof(server_MAC_key_20));
andrewboyson 71:9edbc59d6f64 137 HttpAddBytesAsHex(client_key_16, sizeof(client_key_16));
andrewboyson 71:9edbc59d6f64 138 HttpAddBytesAsHex(server_key_16, sizeof(server_key_16));
andrewboyson 71:9edbc59d6f64 139 HttpAddText("</code>");
andrewboyson 71:9edbc59d6f64 140
andrewboyson 71:9edbc59d6f64 141
andrewboyson 69:ca9010196c6e 142
andrewboyson 63:ae264156d655 143 WebAddH2("Big num test");
andrewboyson 63:ae264156d655 144
andrewboyson 63:ae264156d655 145 char* n =
andrewboyson 63:ae264156d655 146 "E08973398DD8F5F5E88776397F4EB005BB5383DE0FB7ABDC7DC775290D052E6D"
andrewboyson 63:ae264156d655 147 "12DFA68626D4D26FAA5829FC97ECFA82510F3080BEB1509E4644F12CBBD832CF"
andrewboyson 63:ae264156d655 148 "C6686F07D9B060ACBEEE34096A13F5F7050593DF5EBA3556D961FF197FC981E6"
andrewboyson 63:ae264156d655 149 "F86CEA874070EFAC6D2C749F2DFA553AB9997702A648528C4EF357385774575F";
andrewboyson 63:ae264156d655 150
andrewboyson 63:ae264156d655 151 char* d =
andrewboyson 63:ae264156d655 152 "00A403C327477634346CA686B57949014B2E8AD2C862B2C7D748096A8B91F736"
andrewboyson 63:ae264156d655 153 "F275D6E8CD15906027314735644D95CD6763CEB49F56AC2F376E1CEE0EBF282D"
andrewboyson 63:ae264156d655 154 "F439906F34D86E085BD5656AD841F313D72D395EFE33CBFF29E4030B3D05A28F"
andrewboyson 63:ae264156d655 155 "B7F18EA27637B07957D32F2BDE8706227D04665EC91BAF8B1AC3EC9144AB7F21";
andrewboyson 64:c736b8924574 156
andrewboyson 63:ae264156d655 157 char* m =
andrewboyson 63:ae264156d655 158 "0001FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
andrewboyson 63:ae264156d655 159 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
andrewboyson 63:ae264156d655 160 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00302130"
andrewboyson 63:ae264156d655 161 "0906052B0E03021A05000414A9993E364706816ABA3E25717850C26C9CD0D89D";
andrewboyson 49:9491c966dc60 162
andrewboyson 64:c736b8924574 163 uint32_t message [32];
andrewboyson 64:c736b8924574 164 uint32_t exponent[32];
andrewboyson 64:c736b8924574 165 uint32_t modulus [32];
andrewboyson 63:ae264156d655 166
andrewboyson 64:c736b8924574 167 BnParseHex1024(message, m);
andrewboyson 64:c736b8924574 168 BnParseHex1024(exponent, d);
andrewboyson 64:c736b8924574 169 BnParseHex1024(modulus, n);
andrewboyson 63:ae264156d655 170
andrewboyson 68:19c5efffc900 171 static int ticket = 0;
andrewboyson 63:ae264156d655 172
andrewboyson 63:ae264156d655 173 static bool started = false;
andrewboyson 63:ae264156d655 174 if (!started)
andrewboyson 63:ae264156d655 175 {
andrewboyson 68:19c5efffc900 176 ticket = BnExpModStart(message, exponent, modulus);
andrewboyson 63:ae264156d655 177 started = true;
andrewboyson 63:ae264156d655 178 }
andrewboyson 63:ae264156d655 179
andrewboyson 63:ae264156d655 180 HttpAddText("<code>");
andrewboyson 63:ae264156d655 181 HttpAddText("Message\r\n");
andrewboyson 64:c736b8924574 182 BnAsHttp1024(message);
andrewboyson 63:ae264156d655 183 HttpAddText("\r\nExponent\r\n");
andrewboyson 64:c736b8924574 184 BnAsHttp1024(exponent);
andrewboyson 63:ae264156d655 185 HttpAddText("\r\nModulus\r\n");
andrewboyson 64:c736b8924574 186 BnAsHttp1024(modulus);
andrewboyson 63:ae264156d655 187 HttpAddText("\r\nResult\r\n");
andrewboyson 68:19c5efffc900 188 if (ticket >= 0)
andrewboyson 63:ae264156d655 189 {
andrewboyson 68:19c5efffc900 190 switch(BnExpModStatus[ticket])
andrewboyson 68:19c5efffc900 191 {
andrewboyson 68:19c5efffc900 192 case BIGNUM_CALC_NONE:
andrewboyson 68:19c5efffc900 193 HttpAddText("Not started\r\n");
andrewboyson 68:19c5efffc900 194 break;
andrewboyson 68:19c5efffc900 195 case BIGNUM_CALC_STARTED:
andrewboyson 68:19c5efffc900 196 HttpAddF("Progress %d\r\n", BnExpModProgress[ticket]);
andrewboyson 68:19c5efffc900 197 BnAsHttp1024(BnExpModGetResult(ticket));
andrewboyson 68:19c5efffc900 198 break;
andrewboyson 68:19c5efffc900 199 case BIGNUM_CALC_FINISHED:
andrewboyson 68:19c5efffc900 200 HttpAddText("Finished\r\n");
andrewboyson 68:19c5efffc900 201 BnAsHttp1024(BnExpModGetResult(ticket));
andrewboyson 68:19c5efffc900 202 HttpAddF("Time to multiply %llu ms\r\n", BnMulHr[ticket] / 96000);
andrewboyson 68:19c5efffc900 203 HttpAddF("Time to modulus %llu ms\r\n", BnModHr[ticket] / 96000);
andrewboyson 68:19c5efffc900 204 break;
andrewboyson 68:19c5efffc900 205 }
andrewboyson 68:19c5efffc900 206 }
andrewboyson 68:19c5efffc900 207 else
andrewboyson 68:19c5efffc900 208 {
andrewboyson 68:19c5efffc900 209 HttpAddText("No ticket available to calculate result\r\n");
andrewboyson 63:ae264156d655 210 }
andrewboyson 63:ae264156d655 211 HttpAddText("</code>");
andrewboyson 63:ae264156d655 212
andrewboyson 63:ae264156d655 213 WebAddEnd();
andrewboyson 49:9491c966dc60 214 }