Azure IoT common library

Dependents:   STM32F746_iothub_client_sample_mqtt f767zi_mqtt iothub_client_sample_amqp iothub_client_sample_http ... more

Files at this revision

API Documentation at this revision

Comitter:
AzureIoTClient
Date:
Tue Mar 20 10:31:23 2018 -0700
Parent:
41:dc93369d5ed4
Child:
43:00b607807827
Commit message:
1.2.1

Changed in this revision

azure_c_shared_utility/const_defines.h Show annotated file Show diff for this revision Revisions of this file
azure_c_shared_utility/crt_abstractions.h Show annotated file Show diff for this revision Revisions of this file
azure_c_shared_utility/macro_utils.h Show annotated file Show diff for this revision Revisions of this file
azure_c_shared_utility/tlsio_wolfssl.h Show annotated file Show diff for this revision Revisions of this file
tlsio_wolfssl.c Show annotated file Show diff for this revision Revisions of this file
--- a/azure_c_shared_utility/const_defines.h	Mon Mar 05 17:43:09 2018 -0800
+++ b/azure_c_shared_utility/const_defines.h	Tue Mar 20 10:31:23 2018 -0700
@@ -11,8 +11,8 @@
     #define STATIC_VAR_UNUSED
 #endif
 
-#ifndef UNREFERENCED_PARAMETER
-#define UNREFERENCED_PARAMETER(param)   (void)(param)
+#ifndef AZURE_UNREFERENCED_PARAMETER
+#define AZURE_UNREFERENCED_PARAMETER(param)   (void)(param)
 #endif
 
 #endif // CONST_DEFINES
\ No newline at end of file
--- a/azure_c_shared_utility/crt_abstractions.h	Mon Mar 05 17:43:09 2018 -0800
+++ b/azure_c_shared_utility/crt_abstractions.h	Tue Mar 20 10:31:23 2018 -0700
@@ -50,8 +50,8 @@
 #else // __cplusplus
 typedef unsigned char bool;
 
-#define false	0
-#define true	1
+#define false   0
+#define true    1
 #endif // __cplusplus
 #endif // _WIN32_WCE
 
@@ -83,7 +83,6 @@
 /* Codes_SRS_CRT_ABSTRACTIONS_99_002: [CRTAbstractions module shall expose the following API]*/
 #ifdef _MSC_VER
 #else // _MSC_VER
-#include "inttypes.h"
 
 /* Adding definitions from errno.h & crtdefs.h */
 #if !defined (_TRUNCATE)
@@ -144,25 +143,6 @@
 #endif // __STDC_VERSION__
 #endif // _MSC_VER
 
-#ifdef _MSC_VER
-#define INT64_PRINTF "%I64d"
-#else
-#if defined __STDC_VERSION__
-#if ((__STDC_VERSION__  == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L))
-/*C99 compiler or C11*/
-#define INT64_PRINTF "%" PRId64 ""
-#else // ((__STDC_VERSION__  == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L))
-#error update this file to contain the latest C standard.
-#endif // ((__STDC_VERSION__  == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L))
-#else // __STDC_VERSION__
-#ifdef __cplusplus 
-#define INT64_PRINTF "%" PRId64 ""
-#else // __cplusplus
-#error unknown (or C89) compiler, provide INT64_PRINTF with the same meaning as PRIdN in C99 standard
-#endif // __cplusplus
-#endif // __STDC_VERSION__
-#endif // _MSC_VER
-
 #ifdef __cplusplus
 }
 #endif // __cplusplus
--- a/azure_c_shared_utility/macro_utils.h	Mon Mar 05 17:43:09 2018 -0800
+++ b/azure_c_shared_utility/macro_utils.h	Tue Mar 20 10:31:23 2018 -0700
@@ -4,7 +4,11 @@
 /*THIS FILE IS GENERATED*/
 /*DO NOT EDIT BY HAND!!!*/
 /*instead edit macro_utils.tt here: http://www.github.com/azure/azure-macro-utils-c.git */
-/*and then copy the generated file overwriting this one*/
+/*and then propagate the generated file to all the repos*/
+/* !!! CAUTION!!! This file is copied to multiple places */
+/* in https://github.com/Azure/azure-c-shared-utility.git, */
+/* and all of these copies must be located and replaced. */
+
 
 
 #ifndef MACRO_UTILS_H
