use of org.openmuc.jdlms.MethodResultCode in project open-smart-grid-platform by OSGP.
the class DeviceChannelsHelperTest method testDeinstallSlave3.
@Test
void testDeinstallSlave3() throws ProtocolAdapterException {
// unsuccessful deinstall with signed integer parameter
when(this.conn.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
when(this.mBusSetup.callMethod(eq(MBusClientMethod.SLAVE_DEINSTALL), any(DataObject.class))).thenReturn(MethodResultCode.SCOPE_OF_ACCESS_VIOLATION);
final MethodResultCode methodResultCode = this.deviceChannelsHelper.deinstallSlave(this.conn, this.device, (short) 1, this.mBusSetup);
assertThat(methodResultCode).isEqualTo(MethodResultCode.SCOPE_OF_ACCESS_VIOLATION);
verify(this.mBusSetup, times(1)).callMethod(eq(MBusClientMethod.SLAVE_DEINSTALL), any());
}
use of org.openmuc.jdlms.MethodResultCode in project open-smart-grid-platform by OSGP.
the class AbstractReplaceKeyCommandExecutor method sendToDevice.
/**
* Send the key to the device.
*
* @param conn jDLMS connection.
* @param deviceIdentification Device identification
* @param keyWrapper Key data
* @param messageMetadata
*/
private void sendToDevice(final DlmsConnectionManager conn, final String deviceIdentification, final ReplaceKeyInput keyWrapper, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
try {
final byte[] decryptedKey = keyWrapper.getBytes();
final byte[] decryptedMasterKey = this.secretManagementService.getKey(messageMetadata, deviceIdentification, SecurityKeyType.E_METER_MASTER);
final MethodParameter methodParameterAuth = SecurityUtils.keyChangeMethodParamFor(decryptedMasterKey, decryptedKey, keyWrapper.getKeyId());
conn.getDlmsMessageListener().setDescription("ReplaceKey for " + keyWrapper.getSecurityKeyType() + " " + keyWrapper.getKeyId() + ", call method: " + JdlmsObjectToStringUtil.describeMethod(methodParameterAuth));
final MethodResultCode methodResultCode = conn.getConnection().action(methodParameterAuth).getResultCode();
if (!MethodResultCode.SUCCESS.equals(methodResultCode)) {
throw new ProtocolAdapterException("AccessResultCode for replace keys was not SUCCESS: " + methodResultCode);
}
if (keyWrapper.getSecurityKeyType() == SecurityKeyType.E_METER_AUTHENTICATION) {
conn.getConnection().changeClientGlobalAuthenticationKey(decryptedKey);
} else if (keyWrapper.getSecurityKeyType() == SecurityKeyType.E_METER_ENCRYPTION) {
conn.getConnection().changeClientGlobalEncryptionKey(decryptedKey);
}
} catch (final IOException e) {
throw new ConnectionException(e);
} catch (final EncrypterException e) {
throw new ProtocolAdapterException("Unexpected exception during decryption of security keys, reason = " + e.getMessage(), e);
}
}
use of org.openmuc.jdlms.MethodResultCode in project open-smart-grid-platform by OSGP.
the class SetMbusUserKeyByChannelCommandExecutor method executeBundleAction.
@Override
public ActionResponseDto executeBundleAction(final DlmsConnectionManager conn, final DlmsDevice device, final ActionRequestDto actionRequestDto, final MessageMetadata messageMetadata) throws OsgpException {
this.checkActionRequestType(actionRequestDto);
final SetMbusUserKeyByChannelRequestDataDto setMbusUserKeyByChannelRequestData = (SetMbusUserKeyByChannelRequestDataDto) actionRequestDto;
final GMeterInfoDto gMeterInfo = this.configurationService.getMbusKeyExchangeData(conn, device, setMbusUserKeyByChannelRequestData, messageMetadata);
final MethodResultCode executionResult = this.execute(conn, device, gMeterInfo, messageMetadata);
return this.asBundleResponse(executionResult);
}
use of org.openmuc.jdlms.MethodResultCode in project open-smart-grid-platform by OSGP.
the class ImageTransfer method activateImage.
/**
* The image is activated.
*/
public void activateImage() throws OsgpException {
final DataObject parameter = DataObject.newInteger8Data((byte) 0);
this.setDescriptionForMethodCall(ImageTransferMethod.IMAGE_ACTIVATE, parameter);
final MethodResultCode imageActivate = this.imageTransferCosem.callMethod(ImageTransferMethod.IMAGE_ACTIVATE, parameter);
if (imageActivate == null) {
throw new ProtocolAdapterException(EXCEPTION_MSG_IMAGE_ACTIVATE_NOT_CALLED);
}
}
use of org.openmuc.jdlms.MethodResultCode in project open-smart-grid-platform by OSGP.
the class ImageTransfer method verifyImage.
/**
* The Image is verified. This is done by invoking the image_verify method by the client and
* testing the image transfer status.
*/
public void verifyImage() throws OsgpException {
final DataObject parameter = DataObject.newInteger8Data((byte) 0);
this.setDescriptionForMethodCall(ImageTransferMethod.IMAGE_VERIFY, parameter);
final MethodResultCode verified = this.imageTransferCosem.callMethod(ImageTransferMethod.IMAGE_VERIFY, parameter);
if (verified == null) {
throw new ProtocolAdapterException(EXCEPTION_MSG_IMAGE_VERIFY_NOT_CALLED);
}
if (verified == MethodResultCode.SUCCESS) {
return;
}
if (verified == MethodResultCode.TEMPORARY_FAILURE) {
this.waitForImageVerification();
}
// If activation was triggered the device will not verify again.
if (this.imageIsVerified()) {
return;
}
final int status = this.getImageTransferStatus();
throw new ImageTransferException(String.format(EXCEPTION_MSG_IMAGE_VERIFICATION_ERROR, ImageTransferStatus.getByValue(status).name(), verified.name()));
}
Aggregations