Azure IoT / iothub_client

Dependents:   sht15_remote_monitoring RobotArmDemo iothub_client_sample_amqp f767zi_mqtt ... more

Files at this revision

API Documentation at this revision

Comitter:
AzureIoTClient
Date:
Wed Nov 16 21:37:53 2016 -0800
Parent:
52:1cc3c6d07cad
Child:
54:6dcad9019a64
Commit message:
1.0.10

Changed in this revision

iothub_client.c Show annotated file Show diff for this revision Revisions of this file
iothub_client.h Show annotated file Show diff for this revision Revisions of this file
iothub_client_ll.c Show annotated file Show diff for this revision Revisions of this file
iothub_client_ll.h Show annotated file Show diff for this revision Revisions of this file
iothub_client_private.h Show annotated file Show diff for this revision Revisions of this file
iothub_client_version.h Show annotated file Show diff for this revision Revisions of this file
iothub_message.c Show annotated file Show diff for this revision Revisions of this file
iothub_message.h Show annotated file Show diff for this revision Revisions of this file
iothub_transport_ll.h Show annotated file Show diff for this revision Revisions of this file
iothubtransport.c Show annotated file Show diff for this revision Revisions of this file
--- a/iothub_client.c	Thu Oct 20 17:07:32 2016 -0700
+++ b/iothub_client.c	Wed Nov 16 21:37:53 2016 -0800
@@ -184,7 +184,7 @@
     else
     {
         /* Codes_SRS_IOTHUBCLIENT_12_004: [IoTHubClient_CreateFromConnectionString shall allocate a new IoTHubClient instance.] */
-		result = (IOTHUB_CLIENT_INSTANCE *) malloc(sizeof(IOTHUB_CLIENT_INSTANCE));
+        result = (IOTHUB_CLIENT_INSTANCE *) malloc(sizeof(IOTHUB_CLIENT_INSTANCE));
 
         /* Codes_SRS_IOTHUBCLIENT_12_011: [If the allocation failed, IoTHubClient_CreateFromConnectionString returns NULL] */
         if (result == NULL)
@@ -614,41 +614,139 @@
             }
 
             /* Codes_SRS_IOTHUBCLIENT_01_027: [IoTHubClient_SetMessageCallback shall be made thread-safe by using the lock created in IoTHubClient_Create.] */
-            Unlock(iotHubClientInstance->LockHandle);
+            (void)Unlock(iotHubClientInstance->LockHandle);
         }
     }
 
     return result;
 }
 
-IOTHUB_CLIENT_RESULT IoTHubClient_SetConnectionStatusCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK connectionStatusCallback, void * userContextCallback)
+IOTHUB_CLIENT_RESULT IoTHubClient_SetConnectionStatusCallback(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK connectionStatusCallback, void * userContextCallback)
 {
-    IOTHUB_CLIENT_RESULT result = IOTHUB_CLIENT_OK;
-    (void)iotHubClientHandle;
-    (void)connectionStatusCallback;
-    (void)userContextCallback;
+    IOTHUB_CLIENT_RESULT result;
+
+    if (iotHubClientHandle == NULL)
+    {
+        /* Codes_SRS_IOTHUBCLIENT_25_076: [** If `iotHubClientHandle` is `NULL`, `IoTHubClient_SetRetryPolicy` shall return `IOTHUB_CLIENT_INVALID_ARG`. ] */
+        result = IOTHUB_CLIENT_INVALID_ARG;
+        LogError("NULL iothubClientHandle");
+    }
+    else
+    {
+        IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle;
 
+        /* Codes_SRS_IOTHUBCLIENT_25_087: [ `IoTHubClient_SetConnectionStatusCallback` shall be made thread-safe by using the lock created in `IoTHubClient_Create`. ] */
+        if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK)
+        {
+            /* Codes_SRS_IOTHUBCLIENT_25_088: [ If acquiring the lock fails, `IoTHubClient_SetConnectionStatusCallback` shall return `IOTHUB_CLIENT_ERROR`. ]*/
+            result = IOTHUB_CLIENT_ERROR;
+            LogError("Could not acquire lock");
+        }
+        else
+        {
+            /* Codes_SRS_IOTHUBCLIENT_25_081: [ `IoTHubClient_SetConnectionStatusCallback` shall start the worker thread if it was not previously started. ]*/
+            if ((result = StartWorkerThreadIfNeeded(iotHubClientInstance)) != IOTHUB_CLIENT_OK)
+            {
+                /* Codes_SRS_IOTHUBCLIENT_25_083: [ If starting the thread fails, `IoTHubClient_SetConnectionStatusCallback` shall return `IOTHUB_CLIENT_ERROR`. ]*/
+                result = IOTHUB_CLIENT_ERROR;
+                LogError("Could not start worker thread");
+            }
+            else
+            {
+                /* Codes_SRS_IOTHUBCLIENT_25_085: [ `IoTHubClient_SetConnectionStatusCallback` shall call `IoTHubClient_LL_SetConnectionStatusCallback`, while passing the `IoTHubClient_LL` handle created by `IoTHubClient_Create` and the parameters `connectionStatusCallback` and `userContextCallback`. ]*/
+                result = IoTHubClient_LL_SetConnectionStatusCallback(iotHubClientInstance->IoTHubClientLLHandle, connectionStatusCallback, userContextCallback);
+            }
+
+            (void)Unlock(iotHubClientInstance->LockHandle);
+        }
+    }
 
     return result;
-    
+
 }
 
-IOTHUB_CLIENT_RESULT IoTHubClient_SetRetryPolicy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitinSeconds)
+IOTHUB_CLIENT_RESULT IoTHubClient_SetRetryPolicy(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitInSeconds)
 {
-    IOTHUB_CLIENT_RESULT result = IOTHUB_CLIENT_OK;
-    (void)iotHubClientHandle;
-    (void)retryPolicy;
-    (void)retryTimeoutLimitinSeconds;
+    IOTHUB_CLIENT_RESULT result;
+
+    if (iotHubClientHandle == NULL)
+    {
+        /* Codes_SRS_IOTHUBCLIENT_25_076: [** If `iotHubClientHandle` is `NULL`, `IoTHubClient_SetRetryPolicy` shall return `IOTHUB_CLIENT_INVALID_ARG`. ] */
+        result = IOTHUB_CLIENT_INVALID_ARG;
+        LogError("NULL iothubClientHandle");
+    }
+    else
+    {
+        IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle;
+
+        /* Codes_SRS_IOTHUBCLIENT_25_079: [ `IoTHubClient_SetRetryPolicy` shall be made thread-safe by using the lock created in `IoTHubClient_Create`.] */
+        if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK)
+        {
+            /* Codes_SRS_IOTHUBCLIENT_25_080: [ If acquiring the lock fails, `IoTHubClient_SetRetryPolicy` shall return `IOTHUB_CLIENT_ERROR`. ]*/
+            result = IOTHUB_CLIENT_ERROR;
+            LogError("Could not acquire lock");
+        }
+        else
+        {
+            /* Codes_SRS_IOTHUBCLIENT_25_073: [ `IoTHubClient_SetRetryPolicy` shall start the worker thread if it was not previously started. ] */
+            if ((result = StartWorkerThreadIfNeeded(iotHubClientInstance)) != IOTHUB_CLIENT_OK)
+            {
+                /* Codes_SRS_IOTHUBCLIENT_25_075: [ If starting the thread fails, `IoTHubClient_SetRetryPolicy` shall return `IOTHUB_CLIENT_ERROR`. ]*/
+                result = IOTHUB_CLIENT_ERROR;
+                LogError("Could not start worker thread");
+            }
+            else
+            {
+                /* Codes_SRS_IOTHUBCLIENT_25_077: [ `IoTHubClient_SetRetryPolicy` shall call `IoTHubClient_LL_SetRetryPolicy`, while passing the `IoTHubClient_LL` handle created by `IoTHubClient_Create` and the parameters `retryPolicy` and `retryTimeoutLimitinSeconds`.]*/
+                result = IoTHubClient_LL_SetRetryPolicy(iotHubClientInstance->IoTHubClientLLHandle, retryPolicy, retryTimeoutLimitInSeconds);
+            }
+
+            (void)Unlock(iotHubClientInstance->LockHandle);
+        }
+    }
 
     return result;
 }
 
-IOTHUB_CLIENT_RESULT IoTHubClient_GetRetryPolicy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY * retryPolicy, size_t * retryTimeoutLimitinSeconds)
+IOTHUB_CLIENT_RESULT IoTHubClient_GetRetryPolicy(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY * retryPolicy, size_t * retryTimeoutLimitInSeconds)
 {
-    IOTHUB_CLIENT_RESULT result = IOTHUB_CLIENT_OK;
-    (void)iotHubClientHandle;
-    (void)retryPolicy;
-    (void)retryTimeoutLimitinSeconds;
+    IOTHUB_CLIENT_RESULT result;
+
+    if (iotHubClientHandle == NULL)
+    {
+        /* Codes_SRS_IOTHUBCLIENT_25_092: [ If `iotHubClientHandle` is `NULL`, `IoTHubClient_GetRetryPolicy` shall return `IOTHUB_CLIENT_INVALID_ARG`. ]*/
+        result = IOTHUB_CLIENT_INVALID_ARG;
+        LogError("NULL iothubClientHandle");
+    }
+    else
+    {
+        IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle;
+
+        /* Codes_SRS_IOTHUBCLIENT_25_095: [ `IoTHubClient_GetRetryPolicy` shall be made thread-safe by using the lock created in `IoTHubClient_Create`. ]*/
+        if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK)
+        {
+            /* Codes_SRS_IOTHUBCLIENT_25_096: [ If acquiring the lock fails, `IoTHubClient_GetRetryPolicy` shall return `IOTHUB_CLIENT_ERROR`. ]*/
+            result = IOTHUB_CLIENT_ERROR;
+            LogError("Could not acquire lock");
+        }
+        else
+        {
+            /* Codes_SRS_IOTHUBCLIENT_25_089: [ `IoTHubClient_GetRetryPolicy` shall start the worker thread if it was not previously started.]*/
+            if ((result = StartWorkerThreadIfNeeded(iotHubClientInstance)) != IOTHUB_CLIENT_OK)
+            {
+                /* Codes_SRS_IOTHUBCLIENT_25_091: [ If starting the thread fails, `IoTHubClient_GetRetryPolicy` shall return `IOTHUB_CLIENT_ERROR`.]*/
+                result = IOTHUB_CLIENT_ERROR;
+                LogError("Could not start worker thread");
+            }
+            else
+            {
+                /* Codes_SRS_IOTHUBCLIENT_25_093: [ `IoTHubClient_GetRetryPolicy` shall call `IoTHubClient_LL_GetRetryPolicy`, while passing the `IoTHubClient_LL` handle created by `IoTHubClient_Create` and the parameters `connectionStatusCallback` and `userContextCallback`.]*/
+                result = IoTHubClient_LL_GetRetryPolicy(iotHubClientInstance->IoTHubClientLLHandle, retryPolicy, retryTimeoutLimitInSeconds);
+            }
+
+            (void)Unlock(iotHubClientInstance->LockHandle);
+        }
+    }
 
     return result;
 }
@@ -681,7 +779,7 @@
             result = IoTHubClient_LL_GetLastMessageReceiveTime(iotHubClientInstance->IoTHubClientLLHandle, lastMessageReceiveTime);
 
             /* Codes_SRS_IOTHUBCLIENT_01_035: [IoTHubClient_GetLastMessageReceiveTime shall be made thread-safe by using the lock created in IoTHubClient_Create.] */
-            Unlock(iotHubClientInstance->LockHandle);
+            (void)Unlock(iotHubClientInstance->LockHandle);
         }
     }
 
@@ -701,7 +799,7 @@
         )
     {
         result = IOTHUB_CLIENT_INVALID_ARG;
-        LogError("invalid arg (NULL)r\n");
+        LogError("invalid arg (NULL)");
     }
     else
     {
@@ -723,12 +821,153 @@
                 LogError("IoTHubClient_LL_SetOption failed");
             }
 
-            Unlock(iotHubClientInstance->LockHandle);
+            (void)Unlock(iotHubClientInstance->LockHandle);
+        }
+    }
+    return result;
+}
+
+IOTHUB_CLIENT_RESULT IoTHubClient_SetDeviceTwinCallback(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK deviceTwinCallback, void* userContextCallback)
+{
+    IOTHUB_CLIENT_RESULT result;
+
+    /*Codes_SRS_IOTHUBCLIENT_10_001: [** `IoTHubClient_SetDeviceTwinCallback` shall fail and return `IOTHUB_CLIENT_INVALID_ARG` if parameter `iotHubClientHandle` is `NULL`. ]*/
+    if (iotHubClientHandle == NULL)
+    {
+        result = IOTHUB_CLIENT_INVALID_ARG;
+        LogError("invalid arg (NULL)");
+    }
+    else
+    {
+        IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle;
+
+        /*Codes_SRS_IOTHUBCLIENT_10_020: [** `IoTHubClient_SetDeviceTwinCallback` shall be made thread - safe by using the lock created in IoTHubClient_Create. ]*/
+        if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK)
+        {
+            /*Codes_SRS_IOTHUBCLIENT_10_002: [** If acquiring the lock fails, `IoTHubClient_SetDeviceTwinCallback` shall return `IOTHUB_CLIENT_ERROR`. ]*/
+            result = IOTHUB_CLIENT_ERROR;
+            LogError("Could not acquire lock");
+        }
+        else
+        {
+            /*Codes_SRS_IOTHUBCLIENT_10_003: [** If the transport connection is shared, the thread shall be started by calling `IoTHubTransport_StartWorkerThread`. ]*/
+            if ((result = StartWorkerThreadIfNeeded(iotHubClientInstance)) != IOTHUB_CLIENT_OK)
+            {
+                /*Codes_SRS_IOTHUBCLIENT_10_004: [** If starting the thread fails, `IoTHubClient_SetDeviceTwinCallback` shall return `IOTHUB_CLIENT_ERROR`. ]*/
+                result = IOTHUB_CLIENT_ERROR;
+                LogError("Could not start worker thread");
+            }
+            else
+            {
+                /*Codes_SRS_IOTHUBCLIENT_10_005: [** `IoTHubClient_LL_SetDeviceTwinCallback` shall call `IoTHubClient_LL_SetDeviceTwinCallback`, while passing the `IoTHubClient_LL handle` created by `IoTHubClient_LL_Create` along with the parameters `reportedStateCallback` and `userContextCallback`. ]*/
+                result = IoTHubClient_LL_SetDeviceTwinCallback(iotHubClientInstance->IoTHubClientLLHandle, deviceTwinCallback, userContextCallback);
+                if (result != IOTHUB_CLIENT_OK)
+                {
+                    LogError("IoTHubClient_LL_SetDeviceTwinCallback failed");
+                }
+            }
+
+            (void)Unlock(iotHubClientInstance->LockHandle);
         }
     }
     return result;
 }
 
