Simple serial protocol for side-channel analysis. More...
#include <stddef.h>
#include <stdint.h>
#include "sw/device/lib/base/status.h"
#include "sw/device/lib/dif/dif_base.h"
#include "sw/device/lib/dif/dif_uart.h"
Go to the source code of this file.
Macros | |
#define | SS_CHECK(condition) |
Sends an error message over UART if condition evaluates to false. More... | |
#define | SS_CHECK_STATUS_OK(expr) |
Sends an error message over UART if the status represents an error. More... | |
#define | SS_CHECK_DIF_OK(dif_call) |
Sends an error message over UART if DIF does not return kDifOk. More... | |
Typedefs | |
typedef enum simple_serial_result | simple_serial_result_t |
Simple serial status codes. | |
typedef void(* | simple_serial_command_handler) (const uint8_t *, size_t) |
Command handlers must conform to this prototype. | |
Enumerations | |
enum | simple_serial_result { kSimpleSerialOk = 0 , kSimpleSerialError = 1 } |
Simple serial status codes. | |
Functions | |
void | simple_serial_init (const dif_uart_t *uart) |
Initializes the data structures used by simple serial. More... | |
simple_serial_result_t | simple_serial_register_handler (uint8_t cmd, simple_serial_command_handler handler) |
Registers a handler for a simple serial command. More... | |
void | simple_serial_process_packet (void) |
Waits for a simple serial packet and dispatches it to the appropriate handler. | |
void | simple_serial_send_packet (const uint8_t cmd, const uint8_t *data, size_t data_len) |
Sends a simple serial packet over UART. More... | |
void | simple_serial_send_status (uint8_t res) |
Sends a simple serial status packer over UART. More... | |
void | simple_serial_print_hex (const uint8_t *data, size_t data_len) |
Sends a buffer over UART as a hex encoded string. More... | |
Simple serial protocol for side-channel analysis.
This library implements simple serial protocol version 1.1 and provides built-in handlers for 'v' (version) and 's' (seed PRNG) commands. Clients can implement additional command by registering their handlers using simple_serial_register_handler()
. See https://wiki.newae.com/SimpleSerial for details on the protocol.
Definition in file simple_serial.h.
#define SS_CHECK | ( | condition | ) |
Sends an error message over UART if condition evaluates to false.
Definition at line 29 of file simple_serial.h.
#define SS_CHECK_DIF_OK | ( | dif_call | ) |
Sends an error message over UART if DIF does not return kDifOk.
Definition at line 53 of file simple_serial.h.
#define SS_CHECK_STATUS_OK | ( | expr | ) |
Sends an error message over UART if the status represents an error.
Definition at line 40 of file simple_serial.h.
void simple_serial_init | ( | const dif_uart_t * | uart | ) |
Initializes the data structures used by simple serial.
This function also registers handlers for 'v' (version) and 's' (seed PRNG) commands.
uart | Handle to an initialized UART device. |
Definition at line 192 of file simple_serial.c.
void simple_serial_print_hex | ( | const uint8_t * | data, |
size_t | data_len | ||
) |
Sends a buffer over UART as a hex encoded string.
data | A buffer |
data_len | Size of the buffer. |
Definition at line 239 of file simple_serial.c.
simple_serial_result_t simple_serial_register_handler | ( | uint8_t | cmd, |
simple_serial_command_handler | handler | ||
) |
Registers a handler for a simple serial command.
Clients cannot register handlers for 'v' (version) and 's' (seed PRNG) commands since these are handled by this library.
cmd | Simple serial command. |
handler | Command handler. |
Definition at line 204 of file simple_serial.c.
void simple_serial_send_packet | ( | const uint8_t | cmd, |
const uint8_t * | data, | ||
size_t | data_len | ||
) |
Sends a simple serial packet over UART.
cmd | Simple serial command. |
data | Packet payload. |
data_len | Payload length. |
Definition at line 225 of file simple_serial.c.
void simple_serial_send_status | ( | uint8_t | res | ) |
Sends a simple serial status packer over UART.
res | Status code. |
Definition at line 235 of file simple_serial.c.