<?xml version="1.0" encoding="UTF-8" ?>
<data version="1">
  <plcType>WAGO</type> 
  <licenceType version="1">EOV_OSV</licenceType> 
  <licenceName>Licence pro EOV_OSV</licenceName>
  <station>ceskatrebova</station>
  <distributor>RO1</distributor>
</data>

map<string, const char*> getArguments(int argc, char *argv[])
{
  const char splitChar='=';
  map<string, const char*> result;
  if (argc <= 1) return result;

  for (int i = 1; i < argc; ++i)
  {
    bool isArgName = true;
    int argLength = strlen(argv[i]);
    string argName;
    string argValue;
    char* argValueChar;

    for (int j=0;j<argLength;j++)
    {
      if (argv[i][j] == splitChar)
      {
        isArgName = false;
        continue;
      }

      if (isArgName)
      {
        argName += argv[i][j];
      }
      else
      {
        argValue += argv[i][j];
      }
    }

    //getCharsFromString(argValue, argValueChar);

    const char * chValue = argValue.c_str();

    result.insert(make_pair(argName, chValue));
  }
  return result;
}

-cid=9f544930303030300000000b47015423
-outputType=base64

g++ -Wall -Wextra -g -lssl -lcrypto -w -Iinclude -c -MMD src/CreateLicence.cpp  -o src/CreateLicence.o
g++ -Wall -Wextra -g -lssl -lcrypto -w -Iinclude -c -MMD src/PlcLicence.cpp  -o src/PlcLicence.o
g++ -Wall -Wextra -g -lssl -lcrypto -w -Iinclude -c -MMD src/utils.cpp  -o src/utils.o
g++ -Wall -Wextra -g -lssl -lcrypto -w -Iinclude -o output\main.exe src/CreateLicence.o src/PlcLicence.o src/utils.o  -Llib

19 - 110 (n)
20 - 105 (i)
21 - 99 (c)
22 - 101 (e)
23 - 49 (1)

59 - 118 (v)
60 - 97 (a)
61 - 100 (d)
62 - 101 (e)
63 - 99 (c)
59 - 49 (1)


// karta2
  // cid = "9f54495344434954615ad803b601714d";
  // csd = "400e00325b5900003be77f800a400043";

  // karta1
  // cid = "9f544953444349546159d803600171fb";
  // csd = "400e00325b5900003be77f800a400043";

  // CreateLicense(cid, csd, stationName, switchName, "licData.xml");

  // if (ReadLicence("ezlic_eovosv0_vaxvcpalxjx.lic", nullptr, LidIdType::EovOsv, 0, cid, csd) == false)
  // {
  //   cout << "Reading error: " << operationErrors << "\n" << endl;
  // }




BOOL codesys v C ?
string v codeses v C ? char[] s \0 nebo bez \0

g++ -std=c++17 -Wall -Wextra -g -fdiagnostics-color=always -w -Iinclude -c -MMD src/main.cpp  -o src/main.o
g++ -std=c++17 -Wall -Wextra -g -fdiagnostics-color=always -w -Iinclude -c -MMD src/test.cpp  -o src/test.o
g++ -std=c++17 -Wall -Wextra -g -fdiagnostics-color=always -w -Iinclude -o output\main.exe src/main.o src/test.o  -Llib

Online - Login (wago) / /(admin/wago)
F5 run, F8 stepin

https://172.16.154.3/wbm/#/configuration/ports-and-services/network-services

licDate = D#1970-01-01

