use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile in project open-smart-grid-platform by OSGP.
the class MacGenerationServiceTest method calculateMac.
void calculateMac(final byte[] byteArray, final String deviceIdentification, final byte[] firmwareUpdateAuthenticationKey, final String expectedMac) throws IOException, ProtocolAdapterException {
when(this.secretManagementService.getKey(messageMetadata, deviceIdentification, SecurityKeyType.G_METER_FIRMWARE_UPDATE_AUTHENTICATION)).thenReturn(firmwareUpdateAuthenticationKey);
final String mbusDeviceIdentificationNumber = deviceIdentification.substring(7, 15);
final FirmwareFile firmwareFile = this.createFirmwareFile(byteArray, mbusDeviceIdentificationNumber);
final byte[] calculatedMac = this.macGenerationService.calculateMac(messageMetadata, deviceIdentification, firmwareFile);
assertThat(Hex.toHexString(calculatedMac)).isEqualTo(expectedMac);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile in project open-smart-grid-platform by OSGP.
the class MacGenerationServiceTest method testIV.
public void testIV(final byte[] byteArray, final String expectedIv, final String mbusDeviceIdentificationNumber) throws IOException, ProtocolAdapterException {
final FirmwareFile firmwareFile = this.createFirmwareFile(byteArray, mbusDeviceIdentificationNumber);
final byte[] iv = this.macGenerationService.createIV(firmwareFile);
assertThat(Hex.toHexString(iv)).isEqualTo(expectedIv);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile in project open-smart-grid-platform by OSGP.
the class UpdateFirmwareCommandExecutor method execute.
@Override
public UpdateFirmwareResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final UpdateFirmwareRequestDto updateFirmwareRequestDto, final MessageMetadata messageMetadata) throws OsgpException {
final String firmwareIdentification = updateFirmwareRequestDto.getFirmwareIdentification();
final FirmwareFile firmwareFile = this.getFirmwareFile(updateFirmwareRequestDto, messageMetadata);
final ImageTransfer transfer = new ImageTransfer(conn, this.imageTransferProperties, this.getImageIdentifier(firmwareIdentification, firmwareFile), firmwareFile.getByteArray());
try {
this.prepare(transfer);
this.transfer(transfer);
if (!firmwareFile.isMbusFirmware()) {
this.verify(transfer);
this.activate(transfer);
} else {
this.activateWithoutVerification(transfer);
}
return new UpdateFirmwareResponseDto(firmwareIdentification);
} catch (final ImageTransferException | ProtocolAdapterException e) {
throw new ProtocolAdapterException(EXCEPTION_MSG_UPDATE_FAILED, e);
}
}
Aggregations