Virgil IoT KIT
Functions
snap.h File Reference

SNAP network interface calls. More...

#include <stdint.h>
#include <virgil/iot/protocols/snap/snap-structs.h>
#include <virgil/iot/status_code/status_code.h>

Go to the source code of this file.

Functions

vs_status_e vs_snap_init (vs_netif_t *default_netif, const vs_device_manufacture_id_t manufacturer_id, const vs_device_type_t device_type, const vs_device_serial_t device_serial, uint32_t device_roles)
 Init SNAP. More...
 
vs_status_e vs_snap_deinit ()
 Destroy SNAP. More...
 
const vs_device_manufacture_id_tvs_snap_device_manufacture (void)
 Return current manufacture ID. More...
 
const vs_device_type_tvs_snap_device_type (void)
 Return current device type. More...
 
const vs_device_serial_tvs_snap_device_serial (void)
 Return current device serial number. More...
 
uint32_t vs_snap_device_roles (void)
 Return device role. More...
 
const vs_netif_tvs_snap_default_netif (void)
 Return device network interface. More...
 
vs_status_e vs_snap_send (const vs_netif_t *netif, const uint8_t *data, uint16_t data_sz)
 Send SNAP message. More...
 
vs_status_e vs_snap_register_service (const vs_snap_service_t *service)
 Register SNAP service. More...
 
vs_status_e vs_snap_mac_addr (const vs_netif_t *netif, vs_mac_addr_t *mac_addr)
 MAC address. More...
 
const vs_mac_addr_tvs_snap_broadcast_mac (void)
 Return MAC address. More...
 
vs_status_e vs_snap_send_request (const vs_netif_t *netif, const vs_mac_addr_t *mac, vs_snap_service_id_t service_id, vs_snap_element_t element_id, const uint8_t *data, uint16_t data_sz)
 Prepare and send SNAP message. More...
 
vs_snap_stat_t vs_snap_get_statistics (void)
 Return SNAP statistics. More...
 

Detailed Description

SNAP network interface calls.

Secure Network Adjustable Protocol is used as transport layer for network communication. There are several layers provided by Virgil IoT SDK that use this interface :

Warning
User has to provide network interface for vs_snap_init call. As UDP broadcast example user can use c-implementation tool.

User can add his own protocols base on SNAP. It is necessary to provide service callbacks by filling vs_snap_service_t structure and register service by vs_snap_register_service call.

Function Documentation

◆ vs_snap_broadcast_mac()

const vs_mac_addr_t* vs_snap_broadcast_mac ( void  )

Return MAC address.

Returns
vs_mac_addr_t MAC address.

◆ vs_snap_default_netif()

const vs_netif_t* vs_snap_default_netif ( void  )

Return device network interface.

Returns
vs_netif_t Device network interface. Cannot be NULL.

◆ vs_snap_deinit()

vs_status_e vs_snap_deinit ( )

Destroy SNAP.

Uses deinit call from vs_snap_service_t structure for each SNAP registered service and deinit call from vs_netif_t structure for network interface.

Returns
VS_CODE_OK in case of success or error code.

◆ vs_snap_device_manufacture()

const vs_device_manufacture_id_t* vs_snap_device_manufacture ( void  )

Return current manufacture ID.

Returns
vs_device_manufacture_id_t Manufacture ID. Cannot be NULL.

◆ vs_snap_device_roles()

uint32_t vs_snap_device_roles ( void  )

Return device role.

Returns
#Device roles mask formed from vs_device_serial_t elements.

◆ vs_snap_device_serial()

const vs_device_serial_t* vs_snap_device_serial ( void  )

Return current device serial number.

Returns
vs_device_serial_t Device serial number. Cannot be NULL.

◆ vs_snap_device_type()

const vs_device_type_t* vs_snap_device_type ( void  )

Return current device type.

Returns
vs_device_type_t Device type. Cannot be NULL.

◆ vs_snap_get_statistics()

vs_snap_stat_t vs_snap_get_statistics ( void  )

Return SNAP statistics.

Returns
vs_snap_stat_t Statistic data

◆ vs_snap_init()

vs_status_e vs_snap_init ( vs_netif_t default_netif,
const vs_device_manufacture_id_t  manufacturer_id,
const vs_device_type_t  device_type,
const vs_device_serial_t  device_serial,
uint32_t  device_roles 
)

Init SNAP.

Initializes SNAP. Uses init call from vs_netif_t network interface. Must be called prior to any SNAP call.

Parameters
[in]default_netifDefault network interface. Must not be NULL.
[in]manufacturer_idManufacturer ID.
[in]device_typeDevice type.
[in]device_serialDevice serial number.
[in]device_rolesDevice roles. Mask formed from vs_snap_device_role_e element.
Returns
VS_CODE_OK in case of success or error code.

◆ vs_snap_mac_addr()

vs_status_e vs_snap_mac_addr ( const vs_netif_t netif,
vs_mac_addr_t mac_addr 
)

MAC address.

Returns mac_addr MAC address. Uses mac_addr call from vs_netif_t network interface.

Parameters
[in]netifSNAP service descriptor. Must not be NULL.
[out]mac_addrBuffer to store MAC address. Must not be NULL.
Returns
VS_CODE_OK in case of success or error code.

◆ vs_snap_register_service()

vs_status_e vs_snap_register_service ( const vs_snap_service_t service)

Register SNAP service.

Initializes SNAP service.

Parameters
[in]serviceSNAP service descriptor. Must not be NULL.
Returns
VS_CODE_OK in case of success or error code.

◆ vs_snap_send()

vs_status_e vs_snap_send ( const vs_netif_t netif,
const uint8_t *  data,
uint16_t  data_sz 
)

Send SNAP message.

Sends data message data_sz bytes length by using SNAP protocol specified by netif network interface. tx callback from vs_netif_t network interface is used.

Parameters
[in]netifNetwork interface. If NULL, default network interface specified by default_netif parameter for vs_snap_init call is used.
[in]dataData buffer to be send. Must not be NULL.
[in]data_szData size in bytes to be send. Must not be zero.
Returns
VS_CODE_OK in case of success or error code.

◆ vs_snap_send_request()

vs_status_e vs_snap_send_request ( const vs_netif_t netif,
const vs_mac_addr_t mac,
vs_snap_service_id_t  service_id,
vs_snap_element_t  element_id,
const uint8_t *  data,
uint16_t  data_sz 
)

Prepare and send SNAP message.

Sends data message data_sz bytes length by using element_ID element of service_id SNAP service to mac device by netif network interface.

Parameters
[in]netifNetwork interface. If NULL, default network interface specified by default_netif parameter for vs_snap_init call is used.
[in]macMAC address. If NULL, broadcast MAC address is used.
[in]service_idService ID registered by vs_snap_register_service call.
[in]element_idElement ID of service_id.
[in]dataData buffer to be send. Must not be NULL.
[in]data_szData size in bytes to be send. Must not be zero.
Returns
VS_CODE_OK in case of success or error code.