Google Cloud IoT device SDK for embedded C  1.0.2
iotc_bsp_tls.h File Reference

Go to the source code of this file.

Data Structures

struct  iotc_bsp_tls_init_params_s
 

Typedefs

typedef enum iotc_bsp_tls_state_e iotc_bsp_tls_state_t
 
typedef struct iotc_bsp_tls_init_params_s iotc_bsp_tls_init_params_t
 
typedef void iotc_bsp_tls_context_t
 

Enumerations

enum  iotc_bsp_tls_state_e {
  IOTC_BSP_TLS_STATE_OK = 0, IOTC_BSP_TLS_STATE_INIT_ERROR = 1, IOTC_BSP_TLS_STATE_CERT_ERROR = 2, IOTC_BSP_TLS_STATE_CONNECT_ERROR = 3,
  IOTC_BSP_TLS_STATE_WANT_READ = 4, IOTC_BSP_TLS_STATE_WANT_WRITE = 5, IOTC_BSP_TLS_STATE_READ_ERROR = 6, IOTC_BSP_TLS_STATE_WRITE_ERROR = 7
}
 

Functions

iotc_bsp_tls_state_t iotc_bsp_tls_init (iotc_bsp_tls_context_t **tls_context, iotc_bsp_tls_init_params_t *init_params)
 
iotc_bsp_tls_state_t iotc_bsp_tls_cleanup (iotc_bsp_tls_context_t **tls_context)
 
iotc_bsp_tls_state_t iotc_bsp_tls_connect (iotc_bsp_tls_context_t *tls_context)
 
iotc_bsp_tls_state_t iotc_bsp_tls_read (iotc_bsp_tls_context_t *tls_context, uint8_t *data_ptr, size_t data_size, int *bytes_read)
 
int iotc_bsp_tls_pending (iotc_bsp_tls_context_t *tls_context)
 
iotc_bsp_tls_state_t iotc_bsp_tls_write (iotc_bsp_tls_context_t *tls_context, uint8_t *data_ptr, size_t data_size, int *bytes_written)
 
iotc_bsp_tls_state_t iotc_bsp_tls_recv_callback (char *buf, int sz, void *context, int *bytes_sent)
 
iotc_bsp_tls_state_t iotc_bsp_tls_send_callback (char *buf, int sz, void *context, int *bytes_sent)
 

Detailed Description

Implements Transport Layer Security (TLS).

All TLS functions are non-blocking.

Definition in file iotc_bsp_tls.h.

Typedef Documentation

◆ iotc_bsp_tls_context_t

The TLS context.

Definition at line 96 of file iotc_bsp_tls.h.

◆ iotc_bsp_tls_init_params_t

The TLS context parameters.

See also
iotc_bsp_tls_init_params_s

◆ iotc_bsp_tls_state_t

Enumeration Type Documentation

◆ iotc_bsp_tls_state_e

Enumerator
IOTC_BSP_TLS_STATE_OK 

The TLS function succeeded.

IOTC_BSP_TLS_STATE_INIT_ERROR 

Can't initialize TLS library.

IOTC_BSP_TLS_STATE_CERT_ERROR 

Can't validate CA certificate.

IOTC_BSP_TLS_STATE_CONNECT_ERROR 

Can't complete TLS handshake.

IOTC_BSP_TLS_STATE_WANT_READ 

TLS handshake is partially complete.

Run the function again to read the remaining data.

IOTC_BSP_TLS_STATE_WANT_WRITE 

TLS handshake is partially complete.

Run the function again to write the remaining data.

IOTC_BSP_TLS_STATE_READ_ERROR 

Can't read data.

IOTC_BSP_TLS_STATE_WRITE_ERROR 

Can't write data.

Definition at line 36 of file iotc_bsp_tls.h.

Function Documentation

◆ iotc_bsp_tls_cleanup()

iotc_bsp_tls_state_t iotc_bsp_tls_cleanup ( iotc_bsp_tls_context_t **  tls_context)

Frees a TLS context from memory and deletes any associated data.

Parameters
[out]tls_contextA pointer to the TLS context.
Return values
IOTC_BSP_TLS_STATE_OKTLS context successfully freed.

◆ iotc_bsp_tls_connect()

iotc_bsp_tls_state_t iotc_bsp_tls_connect ( iotc_bsp_tls_context_t tls_context)

Starts a TLS handshake.

Parameters
[out]tls_contextA pointer to the TLS context.

◆ iotc_bsp_tls_init()

iotc_bsp_tls_state_t iotc_bsp_tls_init ( iotc_bsp_tls_context_t **  tls_context,
iotc_bsp_tls_init_params_t init_params 
)

Initializes a TLS library and creates a TLS context.

The SDK calls the function and then deletes init_params, so store persistant data outside the function scope.

Parameters
[out]tls_contextA pointer to the TLS context.
[in]init_paramsThe TLS context parameters.

◆ iotc_bsp_tls_pending()

int iotc_bsp_tls_pending ( iotc_bsp_tls_context_t tls_context)

Gets the pending readable bytes.

Parameters
[out]tls_contextA pointer to the TLS context.

◆ iotc_bsp_tls_read()

iotc_bsp_tls_state_t iotc_bsp_tls_read ( iotc_bsp_tls_context_t tls_context,
uint8_t *  data_ptr,
size_t  data_size,
int *  bytes_read 
)

Reads data on a socket.

Parameters
[out]tls_contextA pointer to the TLS context.
[in]data_ptrA pointer to a buffer to store data that is read.
[in]data_sizeThe size, in bytes, of the buffer to which data_ptr points.
[out]bytes_readThe number of bytes read.

◆ iotc_bsp_tls_recv_callback()

iotc_bsp_tls_state_t iotc_bsp_tls_recv_callback ( char *  buf,
int  sz,
void *  context,
int *  bytes_sent 
)

Notifies the client application to read data on a socket. Implemented in the SDK; don't modify this function.

◆ iotc_bsp_tls_send_callback()

iotc_bsp_tls_state_t iotc_bsp_tls_send_callback ( char *  buf,
int  sz,
void *  context,
int *  bytes_sent 
)

Notifies the client application to write data to a socket. Implemented in the SDK; don't modify this function.

◆ iotc_bsp_tls_write()

iotc_bsp_tls_state_t iotc_bsp_tls_write ( iotc_bsp_tls_context_t tls_context,
uint8_t *  data_ptr,
size_t  data_size,
int *  bytes_written 
)

Write data to a socket.

Parameters
[out]tls_contextA pointer to the TLS context.
[in]data_ptrA pointer to a buffer with the data to be sent.
[in]data_sizeThe size, in bytes, of the buffer to which
data_ptr
points.
[out]bytes_writtenThe number of bytes written.