This commit is contained in:
jbobotek 2020-01-28 17:42:05 -08:00
Родитель 7fad1decea
Коммит 1082498b53
17 изменённых файлов: 45121 добавлений и 44992 удалений

Просмотреть файл

@ -30,7 +30,7 @@ before_install:
- findAndReplace() { sed -i'' -e"s|$1|$2|g" "$3"; }
- buildExampleSketch() {
EXAMPLE_SKETCH=$PWD/examples/iothub_ll_telemetry_sample/telemetry_sample.c.ino;
EXAMPLE_SKETCH=$PWD/examples/iothub_ll_telemetry_sample/iothub_ll_telemetry_sample.ino;
arduino --verbose-build --verify --board $BOARD $EXAMPLE_SKETCH;
}

21
LICENSE Normal file
Просмотреть файл

@ -0,0 +1,21 @@
Microsoft Azure IoT SDKs
Copyright (c) Microsoft Corporation
All rights reserved.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the ""Software""), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Просмотреть файл

@ -1,5 +1,5 @@
name=AzureIoTUtility
version=1.1.12
version=1.3.8
author=Microsoft
maintainer=Microsoft <iotcert@microsoft.com>
sentence=Azure C shared utility library for Arduino. For the Arduino MKR1000 or Zero and WiFi Shield 101, Adafruit Huzzah and Feather M0, or SparkFun Thing.

Просмотреть файл

@ -7,7 +7,11 @@
#include "azure_c_shared_utility/platform.h"
#include "azure_c_shared_utility/lock.h"
#include "azure_c_shared_utility/threadapi.h"
#include "azure_c_shared_utility/crt_abstractions.h"
#include "azure_c_shared_utility/shared_util_options.h"
#include "azure_c_shared_utility/tlsio.h"
#include "azure_c_shared_utility/xlogging.h"
#define AzureIoTUtilityVersion "1.1.12"
#define AzureIoTUtilityVersion "1.3.8"
#endif //AZUREIOTUTILITY_H

Просмотреть файл