+IOTHUB_CLIENT_RESULT IoTHubClient_SendReportedState(IOTHUB_CLIENT_HANDLE iotHubClientHandle, const unsigned char* reportedState, size_t size, IOTHUB_CLIENT_REPORTED_STATE_CALLBACK reportedStateCallback, void* userContextCallback)
+{
+    IOTHUB_CLIENT_RESULT result;
+
+    /*Codes_SRS_IOTHUBCLIENT_10_013: [** If `iotHubClientHandle` is `NULL`, `IoTHubClient_SendReportedState` shall return `IOTHUB_CLIENT_INVALID_ARG`. ]*/
+    if (iotHubClientHandle == NULL)
+    {
+        result = IOTHUB_CLIENT_INVALID_ARG;
+        LogError("invalid arg (NULL)");
+    }
+    else
+    {
+        IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle;
+
+        /*Codes_SRS_IOTHUBCLIENT_10_021: [** `IoTHubClient_SendReportedState` shall be made thread-safe by using the lock created in IoTHubClient_Create. ]*/
+        if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK)
+        {
+            /*Codes_SRS_IOTHUBCLIENT_10_014: [** If acquiring the lock fails, `IoTHubClient_SendReportedState` shall return `IOTHUB_CLIENT_ERROR`. ]*/
+            result = IOTHUB_CLIENT_ERROR;
+            LogError("Could not acquire lock");
+        }
+        else
+        {
+            /*Codes_SRS_IOTHUBCLIENT_10_015: [** If the transport connection is shared, the thread shall be started by calling `IoTHubTransport_StartWorkerThread`. ]*/
+            if ((result = StartWorkerThreadIfNeeded(iotHubClientInstance)) != IOTHUB_CLIENT_OK)
+            {
+                /*Codes_SRS_IOTHUBCLIENT_10_016: [** If starting the thread fails, `IoTHubClient_SendReportedState` shall return `IOTHUB_CLIENT_ERROR`. ]*/
+                result = IOTHUB_CLIENT_ERROR;
+                LogError("Could not start worker thread");
+            }
+            else
+            {
+                /*Codes_SRS_IOTHUBCLIENT_10_017: [** `IoTHubClient_SendReportedState` shall call `IoTHubClient_LL_SendReportedState`, while passing the `IoTHubClient_LL handle` created by `IoTHubClient_LL_Create` along with the parameters `reportedState`, `size`, `reportedStateCallback`, and `userContextCallback`. ]*/
+                /*Codes_SRS_IOTHUBCLIENT_10_018: [** When `IoTHubClient_LL_SendReportedState` is called, `IoTHubClient_SendReportedState` shall return the result of `IoTHubClient_LL_SendReportedState`. **]*/
+                result = IoTHubClient_LL_SendReportedState(iotHubClientInstance->IoTHubClientLLHandle, reportedState, size, reportedStateCallback, userContextCallback);
+                if (result != IOTHUB_CLIENT_OK)
+                {
+                    LogError("IoTHubClient_LL_SendReportedState failed");
+                }
+            }
+
+            (void)Unlock(iotHubClientInstance->LockHandle);
+        }
+    }
+    return result;
+}
+
+IOTHUB_CLIENT_RESULT IoTHubClient_SetDeviceMethodCallback(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC deviceMethodCallback, void* userContextCallback)
+{
+    IOTHUB_CLIENT_RESULT result;
+
+    /*Codes_SRS_IOTHUBCLIENT_12_012: [ If iotHubClientHandle is NULL, IoTHubClient_SetDeviceMethodCallback shall return IOTHUB_CLIENT_INVALID_ARG. ]*/ 
+    if (iotHubClientHandle == NULL)
+    {
+        result = IOTHUB_CLIENT_INVALID_ARG;
+        LogError("invalid arg (NULL)");
+    }
+    else
+    {
+        IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle;
+
+        /*Codes_SRS_IOTHUBCLIENT_12_018: [ IoTHubClient_SetDeviceMethodCallback shall be made thread-safe by using the lock created in IoTHubClient_Create. ]*/
+        if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK)
+        {
+            /*Codes_SRS_IOTHUBCLIENT_12_013: [ If acquiring the lock fails, IoTHubClient_SetDeviceMethodCallback shall return IOTHUB_CLIENT_ERROR. ]*/
+            result = IOTHUB_CLIENT_ERROR;
+            LogError("Could not acquire lock");
+        }
+        else
+        {
+            /*Codes_SRS_IOTHUBCLIENT_12_014: [ If the transport handle is null and the worker thread is not initialized, the thread shall be started by calling IoTHubTransport_StartWorkerThread. ]*/
+            if ((result = StartWorkerThreadIfNeeded(iotHubClientInstance)) != IOTHUB_CLIENT_OK)
+            {
+                /*Codes_SRS_IOTHUBCLIENT_12_015: [ If starting the thread fails, IoTHubClient_SetDeviceMethodCallback shall return IOTHUB_CLIENT_ERROR. ]*/
+                result = IOTHUB_CLIENT_ERROR;
+                LogError("Could not start worker thread");
+            }
+            else
+            {
+                /*Codes_SRS_IOTHUBCLIENT_12_016: [ IoTHubClient_SetDeviceMethodCallback shall call IoTHubClient_LL_SetDeviceMethodCallback, while passing the IoTHubClient_LL_handle created by IoTHubClient_LL_Create along with the parameters deviceMethodCallback and userContextCallback. ]*/
+                /*Codes_SRS_IOTHUBCLIENT_12_017: [ When IoTHubClient_LL_SetDeviceMethodCallback is called, IoTHubClient_SetDeviceMethodCallback shall return the result of IoTHubClient_LL_SetDeviceMethodCallback. ]*/
+                result = IoTHubClient_LL_SetDeviceMethodCallback(iotHubClientInstance->IoTHubClientLLHandle, deviceMethodCallback, userContextCallback);
+                if (result != IOTHUB_CLIENT_OK)
+                {
+                    LogError("IoTHubClient_LL_SetDeviceMethodCallback failed");
+                }
+            }
+
+            (void)Unlock(iotHubClientInstance->LockHandle);
+        }
+    }
+    return result;
+}
+
+
 #ifndef DONT_USE_UPLOADTOBLOB
 static int uploadingThread(void *data)
 {
@@ -919,7 +1158,7 @@
                                 }
                             }
                         }
-                        Unlock(iotHubClientHandleData->LockHandle);
+                        (void)Unlock(iotHubClientHandleData->LockHandle);
                     }
                 }
             }
--- a/iothub_client.h	Thu Oct 20 17:07:32 2016 -0700
+++ b/iothub_client.h	Wed Nov 16 21:37:53 2016 -0800
@@ -17,8 +17,13 @@
 
 typedef struct IOTHUB_CLIENT_INSTANCE_TAG* IOTHUB_CLIENT_HANDLE;
 
+
+#include "iothubtransport.h"
+#include <stddef.h>
+#include <stdint.h>
+
 #include "iothub_client_ll.h"
-#include "iothubtransport.h"
+#include "azure_c_shared_utility/umock_c_prod.h"
 
 #ifdef __cplusplus
 extern "C"
@@ -32,113 +37,113 @@
     DEFINE_ENUM(IOTHUB_CLIENT_FILE_UPLOAD_RESULT, IOTHUB_CLIENT_FILE_UPLOAD_RESULT_VALUES)
         typedef void(*IOTHUB_CLIENT_FILE_UPLOAD_CALLBACK)(IOTHUB_CLIENT_FILE_UPLOAD_RESULT result, void* userContextCallback);
 
-	/**
-	* @brief	Creates a IoT Hub client for communication with an existing
-	* 			IoT Hub using the specified connection string parameter.
-	*
-	* @param	connectionString	Pointer to a character string
-	* @param	protocol			Function pointer for protocol implementation
-	*
-	*			Sample connection string:
-	*				<blockquote>
-	*					<pre>HostName=[IoT Hub name goes here].[IoT Hub suffix goes here, e.g., private.azure-devices-int.net];DeviceId=[Device ID goes here];SharedAccessKey=[Device key goes here];</pre>
-	*                   <pre>HostName=[IoT Hub name goes here].[IoT Hub suffix goes here, e.g., private.azure-devices-int.net];DeviceId=[Device ID goes here];SharedAccessSignature=SharedAccessSignature sr=[IoT Hub name goes here].[IoT Hub suffix goes here, e.g., private.azure-devices-int.net]/devices/[Device ID goes here]&sig=[SAS Token goes here]&se=[Expiry Time goes here];</pre>
-	*				</blockquote>
-	*
-	* @return	A non-NULL @c IOTHUB_CLIENT_HANDLE value that is used when
-	* 			invoking other functions for IoT Hub client and @c NULL on failure.
-	*/
-	extern IOTHUB_CLIENT_HANDLE IoTHubClient_CreateFromConnectionString(const char* connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol);
+    /**
+    * @brief	Creates a IoT Hub client for communication with an existing
+    * 			IoT Hub using the specified connection string parameter.
+    *
+    * @param	connectionString	Pointer to a character string
+    * @param	protocol			Function pointer for protocol implementation
+    *
+    *			Sample connection string:
+    *				<blockquote>
+    *					<pre>HostName=[IoT Hub name goes here].[IoT Hub suffix goes here, e.g., private.azure-devices-int.net];DeviceId=[Device ID goes here];SharedAccessKey=[Device key goes here];</pre>
+    *                   <pre>HostName=[IoT Hub name goes here].[IoT Hub suffix goes here, e.g., private.azure-devices-int.net];DeviceId=[Device ID goes here];SharedAccessSignature=SharedAccessSignature sr=[IoT Hub name goes here].[IoT Hub suffix goes here, e.g., private.azure-devices-int.net]/devices/[Device ID goes here]&sig=[SAS Token goes here]&se=[Expiry Time goes here];</pre>
+    *				</blockquote>
+    *
+    * @return	A non-NULL @c IOTHUB_CLIENT_HANDLE value that is used when
+    * 			invoking other functions for IoT Hub client and @c NULL on failure.
+    */
+    MOCKABLE_FUNCTION(, IOTHUB_CLIENT_HANDLE, IoTHubClient_CreateFromConnectionString, const char*, connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER, protocol);
 
-	/**
-	* @brief	Creates a IoT Hub client for communication with an existing IoT
-	* 			Hub using the specified parameters.
-	*
-	* @param	config	Pointer to an @c IOTHUB_CLIENT_CONFIG structure
-	*
-	*			The API does not allow sharing of a connection across multiple
-	*			devices. This is a blocking call.
-	*
-	* @return	A non-NULL @c IOTHUB_CLIENT_HANDLE value that is used when
-	* 			invoking other functions for IoT Hub client and @c NULL on failure.
-	*/
-	extern IOTHUB_CLIENT_HANDLE IoTHubClient_Create(const IOTHUB_CLIENT_CONFIG* config);
+    /**
+    * @brief	Creates a IoT Hub client for communication with an existing IoT
+    * 			Hub using the specified parameters.
+    *
+    * @param	config	Pointer to an @c IOTHUB_CLIENT_CONFIG structure
+    *
+    *			The API does not allow sharing of a connection across multiple
+    *			devices. This is a blocking call.
+    *
+    * @return	A non-NULL @c IOTHUB_CLIENT_HANDLE value that is used when
+    * 			invoking other functions for IoT Hub client and @c NULL on failure.
+    */
+    MOCKABLE_FUNCTION(, IOTHUB_CLIENT_HANDLE, IoTHubClient_Create, const IOTHUB_CLIENT_CONFIG*, config);
 
-	/**
-	* @brief	Creates a IoT Hub client for communication with an existing IoT
-	* 			Hub using the specified parameters.
-	*
-	* @param	transportHandle	TRANSPORT_HANDLE which represents a connection.
-	* @param	config	Pointer to an @c IOTHUB_CLIENT_CONFIG structure
-	*
-	*			The API allows sharing of a connection across multiple
-	*			devices. This is a blocking call.
-	*
-	* @return	A non-NULL @c IOTHUB_CLIENT_HANDLE value that is used when
-	* 			invoking other functions for IoT Hub client and @c NULL on failure.
-	*/
-	extern IOTHUB_CLIENT_HANDLE IoTHubClient_CreateWithTransport(TRANSPORT_HANDLE transportHandle, const IOTHUB_CLIENT_CONFIG* config);
+    /**
+    * @brief	Creates a IoT Hub client for communication with an existing IoT
+    * 			Hub using the specified parameters.
+    *
+    * @param	transportHandle	TRANSPORT_HANDLE which represents a connection.
+    * @param	config	Pointer to an @c IOTHUB_CLIENT_CONFIG structure
+    *
+    *			The API allows sharing of a connection across multiple
+    *			devices. This is a blocking call.
+    *
+    * @return	A non-NULL @c IOTHUB_CLIENT_HANDLE value that is used when
+    * 			invoking other functions for IoT Hub client and @c NULL on failure.
+    */
+    MOCKABLE_FUNCTION(, IOTHUB_CLIENT_HANDLE, IoTHubClient_CreateWithTransport, TRANSPORT_HANDLE, transportHandle, const IOTHUB_CLIENT_CONFIG*, config);
 
-	/**
-	* @brief	Disposes of resources allocated by the IoT Hub client. This is a
-	* 			blocking call.
-	*
-	* @param	iotHubClientHandle	The handle created by a call to the create function.
-	*/
-	extern void IoTHubClient_Destroy(IOTHUB_CLIENT_HANDLE iotHubClientHandle);
+    /**
+    * @brief	Disposes of resources allocated by the IoT Hub client. This is a
+    * 			blocking call.
+    *
+    * @param	iotHubClientHandle	The handle created by a call to the create function.
+    */
+    MOCKABLE_FUNCTION(, void, IoTHubClient_Destroy, IOTHUB_CLIENT_HANDLE, iotHubClientHandle);
 
-	/**
-	* @brief	Asynchronous call to send the message specified by @p eventMessageHandle.
-	*
-	* @param	iotHubClientHandle		   	The handle created by a call to the create function.
-	* @param	eventMessageHandle		   	The handle to an IoT Hub message.
-	* @param	eventConfirmationCallback  	The callback specified by the device for receiving
-	* 										confirmation of the delivery of the IoT Hub message.
-	* 										This callback can be expected to invoke the
-	* 										::IoTHubClient_SendEventAsync function for the
-	* 										same message in an attempt to retry sending a failing
-	* 										message. The user can specify a @c NULL value here to
-	* 										indicate that no callback is required.
-	* @param	userContextCallback			User specified context that will be provided to the
-	* 										callback. This can be @c NULL.
-	*
-	*			@b NOTE: The application behavior is undefined if the user calls
-	*			the ::IoTHubClient_Destroy function from within any callback.
-	*
-	* @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
-	*/
-	extern IOTHUB_CLIENT_RESULT IoTHubClient_SendEventAsync(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_MESSAGE_HANDLE eventMessageHandle, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK eventConfirmationCallback, void* userContextCallback);
+    /**
+    * @brief	Asynchronous call to send the message specified by @p eventMessageHandle.
+    *
+    * @param	iotHubClientHandle		   	The handle created by a call to the create function.
+    * @param	eventMessageHandle		   	The handle to an IoT Hub message.
+    * @param	eventConfirmationCallback  	The callback specified by the device for receiving
+    * 										confirmation of the delivery of the IoT Hub message.
+    * 										This callback can be expected to invoke the
+    * 										::IoTHubClient_SendEventAsync function for the
+    * 										same message in an attempt to retry sending a failing
+    * 										message. The user can specify a @c NULL value here to
+    * 										indicate that no callback is required.
+    * @param	userContextCallback			User specified context that will be provided to the
+    * 										callback. This can be @c NULL.
+    *
+    *			@b NOTE: The application behavior is undefined if the user calls
+    *			the ::IoTHubClient_Destroy function from within any callback.
+    *
+    * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
+    */
+    MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SendEventAsync, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_MESSAGE_HANDLE, eventMessageHandle, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK, eventConfirmationCallback, void*, userContextCallback);
 
-	/**
-	* @brief	This function returns the current sending status for IoTHubClient.
-	*
-	* @param	iotHubClientHandle		The handle created by a call to the create function.
-	* @param	iotHubClientStatus		The sending state is populated at the address pointed
-	* 									at by this parameter. The value will be set to
-	* 									@c IOTHUBCLIENT_SENDSTATUS_IDLE if there is currently
-	* 								    no item to be sent and @c IOTHUBCLIENT_SENDSTATUS_BUSY
-	* 								    if there are.
-	*
-	* @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
-	*/
-	extern IOTHUB_CLIENT_RESULT IoTHubClient_GetSendStatus(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_STATUS *iotHubClientStatus);
+    /**
+    * @brief	This function returns the current sending status for IoTHubClient.
+    *
+    * @param	iotHubClientHandle		The handle created by a call to the create function.
+    * @param	iotHubClientStatus		The sending state is populated at the address pointed
+    * 									at by this parameter. The value will be set to
+    * 									@c IOTHUBCLIENT_SENDSTATUS_IDLE if there is currently
+    * 								    no item to be sent and @c IOTHUBCLIENT_SENDSTATUS_BUSY
+    * 								    if there are.
+    *
+    * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
+    */
+    MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_GetSendStatus, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_STATUS*, iotHubClientStatus);
 
-	/**
-	* @brief	Sets up the message callback to be invoked when IoT Hub issues a
-	* 			message to the device. This is a blocking call.
-	*
-	* @param	iotHubClientHandle		   	The handle created by a call to the create function.
-	* @param	messageCallback     	   	The callback specified by the device for receiving
-	* 										messages from IoT Hub.
-	* @param	userContextCallback			User specified context that will be provided to the
-	* 										callback. This can be @c NULL.
-	*
-	*			@b NOTE: The application behavior is undefined if the user calls
-	*			the ::IoTHubClient_Destroy function from within any callback.
-	*
-	* @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
-	*/
-	extern IOTHUB_CLIENT_RESULT IoTHubClient_SetMessageCallback(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC messageCallback, void* userContextCallback);
+    /**
+    * @brief	Sets up the message callback to be invoked when IoT Hub issues a
+    * 			message to the device. This is a blocking call.
+    *
+    * @param	iotHubClientHandle		   	The handle created by a call to the create function.
+    * @param	messageCallback     	   	The callback specified by the device for receiving
+    * 										messages from IoT Hub.
+    * @param	userContextCallback			User specified context that will be provided to the
+    * 										callback. This can be @c NULL.
+    *
+    *			@b NOTE: The application behavior is undefined if the user calls
+    *			the ::IoTHubClient_Destroy function from within any callback.
+    *
+    * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
+    */
+    MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SetMessageCallback, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC, messageCallback, void*, userContextCallback);
 
     /**
     * @brief	Sets up the connection status callback to be invoked representing the status of
@@ -155,7 +160,7 @@
     *
     * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
     */
-    extern IOTHUB_CLIENT_RESULT IoTHubClient_SetConnectionStatusCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK connectionStatusCallback, void* userContextCallback);
+    MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SetConnectionStatusCallback, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK, connectionStatusCallback, void*, userContextCallback);
 
     /**
     * @brief	Sets up the connection status callback to be invoked representing the status of
@@ -164,7 +169,7 @@
     * @param	iotHubClientHandle		   	        The handle created by a call to the create function.
     * @param	retryPolicy                  	   	The policy to use to reconnect to IoT Hub when a
     *                                               connection drops.
-    * @param	retryTimeoutLimitinSeconds			Maximum amount of time(seconds) to attempt reconnection when a
+    * @param	retryTimeoutLimitInSeconds			Maximum amount of time(seconds) to attempt reconnection when a
     *                                               connection drops to IOT Hub.
     *
     *			@b NOTE: The application behavior is undefined if the user calls
@@ -172,7 +177,7 @@
     *
     * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
     */
