Commit 2f2777b0 authored by Adam Wujek's avatar Adam Wujek 💬

lib/snmp: add wrpcSdbGroup to format sdb

Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 4f77dba8
......@@ -183,6 +183,13 @@ config SNMP_INIT
help
This option adds a branch wrpcInitScriptConfigGroup to the SNMP
config SNMP_SDB
depends on SNMP && GENSDBFS
default y
boolean "Adds support of generation of SDB via SNMP"
help
This option adds a branch wrpcSdbGroup to the SNMP
config SNMP_AUX_DIAG
depends on SNMP && AUX_DIAG
default y if AUX_DIAG
......
......@@ -773,7 +773,61 @@ wrpcInitScriptConfigLine OBJECT-TYPE
"Line to be added to the init script."
::= { wrpcInitScriptConfigGroup 2 }
-- ****************************************************************************
wrpcSdbGroup OBJECT IDENTIFIER ::= { wrpcCore 10 }
wrpcSdbApply OBJECT-TYPE
SYNTAX INTEGER {
na(0),
writeToFlash(1),
eraseFlash(50),
applySuccessful(100),
applyFailed(200),
applyFailedEmptyParam(201)
}
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"Make a change to a init script
writeToFlash - Add a defined command from wrpcInitScriptConfigLine to the init script
eraseFlash - Erase init script in the flash.
applySuccessful - Configuration applied successfully.
applyFailed - Failed to update init script.
applyFailedEmptyParam - Failed to write to SDB, some params are empty is empty.
"
::= { wrpcSdbGroup 1 }
wrpcSdbMemType OBJECT-TYPE
SYNTAX INTEGER {
flash(0),
eeprom(1),
w1eeprom(2),
fram(3)
}
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"Mem type"
::= { wrpcSdbGroup 2 }
wrpcSdbBaseAddr OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"Base addr"
::= { wrpcSdbGroup 3 }
wrpcSdbParam OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"Param"
::= { wrpcSdbGroup 4 }
-- ****************************************************************************
END
......@@ -127,6 +127,10 @@
#define writeToFlash 1
#define applyFailedEmptyLine 201
/* new defines for oid_wrpcSdbApply, some are used from
* wrpcPtpConfigApply */
#define applyFailedEmptyParam 201
/* defines for wrpcTemperatureTable */
#define TABLE_ROW 1
#define TABLE_COL 0
......@@ -220,6 +224,13 @@ static int ptp_config_apply_status;
static int ptp_restart_status;
static char init_script_line[32];
static int init_script_config_apply_status;
/* related to wrpcSdbGroup */
static int sdb_apply_status;
static int sdb_mem_type = -1;
static int sdb_base_addr = -1;
static int sdb_param = -1;
/* Keep the number of aux diag registers available in the FPGA bitstream */
static uint32_t aux_diag_reg_ro_num;
static uint32_t aux_diag_reg_rw_num;
......@@ -268,6 +279,7 @@ static int set_p(uint8_t *buf, struct snmp_oid *obj);
static int set_ptp_restart(uint8_t *buf, struct snmp_oid *obj);
static int set_ptp_config(uint8_t *buf, struct snmp_oid *obj);
static int set_init_script_config(uint8_t *buf, struct snmp_oid *obj);
static int set_sdb(uint8_t *buf, struct snmp_oid *obj);
static int set_aux_diag(uint8_t *buf, struct snmp_oid *obj);
static int data_aux_diag(uint8_t *buf, struct snmp_oid *obj, int mode);
......@@ -285,6 +297,7 @@ static uint8_t oid_wrpcPortGroup[] = {0x2B,6,1,4,1,96,101,1,7};
/* Include wrpcSfpEntry into OID */
static uint8_t oid_wrpcSfpTable[] = {0x2B,6,1,4,1,96,101,1,8,1};
static uint8_t oid_wrpcInitScriptConfigGroup[] = {0x2B,6,1,4,1,96,101,1,9};
static uint8_t oid_wrpcSdbGroup[] = {0x2B,6,1,4,1,96,101,1,10};
/* In below OIDs zeros will be replaced in the snmp_init function by values
* read from FPA */
static uint8_t oid_wrpcAuxRoTable[] = {0x2B,6,1,4,1,96,101,2,0,0,1,1};
......@@ -360,6 +373,13 @@ static uint8_t oid_wrpcSfpAlpha[] = {5};
static uint8_t oid_wrpcInitScriptConfigApply[] = {1,0};
static uint8_t oid_wrpcInitScriptConfigLine[] = {2,0};
/* oid_wrpcSdbGroup */
static uint8_t oid_wrpcSdbApply[] = {1,0};
static uint8_t oid_wrpcSdbMemType[] = {2,0};
static uint8_t oid_wrpcSdbBaseAddr[] = {3,0};
static uint8_t oid_wrpcSdbParam[] = {4,0};
/* NOTE: to have SNMP_GET_NEXT working properly this array has to be sorted by
OIDs */
/* wrpcVersionGroup */
......@@ -460,6 +480,15 @@ static struct snmp_oid oid_array_wrpcInitScriptConfigGroup[] = {
{ 0, }
};
/* wrpcSdbGroup */
static struct snmp_oid oid_array_wrpcSdbGroup[] = {
OID_FIELD_VAR( oid_wrpcSdbApply, get_p, set_sdb, ASN_INTEGER, &sdb_apply_status),
OID_FIELD_VAR( oid_wrpcSdbMemType, get_p, set_p, ASN_INTEGER, &sdb_mem_type),
OID_FIELD_VAR( oid_wrpcSdbBaseAddr, get_p, set_p, ASN_INTEGER, &sdb_base_addr),
OID_FIELD_VAR( oid_wrpcSdbParam, get_p, set_p, ASN_INTEGER, &sdb_param),
{ 0, }
};
static struct snmp_oid oid_array_wrpcAuxRoTable[] = {
OID_FIELD_VAR(NULL, get_aux_diag, NO_SET, ASN_UNSIGNED, AUX_DIAG_RO),
{ 0, }
......@@ -484,6 +513,9 @@ static struct snmp_oid_limb oid_limb_array[] = {
#ifdef CONFIG_SNMP_INIT
OID_LIMB_FIELD(oid_wrpcInitScriptConfigGroup, func_group, oid_array_wrpcInitScriptConfigGroup),
#endif
#ifdef CONFIG_SNMP_SDB
OID_LIMB_FIELD(oid_wrpcSdbGroup, func_group, oid_array_wrpcSdbGroup),
#endif
#ifdef CONFIG_SNMP_AUX_DIAG
OID_LIMB_FIELD(oid_wrpcAuxRoTable, func_aux_diag, oid_array_wrpcAuxRoTable),
OID_LIMB_FIELD(oid_wrpcAuxRwTable, func_aux_diag, oid_array_wrpcAuxRwTable),
......@@ -1404,6 +1436,58 @@ static int set_init_script_config(uint8_t *buf, struct snmp_oid *obj)
return ret;
}
static int set_sdb(uint8_t *buf, struct snmp_oid *obj)
{
int ret;
int32_t *apply_mode;
uint8_t i2c_adr = FMC_EEPROM_ADR;
int blocksize = 1;
apply_mode = obj->p;
ret = set_value(buf, obj, apply_mode);
if (ret <= 0)
return ret;
snmp_verbose("%s enter\n", __func__);
if (sdb_mem_type == -1
|| sdb_base_addr == -1
|| sdb_param == -1) {
*apply_mode = applyFailedEmptyParam;
pp_printf("%s wrong params\n", __func__);
return ret;
}
if (sdb_mem_type == MEM_FLASH)
blocksize = sdb_param * 1024;
else if (sdb_param)
i2c_adr = sdb_param;
switch (*apply_mode) {
case writeToFlash:
snmp_verbose("%s writeToFlash\n", __func__);
if (storage_gensdbfs(sdb_mem_type, sdb_base_addr, blocksize,
i2c_adr) < 0)
*apply_mode = applyFailed;
else
*apply_mode = applySuccessful;
break;
case eraseFlash:
snmp_verbose("%s eraseFlash\n", __func__);
if (storage_sdbfs_erase(sdb_mem_type, sdb_base_addr, blocksize,
i2c_adr) < 0)
*apply_mode = applyFailed;
else
*apply_mode = applySuccessful;
break;
default:
*apply_mode = applyFailed;
}
return ret;
}
/*
* Perverse... snmpwalk does getnext anyways.
*
......@@ -1578,6 +1662,8 @@ static int snmp_respond(uint8_t *buf)
oid_array_wrpcAuxRoTable[0].oid_len = 0;
oid_array_wrpcInitScriptConfigGroup[0].oid_len = 0;
(void) oid_wrpcInitScriptConfigGroup;
oid_array_wrpcSdbGroup[0].oid_len = 0;
(void) oid_wrpcSdbGroup;
}
for (a_i = 0, h_i = 0; a_i < sizeof(match_array); a_i++, h_i++) {
......
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