@ -1,3 +1,4 @@
#ifdef ARDUINO_ARCH_ESP32
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
@ -7,7 +8,6 @@
#include <stdbool.h>
#include <string.h>
#include "mbedtls/config.h"
#include "mbedtls/debug.h"
#include "mbedtls/ssl.h"
#include "mbedtls/entropy.h"
@ -43,7 +43,8 @@ typedef enum TLSIO_STATE_ENUM_TAG
typedef struct SEND_COMPLETE_INFO_TAG
{
int send_complete_count;
bool is_fragmented_req;
IO_SEND_RESULT last_fragmented_req_status;
ON_SEND_COMPLETE on_send_complete;
void *on_send_complete_callback_context;
} SEND_COMPLETE_INFO;
@ -130,6 +131,28 @@ static int decode_ssl_received_bytes(TLS_IO_INSTANCE *tls_io_instance)
return result;
}
static bool is_fragmented_send_request(TLS_IO_INSTANCE *tls_io_instance, size_t send_size)
{
#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
size_t max_len = mbedtls_ssl_get_max_frag_len(&tls_io_instance->ssl);
#else
size_t max_len = MBEDTLS_SSL_MAX_CONTENT_LEN;
(void)tls_io_instance;
#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
bool result;
if (send_size > max_len)
{
result = true;
}
else
{
result = false;
}
return result;
}
static void on_underlying_io_open_complete(void *context, IO_OPEN_RESULT open_result)
{
if (context == NULL)
@ -342,12 +365,21 @@ static void on_send_complete(void* context, IO_SEND_RESULT send_result)
TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE *)context;
if (tls_io_instance != NULL)
{
// If the state is not open then this is probably an internal call
// So don't notify the upper level
if (tls_io_instance->send_complete_info.on_send_complete != NULL && tls_io_instance->send_complete_info.send_complete_count == 0 && tls_io_instance->tlsio_state != TLSIO_STATE_CLOSING)
// update fragment status
if (tls_io_instance->send_complete_info.is_fragmented_req)
{
tls_io_instance->send_complete_info.on_send_complete(tls_io_instance->send_complete_info.on_send_complete_callback_context, send_result);
tls_io_instance->send_complete_info.send_complete_count++;
tls_io_instance->send_complete_info.last_fragmented_req_status = send_result;
}
if (tls_io_instance->send_complete_info.on_send_complete != NULL &&
tls_io_instance->tlsio_state != TLSIO_STATE_CLOSING)
{
// trigger callback always on failure, otherwise call it on last fragment completion
if (send_result != IO_SEND_OK || !tls_io_instance->send_complete_info.is_fragmented_req)
{
void *ctx = tls_io_instance->send_complete_info.on_send_complete_callback_context;
tls_io_instance->send_complete_info.on_send_complete(ctx, send_result);
}
}
}
else
@ -367,7 +399,17 @@ static int on_io_send(void *context, const unsigned char *buf, size_t sz)
else
{
TLS_IO_INSTANCE *tls_io_instance = (TLS_IO_INSTANCE *)context;
if (xio_send(tls_io_instance->socket_io, buf, sz, on_send_complete, tls_io_instance) != 0)
ON_SEND_COMPLETE on_complete_callback = NULL;
void *context = NULL;
// Only allow Application data type message to send on_send_complete callback.
if (tls_io_instance->ssl.out_msgtype == MBEDTLS_SSL_MSG_APPLICATION_DATA)
{
on_complete_callback = on_send_complete;
context = tls_io_instance;
}
if (xio_send(tls_io_instance->socket_io, buf, sz, on_complete_callback, context) != 0)
{
indicate_error(tls_io_instance);
result = 0;
@ -511,7 +553,6 @@ CONCRETE_IO_HANDLE tlsio_mbedtls_create(void *io_create_parameters)
{
result->tls_status = TLS_STATE_NOT_INITIALIZED;
mbedtls_init((void*)result);
result->tlsio_state = TLSIO_STATE_NOT_OPEN;
}
}
@ -631,11 +672,22 @@ int tlsio_mbedtls_close(CONCRETE_IO_HANDLE tls_io, ON_IO_CLOSE_COMPLETE on_io_cl
}
else
{
int is_error = tls_io_instance->tlsio_state == TLSIO_STATE_ERROR;
tls_io_instance->tlsio_state = TLSIO_STATE_CLOSING;
if (tls_io_instance->tls_status == TLS_STATE_INITIALIZED)
{
// Tell the peer that you're going to close
mbedtls_ssl_close_notify(&tls_io_instance->ssl);
if (is_error)
{
// forced shutdown if tls is in ERROR state
mbedtls_ssl_session_reset(&tls_io_instance->ssl);
}
else
{
// Tell the peer that you're going to close
mbedtls_ssl_close_notify(&tls_io_instance->ssl);
}
tls_io_instance->tls_status = TLS_STATE_CLOSING;
}
@ -676,19 +728,38 @@ int tlsio_mbedtls_send(CONCRETE_IO_HANDLE tls_io, const void *buffer, size_t siz
{
tls_io_instance->send_complete_info.on_send_complete = on_send_complete;
tls_io_instance->send_complete_info.on_send_complete_callback_context = callback_context;
tls_io_instance->send_complete_info.send_complete_count = 0;
int res = mbedtls_ssl_write(&tls_io_instance->ssl, buffer, size);
if (res != (int)size)
tls_io_instance->send_complete_info.last_fragmented_req_status = IO_SEND_OK;
int out_left = size;
result = 0;
do
{
LogError("Unexpected data size returned from mbedtls_ssl_write %d/%d", res, (int)size);
result = MU_FAILURE;
}
else
{
result = 0;
}
tls_io_instance->send_complete_info.is_fragmented_req = is_fragmented_send_request(tls_io_instance, out_left);
unsigned char *buf = (unsigned char *)buffer + size - out_left;
int ret = mbedtls_ssl_write(&tls_io_instance->ssl, buf, out_left);
if (ret < 0)
{
LogError("Unexpected data size returned from mbedtls_ssl_write %d/%d", ret, (int)size);
result = MU_FAILURE;
break;
}
else if (tls_io_instance->send_complete_info.last_fragmented_req_status != IO_SEND_OK)
{
LogError("Failed to send last fragment with error:0x%0x, aborting whole send",
tls_io_instance->send_complete_info.last_fragmented_req_status);
result = MU_FAILURE;
break;
}
out_left -= ret;
} while (out_left > 0);
// remove on send complete info
memset((void*)&tls_io_instance->send_complete_info, 0, sizeof(tls_io_instance->send_complete_info));
}
}
return result;
}
@ -1040,3 +1111,4 @@ const IO_INTERFACE_DESCRIPTION *tlsio_mbedtls_get_interface_description(void)
{
return &tlsio_mbedtls_interface_description;
}
#endif //ARDUINO_ARCH_ESP32

