Google Cloud IoT device SDK for embedded C  1.0.2

This is a reference for the Board Support Package (BSP) and its components. The BSP is a set of well-defined functions that the SDK invokes to interact with hardware-specific drivers and routines. The functions run on POSIX platforms by default. To customize the BSP for new devices, see the porting guide.

Function summary

The following tables list the hardware-specific drivers and routines you can define to implement MQTT with TLS.


Function Description
iotc_bsp_time_init() Initializes the platform-specific timekeeping requirements.
iotc_bsp_time_getcurrenttime_milliseconds() Gets the milliseconds since Epoch.
iotc_bsp_time_getcurrenttime_seconds() Gets the seconds since Epoch.
iotc_bsp_time_getmonotonictime_milliseconds() Gets the monotonic time in milliseconds.

Generating random numbers

Function Description
iotc_bsp_rng_get() Generates and returns a random, 32-bit integer.
iotc_bsp_rng_init() Initializes the platform-specific RNG requirements.
iotc_bsp_rng_shutdown() Shuts down the RNG and frees all of the resources from initializing and generating random numbers.

Generating JWTs

Function Description
iotc_bsp_base64_encode_urlsafe() Encodes a string as a URL-safe, base64 string by replacing all URL-unsafe characters with a - (dash) or _ (underscore).
iotc_bsp_ecc() Generates an Elliptic Curve signature for a private key.
iotc_bsp_sha256() Generates a SHA256 cryptographic hash.

Managing files

Function Description
iotc_bsp_io_fs_open() Opens a file.
iotc_bsp_io_fs_read() Reads a file.
iotc_bsp_io_fs_stat() Gets the size of a file.
iotc_bsp_io_fs_write() Writes to a file.
iotc_bsp_io_fs_close() Closes a file and frees all of the resources from reading or writing to the file.
iotc_bsp_io_fs_remove() Deletes a file.

Managing TLS connections

Function Description
iotc_bsp_tls_init() Initializes a TLS library and creates a TLS context.
iotc_bsp_tls_connect() Starts a TLS handshake.
iotc_bsp_tls_pending() Gets the pending readable bytes.
iotc_bsp_tls_read() Decrypts MQTT messages.
iotc_bsp_tls_write() Encrypts MQTT messages.
iotc_bsp_tls_cleanup() Frees a TLS context from memory and deletes any associated data.

Managing platform memory

Function Description
iotc_bsp_mem_alloc() Allocates memory and returns a pointer to the allocated block.
iotc_bsp_mem_free() Frees a block of memory.
iotc_bsp_mem_realloc() Changes the size of a memory block and returns a pointer to the reallocated block.

Creating and managing sockets

Function Description
iotc_bsp_io_net_socket_connect() Creates a socket and connects it to an endpoint.
iotc_bsp_io_net_connection_check() Checks a socket connection status
iotc_bsp_io_net_read() Reads from a socket.
iotc_bsp_io_net_select() Checks a socket for scheduled read or write operations.
iotc_bsp_io_net_write() Writes to a socket.
iotc_bsp_io_net_close_socket() Closes a socket.


The POSIX BSP is in the src/bsp/platforms/posix directory. If you're customizing the BSP for a new device, you can refer to this implementation as an example.

TLS implementations

The SDK has turn-key mbedTLS and wolfSSL implementations. The default make target downloads and builds mbedTLS.

To use the turn-key wolfTLS implementation, specify IOTC_BSP_TLS=wolfssl in the main makefile.

The turn-key TLS libraries consist of customized iot_bsp_tls.h and iotc_bsp_crypto.h functions:

mbedTLS wolfSSL
src/bsp/tls/mbedtls/iotc_bsp_tls_mbedtls.c src/bsp/tls/wolfssl/iotc_bsp_tls_wolfssl.c
src/bsp/crypto/mbedtls/iotc_bsp_crypto.c src/bsp/crypto/wolfssl/iotc_bsp_crypto.c