DEBUG funkční
------------------------------------------------------------------
FUNCTION fEz_CreateLicenceFile : tEz_LicenceRetData
VAR
	(* promenne pro praci se soubory a adresari *)
	sdFileHandle: DWORD;
	sdDirHandle: DWORD;
	dirFileName: STRING;
	dirFilePath: STRING;
	dirInfo: DIRECTORY_INFO;

	dataMainToFileELC1: tEz_LicenceDataMainELC1;	(* hlavicka urcena pro zapis do souboru - typ ELC1 *)
	dataToFile_10_10: 	tEz_LicenceData_10_10;			(* data urcena pro sifrovani a zapis do soubotu - verze => hlavicka: 1.0, data: 1.0 *)

	(* pomocne promenne *)
	dataWiteToFile: ARRAY [0..cEzLic_p78ou3_maxDataToFile] OF BYTE;	(* data zapisovana do souboru *)
	retDataCount: DWORD;	(* pocty zapisovanych a ctenych dat - navratova hodnota jednotlivych funkci *)
	licencePostfix: STRING;	(* pomocna promenna pro kontrolu postfixu *)
	mainLicDescription: STRING(79);	(* globalni pojmenovani licence v nesifrovane casti licence *)

	freeDataSize: UINT;	(* velikost volne citelnych dat v souboru licenci *)
	cryptDataSize: UINT;	(* velikost volne cryptovanych dat v souboru licenci *)
	fullDataSize: UINT;	(* celkova velikost souboru licenci *)

	generation: USINT;	(* verze SW pro licence *)

	(* testCrypt: ARRAY  [0..3] OF BYTE := 116,101,115,116; (* test *) *)
	testCrypt: ARRAY  [0..4] OF BYTE := 107,117,114,118,97;
	encTest: ARRAY [0..100] OF BYTE;	(* data zapisovana do souboru *)
	testByte: BYTE;


END_VAR


(*
funkce:
	- nacte SD kartu a dekoduje informace CID, CSD
	- vygeneruje jmena a hesla
	- vytvori soubor licence
*)

fEz_CreateLicenceFile.isDone := FALSE;

(* nacteni CID a CSD informaci SD karty - pro vsechny verze licencnich souboru STEJNE *)
fEz_CreateLicenceFile := fEz_ReadSD( cEzLic_p78ou3_sdinfofilepath );
IF fEz_CreateLicenceFile.retCode > 0 THEN
	RETURN;
END_IF;