@@ -12577,7 +12581,7 @@
 #define DEFINE_ENUM_STRINGS(enumName, ...) const char* C2(enumName, StringStorage)[COUNT_ARG(__VA_ARGS__)] = {FOR_EACH_1(DEFINE_ENUMERATION_CONSTANT_AS_STRING, __VA_ARGS__)}; \
 const char* C2(enumName,Strings)(enumName value)                   \
 {                                                                  \
-    if((int)value<0 || (int)value>=COUNT_ARG(__VA_ARGS__))                         \
+    if((int)value<0 || (int)value>=COUNT_ARG(__VA_ARGS__))         \
     {                                                              \
         /*this is an error case*/                                  \
         return NULL;                                               \
@@ -12612,9 +12616,9 @@
 
 #define DEFINE_LOCAL_ENUM(enumName, ...) typedef enum C2(enumName, _TAG) { FOR_EACH_1(DEFINE_ENUMERATION_CONSTANT, __VA_ARGS__)} enumName; \
 static const char* C2(enumName, StringStorage)[COUNT_ARG(__VA_ARGS__)] = {FOR_EACH_1(DEFINE_ENUMERATION_CONSTANT_AS_STRING, __VA_ARGS__)}; \
-static const char* C2(enumName,Strings)(enumName value)                   \
+static const char* C2(enumName,Strings)(enumName value)            \
 {                                                                  \
-    if((int)value<0 || (int)value>=COUNT_ARG(__VA_ARGS__))                         \
+    if((int)value<0 || (int)value>=COUNT_ARG(__VA_ARGS__))         \
     {                                                              \
         /*this is an error case*/                                  \
         return NULL;                                               \
@@ -12625,12 +12629,13 @@
     }                                                              \
 }
 
+
 #define ENUM_TO_STRING(enumName, enumValue) C2(enumName, Strings)(enumValue)
 #define STRING_TO_ENUM(stringValue, enumName, addressOfEnumVariable) C2(enumName, _FromString)(stringValue, addressOfEnumVariable)
 
 #define DEFINE_MICROMOCK_ENUM_TO_STRING(type, ...) MICROMOCK_ENUM_TO_STRING(type, FOR_EACH_1(DEFINE_ENUMERATION_CONSTANT_AS_WIDESTRING, __VA_ARGS__));
 
 #define EMPTY()
-#define DELAY(id) id EMPTY LPAREN )
+#define MACRO_UTILS_DELAY(id) id EMPTY LPAREN )
 
 #endif /*MACRO_UTILS_H*/
--- a/azure_c_shared_utility/tlsio_wolfssl.h	Mon Mar 05 17:43:09 2018 -0800
+++ b/azure_c_shared_utility/tlsio_wolfssl.h	Tue Mar 20 10:31:23 2018 -0700
@@ -7,6 +7,7 @@
 #include "azure_c_shared_utility/xio.h"
 #include "azure_c_shared_utility/xlogging.h"
 #include "azure_c_shared_utility/umock_c_prod.h"
+#include "azure_c_shared_utility/const_defines.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -15,6 +16,8 @@
 #include <stddef.h>
 #endif /* __cplusplus */
 
+extern const char* const OPTION_WOLFSSL_SET_DEVICE_ID;
+
 MOCKABLE_FUNCTION(, CONCRETE_IO_HANDLE, tlsio_wolfssl_create, void*, io_create_parameters);
 MOCKABLE_FUNCTION(, void, tlsio_wolfssl_destroy, CONCRETE_IO_HANDLE, tls_io);
 MOCKABLE_FUNCTION(, int, tlsio_wolfssl_open, CONCRETE_IO_HANDLE, tls_io, ON_IO_OPEN_COMPLETE, on_io_open_complete, void*, on_io_open_complete_context, ON_BYTES_RECEIVED, on_bytes_received, void*, on_bytes_received_context, ON_IO_ERROR, on_io_error, void*, on_io_error_context);
--- a/tlsio_wolfssl.c	Mon Mar 05 17:43:09 2018 -0800
+++ b/tlsio_wolfssl.c	Tue Mar 20 10:31:23 2018 -0700
@@ -6,6 +6,7 @@
 #include "wolfssl/options.h"
 #include "wolfssl/ssl.h"
 #include "wolfssl/error-ssl.h"
+#include "wolfssl/wolfcrypt/types.h"
 #include <stdio.h>
 #include <stdbool.h>
 #include <string.h>
@@ -49,8 +50,11 @@
     char* certificate;
     char* x509certificate;
     char* x509privatekey;
+    int wolfssl_device_id;
 } TLS_IO_INSTANCE;
 
+STATIC_VAR_UNUSED const char* const OPTION_WOLFSSL_SET_DEVICE_ID = "SetDeviceId";
+
 /*this function will clone an option given by name and value*/
 static void* tlsio_wolfssl_CloneOption(const char* name, const void* value)
 {
@@ -348,7 +352,7 @@
         TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)context;
         unsigned char* new_socket_io_read_bytes;
 
-        (void)ssl;
+        AZURE_UNREFERENCED_PARAMETER(ssl);
         while (tls_io_instance->socket_io_read_byte_count == 0)
         {
             xio_dowork(tls_io_instance->socket_io);
@@ -403,9 +407,10 @@
 static int on_io_send(WOLFSSL *ssl, char *buf, int sz, void *context)
 {
     int result;
+    AZURE_UNREFERENCED_PARAMETER(ssl);
+
     TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)context;
 
-    (void)ssl;
     if (xio_send(tls_io_instance->socket_io, buf, sz, tls_io_instance->on_send_complete, tls_io_instance->on_send_complete_callback_context) != 0)
     {
         LogError("Failed sending bytes through underlying IO");
@@ -423,8 +428,8 @@
 
 static int on_handshake_done(WOLFSSL* ssl, void* context)
 {
+    AZURE_UNREFERENCED_PARAMETER(ssl);
     TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)context;
-    (void)ssl;
     if (tls_io_instance->tlsio_state != TLSIO_STATE_IN_HANDSHAKE)
     {
         LogInfo("on_handshake_done called when not in IN_HANDSHAKE state");
@@ -511,6 +516,9 @@
         tls_io_instance->socket_io_read_byte_count = 0;
         tls_io_instance->on_send_complete = NULL;
         tls_io_instance->on_send_complete_callback_context = NULL;
+#ifdef INVALID_DEVID
+        tls_io_instance->wolfssl_device_id = INVALID_DEVID;
+#endif
 
         wolfSSL_set_using_nonblock(tls_io_instance->ssl, 1);
         wolfSSL_SetIOSend(tls_io_instance->ssl_context, on_io_send);
@@ -542,6 +550,13 @@
         LogError("unable to use x509 authentication");
         result = __FAILURE__;
     }
+#ifdef INVALID_DEVID
+    else if (tls_io_instance->wolfssl_device_id != INVALID_DEVID && wolfSSL_SetDevId(tls_io_instance->ssl, tls_io_instance->wolfssl_device_id) != WOLFSSL_SUCCESS)
+    {
+        LogError("Failure setting device id");
+        result = __FAILURE__;
+    }
+#endif
     else
     {
         result = 0;
@@ -593,6 +608,7 @@
             }
             else
             {
+                SOCKETIO_CONFIG socketio_config;
                 const IO_INTERFACE_DESCRIPTION* underlying_io_interface;
                 void* io_interface_parameters;
 
@@ -603,8 +619,6 @@
                 }
                 else
                 {
-                    SOCKETIO_CONFIG socketio_config;
-
                     socketio_config.hostname = tls_io_config->hostname;
                     socketio_config.port = tls_io_config->port;
                     socketio_config.accepted_socket = NULL;
@@ -890,6 +904,30 @@
         {
             result = process_option(&tls_io_instance->x509privatekey, optionName, value);
         }
+#ifdef INVALID_DEVID
+        else if (strcmp(OPTION_WOLFSSL_SET_DEVICE_ID, optionName) == 0)
+        {
+            int device_id = *((int *)value);
+            if (tls_io_instance->ssl != NULL)
+            {
+                if (tls_io_instance->ssl != NULL && wolfSSL_SetDevId(tls_io_instance->ssl, device_id) != WOLFSSL_SUCCESS)
+                {
+                    LogError("Failure setting device id on ssl");
+                    result = __FAILURE__;
+                }
+                else
+                {
+                    result = 0;
+                }
+            }
+            else
+            {
+                // Save the id till we create the ssl object
+                tls_io_instance->wolfssl_device_id = device_id;
+                result = 0;
+            }
+        }
+#endif
         else
         {
             if (tls_io_instance->socket_io == NULL)