Index: azure_iot_hub_f767zi/trunk/azure_iot_sdk/c-utility/adapters/httpapi_compact.c
===================================================================
--- azure_iot_hub_f767zi/trunk/azure_iot_sdk/c-utility/adapters/httpapi_compact.c	(revision 468)
+++ azure_iot_hub_f767zi/trunk/azure_iot_sdk/c-utility/adapters/httpapi_compact.c	(revision 471)
@@ -7,6 +7,4 @@
 #include <string.h>
 #include <limits.h>
-
-#include "azure_macro_utils/macro_utils.h"
 #include "azure_c_shared_utility/gballoc.h"
 #include "azure_c_shared_utility/httpheaders.h"
@@ -51,4 +49,8 @@
     char*           x509ClientCertificate;
     char*           x509ClientPrivateKey;
+    const char*     proxy_host;
+    int             proxy_port;
+    const char*     proxy_username;
+    const char*     proxy_password;
     XIO_HANDLE      xio_handle;
     size_t          received_bytes_count;
@@ -201,5 +203,4 @@
 {
     HTTP_HANDLE_DATA* http_instance;
-    TLSIO_CONFIG tlsio_config;
 
     if (hostName == NULL)
@@ -223,7 +224,7 @@
             LogError("There is no memory to control the http connection");
         }
-        else if (mallocAndStrcpy_s(&http_instance->hostName, hostName) != 0)
-        {
-            LogError("Failed copying hostname");
+        else if(mallocAndStrcpy_s((char**)&(http_instance->hostName), hostName) != 0)
+        {
+            LogError("failure allocate host name");
             free(http_instance);
             http_instance = NULL;
@@ -231,29 +232,16 @@
         else
         {
-            tlsio_config.hostname = http_instance->hostName;
-            tlsio_config.port = 443;
-            tlsio_config.underlying_io_interface = NULL;
-            tlsio_config.underlying_io_parameters = NULL;
-
-            http_instance->xio_handle = xio_create(platform_get_default_tlsio(), (void*)&tlsio_config);
-
-            /*Codes_SRS_HTTPAPI_COMPACT_21_016: [ If the HTTPAPI_CreateConnection failed to create the connection, it shall return NULL as the handle. ]*/
-            if (http_instance->xio_handle == NULL)
-            {
-                LogError("Create connection failed");
-                free(http_instance->hostName);
-                free(http_instance);
-                http_instance = NULL;
-            }
-            else
-            {
-                http_instance->is_connected = 0;
-                http_instance->is_io_error = 0;
-                http_instance->received_bytes_count = 0;
-                http_instance->received_bytes = NULL;
-                http_instance->certificate = NULL;
-                http_instance->x509ClientCertificate = NULL;
-                http_instance->x509ClientPrivateKey = NULL;
-            }
+            http_instance->xio_handle = NULL;
+            http_instance->is_connected = 0;
+            http_instance->is_io_error = 0;
+            http_instance->received_bytes_count = 0;
+            http_instance->received_bytes = NULL;
+            http_instance->certificate = NULL;
+            http_instance->x509ClientCertificate = NULL;
+            http_instance->x509ClientPrivateKey = NULL;
+            http_instance->proxy_host = NULL;
+            http_instance->proxy_port = 0;
+            http_instance->proxy_username = NULL;
+            http_instance->proxy_password = NULL;
         }
     }
@@ -321,4 +309,9 @@
         }
 
+        if (http_instance->hostName != NULL)
+        {
+            free((void*)http_instance->hostName);
+        }
+
 #ifndef DO_NOT_COPY_TRUSTED_CERTS_STRING
         /*Codes_SRS_HTTPAPI_COMPACT_21_018: [ If there is a certificate associated to this connection, the HTTPAPI_CloseConnection shall free all allocated memory for the certificate. ]*/
@@ -341,7 +334,15 @@
         }
 
