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
web-this/system/web-system-html.c@69:ca9010196c6e, 2019-08-20 (annotated)
- Committer:
- andrewboyson
- Date:
- Tue Aug 20 14:51:28 2019 +0000
- Revision:
- 69:ca9010196c6e
- Parent:
- 68:19c5efffc900
- Child:
- 70:c7d0d3d926e1
Updated libraries
Who changed what in which revision?
User | Revision | Line number | New 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 | 67:2d379b0c5f05 | 9 | #include "sha-256.h" |
andrewboyson | 69:ca9010196c6e | 10 | #include "sha256.h" |
andrewboyson | 67:2d379b0c5f05 | 11 | #include "hmac-sha-256.h" |
andrewboyson | 69:ca9010196c6e | 12 | #include "tls-prf.h" |
andrewboyson | 49:9491c966dc60 | 13 | |
andrewboyson | 49:9491c966dc60 | 14 | void WebSystemHtml() |
andrewboyson | 49:9491c966dc60 | 15 | { |
andrewboyson | 49:9491c966dc60 | 16 | HttpOk("text/html; charset=UTF-8", "no-cache", NULL, NULL); |
andrewboyson | 51:c7c6ce0d57ad | 17 | WebAddHeader("System", "settings.css", "system.js"); |
andrewboyson | 51:c7c6ce0d57ad | 18 | WebAddNav(SYSTEM_PAGE); |
andrewboyson | 51:c7c6ce0d57ad | 19 | WebAddH1("System"); |
andrewboyson | 49:9491c966dc60 | 20 | |
andrewboyson | 51:c7c6ce0d57ad | 21 | WebAddH2("TFTP"); |
andrewboyson | 51:c7c6ce0d57ad | 22 | WebAddAjaxInput ("Server url", 5, "ajax-server-name", "tftpserver" ); |
andrewboyson | 51:c7c6ce0d57ad | 23 | WebAddAjaxInput ("File (strftime)", 11, "ajax-file-name", "tftpfilename" ); |
andrewboyson | 51:c7c6ce0d57ad | 24 | WebAddAjaxInput ("Interval (secs) 0=no", 5, "ajax-read-interval", "tftpreadint" ); |
andrewboyson | 51:c7c6ce0d57ad | 25 | WebAddAjaxInput ("Records per backup 0=no", 5, "ajax-write-size", "tftpwriteint" ); |
andrewboyson | 51:c7c6ce0d57ad | 26 | WebAddAjaxLabelled("Count", "ajax-count" ); |
andrewboyson | 51:c7c6ce0d57ad | 27 | WebAddAjaxLabelled("Started", "ajax-start-time" ); |
andrewboyson | 49:9491c966dc60 | 28 | |
andrewboyson | 51:c7c6ce0d57ad | 29 | WebAddH2("FRAM"); |
andrewboyson | 51:c7c6ce0d57ad | 30 | WebAddAjaxLabelled("Used", "ajax-fram-used" ); |
andrewboyson | 49:9491c966dc60 | 31 | |
andrewboyson | 51:c7c6ce0d57ad | 32 | WebAddH2("Compiler"); |
andrewboyson | 51:c7c6ce0d57ad | 33 | WebAddLabelledInt("Version Vvvbbbb", __ARMCC_VERSION); |
andrewboyson | 49:9491c966dc60 | 34 | |
andrewboyson | 67:2d379b0c5f05 | 35 | WebAddH2("SHA 256 test"); |
andrewboyson | 69:ca9010196c6e | 36 | uint8_t hash[32]; |
andrewboyson | 69:ca9010196c6e | 37 | char* input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"; |
andrewboyson | 69:ca9010196c6e | 38 | Sha256Old((uint8_t*)input, strlen(input), hash); |
andrewboyson | 67:2d379b0c5f05 | 39 | HttpAddText("<code>"); |
andrewboyson | 69:ca9010196c6e | 40 | HttpAddBytesAsHex((char*)hash, sizeof(hash)); |
andrewboyson | 69:ca9010196c6e | 41 | HttpAddText("</code>"); |
andrewboyson | 69:ca9010196c6e | 42 | |
andrewboyson | 69:ca9010196c6e | 43 | WebAddH2("SHA 256 stream test"); |
andrewboyson | 69:ca9010196c6e | 44 | struct Sha256State sha256state; |
andrewboyson | 69:ca9010196c6e | 45 | Sha256Start (&sha256state); |
andrewboyson | 69:ca9010196c6e | 46 | Sha256Add (&sha256state, (uint8_t*)input, strlen(input)); |
andrewboyson | 69:ca9010196c6e | 47 | Sha256Finish(&sha256state, (uint8_t*)hash); |
andrewboyson | 69:ca9010196c6e | 48 | |
andrewboyson | 69:ca9010196c6e | 49 | HttpAddText("<code>"); |
andrewboyson | 69:ca9010196c6e | 50 | HttpAddBytesAsHex((char*)hash, sizeof(hash)); |
andrewboyson | 67:2d379b0c5f05 | 51 | HttpAddText("</code>"); |
andrewboyson | 67:2d379b0c5f05 | 52 | |
andrewboyson | 67:2d379b0c5f05 | 53 | WebAddH2("HMAC SHA 256 test"); |
andrewboyson | 67:2d379b0c5f05 | 54 | char* key = "Jefe"; |
andrewboyson | 67:2d379b0c5f05 | 55 | char* msg = "what do ya want for nothing?"; |
andrewboyson | 69:ca9010196c6e | 56 | uint8_t mac[32]; |
andrewboyson | 69:ca9010196c6e | 57 | HmacSha256((uint8_t*)key, strlen(key), (uint8_t*)msg, strlen(msg), mac); |
andrewboyson | 69:ca9010196c6e | 58 | HttpAddText("<code>"); |
andrewboyson | 69:ca9010196c6e | 59 | HttpAddBytesAsHex((char*)mac, sizeof(mac)); |
andrewboyson | 69:ca9010196c6e | 60 | HttpAddText("</code>"); |
andrewboyson | 69:ca9010196c6e | 61 | |
andrewboyson | 69:ca9010196c6e | 62 | WebAddH2("HMAC SHA 256 stream test"); |
andrewboyson | 69:ca9010196c6e | 63 | struct HmacSha256Struct hmacState; |
andrewboyson | 69:ca9010196c6e | 64 | HmacSha256Start (&hmacState, (uint8_t*)key, strlen(key)); |
andrewboyson | 69:ca9010196c6e | 65 | HmacSha256Add (&hmacState, (uint8_t*)msg, strlen(msg)); |
andrewboyson | 69:ca9010196c6e | 66 | HmacSha256Finish(&hmacState, mac); |
andrewboyson | 67:2d379b0c5f05 | 67 | HttpAddText("<code>"); |
andrewboyson | 69:ca9010196c6e | 68 | HttpAddBytesAsHex((char*)mac, sizeof(mac)); |
andrewboyson | 67:2d379b0c5f05 | 69 | HttpAddText("</code>"); |
andrewboyson | 67:2d379b0c5f05 | 70 | |
andrewboyson | 69:ca9010196c6e | 71 | WebAddH2("Verify data test"); |
andrewboyson | 69:ca9010196c6e | 72 | uint8_t masterSecret [48] = {0x91, 0x6a, 0xbf, 0x9d, 0xa5, 0x59, 0x73, 0xe1, |
andrewboyson | 69:ca9010196c6e | 73 | 0x36, 0x14, 0xae, 0x0a, 0x3f, 0x5d, 0x3f, 0x37, |
andrewboyson | 69:ca9010196c6e | 74 | 0xb0, 0x23, 0xba, 0x12, 0x9a, 0xee, 0x02, 0xcc, |
andrewboyson | 69:ca9010196c6e | 75 | 0x91, 0x34, 0x33, 0x81, 0x27, 0xcd, 0x70, 0x49, |
andrewboyson | 69:ca9010196c6e | 76 | 0x78, 0x1c, 0x8e, 0x19, 0xfc, 0x1e, 0xb2, 0xa7, |
andrewboyson | 69:ca9010196c6e | 77 | 0x38, 0x7a, 0xc0, 0x6a, 0xe2, 0x37, 0x34, 0x4c}; |
andrewboyson | 69:ca9010196c6e | 78 | |
andrewboyson | 69:ca9010196c6e | 79 | uint8_t hashHandshakes[32] = {0xb2, 0x01, 0x7b, 0xa2, 0x8d, 0x0e, 0x27, 0xf0, |
andrewboyson | 69:ca9010196c6e | 80 | 0x3a, 0xe3, 0x27, 0x45, 0x6b, 0x6f, 0xf0, 0x0b, |
andrewboyson | 69:ca9010196c6e | 81 | 0x4d, 0x5b, 0xbf, 0x0e, 0xf7, 0xcd, 0xa8, 0x3c, |
andrewboyson | 69:ca9010196c6e | 82 | 0xe1, 0x02, 0x9b, 0x52, 0x1c, 0x3e, 0x7c, 0x35}; |
andrewboyson | 69:ca9010196c6e | 83 | uint8_t verifyData[12]; |
andrewboyson | 69:ca9010196c6e | 84 | TlsPrfServerFinished12(masterSecret, hashHandshakes, verifyData); |
andrewboyson | 69:ca9010196c6e | 85 | |
andrewboyson | 69:ca9010196c6e | 86 | HttpAddText("<code>"); |
andrewboyson | 69:ca9010196c6e | 87 | HttpAddBytesAsHex((char*)verifyData, sizeof(verifyData)); |
andrewboyson | 69:ca9010196c6e | 88 | HttpAddText("</code>"); |
andrewboyson | 69:ca9010196c6e | 89 | |
andrewboyson | 69:ca9010196c6e | 90 | |
andrewboyson | 69:ca9010196c6e | 91 | |
andrewboyson | 63:ae264156d655 | 92 | WebAddH2("Big num test"); |
andrewboyson | 63:ae264156d655 | 93 | |
andrewboyson | 63:ae264156d655 | 94 | char* n = |
andrewboyson | 63:ae264156d655 | 95 | "E08973398DD8F5F5E88776397F4EB005BB5383DE0FB7ABDC7DC775290D052E6D" |
andrewboyson | 63:ae264156d655 | 96 | "12DFA68626D4D26FAA5829FC97ECFA82510F3080BEB1509E4644F12CBBD832CF" |
andrewboyson | 63:ae264156d655 | 97 | "C6686F07D9B060ACBEEE34096A13F5F7050593DF5EBA3556D961FF197FC981E6" |
andrewboyson | 63:ae264156d655 | 98 | "F86CEA874070EFAC6D2C749F2DFA553AB9997702A648528C4EF357385774575F"; |
andrewboyson | 63:ae264156d655 | 99 | |
andrewboyson | 63:ae264156d655 | 100 | char* d = |
andrewboyson | 63:ae264156d655 | 101 | "00A403C327477634346CA686B57949014B2E8AD2C862B2C7D748096A8B91F736" |
andrewboyson | 63:ae264156d655 | 102 | "F275D6E8CD15906027314735644D95CD6763CEB49F56AC2F376E1CEE0EBF282D" |
andrewboyson | 63:ae264156d655 | 103 | "F439906F34D86E085BD5656AD841F313D72D395EFE33CBFF29E4030B3D05A28F" |
andrewboyson | 63:ae264156d655 | 104 | "B7F18EA27637B07957D32F2BDE8706227D04665EC91BAF8B1AC3EC9144AB7F21"; |
andrewboyson | 64:c736b8924574 | 105 | |
andrewboyson | 63:ae264156d655 | 106 | char* m = |
andrewboyson | 63:ae264156d655 | 107 | "0001FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" |
andrewboyson | 63:ae264156d655 | 108 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" |
andrewboyson | 63:ae264156d655 | 109 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00302130" |
andrewboyson | 63:ae264156d655 | 110 | "0906052B0E03021A05000414A9993E364706816ABA3E25717850C26C9CD0D89D"; |
andrewboyson | 49:9491c966dc60 | 111 | |
andrewboyson | 64:c736b8924574 | 112 | uint32_t message [32]; |
andrewboyson | 64:c736b8924574 | 113 | uint32_t exponent[32]; |
andrewboyson | 64:c736b8924574 | 114 | uint32_t modulus [32]; |
andrewboyson | 63:ae264156d655 | 115 | |
andrewboyson | 64:c736b8924574 | 116 | BnParseHex1024(message, m); |
andrewboyson | 64:c736b8924574 | 117 | BnParseHex1024(exponent, d); |
andrewboyson | 64:c736b8924574 | 118 | BnParseHex1024(modulus, n); |
andrewboyson | 63:ae264156d655 | 119 | |
andrewboyson | 68:19c5efffc900 | 120 | static int ticket = 0; |
andrewboyson | 63:ae264156d655 | 121 | |
andrewboyson | 63:ae264156d655 | 122 | static bool started = false; |
andrewboyson | 63:ae264156d655 | 123 | if (!started) |
andrewboyson | 63:ae264156d655 | 124 | { |
andrewboyson | 68:19c5efffc900 | 125 | ticket = BnExpModStart(message, exponent, modulus); |
andrewboyson | 63:ae264156d655 | 126 | started = true; |
andrewboyson | 63:ae264156d655 | 127 | } |
andrewboyson | 63:ae264156d655 | 128 | |
andrewboyson | 63:ae264156d655 | 129 | HttpAddText("<code>"); |
andrewboyson | 63:ae264156d655 | 130 | HttpAddText("Message\r\n"); |
andrewboyson | 64:c736b8924574 | 131 | BnAsHttp1024(message); |
andrewboyson | 63:ae264156d655 | 132 | HttpAddText("\r\nExponent\r\n"); |
andrewboyson | 64:c736b8924574 | 133 | BnAsHttp1024(exponent); |
andrewboyson | 63:ae264156d655 | 134 | HttpAddText("\r\nModulus\r\n"); |
andrewboyson | 64:c736b8924574 | 135 | BnAsHttp1024(modulus); |
andrewboyson | 63:ae264156d655 | 136 | HttpAddText("\r\nResult\r\n"); |
andrewboyson | 68:19c5efffc900 | 137 | if (ticket >= 0) |
andrewboyson | 63:ae264156d655 | 138 | { |
andrewboyson | 68:19c5efffc900 | 139 | switch(BnExpModStatus[ticket]) |
andrewboyson | 68:19c5efffc900 | 140 | { |
andrewboyson | 68:19c5efffc900 | 141 | case BIGNUM_CALC_NONE: |
andrewboyson | 68:19c5efffc900 | 142 | HttpAddText("Not started\r\n"); |
andrewboyson | 68:19c5efffc900 | 143 | break; |
andrewboyson | 68:19c5efffc900 | 144 | case BIGNUM_CALC_STARTED: |
andrewboyson | 68:19c5efffc900 | 145 | HttpAddF("Progress %d\r\n", BnExpModProgress[ticket]); |
andrewboyson | 68:19c5efffc900 | 146 | BnAsHttp1024(BnExpModGetResult(ticket)); |
andrewboyson | 68:19c5efffc900 | 147 | break; |
andrewboyson | 68:19c5efffc900 | 148 | case BIGNUM_CALC_FINISHED: |
andrewboyson | 68:19c5efffc900 | 149 | HttpAddText("Finished\r\n"); |
andrewboyson | 68:19c5efffc900 | 150 | BnAsHttp1024(BnExpModGetResult(ticket)); |
andrewboyson | 68:19c5efffc900 | 151 | HttpAddF("Time to multiply %llu ms\r\n", BnMulHr[ticket] / 96000); |
andrewboyson | 68:19c5efffc900 | 152 | HttpAddF("Time to modulus %llu ms\r\n", BnModHr[ticket] / 96000); |
andrewboyson | 68:19c5efffc900 | 153 | break; |
andrewboyson | 68:19c5efffc900 | 154 | } |
andrewboyson | 68:19c5efffc900 | 155 | } |
andrewboyson | 68:19c5efffc900 | 156 | else |
andrewboyson | 68:19c5efffc900 | 157 | { |
andrewboyson | 68:19c5efffc900 | 158 | HttpAddText("No ticket available to calculate result\r\n"); |
andrewboyson | 63:ae264156d655 | 159 | } |
andrewboyson | 63:ae264156d655 | 160 | HttpAddText("</code>"); |
andrewboyson | 63:ae264156d655 | 161 | |
andrewboyson | 63:ae264156d655 | 162 | WebAddEnd(); |
andrewboyson | 49:9491c966dc60 | 163 | } |