Search in sources :

Example 1 with MethodResultCode

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());
}
Also used : MethodResultCode(org.openmuc.jdlms.MethodResultCode) DataObject(org.openmuc.jdlms.datatypes.DataObject) Test(org.junit.jupiter.api.Test)

Example 2 with MethodResultCode

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);
    }
}
Also used : MethodResultCode(org.openmuc.jdlms.MethodResultCode) EncrypterException(org.opensmartgridplatform.shared.exceptionhandling.EncrypterException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) IOException(java.io.IOException) MethodParameter(org.openmuc.jdlms.MethodParameter) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Example 3 with MethodResultCode

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);
}
Also used : MethodResultCode(org.openmuc.jdlms.MethodResultCode) GMeterInfoDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GMeterInfoDto) SetMbusUserKeyByChannelRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetMbusUserKeyByChannelRequestDataDto)

Example 4 with MethodResultCode

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);
    }
}
Also used : MethodResultCode(org.openmuc.jdlms.MethodResultCode) DataObject(org.openmuc.jdlms.datatypes.DataObject) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 5 with MethodResultCode

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()));
}
Also used : MethodResultCode(org.openmuc.jdlms.MethodResultCode) DataObject(org.openmuc.jdlms.datatypes.DataObject) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ImageTransferException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ImageTransferException)

Aggregations

MethodResultCode (org.openmuc.jdlms.MethodResultCode)11 DataObject (org.openmuc.jdlms.datatypes.DataObject)6 Test (org.junit.jupiter.api.Test)4 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)3 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 MethodParameter (org.openmuc.jdlms.MethodParameter)1 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)1 ImageTransferException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ImageTransferException)1 GMeterInfoDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.GMeterInfoDto)1 SetMbusUserKeyByChannelRequestDataDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SetMbusUserKeyByChannelRequestDataDto)1 EncrypterException (org.opensmartgridplatform.shared.exceptionhandling.EncrypterException)1