-        if (http_instance->hostName)
-        {
-            free(http_instance->hostName);
+        if (http_instance->proxy_host != NULL)
+        {
+            free((void*)http_instance->proxy_host);
+        }
+        if (http_instance->proxy_username != NULL)
+        {
+            free((void*)http_instance->proxy_username);
+        }
+        if (http_instance->proxy_password != NULL)
+        {
+            free((void*)http_instance->proxy_password);
         }
 
@@ -711,4 +712,6 @@
 {
     HTTPAPI_RESULT result;
+    TLSIO_CONFIG tlsio_config;
+    HTTP_PROXY_IO_CONFIG http_proxy_io_config;
 
     if (http_instance->is_connected != 0)
@@ -720,7 +723,38 @@
     {
         http_instance->is_io_error = 0;
-
+        tlsio_config.hostname = http_instance->hostName;
+        tlsio_config.port = 443;
+
+        if (http_instance->proxy_host != NULL) {
+            tlsio_config.underlying_io_interface = http_proxy_io_get_interface_description();
+        }
+        else {
+            tlsio_config.underlying_io_interface = NULL;
+        }
+
+        if (tlsio_config.underlying_io_interface != NULL) {
+            tlsio_config.underlying_io_parameters = (void*)&http_proxy_io_config;
+
+            http_proxy_io_config.proxy_hostname = http_instance->proxy_host;
+            http_proxy_io_config.proxy_port = http_instance->proxy_port;
+            http_proxy_io_config.username = http_instance->proxy_username;
+            http_proxy_io_config.password = http_instance->proxy_password;
+            http_proxy_io_config.hostname = http_instance->hostName;
+            http_proxy_io_config.port = 443;
+        }
+        else {
+            tlsio_config.underlying_io_parameters = NULL;
+        }
+
+        http_instance->xio_handle = xio_create(platform_get_default_tlsio(), (void*)&tlsio_config);
+
+        if (http_instance->xio_handle == NULL)
+        {
+            LogError("Create connection failed");
+            free(http_instance);
+            http_instance = NULL;
+        }
         /*Codes_SRS_HTTPAPI_COMPACT_21_022: [ If a Certificate was provided, the HTTPAPI_ExecuteRequest shall set this option on the transport layer. ]*/
-        if ((http_instance->certificate != NULL) &&
+        else if ((http_instance->certificate != NULL) &&
             (xio_setoption(http_instance->xio_handle, OPTION_TRUSTED_CERT, http_instance->certificate) != 0))
         {
@@ -740,5 +774,4 @@
             (xio_setoption(http_instance->xio_handle, SU_OPTION_X509_PRIVATE_KEY, http_instance->x509ClientPrivateKey) != 0))
         {
-
             /*Codes_SRS_HTTPAPI_COMPACT_06_006: [ If the transport failed setting the client certificate private key, the HTTPAPI_ExecuteRequest shall not send any request and return HTTPAPI_SET_OPTION_FAILED. ] */
             result = HTTPAPI_SET_OPTION_FAILED;
@@ -764,5 +797,5 @@
                 {
                     xio_dowork(http_instance->xio_handle);
-                    LogInfo("Waiting for TLS connection");
+                    //LogInfo("Waiting for TLS connection");
                     if ((countRetry--) < 0)
                     {
@@ -838,5 +871,5 @@
 const char* get_request_type(HTTPAPI_REQUEST_TYPE requestType)
 {
-    return (const char*)httpapiRequestString[requestType - HTTPAPI_REQUEST_GET];
+    return (const char*)httpapiRequestString[requestType];
 }
 
@@ -1220,20 +1253,20 @@
     {
         result = HTTPAPI_INVALID_ARG;
-        LogError("(result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(HTTPAPI_RESULT, result));
+        LogError("(result = %s)", MU_ENUM_TO_STRING(HTTPAPI_RESULT, result));
     }
     /*Codes_SRS_HTTPAPI_COMPACT_21_024: [ The HTTPAPI_ExecuteRequest shall open the transport connection with the host to send the request. ]*/
     else if ((result = OpenXIOConnection(http_instance)) != HTTPAPI_OK)
     {
-        LogError("Open HTTP connection failed (result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(HTTPAPI_RESULT, result));
+        LogError("Open HTTP connection failed (result = %s)", MU_ENUM_TO_STRING(HTTPAPI_RESULT, result));
     }
     /*Codes_SRS_HTTPAPI_COMPACT_21_026: [ If the open process succeed, the HTTPAPI_ExecuteRequest shall send the request message to the host. ]*/
     else if ((result = SendHeadsToXIO(http_instance, requestType, relativePath, httpHeadersHandle, headersCount)) != HTTPAPI_OK)
     {
-        LogError("Send heads to HTTP failed (result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(HTTPAPI_RESULT, result));
+        LogError("Send heads to HTTP failed (result = %s)", MU_ENUM_TO_STRING(HTTPAPI_RESULT, result));
     }
     /*Codes_SRS_HTTPAPI_COMPACT_21_042: [ The request can contain the a content message, provided in content parameter. ]*/
     else if ((result = SendContentToXIO(http_instance, content, contentLength)) != HTTPAPI_OK)
     {
-        LogError("Send content to HTTP failed (result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(HTTPAPI_RESULT, result));
+        LogError("Send content to HTTP failed (result = %s)", MU_ENUM_TO_STRING(HTTPAPI_RESULT, result));
     }
     /*Codes_SRS_HTTPAPI_COMPACT_21_030: [ At the end of the transmission, the HTTPAPI_ExecuteRequest shall receive the response from the host. ]*/
@@ -1241,10 +1274,10 @@
     else if ((result = ReceiveHeaderFromXIO(http_instance, statusCode)) != HTTPAPI_OK)
     {
-        LogError("Receive header from HTTP failed (result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(HTTPAPI_RESULT, result));
+        LogError("Receive header from HTTP failed (result = %s)", MU_ENUM_TO_STRING(HTTPAPI_RESULT, result));
     }
     /*Codes_SRS_HTTPAPI_COMPACT_21_074: [ After the header, the message received by the HTTPAPI_ExecuteRequest can contain addition information about the content. ]*/
     else if ((result = ReceiveContentInfoFromXIO(http_instance, responseHeadersHandle, &bodyLength, &chunked)) != HTTPAPI_OK)
     {
-        LogError("Receive content information from HTTP failed (result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(HTTPAPI_RESULT, result));
+        LogError("Receive content information from HTTP failed (result = %s)", MU_ENUM_TO_STRING(HTTPAPI_RESULT, result));
     }
     /*Codes_SRS_HTTPAPI_COMPACT_42_084: [ The message received by the HTTPAPI_ExecuteRequest should not contain http body. ]*/
@@ -1254,5 +1287,5 @@
         if ((result = ReadHTTPResponseBodyFromXIO(http_instance, bodyLength, chunked, responseContent)) != HTTPAPI_OK)
         {
-            LogError("Read HTTP response body from HTTP failed (result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(HTTPAPI_RESULT, result));
+            LogError("Read HTTP response body from HTTP failed (result = %s)", MU_ENUM_TO_STRING(HTTPAPI_RESULT, result));
         }
     }
@@ -1311,5 +1344,5 @@
 #endif // DO_NOT_COPY_TRUSTED_CERTS_STRING
     }
-    else if (strcmp(SU_OPTION_X509_CERT, optionName) == 0 || strcmp(OPTION_X509_ECC_CERT, optionName) == 0)
+    else if (strcmp(SU_OPTION_X509_CERT, optionName) == 0)
     {
         int len;
@@ -1334,5 +1367,5 @@
         }
     }
-    else if (strcmp(SU_OPTION_X509_PRIVATE_KEY, optionName) == 0 || strcmp(OPTION_X509_ECC_KEY, optionName) == 0)
+    else if (strcmp(SU_OPTION_X509_PRIVATE_KEY, optionName) == 0)
     {
         int len;
@@ -1359,68 +1392,66 @@
     else if (strcmp(OPTION_HTTP_PROXY, optionName) == 0)
     {
-        TLSIO_CONFIG tlsio_config;
-        HTTP_PROXY_IO_CONFIG proxy_config;
-        HTTP_PROXY_OPTIONS* proxy_options = (HTTP_PROXY_OPTIONS*)value;
-
-        if (proxy_options->host_address == NULL)
-        {
-            LogError("NULL host_address in proxy options");
+        HTTP_PROXY_OPTIONS* proxy_data = (HTTP_PROXY_OPTIONS*)value;
+        if (proxy_data->host_address == NULL || proxy_data->port <= 0)
+        {
+            LogError("invalid proxy_data values ( host_address = %p, port = %d)", proxy_data->host_address, proxy_data->port);
             result = HTTPAPI_ERROR;
         }
-        else if (((proxy_options->username == NULL) || (proxy_options->password == NULL)) &&
-                (proxy_options->username != proxy_options->password))
-        {
-            LogError("Only one of username and password for proxy settings was NULL");
-            result = HTTPAPI_ERROR;
-        }
         else
         {
-
-            /* Workaround: xio interface is already created when HTTPAPI_CreateConnection is call without proxy support
-             * need to destroy the interface and create a new one with proxy information
-             */
-            OPTIONHANDLER_HANDLE xio_options;
-            if ((xio_options = xio_retrieveoptions(http_instance->xio_handle)) == NULL)
-            {
-                LogError("failed saving underlying I/O transport options");
+            if(http_instance->proxy_host != NULL)
+            {
+                free((void*)http_instance->proxy_host);
+                http_instance->proxy_host = NULL;
+            }
+            if(mallocAndStrcpy_s((char**)&(http_instance->proxy_host), (const char*)proxy_data->host_address) != 0)
+            {
+                LogError("failure allocate proxy host");
                 result = HTTPAPI_ERROR;
             }
             else
             {
-                xio_destroy(http_instance->xio_handle);
-
-                proxy_config.hostname = http_instance->hostName;
-                proxy_config.proxy_hostname = proxy_options->host_address;
-                proxy_config.password = proxy_options->password;
-                proxy_config.username = proxy_options->username;
-                proxy_config.proxy_port = proxy_options->port;
-                proxy_config.port = 443;
-
-                tlsio_config.hostname = http_instance->hostName;
-                tlsio_config.port = 443;
-                tlsio_config.underlying_io_interface =  http_proxy_io_get_interface_description();
-                tlsio_config.underlying_io_parameters = &proxy_config;
-
-                http_instance->xio_handle = xio_create(platform_get_default_tlsio(), (void*)&tlsio_config);
-
-                if (http_instance->xio_handle == NULL)
-                {
-                    LogError("Failed to create xio handle with proxy configuration");
-                    result = HTTPAPI_ERROR;
+                http_instance->proxy_port = proxy_data->port;
+
+                if (proxy_data->username != NULL && proxy_data->password != NULL)
+                {
+                    if(http_instance->proxy_username != NULL)
+                    {
+                        free((void*)http_instance->proxy_username);
+                        http_instance->proxy_username = NULL;
+                    }
+                    if(mallocAndStrcpy_s((char**)&(http_instance->proxy_username), (const char*)proxy_data->username) != 0)
+                    {
+                        LogError("failure allocate proxy username");
+                        free((void*)http_instance->proxy_host);
+                        http_instance->proxy_host = NULL;
+                        result = HTTPAPI_ERROR;
+                    }
+                    else
+                    {
+                        if(http_instance->proxy_password != NULL)
+                        {
+                          free((void*)http_instance->proxy_password);
+                          http_instance->proxy_password = NULL;
+                        }
+                        if(mallocAndStrcpy_s((char**)&(http_instance->proxy_password), (const char*)proxy_data->password) != 0)
+                        {
+                            LogError("failure allocate proxy password");
+                            free((void*)http_instance->proxy_host);
+                            http_instance->proxy_host = NULL;
+                            free((void*)http_instance->proxy_username);
+                            http_instance->proxy_username = NULL;
+                            result = HTTPAPI_ERROR;
+                        }
+                        else
+                        {
+                          result = HTTPAPI_OK;
+                        }
+                    }
                 }
                 else
                 {
-                    if (OptionHandler_FeedOptions(xio_options, http_instance->xio_handle) != OPTIONHANDLER_OK)
-                    {
-                        LogError("Failed feeding existing options to new xio instance.");
-                        result = HTTPAPI_ERROR;
-                    }
-                    else
-                    {
-                        result = HTTPAPI_OK;
-                    }
-                }
-
-                OptionHandler_Destroy(xio_options);
+                    result = HTTPAPI_OK;
+                }
             }
         }
@@ -1432,5 +1463,4 @@
         LogInfo("unknown option %s", optionName);
     }
-
     return result;
 }
@@ -1477,5 +1507,5 @@
 #endif // DO_NOT_COPY_TRUSTED_CERTS_STRING
     }
-    else if (strcmp(SU_OPTION_X509_CERT, optionName) == 0 || strcmp(OPTION_X509_ECC_CERT, optionName) == 0)
+    else if (strcmp(SU_OPTION_X509_CERT, optionName) == 0)
     {
         certLen = strlen((const char*)value);
@@ -1494,5 +1524,5 @@
         }
     }
-    else if (strcmp(SU_OPTION_X509_PRIVATE_KEY, optionName) == 0 || strcmp(OPTION_X509_ECC_KEY, optionName) == 0)
+    else if (strcmp(SU_OPTION_X509_PRIVATE_KEY, optionName) == 0)
     {
         certLen = strlen((const char*)value);
Index: azure_iot_hub_f767zi/trunk/azure_iot_sdk/c-utility/adapters/tlsio_wolfssl.c
===================================================================
--- azure_iot_hub_f767zi/trunk/azure_iot_sdk/c-utility/adapters/tlsio_wolfssl.c	(revision 468)
+++ azure_iot_hub_f767zi/trunk/azure_iot_sdk/c-utility/adapters/tlsio_wolfssl.c	(revision 471)
@@ -52,10 +52,9 @@
     char* x509privatekey;
     int wolfssl_device_id;
-    char* hostname;
-    bool ignore_host_name_check;
+    size_t socket_reads;
 } TLS_IO_INSTANCE;
 
 STATIC_VAR_UNUSED const char* const OPTION_WOLFSSL_SET_DEVICE_ID = "SetDeviceId";
-static const size_t SOCKET_READ_LIMIT = 5;
+static const size_t SOCKET_READ_LIMIT = 10000; // 10,000 ms ?
 
 /*this function will clone an option given by name and value*/
@@ -106,21 +105,4 @@
             }
         }
-        #ifdef INVALID_DEVID
-        else if(strcmp(name, OPTION_WOLFSSL_SET_DEVICE_ID) == 0 )
-        {
-             int* value_clone;
-
-             if ((value_clone = malloc(sizeof(int))) == NULL)
-             {
-                 LogError("unable to clone device id option");
-             }
-             else
-             {
-                 *value_clone = *(int*)value;
-             }
-
-             result = value_clone;
-        }
-        #endif
         else
         {
@@ -144,6 +126,5 @@
         if ((strcmp(name, OPTION_TRUSTED_CERT) == 0) ||
             (strcmp(name, SU_OPTION_X509_CERT) == 0) ||
-            (strcmp(name, SU_OPTION_X509_PRIVATE_KEY) == 0) ||
-            (strcmp(name, OPTION_WOLFSSL_SET_DEVICE_ID) == 0))
+            (strcmp(name, SU_OPTION_X509_PRIVATE_KEY) == 0))
         {
             free((void*)value);
@@ -203,15 +184,4 @@
                 result = NULL;
             }
-            #ifdef INVALID_DEVID
-            else if (
-                (tls_io_instance->wolfssl_device_id != INVALID_DEVID) &&
-                (OptionHandler_AddOption(result, OPTION_WOLFSSL_SET_DEVICE_ID, &tls_io_instance->wolfssl_device_id) != OPTIONHANDLER_OK)
-                )
-            {
-                LogError("unable to save deviceid option");
-                OptionHandler_Destroy(result);
-                result = NULL;
-            }
-            #endif
             else
             {
@@ -287,10 +257,10 @@
         int res;
         tls_io_instance->tlsio_state = TLSIO_STATE_IN_HANDSHAKE;
+        tls_io_instance->socket_reads = 0;
 
         res = wolfSSL_connect(tls_io_instance->ssl);
         if (res != SSL_SUCCESS)
         {
-            // Error codes explained in https://www.wolfssl.com/docs/wolfssl-manual/appendix-c/
-            LogError("WolfSSL connect failed (%d)", wolfSSL_get_error(tls_io_instance->ssl, res));
+            LogError("WolfSSL connect failed");
             indicate_open_complete(tls_io_instance, IO_OPEN_ERROR);
             tls_io_instance->tlsio_state = TLSIO_STATE_ERROR;
@@ -384,15 +354,18 @@
         TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)context;
         unsigned char* new_socket_io_read_bytes;
-        size_t socket_reads = 0;
 
         AZURE_UNREFERENCED_PARAMETER(ssl);
-        while (tls_io_instance->socket_io_read_byte_count == 0 && socket_reads < SOCKET_READ_LIMIT)
-        {
+        if (tls_io_instance->socket_io_read_byte_count == 0)
+        {
+            if (tls_io_instance->socket_reads >= SOCKET_READ_LIMIT) {
+                return WOLFSSL_CBIO_ERR_TIMEOUT;
+            }
             xio_dowork(tls_io_instance->socket_io);
-            if (tls_io_instance->tlsio_state != TLSIO_STATE_IN_HANDSHAKE)
-            {
-                break;
-            }
-            socket_reads++;
+            if (tls_io_instance->tlsio_state == TLSIO_STATE_IN_HANDSHAKE)
+            {
+                tls_io_instance->socket_reads++;
+                ThreadAPI_Sleep(1);
+                return 0;
+            }
         }
 
@@ -443,4 +416,16 @@
 }
 
+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) || (tls_io_instance->on_send_complete == NULL))
+		return;
+
+	tls_io_instance->on_send_complete(tls_io_instance->on_send_complete_callback_context, send_result);
+
+	tls_io_instance->on_send_complete = NULL;
+	tls_io_instance->on_send_complete_callback_context = NULL;
+}
+
 static int on_io_send(WOLFSSL *ssl, char *buf, int sz, void *context)
 {
@@ -450,10 +435,10 @@
     TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)context;
 
-    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)
+    if (xio_send(tls_io_instance->socket_io, buf, sz, on_send_complete, tls_io_instance) != 0)
     {
         LogError("Failed sending bytes through underlying IO");
         tls_io_instance->tlsio_state = TLSIO_STATE_ERROR;
         indicate_error(tls_io_instance);
-        result = WOLFSSL_CBIO_ERR_GENERAL;
+        result = -1;
     }
     else
@@ -469,5 +454,7 @@
     AZURE_UNREFERENCED_PARAMETER(ssl);
     TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)context;
-    if (tls_io_instance->tlsio_state != TLSIO_STATE_IN_HANDSHAKE)
+    if (tls_io_instance->tlsio_state == TLSIO_STATE_OPEN) {
+    }
+    else if (tls_io_instance->tlsio_state != TLSIO_STATE_IN_HANDSHAKE)
     {
         LogInfo("on_handshake_done called when not in IN_HANDSHAKE state");
@@ -569,29 +556,8 @@
 }
 
-static int enable_domain_check(TLS_IO_INSTANCE* tls_io_instance)
-{
-    int result = 0;
-
-    if (!tls_io_instance->ignore_host_name_check)
-    {
-        if (wolfSSL_check_domain_name(tls_io_instance->ssl, tls_io_instance->hostname) != WOLFSSL_SUCCESS)
-        {
-            result = MU_FAILURE;
-        }
-    }
-
-    return result;
-}
-
 static int prepare_wolfssl_open(TLS_IO_INSTANCE* tls_io_instance)
 {
     int result;
-
-    if (enable_domain_check(tls_io_instance))
-    {
-        LogError("Failed to configure domain name verification");
-        result = MU_FAILURE;
-    }
-    else if (add_certificate_to_store(tls_io_instance) != 0)
+    if (add_certificate_to_store(tls_io_instance) != 0)
     {
         LogError("Failed to add certificates to store");
@@ -607,4 +573,11 @@
         result = MU_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 = MU_FAILURE;
+    }
+#endif
     else
     {
@@ -653,10 +626,4 @@
             {
                 LogError("Cannot create the wolfSSL context");
-                free(result);
-                result = NULL;
-            }
-            else if (mallocAndStrcpy_s(&result->hostname, tls_io_config->hostname) != 0)
-            {
-                LogError("Failed copying the target hostname.");
                 free(result);
                 result = NULL;
@@ -691,5 +658,4 @@
                     LogError("Failed getting socket IO interface description.");
                     wolfSSL_CTX_free(result->ssl_context);
-                    free(result->hostname);
                     free(result);
                     result = NULL;
@@ -702,5 +668,4 @@
                         LogError("Failure connecting to underlying socket_io");
                         wolfSSL_CTX_free(result->ssl_context);
-                        free(result->hostname);
                         free(result);
                         result = NULL;
@@ -710,5 +675,4 @@
                         LogError("Failure connecting to underlying socket_io");
                         wolfSSL_CTX_free(result->ssl_context);
-                        free(result->hostname);
                         free(result);
                         result = NULL;
@@ -753,5 +717,4 @@
 
         xio_destroy(tls_io_instance->socket_io);
-        free(tls_io_instance->hostname);
         free(tls_io);
     }
@@ -803,8 +766,176 @@
             else
             {
-                // The state can get changed in the on_underlying_io_open_complete
-                if (tls_io_instance->tlsio_state != TLSIO_STATE_OPEN)
+                result = 0;
+            }
+        }
+    }
+
+    return result;
+}
+
+int tlsio_wolfssl_close(CONCRETE_IO_HANDLE tls_io, ON_IO_CLOSE_COMPLETE on_io_close_complete, void* callback_context)
+{
+    int result = 0;
+
+    if (tls_io == NULL)
+    {
+        LogError("NULL tls_io handle.");
+        result = MU_FAILURE;
+    }
+    else
+    {
+        TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)tls_io;
+
+        if ((tls_io_instance->tlsio_state == TLSIO_STATE_NOT_OPEN) ||
+            (tls_io_instance->tlsio_state == TLSIO_STATE_CLOSING))
+        {
+            LogError("Close called while not open.");
+            result = MU_FAILURE;
+        }
+        else
+        {
+            tls_io_instance->tlsio_state = TLSIO_STATE_CLOSING;
+            tls_io_instance->on_io_close_complete = on_io_close_complete;
+            tls_io_instance->on_io_close_complete_context = callback_context;
+
+            if (xio_close(tls_io_instance->socket_io, on_underlying_io_close_complete, tls_io_instance) != 0)
+            {
+                LogError("xio_close failed.");
+                result = MU_FAILURE;
+            }
+            else
+            {
+                result = 0;
+            }
+        }
+    }
+
+    return result;
+}
+
+int tlsio_wolfssl_send(CONCRETE_IO_HANDLE tls_io, const void* buffer, size_t size, ON_SEND_COMPLETE on_send_complete, void* callback_context)
+{
+    int result;
+
+    if (tls_io == NULL || buffer == NULL || size == 0)
+    {
+        LogError("Invalid parameter specified tls_io: %p, buffer: %p, size: %ul", tls_io, buffer, (unsigned int)size);
+        result = MU_FAILURE;
+    }
+    else
+    {
+        TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)tls_io;
+
+        if (tls_io_instance->tlsio_state != TLSIO_STATE_OPEN)
+        {
+            LogError("send called while not open");
+            result = MU_FAILURE;
+        }
+        if (tls_io_instance->on_send_complete != NULL)
+        {
+            LogError("Error writing data");
+            result = MU_FAILURE;
+        }
+        else
+        {
+            tls_io_instance->on_send_complete = on_send_complete;
+            tls_io_instance->on_send_complete_callback_context = callback_context;
+
+            int res = wolfSSL_write(tls_io_instance->ssl, buffer, size);
+            if ((res < 0) || ((size_t)res != size)) // Best way I can think of to safely compare an int to a size_t
+            {
+                LogError("Error writing data through WolfSSL");
+                result = MU_FAILURE;
+            }
+            else
+            {
+                result = 0;
+            }
+        }
+    }
+
+    return result;
+}
+
+void tlsio_wolfssl_dowork(CONCRETE_IO_HANDLE tls_io)
+{
+    if (tls_io == NULL)
+    {
+        LogError("NULL tls_io");
+    }
+    else
+    {
+        TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)tls_io;
+
+        if ((tls_io_instance->tlsio_state != TLSIO_STATE_NOT_OPEN) &&
+            (tls_io_instance->tlsio_state != TLSIO_STATE_ERROR))
+        {
+            if (tls_io_instance->tlsio_state != TLSIO_STATE_OPENING_UNDERLYING_IO)
+                decode_ssl_received_bytes(tls_io_instance);
+            xio_dowork(tls_io_instance->socket_io);
+        }
+    }
+}
+
+
+static int process_option(char** destination, const char* name, const char* value)
+{
+    int result;
+    if (*destination != NULL)
+    {
+        free(*destination);
+        *destination = NULL;
+    }
+    if (mallocAndStrcpy_s(destination, value) != 0)
+    {
+        LogError("unable to process option %s",name);
+        result = MU_FAILURE;
+    }
+    else
+    {
+        result = 0;
+    }
+    return result;
+}
+
+int tlsio_wolfssl_setoption(CONCRETE_IO_HANDLE tls_io, const char* optionName, const void* value)
+{
+    int result;
+
+    if (tls_io == NULL || optionName == NULL)
+    {
+        LogError("Bad arguments, tls_io = %p, optionName = %p", tls_io, optionName);
+        result = MU_FAILURE;
+    }
+    else
+    {
+        TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)tls_io;
+
+        if (strcmp(OPTION_TRUSTED_CERT, optionName) == 0)
+        {
+            result  = process_option(&tls_io_instance->certificate, optionName, value);
+        }
+        else if (strcmp(SU_OPTION_X509_CERT, optionName) == 0 || strcmp(OPTION_X509_ECC_CERT, optionName) == 0)
+        {
+            result = process_option(&tls_io_instance->x509certificate, optionName, value);
+        }
+        else if (strcmp(SU_OPTION_X509_PRIVATE_KEY, optionName) == 0 || strcmp(OPTION_X509_ECC_KEY, optionName) == 0)
+        {
+            result = process_option(&tls_io_instance->x509privatekey, optionName, value);
+        }
+        else if (strcmp(optionName, OPTION_SET_TLS_RENEGOTIATION) == 0)
+        {
+            // No need to do anything for WolfSSL
+            result = 0;
+        }
+#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("Failed to connect to server.  The certificates may not be correct.");
+                    LogError("Failure setting device id on ssl");
                     result = MU_FAILURE;
                 }
@@ -814,174 +945,7 @@
                 }
             }
