├── LICENSE ├── README.md ├── examples ├── AWS-MQTT.c ├── CA-list.h ├── CSR.c ├── CertCheck.c ├── Chat-MQTT.c ├── LED-JSON.c ├── LED-SMQ.c ├── MultiWsLedServer.c ├── RayCrypto-ECDSA.c ├── SMTP-example.c ├── SharkAESCrypt.c ├── SharkTrust.c ├── WsEchoClient.c ├── certificates │ ├── CA_ISRG_Root_X1.h │ ├── CA_RTL_EC_256.h │ ├── device_EC_256.h │ └── device_RSA_2048.h ├── getzkey.ch ├── led-host-sim.ch ├── ledctrl.h ├── malloc │ ├── README.md │ ├── dbglog.h │ ├── licence.txt │ ├── umm_malloc.c │ ├── umm_malloc.h │ └── umm_malloc_cfg.h ├── proxy.ch └── proxy.h ├── inc ├── BufPrint.h ├── DoubleList.h ├── GenPrimT.h ├── HttpServer.h ├── MSLib.h ├── SMQ.h ├── SMTP.h ├── SeCtx.h ├── SharkMQTT.h ├── SharkSSL.h ├── SharkSSL_cfg.h ├── SharkSSL_opts.h ├── SharkSslASN1.h ├── SharkSslCrypto.h ├── SharkSslEx.h ├── SharkSslSCMgr.h ├── SingleList.h ├── SplayTree.h ├── WsClientLib.h ├── ZipFileSystem.h ├── arch │ ├── BareMetal │ │ └── TargConfig.h │ ├── FreeRTOS │ │ └── TargConfig.h │ ├── INTEGRITY │ │ └── TargConfig.h │ ├── MDK │ │ └── TargConfig.h │ ├── MQX │ │ └── TargConfig.h │ ├── Posix │ │ └── TargConfig.h │ ├── ThreadX │ │ ├── TargConfig.h │ │ └── readme.txt │ ├── Windows │ │ └── TargConfig.h │ ├── _template │ │ └── TargConfig.h │ ├── eCOG1X │ │ └── TargConfig.h │ ├── embOS │ │ └── TargConfig.h │ └── mbed │ │ └── TargConfig.h └── selib.h ├── src ├── MinnowServer │ ├── MSLib.c │ └── ZipFileSystem.c ├── SMTP │ ├── BufPrint.c │ └── SMTP.c ├── SeCtx.c ├── SharkMQ.c ├── SharkMQTT.c ├── SharkSSL.c ├── WsClientLib.c ├── arch │ ├── FreeRTOS-TCP │ │ └── selibplat.h │ ├── Harmony │ │ ├── README.txt │ │ ├── seHarmony.c │ │ └── selibplat.h │ ├── INTEGRITY │ │ └── selibplat.h │ ├── MDK │ │ └── selibplat.h │ ├── MQX │ │ └── selibplat.h │ ├── NetX │ │ ├── README.txt │ │ ├── seNetX.c │ │ └── selibplat.h │ ├── Posix │ │ └── selibplat.h │ ├── README.txt │ ├── Windows │ │ └── selibplat.h │ ├── lwIP-raw │ │ ├── README.txt │ │ ├── seLwIP.c │ │ └── selibplat.h │ ├── lwIP │ │ ├── seLwIP.c │ │ └── selibplat.h │ └── uip │ │ ├── README.txt │ │ ├── selibplat.h │ │ └── seuip.c └── selib.c └── tools ├── SharkSSLParseCAList.c ├── SharkSSLParseCert.c ├── SharkSSLParseKey.c └── SharkSSLTools.h /examples/SMTP-example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SMTP example program 10 | **************************************************************************** 11 | * 12 | * $Id: SMTP-example.c 4769 2021-06-11 17:29:36Z gianluca $ 13 | * 14 | * COPYRIGHT: Real Time Logic, 2013 - 2016 15 | * 16 | * This software is copyrighted by and is the sole property of Real 17 | * Time Logic LLC. All rights, title, ownership, or other interests in 18 | * the software remain the property of Real Time Logic LLC. This 19 | * software may only be used in accordance with the terms and 20 | * conditions stipulated in the corresponding license agreement under 21 | * which the software has been supplied. Any unauthorized use, 22 | * duplication, transmission, distribution, or disclosure of this 23 | * software is expressly forbidden. 24 | * 25 | * This Copyright notice may not be removed or modified without prior 26 | * written consent of Real Time Logic LLC. 27 | * 28 | * Real Time Logic LLC. reserves the right to modify this software 29 | * without notice. 30 | * 31 | * http://www.realtimelogic.com 32 | **************************************************************************** 33 | */ 34 | 35 | 36 | 37 | #include "SMTP.h" 38 | 39 | /* List of trusted root certificates: See sharkSslCAList in SharkSsl 40 | * constructor below. 41 | */ 42 | #include 43 | 44 | #if HOST_PLATFORM 45 | 46 | static char* emailAddress; 47 | 48 | /* Function used by selib. 49 | * Replace with function that prints to a console or create a stub 50 | * that does nothing. 51 | */ 52 | void _xprintf(const char* fmt, ...) 53 | { 54 | va_list varg; 55 | va_start(varg, fmt); 56 | vprintf(fmt, varg); 57 | va_end(varg); 58 | } 59 | #else 60 | extern char* emailAddress; 61 | #endif 62 | 63 | static const char* ecode2Msg(int ecode) 64 | { 65 | switch(ecode) 66 | { 67 | case SMTP_ErrHostName: return "SMTP_ErrHostName"; 68 | case SMTP_ErrSocketCreate: return "SMTP_ErrSocketCreate"; 69 | case SMTP_ErrConnect: return "SMTP_ErrConnect"; 70 | case SMTP_ErrHELO: return "SMTP_ErrHELO"; 71 | case SMTP_ErrMAILFROM: return "SMTP_ErrMAILFROM"; 72 | case SMTP_ErrDATA: return "SMTP_ErrDATA"; 73 | case SMTP_ErrRCPTTO: return "SMTP_ErrRCPTTO"; 74 | case SMTP_ErrSocketClosed: return "SMTP_ErrSocketClosed"; 75 | case SMTP_ErrSmtpResponseCode: return "SMTP_ErrSmtpResponseCode"; 76 | case SMTP_ErrWriteStarted: return "SMTP_ErrWriteStarted"; 77 | case SMTP_ErrNoAuthSup: return "SMTP_ErrNoAuthSup"; 78 | case SMTP_ErrAuth: return "SMTP_ErrAuth"; 79 | case SMTP_ErrSslCon: return "SMTP_ErrSslCon"; 80 | case SMTP_ErrCertNotTrusted: return "SMTP_ErrCertNotTrusted"; 81 | } 82 | return "OK"; 83 | } 84 | 85 | 86 | void mainTask(SeCtx* ctx) 87 | { 88 | static SharkSsl sharkSsl; 89 | static SMTP smtp; 90 | 91 | if(!emailAddress) 92 | { 93 | xprintf(("Warning (mainTask): no email address, sending to RTL\n")); 94 | emailAddress="ginfo@realtimelogic.com"; 95 | } 96 | 97 | SharkSsl_constructor(&sharkSsl, 98 | SharkSsl_Client, 99 | 0, /* cache size */ 100 | 1400, /* initial inBuf size */ 101 | 3500); /* outBuf size - fixed */ 102 | 103 | /* CA list from CA-list.h */ 104 | SharkSsl_setCAList(&sharkSsl, sharkSslCAList); /* Ref-CA */ 105 | 106 | 107 | #error Remove this line and insert your SMTP credentials. See examples below. 108 | 109 | 110 | #if 0 111 | SMTP_constructor( 112 | &smtp, 113 | "XXXXXXX@gmail.com", //const char* from, 114 | emailAddress, //const char* to, 115 | "Poem sent via Gmail", //const char* subject, 116 | "smtp.gmail.com", //const char* smtpServer, 117 | 465, //int port, 118 | &sharkSsl, 119 | FALSE, //int startTLS, 120 | "XXXXXXX@gmail.com", //const char* username, 121 | "XXXXXXX", 122 | 0, //const char* clientDomainName, 123 | "smtp.gmail.com", //const char* serverDomainName 124 | ctx); 125 | #endif 126 | 127 | #if 0 128 | SMTP_constructor( 129 | &smtp, 130 | "XXXXXXXXX@hotmail.com", //const char* from, 131 | emailAddress, //const char* to, 132 | "Poem sent via Hotmail", //const char* subject, 133 | "smtp.live.com", //const char* smtpServer, 134 | 587, //int port, 135 | &sharkSsl, 136 | TRUE, //int startTLS, 137 | "XXXXXXXXX@hotmail.com", //const char* username, 138 | "XXXXXXX", 139 | 0, //const char* clientDomainName, 140 | "smtp.live.com", //const char* serverDomainName 141 | ctx); 142 | #endif 143 | 144 | if(SMTP_getEcode(&smtp) == SMTP_NoError) 145 | { 146 | xprintf(("8BITMIME support: %s\n", SMTP_bit8(&smtp) ? "YES" : "NO")); 147 | 148 | SMTP_addRecipient(&smtp,"gsupport@realtimelogic.com"); 149 | } 150 | 151 | if(SMTP_getEcode(&smtp) == SMTP_NoError) 152 | SMTP_printf(&smtp,"%s\n", 153 | "Two roads diverged in a yellow wood,\n" 154 | "And sorry I could not travel both\n" 155 | "And be one traveler, long I stood\n" 156 | "And looked down one as far as I could\n" 157 | "To where it bent in the undergrowth;\n"); 158 | if(SMTP_getEcode(&smtp) == SMTP_NoError) 159 | SMTP_printf(&smtp,"%s\n", 160 | "Then took the other, as just as fair,\n" 161 | "And having perhaps the better claim\n" 162 | "Because it was grassy and wanted wear,\n" 163 | "Though as for that the passing there\n" 164 | "Had worn them really about the same,\n"); 165 | if(SMTP_getEcode(&smtp) == SMTP_NoError) 166 | SMTP_printf(&smtp,"%s\n", 167 | "And both that morning equally lay\n" 168 | "In leaves no step had trodden black.\n" 169 | "Oh, I marked the first for another day!\n" 170 | "Yet knowing how way leads on to way\n" 171 | "I doubted if I should ever come back.\n"); 172 | if(SMTP_getEcode(&smtp) == SMTP_NoError) 173 | SMTP_printf(&smtp,"%s\n", 174 | "I shall be telling this with a sigh\n" 175 | "Somewhere ages and ages hence:\n" 176 | "Two roads diverged in a wood, and I,\n" 177 | "I took the one less traveled by,\n" 178 | "And that has made all the difference.\n"); 179 | if( !SMTP_commit(&smtp) ) 180 | xprintf(("Email sent\n")); //Success. 181 | else 182 | { 183 | const char* emsg=SMTP_getEmsg(&smtp); 184 | xprintf(("Sending email failed: %s\n",ecode2Msg(SMTP_getEcode(&smtp)))); 185 | if(emsg) 186 | xprintf(("SMTP response %s\n", emsg)); 187 | } 188 | SMTP_destructor(&smtp); 189 | xprintf(("\nWe are done!\nPress return to continue.")); 190 | getchar(); 191 | #if HOST_PLATFORM 192 | exit(0); 193 | #endif 194 | } 195 | 196 | #if HOST_PLATFORM && !defined(NO_MAIN) 197 | int main(int argc, char **argv) 198 | { 199 | #ifdef _WIN32 200 | { 201 | WSADATA wsaData; 202 | WSAStartup(MAKEWORD(1,1), &wsaData); 203 | } 204 | #endif 205 | 206 | if(argc != 2) 207 | { 208 | printf("Usage:\n%s \n",argv[0]); 209 | exit(1); 210 | } 211 | emailAddress = argv[1]; 212 | mainTask(0); 213 | return 0; 214 | } 215 | #endif 216 | 217 | -------------------------------------------------------------------------------- /examples/certificates/CA_RTL_EC_256.h: -------------------------------------------------------------------------------- 1 | /* CA cert for http://sharktrustEC.realtimelogic.com 2 | */ 3 | #include 4 | const U8 sharkSSL_New_RTL_ECC_CA[] = { 5 | 0x00, 0x00, 0x00, 0x01, 0x52, 0x65, 0x61 6 | , 0x6C, 0x20, 0x54, 0x69, 0x6D, 0x00, 0x00, 0x00 7 | , 0x10, 0x30, 0x82, 0x02, 0x22, 0x30, 0x82, 0x01 8 | , 0xC7, 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09 9 | , 0x00, 0xB7, 0x0C, 0xDA, 0x1E, 0x43, 0x9A, 0xE3 10 | , 0xBB, 0x30, 0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48 11 | , 0xCE, 0x3D, 0x04, 0x03, 0x02, 0x30, 0x73, 0x31 12 | , 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06 13 | , 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11 14 | , 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x0A, 0x43 15 | , 0x61, 0x6C, 0x69, 0x66, 0x6F, 0x72, 0x6E, 0x69 16 | , 0x61, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55 17 | , 0x04, 0x07, 0x0C, 0x0A, 0x44, 0x61, 0x6E, 0x61 18 | , 0x20, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x31, 0x18 19 | , 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C 20 | , 0x0F, 0x52, 0x65, 0x61, 0x6C, 0x20, 0x54, 0x69 21 | , 0x6D, 0x65, 0x20, 0x4C, 0x6F, 0x67, 0x69, 0x63 22 | , 0x31, 0x20, 0x30, 0x1E, 0x06, 0x03, 0x55, 0x04 23 | , 0x03, 0x0C, 0x17, 0x52, 0x65, 0x61, 0x6C, 0x20 24 | , 0x54, 0x69, 0x6D, 0x65, 0x20, 0x4C, 0x6F, 0x67 25 | , 0x69, 0x63, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20 26 | , 0x43, 0x41, 0x30, 0x20, 0x17, 0x0D, 0x32, 0x30 27 | , 0x30, 0x31, 0x31, 0x33, 0x30, 0x30, 0x34, 0x38 28 | , 0x30, 0x33, 0x5A, 0x18, 0x0F, 0x32, 0x30, 0x36 29 | , 0x39, 0x31, 0x32, 0x33, 0x31, 0x30, 0x30, 0x34 30 | , 0x38, 0x30, 0x33, 0x5A, 0x30, 0x73, 0x31, 0x0B 31 | , 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13 32 | , 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06 33 | , 0x03, 0x55, 0x04, 0x08, 0x0C, 0x0A, 0x43, 0x61 34 | , 0x6C, 0x69, 0x66, 0x6F, 0x72, 0x6E, 0x69, 0x61 35 | , 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04 36 | , 0x07, 0x0C, 0x0A, 0x44, 0x61, 0x6E, 0x61, 0x20 37 | , 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x31, 0x18, 0x30 38 | , 0x16, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0F 39 | , 0x52, 0x65, 0x61, 0x6C, 0x20, 0x54, 0x69, 0x6D 40 | , 0x65, 0x20, 0x4C, 0x6F, 0x67, 0x69, 0x63, 0x31 41 | , 0x20, 0x30, 0x1E, 0x06, 0x03, 0x55, 0x04, 0x03 42 | , 0x0C, 0x17, 0x52, 0x65, 0x61, 0x6C, 0x20, 0x54 43 | , 0x69, 0x6D, 0x65, 0x20, 0x4C, 0x6F, 0x67, 0x69 44 | , 0x63, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x43 45 | , 0x41, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A 46 | , 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x06, 0x08 47 | , 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07 48 | , 0x03, 0x42, 0x00, 0x04, 0xF7, 0x3B, 0xAF, 0x91 49 | , 0x1A, 0xBA, 0xCE, 0xC1, 0x0B, 0x4C, 0x53, 0xF1 50 | , 0x02, 0x2E, 0xB7, 0x8B, 0x60, 0x5A, 0x62, 0x6D 51 | , 0x92, 0xDB, 0x98, 0x5B, 0x96, 0xCC, 0x00, 0xA8 52 | , 0x73, 0xD1, 0xFF, 0x6E, 0x2A, 0x9C, 0x22, 0xB2 53 | , 0x6A, 0x5A, 0xA1, 0x43, 0xBE, 0x6F, 0x8E, 0x7B 54 | , 0xBA, 0x22, 0x7F, 0x55, 0xF9, 0x00, 0xCA, 0x80 55 | , 0x12, 0x9D, 0x3E, 0xBB, 0x65, 0xA0, 0x5D, 0xC9 56 | , 0xEE, 0xC8, 0x7D, 0xC5, 0xA3, 0x42, 0x30, 0x40 57 | , 0x30, 0x0E, 0x06, 0x03, 0x55, 0x1D, 0x0F, 0x01 58 | , 0x01, 0xFF, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06 59 | , 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D, 0x13, 0x01 60 | , 0x01, 0xFF, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01 61 | , 0xFF, 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x0E 62 | , 0x04, 0x16, 0x04, 0x14, 0x62, 0x8F, 0x92, 0x73 63 | , 0x1B, 0xDC, 0x3F, 0x50, 0x4E, 0x95, 0xC2, 0x3C 64 | , 0x6B, 0x56, 0x62, 0xD8, 0xAF, 0x56, 0xAE, 0x02 65 | , 0x30, 0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE 66 | , 0x3D, 0x04, 0x03, 0x02, 0x03, 0x49, 0x00, 0x30 67 | , 0x46, 0x02, 0x21, 0x00, 0xE8, 0x67, 0x43, 0xB8 68 | , 0x2A, 0xD6, 0xD7, 0x99, 0x68, 0xBC, 0xFF, 0x81 69 | , 0x64, 0xB5, 0x04, 0xE2, 0x70, 0x7A, 0x2C, 0xCE 70 | , 0x0C, 0xCE, 0x16, 0x8D, 0xDA, 0xBE, 0x0C, 0x1F 71 | , 0x5F, 0x66, 0x67, 0x02, 0x02, 0x21, 0x00, 0xD3 72 | , 0x0B, 0x0B, 0x82, 0xCB, 0xA1, 0x50, 0x89, 0x38 73 | , 0x8C, 0x69, 0xD2, 0x7B, 0x77, 0x51, 0xB1, 0x7F 74 | , 0x20, 0x3D, 0x03, 0x22, 0x0C, 0x2B, 0x20, 0x4E 75 | , 0x95, 0x2D, 0x5E, 0xDD, 0xB2, 0x9A, 0xC7 76 | }; 77 | -------------------------------------------------------------------------------- /examples/certificates/device_EC_256.h: -------------------------------------------------------------------------------- 1 | /** 2 | * SharkSSLParseCert. Build 3370. 3 | * Copyright (c) 2014 Real Time Logic. 4 | */ 5 | 6 | #include "TargConfig.h" 7 | 8 | const U8 sharkSslECCert_device[776] = 9 | { 10 | 0x30, 0x82, 0x02, 0x9E, 0x30, 0x82, 0x02, 0x43, 11 | 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x04, 12 | 0x30, 0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 13 | 0x3D, 0x04, 0x03, 0x02, 0x30, 0x81, 0x88, 0x31, 14 | 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 15 | 0x13, 0x02, 0x55, 0x53, 0x31, 0x1C, 0x30, 0x1A, 16 | 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x13, 0x52, 17 | 0x65, 0x61, 0x6C, 0x20, 0x54, 0x69, 0x6D, 0x65, 18 | 0x20, 0x4C, 0x6F, 0x67, 0x69, 0x63, 0x20, 0x4C, 19 | 0x4C, 0x43, 0x31, 0x11, 0x30, 0x0F, 0x06, 0x03, 20 | 0x55, 0x04, 0x0B, 0x13, 0x08, 0x53, 0x68, 0x61, 21 | 0x72, 0x6B, 0x53, 0x53, 0x4C, 0x31, 0x20, 0x30, 22 | 0x1E, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x17, 23 | 0x52, 0x65, 0x61, 0x6C, 0x20, 0x54, 0x69, 0x6D, 24 | 0x65, 0x20, 0x4C, 0x6F, 0x67, 0x69, 0x63, 0x20, 25 | 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x43, 0x41, 0x31, 26 | 0x26, 0x30, 0x24, 0x06, 0x09, 0x2A, 0x86, 0x48, 27 | 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x17, 28 | 0x67, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x72, 0x65, 29 | 0x61, 0x6C, 0x74, 0x69, 0x6D, 0x65, 0x6C, 0x6F, 30 | 0x67, 0x69, 0x63, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 31 | 0x1E, 0x17, 0x0D, 0x31, 0x34, 0x30, 0x36, 0x32, 32 | 0x33, 0x31, 0x38, 0x32, 0x33, 0x31, 0x37, 0x5A, 33 | 0x17, 0x0D, 0x32, 0x34, 0x30, 0x36, 0x32, 0x30, 34 | 0x31, 0x38, 0x32, 0x33, 0x31, 0x37, 0x5A, 0x30, 35 | 0x11, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 36 | 0x04, 0x03, 0x13, 0x06, 0x64, 0x65, 0x76, 0x69, 37 | 0x63, 0x65, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 38 | 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x06, 39 | 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 40 | 0x07, 0x03, 0x42, 0x00, 0x04, 0xD5, 0xC3, 0x8A, 41 | 0x83, 0xF0, 0xE5, 0x23, 0xA7, 0x61, 0xD9, 0xC3, 42 | 0xD0, 0x5A, 0x16, 0xF5, 0x61, 0x27, 0x20, 0x7D, 43 | 0x1A, 0x6D, 0x50, 0x78, 0xFE, 0xA0, 0xA8, 0x36, 44 | 0x59, 0x04, 0x4B, 0xCE, 0x1D, 0xCE, 0xB3, 0xB5, 45 | 0x7C, 0x00, 0xB0, 0x18, 0x8C, 0xCA, 0x09, 0xF5, 46 | 0x3A, 0xF5, 0x44, 0xB3, 0x70, 0xAF, 0xD3, 0xCA, 47 | 0xD6, 0xAF, 0xE9, 0x2B, 0x26, 0x5C, 0x4F, 0xDD, 48 | 0x5F, 0x0F, 0x73, 0xA2, 0xC9, 0xA3, 0x82, 0x01, 49 | 0x12, 0x30, 0x82, 0x01, 0x0E, 0x30, 0x1D, 0x06, 50 | 0x03, 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 51 | 0x6D, 0x20, 0x36, 0x22, 0x18, 0x9A, 0xCA, 0x47, 52 | 0x21, 0xDA, 0x00, 0xD5, 0x31, 0x8E, 0x5F, 0xB5, 53 | 0x96, 0xCF, 0xE4, 0x08, 0x30, 0x81, 0xB5, 0x06, 54 | 0x03, 0x55, 0x1D, 0x23, 0x04, 0x81, 0xAD, 0x30, 55 | 0x81, 0xAA, 0x80, 0x14, 0x03, 0x58, 0xA1, 0xBE, 56 | 0x4F, 0xDC, 0x8F, 0xA1, 0x1F, 0xBB, 0xBC, 0xA1, 57 | 0xAA, 0xE6, 0x3E, 0xC0, 0xDB, 0x56, 0x1F, 0x18, 58 | 0xA1, 0x81, 0x8E, 0xA4, 0x81, 0x8B, 0x30, 0x81, 59 | 0x88, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 60 | 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x1C, 61 | 0x30, 0x1A, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 62 | 0x13, 0x52, 0x65, 0x61, 0x6C, 0x20, 0x54, 0x69, 63 | 0x6D, 0x65, 0x20, 0x4C, 0x6F, 0x67, 0x69, 0x63, 64 | 0x20, 0x4C, 0x4C, 0x43, 0x31, 0x11, 0x30, 0x0F, 65 | 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x08, 0x53, 66 | 0x68, 0x61, 0x72, 0x6B, 0x53, 0x53, 0x4C, 0x31, 67 | 0x20, 0x30, 0x1E, 0x06, 0x03, 0x55, 0x04, 0x03, 68 | 0x13, 0x17, 0x52, 0x65, 0x61, 0x6C, 0x20, 0x54, 69 | 0x69, 0x6D, 0x65, 0x20, 0x4C, 0x6F, 0x67, 0x69, 70 | 0x63, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x43, 71 | 0x41, 0x31, 0x26, 0x30, 0x24, 0x06, 0x09, 0x2A, 72 | 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x01, 73 | 0x16, 0x17, 0x67, 0x69, 0x6E, 0x66, 0x6F, 0x40, 74 | 0x72, 0x65, 0x61, 0x6C, 0x74, 0x69, 0x6D, 0x65, 75 | 0x6C, 0x6F, 0x67, 0x69, 0x63, 0x2E, 0x63, 0x6F, 76 | 0x6D, 0x82, 0x01, 0x01, 0x30, 0x09, 0x06, 0x03, 77 | 0x55, 0x1D, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 78 | 0x0B, 0x06, 0x03, 0x55, 0x1D, 0x0F, 0x04, 0x04, 79 | 0x03, 0x02, 0x03, 0xA8, 0x30, 0x1D, 0x06, 0x03, 80 | 0x55, 0x1D, 0x25, 0x04, 0x16, 0x30, 0x14, 0x06, 81 | 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 82 | 0x02, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 83 | 0x07, 0x03, 0x01, 0x30, 0x0A, 0x06, 0x08, 0x2A, 84 | 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02, 0x03, 85 | 0x49, 0x00, 0x30, 0x46, 0x02, 0x21, 0x00, 0xF2, 86 | 0xA3, 0x07, 0x75, 0x8A, 0x1F, 0x9C, 0xE7, 0x70, 87 | 0xF6, 0xBF, 0x6D, 0x92, 0xD5, 0x84, 0xA0, 0x4F, 88 | 0xEA, 0xE5, 0xDB, 0xEA, 0xB2, 0x36, 0x61, 0x55, 89 | 0x11, 0x26, 0xEA, 0x71, 0x66, 0xE5, 0x74, 0x02, 90 | 0x21, 0x00, 0xEE, 0x87, 0xEF, 0x78, 0xEC, 0x76, 91 | 0x9B, 0xF7, 0xAD, 0x70, 0xA1, 0x0E, 0xCC, 0x73, 92 | 0x88, 0x47, 0x4D, 0x63, 0xBE, 0x5B, 0x02, 0x98, 93 | 0x09, 0x30, 0xED, 0xCF, 0xE4, 0x1C, 0x79, 0xAA, 94 | 0x41, 0xE6, 0xFF, 0xFF, 0x02, 0x20, 0x17, 0x20, 95 | 0x02, 0xF3, 0x3E, 0xCE, 0x0E, 0xB4, 0xAC, 0x41, 96 | 0x6C, 0x7C, 0xF2, 0x2E, 0x80, 0x28, 0xE6, 0xAA, 97 | 0x31, 0xB8, 0xD6, 0x7A, 0x8F, 0x84, 0x32, 0x95, 98 | 0x4C, 0x75, 0xBC, 0x56, 0xB0, 0xA2, 0xE8, 0xF2, 99 | 0xD5, 0xC3, 0x8A, 0x83, 0xF0, 0xE5, 0x23, 0xA7, 100 | 0x61, 0xD9, 0xC3, 0xD0, 0x5A, 0x16, 0xF5, 0x61, 101 | 0x27, 0x20, 0x7D, 0x1A, 0x6D, 0x50, 0x78, 0xFE, 102 | 0xA0, 0xA8, 0x36, 0x59, 0x04, 0x4B, 0xCE, 0x1D, 103 | 0xCE, 0xB3, 0xB5, 0x7C, 0x00, 0xB0, 0x18, 0x8C, 104 | 0xCA, 0x09, 0xF5, 0x3A, 0xF5, 0x44, 0xB3, 0x70, 105 | 0xAF, 0xD3, 0xCA, 0xD6, 0xAF, 0xE9, 0x2B, 0x26, 106 | 0x5C, 0x4F, 0xDD, 0x5F, 0x0F, 0x73, 0xA2, 0xC9 107 | }; 108 | 109 | -------------------------------------------------------------------------------- /examples/ledctrl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: selib.h 3407 2014-06-24 22:44:50Z wini $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2013 - 2015 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://realtimelogic.com 33 | * http://sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | 38 | #ifndef _ledctrl_h 39 | #define _ledctrl_h 40 | 41 | #include "selib.h" 42 | 43 | /* Do not change the number sequence. Must match peer code. */ 44 | typedef enum 45 | { 46 | LedColor_red=0, 47 | LedColor_yellow=1, 48 | LedColor_green=2, 49 | LedColor_blue=3 50 | } LedColor; 51 | 52 | 53 | /* Each LED is registered with the following information */ 54 | typedef struct { 55 | const char* name; /* LED name shown in the browser */ 56 | LedColor color; /* The color of this particular LED */ 57 | int id; /* A unique ID for the LED. ID range can be 0 to 15. */ 58 | } LedInfo; 59 | 60 | 61 | typedef enum { 62 | ProgramStatus_Starting, 63 | ProgramStatus_Restarting, 64 | ProgramStatus_Connecting, 65 | ProgramStatus_SslHandshake, 66 | ProgramStatus_DeviceReady, 67 | ProgramStatus_CloseCommandReceived, 68 | 69 | ProgramStatus_SocketError, 70 | ProgramStatus_DnsError, 71 | ProgramStatus_ConnectionError, 72 | ProgramStatus_CertificateNotTrustedError, 73 | ProgramStatus_SslHandshakeError, 74 | ProgramStatus_WebServiceNotAvailError, 75 | ProgramStatus_PongResponseError, 76 | ProgramStatus_InvalidCommandError, 77 | ProgramStatus_MemoryError 78 | } ProgramStatus; 79 | 80 | 81 | #ifdef __cplusplus 82 | extern "C" { 83 | #endif 84 | 85 | /* 86 | Return an array of LedInfo (struct). Each element in the array 87 | provides information for one LED. The 'len' argument must be set by 88 | function getLedInfo. The out argument 'en' specifies the length of 89 | the returned array, that is, number of LEDs in the device. Each LED 90 | has a name, color, and ID. The ID, which provides information about 91 | which LED to turn on/off, is used by control messages sent between 92 | device code and UI clients. The IDs for a four LED device can for 93 | example be 1,2,3,4. 94 | */ 95 | const LedInfo* getLedInfo(int* len); 96 | 97 | 98 | /* Returns the name of this device. The name is presented by UI 99 | clients such as browsers. 100 | */ 101 | const char* getDevName(void); 102 | 103 | 104 | /* Command sent by UI client to turn LED with ID on or off. This 105 | function must set the LED to on if 'on' is TRUE and off if 'on' is FALSE. 106 | */ 107 | int setLed(int ledId, int on); 108 | 109 | /* 110 | An optional function that enables LEDs to be set directly by the 111 | device. This function is typically used by devices that include one 112 | or more buttons. A button click may for example turn on a specific 113 | LED. The function is called at intervals (polled) by the LED device 114 | code. The function may for example detect a button click and return 115 | the information to the caller. Arguments 'ledId' and 'on' are out 116 | arguments, where 'ledId' is set to the LED ID and 'on' is set to 117 | TRUE for on and FALSE for off. The function must return TRUE (a non 118 | zero value) if the LED is to be set on/off and zero on no 119 | change. Create an empty function returning zero if you do not plan 120 | on implementing this feature. 121 | */ 122 | int setLedFromDevice(int* ledId, int* on); 123 | 124 | /* Returns the LED on/off state for led with ID 'ledId'. 125 | */ 126 | int getLedState(int ledId); 127 | 128 | /* 129 | The purpose with program status is to provide visible program 130 | connection state information during startup. The function is typically 131 | used to signal information via the LEDs. Simply create an empty 132 | function if you do not want to set program status. 133 | */ 134 | void setProgramStatus(ProgramStatus s); 135 | 136 | /* Required by SMQ examples. 137 | The unique ID is used when calling the SMQ constructor. The 138 | unique ID is typically set to the MAC address. See the SMQ 139 | documentation for details: 140 | https://realtimelogic.com/ba/doc/en/C/shark/structSharkMQ.html 141 | */ 142 | int getUniqueId(const char** id); 143 | 144 | /* Optional function that can be implemented and used by the SMQ 145 | examples if the device includes a temperature sensor. The returned 146 | value must be in Celsius times 10 i.e. the temperature 20 Celsius 147 | must be returned as the value 200. You must also compile the code 148 | with the macro ENABLE_TEMP defined to enable the temperature 149 | logic. The simulated (host) version includes a simulated 150 | temperature and the temperature can be changed by using the up and 151 | down keyboard arrows. The temperature is displayed in the browser UI. 152 | */ 153 | int getTemp(void); 154 | 155 | 156 | #ifdef __cplusplus 157 | } 158 | #endif 159 | 160 | #endif 161 | -------------------------------------------------------------------------------- /examples/malloc/README.md: -------------------------------------------------------------------------------- 1 | 2 | A memory allocator for embedded systems (microcontrollers) 3 | ========================================================== 4 | 5 | Based on: https://github.com/dimonomid/umm_malloc/blob/master/README.md 6 | 7 | 8 | This is a memory management library specifically designed to work with the 9 | ARM7 embedded processor, but it should work on many other 32 bit processors, 10 | as well as 16 and 8 bit devices. 11 | 12 | Initially I've found this great memory allocator here: 13 | http://hempeldesigngroup.com/embedded/stories/memorymanager/ , 14 | fixed little configuration issues, and uploaded to the github. 15 | 16 | I successfully tested it on Microchip PIC32 device, and it is 17 | extremely effective comparing to default memory allocator provided by Microchip. 18 | 19 | I was seriously beaten by fragmentation with default allocator: my project often 20 | allocates blocks of various size, from several bytes to several hundreds of bytes, 21 | and sometimes I faced 'out of memory' error. 22 | My project has total 8192 bytes of heap, at the particular moment there is more 23 | than 5K of free memory, but default allocator has maximum non-fragmented 24 | memory block just of about 700 bytes, because of fragmentation. 25 | This is too bad, so I decided to look for more efficient solution. 26 | 27 | When I tried this memory allocator, in exactly the same situation it has more 28 | than 3800 bytes block! It was so unbelievable to be, and I performed hard test: 29 | device worked heavily more than 30 hours. No memory leaks, everything works 30 | as it should work. 31 | 32 | I also found this allocator in the FreeRTOS repository: 33 | http://svnmios.midibox.org/listing.php?repname=svn.mios32&path=%2Ftrunk%2FFreeRTOS%2FSource%2Fportable%2FMemMang%2F&rev=1041&peg=1041# , 34 | and this fact is an additional evidence of stability of ```umm_malloc```. 35 | 36 | So I completely switched to ```umm_malloc```, and I'm quite happy with it. 37 | 38 | 39 | Acknowledgements 40 | ---------------- 41 | 42 | Joerg Wunsch and the avr-libc provided the first malloc() implementation 43 | that I examined in detail. 44 | 45 | http://www.nongnu.org/avr-libc 46 | 47 | Doug Lea's paper on malloc() was another excellent reference and provides 48 | a lot of detail on advanced memory management techniques such as binning. 49 | 50 | http://g.oswego.edu/dl/html/malloc.html 51 | 52 | Bill Dittman provided excellent suggestions, including macros to support 53 | using these functions in critical sections, and for optimizing realloc() 54 | further by checking to see if the previous block was free and could be 55 | used for the new block size. This can help to reduce heap fragmentation 56 | significantly. 57 | 58 | Yaniv Ankin suggested that a way to dump the current heap condition 59 | might be useful. I combined this with an idea from plarroy to also 60 | allow checking a free pointer to make sure it's valid. 61 | 62 | --------------------------------------------------------------- 63 | 64 | The memory manager assumes the following things: 65 | 66 | 1. The standard POSIX compliant malloc/realloc/free semantics are used 67 | 2. All memory used by the manager is allocated at link time, it is aligned 68 | on a 32 bit boundary, it is contiguous, and its extent (start and end 69 | address) is filled in by the linker. 70 | 3. All memory used by the manager is initialized to 0 as part of the 71 | runtime startup routine. No other initialization is required. 72 | 73 | The fastest linked list implementations use doubly linked lists so that 74 | its possible to insert and delete blocks in constant time. This memory 75 | manager keeps track of both free and used blocks in a doubly linked list. 76 | 77 | Most memory managers use some kind of list structure made up of pointers 78 | to keep track of used - and sometimes free - blocks of memory. In an 79 | embedded system, this can get pretty expensive as each pointer can use 80 | up to 32 bits. 81 | 82 | In most embedded systems there is no need for managing large blocks 83 | of memory dynamically, so a full 32 bit pointer based data structure 84 | for the free and used block lists is wasteful. A block of memory on 85 | the free list would use 16 bytes just for the pointers! 86 | 87 | This memory management library sees the malloc heap as an array of blocks, 88 | and uses block numbers to keep track of locations. The block numbers are 89 | 15 bits - which allows for up to 32767 blocks of memory. The high order 90 | bit marks a block as being either free or in use, which will be explained 91 | later. 92 | 93 | The result is that a block of memory on the free list uses just 8 bytes 94 | instead of 16. 95 | 96 | In fact, we go even one step futher when we realize that the free block 97 | index values are available to store data when the block is allocated. 98 | 99 | The overhead of an allocated block is therefore just 4 bytes. 100 | 101 | Each memory block holds 8 bytes, and there are up to 32767 blocks 102 | available, for about 256K of heap space. If that's not enough, you 103 | can always add more data bytes to the body of the memory block 104 | at the expense of free block size overhead. 105 | 106 | Detailed explanation of algorithms can be found in ```umm_malloc.c``` file. 107 | 108 | Usage 109 | ----- 110 | 111 | - Clone repository ```umm_malloc``` somewhere (or just download zip file and unpack it) 112 | - Add ```umm_malloc.c``` file to your project 113 | - Edit ```umm_malloc_cfg.h``` file depending on your needs 114 | (if you haven't defined ```UMM_REDEFINE_MEM_FUNCTIONS``` macro, make sure you use 115 | ```umm_malloc()``` and ```umm_free()``` functions in your project, instead of standard 116 | ```malloc()``` and ```free()``` functions) 117 | 118 | 119 | -------------------------------------------------------------------------------- /examples/malloc/dbglog.h: -------------------------------------------------------------------------------- 1 | // ---------------------------------------------------------------------------- 2 | // dbglog.h - A set of macros that cleans up code that needs to produce debug 3 | // or log information. 4 | // 5 | // See copyright notice in LICENSE.TXT 6 | // ---------------------------------------------------------------------------- 7 | // 8 | // There are macros to handle the following decreasing levels of detail: 9 | // 10 | // 6 = TRACE 11 | // 5 = DEBUG 12 | // 4 = CRITICAL 13 | // 3 = ERROR 14 | // 2 = WARNING 15 | // 1 = INFO 16 | // 0 = FORCE - The printf is always compiled in and is called only when 17 | // the first parameter to the macro is non-0 18 | // 19 | // ---------------------------------------------------------------------------- 20 | // 21 | // The following #define should be set up before this file is included so 22 | // that we can be sure that the correct macros are defined. 23 | // 24 | // #define DBG_LOG_LEVEL x 25 | // ---------------------------------------------------------------------------- 26 | 27 | #ifndef DBG_LOG_LEVEL 28 | # error "DBG_LOG_LEVEL is not defined!" 29 | #endif 30 | 31 | // ---------------------------------------------------------------------------- 32 | // 33 | // FIXME: Currently the macros are defined at compile time, which means that 34 | // the debug level is fixed. It will be possible in later versions to 35 | // set up run time control of debug info at the expense of speed and 36 | // code size 37 | // ---------------------------------------------------------------------------- 38 | 39 | #undef DBG_LOG_TRACE 40 | #undef DBG_LOG_DEBUG 41 | #undef DBG_LOG_CRITICAL 42 | #undef DBG_LOG_ERROR 43 | #undef DBG_LOG_WARNING 44 | #undef DBG_LOG_INFO 45 | #undef DBG_LOG_FORCE 46 | 47 | // ---------------------------------------------------------------------------- 48 | 49 | #if DBG_LOG_LEVEL >= 6 50 | # define DBG_LOG_TRACE( format, ... ) printf( format, ## __VA_ARGS__ ) 51 | #else 52 | # define DBG_LOG_TRACE( format, ... ) 53 | #endif 54 | 55 | #if DBG_LOG_LEVEL >= 5 56 | # define DBG_LOG_DEBUG( format, ... ) printf( format, ## __VA_ARGS__ ) 57 | #else 58 | # define DBG_LOG_DEBUG( format, ... ) 59 | #endif 60 | 61 | #if DBG_LOG_LEVEL >= 4 62 | # define DBG_LOG_CRITICAL( format, ... ) printf( format, ## __VA_ARGS__ ) 63 | #else 64 | # define DBG_LOG_CRITICAL( format, ... ) 65 | #endif 66 | 67 | #if DBG_LOG_LEVEL >= 3 68 | # define DBG_LOG_ERROR( format, ... ) printf( format, ## __VA_ARGS__ ) 69 | #else 70 | # define DBG_LOG_ERROR( format, ... ) 71 | #endif 72 | 73 | #if DBG_LOG_LEVEL >= 2 74 | # define DBG_LOG_WARNING( format, ... ) printf( format, ## __VA_ARGS__ ) 75 | #else 76 | # define DBG_LOG_WARNING( format, ... ) 77 | #endif 78 | 79 | #if DBG_LOG_LEVEL >= 1 80 | # define DBG_LOG_INFO( format, ... ) printf( format, ## __VA_ARGS__ ) 81 | #else 82 | # define DBG_LOG_INFO( format, ... ) 83 | #endif 84 | 85 | 86 | #if DBG_LOG_LEVEL >= 1 87 | #define DBG_LOG_FORCE( force, format, ... ) {if(force) {printf( format, ## __VA_ARGS__ );}} 88 | #else 89 | # define DBG_LOG_FORCE( force, format, ... ) 90 | #endif 91 | 92 | // ---------------------------------------------------------------------------- 93 | -------------------------------------------------------------------------------- /examples/malloc/licence.txt: -------------------------------------------------------------------------------- 1 | // ---------------------------------------------------------------------------- 2 | // Copyright (c) 2007-2008 Ralph Hempel 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | // ---------------------------------------------------------------------------- 22 | -------------------------------------------------------------------------------- /examples/malloc/umm_malloc.h: -------------------------------------------------------------------------------- 1 | // ---------------------------------------------------------------------------- 2 | // umm_malloc.h - a memory allocator for embedded systems (microcontrollers) 3 | // 4 | // See copyright notice in LICENSE.TXT 5 | // ---------------------------------------------------------------------------- 6 | 7 | #ifndef UMM_MALLOC_H 8 | #define UMM_MALLOC_H 9 | 10 | // ---------------------------------------------------------------------------- 11 | 12 | #include 13 | 14 | 15 | typedef struct UMM_HEAP_INFO_t { 16 | unsigned short int totalEntries; 17 | unsigned short int usedEntries; 18 | unsigned short int freeEntries; 19 | 20 | unsigned short int totalBlocks; 21 | unsigned short int usedBlocks; 22 | unsigned short int freeBlocks; 23 | } 24 | UMM_HEAP_INFO; 25 | 26 | extern UMM_HEAP_INFO heapInfo; 27 | 28 | extern char __umm_heap_start[]; 29 | extern char __umm_heap_end[]; 30 | extern size_t __umm_heap_size; 31 | 32 | void *umm_info( void *ptr, int force ); 33 | 34 | void *umm_malloc( size_t size ); 35 | void *umm_realloc( void *ptr, size_t size ); 36 | void umm_free( void *ptr ); 37 | 38 | 39 | // ---------------------------------------------------------------------------- 40 | 41 | #endif // UMM_MALLOC_H 42 | -------------------------------------------------------------------------------- /examples/malloc/umm_malloc_cfg.h: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------------- 2 | // User-dependent configuration file for umm_malloc 3 | // --------------------------------------------------------------------------- 4 | 5 | #ifndef _UMM_MALLOC_CFG_H 6 | #define _UMM_MALLOC_CFG_H 7 | 8 | 9 | // ---------------------------------------------------------------------------- 10 | // 11 | // There are a number of defines you can set at compile time that affect how 12 | // the memory allocator will operate. 13 | // You can set them in your config file umm_malloc_cfg.h. 14 | // In GNU C, you also can set these compile time defines like this: 15 | // 16 | // -D UMM_TEST_MAIN 17 | // 18 | // Set this if you want to compile in the test suite at the end of this file. 19 | // 20 | // If you leave this define unset, then you might want to set another one: 21 | // 22 | // -D UMM_REDEFINE_MEM_FUNCTIONS 23 | // 24 | // If you leave this define unset, then the function names are left alone as 25 | // umm_malloc() umm_free() and umm_realloc() so that they cannot be confused 26 | // with the C runtime functions malloc() free() and realloc() 27 | // 28 | // If you do set this define, then the function names become malloc() 29 | // free() and realloc() so that they can be used as the C runtime functions 30 | // in an embedded environment. 31 | // 32 | // -D UMM_BEST_FIT (defualt) 33 | // 34 | // Set this if you want to use a best-fit algorithm for allocating new 35 | // blocks 36 | // 37 | // -D UMM_FIRST_FIT 38 | // 39 | // Set this if you want to use a first-fit algorithm for allocating new 40 | // blocks 41 | // 42 | // -D UMM_DBG_LOG_LEVEL=n 43 | // 44 | // Set n to a value from 0 to 6 depending on how verbose you want the debug 45 | // log to be 46 | // 47 | // If you want umm_malloc not to be built at all, without removing it from the project, 48 | // you can set this macro: 49 | // 50 | // -D UMM_MALLOC_CFG__DONT_BUILD 51 | // 52 | // This can be useful if you want to easily switch between different allocators 53 | // to test them. 54 | // 55 | // ---------------------------------------------------------------------------- 56 | // 57 | // Support for this library in a multitasking environment is provided when 58 | // you add bodies to the UMM_CRITICAL_ENTRY and UMM_CRITICAL_EXIT macros 59 | // (see below) 60 | // 61 | // ---------------------------------------------------------------------------- 62 | 63 | 64 | 65 | 66 | 67 | // ---------------------------------------------------------------------------- 68 | // Size of the heap in bytes 69 | 70 | #include 71 | 72 | /* 73 | The assumption is that a SharkSSL configuration with Elliptic Curves 74 | Certs "only" uses less memory for the following reasons: 75 | 76 | * ECC certs are smaller 77 | * An ECC certificate will not be chained. 78 | 79 | The configuration below is sufficient for one SharkSSL connection. 80 | */ 81 | 82 | #ifndef UMM_MALLOC_CFG__HEAP_SIZE 83 | #if SHARKSSL_ENABLE_RSA 84 | #define UMM_MALLOC_CFG__HEAP_SIZE 0x9000 85 | #else 86 | #define UMM_MALLOC_CFG__HEAP_SIZE 0x6000 87 | #endif 88 | #endif 89 | 90 | 91 | // ---------------------------------------------------------------------------- 92 | // A couple of macros to make packing structures less compiler dependent 93 | 94 | #ifdef __IAR_SYSTEMS_ICC__ 95 | #define UMM_H_ATTPACKPRE __packed 96 | #define UMM_H_ATTPACKSUF 97 | #elif defined(_WIN32) 98 | #define UMM_H_ATTPACKPRE 99 | #define UMM_H_ATTPACKSUF 100 | #else 101 | #define UMM_H_ATTPACKPRE 102 | #define UMM_H_ATTPACKSUF __attribute__((__packed__)) 103 | #endif 104 | 105 | 106 | // ---------------------------------------------------------------------------- 107 | // A couple of macros to make it easier to protect the memory allocator 108 | // in a multitasking system. You should set these macros up to use whatever 109 | // your system uses for this purpose. You can disable interrupts entirely, or 110 | // just disable task switching - it's up to you 111 | // 112 | // NOTE WELL that these macros MUST be allowed to nest, because umm_free() is 113 | // called from within umm_malloc() 114 | #ifndef UMM_CRITICAL_ENTRY 115 | #define UMM_CRITICAL_ENTRY() 116 | #define UMM_CRITICAL_EXIT() 117 | #endif 118 | 119 | 120 | 121 | #endif // _UMM_MALLOC_CFG_H 122 | /*************************************************************************************************** 123 | end of file 124 | **************************************************************************************************/ 125 | 126 | 127 | -------------------------------------------------------------------------------- /examples/proxy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: proxy.h 5076 2022-02-10 16:59:48Z wini $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2016 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://realtimelogic.com 33 | * http://sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | 38 | #ifndef _proxy_h 39 | #define _proxy_h 40 | 41 | #define E_PROXY_AUTH -1000 /* Authentication required or wrong credentials */ 42 | #define E_PROXY_GENERAL -1001 /* general SOCKS server failure */ 43 | #define E_PROXY_NOT_ALLOWED -1002 /* connection not allowed by ruleset */ 44 | #define E_PROXY_NETWORK -1003 /* Network unreachable */ 45 | #define E_PROXY_HOST -1004 /* Host unreachable */ 46 | #define E_PROXY_REFUSED -1005 /* Connection refused */ 47 | #define E_PROXY_TTL -1006 /* TTL expired */ 48 | #define E_PROXY_COMMAND_NOT_SUP -1007 /* Command not supported */ 49 | #define E_PROXY_ADDRESS_NOT_SUP -1008 /* Address type not supported */ 50 | #define E_PROXY_NOT_COMPATIBLE -1009 /* Not a supported SOCKS version */ 51 | #define E_PROXY_UNKNOWN -1010 /* Unkown socks err */ 52 | #define E_PROXY_CLOSED -1011 /* Socket closed while communicating with proxy */ 53 | #define E_PROXY_CANNOTCONNECT -1012 /* Cannot resolve or connect to proxy */ 54 | 55 | struct Proxy; 56 | struct ProxyArgs; 57 | 58 | typedef int (*ProxyConnect)(struct Proxy* o, struct ProxyArgs* args); 59 | 60 | typedef struct Proxy 61 | { 62 | ProxyConnect connect; 63 | const char* proxyUserPass; 64 | const char* proxyName; 65 | U16 proxyPortNo; 66 | } Proxy; 67 | 68 | void Proxy_constructor(Proxy* o, const char* proxyName, 69 | U16 proxyPortNo, const char* proxyUserPass, 70 | int socks); 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /inc/GenPrimT.h: -------------------------------------------------------------------------------- 1 | 2 | /* Used as a wrapper for BufPrint, which is a copied from the 3 | * Barracuda Web Server source code 4 | */ 5 | #include "SharkSSL.h" 6 | -------------------------------------------------------------------------------- /inc/HttpServer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * HEADER 12 | * 13 | * $Id: HttpServer.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2013 - 2018 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://sharkssl.com 33 | **************************************************************************** 34 | * 35 | * 36 | * Minnow Server: SharkSSL WebSocket Server 37 | */ 38 | 39 | /* Barracuda Server stub header used by the Zip File System */ 40 | 41 | #ifndef _HttpServer_h 42 | #define _HttpServer_h 43 | 44 | #define SharkSslStandalone 45 | #ifndef FALSE 46 | #define FALSE 0 47 | #define TRUE 1 48 | #endif 49 | 50 | #ifndef BA_API 51 | #define BA_API 52 | #endif 53 | 54 | #define baFatalE(ecode1,ecode2) baAssert(0) 55 | #define FE_INVALID_CSPREADER 1 56 | 57 | 58 | #include 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /inc/SeCtx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | **************************************************************************** 10 | * HEADER 11 | * 12 | * $Id: SeCtx.h 4914 2021-12-01 18:24:30Z wini $ 13 | * 14 | * COPYRIGHT: Real Time Logic LLC, 2014 - 2017 15 | * 16 | * This software is copyrighted by and is the sole property of Real 17 | * Time Logic LLC. All rights, title, ownership, or other interests in 18 | * the software remain the property of Real Time Logic LLC. This 19 | * software may only be used in accordance with the terms and 20 | * conditions stipulated in the corresponding license agreement under 21 | * which the software has been supplied. Any unauthorized use, 22 | * duplication, transmission, distribution, or disclosure of this 23 | * software is expressly forbidden. 24 | * 25 | * This Copyright notice may not be removed or modified without prior 26 | * written consent of Real Time Logic LLC. 27 | * 28 | * Real Time Logic LLC. reserves the right to modify this software 29 | * without notice. 30 | * 31 | * http://sharkssl.com 32 | **************************************************************************** 33 | * 34 | */ 35 | 36 | #define SE_CTX 37 | 38 | 39 | /** @defgroup SeCtx Context Manager 40 | @ingroup BareMetal 41 | 42 | The SeCtx library makes it possible to use sequential functions in 43 | an event driven system such as a bare metal (non RTOS) system. It 44 | does so by implementing a method for saving and restoring the 45 | stack by using the standard C library functions setjmp/longjmp. 46 | 47 | \if SharkSslDoc 48 | See [Bare Metal Systems](@ref BareMetal) for an introduction. 49 | \else 50 | See [Bare Metal Systems](../../shark/group__BareMetal.html) for an introduction. 51 | \endif 52 | 53 | @{ 54 | */ 55 | 56 | 57 | 58 | 59 | #include 60 | #include 61 | 62 | struct SeCtx; 63 | 64 | /** The task/thread entry point */ 65 | typedef void (*SeCtxTask)(struct SeCtx* ctx); 66 | 67 | /** SeCtx structure: See [Context Manager](@ref SeCtx) and 68 | [Bare Metal Systems](@ref BareMetal) for details. 69 | */ 70 | typedef struct SeCtx 71 | { 72 | jmp_buf savedContext; 73 | #ifndef NDEBUG 74 | U32 magic1; 75 | #endif 76 | jmp_buf startContext; 77 | #ifndef NDEBUG 78 | U32 magic2; 79 | #endif 80 | SeCtxTask task; 81 | U8* stackTop; 82 | void* stackBuf; 83 | #ifndef NDEBUG 84 | U8* currentStack; 85 | #endif 86 | U32 timeout; 87 | U32 startTime; 88 | U16 stackBufLen; 89 | U8 hasContext; 90 | U8 ready; 91 | #ifdef SECTX_EX 92 | SECTX_EX; 93 | #endif 94 | } SeCtx; 95 | 96 | #define SeCtx_setStackTop(o, stackMark) \ 97 | (*(stackMark)=1,(o)->stackTop=stackMark,setjmp((o)->startContext)) 98 | 99 | #ifdef DYNAMIC_SE_CTX 100 | void SeCtx_constructor(SeCtx* o,SeCtxTask t); 101 | void SeCtx_destructor(SeCtx* o); 102 | #else 103 | 104 | 105 | /** Create a Context Manager instance. 106 | \param o uninitialized data of size sizeof(SeCtx). 107 | \param t the task/thread to call 108 | \param buf buffer used for storing the stack when switching from 109 | sequential mode to event driven mode. 110 | \param bufLen buffer length. 111 | \sa SeCtx_panic 112 | */ 113 | void SeCtx_constructor(SeCtx* o, SeCtxTask t, void* buf, int bufLen); 114 | #define SeCtx_destructor(o) 115 | #endif 116 | 117 | void SeCtx_save(SeCtx* o); 118 | 119 | void SeCtx_restore(SeCtx* o); 120 | 121 | /** Function you must implement. This function is called if the buffer 122 | provided in SeCtx_constructor is too small. 123 | */ 124 | void SeCtx_panic(SeCtx* o, U32 size); 125 | 126 | /** @} */ /* end group SeCtx */ 127 | -------------------------------------------------------------------------------- /inc/SharkSSL_opts.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | SharkSSL_opts.h is a user file that you can use to configure 5 | SharkSSL. You do not need to define every option that is defined in 6 | the main configuration file SharkSSL_cfg.h; if you do not define an 7 | option, a default value will be used. In other words, SharkSSL_opts.h 8 | provides a way to override the default configuration options for 9 | SharkSSL. 10 | 11 | */ 12 | 13 | /* 14 | The following options configure the smallest possible SharkSSL library: 15 | */ 16 | 17 | #ifdef SHARKSSL_TINY /* DEFAULT value in SharkSsl_cfg.h */ 18 | 19 | #define SHARKSSL_USE_AES_256 0 /* 1 */ 20 | #define SHARKSSL_ENABLE_AES_GCM 0 /* 1 */ 21 | #define SHARKSSL_USE_SHA_384 0 /* 1 */ 22 | #define SHARKSSL_USE_SHA_512 0 /* 0 */ 23 | #define SHARKSSL_SSL_SERVER_CODE 0 /* 1 */ 24 | #define SHARKSSL_ENABLE_CLIENT_AUTH 0 /* 1 */ 25 | #define SHARKSSL_ENABLE_SNI 1 /* 1 */ 26 | #define SHARKSSL_ENABLE_RSA 0 /* 1 */ 27 | #define SHARKSSL_ENABLE_SESSION_CACHE 0 /* 1 */ 28 | #define SHARKSSL_ENABLE_SECURE_RENEGOTIATION 0 /* 1 */ 29 | #define SHARKSSL_ENABLE_DHE_RSA 0 /* 1 */ 30 | #define SHARKSSL_ENABLE_SELECT_CIPHERSUITE 0 /* 1 */ 31 | #define SHARKSSL_ENABLE_ALPN_EXTENSION 1 /* 1 */ 32 | #define SHARKSSL_ENABLE_RSA_API 0 /* 0 */ 33 | #define SHARKSSL_ENABLE_RSA_PKCS1 0 /* 1 */ 34 | #define SHARKSSL_ENABLE_ECDSA_API 0 /* 1 */ 35 | #define SHARKSSL_ENABLE_PEM_API 0 /* 1 */ 36 | #define SHARKSSL_ENABLE_INFO_API 0 /* 1 */ 37 | #define SHARKSSL_ENABLE_CERT_CHAIN 0 /* 1 */ 38 | #define SHARKSSL_ENABLE_CA_LIST 1 /* 1 */ 39 | #define SHARKSSL_ENABLE_CERTSTORE_API 0 /* 0 */ 40 | #define SHARKSSL_SHA256_SMALL_FOOTPRINT 1 /* 0 */ 41 | #define SHARKSSL_BIGINT_EXP_SLIDING_WINDOW_K 1 /* 4 */ 42 | #define SHARKSSL_ENABLE_AES_CTR_MODE 0 /* 1 */ 43 | #define SHARKSSL_AES_CIPHER_LOOP_UNROLL 0 /* 1 */ 44 | #define SHARKSSL_UNALIGNED_ACCESS 1 /* nd */ 45 | #define SHARKSSL_BIGINT_WORDSIZE 32 /* 32 */ 46 | #define SHARKSSL_USE_ECC 1 /* 1 */ 47 | #define SHARKSSL_ENABLE_ECDSA 1 /* 1 */ 48 | #define SHARKSSL_ECC_VERIFY_POINT 0 /* 1 */ 49 | #define SHARKSSL_ECC_TIMING_RESISTANT 0 /* 0 */ 50 | #define SHARKSSL_ECC_USE_SECP521R1 0 /* 1 */ 51 | #define SHARKSSL_ECC_USE_BRAINPOOLP512R1 0 /* 1 */ 52 | #define SHARKSSL_ENABLE_ECDHE_RSA 0 /* 1 */ 53 | #define SHARKSSL_USE_RNG_TINYMT 1 /* 0 */ 54 | 55 | 56 | #ifndef BASIC_TRUST_CHECK 57 | #define BASIC_TRUST_CHECK 58 | #endif 59 | 60 | #ifndef NDEBUG 61 | #define NDEBUG 62 | #endif 63 | 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /inc/SharkSslEx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: SharkSslEx.h 5102 2022-02-19 19:34:26Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2013 - 2022 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://www.realtimelogic.com 33 | * http://www.sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | #ifndef _SharkSslEx_h 38 | #define _SharkSslEx_h 39 | 40 | #include "SharkSSL.h" 41 | 42 | /* Macro set if compiled together with BAS */ 43 | #ifndef ThreadLib_hpp 44 | #ifndef BaTime 45 | #include 46 | typedef time_t BaTime; 47 | #endif 48 | #endif 49 | 50 | /** SubjectAltName Iterator */ 51 | typedef struct SubjectAltNameEnumerator 52 | { 53 | U8 *ptr, *dataptr; 54 | U32 len, datalen; 55 | } 56 | SubjectAltNameEnumerator; 57 | 58 | /** SubjectAltName 59 | */ 60 | typedef struct SubjectAltName 61 | { 62 | U8 *ptr; 63 | U16 len; 64 | U8 tag; 65 | } SubjectAltName; 66 | 67 | #define SubjectAltName_getTag(o) ((o)->tag) 68 | #define SubjectAltName_getLen(o) ((o)->len) 69 | #define SubjectAltName_getPtr(o) ((o)->ptr) 70 | #define SubjectAltName_isValid(o) (NULL != SubjectAltName_getPtr(o)) 71 | 72 | SHARKSSL_API void SubjectAltNameEnumerator_constructor(SubjectAltNameEnumerator *o, U8 *ptr, U16 len); 73 | SHARKSSL_API void SubjectAltNameEnumerator_getElement(SubjectAltNameEnumerator *o, SubjectAltName *s); 74 | #define SubjectAltNameEnumerator_nextElement SubjectAltNameEnumerator_getElement 75 | 76 | /** possible values for SubjectAltName_getTag 77 | see https://tools.ietf.org/html/rfc5280#section-4.2.1.6 78 | */ 79 | #define SUBJECTALTNAME_OTHERNAME 0 80 | #define SUBJECTALTNAME_RFC822NAME 1 81 | #define SUBJECTALTNAME_DNSNAME 2 82 | #define SUBJECTALTNAME_X400ADDRESS 3 83 | #define SUBJECTALTNAME_DIRECTORYNAME 4 84 | #define SUBJECTALTNAME_EDIPARTYNAME 5 85 | #define SUBJECTALTNAME_URI 6 86 | #define SUBJECTALTNAME_IPADDRESS 7 87 | 88 | 89 | /** Case insensitive string compare. 90 | */ 91 | SHARKSSL_API int sharkStrCaseCmp( 92 | const char *a, int aLen, const char *b, int bLen); 93 | 94 | 95 | /** Certificate subject name/subject alternative name comparison to "name" 96 | */ 97 | SHARKSSL_API int sharkSubjectSubjectAltCmp( 98 | const char *cn, U16 cnLen, U8 *subjAltPtr, U16 subjAltLen, const char* name, U16 nameLen); 99 | 100 | /** Converts the expected certificate time string format 101 | YY[YY]MMDDHHMMSSZ 102 | to seconds since Jan 1, 1970. 103 | */ 104 | SHARKSSL_API BaTime sharkParseCertTime(const U8* utc, U8 len); 105 | 106 | 107 | 108 | /** @addtogroup SharkSslInfoAndCodes 109 | @{ 110 | */ 111 | 112 | /** #SharkSslCon_trusted return values */ 113 | typedef enum 114 | { 115 | /** Not a secure connection (SSL handshake not completed). 116 | */ 117 | SharkSslConTrust_NotSSL=10, 118 | 119 | /** The SSL certificate is not trusted and the subject's common 120 | name does not matches the host name of the URL. 121 | */ 122 | SharkSslConTrust_None, 123 | 124 | /** Domain mismatch: The SSL certificate is trusted but the 125 | subject's common name does not matches the host name of the URL. 126 | */ 127 | SharkSslConTrust_Cert, 128 | 129 | /** The subject's common name matches the host name of the URL, but 130 | the certificate is not trusted. This is typical for expired 131 | certificates. 132 | */ 133 | SharkSslConTrust_Cn, 134 | 135 | /** The peer's SSL certificate is trusted and the 136 | subject's common name matches the host name of the URL. 137 | */ 138 | SharkSslConTrust_CertCn, 139 | 140 | /** This value is returned instead of SharkSslConTrust_CertCn when a 141 | certificate is trusted and the SharkSSL code is compiled with 142 | SHARKSSL_CHECK_DATE=1. This mode also checks the 143 | certificate's 'from' and 'to' dates with the time returned by 144 | #baGetUnixTime. The certificate and all intermediates are 145 | checked, except for the root certificate. Unfortunately, many 146 | root certifies are expired and must simply be accepted. 147 | */ 148 | SharkSslConTrust_CertCnDate 149 | } SharkSslConTrust; 150 | 151 | #if SHARKSSL_CHECK_DATE == 0 152 | #define SharkSslConTrust_CertCnDate SharkSslConTrust_CertCn 153 | #endif 154 | 155 | 156 | /** @} */ /* end group SharkSslInfoAndCodes */ 157 | 158 | /** @addtogroup SharkSslApi 159 | @{ 160 | */ 161 | 162 | /** Returns the peer's "trust" status and certificate. 163 | 164 | This function extends #SharkSslCon_trustedCA and also checks that 165 | the domain name (including any wildcards) matches the domain 166 | name. The function also checks the certificate's date if the 167 | SharkSSL code is compiled with #SHARKSSL_CHECK_DATE =1. 168 | 169 | \param o the SharkSslCon object 170 | 171 | \param name is the domain name (common name) 172 | 173 | \param cPtr is an optional pointer that will be set to the 174 | connections's SharkSslCertInfo object, if provided. 175 | 176 | \returns SharkSslConTrust 177 | 178 | \sa SharkSslConTrust and SharkSslCon_trustedCA 179 | */ 180 | SHARKSSL_API SharkSslConTrust SharkSslCon_trusted( 181 | SharkSslCon* o, const char* name, SharkSslCertInfo** cPtr); 182 | 183 | /** @} */ /* end group SharkSslApi */ 184 | 185 | #endif 186 | -------------------------------------------------------------------------------- /inc/SharkSslSCMgr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: SharkSslSCMgr.h 5300 2022-10-25 13:21:57Z wini $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2013 - 2022 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://www.realtimelogic.com 33 | * http://www.sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | #ifndef _SharkSslSCMgr_h 38 | #define _SharkSslSCMgr_h 39 | 40 | #include 41 | #include "SplayTree.h" 42 | #include "DoubleList.h" 43 | 44 | #ifndef SHARKSSL_API 45 | #define SHARKSSL_API 46 | #else /* Barracuda */ 47 | #define SHARKSSL_BA 1 48 | #endif 49 | 50 | 51 | /** @addtogroup SharkSslSCMgr 52 | @{ 53 | */ 54 | 55 | /** The handle returned by #SharkSslSCMgr_get and passed into 56 | #SharkSslSCMgr_save. The handle will be NULL when SharkSslSCMgr_get 57 | does not have a saved session. The null pointer must be passed into 58 | SharkSslSCMgr_save. 59 | */ 60 | typedef struct 61 | { 62 | SplayTreeNode super; 63 | DoubleLink dlink; 64 | SharkSslSession* ss; 65 | const char* host; 66 | U16 hostLen; 67 | U16 port; 68 | } SharkSslSCMgrNode; 69 | 70 | 71 | 72 | /** See #SharkSslSCMgr_constructor for details. 73 | */ 74 | typedef struct 75 | { 76 | SharkSslIntf super; 77 | SplayTree stree; 78 | DoubleList dlist; 79 | SharkSsl* ssl; 80 | U32 maxTime; 81 | int noOfSessions; 82 | } SharkSslSCMgr; 83 | 84 | 85 | #ifdef __cplusplus 86 | extern "C" { 87 | #endif 88 | 89 | /** SharkSslSCMgr simplifies using the session API for TLS clients; 90 | the constructor initializes a SharkSslSCMgr instance. 91 | \param o an uninitialized static object or dynamically allocated object. 92 | \param ssl an initialized SharkSsl instance. 93 | \param maxTime the maximum time for stored sessions in seconds. A 94 | good value would be 60*60. 95 | */ 96 | SHARKSSL_API void SharkSslSCMgr_constructor( 97 | SharkSslSCMgr* o, SharkSsl* ssl, U32 maxTime); 98 | 99 | /** Resume a session. The returned value is a handle and should not be 100 | modified by the client. The method returns NULL if no session could 101 | be resumed. The method must be called just after 102 | SharkSslCon_isHandshakeComplete() returns true. 103 | */ 104 | SHARKSSL_API SharkSslSCMgrNode* SharkSslSCMgr_get( 105 | SharkSslSCMgr* o,SharkSslCon* scon,const char* host,U16 port); 106 | 107 | /** Save the session when #SharkSslSCMgr_get returns NULL. It is an 108 | error calling this method if #SharkSslSCMgr_get returns a 109 | handle. The method should be called when closing the connection 110 | and just before terminating the SharkSslCon object. 111 | 112 | \param o an initialized SharkSslSCMgrNode object 113 | \param scon a valid SharkSslCon object. 114 | \param host the server's domain name 115 | \param port the server's port number e.g. 443 116 | \return 0 if session was saved, otherwise -1 is returned. 117 | */ 118 | SHARKSSL_API int SharkSslSCMgr_save( 119 | SharkSslSCMgr* o, SharkSslCon* scon, const char* host, U16 port); 120 | 121 | #ifdef __cplusplus 122 | } 123 | #endif 124 | 125 | /** @} */ /* end group SharkSslSCMgr */ 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /inc/SplayTree.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * Barracuda Embedded Web-Server 10 | **************************************************************************** 11 | * HEADER 12 | * 13 | * $Id: SplayTree.h 4915 2021-12-01 18:26:55Z wini $ 14 | * 15 | * COPYRIGHT: Real Time Logic, 2004 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://www.realtimelogic.com 33 | **************************************************************************** 34 | * 35 | */ 36 | 37 | #ifndef __SplayTree_h 38 | #define __SplayTree_h 39 | 40 | #include 41 | 42 | typedef const void* SplayTreeKey; 43 | 44 | typedef struct SplayTreeNode 45 | { 46 | #ifdef __cplusplus 47 | void *operator new(size_t s) { return ::baMalloc(s); } 48 | void operator delete(void* d) { if(d) ::baFree(d); } 49 | void *operator new(size_t, void *place) { return place; } 50 | void operator delete(void*, void *) { } 51 | SplayTreeNode(){} /* Dummy constructor */ 52 | SplayTreeNode(SplayTreeKey key); 53 | SplayTreeKey getKey(); 54 | #endif 55 | struct SplayTreeNode* left; 56 | struct SplayTreeNode* right; 57 | SplayTreeKey key; 58 | } SplayTreeNode; 59 | 60 | #ifdef __cplusplus 61 | extern "C" { 62 | #endif 63 | BA_API void SplayTreeNode_constructor(SplayTreeNode* o, SplayTreeKey key); 64 | #define SplayTreeNode_getKey(o) (o)->key 65 | 66 | #ifdef __cplusplus 67 | } 68 | inline SplayTreeNode::SplayTreeNode(SplayTreeKey key) { 69 | SplayTreeNode_constructor(this, key); } 70 | inline SplayTreeKey SplayTreeNode::getKey() { 71 | return SplayTreeNode_getKey(this); } 72 | #endif 73 | 74 | /** Compares k and n, returning negative value if kn. 76 | */ 77 | typedef int (*SplayTree_Compare)(SplayTreeNode* n, SplayTreeKey k); 78 | 79 | typedef int (*SplayTree_Iter)(void* o, SplayTreeNode* n); 80 | 81 | 82 | typedef struct SplayTree 83 | { 84 | #ifdef __cplusplus 85 | SplayTree(){} /* Dummy constructor */ 86 | SplayTree(SplayTree_Compare compare); 87 | int insert(SplayTreeNode* n); 88 | SplayTreeNode* find(SplayTreeKey key); 89 | int remove(SplayTreeNode* n); 90 | SplayTreeNode* getRoot(); 91 | private: 92 | #endif 93 | SplayTreeNode* root; 94 | SplayTree_Compare compare; 95 | } SplayTree; 96 | 97 | #ifdef __cplusplus 98 | extern "C" { 99 | #endif 100 | #define SplayTree_constructor(o, compareCB) do { \ 101 | (o)->compare = compareCB; \ 102 | (o)->root = 0; \ 103 | } while(0) 104 | BA_API int SplayTree_insert(SplayTree* o, SplayTreeNode* n); 105 | BA_API SplayTreeNode* SplayTree_find(SplayTree* o, SplayTreeKey key); 106 | BA_API int SplayTree_remove(SplayTree* o, SplayTreeNode* n); 107 | #define SplayTree_getRoot(o) (o)->root 108 | BA_API int SplayTree_iterate(SplayTree* o, void* userObj, SplayTree_Iter i); 109 | #ifdef __cplusplus 110 | } 111 | inline SplayTree::SplayTree(SplayTree_Compare compare) { 112 | SplayTree_constructor(this, compare); } 113 | inline int SplayTree::insert(SplayTreeNode* n) { 114 | return SplayTree_insert(this, n); } 115 | inline SplayTreeNode* SplayTree::find(SplayTreeKey key) { 116 | return SplayTree_find(this, key); } 117 | inline int SplayTree::remove(SplayTreeNode* n) { 118 | return SplayTree_remove(this, n); } 119 | inline SplayTreeNode* SplayTree::getRoot() { 120 | return SplayTree_getRoot(this); } 121 | #endif 122 | 123 | 124 | #endif 125 | -------------------------------------------------------------------------------- /inc/ZipFileSystem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * HEADER 12 | * 13 | * $Id: ZipFileSystem.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2013 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://realtimelogic.com 33 | * http://sharkssl.com 34 | **************************************************************************** 35 | * 36 | * 37 | */ 38 | 39 | #ifndef _ZipFileSystem_h 40 | #define _ZipFileSystem_h 41 | 42 | 43 | #include 44 | #include "MSLib.h" 45 | 46 | 47 | /** @defgroup ZipFileSystem Minnow Server ZIP File System Plugin 48 | @ingroup MSLib 49 | 50 | \brief The ZipFileSystem is an optional plugin that requires the 51 | 53 | Barracuda Web Server ZipFileIterator plugin. 54 | 55 | The optional ZipFileSystem plugin for the Minnow Server lets you 56 | store the web presentation logic compressed in the 57 | device. Compressed web applications are typically only one-third 58 | of the original size. The compressed web pages are not 59 | uncompressed on the device. The web pages are extracted from 60 | within the ZIP file and sent "as is" to the browser. All modern 61 | browsers uncompress "compressed" data received from the servers. 62 | 63 | The optional ZipFileSystem plugin is available at an additional 64 | cost. 65 | 66 | The ZipFileSystem is a small plugin that includes the classes 67 | ZipContainer, CentralDirIterator, and ZipFileInfo. The 68 | complete ZipFileSystem does not come delivered with SharkSSL. 69 | @{ 70 | */ 71 | 72 | /** The ZipFileSystem handle. See msInitZipFileSystem for more information. 73 | */ 74 | typedef struct { 75 | ZipReader* reader; 76 | ZipContainer zc; 77 | U8 buf[256]; 78 | } ZipFileSystem; 79 | 80 | #ifdef __cplusplus 81 | extern "C" { 82 | #endif 83 | 84 | /** 85 | Initializes the ZIP File System and returns a WsFetchPage callback function. 86 | 87 | \param zfs the ZipFileSystem to initialize 88 | 89 | \param zipReader a device driver (interface object) between the Zip 90 | File System and the ZIP file. The example below extern declares a 91 | function that returns a ZipReader object. This function is typically 92 | created automatically by our bin2c tool which converts a ZIP file into 93 | a C array. The bin2c tool also generates a ZipReader object 94 | automatically. You can also create your own ZipReader driver object if 95 | you, for example, want to keep the ZIP file separate from your firmware. 96 | 97 | Example code: 98 | \code 99 | extern ZipReader* getZipReader(void); 100 | . 101 | . 102 | WssProtocolHandshake wph={0}; 103 | ZipFileSystem zfs; 104 | wph.fetchPage = msInitZipFileSystem(&zfs, getZipReader()); 105 | wph.fetchPageHndl=&zfs; 106 | \endcode 107 | 108 | The following example shows a code snippet from a ZIP file converted 109 | to C data by running the bin2c tool as follows:
bin2c -z getZipReader 110 | www.zip www.c 111 | 112 | \code 113 | static const U8 zipfileData[] = { ZIP FILE CONTENT HERE }; 114 | 115 | //ZIP device driver function 116 | int readFromZipFile(CspReader* o,void* data,U32 offset,U32 size,int blockStart) 117 | { 118 | memcpy(data, zipfileData+offset, size); // Copy ZIP content at offset pos 119 | return 0; // OK 120 | } 121 | 122 | // Init and return a ZIP device driver 123 | ZipReader* getZipReader(void) 124 | { 125 | static ZipReader zipReader; 126 | ZipReader_constructor(&zipReader,readFromZipFile,sizeof(zipfileData)); 127 | CspReader_setIsValid(&zipReader); 128 | return &zipReader; 129 | } 130 | \endcode 131 | */ 132 | MSFetchPage msInitZipFileSystem(ZipFileSystem* zfs, ZipReader* zipReader); 133 | 134 | #ifdef __cplusplus 135 | } 136 | #endif 137 | 138 | 139 | /** @} */ /* end group ZipFileSystem */ 140 | 141 | #endif 142 | -------------------------------------------------------------------------------- /inc/arch/BareMetal/TargConfig.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: TargConfig.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2014 - 2017 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://www.realtimelogic.com 33 | * http://www.sharkssl.com 34 | **************************************************************************** 35 | 36 | 37 | The following file shows how to configure SharkSSL for bare metal (no RTOS). 38 | 39 | The allocators are mapped to lwIP's allocator lib 40 | 41 | */ 42 | #ifndef _SharkSsl_TargConfig_h 43 | #define _SharkSsl_TargConfig_h 44 | 45 | #if !defined(B_LITTLE_ENDIAN) && !defined(B_BIG_ENDIAN) 46 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 47 | #define B_LITTLE_ENDIAN 48 | #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 49 | #define B_BIG_ENDIAN 50 | #endif 51 | #endif 52 | 53 | 54 | #ifndef NDEBUG 55 | #pragma GCC diagnostic ignored "-Wunused-value" 56 | #define baAssert(exp) ( (exp) ? (void)0 : sharkAssert(__FILE__, __LINE__) ) 57 | #else 58 | #define baAssert(x) 59 | #endif 60 | 61 | #ifdef _SHARKSSL_C_ 62 | #ifndef NDEBUG 63 | const char* assert_file; 64 | int assert_line; 65 | void sharkAssert(const char* file, int line) 66 | { 67 | assert_file = file; 68 | assert_line = line; 69 | for(;;); 70 | } 71 | #endif 72 | #endif 73 | 74 | #ifndef TRUE 75 | #define TRUE 1 76 | #endif 77 | #ifndef FALSE 78 | #define FALSE 0 79 | #endif 80 | 81 | #if BYTE_ORDER == LITTLE_ENDIAN 82 | #define B_LITTLE_ENDIAN 83 | #elif BYTE_ORDER == BIG_ENDIAN 84 | #define B_BIG_ENDIAN 85 | #else 86 | #error fix endian 87 | #endif 88 | 89 | /** 90 | * baMalloc should return 32-bit aligned addresses when succesful, 91 | * (void*)0 when not succesful. 92 | */ 93 | 94 | #ifdef __PIC32__ 95 | #ifndef UMM_MALLOC 96 | #define UMM_MALLOC 97 | #endif 98 | #endif 99 | 100 | #ifdef UMM_MALLOC 101 | #include "../../../examples/malloc/umm_malloc.h" 102 | #define baMalloc(s) umm_malloc(s) 103 | #define baRealloc(m, s) umm_realloc(m, s) 104 | #define baFree(m) umm_free(m) 105 | #else 106 | #include 107 | #include 108 | /* should return 32-bit aligned address */ 109 | #define baMalloc(s) mem_malloc(s) 110 | /* not implemeneted, which is OK */ 111 | #define baRealloc(m, s) 0 112 | #define baFree(m) mem_free(m) 113 | #endif 114 | 115 | 116 | #include 117 | typedef uint8_t U8; 118 | typedef int8_t S8; 119 | typedef uint16_t U16; 120 | typedef int16_t S16; 121 | typedef uint32_t U32; 122 | typedef int32_t S32; 123 | typedef uint64_t U64; 124 | typedef int64_t S64; 125 | typedef U8 BaBool; 126 | 127 | 128 | typedef U8 ThreadMutexBase; 129 | #define ThreadMutex_constructor(o) 130 | #define ThreadMutex_destructor(o) 131 | #define ThreadMutex_set(o) 132 | #define ThreadMutex_release(o) 133 | 134 | #ifdef __PIC32__ 135 | #include 136 | #define baGetUnixTime() \ 137 | SYS_TMR_SystemCountGet()/SYS_TMR_SystemCountFrequencyGet() 138 | #else 139 | /* Assume LwIP */ 140 | #define baGetUnixTime() sys_now() 141 | #endif 142 | 143 | #endif /* _SharkSsl_TargConfig_h */ 144 | -------------------------------------------------------------------------------- /inc/arch/FreeRTOS/TargConfig.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: TargConfig.h 5466 2023-07-12 14:04:42Z wini $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2015 - 2023 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://www.realtimelogic.com 33 | * http://www.sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | #ifndef _SharkSsl_TargConfig_h 38 | #define _SharkSsl_TargConfig_h 39 | 40 | #if !defined(B_LITTLE_ENDIAN) && !defined(B_BIG_ENDIAN) 41 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 42 | #define B_LITTLE_ENDIAN 43 | #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 44 | #define B_BIG_ENDIAN 45 | #endif 46 | #endif 47 | 48 | #ifdef ESP_PLATFORM 49 | #include 50 | #include 51 | #include 52 | #else 53 | #include 54 | #include 55 | #include 56 | #endif 57 | 58 | /** 59 | * baMalloc should return 32-bit aligned addresses when succesful, 60 | * (void*)0 when not succesful. 61 | * baRealloc should return 32-bit aligned addresses when succesful, 62 | * (void*)0 when not succesful or NOT available. 63 | */ 64 | 65 | #ifndef NDEBUG 66 | #define baAssert(exp) ( (exp) ? (void)0 : sharkAssert(__FILE__, __LINE__) ) 67 | #else 68 | #define baAssert(x) 69 | #endif 70 | 71 | 72 | void sharkAssert(const char* file, int line); 73 | #ifdef _SHARKSSL_C_ 74 | #ifndef NDEBUG 75 | const char* assert_file; 76 | int assert_line; 77 | void sharkAssert(const char* file, int line) 78 | { 79 | assert_file = file; 80 | assert_line = line; 81 | for(;;); 82 | } 83 | #endif 84 | #endif 85 | 86 | 87 | #ifndef TRUE 88 | #define TRUE 1 89 | #endif 90 | 91 | #ifndef FALSE 92 | #define FALSE 0 93 | #endif 94 | 95 | #ifdef UMM_MALLOC 96 | #include "../../../examples/malloc/umm_malloc.h" 97 | #define baMalloc(s) umm_malloc(s) 98 | #define baRealloc(m, s) umm_realloc(m, s) 99 | #define baFree(m) umm_free(m) 100 | #else 101 | #include 102 | #define baMalloc(s) malloc(s) /* should return 32-bit aligned address */ 103 | #define baRealloc(m, s) realloc(m, s) /* as above */ 104 | #define baFree(m) free(m) 105 | #endif 106 | 107 | #ifndef INTEGRAL_TYPES 108 | #define INTEGRAL_TYPES 109 | #if (__STDC_VERSION__ >= 199901L) || defined( __GNUC__) 110 | #include 111 | typedef uint8_t U8; 112 | typedef int8_t S8; 113 | typedef uint16_t U16; 114 | typedef int16_t S16; 115 | typedef uint32_t U32; 116 | typedef int32_t S32; 117 | typedef uint64_t U64; 118 | typedef int64_t S64; 119 | #else 120 | typedef unsigned char U8; 121 | typedef signed char S8; 122 | typedef unsigned short U16; 123 | typedef signed short S16; 124 | typedef unsigned int U32; 125 | typedef signed int S32; 126 | typedef unsigned long long U64; 127 | typedef signed long long S64; 128 | #endif 129 | #endif 130 | typedef U8 BaBool; 131 | 132 | 133 | #define baGetUnixTime() (U32)(((U64)xTaskGetTickCount() * (U64)portTICK_PERIOD_MS) / 1000) 134 | 135 | #if !configUSE_MUTEXES 136 | #error Set configUSE_MUTEXES in FreeRTOS.h 137 | #endif 138 | 139 | 140 | typedef struct ThreadMutexBase 141 | { 142 | SemaphoreHandle_t mutex; 143 | } ThreadMutexBase; 144 | 145 | #if 0 146 | #define ThreadMutex_destructor(o) vSemaphoreDelete((o)->mutex) 147 | #define ThreadMutex_set(o) xSemaphoreTake((o)->mutex,portMAX_DELAY) 148 | #define ThreadMutex_release(o) xSemaphoreGive((o)->mutex) 149 | #define ThreadMutex_constructor(o) (o)->mutex=xSemaphoreCreateMutex() 150 | #else 151 | #define ThreadMutex_destructor(o) 152 | #define ThreadMutex_set(o) 153 | #define ThreadMutex_release(o) 154 | #define ThreadMutex_constructor(o) 155 | #endif 156 | 157 | 158 | 159 | /* The following is not required by SharkSSL, but is used by some of 160 | the examples. 161 | */ 162 | 163 | #ifndef TRUE 164 | #define TRUE 1 165 | #endif 166 | 167 | #ifndef FALSE 168 | #define FALSE 0 169 | #endif 170 | 171 | #endif /* _SharkSsl_TargConfig_h */ 172 | -------------------------------------------------------------------------------- /inc/arch/INTEGRITY/TargConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * Barracuda Embedded Web-Server 10 | * 11 | **************************************************************************** 12 | * HEADER 13 | * 14 | * $Id: TargConfig.h 5076 2022-02-10 16:59:48Z wini $ 15 | * 16 | * COPYRIGHT: Real Time Logic, 2020 17 | * 18 | * This software is copyrighted by and is the sole property of Real 19 | * Time Logic LLC. All rights, title, ownership, or other interests in 20 | * the software remain the property of Real Time Logic LLC. This 21 | * software may only be used in accordance with the terms and 22 | * conditions stipulated in the corresponding license agreement under 23 | * which the software has been supplied. Any unauthorized use, 24 | * duplication, transmission, distribution, or disclosure of this 25 | * software is expressly forbidden. 26 | * 27 | * This Copyright notice may not be removed or modified without prior 28 | * written consent of Real Time Logic LLC. 29 | * 30 | * Real Time Logic LLC. reserves the right to modify this software 31 | * without notice. 32 | * 33 | * http://www.realtimelogic.com 34 | **************************************************************************** 35 | * 36 | * Platform: INTEGRITY. 37 | * 38 | */ 39 | #ifndef _SharkSsl_TargConfig_h 40 | #define _SharkSsl_TargConfig_h 41 | 42 | #include 43 | 44 | #if defined(__LittleEndian) || defined(LittleEndian) || defined(TM_LITTLE_ENDIAN) 45 | #ifdef B_BIG_ENDIAN 46 | #error ENDIANESS MISMATCH! 47 | #endif 48 | #ifndef B_LITTLE_ENDIAN 49 | #define B_LITTLE_ENDIAN 50 | #endif 51 | #elif defined(__BigEndian) || defined(BigEndian) || defined(TM_BIG_ENDIAN) 52 | #ifdef B_LITTLE_ENDIAN 53 | #error ENDIANESS MISMATCH! 54 | #endif 55 | #ifndef B_BIG_ENDIAN 56 | #define B_BIG_ENDIAN 57 | #endif 58 | #else 59 | #error Missing little/big endian declaration 60 | #endif 61 | 62 | #ifndef NDEBUG 63 | #include 64 | #define baAssert(x) assert(x) 65 | #else 66 | #define baAssert(x) 67 | #endif 68 | 69 | /* The following is not required by SharkSSL, but is used by some of the examples */ 70 | 71 | #ifndef TRUE 72 | #define TRUE 1 73 | #endif 74 | 75 | #ifndef FALSE 76 | #define FALSE 0 77 | #endif 78 | 79 | #ifndef SHARKSSL_API 80 | //#define SHARKSSL_API 81 | #endif 82 | #define BaBool Boolean 83 | 84 | #define baMalloc(s) malloc(s) /* should return 32-bit aligned address */ 85 | #define baRealloc(m, s) realloc(m, s) /* as above */ 86 | #define baFree(m) free(m) 87 | 88 | #include 89 | #define baGetUnixTime() ((U32)time(0)) 90 | 91 | #include 92 | typedef uint8_t U8; 93 | typedef int8_t S8; 94 | typedef uint16_t U16; 95 | typedef int16_t S16; 96 | typedef uint32_t U32; 97 | typedef int32_t S32; 98 | typedef uint64_t U64; 99 | typedef int64_t S64; 100 | 101 | #if defined(NDEBUG) && !defined(BA_OS_CHECK) 102 | #define Thread_ce(x) x 103 | #else 104 | #ifdef __cplusplus 105 | extern "C" { 106 | #endif 107 | void Thread_cef(Error status, const char* file, int line); 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | #define Thread_ce(x) baAssert(Success==x) 112 | #endif 113 | 114 | typedef struct ThreadMutexBase 115 | { 116 | Value tid; /* Lock owner */ 117 | LocalMutex mutex; 118 | } ThreadMutexBase; 119 | 120 | #define ThreadMutex_constructor(o) \ 121 | Thread_ce(CreateLocalMutex(&(o)->mutex)) 122 | 123 | #define ThreadMutex_destructor(o) \ 124 | Thread_ce(CloseLocalMutex((o)->mutex)) 125 | 126 | #define ThreadMutex_set(o) do {\ 127 | Thread_ce(WaitForLocalMutex((o)->mutex));\ 128 | Thread_ce(GetTaskUniqueId(CurrentTask(), &(o)->tid));\ 129 | } while(0) 130 | 131 | #define ThreadMutex_release(o) do{\ 132 | (o)->tid=0;\ 133 | Thread_ce(ReleaseLocalMutex((o)->mutex));\ 134 | } while(0) 135 | 136 | 137 | 138 | 139 | #endif 140 | -------------------------------------------------------------------------------- /inc/arch/MDK/TargConfig.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: TargConfig.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2016 - 2018 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://www.realtimelogic.com 33 | * http://www.sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | #ifndef _SharkSsl_TargConfig_h 38 | #define _SharkSsl_TargConfig_h 39 | 40 | #include 41 | #include 42 | 43 | 44 | #if !defined(B_BIG_ENDIAN) && !defined(B_LITTLE_ENDIAN) 45 | #ifdef __ARM_BIG_ENDIAN 46 | #define B_BIG_ENDIAN 47 | #else 48 | #define B_LITTLE_ENDIAN 49 | #endif 50 | #endif 51 | 52 | 53 | #ifndef NDEBUG 54 | #define baAssert(exp) ( (exp) ? (void)0 : sharkAssert(__FILE__, __LINE__) ) 55 | #else 56 | #define baAssert(x) 57 | #endif 58 | 59 | #ifdef __cplusplus 60 | extern "C" { 61 | #endif 62 | void sharkAssert(const char* file, int line); 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #ifdef _SHARKSSL_C_ 68 | const char* assert_file; 69 | int assert_line; 70 | void sharkAssert(const char* file, int line) 71 | { 72 | assert_file = file; 73 | assert_line = line; 74 | for(;;); 75 | } 76 | #endif 77 | 78 | 79 | 80 | /* The following is not required by SharkSSL, but is used by some of 81 | the examples. 82 | */ 83 | 84 | #ifndef TRUE 85 | #define TRUE 1 86 | #endif 87 | 88 | #ifndef FALSE 89 | #define FALSE 0 90 | #endif 91 | 92 | /** 93 | * baMalloc should return 32-bit aligned addresses when succesful, 94 | * (void*)0 when not succesful. 95 | * baRealloc should return 32-bit aligned addresses when succesful, 96 | * (void*)0 when not succesful or NOT available. 97 | */ 98 | 99 | #define UMM_MALLOC 100 | 101 | #ifdef UMM_MALLOC 102 | #include 103 | #define baMalloc(s) umm_malloc(s) 104 | #define baRealloc(m, s) umm_realloc(m, s) 105 | #define baFree(m) umm_free(m) 106 | #define UMM_CRITICAL_ENTRY umm_critical_entry 107 | #define UMM_CRITICAL_EXIT umm_critical_exit 108 | void umm_critical_entry(void); 109 | void umm_critical_exit(void); 110 | void umm_init(void); 111 | #else 112 | #include 113 | #define baMalloc(s) malloc(s) /* should return 32-bit aligned address */ 114 | #define baRealloc(m, s) realloc(m, s) /* as above */ 115 | #define baFree(m) free(m) 116 | #endif 117 | 118 | #ifndef INTEGRAL_TYPES 119 | #define INTEGRAL_TYPES 120 | #if (__STDC_VERSION__ >= 199901L) || defined( __GNUC__) 121 | #include 122 | typedef uint8_t U8; 123 | typedef int8_t S8; 124 | typedef uint16_t U16; 125 | typedef int16_t S16; 126 | typedef uint32_t U32; 127 | typedef int32_t S32; 128 | typedef uint64_t U64; 129 | typedef int64_t S64; 130 | #else 131 | typedef unsigned char U8; 132 | typedef signed char S8; 133 | typedef unsigned short U16; 134 | typedef signed short S16; 135 | typedef unsigned int U32; 136 | typedef signed int S32; 137 | typedef unsigned long long U64; 138 | typedef signed long long S64; 139 | #endif 140 | #endif 141 | typedef U8 BaBool; 142 | 143 | #ifdef EXT_SHARK_LIB 144 | U32 baGetUnixTime(void); 145 | char *sharkStrchr(const char *s, int c); 146 | char *sharkStrstr(const char *haystack, const char *needle); 147 | #else 148 | /* FIXME */ 149 | #define baGetUnixTime() osKernelSysTick() 150 | #endif 151 | 152 | typedef struct ThreadMutexBase 153 | { 154 | osMutexId mid; 155 | osMutexDef_t mdef; 156 | #ifdef __MBED_CMSIS_RTOS_CA9 157 | int32_t mdata[4]; 158 | #else 159 | int32_t mdata[3]; 160 | #endif 161 | } ThreadMutexBase; 162 | 163 | void ThreadMutex_destructor(ThreadMutexBase* o); 164 | void ThreadMutex_set(ThreadMutexBase* o); 165 | void ThreadMutex_release(ThreadMutexBase* o); 166 | void ThreadMutex_constructor(ThreadMutexBase* o); 167 | 168 | #ifdef _SHARKSSL_C_ 169 | #include 170 | void ThreadMutex_constructor(ThreadMutexBase* o) 171 | { 172 | memset(o->mdata, 0, sizeof(o->mdata)); 173 | o->mdef.mutex = o->mdata; 174 | o->mid = osMutexCreate(&o->mdef); 175 | baAssert(o->mid); 176 | } 177 | 178 | void ThreadMutex_destructor(ThreadMutexBase* o) 179 | { 180 | osMutexDelete(o->mid); 181 | } 182 | 183 | void ThreadMutex_set(ThreadMutexBase* o) 184 | { 185 | osMutexWait(o->mid, osWaitForever); 186 | } 187 | 188 | void ThreadMutex_release(ThreadMutexBase* o) 189 | { 190 | osMutexRelease(o->mid); 191 | } 192 | 193 | #ifdef UMM_MALLOC 194 | 195 | static ThreadMutexBase ummMutex; 196 | 197 | void umm_critical_entry(void) 198 | { 199 | osMutexWait(ummMutex.mid, osWaitForever); 200 | } 201 | 202 | void umm_critical_exit(void) 203 | { 204 | osMutexRelease(ummMutex.mid); 205 | } 206 | 207 | void umm_init(void) 208 | { 209 | ThreadMutex_constructor(&ummMutex); 210 | } 211 | 212 | #endif 213 | 214 | #endif 215 | 216 | 217 | #endif /* _SharkSsl_TargConfig_h */ 218 | -------------------------------------------------------------------------------- /inc/arch/MQX/TargConfig.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: TargConfig.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2010 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://www.realtimelogic.com 33 | * http://www.sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | #ifndef _SharkSsl_TargConfig_h 38 | #define _SharkSsl_TargConfig_h 39 | 40 | /** 41 | * baMalloc should return 32-bit aligned addresses when succesful, 42 | * (void*)0 when not succesful. 43 | * baRealloc should return 32-bit aligned addresses when succesful, 44 | * (void*)0 when not succesful or NOT available. 45 | */ 46 | 47 | #ifndef NDEBUG 48 | #define baAssert(x) ((x) ? 0 : printf("failed assertion %s %d\n", __FILE__, __LINE__)) 49 | #else 50 | #define baAssert(x) 51 | #endif 52 | 53 | #ifndef TRUE 54 | #define TRUE 1 55 | #endif 56 | 57 | #ifndef FALSE 58 | #define FALSE 0 59 | #endif 60 | 61 | 62 | /* MQX */ 63 | #include 64 | #include 65 | #include /* printf */ 66 | 67 | #define baMalloc(s) _mem_alloc_system(s) /* should return 32-bit aligned address */ 68 | #define baRealloc(m, s) (void*)0 69 | #define baFree(m) _mem_free(m) 70 | 71 | #if MQX_VERSION > 400 72 | typedef uint8_t U8; 73 | typedef int8_t S8; 74 | typedef uint16_t U16; 75 | typedef int16_t S16; 76 | typedef uint32_t U32; 77 | typedef int32_t S32; 78 | typedef uint64_t U64; 79 | typedef int64_t S64; 80 | #else 81 | typedef uint_8 U8; 82 | typedef int_8 S8; 83 | typedef uint_16 U16; 84 | typedef int_16 S16; 85 | typedef uint_32 U32; 86 | typedef int_32 S32; 87 | typedef uint_64 U64; 88 | typedef int_64 S64; 89 | #endif 90 | typedef U8 BaBool; 91 | 92 | typedef struct ThreadMutexBase 93 | { 94 | MUTEX_STRUCT mutex; 95 | } ThreadMutexBase; 96 | 97 | #define ThreadMutex_constructor(o) _mutex_init(&(o)->mutex,0) 98 | #define ThreadMutex_destructor(o) _mutex_destroy(&(o)->mutex) 99 | #define ThreadMutex_set(o) _mutex_lock(&(o)->mutex) 100 | #define ThreadMutex_release(o) _mutex_unlock(&(o)->mutex) 101 | 102 | extern 103 | #ifdef __cplusplus 104 | "C" 105 | #endif 106 | U32 baGetUnixTime(void); 107 | 108 | #ifdef _SHARKSSL_C_ 109 | U32 baGetUnixTime(void) 110 | { 111 | TIME_STRUCT t; 112 | _time_get(&t); 113 | return t.SECONDS; 114 | } 115 | #endif /* _SHARKSSL_C_ */ 116 | 117 | #endif /* _SharkSsl_TargConfig_h */ 118 | -------------------------------------------------------------------------------- /inc/arch/Posix/TargConfig.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: TargConfig.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2010 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://www.realtimelogic.com 33 | * http://www.sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | #ifndef _SharkSsl_TargConfig_h 38 | #define _SharkSsl_TargConfig_h 39 | 40 | 41 | #if !defined(B_LITTLE_ENDIAN) && !defined(B_BIG_ENDIAN) 42 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 43 | #define B_LITTLE_ENDIAN 44 | #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 45 | #define B_BIG_ENDIAN 46 | #endif 47 | #endif 48 | 49 | 50 | /** 51 | * baMalloc should return 32-bit aligned addresses when succesful, 52 | * (void*)0 when not succesful. 53 | * baRealloc should return 32-bit aligned addresses when succesful, 54 | * (void*)0 when not succesful or NOT available. 55 | */ 56 | 57 | #ifndef NDEBUG 58 | #include 59 | #define baAssert(x) assert(x) 60 | #else 61 | #define baAssert(x) 62 | #endif 63 | 64 | #ifndef TRUE 65 | #define TRUE 1 66 | #endif 67 | 68 | #ifndef FALSE 69 | #define FALSE 0 70 | #endif 71 | 72 | 73 | /* Linux/Posix */ 74 | #include /* malloc/realloc/free */ 75 | #include 76 | 77 | #define baMalloc(s) malloc(s) /* should return 32-bit aligned address */ 78 | #define baRealloc(m, s) realloc(m, s) /* as above */ 79 | #define baFree(m) free(m) 80 | 81 | #ifndef INTEGRAL_TYPES 82 | #define INTEGRAL_TYPES 83 | #if (__STDC_VERSION__ >= 199901L) || defined( __GNUC__) 84 | #include 85 | typedef uint8_t U8; 86 | typedef int8_t S8; 87 | typedef uint16_t U16; 88 | typedef int16_t S16; 89 | typedef uint32_t U32; 90 | typedef int32_t S32; 91 | typedef uint64_t U64; 92 | typedef int64_t S64; 93 | #else 94 | typedef unsigned char U8; 95 | typedef signed char S8; 96 | typedef unsigned short U16; 97 | typedef signed short S16; 98 | typedef unsigned int U32; 99 | typedef signed int S32; 100 | typedef unsigned long long U64; 101 | typedef signed long long S64; 102 | #endif 103 | #endif 104 | typedef U8 BaBool; 105 | 106 | 107 | #include 108 | #define baGetUnixTime() ((U32)time(0)) 109 | 110 | #include 111 | typedef struct ThreadMutexBase 112 | { 113 | pthread_mutex_t mutex; 114 | } ThreadMutexBase; 115 | 116 | #define ThreadMutex_destructor(o) pthread_mutex_destroy(&(o)->mutex) 117 | #define ThreadMutex_set(o) pthread_mutex_lock(&(o)->mutex) 118 | #define ThreadMutex_release(o) pthread_mutex_unlock(&(o)->mutex) 119 | #define ThreadMutex_constructor(o) pthread_mutex_init(&(o)->mutex,0) 120 | 121 | 122 | 123 | /* The following is not required by SharkSSL, but is used by some of the examples */ 124 | 125 | #ifndef TRUE 126 | #define TRUE 1 127 | #endif 128 | 129 | #ifndef FALSE 130 | #define FALSE 0 131 | #endif 132 | 133 | #endif /* _SharkSsl_TargConfig_h */ 134 | -------------------------------------------------------------------------------- /inc/arch/ThreadX/TargConfig.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: TargConfig.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2010 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://www.realtimelogic.com 33 | * http://www.sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | #ifndef _SharkSsl_TargConfig_h 38 | #define _SharkSsl_TargConfig_h 39 | 40 | /** 41 | * baMalloc should return 32-bit aligned addresses when succesful, 42 | * (void*)0 when not succesful. 43 | * baRealloc should return 32-bit aligned addresses when succesful, 44 | * (void*)0 when not succesful or NOT available. 45 | */ 46 | 47 | #ifndef NDEBUG 48 | #define baAssert(x) ((x) ? 0 : sharkAssert(__FILE__, __LINE__)) 49 | #else 50 | #define baAssert(x) 51 | #endif 52 | 53 | /* ThreadX */ 54 | #include 55 | 56 | #define baMalloc(size) sharkSslTxByteAlloc((U32)size) /* should return 32-bit aligned address */ 57 | #define baRealloc(ptr, size) (void*)0; /* not implemented */ 58 | #define baFree(ptr) tx_byte_release((VOID*)ptr) 59 | 60 | typedef unsigned char U8; 61 | typedef signed char S8; 62 | typedef unsigned short U16; 63 | typedef signed short S16; 64 | typedef ULONG U32; 65 | typedef signed int S32; 66 | typedef unsigned long long U64; 67 | typedef signed long long S64; 68 | typedef U8 BaBool; 69 | 70 | 71 | typedef struct ThreadMutexBase 72 | { 73 | TX_MUTEX mutex; 74 | } ThreadMutexBase; 75 | 76 | #define ThreadMutex_constructor(o) tx_mutex_create(&(o)->mutex, "SM", TX_INHERIT) 77 | #define ThreadMutex_destructor(o) tx_mutex_delete(&(o)->mutex) 78 | #define ThreadMutex_set(o) tx_mutex_get(&(o)->mutex,TX_WAIT_FOREVER) 79 | #define ThreadMutex_release(o) tx_mutex_put(&(o)->mutex) 80 | 81 | 82 | #ifdef _SHARKSSL_C_ 83 | static U32 sharkSslUnixTime; 84 | static TX_BYTE_POOL *sharkSslBytePool; 85 | 86 | 87 | #ifndef NDEBUG 88 | void sharkAssert(char *fileName, int line) 89 | { 90 | (void)fileName; 91 | line++; /* dummy code to place a breakpoint, don't optimize out */ 92 | for(;;); 93 | } 94 | #endif 95 | 96 | 97 | static void oneSecondTimer(U32 notUsed) 98 | { 99 | (void)notUsed; 100 | sharkSslUnixTime++; 101 | } 102 | 103 | 104 | void baInitTxUnixTime(U32 time, U32 ticksPerSecond) 105 | { 106 | static TX_TIMER timer; 107 | sharkSslUnixTime = time; 108 | memset(&timer, 0, sizeof(TX_TIMER)); 109 | tx_timer_create(&timer, "S sec tick", oneSecondTimer, 0, 110 | ticksPerSecond, ticksPerSecond, 111 | TX_AUTO_ACTIVATE); 112 | } 113 | 114 | 115 | U32 baGetUnixTime(void) 116 | { 117 | return sharkSslUnixTime; 118 | } 119 | 120 | 121 | void baSetTxBytePool (TX_BYTE_POOL *pool) 122 | { 123 | sharkSslBytePool = pool; 124 | } 125 | 126 | 127 | void *sharkSslTxByteAlloc (U32 size) 128 | { 129 | void *p; 130 | if(tx_byte_allocate(sharkSslBytePool, &p, size, TX_NO_WAIT)) 131 | return 0; 132 | 133 | baAssert(0 == ((U32)p & 0x03)); 134 | return p; 135 | } 136 | 137 | #else 138 | #ifdef __cplusplus 139 | #ifndef NDEBUG 140 | extern "C" int sharkAssert(char *fileName, int line); 141 | #endif 142 | extern "C" U32 baGetUnixTime(void); 143 | extern "C" void baInitTxUnixTime(U32 time, U32 ticksPerSecond); 144 | extern "C" void baSetTxBytePool(TX_BYTE_POOL *pool); 145 | extern"C" void *sharkSslTxByteAlloc(U32 size); 146 | 147 | #else 148 | #ifndef NDEBUG 149 | extern int sharkAssert(char *fileName, int line); 150 | #endif 151 | extern U32 baGetUnixTime(void); 152 | extern void baInitTxUnixTime(U32 time, U32 ticksPerSecond); 153 | extern void baSetTxBytePool(TX_BYTE_POOL *pool); 154 | extern void *sharkSslTxByteAlloc(U32 size); 155 | 156 | #endif /* __cplusplus */ 157 | 158 | 159 | 160 | 161 | /* The following is not required by SharkSSL, but is used by some of the examples */ 162 | 163 | #ifndef TRUE 164 | #define TRUE 1 165 | #endif 166 | 167 | #ifndef FALSE 168 | #define FALSE 0 169 | #endif 170 | 171 | 172 | #endif /* _SHARKSSL_C_ */ 173 | 174 | #endif /* _SharkSsl_TargConfig_h */ 175 | -------------------------------------------------------------------------------- /inc/arch/ThreadX/readme.txt: -------------------------------------------------------------------------------- 1 | SharkSSL(TM) ThreadX port notes 2 | ------------------------------- 3 | 4 | - The sharkAssert function must be routed to a console/terminal if the 5 | code is not compiled with the macro NDEBUG. 6 | 7 | - baMalloc (allocation function) and baFree (deallocation function) 8 | are mapped to a ThreadX byte pool that must be initialized by 9 | calling baSetTxBytePool prior to using SharkSSL. 10 | 11 | - A one-second timer is implemented in the porting code and must be 12 | initialized with a call to baInitTxUnixTime, specifying current time 13 | as first parameter (Unix format) and number of system ticks per 14 | second as second parameter Users can implement baGetUnixTime() in 15 | any other convenient way provided that the function returns the 16 | 32-bit time in Unix format (necessary to comply with the SSL/TLS 17 | standards) 18 | -------------------------------------------------------------------------------- /inc/arch/Windows/TargConfig.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: TargConfig.h 5163 2022-05-21 12:08:39Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2010 - 2022 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://www.realtimelogic.com 33 | * http://www.sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | #ifndef _SharkSsl_TargConfig_h 38 | #define _SharkSsl_TargConfig_h 39 | 40 | #ifndef WIN32_LEAN_AND_MEAN 41 | #define WIN32_LEAN_AND_MEAN 1 42 | #endif 43 | 44 | /** 45 | * baMalloc should return 32-bit aligned addresses when successful, 46 | * NULL when not successful. 47 | * baRealloc should return 32-bit aligned addresses when successful, 48 | * NULL when not successful or NOT available. 49 | */ 50 | 51 | #ifndef NDEBUG 52 | #define baAssert(x) ((x) ? 0 : printf("failed assertion %s %d\n", __FILE__, __LINE__)) 53 | #else 54 | #define baAssert(x) 55 | #endif 56 | 57 | /* x86, remove if different architecture */ 58 | #ifndef B_LITTLE_ENDIAN 59 | #define B_LITTLE_ENDIAN 60 | #endif 61 | #define SHARKSSL_BIGINT_WORDSIZE 32 62 | #define SHARKSSL_UNALIGNED_ACCESS 1 63 | 64 | 65 | /* WINDOWS */ 66 | #include 67 | 68 | #if 1 69 | #include /* malloc/realloc/free */ 70 | #define baMalloc(s) malloc(s) /* should return 32-bit aligned address */ 71 | #define baRealloc(m, s) realloc(m, s) /* as above */ 72 | #define baFree(m) free(m) 73 | #else 74 | #include "../../../examples/malloc/umm_malloc.h" 75 | #define baMalloc(s) umm_malloc(s) 76 | #define baRealloc(m, s) umm_realloc(m, s) 77 | #define baFree(m) umm_free(m) 78 | #endif 79 | 80 | #if 1 /* set to 0 if your Visual Studio compiler does not support C99 */ 81 | #include 82 | typedef uint8_t U8; 83 | typedef int8_t S8; 84 | typedef uint16_t U16; 85 | typedef int16_t S16; 86 | typedef uint32_t U32; 87 | typedef int32_t S32; 88 | typedef uint64_t U64; 89 | typedef int64_t S64; 90 | #else 91 | typedef unsigned char U8; 92 | typedef signed char S8; 93 | typedef unsigned short U16; 94 | typedef signed short S16; 95 | typedef unsigned long U32; 96 | typedef signed long S32; 97 | typedef unsigned long long U64; 98 | typedef signed long long S64; 99 | #endif 100 | typedef U8 BaBool; 101 | 102 | 103 | #include 104 | #define baGetUnixTime() ((U32)time(0)) 105 | 106 | #include 107 | typedef struct ThreadMutexBase 108 | { 109 | CRITICAL_SECTION section; 110 | } ThreadMutexBase; 111 | 112 | #define ThreadMutex_constructor(o) InitializeCriticalSection(&(o)->section) 113 | #define ThreadMutex_destructor(o) DeleteCriticalSection(&(o)->section) 114 | #define ThreadMutex_set(o) EnterCriticalSection(&(o)->section) 115 | #define ThreadMutex_release(o) LeaveCriticalSection(&(o)->section) 116 | 117 | 118 | 119 | /* The following is not required by SharkSSL, but is used by some of the examples */ 120 | 121 | #ifndef TRUE 122 | #define TRUE 1 123 | #endif 124 | 125 | #ifndef FALSE 126 | #define FALSE 0 127 | #endif 128 | 129 | 130 | #endif /* _SharkSsl_TargConfig_h */ 131 | -------------------------------------------------------------------------------- /inc/arch/_template/TargConfig.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: TargConfig.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2010 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://www.realtimelogic.com 33 | * http://www.sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | #ifndef _SharkSsl_TargConfig_h 38 | #define _SharkSsl_TargConfig_h 39 | 40 | /** 41 | * baMalloc should return 32-bit aligned addresses when succesful, 42 | * (void*)0 when not succesful. 43 | * baRealloc should return 32-bit aligned addresses when succesful, 44 | * (void*)0 when not succesful or NOT available. 45 | */ 46 | 47 | #ifndef NDEBUG 48 | #include /* printf */ 49 | #define baAssert(x) ((x) ? 0 : printf("failed assertion %s %d\n", __FILE__, __LINE__)) 50 | #else 51 | #define baAssert(x) 52 | #endif 53 | 54 | #ifndef TRUE 55 | #define TRUE 1 56 | #endif 57 | 58 | #ifndef FALSE 59 | #define FALSE 0 60 | #endif 61 | 62 | 63 | /* MUST BE ADAPTED TO THE ARCHITECTURE */ 64 | #include /* malloc/realloc/free */ 65 | 66 | #define baMalloc(s) malloc(s) /* should return 32-bit aligned address */ 67 | #define baRealloc(m, s) realloc(m, s) /* as above - see also #define below */ 68 | #define baFree(m) free(m) 69 | 70 | /** 71 | * set SHARKSSL_UNALIGNED_MALLOC to 1 if either malloc 72 | * or realloc don't return a 32-bit aligned address 73 | */ 74 | #define SHARKSSL_UNALIGNED_MALLOC 0 75 | 76 | 77 | #if (__STDC_VERSION__ >= 199901L) /* C99: '-std=c99' in GCC */ 78 | #include 79 | typedef uint8_t U8; 80 | typedef int8_t S8; 81 | typedef uint16_t U16; 82 | typedef int16_t S16; 83 | typedef uint32_t U32; 84 | typedef int32_t S32; 85 | typedef uint64_t U64; 86 | typedef int64_t S64; 87 | #else 88 | typedef unsigned char U8; 89 | typedef signed char S8; 90 | typedef unsigned short U16; 91 | typedef signed short S16; 92 | typedef unsigned long U32; 93 | typedef signed long S32; 94 | typedef unsigned long long U64; 95 | typedef signed long long S64; 96 | #endif 97 | 98 | typedef U8 BaBool; 99 | 100 | 101 | /** 102 | * baGetUnixTime demo implementation 103 | */ 104 | #ifdef _SHARKSSL_C_ 105 | static U32 sharkSslDemoTime = 0; 106 | 107 | U32 baGetUnixTime(void) 108 | { 109 | return sharkSslDemoTime++; 110 | } 111 | 112 | #else 113 | extern 114 | #ifdef __cplusplus 115 | "C" 116 | #endif 117 | U32 baGetUnixTime(void); 118 | 119 | #endif /* _SHARKSSL_C_ */ 120 | 121 | /** 122 | * possible baGetUnixTime alternate implementation 123 | * #define baGetUnixTime() 0 -- TO BE IMPLEMENTED 124 | */ 125 | 126 | 127 | typedef struct ThreadMutexBase 128 | { 129 | U32 mutex; /* TO BE IMPLEMENTED */ 130 | } ThreadMutexBase; 131 | 132 | #define ThreadMutex_destructor(o) /* TO BE IMPLEMENTED */ 133 | #define ThreadMutex_set(o) /* TO BE IMPLEMENTED */ 134 | #define ThreadMutex_release(o) /* TO BE IMPLEMENTED */ 135 | #define ThreadMutex_constructor(o) /* TO BE IMPLEMENTED */ 136 | 137 | #endif /* _SharkSsl_TargConfig_h */ 138 | -------------------------------------------------------------------------------- /inc/arch/eCOG1X/TargConfig.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: TargConfig.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2010 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://www.realtimelogic.com 33 | * http://www.sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | #ifndef _SharkSsl_TargConfig_h 38 | #define _SharkSsl_TargConfig_h 39 | 40 | /** 41 | * baMalloc should return aligned addresses when succesful, 42 | * (void*)0 when not succesful. 43 | * baRealloc should return aligned addresses when succesful, 44 | * (void*)0 when not succesful or NOT available. 45 | */ 46 | 47 | #ifndef NDEBUG 48 | #include /* printf */ 49 | #define baAssert(x) ((x) ? (void)0 : printf("failed assertion %s %d\n", __FILE__, __LINE__)) 50 | #else 51 | #define baAssert(x) 52 | #endif 53 | 54 | #ifndef TRUE 55 | #define TRUE 1 56 | #endif 57 | 58 | #ifndef FALSE 59 | #define FALSE 0 60 | #endif 61 | 62 | 63 | /* MUST BE ADAPTED TO THE ARCHITECTURE */ 64 | #include /* malloc/realloc/free */ 65 | 66 | #define baMalloc(s) malloc(s) /* should return 32-bit aligned address */ 67 | #define baRealloc(m, s) 0 68 | #define baFree(m) free(m) 69 | 70 | /** 71 | * set SHARKSSL_UNALIGNED_MALLOC to 1 if malloc 72 | * doesn't return a 32-bit aligned address 73 | * { in such case: #define baRealloc(m,s) 0 } 74 | */ 75 | #define SHARKSSL_UNALIGNED_MALLOC 0 76 | 77 | /** 78 | * machine-dependent settings 79 | */ 80 | #define UPTR U16 /* 16-bit pointers */ 81 | #define SHARKSSL_ALIGNMENT 2 /* 16-bit alignment */ 82 | #define SHARKSSL_BIGINT_WORDSIZE 16 /* 16x16 multiplications */ 83 | #define SHARKSSL_UNALIGNED_ACCESS 1 /* support for unaligned accesses */ 84 | 85 | 86 | typedef unsigned char U8; 87 | typedef signed char S8; 88 | typedef unsigned short U16; 89 | typedef signed short S16; 90 | typedef unsigned long U32; 91 | typedef signed long S32; 92 | typedef unsigned long long U64; 93 | typedef signed long long S64; 94 | typedef U8 BaBool; 95 | 96 | /** 97 | * baGetUnixTime demo implementation 98 | */ 99 | #ifdef _SHARKSSL_C_ 100 | static U32 sharkSslDemoTime = 0; 101 | 102 | U32 baGetUnixTime(void) 103 | { 104 | return sharkSslDemoTime++; 105 | } 106 | 107 | #else 108 | extern 109 | #ifdef __cplusplus 110 | "C" 111 | #endif 112 | U32 baGetUnixTime(void); 113 | 114 | #endif /* _SHARKSSL_C_ */ 115 | 116 | /** 117 | * possible baGetUnixTime alternate implementation 118 | * #define baGetUnixTime() 0 -- TO BE IMPLEMENTED 119 | */ 120 | 121 | 122 | typedef struct ThreadMutexBase 123 | { 124 | U32 mutex; /* TO BE IMPLEMENTED */ 125 | } ThreadMutexBase; 126 | 127 | #define ThreadMutex_destructor(o) /* TO BE IMPLEMENTED */ 128 | #define ThreadMutex_set(o) /* TO BE IMPLEMENTED */ 129 | #define ThreadMutex_release(o) /* TO BE IMPLEMENTED */ 130 | #define ThreadMutex_constructor(o) /* TO BE IMPLEMENTED */ 131 | 132 | #endif /* _SharkSsl_TargConfig_h */ 133 | -------------------------------------------------------------------------------- /inc/arch/embOS/TargConfig.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: TargConfig.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2010 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://www.realtimelogic.com 33 | * http://www.sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | #ifndef _SharkSsl_TargConfig_h 38 | #define _SharkSsl_TargConfig_h 39 | 40 | /** 41 | * baMalloc should return 32-bit aligned addresses when succesful, 42 | * (void*)0 when not succesful. 43 | * baRealloc should return 32-bit aligned addresses when succesful, 44 | * (void*)0 when not succesful or NOT available. 45 | */ 46 | 47 | #ifndef NDEBUG 48 | #include 49 | #define baAssert(x) ((x) ? 0 : printf("failed assertion %s %d\n", __FILE__, __LINE__)) 50 | #else 51 | #define baAssert(x) 52 | #endif 53 | 54 | 55 | /* embOS */ 56 | #include 57 | 58 | #ifndef TRUE 59 | #define TRUE 1 60 | #endif 61 | #ifndef FALSE 62 | #define FALSE 0 63 | #endif 64 | 65 | 66 | #if OS_SUPPORT_OS_ALLOC 67 | #define baMalloc(s) OS_malloc(s) /* should return 32-bit aligned address */ 68 | #define baRealloc(m, s) OS_realloc(m, s) /* as above - see also #define below */ 69 | #define baFree(m) OS_free(m) 70 | 71 | #else 72 | #include /* standard malloc/realloc/free */ 73 | #define baMalloc(s) malloc(s) /* should return 32-bit aligned address */ 74 | #define baRealloc(m, s) realloc(m, s) /* as above - see also #define below */ 75 | #define baFree(m) free(m) 76 | 77 | #endif 78 | 79 | 80 | typedef OS_U8 U8; 81 | typedef OS_I8 S8; 82 | typedef OS_U16 U16; 83 | typedef OS_I16 S16; 84 | typedef OS_U32 U32; 85 | typedef OS_I32 S32; 86 | typedef unsigned long long U64; 87 | typedef signed long long S64; 88 | typedef U8 BaBool; 89 | 90 | 91 | typedef struct ThreadMutexBase 92 | { 93 | OS_RSEMA mutex; 94 | } ThreadMutexBase; 95 | 96 | #define ThreadMutex_constructor(o) OS_CREATERSEMA(&(o)->mutex) 97 | #define ThreadMutex_destructor(o) OS_DeleteRSema(&(o)->mutex) 98 | #define ThreadMutex_set(o) OS_Use(&(o)->mutex) 99 | #define ThreadMutex_release(o) OS_Unuse(&(o)->mutex) 100 | 101 | extern 102 | #ifdef __cplusplus 103 | "C" 104 | #endif 105 | U32 baGetUnixTime(void); 106 | 107 | #ifdef _SHARKSSL_C_ 108 | U32 baGetUnixTime(void) 109 | { 110 | return (U32)OS_GetTime32() / 1000; /* one tick each ms */ 111 | } 112 | #endif /* _SHARKSSL_C_ */ 113 | 114 | #endif /* _SharkSsl_TargConfig_h */ 115 | -------------------------------------------------------------------------------- /inc/arch/mbed/TargConfig.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: TargConfig.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2016 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://www.realtimelogic.com 33 | * http://www.sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | #ifndef _SharkSsl_TargConfig_h 38 | #define _SharkSsl_TargConfig_h 39 | 40 | #include 41 | #include 42 | 43 | 44 | #ifndef NDEBUG 45 | #define baAssert(x) ((x) ? 0 : sharkAssert(__FILE__, __LINE__)) 46 | #else 47 | #define baAssert(x) 48 | #endif 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | void sharkAssert(const char* file, int line); 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #ifdef _SHARKSSL_C_ 59 | const char* assert_file; 60 | int assert_line; 61 | void sharkAssert(const char* file, int line) 62 | { 63 | assert_file = file; 64 | assert_line = line; 65 | for(;;); 66 | } 67 | #endif 68 | 69 | 70 | 71 | /* The following is not required by SharkSSL, but is used by some of 72 | the examples. 73 | */ 74 | 75 | #ifndef TRUE 76 | #define TRUE 1 77 | #endif 78 | 79 | #ifndef FALSE 80 | #define FALSE 0 81 | #endif 82 | 83 | /** 84 | * baMalloc should return 32-bit aligned addresses when succesful, 85 | * (void*)0 when not succesful. 86 | * baRealloc should return 32-bit aligned addresses when succesful, 87 | * (void*)0 when not succesful or NOT available. 88 | */ 89 | 90 | #ifdef UMM_MALLOC 91 | #include "../../../examples/malloc/umm_malloc.h" 92 | #define baMalloc(s) umm_malloc(s) 93 | #define baRealloc(m, s) umm_realloc(m, s) 94 | #define baFree(m) umm_free(m) 95 | #else 96 | #include 97 | #define baMalloc(s) malloc(s) /* should return 32-bit aligned address */ 98 | #define baRealloc(m, s) realloc(m, s) /* as above */ 99 | #define baFree(m) free(m) 100 | #endif 101 | 102 | /* Some mbed releases use conflicting types. Undo the two macro 103 | definitions commented out below if you get 'type conflict' compile 104 | errors. 105 | */ 106 | /* #ifndef __MBED__ */ 107 | 108 | #ifndef INTEGRAL_TYPES 109 | #define INTEGRAL_TYPES 110 | #if (__STDC_VERSION__ >= 199901L) || defined( __GNUC__) 111 | #include 112 | typedef uint8_t U8; 113 | typedef int8_t S8; 114 | typedef uint16_t U16; 115 | typedef int16_t S16; 116 | typedef uint32_t U32; 117 | typedef int32_t S32; 118 | typedef uint64_t U64; 119 | typedef int64_t S64; 120 | #else 121 | typedef unsigned char U8; 122 | typedef signed char S8; 123 | typedef unsigned short U16; 124 | typedef signed short S16; 125 | typedef unsigned int U32; 126 | typedef signed int S32; 127 | typedef unsigned long long U64; 128 | typedef signed long long S64; 129 | #endif 130 | #endif 131 | 132 | /* #endif */ /* __MBED__ */ 133 | 134 | typedef U8 BaBool; 135 | 136 | #ifdef EXT_SHARK_LIB 137 | U32 baGetUnixTime(void); 138 | char *sharkStrchr(const char *s, int c); 139 | char *sharkStrstr(const char *haystack, const char *needle); 140 | #else 141 | #define baGetUnixTime() time(0) 142 | #endif 143 | 144 | typedef struct ThreadMutexBase 145 | { 146 | osMutexId mid; 147 | osMutexDef_t mdef; 148 | #ifdef __MBED_CMSIS_RTOS_CA9 149 | int32_t mdata[4]; 150 | #else 151 | int32_t mdata[3]; 152 | #endif 153 | } ThreadMutexBase; 154 | 155 | void ThreadMutex_destructor(ThreadMutexBase* o); 156 | void ThreadMutex_set(ThreadMutexBase* o); 157 | void ThreadMutex_release(ThreadMutexBase* o); 158 | void ThreadMutex_constructor(ThreadMutexBase* o); 159 | 160 | #ifdef _SHARKSSL_C_ 161 | #include 162 | void ThreadMutex_constructor(ThreadMutexBase* o) 163 | { 164 | memset(o->mdata, 0, sizeof(o->mdata)); 165 | o->mdef.mutex = o->mdata; 166 | o->mid = osMutexCreate(&o->mdef); 167 | baAssert(o->mid); 168 | } 169 | 170 | void ThreadMutex_destructor(ThreadMutexBase* o) 171 | { 172 | osMutexDelete(o->mid); 173 | } 174 | 175 | void ThreadMutex_set(ThreadMutexBase* o) 176 | { 177 | osMutexWait(o->mid, osWaitForever); 178 | } 179 | 180 | void ThreadMutex_release(ThreadMutexBase* o) 181 | { 182 | osMutexRelease(o->mid); 183 | } 184 | #endif 185 | 186 | 187 | #endif /* _SharkSsl_TargConfig_h */ 188 | -------------------------------------------------------------------------------- /src/MinnowServer/ZipFileSystem.c: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: ZipFileSystem.c 4125 2017-12-15 17:59:48Z wini $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2013 - 2018 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://sharkssl.com 33 | **************************************************************************** 34 | */ 35 | 36 | #include "ZipFileSystem.h" 37 | 38 | 39 | static int 40 | sendPage(ZipFileSystem* zfs, ZipFileHeader* zfh, MST* mst, int comp) 41 | { 42 | static const U8 egz[] = {"\r\nContent-Encoding: gzip"}; 43 | GzipTrailer* gt; 44 | U8* sptr; 45 | U32 fsize = comp ? ZipFileHeader_getCompressedSize(zfh) : 46 | ZipFileHeader_getUncompressedSize(zfh); 47 | int sblen=MST_getSendBufSize(mst); 48 | sptr = msRespCT( 49 | MST_getSendBufPtr(mst), &sblen, comp ? fsize+18 : fsize, egz); 50 | if(sptr && sblen > 10) 51 | { 52 | ZipFileInfo zfi; 53 | int x; 54 | ZipFileInfo_constructor(&zfi, zfh, (U8*)0); 55 | if(comp) 56 | { 57 | if(initGZipHeader(&zfi, (GzipHeader*)sptr)) 58 | return MS_ERR_ENCRYPTED_ZIP; 59 | sptr+=10; 60 | sblen-=10; 61 | } 62 | while(fsize) 63 | { 64 | int chunkz; 65 | if(!sblen) 66 | { 67 | sblen=MST_getSendBufSize(mst); 68 | if(MST_write(mst, 0, sblen) < 0) 69 | return MS_ERR_WRITE; 70 | sptr=MST_getSendBufPtr(mst); 71 | } 72 | chunkz = (int)(fsize > (U32)sblen ? sblen : fsize); 73 | if(CspReader_read(zfs->reader, sptr, zfi.dataOffset, chunkz, FALSE)) 74 | return MS_ERR_FILE_IO; 75 | fsize -= chunkz; 76 | sblen -= chunkz; 77 | zfi.dataOffset += chunkz; 78 | sptr += chunkz; 79 | } 80 | if(comp) 81 | { 82 | if(sblen < 8) 83 | { 84 | if(MST_write(mst,0,sptr-MST_getSendBufPtr(mst)) < 0) 85 | return MS_ERR_WRITE; 86 | sptr=MST_getSendBufPtr(mst); 87 | } 88 | gt = (GzipTrailer*)sptr; 89 | x = ZipFileInfo_getCrc32LittleEndian(&zfi); 90 | memcpy(gt->crc, &x, 4); 91 | x = ZipFileInfo_getUncompressedSizeLittleEndian(&zfi); 92 | memcpy(gt->uncompressedSize, &x, 4); 93 | sptr += 8; 94 | } 95 | if(sptr-MST_getSendBufPtr(mst) > 0) 96 | { 97 | return MST_write(mst,0,sptr-MST_getSendBufPtr(mst)) < 0 ? MS_ERR_WRITE : 1; 98 | } 99 | return 1; 100 | } 101 | return MS_ERR_ALLOC; 102 | } 103 | 104 | 105 | static int 106 | fetchZipPage(void* hndl, MST* mst, U8* path) 107 | { 108 | CentralDirIterator iter; 109 | U8* ptr=0; 110 | ZipFileSystem* zfs = (ZipFileSystem*)hndl; 111 | CentralDirIterator_constructor(&iter, &zfs->zc); 112 | if(*path == '/') path++; 113 | if(!*path || ((ptr=(U8*)strrchr((char*)path, '/')) !=0 && !ptr[1])) 114 | { 115 | ptr=MST_getSendBufPtr(mst); 116 | strcpy((char*)ptr, (char*)path); 117 | strcat((char*)ptr, "index.html"); 118 | path=ptr; 119 | } 120 | do 121 | { 122 | ZipFileHeader* zfh = CentralDirIterator_getElement(&iter); 123 | if( ! zfh ) 124 | { 125 | return CentralDirIterator_getECode(&iter); 126 | } 127 | if( ! ZipFileHeader_isDirectory(zfh) ) 128 | { 129 | const char* pathName = ZipFileHeader_getFn(zfh); 130 | int fnLen = ZipFileHeader_getFnLen(zfh); 131 | if(*path == *pathName) 132 | { 133 | const U8* ptr = path+1; 134 | while(--fnLen && *++pathName == *ptr++); 135 | if( ! fnLen && !*ptr ) 136 | { 137 | switch(ZipFileHeader_getComprMethod(zfh)) 138 | { 139 | case ZipComprMethod_Stored: 140 | return sendPage(zfs,zfh,mst,FALSE); 141 | case ZipComprMethod_Deflated: 142 | return sendPage(zfs,zfh,mst,TRUE); 143 | default: 144 | return ZipErr_Compression; 145 | } 146 | } 147 | } 148 | } 149 | } while(CentralDirIterator_nextElement(&iter)); 150 | return 0; 151 | } 152 | 153 | 154 | MSFetchPage 155 | msInitZipFileSystem(ZipFileSystem* zfs, ZipReader* zr) 156 | { 157 | ZipContainer_constructor(&zfs->zc,zr,zfs->buf,sizeof(zfs->buf)); 158 | zfs->reader=zr; 159 | return fetchZipPage; 160 | } 161 | -------------------------------------------------------------------------------- /src/SeCtx.c: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: SeCtx.c 4914 2021-12-01 18:24:30Z wini $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2014 - 2017 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://realtimelogic.com 33 | **************************************************************************** 34 | 35 | 36 | 37 | 38 | SeCtx ( Socket Example Library Context Manager) for bare metal systems. 39 | 40 | Documentation: 41 | https://realtimelogic.com/ba/doc/en/C/shark/group__BareMetal.html 42 | 43 | 44 | 45 | 46 | */ 47 | 48 | #include "selib.h" 49 | 50 | 51 | #ifdef DYNAMIC_SE_CTX 52 | void 53 | SeCtx_destructor(SeCtx* o) 54 | { 55 | if(o->stackBuf) 56 | baFree(o->stackBuf); 57 | o->stackBuf=0; 58 | } 59 | #endif 60 | 61 | static void 62 | SeCtx_setStackBuf(SeCtx* o, U32 size) 63 | { 64 | #ifdef DYNAMIC_SE_CTX 65 | if(size > 40*1024) 66 | SeCtx_panic(0, size); 67 | if(o->stackBuf) 68 | baFree(o->stackBuf); 69 | o->stackBufLen = (U16)size; 70 | o->stackBuf = baMalloc(o->stackBufLen); 71 | if( ! o->stackBuf ) 72 | #endif 73 | SeCtx_panic(o, size); 74 | } 75 | 76 | static int 77 | SeCtx_saveStackOrSwitchContext(SeCtx* o, U8 switchContext) 78 | { 79 | auto U8 stackmark; 80 | U8* currentStack; 81 | stackmark = 1; /* Make sure compiler keeps this variable. */ 82 | currentStack = &stackmark; 83 | if(switchContext) /* Restore original context */ 84 | { 85 | baAssert(o->currentStack == currentStack); 86 | memcpy(currentStack, o->stackBuf, o->stackTop-currentStack); 87 | return FALSE; 88 | } 89 | else /* Save context i.e. save stack. */ 90 | { 91 | #ifndef NDEBUG 92 | o->currentStack = currentStack; 93 | #endif 94 | if((o->stackTop - currentStack) > o->stackBufLen) 95 | SeCtx_setStackBuf(o, (o->stackTop - currentStack) + 100); 96 | memcpy(o->stackBuf, currentStack, o->stackTop-currentStack); 97 | return TRUE; 98 | } 99 | } 100 | 101 | 102 | #ifdef DYNAMIC_SE_CTX 103 | void 104 | SeCtx_constructor(SeCtx* o, SeCtxTask* t) 105 | { 106 | baAssert(sizeof(int) >= sizeof(void*)); 107 | memset(o, 0, sizeof(SeCtx)); 108 | o->task=t; 109 | #ifndef NDEBUG 110 | o->magic1 = o->magic2 = 0xAFA5A5F5; 111 | #endif 112 | SeCtx_setStackBuf(o, 1000); 113 | } 114 | #else 115 | void 116 | SeCtx_constructor(SeCtx* o, SeCtxTask t, void* buf, int bufLen) 117 | { 118 | baAssert(sizeof(int) >= sizeof(void*)); 119 | memset(o, 0, sizeof(SeCtx)); 120 | #ifndef NDEBUG 121 | o->magic1 = o->magic2 = 0xAFA5A5F5; 122 | #endif 123 | o->task=t; 124 | o->stackBuf = buf; 125 | o->stackBufLen = (U16)bufLen; 126 | } 127 | #endif 128 | 129 | 130 | void 131 | SeCtx_save(SeCtx* o) 132 | { 133 | int val; 134 | baAssert( ! o->hasContext ); 135 | baAssert(o->ready == FALSE); 136 | baAssert(o->magic1 == 0xAFA5A5F5 && o->magic2== 0xAFA5A5F5); 137 | val = setjmp(o->savedContext); 138 | if(val) 139 | { 140 | o = (SeCtx*)val; 141 | SeCtx_saveStackOrSwitchContext(o, TRUE); 142 | baAssert(o->magic1 == 0xAFA5A5F5 && o->magic2== 0xAFA5A5F5); 143 | } 144 | else 145 | { 146 | if(SeCtx_saveStackOrSwitchContext(o, FALSE)) 147 | { 148 | o->hasContext = TRUE; 149 | longjmp(o->startContext, 1); 150 | } 151 | } 152 | } 153 | 154 | 155 | void 156 | SeCtx_restore(SeCtx* o) 157 | { 158 | baAssert(o->hasContext); 159 | o->hasContext = FALSE; 160 | o->ready = FALSE; 161 | longjmp(o->savedContext, (int)o); 162 | } 163 | -------------------------------------------------------------------------------- /src/arch/FreeRTOS-TCP/selibplat.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: selibplat.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2018 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://realtimelogic.com 33 | * http://sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | 38 | #include "FreeRTOS_IP.h" 39 | #include "FreeRTOS_Sockets.h" 40 | 41 | #if !defined(B_LITTLE_ENDIAN) || defined(B_BIG_ENDIAN) 42 | #if ipconfigBYTE_ORDER == pdFREERTOS_BIG_ENDIAN 43 | #define B_BIG_ENDIAN 44 | #else 45 | #define B_LITTLE_ENDIAN 46 | #endif 47 | #endif 48 | 49 | #define NO_BSD_SOCK 50 | 51 | #define SOCKET Socket_t 52 | 53 | 54 | #ifdef SELIB_C 55 | 56 | int se_sockValid(SOCKET* sock) 57 | { 58 | return *sock != FREERTOS_INVALID_SOCKET; 59 | } 60 | 61 | 62 | void se_close(SOCKET* sock) 63 | { 64 | TickType_t start_time; 65 | U8 buffer[10]; 66 | 67 | if(*sock != FREERTOS_INVALID_SOCKET) 68 | { 69 | FreeRTOS_shutdown(*sock, FREERTOS_SHUT_RDWR); 70 | start_time = xTaskGetTickCount(); 71 | 72 | do 73 | { 74 | int rc = FreeRTOS_recv(*sock, buffer, sizeof(buffer), 0); 75 | if(rc < 0 && rc != -pdFREERTOS_ERRNO_EAGAIN) 76 | { 77 | break; 78 | } 79 | } while((xTaskGetTickCount() - start_time) < pdMS_TO_TICKS(1000)); 80 | 81 | FreeRTOS_closesocket(*sock); 82 | *sock=FREERTOS_INVALID_SOCKET; 83 | } 84 | } 85 | 86 | int se_bind(SOCKET* sock, uint16_t port) 87 | { 88 | struct freertos_sockaddr addr; 89 | socklen_t addrlen=sizeof(addr); 90 | *sock = FreeRTOS_socket( 91 | FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP ); 92 | if(*sock == FREERTOS_INVALID_SOCKET) 93 | { 94 | return -1; 95 | } 96 | addr.sin_addr=INADDR_ANY; 97 | addr.sin_port = FreeRTOS_htons(port); 98 | if(FreeRTOS_bind(*sock, &addr, addrlen)) 99 | { 100 | se_close(sock); 101 | return -3; 102 | } 103 | if(FreeRTOS_listen(*sock, SOMAXCONN)) 104 | { 105 | se_close(sock); 106 | return -2; 107 | } 108 | return 0; 109 | } 110 | 111 | int se_connect(SOCKET* sock, const char* address, uint16_t port) 112 | { 113 | struct freertos_sockaddr addr; 114 | socklen_t addrlen=sizeof(addr); 115 | uint32_t ip = FreeRTOS_gethostbyname(address); 116 | if( ! ip ) 117 | { 118 | ip = FreeRTOS_inet_addr(address); 119 | if( ! ip ) 120 | { 121 | *sock = FREERTOS_INVALID_SOCKET; 122 | return -2; 123 | } 124 | } 125 | *sock = FreeRTOS_socket( 126 | FREERTOS_AF_INET,FREERTOS_SOCK_STREAM,FREERTOS_IPPROTO_TCP); 127 | if( ! *sock ) 128 | { 129 | return -1; 130 | } 131 | if(*sock == FREERTOS_INVALID_SOCKET) 132 | { 133 | return -1; 134 | } 135 | addr.sin_addr=ip; 136 | addr.sin_port = FreeRTOS_htons(port); 137 | if(FreeRTOS_connect(*sock, &addr, sizeof(addr))) 138 | { 139 | se_close(sock); 140 | return -3; 141 | } 142 | return 0; 143 | } 144 | 145 | 146 | int se_accept(SOCKET** listenSock, U32 timeout, SOCKET** outSock) 147 | { 148 | struct freertos_sockaddr addr; 149 | socklen_t addrlen=sizeof(addr); 150 | TickType_t tickTmo; 151 | tickTmo = timeout==INFINITE_TMO ? portMAX_DELAY : timeout/portTICK_PERIOD_MS; 152 | FreeRTOS_setsockopt(**listenSock,0,FREERTOS_SO_RCVTIMEO,&tickTmo,0); 153 | **outSock=FreeRTOS_accept(**listenSock,&addr,&addrlen); 154 | return **outSock == 0 ? 0 : (**outSock < 0 ? -1 : 1); 155 | } 156 | 157 | 158 | S32 se_recv(SOCKET* sock, void* buf, U32 len, U32 timeout) 159 | { 160 | TickType_t tickTmo; 161 | tickTmo = timeout==INFINITE_TMO ? portMAX_DELAY : timeout/portTICK_PERIOD_MS; 162 | FreeRTOS_setsockopt(*sock,0,FREERTOS_SO_RCVTIMEO,&tickTmo,0); 163 | return FreeRTOS_recv(*sock,buf,len,0); 164 | } 165 | 166 | S32 se_send(SOCKET* sock, const void* buf, U32 len) 167 | { 168 | return FreeRTOS_send(*sock, buf, len, 0); 169 | } 170 | 171 | #endif /* SELIB_C */ 172 | 173 | -------------------------------------------------------------------------------- /src/arch/Harmony/README.txt: -------------------------------------------------------------------------------- 1 | 2 | Porting layer for Microchip Harmony TCP/IP stack : 3 | http://ww1.microchip.com/downloads/en/DeviceDoc/MPLAB%20Harmony%20TCP-IP%20Stack%20Libraries_v110.pdf 4 | 5 | Designed specifically for event driven non RTOS (bare metal) systems. 6 | 7 | Start by reading: 8 | https://realtimelogic.com/ba/doc/en/C/shark/group__BareMetal.html 9 | 10 | Compiler include path: 11 | examples\arch\Harmony 12 | examples 13 | inc 14 | inc\arch\BareMetal 15 | 16 | Set the macro UMM_MALLOC. See inc\arch\BareMetal\TargConfig.h for details 17 | Include umm_malloc.c in your build 18 | 19 | 20 | Limitations: 21 | 22 | The porting layer is currently limited to client socket connections. 23 | 24 | The limitation mentioned in the documentation, that a socket cannot be 25 | declared on the task stack, does not apply to the Harmony porting 26 | layer. You may declare sockets on the task stack. 27 | 28 | SharkSSL requires an allocator. You can use any allocator or the 29 | included 'umm' allocator in examples/malloc/. See 30 | inc/arch/BareMetal/TargConfig.h for details. 31 | -------------------------------------------------------------------------------- /src/arch/Harmony/seHarmony.c: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: seHarmony.c 4029 2017-03-14 21:19:09Z wini $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2017 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://realtimelogic.com 33 | * http://sharkssl.com 34 | **************************************************************************** 35 | */ 36 | 37 | 38 | #include "../../selib.h" 39 | 40 | #ifndef SharkSSLHarmony 41 | #error SharkSSLHarmony not defined -> Using incorrect selibplat.h 42 | #endif 43 | 44 | 45 | U32 46 | millisec2Ticks(U32 time) 47 | { 48 | return (time * SYS_TMR_TickCounterFrequencyGet()) / 1000; 49 | } 50 | 51 | 52 | /* Returns 0 on success. 53 | Error codes returned: 54 | -1: Cannot create socket: Fatal 55 | -2: Cannot resolve 'address' 56 | -3: Cannot connect 57 | */ 58 | int 59 | se_connect(SOCKET* sock, const char* name, U16 port) 60 | { 61 | 62 | IP_MULTI_ADDRESS addr; 63 | TCPIP_DNS_RESULT result = TCPIP_DNS_Resolve(name, TCPIP_DNS_TYPE_A); 64 | if(TCPIP_DNS_RES_PENDING == result) 65 | { 66 | sock->ctx->state = SELIB_DNS_PENDING; 67 | for(;;) 68 | { 69 | sock->ctx->htcp = sock->htcp; 70 | SeCtx_save(sock->ctx); 71 | L_fetchIp: 72 | result = TCPIP_DNS_IsNameResolved(name, &addr.v4Add, 0); 73 | if(TCPIP_DNS_RES_OK == result) 74 | break; 75 | if(TCPIP_DNS_RES_PENDING != result) 76 | return -2; 77 | } 78 | } 79 | else if(TCPIP_DNS_RES_NAME_IS_IPADDRESS == result) 80 | { 81 | if( ! TCPIP_Helper_StringToIPAddress(name, &addr.v4Add) ) 82 | return -2; 83 | } 84 | else if(TCPIP_DNS_RES_OK == result) 85 | goto L_fetchIp; 86 | else 87 | return -2; 88 | sock->htcp = TCPIP_TCP_ClientOpen(IP_ADDRESS_TYPE_IPV4, port, &addr); 89 | if(INVALID_SOCKET == sock->htcp) 90 | return -1; 91 | sock->ctx->state = SELIB_CONNECT_PENDING; 92 | sock->ctx->timeout = millisec2Ticks(5000); /* hardcoded 5 secs */ 93 | sock->ctx->htcp = sock->htcp; 94 | SeCtx_save(sock->ctx); 95 | if(TCPIP_TCP_IsConnected(sock->htcp)) 96 | return 0; 97 | TCPIP_TCP_Abort(sock->htcp, TRUE); 98 | sock->htcp = INVALID_SOCKET; 99 | return -3; 100 | } 101 | 102 | 103 | 104 | void 105 | se_close(SOCKET* sock) 106 | { 107 | if(INVALID_SOCKET != sock->htcp) 108 | { 109 | TCPIP_TCP_Close(sock->htcp); 110 | sock->htcp = INVALID_SOCKET; 111 | } 112 | } 113 | 114 | 115 | S32 116 | se_send(SOCKET* sock, const void* buf, U32 len) 117 | { 118 | U32 ix = len; 119 | uint8_t* ptr = (uint8_t*)buf; 120 | sock->ctx->state = SELIB_SEND_PENDING; 121 | for(;;) 122 | { 123 | U32 max = (U32)TCPIP_TCP_PutIsReady(sock->htcp); 124 | if(max > 0) 125 | { 126 | if(max > ix) 127 | max = ix; 128 | if(max!=(U32)TCPIP_TCP_ArrayPut(sock->htcp,ptr,(uint16_t)max)) 129 | return -1; 130 | ix = ix - max; 131 | if(ix == 0) 132 | return (S32)len; 133 | ptr+=max; 134 | } 135 | sock->ctx->htcp = sock->htcp; 136 | sock->ctx->timeout = millisec2Ticks(30000); /* hardcoded 30 secs */ 137 | SeCtx_save(sock->ctx); 138 | if(! TCPIP_TCP_IsConnected(sock->htcp) ) 139 | return -1; 140 | if( ! TCPIP_TCP_PutIsReady(sock->ctx->htcp) ) 141 | return -2; 142 | } 143 | } 144 | 145 | 146 | S32 147 | se_recv(SOCKET* sock, void* buf, U32 len, U32 timeout) 148 | { 149 | uint16_t rlen; 150 | int i; 151 | sock->ctx->state = SELIB_RECV; 152 | if(timeout != INFINITE_TMO) 153 | sock->ctx->timeout = millisec2Ticks(timeout); 154 | for(i = 0 ; 0 == (rlen = TCPIP_TCP_GetIsReady(sock->htcp)) ; i++) 155 | { 156 | if( ! TCPIP_TCP_IsConnected(sock->htcp) ) 157 | return -1; 158 | if(i > 0) /* timeout */ 159 | { 160 | baAssert(timeout != INFINITE_TMO); 161 | return 0; 162 | } 163 | sock->ctx->htcp = sock->htcp; 164 | SeCtx_save(sock->ctx); 165 | } 166 | if((U32)rlen > len) 167 | rlen = (uint16_t)len; 168 | return (S32)TCPIP_TCP_ArrayGet(sock->htcp, (uint8_t*)buf, rlen); 169 | } 170 | 171 | 172 | int 173 | se_accept(SOCKET** listenSock, U32 timeout, SOCKET** outSock) 174 | { 175 | (void)listenSock; 176 | (void)timeout; 177 | (void)outSock; 178 | baAssert(0); /* not implemented */ 179 | return -1; 180 | } 181 | 182 | 183 | int 184 | se_bind(SOCKET* sock, U16 port) 185 | { 186 | (void)sock; 187 | (void)port; 188 | baAssert(0); /* not implemented */ 189 | return -1; 190 | } 191 | 192 | 193 | int 194 | se_sockValid(SOCKET* sock) 195 | { 196 | return TCPIP_TCP_IsConnected(sock->htcp); 197 | } 198 | 199 | 200 | int 201 | SeCtx_run(SeCtx* ctx) 202 | { 203 | auto U8 stackMark; 204 | if(ctx->hasContext) /* If function mainTask is running */ 205 | { 206 | switch(ctx->state) 207 | { 208 | case SELIB_DNS_PENDING: 209 | SeCtx_restore(ctx); 210 | break; 211 | case SELIB_CONNECT_PENDING: 212 | if(TCPIP_TCP_IsConnected(ctx->htcp)) 213 | { 214 | ctx->startTime = ctx->timeout = 0; 215 | SeCtx_restore(ctx); 216 | } 217 | break; 218 | 219 | case SELIB_SEND_PENDING: 220 | if(TCPIP_TCP_PutIsReady(ctx->htcp) > 0 || 221 | ! TCPIP_TCP_IsConnected(ctx->htcp)) 222 | { 223 | ctx->startTime = ctx->timeout = 0; 224 | SeCtx_restore(ctx); 225 | } 226 | break; 227 | 228 | case SELIB_RECV: 229 | if(TCPIP_TCP_GetIsReady(ctx->htcp) > 0 || 230 | ! TCPIP_TCP_IsConnected(ctx->htcp)) 231 | { 232 | ctx->startTime = ctx->timeout = 0; 233 | SeCtx_restore(ctx); 234 | } 235 | break; 236 | 237 | default: 238 | baAssert(0); 239 | } 240 | if(ctx->timeout) /* Timeout on se_connect or se_recv */ 241 | { 242 | if( ! ctx->startTime ) 243 | { 244 | ctx->startTime = SYS_TMR_TickCountGet(); /* Start timer */ 245 | } 246 | else if( (S32)(SYS_TMR_TickCountGet() - ctx->startTime) >= 247 | (S32)ctx->timeout ) 248 | { /* timeout */ 249 | ctx->startTime = ctx->timeout = 0; 250 | SeCtx_restore(ctx); 251 | } 252 | } 253 | } 254 | else if( ! SeCtx_setStackTop(ctx, &stackMark) ) 255 | { 256 | ctx->state = SELIB_INVALID; 257 | ctx->task(ctx); 258 | baAssert( ! ctx->hasContext ); 259 | return -1; 260 | } 261 | return 0; 262 | } 263 | -------------------------------------------------------------------------------- /src/arch/Harmony/selibplat.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: selibplat.h 4019 2017-03-03 20:24:42Z wini $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2017 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://realtimelogic.com 33 | **************************************************************************** 34 | * 35 | */ 36 | 37 | #define SharkSSLHarmony 38 | #define NO_BSD_SOCK 39 | #define SECTX_EX TCP_SOCKET htcp;int state 40 | 41 | #define SOCKET MCSOCKET 42 | #include 43 | #include 44 | #undef SOCKET 45 | #include "../../SeCtx.h" 46 | 47 | 48 | typedef struct SOCKET 49 | { 50 | SeCtx* ctx; 51 | TCP_SOCKET htcp; 52 | int state; 53 | } SOCKET; 54 | 55 | #define SELIB_INVALID 0 56 | #define SELIB_DNS_PENDING 1 57 | #define SELIB_CONNECT_PENDING 2 58 | #define SELIB_SEND_PENDING 3 59 | #define SELIB_RECV 4 60 | 61 | #define SOCKET_constructor(o, ctxMA) \ 62 | memset(o,0,sizeof(SOCKET)),(o)->htcp=INVALID_SOCKET,(o)->ctx=ctxMA 63 | 64 | int SeCtx_run(SeCtx* ctx); 65 | -------------------------------------------------------------------------------- /src/arch/INTEGRITY/selibplat.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: selibplat.h 4366 2019-03-22 00:32:43Z wini $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2014 - 2019 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://realtimelogic.com 33 | * http://sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | 38 | #define SharkSSLPosix 39 | #define HOST_PLATFORM 1 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | 53 | #ifdef __cplusplus 54 | extern "C" { 55 | #endif 56 | 57 | #ifdef SELIB_C 58 | #define X_se_connect 59 | int se_connect(int* sock, const char* address, U16 port) 60 | { 61 | int retVal=-3; 62 | struct addrinfo* ptr; 63 | struct addrinfo* result = 0; 64 | if(getaddrinfo(address, 0, 0, &result)) 65 | return -2; 66 | for(ptr=result ; ptr ; ptr=ptr->ai_next) 67 | { 68 | int sockfd; 69 | sockfd=socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol); 70 | if(sockfd < 0) 71 | { 72 | retVal=-1; 73 | } 74 | else 75 | { 76 | int nonBlock=1; 77 | if(ptr->ai_family == AF_INET) 78 | ((struct sockaddr_in*)ptr->ai_addr)->sin_port = htons(port); 79 | else if(ptr->ai_family == AF_INET6) 80 | ((struct sockaddr_in6*)ptr->ai_addr)->sin6_port = htons(port); 81 | else 82 | goto L_close; 83 | ioctl(sockfd, FIONBIO, &nonBlock); 84 | if(connect(sockfd, ptr->ai_addr, ptr->ai_addrlen) < 0) 85 | { 86 | if(errno == EINPROGRESS) 87 | { 88 | struct timeval tv; 89 | fd_set fds; 90 | FD_ZERO(&fds); 91 | FD_SET(sockfd, &fds); 92 | tv.tv_sec = 4; 93 | tv.tv_usec = 0; 94 | if(select(sockfd + 1, 0, &fds, 0, &tv)==1) 95 | { 96 | struct sockaddr_in6 in6; 97 | socklen_t size=sizeof(struct sockaddr_in6); 98 | if(!getpeername(sockfd, (struct sockaddr*)&in6, &size)) 99 | goto L_ok; 100 | } 101 | } 102 | L_close: 103 | retVal=-3; 104 | close(sockfd); 105 | } 106 | else 107 | { 108 | L_ok: 109 | nonBlock=0; 110 | ioctl(sockfd, FIONBIO, &nonBlock); 111 | *sock=sockfd; 112 | retVal=0; 113 | break; 114 | } 115 | } 116 | } 117 | freeaddrinfo(result); 118 | return retVal; 119 | } 120 | #endif 121 | 122 | #ifdef __cplusplus 123 | } 124 | #endif 125 | -------------------------------------------------------------------------------- /src/arch/MDK/selibplat.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: selibplat.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2016 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://realtimelogic.com 33 | * http://sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | 38 | 39 | #define SharkSSLMDK 40 | #include "rl_net.h" 41 | 42 | #if !defined(B_BIG_ENDIAN) && !defined(B_LITTLE_ENDIAN) 43 | #ifdef __ARM_BIG_ENDIAN 44 | #define B_BIG_ENDIAN 45 | #else 46 | #define B_LITTLE_ENDIAN 47 | #endif 48 | #endif 49 | 50 | #ifndef baAssert 51 | #ifndef NDEBUG 52 | #define baAssert_func 53 | #define baAssert(x) ((x) ? 0 : sharkAssert(__FILE__, __LINE__)) 54 | #ifdef __cplusplus 55 | extern "C" { 56 | #endif 57 | int sharkAssert(const char* file, int line); 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | #else 62 | #define baAssert(x) 63 | #endif 64 | #endif 65 | 66 | #ifdef SELIB_C 67 | 68 | #ifdef baAssert_func 69 | const char* assert_file; 70 | int assert_line; 71 | int sharkAssert(const char* file, int line) 72 | { 73 | assert_file = file; 74 | assert_line = line; 75 | for(;;); 76 | } 77 | #endif 78 | 79 | #define X_readtmo 80 | #define X_se_connect 81 | #define X_se_recv 82 | #define SOMAXCONN 3 83 | #define closesocket closesocket 84 | 85 | /* Not implemented for accept */ 86 | static int readtmo(int sock, U32 tmo) 87 | { 88 | return 0; 89 | } 90 | 91 | 92 | int se_connect(int* sock, const char* address, U16 port) 93 | { 94 | int err; 95 | HOSTENT* host = gethostbyname (address, &err); 96 | if(host && host->h_addrtype == AF_INET) /* only IPv4 for now */ 97 | { 98 | int i; 99 | *sock = socket (AF_INET, SOCK_STREAM, 0); 100 | if(*sock) 101 | { 102 | for (i = 0; host->h_addr_list[i]; i++) 103 | { 104 | SOCKADDR_IN addr; 105 | IN_ADDR* ia = (IN_ADDR *)host->h_addr_list[i]; 106 | addr.sin_port = htons(port); 107 | addr.sin_family = PF_INET; 108 | addr.sin_addr.s_b1 = ia->s_b1; 109 | addr.sin_addr.s_b2 = ia->s_b2; 110 | addr.sin_addr.s_b3 = ia->s_b3; 111 | addr.sin_addr.s_b4 = ia->s_b4; 112 | if(BSD_SUCCESS == connect(*sock, (SOCKADDR *)&addr, sizeof (addr))) 113 | { 114 | /* Required for each persistent connection in this TCP/IP stack. 115 | The connection goes down after 120 seconds otherwise. 116 | */ 117 | char optval = 1; 118 | setsockopt(*sock,SOL_SOCKET,SO_KEEPALIVE,&optval,sizeof(optval)); 119 | return 0; 120 | } 121 | } 122 | closesocket(*sock); 123 | return -3; 124 | } 125 | return -1; 126 | } 127 | return -2; 128 | } 129 | 130 | 131 | S32 se_recv(int* sock, void* buf, U32 len, U32 tmo) 132 | { 133 | int recLen; 134 | uint32_t t = tmo; 135 | if(setsockopt(*sock,SOL_SOCKET,SO_RCVTIMEO,(const char *)&t, sizeof(t)) < 0) 136 | return -10; 137 | L_again: 138 | recLen = recv(*sock,buf,len,0); 139 | if (recLen <= 0) 140 | { 141 | if(recLen == BSD_ERROR_TIMEOUT) 142 | { 143 | if(tmo == INFINITE_TMO) 144 | goto L_again; 145 | return 0; 146 | } 147 | return -1; 148 | } 149 | return recLen; 150 | } 151 | 152 | 153 | 154 | 155 | 156 | #endif 157 | -------------------------------------------------------------------------------- /src/arch/MQX/selibplat.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: selibplat.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2014 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://realtimelogic.com 33 | * http://sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | #include 38 | 39 | #if (!RTCSCFG_ENABLE_DNS) 40 | #error Please recompile RTCS with RTCSCFG_ENABLE_DNS set to 1 in rtcscfg.h 41 | #endif 42 | 43 | 44 | #ifdef SELIB_C 45 | #include 46 | 47 | #ifndef SOMAXCONN 48 | #define SOMAXCONN 5 49 | #endif 50 | 51 | void se_close(int* sock); 52 | 53 | #define X_readtmo 54 | static int readtmo(int sock, U32 tmo) 55 | { 56 | return RTCS_selectset(&sock, 1, tmo == (~((U32)0)) ? 0 : tmo) ? 0 : -1; 57 | } 58 | 59 | #define X_se_bind 60 | int se_bind(int* sock, uint16_t port) 61 | { 62 | struct sockaddr_in addr; 63 | addr.sin_family = AF_INET; 64 | addr.sin_port = port; 65 | addr.sin_addr.s_addr = INADDR_ANY; 66 | if((*sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) 67 | { 68 | return -1; 69 | } 70 | if(bind(*sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) 71 | { 72 | se_close(sock); 73 | return -3; 74 | } 75 | if(listen(*sock, SOMAXCONN) < 0) 76 | { 77 | se_close(sock); 78 | return -2; 79 | } 80 | return 0; 81 | } 82 | 83 | #define X_se_connect 84 | int se_connect(int* sock, const char* address, uint16_t port) 85 | { 86 | unsigned int ip; 87 | struct sockaddr_in addr; 88 | in_addr ipaddr; 89 | if( isdigit(address[0]) && inet_aton(address, &ipaddr) ) 90 | ip = ipaddr.s_addr; 91 | else 92 | { 93 | HOSTENT_STRUCT_PTR hostInfo = DNS_gethostbyname((char*)address); 94 | if( ! hostInfo ) 95 | return -2; 96 | ip = *(uint32_t*)hostInfo->h_addr_list[0]; 97 | } 98 | memset((char*)&addr, 0, sizeof(sockaddr_in)); 99 | addr.sin_family = AF_INET; 100 | addr.sin_port = port; 101 | addr.sin_addr.s_addr = ip; 102 | if ((*sock = socket(AF_INET, SOCK_STREAM, 0)) == RTCS_SOCKET_ERROR) 103 | { 104 | return -1; 105 | } 106 | if(connect(*sock, (struct sockaddr*)&addr, sizeof(sockaddr_in)) == RTCS_OK) 107 | { 108 | return 0; 109 | } 110 | se_close(sock); 111 | return -3; 112 | } 113 | 114 | #define X_se_recv 115 | S32 se_recv(int* sock, void* buf, U32 len, U32 timeout) 116 | { 117 | int recLen; 118 | 119 | if(timeout == INFINITE_TMO) 120 | { 121 | timeout = 0; 122 | } 123 | 124 | recLen = setsockopt(*sock,SOL_TCP,OPT_RECEIVE_TIMEOUT,&timeout,sizeof(U32)); 125 | recLen = recv(*sock,buf,len,0); 126 | 127 | if (recLen == RTCS_ERROR) 128 | { 129 | recLen = RTCS_geterror(*sock); 130 | if (RTCSERR_TCP_TIMED_OUT == recLen) 131 | { 132 | return 0; 133 | } 134 | 135 | return -1; 136 | } 137 | return recLen; 138 | } 139 | 140 | #define closesocket(s) shutdown(s,FLAG_CLOSE_TX) 141 | 142 | #endif /* SELIB_C */ 143 | 144 | -------------------------------------------------------------------------------- /src/arch/NetX/README.txt: -------------------------------------------------------------------------------- 1 | NetX porting layer for selib (socket library). 2 | 3 | Include this directory in the compiler's include path and add seNetX.c 4 | to your build. 5 | 6 | Function seNetX_init (in selibplat.h) must be called prior to using 7 | this library. 8 | 9 | The source code in seNetX.c provides a porting layer to the NetX 10 | TCP/IP stack for all example programs. 11 | 12 | Error codes from some of the native NetX calls in seNetX.c are 13 | considered fatal (they should not occur) and the macro VRSP() calls 14 | function time2Reboot() if an error is returned. You must modify function 15 | time2Reboot() and/or macro VRSP() to suit your platform requirements. 16 | 17 | The API provided by selib follows the typical BSD style API and makes 18 | it possible for all example programs to be portable across all 19 | supported TCP/IP stacks. This is true for all API calls, but special 20 | care must be taken when using function se_accept(). 21 | 22 | BSD accept vs. NetX accept: 23 | 24 | The BSD API takes a server listening socket and spawns a new socket 25 | when a client connects: 26 | 27 | int newSocket = accept(listenSocket, 0, 0); 28 | 29 | NetX on the other hand converts listenSocket into newSocket; details: 30 | https://docs.microsoft.com/en-us/azure/rtos/netx/chapter4#nx_tcp_server_socket_accept 31 | 32 | The selib function se_accept is designed to be NetX compatible, but a 33 | programmer using this function must take extra care when declaring the 34 | socket variables. The following example illustrates how the variables 35 | must be declared. The code is copied from WsLedServer.c, a Minnow 36 | Server example program. 37 | 38 | SOCKET listenSock; 39 | SOCKET sock; 40 | SOCKET* listenSockPtr = &listenSock; 41 | SOCKET* sockPtr = &sock; 42 | ...... 43 | se_accept(&listenSockPtr, INFINITE_TMO, &sockPtr); 44 | 45 | The variables listenSock and sock swaps identity after se_accept 46 | returns. However, since we are using two pointers (listenSockPtr and 47 | sockPtr) further down in the program, everything will work as it does 48 | with a traditional BSD socket accept. This construction works as long 49 | as you do not spawn threads as shown in the multi threaded Minnow 50 | Server example MultiWsLedServer.c, which will not work with NetX. This 51 | code would need some minor redesign when used with NetX. Instead of 52 | declaring the sockets as variables, the socket pointers must be 53 | dynamically allocated, e.g. 54 | 55 | SOCKET* sock1Ptr = malloc(sizeof(SOCKET)); 56 | SOCKET* sock2Ptr = malloc(sizeof(SOCKET)); 57 | ...... 58 | se_accept(&sock1Ptr, INFINITE_TMO, &sock2Ptr); 59 | 60 | When using the Minnow Server library with one socket, an alternative to using 61 | se_accept is to directly use the NetX native API as follows: 62 | 63 | for(;;) 64 | { 65 | SOCKET sock; 66 | NX_TCP_SOCKET* nsSock; 67 | SOCKET_constructor(&sock, NULL); 68 | se_bind(&sock, port); 69 | nsSock=&sock.nxSock; 70 | nx_tcp_server_socket_accept(nxSock, NX_WAIT_FOREVER); 71 | ..... 72 | runServer(&ms, &wph); 73 | ..... 74 | se_close(&sock); 75 | } 76 | -------------------------------------------------------------------------------- /src/arch/NetX/selibplat.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: selibplat.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2014 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://realtimelogic.com 33 | * http://sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | 38 | 39 | #define SharkSSLNetX 40 | #define NO_BSD_SOCK 41 | 42 | #include 43 | #include 44 | 45 | typedef struct { 46 | NX_TCP_SOCKET nxSock; 47 | NX_PACKET* nxFirstPacket; 48 | NX_PACKET* nxPacket; 49 | UCHAR* nxPktOffs; 50 | } SOCKET; 51 | 52 | 53 | #ifdef __cplusplus 54 | extern "C" { 55 | #endif 56 | 57 | void seNetX_init(NX_IP* ip, NX_DNS* dns); 58 | #define se_getSockName seNetX_getSockName 59 | void seNetX_getSockName(SOCKET* sock, char* buf, int* status); 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | -------------------------------------------------------------------------------- /src/arch/Posix/selibplat.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: selibplat.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2014 - 2019 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://realtimelogic.com 33 | * http://sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | 38 | 39 | #define SharkSSLPosix 40 | #define HOST_PLATFORM 1 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | 55 | #ifdef __CYGWIN__ 56 | #define __linux__ 1 57 | #endif 58 | 59 | #ifdef SELIB_C 60 | #ifndef __CYGWIN__ 61 | #define X_se_connect 62 | int se_connect(int* sock, const char* address, U16 port) 63 | { 64 | int retVal=-3; 65 | struct addrinfo* ptr; 66 | struct addrinfo* result = 0; 67 | if(getaddrinfo(address, 0, 0, &result)) 68 | return -2; 69 | for(ptr=result ; ptr ; ptr=ptr->ai_next) 70 | { 71 | int sockfd; 72 | sockfd=socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol); 73 | if(sockfd < 0) 74 | { 75 | retVal=-1; 76 | } 77 | else 78 | { 79 | int nonBlock=1; 80 | if(ptr->ai_family == AF_INET) 81 | ((struct sockaddr_in*)ptr->ai_addr)->sin_port = htons(port); 82 | else if(ptr->ai_family == AF_INET6) 83 | ((struct sockaddr_in6*)ptr->ai_addr)->sin6_port = htons(port); 84 | else 85 | goto L_close; 86 | ioctl(sockfd, FIONBIO, &nonBlock); 87 | if(connect(sockfd, ptr->ai_addr, ptr->ai_addrlen) < 0) 88 | { 89 | if(errno == EINPROGRESS) 90 | { 91 | struct timeval tv; 92 | fd_set fds; 93 | FD_ZERO(&fds); 94 | FD_SET(sockfd, &fds); 95 | tv.tv_sec = 4; 96 | tv.tv_usec = 0; 97 | if(select(sockfd + 1, 0, &fds, 0, &tv)==1) 98 | { 99 | struct sockaddr_in6 in6; 100 | socklen_t size=sizeof(struct sockaddr_in6); 101 | if(!getpeername(sockfd, (struct sockaddr*)&in6, &size)) 102 | goto L_ok; 103 | } 104 | } 105 | L_close: 106 | retVal=-3; 107 | close(sockfd); 108 | } 109 | else 110 | { 111 | L_ok: 112 | nonBlock=0; 113 | ioctl(sockfd, FIONBIO, &nonBlock); 114 | *sock=sockfd; 115 | retVal=0; 116 | break; 117 | } 118 | } 119 | } 120 | freeaddrinfo(result); 121 | return retVal; 122 | } 123 | #endif 124 | #endif 125 | -------------------------------------------------------------------------------- /src/arch/README.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | Socket Example library (selib.c) porting layers 4 | 5 | selib.h includes selibplat.h, which can be found in the following 6 | directories: 7 | 8 | - Non event based porting layers (RTOS): 9 | FreeRTOS-TCP https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/ 10 | Harmony Microchip Harmony TCP/IP 11 | MDK Keil MDK 12 | MQX MQX and RTCS from Freescale 13 | NetX ThreadX and NetX from Express Logic 14 | Posix POSIX including Linux, Mac, VxWorks, QNX 15 | Windows Windows 16 | lwIP lwIP Netconn API for RTOS enabled systems 17 | 18 | - Bare metal (no RTOS) event based porting layers: 19 | lwIP-raw lwIP raw TCP API port: http://lwip.wikia.com/wiki/Raw/TCP 20 | uip uIP TCP/IP port: http://sourceforge.net/projects/uip-stack/ 21 | 22 | Note: bare metal (event based) requires the context manager SeCtx.c 23 | -------------------------------------------------------------------------------- /src/arch/Windows/selibplat.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: selibplat.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2014 - 2017 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://realtimelogic.com 33 | * http://sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | 38 | #ifndef WIN32_LEAN_AND_MEAN 39 | #define WIN32_LEAN_AND_MEAN 1 40 | #endif 41 | 42 | 43 | #define SharkSSLWindows 44 | #ifndef HOST_PLATFORM 45 | #define HOST_PLATFORM 1 46 | #endif 47 | 48 | #include 49 | #include 50 | #include 51 | 52 | #define WINFD_SET(sock,fd) FD_SET((u_int)sock, fd) 53 | 54 | #ifdef SELIB_C 55 | 56 | #include 57 | 58 | #ifndef NO_getaddrinfo 59 | #define X_se_connect 60 | int se_connect(int* sock, const char* address, U16 port) 61 | { 62 | int retVal=-3; 63 | struct addrinfo* ptr; 64 | struct addrinfo* result = 0; 65 | if(getaddrinfo(address, 0, 0, &result)) 66 | return -2; 67 | for(ptr=result ; ptr ; ptr=ptr->ai_next) 68 | { 69 | int sockfd; 70 | sockfd=socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol); 71 | if(sockfd < 0) 72 | { 73 | retVal=-1; 74 | } 75 | else 76 | { 77 | u_long nonBlock=1; 78 | if(ptr->ai_family == AF_INET) 79 | ((struct sockaddr_in*)ptr->ai_addr)->sin_port = htons(port); 80 | else if(ptr->ai_family == AF_INET6) 81 | ((struct sockaddr_in6*)ptr->ai_addr)->sin6_port = htons(port); 82 | else 83 | goto L_close; 84 | ioctlsocket(sockfd, FIONBIO, &nonBlock); 85 | if(connect(sockfd, ptr->ai_addr, ptr->ai_addrlen) < 0) 86 | { 87 | if(WSAGetLastError() == WSAEWOULDBLOCK) 88 | { 89 | struct timeval tv; 90 | fd_set fds; 91 | FD_ZERO(&fds); 92 | WINFD_SET(sockfd, &fds); 93 | tv.tv_sec = 3; 94 | tv.tv_usec = 0; 95 | if(select(sockfd + 1, 0, &fds, 0, &tv)==1) 96 | { 97 | struct sockaddr_in6 in6; 98 | int size=sizeof(struct sockaddr_in6); 99 | if(!getpeername(sockfd, (struct sockaddr*)&in6, &size)) 100 | goto L_ok; 101 | } 102 | } 103 | L_close: 104 | retVal=-3; 105 | closesocket(sockfd); 106 | } 107 | else 108 | { 109 | L_ok: 110 | nonBlock=0; 111 | ioctlsocket(sockfd, FIONBIO, &nonBlock); 112 | *sock=sockfd; 113 | retVal=0; 114 | break; 115 | } 116 | } 117 | } 118 | freeaddrinfo(result); 119 | return retVal; 120 | } 121 | #endif 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /src/arch/lwIP-raw/README.txt: -------------------------------------------------------------------------------- 1 | 2 | Porting layer for lwIP Raw/TCP : http://lwip.wikia.com/wiki/Raw/TCP 3 | 4 | Designed specifically for event driven non RTOS (bare metal) systems. 5 | 6 | Start by reading: 7 | https://realtimelogic.com/ba/doc/en/C/shark/group__BareMetal.html 8 | 9 | 10 | ## lwIP Example: 11 | 12 | 13 | ------------------- Example 1: original lwIP poll loop -------------------- 14 | for(;;) { 15 | sys_check_timeouts(); 16 | . 17 | . 18 | --------------------------------------------------------------------------- 19 | 20 | 21 | 22 | ------------------- Example 2: modified lwIP poll loop -------------------- 23 | static char stackbuf[512]; 24 | static SeCtx ctx; /* Context Manager (magic stack handler) */ 25 | SeCtx_constructor(&ctx, mainTask, stackbuf, sizeof(stackbuf)); 26 | for(;;) { 27 | sys_check_timeouts(); /* 1: run lwIP events */ 28 | SeCtx_run(&ctx); /* 2: run sequential code */ 29 | . 30 | . 31 | 32 | -------------------------------------------------------------------------------- /src/arch/lwIP-raw/selibplat.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: selibplat.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2014 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://realtimelogic.com 33 | * http://sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | 38 | #include 39 | #include 40 | #include "../../SeCtx.h" 41 | 42 | #define SharkSSLlwIPRaw 43 | #define NO_BSD_SOCK 44 | 45 | struct SOCCONT; 46 | 47 | typedef struct SOCKET 48 | { 49 | union { 50 | ip_addr_t ipaddr; /* connect and gethostbyname */ 51 | struct { 52 | struct SOCCONT* pending; 53 | struct SOCKET* outSock; 54 | } accept; 55 | struct { 56 | struct pbuf* buf; /* head */ 57 | struct pbuf* cur; /* cursor */ 58 | U8* data; /* ptr into cursor */ 59 | u16_t len; /* len left in cursor */ 60 | } rec; 61 | } u; 62 | struct tcp_pcb * pcb; 63 | SeCtx* ctx; 64 | int ecode; 65 | S32 outLen; 66 | U8 flags; 67 | } SOCKET; 68 | 69 | 70 | typedef struct SOCCONT 71 | { 72 | struct SOCCONT* next; 73 | SOCKET sock; 74 | } SOCCONT; 75 | 76 | 77 | #define SOCKFLAG_inRecv 1 78 | #define SOCKFLAG_inSend 2 79 | 80 | 81 | #define SOCKET_constructor(o, ctxMA) memset(o,0,sizeof(SOCKET)),(o)->ctx=ctxMA 82 | 83 | int SeCtx_run(SeCtx* ctx); 84 | -------------------------------------------------------------------------------- /src/arch/lwIP/seLwIP.c: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: seLwIP.c 4963 2021-12-17 00:32:59Z wini $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2014 - 2021 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://realtimelogic.com 33 | * http://sharkssl.com 34 | **************************************************************************** 35 | */ 36 | 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #ifndef SharkSSLLwIP 44 | #error SharkSSLLwIP not defined -> Using incorrect selibplat.h 45 | #endif 46 | 47 | 48 | #if LWIP_SO_RCVTIMEO != 1 49 | #error LWIP_SO_RCVTIMEO must be set 50 | #endif 51 | 52 | #ifndef netconn_set_recvtimeout 53 | #define OLD_LWIP 54 | #define netconn_set_recvtimeout(conn, timeout) \ 55 | ((conn)->recv_timeout = (timeout)) 56 | #endif 57 | 58 | 59 | 60 | 61 | int se_accept(SOCKET** listenSock, U32 timeout, SOCKET** outSock) 62 | { 63 | err_t err; 64 | memset(*outSock, 0, sizeof(SOCKET)); 65 | netconn_set_recvtimeout( 66 | (*listenSock)->con, timeout == INFINITE_TMO ? 0 : timeout); 67 | #ifdef OLD_LWIP 68 | (*outSock)->con = netconn_accept((*listenSock)->con); 69 | err = (*outSock)->con->err; 70 | if(!(*outSock)->con && !err) err = ERR_CONN; 71 | #else 72 | err = netconn_accept((*listenSock)->con, &(*outSock)->con); 73 | #endif 74 | if(err != ERR_OK) 75 | { 76 | return err == ERR_TIMEOUT ? 0 : -1; 77 | } 78 | return 1; 79 | } 80 | 81 | 82 | int se_bind(SOCKET* sock, U16 port) 83 | { 84 | int err; 85 | memset(sock, 0, sizeof(SOCKET)); 86 | sock->con = netconn_new(NETCONN_TCP); 87 | if( ! sock->con ) 88 | return -1; 89 | if(netconn_bind(sock->con, IP_ADDR_ANY, port) == ERR_OK) 90 | { 91 | if(netconn_listen(sock->con) == ERR_OK) 92 | return 0; 93 | err = -2; 94 | } 95 | else 96 | err = -3; 97 | netconn_delete(sock->con); 98 | sock->con=0; 99 | return err; 100 | } 101 | 102 | 103 | 104 | /* Returns 0 on success. 105 | Error codes returned: 106 | -1: Cannot create socket: Fatal 107 | -2: Cannot resolve 'address' 108 | -3: Cannot connect 109 | */ 110 | int se_connect(SOCKET* sock, const char* name, U16 port) 111 | { 112 | #ifdef OLD_LWIP 113 | struct ip_addr addr; 114 | #else 115 | ip_addr_t addr; 116 | #endif 117 | memset(sock, 0, sizeof(SOCKET)); 118 | if(netconn_gethostbyname(name, &addr) != ERR_OK) 119 | return -2; 120 | sock->con = netconn_new(NETCONN_TCP); 121 | if( ! sock->con ) 122 | return -1; 123 | if(netconn_connect(sock->con, &addr, port) == ERR_OK) 124 | return 0; 125 | netconn_delete(sock->con); 126 | sock->con=0; 127 | return -3; 128 | } 129 | 130 | 131 | 132 | void se_close(SOCKET* sock) 133 | { 134 | if(sock->con) 135 | { 136 | netconn_close(sock->con); 137 | netconn_delete(sock->con); 138 | } 139 | if(sock->nbuf) 140 | netbuf_delete(sock->nbuf); 141 | memset(sock, 0, sizeof(SOCKET)); 142 | } 143 | 144 | 145 | 146 | S32 se_send(SOCKET* sock, const void* buf, U32 len) 147 | { 148 | err_t err=netconn_write(sock->con, buf, len, NETCONN_COPY); 149 | if(err != ERR_OK) 150 | { 151 | se_close(sock); 152 | return (S32)err; 153 | } 154 | return len; 155 | } 156 | 157 | 158 | 159 | S32 se_recv(SOCKET* sock, void* data, U32 len, U32 timeout) 160 | { 161 | int rlen; 162 | netconn_set_recvtimeout(sock->con, timeout == INFINITE_TMO ? 0 : timeout); 163 | if( ! sock->nbuf ) 164 | { 165 | err_t err; 166 | sock->pbOffs = 0; 167 | #ifdef OLD_LWIP 168 | sock->nbuf = netconn_recv(sock->con); 169 | err = sock->con->err; 170 | if(!sock->nbuf && !err) err = ERR_CONN; 171 | #else 172 | err = netconn_recv(sock->con, &sock->nbuf); 173 | #endif 174 | if(ERR_OK != err) 175 | { 176 | if(sock->nbuf) 177 | netbuf_delete(sock->nbuf); 178 | sock->nbuf=0; 179 | return err == ERR_TIMEOUT ? 0 : (S32)err; 180 | } 181 | } 182 | rlen=(int)netbuf_copy_partial(sock->nbuf,(U8*)data,len,sock->pbOffs); 183 | if(!rlen) 184 | return -1; 185 | sock->pbOffs += rlen; 186 | if(sock->pbOffs >= netbuf_len(sock->nbuf)) 187 | { 188 | netbuf_delete(sock->nbuf); 189 | sock->nbuf=0; 190 | } 191 | return rlen; 192 | } 193 | 194 | 195 | 196 | int se_sockValid(SOCKET* sock) 197 | { 198 | return sock->con != 0; 199 | } 200 | -------------------------------------------------------------------------------- /src/arch/lwIP/selibplat.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: selibplat.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2014 - 2016 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://realtimelogic.com 33 | * http://sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | 38 | #define SharkSSLLwIP 39 | #define NO_BSD_SOCK 40 | 41 | struct netconn; 42 | struct netbuf; 43 | 44 | typedef struct 45 | { 46 | struct netconn* con; 47 | struct netbuf* nbuf; 48 | int pbOffs; 49 | } SOCKET; 50 | 51 | #if __MBED__ 52 | #include 53 | #ifndef B_LITTLE_ENDIAN 54 | #define B_LITTLE_ENDIAN 55 | #endif 56 | #define XTYPES 57 | #define xprintf(x) printf x 58 | #endif 59 | -------------------------------------------------------------------------------- /src/arch/uip/README.txt: -------------------------------------------------------------------------------- 1 | 2 | Porting layer for uIP, the two kb TCP/IP stack. 3 | 4 | Start by reading: 5 | https://realtimelogic.com/ba/doc/en/C/shark/group__BareMetal.html 6 | 7 | The uIP porting layer has been tested on the uIP stack that comes with 8 | the Texas Instrument's extremely low cost Cortex M4 development board 9 | EK-TM4C1294XL: http://www.ti.com/tool/ek-tm4c1294xl 10 | 11 | uIP version 1.0 can also be downloaded from: 12 | http://sourceforge.net/projects/uip-stack/ 13 | 14 | The porting layer is currently limited to client socket 15 | connections. It is specifically designed for low cost IoT (M2M) 16 | solutions. The porting layer has been tested with SharkMQ, the LED 17 | demos, and the SMTP lib. These examples require DHCP for easy 18 | configuration and hostname lookup (DNS). DHCP and DNS are provided in 19 | uIP as applications and can be found in the uIP's application sub 20 | directory. 21 | 22 | Compiler include path: 23 | examples\arch\uip 24 | examples 25 | inc 26 | inc\arch\BareMetal 27 | 28 | 29 | ----------------------------------------------------------- 30 | ***** Required uIP modifications 31 | ----------------------------------------------------------- 32 | 33 | uIP is optimized for use with one application. Using more 34 | than one application requires careful configuration; at a 35 | minimum, three applications will be required: one SharkSSL example, DHCP, and 36 | DNS. 37 | 38 | 39 | 40 | 41 | ----------------------------------------------------------- 42 | ***** Step 1: Modify uIP for multi application use. 43 | ----------------------------------------------------------- 44 | 45 | resolv.h: comment out: 46 | typedef int uip_udp_appstate_t; 47 | #define UIP_UDP_APPCALL resolv_appcall 48 | 49 | dhcp.h: comment out: 50 | typedef struct dhcpc_state uip_udp_appstate_t; 51 | #define UIP_UDP_APPCALL dhcpc_appcall 52 | 53 | ** Add the following in uip-conf.h: 54 | #include "dhcpc/dhcpc.h" 55 | #include "resolv/resolv.h" 56 | #ifdef RESOLV_C 57 | typedef int uip_udp_appstate_t; 58 | #else 59 | typedef union{ 60 | int resolve; 61 | struct dhcpc_state dhcp; 62 | }uip_udp_appstate_t; 63 | #endif 64 | 65 | #define UIP_UDP_APPCALL() do { \ 66 | if(uip_hostaddr[0]) resolv_appcall(); else dhcpc_appcall(); } while(0) 67 | 68 | #define resolv_found se_resolv_found 69 | 70 | ** Modify the following code: 71 | 72 | from: 73 | #define UIP_APPCALL httpd_appcall 74 | to: 75 | #define UIP_APPCALL() se_appcall() 76 | 77 | ** Modify the following code: 78 | 79 | from: 80 | typedef struct httpd_state uip_tcp_appstate_t 81 | to: 82 | struct SOCKET; 83 | typedef struct 84 | { 85 | struct SOCKET* sock; 86 | } uip_tcp_appstate_t; 87 | 88 | #define GET_SOCKET() uip_conn->appstate.sock 89 | #define SET_SOCKET(conn,s) conn->appstate.sock=s 90 | 91 | Make sure this is set: 92 | #define UIP_BUFSIZE 1500 /* We have also tested with 700 */ 93 | #define UIP_REASSEMBLY 1 94 | 95 | 96 | ----------------------------------------------------------- 97 | ***** Step 2: Include the additional uIP apps required. 98 | ----------------------------------------------------------- 99 | 100 | Make sure dhcpc/dhcpc.c and resolv/resolv.c are included in your build. 101 | 102 | Add the following in resolve.c, just above the line: #include "resolv.h" 103 | #define RESOLV_C 104 | 105 | Make sure resolv_init and resolv_conf are called. Function resolv_conf 106 | can be called when DHCP is configured as follows: 107 | resolv_conf((unsigned short*)s->default_router); 108 | 109 | ----------------------------------------------------------- 110 | ***** Step 3: Implement timer function. 111 | ----------------------------------------------------------- 112 | 113 | Implement function u32_t sys_now(void); 114 | 115 | The timer function must return system time in milliseconds. The 116 | function is typically implemented as follows: 117 | 118 | u32_t systemTime; /* Global variable updated by timer tick interrupt function */ 119 | u32_t sys_now(void) 120 | { 121 | return systemTime; 122 | } 123 | 124 | 125 | ----------------------------------------------------------- 126 | ***** Step 4: Include an allocator. 127 | ----------------------------------------------------------- 128 | 129 | SharkSSL requires an allocator. You can use any allocator or the 130 | included 'umm' allocator. You must compile the code with the following 131 | macro if you intend to use 'umm'. 132 | 133 | UMM_MALLOC 134 | 135 | 136 | ----------------------------------------------------------- 137 | ***** Step 5: Call SeCtx_run from uIP main loop. 138 | ----------------------------------------------------------- 139 | 140 | static char stackbuf[512]; 141 | static SeCtx ctx; /* Context Manager (magic stack handler) */ 142 | SeCtx_constructor(&ctx, mainTask, stackbuf, sizeof(stackbuf)); 143 | while(true) 144 | { 145 | ; 146 | ; 147 | if(BUF->type == htons(UIP_ETHTYPE_IP)) 148 | { 149 | uip_arp_ipin(); 150 | uip_input(); 151 | SeCtx_run(&ctx); 152 | ; 153 | ; 154 | } 155 | else // main loop is idle 156 | { 157 | SeCtx_run(&ctx); // Check timers 158 | } 159 | 160 | The above code snippet is from the TM4C1294XL port. The uIP function 161 | uip_input is called when a new Ethernet interrupt has 162 | occurred. function SeCtx_run must be called immediately after 163 | uip_input. We are also calling SeCtx_run when the main loop is idle. 164 | 165 | Function 'SeCtx_run', found in seuip.c, is internally using the 166 | Context Manager (SeCtx.c). See the following link for more info on SeCtx.c. 167 | https://realtimelogic.com/ba/doc/en/C/shark/group__BareMetal.html 168 | 169 | ------------------------ 170 | Errors: 171 | ------------------------ 172 | 173 | We got a compile error in uIP when compiled with IAR. If you get a 174 | compile error in resolv_conf, change the function to: 175 | 176 | void 177 | resolv_conf(u16_t *dnsserver) 178 | { 179 | union { 180 | u16_t *dns; 181 | uip_ipaddr_t* addr; 182 | } u; 183 | if(resolv_conn != NULL) { 184 | uip_udp_remove(resolv_conn); 185 | } 186 | u.dns = dnsserver; 187 | resolv_conn = uip_udp_new(u.addr, HTONS(53)); 188 | } 189 | 190 | ------------------------ 191 | Optimizing SharkSSL for minimum size: 192 | ------------------------ 193 | 194 | You probably have severe memory limitations if you use uIP. The 195 | following macro makes the SharkSSL code base less than 20Kb. 196 | 197 | SHARKSSL_TINY 198 | 199 | See the user config file inc/SharkSSL_opts.h for details. 200 | -------------------------------------------------------------------------------- /src/arch/uip/selibplat.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: selibplat.h 4769 2021-06-11 17:29:36Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2014 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://realtimelogic.com 33 | **************************************************************************** 34 | * 35 | */ 36 | 37 | #include 38 | #include "../../SeCtx.h" 39 | 40 | #define SharkSSLuIP 41 | #define NO_BSD_SOCK 42 | 43 | typedef struct SOCKETMSG 44 | { 45 | struct SOCKETMSG* next; 46 | int size; 47 | } SOCKETMSG; 48 | 49 | #ifndef SEUIP_CONN 50 | #define SEUIP_CONN struct uip_conn 51 | #endif 52 | 53 | typedef struct SOCKET 54 | { 55 | SeCtx* ctx; 56 | SEUIP_CONN* conn; 57 | union { 58 | struct { 59 | uip_ipaddr_t ipaddr; 60 | BaBool OK; 61 | } resolv; 62 | struct { 63 | U8* buf; 64 | int size; 65 | } data; 66 | } u; 67 | SOCKETMSG* msg; 68 | U8 flags; 69 | } SOCKET; 70 | 71 | #define SOCKFLAG_inRecv 1 72 | #define SOCKFLAG_inSend 2 73 | #define SOCKFLAG_inConnect 4 74 | #define SOCKFLAG_newdata 8 75 | #define SOCKFLAG_startSend 16 76 | 77 | 78 | #define SOCKET_constructor(o, ctxMA) memset(o,0,sizeof(SOCKET)),(o)->ctx=ctxMA 79 | 80 | int SeCtx_run(SeCtx* ctx); 81 | -------------------------------------------------------------------------------- /tools/SharkSSLParseCAList.c: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: SharkSSLParseCAList.c 5006 2022-01-07 19:54:12Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2010 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://www.realtimelogic.com 33 | * http://www.sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | 38 | 39 | /** 40 | * COMPILATION - command line from within the tools subdir 41 | * 42 | * WINDOWS: 43 | * cl /O2 SharkSslParseCAList.c -I..\inc -I..\inc\arch\Windows 44 | * 45 | * LINUX: 46 | * gcc SharkSslParseCAList.c -I../inc -I../inc/arch/Posix -O3 -o SharkSslParseCAList 47 | */ 48 | 49 | 50 | #include "SharkSSLTools.h" 51 | 52 | 53 | static int SharkSslCertStore_assemble_2(SharkSslCertStore *o, unsigned char **outList) 54 | { 55 | int list_off, cert_size, tot_cert_size; 56 | DoubleListEnumerator iter; 57 | SharkSslCSCert *cert; 58 | unsigned char *p; 59 | 60 | /* determine total vector size */ 61 | list_off = 4 + (o->elements * SHARKSSL_CA_LIST_ELEMENT_SIZE); 62 | tot_cert_size = list_off; 63 | DoubleListEnumerator_constructor(&iter, &o->certList); 64 | for (cert = (SharkSslCSCert*)DoubleListEnumerator_getElement(&iter); cert; 65 | cert = (SharkSslCSCert*)DoubleListEnumerator_nextElement(&iter)) 66 | { 67 | cert_size = SharkSslCert_len(cert->ptr); 68 | tot_cert_size += cert_size; 69 | } 70 | 71 | /* create vector */ 72 | p = (unsigned char*)baMalloc(tot_cert_size); 73 | *outList = p; 74 | if (p == (void*)0) 75 | { 76 | return -1; 77 | } 78 | 79 | *p++ = SHARKSSL_CA_LIST_INDEX_TYPE; 80 | *p++ = 0; 81 | *p++ = (unsigned char)(((o->elements) >> 8)); 82 | *p++ = (unsigned char)((o->elements) & 0xFF); 83 | 84 | DoubleListEnumerator_constructor(&iter, &o->certList); 85 | for (cert = (SharkSslCSCert*)DoubleListEnumerator_getElement(&iter); cert; 86 | cert = (SharkSslCSCert*)DoubleListEnumerator_nextElement(&iter)) 87 | { 88 | memcpy(p, cert->name, SHARKSSL_CA_LIST_NAME_SIZE); 89 | p += SHARKSSL_CA_LIST_NAME_SIZE; 90 | *p++ = (unsigned char)(list_off >> 24); 91 | *p++ = (unsigned char)(list_off >> 16); 92 | *p++ = (unsigned char)(list_off >> 8); 93 | *p++ = (unsigned char)(list_off & 0xFF); 94 | cert_size = SharkSslCert_len(cert->ptr); 95 | memcpy(*outList + list_off, cert->ptr, cert_size); 96 | list_off += cert_size; 97 | } 98 | 99 | return tot_cert_size; 100 | } 101 | 102 | 103 | /** 104 | * main 105 | */ 106 | int main(int argc, char **argv) 107 | { 108 | SharkSslCertStore certStore; 109 | unsigned char *caList, *outBuf; 110 | 111 | initVars(); 112 | (void)errorString; /* warning removal */ 113 | printRev("$Id: SharkSSLParseCAList.c 5006 2022-01-07 19:54:12Z gianluca $"); 114 | 115 | if (argc < 2) 116 | { 117 | print_usage: 118 | printf("Usage: %s [-b ] [certfile...]\n" 119 | " where certfile is a .PEM, .DER or .P7B file containing\n" 120 | " one or more certificates\n", argv[0]); 121 | return 1; 122 | } 123 | 124 | if (strcmp(argv[1], "-b") == 0) 125 | { 126 | if (argc < 4) 127 | { 128 | goto print_usage; 129 | } 130 | 131 | output_fmt = BINARY; 132 | binFName = argv[2]; 133 | } 134 | 135 | SharkSslCertStore_constructor(&certStore); 136 | while (--argc >= ((output_fmt == BINARY) ? 3 : 1)) 137 | { 138 | ret_val = readFile(argv[argc], &outBuf); 139 | if (ret_val < 0) 140 | { 141 | printf("Error parsing \"%s\"\n", argv[argc]); 142 | ret_val = 1; 143 | goto _end; 144 | } 145 | else 146 | { 147 | SharkSslCertStore_add(&certStore, (const char*)outBuf, (U32)ret_val); 148 | baFree(outBuf); 149 | } 150 | } 151 | 152 | vect_size = SharkSslCertStore_assemble_2(&certStore, &caList); 153 | if (vect_size > 0) 154 | { 155 | ret_val = outputVector(caList, "sharkSslCAList"); 156 | } 157 | else 158 | { 159 | printf("Error allocating memory\n"); 160 | ret_val = 1; 161 | } 162 | _end: 163 | SharkSslCertStore_destructor(&certStore); 164 | return ret_val; 165 | } 166 | 167 | -------------------------------------------------------------------------------- /tools/SharkSSLParseCert.c: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: SharkSSLParseCert.c 5637 2025-03-02 21:51:18Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2010 - 2018 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://www.realtimelogic.com 33 | * http://www.sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | 38 | 39 | /** 40 | * COMPILATION - command line from within the tools subdir 41 | * 42 | * WINDOWS: 43 | * cl /O2 SharkSslParseCert.c -I..\inc -I..\inc\arch\Windows 44 | * 45 | * LINUX: 46 | * gcc SharkSslParseCert.c -I../inc -I../inc/arch/Posix -O3 -o SharkSSLParseCert 47 | */ 48 | 49 | 50 | #include "SharkSSLTools.h" 51 | 52 | 53 | /** 54 | * main 55 | */ 56 | int main (int argc, char **argv) 57 | { 58 | sharkssl_PEM_RetVal ret; 59 | unsigned char *certBuf, *keyBuf; 60 | char str[30], *type; 61 | SharkSslCert sharkSslCert; 62 | char *certName=""; 63 | U8 cert_type; 64 | 65 | initVars(); 66 | printRev("$Id: SharkSSLParseCert.c 5637 2025-03-02 21:51:18Z gianluca $"); 67 | 68 | if (argc < 3) 69 | { 70 | print_usage: 71 | printf("Usage: %s [-p ] [-b ] [-c ]\n", argv[0]); 72 | return 1; 73 | } 74 | 75 | if (argc > 3) 76 | { 77 | if (strcmp(argv[3], "-b") == 0 || strcmp(argv[3], "-c") == 0) 78 | { 79 | if (argc != 5) 80 | { 81 | goto print_usage; 82 | } 83 | if(strcmp(argv[3], "-b") == 0) 84 | { 85 | output_fmt = BINARY; 86 | binFName = argv[4]; 87 | } 88 | else 89 | { 90 | certName = argv[4]; 91 | } 92 | } 93 | 94 | else if (strcmp(argv[3], "-p") == 0) 95 | { 96 | if (argc == 7) 97 | { 98 | if (strcmp(argv[5], "-b") == 0) 99 | { 100 | output_fmt = BINARY; 101 | binFName = argv[6]; 102 | } 103 | else if (strcmp(argv[5], "-c") == 0) 104 | { 105 | certName = argv[6]; 106 | } 107 | else 108 | { 109 | goto print_usage; 110 | } 111 | } 112 | 113 | else if (argc != 5) 114 | { 115 | goto print_usage; 116 | } 117 | 118 | passKey = argv[4]; 119 | } 120 | 121 | else 122 | { 123 | goto print_usage; 124 | } 125 | } 126 | 127 | if (readFile(argv[1], &certBuf) < 0) 128 | { 129 | printf("Error reading %s\n",argv[1]); 130 | return 1; 131 | } 132 | 133 | if (readFile(argv[2], &keyBuf) < 0) 134 | { 135 | printf("Error reading %s\n",argv[2]); 136 | baFree(certBuf); 137 | return 1; 138 | } 139 | 140 | ret = sharkssl_PEM((const char*)certBuf, 141 | (const char*)keyBuf, (const char*)passKey, 142 | &sharkSslCert); 143 | 144 | baFree(certBuf); 145 | baFree(keyBuf); 146 | 147 | if (ret != SHARKSSL_PEM_OK) 148 | { 149 | if (ret == SHARKSSL_PEM_OK_PUBLIC) 150 | { 151 | printf("Please provide a PRIVATE key\n"); 152 | } 153 | else 154 | { 155 | printf("%s error\n", errorString(ret)); 156 | } 157 | return 1; 158 | } 159 | 160 | vect_size = SharkSslCert_vectSize_keyInfo(sharkSslCert, &cert_type, NULL, NULL, NULL, NULL, NULL); 161 | if (vect_size > 0) 162 | { 163 | if (SHARKSSL_KEYTYPE_RSA == cert_type) 164 | { 165 | type = (char*)"RSA"; 166 | } 167 | else if (SHARKSSL_KEYTYPE_EC == cert_type) 168 | { 169 | type = (char*)"EC"; 170 | } 171 | else 172 | { 173 | goto _parsing_error; 174 | } 175 | } 176 | else 177 | { 178 | _parsing_error: 179 | printf("Parsing error\n"); 180 | return 1; 181 | } 182 | pad_size = 1 + SHARKSSL_DIM_ARR(padv) - (vect_size & SHARKSSL_DIM_ARR(padv)); 183 | pad_size &= SHARKSSL_DIM_ARR(padv); 184 | 185 | sprintf(str, "sharkSsl%sCert%s", type, certName); 186 | ret_val = outputVector((unsigned char*)sharkSslCert, str); 187 | baFree((void*)sharkSslCert); 188 | return ret_val; 189 | } 190 | 191 | -------------------------------------------------------------------------------- /tools/SharkSSLParseKey.c: -------------------------------------------------------------------------------- 1 | /** 2 | * ____ _________ __ _ 3 | * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 4 | * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 5 | * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 6 | * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 7 | * /____/ 8 | * 9 | * SharkSSL Embedded SSL/TLS Stack 10 | **************************************************************************** 11 | * PROGRAM MODULE 12 | * 13 | * $Id: SharkSSLParseKey.c 5637 2025-03-02 21:51:18Z gianluca $ 14 | * 15 | * COPYRIGHT: Real Time Logic LLC, 2010 16 | * 17 | * This software is copyrighted by and is the sole property of Real 18 | * Time Logic LLC. All rights, title, ownership, or other interests in 19 | * the software remain the property of Real Time Logic LLC. This 20 | * software may only be used in accordance with the terms and 21 | * conditions stipulated in the corresponding license agreement under 22 | * which the software has been supplied. Any unauthorized use, 23 | * duplication, transmission, distribution, or disclosure of this 24 | * software is expressly forbidden. 25 | * 26 | * This Copyright notice may not be removed or modified without prior 27 | * written consent of Real Time Logic LLC. 28 | * 29 | * Real Time Logic LLC. reserves the right to modify this software 30 | * without notice. 31 | * 32 | * http://www.realtimelogic.com 33 | * http://www.sharkssl.com 34 | **************************************************************************** 35 | * 36 | */ 37 | 38 | 39 | /** 40 | * COMPILATION - command line from within the tools subdir 41 | * 42 | * WINDOWS: 43 | * cl /O2 SharkSslParseKey.c -I..\inc -I..\inc\arch\Windows 44 | * 45 | * LINUX: 46 | * gcc SharkSslParseKey.c -I../inc -I../inc/arch/Posix -O3 -o SharkSSLParseKey 47 | */ 48 | 49 | 50 | #include "SharkSSLTools.h" 51 | 52 | 53 | /** 54 | * main 55 | */ 56 | int main (int argc, char **argv) 57 | { 58 | sharkssl_PEM_RetVal ret; 59 | unsigned char *keyBuf; 60 | char str[30], *type; 61 | SharkSslCert sharkSslCert; 62 | U8 cert_type; 63 | 64 | initVars(); 65 | printRev("$Id: SharkSSLParseKey.c 5637 2025-03-02 21:51:18Z gianluca $"); 66 | 67 | if (argc < 2) 68 | { 69 | print_usage: 70 | printf("Usage: %s [-p ] [-b ]\n" 71 | " %s [-b ]\n", argv[0], argv[0]); 72 | return 1; 73 | } 74 | 75 | if (argc > 2) 76 | { 77 | if (strcmp(argv[2], "-b") == 0) 78 | { 79 | if (argc != 4) 80 | { 81 | goto print_usage; 82 | } 83 | 84 | output_fmt = BINARY; 85 | binFName = argv[3]; 86 | } 87 | 88 | else if (strcmp(argv[2], "-p") == 0) 89 | { 90 | if (argc == 6) 91 | { 92 | if (strcmp(argv[4], "-b") == 0) 93 | { 94 | output_fmt = BINARY; 95 | binFName = argv[5]; 96 | } 97 | 98 | else 99 | { 100 | goto print_usage; 101 | } 102 | } 103 | 104 | else if (argc != 4) 105 | { 106 | goto print_usage; 107 | } 108 | 109 | passKey = argv[3]; 110 | } 111 | 112 | else 113 | { 114 | goto print_usage; 115 | } 116 | } 117 | 118 | if (readFile(argv[1], &keyBuf) < 0) 119 | { 120 | printf("Error reading %s\n",argv[1]); 121 | return 1; 122 | } 123 | 124 | ret = sharkssl_PEM((const char*)0, 125 | (const char*)keyBuf, (const char*)passKey, 126 | &sharkSslCert); 127 | 128 | baFree(keyBuf); 129 | 130 | if ((ret != SHARKSSL_PEM_OK) && (ret != SHARKSSL_PEM_OK_PUBLIC)) 131 | { 132 | printf("%s error\n", errorString(ret)); 133 | return 1; 134 | } 135 | 136 | vect_size = SharkSslCert_vectSize_keyInfo(sharkSslCert, &cert_type, NULL, NULL, NULL, NULL, NULL); 137 | if (vect_size > 0) 138 | { 139 | if (SHARKSSL_KEYTYPE_RSA == cert_type) 140 | { 141 | type = (char*)"RSA"; 142 | } 143 | else if (SHARKSSL_KEYTYPE_EC == cert_type) 144 | { 145 | type = (char*)"EC"; 146 | } 147 | else 148 | { 149 | goto _parsing_error; 150 | } 151 | } 152 | else 153 | { 154 | _parsing_error: 155 | printf("Parsing error\n"); 156 | return 1; 157 | } 158 | pad_size = 1 + SHARKSSL_DIM_ARR(padv) - (vect_size & SHARKSSL_DIM_ARR(padv)); 159 | pad_size &= SHARKSSL_DIM_ARR(padv); 160 | 161 | sprintf(str, "sharkSsl%s%sKey", (ret == SHARKSSL_PEM_OK_PUBLIC ? "Pub" : "Priv"), type); 162 | ret_val = outputVector((unsigned char*)sharkSslCert, str); 163 | baFree((void*)sharkSslCert); 164 | return ret_val; 165 | } 166 | --------------------------------------------------------------------------------