(* nastaveni dat licence *)
EZlic_LicenceIdent.licPrefixType := SHR( EZlic_sourceLicenceData.licType, 12 );
EZlic_LicenceIdent.licHeaderType := ( SHR( EZlic_sourceLicenceData.licType, 8 ) AND 16#000F );
EZlic_LicenceIdent.licDataType := ( SHR( EZlic_sourceLicenceData.licType, 4 ) AND 16#000F );
EZlic_LicenceIdent.licSubType := SHL(EZlic_LicenceIdent.licHeaderType, 8) OR EZlic_LicenceIdent.licDataType;
EZlic_LicenceIdent.licIDType := EZlic_sourceLicenceData.licType AND 16#000F;

(* kontrola a nastaveni postfixu *)
IF EZlic_sourceLicenceData.licPostfix > 9 THEN
	EZlic_sourceLicenceData.licPostfix := 0;
END_IF;
licencePostfix := BYTE_TO_STRING( EZlic_sourceLicenceData.licPostfix );
EZlic_sourceLicenceData.licPostfixIdent := RIGHT( licencePostfix, 1 );

(* vygenerovani jmena licencniho souboru *)
fEz_CreateLicenceFile := fEz_GetLicenceFileName( EZlic_LicenceIdent.licIDType, EZlic_sourceLicenceData.licPostfix, EZlic_licenceFilePath, generation);
IF fEz_CreateLicenceFile.retCode > 0 THEN
	RETURN;
END_IF;

(* nastaveni dat licence *)
CASE EZlic_LicenceIdent.licHeaderType OF
	cEzLic_p78ou3_HeaderType_10:	(* hlavicka licence verze 1.0 *)
			CASE EZlic_LicenceIdent.licDataType OF
				cEzLic_p78ou3_DataType_10: (* verze licencnich dat 1.0 *)
						(* hlavicka licence *)
						dataToFile_10_10.id.version := 10;
						dataToFile_10_10.id.cardSize := EzLic_p78ou3_SD_Data.cardSize;
						CASE EZlic_LicenceIdent.licIDType OF
							cEzLic_p78ou3_IDType_DDTS: (* ddts *)
									mainLicDescription := 'ddts ';
							cEzLic_p78ou3_IDType_EOVOSV: (* eov, osv *)
									mainLicDescription := 'eov, osv ';
							ELSE
									mainLicDescription := 'neznama app ';
						END_CASE;
						mainLicDescription := CONCAT( mainLicDescription, EZlic_sourceLicenceData.licPostfixIdent );
						mainLicDescription := CONCAT( mainLicDescription, ' => ' );
						(* data licence *)
						dataToFile_10_10.header.licVersion := 10;
						dataToFile_10_10.header.licType := WORD_TO_BYTE( EZlic_LicenceIdent.licIDType );
						dataToFile_10_10.header.licDate := DT_TO_DATE( SysRtcGetTime(TRUE) );
						dataToFile_10_10.header.licDescription1 := EZlic_sourceLicenceData.licDescription1;
						dataToFile_10_10.header.licDescription2 := EZlic_sourceLicenceData.licDescription2;
						mainLicDescription := CONCAT( mainLicDescription, dataToFile_10_10.header.licDescription1 );
						mainLicDescription := CONCAT( mainLicDescription, ' [' );
						mainLicDescription := CONCAT( mainLicDescription, dataToFile_10_10.header.licDescription2 );
						mainLicDescription := CONCAT( mainLicDescription, ']' );
						CASE EZlic_LicenceIdent.licIDType OF
							cEzLic_p78ou3_IDType_EOVOSV: (* eov, osv *)
									IF generation = 1 THEN
										dataToFile_10_10.header.licCount := 1;
										dataToFile_10_10.items[0].licCount := 65535;
										dataToFile_10_10.items[0].protoId := cEzLic_p78ou3_CheckLicNumberId_EOV1;
										dataToFile_10_10.items[0].data1 := cEzLic_p78ou3_CheckLicNumber_EOV1;
									ELSE
										dataToFile_10_10.header.licCount := 1;
										dataToFile_10_10.items[1].licCount := 65535;
										dataToFile_10_10.items[1].protoId := cEzLic_p78ou3_CheckLicNumberId_EOV1;
										dataToFile_10_10.items[1].data1 := cEzLic_p78ou3_CheckLicNumber_EOV1;
									END_IF;
						END_CASE;
						(* parametry pro sifrovani a zapis do souboru *)

						(* - dekoment
						EzLic_p78ou3_CryptoData.cryptDataAddress := ADR( dataToFile_10_10 );
						EzLic_p78ou3_CryptoData.cryptDataSize := SIZEOF( dataToFile_10_10 );
						*)

						EzLic_p78ou3_CryptoData.cryptDataAddress := ADR( testCrypt );
						EzLic_p78ou3_CryptoData.cryptDataSize := SIZEOF( testCrypt );


						(*nastaveni id souboru a vypocet CRC pro hlavicky a licencnich dat *)
						dataToFile_10_10.id.version := 10;
						dataToFile_10_10.crc := fEz_crc16( ADR( dataToFile_10_10 ), SIZEOF( dataToFile_10_10 ) - SIZEOF( dataToFile_10_10.crc ) );
						dataToFile_10_10.crc := 1000;
			ELSE
				(* neznama verze licencnich dat *)
				fEz_CreateLicenceFile := fEz_SetRetData(cEzLic_p78ou3_error_data, 1);
				RETURN;
			END_CASE;
	ELSE
		(* neznama verze hlavicky kriptovanych dat *)
		fEz_CreateLicenceFile := fEz_SetRetData(cEzLic_p78ou3_error_header, 1);
		RETURN;
END_CASE;

(* inicializace Ckryptovacich algoritmu, Vektoru a klice *)
fEz_CreateLicenceFile := fEz_InitCrypto(EZlic_LicenceIdent.licIDType);
IF fEz_CreateLicenceFile.retCode > 0 THEN
	RETURN;
END_IF;

(* zpracovani dat licencniho souboru [sifrovani, podpis, komprese, ...] *)
CASE EZlic_LicenceIdent.licPrefixType OF
	cEzLic_p78ou3_LicPrefixType_ELC1: (* typ1 = pouze zasifrovani dat *)
		freeDataSize := SIZEOF( dataMainToFileELC1 );

EzLic_p78ou3_CryptoData.aesRetVal := WCRYPTO_fAesEncrypt(
											pabPlain := EzLic_p78ou3_CryptoData.cryptDataAddress,
											diPlainLen := EzLic_p78ou3_CryptoData.cryptDataSize,
											sCipher := cEzLic_p78ou3_CipherAES,
											pIv := ADR(EzLic_p78ou3_CryptoData.aesInitVector),
											diIvLen := SIZEOF(EzLic_p78ou3_CryptoData.aesInitVector),
											pKey := ADR(EzLic_p78ou3_CryptoData.aesKey),
											diKeyLen := SIZEOF(EzLic_p78ou3_CryptoData.aesKey),
											(*
											pabCiphered := ADR(encTest),
											diCipheredLen := SIZEOF(encTest)
											*)
											pabCiphered := ADR( dataWiteToFile ) + freeDataSize,
											diCipheredLen := SIZEOF( dataWiteToFile ) - freeDataSize
											);

		(* EzLic_p78ou3_CryptoData.aesRetVal := SIZEOF(dataToFile_10_10); *)

		IF EzLic_p78ou3_CryptoData.aesRetVal > 0 THEN
			SysMemSet( ADR( dataMainToFileELC1.licHeader.description ), 0, SIZEOF( dataMainToFileELC1.licHeader.description ) );
			dataMainToFileELC1.prefix := 16#31434C45;
			SysMemCpy( ADR( dataMainToFileELC1.licHeader.description ), ADR( mainLicDescription ), LEN( mainLicDescription ) );
			dataMainToFileELC1.licHeader.sizeData := EzLic_p78ou3_CryptoData.aesRetVal;
			dataMainToFileELC1.licHeader.licType := WORD_TO_BYTE( EZlic_LicenceIdent.licIDType );
			dataMainToFileELC1.licHeader.licSubType := SHL( EZlic_LicenceIdent.licHeaderType, 8 ) OR EZlic_LicenceIdent.licDataType;
			SysMemCpy(ADR( dataWiteToFile ), ADR( dataMainToFileELC1 ), freeDataSize );
			(* SysMemCpy(ADR(dataWiteToFile) + freeDataSize, ADR(encTest), SIZEOF(encTest)); *)
			SysMemCpy(ADR(dataWiteToFile) + freeDataSize, ADR( dataToFile_10_10), SIZEOF( dataToFile_10_10));
			cryptDataSize := DINT_TO_UINT( EzLic_p78ou3_CryptoData.aesRetVal );
		ELSE
			(* chyba pri sifrovani *)
			fEz_CreateLicenceFile := fEz_SetRetData(cEzLic_p78ou3_error_crypto, EzLic_p78ou3_CryptoData.aesRetVal);
			RETURN;
		END_IF;
	ELSE
		(* neznamy prefix licencniho souboru *)
		fEz_CreateLicenceFile := fEz_SetRetData(cEzLic_p78ou3_error_prefix, 1);
		RETURN;
END_CASE;

IF EZlic_sourceLicenceData.enInit THEN
	(* smazani vsech souboru v adresari licenci - pro vsechny verze licencnich souboru STEJNE *)
	sdDirHandle := SysDirOpen( EzLic_p78ou3_licencfilepath );
	WHILE SysDirRead(sdDirHandle, dirFileName, ADR( dirInfo ) ) > 0 DO
		IF NOT dirInfo.bDirectory THEN
			dirFilePath := CONCAT( EzLic_p78ou3_licencfilepath, dirFileName );
			SysFileDelete( dirFilePath );
		END_IF;
	END_WHILE;
ELSE
	(* smazani pouze aktualini licence *)
	SysFileDelete( EZlic_licenceFilePath );
END_IF;

(* zapsani souboru licence na SD kartu - pro vsechny verze licencnich souboru STEJNE *)
fullDataSize := freeDataSize + cryptDataSize;
sdFileHandle := SysFileOpen( EZlic_licenceFilePath, 'w');
IF sdFileHandle > 0 THEN
	retDataCount := SysFileWrite( sdfileHandle, ADR( dataWiteToFile ), fullDataSize );
	SysFileClose( sdFileHandle );
	IF retDataCount <> fullDataSize THEN
		(* chyba pri zapisu licence *)
		fEz_CreateLicenceFile := fEz_SetRetData(cEzLic_p78ou3_error_write, 0);
		RETURN;
	END_IF;
END_IF;

(* korektne vygenerovany soubor licenci *)
fEz_CreateLicenceFile := fEz_SetRetData(cEzLic_p78ou3_error_no, 0);
fEz_CreateLicenceFile.isDone := TRUE;



---------------------------------------------- funkcni --------------------------------------
(*
funkce:
	- nacte SD kartu a dekoduje informace CID, CSD
	- vygeneruje jmena a hesla
	- vytvori soubor licence
*)

fEz_CreateLicenceFile.isDone := FALSE;

(* nacteni CID a CSD informaci SD karty - pro vsechny verze licencnich souboru STEJNE *)
fEz_CreateLicenceFile := fEz_ReadSD( cEzLic_p78ou3_sdinfofilepath );
IF fEz_CreateLicenceFile.retCode > 0 THEN
	RETURN;
END_IF;

(* nastaveni dat licence *)
EZlic_LicenceIdent.licPrefixType := SHR( EZlic_sourceLicenceData.licType, 12 );
EZlic_LicenceIdent.licHeaderType := ( SHR( EZlic_sourceLicenceData.licType, 8 ) AND 16#000F );
EZlic_LicenceIdent.licDataType := ( SHR( EZlic_sourceLicenceData.licType, 4 ) AND 16#000F );
EZlic_LicenceIdent.licSubType := SHL(EZlic_LicenceIdent.licHeaderType, 8) OR EZlic_LicenceIdent.licDataType;
EZlic_LicenceIdent.licIDType := EZlic_sourceLicenceData.licType AND 16#000F;

(* kontrola a nastaveni postfixu *)
IF EZlic_sourceLicenceData.licPostfix > 9 THEN
	EZlic_sourceLicenceData.licPostfix := 0;
END_IF;
licencePostfix := BYTE_TO_STRING( EZlic_sourceLicenceData.licPostfix );
EZlic_sourceLicenceData.licPostfixIdent := RIGHT( licencePostfix, 1 );

(* vygenerovani jmena licencniho souboru *)
fEz_CreateLicenceFile := fEz_GetLicenceFileName( EZlic_LicenceIdent.licIDType, EZlic_sourceLicenceData.licPostfix, EZlic_licenceFilePath, generation);
IF fEz_CreateLicenceFile.retCode > 0 THEN
	RETURN;
END_IF;

(* nastaveni dat licence *)
CASE EZlic_LicenceIdent.licHeaderType OF
	cEzLic_p78ou3_HeaderType_10:	(* hlavicka licence verze 1.0 *)
			CASE EZlic_LicenceIdent.licDataType OF
				cEzLic_p78ou3_DataType_10: (* verze licencnich dat 1.0 *)
						(* hlavicka licence *)
						dataToFile_10_10.id.version := 10;
						dataToFile_10_10.id.cardSize := EzLic_p78ou3_SD_Data.cardSize;
						CASE EZlic_LicenceIdent.licIDType OF
							cEzLic_p78ou3_IDType_DDTS: (* ddts *)
									mainLicDescription := 'ddts ';
							cEzLic_p78ou3_IDType_EOVOSV: (* eov, osv *)
									mainLicDescription := 'eov, osv ';
							ELSE
									mainLicDescription := 'neznama app ';
						END_CASE;
						mainLicDescription := CONCAT( mainLicDescription, EZlic_sourceLicenceData.licPostfixIdent );
						mainLicDescription := CONCAT( mainLicDescription, ' => ' );
						(* data licence *)
						dataToFile_10_10.header.licVersion := 10;
						dataToFile_10_10.header.licType := WORD_TO_BYTE( EZlic_LicenceIdent.licIDType );
						dataToFile_10_10.header.licDate := DT_TO_DATE( SysRtcGetTime(TRUE) );
						dataToFile_10_10.header.licDescription1 := EZlic_sourceLicenceData.licDescription1;
						dataToFile_10_10.header.licDescription2 := EZlic_sourceLicenceData.licDescription2;
						mainLicDescription := CONCAT( mainLicDescription, dataToFile_10_10.header.licDescription1 );
						mainLicDescription := CONCAT( mainLicDescription, ' [' );
						mainLicDescription := CONCAT( mainLicDescription, dataToFile_10_10.header.licDescription2 );
						mainLicDescription := CONCAT( mainLicDescription, ']' );
						CASE EZlic_LicenceIdent.licIDType OF
							cEzLic_p78ou3_IDType_EOVOSV: (* eov, osv *)
									IF generation = 1 THEN
										dataToFile_10_10.header.licCount := 1;
										dataToFile_10_10.items[0].licCount := 65535;
										dataToFile_10_10.items[0].protoId := cEzLic_p78ou3_CheckLicNumberId_EOV1;
										dataToFile_10_10.items[0].data1 := cEzLic_p78ou3_CheckLicNumber_EOV1;
									ELSE
										dataToFile_10_10.header.licCount := 1;
										dataToFile_10_10.items[1].licCount := 65535;
										dataToFile_10_10.items[1].protoId := cEzLic_p78ou3_CheckLicNumberId_EOV1;
										dataToFile_10_10.items[1].data1 := cEzLic_p78ou3_CheckLicNumber_EOV1;
									END_IF;
						END_CASE;
						(* parametry pro sifrovani a zapis do souboru *)
						EzLic_p78ou3_CryptoData.cryptDataAddress := ADR( dataToFile_10_10 );
						EzLic_p78ou3_CryptoData.cryptDataSize := SIZEOF( dataToFile_10_10 );
						(*nastaveni id souboru a vypocet CRC pro hlavicky a licencnich dat *)
						dataToFile_10_10.id.version := 10;
						dataToFile_10_10.crc := fEz_crc16( ADR( dataToFile_10_10 ), SIZEOF( dataToFile_10_10 ) - SIZEOF( dataToFile_10_10.crc ) );
			ELSE
				(* neznama verze licencnich dat *)
				fEz_CreateLicenceFile := fEz_SetRetData(cEzLic_p78ou3_error_data, 1);
				RETURN;
			END_CASE;
	ELSE
		(* neznama verze hlavicky kriptovanych dat *)
		fEz_CreateLicenceFile := fEz_SetRetData(cEzLic_p78ou3_error_header, 1);
		RETURN;
END_CASE;

(* inicializace Ckryptovacich algoritmu, Vektoru a klice *)
fEz_CreateLicenceFile := fEz_InitCrypto(EZlic_LicenceIdent.licIDType);
IF fEz_CreateLicenceFile.retCode > 0 THEN
	RETURN;
END_IF;

(* zpracovani dat licencniho souboru [sifrovani, podpis, komprese, ...] *)
CASE EZlic_LicenceIdent.licPrefixType OF
	cEzLic_p78ou3_LicPrefixType_ELC1: (* typ1 = pouze zasifrovani dat *)
		freeDataSize := SIZEOF( dataMainToFileELC1 );
		EzLic_p78ou3_CryptoData.aesRetVal := WCRYPTO_fAesEncrypt(
											pabPlain := EzLic_p78ou3_CryptoData.cryptDataAddress,
											diPlainLen := EzLic_p78ou3_CryptoData.cryptDataSize,
											sCipher := cEzLic_p78ou3_CipherAES,
											pIv := ADR(EzLic_p78ou3_CryptoData.aesInitVector),
											diIvLen := SIZEOF(EzLic_p78ou3_CryptoData.aesInitVector),
											pKey := ADR(EzLic_p78ou3_CryptoData.aesKey),
											diKeyLen := SIZEOF(EzLic_p78ou3_CryptoData.aesKey),
											pabCiphered := ADR( dataWiteToFile ) + freeDataSize,
											diCipheredLen := SIZEOF( dataWiteToFile ) - freeDataSize );

		IF EzLic_p78ou3_CryptoData.aesRetVal > 0 THEN
			SysMemSet( ADR( dataMainToFileELC1.licHeader.description ), 0, SIZEOF( dataMainToFileELC1.licHeader.description ) );
			dataMainToFileELC1.prefix := 16#31434C45;
			SysMemCpy( ADR( dataMainToFileELC1.licHeader.description ), ADR( mainLicDescription ), LEN( mainLicDescription ) );
			dataMainToFileELC1.licHeader.sizeData := EzLic_p78ou3_CryptoData.aesRetVal;
			dataMainToFileELC1.licHeader.licType := WORD_TO_BYTE( EZlic_LicenceIdent.licIDType );
			dataMainToFileELC1.licHeader.licSubType := SHL( EZlic_LicenceIdent.licHeaderType, 8 ) OR EZlic_LicenceIdent.licDataType;
			SysMemCpy(ADR( dataWiteToFile ), ADR( dataMainToFileELC1 ), freeDataSize );
			cryptDataSize := DINT_TO_UINT( EzLic_p78ou3_CryptoData.aesRetVal );
		ELSE
			(* chyba pri sifrovani *)
			fEz_CreateLicenceFile := fEz_SetRetData(cEzLic_p78ou3_error_crypto, EzLic_p78ou3_CryptoData.aesRetVal);
			RETURN;
		END_IF;
	ELSE
		(* neznamy prefix licencniho souboru *)
		fEz_CreateLicenceFile := fEz_SetRetData(cEzLic_p78ou3_error_prefix, 1);
		RETURN;
END_CASE;

IF EZlic_sourceLicenceData.enInit THEN
	(* smazani vsech souboru v adresari licenci - pro vsechny verze licencnich souboru STEJNE *)
	sdDirHandle := SysDirOpen( EzLic_p78ou3_licencfilepath );
	WHILE SysDirRead(sdDirHandle, dirFileName, ADR( dirInfo ) ) > 0 DO
		IF NOT dirInfo.bDirectory THEN
			dirFilePath := CONCAT( EzLic_p78ou3_licencfilepath, dirFileName );
			SysFileDelete( dirFilePath );
		END_IF;
	END_WHILE;
ELSE
	(* smazani pouze aktualini licence *)
	SysFileDelete( EZlic_licenceFilePath );
END_IF;

(* zapsani souboru licence na SD kartu - pro vsechny verze licencnich souboru STEJNE *)
fullDataSize := freeDataSize + cryptDataSize;
sdFileHandle := SysFileOpen( EZlic_licenceFilePath, 'w');
IF sdFileHandle > 0 THEN
	retDataCount := SysFileWrite( sdfileHandle, ADR( dataWiteToFile ), fullDataSize );
	SysFileClose( sdFileHandle );
	IF retDataCount <> fullDataSize THEN
		(* chyba pri zapisu licence *)
		fEz_CreateLicenceFile := fEz_SetRetData(cEzLic_p78ou3_error_write, 0);
		RETURN;
	END_IF;
END_IF;

(* korektne vygenerovany soubor licenci *)
fEz_CreateLicenceFile := fEz_SetRetData(cEzLic_p78ou3_error_no, 0);
fEz_CreateLicenceFile.isDone := TRUE;
----------------------------------------------------