use of org.openmuc.jdlms.MethodParameter in project open-smart-grid-platform by OSGP.
the class SetActivityCalendarCommandActivationExecutor method execute.
@Override
public MethodResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final Void v, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
LOGGER.info("ACTIVATING PASSIVE CALENDAR");
final MethodParameter method = new MethodParameter(CLASS_ID, OBIS_CODE, METHOD_ID_ACTIVATE_PASSIVE_CALENDAR, DataObject.newInteger32Data(0));
conn.getDlmsMessageListener().setDescription("SetActivityCalendarActivation, call method: " + JdlmsObjectToStringUtil.describeMethod(method));
final MethodResult methodResultCode;
try {
methodResultCode = conn.getConnection().action(method);
} catch (final IOException e) {
throw new ConnectionException(e);
}
if (!MethodResultCode.SUCCESS.equals(methodResultCode.getResultCode())) {
throw new ProtocolAdapterException("Activating the activity calendar failed. MethodResult is: " + methodResultCode.getResultCode() + " ClassId: " + CLASS_ID + " obisCode: " + OBIS_CODE + " method id: " + METHOD_ID_ACTIVATE_PASSIVE_CALENDAR);
}
return MethodResultCode.SUCCESS;
}
use of org.openmuc.jdlms.MethodParameter in project open-smart-grid-platform by OSGP.
the class ClearMBusStatusOnAllChannelsCommandExecutorTest method assertMethodResetAlarm.
private void assertMethodResetAlarm(final List<MethodParameter> allMethods) {
for (int i = 1; i <= 4; i++) {
final MethodParameter methodParameter = allMethods.get(i - 1);
assertThat(((Number) methodParameter.getParameter().getValue()).longValue()).isEqualTo(0L);
assertThat(methodParameter.getInstanceId().asDecimalString()).isEqualTo(OBIS_CODE_TEMPLATE_MBUS_CLIENT_SETUP.replaceAll("<c>", String.valueOf(i)));
assertThat(methodParameter.getClassId()).isEqualTo(CLASS_ID_MBUS_CLIENT);
}
}
use of org.openmuc.jdlms.MethodParameter in project open-smart-grid-platform by OSGP.
the class SetEncryptionKeyExchangeOnGMeterCommandExecutor method transferKey.
private MethodResult transferKey(final DlmsConnectionManager conn, final String mbusDeviceIdentification, final int channel, final byte[] encryptionKey, final MessageMetadata messageMetadata) throws ProtocolAdapterException, IOException {
final MethodParameter methodTransferKey = this.getTransferKeyMethodParameter(mbusDeviceIdentification, channel, encryptionKey, messageMetadata);
conn.getDlmsMessageListener().setDescription("SetEncryptionKeyExchangeOnGMeter for channel " + channel + ", call M-Bus Setup transfer_key method: " + JdlmsObjectToStringUtil.describeMethod(methodTransferKey));
return conn.getConnection().action(methodTransferKey);
}
use of org.openmuc.jdlms.MethodParameter in project open-smart-grid-platform by OSGP.
the class SetEncryptionKeyExchangeOnGMeterCommandExecutor method getTransferKeyMethodParameter.
private MethodParameter getTransferKeyMethodParameter(final String mbusDeviceIdentification, final int channel, final byte[] gMeterUserKey, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final DlmsDevice mbusDevice = this.dlmsDeviceRepository.findByDeviceIdentification(mbusDeviceIdentification);
if (mbusDevice == null) {
throw new ProtocolAdapterException("Unknown M-Bus device: " + mbusDeviceIdentification);
}
final byte[] mbusDefaultKey = this.secretManagementService.getKey(messageMetadata, mbusDeviceIdentification, G_METER_MASTER);
final byte[] encryptedUserKey = this.encryptMbusUserKey(mbusDefaultKey, gMeterUserKey);
final DataObject methodParameter = DataObject.newOctetStringData(encryptedUserKey);
final MBusClientMethod method = MBusClientMethod.TRANSFER_KEY;
return new MethodParameter(method.getInterfaceClass().id(), OBIS_HASHMAP.get(channel), method.getMethodId(), methodParameter);
}
use of org.openmuc.jdlms.MethodParameter 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);
}
}
Aggregations