Virgil IoT KIT
cloud.h
Go to the documentation of this file.
1 // Copyright (C) 2015-2020 Virgil Security, Inc.
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // (1) Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // (2) Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in
14 // the documentation and/or other materials provided with the
15 // distribution.
16 //
17 // (3) Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
22 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 // DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 // POSSIBILITY OF SUCH DAMAGE.
32 //
33 // Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
34 
147 #ifndef VS_CLOUD_H
148 #define VS_CLOUD_H
149 
150 #include <stdint.h>
151 #include <stddef.h>
152 #include <stdbool.h>
154 #include <global-hal.h>
156 
157 #ifdef __cplusplus
158 namespace VirgilIoTKit {
159 extern "C" {
160 #endif
161 
163 #define VS_UPD_URL_STR_SIZE 200
164 
175 typedef size_t (*vs_fetch_handler_cb_t)(const char *contents, size_t chunksize, void *userdata);
176 
177 typedef enum {
181 
198  const char *url,
199  const char *request_body,
200  size_t request_body_size,
201  char *out_data,
202  vs_fetch_handler_cb_t fetch_handler,
203  void *hander_data,
204  size_t *in_out_size);
205 
207 typedef struct {
210 
221 vs_cloud_fetch_and_store_fw_file(const char *fw_file_url, vs_firmware_header_t *fetched_header);
222 
232 vs_cloud_fetch_and_store_tl(const char *tl_file_url);
233 
238 typedef struct {
239  char *topic_list;
240  uint16_t *topic_len_list;
241  size_t topic_count;
243 
248 typedef enum {
252 
262 typedef void (*vs_cloud_mb_process_custom_topic_cb_t)(const char *topic,
263  uint16_t topic_sz,
264  const uint8_t *data,
265  uint16_t length);
266 
276 typedef void (*vs_cloud_mb_process_default_topic_cb_t)(const uint8_t *url, uint16_t length);
277 
290 
302 
317 typedef vs_status_e (*vs_cloud_mb_init_func_t)(const char *host,
318  uint16_t port,
319  const char *device_cert,
320  const char *priv_key,
321  const char *ca_cert);
322 
337 typedef vs_status_e (*vs_cloud_mb_connect_subscribe_func_t)(const char *client_id,
338  const char *login,
339  const char *password,
340  const vs_cloud_mb_topics_list_t *topic_list,
342 
352 
354 typedef struct {
360 
370 
382 vs_cloud_init(const vs_cloud_impl_t *cloud_impl,
383  const vs_cloud_message_bin_impl_t *message_bin_impl,
384  vs_secmodule_impl_t *secmodule);
385 
386 #ifdef __cplusplus
387 } // extern "C"
388 } // namespace VirgilIoTKit
389 #endif
390 
391 #endif // VS_CLOUD_H
vs_cloud_message_bin_impl_t::init
vs_cloud_mb_init_func_t init
Message bin initialization.
Definition: cloud.h:355
vs_firmware_header_t
Firmware header.
Definition: firmware.h:240
VS_CLOUD_MB_TOPIC_FW
@ VS_CLOUD_MB_TOPIC_FW
Firmware.
Definition: cloud.h:250
VS_CLOUD_REQUEST_GET
@ VS_CLOUD_REQUEST_GET
HTTP request by GET method.
Definition: cloud.h:178
vs_cloud_impl_t
Cloud implementation.
Definition: cloud.h:207
vs_secmodule_impl_t
Security Module implementation.
Definition: secmodule.h:458
vs_cloud_mb_topic_id_t
vs_cloud_mb_topic_id_t
Default topics.
Definition: cloud.h:248
vs_status_e
vs_status_e
Status code.
Definition: status_code.h:77
vs_cloud_impl_t::http_request
vs_cloud_http_request_func_t http_request
GET and POST requests processing.
Definition: cloud.h:208
vs_cloud_init
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.
VS_CLOUD_MB_TOPIC_TL
@ VS_CLOUD_MB_TOPIC_TL
Trust List.
Definition: cloud.h:249
vs_cloud_http_method_e
vs_cloud_http_method_e
Definition: cloud.h:177
vs_cloud_message_bin_register_default_handler
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.
vs_cloud_mb_process_custom_topic_cb_t
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.
Definition: cloud.h:262
vs_cloud_message_bin_impl_t::process
vs_cloud_mb_process_func_t process
Message bin processing : listen incoming messages and executing implementation calls.
Definition: cloud.h:358
status_code.h
Status codes and macroses.
vs_cloud_message_bin_impl_t::connect_subscribe
vs_cloud_mb_connect_subscribe_func_t connect_subscribe
Message bin connection and topic subscribing.
Definition: cloud.h:356
vs_cloud_mb_connect_subscribe_func_t
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.
Definition: cloud.h:337
vs_cloud_message_bin_impl_t
Message Bin implementation.
Definition: cloud.h:354
vs_cloud_mb_init_func_t
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.
Definition: cloud.h:317
firmware.h
Firmware uploading/downloading and installation implementation.
vs_cloud_http_request_func_t
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.
Definition: cloud.h:197
vs_cloud_fetch_and_store_fw_file
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.
vs_cloud_fetch_and_store_tl
vs_status_e vs_cloud_fetch_and_store_tl(const char *tl_file_url)
Fetch and store Trust List.
vs_cloud_message_bin_register_custom_handler
vs_status_e vs_cloud_message_bin_register_custom_handler(vs_cloud_mb_process_custom_topic_cb_t handler)
Register custom handler implementation.
vs_cloud_mb_topics_list_t::topic_count
size_t topic_count
Topics amount for topic_list and topic_len_list.
Definition: cloud.h:241
vs_fetch_handler_cb_t
size_t(* vs_fetch_handler_cb_t)(const char *contents, size_t chunksize, void *userdata)
Implementation for data header download.
Definition: cloud.h:175
vs_cloud_mb_topics_list_t::topic_len_list
uint16_t * topic_len_list
List for each topis size.
Definition: cloud.h:240
vs_cloud_mb_topics_list_t
List of available topics.
Definition: cloud.h:238
vs_cloud_mb_process_func_t
vs_status_e(* vs_cloud_mb_process_func_t)(void)
Message Bin processing.
Definition: cloud.h:351
VS_CLOUD_REQUEST_POST
@ VS_CLOUD_REQUEST_POST
HTTP request by POST method.
Definition: cloud.h:179
vs_cloud_mb_topics_list_t::topic_list
char * topic_list
Text string with all topics.
Definition: cloud.h:239
vs_cloud_message_bin_process
vs_status_e vs_cloud_message_bin_process(void)
Process message bin.
vs_cloud_mb_process_default_topic_cb_t
void(* vs_cloud_mb_process_default_topic_cb_t)(const uint8_t *url, uint16_t length)
Implementation for default topics processing.
Definition: cloud.h:276