Virgil IoT KIT
|
Cloud implementation. More...
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <virgil/iot/firmware/firmware.h>
#include <global-hal.h>
#include <virgil/iot/status_code/status_code.h>
Go to the source code of this file.
Data Structures | |
struct | vs_cloud_impl_t |
Cloud implementation. More... | |
struct | vs_cloud_mb_topics_list_t |
List of available topics. More... | |
struct | vs_cloud_message_bin_impl_t |
Message Bin implementation. More... | |
Macros | |
#define | VS_UPD_URL_STR_SIZE 200 |
Length of the update URL string. More... | |
Typedefs | |
typedef size_t(* | vs_fetch_handler_cb_t) (const char *contents, size_t chunksize, void *userdata) |
Implementation for data header download. More... | |
typedef vs_status_e(* | vs_cloud_http_request_func_t) (vs_cloud_http_method_e method, const char *url, const char *request_body, size_t request_body_size, char *out_data, vs_fetch_handler_cb_t fetch_handler, void *hander_data, size_t *in_out_size) |
Implementation for GET and POST requests processing. More... | |
typedef void(* | vs_cloud_mb_process_custom_topic_cb_t) (const char *topic, uint16_t topic_sz, const uint8_t *data, uint16_t length) |
Implementation for custom topics processing. More... | |
typedef void(* | vs_cloud_mb_process_default_topic_cb_t) (const uint8_t *url, uint16_t length) |
Implementation for default topics processing. More... | |
typedef vs_status_e(* | vs_cloud_mb_init_func_t) (const char *host, uint16_t port, const char *device_cert, const char *priv_key, const char *ca_cert) |
Message bin initialization. More... | |
typedef vs_status_e(* | vs_cloud_mb_connect_subscribe_func_t) (const char *client_id, const char *login, const char *password, const vs_cloud_mb_topics_list_t *topic_list, vs_cloud_mb_process_custom_topic_cb_t process_topic) |
Message bin connection and subscription to topic implementation. More... | |
typedef vs_status_e(* | vs_cloud_mb_process_func_t) (void) |
Message Bin processing. More... | |
Enumerations | |
enum | vs_cloud_http_method_e { VS_CLOUD_REQUEST_GET, VS_CLOUD_REQUEST_POST } |
enum | vs_cloud_mb_topic_id_t { VS_CLOUD_MB_TOPIC_TL, VS_CLOUD_MB_TOPIC_FW } |
Default topics. More... | |
Functions | |
vs_status_e | vs_cloud_fetch_and_store_fw_file (const char *fw_file_url, vs_firmware_header_t *fetched_header) |
Fetch and store Firmware. More... | |
vs_status_e | vs_cloud_fetch_and_store_tl (const char *tl_file_url) |
Fetch and store Trust List. More... | |
vs_status_e | vs_cloud_message_bin_register_default_handler (vs_cloud_mb_topic_id_t topic_id, vs_cloud_mb_process_default_topic_cb_t handler) |
Register processing handlers for default topics from vs_cloud_mb_topic_id_t enumeration. More... | |
vs_status_e | vs_cloud_message_bin_register_custom_handler (vs_cloud_mb_process_custom_topic_cb_t handler) |
Register custom handler implementation. More... | |
vs_status_e | vs_cloud_message_bin_process (void) |
Process message bin. More... | |
vs_status_e | vs_cloud_init (const vs_cloud_impl_t *cloud_impl, const vs_cloud_message_bin_impl_t *message_bin_impl, vs_secmodule_impl_t *secmodule) |
Initialize message bin. More... | |
Cloud implementation.
Cloud is a library that implements functions for communication with the Cloud and is used for the following :
Virgil IoT KIT provides MQTT implementation based on AWS IoT library.
Function vs_cloud_message_bin_process tries to obtain credentials for connecting to message bin broker from thing service using vs_cloud_http_request_func_t and connect to the broker using vs_cloud_mb_connect_subscribe_func_t. Then it waits for new messages, periodically calling vs_cloud_mb_process_func_t. User can register own handlers for events of new firmware or trust list by calling vs_cloud_message_bin_register_default_handler or custom handler for raw data processing from some topics by calling vs_cloud_message_bin_register_custom_handler. Cloud module uses provision and firmware modules, which must be initialized before.
Here you can see an example of Cloud module initialization :
You can use vs_curl_http_impl() for cloud_impl, vs_aws_message_bin_impl() for message_bin_impl, vs_soft_secmodule_impl() for secmodule_impl.
fw_topic_process receives an URL that can be used to fetch a new version of Firmware. See firmware_usage for details.
Here you can see an example of Cloud library usage:
#define VS_UPD_URL_STR_SIZE 200 |
Length of the update URL string.
typedef vs_status_e(* vs_cloud_http_request_func_t) (vs_cloud_http_method_e method, const char *url, const char *request_body, size_t request_body_size, char *out_data, vs_fetch_handler_cb_t fetch_handler, void *hander_data, size_t *in_out_size) |
Implementation for GET and POST requests processing.
This function implementation loads requested data and stores it in the out_data output buffer.
[in] | method | HTTP method, which will be performed |
[in] | url | URL for data download. Must not be NULL. |
[in] | request_body | The body of the POST request. |
[in] | request_body_size | The size of the POST request body. |
[out] | out_data | Output buffer to store processed data if fetch_handler has not been specified. Must not be NULL. |
[in] | fetch_handler | Implementation to process information that has been downloaded. If NULL, default processing will be used. |
[in] | fetch_hander_data | Context from fetch_handler . userdata parameter. |
[in,out] | in_out_size | Data size storage. Must not be NULL. |
typedef vs_status_e(* vs_cloud_mb_connect_subscribe_func_t) (const char *client_id, const char *login, const char *password, const vs_cloud_mb_topics_list_t *topic_list, vs_cloud_mb_process_custom_topic_cb_t process_topic) |
Message bin connection and subscription to topic implementation.
This implementation connects to the message bin broker and subscribes to topics. vs_aws_message_bin_impl() returns vs_cloud_message_bin_impl_t structure with default implementation provided by Virgil IoT KIT library. You can analyze function which connect_subscribe member points to for an example.
[in] | client_id | Client identifier. Cannot be NULL. |
[in] | login | Login. Cannot be NULL. |
[in] | password | Password. Cannot be NULL. |
[in] | topic_list | Pointer to the list of topics. Cannot be NULL. |
[in] | process_topic | Implementation for topics processing. Cannot be NULL. |
typedef vs_status_e(* vs_cloud_mb_init_func_t) (const char *host, uint16_t port, const char *device_cert, const char *priv_key, const char *ca_cert) |
Message bin initialization.
This implementation initializes MQTT with specified URL and certificates. vs_aws_message_bin_impl() returns vs_cloud_message_bin_impl_t structure with default implementation provided by Virgil IoT KIT library. You can analyze function which init member points to for an example.
[in] | host | Host URL. Must not be NULL. |
[in] | port | Port for host access. |
[in] | device_cert | Device certificate to be send to the broker. |
[in] | priv_key | Device private key. |
[in] | ca_cert | Broker's certificate. Must not be NULL. |
typedef void(* vs_cloud_mb_process_custom_topic_cb_t) (const char *topic, uint16_t topic_sz, const uint8_t *data, uint16_t length) |
Implementation for custom topics processing.
This implementation processes messages from topics as raw data.
[in] | topic | Topic name. Cannot be NULL. |
[in] | topic_sz | Topic name size. Cannot be zero. |
[in] | data | Topic data. Cannot be NULL |
[in] | length | Topic data size. Cannot be zero. |
typedef void(* vs_cloud_mb_process_default_topic_cb_t) (const uint8_t *url, uint16_t length) |
Implementation for default topics processing.
Virgil IoT KIT preprocesses topics from vs_cloud_mb_topic_id_t enumeration. It calls this function when receives a notification about a new version of Trust List or Firmware to load data for this topic.
[in] | url | URL where user can fetch a new version of file. |
[in] | length | Topic URL size. |
typedef vs_status_e(* vs_cloud_mb_process_func_t) (void) |
Message Bin processing.
Implementation for message bin processing. vs_aws_message_bin_impl() returns vs_cloud_message_bin_impl_t structure with default implementation provided by Virgil IoT KIT library. You can analyze function which process member points to for an example.
typedef size_t(* vs_fetch_handler_cb_t) (const char *contents, size_t chunksize, void *userdata) |
Implementation for data header download.
This function implementation stores loaded handler in internal buffers.
[in] | contents | Input data. Must not be NULL. |
[in] | chunksize | Input data size. Must not be zero. |
[in,out] | userdata | Data specific context. Must not be NULL. |
Default topics.
This is the list of default topics processed by vs_cloud_mb_process_default_topic_cb_t() implementation.
Enumerator | |
---|---|
VS_CLOUD_MB_TOPIC_TL | Trust List. |
VS_CLOUD_MB_TOPIC_FW | Firmware. |
vs_status_e vs_cloud_fetch_and_store_fw_file | ( | const char * | fw_file_url, |
vs_firmware_header_t * | fetched_header | ||
) |
Fetch and store Firmware.
Fetches Firmware and stores it in internal storage.
[in] | fw_file_url | Firmware URL to fetch. Must not be NULL. |
[out] | fetched_header |
vs_status_e vs_cloud_fetch_and_store_tl | ( | const char * | tl_file_url | ) |
Fetch and store Trust List.
Fetches Trust List and stores it in internal storage.
[in] | tl_file_url | Trust List URL to fetch. Must not be NULL. |
vs_status_e vs_cloud_init | ( | const vs_cloud_impl_t * | cloud_impl, |
const vs_cloud_message_bin_impl_t * | message_bin_impl, | ||
vs_secmodule_impl_t * | secmodule | ||
) |
Initialize message bin.
[in] | cloud_impl | Cloud implementation. Must not be NULL. |
[in] | message_bin_impl | Message bin implementation. You can use default implementation returned by vs_aws_message_bin_impl(). Must not be NULL. |
[in] | secmodule | Security module implementation. You can use default implementation returned by vs_soft_secmodule_impl(). Must not be NULL. |
vs_status_e vs_cloud_message_bin_process | ( | void | ) |
Process message bin.
Initializes message bin if needed and processes protocol. Normally this function is called in the MQTT processing infinite loop.
vs_status_e vs_cloud_message_bin_register_custom_handler | ( | vs_cloud_mb_process_custom_topic_cb_t | handler | ) |
Register custom handler implementation.
Registers custom topics processing. You can use vs_cloud_message_bin_register_default_handler() if it is enough for your default topics processing.
[in] | handler | Custom topics processing handler. Must not be NULL. |
vs_status_e vs_cloud_message_bin_register_default_handler | ( | vs_cloud_mb_topic_id_t | topic_id, |
vs_cloud_mb_process_default_topic_cb_t | handler | ||
) |
Register processing handlers for default topics from vs_cloud_mb_topic_id_t enumeration.
Registers topic processing handlers.
[in] | topic_id | Topic identifier. |
[in] | handler | Topic processing implementation. Must not be NULL. |