SEcube
SEcube Open Source Library - Device
Data Structures | Typedefs | Enumerations | Functions
se3_proto.c File Reference

USB read/write handlers. More...

#include "se3_proto.h"
#include <se3_sdio.h>

Data Structures

struct  s3_storage_range_
 SDIO read/write request buffer context. More...
 

Typedefs

typedef struct s3_storage_range_ s3_storage_range
 SDIO read/write request buffer context.
 

Enumerations

enum  s3_storage_range_direction { range_write, range_read }
 

Functions

static bool block_is_magic (const uint8_t *buf)
 Check if block contains the magic sequence. More...
 
static int find_magic_index (uint32_t block)
 Check if block belongs to the special protocol file. More...
 
static int32_t se3_storage_range_add (s3_storage_range *range, uint8_t lun, uint8_t *buf, uint32_t block, enum s3_storage_range_direction direction)
 add request to SDIO read/write buffer More...
 
void se3_proto_request_reset ()
 Reset protocol request buffer. More...
 
static void handle_req_recv (int index, const uint8_t *blockdata)
 Handle request for incoming protocol block. More...
 
int32_t se3_proto_recv (uint8_t lun, const uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
 USB data receive handler. More...
 
static void handle_resp_send (int index, uint8_t *blockdata)
 Handle request for outgoing protocol block. More...
 
int32_t se3_proto_send (uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
 USB data send handler. More...
 

Detailed Description

USB read/write handlers.

Author
Nicola Ferri

Function Documentation

static bool block_is_magic ( const uint8_t *  buf)
static

Check if block contains the magic sequence.

Parameters
bufpointer to block data
Returns
true if the block contains the magic sequence, otherwise false

Check if a block of data contains the magic sequence, used to initialize the special protocol file.

static int find_magic_index ( uint32_t  block)
static

Check if block belongs to the special protocol file.

Parameters
blockblock number
Returns
the index of the corresponding protocol file block, or -1 if the block does not belong to the protocol file.

The special protocol file is made up of multiple blocks. Each block is mapped to a block on the physical storage

static void handle_req_recv ( int  index,
const uint8_t *  blockdata 
)
static

Handle request for incoming protocol block.

Parameters
indexindex of block in the special protocol file
blockdatadata

Handle a single block belonging to a protocol request. The data is stored in the request buffer. As soon as the request data is received completely, the device will start processing the request

static void handle_resp_send ( int  index,
uint8_t *  blockdata 
)
static

Handle request for outgoing protocol block.

Parameters
indexindex of block in the special protocol file
blockdataoutput data

Output a single block of a protocol response. If the response is ready, the data is taken from the response buffer. Otherwise the 'not ready' state is returned.

int32_t se3_proto_recv ( uint8_t  lun,
const uint8_t *  buf,
uint32_t  blk_addr,
uint16_t  blk_len 
)

USB data receive handler.

SEcube API requests are filtered and data is stored in the request buffer. The function also takes care of the initialization of the special protocol file. Other requests are passed to the SDIO interface.

void se3_proto_request_reset ( )

Reset protocol request buffer.

Reset the protocol request buffer, making the device ready for a new request.

int32_t se3_proto_send ( uint8_t  lun,
uint8_t *  buf,
uint32_t  blk_addr,
uint16_t  blk_len 
)

USB data send handler.

SEcube API requests are filtered and data is sent from the response buffer Other requests are passed to the SDIO interface.

static int32_t se3_storage_range_add ( s3_storage_range range,
uint8_t  lun,
uint8_t *  buf,
uint32_t  block,
enum s3_storage_range_direction  direction 
)
static

add request to SDIO read/write buffer

Parameters
rangecontext; the count field must be initialized to zero on first usage
lunparameter from USB handler
bufpointer to request data
blockrequest block index
directionread or write

Contiguous requests are processed with a single call to the SDIO interface, as soon as a non-contiguous request is added.