Просмотреть файл

@ -19,4 +19,4 @@ directory and its subfolders.
### Porting to new devices
Instructions for porting the Azure IoT C SDK to new devices are located
[here](https://github.com/Azure/azure-c-shared-utility/blob/pal-porting/devdoc/porting_guide.md).
[here](https://github.com/Azure/azure-c-shared-utility/blob/master/devdoc/porting_guide.md).

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -318,6 +318,7 @@ extern int BUFFER_unbuild(BUFFER_HANDLE handle)
if (handle == NULL)
{
/* Codes_SRS_BUFFER_07_014: [BUFFER_unbuild shall return a nonzero value if BUFFER_HANDLE is NULL.] */
LogError("Failure: handle is invalid.");
result = MU_FAILURE;
}
else
@ -325,17 +326,14 @@ extern int BUFFER_unbuild(BUFFER_HANDLE handle)
BUFFER* b = (BUFFER*)handle;
if (b->buffer != NULL)
{
LogError("Failure buffer data is NULL");
free(b->buffer);
b->buffer = NULL;
b->size = 0;
result = 0;
}
else
{
/* Codes_SRS_BUFFER_07_015: [BUFFER_unbuild shall return a nonzero value if the unsigned char* referenced by BUFFER_HANDLE is NULL.] */
result = MU_FAILURE;
}
/* Codes_SRS_BUFFER_07_015: [BUFFER_unbuild shall always return success if the unsigned char* referenced by BUFFER_HANDLE is NULL.] */
result = 0;
}
return result;
}

Просмотреть файл