-    extern IOTHUB_CLIENT_RESULT IoTHubClient_SetRetryPolicy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitinSeconds);
+    MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SetRetryPolicy, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY, retryPolicy, size_t, retryTimeoutLimitInSeconds);
 
     /**
     * @brief	Sets up the connection status callback to be invoked representing the status of
@@ -180,7 +185,7 @@
     *
     * @param	iotHubClientHandle		   	        The handle created by a call to the create function.
     * @param	retryPolicy                  	   	Out parameter containing the policy to use to reconnect to IoT Hub.
-    * @param	retryTimeoutLimitinSeconds			Out parameter containing maximum amount of time in seconds to attempt reconnection
+    * @param	retryTimeoutLimitInSeconds			Out parameter containing maximum amount of time in seconds to attempt reconnection
     to IOT Hub.
     *
     *			@b NOTE: The application behavior is undefined if the user calls
@@ -188,61 +193,110 @@
     *
     * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
     */
-    extern IOTHUB_CLIENT_RESULT IoTHubClient_GetRetryPolicy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY* retryPolicy, size_t* retryTimeoutLimitinSeconds);
+    MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_GetRetryPolicy, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY*, retryPolicy, size_t*, retryTimeoutLimitInSeconds);
 
-	/**
-	* @brief	This function returns in the out parameter @p lastMessageReceiveTime
-	* 			what was the value of the @c time function when the last message was
-	* 			received at the client.
-	*
-	* @param	iotHubClientHandle				The handle created by a call to the create function.
-	* @param	lastMessageReceiveTime  		Out parameter containing the value of @c time function
-	* 											when the last message was received.
-	*
-	* @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
-	*/
-	extern IOTHUB_CLIENT_RESULT IoTHubClient_GetLastMessageReceiveTime(IOTHUB_CLIENT_HANDLE iotHubClientHandle, time_t* lastMessageReceiveTime);
+    /**
+    * @brief	This function returns in the out parameter @p lastMessageReceiveTime
+    * 			what was the value of the @c time function when the last message was
+    * 			received at the client.
+    *
+    * @param	iotHubClientHandle				The handle created by a call to the create function.
+    * @param	lastMessageReceiveTime  		Out parameter containing the value of @c time function
+    * 											when the last message was received.
+    *
+    * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
+    */
+    MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_GetLastMessageReceiveTime, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, time_t*, lastMessageReceiveTime);
 
-	/**
-	* @brief	This API sets a runtime option identified by parameter @p optionName
-	* 			to a value pointed to by @p value. @p optionName and the data type
-	* 			@p value is pointing to are specific for every option.
-	*
-	* @param	iotHubClientHandle	The handle created by a call to the create function.
-	* @param	optionName		  	Name of the option.
-	* @param	value			  	The value.
-	*
-	*			The options that can be set via this API are:
-	*				- @b timeout - the maximum time in milliseconds a communication is
-	*				  allowed to use. @p value is a pointer to an @c unsigned @c int with
-	*				  the timeout value in milliseconds. This is only supported for the HTTP
-	*				  protocol as of now. When the HTTP protocol uses CURL, the meaning of
-	*				  the parameter is <em>total request time</em>. When the HTTP protocol uses
-	*				  winhttp, the meaning is the same as the @c dwSendTimeout and
-	*				  @c dwReceiveTimeout parameters of the
-	*				  <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa384116(v=vs.85).aspx">
-	*				  WinHttpSetTimeouts</a> API.
-	*				- @b CURLOPT_LOW_SPEED_LIMIT - only available for HTTP protocol and only
-	*				  when CURL is used. It has the same meaning as CURL's option with the same
-	*				  name. @p value is pointer to a long.
-	*				- @b CURLOPT_LOW_SPEED_TIME - only available for HTTP protocol and only
-	*				  when CURL is used. It has the same meaning as CURL's option with the same
-	*				  name. @p value is pointer to a long.
-	*				- @b CURLOPT_FORBID_REUSE - only available for HTTP protocol and only
-	*				  when CURL is used. It has the same meaning as CURL's option with the same
-	*				  name. @p value is pointer to a long.
-	*				- @b CURLOPT_FRESH_CONNECT - only available for HTTP protocol and only
-	*				  when CURL is used. It has the same meaning as CURL's option with the same
-	*				  name. @p value is pointer to a long.
-	*				- @b CURLOPT_VERBOSE - only available for HTTP protocol and only
-	*				  when CURL is used. It has the same meaning as CURL's option with the same
-	*				  name. @p value is pointer to a long.
-	*				- @b messageTimeout - the maximum time in milliseconds until a message
-	*                 is timeouted. The time starts at IoTHubClient_SendEventAsync. By default,
-	*                 messages do not expire. @p is a pointer to a uint64_t
-	* @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
-	*/
-	extern IOTHUB_CLIENT_RESULT IoTHubClient_SetOption(IOTHUB_CLIENT_HANDLE iotHubClientHandle, const char* optionName, const void* value);
+    /**
+    * @brief	This API sets a runtime option identified by parameter @p optionName
+    * 			to a value pointed to by @p value. @p optionName and the data type
+    * 			@p value is pointing to are specific for every option.
+    *
+    * @param	iotHubClientHandle	The handle created by a call to the create function.
+    * @param	optionName		  	Name of the option.
+    * @param	value			  	The value.
+    *
+    *			The options that can be set via this API are:
+    *				- @b timeout - the maximum time in milliseconds a communication is
+    *				  allowed to use. @p value is a pointer to an @c unsigned @c int with
+    *				  the timeout value in milliseconds. This is only supported for the HTTP
+    *				  protocol as of now. When the HTTP protocol uses CURL, the meaning of
+    *				  the parameter is <em>total request time</em>. When the HTTP protocol uses
+    *				  winhttp, the meaning is the same as the @c dwSendTimeout and
+    *				  @c dwReceiveTimeout parameters of the
+    *				  <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa384116(v=vs.85).aspx">
+    *				  WinHttpSetTimeouts</a> API.
+    *				- @b CURLOPT_LOW_SPEED_LIMIT - only available for HTTP protocol and only
+    *				  when CURL is used. It has the same meaning as CURL's option with the same
+    *				  name. @p value is pointer to a long.
+    *				- @b CURLOPT_LOW_SPEED_TIME - only available for HTTP protocol and only
+    *				  when CURL is used. It has the same meaning as CURL's option with the same
+    *				  name. @p value is pointer to a long.
+    *				- @b CURLOPT_FORBID_REUSE - only available for HTTP protocol and only
+    *				  when CURL is used. It has the same meaning as CURL's option with the same
+    *				  name. @p value is pointer to a long.
+    *				- @b CURLOPT_FRESH_CONNECT - only available for HTTP protocol and only
+    *				  when CURL is used. It has the same meaning as CURL's option with the same
+    *				  name. @p value is pointer to a long.
+    *				- @b CURLOPT_VERBOSE - only available for HTTP protocol and only
+    *				  when CURL is used. It has the same meaning as CURL's option with the same
+    *				  name. @p value is pointer to a long.
+    *				- @b messageTimeout - the maximum time in milliseconds until a message
+    *                 is timeouted. The time starts at IoTHubClient_SendEventAsync. By default,
+    *                 messages do not expire. @p is a pointer to a uint64_t
+    * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
+    */
+    MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SetOption, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, const char*, optionName, const void*, value);
+
+    /**
+    * @brief	This API specifies a call back to be used when the device receives a state update.
+    *
+    * @param	iotHubClientHandle		The handle created by a call to the create function.
+    * @param	deviceTwinCallback	    The callback specified by the device client to be used for updating
+    *									the desired state. The callback will be called in response to a 
+    *									request send by the IoTHub services. The payload will be passed to the
+    *									callback, along with two version numbers:
+    *										- Desired:
+    *										- LastSeenReported:
+    * @param	userContextCallback		User specified context that will be provided to the
+    * 									callback. This can be @c NULL.
+    *
+    *			@b NOTE: The application behavior is undefined if the user calls
+    *			the ::IoTHubClient_Destroy function from within any callback.
+    *
+    * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
+    */
+    MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SetDeviceTwinCallback, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK, deviceTwinCallback, void*, userContextCallback);
+
+    /**
+    * @brief	This API sends a report of the device's properties and their current values.
+    *
+    * @param	iotHubClientHandle		The handle created by a call to the create function.
+    * @param	reportedState			The current device property values to be 'reported' to the IoTHub.
+    * @param	reportedStateCallback	The callback specified by the device client to be called with the
+    *									result of the transaction.
+    * @param	userContextCallback		User specified context that will be provided to the
+    * 									callback. This can be @c NULL.
+    *
+    *			@b NOTE: The application behavior is undefined if the user calls
+    *			the ::IoTHubClient_Destroy function from within any callback.
+    *
+    * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
+    */
+    MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SendReportedState, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, const unsigned char*, reportedState, size_t, size, IOTHUB_CLIENT_REPORTED_STATE_CALLBACK, reportedStateCallback, void*, userContextCallback);
+
+    /**
+    * @brief	This API sets callback for cloud to device method call.
+    *
+    * @param	iotHubClientHandle		The handle created by a call to the create function.
+    * @param	deviceMethodCallback	The callback which will be called by IoTHub.
+    * @param	userContextCallback		User specified context that will be provided to the
+    * 									callback. This can be @c NULL.
+    *
+    * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
+    */
+    MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SetDeviceMethodCallback, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC, deviceMethodCallback, void*, userContextCallback);
 
 #ifndef DONT_USE_UPLOADTOBLOB
     /**
@@ -257,7 +311,7 @@
     *
     * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
     */
-    extern IOTHUB_CLIENT_RESULT IoTHubClient_UploadToBlobAsync(IOTHUB_CLIENT_HANDLE iotHubClientHandle, const char* destinationFileName, const unsigned char* source, size_t size, IOTHUB_CLIENT_FILE_UPLOAD_CALLBACK iotHubClientFileUploadCallback, void* context);
+    MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_UploadToBlobAsync, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, const char*, destinationFileName, const unsigned char*, source, size_t, size, IOTHUB_CLIENT_FILE_UPLOAD_CALLBACK, iotHubClientFileUploadCallback, void*, context);
 #endif
 #ifdef __cplusplus
 }
--- a/iothub_client_ll.c	Thu Oct 20 17:07:32 2016 -0700
+++ b/iothub_client_ll.c	Wed Nov 16 21:37:53 2016 -0800
@@ -11,11 +11,13 @@
 #include "azure_c_shared_utility/doublylinkedlist.h"
 #include "azure_c_shared_utility/xlogging.h"
 #include "azure_c_shared_utility/tickcounter.h"
+#include "azure_c_shared_utility/constbuffer.h"
 
 #include "iothub_client_ll.h"
 #include "iothub_client_private.h"
 #include "iothub_client_version.h"
 #include "iothub_transport_ll.h"
+#include <stdint.h>
 
 #ifndef DONT_USE_UPLOADTOBLOB
 #include "iothub_client_ll_uploadtoblob.h"
@@ -30,21 +32,31 @@
 typedef struct IOTHUB_CLIENT_LL_HANDLE_DATA_TAG
 {
     DLIST_ENTRY waitingToSend;
+    DLIST_ENTRY iot_msg_queue;
+    DLIST_ENTRY iot_ack_queue;
     TRANSPORT_LL_HANDLE transportHandle;
     bool isSharedTransport;
     IOTHUB_DEVICE_HANDLE deviceHandle;
     TRANSPORT_PROVIDER_FIELDS;
     IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC messageCallback;
     void* messageUserContextCallback;
+    IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK conStatusCallback;
+    void* conStatusUserContextCallback;
     time_t lastMessageReceiveTime;
     TICK_COUNTER_HANDLE tickCounter; /*shared tickcounter used to track message timeouts in waitingToSend list*/
     uint64_t currentMessageTimeout;
+    uint64_t current_device_twin_timeout;
+    IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK deviceTwinCallback;
+    void* deviceTwinContextCallback;
+    IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC deviceMethodCallback;
+    void* deviceMethodUserContextCallback;
     IOTHUB_CLIENT_RETRY_POLICY retryPolicy;
-    size_t retryTimeoutinSeconds;
+    size_t retryTimeoutLimitInSeconds;
 #ifndef DONT_USE_UPLOADTOBLOB
     IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE uploadToBlobHandle;
 #endif
-
+    uint32_t data_msg_id;
+    bool complete_twin_update_encountered;
 }IOTHUB_CLIENT_LL_HANDLE_DATA;
 
 static const char HOSTNAME_TOKEN[] = "HostName";
@@ -55,9 +67,62 @@
 static const char DEVICESAS_TOKEN[] = "SharedAccessSignature";
 static const char PROTOCOL_GATEWAY_HOST[] = "GatewayHostName";
 
