Commit ed51ab3c authored by Adam Wujek's avatar Adam Wujek 💬

lib/snmp: improve implementation of wrpcPtpConfigGroup

Write to the flash, if failed return corresponding error.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 29f97f33
......@@ -549,17 +549,32 @@ wrpcPtpConfigApply OBJECT-TYPE
writeToFlashGivenSfp(1),
writeToFlashCurrentSfp(2),
writeToMemoryCurrentSfp(3),
applySuccessful(10),
applyFailed(11),
eraseFlash(50),
applySuccessful(100),
applySuccessfulMatchFailed(101),
applyFailed(200),
applyFailedI2CError(201),
applyFailedDBFull(202),
applyFailedInvalidPN(203)
}
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"Apply configuration of the ptp"
"Apply configuration of the ptp
writeToFlashGivenSfp - Write delta TX/RX and alpha for provided SFP's PN to the sfp database in the flash. Perform sfp match.
writeToFlashCurrentSfp - Write delta TX/RX and alpha for currently used SFP to the sfp database in the flash. Perform sfp match.
writeToMemoryCurrentSfp - Write delta TX/RX and alpha for currently used SFP to the the memory. Do not perform sfp match.
eraseFlash - Erase sfp database in the flash. Do not perform sfp match.
applySuccessful - Configuration applied successfully.
applySuccessfulMatchFailed - SFP entry written, but failed to match with the plugged SFP.
applyFailed - Failed to apply configuration.
applyFailedI2CError - Failed to apply configuration due to communication error with the flash memory.
applyFailedDBFull - Failed to apply configuration. Database is full.
applyFailedInvalidPN - Invalid Product Number (PN) provided."
::= { wrpcPtpConfigGroup 1 }
wrpcPtpConfigSfpPn OBJECT-TYPE
SYNTAX OCTET STRING (SIZE(16)) --17?
SYNTAX OCTET STRING (SIZE(0..16))
MAX-ACCESS read-write
STATUS current
DESCRIPTION
......@@ -606,7 +621,7 @@ wrpcPortLinkStatus OBJECT-TYPE
::= { wrpcPortGroup 1 }
wrpcPortSfpPn OBJECT-TYPE
SYNTAX OCTET STRING (SIZE(16))
SYNTAX OCTET STRING (SIZE(0..16))
MAX-ACCESS read-only
STATUS current
DESCRIPTION
......
......@@ -93,9 +93,13 @@
#define writeToFlashGivenSfp 1
#define writeToFlashCurrentSfp 2
#define writeToMemoryCurrentSfp 3
#define applySuccessful 10
#define applyFailed 11
#define eraseFlash 50
#define applySuccessful 100
#define applySuccessfulMatchFailed 101
#define applyFailed 200
#define applyFailedI2CError 201
#define applyFailedDBFull 202
#define applyFailedInvalidPN 203
#define OID_FIELD_STRUCT(_oid, _getf, _setf, _asn, _type, _pointer, _field) { \
.oid_match = _oid, \
......@@ -517,6 +521,7 @@ static int set_ptp_config(uint8_t *buf, struct snmp_oid *obj)
{
int ret;
int32_t *apply_mode;
int temp;
apply_mode = obj->p;
ret = set_value(buf, obj, apply_mode);
......@@ -525,14 +530,51 @@ static int set_ptp_config(uint8_t *buf, struct snmp_oid *obj)
sfp_deltaTx = snmp_ptp_config.dTx;
sfp_deltaRx = snmp_ptp_config.dRx;
sfp_alpha = snmp_ptp_config.alpha;
/* restart of ppsi is needed here */
*apply_mode = applySuccessful;
break;
case writeToFlashCurrentSfp:
*apply_mode = applySuccessful;
break;
memcpy(snmp_ptp_config.pn, sfp_pn, SFP_PN_LEN);
/* continue with writeToFlashGivenSfp */
case writeToFlashGivenSfp:
if (snmp_ptp_config.pn[0] == '\0') { /* empty PN */
snmp_verbose("%s: Invalid PN\n", __func__);
*apply_mode = applyFailedInvalidPN;
break;
}
temp = strnlen(snmp_ptp_config.pn, SFP_PN_LEN);
/* padding with spaces */
while (temp < SFP_PN_LEN)
snmp_ptp_config.pn[temp++] = ' ';
/* add a sfp to the DB */
temp = storage_get_sfp(&snmp_ptp_config, SFP_ADD, 0);
if (temp == EE_RET_DBFULL) {
snmp_verbose("%s: SFP DB is full\n", __func__);
*apply_mode = applyFailedDBFull;
break;
} else if (temp == EE_RET_I2CERR) {
snmp_verbose("%s: I2C error\n", __func__);
*apply_mode = applyFailedI2CError;
break;
}
/* perform a sfp match */
temp = sfp_match();
if (temp) {
snmp_verbose("%s: Match error (%d)\n", __func__, temp);
*apply_mode = applySuccessfulMatchFailed;
break;
}
/* restart of ppsi is needed here */
*apply_mode = applySuccessful;
break;
case eraseFlash:
if (storage_sfpdb_erase() == EE_RET_I2CERR)
*apply_mode = applyFailed;
else
*apply_mode = applySuccessful;
break;
default:
*apply_mode = applyFailed;
}
......
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