-        }
-    }
-
-    return result;
-}
-
-int tlsio_wolfssl_close(CONCRETE_IO_HANDLE tls_io, ON_IO_CLOSE_COMPLETE on_io_close_complete, void* callback_context)
-{
-    int result = 0;
-
-    if (tls_io == NULL)
-    {
-        LogError("NULL tls_io handle.");
-        result = MU_FAILURE;
-    }
-    else
-    {
-        TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)tls_io;
-
-        if ((tls_io_instance->tlsio_state == TLSIO_STATE_NOT_OPEN) ||
-            (tls_io_instance->tlsio_state == TLSIO_STATE_CLOSING))
-        {
-            LogError("Close called while not open.");
-            result = MU_FAILURE;
-        }
-        else
-        {
-            tls_io_instance->tlsio_state = TLSIO_STATE_CLOSING;
-            tls_io_instance->on_io_close_complete = on_io_close_complete;
-            tls_io_instance->on_io_close_complete_context = callback_context;
-
-            if (xio_close(tls_io_instance->socket_io, on_underlying_io_close_complete, tls_io_instance) != 0)
-            {
-                LogError("xio_close failed.");
-                result = MU_FAILURE;
-            }
-            else
-            {
-                result = 0;
-            }
-        }
-    }
-
-    return result;
-}
-
-int tlsio_wolfssl_send(CONCRETE_IO_HANDLE tls_io, const void* buffer, size_t size, ON_SEND_COMPLETE on_send_complete, void* callback_context)
-{
-    int result;
-
-    if (tls_io == NULL || buffer == NULL || size == 0)
-    {
-        LogError("Invalid parameter specified tls_io: %p, buffer: %p, size: %ul", tls_io, buffer, (unsigned int)size);
-        result = MU_FAILURE;
-    }
-    else
-    {
-        TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)tls_io;
-
-        if (tls_io_instance->tlsio_state != TLSIO_STATE_OPEN)
-        {
-            LogError("send called while not open");
-            result = MU_FAILURE;
-        }
-        else
-        {
-            tls_io_instance->on_send_complete = on_send_complete;
-            tls_io_instance->on_send_complete_callback_context = callback_context;
-
-            int res = wolfSSL_write(tls_io_instance->ssl, buffer, size);
-            if ((res < 0) || ((size_t)res != size)) // Best way I can think of to safely compare an int to a size_t
-            {
-                LogError("Error writing data through WolfSSL");
-                result = MU_FAILURE;
-            }
-            else
-            {
-                result = 0;
-            }
-        }
-    }
-
-    return result;
-}
-
-void tlsio_wolfssl_dowork(CONCRETE_IO_HANDLE tls_io)
-{
-    if (tls_io == NULL)
-    {
-        LogError("NULL tls_io");
-    }
-    else
-    {
-        TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)tls_io;
-
-        if ((tls_io_instance->tlsio_state != TLSIO_STATE_NOT_OPEN) &&
-            (tls_io_instance->tlsio_state != TLSIO_STATE_ERROR))
-        {
-            decode_ssl_received_bytes(tls_io_instance);
-            xio_dowork(tls_io_instance->socket_io);
-        }
-    }
-}
-
-
-static int process_option(char** destination, const char* name, const char* value)
-{
-
-    (void) name;
-    
-    int result;
-    if (*destination != NULL)
-    {
-        free(*destination);
-        *destination = NULL;
-    }
-    if (mallocAndStrcpy_s(destination, value) != 0)
-    {
-        LogError("unable to process option %s",name);
-        result = MU_FAILURE;
-    }
-    else
-    {
-        result = 0;
-    }
-    return result;
-}
-
-int tlsio_wolfssl_setoption(CONCRETE_IO_HANDLE tls_io, const char* optionName, const void* value)
-{
-    int result;
-
-    if (tls_io == NULL || optionName == NULL)
-    {
-        LogError("Bad arguments, tls_io = %p, optionName = %p", tls_io, optionName);
-        result = MU_FAILURE;
-    }
-    else
-    {
-        TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)tls_io;
-
-        if (strcmp(OPTION_TRUSTED_CERT, optionName) == 0)
-        {
-            result  = process_option(&tls_io_instance->certificate, optionName, value);
-        }
-        else if (strcmp(SU_OPTION_X509_CERT, optionName) == 0 || strcmp(OPTION_X509_ECC_CERT, optionName) == 0)
-        {
-            result = process_option(&tls_io_instance->x509certificate, optionName, value);
-        }
-        else if (strcmp(SU_OPTION_X509_PRIVATE_KEY, optionName) == 0 || strcmp(OPTION_X509_ECC_KEY, optionName) == 0)
-        {
-            result = process_option(&tls_io_instance->x509privatekey, optionName, value);
-        }
-        else if (strcmp(optionName, OPTION_SET_TLS_RENEGOTIATION) == 0)
-        {
-            // No need to do anything for WolfSSL
-            result = 0;
-        }
-#ifdef INVALID_DEVID
-        else if (strcmp(OPTION_WOLFSSL_SET_DEVICE_ID, optionName) == 0)
-        {
-            int device_id = *((int *)value);
-            if (tls_io_instance->ssl != NULL && wolfSSL_SetDevId(tls_io_instance->ssl, device_id) != WOLFSSL_SUCCESS)
-            {
-                LogError("Failure setting device id on ssl");
-                result = MU_FAILURE;
-            }
-            else
-            {
-                // Save the device Id even if ssl object not yet created.
+            else
+            {
+                // Save the id till we create the ssl object
                 tls_io_instance->wolfssl_device_id = device_id;
                 result = 0;
@@ -989,10 +953,4 @@
         }
 #endif
-        else if (strcmp("ignore_host_name_check", optionName) == 0)
-        {
-            bool* server_name_check = (bool*)value;
-            tls_io_instance->ignore_host_name_check = *server_name_check;
-            result = 0;
-        }
         else
         {
Index: azure_iot_hub_f767zi/trunk/azure_iot_sdk/serializer/src/commanddecoder.c
===================================================================
--- azure_iot_hub_f767zi/trunk/azure_iot_sdk/serializer/src/commanddecoder.c	(revision 468)
+++ azure_iot_hub_f767zi/trunk/azure_iot_sdk/serializer/src/commanddecoder.c	(revision 471)
@@ -731,4 +731,8 @@
                 else
                 {
+                    //printf("%s %s\n", fullMethodName, methodJSON);
+                    if (strcmp(methodJSON, "null") == 0) {
+                        strcpy(methodJSON, "{}");
+                    }
                     MULTITREE_HANDLE methodTree;
                     if (JSONDecoder_JSON_To_MultiTree(methodJSON, &methodTree) != JSON_DECODER_OK)
Index: azure_iot_hub_f767zi/trunk/azure_iot_sdk/serializer/src/jsondecoder.c
===================================================================
--- azure_iot_hub_f767zi/trunk/azure_iot_sdk/serializer/src/jsondecoder.c	(revision 468)
+++ azure_iot_hub_f767zi/trunk/azure_iot_sdk/serializer/src/jsondecoder.c	(revision 471)
@@ -598,4 +598,7 @@
             result = JSON_DECODER_MULTITREE_FAILED;
         }
+        else if (strcmp(json, "null") == 0) {
+            result = JSON_DECODER_OK;
+        }
         else
         {
