Virgil IoT KIT
Data Structures | Macros | Typedefs | Enumerations
snap-structs.h File Reference

SNAP structures. More...

#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <virgil/iot/provision/provision-structs.h>

Go to the source code of this file.

Data Structures

struct  vs_mac_addr_t
 MAC address. More...
 
struct  ethernet_header
 Ethernet header. More...
 
struct  vs_snap_header_t
 SNAP packet header. More...
 
struct  vs_snap_packet_t
 SNAP packet. More...
 
struct  vs_netif_t
 Network interface. More...
 
struct  vs_snap_service_t
 SNAP service descriptor. More...
 
struct  vs_snap_stat_t
 SNAP statistics. More...
 

Macros

#define ETH_ADDR_LEN   (6)
 
#define ETH_TYPE_LEN   (2)
 
#define ETH_CRC_LEN   (4)
 
#define ETH_HEADER_LEN   (ETH_ADDR_LEN + ETH_ADDR_LEN + ETH_TYPE_LEN)
 
#define ETH_MIN_LEN   (64)
 
#define ETH_MTU   (1500)
 
#define VS_ETHERTYPE_VIRGIL   (HTONS_IN_COMPILE_TIME(0xABCD))
 
#define VS_NETIF_PACKET_BUF_SIZE   (1024)
 

Typedefs

typedef uint16_t vs_snap_transaction_id_t
 SNAP transaction ID. More...
 
typedef uint32_t vs_snap_service_id_t
 SNAP service ID. More...
 
typedef uint32_t vs_snap_element_t
 SNAP element ID. More...
 
typedef vs_status_e(* vs_netif_rx_cb_t) (struct vs_netif_t *netif, const uint8_t *data, const uint16_t data_sz, const uint8_t **packet_data, uint16_t *packet_data_sz)
 Received data. More...
 
typedef vs_status_e(* vs_netif_process_cb_t) (struct vs_netif_t *netif, const uint8_t *data, const uint16_t data_sz)
 Preprocessed data. More...
 
typedef vs_status_e(* vs_netif_tx_t) (struct vs_netif_t *netif, const uint8_t *data, const uint16_t data_sz)
 Send data. More...
 
typedef vs_status_e(* vs_netif_mac_t) (const struct vs_netif_t *netif, struct vs_mac_addr_t *mac_addr)
 Get MAC address. More...
 
typedef vs_status_e(* vs_netif_init_t) (struct vs_netif_t *netif, const vs_netif_rx_cb_t rx_cb, const vs_netif_process_cb_t process_cb)
 Initializer. More...
 
typedef vs_status_e(* vs_netif_deinit_t) (struct vs_netif_t *netif)
 Destructor. More...
 
typedef vs_status_e(* vs_snap_service_request_processor_t) (const struct vs_netif_t *netif, vs_snap_element_t element_id, const uint8_t *request, const uint16_t request_sz, uint8_t *response, const uint16_t response_buf_sz, uint16_t *response_sz)
 SNAP Service Request Processor. More...
 
typedef vs_status_e(* vs_snap_service_response_processor_t) (const struct vs_netif_t *netif, vs_snap_element_t element_id, bool is_ack, const uint8_t *response, const uint16_t response_sz)
 SNAP Service Response Processor. More...
 
typedef vs_status_e(* vs_snap_service_periodical_processor_t) (void)
 SNAP Periodical data. More...
 
typedef vs_status_e(* vs_snap_service_deinit_t) (void)
 SNAP Service Destructor. More...
 

Enumerations

enum  vs_snap_device_role_e {
  VS_SNAP_DEV_GATEWAY = HTONL_IN_COMPILE_TIME(0x0001), VS_SNAP_DEV_THING = HTONL_IN_COMPILE_TIME(0x0002), VS_SNAP_DEV_CONTROL = HTONL_IN_COMPILE_TIME(0x0004), VS_SNAP_DEV_LOGGER = HTONL_IN_COMPILE_TIME(0x0008),
  VS_SNAP_DEV_SNIFFER = HTONL_IN_COMPILE_TIME(0x0010), VS_SNAP_DEV_DEBUGGER = HTONL_IN_COMPILE_TIME(0x0020), VS_SNAP_DEV_INITIALIZER = HTONL_IN_COMPILE_TIME(0x0040)
}
 Device roles. More...
 