+static void device_twin_data_destroy(IOTHUB_DEVICE_TWIN* client_item)
+{
+    CONSTBUFFER_Destroy(client_item->report_data_handle);
+    free(client_item);
+}
+
+static uint32_t get_next_item_id(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData)
+{    
+    if (handleData->data_msg_id+1 >= UINT32_MAX)
+    {
+        handleData->data_msg_id = 1;
+    }
+    else
+    {
+        handleData->data_msg_id++;
+    }
+    return handleData->data_msg_id;
+}
+
+static IOTHUB_DEVICE_TWIN* dev_twin_data_create(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData, uint32_t id, const unsigned char* reportedState, size_t size, IOTHUB_CLIENT_REPORTED_STATE_CALLBACK reportedStateCallback, void* userContextCallback)
+{
+    IOTHUB_DEVICE_TWIN* result = (IOTHUB_DEVICE_TWIN*)malloc(sizeof(IOTHUB_DEVICE_TWIN) );
+    if (result != NULL)
+    {
+        result->report_data_handle = CONSTBUFFER_Create(reportedState, size);
+        if (result->report_data_handle == NULL)
+        {
+            LogError("Failure allocating reported state data");
+            free(result);
+            result = NULL;
+        }
+        else if (tickcounter_get_current_ms(handleData->tickCounter, &result->ms_timesOutAfter) != 0)
+        {
+            LogError("Failure getting tickcount info");
+            CONSTBUFFER_Destroy(result->report_data_handle);
+            free(result);
+            result = NULL;
+        }
+        else
+        {
+            result->item_id = id;
+            result->ms_timesOutAfter = 0;
+            result->context = userContextCallback;
+            result->reported_state_callback = reportedStateCallback;
+        }
+    }
+    else
+    {
+        LogError("Failure allocating device twin information");
+    }
+    return result;
+}
+
 IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateFromConnectionString(const char* connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol)
 {
-    IOTHUB_CLIENT_LL_HANDLE result = NULL;
+    IOTHUB_CLIENT_LL_HANDLE result;
 
     /*Codes_SRS_IOTHUBCLIENT_LL_05_001: [IoTHubClient_LL_CreateFromConnectionString shall obtain the version string by a call to IoTHubClient_GetVersionString.]*/
     /*Codes_SRS_IOTHUBCLIENT_LL_05_002: [IoTHubClient_LL_CreateFromConnectionString shall print the version string to standard output.]*/
@@ -67,20 +132,22 @@
     if (connectionString == NULL)
     {
         LogError("Input parameter is NULL: connectionString");
+        result = NULL;
     }
     else if (protocol == NULL)
     {
         LogError("Input parameter is NULL: protocol");
+        result = NULL;
     }
     else
     {
         /* Codes_SRS_IOTHUBCLIENT_LL_12_004: [IoTHubClient_LL_CreateFromConnectionString shall allocate IOTHUB_CLIENT_CONFIG structure] */
-		IOTHUB_CLIENT_CONFIG* config = (IOTHUB_CLIENT_CONFIG*) malloc(sizeof(IOTHUB_CLIENT_CONFIG));
+        IOTHUB_CLIENT_CONFIG* config = (IOTHUB_CLIENT_CONFIG*) malloc(sizeof(IOTHUB_CLIENT_CONFIG));
         if (config == NULL)
         {
             /* Codes_SRS_IOTHUBCLIENT_LL_12_012: [If the allocation failed IoTHubClient_LL_CreateFromConnectionString  returns NULL]  */
             LogError("Malloc failed");
-            return NULL;
+            result = NULL;
         }
         else
         {
@@ -109,26 +176,32 @@
             if ((connString = STRING_construct(connectionString)) == NULL)
             {
                 LogError("Error constructing connectiong String");
+                result = NULL;
             }
             else if ((tokenizer1 = STRING_TOKENIZER_create(connString)) == NULL)
             {
                 LogError("Error creating Tokenizer");
+                result = NULL;
             }
             else if ((tokenString = STRING_new()) == NULL)
             {
                 LogError("Error creating Token String");
+                result = NULL;
             }
             else if ((valueString = STRING_new()) == NULL)
             {
                 LogError("Error creating Value String");
+                result = NULL;
             }
             else if ((hostNameString = STRING_new()) == NULL)
             {
                 LogError("Error creating HostName String");
+                result = NULL;
             }
             else if ((hostSuffixString = STRING_new()) == NULL)
             {
                 LogError("Error creating HostSuffix String");
+                result = NULL;
             }
             /* Codes_SRS_IOTHUBCLIENT_LL_12_005: [IoTHubClient_LL_CreateFromConnectionString shall try to parse the connectionString input parameter for the following structure: "Key1=value1;key2=value2;key3=value3..."] */
             /* Codes_SRS_IOTHUBCLIENT_LL_12_006: [IoTHubClient_LL_CreateFromConnectionString shall verify the existence of the following Key/Value pairs in the connection string: HostName, DeviceId, SharedAccessKey, SharedAccessSignature or x509]  */
@@ -190,6 +263,11 @@
                                 {
                                     config->deviceId = STRING_c_str(deviceIdString);
                                 }
+                                else
+                                {
+                                    LogError("Failure cloning device id string");
+                                    break;
+                                }
                             }
                             else if (strcmp(s_token, DEVICEKEY_TOKEN) == 0)
                             {
@@ -198,6 +276,11 @@
                                 {
                                     config->deviceKey = STRING_c_str(deviceKeyString);
                                 }
+                                else
+                                {
+                                    LogError("Failure cloning device key string");
+                                    break;
+                                }
                             }
                             else if (strcmp(s_token, DEVICESAS_TOKEN) == 0)
                             {
@@ -206,12 +289,18 @@
                                 {
                                     config->deviceSasToken = STRING_c_str(deviceSasTokenString);
                                 }
+                                else
+                                {
+                                    LogError("Failure cloning device sasToken string");
+                                    break;
+                                }
                             }
                             else if (strcmp(s_token, X509_TOKEN) == 0)
                             {
                                 if (strcmp(STRING_c_str(valueString), X509_TOKEN_ONLY_ACCEPTABLE_VALUE) != 0)
                                 {
                                     LogError("x509 option has wrong value, the only acceptable one is \"true\"");
+                                    break;
                                 }
                                 else
                                 {
@@ -226,6 +315,11 @@
                                 {
                                     config->protocolGatewayHostName = STRING_c_str(protocolGateway);
                                 }
+                                else
+                                {
+                                    LogError("Failure cloning protocol Gateway Name");
+                                    break;
+                                }
                             }
                         }
                     }
@@ -234,14 +328,17 @@
                 if (config->iotHubName == NULL)
                 {
                     LogError("iotHubName is not found");
+                    result = NULL;
                 }
                 else if (config->iotHubSuffix == NULL)
                 {
                     LogError("iotHubSuffix is not found");
+                    result = NULL;
                 }
                 else if (config->deviceId == NULL)
                 {
                     LogError("deviceId is not found");
+                    result = NULL;
                 }
                 else if (!(
                     ((!isx509found) && (config->deviceSasToken == NULL) ^ (config->deviceKey == NULL)) ||
@@ -249,6 +346,7 @@
                     ))
                 {
                     LogError("invalid combination of x509, deviceSasToken and deviceKey");
+                    result = NULL;
                 }
                 else
                 {
@@ -304,8 +402,13 @@
     handleData->IoTHubTransport_Subscribe = protocol->IoTHubTransport_Subscribe;
     handleData->IoTHubTransport_Unsubscribe = protocol->IoTHubTransport_Unsubscribe;
     handleData->IoTHubTransport_DoWork = protocol->IoTHubTransport_DoWork;
+    handleData->IoTHubTransport_SetRetryPolicy = protocol->IoTHubTransport_SetRetryPolicy;
     handleData->IoTHubTransport_GetSendStatus = protocol->IoTHubTransport_GetSendStatus;
-
+    handleData->IoTHubTransport_ProcessItem = protocol->IoTHubTransport_ProcessItem;
+    handleData->IoTHubTransport_Subscribe_DeviceTwin = protocol->IoTHubTransport_Subscribe_DeviceTwin;
+    handleData->IoTHubTransport_Unsubscribe_DeviceTwin = protocol->IoTHubTransport_Unsubscribe_DeviceTwin;
+    handleData->IoTHubTransport_Subscribe_DeviceMethod = protocol->IoTHubTransport_Subscribe_DeviceMethod;
+    handleData->IoTHubTransport_Unsubscribe_DeviceMethod = protocol->IoTHubTransport_Unsubscribe_DeviceMethod;
 }
 
 IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_Create(const IOTHUB_CLIENT_CONFIG* config)
@@ -361,10 +464,22 @@
                     /*Codes_SRS_IOTHUBCLIENT_LL_02_004: [Otherwise IoTHubClient_LL_Create shall initialize a new DLIST (further called "waitingToSend") containing records with fields of the following types: IOTHUB_MESSAGE_HANDLE, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK, void*.]*/
                     IOTHUBTRANSPORT_CONFIG lowerLayerConfig;
                     DList_InitializeListHead(&(handleData->waitingToSend));
+                    DList_InitializeListHead(&(handleData->iot_msg_queue));
+                    DList_InitializeListHead(&(handleData->iot_ack_queue));
                     setTransportProtocol(handleData, (TRANSPORT_PROVIDER*)config->protocol());
                     handleData->messageCallback = NULL;
                     handleData->messageUserContextCallback = NULL;
+                    handleData->deviceTwinCallback = NULL;
+                    handleData->deviceTwinContextCallback = NULL;
+                    handleData->deviceMethodCallback = NULL;
+                    handleData->deviceMethodUserContextCallback = NULL;
                     handleData->lastMessageReceiveTime = INDEFINITE_TIME;
+                    handleData->data_msg_id = 1;
+                    handleData->complete_twin_update_encountered = false;
+                    handleData->conStatusCallback = NULL;
+                    handleData->conStatusUserContextCallback = NULL;
+                    handleData->lastMessageReceiveTime = INDEFINITE_TIME;
+
                     /*Codes_SRS_IOTHUBCLIENT_LL_02_006: [IoTHubClient_LL_Create shall populate a structure of type IOTHUBTRANSPORT_CONFIG with the information from config parameter and the previous DLIST and shall pass that to the underlying layer _Create function.]*/
                     lowerLayerConfig.upperConfig = config;
                     lowerLayerConfig.waitingToSend = &(handleData->waitingToSend);
@@ -406,7 +521,15 @@
                             handleData->isSharedTransport = false;
                             /*Codes_SRS_IOTHUBCLIENT_LL_02_042: [ By default, messages shall not timeout. ]*/
                             handleData->currentMessageTimeout = 0;
+                            handleData->current_device_twin_timeout = 0;
                             result = handleData;
+                            /*Codes_SRS_IOTHUBCLIENT_LL_25_124: [ `IoTHubClient_LL_Create` shall set the default retry policy as Exponential backoff with jitter and if succeed and return a `non-NULL` handle. ]*/
+                            if (IoTHubClient_LL_SetRetryPolicy(handleData, IOTHUB_CLIENT_RETRY_EXPONENTIAL_BACKOFF_WITH_JITTER, 0) != IOTHUB_CLIENT_OK)
+                            {
+                                LogError("Setting default retry policy in transport failed");
+                                IoTHubClient_LL_Destroy(handleData);
+                                result = NULL;
+                            }
                         }
                     }
                 }
@@ -462,7 +585,7 @@
             else
             {
                 /*Codes_SRS_IOTHUBCLIENT_LL_02_096: [ IoTHubClient_LL_CreateWithTransport shall create the data structures needed to instantiate a IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE. ]*/
-				char* IoTHubName = (char*) malloc(whereIsDot - hostname + 1);
+                char* IoTHubName = (char*) malloc(whereIsDot - hostname + 1);
                 if (IoTHubName == NULL)
                 {
                     /*Codes_SRS_IOTHUBCLIENT_LL_02_097: [ If creating the data structures fails or instantiating the IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE fails then IoTHubClient_LL_CreateWithTransport shall fail and return NULL. ]*/
@@ -512,11 +635,17 @@
                         {
                             /*Codes_SRS_IOTHUBCLIENT_LL_17_004: [IoTHubClient_LL_CreateWithTransport shall initialize a new DLIST (further called "waitingToSend") containing records with fields of the following types: IOTHUB_MESSAGE_HANDLE, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK, void*.]*/
                             DList_InitializeListHead(&(handleData->waitingToSend));
-                            
+                            DList_InitializeListHead(&(handleData->iot_msg_queue));
+                            DList_InitializeListHead(&(handleData->iot_ack_queue));
                             handleData->messageCallback = NULL;
                             handleData->messageUserContextCallback = NULL;
+                            handleData->deviceTwinCallback = NULL;
+                            handleData->deviceTwinContextCallback = NULL;
+                            handleData->deviceMethodCallback = NULL;
+                            handleData->deviceMethodUserContextCallback = NULL;
                             handleData->lastMessageReceiveTime = INDEFINITE_TIME;
-                            
+                            handleData->data_msg_id = 1;
+                            handleData->complete_twin_update_encountered = false;
 
                             IOTHUB_DEVICE_CONFIG deviceConfig;
 
@@ -542,7 +671,15 @@
                                 handleData->isSharedTransport = true;
                                 /*Codes_SRS_IOTHUBCLIENT_LL_02_042: [ By default, messages shall not timeout. ]*/
                                 handleData->currentMessageTimeout = 0;
+                                handleData->current_device_twin_timeout = 0;
                                 result = handleData;
+                                /*Codes_SRS_IOTHUBCLIENT_LL_25_125: [ `IoTHubClient_LL_CreateWithTransport` shall set the default retry policy as Exponential backoff with jitter and if succeed and return a `non-NULL` handle. ]*/
+                                if (IoTHubClient_LL_SetRetryPolicy(handleData, IOTHUB_CLIENT_RETRY_EXPONENTIAL_BACKOFF_WITH_JITTER, 0) != IOTHUB_CLIENT_OK)
+                                {
+                                    LogError("Setting default retry policy in transport failed");
+                                    IoTHubClient_LL_Destroy(handleData);
+                                    result = NULL;
+                                }
                             }
                         }
                     }
@@ -583,6 +720,19 @@
             IoTHubMessage_Destroy(temp->messageHandle);
             free(temp);
         }
+
+        /* Codes_SRS_IOTHUBCLIENT_LL_07_007: [ IoTHubClient_LL_Destroy shall iterate the device twin queues and destroy any remaining items. ] */
+        while ((unsend = DList_RemoveHeadList(&(handleData->iot_msg_queue))) != &(handleData->iot_msg_queue))
+        {
+            IOTHUB_DEVICE_TWIN* temp = containingRecord(unsend, IOTHUB_DEVICE_TWIN, entry);
+            device_twin_data_destroy(temp);
+        }
+        while ((unsend = DList_RemoveHeadList(&(handleData->iot_ack_queue))) != &(handleData->iot_ack_queue))
+        {
+            IOTHUB_DEVICE_TWIN* temp = containingRecord(unsend, IOTHUB_DEVICE_TWIN, entry);
+            device_twin_data_destroy(temp);
+        }
+
         /*Codes_SRS_IOTHUBCLIENT_LL_17_011: [IoTHubClient_LL_Destroy  shall free the resources allocated by IoTHubClient (if any).] */
         tickcounter_destroy(handleData->tickCounter);
 #ifndef DONT_USE_UPLOADTOBLOB
@@ -761,6 +911,40 @@
         IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
         DoTimeouts(handleData);
 
+        /*Codes_SRS_IOTHUBCLIENT_LL_07_008: [ IoTHubClient_LL_DoWork shall iterate the message queue and execute the underlying transports IoTHubTransport_ProcessItem function for each item. ] */
+        DLIST_ENTRY* client_item = handleData->iot_msg_queue.Flink;
+        while (client_item != &(handleData->iot_msg_queue)) /*while we are not at the end of the list*/
+        {
+            PDLIST_ENTRY next_item = client_item->Flink;
+
+            IOTHUB_DEVICE_TWIN* queue_data = containingRecord(client_item, IOTHUB_DEVICE_TWIN, entry);
+            IOTHUB_IDENTITY_INFO identity_info;
+            identity_info.device_twin = queue_data;
+            IOTHUB_PROCESS_ITEM_RESULT process_results =  handleData->IoTHubTransport_ProcessItem(handleData->transportHandle, IOTHUB_TYPE_DEVICE_TWIN, &identity_info);
+            if (process_results == IOTHUB_PROCESS_CONTINUE || process_results == IOTHUB_PROCESS_NOT_CONNECTED)
+            {
+                /*Codes_SRS_IOTHUBCLIENT_LL_07_010: [ If 'IoTHubTransport_ProcessItem' returns IOTHUB_PROCESS_CONTINUE or IOTHUB_PROCESS_NOT_CONNECTED IoTHubClient_LL_DoWork shall continue on to call the underlaying layer's _DoWork function. ]*/
+                break;
+            }
+            else 
+            {
+                DList_RemoveEntryList(client_item);
+                if (process_results == IOTHUB_PROCESS_OK)
+                {
+                    /*Codes_SRS_IOTHUBCLIENT_LL_07_011: [ If 'IoTHubTransport_ProcessItem' returns IOTHUB_PROCESS_OK IoTHubClient_LL_DoWork shall add the IOTHUB_DEVICE_TWIN to the ack queue. ]*/
+                    DList_InsertTailList(&(iotHubClientHandle->iot_ack_queue), &(queue_data->entry));
+                }
+                else
+                {
+                    /*Codes_SRS_IOTHUBCLIENT_LL_07_012: [ If 'IoTHubTransport_ProcessItem' returns any other value IoTHubClient_LL_DoWork shall destroy the IOTHUB_DEVICE_TWIN item. ]*/
+                    LogError("Failure queue processing item");
+                    device_twin_data_destroy(queue_data);
+                }
+            }
+            // Move along to the next item
+            client_item = next_item;
+        }
+
         /*Codes_SRS_IOTHUBCLIENT_LL_02_021: [Otherwise, IoTHubClient_LL_DoWork shall invoke the underlaying layer's _DoWork function.]*/
         handleData->IoTHubTransport_DoWork(handleData->transportHandle, iotHubClientHandle);
     }
@@ -818,6 +1002,107 @@
     }
 }
 
+int IoTHubClient_LL_DeviceMethodComplete(IOTHUB_CLIENT_LL_HANDLE handle, const char* method_name, const unsigned char* payLoad, size_t size, BUFFER_HANDLE response)
+{
+    int result;
+    if (handle == NULL || response == NULL)
+    {
+        /* Codes_SRS_IOTHUBCLIENT_LL_07_017: [ If handle or response is NULL then IoTHubClient_LL_DeviceMethodComplete shall return 500. ] */
+        LogError("Invalid argument handle=%p", handle);
+        result = 500;
+    }
+    else
+    {
+        /* Codes_SRS_IOTHUBCLIENT_LL_07_018: [ If deviceMethodCallback is not NULL IoTHubClient_LL_DeviceMethodComplete shall execute deviceMethodCallback and return the status. ] */
+        IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle;
+        if (handleData->deviceMethodCallback)
+        {
+            unsigned char* payload_resp = NULL;
+            size_t resp_size = 0;
+            result = handleData->deviceMethodCallback(method_name, payLoad, size, &payload_resp, &resp_size, handleData->deviceMethodUserContextCallback);
+            /* Codes_SRS_IOTHUBCLIENT_LL_07_020: [ deviceMethodCallback shall buil the BUFFER_HANDLE with the response payload from the IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC callback. ] */
+            if (payload_resp != NULL && resp_size > 0)
+            {
+                if (BUFFER_build(response, payload_resp, resp_size) != 0)
+                {
+                    result = 500;
+                }
+            }
+            if (payload_resp != NULL)
+            {
+                free(payload_resp);
+            }
+        }
+        else
+        {
+            /* Codes_SRS_IOTHUBCLIENT_LL_07_019: [ If deviceMethodCallback is NULL IoTHubClient_LL_DeviceMethodComplete shall return 404. ] */
+            result = 404;
+        }
+    }
+    return result;
+}
+
+void IoTHubClient_LL_RetrievePropertyComplete(IOTHUB_CLIENT_LL_HANDLE handle, DEVICE_TWIN_UPDATE_STATE update_state, const unsigned char* payLoad, size_t size)
+{
+    if (handle == NULL)
+    {
+        /* Codes_SRS_IOTHUBCLIENT_LL_07_013: [ If handle is NULL then IoTHubClient_LL_RetrievePropertyComplete shall do nothing.] */
+        LogError("Invalid argument handle=%p", handle);
+    }
+    else
+    {
+        IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle;
+        /* Codes_SRS_IOTHUBCLIENT_LL_07_014: [ If deviceTwinCallback is NULL then IoTHubClient_LL_RetrievePropertyComplete shall do nothing.] */
+        if (handleData->deviceTwinCallback)
+        {
+            /* Codes_SRS_IOTHUBCLIENT_LL_07_015: [ If the the update_state parameter is DEVICE_TWIN_UPDATE_PARTIAL and a DEVICE_TWIN_UPDATE_COMPLETE has not been previously recieved then IoTHubClient_LL_RetrievePropertyComplete shall do nothing.] */
+            if (update_state == DEVICE_TWIN_UPDATE_COMPLETE)
+            {
+                handleData->complete_twin_update_encountered = true;
+            }
+            if (handleData->complete_twin_update_encountered)
+            {
+                /* Codes_SRS_IOTHUBCLIENT_LL_07_016: [ If deviceTwinCallback is set and DEVICE_TWIN_UPDATE_COMPLETE has been encountered then IoTHubClient_LL_RetrievePropertyComplete shall call deviceTwinCallback.] */
+                handleData->deviceTwinCallback(update_state, payLoad, size, handleData->deviceTwinContextCallback);
+            }
+        }
+    }
+}
+
+void IoTHubClient_LL_ReportedStateComplete(IOTHUB_CLIENT_LL_HANDLE handle, uint32_t item_id, int status_code)
+{
+    /* Codes_SRS_IOTHUBCLIENT_LL_07_002: [ if handle or queue_handle are NULL then IoTHubClient_LL_ReportedStateComplete shall do nothing. ] */
+    if (handle == NULL)
+    {
+        /*"shall return"*/
+        LogError("Invalid argument handle=%p", handle);
+    }
+    else
+    {
+        IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle;
+
+        /* Codes_SRS_IOTHUBCLIENT_LL_07_003: [ IoTHubClient_LL_ReportedStateComplete shall enumerate through the IOTHUB_DEVICE_TWIN structures in queue_handle. ]*/
+        DLIST_ENTRY* client_item = handleData->iot_ack_queue.Flink;
+        while (client_item != &(handleData->iot_ack_queue)) /*while we are not at the end of the list*/
+        {
+            PDLIST_ENTRY next_item = client_item->Flink;
+            IOTHUB_DEVICE_TWIN* queue_data = containingRecord(client_item, IOTHUB_DEVICE_TWIN, entry);
+            if (queue_data->item_id == item_id)
+            {
+                if (queue_data->reported_state_callback != NULL)
+                {
+                    queue_data->reported_state_callback(status_code, queue_data->context);
+                }
+                /*Codes_SRS_IOTHUBCLIENT_LL_07_009: [ IoTHubClient_LL_ReportedStateComplete shall remove the IOTHUB_DEVICE_TWIN item from the ack queue.]*/
+                DList_RemoveEntryList(client_item);
+                device_twin_data_destroy(queue_data);
+                break;
+            }
+            client_item = next_item;
+        }
+    }
+}
+
 IOTHUBMESSAGE_DISPOSITION_RESULT IoTHubClient_LL_MessageCallback(IOTHUB_CLIENT_LL_HANDLE handle, IOTHUB_MESSAGE_HANDLE message)
 {
     int result;
@@ -847,43 +1132,106 @@
         }
     }
     /*Codes_SRS_IOTHUBCLIENT_LL_02_031: [Then IoTHubClient_LL_MessageCallback shall return what the user function returns.]*/
-	return (IOTHUBMESSAGE_DISPOSITION_RESULT) result;
+    return (IOTHUBMESSAGE_DISPOSITION_RESULT) result;
 }
 
-void IotHubClient_LL_ConnectionStatusCallBack(IOTHUB_CLIENT_LL_HANDLE handle, PDLIST_ENTRY connectionStatus)
+void IotHubClient_LL_ConnectionStatusCallBack(IOTHUB_CLIENT_LL_HANDLE handle, IOTHUB_CLIENT_CONNECTION_STATUS status, IOTHUB_CLIENT_CONNECTION_STATUS_REASON reason)
 {
-    (void)handle;
-    (void)connectionStatus;
+    /*Codes_SRS_IOTHUBCLIENT_LL_25_113: [If parameter connectionStatus is NULL or parameter handle is NULL then IotHubClient_LL_ConnectionStatusCallBack shall return.]*/
+    if (handle == NULL)
+    {
+        /*"shall return"*/
+        LogError("invalid arg");
+    }
+    else
+    {
+        IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle;
+
+        /*Codes_SRS_IOTHUBCLIENT_LL_25_114: [IotHubClient_LL_ConnectionStatusCallBack shall call non-callback set by the user from IoTHubClient_LL_SetConnectionStatusCallback passing the status, reason and the passed userContextCallback.]*/
+        if (handleData->conStatusCallback != NULL)
+        {
+            handleData->conStatusCallback(status, reason, handleData->conStatusUserContextCallback);
+        }
+    }
+
 }
 
 IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetConnectionStatusCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK connectionStatusCallback, void * userContextCallback)
 {
-
-    IOTHUB_CLIENT_RESULT result = IOTHUB_CLIENT_OK;
-    (void)iotHubClientHandle;
-    (void)connectionStatusCallback;
-    (void)userContextCallback;
-
+    IOTHUB_CLIENT_RESULT result;
+    /*Codes_SRS_IOTHUBCLIENT_LL_25_111: [IoTHubClient_LL_SetConnectionStatusCallback shall return IOTHUB_CLIENT_INVALID_ARG if called with NULL parameter iotHubClientHandle**]** */
+    if (iotHubClientHandle == NULL)
+    {
+        result = IOTHUB_CLIENT_INVALID_ARG;
+        LOG_ERROR_RESULT;
+    }
+    else
+    {
+        IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
+        /*Codes_SRS_IOTHUBCLIENT_LL_25_112: [IoTHubClient_LL_SetConnectionStatusCallback shall return IOTHUB_CLIENT_OK and save the callback and userContext as a member of the handle.] */
+        handleData->conStatusCallback = connectionStatusCallback;
+        handleData->conStatusUserContextCallback = userContextCallback;
+        result = IOTHUB_CLIENT_OK;
+    }
 
     return result;
 }
 
-IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetRetryPolicy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitinSeconds)
+IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetRetryPolicy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitInSeconds)
 {
-    IOTHUB_CLIENT_RESULT result = IOTHUB_CLIENT_OK;
-    (void)iotHubClientHandle;
-    (void)retryPolicy;
-    (void)retryTimeoutLimitinSeconds;
+    IOTHUB_CLIENT_RESULT result;
+    IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
 
+    /* Codes_SRS_IOTHUBCLIENT_LL_25_116: [**IoTHubClient_LL_SetRetryPolicy shall return IOTHUB_CLIENT_INVALID_ARG if called with NULL iotHubClientHandle]*/
+    if (handleData == NULL)
+    {
+        result = IOTHUB_CLIENT_INVALID_ARG;
+        LOG_ERROR_RESULT;
+    }
+    else
+    {
+        if (handleData->transportHandle == NULL)
+        {
+            result = IOTHUB_CLIENT_ERROR;
+            LOG_ERROR_RESULT;
+        }
+        else
+        {
+            if (handleData->IoTHubTransport_SetRetryPolicy(handleData->transportHandle, retryPolicy, retryTimeoutLimitInSeconds) != 0)
+            {
+                result = IOTHUB_CLIENT_ERROR;
+                LOG_ERROR_RESULT;
+            }
+            else
+            {
+                /*Codes_SRS_IOTHUBCLIENT_LL_25_118: [**IoTHubClient_LL_SetRetryPolicy shall save connection retry policies specified by the user to retryPolicy in struct IOTHUB_CLIENT_LL_HANDLE_DATA]*/
+                /*Codes_SRS_IOTHUBCLIENT_LL_25_119: [**IoTHubClient_LL_SetRetryPolicy shall save retryTimeoutLimitInSeconds in seconds to retryTimeout in struct IOTHUB_CLIENT_LL_HANDLE_DATA]*/
+                handleData->retryPolicy = retryPolicy;
+                handleData->retryTimeoutLimitInSeconds = retryTimeoutLimitInSeconds;
+                result = IOTHUB_CLIENT_OK;
+            }
+        }
+    }
     return result;
 }
 
-IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetRetryPolicy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY* retryPolicy, size_t* retryTimeoutLimitinSeconds)
+IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetRetryPolicy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY* retryPolicy, size_t* retryTimeoutLimitInSeconds)
 {
     IOTHUB_CLIENT_RESULT result = IOTHUB_CLIENT_OK;
-    (void)iotHubClientHandle;
-    (void)retryPolicy;
-    (void)retryTimeoutLimitinSeconds;
+    IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
+
+    /* Codes_SRS_IOTHUBCLIENT_LL_09_001: [IoTHubClient_LL_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_INVALID_ARG if any of the arguments is NULL] */
+    if (handleData == NULL || retryPolicy == NULL || retryTimeoutLimitInSeconds == NULL)
+    {
+        result = IOTHUB_CLIENT_INVALID_ARG;
+        LOG_ERROR_RESULT;
+    }
+    else
+    {
+        *retryPolicy = handleData->retryPolicy;
+        *retryTimeoutLimitInSeconds = handleData->retryTimeoutLimitInSeconds;
+        result = IOTHUB_CLIENT_OK;
+    }
 
     return result;
 }
@@ -985,6 +1333,130 @@
     return result;
 }
 
+IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetDeviceTwinCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK deviceTwinCallback, void* userContextCallback)
+{
+    IOTHUB_CLIENT_RESULT result;
+    /* Codes_SRS_IOTHUBCLIENT_LL_10_001: [ IoTHubClient_LL_SetDeviceTwinCallback shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL.] */
+    if (iotHubClientHandle == NULL)
+    {
+        result = IOTHUB_CLIENT_INVALID_ARG;
+        LogError("Invalid argument specified iothubClientHandle=%p", iotHubClientHandle);
+    }
+    else
+    {
+        IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
+        if (deviceTwinCallback == NULL)
+        {
+            /* Codes_SRS_IOTHUBCLIENT_LL_10_006: [ If deviceTwinCallback is NULL, then IoTHubClient_LL_SetDeviceTwinCallback shall call the underlying layer's _Unsubscribe function and return IOTHUB_CLIENT_OK.] */
+            handleData->IoTHubTransport_Unsubscribe_DeviceTwin(handleData->transportHandle);
+            handleData->deviceTwinCallback = NULL;
+            result = IOTHUB_CLIENT_OK;
+        }
+        else
+        {
+            /* Codes_SRS_IOTHUBCLIENT_LL_10_002: [ If deviceTwinCallback is not NULL, then IoTHubClient_LL_SetDeviceTwinCallback shall call the underlying layer's _Subscribe function.] */
+            if (handleData->IoTHubTransport_Subscribe_DeviceTwin(handleData->transportHandle) == 0)
+            {
+                handleData->deviceTwinCallback = deviceTwinCallback;
+                handleData->deviceTwinContextCallback = userContextCallback;
+                /* Codes_SRS_IOTHUBCLIENT_LL_10_005: [ Otherwise IoTHubClient_LL_SetDeviceTwinCallback shall succeed and return IOTHUB_CLIENT_OK.] */
+                result = IOTHUB_CLIENT_OK;
+            }
+            else
+            {
+                /* Codes_SRS_IOTHUBCLIENT_LL_10_003: [ If the underlying layer's _Subscribe function fails, then IoTHubClient_LL_SetDeviceTwinCallback shall fail and return IOTHUB_CLIENT_ERROR.] */
+                result = IOTHUB_CLIENT_ERROR;
+            }
+        }
+    }
+    return result;
+}
+
+IOTHUB_CLIENT_RESULT IoTHubClient_LL_SendReportedState(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const unsigned char* reportedState, size_t size, IOTHUB_CLIENT_REPORTED_STATE_CALLBACK reportedStateCallback, void* userContextCallback)
+{
+    IOTHUB_CLIENT_RESULT result;
+    /* Codes_SRS_IOTHUBCLIENT_LL_10_012: [ IoTHubClient_LL_SendReportedState shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL. ] */
+    /* Codes_SRS_IOTHUBCLIENT_LL_10_013: [ IoTHubClient_LL_SendReportedState shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter reportedState is NULL] */
+    /* Codes_SRS_IOTHUBCLIENT_LL_07_005: [ IoTHubClient_LL_SendReportedState shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter size is equal to 0. ] */
+    if (iotHubClientHandle == NULL || (reportedState == NULL || size == 0) )
+    {
+        result = IOTHUB_CLIENT_INVALID_ARG;
+        LogError("Invalid argument specified iothubClientHandle=%p, reportedState=%p, size=%zu", iotHubClientHandle, reportedState, size);
+    }
+    else
+    {
+        IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
+        /* Codes_SRS_IOTHUBCLIENT_LL_10_014: [IoTHubClient_LL_SendReportedState shall construct and queue the reported a Device_Twin structure for transmition by the underlying transport.] */
+        IOTHUB_DEVICE_TWIN* client_data = dev_twin_data_create(handleData, get_next_item_id(handleData), reportedState, size, reportedStateCallback, userContextCallback);
+        if (client_data == NULL)
+        {
+            /* Codes_SRS_IOTHUBCLIENT_LL_10_015: [If any error is encountered IoTHubClient_LL_SendReportedState shall return IOTHUB_CLIENT_ERROR.] */
+            LogError("Failure constructing device twin data");
+            result = IOTHUB_CLIENT_ERROR;
+        }
+        else
+        {
+            if (handleData->IoTHubTransport_Subscribe_DeviceTwin(handleData->transportHandle) != 0)
+            {
+                LogError("Failure adding device twin data to queue");
+                device_twin_data_destroy(client_data);
+                result = IOTHUB_CLIENT_ERROR;
+            }
+            else
+            {
+                /* Codes_SRS_IOTHUBCLIENT_LL_07_001: [ IoTHubClient_LL_SendReportedState shall queue the constructed reportedState data to be consumed by the targeted transport. ] */
+                DList_InsertTailList(&(iotHubClientHandle->iot_msg_queue), &(client_data->entry));
+
+                /* Codes_SRS_IOTHUBCLIENT_LL_10_016: [ Otherwise IoTHubClient_LL_SendReportedState shall succeed and return IOTHUB_CLIENT_OK.] */
+                result = IOTHUB_CLIENT_OK;
+            }
+        }
+    }
+    return result;
+}
+
+IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetDeviceMethodCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC deviceMethodCallback, void* userContextCallback)
+{
+    IOTHUB_CLIENT_RESULT result;
+
+    /*Codes_SRS_IOTHUBCLIENT_LL_12_017: [ IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL. ] */
+    if (iotHubClientHandle == NULL)
+    {
+        result = IOTHUB_CLIENT_INVALID_ARG;
+        LOG_ERROR_RESULT;
+    }
+    else
+    {
+        IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
+        if (deviceMethodCallback == NULL)
+        {
+            /*Codes_SRS_IOTHUBCLIENT_LL_12_018: [If deviceMethodCallback is NULL, then IoTHubClient_LL_SetDeviceMethodCallback shall call the underlying layer's IoTHubTransport_Unsubscribe_DeviceMethod function and return IOTHUB_CLIENT_OK. ] */
+            /*Codes_SRS_IOTHUBCLIENT_LL_12_022: [ Otherwise IoTHubClient_LL_SetDeviceMethodCallback shall succeed and return IOTHUB_CLIENT_OK. ]*/
+            handleData->IoTHubTransport_Unsubscribe_DeviceMethod(handleData->transportHandle);
+            handleData->deviceMethodCallback = NULL;
+            result = IOTHUB_CLIENT_OK;
+        }
+        else
+        {
+            /*Codes_SRS_IOTHUBCLIENT_LL_12_019: [ If deviceMethodCallback is not NULL, then IoTHubClient_LL_SetDeviceMethodCallback shall call the underlying layer's IoTHubTransport_Subscribe_DeviceMethod function. ]*/
+            if (handleData->IoTHubTransport_Subscribe_DeviceMethod(handleData->deviceHandle) == 0)
+            {
+                /*Codes_SRS_IOTHUBCLIENT_LL_12_022: [ Otherwise IoTHubClient_LL_SetDeviceMethodCallback shall succeed and return IOTHUB_CLIENT_OK. ]*/
+                handleData->deviceMethodCallback = deviceMethodCallback;
+                handleData->deviceMethodUserContextCallback = userContextCallback;
+                result = IOTHUB_CLIENT_OK;
+            }
+            else
+            {
+                /*Codes_SRS_IOTHUBCLIENT_LL_12_020: [ If the underlying layer's IoTHubTransport_Subscribe_DeviceMethod function fails, then IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_ERROR. ]*/
+                /*Codes_SRS_IOTHUBCLIENT_LL_12_021: [ If adding the information fails for any reason, IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_ERROR. ]*/
+                result = IOTHUB_CLIENT_ERROR;
+            }
+        }
+    }
+    return result;
+}
+
 #ifndef DONT_USE_UPLOADTOBLOB
 IOTHUB_CLIENT_RESULT IoTHubClient_LL_UploadToBlob(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const char* destinationFileName, const unsigned char* source, size_t size)
 {
--- a/iothub_client_ll.h	Thu Oct 20 17:07:32 2016 -0700
+++ b/iothub_client_ll.h	Wed Nov 16 21:37:53 2016 -0800
@@ -24,19 +24,35 @@
 #define IOTHUB_CLIENT_LL_H
 
 #include "azure_c_shared_utility/macro_utils.h"
+#include "azure_c_shared_utility/umock_c_prod.h"
 
 #define IOTHUB_CLIENT_RESULT_VALUES       \
     IOTHUB_CLIENT_OK,                     \
     IOTHUB_CLIENT_INVALID_ARG,            \
     IOTHUB_CLIENT_ERROR,                  \
     IOTHUB_CLIENT_INVALID_SIZE,           \
-    IOTHUB_CLIENT_INDEFINITE_TIME         \
+    IOTHUB_CLIENT_INDEFINITE_TIME
 
 /** @brief Enumeration specifying the status of calls to various APIs in this module.
 */
 
 DEFINE_ENUM(IOTHUB_CLIENT_RESULT, IOTHUB_CLIENT_RESULT_VALUES);
 
+#define IOTHUB_CLIENT_RETRY_POLICY_VALUES     \
+    IOTHUB_CLIENT_RETRY_NONE,                   \
+    IOTHUB_CLIENT_RETRY_IMMEDIATE,                  \
+    IOTHUB_CLIENT_RETRY_INTERVAL,      \
+    IOTHUB_CLIENT_RETRY_LINEAR_BACKOFF,      \
+    IOTHUB_CLIENT_RETRY_EXPONENTIAL_BACKOFF,                 \
+    IOTHUB_CLIENT_RETRY_EXPONENTIAL_BACKOFF_WITH_JITTER,                 \
+    IOTHUB_CLIENT_RETRY_RANDOM
+
+/** @brief Enumeration passed in by the IoT Hub when the event confirmation
+*		   callback is invoked to indicate status of the event processing in
+*		   the hub.
+*/
+DEFINE_ENUM(IOTHUB_CLIENT_RETRY_POLICY, IOTHUB_CLIENT_RETRY_POLICY_VALUES);
+
 struct IOTHUBTRANSPORT_CONFIG_TAG;
 typedef struct IOTHUBTRANSPORT_CONFIG_TAG IOTHUBTRANSPORT_CONFIG;
 
@@ -44,18 +60,41 @@
 
 #define IOTHUB_CLIENT_STATUS_VALUES       \
     IOTHUB_CLIENT_SEND_STATUS_IDLE,       \
-    IOTHUB_CLIENT_SEND_STATUS_BUSY        \
+    IOTHUB_CLIENT_SEND_STATUS_BUSY
 
 /** @brief Enumeration returned by the ::IoTHubClient_LL_GetSendStatus
 *		   API to indicate the current sending status of the IoT Hub client.
 */
 DEFINE_ENUM(IOTHUB_CLIENT_STATUS, IOTHUB_CLIENT_STATUS_VALUES);
 
+#define IOTHUB_IDENTITY_TYPE_VALUE  \
+    IOTHUB_TYPE_TELEMETRY,          \
+    IOTHUB_TYPE_DEVICE_TWIN,        \
+    IOTHUB_TYPE_DEVICE_METHODS
+DEFINE_ENUM(IOTHUB_IDENTITY_TYPE, IOTHUB_IDENTITY_TYPE_VALUE);
+
+#define IOTHUB_PROCESS_ITEM_RESULT_VALUE    \
+    IOTHUB_PROCESS_OK,                      \
+    IOTHUB_PROCESS_ERROR,                   \
+    IOTHUB_PROCESS_NOT_CONNECTED,           \
+    IOTHUB_PROCESS_CONTINUE
+DEFINE_ENUM(IOTHUB_PROCESS_ITEM_RESULT, IOTHUB_PROCESS_ITEM_RESULT_VALUE);
+
 #include "azure_c_shared_utility/agenttime.h"
 #include "azure_c_shared_utility/xio.h"
 #include "azure_c_shared_utility/doublylinkedlist.h"
 #include "iothub_message.h"
 #include "iothub_transport_ll.h"
+#include <stddef.h>
+#include <stdint.h>
+
+#define IOTHUB_CLIENT_IOTHUB_METHOD_STATUS_VALUES \
+    IOTHUB_CLIENT_IOTHUB_METHOD_STATUS_SUCCESS,   \
+    IOTHUB_CLIENT_IOTHUB_METHOD_STATUS_ERROR      \
+
+/** @brief Enumeration returned by remotely executed functions
+*/
+DEFINE_ENUM(IOTHUB_CLIENT_IOTHUB_METHOD_STATUS, IOTHUB_CLIENT_IOTHUB_METHOD_STATUS_VALUES);
 
 #ifdef __cplusplus
 extern "C"
@@ -68,20 +107,16 @@
     IOTHUB_CLIENT_CONFIRMATION_MESSAGE_TIMEOUT,      \
     IOTHUB_CLIENT_CONFIRMATION_ERROR                 \
 
-	/** @brief Enumeration passed in by the IoT Hub when the event confirmation
-	*		   callback is invoked to indicate status of the event processing in
-	*		   the hub.
-	*/
-	DEFINE_ENUM(IOTHUB_CLIENT_CONFIRMATION_RESULT, IOTHUB_CLIENT_CONFIRMATION_RESULT_VALUES);
+    /** @brief Enumeration passed in by the IoT Hub when the event confirmation
+    *		   callback is invoked to indicate status of the event processing in
+    *		   the hub.
+    */
+    DEFINE_ENUM(IOTHUB_CLIENT_CONFIRMATION_RESULT, IOTHUB_CLIENT_CONFIRMATION_RESULT_VALUES);
 
-#define IOTHUB_CLIENT_CONNECTION_STATUS_VALUES                                     \
-    IOTHUB_CLIENT_CONNECTION_INPROGRESS,                                           \
-    IOTHUB_CLIENT_CONNECTION_SUCCESS,                                              \
-    IOTHUB_CLIENT_CONNECTION_DISCONNECTED,                                         \
-    IOTHUB_CLIENT_CONNECTION_RETRY,                                                \
-    IOTHUB_CLIENT_CONNECTION_RETRY_TIMEOUT,                                        \
-    IOTHUB_CLIENT_CONNECTION_RECOVERABLE_ERROR,                                    \
-    IOTHUB_CLIENT_CONNECTION_UNRECOVERABLE_ERROR                                   \
+#define IOTHUB_CLIENT_CONNECTION_STATUS_VALUES             \
+    IOTHUB_CLIENT_CONNECTION_AUTHENTICATED,                \
+    IOTHUB_CLIENT_CONNECTION_UNAUTHENTICATED               \
+
 
     /** @brief Enumeration passed in by the IoT Hub when the connection status
     *		   callback is invoked to indicate status of the connection in
@@ -89,11 +124,13 @@
     */
     DEFINE_ENUM(IOTHUB_CLIENT_CONNECTION_STATUS, IOTHUB_CLIENT_CONNECTION_STATUS_VALUES);
 
-#define IOTHUB_CLIENT_CONNECTION_STATUS_REASON_VALUES                               \
-    IOTHUB_CLIENT_CONNECTION_UNRECOVERABLE_SERVER_AUTHENTICATION_ERROR,             \
-    IOTHUB_CLIENT_CONNECTION_UNRECOVERABLE_SERVER_QUOTA_EXCEEDED,                   \
-    IOTHUB_CLIENT_CONNECTION_USER_REQUEST,                                          \
-    IOTHUB_CLIENT_CONNECTION_OK                                                     \
+#define IOTHUB_CLIENT_CONNECTION_STATUS_REASON_VALUES      \
+    IOTHUB_CLIENT_CONNECTION_EXPIRED_SAS_TOKEN,            \
+    IOTHUB_CLIENT_CONNECTION_DEVICE_DISABLED,              \
+    IOTHUB_CLIENT_CONNECTION_BAD_CREDENTIAL,               \
+    IOTHUB_CLIENT_CONNECTION_RETRY_EXPIRED,                \
+    IOTHUB_CLIENT_CONNECTION_NO_NETWORK,                   \
+    IOTHUB_CLIENT_CONNECTION_OK                            \
 
     /** @brief Enumeration passed in by the IoT Hub when the connection status
     *		   callback is invoked to indicate status of the connection in
@@ -105,205 +142,199 @@
     TRANSPORT_LL, /*LL comes from "LowLevel" */ \
     TRANSPORT_THREADED
 
-	DEFINE_ENUM(TRANSPORT_TYPE, TRANSPORT_TYPE_VALUES);
+    DEFINE_ENUM(TRANSPORT_TYPE, TRANSPORT_TYPE_VALUES);
 
 #define IOTHUBMESSAGE_DISPOSITION_RESULT_VALUES \
     IOTHUBMESSAGE_ACCEPTED, \
     IOTHUBMESSAGE_REJECTED, \
     IOTHUBMESSAGE_ABANDONED
 
-	/** @brief Enumeration returned by the callback which is invoked whenever the
-	*		   IoT Hub sends a message to the device.
-	*/
-	DEFINE_ENUM(IOTHUBMESSAGE_DISPOSITION_RESULT, IOTHUBMESSAGE_DISPOSITION_RESULT_VALUES);
+    /** @brief Enumeration returned by the callback which is invoked whenever the
+    *		   IoT Hub sends a message to the device.
+    */
+    DEFINE_ENUM(IOTHUBMESSAGE_DISPOSITION_RESULT, IOTHUBMESSAGE_DISPOSITION_RESULT_VALUES);
+
+#define DEVICE_TWIN_UPDATE_STATE_VALUES \
+    DEVICE_TWIN_UPDATE_COMPLETE, \
+    DEVICE_TWIN_UPDATE_PARTIAL
 
-#define IOTHUB_CLIENT_RETRY_POLICY_VALUES     \
-    IOTHUB_CLIENT_RETRY_NONE,                   \
-    IOTHUB_CLIENT_RETRY_IMMEDIATE,                  \
-    IOTHUB_CLIENT_RETRY_INTERVAL,      \
-    IOTHUB_CLIENT_RETRY_LINEAR_BACKOFF,      \
-    IOTHUB_CLIENT_RETRY_EXPONENTIAL_BACKOFF,                 \
-    IOTHUB_CLIENT_RETRY_EXPONENTIAL_BACKOFF_WITH_JITTER,                 \
-    IOTHUB_CLIENT_RETRY_RANDOM
+    DEFINE_ENUM(DEVICE_TWIN_UPDATE_STATE, DEVICE_TWIN_UPDATE_STATE_VALUES);
 
-    /** @brief Enumeration passed in by the IoT Hub when the event confirmation
-    *		   callback is invoked to indicate status of the event processing in
-    *		   the hub.
-    */
-    DEFINE_ENUM(IOTHUB_CLIENT_RETRY_POLICY, IOTHUB_CLIENT_RETRY_POLICY_VALUES);
+    typedef void(*IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK)(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCallback);
+    typedef void(*IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK)(IOTHUB_CLIENT_CONNECTION_STATUS result, IOTHUB_CLIENT_CONNECTION_STATUS_REASON reason, void* userContextCallback);
+    typedef IOTHUBMESSAGE_DISPOSITION_RESULT (*IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC)(IOTHUB_MESSAGE_HANDLE message, void* userContextCallback);
+    typedef const TRANSPORT_PROVIDER*(*IOTHUB_CLIENT_TRANSPORT_PROVIDER)(void);
+
+    typedef void(*IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK)(DEVICE_TWIN_UPDATE_STATE update_state, const unsigned char* payLoad, size_t size, void* userContextCallback);
+    typedef void(*IOTHUB_CLIENT_REPORTED_STATE_CALLBACK)(int status_code, void* userContextCallback);
+    typedef int(*IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC)(const char* method_name, const unsigned char* payload, size_t size, unsigned char** response, size_t* resp_size, void* userContextCallback);
 
-	
-	typedef void(*IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK)(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCallback);
-    typedef void(*IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK)(IOTHUB_CLIENT_CONNECTION_STATUS result, IOTHUB_CLIENT_CONNECTION_STATUS_REASON reason, void* userContextCallback);
-	typedef IOTHUBMESSAGE_DISPOSITION_RESULT (*IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC)(IOTHUB_MESSAGE_HANDLE message, void* userContextCallback);
-	typedef const TRANSPORT_PROVIDER*(*IOTHUB_CLIENT_TRANSPORT_PROVIDER)(void);
+    /** @brief	This struct captures IoTHub client configuration. */
+    typedef struct IOTHUB_CLIENT_CONFIG_TAG
+    {
+        /** @brief A function pointer that is passed into the @c IoTHubClientCreate.
+        *	A function definition for AMQP is defined in the include @c iothubtransportamqp.h.
+        *   A function definition for HTTP is defined in the include @c iothubtransporthttp.h
+        *   A function definition for MQTT is defined in the include @c iothubtransportmqtt.h */
+        IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol;
 
-	/** @brief	This struct captures IoTHub client configuration. */
-	typedef struct IOTHUB_CLIENT_CONFIG_TAG
-	{
-		/** @brief A function pointer that is passed into the @c IoTHubClientCreate.
-		*	A function definition for AMQP is defined in the include @c iothubtransportamqp.h.
-		*   A function definition for HTTP is defined in the include @c iothubtransporthttp.h
-		*   A function definition for MQTT is defined in the include @c iothubtransportmqtt.h */
-		IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol;
+        /** @brief	A string that identifies the device. */
+        const char* deviceId;
 
-		/** @brief	A string that identifies the device. */
-		const char* deviceId;
+        /** @brief	The device key used to authenticate the device. 
+        If neither deviceSasToken nor deviceKey is present then the authentication is assumed x509.*/
+        const char* deviceKey;
 
-		/** @brief	The device key used to authenticate the device. 
+        /** @brief	The device SAS Token used to authenticate the device in place of device key. 
         If neither deviceSasToken nor deviceKey is present then the authentication is assumed x509.*/
-		const char* deviceKey;
+        const char* deviceSasToken;
 
-		/** @brief	The device SAS Token used to authenticate the device in place of device key. 
-        If neither deviceSasToken nor deviceKey is present then the authentication is assumed x509.*/
-		const char* deviceSasToken;
+        /** @brief	The IoT Hub name to which the device is connecting. */
+        const char* iotHubName;
 
-		/** @brief	The IoT Hub name to which the device is connecting. */
-		const char* iotHubName;
+        /** @brief	IoT Hub suffix goes here, e.g., private.azure-devices-int.net. */
+        const char* iotHubSuffix;
 
-		/** @brief	IoT Hub suffix goes here, e.g., private.azure-devices-int.net. */
-		const char* iotHubSuffix;
+        const char* protocolGatewayHostName;
+    } IOTHUB_CLIENT_CONFIG;
 
-		const char* protocolGatewayHostName;
-	} IOTHUB_CLIENT_CONFIG;
-
-	/** @brief	This struct captures IoTHub client device configuration. */
-	typedef struct IOTHUB_CLIENT_DEVICE_CONFIG_TAG
-	{
-		/** @brief A function pointer that is passed into the @c IoTHubClientCreate.
-		*	A function definition for AMQP is defined in the include @c iothubtransportamqp.h.
-		*   A function definition for HTTP is defined in the include @c iothubtransporthttp.h
-		*   A function definition for MQTT is defined in the include @c iothubtransportmqtt.h */
-		IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol;
+    /** @brief	This struct captures IoTHub client device configuration. */
+    typedef struct IOTHUB_CLIENT_DEVICE_CONFIG_TAG
+    {
+        /** @brief A function pointer that is passed into the @c IoTHubClientCreate.
+        *	A function definition for AMQP is defined in the include @c iothubtransportamqp.h.
+        *   A function definition for HTTP is defined in the include @c iothubtransporthttp.h
+        *   A function definition for MQTT is defined in the include @c iothubtransportmqtt.h */
+        IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol;
 
-		/** @brief a transport handle implementing the protocol */
-		void * transportHandle;
+        /** @brief a transport handle implementing the protocol */
+        void * transportHandle;
 
-		/** @brief	A string that identifies the device. */
-		const char* deviceId;
+        /** @brief	A string that identifies the device. */
+        const char* deviceId;
 
-		/** @brief	The device key used to authenticate the device. 
+        /** @brief	The device key used to authenticate the device. 
         x509 authentication is is not supported for multiplexed connections*/
-		const char* deviceKey;
+        const char* deviceKey;
 
-		/** @brief	The device SAS Token used to authenticate the device in place of device key. 
+        /** @brief	The device SAS Token used to authenticate the device in place of device key. 
         x509 authentication is is not supported for multiplexed connections.*/
-		const char* deviceSasToken;
-	} IOTHUB_CLIENT_DEVICE_CONFIG;
+        const char* deviceSasToken;
+    } IOTHUB_CLIENT_DEVICE_CONFIG;
 
-	/** @brief	This struct captures IoTHub transport configuration. */
-	struct IOTHUBTRANSPORT_CONFIG_TAG
-	{
-		const IOTHUB_CLIENT_CONFIG* upperConfig;
-		PDLIST_ENTRY waitingToSend;
-	};
+    /** @brief	This struct captures IoTHub transport configuration. */
+    struct IOTHUBTRANSPORT_CONFIG_TAG
+    {
+        const IOTHUB_CLIENT_CONFIG* upperConfig;
+        PDLIST_ENTRY waitingToSend;
+    };
 
 
-	/**
-	* @brief	Creates a IoT Hub client for communication with an existing
-	* 			IoT Hub using the specified connection string parameter.
-	*
-	* @param	connectionString	Pointer to a character string
-	* @param	protocol			Function pointer for protocol implementation
-	*
-	*			Sample connection string:
-	*				<blockquote>
-	*					<pre>HostName=[IoT Hub name goes here].[IoT Hub suffix goes here, e.g., private.azure-devices-int.net];DeviceId=[Device ID goes here];SharedAccessKey=[Device key goes here];</pre>
-	*				</blockquote>
-	*
-	* @return	A non-NULL @c IOTHUB_CLIENT_LL_HANDLE value that is used when
-	* 			invoking other functions for IoT Hub client and @c NULL on failure.
-	*/
-	extern IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateFromConnectionString(const char* connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol);
+    /**
+    * @brief	Creates a IoT Hub client for communication with an existing
+    * 			IoT Hub using the specified connection string parameter.
+    *
+    * @param	connectionString	Pointer to a character string
+    * @param	protocol			Function pointer for protocol implementation
+    *
+    *			Sample connection string:
+    *				<blockquote>
+    *					<pre>HostName=[IoT Hub name goes here].[IoT Hub suffix goes here, e.g., private.azure-devices-int.net];DeviceId=[Device ID goes here];SharedAccessKey=[Device key goes here];</pre>
+    *				</blockquote>
+    *
+    * @return	A non-NULL @c IOTHUB_CLIENT_LL_HANDLE value that is used when
+    * 			invoking other functions for IoT Hub client and @c NULL on failure.
+    */
+     MOCKABLE_FUNCTION(, IOTHUB_CLIENT_LL_HANDLE, IoTHubClient_LL_CreateFromConnectionString, const char*, connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER, protocol);
 
-	/**
-	* @brief	Creates a IoT Hub client for communication with an existing IoT
-	* 			Hub using the specified parameters.
-	*
-	* @param	config	Pointer to an @c IOTHUB_CLIENT_CONFIG structure
-	*
-	*			The API does not allow sharing of a connection across multiple
-	*			devices. This is a blocking call.
-	*
-	* @return	A non-NULL @c IOTHUB_CLIENT_LL_HANDLE value that is used when
-	* 			invoking other functions for IoT Hub client and @c NULL on failure.
-	*/
-	extern IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_Create(const IOTHUB_CLIENT_CONFIG* config);
+    /**
+    * @brief	Creates a IoT Hub client for communication with an existing IoT
+    * 			Hub using the specified parameters.
+    *
+    * @param	config	Pointer to an @c IOTHUB_CLIENT_CONFIG structure
+    *
+    *			The API does not allow sharing of a connection across multiple
+    *			devices. This is a blocking call.
+    *
+    * @return	A non-NULL @c IOTHUB_CLIENT_LL_HANDLE value that is used when
+    * 			invoking other functions for IoT Hub client and @c NULL on failure.
+    */
+     MOCKABLE_FUNCTION(, IOTHUB_CLIENT_LL_HANDLE, IoTHubClient_LL_Create, const IOTHUB_CLIENT_CONFIG*, config);
 
-	/**
-	* @brief	Creates a IoT Hub client for communication with an existing IoT
-	* 			Hub using an existing transport.
-	*
-	* @param	config	Pointer to an @c IOTHUB_CLIENT_DEVICE_CONFIG structure
-	*
-	*			The API *allows* sharing of a connection across multiple
-	*			devices. This is a blocking call.
-	*
-	* @return	A non-NULL @c IOTHUB_CLIENT_LL_HANDLE value that is used when
-	* 			invoking other functions for IoT Hub client and @c NULL on failure.
-	*/
-	extern IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateWithTransport(const IOTHUB_CLIENT_DEVICE_CONFIG * config);
+    /**
+    * @brief	Creates a IoT Hub client for communication with an existing IoT
+    * 			Hub using an existing transport.
+    *
+    * @param	config	Pointer to an @c IOTHUB_CLIENT_DEVICE_CONFIG structure
+    *
+    *			The API *allows* sharing of a connection across multiple
+    *			devices. This is a blocking call.
+    *
+    * @return	A non-NULL @c IOTHUB_CLIENT_LL_HANDLE value that is used when
+    * 			invoking other functions for IoT Hub client and @c NULL on failure.
+    */
+     MOCKABLE_FUNCTION(, IOTHUB_CLIENT_LL_HANDLE, IoTHubClient_LL_CreateWithTransport, const IOTHUB_CLIENT_DEVICE_CONFIG*, config);
 
-	/**
-	* @brief	Disposes of resources allocated by the IoT Hub client. This is a
-	* 			blocking call.
-	*
-	* @param	iotHubClientHandle	The handle created by a call to the create function.
-	*/
-	extern void IoTHubClient_LL_Destroy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle);
+    /**
+    * @brief	Disposes of resources allocated by the IoT Hub client. This is a
+    * 			blocking call.
+    *
+    * @param	iotHubClientHandle	The handle created by a call to the create function.
+    */
+     MOCKABLE_FUNCTION(, void, IoTHubClient_LL_Destroy, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle);
 
-	/**
-	* @brief	Asynchronous call to send the message specified by @p eventMessageHandle.
-	*
-	* @param	iotHubClientHandle		   	The handle created by a call to the create function.
-	* @param	eventMessageHandle		   	The handle to an IoT Hub message.
-	* @param	eventConfirmationCallback  	The callback specified by the device for receiving
-	* 										confirmation of the delivery of the IoT Hub message.
-	* 										This callback can be expected to invoke the
-	* 										::IoTHubClient_LL_SendEventAsync function for the
-	* 										same message in an attempt to retry sending a failing
-	* 										message. The user can specify a @c NULL value here to
-	* 										indicate that no callback is required.
-	* @param	userContextCallback			User specified context that will be provided to the
-	* 										callback. This can be @c NULL.
-	*
-	*			@b NOTE: The application behavior is undefined if the user calls
-	*			the ::IoTHubClient_LL_Destroy function from within any callback.
-	*
-	* @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
-	*/
-	extern IOTHUB_CLIENT_RESULT IoTHubClient_LL_SendEventAsync(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_MESSAGE_HANDLE eventMessageHandle, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK eventConfirmationCallback, void* userContextCallback);
+    /**
+    * @brief	Asynchronous call to send the message specified by @p eventMessageHandle.
+    *
+    * @param	iotHubClientHandle		   	The handle created by a call to the create function.
+    * @param	eventMessageHandle		   	The handle to an IoT Hub message.
+    * @param	eventConfirmationCallback  	The callback specified by the device for receiving
+    * 										confirmation of the delivery of the IoT Hub message.
+    * 										This callback can be expected to invoke the
+    * 										::IoTHubClient_LL_SendEventAsync function for the
+    * 										same message in an attempt to retry sending a failing
+    * 										message. The user can specify a @c NULL value here to
+    * 										indicate that no callback is required.
+    * @param	userContextCallback			User specified context that will be provided to the
+    * 										callback. This can be @c NULL.
+    *
+    *			@b NOTE: The application behavior is undefined if the user calls
+    *			the ::IoTHubClient_LL_Destroy function from within any callback.
+    *
+    * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
+    */
+     MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SendEventAsync, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_MESSAGE_HANDLE, eventMessageHandle, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK, eventConfirmationCallback, void*, userContextCallback);
 
-	/**
-	* @brief	This function returns the current sending status for IoTHubClient.
-	*
-	* @param	iotHubClientHandle		The handle created by a call to the create function.
-	* @param	iotHubClientStatus		The sending state is populated at the address pointed
-	* 									at by this parameter. The value will be set to
-	* 									@c IOTHUBCLIENT_SENDSTATUS_IDLE if there is currently
-	* 								    no item to be sent and @c IOTHUBCLIENT_SENDSTATUS_BUSY
-	* 								    if there are.
-	*
-	* @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
-	*/
-	extern IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetSendStatus(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_STATUS *iotHubClientStatus);
+    /**
+    * @brief	This function returns the current sending status for IoTHubClient.
+    *
+    * @param	iotHubClientHandle		The handle created by a call to the create function.
+    * @param	iotHubClientStatus		The sending state is populated at the address pointed
+    * 									at by this parameter. The value will be set to
+    * 									@c IOTHUBCLIENT_SENDSTATUS_IDLE if there is currently
+    * 								    no item to be sent and @c IOTHUBCLIENT_SENDSTATUS_BUSY
+    * 								    if there are.
+    *
+    * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
+    */
+     MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_GetSendStatus, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_STATUS*, iotHubClientStatus);
 
-	/**
-	* @brief	Sets up the message callback to be invoked when IoT Hub issues a
-	* 			message to the device. This is a blocking call.
-	*
-	* @param	iotHubClientHandle		   	The handle created by a call to the create function.
-	* @param	messageCallback     	   	The callback specified by the device for receiving
-	* 										messages from IoT Hub.
-	* @param	userContextCallback			User specified context that will be provided to the
-	* 										callback. This can be @c NULL.
-	*
-	*			@b NOTE: The application behavior is undefined if the user calls
-	*			the ::IoTHubClient_LL_Destroy function from within any callback.
-	*
-	* @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
-	*/
-	extern IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetMessageCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC messageCallback, void* userContextCallback);
+    /**
+    * @brief	Sets up the message callback to be invoked when IoT Hub issues a
+    * 			message to the device. This is a blocking call.
+    *
+    * @param	iotHubClientHandle		   	The handle created by a call to the create function.
+    * @param	messageCallback     	   	The callback specified by the device for receiving
+    * 										messages from IoT Hub.
+    * @param	userContextCallback			User specified context that will be provided to the
+    * 										callback. This can be @c NULL.
+    *
+    *			@b NOTE: The application behavior is undefined if the user calls
+    *			the ::IoTHubClient_LL_Destroy function from within any callback.
+    *
+    * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
+    */
+     MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetMessageCallback, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC, messageCallback, void*, userContextCallback);
 
     /**
     * @brief	Sets up the connection status callback to be invoked representing the status of
@@ -320,7 +351,7 @@
     *
     * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
     */
-    extern IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetConnectionStatusCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK connectionStatusCallback, void* userContextCallback);
+     MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetConnectionStatusCallback, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK, connectionStatusCallback, void*, userContextCallback);
 
     /**
     * @brief	Sets up the connection status callback to be invoked representing the status of
@@ -329,7 +360,7 @@
     * @param	iotHubClientHandle		   	        The handle created by a call to the create function.
     * @param	retryPolicy                  	   	The policy to use to reconnect to IoT Hub when a
     *                                               connection drops.
-    * @param	retryTimeoutLimitinSeconds			Maximum amount of time(seconds) to attempt reconnection when a
+    * @param	retryTimeoutLimitInSeconds			Maximum amount of time(seconds) to attempt reconnection when a
     *                                               connection drops to IOT Hub.
     *
     *			@b NOTE: The application behavior is undefined if the user calls
@@ -337,7 +368,7 @@
     *
     * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
     */
-    extern IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetRetryPolicy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitinSeconds);
+     MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetRetryPolicy, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY, retryPolicy, size_t, retryTimeoutLimitInSeconds);
 
 
     /**
@@ -346,7 +377,7 @@
     *
     * @param	iotHubClientHandle		   	        The handle created by a call to the create function.
     * @param	retryPolicy                  	   	Out parameter containing the policy to use to reconnect to IoT Hub.
-    * @param	retryTimeoutLimitinSeconds			Out parameter containing maximum amount of time in seconds to attempt reconnection
+    * @param	retryTimeoutLimitInSeconds			Out parameter containing maximum amount of time in seconds to attempt reconnection
                                                     to IOT Hub.
     *
     *			@b NOTE: The application behavior is undefined if the user calls
@@ -354,75 +385,124 @@
     *
     * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
     */
-    extern IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetRetryPolicy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY* retryPolicy, size_t* retryTimeoutLimitinSeconds);
+     MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_GetRetryPolicy, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY*, retryPolicy, size_t*, retryTimeoutLimitInSeconds);
 
-	/**
-	* @brief	This function returns in the out parameter @p lastMessageReceiveTime
-	* 			what was the value of the @c time function when the last message was
-	* 			received at the client.
-	*
-	* @param	iotHubClientHandle				The handle created by a call to the create function.
-	* @param	lastMessageReceiveTime  		Out parameter containing the value of @c time function
-	* 											when the last message was received.
-	*
-	* @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
-	*/
-	extern IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetLastMessageReceiveTime(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, time_t* lastMessageReceiveTime);
+    /**
+    * @brief	This function returns in the out parameter @p lastMessageReceiveTime
+    * 			what was the value of the @c time function when the last message was
+    * 			received at the client.
+    *
+    * @param	iotHubClientHandle				The handle created by a call to the create function.
+    * @param	lastMessageReceiveTime  		Out parameter containing the value of @c time function
+    * 											when the last message was received.
+    *
+    * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
+    */
+     MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_GetLastMessageReceiveTime, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, time_t*, lastMessageReceiveTime);
 
-	/**
-	* @brief	This function is meant to be called by the user when work
-	* 			(sending/receiving) can be done by the IoTHubClient.
-	*
-	* @param	iotHubClientHandle	The handle created by a call to the create function.
-	*
-	*			All IoTHubClient interactions (in regards to network traffic
-	*			and/or user level callbacks) are the effect of calling this
-	*			function and they take place synchronously inside _DoWork.
-	*/
-	extern void IoTHubClient_LL_DoWork(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle);
+    /**
+    * @brief	This function is meant to be called by the user when work
+    * 			(sending/receiving) can be done by the IoTHubClient.
+    *
+    * @param	iotHubClientHandle	The handle created by a call to the create function.
+    *
+    *			All IoTHubClient interactions (in regards to network traffic
+    *			and/or user level callbacks) are the effect of calling this
+    *			function and they take place synchronously inside _DoWork.
+    */
+     MOCKABLE_FUNCTION(, void, IoTHubClient_LL_DoWork, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle);
 
-	/**
-	* @brief	This API sets a runtime option identified by parameter @p optionName
-	* 			to a value pointed to by @p value. @p optionName and the data type
-	* 			@p value is pointing to are specific for every option.
-	*
-	* @param	iotHubClientHandle	The handle created by a call to the create function.
-	* @param	optionName		  	Name of the option.
-	* @param	value			  	The value.
-	*
-	*			The options that can be set via this API are:
-	*				- @b timeout - the maximum time in milliseconds a communication is
-	*				  allowed to use. @p value is a pointer to an @c unsigned @c int with
-	*				  the timeout value in milliseconds. This is only supported for the HTTP
-	*				  protocol as of now. When the HTTP protocol uses CURL, the meaning of
-	*				  the parameter is <em>total request time</em>. When the HTTP protocol uses
-	*				  winhttp, the meaning is the same as the @c dwSendTimeout and
-	*				  @c dwReceiveTimeout parameters of the
-	*				  <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa384116(v=vs.85).aspx">
-	*				  WinHttpSetTimeouts</a> API.
-	*				- @b CURLOPT_LOW_SPEED_LIMIT - only available for HTTP protocol and only
-	*				  when CURL is used. It has the same meaning as CURL's option with the same
-	*				  name. @p value is pointer to a long.
-	*				- @b CURLOPT_LOW_SPEED_TIME - only available for HTTP protocol and only
-	*				  when CURL is used. It has the same meaning as CURL's option with the same
-	*				  name. @p value is pointer to a long.
-	*				- @b CURLOPT_FORBID_REUSE - only available for HTTP protocol and only
-	*				  when CURL is used. It has the same meaning as CURL's option with the same
-	*				  name. @p value is pointer to a long.
-	*				- @b CURLOPT_FRESH_CONNECT - only available for HTTP protocol and only
-	*				  when CURL is used. It has the same meaning as CURL's option with the same
-	*				  name. @p value is pointer to a long.
-	*				- @b CURLOPT_VERBOSE - only available for HTTP protocol and only
-	*				  when CURL is used. It has the same meaning as CURL's option with the same
-	*				  name. @p value is pointer to a long.
-	*              - @b keepalive - available for MQTT protocol.  Integer value that sets the
-	*                interval in seconds when pings are sent to the server.
-	*              - @b logtrace - available for MQTT protocol.  Boolean value that turns on and
-	*                off the diagnostic logging.
-	*
-	* @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
-	*/
-	extern IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetOption(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const char* optionName, const void* value);
+    /**
+    * @brief	This API sets a runtime option identified by parameter @p optionName
+    * 			to a value pointed to by @p value. @p optionName and the data type
+    * 			@p value is pointing to are specific for every option.
+    *
+    * @param	iotHubClientHandle	The handle created by a call to the create function.
+    * @param	optionName		  	Name of the option.
+    * @param	value			  	The value.
+    *
+    *			The options that can be set via this API are:
+    *				- @b timeout - the maximum time in milliseconds a communication is
+    *				  allowed to use. @p value is a pointer to an @c unsigned @c int with
+    *				  the timeout value in milliseconds. This is only supported for the HTTP
+    *				  protocol as of now. When the HTTP protocol uses CURL, the meaning of
+    *				  the parameter is <em>total request time</em>. When the HTTP protocol uses
+    *				  winhttp, the meaning is the same as the @c dwSendTimeout and
+    *				  @c dwReceiveTimeout parameters of the
+    *				  <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa384116(v=vs.85).aspx">
+    *				  WinHttpSetTimeouts</a> API.
+    *				- @b CURLOPT_LOW_SPEED_LIMIT - only available for HTTP protocol and only
+    *				  when CURL is used. It has the same meaning as CURL's option with the same
+    *				  name. @p value is pointer to a long.
+    *				- @b CURLOPT_LOW_SPEED_TIME - only available for HTTP protocol and only
+    *				  when CURL is used. It has the same meaning as CURL's option with the same
+    *				  name. @p value is pointer to a long.
+    *				- @b CURLOPT_FORBID_REUSE - only available for HTTP protocol and only
+    *				  when CURL is used. It has the same meaning as CURL's option with the same
+    *				  name. @p value is pointer to a long.
+    *				- @b CURLOPT_FRESH_CONNECT - only available for HTTP protocol and only
+    *				  when CURL is used. It has the same meaning as CURL's option with the same
+    *				  name. @p value is pointer to a long.
+    *				- @b CURLOPT_VERBOSE - only available for HTTP protocol and only
+    *				  when CURL is used. It has the same meaning as CURL's option with the same
+    *				  name. @p value is pointer to a long.
+    *              - @b keepalive - available for MQTT protocol.  Integer value that sets the
+    *                interval in seconds when pings are sent to the server.
+    *              - @b logtrace - available for MQTT protocol.  Boolean value that turns on and
+    *                off the diagnostic logging.
+    *
+    * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
+    */
+     MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetOption, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, const char*, optionName, const void*, value);
+
+    /**
+    * @brief	This API specifies a call back to be used when the device receives a desired state update.
+    *
+    * @param	iotHubClientHandle		The handle created by a call to the create function.
+    * @param	deviceTwinCallback	    The callback specified by the device client to be used for updating
+    *									the desired state. The callback will be called in response to patch 
+    *									request send by the IoTHub services. The payload will be passed to the
+    *									callback, along with two version numbers:
+    *										- Desired:
+    *										- LastSeenReported:
+    * @param	userContextCallback		User specified context that will be provided to the
+    * 									callback. This can be @c NULL.
+    *
+    *			@b NOTE: The application behavior is undefined if the user calls
+    *			the ::IoTHubClient_LL_Destroy function from within any callback.
+    *
+    * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
+    */
+     MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetDeviceTwinCallback, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK, deviceTwinCallback, void*, userContextCallback);
+
+    /**
+    * @brief	This API sneds a report of the device's properties and their current values.
+    *
+    * @param	iotHubClientHandle		The handle created by a call to the create function.
+    * @param	reportedState			The current device property values to be 'reported' to the IoTHub.
+    * @param	reportedStateCallback	The callback specified by the device client to be called with the
+    *									result of the transaction.
+    * @param	userContextCallback		User specified context that will be provided to the
+    * 									callback. This can be @c NULL.
+    *
+    *			@b NOTE: The application behavior is undefined if the user calls
+    *			the ::IoTHubClient_LL_Destroy function from within any callback.
+    *
+    * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
+    */
+     MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SendReportedState, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, const unsigned char*, reportedState, size_t, size, IOTHUB_CLIENT_REPORTED_STATE_CALLBACK, reportedStateCallback, void*, userContextCallback);
+
+     /**
+     * @brief	This API sets callback for cloud to device method call.
+     *
+     * @param	iotHubClientHandle		The handle created by a call to the create function.
+     * @param	deviceMethodCallback	The callback which will be called by IoTHub.
+     * @param	userContextCallback		User specified context that will be provided to the
+     * 									callback. This can be @c NULL.
+     *
+     * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
+     */
+     MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetDeviceMethodCallback, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC, deviceMethodCallback, void*, userContextCallback);
 
 #ifndef DONT_USE_UPLOADTOBLOB
     /**
@@ -436,7 +516,7 @@
     *
     * @return	IOTHUB_CLIENT_OK upon success or an error code upon failure.
     */
