├── README.md ├── aws_mbedtls_mqtt-master.zip ├── examples ├── aws_paho_mqtt │ ├── aws_mtk_iot_config.h │ └── aws_paho_mqtt.ino └── aws_paho_shadow │ ├── aws_mtk_iot_config.h │ └── aws_paho_shadow.ino ├── library.json ├── library.properties ├── src ├── aws_iot_lib │ ├── MQTTClient.cpp │ ├── MQTTClient.h │ ├── MQTTConnect.h │ ├── MQTTConnectClient.cpp │ ├── MQTTConnectServer.cpp │ ├── MQTTDeserializePublish.cpp │ ├── MQTTFormat.cpp │ ├── MQTTFormat.h │ ├── MQTTPacket.cpp │ ├── MQTTPacket.h │ ├── MQTTPublish.h │ ├── MQTTSerializePublish.cpp │ ├── MQTTSubscribe.h │ ├── MQTTSubscribeClient.cpp │ ├── MQTTSubscribeServer.cpp │ ├── MQTTUnsubscribe.h │ ├── MQTTUnsubscribeClient.cpp │ ├── MQTTUnsubscribeServer.cpp │ ├── aws_iot_config.h │ ├── aws_iot_error.h │ ├── aws_iot_json_utils.cpp │ ├── aws_iot_json_utils.h │ ├── aws_iot_log.h │ ├── aws_iot_mqtt_embedded_client_wrapper.cpp │ ├── aws_iot_mqtt_interface.h │ ├── aws_iot_shadow.cpp │ ├── aws_iot_shadow_actions.cpp │ ├── aws_iot_shadow_actions.h │ ├── aws_iot_shadow_interface.h │ ├── aws_iot_shadow_json.cpp │ ├── aws_iot_shadow_json.h │ ├── aws_iot_shadow_json_data.h │ ├── aws_iot_shadow_key.h │ ├── aws_iot_shadow_records.cpp │ ├── aws_iot_shadow_records.h │ ├── aws_iot_version.h │ ├── network_interface.h │ ├── network_mbedtls_wrapper.cpp │ ├── timer.cpp │ └── timer_interface.h ├── linkit_aws_header.h └── mbedtls │ ├── .gitignore │ ├── FP.h │ ├── StackTrace.h │ ├── aes.c │ ├── aes.h │ ├── aesni.c │ ├── aesni.h │ ├── arc4.c │ ├── arc4.h │ ├── asn1.h │ ├── asn1parse.c │ ├── asn1write.c │ ├── asn1write.h │ ├── base64.c │ ├── base64.h │ ├── bignum.c │ ├── bignum.h │ ├── blowfish.c │ ├── blowfish.h │ ├── bn_mul.h │ ├── camellia.c │ ├── camellia.h │ ├── ccm.c │ ├── ccm.h │ ├── certs.c │ ├── certs.h │ ├── check_config.h │ ├── cipher.c │ ├── cipher.h │ ├── cipher_internal.h │ ├── cipher_wrap.c │ ├── compat-1.3.h │ ├── config.h │ ├── ctr_drbg.c │ ├── ctr_drbg.h │ ├── debug.c │ ├── debug.h │ ├── des.c │ ├── des.h │ ├── dhm.c │ ├── dhm.h │ ├── ecdh.c │ ├── ecdh.h │ ├── ecdsa.c │ ├── ecdsa.h │ ├── ecp.c │ ├── ecp.h │ ├── ecp_curves.c │ ├── entropy.c │ ├── entropy.h │ ├── entropy_poll.c │ ├── entropy_poll.h │ ├── error.c │ ├── error.h │ ├── gcm.c │ ├── gcm.h │ ├── havege.c │ ├── havege.h │ ├── hmac_drbg.c │ ├── hmac_drbg.h │ ├── jsmn.c │ ├── jsmn.h │ ├── md.c │ ├── md.h │ ├── md2.c │ ├── md2.h │ ├── md4.c │ ├── md4.h │ ├── md5.c │ ├── md5.h │ ├── md_internal.h │ ├── md_wrap.c │ ├── memory_buffer_alloc.c │ ├── memory_buffer_alloc.h │ ├── mtk.cpp │ ├── mtk.h │ ├── myprintWrapper.cpp │ ├── net.c │ ├── net.h │ ├── oid.c │ ├── oid.h │ ├── padlock.c │ ├── padlock.h │ ├── pem.c │ ├── pem.h │ ├── pk.c │ ├── pk.h │ ├── pk_internal.h │ ├── pk_wrap.c │ ├── pkcs11.c │ ├── pkcs11.h │ ├── pkcs12.c │ ├── pkcs12.h │ ├── pkcs5.c │ ├── pkcs5.h │ ├── pkparse.c │ ├── pkwrite.c │ ├── platform.c │ ├── platform.h │ ├── ripemd160.c │ ├── ripemd160.h │ ├── rsa.c │ ├── rsa.h │ ├── sha1.c │ ├── sha1.h │ ├── sha256.c │ ├── sha256.h │ ├── sha512.c │ ├── sha512.h │ ├── ssl.h │ ├── ssl_cache.c │ ├── ssl_cache.h │ ├── ssl_ciphersuites.c │ ├── ssl_ciphersuites.h │ ├── ssl_cli.c │ ├── ssl_cookie.c │ ├── ssl_cookie.h │ ├── ssl_internal.h │ ├── ssl_srv.c │ ├── ssl_ticket.c │ ├── ssl_ticket.h │ ├── ssl_tls.c │ ├── threading.c │ ├── threading.h │ ├── timing.c │ ├── timing.h │ ├── version.c │ ├── version.h │ ├── version_features.c │ ├── x509.c │ ├── x509.h │ ├── x509_create.c │ ├── x509_crl.c │ ├── x509_crl.h │ ├── x509_crt.c │ ├── x509_crt.h │ ├── x509_csr.c │ ├── x509_csr.h │ ├── x509write_crt.c │ ├── x509write_csr.c │ ├── xtea.c │ └── xtea.h └── tools ├── platform_txt ├── Mac_Arduino_1.5.7_platform │ └── platform.txt ├── Mac_Arduino_1.6.5_platform │ └── platform.txt ├── Windows_Arduino_1.5.7_platform │ └── platform.txt └── Windows_Arduino_1.6.5_platform │ └── platform.txt └── root_cert └── G5.pem /aws_mbedtls_mqtt-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MediaTek-Labs/aws_mbedtls_mqtt/6636bdc7bcfa5e87a518bd8299ca35c4217fba90/aws_mbedtls_mqtt-master.zip -------------------------------------------------------------------------------- /examples/aws_paho_mqtt/aws_mtk_iot_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_mtk_iot_config.h 18 | * @brief AWS IoT specific configuration file 19 | */ 20 | 21 | #ifndef SRC_SHADOW_IOT_SHADOW_CONFIG_H_ 22 | #define SRC_SHADOW_IOT_SHADOW_CONFIG_H_ 23 | 24 | // Get from console 25 | // ================================================= 26 | #define AWS_IOT_MQTT_HOST "A21DXA5BCPF81N.iot.us-west-2.amazonaws.com" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow 27 | #define AWS_IOT_MQTT_PORT 8883 ///< default port for MQTT/S 28 | #define AWS_IOT_MQTT_CLIENT_ID "NTHU_LinkitOne" ///< MQTT client ID should be unique for every device 29 | #define AWS_IOT_MY_THING_NAME "mtk_test_mf" //IMPORTANT: for a temporary work around, you also need to modify the same name in your library for aws_iot_config.h (under arduino library path) 30 | #define AWS_IOT_ROOT_CA_FILENAME "root.pem" ///< Root CA file name 31 | #define AWS_IOT_CERTIFICATE_FILENAME "8cbd725746-certificate.pem.crt" ///< device signed certificate file name 32 | #define AWS_IOT_PRIVATE_KEY_FILENAME "8cbd725746-private.pem.key" ///< Device private key filename 33 | #define AWS_IOT_TOPIC_NAME "$aws/things/mtk_test_mf/shadow/update" //MQTT subscribe/publish Topic name 34 | // ================================================= 35 | 36 | //set to use Wifi or GPRS 37 | #define WIFI_USED true //true (Wifi) or false (GPRS) 38 | 39 | /* change Wifi settings here */ 40 | #define WIFI_AP "Home-WIFI" 41 | #define WIFI_PASSWORD "06191026" 42 | #define WIFI_AUTH LWIFI_WPA // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP 43 | 44 | /* change GPRS settings here */ 45 | #define GPRS_APN "wap.cingular" //for AT&T 46 | #define GPRS_USERNAME "wap@cingulargprs.com" 47 | #define GPRS_PASSWORD "cingular1" 48 | 49 | #endif /* SRC_SHADOW_IOT_SHADOW_CONFIG_H_ */ 50 | -------------------------------------------------------------------------------- /examples/aws_paho_shadow/aws_mtk_iot_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_mtk_iot_config.h 18 | * @brief AWS IoT specific configuration file 19 | */ 20 | 21 | #ifndef SRC_SHADOW_IOT_SHADOW_CONFIG_H_ 22 | #define SRC_SHADOW_IOT_SHADOW_CONFIG_H_ 23 | 24 | // Get from console 25 | // ================================================= 26 | #define AWS_IOT_MQTT_HOST "A21DXA5BCPF81N.iot.us-west-2.amazonaws.com" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow 27 | #define AWS_IOT_MQTT_PORT 8883 ///< default port for MQTT/S 28 | #define AWS_IOT_MQTT_CLIENT_ID "NTHU_LinkitOne" ///< MQTT client ID should be unique for every device 29 | #define AWS_IOT_MY_THING_NAME "mtk_test_mf" //IMPORTANT: for a temporary work around, you also need to modify the same name in your library for aws_iot_config.h (under arduino library path) 30 | #define AWS_IOT_ROOT_CA_FILENAME "root.pem" ///< Root CA file name 31 | #define AWS_IOT_CERTIFICATE_FILENAME "8cbd725746-certificate.pem.crt" ///< device signed certificate file name 32 | #define AWS_IOT_PRIVATE_KEY_FILENAME "8cbd725746-private.pem.key" ///< Device private key filename 33 | // ================================================= 34 | 35 | //set to use Wifi or GPRS 36 | #define WIFI_USED true //true (Wifi) or false (GPRS) 37 | 38 | /* change Wifi settings here */ 39 | #define WIFI_AP "Home-WIFI" 40 | #define WIFI_PASSWORD "06191026" 41 | #define WIFI_AUTH LWIFI_WPA // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP 42 | 43 | /* change GPRS settings here */ 44 | #define GPRS_APN "wap.cingular" //for AT&T 45 | #define GPRS_USERNAME "wap@cingulargprs.com" 46 | #define GPRS_PASSWORD "cingular1" 47 | 48 | #endif /* SRC_SHADOW_IOT_SHADOW_CONFIG_H_ */ 49 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "LinkIt One AWS mqtt library", 3 | "frameworks": "Arduino", 4 | "description": "AWS mqtt library based on mbedTLS especially for LinkIt One", 5 | "url": "https://github.com/ericwahahaha/aws_mbedtls_mqtt", 6 | "authors": 7 | [ 8 | { 9 | "name": "ericwahahaha" 10 | } 11 | ], 12 | "repository": 13 | { 14 | "type": "git", 15 | "url": "https://github.com/ericwahahaha/aws_mbedtls_mqtt" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=LinkIt One AWS mqtt library 2 | version=0.1.0 3 | author=Ericwahahaha 4 | maintainer=Ericwahahaha 5 | sentence=AWS mqtt library based on mbedTLS especially for LinkIt One 6 | paragraph=AWS mqtt C library port of LinkIt One. This library can let you using AWS IoT on LinkIt One 7 | category=Communication 8 | url=https://github.com/ericwahahaha/aws_mbedtls_mqtt 9 | architectures=* 10 | -------------------------------------------------------------------------------- /src/aws_iot_lib/MQTTClient.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Allan Stockdill-Mander/Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #ifndef __MQTT_CLIENT_C_ 18 | #define __MQTT_CLIENT_C_ 19 | 20 | #include "MQTTPacket.h" 21 | #include "stdio.h" 22 | #include "aws_iot_config.h" 23 | 24 | //Platform specific implementation header file 25 | #include "network_interface.h" 26 | #include "timer_interface.h" 27 | 28 | #define MAX_PACKET_ID 65535 29 | #define MAX_MESSAGE_HANDLERS AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 30 | 31 | enum QoS { QOS0, QOS1, QOS2 }; 32 | 33 | // all failure return codes must be negative 34 | enum returnCode { BUFFER_OVERFLOW = -2, FAILURE = -1, SUCCESS = 0 }; 35 | 36 | void NewTimer(Timer*); 37 | 38 | typedef struct MQTTMessage MQTTMessage; 39 | 40 | typedef struct MessageData MessageData; 41 | 42 | typedef void (*messageHandler)(MessageData*); 43 | typedef void (*pApplicationHandler_t)(void); 44 | typedef void (*disconnectHander_t)(void); 45 | 46 | struct MQTTMessage 47 | { 48 | enum QoS qos; 49 | char retained; 50 | char dup; 51 | unsigned short id; 52 | void *payload; 53 | size_t payloadlen; 54 | }; 55 | 56 | struct MessageData 57 | { 58 | MQTTMessage* message; 59 | MQTTString* topicName; 60 | pApplicationHandler_t applicationHandler; 61 | }; 62 | 63 | typedef struct Client Client; 64 | 65 | int MQTTConnect (Client*, MQTTPacket_connectData*); 66 | int MQTTPublish (Client*, const char*, MQTTMessage*); 67 | //int MQTTSubscribe(Client* c, const char* topicFilter, enum QoS qos, messageHandler messageHandler, pApplicationHandler_t applicationHandler); 68 | int MQTTSubscribe(Client* c, const char* topicFilter, int qos, messageHandler messageHandler, pApplicationHandler_t applicationHandler); 69 | int MQTTUnsubscribe (Client*, const char*); 70 | int MQTTDisconnect (Client*); 71 | int MQTTYield (Client*, int); 72 | 73 | void setDefaultMessageHandler(Client*, messageHandler); 74 | void setDisconnectHandler(Client*, disconnectHander_t disconnectHandler); 75 | 76 | void MQTTClient(Client*, Network*, unsigned int, unsigned char*, size_t, unsigned char*, size_t); 77 | 78 | struct Client { 79 | unsigned int next_packetid; 80 | unsigned int command_timeout_ms; 81 | size_t buf_size, readbuf_size; 82 | unsigned char *buf; 83 | unsigned char *readbuf; 84 | unsigned int keepAliveInterval; 85 | char ping_outstanding; 86 | int isconnected; 87 | 88 | struct MessageHandlers 89 | { 90 | const char* topicFilter; 91 | void (*fp) (MessageData*); 92 | pApplicationHandler_t applicationHandler; 93 | } messageHandlers[MAX_MESSAGE_HANDLERS]; // Message handlers are indexed by subscription topic 94 | 95 | void (*defaultMessageHandler) (MessageData*); 96 | disconnectHander_t disconnectHandler; 97 | 98 | Network* ipstack; 99 | Timer ping_timer; 100 | }; 101 | 102 | #define DefaultClient {0, 0, 0, 0, NULL, NULL, 0, 0, 0} 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /src/aws_iot_lib/MQTTConnect.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | * Xiang Rong - 442039 Add makefile to Embedded C client 16 | *******************************************************************************/ 17 | 18 | #ifndef MQTTCONNECT_H_ 19 | #define MQTTCONNECT_H_ 20 | 21 | #if !defined(DLLImport) 22 | #define DLLImport 23 | #endif 24 | #if !defined(DLLExport) 25 | #define DLLExport 26 | #endif 27 | 28 | 29 | typedef union 30 | { 31 | unsigned char all; /**< all connect flags */ 32 | #if defined(REVERSED) 33 | struct 34 | { 35 | unsigned int username : 1; /**< 3.1 user name */ 36 | unsigned int password : 1; /**< 3.1 password */ 37 | unsigned int willRetain : 1; /**< will retain setting */ 38 | unsigned int willQoS : 2; /**< will QoS value */ 39 | unsigned int will : 1; /**< will flag */ 40 | unsigned int cleansession : 1; /**< clean session flag */ 41 | unsigned int : 1; /**< unused */ 42 | } bits; 43 | #else 44 | struct 45 | { 46 | unsigned int : 1; /**< unused */ 47 | unsigned int cleansession : 1; /**< cleansession flag */ 48 | unsigned int will : 1; /**< will flag */ 49 | unsigned int willQoS : 2; /**< will QoS value */ 50 | unsigned int willRetain : 1; /**< will retain setting */ 51 | unsigned int password : 1; /**< 3.1 password */ 52 | unsigned int username : 1; /**< 3.1 user name */ 53 | } bits; 54 | #endif 55 | } MQTTConnectFlags; /**< connect flags byte */ 56 | 57 | 58 | 59 | /** 60 | * Defines the MQTT "Last Will and Testament" (LWT) settings for 61 | * the connect packet. 62 | */ 63 | typedef struct 64 | { 65 | /** The eyecatcher for this structure. must be MQTW. */ 66 | char struct_id[4]; 67 | /** The version number of this structure. Must be 0 */ 68 | int struct_version; 69 | /** The LWT topic to which the LWT message will be published. */ 70 | MQTTString topicName; 71 | /** The LWT payload. */ 72 | MQTTString message; 73 | /** 74 | * The retained flag for the LWT message (see MQTTAsync_message.retained). 75 | */ 76 | unsigned char retained; 77 | /** 78 | * The quality of service setting for the LWT message (see 79 | * MQTTAsync_message.qos and @ref qos). 80 | */ 81 | char qos; 82 | } MQTTPacket_willOptions; 83 | 84 | 85 | #define MQTTPacket_willOptions_initializer { {'M', 'Q', 'T', 'W'}, 0, {NULL, {0, NULL}}, {NULL, {0, NULL}}, 0, 0 } 86 | 87 | 88 | typedef struct 89 | { 90 | /** The eyecatcher for this structure. must be MQTC. */ 91 | char struct_id[4]; 92 | /** The version number of this structure. Must be 0 */ 93 | int struct_version; 94 | /** Version of MQTT to be used. 3 = 3.1 4 = 3.1.1 95 | */ 96 | unsigned char MQTTVersion; 97 | MQTTString clientID; 98 | unsigned short keepAliveInterval; 99 | unsigned char cleansession; 100 | unsigned char willFlag; 101 | MQTTPacket_willOptions will; 102 | MQTTString username; 103 | MQTTString password; 104 | } MQTTPacket_connectData; 105 | 106 | typedef union 107 | { 108 | unsigned char all; /**< all connack flags */ 109 | #if defined(REVERSED) 110 | struct 111 | { 112 | unsigned int sessionpresent : 1; /**< session present flag */ 113 | unsigned int : 7; /**< unused */ 114 | } bits; 115 | #else 116 | struct 117 | { 118 | unsigned int : 7; /**< unused */ 119 | unsigned int sessionpresent : 1; /**< session present flag */ 120 | } bits; 121 | #endif 122 | } MQTTConnackFlags; /**< connack flags byte */ 123 | 124 | #define MQTTPacket_connectData_initializer { {'M', 'Q', 'T', 'C'}, 0, 4, {NULL, {0, NULL}}, 60, 1, 0, \ 125 | MQTTPacket_willOptions_initializer, {NULL, {0, NULL}}, {NULL, {0, NULL}} } 126 | 127 | DLLExport int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData* options); 128 | DLLExport int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, int len); 129 | 130 | DLLExport int MQTTSerialize_connack(unsigned char* buf, int buflen, unsigned char connack_rc, unsigned char sessionPresent); 131 | DLLExport int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connack_rc, unsigned char* buf, int buflen); 132 | 133 | DLLExport int MQTTSerialize_disconnect(unsigned char* buf, int buflen); 134 | DLLExport int MQTTSerialize_pingreq(unsigned char* buf, int buflen); 135 | 136 | #endif /* MQTTCONNECT_H_ */ 137 | -------------------------------------------------------------------------------- /src/aws_iot_lib/MQTTDeserializePublish.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #include "mbedtls/StackTrace.h" 18 | #include "MQTTPacket.h" 19 | #include 20 | 21 | #define min(a, b) ((a < b) ? 1 : 0) 22 | 23 | /** 24 | * Deserializes the supplied (wire) buffer into publish data 25 | * @param dup returned integer - the MQTT dup flag 26 | * @param qos returned integer - the MQTT QoS value 27 | * @param retained returned integer - the MQTT retained flag 28 | * @param packetid returned integer - the MQTT packet identifier 29 | * @param topicName returned MQTTString - the MQTT topic in the publish 30 | * @param payload returned byte buffer - the MQTT publish payload 31 | * @param payloadlen returned integer - the length of the MQTT payload 32 | * @param buf the raw buffer data, of the correct length determined by the remaining length field 33 | * @param buflen the length in bytes of the data in the supplied buffer 34 | * @return error code. 1 is success 35 | */ 36 | int MQTTDeserialize_publish(unsigned char* dup, int* qos, unsigned char* retained, unsigned short* packetid, MQTTString* topicName, 37 | unsigned char** payload, int* payloadlen, unsigned char* buf, int buflen) 38 | { 39 | MQTTHeader header = {0}; 40 | unsigned char* curdata = buf; 41 | unsigned char* enddata = NULL; 42 | int rc = 0; 43 | int mylen = 0; 44 | 45 | FUNC_ENTRY; 46 | header.byte = readChar(&curdata); 47 | if (header.bits.type != PUBLISH) 48 | goto exit; 49 | *dup = header.bits.dup; 50 | *qos = header.bits.qos; 51 | *retained = header.bits.retain; 52 | 53 | curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */ 54 | enddata = curdata + mylen; 55 | 56 | if (!readMQTTLenString(topicName, &curdata, enddata) || 57 | enddata - curdata < 0) /* do we have enough data to read the protocol version byte? */ 58 | goto exit; 59 | 60 | if (*qos > 0) 61 | *packetid = readInt(&curdata); 62 | 63 | *payloadlen = enddata - curdata; 64 | *payload = curdata; 65 | rc = 1; 66 | exit: 67 | FUNC_EXIT_RC(rc); 68 | return rc; 69 | } 70 | 71 | 72 | 73 | /** 74 | * Deserializes the supplied (wire) buffer into an ack 75 | * @param packettype returned integer - the MQTT packet type 76 | * @param dup returned integer - the MQTT dup flag 77 | * @param packetid returned integer - the MQTT packet identifier 78 | * @param buf the raw buffer data, of the correct length determined by the remaining length field 79 | * @param buflen the length in bytes of the data in the supplied buffer 80 | * @return error code. 1 is success, 0 is failure 81 | */ 82 | int MQTTDeserialize_ack(unsigned char* packettype, unsigned char* dup, unsigned short* packetid, unsigned char* buf, int buflen) 83 | { 84 | MQTTHeader header = {0}; 85 | unsigned char* curdata = buf; 86 | unsigned char* enddata = NULL; 87 | int rc = 0; 88 | int mylen; 89 | 90 | FUNC_ENTRY; 91 | header.byte = readChar(&curdata); 92 | *dup = header.bits.dup; 93 | *packettype = header.bits.type; 94 | 95 | curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */ 96 | enddata = curdata + mylen; 97 | 98 | if (enddata - curdata < 2) 99 | goto exit; 100 | *packetid = readInt(&curdata); 101 | 102 | rc = 1; 103 | exit: 104 | FUNC_EXIT_RC(rc); 105 | return rc; 106 | } 107 | 108 | -------------------------------------------------------------------------------- /src/aws_iot_lib/MQTTFormat.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #if !defined(MQTTFORMAT_H) 18 | #define MQTTFORMAT_H 19 | 20 | #include "mbedtls/StackTrace.h" 21 | #include "MQTTPacket.h" 22 | 23 | const char* MQTTPacket_getName(unsigned short packetid); 24 | int MQTTStringFormat_connect(char* strbuf, int strbuflen, MQTTPacket_connectData* data); 25 | int MQTTStringFormat_connack(char* strbuf, int strbuflen, unsigned char connack_rc, unsigned char sessionPresent); 26 | int MQTTStringFormat_publish(char* strbuf, int strbuflen, unsigned char dup, int qos, unsigned char retained, 27 | unsigned short packetid, MQTTString topicName, unsigned char* payload, int payloadlen); 28 | int MQTTStringFormat_ack(char* strbuf, int strbuflen, unsigned char packettype, unsigned char dup, unsigned short packetid); 29 | int MQTTStringFormat_subscribe(char* strbuf, int strbuflen, unsigned char dup, unsigned short packetid, int count, 30 | MQTTString topicFilters[], int requestedQoSs[]); 31 | int MQTTStringFormat_suback(char* strbuf, int strbuflen, unsigned short packetid, int count, int* grantedQoSs); 32 | int MQTTStringFormat_unsubscribe(char* strbuf, int strbuflen, unsigned char dup, unsigned short packetid, 33 | int count, MQTTString topicFilters[]); 34 | char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf, int buflen); 35 | char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf, int buflen); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/aws_iot_lib/MQTTPacket.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | * Xiang Rong - 442039 Add makefile to Embedded C client 16 | *******************************************************************************/ 17 | 18 | #ifndef MQTTPACKET_H_ 19 | #define MQTTPACKET_H_ 20 | 21 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 22 | extern "C" { 23 | #endif 24 | 25 | #if defined(WIN32_DLL) || defined(WIN64_DLL) 26 | #define DLLImport __declspec(dllimport) 27 | #define DLLExport __declspec(dllexport) 28 | #elif defined(LINUX_SO) 29 | #define DLLImport extern 30 | #define DLLExport __attribute__ ((visibility ("default"))) 31 | #else 32 | #define DLLImport 33 | #define DLLExport 34 | #endif 35 | 36 | enum errors 37 | { 38 | MQTTPACKET_BUFFER_TOO_SHORT = -2, 39 | MQTTPACKET_READ_ERROR = -1, 40 | MQTTPACKET_READ_COMPLETE 41 | }; 42 | 43 | enum msgTypes 44 | { 45 | CONNECT = 1, CONNACK, PUBLISH, PUBACK, PUBREC, PUBREL, 46 | PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK, 47 | PINGREQ, PINGRESP, DISCONNECT 48 | }; 49 | 50 | /** 51 | * Bitfields for the MQTT header byte. 52 | */ 53 | typedef union 54 | { 55 | unsigned char byte; /**< the whole byte */ 56 | #if defined(REVERSED) 57 | struct 58 | { 59 | unsigned int type : 4; /**< message type nibble */ 60 | unsigned int dup : 1; /**< DUP flag bit */ 61 | unsigned int qos : 2; /**< QoS value, 0, 1 or 2 */ 62 | unsigned int retain : 1; /**< retained flag bit */ 63 | } bits; 64 | #else 65 | struct 66 | { 67 | unsigned int retain : 1; /**< retained flag bit */ 68 | unsigned int qos : 2; /**< QoS value, 0, 1 or 2 */ 69 | unsigned int dup : 1; /**< DUP flag bit */ 70 | unsigned int type : 4; /**< message type nibble */ 71 | } bits; 72 | #endif 73 | } MQTTHeader; 74 | 75 | typedef struct 76 | { 77 | int len; 78 | char* data; 79 | } MQTTLenString; 80 | 81 | typedef struct 82 | { 83 | char* cstring; 84 | MQTTLenString lenstring; 85 | } MQTTString; 86 | 87 | #define MQTTString_initializer {NULL, {0, NULL}} 88 | 89 | int MQTTstrlen(MQTTString mqttstring); 90 | 91 | #include "MQTTConnect.h" 92 | #include "MQTTPublish.h" 93 | #include "MQTTSubscribe.h" 94 | #include "MQTTUnsubscribe.h" 95 | #include "MQTTFormat.h" 96 | 97 | int MQTTSerialize_ack(unsigned char* buf, int buflen, unsigned char type, unsigned char dup, unsigned short packetid); 98 | int MQTTDeserialize_ack(unsigned char* packettype, unsigned char* dup, unsigned short* packetid, unsigned char* buf, int buflen); 99 | 100 | int MQTTPacket_len(int rem_len); 101 | int MQTTPacket_equals(MQTTString* a, char* b); 102 | 103 | int MQTTPacket_encode(unsigned char* buf, int length); 104 | int MQTTPacket_decode(int (*getcharfn)(unsigned char*, int), int* value); 105 | int MQTTPacket_decodeBuf(unsigned char* buf, int* value); 106 | 107 | int readInt(unsigned char** pptr); 108 | char readChar(unsigned char** pptr); 109 | void writeChar(unsigned char** pptr, char c); 110 | void writeInt(unsigned char** pptr, int anInt); 111 | int readMQTTLenString(MQTTString* mqttstring, unsigned char** pptr, unsigned char* enddata); 112 | void writeCString(unsigned char** pptr, const char* string); 113 | void writeMQTTString(unsigned char** pptr, MQTTString mqttstring); 114 | 115 | DLLExport int MQTTPacket_read(unsigned char* buf, int buflen, int (*getfn)(unsigned char*, int)); 116 | 117 | typedef struct { 118 | int (*getfn)(void *, unsigned char*, int); /* must return -1 for error, 0 for call again, or the number of bytes read */ 119 | void *sck; /* pointer to whatever the system may use to identify the transport */ 120 | int multiplier; 121 | int rem_len; 122 | int len; 123 | char state; 124 | }MQTTTransport; 125 | 126 | int MQTTPacket_readnb(unsigned char* buf, int buflen, MQTTTransport *trp); 127 | 128 | #ifdef __cplusplus /* If this is a C++ compiler, use C linkage */ 129 | } 130 | #endif 131 | 132 | 133 | #endif /* MQTTPACKET_H_ */ 134 | -------------------------------------------------------------------------------- /src/aws_iot_lib/MQTTPublish.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | * Xiang Rong - 442039 Add makefile to Embedded C client 16 | *******************************************************************************/ 17 | 18 | #ifndef MQTTPUBLISH_H_ 19 | #define MQTTPUBLISH_H_ 20 | 21 | #if !defined(DLLImport) 22 | #define DLLImport 23 | #endif 24 | #if !defined(DLLExport) 25 | #define DLLExport 26 | #endif 27 | 28 | DLLExport int MQTTSerialize_publish(unsigned char* buf, int buflen, unsigned char dup, int qos, unsigned char retained, unsigned short packetid, 29 | MQTTString topicName, unsigned char* payload, int payloadlen); 30 | 31 | DLLExport int MQTTDeserialize_publish(unsigned char* dup, int* qos, unsigned char* retained, unsigned short* packetid, MQTTString* topicName, 32 | unsigned char** payload, int* payloadlen, unsigned char* buf, int len); 33 | 34 | DLLExport int MQTTSerialize_puback(unsigned char* buf, int buflen, unsigned short packetid); 35 | DLLExport int MQTTSerialize_pubrel(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid); 36 | DLLExport int MQTTSerialize_pubcomp(unsigned char* buf, int buflen, unsigned short packetid); 37 | 38 | #endif /* MQTTPUBLISH_H_ */ 39 | -------------------------------------------------------------------------------- /src/aws_iot_lib/MQTTSubscribe.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | * Xiang Rong - 442039 Add makefile to Embedded C client 16 | *******************************************************************************/ 17 | 18 | #ifndef MQTTSUBSCRIBE_H_ 19 | #define MQTTSUBSCRIBE_H_ 20 | 21 | #if !defined(DLLImport) 22 | #define DLLImport 23 | #endif 24 | #if !defined(DLLExport) 25 | #define DLLExport 26 | #endif 27 | 28 | DLLExport int MQTTSerialize_subscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid, 29 | int count, MQTTString topicFilters[], int requestedQoSs[]); 30 | 31 | DLLExport int MQTTDeserialize_subscribe(unsigned char* dup, unsigned short* packetid, 32 | int maxcount, int* count, MQTTString topicFilters[], int requestedQoSs[], unsigned char* buf, int len); 33 | 34 | DLLExport int MQTTSerialize_suback(unsigned char* buf, int buflen, unsigned short packetid, int count, int* grantedQoSs); 35 | 36 | DLLExport int MQTTDeserialize_suback(unsigned short* packetid, int maxcount, int* count, int grantedQoSs[], unsigned char* buf, int len); 37 | 38 | 39 | #endif /* MQTTSUBSCRIBE_H_ */ 40 | -------------------------------------------------------------------------------- /src/aws_iot_lib/MQTTSubscribeClient.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #include "MQTTPacket.h" 18 | #include "mbedtls/StackTrace.h" 19 | 20 | #include 21 | 22 | /** 23 | * Determines the length of the MQTT subscribe packet that would be produced using the supplied parameters 24 | * @param count the number of topic filter strings in topicFilters 25 | * @param topicFilters the array of topic filter strings to be used in the publish 26 | * @return the length of buffer needed to contain the serialized version of the packet 27 | */ 28 | int MQTTSerialize_subscribeLength(int count, MQTTString topicFilters[]) 29 | { 30 | int i; 31 | int len = 2; /* packetid */ 32 | 33 | for (i = 0; i < count; ++i) 34 | len += 2 + MQTTstrlen(topicFilters[i]) + 1; /* length + topic + req_qos */ 35 | return len; 36 | } 37 | 38 | 39 | /** 40 | * Serializes the supplied subscribe data into the supplied buffer, ready for sending 41 | * @param buf the buffer into which the packet will be serialized 42 | * @param buflen the length in bytes of the supplied bufferr 43 | * @param dup integer - the MQTT dup flag 44 | * @param packetid integer - the MQTT packet identifier 45 | * @param count - number of members in the topicFilters and reqQos arrays 46 | * @param topicFilters - array of topic filter names 47 | * @param requestedQoSs - array of requested QoS 48 | * @return the length of the serialized data. <= 0 indicates error 49 | */ 50 | int MQTTSerialize_subscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid, int count, 51 | MQTTString topicFilters[], int requestedQoSs[]) 52 | { 53 | unsigned char *ptr = buf; 54 | MQTTHeader header = {0}; 55 | int rem_len = 0; 56 | int rc = 0; 57 | int i = 0; 58 | 59 | FUNC_ENTRY; 60 | if (MQTTPacket_len(rem_len = MQTTSerialize_subscribeLength(count, topicFilters)) > buflen) 61 | { 62 | rc = MQTTPACKET_BUFFER_TOO_SHORT; 63 | goto exit; 64 | } 65 | 66 | header.byte = 0; 67 | header.bits.type = SUBSCRIBE; 68 | header.bits.dup = dup; 69 | header.bits.qos = 1; 70 | writeChar(&ptr, header.byte); /* write header */ 71 | 72 | ptr += MQTTPacket_encode(ptr, rem_len); /* write remaining length */; 73 | 74 | writeInt(&ptr, packetid); 75 | 76 | for (i = 0; i < count; ++i) 77 | { 78 | writeMQTTString(&ptr, topicFilters[i]); 79 | writeChar(&ptr, requestedQoSs[i]); 80 | } 81 | 82 | rc = ptr - buf; 83 | exit: 84 | FUNC_EXIT_RC(rc); 85 | return rc; 86 | } 87 | 88 | 89 | 90 | /** 91 | * Deserializes the supplied (wire) buffer into suback data 92 | * @param packetid returned integer - the MQTT packet identifier 93 | * @param maxcount - the maximum number of members allowed in the grantedQoSs array 94 | * @param count returned integer - number of members in the grantedQoSs array 95 | * @param grantedQoSs returned array of integers - the granted qualities of service 96 | * @param buf the raw buffer data, of the correct length determined by the remaining length field 97 | * @param buflen the length in bytes of the data in the supplied buffer 98 | * @return error code. 1 is success, 0 is failure 99 | */ 100 | int MQTTDeserialize_suback(unsigned short* packetid, int maxcount, int* count, int grantedQoSs[], unsigned char* buf, int buflen) 101 | { 102 | MQTTHeader header = {0}; 103 | unsigned char* curdata = buf; 104 | unsigned char* enddata = NULL; 105 | int rc = 0; 106 | int mylen; 107 | 108 | FUNC_ENTRY; 109 | header.byte = readChar(&curdata); 110 | if (header.bits.type != SUBACK) 111 | goto exit; 112 | 113 | curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */ 114 | enddata = curdata + mylen; 115 | if (enddata - curdata < 2) 116 | goto exit; 117 | 118 | *packetid = readInt(&curdata); 119 | 120 | *count = 0; 121 | while (curdata < enddata) 122 | { 123 | if (*count > maxcount) 124 | { 125 | rc = -1; 126 | goto exit; 127 | } 128 | grantedQoSs[(*count)++] = readChar(&curdata); 129 | } 130 | 131 | rc = 1; 132 | exit: 133 | FUNC_EXIT_RC(rc); 134 | return rc; 135 | } 136 | 137 | 138 | -------------------------------------------------------------------------------- /src/aws_iot_lib/MQTTSubscribeServer.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #include "MQTTPacket.h" 18 | #include "mbedtls/StackTrace.h" 19 | 20 | #include 21 | 22 | 23 | /** 24 | * Deserializes the supplied (wire) buffer into subscribe data 25 | * @param dup integer returned - the MQTT dup flag 26 | * @param packetid integer returned - the MQTT packet identifier 27 | * @param maxcount - the maximum number of members allowed in the topicFilters and requestedQoSs arrays 28 | * @param count - number of members in the topicFilters and requestedQoSs arrays 29 | * @param topicFilters - array of topic filter names 30 | * @param requestedQoSs - array of requested QoS 31 | * @param buf the raw buffer data, of the correct length determined by the remaining length field 32 | * @param buflen the length in bytes of the data in the supplied buffer 33 | * @return the length of the serialized data. <= 0 indicates error 34 | */ 35 | int MQTTDeserialize_subscribe(unsigned char* dup, unsigned short* packetid, int maxcount, int* count, MQTTString topicFilters[], 36 | int requestedQoSs[], unsigned char* buf, int buflen) 37 | { 38 | MQTTHeader header = {0}; 39 | unsigned char* curdata = buf; 40 | unsigned char* enddata = NULL; 41 | int rc = -1; 42 | int mylen = 0; 43 | 44 | FUNC_ENTRY; 45 | header.byte = readChar(&curdata); 46 | if (header.bits.type != SUBSCRIBE) 47 | goto exit; 48 | *dup = header.bits.dup; 49 | 50 | curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */ 51 | enddata = curdata + mylen; 52 | 53 | *packetid = readInt(&curdata); 54 | 55 | *count = 0; 56 | while (curdata < enddata) 57 | { 58 | if (!readMQTTLenString(&topicFilters[*count], &curdata, enddata)) 59 | goto exit; 60 | if (curdata >= enddata) /* do we have enough data to read the req_qos version byte? */ 61 | goto exit; 62 | requestedQoSs[*count] = readChar(&curdata); 63 | (*count)++; 64 | } 65 | 66 | rc = 1; 67 | exit: 68 | FUNC_EXIT_RC(rc); 69 | return rc; 70 | } 71 | 72 | 73 | /** 74 | * Serializes the supplied suback data into the supplied buffer, ready for sending 75 | * @param buf the buffer into which the packet will be serialized 76 | * @param buflen the length in bytes of the supplied buffer 77 | * @param packetid integer - the MQTT packet identifier 78 | * @param count - number of members in the grantedQoSs array 79 | * @param grantedQoSs - array of granted QoS 80 | * @return the length of the serialized data. <= 0 indicates error 81 | */ 82 | int MQTTSerialize_suback(unsigned char* buf, int buflen, unsigned short packetid, int count, int* grantedQoSs) 83 | { 84 | MQTTHeader header = {0}; 85 | int rc = -1; 86 | unsigned char *ptr = buf; 87 | int i; 88 | 89 | FUNC_ENTRY; 90 | if (buflen < 2 + count) 91 | { 92 | rc = MQTTPACKET_BUFFER_TOO_SHORT; 93 | goto exit; 94 | } 95 | header.byte = 0; 96 | header.bits.type = SUBACK; 97 | writeChar(&ptr, header.byte); /* write header */ 98 | 99 | ptr += MQTTPacket_encode(ptr, 2 + count); /* write remaining length */ 100 | 101 | writeInt(&ptr, packetid); 102 | 103 | for (i = 0; i < count; ++i) 104 | writeChar(&ptr, grantedQoSs[i]); 105 | 106 | rc = ptr - buf; 107 | exit: 108 | FUNC_EXIT_RC(rc); 109 | return rc; 110 | } 111 | 112 | 113 | -------------------------------------------------------------------------------- /src/aws_iot_lib/MQTTUnsubscribe.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | * Xiang Rong - 442039 Add makefile to Embedded C client 16 | *******************************************************************************/ 17 | 18 | #ifndef MQTTUNSUBSCRIBE_H_ 19 | #define MQTTUNSUBSCRIBE_H_ 20 | 21 | #if !defined(DLLImport) 22 | #define DLLImport 23 | #endif 24 | #if !defined(DLLExport) 25 | #define DLLExport 26 | #endif 27 | 28 | DLLExport int MQTTSerialize_unsubscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid, 29 | int count, MQTTString topicFilters[]); 30 | 31 | DLLExport int MQTTDeserialize_unsubscribe(unsigned char* dup, unsigned short* packetid, int max_count, int* count, MQTTString topicFilters[], 32 | unsigned char* buf, int len); 33 | 34 | DLLExport int MQTTSerialize_unsuback(unsigned char* buf, int buflen, unsigned short packetid); 35 | 36 | DLLExport int MQTTDeserialize_unsuback(unsigned short* packetid, unsigned char* buf, int len); 37 | 38 | #endif /* MQTTUNSUBSCRIBE_H_ */ 39 | -------------------------------------------------------------------------------- /src/aws_iot_lib/MQTTUnsubscribeClient.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #include "MQTTPacket.h" 18 | #include "mbedtls/StackTrace.h" 19 | 20 | #include 21 | 22 | /** 23 | * Determines the length of the MQTT unsubscribe packet that would be produced using the supplied parameters 24 | * @param count the number of topic filter strings in topicFilters 25 | * @param topicFilters the array of topic filter strings to be used in the publish 26 | * @return the length of buffer needed to contain the serialized version of the packet 27 | */ 28 | int MQTTSerialize_unsubscribeLength(int count, MQTTString topicFilters[]) 29 | { 30 | int i; 31 | int len = 2; /* packetid */ 32 | 33 | for (i = 0; i < count; ++i) 34 | len += 2 + MQTTstrlen(topicFilters[i]); /* length + topic*/ 35 | return len; 36 | } 37 | 38 | 39 | /** 40 | * Serializes the supplied unsubscribe data into the supplied buffer, ready for sending 41 | * @param buf the raw buffer data, of the correct length determined by the remaining length field 42 | * @param buflen the length in bytes of the data in the supplied buffer 43 | * @param dup integer - the MQTT dup flag 44 | * @param packetid integer - the MQTT packet identifier 45 | * @param count - number of members in the topicFilters array 46 | * @param topicFilters - array of topic filter names 47 | * @return the length of the serialized data. <= 0 indicates error 48 | */ 49 | int MQTTSerialize_unsubscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid, 50 | int count, MQTTString topicFilters[]) 51 | { 52 | unsigned char *ptr = buf; 53 | MQTTHeader header = {0}; 54 | int rem_len = 0; 55 | int rc = -1; 56 | int i = 0; 57 | 58 | FUNC_ENTRY; 59 | if (MQTTPacket_len(rem_len = MQTTSerialize_unsubscribeLength(count, topicFilters)) > buflen) 60 | { 61 | rc = MQTTPACKET_BUFFER_TOO_SHORT; 62 | goto exit; 63 | } 64 | 65 | header.byte = 0; 66 | header.bits.type = UNSUBSCRIBE; 67 | header.bits.dup = dup; 68 | header.bits.qos = 1; 69 | writeChar(&ptr, header.byte); /* write header */ 70 | 71 | ptr += MQTTPacket_encode(ptr, rem_len); /* write remaining length */; 72 | 73 | writeInt(&ptr, packetid); 74 | 75 | for (i = 0; i < count; ++i) 76 | writeMQTTString(&ptr, topicFilters[i]); 77 | 78 | rc = ptr - buf; 79 | exit: 80 | FUNC_EXIT_RC(rc); 81 | return rc; 82 | } 83 | 84 | 85 | /** 86 | * Deserializes the supplied (wire) buffer into unsuback data 87 | * @param packetid returned integer - the MQTT packet identifier 88 | * @param buf the raw buffer data, of the correct length determined by the remaining length field 89 | * @param buflen the length in bytes of the data in the supplied buffer 90 | * @return error code. 1 is success, 0 is failure 91 | */ 92 | int MQTTDeserialize_unsuback(unsigned short* packetid, unsigned char* buf, int buflen) 93 | { 94 | unsigned char type = 0; 95 | unsigned char dup = 0; 96 | int rc = 0; 97 | 98 | FUNC_ENTRY; 99 | rc = MQTTDeserialize_ack(&type, &dup, packetid, buf, buflen); 100 | if (type == UNSUBACK) 101 | rc = 1; 102 | FUNC_EXIT_RC(rc); 103 | return rc; 104 | } 105 | 106 | 107 | -------------------------------------------------------------------------------- /src/aws_iot_lib/MQTTUnsubscribeServer.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #include "MQTTPacket.h" 18 | #include "mbedtls/StackTrace.h" 19 | 20 | #include 21 | 22 | 23 | /** 24 | * Deserializes the supplied (wire) buffer into unsubscribe data 25 | * @param dup integer returned - the MQTT dup flag 26 | * @param packetid integer returned - the MQTT packet identifier 27 | * @param maxcount - the maximum number of members allowed in the topicFilters and requestedQoSs arrays 28 | * @param count - number of members in the topicFilters and requestedQoSs arrays 29 | * @param topicFilters - array of topic filter names 30 | * @param buf the raw buffer data, of the correct length determined by the remaining length field 31 | * @param buflen the length in bytes of the data in the supplied buffer 32 | * @return the length of the serialized data. <= 0 indicates error 33 | */ 34 | int MQTTDeserialize_unsubscribe(unsigned char* dup, unsigned short* packetid, int maxcount, int* count, MQTTString topicFilters[], 35 | unsigned char* buf, int len) 36 | { 37 | MQTTHeader header = {0}; 38 | unsigned char* curdata = buf; 39 | unsigned char* enddata = NULL; 40 | int rc = 0; 41 | int mylen = 0; 42 | 43 | FUNC_ENTRY; 44 | header.byte = readChar(&curdata); 45 | if (header.bits.type != UNSUBSCRIBE) 46 | goto exit; 47 | *dup = header.bits.dup; 48 | 49 | curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */ 50 | enddata = curdata + mylen; 51 | 52 | *packetid = readInt(&curdata); 53 | 54 | *count = 0; 55 | while (curdata < enddata) 56 | { 57 | if (!readMQTTLenString(&topicFilters[*count], &curdata, enddata)) 58 | goto exit; 59 | (*count)++; 60 | } 61 | 62 | rc = 1; 63 | exit: 64 | FUNC_EXIT_RC(rc); 65 | return rc; 66 | } 67 | 68 | 69 | /** 70 | * Serializes the supplied unsuback data into the supplied buffer, ready for sending 71 | * @param buf the buffer into which the packet will be serialized 72 | * @param buflen the length in bytes of the supplied buffer 73 | * @param packetid integer - the MQTT packet identifier 74 | * @return the length of the serialized data. <= 0 indicates error 75 | */ 76 | int MQTTSerialize_unsuback(unsigned char* buf, int buflen, unsigned short packetid) 77 | { 78 | MQTTHeader header = {0}; 79 | int rc = 0; 80 | unsigned char *ptr = buf; 81 | 82 | FUNC_ENTRY; 83 | if (buflen < 2) 84 | { 85 | rc = MQTTPACKET_BUFFER_TOO_SHORT; 86 | goto exit; 87 | } 88 | header.byte = 0; 89 | header.bits.type = UNSUBACK; 90 | writeChar(&ptr, header.byte); /* write header */ 91 | 92 | ptr += MQTTPacket_encode(ptr, 2); /* write remaining length */ 93 | 94 | writeInt(&ptr, packetid); 95 | 96 | rc = ptr - buf; 97 | exit: 98 | FUNC_EXIT_RC(rc); 99 | return rc; 100 | } 101 | 102 | 103 | -------------------------------------------------------------------------------- /src/aws_iot_lib/aws_iot_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_mtk_iot_config.h 18 | * @brief AWS IoT specific configuration file 19 | */ 20 | 21 | #ifndef SRC_SHADOW_IOT_CONFIG_H_ 22 | #define SRC_SHADOW_IOT_CONFIG_H_ 23 | 24 | // Only for default values 25 | #define AWS_IOT_MQTT_HOST "" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow 26 | #define AWS_IOT_MQTT_PORT 8883 ///< default port for MQTT/S 27 | #define AWS_IOT_MQTT_CLIENT_ID "" ///< MQTT client ID should be unique for every device 28 | #define AWS_IOT_MY_THING_NAME "mtk_aws_1" ///< Thing Name of the Shadow this device is associated with 29 | #define AWS_IOT_ROOT_CA_FILENAME "" ///< Root CA file name 30 | #define AWS_IOT_CERTIFICATE_FILENAME "" ///< device signed certificate file name 31 | #define AWS_IOT_PRIVATE_KEY_FILENAME "" ///< Device private key filename 32 | // MQTT PubSub 33 | #define AWS_IOT_MQTT_TX_BUF_LEN 512 ///< Any time a message is sent out through the MQTT layer. The message is copied into this buffer anytime a publish is done. This will also be used in the case of Thing Shadow 34 | #define AWS_IOT_MQTT_RX_BUF_LEN 512 ///< Any message that comes into the device should be less than this buffer size. If a received message is bigger than this buffer size the message will be dropped. 35 | #define AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5 ///< Maximum number of topic filters the MQTT client can handle at any given time. This should be increased appropriately when using Thing Shadow 36 | 37 | // Thing Shadow specific configs 38 | #define SHADOW_MAX_SIZE_OF_RX_BUFFER AWS_IOT_MQTT_RX_BUF_LEN+1 ///< Maximum size of the SHADOW buffer to store the received Shadow message 39 | #define MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES 80 ///< Maximum size of the Unique Client Id. For More info on the Client Id refer \ref response "Acknowledgments" 40 | #define MAX_SIZE_CLIENT_ID_WITH_SEQUENCE MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES + 10 ///< This is size of the extra sequence number that will be appended to the Unique client Id 41 | #define MAX_SIZE_CLIENT_TOKEN_CLIENT_SEQUENCE MAX_SIZE_CLIENT_ID_WITH_SEQUENCE + 20 ///< This is size of the the total clientToken key and value pair in the JSON 42 | #define MAX_ACKS_TO_COMEIN_AT_ANY_GIVEN_TIME 10 ///< At Any given time we will wait for this many responses. This will correlate to the rate at which the shadow actions are requested 43 | #define MAX_THINGNAME_HANDLED_AT_ANY_GIVEN_TIME 10 ///< We could perform shadow action on any thing Name and this is maximum Thing Names we can act on at any given time 44 | #define MAX_JSON_TOKEN_EXPECTED 120 ///< These are the max tokens that is expected to be in the Shadow JSON document. Include the metadata that gets published 45 | #define MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME 60 ///< All shadow actions have to be published or subscribed to a topic which is of the format $aws/things/{thingName}/shadow/update/accepted. This refers to the size of the topic without the Thing Name 46 | #define MAX_SIZE_OF_THING_NAME 20 ///< The Thing Name should not be bigger than this value. Modify this if the Thing Name needs to be bigger 47 | #define MAX_SHADOW_TOPIC_LENGTH_BYTES MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME + MAX_SIZE_OF_THING_NAME ///< This size includes the length of topic with Thing Name 48 | 49 | #endif /* SRC_SHADOW_IOT_CONFIG_H_ */ -------------------------------------------------------------------------------- /src/aws_iot_lib/aws_iot_error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_error.h 18 | * @brief Definition of error types for the SDK. 19 | */ 20 | 21 | #ifndef AWS_IOT_SDK_SRC_IOT_ERROR_H_ 22 | #define AWS_IOT_SDK_SRC_IOT_ERROR_H_ 23 | 24 | 25 | /** 26 | * @brief IoT Error enum 27 | * 28 | * Enumeration of return values from the IoT_* functions within the SDK. 29 | */ 30 | typedef enum { 31 | NONE_ERROR = 0, /** Success return value - no error occurred. */ 32 | GENERIC_ERROR = -1, /** A generic error. A placeholder for a more specific error. */ 33 | NULL_VALUE_ERROR = -2, /** A required parameter was passed as null. */ 34 | CONNECTION_ERROR = -3, /** A connection could not be established. */ 35 | SUBSCRIBE_ERROR = -4, /** The subscribe failed. A SUBACK was not returned from the service. */ 36 | PUBLISH_ERROR = -5, /** The publish failed. In the case of a QoS 1 message a PUBACK was not received. */ 37 | DISCONNECT_ERROR = -6, /** The disconnect failed. The disconnect control packet could not be sent. */ 38 | YIELD_ERROR = -7, /** An error occurred when yielding to the IoT MQTT client. A possible cause is an unexpected TCP socket disconnect. */ 39 | TCP_CONNECT_ERROR = -8, /** The TCP socket could not be established. */ 40 | SSL_CONNECT_ERROR = -9, /** The TLS handshake failed. */ 41 | TCP_SETUP_ERROR =-10, /** ? */ 42 | SSL_CONNECT_TIMEOUT_ERROR = -11, /** A timeout occurred while waiting for the TLS handshake to complete. */ 43 | SSL_WRITE_ERROR = -12, /** A Generic error based on the platform used */ 44 | SSL_INIT_ERROR = -13, /** ? */ 45 | SSL_CERT_ERROR= -14, /** An error occurred when loading the certificates. The certificates could not be located or are incorrectly formatted. */ 46 | UNSUBSCRIBE_ERROR = -15, /** The unsubscribe failed. The unsubscribe control packet could not be sent. */ 47 | JSON_PARSE_ERROR = -16, /** An error occurred while parsing the JSON string. Usually malformed JSON. */ 48 | WAIT_FOR_PUBLISH = -17, /** Shadow: The response Ack table is currently full waiting for previously published updates */ 49 | SSL_WRITE_TIMEOUT_ERROR = -18, /** SSL Write times out */ 50 | SSL_READ_TIMEOUT_ERROR = -19, /** SSL Read times out */ 51 | SSL_READ_ERROR = -20, /** A Generic error based on the platform used */ 52 | SHADOW_JSON_BUFFER_TRUNCATED = -21, /** Any time an snprintf writes more than size value, this error will be returned */ 53 | SHADOW_JSON_ERROR = -22 /** Any time an snprintf encounters an encoding error or not enough space in the given buffer */ 54 | }IoT_Error_t; 55 | 56 | #endif /* AWS_IOT_SDK_SRC_IOT_ERROR_H_ */ 57 | -------------------------------------------------------------------------------- /src/aws_iot_lib/aws_iot_log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_log.h 18 | * @brief Logging macros for the SDK. 19 | * This file defines common logging macros with log levels to be used within the SDK. 20 | * These macros can also be used in the IoT application code as a common way to output 21 | * logs. The log levels can be tuned by modifying the makefile. Removing (commenting 22 | * out) the IOT_* statement in the makefile disables that log level. 23 | * 24 | * It is expected that the macros below will be modified or replaced when porting to 25 | * specific hardware platforms as printf may not be the desired behavior. 26 | */ 27 | 28 | #ifndef _IOT_LOG_H 29 | #define _IOT_LOG_H 30 | 31 | #include 32 | #include 33 | 34 | /** 35 | * @brief Debug level logging macro. 36 | * 37 | * Macro to expose function, line number as well as desired log message. 38 | */ 39 | #ifdef IOT_DEBUG 40 | #define DEBUG(...) \ 41 | {\ 42 | printf("DEBUG: %s L#%d ", __PRETTY_FUNCTION__, __LINE__); \ 43 | printf(__VA_ARGS__); \ 44 | printf("\n"); \ 45 | } 46 | #else 47 | #define DEBUG(...) 48 | #endif 49 | 50 | /** 51 | * @brief Info level logging macro. 52 | * 53 | * Macro to expose desired log message. Info messages do not include automatic function names and line numbers. 54 | */ 55 | #ifdef IOT_INFO 56 | #define INFO(...) \ 57 | {\ 58 | printf(__VA_ARGS__); \ 59 | printf("\n"); \ 60 | } 61 | #else 62 | #define INFO(...) 63 | #endif 64 | 65 | /** 66 | * @brief Warn level logging macro. 67 | * 68 | * Macro to expose function, line number as well as desired log message. 69 | */ 70 | #ifdef IOT_WARN 71 | #define WARN(...) \ 72 | { \ 73 | printf("WARN: %s L#%d ", __PRETTY_FUNCTION__, __LINE__); \ 74 | printf(__VA_ARGS__); \ 75 | printf("\n"); \ 76 | } 77 | #else 78 | #define WARN(...) 79 | #endif 80 | 81 | /** 82 | * @brief Error level logging macro. 83 | * 84 | * Macro to expose function, line number as well as desired log message. 85 | */ 86 | #ifdef IOT_ERROR 87 | #define ERROR(...) \ 88 | { \ 89 | printf("ERROR: %s L#%d ", __PRETTY_FUNCTION__, __LINE__); \ 90 | printf(__VA_ARGS__); \ 91 | printf("\n"); \ 92 | } 93 | #else 94 | #define ERROR(...) 95 | #endif 96 | 97 | #endif // _IOT_LOG_H 98 | -------------------------------------------------------------------------------- /src/aws_iot_lib/aws_iot_shadow_actions.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #include "aws_iot_shadow_actions.h" 17 | 18 | #include "aws_iot_log.h" 19 | #include "aws_iot_shadow_json.h" 20 | #include "aws_iot_shadow_records.h" 21 | #include "aws_iot_config.h" 22 | 23 | IoT_Error_t iot_shadow_action(MQTTClient_t *pClient, const char *pThingName, ShadowActions_t action, 24 | const char *pJsonDocumentToBeSent, fpActionCallback_t callback, void *pCallbackContext, 25 | uint32_t timeout_seconds, bool isSticky) { 26 | 27 | IoT_Error_t ret_val = NONE_ERROR; 28 | bool isCallbackPresent = false; 29 | bool isClientTokenPresent = false; 30 | bool isAckWaitListFree = false; 31 | uint8_t indexAckWaitList; 32 | 33 | if(pClient == NULL || pThingName == NULL || pJsonDocumentToBeSent == NULL){ 34 | return NULL_VALUE_ERROR; 35 | } 36 | 37 | if (getNextFreeIndexOfAckWaitList(&indexAckWaitList)) { 38 | isAckWaitListFree = true; 39 | } 40 | if (callback != NULL) { 41 | isCallbackPresent = true; 42 | } 43 | 44 | char extractedClientToken[MAX_SIZE_CLIENT_TOKEN_CLIENT_SEQUENCE]; 45 | isClientTokenPresent = extractClientToken(pJsonDocumentToBeSent, extractedClientToken); 46 | 47 | if (isClientTokenPresent && isCallbackPresent && isAckWaitListFree) { 48 | if (!isSubscriptionPresent(pThingName, action)) { 49 | ret_val = subscribeToShadowActionAcks(pThingName, action, isSticky); 50 | } else { 51 | incrementSubscriptionCnt(pThingName, action, isSticky); 52 | } 53 | } 54 | 55 | 56 | if (ret_val == NONE_ERROR) { 57 | ret_val = publishToShadowAction(pThingName, action, pJsonDocumentToBeSent); 58 | } 59 | 60 | if (isClientTokenPresent && isCallbackPresent && ret_val == NONE_ERROR && isAckWaitListFree) { 61 | addToAckWaitList(indexAckWaitList, pThingName, action, extractedClientToken, callback, pCallbackContext, 62 | timeout_seconds); 63 | } 64 | return ret_val; 65 | } 66 | -------------------------------------------------------------------------------- /src/aws_iot_lib/aws_iot_shadow_actions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #ifndef SRC_SHADOW_AWS_IOT_SHADOW_ACTIONS_H_ 17 | #define SRC_SHADOW_AWS_IOT_SHADOW_ACTIONS_H_ 18 | 19 | #include "aws_iot_shadow_interface.h" 20 | 21 | IoT_Error_t iot_shadow_action(MQTTClient_t *pClient, const char *pThingName, ShadowActions_t action, 22 | const char *pJsonDocumentToBeSent, fpActionCallback_t callback, void *pCallbackContext, 23 | uint32_t timeout_seconds, bool isSticky); 24 | 25 | #endif /* SRC_SHADOW_AWS_IOT_SHADOW_ACTIONS_H_ */ 26 | -------------------------------------------------------------------------------- /src/aws_iot_lib/aws_iot_shadow_json.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | #ifndef AWS_IOT_SDK_SRC_IOT_SHADOW_JSON_H_ 16 | #define AWS_IOT_SDK_SRC_IOT_SHADOW_JSON_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "aws_iot_error.h" 23 | #include "aws_iot_shadow_json_data.h" 24 | 25 | extern const char* tmp_thing; 26 | 27 | bool isJsonValidAndParse(const char *pJsonDocument, void *pJsonHandler, int32_t *pTokenCount); 28 | bool isJsonKeyMatchingAndUpdateValue(const char *pJsonDocument, void *pJsonHandler, int32_t tokenCount, 29 | jsonStruct_t *pDataStruct, uint32_t *pDataLength, int32_t *pDataPosition); 30 | 31 | void iot_shadow_get_request_json(char *pJsonDocument); 32 | void iot_shadow_delete_request_json(char *pJsonDocument); 33 | void resetClientTokenSequenceNum(void); 34 | 35 | 36 | bool isReceivedJsonValid(const char *pJsonDocument); 37 | void FillWithClientToken(char *pStringToUpdateClientToken); 38 | bool extractClientToken(const char *pJsonDocumentToBeSent, char *pExtractedClientToken); 39 | bool extractVersionNumber(const char *pJsonDocument, void *pJsonHandler, int32_t tokenCount, uint32_t *pVersionNumber); 40 | #endif // AWS_IOT_SDK_SRC_IOT_SHADOW_JSON_H_ 41 | -------------------------------------------------------------------------------- /src/aws_iot_lib/aws_iot_shadow_key.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #ifndef SRC_SHADOW_AWS_IOT_SHADOW_KEY_H_ 17 | #define SRC_SHADOW_AWS_IOT_SHADOW_KEY_H_ 18 | 19 | #define SHADOW_CLIENT_TOKEN_STRING "clientToken" 20 | #define SHADOW_VERSION_STRING "version" 21 | 22 | #endif /* SRC_SHADOW_AWS_IOT_SHADOW_KEY_H_ */ 23 | -------------------------------------------------------------------------------- /src/aws_iot_lib/aws_iot_shadow_records.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #ifndef SRC_SHADOW_AWS_IOT_SHADOW_RECORDS_H_ 17 | #define SRC_SHADOW_AWS_IOT_SHADOW_RECORDS_H_ 18 | 19 | #include 20 | 21 | #include "aws_iot_shadow_interface.h" 22 | #include "aws_iot_config.h" 23 | 24 | 25 | extern uint32_t shadowJsonVersionNum; 26 | extern bool shadowDiscardOldDeltaFlag; 27 | 28 | void initializeRecords(MQTTClient_t *pClient); 29 | bool isSubscriptionPresent(const char *pThingName, ShadowActions_t action); 30 | IoT_Error_t subscribeToShadowActionAcks(const char *pThingName, ShadowActions_t action, bool isSticky); 31 | void incrementSubscriptionCnt(const char *pThingName, ShadowActions_t action, bool isSticky); 32 | 33 | IoT_Error_t publishToShadowAction(const char * pThingName, ShadowActions_t action, const char *pJsonDocumentToBeSent); 34 | void addToAckWaitList(uint8_t indexAckWaitList, const char *pThingName, ShadowActions_t action, 35 | const char *pExtractedClientToken, fpActionCallback_t callback, void *pCallbackContext, 36 | uint32_t timeout_seconds); 37 | bool getNextFreeIndexOfAckWaitList(uint8_t *pIndex); 38 | void HandleExpiredResponseCallbacks(void); 39 | void initDeltaTokens(void); 40 | IoT_Error_t registerJsonTokenOnDelta(jsonStruct_t *pStruct); 41 | 42 | #endif /* SRC_SHADOW_AWS_IOT_SHADOW_RECORDS_H_ */ 43 | -------------------------------------------------------------------------------- /src/aws_iot_lib/aws_iot_version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_version.h 18 | * @brief Constants defining the release version of the SDK. 19 | * 20 | * This file contains constants defining the release version of the SDK. 21 | * This file is modified by AWS upon release of the SDK and should not be 22 | * modified by the consumer of the SDK. The provided samples show example 23 | * usage of these constants. 24 | * 25 | * Versioning of the SDK follows the MAJOR.MINOR.PATCH Semantic Versioning guidelines. 26 | * @see http://semver.org/ 27 | */ 28 | #ifndef SRC_UTILS_AWS_IOT_VERSION_H_ 29 | #define SRC_UTILS_AWS_IOT_VERSION_H_ 30 | 31 | /** 32 | * @brief MAJOR version, incremented when incompatible API changes are made. 33 | */ 34 | #define VERSION_MAJOR 1 35 | /** 36 | * @brief MINOR version when functionality is added in a backwards-compatible manner. 37 | */ 38 | #define VERSION_MINOR 0 39 | /** 40 | * @brief PATCH version when backwards-compatible bug fixes are made. 41 | */ 42 | #define VERSION_PATCH 0 43 | /** 44 | * @brief TAG is an (optional) tag appended to the version if a more descriptive verion is needed. 45 | */ 46 | #define VERSION_TAG "" 47 | 48 | #endif /* SRC_UTILS_AWS_IOT_VERSION_H_ */ 49 | -------------------------------------------------------------------------------- /src/aws_iot_lib/network_interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file network_interface.h 18 | * @brief Network interface definition for MQTT client. 19 | * 20 | * Defines an interface to the TLS layer to be used by the MQTT client. 21 | * Starting point for porting the SDK to the networking layer of a new platform. 22 | */ 23 | 24 | #ifndef __NETWORK_INTERFACE_H_ 25 | #define __NETWORK_INTERFACE_H_ 26 | 27 | /** 28 | * @brief Network Type 29 | * 30 | * Defines a type for the network struct. See structure definition below. 31 | */ 32 | typedef struct Network Network; 33 | 34 | /** 35 | * @brief TLS Connection Parameters 36 | * 37 | * Defines a type containing TLS specific parameters to be passed down to the 38 | * TLS networking layer to create a TLS secured socket. 39 | */ 40 | typedef struct{ 41 | char* pRootCALocation; ///< Pointer to string containing the filename (including path) of the root CA file. 42 | char* pDeviceCertLocation; ///< Pointer to string containing the filename (including path) of the device certificate. 43 | char* pDevicePrivateKeyLocation; ///< Pointer to string containing the filename (including path) of the device private key file. 44 | char* pDestinationURL; ///< Pointer to string containing the endpoint of the MQTT service. 45 | int DestinationPort; ///< Integer defining the connection port of the MQTT service. 46 | unsigned int timeout_ms; ///< Unsigned integer defining the TLS handshake timeout value in milliseconds. 47 | unsigned char ServerVerificationFlag; ///< Boolean. True = perform server certificate hostname validation. False = skip validation \b NOT recommended. 48 | }TLSConnectParams; 49 | 50 | /** 51 | * @brief Network Structure 52 | * 53 | * Structure for defining a network connection. 54 | */ 55 | struct Network{ 56 | int my_socket; ///< Integer holding the socket file descriptor 57 | int (*mqttread) (Network*, unsigned char*, int, int); ///< Function pointer pointing to the network function to read from the network 58 | int (*mqttwrite) (Network*, unsigned char*, int, int); ///< Function pointer pointing to the network function to write to the network 59 | void (*disconnect) (Network*); ///< Function pointer pointing to the network function to disconnect from the network 60 | }; 61 | 62 | /** 63 | * @brief Initialize the TLS implementation 64 | * 65 | * Perform any initialization required by the TLS layer. 66 | * Connects the interface to implementation by setting up 67 | * the network layer function pointers to platform implementations. 68 | * 69 | * @param pNetwork - Pointer to a Network struct defining the network interface. 70 | * @return integer defining successful initialization or TLS error 71 | */ 72 | int iot_tls_init(Network *pNetwork); 73 | 74 | /** 75 | * @brief Create a TLS socket and open the connection 76 | * 77 | * Creates an open socket connection including TLS handshake. 78 | * 79 | * @param pNetwork - Pointer to a Network struct defining the network interface. 80 | * @param TLSParams - TLSConnectParams defines the properties of the TLS connection. 81 | * @return integer - successful connection or TLS error 82 | */ 83 | int iot_tls_connect(Network *pNetwork, TLSConnectParams TLSParams); 84 | 85 | /** 86 | * @brief Write bytes to the network socket 87 | * 88 | * @param Network - Pointer to a Network struct defining the network interface. 89 | * @param unsigned char pointer - buffer to write to socket 90 | * @param integer - number of bytes to write 91 | * @param integer - write timeout value in milliseconds 92 | * @return integer - number of bytes written or TLS error 93 | */ 94 | int iot_tls_write(Network*, unsigned char*, int, int); 95 | 96 | /** 97 | * @brief Read bytes from the network socket 98 | * 99 | * @param Network - Pointer to a Network struct defining the network interface. 100 | * @param unsigned char pointer - pointer to buffer where read bytes should be copied 101 | * @param integer - number of bytes to read 102 | * @param integer - read timeout value in milliseconds 103 | * @return integer - number of bytes read or TLS error 104 | */ 105 | int iot_tls_read(Network*, unsigned char*, int, int); 106 | 107 | /** 108 | * @brief Disconnect from network socket 109 | * 110 | * @param Network - Pointer to a Network struct defining the network interface. 111 | */ 112 | void iot_tls_disconnect(Network *pNetwork); 113 | 114 | /** 115 | * @brief Perform any tear-down or cleanup of TLS layer 116 | * 117 | * Called to cleanup any resources required for the TLS layer. 118 | * 119 | * @param Network - Pointer to a Network struct defining the network interface. 120 | * @return integer - successful cleanup or TLS error 121 | */ 122 | int iot_tls_destroy(Network *pNetwork); 123 | 124 | #endif //__NETWORK_INTERFACE_H_ 125 | -------------------------------------------------------------------------------- /src/aws_iot_lib/timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file timer.c 18 | * @brief Linux implementation of the timer interface. 19 | */ 20 | 21 | #include 22 | #include 23 | #include "timer_interface.h" 24 | #include 25 | #include 26 | 27 | //sub time from timer 28 | void Ltimersub(const timeval* tvp, const timeval* uvp, timeval* vvp){ 29 | if (tvp->tv_sec < uvp->tv_sec){ 30 | vvp->tv_sec = 0; 31 | return; 32 | } 33 | 34 | vvp->tv_sec = tvp->tv_sec - uvp->tv_sec; 35 | vvp->tv_usec = tvp->tv_usec - uvp->tv_usec; 36 | if (vvp->tv_usec < 0) 37 | { 38 | --vvp->tv_sec; 39 | vvp->tv_usec += 1000000; 40 | } 41 | } 42 | 43 | //add time to timer 44 | void Ltimeradd(const timeval* tvp, const timeval* uvp, timeval* vvp){ 45 | vvp->tv_sec = tvp->tv_sec + uvp->tv_sec; 46 | vvp->tv_usec = tvp->tv_usec + uvp->tv_usec; 47 | } 48 | 49 | //count timer and return true or false if the time ends up 50 | char expired(Timer* timer) 51 | { 52 | timeval now, res; 53 | VMUINT32 start; 54 | start = vm_ust_get_current_time(); 55 | now.tv_sec = start/1000000; 56 | now.tv_usec = start%(now.tv_sec * 1000000); 57 | Ltimersub(&timer->end_time, &now, &res); 58 | 59 | return res.tv_sec == 0; 60 | } 61 | 62 | //add time to the timer in microseconds level 63 | void countdown_ms(Timer* timer, unsigned int timeout) 64 | { 65 | timeval now; 66 | VMUINT32 start; 67 | start = vm_ust_get_current_time(); 68 | now.tv_sec = start / 1000000; 69 | now.tv_usec = start % (now.tv_sec * 1000000); 70 | timeval interval = { timeout / 1000, (timeout % 1000) * 1000 }; 71 | 72 | Ltimeradd(&now, &interval, &timer->end_time); 73 | } 74 | 75 | //add time to the timer in seconds level 76 | void countdown(Timer* timer, unsigned int timeout) 77 | { 78 | timeval now; 79 | VMUINT32 start; 80 | start = vm_ust_get_current_time(); 81 | now.tv_sec = start / 1000000; 82 | now.tv_usec = start % (now.tv_sec * 1000000); 83 | timeval interval = {timeout, 0}; 84 | 85 | Ltimeradd(&now, &interval, &timer->end_time); 86 | } 87 | 88 | //calculate the left time in microseconds level 89 | int left_ms(Timer* timer) 90 | { 91 | timeval now, res; 92 | VMUINT32 start; 93 | start = vm_ust_get_current_time(); 94 | now.tv_sec = start / 1000000; 95 | now.tv_usec = start % (now.tv_sec * 1000000); 96 | Ltimersub(&timer->end_time, &now, &res); 97 | //printf("left %d ms\n", (res.tv_sec < 0) ? 0 : res.tv_sec * 1000 + res.tv_usec / 1000); 98 | return (res.tv_sec < 0) ? 0 : res.tv_sec * 1000; 99 | } 100 | 101 | void InitTimer(Timer* timer) { 102 | timer->end_time = (timeval ) { 0, 0 }; 103 | } -------------------------------------------------------------------------------- /src/aws_iot_lib/timer_interface.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Allan Stockdill-Mander - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | /** 18 | * @file timer_interface.h 19 | * @brief Timer interface definition for MQTT client. 20 | * 21 | * Defines an interface to timers that can be used by other system 22 | * components. MQTT client requires timers to handle timeouts and 23 | * MQTT keep alive. 24 | * Starting point for porting the SDK to the timer hardware layer of a new platform. 25 | */ 26 | 27 | #ifndef __TIMER_INTERFACE_H_ 28 | #define __TIMER_INTERFACE_H_ 29 | 30 | #include 31 | //#include 32 | //#include 33 | #include 34 | 35 | /** 36 | * @brief Timer Type 37 | * 38 | * Forward declaration of a timer struct. The definition of this struct is 39 | * platform dependent. When porting to a new platform add this definition 40 | * in "timer_.h" and include that file above. 41 | * 42 | */ 43 | typedef struct Timer Timer; 44 | 45 | struct Timer { 46 | timeval end_time; 47 | }; 48 | 49 | 50 | /** 51 | * @brief Check if a timer is expired 52 | * 53 | * Call this function passing in a timer to check if that timer has expired. 54 | * 55 | * @param Timer - pointer to the timer to be checked for expiration 56 | * @return character - 1 = timer expired, 0 = timer not expired 57 | */ 58 | char expired(Timer*); 59 | 60 | /** 61 | * @brief Create a timer (milliseconds) 62 | * 63 | * Sets the timer to expire in a specified number of milliseconds. 64 | * 65 | * @param Timer - pointer to the timer to be set to expire in milliseconds 66 | * @param unsigned int - set the timer to expire in this number of milliseconds 67 | */ 68 | void countdown_ms(Timer*, unsigned int); 69 | 70 | /** 71 | * @brief Create a timer (seconds) 72 | * 73 | * Sets the timer to expire in a specified number of seconds. 74 | * 75 | * @param Timer - pointer to the timer to be set to expire in seconds 76 | * @param unsigned int - set the timer to expire in this number of seconds 77 | */ 78 | void countdown(Timer*, unsigned int); 79 | 80 | /** 81 | * @brief Check the time remaining on a give timer 82 | * 83 | * Checks the input timer and returns the number of milliseconds remaining on the timer. 84 | * 85 | * @param Timer - pointer to the timer to be set to checked 86 | * @return int - milliseconds left on the countdown timer 87 | */ 88 | int left_ms(Timer*); 89 | 90 | /** 91 | * @brief Initialize a timer 92 | * 93 | * Performs any initialization required to the timer passed in. 94 | * 95 | * @param Timer - pointer to the timer to be initialized 96 | */ 97 | void InitTimer(Timer*); 98 | 99 | #endif //__TIMER_INTERFACE_H_ 100 | -------------------------------------------------------------------------------- /src/linkit_aws_header.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | /** 16 | * @file linkit_aws_header.h 17 | * @brief AWS IoT specific configuration file 18 | */ 19 | 20 | #ifndef SRC_LINKIT_AWS_HEADER_H_ 21 | #define SRC_LINKIT_AWS_HEADER_H_ 22 | 23 | #include "mbedtls/net.h" 24 | #include "mbedtls/mtk.h" 25 | 26 | #include "aws_iot_lib/aws_iot_mqtt_interface.h" 27 | #include "aws_iot_lib/aws_iot_version.h" 28 | #include "aws_iot_lib/aws_iot_shadow_interface.h" 29 | #include "aws_iot_lib/aws_iot_shadow_json_data.h" 30 | #include "aws_iot_lib/aws_iot_json_utils.h" 31 | #include "aws_iot_lib/aws_iot_log.h" 32 | 33 | #endif /* SRC_LINKIT_AWS_HEADER_H_ */ 34 | -------------------------------------------------------------------------------- /src/mbedtls/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | libmbed* 3 | *.sln 4 | *.vcxproj 5 | -------------------------------------------------------------------------------- /src/mbedtls/StackTrace.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | * Ian Craggs - fix for bug #434081 16 | *******************************************************************************/ 17 | 18 | #ifndef STACKTRACE_H_ 19 | #define STACKTRACE_H_ 20 | 21 | #include 22 | #define NOSTACKTRACE 1 23 | 24 | #if defined(NOSTACKTRACE) 25 | #define FUNC_ENTRY 26 | #define FUNC_ENTRY_NOLOG 27 | #define FUNC_ENTRY_MED 28 | #define FUNC_ENTRY_MAX 29 | #define FUNC_EXIT 30 | #define FUNC_EXIT_NOLOG 31 | #define FUNC_EXIT_MED 32 | #define FUNC_EXIT_MAX 33 | #define FUNC_EXIT_RC(x) 34 | #define FUNC_EXIT_MED_RC(x) 35 | #define FUNC_EXIT_MAX_RC(x) 36 | 37 | #else 38 | 39 | #if defined(WIN32) 40 | #define inline __inline 41 | #define FUNC_ENTRY StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MINIMUM) 42 | #define FUNC_ENTRY_NOLOG StackTrace_entry(__FUNCTION__, __LINE__, -1) 43 | #define FUNC_ENTRY_MED StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MEDIUM) 44 | #define FUNC_ENTRY_MAX StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MAXIMUM) 45 | #define FUNC_EXIT StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MINIMUM) 46 | #define FUNC_EXIT_NOLOG StackTrace_exit(__FUNCTION__, __LINE__, -1) 47 | #define FUNC_EXIT_MED StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MEDIUM) 48 | #define FUNC_EXIT_MAX StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MAXIMUM) 49 | #define FUNC_EXIT_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MINIMUM) 50 | #define FUNC_EXIT_MED_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MEDIUM) 51 | #define FUNC_EXIT_MAX_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MAXIMUM) 52 | #else 53 | #define FUNC_ENTRY StackTrace_entry(__func__, __LINE__, TRACE_MINIMUM) 54 | #define FUNC_ENTRY_NOLOG StackTrace_entry(__func__, __LINE__, -1) 55 | #define FUNC_ENTRY_MED StackTrace_entry(__func__, __LINE__, TRACE_MEDIUM) 56 | #define FUNC_ENTRY_MAX StackTrace_entry(__func__, __LINE__, TRACE_MAXIMUM) 57 | #define FUNC_EXIT StackTrace_exit(__func__, __LINE__, NULL, TRACE_MINIMUM) 58 | #define FUNC_EXIT_NOLOG StackTrace_exit(__func__, __LINE__, NULL, -1) 59 | #define FUNC_EXIT_MED StackTrace_exit(__func__, __LINE__, NULL, TRACE_MEDIUM) 60 | #define FUNC_EXIT_MAX StackTrace_exit(__func__, __LINE__, NULL, TRACE_MAXIMUM) 61 | #define FUNC_EXIT_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MINIMUM) 62 | #define FUNC_EXIT_MED_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MEDIUM) 63 | #define FUNC_EXIT_MAX_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MAXIMUM) 64 | 65 | void StackTrace_entry(const char* name, int line, int trace); 66 | void StackTrace_exit(const char* name, int line, void* return_value, int trace); 67 | 68 | void StackTrace_printStack(FILE* dest); 69 | char* StackTrace_get(unsigned long); 70 | 71 | #endif 72 | 73 | #endif 74 | 75 | 76 | 77 | 78 | #endif /* STACKTRACE_H_ */ 79 | -------------------------------------------------------------------------------- /src/mbedtls/aesni.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file aesni.h 3 | * 4 | * \brief AES-NI for hardware AES acceleration on some Intel processors 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_AESNI_H 24 | #define MBEDTLS_AESNI_H 25 | 26 | #include "aes.h" 27 | 28 | #define MBEDTLS_AESNI_AES 0x02000000u 29 | #define MBEDTLS_AESNI_CLMUL 0x00000002u 30 | 31 | #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \ 32 | ( defined(__amd64__) || defined(__x86_64__) ) && \ 33 | ! defined(MBEDTLS_HAVE_X86_64) 34 | #define MBEDTLS_HAVE_X86_64 35 | #endif 36 | 37 | #if defined(MBEDTLS_HAVE_X86_64) 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** 44 | * \brief AES-NI features detection routine 45 | * 46 | * \param what The feature to detect 47 | * (MBEDTLS_AESNI_AES or MBEDTLS_AESNI_CLMUL) 48 | * 49 | * \return 1 if CPU has support for the feature, 0 otherwise 50 | */ 51 | int mbedtls_aesni_has_support( unsigned int what ); 52 | 53 | /** 54 | * \brief AES-NI AES-ECB block en(de)cryption 55 | * 56 | * \param ctx AES context 57 | * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT 58 | * \param input 16-byte input block 59 | * \param output 16-byte output block 60 | * 61 | * \return 0 on success (cannot fail) 62 | */ 63 | int mbedtls_aesni_crypt_ecb( mbedtls_aes_context *ctx, 64 | int mode, 65 | const unsigned char input[16], 66 | unsigned char output[16] ); 67 | 68 | /** 69 | * \brief GCM multiplication: c = a * b in GF(2^128) 70 | * 71 | * \param c Result 72 | * \param a First operand 73 | * \param b Second operand 74 | * 75 | * \note Both operands and result are bit strings interpreted as 76 | * elements of GF(2^128) as per the GCM spec. 77 | */ 78 | void mbedtls_aesni_gcm_mult( unsigned char c[16], 79 | const unsigned char a[16], 80 | const unsigned char b[16] ); 81 | 82 | /** 83 | * \brief Compute decryption round keys from encryption round keys 84 | * 85 | * \param invkey Round keys for the equivalent inverse cipher 86 | * \param fwdkey Original round keys (for encryption) 87 | * \param nr Number of rounds (that is, number of round keys minus one) 88 | */ 89 | void mbedtls_aesni_inverse_key( unsigned char *invkey, 90 | const unsigned char *fwdkey, int nr ); 91 | 92 | /** 93 | * \brief Perform key expansion (for encryption) 94 | * 95 | * \param rk Destination buffer where the round keys are written 96 | * \param key Encryption key 97 | * \param bits Key size in bits (must be 128, 192 or 256) 98 | * 99 | * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH 100 | */ 101 | int mbedtls_aesni_setkey_enc( unsigned char *rk, 102 | const unsigned char *key, 103 | size_t bits ); 104 | 105 | #ifdef __cplusplus 106 | } 107 | #endif 108 | 109 | #endif /* MBEDTLS_HAVE_X86_64 */ 110 | 111 | #endif /* MBEDTLS_AESNI_H */ 112 | -------------------------------------------------------------------------------- /src/mbedtls/arc4.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file arc4.h 3 | * 4 | * \brief The ARCFOUR stream cipher 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_ARC4_H 24 | #define MBEDTLS_ARC4_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | 34 | #if !defined(MBEDTLS_ARC4_ALT) 35 | // Regular implementation 36 | // 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /** 43 | * \brief ARC4 context structure 44 | */ 45 | typedef struct 46 | { 47 | int x; /*!< permutation index */ 48 | int y; /*!< permutation index */ 49 | unsigned char m[256]; /*!< permutation table */ 50 | } 51 | mbedtls_arc4_context; 52 | 53 | /** 54 | * \brief Initialize ARC4 context 55 | * 56 | * \param ctx ARC4 context to be initialized 57 | */ 58 | void mbedtls_arc4_init( mbedtls_arc4_context *ctx ); 59 | 60 | /** 61 | * \brief Clear ARC4 context 62 | * 63 | * \param ctx ARC4 context to be cleared 64 | */ 65 | void mbedtls_arc4_free( mbedtls_arc4_context *ctx ); 66 | 67 | /** 68 | * \brief ARC4 key schedule 69 | * 70 | * \param ctx ARC4 context to be setup 71 | * \param key the secret key 72 | * \param keylen length of the key, in bytes 73 | */ 74 | void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key, 75 | unsigned int keylen ); 76 | 77 | /** 78 | * \brief ARC4 cipher function 79 | * 80 | * \param ctx ARC4 context 81 | * \param length length of the input data 82 | * \param input buffer holding the input data 83 | * \param output buffer for the output data 84 | * 85 | * \return 0 if successful 86 | */ 87 | int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input, 88 | unsigned char *output ); 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #else /* MBEDTLS_ARC4_ALT */ 95 | #include "arc4_alt.h" 96 | #endif /* MBEDTLS_ARC4_ALT */ 97 | 98 | #ifdef __cplusplus 99 | extern "C" { 100 | #endif 101 | 102 | /** 103 | * \brief Checkup routine 104 | * 105 | * \return 0 if successful, or 1 if the test failed 106 | */ 107 | int mbedtls_arc4_self_test( int verbose ); 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | #endif /* arc4.h */ 114 | -------------------------------------------------------------------------------- /src/mbedtls/base64.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file base64.h 3 | * 4 | * \brief RFC 1521 base64 encoding/decoding 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_BASE64_H 24 | #define MBEDTLS_BASE64_H 25 | 26 | #include 27 | 28 | #define MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL -0x002A /**< Output buffer too small. */ 29 | #define MBEDTLS_ERR_BASE64_INVALID_CHARACTER -0x002C /**< Invalid character in input. */ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /** 36 | * \brief Encode a buffer into base64 format 37 | * 38 | * \param dst destination buffer 39 | * \param dlen size of the destination buffer 40 | * \param olen number of bytes written 41 | * \param src source buffer 42 | * \param slen amount of data to be encoded 43 | * 44 | * \return 0 if successful, or MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL. 45 | * *olen is always updated to reflect the amount 46 | * of data that has (or would have) been written. 47 | * If that length cannot be represented, then no data is 48 | * written to the buffer and *olen is set to the maximum 49 | * length representable as a size_t. 50 | * 51 | * \note Call this function with dlen = 0 to obtain the 52 | * required buffer size in *olen 53 | */ 54 | int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen, 55 | const unsigned char *src, size_t slen ); 56 | 57 | /** 58 | * \brief Decode a base64-formatted buffer 59 | * 60 | * \param dst destination buffer (can be NULL for checking size) 61 | * \param dlen size of the destination buffer 62 | * \param olen number of bytes written 63 | * \param src source buffer 64 | * \param slen amount of data to be decoded 65 | * 66 | * \return 0 if successful, MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL, or 67 | * MBEDTLS_ERR_BASE64_INVALID_CHARACTER if the input data is 68 | * not correct. *olen is always updated to reflect the amount 69 | * of data that has (or would have) been written. 70 | * 71 | * \note Call this function with *dst = NULL or dlen = 0 to obtain 72 | * the required buffer size in *olen 73 | */ 74 | int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen, 75 | const unsigned char *src, size_t slen ); 76 | 77 | /** 78 | * \brief Checkup routine 79 | * 80 | * \return 0 if successful, or 1 if the test failed 81 | */ 82 | int mbedtls_base64_self_test( int verbose ); 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* base64.h */ 89 | -------------------------------------------------------------------------------- /src/mbedtls/certs.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file certs.h 3 | * 4 | * \brief Sample certificates and DHM parameters for testing 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_CERTS_H 24 | #define MBEDTLS_CERTS_H 25 | 26 | #include 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #if defined(MBEDTLS_PEM_PARSE_C) 33 | /* Concatenation of all CA certificates in PEM format if available */ 34 | extern const char mbedtls_test_cas_pem[]; 35 | extern const size_t mbedtls_test_cas_pem_len; 36 | #endif 37 | 38 | /* List of all CA certificates, terminated by NULL */ 39 | extern const char * mbedtls_test_cas[]; 40 | extern const size_t mbedtls_test_cas_len[]; 41 | 42 | /* 43 | * Convenience for users who just want a certificate: 44 | * RSA by default, or ECDSA if RSA is not available 45 | */ 46 | extern const char * mbedtls_test_ca_crt; 47 | extern const size_t mbedtls_test_ca_crt_len; 48 | extern const char * mbedtls_test_ca_key; 49 | extern const size_t mbedtls_test_ca_key_len; 50 | extern const char * mbedtls_test_ca_pwd; 51 | extern const size_t mbedtls_test_ca_pwd_len; 52 | extern const char * mbedtls_test_srv_crt; 53 | extern const size_t mbedtls_test_srv_crt_len; 54 | extern const char * mbedtls_test_srv_key; 55 | extern const size_t mbedtls_test_srv_key_len; 56 | extern const char * mbedtls_test_cli_crt; 57 | extern const size_t mbedtls_test_cli_crt_len; 58 | extern const char * mbedtls_test_cli_key; 59 | extern const size_t mbedtls_test_cli_key_len; 60 | 61 | #if defined(MBEDTLS_ECDSA_C) 62 | extern const char mbedtls_test_ca_crt_ec[]; 63 | extern const size_t mbedtls_test_ca_crt_ec_len; 64 | extern const char mbedtls_test_ca_key_ec[]; 65 | extern const size_t mbedtls_test_ca_key_ec_len; 66 | extern const char mbedtls_test_ca_pwd_ec[]; 67 | extern const size_t mbedtls_test_ca_pwd_ec_len; 68 | extern const char mbedtls_test_srv_crt_ec[]; 69 | extern const size_t mbedtls_test_srv_crt_ec_len; 70 | extern const char mbedtls_test_srv_key_ec[]; 71 | extern const size_t mbedtls_test_srv_key_ec_len; 72 | extern const char mbedtls_test_cli_crt_ec[]; 73 | extern const size_t mbedtls_test_cli_crt_ec_len; 74 | extern const char mbedtls_test_cli_key_ec[]; 75 | extern const size_t mbedtls_test_cli_key_ec_len; 76 | #endif 77 | 78 | #if defined(MBEDTLS_RSA_C) 79 | extern const char mbedtls_test_ca_crt_rsa[]; 80 | extern const size_t mbedtls_test_ca_crt_rsa_len; 81 | extern const char mbedtls_test_ca_key_rsa[]; 82 | extern const size_t mbedtls_test_ca_key_rsa_len; 83 | extern const char mbedtls_test_ca_pwd_rsa[]; 84 | extern const size_t mbedtls_test_ca_pwd_rsa_len; 85 | extern const char mbedtls_test_srv_crt_rsa[]; 86 | extern const size_t mbedtls_test_srv_crt_rsa_len; 87 | extern const char mbedtls_test_srv_key_rsa[]; 88 | extern const size_t mbedtls_test_srv_key_rsa_len; 89 | extern const char mbedtls_test_cli_crt_rsa[]; 90 | extern const size_t mbedtls_test_cli_crt_rsa_len; 91 | extern const char mbedtls_test_cli_key_rsa[]; 92 | extern const size_t mbedtls_test_cli_key_rsa_len; 93 | #endif 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif /* certs.h */ 100 | -------------------------------------------------------------------------------- /src/mbedtls/cipher_internal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file cipher_internal.h 3 | * 4 | * \brief Cipher wrappers. 5 | * 6 | * \author Adriaan de Jong 7 | * 8 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 9 | * SPDX-License-Identifier: Apache-2.0 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 12 | * not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 19 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | * This file is part of mbed TLS (https://tls.mbed.org) 24 | */ 25 | #ifndef MBEDTLS_CIPHER_WRAP_H 26 | #define MBEDTLS_CIPHER_WRAP_H 27 | 28 | #if !defined(MBEDTLS_CONFIG_FILE) 29 | #include "config.h" 30 | #else 31 | #include MBEDTLS_CONFIG_FILE 32 | #endif 33 | 34 | #include "cipher.h" 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /** 41 | * Base cipher information. The non-mode specific functions and values. 42 | */ 43 | struct mbedtls_cipher_base_t 44 | { 45 | /** Base Cipher type (e.g. MBEDTLS_CIPHER_ID_AES) */ 46 | mbedtls_cipher_id_t cipher; 47 | 48 | /** Encrypt using ECB */ 49 | int (*ecb_func)( void *ctx, mbedtls_operation_t mode, 50 | const unsigned char *input, unsigned char *output ); 51 | 52 | #if defined(MBEDTLS_CIPHER_MODE_CBC) 53 | /** Encrypt using CBC */ 54 | int (*cbc_func)( void *ctx, mbedtls_operation_t mode, size_t length, 55 | unsigned char *iv, const unsigned char *input, 56 | unsigned char *output ); 57 | #endif 58 | 59 | #if defined(MBEDTLS_CIPHER_MODE_CFB) 60 | /** Encrypt using CFB (Full length) */ 61 | int (*cfb_func)( void *ctx, mbedtls_operation_t mode, size_t length, size_t *iv_off, 62 | unsigned char *iv, const unsigned char *input, 63 | unsigned char *output ); 64 | #endif 65 | 66 | #if defined(MBEDTLS_CIPHER_MODE_CTR) 67 | /** Encrypt using CTR */ 68 | int (*ctr_func)( void *ctx, size_t length, size_t *nc_off, 69 | unsigned char *nonce_counter, unsigned char *stream_block, 70 | const unsigned char *input, unsigned char *output ); 71 | #endif 72 | 73 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) 74 | /** Encrypt using STREAM */ 75 | int (*stream_func)( void *ctx, size_t length, 76 | const unsigned char *input, unsigned char *output ); 77 | #endif 78 | 79 | /** Set key for encryption purposes */ 80 | int (*setkey_enc_func)( void *ctx, const unsigned char *key, 81 | unsigned int key_bitlen ); 82 | 83 | /** Set key for decryption purposes */ 84 | int (*setkey_dec_func)( void *ctx, const unsigned char *key, 85 | unsigned int key_bitlen); 86 | 87 | /** Allocate a new context */ 88 | void * (*ctx_alloc_func)( void ); 89 | 90 | /** Free the given context */ 91 | void (*ctx_free_func)( void *ctx ); 92 | 93 | }; 94 | 95 | typedef struct 96 | { 97 | mbedtls_cipher_type_t type; 98 | const mbedtls_cipher_info_t *info; 99 | } mbedtls_cipher_definition_t; 100 | 101 | extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[]; 102 | 103 | extern int mbedtls_cipher_supported[]; 104 | 105 | #ifdef __cplusplus 106 | } 107 | #endif 108 | 109 | #endif /* MBEDTLS_CIPHER_WRAP_H */ 110 | -------------------------------------------------------------------------------- /src/mbedtls/debug.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file debug.h 3 | * 4 | * \brief Debug functions 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_DEBUG_H 24 | #define MBEDTLS_DEBUG_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include "ssl.h" 33 | 34 | #if defined(MBEDTLS_ECP_C) 35 | #include "ecp.h" 36 | #endif 37 | 38 | #if defined(MBEDTLS_DEBUG_C) 39 | 40 | #define MBEDTLS_DEBUG_STRIP_PARENS( ... ) __VA_ARGS__ 41 | 42 | #define MBEDTLS_SSL_DEBUG_MSG( level, args ) \ 43 | mbedtls_debug_print_msg( ssl, level, __FILE__, __LINE__, \ 44 | MBEDTLS_DEBUG_STRIP_PARENS args ) 45 | 46 | #define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) \ 47 | mbedtls_debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret ) 48 | 49 | #define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) \ 50 | mbedtls_debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len ) 51 | 52 | #if defined(MBEDTLS_BIGNUM_C) 53 | #define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) \ 54 | mbedtls_debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X ) 55 | #endif 56 | 57 | #if defined(MBEDTLS_ECP_C) 58 | #define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) \ 59 | mbedtls_debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X ) 60 | #endif 61 | 62 | #if defined(MBEDTLS_X509_CRT_PARSE_C) 63 | #define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) \ 64 | mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt ) 65 | #endif 66 | 67 | #else /* MBEDTLS_DEBUG_C */ 68 | 69 | #define MBEDTLS_SSL_DEBUG_MSG( level, args ) do { } while( 0 ) 70 | #define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) do { } while( 0 ) 71 | #define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 ) 72 | #define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) do { } while( 0 ) 73 | #define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) do { } while( 0 ) 74 | #define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 ) 75 | 76 | #endif /* MBEDTLS_DEBUG_C */ 77 | 78 | #ifdef __cplusplus 79 | extern "C" { 80 | #endif 81 | 82 | /** 83 | * \brief Set the level threshold to handle globally. Messages that have a 84 | * level over the threshold value are ignored. 85 | * (Default value: 0 (No debug)) 86 | * 87 | * \param threshold maximum level of messages to pass on 88 | */ 89 | void mbedtls_debug_set_threshold( int threshold ); 90 | 91 | void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level, 92 | const char *file, int line, 93 | const char *format, ... ); 94 | 95 | void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level, 96 | const char *file, int line, 97 | const char *text, int ret ); 98 | 99 | void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level, 100 | const char *file, int line, const char *text, 101 | const unsigned char *buf, size_t len ); 102 | 103 | #if defined(MBEDTLS_BIGNUM_C) 104 | void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level, 105 | const char *file, int line, 106 | const char *text, const mbedtls_mpi *X ); 107 | #endif 108 | 109 | #if defined(MBEDTLS_ECP_C) 110 | void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level, 111 | const char *file, int line, 112 | const char *text, const mbedtls_ecp_point *X ); 113 | #endif 114 | 115 | #if defined(MBEDTLS_X509_CRT_PARSE_C) 116 | void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level, 117 | const char *file, int line, 118 | const char *text, const mbedtls_x509_crt *crt ); 119 | #endif 120 | 121 | #ifdef __cplusplus 122 | } 123 | #endif 124 | 125 | #endif /* debug.h */ 126 | -------------------------------------------------------------------------------- /src/mbedtls/entropy_poll.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file entropy_poll.h 3 | * 4 | * \brief Platform-specific and custom entropy polling functions 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_ENTROPY_POLL_H 24 | #define MBEDTLS_ENTROPY_POLL_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | /* 39 | * Default thresholds for built-in sources, in bytes 40 | */ 41 | #define MBEDTLS_ENTROPY_MIN_PLATFORM 32 /**< Minimum for platform source */ 42 | #define MBEDTLS_ENTROPY_MIN_HAVEGE 32 /**< Minimum for HAVEGE */ 43 | #define MBEDTLS_ENTROPY_MIN_HARDCLOCK 4 /**< Minimum for mbedtls_timing_hardclock() */ 44 | #define MBEDTLS_ENTROPY_MIN_HARDWARE 32 /**< Minimum for the hardware source */ 45 | 46 | #if !defined(MBEDTLS_NO_PLATFORM_ENTROPY) 47 | /** 48 | * \brief Platform-specific entropy poll callback 49 | */ 50 | int mbedtls_platform_entropy_poll( void *data, 51 | unsigned char *output, size_t len, size_t *olen ); 52 | #endif 53 | 54 | #if defined(MBEDTLS_HAVEGE_C) 55 | /** 56 | * \brief HAVEGE based entropy poll callback 57 | * 58 | * Requires an HAVEGE state as its data pointer. 59 | */ 60 | int mbedtls_havege_poll( void *data, 61 | unsigned char *output, size_t len, size_t *olen ); 62 | #endif 63 | 64 | #if defined(MBEDTLS_TIMING_C) 65 | /** 66 | * \brief mbedtls_timing_hardclock-based entropy poll callback 67 | */ 68 | int mbedtls_hardclock_poll( void *data, 69 | unsigned char *output, size_t len, size_t *olen ); 70 | #endif 71 | 72 | #if defined(MBEDTLS_ENTROPY_HARDWARE_ALT) 73 | /** 74 | * \brief Entropy poll callback for a hardware source 75 | * 76 | * \warning This is not provided by mbed TLS! 77 | * See \c MBEDTLS_ENTROPY_HARDWARE_ALT in config.h. 78 | * 79 | * \note This must accept NULL as its first argument. 80 | */ 81 | int mbedtls_hardware_poll( void *data, 82 | unsigned char *output, size_t len, size_t *olen ); 83 | #endif 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /* entropy_poll.h */ 90 | -------------------------------------------------------------------------------- /src/mbedtls/error.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file error.h 3 | * 4 | * \brief Error to string translation 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_ERROR_H 24 | #define MBEDTLS_ERROR_H 25 | 26 | #include 27 | 28 | /** 29 | * Error code layout. 30 | * 31 | * Currently we try to keep all error codes within the negative space of 16 32 | * bits signed integers to support all platforms (-0x0001 - -0x7FFF). In 33 | * addition we'd like to give two layers of information on the error if 34 | * possible. 35 | * 36 | * For that purpose the error codes are segmented in the following manner: 37 | * 38 | * 16 bit error code bit-segmentation 39 | * 40 | * 1 bit - Unused (sign bit) 41 | * 3 bits - High level module ID 42 | * 5 bits - Module-dependent error code 43 | * 7 bits - Low level module errors 44 | * 45 | * For historical reasons, low-level error codes are divided in even and odd, 46 | * even codes were assigned first, and -1 is reserved for other errors. 47 | * 48 | * Low-level module errors (0x0002-0x007E, 0x0003-0x007F) 49 | * 50 | * Module Nr Codes assigned 51 | * MPI 7 0x0002-0x0010 52 | * GCM 2 0x0012-0x0014 53 | * BLOWFISH 2 0x0016-0x0018 54 | * THREADING 3 0x001A-0x001E 55 | * AES 2 0x0020-0x0022 56 | * CAMELLIA 2 0x0024-0x0026 57 | * XTEA 1 0x0028-0x0028 58 | * BASE64 2 0x002A-0x002C 59 | * OID 1 0x002E-0x002E 0x000B-0x000B 60 | * PADLOCK 1 0x0030-0x0030 61 | * DES 1 0x0032-0x0032 62 | * CTR_DBRG 4 0x0034-0x003A 63 | * ENTROPY 3 0x003C-0x0040 0x003D-0x003F 64 | * NET 11 0x0042-0x0052 0x0043-0x0045 65 | * ASN1 7 0x0060-0x006C 66 | * PBKDF2 1 0x007C-0x007C 67 | * HMAC_DRBG 4 0x0003-0x0009 68 | * CCM 2 0x000D-0x000F 69 | * 70 | * High-level module nr (3 bits - 0x0...-0x7...) 71 | * Name ID Nr of Errors 72 | * PEM 1 9 73 | * PKCS#12 1 4 (Started from top) 74 | * X509 2 19 75 | * PKCS5 2 4 (Started from top) 76 | * DHM 3 9 77 | * PK 3 14 (Started from top) 78 | * RSA 4 9 79 | * ECP 4 8 (Started from top) 80 | * MD 5 4 81 | * CIPHER 6 6 82 | * SSL 6 16 (Started from top) 83 | * SSL 7 31 84 | * 85 | * Module dependent error code (5 bits 0x.00.-0x.F8.) 86 | */ 87 | 88 | #ifdef __cplusplus 89 | extern "C" { 90 | #endif 91 | 92 | /** 93 | * \brief Translate a mbed TLS error code into a string representation, 94 | * Result is truncated if necessary and always includes a terminating 95 | * null byte. 96 | * 97 | * \param errnum error code 98 | * \param buffer buffer to place representation in 99 | * \param buflen length of the buffer 100 | */ 101 | void mbedtls_strerror( int errnum, char *buffer, size_t buflen ); 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | 107 | #endif /* error.h */ 108 | -------------------------------------------------------------------------------- /src/mbedtls/havege.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file havege.h 3 | * 4 | * \brief HAVEGE: HArdware Volatile Entropy Gathering and Expansion 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_HAVEGE_H 24 | #define MBEDTLS_HAVEGE_H 25 | 26 | #include 27 | 28 | #define MBEDTLS_HAVEGE_COLLECT_SIZE 1024 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** 35 | * \brief HAVEGE state structure 36 | */ 37 | typedef struct 38 | { 39 | int PT1, PT2, offset[2]; 40 | int pool[MBEDTLS_HAVEGE_COLLECT_SIZE]; 41 | int WALK[8192]; 42 | } 43 | mbedtls_havege_state; 44 | 45 | /** 46 | * \brief HAVEGE initialization 47 | * 48 | * \param hs HAVEGE state to be initialized 49 | */ 50 | void mbedtls_havege_init( mbedtls_havege_state *hs ); 51 | 52 | /** 53 | * \brief Clear HAVEGE state 54 | * 55 | * \param hs HAVEGE state to be cleared 56 | */ 57 | void mbedtls_havege_free( mbedtls_havege_state *hs ); 58 | 59 | /** 60 | * \brief HAVEGE rand function 61 | * 62 | * \param p_rng A HAVEGE state 63 | * \param output Buffer to fill 64 | * \param len Length of buffer 65 | * 66 | * \return 0 67 | */ 68 | int mbedtls_havege_random( void *p_rng, unsigned char *output, size_t len ); 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif /* havege.h */ 75 | -------------------------------------------------------------------------------- /src/mbedtls/jsmn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Serge A. Zaitsev 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 | 23 | #ifndef __JSMN_H_ 24 | #define __JSMN_H_ 25 | #include 26 | #define JSMN_STRICT 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /** 32 | * JSON type identifier. Basic types are: 33 | * o Object 34 | * o Array 35 | * o String 36 | * o Other primitive: number, boolean (true/false) or null 37 | */ 38 | typedef enum { 39 | JSMN_PRIMITIVE = 0, JSMN_OBJECT = 1, JSMN_ARRAY = 2, JSMN_STRING = 3 40 | } jsmntype_t; 41 | 42 | typedef enum { 43 | /* Not enough tokens were provided */ 44 | JSMN_ERROR_NOMEM = -1, 45 | /* Invalid character inside JSON string */ 46 | JSMN_ERROR_INVAL = -2, 47 | /* The string is not a full JSON packet, more bytes expected */ 48 | JSMN_ERROR_PART = -3, 49 | } jsmnerr_t; 50 | 51 | /** 52 | * JSON token description. 53 | * @param type type (object, array, string etc.) 54 | * @param start start position in JSON data string 55 | * @param end end position in JSON data string 56 | */ 57 | typedef struct { 58 | jsmntype_t type; 59 | int start; 60 | int end; 61 | int size; 62 | #ifdef JSMN_PARENT_LINKS 63 | int parent; 64 | #endif 65 | } jsmntok_t; 66 | 67 | /** 68 | * JSON parser. Contains an array of token blocks available. Also stores 69 | * the string being parsed now and current position in that string 70 | */ 71 | typedef struct { 72 | unsigned int pos; /* offset in the JSON string */ 73 | unsigned int toknext; /* next token to allocate */ 74 | int toksuper; /* superior token node, e.g parent object or array */ 75 | } jsmn_parser; 76 | 77 | /** 78 | * Create JSON parser over an array of tokens 79 | */ 80 | void jsmn_init(jsmn_parser *parser); 81 | 82 | /** 83 | * Run JSON parser. It parses a JSON data string into and array of tokens, each describing 84 | * a single JSON object. 85 | */ 86 | jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, 87 | jsmntok_t *tokens, unsigned int num_tokens); 88 | 89 | #ifdef __cplusplus 90 | } 91 | #endif 92 | 93 | #endif /* __JSMN_H_ */ 94 | -------------------------------------------------------------------------------- /src/mbedtls/md2.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file mbedtls_md2.h 3 | * 4 | * \brief MD2 message digest algorithm (hash function) 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_MD2_H 24 | #define MBEDTLS_MD2_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | 34 | #if !defined(MBEDTLS_MD2_ALT) 35 | // Regular implementation 36 | // 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /** 43 | * \brief MD2 context structure 44 | */ 45 | typedef struct 46 | { 47 | unsigned char cksum[16]; /*!< checksum of the data block */ 48 | unsigned char state[48]; /*!< intermediate digest state */ 49 | unsigned char buffer[16]; /*!< data block being processed */ 50 | size_t left; /*!< amount of data in buffer */ 51 | } 52 | mbedtls_md2_context; 53 | 54 | /** 55 | * \brief Initialize MD2 context 56 | * 57 | * \param ctx MD2 context to be initialized 58 | */ 59 | void mbedtls_md2_init( mbedtls_md2_context *ctx ); 60 | 61 | /** 62 | * \brief Clear MD2 context 63 | * 64 | * \param ctx MD2 context to be cleared 65 | */ 66 | void mbedtls_md2_free( mbedtls_md2_context *ctx ); 67 | 68 | /** 69 | * \brief Clone (the state of) an MD2 context 70 | * 71 | * \param dst The destination context 72 | * \param src The context to be cloned 73 | */ 74 | void mbedtls_md2_clone( mbedtls_md2_context *dst, 75 | const mbedtls_md2_context *src ); 76 | 77 | /** 78 | * \brief MD2 context setup 79 | * 80 | * \param ctx context to be initialized 81 | */ 82 | void mbedtls_md2_starts( mbedtls_md2_context *ctx ); 83 | 84 | /** 85 | * \brief MD2 process buffer 86 | * 87 | * \param ctx MD2 context 88 | * \param input buffer holding the data 89 | * \param ilen length of the input data 90 | */ 91 | void mbedtls_md2_update( mbedtls_md2_context *ctx, const unsigned char *input, size_t ilen ); 92 | 93 | /** 94 | * \brief MD2 final digest 95 | * 96 | * \param ctx MD2 context 97 | * \param output MD2 checksum result 98 | */ 99 | void mbedtls_md2_finish( mbedtls_md2_context *ctx, unsigned char output[16] ); 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #else /* MBEDTLS_MD2_ALT */ 106 | #include "md2_alt.h" 107 | #endif /* MBEDTLS_MD2_ALT */ 108 | 109 | #ifdef __cplusplus 110 | extern "C" { 111 | #endif 112 | 113 | /** 114 | * \brief Output = MD2( input buffer ) 115 | * 116 | * \param input buffer holding the data 117 | * \param ilen length of the input data 118 | * \param output MD2 checksum result 119 | */ 120 | void mbedtls_md2( const unsigned char *input, size_t ilen, unsigned char output[16] ); 121 | 122 | /** 123 | * \brief Checkup routine 124 | * 125 | * \return 0 if successful, or 1 if the test failed 126 | */ 127 | int mbedtls_md2_self_test( int verbose ); 128 | 129 | /* Internal use */ 130 | void mbedtls_md2_process( mbedtls_md2_context *ctx ); 131 | 132 | #ifdef __cplusplus 133 | } 134 | #endif 135 | 136 | #endif /* mbedtls_md2.h */ 137 | -------------------------------------------------------------------------------- /src/mbedtls/md4.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file mbedtls_md4.h 3 | * 4 | * \brief MD4 message digest algorithm (hash function) 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_MD4_H 24 | #define MBEDTLS_MD4_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | #if !defined(MBEDTLS_MD4_ALT) 36 | // Regular implementation 37 | // 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** 44 | * \brief MD4 context structure 45 | */ 46 | typedef struct 47 | { 48 | uint32_t total[2]; /*!< number of bytes processed */ 49 | uint32_t state[4]; /*!< intermediate digest state */ 50 | unsigned char buffer[64]; /*!< data block being processed */ 51 | } 52 | mbedtls_md4_context; 53 | 54 | /** 55 | * \brief Initialize MD4 context 56 | * 57 | * \param ctx MD4 context to be initialized 58 | */ 59 | void mbedtls_md4_init( mbedtls_md4_context *ctx ); 60 | 61 | /** 62 | * \brief Clear MD4 context 63 | * 64 | * \param ctx MD4 context to be cleared 65 | */ 66 | void mbedtls_md4_free( mbedtls_md4_context *ctx ); 67 | 68 | /** 69 | * \brief Clone (the state of) an MD4 context 70 | * 71 | * \param dst The destination context 72 | * \param src The context to be cloned 73 | */ 74 | void mbedtls_md4_clone( mbedtls_md4_context *dst, 75 | const mbedtls_md4_context *src ); 76 | 77 | /** 78 | * \brief MD4 context setup 79 | * 80 | * \param ctx context to be initialized 81 | */ 82 | void mbedtls_md4_starts( mbedtls_md4_context *ctx ); 83 | 84 | /** 85 | * \brief MD4 process buffer 86 | * 87 | * \param ctx MD4 context 88 | * \param input buffer holding the data 89 | * \param ilen length of the input data 90 | */ 91 | void mbedtls_md4_update( mbedtls_md4_context *ctx, const unsigned char *input, size_t ilen ); 92 | 93 | /** 94 | * \brief MD4 final digest 95 | * 96 | * \param ctx MD4 context 97 | * \param output MD4 checksum result 98 | */ 99 | void mbedtls_md4_finish( mbedtls_md4_context *ctx, unsigned char output[16] ); 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #else /* MBEDTLS_MD4_ALT */ 106 | #include "md4_alt.h" 107 | #endif /* MBEDTLS_MD4_ALT */ 108 | 109 | #ifdef __cplusplus 110 | extern "C" { 111 | #endif 112 | 113 | /** 114 | * \brief Output = MD4( input buffer ) 115 | * 116 | * \param input buffer holding the data 117 | * \param ilen length of the input data 118 | * \param output MD4 checksum result 119 | */ 120 | void mbedtls_md4( const unsigned char *input, size_t ilen, unsigned char output[16] ); 121 | 122 | /** 123 | * \brief Checkup routine 124 | * 125 | * \return 0 if successful, or 1 if the test failed 126 | */ 127 | int mbedtls_md4_self_test( int verbose ); 128 | 129 | /* Internal use */ 130 | void mbedtls_md4_process( mbedtls_md4_context *ctx, const unsigned char data[64] ); 131 | 132 | #ifdef __cplusplus 133 | } 134 | #endif 135 | 136 | #endif /* mbedtls_md4.h */ 137 | -------------------------------------------------------------------------------- /src/mbedtls/md5.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file mbedtls_md5.h 3 | * 4 | * \brief MD5 message digest algorithm (hash function) 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_MD5_H 24 | #define MBEDTLS_MD5_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | #if !defined(MBEDTLS_MD5_ALT) 36 | // Regular implementation 37 | // 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** 44 | * \brief MD5 context structure 45 | */ 46 | typedef struct 47 | { 48 | uint32_t total[2]; /*!< number of bytes processed */ 49 | uint32_t state[4]; /*!< intermediate digest state */ 50 | unsigned char buffer[64]; /*!< data block being processed */ 51 | } 52 | mbedtls_md5_context; 53 | 54 | /** 55 | * \brief Initialize MD5 context 56 | * 57 | * \param ctx MD5 context to be initialized 58 | */ 59 | void mbedtls_md5_init( mbedtls_md5_context *ctx ); 60 | 61 | /** 62 | * \brief Clear MD5 context 63 | * 64 | * \param ctx MD5 context to be cleared 65 | */ 66 | void mbedtls_md5_free( mbedtls_md5_context *ctx ); 67 | 68 | /** 69 | * \brief Clone (the state of) an MD5 context 70 | * 71 | * \param dst The destination context 72 | * \param src The context to be cloned 73 | */ 74 | void mbedtls_md5_clone( mbedtls_md5_context *dst, 75 | const mbedtls_md5_context *src ); 76 | 77 | /** 78 | * \brief MD5 context setup 79 | * 80 | * \param ctx context to be initialized 81 | */ 82 | void mbedtls_md5_starts( mbedtls_md5_context *ctx ); 83 | 84 | /** 85 | * \brief MD5 process buffer 86 | * 87 | * \param ctx MD5 context 88 | * \param input buffer holding the data 89 | * \param ilen length of the input data 90 | */ 91 | void mbedtls_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen ); 92 | 93 | /** 94 | * \brief MD5 final digest 95 | * 96 | * \param ctx MD5 context 97 | * \param output MD5 checksum result 98 | */ 99 | void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] ); 100 | 101 | /* Internal use */ 102 | void mbedtls_md5_process( mbedtls_md5_context *ctx, const unsigned char data[64] ); 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #else /* MBEDTLS_MD5_ALT */ 109 | #include "md5_alt.h" 110 | #endif /* MBEDTLS_MD5_ALT */ 111 | 112 | #ifdef __cplusplus 113 | extern "C" { 114 | #endif 115 | 116 | /** 117 | * \brief Output = MD5( input buffer ) 118 | * 119 | * \param input buffer holding the data 120 | * \param ilen length of the input data 121 | * \param output MD5 checksum result 122 | */ 123 | void mbedtls_md5( const unsigned char *input, size_t ilen, unsigned char output[16] ); 124 | 125 | /** 126 | * \brief Checkup routine 127 | * 128 | * \return 0 if successful, or 1 if the test failed 129 | */ 130 | int mbedtls_md5_self_test( int verbose ); 131 | 132 | #ifdef __cplusplus 133 | } 134 | #endif 135 | 136 | #endif /* mbedtls_md5.h */ 137 | -------------------------------------------------------------------------------- /src/mbedtls/md_internal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file md_internal.h 3 | * 4 | * \brief Message digest wrappers. 5 | * 6 | * \warning This in an internal header. Do not include directly. 7 | * 8 | * \author Adriaan de Jong 9 | * 10 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 11 | * SPDX-License-Identifier: Apache-2.0 12 | * 13 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 14 | * not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at 16 | * 17 | * http://www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 21 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | * This file is part of mbed TLS (https://tls.mbed.org) 26 | */ 27 | #ifndef MBEDTLS_MD_WRAP_H 28 | #define MBEDTLS_MD_WRAP_H 29 | 30 | #if !defined(MBEDTLS_CONFIG_FILE) 31 | #include "config.h" 32 | #else 33 | #include MBEDTLS_CONFIG_FILE 34 | #endif 35 | 36 | #include "md.h" 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /** 43 | * Message digest information. 44 | * Allows message digest functions to be called in a generic way. 45 | */ 46 | struct mbedtls_md_info_t 47 | { 48 | /** Digest identifier */ 49 | mbedtls_md_type_t type; 50 | 51 | /** Name of the message digest */ 52 | const char * name; 53 | 54 | /** Output length of the digest function in bytes */ 55 | int size; 56 | 57 | /** Block length of the digest function in bytes */ 58 | int block_size; 59 | 60 | /** Digest initialisation function */ 61 | void (*starts_func)( void *ctx ); 62 | 63 | /** Digest update function */ 64 | void (*update_func)( void *ctx, const unsigned char *input, size_t ilen ); 65 | 66 | /** Digest finalisation function */ 67 | void (*finish_func)( void *ctx, unsigned char *output ); 68 | 69 | /** Generic digest function */ 70 | void (*digest_func)( const unsigned char *input, size_t ilen, 71 | unsigned char *output ); 72 | 73 | /** Allocate a new context */ 74 | void * (*ctx_alloc_func)( void ); 75 | 76 | /** Free the given context */ 77 | void (*ctx_free_func)( void *ctx ); 78 | 79 | /** Clone state from a context */ 80 | void (*clone_func)( void *dst, const void *src ); 81 | 82 | /** Internal use only */ 83 | void (*process_func)( void *ctx, const unsigned char *input ); 84 | }; 85 | 86 | #if defined(MBEDTLS_MD2_C) 87 | extern const mbedtls_md_info_t mbedtls_md2_info; 88 | #endif 89 | #if defined(MBEDTLS_MD4_C) 90 | extern const mbedtls_md_info_t mbedtls_md4_info; 91 | #endif 92 | #if defined(MBEDTLS_MD5_C) 93 | extern const mbedtls_md_info_t mbedtls_md5_info; 94 | #endif 95 | #if defined(MBEDTLS_RIPEMD160_C) 96 | extern const mbedtls_md_info_t mbedtls_ripemd160_info; 97 | #endif 98 | #if defined(MBEDTLS_SHA1_C) 99 | extern const mbedtls_md_info_t mbedtls_sha1_info; 100 | #endif 101 | #if defined(MBEDTLS_SHA256_C) 102 | extern const mbedtls_md_info_t mbedtls_sha224_info; 103 | extern const mbedtls_md_info_t mbedtls_sha256_info; 104 | #endif 105 | #if defined(MBEDTLS_SHA512_C) 106 | extern const mbedtls_md_info_t mbedtls_sha384_info; 107 | extern const mbedtls_md_info_t mbedtls_sha512_info; 108 | #endif 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | 114 | #endif /* MBEDTLS_MD_WRAP_H */ 115 | -------------------------------------------------------------------------------- /src/mbedtls/mtk.cpp: -------------------------------------------------------------------------------- 1 | #include "mtk.h" 2 | 3 | VMINT g_bearer_hdl; 4 | 5 | //VMSTR ca_path = "facebookcert.cer"; 6 | 7 | int ret_connect = -1; 8 | int con_ret = -1; 9 | int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, const char *port, int proto ); 10 | //int ret, len; 11 | //mbedtls_net_context server_fd; 12 | unsigned char buf[1024]; 13 | //const char *pers = "WifiWebClient"; 14 | // path to certification file 15 | 16 | const char* CONNECT_IP_ADDRESS; 17 | VMINT CONNECT_PORT; 18 | // mbedtls_entropy_context entropy; 19 | // mbedtls_ctr_drbg_context ctr_drbg; 20 | // mbedtls_ssl_context ssl; 21 | // mbedtls_ssl_config conf; 22 | 23 | // mbedtls_x509_crt cacert; 24 | // mbedtls_x509_crt clicert; 25 | // mbedtls_pk_context pkey; 26 | // uint32_t flags; 27 | 28 | //SOCKADDR_IN t_addr_in = {0}; 29 | //int t_ai_socktype; /* Socket type. */ 30 | //int t_ai_protocol; /* Protocol of socket. */ 31 | //uint32_t t_ai_addrlen; /* Length of socket address. */ -------------------------------------------------------------------------------- /src/mbedtls/mtk.h: -------------------------------------------------------------------------------- 1 | #ifndef _mtk_ 2 | #define _mtk_ 3 | 4 | #include "net.h" 5 | #include "debug.h" 6 | #include "ssl.h" 7 | #include "entropy.h" 8 | #include "ctr_drbg.h" 9 | #include "error.h" 10 | #include "certs.h" 11 | #include "vmsys.h" 12 | #include "vmsock.h" 13 | 14 | #define VM_IS_SUCCEEDED(x) (((x)>=0)?VM_TRUE:VM_FALSE) /* Use this macro to determine if a VM_RESULT is a success or not. */ 15 | 16 | extern VMINT g_bearer_hdl; 17 | 18 | extern VMSTR ca_path; 19 | 20 | extern int ret_connect; 21 | extern int con_ret; 22 | extern int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, const char *port, int proto ); 23 | //extern int ret, len; 24 | //extern mbedtls_net_context server_fd; 25 | extern unsigned char buf[1024]; 26 | //extern const char *pers; 27 | 28 | extern void myprint(char *str); 29 | extern void myprintln(char *str); 30 | 31 | extern const char* CONNECT_IP_ADDRESS; 32 | extern VMINT CONNECT_PORT; 33 | 34 | // extern SOCKADDR_IN t_addr_in = {0}; 35 | // extern int t_ai_socktype; /* Socket type. */ 36 | // extern int t_ai_protocol; /* Protocol of socket. */ 37 | // extern uint32_t t_ai_addrlen; /* Length of socket address. */ 38 | 39 | // extern mbedtls_entropy_context entropy; 40 | // extern mbedtls_ctr_drbg_context ctr_drbg; 41 | // extern mbedtls_ssl_context ssl; 42 | // extern mbedtls_ssl_config conf; 43 | 44 | // extern mbedtls_x509_crt cacert; 45 | // extern mbedtls_x509_crt clicert; 46 | // extern mbedtls_pk_context pkey; 47 | // extern uint32_t flags; 48 | #endif -------------------------------------------------------------------------------- /src/mbedtls/myprintWrapper.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern "C" { 4 | void myprint(char* str) 5 | { 6 | Serial.print(str); 7 | } 8 | } 9 | 10 | extern "C" { 11 | void myprintln(char* str) 12 | { 13 | Serial.println(str); 14 | } 15 | } -------------------------------------------------------------------------------- /src/mbedtls/padlock.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file padlock.h 3 | * 4 | * \brief VIA PadLock ACE for HW encryption/decryption supported by some 5 | * processors 6 | * 7 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 8 | * SPDX-License-Identifier: Apache-2.0 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 11 | * not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 18 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * 22 | * This file is part of mbed TLS (https://tls.mbed.org) 23 | */ 24 | #ifndef MBEDTLS_PADLOCK_H 25 | #define MBEDTLS_PADLOCK_H 26 | 27 | #include "aes.h" 28 | 29 | #define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */ 30 | 31 | #if defined(__has_feature) 32 | #if __has_feature(address_sanitizer) 33 | #define MBEDTLS_HAVE_ASAN 34 | #endif 35 | #endif 36 | 37 | /* Some versions of ASan result in errors about not enough registers */ 38 | #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \ 39 | !defined(MBEDTLS_HAVE_ASAN) 40 | 41 | #ifndef MBEDTLS_HAVE_X86 42 | #define MBEDTLS_HAVE_X86 43 | #endif 44 | 45 | #include 46 | 47 | #define MBEDTLS_PADLOCK_RNG 0x000C 48 | #define MBEDTLS_PADLOCK_ACE 0x00C0 49 | #define MBEDTLS_PADLOCK_PHE 0x0C00 50 | #define MBEDTLS_PADLOCK_PMM 0x3000 51 | 52 | #define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15)) 53 | 54 | #ifdef __cplusplus 55 | extern "C" { 56 | #endif 57 | 58 | /** 59 | * \brief PadLock detection routine 60 | * 61 | * \param feature The feature to detect 62 | * 63 | * \return 1 if CPU has support for the feature, 0 otherwise 64 | */ 65 | int mbedtls_padlock_has_support( int feature ); 66 | 67 | /** 68 | * \brief PadLock AES-ECB block en(de)cryption 69 | * 70 | * \param ctx AES context 71 | * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT 72 | * \param input 16-byte input block 73 | * \param output 16-byte output block 74 | * 75 | * \return 0 if success, 1 if operation failed 76 | */ 77 | int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx, 78 | int mode, 79 | const unsigned char input[16], 80 | unsigned char output[16] ); 81 | 82 | /** 83 | * \brief PadLock AES-CBC buffer en(de)cryption 84 | * 85 | * \param ctx AES context 86 | * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT 87 | * \param length length of the input data 88 | * \param iv initialization vector (updated after use) 89 | * \param input buffer holding the input data 90 | * \param output buffer holding the output data 91 | * 92 | * \return 0 if success, 1 if operation failed 93 | */ 94 | int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx, 95 | int mode, 96 | size_t length, 97 | unsigned char iv[16], 98 | const unsigned char *input, 99 | unsigned char *output ); 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif /* HAVE_X86 */ 106 | 107 | #endif /* padlock.h */ 108 | -------------------------------------------------------------------------------- /src/mbedtls/pk_internal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file pk.h 3 | * 4 | * \brief Public Key abstraction layer: wrapper functions 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | 24 | #ifndef MBEDTLS_PK_WRAP_H 25 | #define MBEDTLS_PK_WRAP_H 26 | 27 | #if !defined(MBEDTLS_CONFIG_FILE) 28 | #include "config.h" 29 | #else 30 | #include MBEDTLS_CONFIG_FILE 31 | #endif 32 | 33 | #include "pk.h" 34 | 35 | struct mbedtls_pk_info_t 36 | { 37 | /** Public key type */ 38 | mbedtls_pk_type_t type; 39 | 40 | /** Type name */ 41 | const char *name; 42 | 43 | /** Get key size in bits */ 44 | size_t (*get_bitlen)( const void * ); 45 | 46 | /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */ 47 | int (*can_do)( mbedtls_pk_type_t type ); 48 | 49 | /** Verify signature */ 50 | int (*verify_func)( void *ctx, mbedtls_md_type_t md_alg, 51 | const unsigned char *hash, size_t hash_len, 52 | const unsigned char *sig, size_t sig_len ); 53 | 54 | /** Make signature */ 55 | int (*sign_func)( void *ctx, mbedtls_md_type_t md_alg, 56 | const unsigned char *hash, size_t hash_len, 57 | unsigned char *sig, size_t *sig_len, 58 | int (*f_rng)(void *, unsigned char *, size_t), 59 | void *p_rng ); 60 | 61 | /** Decrypt message */ 62 | int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen, 63 | unsigned char *output, size_t *olen, size_t osize, 64 | int (*f_rng)(void *, unsigned char *, size_t), 65 | void *p_rng ); 66 | 67 | /** Encrypt message */ 68 | int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen, 69 | unsigned char *output, size_t *olen, size_t osize, 70 | int (*f_rng)(void *, unsigned char *, size_t), 71 | void *p_rng ); 72 | 73 | /** Check public-private key pair */ 74 | int (*check_pair_func)( const void *pub, const void *prv ); 75 | 76 | /** Allocate a new context */ 77 | void * (*ctx_alloc_func)( void ); 78 | 79 | /** Free the given context */ 80 | void (*ctx_free_func)( void *ctx ); 81 | 82 | /** Interface with the debug module */ 83 | void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items ); 84 | 85 | }; 86 | #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) 87 | /* Container for RSA-alt */ 88 | typedef struct 89 | { 90 | void *key; 91 | mbedtls_pk_rsa_alt_decrypt_func decrypt_func; 92 | mbedtls_pk_rsa_alt_sign_func sign_func; 93 | mbedtls_pk_rsa_alt_key_len_func key_len_func; 94 | } mbedtls_rsa_alt_context; 95 | #endif 96 | 97 | #if defined(MBEDTLS_RSA_C) 98 | extern const mbedtls_pk_info_t mbedtls_rsa_info; 99 | #endif 100 | 101 | #if defined(MBEDTLS_ECP_C) 102 | extern const mbedtls_pk_info_t mbedtls_eckey_info; 103 | extern const mbedtls_pk_info_t mbedtls_eckeydh_info; 104 | #endif 105 | 106 | #if defined(MBEDTLS_ECDSA_C) 107 | extern const mbedtls_pk_info_t mbedtls_ecdsa_info; 108 | #endif 109 | 110 | #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) 111 | extern const mbedtls_pk_info_t mbedtls_rsa_alt_info; 112 | #endif 113 | 114 | #endif /* MBEDTLS_PK_WRAP_H */ 115 | -------------------------------------------------------------------------------- /src/mbedtls/pkcs5.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file pkcs5.h 3 | * 4 | * \brief PKCS#5 functions 5 | * 6 | * \author Mathias Olsson 7 | * 8 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 9 | * SPDX-License-Identifier: Apache-2.0 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 12 | * not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 19 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | * This file is part of mbed TLS (https://tls.mbed.org) 24 | */ 25 | #ifndef MBEDTLS_PKCS5_H 26 | #define MBEDTLS_PKCS5_H 27 | 28 | #include "asn1.h" 29 | #include "md.h" 30 | 31 | #include 32 | #include 33 | 34 | #define MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA -0x2f80 /**< Bad input parameters to function. */ 35 | #define MBEDTLS_ERR_PKCS5_INVALID_FORMAT -0x2f00 /**< Unexpected ASN.1 data. */ 36 | #define MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE -0x2e80 /**< Requested encryption or digest alg not available. */ 37 | #define MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH -0x2e00 /**< Given private key password does not allow for correct decryption. */ 38 | 39 | #define MBEDTLS_PKCS5_DECRYPT 0 40 | #define MBEDTLS_PKCS5_ENCRYPT 1 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** 47 | * \brief PKCS#5 PBES2 function 48 | * 49 | * \param pbe_params the ASN.1 algorithm parameters 50 | * \param mode either MBEDTLS_PKCS5_DECRYPT or MBEDTLS_PKCS5_ENCRYPT 51 | * \param pwd password to use when generating key 52 | * \param pwdlen length of password 53 | * \param data data to process 54 | * \param datalen length of data 55 | * \param output output buffer 56 | * 57 | * \returns 0 on success, or a MBEDTLS_ERR_XXX code if verification fails. 58 | */ 59 | int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode, 60 | const unsigned char *pwd, size_t pwdlen, 61 | const unsigned char *data, size_t datalen, 62 | unsigned char *output ); 63 | 64 | /** 65 | * \brief PKCS#5 PBKDF2 using HMAC 66 | * 67 | * \param ctx Generic HMAC context 68 | * \param password Password to use when generating key 69 | * \param plen Length of password 70 | * \param salt Salt to use when generating key 71 | * \param slen Length of salt 72 | * \param iteration_count Iteration count 73 | * \param key_length Length of generated key in bytes 74 | * \param output Generated key. Must be at least as big as key_length 75 | * 76 | * \returns 0 on success, or a MBEDTLS_ERR_XXX code if verification fails. 77 | */ 78 | int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, const unsigned char *password, 79 | size_t plen, const unsigned char *salt, size_t slen, 80 | unsigned int iteration_count, 81 | uint32_t key_length, unsigned char *output ); 82 | 83 | /** 84 | * \brief Checkup routine 85 | * 86 | * \return 0 if successful, or 1 if the test failed 87 | */ 88 | int mbedtls_pkcs5_self_test( int verbose ); 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #endif /* pkcs5.h */ 95 | -------------------------------------------------------------------------------- /src/mbedtls/ripemd160.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file mbedtls_ripemd160.h 3 | * 4 | * \brief RIPE MD-160 message digest 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_RIPEMD160_H 24 | #define MBEDTLS_RIPEMD160_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | #if !defined(MBEDTLS_RIPEMD160_ALT) 36 | // Regular implementation 37 | // 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** 44 | * \brief RIPEMD-160 context structure 45 | */ 46 | typedef struct 47 | { 48 | uint32_t total[2]; /*!< number of bytes processed */ 49 | uint32_t state[5]; /*!< intermediate digest state */ 50 | unsigned char buffer[64]; /*!< data block being processed */ 51 | } 52 | mbedtls_ripemd160_context; 53 | 54 | /** 55 | * \brief Initialize RIPEMD-160 context 56 | * 57 | * \param ctx RIPEMD-160 context to be initialized 58 | */ 59 | void mbedtls_ripemd160_init( mbedtls_ripemd160_context *ctx ); 60 | 61 | /** 62 | * \brief Clear RIPEMD-160 context 63 | * 64 | * \param ctx RIPEMD-160 context to be cleared 65 | */ 66 | void mbedtls_ripemd160_free( mbedtls_ripemd160_context *ctx ); 67 | 68 | /** 69 | * \brief Clone (the state of) an RIPEMD-160 context 70 | * 71 | * \param dst The destination context 72 | * \param src The context to be cloned 73 | */ 74 | void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst, 75 | const mbedtls_ripemd160_context *src ); 76 | 77 | /** 78 | * \brief RIPEMD-160 context setup 79 | * 80 | * \param ctx context to be initialized 81 | */ 82 | void mbedtls_ripemd160_starts( mbedtls_ripemd160_context *ctx ); 83 | 84 | /** 85 | * \brief RIPEMD-160 process buffer 86 | * 87 | * \param ctx RIPEMD-160 context 88 | * \param input buffer holding the data 89 | * \param ilen length of the input data 90 | */ 91 | void mbedtls_ripemd160_update( mbedtls_ripemd160_context *ctx, 92 | const unsigned char *input, size_t ilen ); 93 | 94 | /** 95 | * \brief RIPEMD-160 final digest 96 | * 97 | * \param ctx RIPEMD-160 context 98 | * \param output RIPEMD-160 checksum result 99 | */ 100 | void mbedtls_ripemd160_finish( mbedtls_ripemd160_context *ctx, unsigned char output[20] ); 101 | 102 | /* Internal use */ 103 | void mbedtls_ripemd160_process( mbedtls_ripemd160_context *ctx, const unsigned char data[64] ); 104 | 105 | #ifdef __cplusplus 106 | } 107 | #endif 108 | 109 | #else /* MBEDTLS_RIPEMD160_ALT */ 110 | #include "ripemd160.h" 111 | #endif /* MBEDTLS_RIPEMD160_ALT */ 112 | 113 | #ifdef __cplusplus 114 | extern "C" { 115 | #endif 116 | 117 | /** 118 | * \brief Output = RIPEMD-160( input buffer ) 119 | * 120 | * \param input buffer holding the data 121 | * \param ilen length of the input data 122 | * \param output RIPEMD-160 checksum result 123 | */ 124 | void mbedtls_ripemd160( const unsigned char *input, size_t ilen, 125 | unsigned char output[20] ); 126 | 127 | /** 128 | * \brief Checkup routine 129 | * 130 | * \return 0 if successful, or 1 if the test failed 131 | */ 132 | int mbedtls_ripemd160_self_test( int verbose ); 133 | 134 | #ifdef __cplusplus 135 | } 136 | #endif 137 | 138 | #endif /* mbedtls_ripemd160.h */ 139 | -------------------------------------------------------------------------------- /src/mbedtls/sha1.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file mbedtls_sha1.h 3 | * 4 | * \brief SHA-1 cryptographic hash function 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_SHA1_H 24 | #define MBEDTLS_SHA1_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | #if !defined(MBEDTLS_SHA1_ALT) 36 | // Regular implementation 37 | // 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** 44 | * \brief SHA-1 context structure 45 | */ 46 | typedef struct 47 | { 48 | uint32_t total[2]; /*!< number of bytes processed */ 49 | uint32_t state[5]; /*!< intermediate digest state */ 50 | unsigned char buffer[64]; /*!< data block being processed */ 51 | } 52 | mbedtls_sha1_context; 53 | 54 | /** 55 | * \brief Initialize SHA-1 context 56 | * 57 | * \param ctx SHA-1 context to be initialized 58 | */ 59 | void mbedtls_sha1_init( mbedtls_sha1_context *ctx ); 60 | 61 | /** 62 | * \brief Clear SHA-1 context 63 | * 64 | * \param ctx SHA-1 context to be cleared 65 | */ 66 | void mbedtls_sha1_free( mbedtls_sha1_context *ctx ); 67 | 68 | /** 69 | * \brief Clone (the state of) a SHA-1 context 70 | * 71 | * \param dst The destination context 72 | * \param src The context to be cloned 73 | */ 74 | void mbedtls_sha1_clone( mbedtls_sha1_context *dst, 75 | const mbedtls_sha1_context *src ); 76 | 77 | /** 78 | * \brief SHA-1 context setup 79 | * 80 | * \param ctx context to be initialized 81 | */ 82 | void mbedtls_sha1_starts( mbedtls_sha1_context *ctx ); 83 | 84 | /** 85 | * \brief SHA-1 process buffer 86 | * 87 | * \param ctx SHA-1 context 88 | * \param input buffer holding the data 89 | * \param ilen length of the input data 90 | */ 91 | void mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen ); 92 | 93 | /** 94 | * \brief SHA-1 final digest 95 | * 96 | * \param ctx SHA-1 context 97 | * \param output SHA-1 checksum result 98 | */ 99 | void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, unsigned char output[20] ); 100 | 101 | /* Internal use */ 102 | void mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[64] ); 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #else /* MBEDTLS_SHA1_ALT */ 109 | #include "sha1_alt.h" 110 | #endif /* MBEDTLS_SHA1_ALT */ 111 | 112 | #ifdef __cplusplus 113 | extern "C" { 114 | #endif 115 | 116 | /** 117 | * \brief Output = SHA-1( input buffer ) 118 | * 119 | * \param input buffer holding the data 120 | * \param ilen length of the input data 121 | * \param output SHA-1 checksum result 122 | */ 123 | void mbedtls_sha1( const unsigned char *input, size_t ilen, unsigned char output[20] ); 124 | 125 | /** 126 | * \brief Checkup routine 127 | * 128 | * \return 0 if successful, or 1 if the test failed 129 | */ 130 | int mbedtls_sha1_self_test( int verbose ); 131 | 132 | #ifdef __cplusplus 133 | } 134 | #endif 135 | 136 | #endif /* mbedtls_sha1.h */ 137 | -------------------------------------------------------------------------------- /src/mbedtls/sha256.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file mbedtls_sha256.h 3 | * 4 | * \brief SHA-224 and SHA-256 cryptographic hash function 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_SHA256_H 24 | #define MBEDTLS_SHA256_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | #if !defined(MBEDTLS_SHA256_ALT) 36 | // Regular implementation 37 | // 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** 44 | * \brief SHA-256 context structure 45 | */ 46 | typedef struct 47 | { 48 | uint32_t total[2]; /*!< number of bytes processed */ 49 | uint32_t state[8]; /*!< intermediate digest state */ 50 | unsigned char buffer[64]; /*!< data block being processed */ 51 | int is224; /*!< 0 => SHA-256, else SHA-224 */ 52 | } 53 | mbedtls_sha256_context; 54 | 55 | /** 56 | * \brief Initialize SHA-256 context 57 | * 58 | * \param ctx SHA-256 context to be initialized 59 | */ 60 | void mbedtls_sha256_init( mbedtls_sha256_context *ctx ); 61 | 62 | /** 63 | * \brief Clear SHA-256 context 64 | * 65 | * \param ctx SHA-256 context to be cleared 66 | */ 67 | void mbedtls_sha256_free( mbedtls_sha256_context *ctx ); 68 | 69 | /** 70 | * \brief Clone (the state of) a SHA-256 context 71 | * 72 | * \param dst The destination context 73 | * \param src The context to be cloned 74 | */ 75 | void mbedtls_sha256_clone( mbedtls_sha256_context *dst, 76 | const mbedtls_sha256_context *src ); 77 | 78 | /** 79 | * \brief SHA-256 context setup 80 | * 81 | * \param ctx context to be initialized 82 | * \param is224 0 = use SHA256, 1 = use SHA224 83 | */ 84 | void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 ); 85 | 86 | /** 87 | * \brief SHA-256 process buffer 88 | * 89 | * \param ctx SHA-256 context 90 | * \param input buffer holding the data 91 | * \param ilen length of the input data 92 | */ 93 | void mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *input, 94 | size_t ilen ); 95 | 96 | /** 97 | * \brief SHA-256 final digest 98 | * 99 | * \param ctx SHA-256 context 100 | * \param output SHA-224/256 checksum result 101 | */ 102 | void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32] ); 103 | 104 | /* Internal use */ 105 | void mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[64] ); 106 | 107 | #ifdef __cplusplus 108 | } 109 | #endif 110 | 111 | #else /* MBEDTLS_SHA256_ALT */ 112 | #include "sha256_alt.h" 113 | #endif /* MBEDTLS_SHA256_ALT */ 114 | 115 | #ifdef __cplusplus 116 | extern "C" { 117 | #endif 118 | 119 | /** 120 | * \brief Output = SHA-256( input buffer ) 121 | * 122 | * \param input buffer holding the data 123 | * \param ilen length of the input data 124 | * \param output SHA-224/256 checksum result 125 | * \param is224 0 = use SHA256, 1 = use SHA224 126 | */ 127 | void mbedtls_sha256( const unsigned char *input, size_t ilen, 128 | unsigned char output[32], int is224 ); 129 | 130 | /** 131 | * \brief Checkup routine 132 | * 133 | * \return 0 if successful, or 1 if the test failed 134 | */ 135 | int mbedtls_sha256_self_test( int verbose ); 136 | 137 | #ifdef __cplusplus 138 | } 139 | #endif 140 | 141 | #endif /* mbedtls_sha256.h */ 142 | -------------------------------------------------------------------------------- /src/mbedtls/sha512.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file mbedtls_sha512.h 3 | * 4 | * \brief SHA-384 and SHA-512 cryptographic hash function 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_SHA512_H 24 | #define MBEDTLS_SHA512_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | #if !defined(MBEDTLS_SHA512_ALT) 36 | // Regular implementation 37 | // 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** 44 | * \brief SHA-512 context structure 45 | */ 46 | typedef struct 47 | { 48 | uint64_t total[2]; /*!< number of bytes processed */ 49 | uint64_t state[8]; /*!< intermediate digest state */ 50 | unsigned char buffer[128]; /*!< data block being processed */ 51 | int is384; /*!< 0 => SHA-512, else SHA-384 */ 52 | } 53 | mbedtls_sha512_context; 54 | 55 | /** 56 | * \brief Initialize SHA-512 context 57 | * 58 | * \param ctx SHA-512 context to be initialized 59 | */ 60 | void mbedtls_sha512_init( mbedtls_sha512_context *ctx ); 61 | 62 | /** 63 | * \brief Clear SHA-512 context 64 | * 65 | * \param ctx SHA-512 context to be cleared 66 | */ 67 | void mbedtls_sha512_free( mbedtls_sha512_context *ctx ); 68 | 69 | /** 70 | * \brief Clone (the state of) a SHA-512 context 71 | * 72 | * \param dst The destination context 73 | * \param src The context to be cloned 74 | */ 75 | void mbedtls_sha512_clone( mbedtls_sha512_context *dst, 76 | const mbedtls_sha512_context *src ); 77 | 78 | /** 79 | * \brief SHA-512 context setup 80 | * 81 | * \param ctx context to be initialized 82 | * \param is384 0 = use SHA512, 1 = use SHA384 83 | */ 84 | void mbedtls_sha512_starts( mbedtls_sha512_context *ctx, int is384 ); 85 | 86 | /** 87 | * \brief SHA-512 process buffer 88 | * 89 | * \param ctx SHA-512 context 90 | * \param input buffer holding the data 91 | * \param ilen length of the input data 92 | */ 93 | void mbedtls_sha512_update( mbedtls_sha512_context *ctx, const unsigned char *input, 94 | size_t ilen ); 95 | 96 | /** 97 | * \brief SHA-512 final digest 98 | * 99 | * \param ctx SHA-512 context 100 | * \param output SHA-384/512 checksum result 101 | */ 102 | void mbedtls_sha512_finish( mbedtls_sha512_context *ctx, unsigned char output[64] ); 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #else /* MBEDTLS_SHA512_ALT */ 109 | #include "sha512_alt.h" 110 | #endif /* MBEDTLS_SHA512_ALT */ 111 | 112 | #ifdef __cplusplus 113 | extern "C" { 114 | #endif 115 | 116 | /** 117 | * \brief Output = SHA-512( input buffer ) 118 | * 119 | * \param input buffer holding the data 120 | * \param ilen length of the input data 121 | * \param output SHA-384/512 checksum result 122 | * \param is384 0 = use SHA512, 1 = use SHA384 123 | */ 124 | void mbedtls_sha512( const unsigned char *input, size_t ilen, 125 | unsigned char output[64], int is384 ); 126 | 127 | /** 128 | * \brief Checkup routine 129 | * 130 | * \return 0 if successful, or 1 if the test failed 131 | */ 132 | int mbedtls_sha512_self_test( int verbose ); 133 | 134 | /* Internal use */ 135 | void mbedtls_sha512_process( mbedtls_sha512_context *ctx, const unsigned char data[128] ); 136 | 137 | #ifdef __cplusplus 138 | } 139 | #endif 140 | 141 | #endif /* mbedtls_sha512.h */ 142 | -------------------------------------------------------------------------------- /src/mbedtls/ssl_cache.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file ssl_cache.h 3 | * 4 | * \brief SSL session cache implementation 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_SSL_CACHE_H 24 | #define MBEDTLS_SSL_CACHE_H 25 | 26 | #include "ssl.h" 27 | 28 | #if defined(MBEDTLS_THREADING_C) 29 | #include "threading.h" 30 | #endif 31 | 32 | /** 33 | * \name SECTION: Module settings 34 | * 35 | * The configuration options you can set for this module are in this section. 36 | * Either change them in config.h or define them on the compiler command line. 37 | * \{ 38 | */ 39 | 40 | #if !defined(MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT) 41 | #define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 86400 /*!< 1 day */ 42 | #endif 43 | 44 | #if !defined(MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES) 45 | #define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /*!< Maximum entries in cache */ 46 | #endif 47 | 48 | /* \} name SECTION: Module settings */ 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | 54 | typedef struct mbedtls_ssl_cache_context mbedtls_ssl_cache_context; 55 | typedef struct mbedtls_ssl_cache_entry mbedtls_ssl_cache_entry; 56 | 57 | /** 58 | * \brief This structure is used for storing cache entries 59 | */ 60 | struct mbedtls_ssl_cache_entry 61 | { 62 | #if defined(MBEDTLS_HAVE_TIME) 63 | time_t timestamp; /*!< entry timestamp */ 64 | #endif 65 | mbedtls_ssl_session session; /*!< entry session */ 66 | #if defined(MBEDTLS_X509_CRT_PARSE_C) 67 | mbedtls_x509_buf peer_cert; /*!< entry peer_cert */ 68 | #endif 69 | mbedtls_ssl_cache_entry *next; /*!< chain pointer */ 70 | }; 71 | 72 | /** 73 | * \brief Cache context 74 | */ 75 | struct mbedtls_ssl_cache_context 76 | { 77 | mbedtls_ssl_cache_entry *chain; /*!< start of the chain */ 78 | int timeout; /*!< cache entry timeout */ 79 | int max_entries; /*!< maximum entries */ 80 | #if defined(MBEDTLS_THREADING_C) 81 | mbedtls_threading_mutex_t mutex; /*!< mutex */ 82 | #endif 83 | }; 84 | 85 | /** 86 | * \brief Initialize an SSL cache context 87 | * 88 | * \param cache SSL cache context 89 | */ 90 | void mbedtls_ssl_cache_init( mbedtls_ssl_cache_context *cache ); 91 | 92 | /** 93 | * \brief Cache get callback implementation 94 | * (Thread-safe if MBEDTLS_THREADING_C is enabled) 95 | * 96 | * \param data SSL cache context 97 | * \param session session to retrieve entry for 98 | */ 99 | int mbedtls_ssl_cache_get( void *data, mbedtls_ssl_session *session ); 100 | 101 | /** 102 | * \brief Cache set callback implementation 103 | * (Thread-safe if MBEDTLS_THREADING_C is enabled) 104 | * 105 | * \param data SSL cache context 106 | * \param session session to store entry for 107 | */ 108 | int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session ); 109 | 110 | #if defined(MBEDTLS_HAVE_TIME) 111 | /** 112 | * \brief Set the cache timeout 113 | * (Default: MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT (1 day)) 114 | * 115 | * A timeout of 0 indicates no timeout. 116 | * 117 | * \param cache SSL cache context 118 | * \param timeout cache entry timeout in seconds 119 | */ 120 | void mbedtls_ssl_cache_set_timeout( mbedtls_ssl_cache_context *cache, int timeout ); 121 | #endif /* MBEDTLS_HAVE_TIME */ 122 | 123 | /** 124 | * \brief Set the cache timeout 125 | * (Default: MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES (50)) 126 | * 127 | * \param cache SSL cache context 128 | * \param max cache entry maximum 129 | */ 130 | void mbedtls_ssl_cache_set_max_entries( mbedtls_ssl_cache_context *cache, int max ); 131 | 132 | /** 133 | * \brief Free referenced items in a cache context and clear memory 134 | * 135 | * \param cache SSL cache context 136 | */ 137 | void mbedtls_ssl_cache_free( mbedtls_ssl_cache_context *cache ); 138 | 139 | #ifdef __cplusplus 140 | } 141 | #endif 142 | 143 | #endif /* ssl_cache.h */ 144 | -------------------------------------------------------------------------------- /src/mbedtls/ssl_cookie.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file ssl_cookie.h 3 | * 4 | * \brief DTLS cookie callbacks implementation 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_SSL_COOKIE_H 24 | #define MBEDTLS_SSL_COOKIE_H 25 | 26 | #include "ssl.h" 27 | 28 | #if defined(MBEDTLS_THREADING_C) 29 | #include "threading.h" 30 | #endif 31 | 32 | /** 33 | * \name SECTION: Module settings 34 | * 35 | * The configuration options you can set for this module are in this section. 36 | * Either change them in config.h or define them on the compiler command line. 37 | * \{ 38 | */ 39 | #ifndef MBEDTLS_SSL_COOKIE_TIMEOUT 40 | #define MBEDTLS_SSL_COOKIE_TIMEOUT 60 /**< Default expiration delay of DTLS cookies, in seconds if HAVE_TIME, or in number of cookies issued */ 41 | #endif 42 | 43 | /* \} name SECTION: Module settings */ 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | /** 50 | * \brief Context for the default cookie functions. 51 | */ 52 | typedef struct 53 | { 54 | mbedtls_md_context_t hmac_ctx; /*!< context for the HMAC portion */ 55 | #if !defined(MBEDTLS_HAVE_TIME) 56 | unsigned long serial; /*!< serial number for expiration */ 57 | #endif 58 | unsigned long timeout; /*!< timeout delay, in seconds if HAVE_TIME, 59 | or in number of tickets issued */ 60 | 61 | #if defined(MBEDTLS_THREADING_C) 62 | mbedtls_threading_mutex_t mutex; 63 | #endif 64 | } mbedtls_ssl_cookie_ctx; 65 | 66 | /** 67 | * \brief Initialize cookie context 68 | */ 69 | void mbedtls_ssl_cookie_init( mbedtls_ssl_cookie_ctx *ctx ); 70 | 71 | /** 72 | * \brief Setup cookie context (generate keys) 73 | */ 74 | int mbedtls_ssl_cookie_setup( mbedtls_ssl_cookie_ctx *ctx, 75 | int (*f_rng)(void *, unsigned char *, size_t), 76 | void *p_rng ); 77 | 78 | /** 79 | * \brief Set expiration delay for cookies 80 | * (Default MBEDTLS_SSL_COOKIE_TIMEOUT) 81 | * 82 | * \param ctx Cookie contex 83 | * \param delay Delay, in seconds if HAVE_TIME, or in number of cookies 84 | * issued in the meantime. 85 | * 0 to disable expiration (NOT recommended) 86 | */ 87 | void mbedtls_ssl_cookie_set_timeout( mbedtls_ssl_cookie_ctx *ctx, unsigned long delay ); 88 | 89 | /** 90 | * \brief Free cookie context 91 | */ 92 | void mbedtls_ssl_cookie_free( mbedtls_ssl_cookie_ctx *ctx ); 93 | 94 | /** 95 | * \brief Generate cookie, see \c mbedtls_ssl_cookie_write_t 96 | */ 97 | mbedtls_ssl_cookie_write_t mbedtls_ssl_cookie_write; 98 | 99 | /** 100 | * \brief Verify cookie, see \c mbedtls_ssl_cookie_write_t 101 | */ 102 | mbedtls_ssl_cookie_check_t mbedtls_ssl_cookie_check; 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif /* ssl_cookie.h */ 109 | -------------------------------------------------------------------------------- /src/mbedtls/ssl_ticket.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file ssl_ticket.h 3 | * 4 | * \brief TLS server ticket callbacks implementation 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_SSL_TICKET_H 24 | #define MBEDTLS_SSL_TICKET_H 25 | 26 | /* 27 | * This implementation of the session ticket callbacks includes key 28 | * management, rotating the keys periodically in order to preserve forward 29 | * secrecy, when MBEDTLS_HAVE_TIME is defined. 30 | */ 31 | 32 | #include "ssl.h" 33 | #include "cipher.h" 34 | 35 | #if defined(MBEDTLS_THREADING_C) 36 | #include "threading.h" 37 | #endif 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** 44 | * \brief Information for session ticket protection 45 | */ 46 | typedef struct 47 | { 48 | unsigned char name[4]; /*!< random key identifier */ 49 | uint32_t generation_time; /*!< key generation timestamp (seconds) */ 50 | mbedtls_cipher_context_t ctx; /*!< context for auth enc/decryption */ 51 | } 52 | mbedtls_ssl_ticket_key; 53 | 54 | /** 55 | * \brief Context for session ticket handling functions 56 | */ 57 | typedef struct 58 | { 59 | mbedtls_ssl_ticket_key keys[2]; /*!< ticket protection keys */ 60 | unsigned char active; /*!< index of the currently active key */ 61 | 62 | uint32_t ticket_lifetime; /*!< lifetime of tickets in seconds */ 63 | 64 | /** Callback for getting (pseudo-)random numbers */ 65 | int (*f_rng)(void *, unsigned char *, size_t); 66 | void *p_rng; /*!< context for the RNG function */ 67 | 68 | #if defined(MBEDTLS_THREADING_C) 69 | mbedtls_threading_mutex_t mutex; 70 | #endif 71 | } 72 | mbedtls_ssl_ticket_context; 73 | 74 | /** 75 | * \brief Initialize a ticket context. 76 | * (Just make it ready for mbedtls_ssl_ticket_setup() 77 | * or mbedtls_ssl_ticket_free().) 78 | * 79 | * \param ctx Context to be initialized 80 | */ 81 | void mbedtls_ssl_ticket_init( mbedtls_ssl_ticket_context *ctx ); 82 | 83 | /** 84 | * \brief Prepare context to be actually used 85 | * 86 | * \param ctx Context to be set up 87 | * \param f_rng RNG callback function 88 | * \param p_rng RNG callback context 89 | * \param cipher AEAD cipher to use for ticket protection. 90 | * Recommended value: MBEDTLS_CIPHER_AES_256_GCM. 91 | * \param lifetime Tickets lifetime in seconds 92 | * Recommended value: 86400 (one day). 93 | * 94 | * \note It is highly recommended to select a cipher that is at 95 | * least as strong as the the strongest ciphersuite 96 | * supported. Usually that means a 256-bit key. 97 | * 98 | * \note The lifetime of the keys is twice the lifetime of tickets. 99 | * It is recommended to pick a reasonnable lifetime so as not 100 | * to negate the benefits of forward secrecy. 101 | * 102 | * \return 0 if successful, 103 | * or a specific MBEDTLS_ERR_XXX error code 104 | */ 105 | int mbedtls_ssl_ticket_setup( mbedtls_ssl_ticket_context *ctx, 106 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, 107 | mbedtls_cipher_type_t cipher, 108 | uint32_t lifetime ); 109 | 110 | /** 111 | * \brief Implementation of the ticket write callback 112 | * 113 | * \note See \c mbedlts_ssl_ticket_write_t for description 114 | */ 115 | mbedtls_ssl_ticket_write_t mbedtls_ssl_ticket_write; 116 | 117 | /** 118 | * \brief Implementation of the ticket parse callback 119 | * 120 | * \note See \c mbedlts_ssl_ticket_parse_t for description 121 | */ 122 | mbedtls_ssl_ticket_parse_t mbedtls_ssl_ticket_parse; 123 | 124 | /** 125 | * \brief Free a context's content and zeroize it. 126 | * 127 | * \param ctx Context to be cleaned up 128 | */ 129 | void mbedtls_ssl_ticket_free( mbedtls_ssl_ticket_context *ctx ); 130 | 131 | #ifdef __cplusplus 132 | } 133 | #endif 134 | 135 | #endif /* ssl_ticket.h */ 136 | -------------------------------------------------------------------------------- /src/mbedtls/threading.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Threading abstraction layer 3 | * 4 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 8 | * not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * This file is part of mbed TLS (https://tls.mbed.org) 20 | */ 21 | 22 | #if !defined(MBEDTLS_CONFIG_FILE) 23 | #include "config.h" 24 | #else 25 | #include MBEDTLS_CONFIG_FILE 26 | #endif 27 | 28 | #if defined(MBEDTLS_THREADING_C) 29 | 30 | #include "threading.h" 31 | 32 | #if defined(MBEDTLS_THREADING_PTHREAD) 33 | static void threading_mutex_init_pthread( mbedtls_threading_mutex_t *mutex ) 34 | { 35 | if( mutex == NULL ) 36 | return; 37 | 38 | mutex->is_valid = pthread_mutex_init( &mutex->mutex, NULL ) == 0; 39 | } 40 | 41 | static void threading_mutex_free_pthread( mbedtls_threading_mutex_t *mutex ) 42 | { 43 | if( mutex == NULL ) 44 | return; 45 | 46 | (void) pthread_mutex_destroy( &mutex->mutex ); 47 | } 48 | 49 | static int threading_mutex_lock_pthread( mbedtls_threading_mutex_t *mutex ) 50 | { 51 | if( mutex == NULL || ! mutex->is_valid ) 52 | return( MBEDTLS_ERR_THREADING_BAD_INPUT_DATA ); 53 | 54 | if( pthread_mutex_lock( &mutex->mutex ) != 0 ) 55 | return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); 56 | 57 | return( 0 ); 58 | } 59 | 60 | static int threading_mutex_unlock_pthread( mbedtls_threading_mutex_t *mutex ) 61 | { 62 | if( mutex == NULL || ! mutex->is_valid ) 63 | return( MBEDTLS_ERR_THREADING_BAD_INPUT_DATA ); 64 | 65 | if( pthread_mutex_unlock( &mutex->mutex ) != 0 ) 66 | return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); 67 | 68 | return( 0 ); 69 | } 70 | 71 | void (*mbedtls_mutex_init)( mbedtls_threading_mutex_t * ) = threading_mutex_init_pthread; 72 | void (*mbedtls_mutex_free)( mbedtls_threading_mutex_t * ) = threading_mutex_free_pthread; 73 | int (*mbedtls_mutex_lock)( mbedtls_threading_mutex_t * ) = threading_mutex_lock_pthread; 74 | int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t * ) = threading_mutex_unlock_pthread; 75 | 76 | /* 77 | * With phtreads we can statically initialize mutexes 78 | */ 79 | #define MUTEX_INIT = { PTHREAD_MUTEX_INITIALIZER, 1 } 80 | 81 | #endif /* MBEDTLS_THREADING_PTHREAD */ 82 | 83 | #if defined(MBEDTLS_THREADING_ALT) 84 | static int threading_mutex_fail( mbedtls_threading_mutex_t *mutex ) 85 | { 86 | ((void) mutex ); 87 | return( MBEDTLS_ERR_THREADING_BAD_INPUT_DATA ); 88 | } 89 | static void threading_mutex_dummy( mbedtls_threading_mutex_t *mutex ) 90 | { 91 | ((void) mutex ); 92 | return; 93 | } 94 | 95 | void (*mbedtls_mutex_init)( mbedtls_threading_mutex_t * ) = threading_mutex_dummy; 96 | void (*mbedtls_mutex_free)( mbedtls_threading_mutex_t * ) = threading_mutex_dummy; 97 | int (*mbedtls_mutex_lock)( mbedtls_threading_mutex_t * ) = threading_mutex_fail; 98 | int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t * ) = threading_mutex_fail; 99 | 100 | /* 101 | * Set functions pointers and initialize global mutexes 102 | */ 103 | void mbedtls_threading_set_alt( void (*mutex_init)( mbedtls_threading_mutex_t * ), 104 | void (*mutex_free)( mbedtls_threading_mutex_t * ), 105 | int (*mutex_lock)( mbedtls_threading_mutex_t * ), 106 | int (*mutex_unlock)( mbedtls_threading_mutex_t * ) ) 107 | { 108 | mbedtls_mutex_init = mutex_init; 109 | mbedtls_mutex_free = mutex_free; 110 | mbedtls_mutex_lock = mutex_lock; 111 | mbedtls_mutex_unlock = mutex_unlock; 112 | 113 | mbedtls_mutex_init( &mbedtls_threading_readdir_mutex ); 114 | mbedtls_mutex_init( &mbedtls_threading_gmtime_mutex ); 115 | } 116 | 117 | /* 118 | * Free global mutexes 119 | */ 120 | void mbedtls_threading_free_alt( void ) 121 | { 122 | mbedtls_mutex_free( &mbedtls_threading_readdir_mutex ); 123 | mbedtls_mutex_free( &mbedtls_threading_gmtime_mutex ); 124 | } 125 | #endif /* MBEDTLS_THREADING_ALT */ 126 | 127 | /* 128 | * Define global mutexes 129 | */ 130 | #ifndef MUTEX_INIT 131 | #define MUTEX_INIT 132 | #endif 133 | mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex MUTEX_INIT; 134 | mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex MUTEX_INIT; 135 | 136 | #endif /* MBEDTLS_THREADING_C */ 137 | -------------------------------------------------------------------------------- /src/mbedtls/threading.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file threading.h 3 | * 4 | * \brief Threading abstraction layer 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_THREADING_H 24 | #define MBEDTLS_THREADING_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #define MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE -0x001A /**< The selected feature is not available. */ 39 | #define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA -0x001C /**< Bad input parameters to function. */ 40 | #define MBEDTLS_ERR_THREADING_MUTEX_ERROR -0x001E /**< Locking / unlocking / free failed with error code. */ 41 | 42 | #if defined(MBEDTLS_THREADING_PTHREAD) 43 | #include 44 | typedef struct 45 | { 46 | pthread_mutex_t mutex; 47 | char is_valid; 48 | } mbedtls_threading_mutex_t; 49 | #endif 50 | 51 | #if defined(MBEDTLS_THREADING_ALT) 52 | /* You should define the mbedtls_threading_mutex_t type in your header */ 53 | #include "threading_alt.h" 54 | 55 | /** 56 | * \brief Set your alternate threading implementation function 57 | * pointers and initialize global mutexes. If used, this 58 | * function must be called once in the main thread before any 59 | * other mbed TLS function is called, and 60 | * mbedtls_threading_free_alt() must be called once in the main 61 | * thread after all other mbed TLS functions. 62 | * 63 | * \note mutex_init() and mutex_free() don't return a status code. 64 | * If mutex_init() fails, it should leave its argument (the 65 | * mutex) in a state such that mutex_lock() will fail when 66 | * called with this argument. 67 | * 68 | * \param mutex_init the init function implementation 69 | * \param mutex_free the free function implementation 70 | * \param mutex_lock the lock function implementation 71 | * \param mutex_unlock the unlock function implementation 72 | */ 73 | void mbedtls_threading_set_alt( void (*mutex_init)( mbedtls_threading_mutex_t * ), 74 | void (*mutex_free)( mbedtls_threading_mutex_t * ), 75 | int (*mutex_lock)( mbedtls_threading_mutex_t * ), 76 | int (*mutex_unlock)( mbedtls_threading_mutex_t * ) ); 77 | 78 | /** 79 | * \brief Free global mutexes. 80 | */ 81 | void mbedtls_threading_free_alt( void ); 82 | #endif /* MBEDTLS_THREADING_ALT */ 83 | 84 | /* 85 | * The function pointers for mutex_init, mutex_free, mutex_ and mutex_unlock 86 | * 87 | * All these functions are expected to work or the result will be undefined. 88 | */ 89 | extern void (*mbedtls_mutex_init)( mbedtls_threading_mutex_t *mutex ); 90 | extern void (*mbedtls_mutex_free)( mbedtls_threading_mutex_t *mutex ); 91 | extern int (*mbedtls_mutex_lock)( mbedtls_threading_mutex_t *mutex ); 92 | extern int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t *mutex ); 93 | 94 | /* 95 | * Global mutexes 96 | */ 97 | extern mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex; 98 | extern mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex; 99 | 100 | #ifdef __cplusplus 101 | } 102 | #endif 103 | 104 | #endif /* threading.h */ 105 | -------------------------------------------------------------------------------- /src/mbedtls/timing.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file timing.h 3 | * 4 | * \brief Portable interface to the CPU cycle counter 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_TIMING_H 24 | #define MBEDTLS_TIMING_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #if !defined(MBEDTLS_TIMING_ALT) 33 | // Regular implementation 34 | // 35 | 36 | #include 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /** 43 | * \brief timer structure 44 | */ 45 | struct mbedtls_timing_hr_time 46 | { 47 | unsigned char opaque[32]; 48 | }; 49 | 50 | /** 51 | * \brief Context for mbedtls_timing_set/get_delay() 52 | */ 53 | typedef struct 54 | { 55 | struct mbedtls_timing_hr_time timer; 56 | uint32_t int_ms; 57 | uint32_t fin_ms; 58 | } mbedtls_timing_delay_context; 59 | 60 | extern volatile int mbedtls_timing_alarmed; 61 | 62 | /** 63 | * \brief Return the CPU cycle counter value 64 | * 65 | * \warning This is only a best effort! Do not rely on this! 66 | * In particular, it is known to be unreliable on virtual 67 | * machines. 68 | */ 69 | unsigned long mbedtls_timing_hardclock( void ); 70 | 71 | /** 72 | * \brief Return the elapsed time in milliseconds 73 | * 74 | * \param val points to a timer structure 75 | * \param reset if set to 1, the timer is restarted 76 | */ 77 | unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int reset ); 78 | 79 | /** 80 | * \brief Setup an alarm clock 81 | * 82 | * \param seconds delay before the "mbedtls_timing_alarmed" flag is set 83 | * 84 | * \warning Only one alarm at a time is supported. In a threaded 85 | * context, this means one for the whole process, not one per 86 | * thread. 87 | */ 88 | void mbedtls_set_alarm( int seconds ); 89 | 90 | /** 91 | * \brief Set a pair of delays to watch 92 | * (See \c mbedtls_timing_get_delay().) 93 | * 94 | * \param data Pointer to timing data 95 | * Must point to a valid \c mbedtls_timing_delay_context struct. 96 | * \param int_ms First (intermediate) delay in milliseconds. 97 | * \param fin_ms Second (final) delay in milliseconds. 98 | * Pass 0 to cancel the current delay. 99 | */ 100 | void mbedtls_timing_set_delay( void *data, uint32_t int_ms, uint32_t fin_ms ); 101 | 102 | /** 103 | * \brief Get the status of delays 104 | * (Memory helper: number of delays passed.) 105 | * 106 | * \param data Pointer to timing data 107 | * Must point to a valid \c mbedtls_timing_delay_context struct. 108 | * 109 | * \return -1 if cancelled (fin_ms = 0) 110 | * 0 if none of the delays are passed, 111 | * 1 if only the intermediate delay is passed, 112 | * 2 if the final delay is passed. 113 | */ 114 | int mbedtls_timing_get_delay( void *data ); 115 | 116 | #ifdef __cplusplus 117 | } 118 | #endif 119 | 120 | #else /* MBEDTLS_TIMING_ALT */ 121 | #include "timing_alt.h" 122 | #endif /* MBEDTLS_TIMING_ALT */ 123 | 124 | #ifdef __cplusplus 125 | extern "C" { 126 | #endif 127 | 128 | #if defined(MBEDTLS_SELF_TEST) 129 | /** 130 | * \brief Checkup routine 131 | * 132 | * \return 0 if successful, or 1 if a test failed 133 | */ 134 | int mbedtls_timing_self_test( int verbose ); 135 | #endif 136 | 137 | #ifdef __cplusplus 138 | } 139 | #endif 140 | 141 | #endif /* timing.h */ 142 | -------------------------------------------------------------------------------- /src/mbedtls/version.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version information 3 | * 4 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 8 | * not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * This file is part of mbed TLS (https://tls.mbed.org) 20 | */ 21 | 22 | #if !defined(MBEDTLS_CONFIG_FILE) 23 | #include "config.h" 24 | #else 25 | #include MBEDTLS_CONFIG_FILE 26 | #endif 27 | 28 | #if defined(MBEDTLS_VERSION_C) 29 | 30 | #include "version.h" 31 | #include 32 | 33 | unsigned int mbedtls_version_get_number() 34 | { 35 | return( MBEDTLS_VERSION_NUMBER ); 36 | } 37 | 38 | void mbedtls_version_get_string( char *string ) 39 | { 40 | memcpy( string, MBEDTLS_VERSION_STRING, 41 | sizeof( MBEDTLS_VERSION_STRING ) ); 42 | } 43 | 44 | void mbedtls_version_get_string_full( char *string ) 45 | { 46 | memcpy( string, MBEDTLS_VERSION_STRING_FULL, 47 | sizeof( MBEDTLS_VERSION_STRING_FULL ) ); 48 | } 49 | 50 | #endif /* MBEDTLS_VERSION_C */ 51 | -------------------------------------------------------------------------------- /src/mbedtls/version.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file version.h 3 | * 4 | * \brief Run-time version information 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | /* 24 | * This set of compile-time defines and run-time variables can be used to 25 | * determine the version number of the mbed TLS library used. 26 | */ 27 | #ifndef MBEDTLS_VERSION_H 28 | #define MBEDTLS_VERSION_H 29 | 30 | #if !defined(MBEDTLS_CONFIG_FILE) 31 | #include "config.h" 32 | #else 33 | #include MBEDTLS_CONFIG_FILE 34 | #endif 35 | 36 | /** 37 | * The version number x.y.z is split into three parts. 38 | * Major, Minor, Patchlevel 39 | */ 40 | #define MBEDTLS_VERSION_MAJOR 2 41 | #define MBEDTLS_VERSION_MINOR 1 42 | #define MBEDTLS_VERSION_PATCH 2 43 | 44 | /** 45 | * The single version number has the following structure: 46 | * MMNNPP00 47 | * Major version | Minor version | Patch version 48 | */ 49 | #define MBEDTLS_VERSION_NUMBER 0x02010200 50 | #define MBEDTLS_VERSION_STRING "2.1.2" 51 | #define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.1.2" 52 | 53 | #if defined(MBEDTLS_VERSION_C) 54 | 55 | #ifdef __cplusplus 56 | extern "C" { 57 | #endif 58 | 59 | /** 60 | * Get the version number. 61 | * 62 | * \return The constructed version number in the format 63 | * MMNNPP00 (Major, Minor, Patch). 64 | */ 65 | unsigned int mbedtls_version_get_number( void ); 66 | 67 | /** 68 | * Get the version string ("x.y.z"). 69 | * 70 | * \param string The string that will receive the value. 71 | * (Should be at least 9 bytes in size) 72 | */ 73 | void mbedtls_version_get_string( char *string ); 74 | 75 | /** 76 | * Get the full version string ("mbed TLS x.y.z"). 77 | * 78 | * \param string The string that will receive the value. The mbed TLS version 79 | * string will use 18 bytes AT MOST including a terminating 80 | * null byte. 81 | * (So the buffer should be at least 18 bytes to receive this 82 | * version string). 83 | */ 84 | void mbedtls_version_get_string_full( char *string ); 85 | 86 | /** 87 | * \brief Check if support for a feature was compiled into this 88 | * mbed TLS binary. This allows you to see at runtime if the 89 | * library was for instance compiled with or without 90 | * Multi-threading support. 91 | * 92 | * \note only checks against defines in the sections "System 93 | * support", "mbed TLS modules" and "mbed TLS feature 94 | * support" in config.h 95 | * 96 | * \param feature The string for the define to check (e.g. "MBEDTLS_AES_C") 97 | * 98 | * \return 0 if the feature is present, 99 | * -1 if the feature is not present and 100 | * -2 if support for feature checking as a whole was not 101 | * compiled in. 102 | */ 103 | int mbedtls_version_check_feature( const char *feature ); 104 | 105 | #ifdef __cplusplus 106 | } 107 | #endif 108 | 109 | #endif /* MBEDTLS_VERSION_C */ 110 | 111 | #endif /* version.h */ 112 | -------------------------------------------------------------------------------- /src/mbedtls/xtea.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file xtea.h 3 | * 4 | * \brief XTEA block cipher (32-bit) 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_XTEA_H 24 | #define MBEDTLS_XTEA_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | #define MBEDTLS_XTEA_ENCRYPT 1 36 | #define MBEDTLS_XTEA_DECRYPT 0 37 | 38 | #define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028 /**< The data input has an invalid length. */ 39 | 40 | #if !defined(MBEDTLS_XTEA_ALT) 41 | // Regular implementation 42 | // 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | /** 49 | * \brief XTEA context structure 50 | */ 51 | typedef struct 52 | { 53 | uint32_t k[4]; /*!< key */ 54 | } 55 | mbedtls_xtea_context; 56 | 57 | /** 58 | * \brief Initialize XTEA context 59 | * 60 | * \param ctx XTEA context to be initialized 61 | */ 62 | void mbedtls_xtea_init( mbedtls_xtea_context *ctx ); 63 | 64 | /** 65 | * \brief Clear XTEA context 66 | * 67 | * \param ctx XTEA context to be cleared 68 | */ 69 | void mbedtls_xtea_free( mbedtls_xtea_context *ctx ); 70 | 71 | /** 72 | * \brief XTEA key schedule 73 | * 74 | * \param ctx XTEA context to be initialized 75 | * \param key the secret key 76 | */ 77 | void mbedtls_xtea_setup( mbedtls_xtea_context *ctx, const unsigned char key[16] ); 78 | 79 | /** 80 | * \brief XTEA cipher function 81 | * 82 | * \param ctx XTEA context 83 | * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT 84 | * \param input 8-byte input block 85 | * \param output 8-byte output block 86 | * 87 | * \return 0 if successful 88 | */ 89 | int mbedtls_xtea_crypt_ecb( mbedtls_xtea_context *ctx, 90 | int mode, 91 | const unsigned char input[8], 92 | unsigned char output[8] ); 93 | 94 | #if defined(MBEDTLS_CIPHER_MODE_CBC) 95 | /** 96 | * \brief XTEA CBC cipher function 97 | * 98 | * \param ctx XTEA context 99 | * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT 100 | * \param length the length of input, multiple of 8 101 | * \param iv initialization vector for CBC mode 102 | * \param input input block 103 | * \param output output block 104 | * 105 | * \return 0 if successful, 106 | * MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH if the length % 8 != 0 107 | */ 108 | int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context *ctx, 109 | int mode, 110 | size_t length, 111 | unsigned char iv[8], 112 | const unsigned char *input, 113 | unsigned char *output); 114 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ 115 | 116 | #ifdef __cplusplus 117 | } 118 | #endif 119 | 120 | #else /* MBEDTLS_XTEA_ALT */ 121 | #include "xtea_alt.h" 122 | #endif /* MBEDTLS_XTEA_ALT */ 123 | 124 | #ifdef __cplusplus 125 | extern "C" { 126 | #endif 127 | 128 | /** 129 | * \brief Checkup routine 130 | * 131 | * \return 0 if successful, or 1 if the test failed 132 | */ 133 | int mbedtls_xtea_self_test( int verbose ); 134 | 135 | #ifdef __cplusplus 136 | } 137 | #endif 138 | 139 | #endif /* xtea.h */ 140 | -------------------------------------------------------------------------------- /tools/platform_txt/Mac_Arduino_1.5.7_platform/platform.txt: -------------------------------------------------------------------------------- 1 | 2 | # Arduino MTK Core and platform. 3 | # 4 | # For more info: 5 | # https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification 6 | 7 | name=Arduino ARM (32-bits) Boards 8 | version=1.5.7 9 | 10 | # MTK compile variables 11 | # ---------------------- 12 | 13 | compiler.path={runtime.ide.path}/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin/ 14 | compiler.c.cmd=arm-none-eabi-gcc 15 | compiler.c.flags=-c -g -O2 -fvisibility=hidden -ffunction-sections -fdata-sections -fpic -mthumb -mlittle-endian -nostdlib -nostdlib -Dprintf=iprintf 16 | compiler.c.elf.cmd=arm-none-eabi-g++ 17 | compiler.c.elf.flags=-O2 -Wl,--gc-sections 18 | compiler.S.flags=-c -g -x assembler-with-cpp 19 | compiler.cpp.cmd=arm-none-eabi-g++ 20 | compiler.cpp.flags=-c -g -O2 -fvisibility=hidden -fpic -mthumb -mlittle-endian -nostdlib -fno-non-call-exceptions -fno-rtti -fno-exceptions -Dprintf=iprintf 21 | compiler.ar.cmd=arm-none-eabi-ar 22 | compiler.ar.flags=rcs 23 | compiler.objcopy.cmd=arm-none-eabi-objcopy 24 | compiler.objcopy.remove.flags=--strip-debug 25 | # compiler.elf2hex.flags=-O binary 26 | # compiler.elf2hex.cmd=arm-none-eabi-objcopy 27 | # compiler.ldflags= 28 | compiler.size.cmd=arm-none-eabi-size 29 | compiler.define=-DARDUINO= 30 | # this can be overriden in boards.txt 31 | build.extra_flags= 32 | 33 | 34 | compiler.libmtk.c.flags="-I{build.system.path}/libmtk" "-I{build.system.path}/libmtk/include" 35 | 36 | # USB Flags 37 | # --------- 38 | build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSBCON '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' 39 | 40 | # Default usb manufacturer will be replaced at compile time using 41 | # numeric vendor ID if available or by board's specific value. 42 | build.usb_manufacturer="Unknown" 43 | 44 | 45 | # MTK compile patterns 46 | # --------------------- 47 | 48 | ## Compile c files 49 | recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {compiler.libmtk.c.flags} {includes} "{source_file}" -o "{object_file}" 50 | 51 | ## Compile c++ files 52 | recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {compiler.libmtk.c.flags} {includes} "{source_file}" -o "{object_file}" 53 | 54 | ## Create archives 55 | recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{build.path}/{archive_file}" "{object_file}" 56 | 57 | ## Combine gc-sections, archives, and objects 58 | recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -lm -fpic -pie -Wl,--entry=gcc_entry -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-unresolved-symbols -Wl,--start-group "{build.path}/syscalls_mtk.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.path}/{archive_file}" -Wl,--end-group 59 | 60 | ## Get debug infomation 61 | #recipe.objcopy.get.pattern="{compiler.path}{compiler.objcopy.cmd}" --only-keep-debug "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.vxp.dbg" 62 | 63 | ## Remove debug infomation 64 | recipe.objcopy.eep.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.objcopy.remove.flags} "{build.path}/{build.project_name}.elf" 65 | 66 | ## Create hex 67 | recipe.objcopy.hex.pattern="{runtime.ide.path}/hardware/tools/mtk/PackTag" -i "{build.path}/{build.project_name}.elf" 68 | 69 | ## Compute size 70 | recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf" 71 | recipe.size.regex=\.text\s+([0-9]+).* 72 | 73 | 74 | # MTK Uploader tools 75 | # ------------------- 76 | 77 | tools.bossac.cmd=pushtool 78 | tools.bossac.cmd.windows=pushtool 79 | tools.bossac.path={runtime.ide.path}/hardware/tools/mtk 80 | 81 | tools.bossac.upload.params.verbose=-v -v -v -v 82 | tools.bossac.upload.params.quiet= 83 | tools.bossac.upload.pattern="{path}/{cmd}" {upload.verbose} -d arduino -b {serial.port.file} -p "{build.path}/{build.project_name}.vxp" 84 | 85 | -------------------------------------------------------------------------------- /tools/platform_txt/Mac_Arduino_1.6.5_platform/platform.txt: -------------------------------------------------------------------------------- 1 | # Arduino MTK Core and platform. 2 | # 3 | # For more info: 4 | # https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification 5 | 6 | name=MediaTek ARM7 EJ-S (32-bits) Boards 7 | version=1.5.7 8 | 9 | # MTK compile variables 10 | # ---------------------- 11 | 12 | compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/ 13 | compiler.c.cmd=arm-none-eabi-gcc 14 | compiler.c.flags=-c -g -O2 -fvisibility=hidden -fpic -ffunction-sections -fdata-sections -mthumb -mlittle-endian -nostdlib -nostdlib -Dprintf=iprintf 15 | compiler.c.elf.cmd=arm-none-eabi-g++ 16 | compiler.c.elf.flags=-O2 -Wl,--gc-sections 17 | compiler.S.flags=-c -g -x assembler-with-cpp 18 | compiler.cpp.cmd=arm-none-eabi-g++ 19 | compiler.cpp.flags=-c -g -O2 -fvisibility=hidden -fpic -mthumb -mlittle-endian -nostdlib -fno-non-call-exceptions -fno-rtti -fno-exceptions -Dprintf=iprintf 20 | compiler.ar.cmd=arm-none-eabi-ar 21 | compiler.ar.flags=rcs 22 | compiler.objcopy.cmd=arm-none-eabi-objcopy 23 | compiler.objcopy.remove.flags=--strip-debug 24 | # compiler.elf2hex.flags=-O binary 25 | # compiler.elf2hex.cmd=arm-none-eabi-objcopy 26 | # compiler.ldflags= 27 | compiler.size.cmd=arm-none-eabi-size 28 | compiler.define=-DARDUINO= 29 | # this can be overriden in boards.txt 30 | build.extra_flags= 31 | 32 | 33 | compiler.libmtk.c.flags="-I{build.system.path}/libmtk" "-I{build.system.path}/libmtk/include" 34 | 35 | # USB Flags 36 | # --------- 37 | build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSBCON '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' 38 | 39 | # Default usb manufacturer will be replaced at compile time using 40 | # numeric vendor ID if available or by board's specific value. 41 | build.usb_manufacturer="Unknown" 42 | 43 | 44 | # MTK compile patterns 45 | # --------------------- 46 | 47 | ## Compile c files 48 | recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {compiler.libmtk.c.flags} {includes} "{source_file}" -o "{object_file}" 49 | 50 | ## Compile c++ files 51 | recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {compiler.libmtk.c.flags} {includes} "{source_file}" -o "{object_file}" 52 | 53 | ## Create archives 54 | recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{build.path}/{archive_file}" "{object_file}" 55 | 56 | ## Combine gc-sections, archives, and objects 57 | recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -lm -fpic -pie -Wl,--entry=gcc_entry -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-unresolved-symbols -Wl,--start-group "{build.path}/syscalls_mtk.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.path}/{archive_file}" -Wl,--end-group 58 | 59 | ## Get debug infomation 60 | #recipe.objcopy.get.pattern="{compiler.path}{compiler.objcopy.cmd}" --only-keep-debug "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.vxp.dbg" 61 | 62 | ## Remove debug infomation 63 | recipe.objcopy.eep.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.objcopy.remove.flags} "{build.path}/{build.project_name}.elf" 64 | 65 | ## Create hex 66 | recipe.objcopy.hex.cmd=PackTag.sh 67 | recipe.objcopy.hex.cmd.windows=PackTag.bat 68 | recipe.objcopy.hex.pattern="{runtime.tools.linkit_tools.path}/{recipe.objcopy.hex.cmd}" "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.vxp" 69 | 70 | ## Compute size 71 | recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.vxp" 72 | recipe.size.regex=\.text\s+([0-9]+).* 73 | 74 | 75 | # MTK LinkIt ONE tools 76 | # ------------------- 77 | 78 | ## sketch uploader 79 | tools.linkit_tools.cmd=PushTool.sh 80 | tools.linkit_tools.cmd.windows=PushTool.bat 81 | tools.linkit_tools.path={runtime.tools.linkit_tools.path} 82 | tools.linkit_tools.upload.params.verbose=-v -v -v -v 83 | tools.linkit_tools.upload.params.quiet= 84 | tools.linkit_tools.upload.pattern="{path}/{cmd}" {serial.port.file} "{build.path}/{build.project_name}.vxp" 85 | 86 | ## bootloader tool is the Firmware Updater 87 | tools.linkit_tools.bootloader.params.verbose=-v -v -v -v 88 | tools.linkit_tools.bootloader.params.quiet= 89 | 90 | ## OS X Firmware Updater 91 | tools.linkit_tools.bootloader.cmd=FirmwareUpdater 92 | tools.linkit_tools.bootloader.pattern=open "{path}/FirmwareUpdater.app" 93 | 94 | ## Windows Firmware Updater 95 | tools.linkit_tools.bootloader.cmd.windows=FirmwareUpdater.exe 96 | tools.linkit_tools.bootloader.pattern.windows="{path}/FirmwareUpdater.exe" 97 | 98 | ## dummy erase option to make tool menu work 99 | tools.linkit_tools.erase.params.verbose=-v 100 | tools.linkit_tools.erase.params.quiet=-q -q 101 | tools.linkit_tools.erase.pattern= -------------------------------------------------------------------------------- /tools/platform_txt/Windows_Arduino_1.5.7_platform/platform.txt: -------------------------------------------------------------------------------- 1 | 2 | # Arduino MTK Core and platform. 3 | # 4 | # For more info: 5 | # https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification 6 | 7 | name=Arduino ARM (32-bits) Boards 8 | version=1.5.7 9 | 10 | # MTK compile variables 11 | # ---------------------- 12 | 13 | compiler.path={runtime.ide.path}/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin/ 14 | compiler.c.cmd=arm-none-eabi-gcc 15 | compiler.c.flags=-c -g -O2 -fvisibility=hidden -ffunction-sections -fdata-sections -fpic -mthumb -mlittle-endian -nostdlib -nostdlib -Dprintf=iprintf 16 | compiler.c.elf.cmd=arm-none-eabi-g++ 17 | compiler.c.elf.flags=-O2 -Wl,--gc-sections 18 | compiler.S.flags=-c -g -x assembler-with-cpp 19 | compiler.cpp.cmd=arm-none-eabi-g++ 20 | compiler.cpp.flags=-c -g -O2 -fvisibility=hidden -fpic -mthumb -mlittle-endian -nostdlib -fno-non-call-exceptions -fno-rtti -fno-exceptions -Dprintf=iprintf 21 | compiler.ar.cmd=arm-none-eabi-ar 22 | compiler.ar.flags=rcs 23 | compiler.objcopy.cmd=arm-none-eabi-objcopy 24 | compiler.objcopy.remove.flags=--strip-debug 25 | # compiler.elf2hex.flags=-O binary 26 | # compiler.elf2hex.cmd=arm-none-eabi-objcopy 27 | # compiler.ldflags= 28 | compiler.size.cmd=arm-none-eabi-size 29 | compiler.define=-DARDUINO= 30 | # this can be overriden in boards.txt 31 | build.extra_flags= 32 | 33 | 34 | compiler.libmtk.c.flags="-I{build.system.path}/libmtk" "-I{build.system.path}/libmtk/include" 35 | 36 | # USB Flags 37 | # --------- 38 | build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSBCON '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' 39 | 40 | # Default usb manufacturer will be replaced at compile time using 41 | # numeric vendor ID if available or by board's specific value. 42 | build.usb_manufacturer="Unknown" 43 | 44 | 45 | # MTK compile patterns 46 | # --------------------- 47 | 48 | ## Compile c files 49 | recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {compiler.libmtk.c.flags} {includes} "{source_file}" -o "{object_file}" 50 | 51 | ## Compile c++ files 52 | recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {compiler.libmtk.c.flags} {includes} "{source_file}" -o "{object_file}" 53 | 54 | ## Create archives 55 | recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{build.path}/{archive_file}" "{object_file}" 56 | 57 | ## Combine gc-sections, archives, and objects 58 | recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -lm -fpic -pie -Wl,--entry=gcc_entry -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-unresolved-symbols -Wl,--start-group "{build.path}/syscalls_mtk.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.path}/{archive_file}" -Wl,--end-group 59 | 60 | ## Get debug infomation 61 | #recipe.objcopy.get.pattern="{compiler.path}{compiler.objcopy.cmd}" --only-keep-debug "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.vxp.dbg" 62 | 63 | ## Remove debug infomation 64 | recipe.objcopy.eep.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.objcopy.remove.flags} "{build.path}/{build.project_name}.elf" 65 | 66 | ## Create hex 67 | recipe.objcopy.hex.pattern="{runtime.ide.path}/hardware/tools/mtk/PackTag.exe" "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.vxp" 68 | 69 | ## Compute size 70 | recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf" 71 | recipe.size.regex=\.text\s+([0-9]+).* 72 | 73 | 74 | # MTK Uploader tools 75 | # ------------------- 76 | 77 | tools.bossac.cmd=pushtool 78 | tools.bossac.cmd.windows=pushtool.exe 79 | tools.bossac.path={runtime.ide.path}/hardware/tools/mtk 80 | 81 | tools.bossac.upload.params.verbose=-v -v -v -v 82 | tools.bossac.upload.params.quiet= 83 | tools.bossac.upload.pattern="{path}/{cmd}" {upload.verbose} -d arduino -b {serial.port.file} -p "{build.path}/{build.project_name}.vxp" 84 | 85 | -------------------------------------------------------------------------------- /tools/platform_txt/Windows_Arduino_1.6.5_platform/platform.txt: -------------------------------------------------------------------------------- 1 | 2 | # Arduino MTK Core and platform. 3 | # 4 | # For more info: 5 | # https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification 6 | 7 | name=MediaTek ARM7 EJ-S (32-bits) Boards 8 | version=1.5.7 9 | 10 | # MTK compile variables 11 | # ---------------------- 12 | 13 | compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/ 14 | compiler.c.cmd=arm-none-eabi-gcc 15 | compiler.c.flags=-c -g -O2 -ffunction-sections -fdata-sections -fvisibility=hidden -fpic -mthumb -mlittle-endian -nostdlib -nostdlib -Dprintf=iprintf 16 | compiler.c.elf.cmd=arm-none-eabi-g++ 17 | compiler.c.elf.flags=-O2 -Wl,--gc-sections 18 | compiler.S.flags=-c -g -x assembler-with-cpp 19 | compiler.cpp.cmd=arm-none-eabi-g++ 20 | compiler.cpp.flags=-c -g -O2 -ffunction-sections -fdata-sections -fvisibility=hidden -fpic -mthumb -mlittle-endian -nostdlib -fno-non-call-exceptions -fno-rtti -fno-exceptions -Dprintf=iprintf 21 | compiler.ar.cmd=arm-none-eabi-ar 22 | compiler.ar.flags=rcs 23 | compiler.objcopy.cmd=arm-none-eabi-objcopy 24 | compiler.objcopy.remove.flags=--strip-debug 25 | # compiler.elf2hex.flags=-O binary 26 | # compiler.elf2hex.cmd=arm-none-eabi-objcopy 27 | # compiler.ldflags= 28 | compiler.size.cmd=arm-none-eabi-size 29 | compiler.define=-DARDUINO= 30 | # this can be overriden in boards.txt 31 | build.extra_flags= 32 | 33 | 34 | compiler.libmtk.c.flags="-I{build.system.path}/libmtk" "-I{build.system.path}/libmtk/include" 35 | 36 | # USB Flags 37 | # --------- 38 | build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSBCON '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' 39 | 40 | # Default usb manufacturer will be replaced at compile time using 41 | # numeric vendor ID if available or by board's specific value. 42 | build.usb_manufacturer="Unknown" 43 | 44 | 45 | # MTK compile patterns 46 | # --------------------- 47 | 48 | ## Compile c files 49 | recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {compiler.libmtk.c.flags} {includes} "{source_file}" -o "{object_file}" 50 | 51 | ## Compile c++ files 52 | recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {compiler.libmtk.c.flags} {includes} "{source_file}" -o "{object_file}" 53 | 54 | ## Create archives 55 | recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{build.path}/{archive_file}" "{object_file}" 56 | 57 | ## Combine gc-sections, archives, and objects 58 | recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -lm -fpic -pie -Wl,--entry=gcc_entry -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-unresolved-symbols -Wl,--start-group "{build.path}/syscalls_mtk.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.path}/{archive_file}" -Wl,--end-group 59 | 60 | ## Get debug infomation 61 | #recipe.objcopy.get.pattern="{compiler.path}{compiler.objcopy.cmd}" --only-keep-debug "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.vxp.dbg" 62 | 63 | ## Remove debug infomation 64 | recipe.objcopy.eep.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.objcopy.remove.flags} "{build.path}/{build.project_name}.elf" 65 | 66 | ## Create hex 67 | recipe.objcopy.hex.cmd=PackTag.sh 68 | recipe.objcopy.hex.cmd.windows=PackTag.bat 69 | recipe.objcopy.hex.pattern="{runtime.tools.linkit_tools.path}/{recipe.objcopy.hex.cmd}" "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.vxp" 70 | 71 | ## Compute size 72 | recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.vxp" 73 | recipe.size.regex=\.text\s+([0-9]+).* 74 | 75 | 76 | # MTK LinkIt ONE tools 77 | # ------------------- 78 | 79 | ## sketch uploader 80 | tools.linkit_tools.cmd=PushTool.sh 81 | tools.linkit_tools.cmd.windows=PushTool.bat 82 | tools.linkit_tools.path={runtime.tools.linkit_tools.path} 83 | tools.linkit_tools.upload.params.verbose=-v -v -v -v 84 | tools.linkit_tools.upload.params.quiet= 85 | tools.linkit_tools.upload.pattern="{path}/{cmd}" {serial.port.file} "{build.path}/{build.project_name}.vxp" 86 | 87 | ## bootloader tool is the Firmware Updater 88 | tools.linkit_tools.bootloader.params.verbose=-v -v -v -v 89 | tools.linkit_tools.bootloader.params.quiet= 90 | 91 | ## OS X Firmware Updater 92 | tools.linkit_tools.bootloader.cmd=FirmwareUpdater 93 | tools.linkit_tools.bootloader.pattern=open "{path}/FirmwareUpdater.app" 94 | 95 | ## Windows Firmware Updater 96 | tools.linkit_tools.bootloader.cmd.windows=FirmwareUpdater.exe 97 | tools.linkit_tools.bootloader.pattern.windows="{path}/FirmwareUpdater.exe" 98 | 99 | ## dummy erase option to make tool menu work 100 | tools.linkit_tools.erase.params.verbose=-v 101 | tools.linkit_tools.erase.params.quiet=-q -q 102 | tools.linkit_tools.erase.pattern= 103 | 104 | -------------------------------------------------------------------------------- /tools/root_cert/G5.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIE0zCCA7ugAwIBAgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhkiG9w0BAQUFADCB 3 | yjELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL 4 | ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJp 5 | U2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxW 6 | ZXJpU2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0 7 | aG9yaXR5IC0gRzUwHhcNMDYxMTA4MDAwMDAwWhcNMzYwNzE2MjM1OTU5WjCByjEL 8 | MAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZW 9 | ZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJpU2ln 10 | biwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxWZXJp 11 | U2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9y 12 | aXR5IC0gRzUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCvJAgIKXo1 13 | nmAMqudLO07cfLw8RRy7K+D+KQL5VwijZIUVJ/XxrcgxiV0i6CqqpkKzj/i5Vbex 14 | t0uz/o9+B1fs70PbZmIVYc9gDaTY3vjgw2IIPVQT60nKWVSFJuUrjxuf6/WhkcIz 15 | SdhDY2pSS9KP6HBRTdGJaXvHcPaz3BJ023tdS1bTlr8Vd6Gw9KIl8q8ckmcY5fQG 16 | BO+QueQA5N06tRn/Arr0PO7gi+s3i+z016zy9vA9r911kTMZHRxAy3QkGSGT2RT+ 17 | rCpSx4/VBEnkjWNHiDxpg8v+R70rfk/Fla4OndTRQ8Bnc+MUCH7lP59zuDMKz10/ 18 | NIeWiu5T6CUVAgMBAAGjgbIwga8wDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8E 19 | BAMCAQYwbQYIKwYBBQUHAQwEYTBfoV2gWzBZMFcwVRYJaW1hZ2UvZ2lmMCEwHzAH 20 | BgUrDgMCGgQUj+XTGoasjY5rw8+AatRIGCx7GS4wJRYjaHR0cDovL2xvZ28udmVy 21 | aXNpZ24uY29tL3ZzbG9nby5naWYwHQYDVR0OBBYEFH/TZafC3ey78DAJ80M5+gKv 22 | MzEzMA0GCSqGSIb3DQEBBQUAA4IBAQCTJEowX2LP2BqYLz3q3JktvXf2pXkiOOzE 23 | p6B4Eq1iDkVwZMXnl2YtmAl+X6/WzChl8gGqCBpH3vn5fJJaCGkgDdk+bW48DW7Y 24 | 5gaRQBi5+MHt39tBquCWIMnNZBU4gcmU7qKEKQsTb47bDN0lAtukixlE0kF6BWlK 25 | WE9gyn6CagsCqiUXObXbf+eEZSqVir2G3l6BFoMtEMze/aiCKm0oHw0LxOXnGiYZ 26 | 4fQRbxC1lfznQgUy286dUV4otp6F01vvpX1FQHKOtw5rDgb7MzVIcbidJ4vEZV8N 27 | hnacRHr2lVz2XTIIM6RUthg/aFzyQkqFOFSDX9HoLPKsEdao7WNq 28 | -----END CERTIFICATE----- --------------------------------------------------------------------------------