enum  vs_snap_flags_e { VS_SNAP_FLAG_ACK = HTONL_IN_COMPILE_TIME(0x0001), VS_SNAP_FLAG_NACK = HTONL_IN_COMPILE_TIME(0x0002) }
 SNAP Flags. More...
 

Detailed Description

SNAP structures.

Macro Definition Documentation

◆ ETH_ADDR_LEN

#define ETH_ADDR_LEN   (6)

◆ ETH_CRC_LEN

#define ETH_CRC_LEN   (4)

◆ ETH_HEADER_LEN

#define ETH_HEADER_LEN   (ETH_ADDR_LEN + ETH_ADDR_LEN + ETH_TYPE_LEN)

◆ ETH_MIN_LEN

#define ETH_MIN_LEN   (64)

◆ ETH_MTU

#define ETH_MTU   (1500)

◆ ETH_TYPE_LEN

#define ETH_TYPE_LEN   (2)

◆ VS_ETHERTYPE_VIRGIL

#define VS_ETHERTYPE_VIRGIL   (HTONS_IN_COMPILE_TIME(0xABCD))

◆ VS_NETIF_PACKET_BUF_SIZE

#define VS_NETIF_PACKET_BUF_SIZE   (1024)

Typedef Documentation

◆ vs_netif_deinit_t

typedef vs_status_e(* vs_netif_deinit_t) (struct vs_netif_t *netif)

Destructor.

Callback for deinit member of vs_netif_t structure. This callback is used to destroy SNAP implementation. Called from vs_snap_deinit call.

Parameters
[in]netifvs_netif_t Network interface. Cannot be NULL.
Returns
VS_CODE_OK in case of success or error code.

◆ vs_netif_init_t

typedef vs_status_e(* vs_netif_init_t) (struct vs_netif_t *netif, const vs_netif_rx_cb_t rx_cb, const vs_netif_process_cb_t process_cb)

Initializer.

Callback for init member of vs_netif_t structure. This callback is used to initialize SNAP implementation. Called from vs_snap_init call.

Parameters
[in]netifvs_netif_t Network interface. Cannot be NULL.
[in]rx_cbvs_netif_rx_cb_t callback. Cannot be NULL.
[in]process_cbvs_netif_process_cb_t callback. Cannot be NULL.
Returns
VS_CODE_OK in case of success or error code.

◆ vs_netif_mac_t

typedef vs_status_e(* vs_netif_mac_t) (const struct vs_netif_t *netif, struct vs_mac_addr_t *mac_addr)

Get MAC address.

Callback for mac_addr member of vs_netif_t structure. This callback is used to receive current MAC address. Called from vs_snap_mac_addr call.

Parameters
[in]netifvs_netif_t Network interface. Cannot be NULL.
[out]mac_addrvs_mac_addr_t MAC address buffer. Cannot be NULL.
Returns
VS_CODE_OK in case of success or error code.

◆ vs_netif_process_cb_t

typedef vs_status_e(* vs_netif_process_cb_t) (struct vs_netif_t *netif, const uint8_t *data, const uint16_t data_sz)

Preprocessed data.

Callback for vs_netif_init_t function callback. This callback is used to preprocess data.

Parameters
[in]netifvs_netif_t Network interface. Cannot be NULL.
[in]dataData buffer. Cannot be NULL.
[in]data_szSize in bytes of data portion. Cannot be zero.
Returns
VS_CODE_OK in case of success or error code.

◆ vs_netif_rx_cb_t

typedef vs_status_e(* vs_netif_rx_cb_t) (struct vs_netif_t *netif, const uint8_t *data, const uint16_t data_sz, const uint8_t **packet_data, uint16_t *packet_data_sz)

Received data.

Callback for vs_netif_init_t function callback. This callback is used when new SNAP data has been loaded.

Parameters
[in]netifvs_netif_t Network interface. Cannot be NULL.
[in]dataReceived portion of data. Cannot be NULL.
[in]data_szSize in bytes of data portion. Cannot be zero.
[out]packet_dataBuffer to store packed data. Cannot be NULL.
[out]packet_data_szOutput buffer to store packet data size in bytes. Cannot be NULL.
Returns
VS_CODE_OK in case of success or error code.

◆ vs_netif_tx_t

typedef vs_status_e(* vs_netif_tx_t) (struct vs_netif_t *netif, const uint8_t *data, const uint16_t data_sz)

Send data.

Callback for tx member of vs_netif_t structure. This callback is used to send data. Called from vs_snap_send call.

Parameters
[in]netifvs_netif_t Network interface. Cannot be NULL.
[in]dataData buffer. Cannot be NULL.
[in]data_szSize in bytes of data portion. Cannot be zero.
Returns
VS_CODE_OK in case of success or error code.

◆ vs_snap_element_t

typedef uint32_t vs_snap_element_t

SNAP element ID.

Used by service to identify its request/process commands.

◆ vs_snap_service_deinit_t

typedef vs_status_e(* vs_snap_service_deinit_t) (void)

SNAP Service Destructor.

Callback for deinit member of vs_snap_service_t structure. This callback is called to destroy SNAP service.

Returns
VS_CODE_OK in case of success or error code.

◆ vs_snap_service_id_t

typedef uint32_t vs_snap_service_id_t

SNAP service ID.

Used to identify service. Library provides FLDT, INFO, PRVS services.

◆ vs_snap_service_periodical_processor_t

typedef vs_status_e(* vs_snap_service_periodical_processor_t) (void)

SNAP Periodical data.

Callback for periodical_process member of vs_snap_service_t structure. This callback is called when there is no input data. It can be used to send some statistical data as it is done for INFO service.

Returns
VS_CODE_OK in case of success or error code.

◆ vs_snap_service_request_processor_t

typedef vs_status_e(* vs_snap_service_request_processor_t) (const struct vs_netif_t *netif, vs_snap_element_t element_id, const uint8_t *request, const uint16_t request_sz, uint8_t *response, const uint16_t response_buf_sz, uint16_t *response_sz)

SNAP Service Request Processor.

Callback for request_process member of vs_snap_service_t structure. This callback is called to process SNAP service request and to prepare response if needed.

Parameters
[in]netifNetwork interface.
[in]element_idvs_snap_element_t service element. Normally this is command ID.
[in]requestRequest data buffer.
[in]request_szRequest data size.
[out]responseResponse output buffer.
[in]response_buf_szResponse output buffer size.
[out]response_szStored output data size. Must be not more than response_buf_size. Cannot be NULL.
Returns
VS_CODE_OK in case of success or error code.

◆ vs_snap_service_response_processor_t

typedef vs_status_e(* vs_snap_service_response_processor_t) (const struct vs_netif_t *netif, vs_snap_element_t element_id, bool is_ack, const uint8_t *response, const uint16_t response_sz)

SNAP Service Response Processor.

Callback for response_process member of vs_snap_service_t structure. This callback is called to process SNAP service response.

Parameters
[in]netifNetwork interface.
[in]element_idvs_snap_element_t service element. Normally this is command ID.
[in]is_ackBoolean flag indicating successful packet receiving
[in]responseResponse buffer.
[in]response_szResponse size.
Returns
VS_CODE_OK in case of success or error code.

◆ vs_snap_transaction_id_t

typedef uint16_t vs_snap_transaction_id_t

SNAP transaction ID.

Enumeration Type Documentation

◆ vs_snap_device_role_e

Device roles.

Enumeration with mask bits to describe device roles.

Enumerator
VS_SNAP_DEV_GATEWAY 

Gateway role.

VS_SNAP_DEV_THING 

Thing role.

VS_SNAP_DEV_CONTROL 

Control role.

VS_SNAP_DEV_LOGGER 

Logger role.

VS_SNAP_DEV_SNIFFER 

Sniffer role.

VS_SNAP_DEV_DEBUGGER 

Debugger role.

VS_SNAP_DEV_INITIALIZER 

Initializer role.

◆ vs_snap_flags_e

SNAP Flags.

Enumerator
VS_SNAP_FLAG_ACK 

Confirmation about receiving a correct packet.

VS_SNAP_FLAG_NACK 

Notification about rejecting a packet.