@ -3,6 +3,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include "azure_macro_utils/macro_utils.h"
#include "azure_c_shared_utility/gballoc.h"
#include "azure_c_shared_utility/map.h"
#include "azure_c_shared_utility/constmap.h"
@ -18,7 +19,7 @@ typedef struct CONSTMAP_HANDLE_DATA_TAG
DEFINE_REFCOUNT_TYPE(CONSTMAP_HANDLE_DATA);
#define LOG_CONSTMAP_ERROR(result) LogError("result = %s", MU_ENUM_TO_STRING(CONSTMAP_RESULT, (result)));
#define LOG_CONSTMAP_ERROR(result) LogError("result = %" PRI_MU_ENUM "", MU_ENUM_VALUE(CONSTMAP_RESULT, (result)));
CONSTMAP_HANDLE ConstMap_Create(MAP_HANDLE sourceMap)
{

Просмотреть файл

@ -3,6 +3,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include "azure_macro_utils/macro_utils.h"
#include "azure_c_shared_utility/gballoc.h"
#include "azure_c_shared_utility/httpapiex.h"
#include "azure_c_shared_utility/optimize_size.h"
@ -27,7 +28,7 @@ typedef struct HTTPAPIEX_HANDLE_DATA_TAG
MU_DEFINE_ENUM_STRINGS(HTTPAPIEX_RESULT, HTTPAPIEX_RESULT_VALUES);
#define LOG_HTTAPIEX_ERROR() LogError("error code = %s", MU_ENUM_TO_STRING(HTTPAPIEX_RESULT, result))
#define LOG_HTTAPIEX_ERROR() LogError("error code = %" PRI_MU_ENUM "", MU_ENUM_VALUE(HTTPAPIEX_RESULT, result))
static int useGlobalInitialization = 0;

Просмотреть файл

@ -3,6 +3,7 @@
#include <stdlib.h>
#include <string.h>
#include "azure_macro_utils/macro_utils.h"
#include "azure_c_shared_utility/gballoc.h"
#include "azure_c_shared_utility/map.h"
#include "azure_c_shared_utility/httpheaders.h"
@ -76,7 +77,7 @@ static HTTP_HEADERS_RESULT headers_ReplaceHeaderNameValuePair(HTTP_HEADERS_HANDL
)
{
result = HTTP_HEADERS_INVALID_ARG;
LogError("invalid arg (NULL) , result= %s", MU_ENUM_TO_STRING(HTTP_HEADERS_RESULT, result));
LogError("invalid arg (NULL) , result= %" PRI_MU_ENUM "", MU_ENUM_VALUE(HTTP_HEADERS_RESULT, result));
}
else
{
@ -95,7 +96,7 @@ static HTTP_HEADERS_RESULT headers_ReplaceHeaderNameValuePair(HTTP_HEADERS_HANDL
if (i < nameLen)
{
result = HTTP_HEADERS_INVALID_ARG;
LogError("(result = %s)", MU_ENUM_TO_STRING(HTTP_HEADERS_RESULT, result));
LogError("(result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(HTTP_HEADERS_RESULT, result));
}
else
{
@ -117,7 +118,7 @@ static HTTP_HEADERS_RESULT headers_ReplaceHeaderNameValuePair(HTTP_HEADERS_HANDL
{
/*Codes_SRS_HTTP_HEADERS_99_015:[ The function shall return HTTP_HEADERS_ALLOC_FAILED when an internal request to allocate memory fails.]*/
result = HTTP_HEADERS_ALLOC_FAILED;
LogError("failed to malloc , result= %s", MU_ENUM_TO_STRING(HTTP_HEADERS_RESULT, result));
LogError("failed to malloc , result= %" PRI_MU_ENUM "", MU_ENUM_VALUE(HTTP_HEADERS_RESULT, result));
}
else
{
@ -134,7 +135,7 @@ static HTTP_HEADERS_RESULT headers_ReplaceHeaderNameValuePair(HTTP_HEADERS_HANDL
{
/*Codes_SRS_HTTP_HEADERS_99_015:[ The function shall return HTTP_HEADERS_ALLOC_FAILED when an internal request to allocate memory fails.]*/
result = HTTP_HEADERS_ERROR;
LogError("failed to Map_AddOrUpdate, result= %s", MU_ENUM_TO_STRING(HTTP_HEADERS_RESULT, result));
LogError("failed to Map_AddOrUpdate, result= %" PRI_MU_ENUM "", MU_ENUM_VALUE(HTTP_HEADERS_RESULT, result));
}
else
{
@ -151,7 +152,7 @@ static HTTP_HEADERS_RESULT headers_ReplaceHeaderNameValuePair(HTTP_HEADERS_HANDL
{
/*Codes_SRS_HTTP_HEADERS_99_015:[ The function shall return HTTP_HEADERS_ALLOC_FAILED when an internal request to allocate memory fails.]*/
result = HTTP_HEADERS_ALLOC_FAILED;
LogError("failed to Map_AddOrUpdate, result= %s", MU_ENUM_TO_STRING(HTTP_HEADERS_RESULT, result));
LogError("failed to Map_AddOrUpdate, result= %" PRI_MU_ENUM "", MU_ENUM_VALUE(HTTP_HEADERS_RESULT, result));
}
else
{
@ -208,7 +209,7 @@ HTTP_HEADERS_RESULT HTTPHeaders_GetHeaderCount(HTTP_HEADERS_HANDLE handle, size_
(headerCount == NULL))
{
result = HTTP_HEADERS_INVALID_ARG;
LogError("(result = %s)", MU_ENUM_TO_STRING(HTTP_HEADERS_RESULT, result));
LogError("(result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(HTTP_HEADERS_RESULT, result));
}
else
{
@ -220,7 +221,7 @@ HTTP_HEADERS_RESULT HTTPHeaders_GetHeaderCount(HTTP_HEADERS_HANDLE handle, size_
{
/*Codes_SRS_HTTP_HEADERS_99_037:[ The function shall return HTTP_HEADERS_ERROR when an internal error occurs.]*/
result = HTTP_HEADERS_ERROR;
LogError("Map_GetInternals failed, result= %s", MU_ENUM_TO_STRING(HTTP_HEADERS_RESULT, result));
LogError("Map_GetInternals failed, result= %" PRI_MU_ENUM "", MU_ENUM_VALUE(HTTP_HEADERS_RESULT, result));
}
else
{
@ -245,7 +246,7 @@ HTTP_HEADERS_RESULT HTTPHeaders_GetHeader(HTTP_HEADERS_HANDLE handle, size_t ind
)
{
result = HTTP_HEADERS_INVALID_ARG;
LogError("invalid arg (NULL), result= %s", MU_ENUM_TO_STRING(HTTP_HEADERS_RESULT, result));
LogError("invalid arg (NULL), result= %" PRI_MU_ENUM "", MU_ENUM_VALUE(HTTP_HEADERS_RESULT, result));
}
/*Codes_SRS_HTTP_HEADERS_99_029:[ The function shall return HTTP_HEADERS_INVALID_ARG if index is not valid (for example, out of range) for the currently stored headers.]*/
else
@ -258,7 +259,7 @@ HTTP_HEADERS_RESULT HTTPHeaders_GetHeader(HTTP_HEADERS_HANDLE handle, size_t ind
{
/*Codes_SRS_HTTP_HEADERS_99_034:[ The function shall return HTTP_HEADERS_ERROR when an internal error occurs]*/
result = HTTP_HEADERS_ERROR;
LogError("Map_GetInternals failed, result= %s", MU_ENUM_TO_STRING(HTTP_HEADERS_RESULT, result));
LogError("Map_GetInternals failed, result= %" PRI_MU_ENUM "", MU_ENUM_VALUE(HTTP_HEADERS_RESULT, result));
}
else
{
@ -266,7 +267,7 @@ HTTP_HEADERS_RESULT HTTPHeaders_GetHeader(HTTP_HEADERS_HANDLE handle, size_t ind
if (index >= headerCount)
{
result = HTTP_HEADERS_INVALID_ARG;
LogError("index out of bounds, result= %s", MU_ENUM_TO_STRING(HTTP_HEADERS_RESULT, result));
LogError("index out of bounds, result= %" PRI_MU_ENUM "", MU_ENUM_VALUE(HTTP_HEADERS_RESULT, result));
}
else
{
@ -277,7 +278,7 @@ HTTP_HEADERS_RESULT HTTPHeaders_GetHeader(HTTP_HEADERS_HANDLE handle, size_t ind
{
/*Codes_SRS_HTTP_HEADERS_99_034:[ The function shall return HTTP_HEADERS_ERROR when an internal error occurs]*/
result = HTTP_HEADERS_ERROR;
LogError("unable to malloc, result= %s", MU_ENUM_TO_STRING(HTTP_HEADERS_RESULT, result));
LogError("unable to malloc, result= %" PRI_MU_ENUM "", MU_ENUM_VALUE(HTTP_HEADERS_RESULT, result));
}
else
{

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include <stdlib.h>
#include "azure_macro_utils/macro_utils.h"
#include "azure_c_shared_utility/gballoc.h"
#include "azure_c_shared_utility/map.h"
#include "azure_c_shared_utility/optimize_size.h"
@ -18,7 +19,7 @@ typedef struct MAP_HANDLE_DATA_TAG
MAP_FILTER_CALLBACK mapFilterCallback;
}MAP_HANDLE_DATA;
#define LOG_MAP_ERROR LogError("result = %s", MU_ENUM_TO_STRING(MAP_RESULT, result));
#define LOG_MAP_ERROR LogError("result = %" PRI_MU_ENUM "", MU_ENUM_VALUE(MAP_RESULT, result));
MAP_HANDLE Map_Create(MAP_FILTER_CALLBACK mapFilterFunc)
{

Просмотреть файл

@ -16,7 +16,7 @@ extern "C" {
OPTIONHANDLER_ERROR, \
OPTIONHANDLER_INVALIDARG
MU_DEFINE_ENUM(OPTIONHANDLER_RESULT, OPTIONHANDLER_RESULT_VALUES)
MU_DEFINE_ENUM_WITHOUT_INVALID(OPTIONHANDLER_RESULT, OPTIONHANDLER_RESULT_VALUES)
typedef struct OPTIONHANDLER_HANDLE_DATA_TAG* OPTIONHANDLER_HANDLE;

Просмотреть файл

@ -31,7 +31,9 @@ typedef enum SOCKETIO_ADDRESS_TYPE_TAG
ADDRESS_TYPE_DOMAIN_SOCKET
} SOCKETIO_ADDRESS_TYPE;
#define RECEIVE_BYTES_VALUE 64
#ifndef XIO_RECEIVE_BUFFER_SIZE
#define XIO_RECEIVE_BUFFER_SIZE 64
#endif
MOCKABLE_FUNCTION(, CONCRETE_IO_HANDLE, socketio_create, void*, io_create_parameters);
MOCKABLE_FUNCTION(, void, socketio_destroy, CONCRETE_IO_HANDLE, socket_io);

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу