title: Semantic of Connection Status in the Azure IoT C SDK
body: <p>I am trying to understand the specific connection and error states of the Azure IoT C SDK.</p>
  
  <p>I can register with <code>IoTHubClient_SetConnectionStatusCallback</code> for the callback in order to receive the <code>IOTHUB_CLIENT_CONNECTION_STATUS</code> and the <code>IOTHUB_CLIENT_CONNECTION_STATUS_REASON</code>. </p>
  
  <p>The value for the first one are <code>IOTHUB_CLIENT_CONNECTION_AUTHENTICATED</code> and <code>IOTHUB_CLIENT_CONNECTION_UNAUTHENTICATED</code>, which I assume simply means "connected" and "not connected". The reason is more interesting however:</p>
  
  <ul>
  <li><code>IOTHUB_CLIENT_CONNECTION_EXPIRED_SAS_TOKEN</code></li>
  <li><code>IOTHUB_CLIENT_CONNECTION_DEVICE_DISABLED</code></li>
  <li><code>IOTHUB_CLIENT_CONNECTION_BAD_CREDENTIAL</code></li>
  <li><code>IOTHUB_CLIENT_CONNECTION_RETRY_EXPIRED</code></li>
  <li><code>IOTHUB_CLIENT_CONNECTION_NO_NETWORK</code></li>
  <li><code>IOTHUB_CLIENT_CONNECTION_COMMUNICATION_ERROR</code></li>
  <li><code>IOTHUB_CLIENT_CONNECTION_OK</code></li>
  </ul>
  
  <p>So my first question is: What are the semantics for the respective reasons? When do they occur? What does the communication error entail? The error is so generic it could simply mean "any error we didn't want to specify explicitely".</p>
  
  <p>My second question goes beyond that. I am trying to use X.509 certificates. However, due to certain requirements I may have certificates that are no longer valid or deleted device ids. Can I somehow distinguish those cases by using the available reasons? When I tried to connect with a non-existing Id I simply got <code>IOTHUB_CLIENT_CONNECTION_COMMUNICATION_ERROR</code>. From my point of view, I no longer need to try to connect to the IoT Hub, since my device doesn't exist. But a communication error may be anything at all. The same issue appeared when I tried to connect with an invalid certificate or private key.</p>
  
  <p>Every time I try I simply get the errors:</p>
  
  <pre><code>Error: Time:Thu May 25 12:04:00 2017 File:~/azure-iot-sdk-c/iothub_client/src/iothubtransport_amqp_messenger.c Func:process_state_changes Line:1563 messagesender reported unexpected state 4 while messenger is starting
  Error: Time:Thu May 25 12:04:00 2017 File:~/azure-iot-sdk-c/iothub_client/src/iothubtransport_amqp_device.c Func:device_do_work Line:848 Device 'MyDevice' messenger failed to be started (messenger got into error state)
  </code></pre>
  
  <p>From those information I cannot determine when to connect or reconnect.</p>