Commit b9273b04 authored by Lucas Russo's avatar Lucas Russo

sm_io/protocols/*/*_bsmp: restrict ops pointer access to inner class

parent 5127b1d7
......@@ -81,6 +81,8 @@ typedef struct _smpr_t smpr_t;
typedef struct _smpr_spi_t smpr_spi_t;
/* Opaque smpr_i2c_t structure */
typedef struct _smpr_i2c_t smpr_i2c_t;
/* Opaque smpr_bsmp_t structure */
typedef struct _smpr_bsmp_t smpr_bsmp_t;
/* Forward smch_err_e declaration enumeration */
typedef enum _smch_err_e smch_err_e;
......
......@@ -12,10 +12,7 @@
extern "C" {
#endif
/* For use by llio_t general structure */
extern const smpr_proto_ops_t smpr_proto_ops_bsmp;
/***************** SMPR proto BSMP methods ************************************/
/***************** SMPR proto BSMP methods **********************/
/* Read/Write to RFFE vars by ID */
smpr_err_e smpr_bsmp_read_var_by_id (smpr_t *self, uint32_t id, uint8_t *data,
......@@ -29,6 +26,16 @@ smpr_err_e smpr_bsmp_func_exec_by_id (smpr_t *self, uint32_t id, uint8_t *write_
smpr_err_e smpr_bsmp_read_curve_by_id (smpr_t *self, uint32_t id, uint8_t *read_data,
size_t size, size_t *valid_bytes);
/************************* Our Methods **************************/
/* Creates a new instance of the proto_bsmp */
smpr_bsmp_t *smpr_bsmp_new ();
/* Destroy an instance of the bsmp */
smpr_err_e smpr_bsmp_destroy (smpr_bsmp_t **self_p);
/* Get BSMP operations */
const smpr_proto_ops_t *smpr_bsmp_get_ops (smpr_bsmp_t *self);
#ifdef __cplusplus
}
#endif
......
......@@ -51,6 +51,12 @@ typedef struct {
struct bsmp_group_list *groups_list; /* BSMP groups handler */
} smpr_proto_bsmp_t;
/* Protocol object specification */
struct _smpr_bsmp_t {
/* Must be located first */
smpr_proto_ops_t proto_ops; /* BSMP protocol operations */
};
static smpr_err_e _smpr_proto_bsmp_get_handlers (smpr_t *self);
static int _smpr_proto_bsmp_send (uint8_t *data, uint32_t *count);
static int _smpr_proto_bsmp_recv (uint8_t *data, uint32_t *count);
......@@ -95,7 +101,7 @@ static smpr_err_e smpr_proto_bsmp_destroy (smpr_proto_bsmp_t **self_p)
/************ smpr_proto_ops_bsmp Implementation **********/
/* Open BSMP protocol */
int bsmp_open (smpr_t *self, uint64_t base, void *args)
static int bsmp_open (smpr_t *self, uint64_t base, void *args)
{
(void) args;
assert (self);
......@@ -146,7 +152,7 @@ err_proto_handler_alloc:
}
/* Release BSMP protocol device */
int bsmp_release (smpr_t *self)
static int bsmp_release (smpr_t *self)
{
assert (self);
......@@ -482,7 +488,7 @@ err_packet_header:
return err;
}
const smpr_proto_ops_t smpr_proto_ops_bsmp = {
static const smpr_proto_ops_t smpr_proto_ops_bsmp = {
.proto_name = "BSMP", /* Protocol name */
.proto_open = bsmp_open, /* Open device */
.proto_release = bsmp_release, /* Release device */
......@@ -501,3 +507,41 @@ const smpr_proto_ops_t smpr_proto_ops_bsmp = {
.proto_write_dma = NULL /* Write arbitrary block size data via DMA,
parameter size in bytes */
};
/************ Our methods implementation **********/
/* Creates a new instance of the proto_bsmp */
smpr_bsmp_t *smpr_bsmp_new ()
{
smpr_bsmp_t *self = (smpr_bsmp_t *) zmalloc (sizeof *self);
ASSERT_ALLOC (self, err_smpr_bsmp_alloc);
/* copy BSMP operations */
self->proto_ops = smpr_proto_ops_bsmp;
return self;
err_smpr_bsmp_alloc:
return NULL;
}
/* Destroy an instance of the bsmp */
smpr_err_e smpr_bsmp_destroy (smpr_bsmp_t **self_p)
{
assert (self_p);
if (*self_p) {
smpr_bsmp_t *self = *self_p;
free (self);
self_p = NULL;
}
return SMPR_SUCCESS;
}
const smpr_proto_ops_t *smpr_bsmp_get_ops (smpr_bsmp_t *self)
{
assert (self);
return &self->proto_ops;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment