VitroIO SDK
Software development kit for Vitro Shard.
Loading...
Searching...
No Matches
iot-block.h
Go to the documentation of this file.
1#ifndef IOT_BLOCK_H
2#define IOT_BLOCK_H
3
7
8
9#define AES_BLOCK_SIZE 16
10
11#define AES_IV_LEN 16
12
17#define PARAMETER_ID_SIZE 2
18
23#define NODE_ID_SIZE 9
24
29#define TIMESTAMP_SIZE 4
30
35#define SHA256_DIGEST_SIZE 32
36
41#define ECDSA_SIGNATURE_SIZE 64
42
47#define METADATA_SIZE (PARAMETER_ID_SIZE + NODE_ID_SIZE + TIMESTAMP_SIZE + \
48 SHA256_DIGEST_SIZE + ECDSA_SIGNATURE_SIZE)
49
50#define MAX_BLOCK_SIZE (7 * 255)
51#define MAX_PD_SIZE (MAX_BLOCK_SIZE - METADATA_SIZE)
52
53#define DATA_BLOB_SIZE AES_IV_LEN + DATA_TO_ENCRYPT_SIZE
54#define CAN_DATA_SIZE 147
55
56namespace vitroio
57{
58
59namespace sdk
60{
75class IoTBlock {
76public:
77
95 struct __attribute__((packed)) Frame
96 {
97 uint16_t parameterID;
98 uint8_t nodeID[NODE_ID_SIZE];
99 uint32_t timestamp;
100 uint8_t blob[MAX_PD_SIZE];
101 uint8_t digest[SHA256_DIGEST_SIZE];
102 uint8_t signature[ECDSA_SIGNATURE_SIZE];
103 };
104
109 typedef enum{
110 SIZE_S = 16,
111 SIZE_M = 128,
112 SIZE_L = 512,
113 SIZE_XL = 1024
115
122
132 int make(uint32_t data, uint32_t parameter);
133
143 int make(void* data, size_t dataLen, uint32_t parameter);
144
155 int make(void* data, IoTBlock_Sizes_t size, uint32_t parameter);
156
162 void send();
163
164
170 Frame* get_frame();
171
178
183 void print();
184
190 uint32_t get_blob_size();
191
192private:
193 Transport_layer* comm_port;
194 uint32_t frameSize;
195 uint32_t blobSize;
196
197 int create_blob(const uint8_t* plaintext, uint16_t plaintext_len, uint8_t* blob);
198};
202} // namespace sdk
203
204} // namespace vitroio
205
206
207
208#endif // IOT_BLOCK_H
Class is an API for creating and sending IoT Blocks.
Definition: iot-block.h:75
void print()
Prints whole Iot Block data.
uint8_t * get_frame_as_array()
Return pointer to uint8_t array of CAN_DATA_SIZE size. The array contains whole IoT block.
IoTBlock_Sizes_t
IoTBlock predefined sizes.
Definition: iot-block.h:109
@ SIZE_S
Definition: iot-block.h:110
@ SIZE_M
Definition: iot-block.h:111
@ SIZE_XL
Definition: iot-block.h:113
@ SIZE_L
Definition: iot-block.h:112
Frame * get_frame()
Return pointer to Frame structure. The structure contains whole IoT block.
int make(void *data, size_t dataLen, uint32_t parameter)
Prepare IoT block consisting of the Initialize Vector, encrypted data, parameter ID,...
uint32_t get_blob_size()
Get the blob size.
int make(uint32_t data, uint32_t parameter)
Prepare IoT block consisting of the Initialize Vector, encrypted data, parameter ID,...
IoTBlock(Transport_layer *comm)
Construct a new IoT Block object.
struct __attribute__((packed)) Frame
Structure contains node's data needed for encryption and final CAN frame.
Definition: iot-block.h:95
int make(void *data, IoTBlock_Sizes_t size, uint32_t parameter)
Prepare IoT block consisting of the Initialize Vector, encrypted data, parameter ID,...
void send()
Send IoT Block by chosen transport layer. Before sending, the Block has to be prepared with the make(...
Virtual class providing interface for communication interfaces.
Definition: transport_layer.h:29
#define NODE_ID_SIZE
Size of node Id field.
Definition: iot-block.h:23
#define MAX_PD_SIZE
Definition: iot-block.h:51
#define SHA256_DIGEST_SIZE
Size of SHA256 digest.
Definition: iot-block.h:35
#define ECDSA_SIGNATURE_SIZE
Size of ECDSA signature.
Definition: iot-block.h:41
The namespace contains all of components of vitro-shard-sdk and components based on the sdk....
Definition: can_layer.h:9