-    extern IOTHUB_CLIENT_RESULT IoTHubClient_LL_UploadToBlob(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const char* destinationFileName, const unsigned char* source, size_t size);
+     MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_UploadToBlob, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, const char*, destinationFileName, const unsigned char*, source, size_t, size);
 
 #endif /*DONT_USE_UPLOADTOBLOB*/
 
--- a/iothub_client_private.h	Thu Oct 20 17:07:32 2016 -0700
+++ b/iothub_client_private.h	Wed Nov 16 21:37:53 2016 -0800
@@ -7,11 +7,15 @@
 #include <signal.h>
 
 #include "azure_c_shared_utility/macro_utils.h"
+#include "azure_c_shared_utility/crt_abstractions.h"
 #include "azure_c_shared_utility/doublylinkedlist.h"
+#include "azure_c_shared_utility/umock_c_prod.h"
+#include "azure_c_shared_utility/constbuffer.h"
 
 #include "iothub_message.h"
 #include "iothub_client_ll.h"
 #include "azure_c_shared_utility/macro_utils.h"
+#include "azure_c_shared_utility/umock_c_prod.h"
 
 #ifdef __cplusplus
 extern "C"
@@ -26,13 +30,15 @@
 #define CLIENT_DEVICE_BACKSLASH "/"
 #define CBS_REPLY_TO "cbs"
 #define CBS_ENDPOINT "/$" CBS_REPLY_TO
-#define API_VERSION "?api-version=2016-02-03"
+#define API_VERSION "?api-version=2016-11-14"
 #define REJECT_QUERY_PARAMETER "&reject"
 
 MOCKABLE_FUNCTION(, void, IoTHubClient_LL_SendComplete, IOTHUB_CLIENT_LL_HANDLE, handle, PDLIST_ENTRY, completed, IOTHUB_CLIENT_CONFIRMATION_RESULT, result);
-MOCKABLE_FUNCTION(, IOTHUBMESSAGE_DISPOSITION_RESULT, IoTHubClient_LL_MessageCallback, IOTHUB_CLIENT_LL_HANDLE, handle, IOTHUB_MESSAGE_HANDLE, message);
-MOCKABLE_FUNCTION(, void, IotHubClient_LL_ConnectionStatusCallBack, IOTHUB_CLIENT_LL_HANDLE, handle, PDLIST_ENTRY, connectionStatus);
-
+MOCKABLE_FUNCTION(, void, IoTHubClient_LL_ReportedStateComplete, IOTHUB_CLIENT_LL_HANDLE, handle, uint32_t, item_id, int, status_code);
+MOCKABLE_FUNCTION(, IOTHUBMESSAGE_DISPOSITION_RESULT, IoTHubClient_LL_MessageCallback, IOTHUB_CLIENT_LL_HANDLE,  handle, IOTHUB_MESSAGE_HANDLE, message);
+MOCKABLE_FUNCTION(, void, IoTHubClient_LL_RetrievePropertyComplete, IOTHUB_CLIENT_LL_HANDLE, handle, DEVICE_TWIN_UPDATE_STATE, update_state, const unsigned char*, payLoad, size_t, size);
+MOCKABLE_FUNCTION(, int, IoTHubClient_LL_DeviceMethodComplete, IOTHUB_CLIENT_LL_HANDLE, handle, const char*, method_name, const unsigned char*, payLoad, size_t, size, BUFFER_HANDLE, result_payload);
+MOCKABLE_FUNCTION(, void, IotHubClient_LL_ConnectionStatusCallBack, IOTHUB_CLIENT_LL_HANDLE, handle, IOTHUB_CLIENT_CONNECTION_STATUS, status, IOTHUB_CLIENT_CONNECTION_STATUS_REASON, reason);
 typedef struct IOTHUB_MESSAGE_LIST_TAG
 {
     IOTHUB_MESSAGE_HANDLE messageHandle;
@@ -42,6 +48,21 @@
     uint64_t ms_timesOutAfter; /* a value of "0" means "no timeout", if the IOTHUBCLIENT_LL's handle tickcounter > msTimesOutAfer then the message shall timeout*/
 }IOTHUB_MESSAGE_LIST;
 
+typedef struct IOTHUB_DEVICE_TWIN_TAG
+{
+    uint32_t item_id;
+    uint64_t ms_timesOutAfter; /* a value of "0" means "no timeout", if the IOTHUBCLIENT_LL's handle tickcounter > msTimesOutAfer then the message shall timeout*/
+    IOTHUB_CLIENT_REPORTED_STATE_CALLBACK reported_state_callback;
+    CONSTBUFFER_HANDLE report_data_handle;
+    void* context;
+    DLIST_ENTRY entry;
+} IOTHUB_DEVICE_TWIN;
+union IOTHUB_IDENTITY_INFO_TAG
+{
+    IOTHUB_DEVICE_TWIN* device_twin;
+    IOTHUB_MESSAGE_LIST* iothub_message;
+};
+
 
 #ifdef __cplusplus
 }
--- a/iothub_client_version.h	Thu Oct 20 17:07:32 2016 -0700
+++ b/iothub_client_version.h	Wed Nov 16 21:37:53 2016 -0800
@@ -8,7 +8,9 @@
 #ifndef IOTHUB_CLIENT_VERSION_H
 #define IOTHUB_CLIENT_VERSION_H
 
-#define IOTHUB_SDK_VERSION "1.0.17"
+#define IOTHUB_SDK_VERSION "1.1.0"
+
+#include "azure_c_shared_utility/umock_c_prod.h"
 
 #ifdef __cplusplus
 extern "C"
@@ -22,7 +24,7 @@
      * @return  Pointer to a null terminated string containing the
      *          current IoT Hub Client SDK version.
      */
-    extern const char* IoTHubClient_GetVersionString(void);
+    MOCKABLE_FUNCTION(, const char*, IoTHubClient_GetVersionString);
 
 #ifdef __cplusplus
 }
--- a/iothub_message.c	Thu Oct 20 17:07:32 2016 -0700
+++ b/iothub_message.c	Wed Nov 16 21:37:53 2016 -0800
@@ -523,4 +523,4 @@
         handleData->correlationId = NULL;
         free(handleData);
     }
-}
\ No newline at end of file
+}
--- a/iothub_message.h	Thu Oct 20 17:07:32 2016 -0700
+++ b/iothub_message.h	Wed Nov 16 21:37:53 2016 -0800
@@ -11,6 +11,7 @@
 
 #include "azure_c_shared_utility/macro_utils.h"
 #include "azure_c_shared_utility/map.h" 
+#include "azure_c_shared_utility/umock_c_prod.h"
 
 #ifdef __cplusplus
 #include <cstddef>
--- a/iothub_transport_ll.h	Thu Oct 20 17:07:32 2016 -0700
+++ b/iothub_transport_ll.h	Wed Nov 16 21:37:53 2016 -0800
@@ -4,12 +4,16 @@
 #ifndef IOTHUB_TRANSPORT_LL_H
 #define IOTHUB_TRANSPORT_LL_H
 
+
 typedef void* TRANSPORT_LL_HANDLE;
 typedef void* IOTHUB_DEVICE_HANDLE;
 
 struct TRANSPORT_PROVIDER_TAG;
 typedef struct TRANSPORT_PROVIDER_TAG TRANSPORT_PROVIDER;
 
+union IOTHUB_IDENTITY_INFO_TAG;
+typedef union IOTHUB_IDENTITY_INFO_TAG IOTHUB_IDENTITY_INFO;
+
 #include "azure_c_shared_utility/doublylinkedlist.h"
 #include "azure_c_shared_utility/strings.h"
 #include "iothub_message.h"
@@ -20,47 +24,59 @@
 {
 #endif
 
-	/** @brief	This struct captures device configuration. */
-	typedef struct IOTHUB_DEVICE_CONFIG_TAG
-	{
-		/** @brief	A string that identifies the device. */
-		const char* deviceId;
+    /** @brief	This struct captures device configuration. */
+    typedef struct IOTHUB_DEVICE_CONFIG_TAG
+    {
+        /** @brief	A string that identifies the device. */
+        const char* deviceId;
 
-		/** @brief	The device key used to authenticate the device. */
-		const char* deviceKey;
+        /** @brief	The device key used to authenticate the device. */
+        const char* deviceKey;
 
-		/** @brief	The device SAS used to authenticate the device in place of using the device key. */
-		const char* deviceSasToken;
+        /** @brief	The device SAS used to authenticate the device in place of using the device key. */
+        const char* deviceSasToken;
 
-	} IOTHUB_DEVICE_CONFIG;
+    } IOTHUB_DEVICE_CONFIG;
 
     typedef STRING_HANDLE (*pfIoTHubTransport_GetHostname)(TRANSPORT_LL_HANDLE handle);
-	typedef IOTHUB_CLIENT_RESULT(*pfIoTHubTransport_SetOption)(TRANSPORT_LL_HANDLE handle, const char *optionName, const void* value);
-	typedef TRANSPORT_LL_HANDLE(*pfIoTHubTransport_Create)(const IOTHUBTRANSPORT_CONFIG* config);
-	typedef void (*pfIoTHubTransport_Destroy)(TRANSPORT_LL_HANDLE handle);
-	typedef IOTHUB_DEVICE_HANDLE(*pfIotHubTransport_Register)(TRANSPORT_LL_HANDLE handle, const IOTHUB_DEVICE_CONFIG* device, IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, PDLIST_ENTRY waitingToSend);
-	typedef void(*pfIotHubTransport_Unregister)(IOTHUB_DEVICE_HANDLE deviceHandle);
-	typedef int (*pfIoTHubTransport_Subscribe)(IOTHUB_DEVICE_HANDLE handle);
-	typedef void (*pfIoTHubTransport_Unsubscribe)(IOTHUB_DEVICE_HANDLE handle);
-	typedef void (*pfIoTHubTransport_DoWork)(TRANSPORT_LL_HANDLE handle, IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle);
-	typedef IOTHUB_CLIENT_RESULT(*pfIoTHubTransport_GetSendStatus)(IOTHUB_DEVICE_HANDLE handle, IOTHUB_CLIENT_STATUS *iotHubClientStatus);
+    typedef IOTHUB_CLIENT_RESULT(*pfIoTHubTransport_SetOption)(TRANSPORT_LL_HANDLE handle, const char *optionName, const void* value);
+    typedef TRANSPORT_LL_HANDLE(*pfIoTHubTransport_Create)(const IOTHUBTRANSPORT_CONFIG* config);
+    typedef void (*pfIoTHubTransport_Destroy)(TRANSPORT_LL_HANDLE handle);
+    typedef IOTHUB_DEVICE_HANDLE(*pfIotHubTransport_Register)(TRANSPORT_LL_HANDLE handle, const IOTHUB_DEVICE_CONFIG* device, IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, PDLIST_ENTRY waitingToSend);
+    typedef void(*pfIotHubTransport_Unregister)(IOTHUB_DEVICE_HANDLE deviceHandle);
+    typedef int (*pfIoTHubTransport_Subscribe)(IOTHUB_DEVICE_HANDLE handle);
+    typedef void (*pfIoTHubTransport_Unsubscribe)(IOTHUB_DEVICE_HANDLE handle);
+    typedef void (*pfIoTHubTransport_DoWork)(TRANSPORT_LL_HANDLE handle, IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle);
+    typedef int(*pfIoTHubTransport_SetRetryPolicy)(TRANSPORT_LL_HANDLE handle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitInSeconds);
+    typedef IOTHUB_CLIENT_RESULT(*pfIoTHubTransport_GetSendStatus)(IOTHUB_DEVICE_HANDLE handle, IOTHUB_CLIENT_STATUS *iotHubClientStatus);
+    typedef int (*pfIoTHubTransport_Subscribe_DeviceTwin)(IOTHUB_DEVICE_HANDLE handle);
+    typedef void (*pfIoTHubTransport_Unsubscribe_DeviceTwin)(IOTHUB_DEVICE_HANDLE handle);
+    typedef IOTHUB_PROCESS_ITEM_RESULT(*pfIoTHubTransport_ProcessItem)(TRANSPORT_LL_HANDLE handle, IOTHUB_IDENTITY_TYPE item_type, IOTHUB_IDENTITY_INFO* iothub_item);
+    typedef int(*pfIoTHubTransport_Subscribe_DeviceMethod)(IOTHUB_DEVICE_HANDLE handle);
+    typedef void(*pfIoTHubTransport_Unsubscribe_DeviceMethod)(IOTHUB_DEVICE_HANDLE handle);
 
-#define TRANSPORT_PROVIDER_FIELDS                            \
-pfIoTHubTransport_GetHostname IoTHubTransport_GetHostname;   \
-pfIoTHubTransport_SetOption IoTHubTransport_SetOption;       \
-pfIoTHubTransport_Create IoTHubTransport_Create;             \
-pfIoTHubTransport_Destroy IoTHubTransport_Destroy;           \
-pfIotHubTransport_Register IoTHubTransport_Register;         \
-pfIotHubTransport_Unregister IoTHubTransport_Unregister;     \
-pfIoTHubTransport_Subscribe IoTHubTransport_Subscribe;       \
-pfIoTHubTransport_Unsubscribe IoTHubTransport_Unsubscribe;   \
-pfIoTHubTransport_DoWork IoTHubTransport_DoWork;             \
-pfIoTHubTransport_GetSendStatus IoTHubTransport_GetSendStatus  /*there's an intentional missing ; on this line*/ \
+#define TRANSPORT_PROVIDER_FIELDS                                                   \
+pfIoTHubTransport_Subscribe_DeviceMethod IoTHubTransport_Subscribe_DeviceMethod;    \
+pfIoTHubTransport_Unsubscribe_DeviceMethod IoTHubTransport_Unsubscribe_DeviceMethod;\
+pfIoTHubTransport_Subscribe_DeviceTwin IoTHubTransport_Subscribe_DeviceTwin;        \
+pfIoTHubTransport_Unsubscribe_DeviceTwin IoTHubTransport_Unsubscribe_DeviceTwin;    \
+pfIoTHubTransport_ProcessItem IoTHubTransport_ProcessItem;                          \
+pfIoTHubTransport_GetHostname IoTHubTransport_GetHostname;                          \
+pfIoTHubTransport_SetOption IoTHubTransport_SetOption;                              \
+pfIoTHubTransport_Create IoTHubTransport_Create;                                    \
+pfIoTHubTransport_Destroy IoTHubTransport_Destroy;                                  \
+pfIotHubTransport_Register IoTHubTransport_Register;                                \
+pfIotHubTransport_Unregister IoTHubTransport_Unregister;                            \
+pfIoTHubTransport_Subscribe IoTHubTransport_Subscribe;                              \
+pfIoTHubTransport_Unsubscribe IoTHubTransport_Unsubscribe;                          \
+pfIoTHubTransport_DoWork IoTHubTransport_DoWork;                                    \
+pfIoTHubTransport_SetRetryPolicy IoTHubTransport_SetRetryPolicy;                    \
+pfIoTHubTransport_GetSendStatus IoTHubTransport_GetSendStatus  /*there's an intentional missing ; on this line*/
 
-	struct TRANSPORT_PROVIDER_TAG
-	{
-		TRANSPORT_PROVIDER_FIELDS;
-	};
+    struct TRANSPORT_PROVIDER_TAG
+    {
+        TRANSPORT_PROVIDER_FIELDS;
+    };
 
 #ifdef __cplusplus
 }
--- a/iothubtransport.c	Thu Oct 20 17:07:32 2016 -0700
+++ b/iothubtransport.c	Wed Nov 16 21:37:53 2016 -0800
@@ -35,7 +35,7 @@
 
 TRANSPORT_HANDLE  IoTHubTransport_Create(IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol, const char* iotHubName, const char* iotHubSuffix)
 {
-	TRANSPORT_HANDLE_DATA * result;
+	TRANSPORT_HANDLE_DATA *result;
 
 	if (protocol == NULL || iotHubName == NULL || iotHubSuffix == NULL)
 	{
@@ -118,6 +118,7 @@
 						result->IoTHubTransport_Subscribe = transportProtocol->IoTHubTransport_Subscribe;
 						result->IoTHubTransport_Unsubscribe = transportProtocol->IoTHubTransport_Unsubscribe;
 						result->IoTHubTransport_DoWork = transportProtocol->IoTHubTransport_DoWork;
+                        result->IoTHubTransport_SetRetryPolicy = transportProtocol->IoTHubTransport_SetRetryPolicy;
 						result->IoTHubTransport_GetSendStatus = transportProtocol->IoTHubTransport_GetSendStatus;
 					}
 				}