upravy opravy
This commit is contained in:
@@ -20,9 +20,19 @@ const BYTE cnibblescount = 32;
|
|||||||
|
|
||||||
const string cidFilePath = "";
|
const string cidFilePath = "";
|
||||||
|
|
||||||
|
struct SDCardInfo
|
||||||
|
{
|
||||||
|
uint32_t cardSize {};
|
||||||
|
uint32_t serialNumber {};
|
||||||
|
string date = "";
|
||||||
|
uint8_t manufacturerID {};
|
||||||
|
char oemID[2] = {};
|
||||||
|
char name[5] = {};
|
||||||
|
bool isLoaded = false;
|
||||||
|
};
|
||||||
|
|
||||||
class SDCard
|
class SDCard
|
||||||
{
|
{
|
||||||
|
|
||||||
struct SDCardData
|
struct SDCardData
|
||||||
{
|
{
|
||||||
uint8_t isCorrectLoad = 0; // SD karta je korektne nactena //bool vs byte ?
|
uint8_t isCorrectLoad = 0; // SD karta je korektne nactena //bool vs byte ?
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <map>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -51,9 +52,9 @@ enum class GeneralError
|
|||||||
|
|
||||||
enum class ELCType
|
enum class ELCType
|
||||||
{
|
{
|
||||||
ELC1 = 1, //starý původní licenční soubor
|
ELC1 = 1, //starý původní licenční soubor zalozený na CID a CSD
|
||||||
ELC2 = 2, //modifikovaný starý licenční soubor umoznující modifikace dle paramatetrů
|
ELC2 = 2, //modifikovaný starý licenční soubor umoznující modifikace (šifrování, název) dle parametrů
|
||||||
ELC3 = 3 //budoucí softwarový licenční soubor, který není zalození na existenci CID a CSD
|
ELC3 = 3 //budoucí softwarový licenční soubor, který není zalozený na existenci CID a CSD, ale na unikátním ID instalace linuxu
|
||||||
};
|
};
|
||||||
enum class ELCSubType
|
enum class ELCSubType
|
||||||
{
|
{
|
||||||
@@ -110,7 +111,6 @@ struct LicenceIdentification
|
|||||||
LicenceType licLicenceType;
|
LicenceType licLicenceType;
|
||||||
string licTypeName = "";
|
string licTypeName = "";
|
||||||
PlcType licPlcType;
|
PlcType licPlcType;
|
||||||
|
|
||||||
uint8_t licenceVersion = 1; // verze licence, určuje kodování, pojmenování souborů
|
uint8_t licenceVersion = 1; // verze licence, určuje kodování, pojmenování souborů
|
||||||
uint8_t licenceIndex = 0; //index licenčního souboru v případě, ze jich je víc
|
uint8_t licenceIndex = 0; //index licenčního souboru v případě, ze jich je víc
|
||||||
uint8_t revision;
|
uint8_t revision;
|
||||||
@@ -123,15 +123,14 @@ struct LicenceIdentification
|
|||||||
/// @brief obecná struktura pro reader
|
/// @brief obecná struktura pro reader
|
||||||
struct LicenceInfoGeneral
|
struct LicenceInfoGeneral
|
||||||
{
|
{
|
||||||
int reqDataPointsCount = 0;
|
map<DWORD, DWORD> licences = {};
|
||||||
unordered_map<int, int> licences = {};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief obecná struktura polozky licence, defaultní kompatibilita
|
/// @brief obecná struktura polozky licence, defaultní kompatibilita
|
||||||
struct LicenceItem
|
struct LicenceItem
|
||||||
{
|
{
|
||||||
int protocolId = -1;
|
DWORD protocolId {};
|
||||||
int dataPointsCount = 0;
|
DWORD dataPointsCount {};
|
||||||
};
|
};
|
||||||
|
|
||||||
/* struktury pro ELC 1 */
|
/* struktury pro ELC 1 */
|
||||||
@@ -159,26 +158,26 @@ struct LicenceELC1Item
|
|||||||
//defaultní struktura pro ELC 2
|
//defaultní struktura pro ELC 2
|
||||||
struct LicenceELC2Info
|
struct LicenceELC2Info
|
||||||
{
|
{
|
||||||
unordered_map<int, int> licences = {};
|
map<DWORD, DWORD> licences = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LicenceELC2Info_1
|
// struct LicenceELC2Info_1
|
||||||
{
|
// {
|
||||||
unordered_map<int, int> licences = {};
|
// map<int, int> licences = {};
|
||||||
};
|
// };
|
||||||
|
|
||||||
//defaultni struktura polozky ELC 2
|
//defaultni struktura polozky ELC 2
|
||||||
struct LicenceELC2Item
|
struct LicenceELC2Item
|
||||||
{
|
{
|
||||||
int protocolId = -1;
|
DWORD protocolId {};
|
||||||
int dataPointsCount = 0;
|
DWORD dataPointsCount {};
|
||||||
};
|
};
|
||||||
|
|
||||||
//struktura polozky ELC 2,
|
//struktura polozky ELC 2,
|
||||||
struct LicenceELC2Item_1
|
struct LicenceELC2Item_1
|
||||||
{
|
{
|
||||||
int protocolId = -1;
|
DWORD protocolId {};
|
||||||
int dataPointsCount = 0;
|
DWORD dataPointsCount {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -29,22 +29,21 @@ public:
|
|||||||
// struct __attribute__((__packed__)) LicencePublicHeader
|
// struct __attribute__((__packed__)) LicencePublicHeader
|
||||||
struct LicenceIdentDataHeader
|
struct LicenceIdentDataHeader
|
||||||
{
|
{
|
||||||
BYTE licenceType = 0; // EOSEOV, DRT ...
|
BYTE licenceType {}; // EOSEOV, DRT ...
|
||||||
BYTE licenceTypeVersion = 1; // verze licence, urcuje nuance sifrování a pojmenování souborů
|
BYTE licenceTypeVersion = 1; // verze licence, urcuje nuance sifrování a pojmenování souborů
|
||||||
BYTE licenceIndex = 0; // puvodní post fix, identifikátor pro více licencí
|
BYTE licenceIndex {}; // puvodní post fix, identifikátor pro více licencí
|
||||||
BYTE compatibilityVersion = 1; // udava verzi komplet PrivateContent
|
BYTE compatibilityVersion = 1; // udava verzi komplet PrivateContent
|
||||||
BYTE licItemCount = 0; // počet licenčních bodů
|
BYTE licItemCount {}; // počet protokolů v linenci
|
||||||
WORD publicHeaderLength = 0; // délka veřejné hlavičy
|
WORD publicHeaderLength {}; // délka veřejné hlavičy
|
||||||
WORD cardSize = 0; // velikost SD karty
|
WORD cardSize {}; // velikost SD karty
|
||||||
DWORD serialNumber = 0; // seriove cislo karty
|
DWORD serialNumber = {}; // seriove cislo karty
|
||||||
};
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
struct licDataItem
|
struct licDataItem
|
||||||
{
|
{
|
||||||
WORD protoId = 0; // id protokolu pro ktery je licence
|
DWORD protoId {}; // id protokolu pro ktery je licence
|
||||||
WORD licCount = 0; // pocet datovych bodu licence
|
DWORD licCount {}; // pocet datovych bodu licence
|
||||||
char dummy[64] = {}; // dummy pro větší velikost licence v případě méně licenčních bodů
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PublicHeader
|
struct PublicHeader
|
||||||
@@ -57,22 +56,22 @@ public:
|
|||||||
|
|
||||||
struct PrivateContent // privátní šifrovaná část
|
struct PrivateContent // privátní šifrovaná část
|
||||||
{
|
{
|
||||||
LicenceIdentDataHeader licenceIdentHeader;
|
LicenceIdentDataHeader licenceIdentHeader {};
|
||||||
vector<licDataItem> dataItems;
|
vector<licDataItem> dataItems {};
|
||||||
WORD crc = 0;
|
WORD crc {};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LicenceBody
|
struct LicenceBody
|
||||||
{
|
{
|
||||||
LicenceId licId;
|
LicenceId licId {};
|
||||||
LicenceIdentDataHeader licenceIdentHeader;
|
LicenceIdentDataHeader licenceIdentHeader {};
|
||||||
string publicHeader = ""; // JSON
|
string publicHeader = ""; // JSON
|
||||||
PrivateContent privateContent;
|
PrivateContent privateContent {};
|
||||||
};
|
};
|
||||||
|
|
||||||
LicenceBody licBody;
|
LicenceBody licBody {};
|
||||||
SDCard sdCard;
|
SDCard sdCard {};
|
||||||
LicenceIdentification lIdentification;
|
LicenceIdentification lIdentification {};
|
||||||
vector<unsigned char> cryptPrivateContent(const std::vector<unsigned char> &content);
|
vector<unsigned char> cryptPrivateContent(const std::vector<unsigned char> &content);
|
||||||
vector<unsigned char> decryptPrivateContent(const std::vector<unsigned char> &content);
|
vector<unsigned char> decryptPrivateContent(const std::vector<unsigned char> &content);
|
||||||
void initVector(BYTE (&iVector)[], BYTE (&key)[]);
|
void initVector(BYTE (&iVector)[], BYTE (&key)[]);
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
#ifndef LICENCE_GENERATOR_H_
|
#ifndef LICENCE_GENERATOR_H_
|
||||||
#define LICENCE_GENERATOR_H_
|
#define LICENCE_GENERATOR_H_
|
||||||
|
|
||||||
|
#define DEFAULT_LICENCE_POINTS_COUNT = 4294967295 //počet licenčních bodů pro některé protokoly např: pt_Ez_buffer a pt_Ez_webs
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "pugixml.hpp"
|
#include "pugixml.hpp"
|
||||||
#include "licenceCommon.h"
|
#include "licenceCommon.h"
|
||||||
// #include "licenceELC11.h"
|
|
||||||
// #include "licenceELC21.h"
|
|
||||||
// #include "licenceELC31.h"
|
|
||||||
|
|
||||||
#include "licGenELC1.h"
|
#include "licGenELC1.h"
|
||||||
#include "licGenELC2.h"
|
#include "licGenELC2.h"
|
||||||
@@ -33,16 +32,17 @@ public:
|
|||||||
pugi::xml_document *doc;
|
pugi::xml_document *doc;
|
||||||
};
|
};
|
||||||
|
|
||||||
LicData licData;
|
LicData licData {};
|
||||||
int elcSwitchType;
|
int elcSwitchType {};
|
||||||
string operationErrors = "";
|
string operationErrors = "";
|
||||||
pugi::xml_document doc;
|
pugi::xml_document doc {} ;
|
||||||
bool argumentsCorrect = false;
|
bool argumentsCorrect = false;
|
||||||
ErrorMessage error;
|
ErrorMessage error {};
|
||||||
// LicenceELC11 *licence11;
|
// LicenceELC11 *licence11;
|
||||||
// LicenceELC21 *licence21;
|
// LicenceELC21 *licence21;
|
||||||
// LicenceELC31 *licence31;
|
// LicenceELC31 *licence31;
|
||||||
Mapping mapping;
|
Mapping mapping {};
|
||||||
|
SDCard sdCard {};
|
||||||
|
|
||||||
LicenceGenerator();
|
LicenceGenerator();
|
||||||
~LicenceGenerator();
|
~LicenceGenerator();
|
||||||
@@ -50,7 +50,7 @@ public:
|
|||||||
|
|
||||||
void createLicenceFile();
|
void createLicenceFile();
|
||||||
|
|
||||||
LicenceInfoGeneral licenceInfo;
|
LicenceInfoGeneral licenceInfo {};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LicenceIdentification licIdentification;
|
LicenceIdentification licIdentification;
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ namespace Reader
|
|||||||
|
|
||||||
bool readLicence(LicenceInfoGeneral *licences);
|
bool readLicence(LicenceInfoGeneral *licences);
|
||||||
bool getLicenceInfo(void *ptr);
|
bool getLicenceInfo(void *ptr);
|
||||||
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
|
|
||||||
void getLicenceItems();
|
void getLicenceItems();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define LICENCE_READER_H_
|
#define LICENCE_READER_H_
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "SDCard.h"
|
||||||
#include "licReaderELC1.h"
|
#include "licReaderELC1.h"
|
||||||
#include "licReaderELC2.h"
|
#include "licReaderELC2.h"
|
||||||
#include "licReaderELC3.h"
|
#include "licReaderELC3.h"
|
||||||
@@ -28,24 +29,22 @@ public:
|
|||||||
string operationErrors = "";
|
string operationErrors = "";
|
||||||
bool argumentsCorrect = false;
|
bool argumentsCorrect = false;
|
||||||
ErrorMessage error;
|
ErrorMessage error;
|
||||||
Licence2 *licence2;
|
|
||||||
Licence1 *licence1;
|
|
||||||
|
|
||||||
|
SDCardInfo sdCardInfo {};
|
||||||
|
|
||||||
LicenceReader();
|
LicenceReader();
|
||||||
~LicenceReader();
|
~LicenceReader();
|
||||||
bool init(int elcType, InitStructure &initStructure);
|
bool init(int elcType, InitStructure &initStructure);
|
||||||
bool initread(int elcType, InitStructure &initStructure);
|
bool initread(int elcType, InitStructure &initStructure);
|
||||||
bool getLicenceInfo(void *returnStructure);
|
bool getLicenceInfo(void *returnStructure); //vrací informace o všech licenčních bodech základě předané návratové struktury
|
||||||
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
|
bool getLicenceItemInfo(int protocolId, void *returnItemStructure); //vrací informace o licenčím bodu na základě id protocolu a předané návratové struktury
|
||||||
|
LicenceInfoGeneral licenceInfo {}; //pole licencí
|
||||||
LicenceInfoGeneral licenceInfo;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LicenceIdentification licIdentification;
|
Licence2 *licence2 {}; //interní struktura pro zpracování licence ELC2
|
||||||
|
Licence1 *licence1 {}; //interní struktura pro zpracování licence ELC1
|
||||||
|
LicenceIdentification licIdentification {};
|
||||||
string configFileName = "";
|
string configFileName = "";
|
||||||
void *licence = nullptr;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
BIN
output/ezlic_drt0_jjacdgpdxpb.lic
Normal file
BIN
output/ezlic_drt0_jjacdgpdxpb.lic
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,29 +1,44 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<licence elc="2" xmlVersion="1" revision="1" compatibility="1">
|
<licence elc="2" xmlVersion="1" revision="1" compatibility="1">
|
||||||
<licenceType licenceVersion="1" licenceIndex="0">EOV_OSV</licenceType>
|
<licenceType licenceVersion="1" licenceIndex="0">DRT</licenceType>
|
||||||
<plcType>wago</plcType>
|
<plcType>wago</plcType>
|
||||||
<licenceName>Licence pro EOV_OSV</licenceName>
|
<licenceName>Licence pro EOV_OSV</licenceName>
|
||||||
<project>testovaci projekt</project>
|
<project>Zdenda Test CRC1</project>
|
||||||
<items>
|
<items>
|
||||||
<item>
|
<item>
|
||||||
|
<name>pt_Ez_interHW</name>
|
||||||
|
<protoId>2</protoId>
|
||||||
|
<dataPointsCount>22</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>pt_Ez_iec61850c</name>
|
||||||
|
<protoId>7</protoId>
|
||||||
|
<dataPointsCount>77</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>pt_Ez_buffer</name>
|
||||||
|
<protoId>1</protoId>
|
||||||
|
<dataPointsCount>4294967295</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>pt_Ez_mdbrtum</name>
|
||||||
|
<protoId>15</protoId>
|
||||||
|
<dataPointsCount>150</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
<name>pt_Ez_iec104c</name>
|
<name>pt_Ez_iec104c</name>
|
||||||
<protoId>5</protoId>
|
<protoId>5</protoId>
|
||||||
<dataPointsCount>2500</dataPointsCount>
|
<dataPointsCount>55</dataPointsCount>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<name>pt_Ez_iec104s</name>
|
<name>pt_Ez_iec104s</name>
|
||||||
<protoId>6</protoId>
|
<protoId>6</protoId>
|
||||||
<dataPointsCount>15000</dataPointsCount>
|
<dataPointsCount>66</dataPointsCount>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<name>pt_Ez_mdbipc</name>
|
<name>pt_Ez_webs</name>
|
||||||
<protoId>9</protoId>
|
<protoId>2</protoId>
|
||||||
<dataPointsCount>250</dataPointsCount>
|
<dataPointsCount>4294967295</dataPointsCount>
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<name>pt_Ez_mdbips</name>
|
|
||||||
<protoId>10</protoId>
|
|
||||||
<dataPointsCount>400</dataPointsCount>
|
|
||||||
</item>
|
</item>
|
||||||
</items>
|
</items>
|
||||||
</licence>
|
</licence>
|
||||||
@@ -1,27 +1,45 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<licence elc="2" xmlVersion="1" revision="1" compatibility="1">
|
<licence elc="2" xmlVersion="1" revision="1" compatibility="1">
|
||||||
<licenceType licenceVersion="1" licenceIndex="0">EOV_OSV</licenceType>
|
<licenceType licenceVersion="1" licenceIndex="0">DRT</licenceType>
|
||||||
<plcType>WAGO</plcType>
|
<plcType>wago</plcType>
|
||||||
<licenceName>Licence pro EOV_OSV</licenceName>
|
<licenceName>Licence pro EOV_OSV</licenceName>
|
||||||
<station>odb.zaluzi.drt.cz</station>
|
<project>Zdenda Test CRC1</project>
|
||||||
<distributor>POZ8</distributor>
|
|
||||||
<project>Projekt XXX stanice YYY</project>
|
|
||||||
<items>
|
<items>
|
||||||
<item>
|
<item>
|
||||||
<name>Položka licence 1</name>
|
<name>pt_Ez_buffer</name>
|
||||||
<protoId>111</protoId>
|
<protoId>1</protoId>
|
||||||
<dataPointsCount>40000</dataPointsCount>
|
<dataPointsCount>4294967295</dataPointsCount>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<name>Položka licence 2</name>
|
<name>pt_Ez_webs</name>
|
||||||
<protoId>222</protoId>
|
<protoId>2</protoId>
|
||||||
<dataPointsCount>51000</dataPointsCount>
|
<dataPointsCount>555</dataPointsCount>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<name>Položka licence 3</name>
|
<name>pt_Ez_iec61850c</name>
|
||||||
<protoId>333</protoId>
|
<protoId>14</protoId>
|
||||||
<dataPointsCount>62000</dataPointsCount>
|
<dataPointsCount>222</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>pt_Ez_iec104c</name>
|
||||||
|
<protoId>9</protoId>
|
||||||
|
<dataPointsCount>333</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>pt_Ez_interHW</name>
|
||||||
|
<protoId>0</protoId>
|
||||||
|
<dataPointsCount>3</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>pt_Ez_iec104s</name>
|
||||||
|
<protoId>8</protoId>
|
||||||
|
<dataPointsCount>444</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>TEST</name>
|
||||||
|
<protoId>20</protoId>
|
||||||
|
<dataPointsCount>4444</dataPointsCount>
|
||||||
</item>
|
</item>
|
||||||
</items>
|
|
||||||
|
|
||||||
|
</items>
|
||||||
</licence>
|
</licence>
|
||||||
Binary file not shown.
BIN
output/temp/ezlic_drt0_jjacdgpdxpb.lic
Normal file
BIN
output/temp/ezlic_drt0_jjacdgpdxpb.lic
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
output/temp/tempBeforeDword/generate/licenceGenerator
Normal file
BIN
output/temp/tempBeforeDword/generate/licenceGenerator
Normal file
Binary file not shown.
BIN
output/temp/tempBeforeDword/read/licenceGenerator
Normal file
BIN
output/temp/tempBeforeDword/read/licenceGenerator
Normal file
Binary file not shown.
@@ -8,7 +8,7 @@
|
|||||||
/// @param argc
|
/// @param argc
|
||||||
/// @param argv parametry pro generování licence
|
/// @param argv parametry pro generování licence
|
||||||
/// @return
|
/// @return
|
||||||
int main5(int argc, char *argv[])
|
int main6(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unordered_map<string, string> arguments = getArguments(argc, argv);
|
unordered_map<string, string> arguments = getArguments(argc, argv);
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -9,11 +9,12 @@
|
|||||||
/// @return
|
/// @return
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
// buffer,850client,104client, 104server, web
|
||||||
|
// kouknout na unikatní klíc pro linux
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
InitStructure initStructure;
|
InitStructure initStructure = {};
|
||||||
initStructure.licenceType = (int)LicenceType::EOS_EOV;
|
initStructure.licenceType = (int)LicenceType::DRT;
|
||||||
initStructure.licenceVersion = 1;
|
initStructure.licenceVersion = 1;
|
||||||
initStructure.licenceIndex = 0;
|
initStructure.licenceIndex = 0;
|
||||||
initStructure.licenceFilePath = ""; // cesta k licenčnímu souboru
|
initStructure.licenceFilePath = ""; // cesta k licenčnímu souboru
|
||||||
@@ -22,24 +23,26 @@ int main()
|
|||||||
initStructure.cid_csd_filePath = ""; // cesta k cidu/csd pro načtení a kontrolu licence
|
initStructure.cid_csd_filePath = ""; // cesta k cidu/csd pro načtení a kontrolu licence
|
||||||
|
|
||||||
// verze původní ELC 1
|
// verze původní ELC 1
|
||||||
LicenceReader licenceReaderELC1{};
|
// LicenceReader licenceReaderELC1{};
|
||||||
if (licenceReaderELC1.initread(1, initStructure)) // iniciacni nacteni
|
// if (licenceReaderELC1.initread(1, initStructure)) // iniciacni nacteni
|
||||||
{
|
// {
|
||||||
LicenceELC1Info info; // struktura pro ELC1. Nemá tam asi nic jiného smysl nez true/false
|
// LicenceELC1Info info; // struktura pro ELC1. Nemá tam asi nic jiného smysl nez true/false
|
||||||
if (licenceReaderELC1.getLicenceInfo(&info))
|
// if (licenceReaderELC1.getLicenceInfo(&info))
|
||||||
{
|
// {
|
||||||
if (info.isValid)
|
// if (info.isValid)
|
||||||
cout << "Platna licence ELC1 \n";
|
// cout << "Platna licence ELC1 \n";
|
||||||
else
|
// else
|
||||||
cout << "Neplatna licence ELC1\n";
|
// cout << "Neplatna licence ELC1\n";
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
cout << "CHYBA: " << licenceReaderELC1.error.message;
|
// cout << "CHYBA: " << licenceReaderELC1.error.message;
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
cout << "CHYBA: " << licenceReaderELC1.error.message;
|
// cout << "CHYBA: " << licenceReaderELC1.error.message;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
//TODO přidat udaje o SD, kompatibilita, čas, jmeno licenčního souboru
|
||||||
|
|
||||||
// verze ELC 2 pro jeden protokol
|
// verze ELC 2 pro jeden protokol
|
||||||
LicenceReader licenceReaderELC2{};
|
LicenceReader licenceReaderELC2{};
|
||||||
@@ -50,7 +53,11 @@ int main()
|
|||||||
// Tedy pro ELC1 to bude LicenceELC1_1, pro ELC LicenceELC2_1
|
// Tedy pro ELC1 to bude LicenceELC1_1, pro ELC LicenceELC2_1
|
||||||
LicenceELC2Item info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31)
|
LicenceELC2Item info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31)
|
||||||
// if ()
|
// if ()
|
||||||
int protocolId = 333;
|
int protocolId = 2;
|
||||||
|
//ukayka dat SD karty
|
||||||
|
cout << "SD přečteno: " << licenceReaderELC2.sdCardInfo.isLoaded << "\n";
|
||||||
|
cout << "Card size: " << licenceReaderELC2.sdCardInfo.cardSize << "\n";
|
||||||
|
cout << "serial: " << licenceReaderELC2.sdCardInfo.serialNumber << "\n";
|
||||||
|
|
||||||
// if (initStructure.compatibility == 1) //ukazka kompatibilita 1
|
// if (initStructure.compatibility == 1) //ukazka kompatibilita 1
|
||||||
// {
|
// {
|
||||||
@@ -62,24 +69,26 @@ int main()
|
|||||||
//...........
|
//...........
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
//TODO toto upravit, kdyz nic neexistuje, tak to vrátí false
|
||||||
if (licenceReaderELC2.getLicenceItemInfo(protocolId, &info))
|
if (licenceReaderELC2.getLicenceItemInfo(protocolId, &info))
|
||||||
{
|
{
|
||||||
cout << "Pocet licencních bodu pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
|
cout << "Pocet licencních bodu pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cout << "CHYBA: " << licenceReaderELC2.error.message;
|
cout << "Tento protokol nemá body";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cout << "CHYBA: " << licenceReaderELC2.error.message;
|
cout << "CHYBA: " << licenceReaderELC2.error.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
LicenceReader licenceReaderCompleteELC2{};
|
|
||||||
// verze ELC 2 kompletní načtení
|
// verze ELC 2 kompletní načtení
|
||||||
|
/*
|
||||||
|
LicenceReader licenceReaderCompleteELC2{};
|
||||||
if (licenceReaderCompleteELC2.init(2, initStructure)) // iniciacni nacteni
|
if (licenceReaderCompleteELC2.init(2, initStructure)) // iniciacni nacteni
|
||||||
{
|
{
|
||||||
LicenceELC2Info info;
|
LicenceELC2Info info;
|
||||||
int protocolId = 333;
|
int protocolId = 2;
|
||||||
|
|
||||||
if (licenceReaderCompleteELC2.getLicenceInfo(&info))
|
if (licenceReaderCompleteELC2.getLicenceInfo(&info))
|
||||||
{
|
{
|
||||||
@@ -87,26 +96,151 @@ int main()
|
|||||||
cout << "Pocet bodu z vectoru pro protokol : " << protocolId << ": " << info.licences.at(protocolId) << "\n";
|
cout << "Pocet bodu z vectoru pro protokol : " << protocolId << ": " << info.licences.at(protocolId) << "\n";
|
||||||
else
|
else
|
||||||
cout << "Pro tento protokol nejsou definovay licencni body\n";
|
cout << "Pro tento protokol nejsou definovay licencni body\n";
|
||||||
|
|
||||||
cout << "Vypis vsech licencnich bodu: " << endl;
|
cout << "Vypis vsech licencnich bodu: " << endl;
|
||||||
for (const auto &pair : info.licences)
|
// for (const auto &pair : info.licences)
|
||||||
{
|
// {
|
||||||
std::cout << "<" << pair.first << ", " << pair.second << ">" << endl;
|
// std::cout << "<" << pair.first << ", " << pair.second << ">" << endl;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cout << "CHYBA: " << licenceReaderCompleteELC2.error.message;
|
cout << "CHYBA: " << licenceReaderCompleteELC2.error.message;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cout << "CHYBA: " << licenceReaderCompleteELC2.error.message;
|
cout << "CHYBA: " << licenceReaderCompleteELC2.error.message;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
cout << "Obecna chyba\n";
|
cout << "Obecna chyba\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// } ] } licC hLenght2 cSize2 ser number 4
|
||||||
|
//125-93-125-1 - 1 - 0 - 1 - 6 - 163 - 1 - 231 - 59 - 197 -3 - 216 - 90 -1 -0 -0 -0 -255-255-255-255
|
||||||
|
//
|
||||||
|
//125-93-125-1 - 1 - 0 - 1 - 6 - 163 - 1 - 231 - 59 - 197 -3 - 216 - 90 -1 -0 -236 -0 -255-255-255-255
|
||||||
|
|
||||||
|
|
||||||
|
//here ŹVżz5Ž;k+3f‰"Ş•ů[ 125-93-125-1-1-0-1-6-163-1-231-59-197-3-216-90-1-0-0-0-255-255-255-255-0
|
||||||
|
//125-1-1-0-1-6-163-1-231-59-197-3-216-90-1-0-236-0-255-255-255-255-0
|
||||||
|
string gV = "69-76-67-50-95-1-1-0-1-6-163-1-231-59-197-3-216-90-123-34-118-101-114-115-105-111-110-34-58-49-46-49-46-49-34-44-34-112-114-111-106-101-99-116-34-58-34-90-100-101-110-100-97-32-84-101-115-116-32-67-82-67-49-34-44-34-100-97-116-101-34-58-34-52-46-52-46-50-48-50-52-34-44-34-110-111-116-101-34-58-34-112-111-122-110-195-161-109-107-97-34-44-34-108-105-99-101-110-99-101-84-121-112-101-34-58-34-68-82-84-48-34-44-34-105-116-101-109-115-34-58-91-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-98-117-102-102-101-114-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-52-50-57-52-57-54-55-50-57-53-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-105-101-99-54-49-56-53-48-99-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-55-55-55-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-105-101-99-49-48-52-99-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-53-53-53-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-105-101-99-49-48-52-115-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-54-54-54-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-119-101-98-115-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-52-50-57-52-57-54-55-50-57-53-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-105-110-116-101-114-72-87-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-51-34-125-93-125-1-1-0-1-6-163-1-231-59-197-3-216-90-1-0-0-0-255-255-255-255-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-7-0-0-0-9-3-0-0-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-5-0-0-0-43-2-0-0-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-6-0-0-0-154-2-0-0-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-2-0-0-0-255-255-255-255-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-0-0-0-0-3-0-0-0-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-186-165";
|
||||||
|
string bV = "69-76-67-50-95-1-1-0-1-6-163-1-231-59-197-3-216-90-123-34-118-101-114-115-105-111-110-34-58-49-46-49-46-49-34-44-34-112-114-111-106-101-99-116-34-58-34-90-100-101-110-100-97-32-84-101-115-116-32-67-82-67-49-34-44-34-100-97-116-101-34-58-34-52-46-52-46-50-48-50-52-34-44-34-110-111-116-101-34-58-34-112-111-122-110-195-161-109-107-97-34-44-34-108-105-99-101-110-99-101-84-121-112-101-34-58-34-68-82-84-48-34-44-34-105-116-101-109-115-34-58-91-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-98-117-102-102-101-114-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-52-50-57-52-57-54-55-50-57-53-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-105-101-99-54-49-56-53-48-99-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-55-55-55-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-105-101-99-49-48-52-99-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-53-53-53-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-105-101-99-49-48-52-115-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-54-54-54-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-119-101-98-115-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-52-50-57-52-57-54-55-50-57-53-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-105-110-116-101-114-72-87-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-51-34-125-93-125-1-1-0-1-6-163-1-231-59-197-3-216-90-1-0-0-0-255-255-255-255-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-7-0-0-0-9-3-0-0-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-5-0-0-0-43-2-0-0-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-6-0-0-0-154-2-0-0-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-2-0-0-0-255-255-255-255-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-0-0-0-0-3-0-0-0-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-186-165";
|
||||||
|
|
||||||
|
// std::vector<string> gTokens;
|
||||||
|
// std::vector<string> bTokens;
|
||||||
|
// std::stringstream ssG(gV);
|
||||||
|
// std::stringstream ssB(bV);
|
||||||
|
// std::string token;
|
||||||
|
|
||||||
|
// while (getline(ssG, token, '-')) { gTokens.push_back(token); }
|
||||||
|
// while (getline(ssB, token, '-')) { bTokens.push_back(token); }
|
||||||
|
|
||||||
|
// cout << gTokens.size() << "\n";
|
||||||
|
// cout << bTokens.size() << "\n";
|
||||||
|
|
||||||
|
|
||||||
|
cout << (gV == bV) << "\n";
|
||||||
|
|
||||||
return SUCCES;
|
return SUCCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
pt_Ez_interHW, // 0 - interni virtualni typ pro urceni licence na dany HW
|
||||||
|
pt_Ez_buffer, // 1 - datovy Buffer
|
||||||
|
pt_Ez_webs, // 2 - Ez www conectivity server
|
||||||
|
pt_Ez_dblogc, // 3 - Ez database log client
|
||||||
|
pt_Ez_sysinfoc, // 4 - Systemove informace systemu
|
||||||
|
pt_Ez_iec104c, // 5 - IEC-104 client
|
||||||
|
pt_Ez_iec104s, // 6 - IEC-104 server
|
||||||
|
pt_Ez_iec61850c, // 7 - IEC-61850 client
|
||||||
|
pt_Ez_iec61850s, // 8 - IEC-61850 server
|
||||||
|
pt_Ez_mdbipc, // 9 - Modbus IP client
|
||||||
|
pt_Ez_mdbips, // 10 - Modbus IP server
|
||||||
|
pt_Ez_mdbrtum, // 11 - Modbus RTU master
|
||||||
|
pt_Ez_mdbrtul, // 12 - Modbus RTU slave
|
||||||
|
pt_Ez_mdbasciim, // 13 - Modbus ASCII master
|
||||||
|
pt_Ez_mdbasciil, // 14 - Modbus ASCII slave
|
||||||
|
pt_Ez_gsmm, // 15 - GSM master
|
||||||
|
pt_Ez_gsml, // 16 - GSM slave
|
||||||
|
pt_Ez_iec101m, // 17 - IEC-101 master
|
||||||
|
pt_Ez_iec101l, // 18 - IEC-101 slave
|
||||||
|
pt_Ez_iec103m, // 19 - IEC-103 master
|
||||||
|
pt_Ext_snmpc, // 20 - SNMP client
|
||||||
|
pt_Ext_snmps, // 21 - SNMP server
|
||||||
|
pt_Ez_siadc09c, // 22 - ANSI/SIA DC-09 client
|
||||||
|
pt_Ez_honeywellgxyc, // 23 - Honeywell Galaxy smart client
|
||||||
|
pt_Ez_contactidm, // 24 - Ademco Contact ID - SIA DC-05 master
|
||||||
|
pt_Ez_litesm, // 25 - EPS Lites master
|
||||||
|
pt_Ez_epsnetmpcc, // 26 - Tecomat Epsnet MPC client
|
||||||
|
pt_Ez_epsnetmpcs, // 27 - Tecomat Epsnet MPC server
|
||||||
|
pt_Ez_epsnetmpcm, // 28 - Tecomat Epsnet MPC master
|
||||||
|
pt_Ez_epsnetmpcl, // 29 - Tecomat Epsnet MPC slave
|
||||||
|
pt_Ez_epsnetplc, // 30 - Tecomat Epsnet PLC
|
||||||
|
pt_Ez_amitdbnetipc, // 31 - AMiT DB-Net/IP client
|
||||||
|
pt_Ez_amitdbnetm, // 32 - AMiT DB-Net master
|
||||||
|
pt_Ez_fatekm, // 33 - Fatek master
|
||||||
|
pt_Ez_canm, // 34 - CAN master
|
||||||
|
pt_Ez_iec6205621m, // 35 - IEC 62056.21 master
|
||||||
|
pt_Ez_mbusm, // 36 - MBus master
|
||||||
|
pt_Ez_azddakm, // 37 - AZD DAK master
|
||||||
|
pt_Ez_rwaytechc, // 38 - RwayTech client (modbus IP)
|
||||||
|
pt_Ez_weinteksl, // 39 - Weintek touch screen server/slave (modbus protokol)
|
||||||
|
|
||||||
|
|
||||||
|
Pro index 0 (pt_Ez_interHW) jsou možné hodnoty (počet licenčních bodů):
|
||||||
|
|
||||||
|
#define EZ_HW_TECOMAT 1
|
||||||
|
#define EZ_HW_WAGO 2
|
||||||
|
#define EZ_HW_NATIVE_LINUX 3
|
||||||
|
#define EZ_HW_NATIVE_LINUX_DOCKER 4
|
||||||
|
#define EZ_HW_ARM64_LINUX 5
|
||||||
|
#define EZ_HW_ARM64_LINUX_DOCKER 6
|
||||||
|
|
||||||
|
Pro ostatní je uveden skutečný požadovaný počet licenčních bodů pro daný protokol.
|
||||||
|
U protokolů pt_Ez_buffer a pt_Ez_webs nastavovat defaultně EZ_PROTO_INFINITE = 4294967295
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
pt_Ez_interHW, // 0 - interni virtualni typ pro urceni licence na dany HW
|
||||||
|
pt_Ez_buffer, // 1 - datovy Buffer
|
||||||
|
pt_Ez_webs, // 2 - Ez www conectivity server
|
||||||
|
pt_Ez_dblogc, // 3 - Ez database log client
|
||||||
|
pt_Ez_mdbipc, // 4 - Modbus IP client
|
||||||
|
pt_Ez_mdbips, // 5 - Modbus IP server
|
||||||
|
pt_Ext_snmpc, // 6 - SNMP client
|
||||||
|
pt_Ext_snmps, // 7 - SNMP server
|
||||||
|
pt_Ez_iec104s, // 8 - IEC-104 server
|
||||||
|
pt_Ez_iec104c, // 9 - IEC-104 client
|
||||||
|
pt_Ez_sysinfoc, // 10 - Systemove informace systemu
|
||||||
|
pt_Ez_siadc09c, // 11 - ANSI/SIA DC-09 client
|
||||||
|
pt_Ez_honeywellgxyc, // 12 - Honeywell Galaxy smart client
|
||||||
|
pt_Ez_iec61850s, // 13 - IEC-61850 server
|
||||||
|
pt_Ez_iec61850c, // 14 - IEC-61850 client
|
||||||
|
pt_Ez_mdbrtum, // 15 - Modbus RTU master
|
||||||
|
pt_Ez_mdbrtul, // 16 - Modbus RTU slave
|
||||||
|
pt_Ez_mdbasciim, // 17 - Modbus ASCII master
|
||||||
|
pt_Ez_mdbasciil, // 18 - Modbus ASCII slave
|
||||||
|
pt_Ez_epsnetmpcc, // 19 - Tecomat Epsnet MPC client
|
||||||
|
pt_Ez_epsnetmpcs, // 20 - Tecomat Epsnet MPC server
|
||||||
|
pt_Ez_epsnetmpcl, // 21 - Tecomat Epsnet MPC slave
|
||||||
|
pt_Ez_epsnetmpcm, // 22 - Tecomat Epsnet MPC master
|
||||||
|
pt_Ez_epsnetplc, // 23 - Tecomat Epsnet PLC
|
||||||
|
pt_Ez_litesm, // 24 - EPS Lites master
|
||||||
|
pt_Ez_contactidm, // 25 - Ademco Contact ID - SIA DC-05 master
|
||||||
|
pt_Ez_amitdbnetipc, // 26 - AMiT DB-Net/IP client
|
||||||
|
pt_Ez_amitdbnetm, // 27 - AMiT DB-Net master
|
||||||
|
pt_Ez_fatekm, // 28 - Fatek master
|
||||||
|
pt_Ez_canm, // 29 - CAN master
|
||||||
|
pt_Ez_iec6205621m, // 30 - IEC 62056.21 master
|
||||||
|
pt_Ez_mbusm, // 31 - MBus master
|
||||||
|
pt_Ez_gsmm, // 32 - GSM master
|
||||||
|
pt_Ez_gsml, // 33 - GSM slave
|
||||||
|
pt_Ez_iec101m, // 34 - IEC-101 master
|
||||||
|
pt_Ez_iec101l, // 35 - IEC-101 slave
|
||||||
|
pt_Ez_iec103m, // 36 - IEC-103 master
|
||||||
|
pt_Ez_azddakm, // 37 - AZD DAK master
|
||||||
|
pt_Ez_rwaytechc, // 38 - RwayTech client (modbus IP)
|
||||||
|
pt_Ez_weinteksl, // 39 - Weintek touch screen server/slave (modbus protokol)
|
||||||
|
*/
|
||||||
|
|||||||
@@ -162,7 +162,10 @@ int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char *
|
|||||||
|
|
||||||
/* Create and initialise the context */
|
/* Create and initialise the context */
|
||||||
if (!(ctx = EVP_CIPHER_CTX_new()))
|
if (!(ctx = EVP_CIPHER_CTX_new()))
|
||||||
|
{
|
||||||
|
EVP_CIPHER_CTX_free(ctx);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialise the decryption operation. IMPORTANT - ensure you use a key
|
* Initialise the decryption operation. IMPORTANT - ensure you use a key
|
||||||
@@ -172,14 +175,20 @@ int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char *
|
|||||||
* is 128 bits
|
* is 128 bits
|
||||||
*/
|
*/
|
||||||
if (1 != EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv))
|
if (1 != EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv))
|
||||||
|
{
|
||||||
|
EVP_CIPHER_CTX_free(ctx);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Provide the message to be decrypted, and obtain the plaintext output.
|
* Provide the message to be decrypted, and obtain the plaintext output.
|
||||||
* EVP_DecryptUpdate can be called multiple times if necessary.
|
* EVP_DecryptUpdate can be called multiple times if necessary.
|
||||||
*/
|
*/
|
||||||
if (1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len))
|
if (1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len))
|
||||||
|
{
|
||||||
|
EVP_CIPHER_CTX_free(ctx);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
plaintext_len = len;
|
plaintext_len = len;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -187,7 +196,10 @@ int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char *
|
|||||||
* this stage.
|
* this stage.
|
||||||
*/
|
*/
|
||||||
if (1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len))
|
if (1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len))
|
||||||
|
{
|
||||||
|
EVP_CIPHER_CTX_free(ctx);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
plaintext_len += len;
|
plaintext_len += len;
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace Generator
|
|||||||
PublicHeader publicHeader;
|
PublicHeader publicHeader;
|
||||||
publicHeader.version = getVersion(lIdentification.revision);
|
publicHeader.version = getVersion(lIdentification.revision);
|
||||||
publicHeader.projectDescription = projectDescription;
|
publicHeader.projectDescription = projectDescription;
|
||||||
publicHeader.date = getDate();
|
publicHeader.date = "4.4.2024"; //getDate();
|
||||||
publicHeader.licenceType = lIdentification.licTypeName;
|
publicHeader.licenceType = lIdentification.licTypeName;
|
||||||
publicHeader.licenceType += to_string(lIdentification.licenceIndex);
|
publicHeader.licenceType += to_string(lIdentification.licenceIndex);
|
||||||
|
|
||||||
@@ -135,12 +135,12 @@ namespace Generator
|
|||||||
|
|
||||||
this->projectDescription = &xmlDoc->child(dataRootName).child("project").child_value()[0];
|
this->projectDescription = &xmlDoc->child(dataRootName).child("project").child_value()[0];
|
||||||
|
|
||||||
licBody.licenceIdentHeader.cardSize = 0;
|
licBody.licenceIdentHeader.cardSize={};
|
||||||
licBody.licenceIdentHeader.compatibilityVersion = this->lIdentification.licCompatibility;
|
licBody.licenceIdentHeader.compatibilityVersion = this->lIdentification.licCompatibility;
|
||||||
licBody.licenceIdentHeader.licenceIndex = this->lIdentification.licenceIndex;
|
licBody.licenceIdentHeader.licenceIndex = this->lIdentification.licenceIndex;
|
||||||
licBody.licenceIdentHeader.licenceType = this->lIdentification.licenceVersion;
|
licBody.licenceIdentHeader.licenceType = (BYTE)this->lIdentification.licLicenceType;
|
||||||
licBody.licenceIdentHeader.licenceTypeVersion = this->lIdentification.licenceVersion;
|
licBody.licenceIdentHeader.licenceTypeVersion = this->lIdentification.licenceVersion;
|
||||||
licBody.licenceIdentHeader.serialNumber = 0;
|
licBody.licenceIdentHeader.serialNumber={};
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -203,15 +203,16 @@ namespace Generator
|
|||||||
this->licBody.licenceIdentHeader.licItemCount = this->licBody.privateContent.dataItems.size();
|
this->licBody.licenceIdentHeader.licItemCount = this->licBody.privateContent.dataItems.size();
|
||||||
this->licBody.licenceIdentHeader.publicHeaderLength = this->licBody.publicHeader.length();
|
this->licBody.licenceIdentHeader.publicHeaderLength = this->licBody.publicHeader.length();
|
||||||
|
|
||||||
vector<unsigned char> publicContent;
|
vector<unsigned char> publicContent {};
|
||||||
vector<unsigned char> privateContent;
|
vector<unsigned char> privateContent {};
|
||||||
vector<unsigned char> privateContentEncrypted;
|
vector<unsigned char> privateContentEncrypted {};
|
||||||
|
|
||||||
publicContent.push_back(this->licBody.licId.licIdent[0]);
|
publicContent.push_back(this->licBody.licId.licIdent[0]);
|
||||||
publicContent.push_back(this->licBody.licId.licIdent[1]);
|
publicContent.push_back(this->licBody.licId.licIdent[1]);
|
||||||
publicContent.push_back(this->licBody.licId.licIdent[2]);
|
publicContent.push_back(this->licBody.licId.licIdent[2]);
|
||||||
publicContent.push_back(((char)48 + (int)this->lIdentification.licElcType));
|
publicContent.push_back(((char)48 + (int)this->lIdentification.licElcType));
|
||||||
publicContent.push_back(this->licBody.licId.licIdent[4]);
|
publicContent.push_back(this->licBody.licId.licIdent[4]);
|
||||||
|
|
||||||
publicContent.push_back(this->licBody.licenceIdentHeader.licenceType);
|
publicContent.push_back(this->licBody.licenceIdentHeader.licenceType);
|
||||||
publicContent.push_back(this->licBody.licenceIdentHeader.licenceTypeVersion);
|
publicContent.push_back(this->licBody.licenceIdentHeader.licenceTypeVersion);
|
||||||
publicContent.push_back(this->licBody.licenceIdentHeader.licenceIndex);
|
publicContent.push_back(this->licBody.licenceIdentHeader.licenceIndex);
|
||||||
@@ -233,6 +234,7 @@ namespace Generator
|
|||||||
cout << "CRC gen public: " << calculateCRC16(publicContent) << "\n";
|
cout << "CRC gen public: " << calculateCRC16(publicContent) << "\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
privateContent.push_back(this->licBody.licenceIdentHeader.licenceType);
|
privateContent.push_back(this->licBody.licenceIdentHeader.licenceType);
|
||||||
privateContent.push_back(this->licBody.licenceIdentHeader.licenceTypeVersion);
|
privateContent.push_back(this->licBody.licenceIdentHeader.licenceTypeVersion);
|
||||||
privateContent.push_back(this->licBody.licenceIdentHeader.licenceIndex);
|
privateContent.push_back(this->licBody.licenceIdentHeader.licenceIndex);
|
||||||
@@ -247,16 +249,35 @@ namespace Generator
|
|||||||
privateContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 16) & 0xFF);
|
privateContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 16) & 0xFF);
|
||||||
privateContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 24) & 0xFF);
|
privateContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 24) & 0xFF);
|
||||||
|
|
||||||
|
privateContent.push_back(1);
|
||||||
|
privateContent.push_back(1);
|
||||||
|
privateContent.push_back(1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// cout << "basic private: \n";
|
||||||
|
// for (const auto x : privateContent) cout << (int)x << "-";
|
||||||
|
// cout << "\n";
|
||||||
|
|
||||||
for (licDataItem dataItem : this->licBody.privateContent.dataItems)
|
for (licDataItem dataItem : this->licBody.privateContent.dataItems)
|
||||||
{
|
{
|
||||||
|
cout << "proto: " << dataItem.protoId << "---";
|
||||||
privateContent.push_back(dataItem.protoId & 0xFF);
|
privateContent.push_back(dataItem.protoId & 0xFF);
|
||||||
privateContent.push_back((dataItem.protoId >> 8) & 0xFF);
|
privateContent.push_back((dataItem.protoId >> 8) & 0xFF);
|
||||||
|
privateContent.push_back((dataItem.protoId >> 16) & 0xFF);
|
||||||
|
privateContent.push_back((dataItem.protoId >> 24) & 0xFF);
|
||||||
privateContent.push_back(dataItem.licCount & 0xFF);
|
privateContent.push_back(dataItem.licCount & 0xFF);
|
||||||
privateContent.push_back((dataItem.licCount >> 8) & 0xFF);
|
privateContent.push_back((dataItem.licCount >> 8) & 0xFF);
|
||||||
for (unsigned int i = 0; i < sizeof(dataItem.dummy); i++)
|
privateContent.push_back((dataItem.licCount >> 16) & 0xFF);
|
||||||
privateContent.push_back(i);
|
privateContent.push_back((dataItem.licCount >> 24) & 0xFF);
|
||||||
|
for (const auto x : privateContent) cout << (int)x << "-";
|
||||||
|
cout << "\n";
|
||||||
|
//for (unsigned int i = 0; i < sizeof(dataItem.dummy); i++) privateContent.push_back(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cout << "\n final private \n";
|
||||||
|
|
||||||
|
|
||||||
#ifdef CRCCHECK
|
#ifdef CRCCHECK
|
||||||
cout << "CRC private size: " << privateContent.size() << "\n";
|
cout << "CRC private size: " << privateContent.size() << "\n";
|
||||||
cout << "CRC gen private: " << calculateCRC16(privateContent) << "\n";
|
cout << "CRC gen private: " << calculateCRC16(privateContent) << "\n";
|
||||||
|
|||||||
@@ -89,6 +89,11 @@ bool LicenceReader::initread(int elcType, InitStructure &initStructure)
|
|||||||
licenceELC2.cid_cdsPath = initStructure.cid_csd_filePath;
|
licenceELC2.cid_cdsPath = initStructure.cid_csd_filePath;
|
||||||
licenceELC2.licenceFilePath = initStructure.licenceFilePath;
|
licenceELC2.licenceFilePath = initStructure.licenceFilePath;
|
||||||
this->licence2->readLicence(&this->licenceInfo);
|
this->licence2->readLicence(&this->licenceInfo);
|
||||||
|
|
||||||
|
this->sdCardInfo.isLoaded = true;
|
||||||
|
this->sdCardInfo.serialNumber = this->licence2->sdCard.cardData.serialNumber;
|
||||||
|
this->sdCardInfo.cardSize = this->licence2->sdCard.cardData.cardSize;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ELCType::ELC3:
|
case ELCType::ELC3:
|
||||||
@@ -113,6 +118,7 @@ bool LicenceReader::initread(int elcType, InitStructure &initStructure)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief vrací informace o licenčím bodu na základě id protocolu a předané návratové struktury
|
/// @brief vrací informace o licenčím bodu na základě id protocolu a předané návratové struktury
|
||||||
|
/// vrací false při chybě nebo v případě, ze pro daný protokol není dostatečný počet licenčních bodů
|
||||||
/// @param protocolId
|
/// @param protocolId
|
||||||
/// @param returnItemStructure
|
/// @param returnItemStructure
|
||||||
/// @return
|
/// @return
|
||||||
@@ -147,7 +153,12 @@ bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure
|
|||||||
if (this->licenceInfo.licences.count(protocolId))
|
if (this->licenceInfo.licences.count(protocolId))
|
||||||
resultPtr->dataPointsCount = this->licenceInfo.licences.at(protocolId);
|
resultPtr->dataPointsCount = this->licenceInfo.licences.at(protocolId);
|
||||||
else
|
else
|
||||||
|
{
|
||||||
resultPtr->dataPointsCount = 0;
|
resultPtr->dataPointsCount = 0;
|
||||||
|
error.code = 0;
|
||||||
|
error.message = "Protokol: " + to_string(protocolId) + " nemá licenční body";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "licReaderELC2.h"
|
#include "licReaderELC2.h"
|
||||||
|
#define SHOW 1
|
||||||
|
|
||||||
namespace Reader
|
namespace Reader
|
||||||
{
|
{
|
||||||
@@ -23,7 +24,7 @@ namespace Reader
|
|||||||
string licFileName = getLicenceName();
|
string licFileName = getLicenceName();
|
||||||
string licFilePath = this->licenceFilePath + licFileName;
|
string licFilePath = this->licenceFilePath + licFileName;
|
||||||
|
|
||||||
vector<char> content;
|
vector<char> content {};
|
||||||
if (readFile(licFilePath, content) == false)
|
if (readFile(licFilePath, content) == false)
|
||||||
{
|
{
|
||||||
throw LicenceException((int)GeneralError::FileOpenError, "Chyba otevření souboru licence: " + licFilePath);
|
throw LicenceException((int)GeneralError::FileOpenError, "Chyba otevření souboru licence: " + licFilePath);
|
||||||
@@ -44,8 +45,6 @@ namespace Reader
|
|||||||
this->licBody.licenceIdentHeader.cardSize = bytesToWord(content[12], content[13]);
|
this->licBody.licenceIdentHeader.cardSize = bytesToWord(content[12], content[13]);
|
||||||
this->licBody.licenceIdentHeader.serialNumber = bytesToDword(content[14], content[15], content[16], content[17]);
|
this->licBody.licenceIdentHeader.serialNumber = bytesToDword(content[14], content[15], content[16], content[17]);
|
||||||
|
|
||||||
//~~~uint16_t crcPublic = bytesToWord(content[18 + licBody.licenceIdentHeader.publicHeaderLength], content[19 + licBody.licenceIdentHeader.publicHeaderLength]);
|
|
||||||
|
|
||||||
int elcVersion = (int)licBody.licId.licIdent[3] - 48; // verze je text, musí se odečíst 48
|
int elcVersion = (int)licBody.licId.licIdent[3] - 48; // verze je text, musí se odečíst 48
|
||||||
|
|
||||||
if (elcVersion != (int)this->lIdentification.licElcType)
|
if (elcVersion != (int)this->lIdentification.licElcType)
|
||||||
@@ -60,11 +59,29 @@ namespace Reader
|
|||||||
cout << "CRC read public: " << calculateCRC16(publicPart) << "\n";
|
cout << "CRC read public: " << calculateCRC16(publicPart) << "\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vector<unsigned char> encryptedPart(content.begin() + licBody.licenceIdentHeader.publicHeaderLength + 18, content.begin() + content.size());
|
#ifdef SHOW
|
||||||
|
cout << "\n public header length: " << licBody.licenceIdentHeader.publicHeaderLength << "\n" ;
|
||||||
|
#endif
|
||||||
|
|
||||||
vector<unsigned char> privateContentDecrypted;
|
//vector<unsigned char> encryptedPart(content.begin() + licBody.licenceIdentHeader.publicHeaderLength + 18, content.begin() + content.size());
|
||||||
|
vector<unsigned char> encryptedPart {};
|
||||||
|
|
||||||
|
for (unsigned int i = licBody.licenceIdentHeader.publicHeaderLength + 18; i<content.size(); i++)
|
||||||
|
{
|
||||||
|
encryptedPart.push_back(content[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<unsigned char> privateContentDecrypted {};
|
||||||
|
//vector<unsigned char> privateContentDecrypted1 {};
|
||||||
privateContentDecrypted = decryptPrivateContent(encryptedPart);
|
privateContentDecrypted = decryptPrivateContent(encryptedPart);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef SHOW
|
||||||
|
cout << "private decrypted: \n";
|
||||||
|
for (const auto &x : privateContentDecrypted) cout << (int)x << "-";
|
||||||
|
cout << "\n";
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CRCCHECK
|
#ifdef CRCCHECK
|
||||||
cout << "CRC read private size: " << privateContentDecrypted.size() << "\n";
|
cout << "CRC read private size: " << privateContentDecrypted.size() << "\n";
|
||||||
cout << "CRC read private: " << calculateCRC16(privateContentDecrypted) << "\n";
|
cout << "CRC read private: " << calculateCRC16(privateContentDecrypted) << "\n";
|
||||||
@@ -83,28 +100,54 @@ namespace Reader
|
|||||||
licBodyDecrypted.licenceIdentHeader.publicHeaderLength = bytesToWord(privateContentDecrypted[5], privateContentDecrypted[6]);
|
licBodyDecrypted.licenceIdentHeader.publicHeaderLength = bytesToWord(privateContentDecrypted[5], privateContentDecrypted[6]);
|
||||||
licBodyDecrypted.licenceIdentHeader.cardSize = bytesToWord(privateContentDecrypted[7], privateContentDecrypted[8]);
|
licBodyDecrypted.licenceIdentHeader.cardSize = bytesToWord(privateContentDecrypted[7], privateContentDecrypted[8]);
|
||||||
licBodyDecrypted.licenceIdentHeader.serialNumber = bytesToDword(privateContentDecrypted[9], privateContentDecrypted[10], privateContentDecrypted[11], privateContentDecrypted[12]);
|
licBodyDecrypted.licenceIdentHeader.serialNumber = bytesToDword(privateContentDecrypted[9], privateContentDecrypted[10], privateContentDecrypted[11], privateContentDecrypted[12]);
|
||||||
|
|
||||||
if (licBodyDecrypted.licenceIdentHeader.licItemCount != this->licBody.licenceIdentHeader.licItemCount)
|
if (licBodyDecrypted.licenceIdentHeader.licItemCount != this->licBody.licenceIdentHeader.licItemCount)
|
||||||
{
|
{
|
||||||
throw LicenceException((int)GeneralError::ItemsCountMismatch, "Nesouhlasí počet položek licence.");
|
throw LicenceException((int)GeneralError::ItemsCountMismatch, "Nesouhlasí počet položek licence.");
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = 13;
|
#ifdef SHOW
|
||||||
|
cout << "velikost: " << sizeof(licBodyDecrypted.licenceIdentHeader) << "\n";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int index = 16;
|
||||||
for (int i = 0; i < this->licBody.licenceIdentHeader.licItemCount; i++)
|
for (int i = 0; i < this->licBody.licenceIdentHeader.licItemCount; i++)
|
||||||
{
|
{
|
||||||
licDataItem item;
|
licDataItem item {};
|
||||||
item.protoId = bytesToWord(privateContentDecrypted[index], privateContentDecrypted[index + 1]);
|
item.protoId = bytesToDword(privateContentDecrypted[index], privateContentDecrypted[index + 1],privateContentDecrypted[index + 2],privateContentDecrypted[index + 3]);
|
||||||
item.licCount = bytesToWord(privateContentDecrypted[index + 2], privateContentDecrypted[index + 3]);
|
item.licCount = bytesToDword(privateContentDecrypted[index + 4], privateContentDecrypted[index + 5], privateContentDecrypted[index + 7], privateContentDecrypted[index + 7]);
|
||||||
index += sizeof(licDataItem);
|
index += sizeof(licDataItem);
|
||||||
this->licBody.privateContent.dataItems.push_back(item);
|
this->licBody.privateContent.dataItems.push_back(item);
|
||||||
this->licenceInfo.licences.insert(pair<int, int>(item.protoId, item.licCount));
|
this->licenceInfo.licences.insert(pair<DWORD, DWORD>(item.protoId, item.licCount));
|
||||||
licences->licences.insert(pair<int, int>(item.protoId, item.licCount));
|
licences->licences.insert(pair<DWORD, DWORD>(item.protoId, item.licCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t crcComplete = bytesToWord(privateContentDecrypted[index], privateContentDecrypted[index + 1]);
|
uint16_t crcComplete = bytesToWord(privateContentDecrypted[index], privateContentDecrypted[index + 1]);
|
||||||
|
|
||||||
vector<unsigned char> completeVector = joinVectors(publicPart, privateContentDecrypted);
|
vector<unsigned char> completeVector = joinVectors(publicPart, privateContentDecrypted);
|
||||||
if (calculateCRC16(completeVector, 2) != crcComplete) throw LicenceException((int)GeneralError::LicenceCRCMismatch, "Nesouhlasí CRC.");
|
|
||||||
|
uint16_t crcCalculated = calculateCRC16(completeVector, 2);
|
||||||
|
|
||||||
|
#ifdef SHOW
|
||||||
|
// cout << "content: \n";
|
||||||
|
// for (const auto x : content) cout << (int)x << "-";
|
||||||
|
|
||||||
|
cout << "\nvector: \n";
|
||||||
|
for (const auto x : completeVector) cout << (int)x << "-";
|
||||||
|
cout << "\n";
|
||||||
|
cout << "crcComplete: " << crcComplete << "\n";
|
||||||
|
cout << "crcCalculated: " << crcCalculated << "\n";
|
||||||
|
cout << "vectorsize: " << completeVector.size() << "\n";
|
||||||
|
cout << "public vector size: " << publicPart.size() << "\n";
|
||||||
|
cout << "private vector size: " << privateContentDecrypted.size() << "\n";
|
||||||
|
|
||||||
|
for (const auto &pair : this->licenceInfo.licences)
|
||||||
|
{
|
||||||
|
cout << "--<" << pair.first << ", " << pair.second << ">--" << endl;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (crcCalculated != crcComplete) throw LicenceException((int)GeneralError::LicenceCRCMismatch, "Nesouhlasí CRC.");
|
||||||
|
else cout << "\n-------------------- KONECNE ---------------------\n";
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
100
zdenda/Makefile
100
zdenda/Makefile
@@ -1,100 +0,0 @@
|
|||||||
#
|
|
||||||
# 'make' build executable file 'main'
|
|
||||||
# 'make clean' removes all .o and executable files
|
|
||||||
#
|
|
||||||
|
|
||||||
# define the Cpp compiler to use
|
|
||||||
CXX = g++
|
|
||||||
|
|
||||||
# define any compile-time flags
|
|
||||||
# CXXFLAGS := -std=c++17 -Wall -Wextra -g -lssl -lcrypto -w
|
|
||||||
CXXFLAGS := -Wall -Wextra -g -lssl -lcrypto
|
|
||||||
|
|
||||||
# define library paths in addition to /usr/lib
|
|
||||||
# if I wanted to include libraries not in /usr/lib I'd specify
|
|
||||||
# their path using -Lpath, something like:
|
|
||||||
LFLAGS =
|
|
||||||
|
|
||||||
# define output directory
|
|
||||||
OUTPUT := output
|
|
||||||
|
|
||||||
# define source directory
|
|
||||||
SRC := src src/common src/reader src/generator
|
|
||||||
|
|
||||||
# define include directory
|
|
||||||
INCLUDE := include include/common include/reader include/generator
|
|
||||||
|
|
||||||
# define lib directory
|
|
||||||
LIB := lib
|
|
||||||
|
|
||||||
ifeq ($(OS),Windows_NT)
|
|
||||||
MAIN := licenceGenerator.exe
|
|
||||||
SOURCEDIRS := $(SRC)
|
|
||||||
INCLUDEDIRS := $(INCLUDE)
|
|
||||||
LIBDIRS := $(LIB)
|
|
||||||
FIXPATH = $(subst /,\,$1)
|
|
||||||
RM := del /q /f
|
|
||||||
MD := mkdir
|
|
||||||
else
|
|
||||||
MAIN := licenceGenerator
|
|
||||||
SOURCEDIRS := $(shell find $(SRC) -type d)
|
|
||||||
INCLUDEDIRS := $(shell find $(INCLUDE) -type d)
|
|
||||||
LIBDIRS := $(shell find $(LIB) -type d)
|
|
||||||
FIXPATH = $1
|
|
||||||
RM = rm -f
|
|
||||||
MD := mkdir -p
|
|
||||||
endif
|
|
||||||
|
|
||||||
# define any directories containing header files other than /usr/include
|
|
||||||
INCLUDES := $(patsubst %,-I%, $(INCLUDEDIRS:%/=%))
|
|
||||||
|
|
||||||
# define the C libs
|
|
||||||
LIBS := $(patsubst %,-L%, $(LIBDIRS:%/=%))
|
|
||||||
|
|
||||||
# define the C source files
|
|
||||||
SOURCES := $(wildcard $(patsubst %,%/*.cpp, $(SOURCEDIRS)))
|
|
||||||
|
|
||||||
# define the C object files
|
|
||||||
OBJECTS := $(SOURCES:.cpp=.o)
|
|
||||||
|
|
||||||
# define the dependency output files
|
|
||||||
DEPS := $(OBJECTS:.o=.d)
|
|
||||||
|
|
||||||
#
|
|
||||||
# The following part of the makefile is generic; it can be used to
|
|
||||||
# build any executable just by changing the definitions above and by
|
|
||||||
# deleting dependencies appended to the file from 'make depend'
|
|
||||||
#
|
|
||||||
|
|
||||||
OUTPUTMAIN := $(call FIXPATH,$(OUTPUT)/$(MAIN))
|
|
||||||
|
|
||||||
all: $(OUTPUT) $(MAIN)
|
|
||||||
@echo Executing 'all' complete!
|
|
||||||
|
|
||||||
$(OUTPUT):
|
|
||||||
$(MD) $(OUTPUT)
|
|
||||||
|
|
||||||
$(MAIN): $(OBJECTS)
|
|
||||||
$(CXX) $(CXXFLAGS) $(INCLUDES) -o $(OUTPUTMAIN) $(OBJECTS) $(LFLAGS) $(LIBS)
|
|
||||||
|
|
||||||
# include all .d files
|
|
||||||
-include $(DEPS)
|
|
||||||
|
|
||||||
# this is a suffix replacement rule for building .o's and .d's from .c's
|
|
||||||
# it uses automatic variables $<: the name of the prerequisite of
|
|
||||||
# the rule(a .c file) and $@: the name of the target of the rule (a .o file)
|
|
||||||
# -MMD generates dependency output files same name as the .o file
|
|
||||||
# (see the gnu make manual section about automatic variables)
|
|
||||||
.cpp.o:
|
|
||||||
$(CXX) $(CXXFLAGS) $(INCLUDES) -c -MMD $< -o $@
|
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
clean:
|
|
||||||
$(RM) $(OUTPUTMAIN)
|
|
||||||
$(RM) $(call FIXPATH,$(OBJECTS))
|
|
||||||
$(RM) $(call FIXPATH,$(DEPS))
|
|
||||||
@echo Cleanup complete!
|
|
||||||
|
|
||||||
run: all
|
|
||||||
./$(OUTPUTMAIN)
|
|
||||||
@echo Executing 'run: all' complete!
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
#ifndef SDCARD_H_
|
|
||||||
#define SDCARD_H_
|
|
||||||
|
|
||||||
#define CID_LENGTH 32
|
|
||||||
#define CSD_LENGTH 32
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
typedef uint32_t DWORD;
|
|
||||||
typedef uint16_t WORD;
|
|
||||||
typedef uint8_t BYTE;
|
|
||||||
typedef uint32_t UDINT;
|
|
||||||
typedef uint32_t DATE;
|
|
||||||
typedef uint8_t USINT;
|
|
||||||
typedef int32_t DINT;
|
|
||||||
typedef uint16_t UINT;
|
|
||||||
typedef int16_t INT;
|
|
||||||
|
|
||||||
const BYTE cnibblescount = 32;
|
|
||||||
|
|
||||||
const string cidFilePath = "";
|
|
||||||
|
|
||||||
class SDCard
|
|
||||||
{
|
|
||||||
|
|
||||||
struct SDCardData
|
|
||||||
{
|
|
||||||
uint8_t isCorrectLoad = 0; // SD karta je korektne nactena //bool vs byte ?
|
|
||||||
uint8_t CID_nibble[32] = {0}; // surova data CID ze souboru
|
|
||||||
uint8_t CID[16] = {0}; // prekodovane CID informace
|
|
||||||
uint8_t manufacturerID = 0; // ID vyrobce 1B -> Byte 15
|
|
||||||
char oemID[2] = {}; // ID aplikace/oem 2B -> Byte 13-14 // oemID: !!STRING(3);
|
|
||||||
char name[5] = {}; // jmeno produktu 5B -> Byte 8-12 !!STRING(6);
|
|
||||||
uint8_t productRevision_hw = 0;
|
|
||||||
uint8_t productRevision_sw = 0;
|
|
||||||
float productRevision = 0; // revize produktu 1B [bcd sh] -> Byte 7, bity 0-3 = revize HW, bity 4-7 = revize SW
|
|
||||||
uint32_t serialNumber = 0; // seriove cislo karty 4B -> Byte 3-6
|
|
||||||
uint16_t manufacturerDate_year = 0;
|
|
||||||
uint8_t manufacturerDate_month = 0;
|
|
||||||
char manufacturerDate[10] = {}; //: STRING(10); // datum vyroby 2B [bcd -yym] -> Byte 1-2, bity 0-3 = mesic, bity 4-11 = posledni cislice roku or roku 2000, bity 12-15 nepouzito
|
|
||||||
uint8_t CRCOK = 0; // CRC 1B -> Byte 0, bity 1-7, bit 0 je vzdy = 1
|
|
||||||
uint8_t CSD_nibble[32] = {}; //: ARRAY [0..31] OF BYTE; // surova data CSD ze souboru
|
|
||||||
uint8_t CSD[16] = {}; //: ARRAY [0..15] OF BYTE; // prekodovane CSD informace
|
|
||||||
uint32_t cardSize = 0; //: UDINT; // velikost SD karty
|
|
||||||
uint8_t cardGSize = 0; // prepocitana velikost na GB
|
|
||||||
bool crcCorrect = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool readSDCard();
|
|
||||||
bool getCIDFromFile();
|
|
||||||
bool getCSDFromFile();
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
SDCardData cardData;
|
|
||||||
bool isLoaded = false;
|
|
||||||
char cid[32] = {};
|
|
||||||
char csd[32] = {};
|
|
||||||
string filePath = "";
|
|
||||||
string cidString = ""; //pro předání pro starý generátor
|
|
||||||
string csdString = ""; //pro předání pro starý generátor
|
|
||||||
|
|
||||||
SDCard();
|
|
||||||
SDCard(string cid, string csd);
|
|
||||||
SDCard(const string filesPath);
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,210 +0,0 @@
|
|||||||
#define CRC = 1
|
|
||||||
|
|
||||||
#ifndef LICENCE_COMMON_H_
|
|
||||||
#define LICENCE_COMMON_H_
|
|
||||||
|
|
||||||
//---------------- společná hlavička pro všechny licence ----------------
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <string>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
#define XML_VERSION 1
|
|
||||||
#define SOFTWARE_VERSION 1
|
|
||||||
#define SUCCES 0;
|
|
||||||
|
|
||||||
const int cidSize = 32;
|
|
||||||
const int csdSize = 32;
|
|
||||||
const int generatorVersion = 1;
|
|
||||||
|
|
||||||
typedef uint8_t BYTE;
|
|
||||||
typedef uint16_t WORD;
|
|
||||||
typedef uint32_t DWORD;
|
|
||||||
typedef uint32_t DATE;
|
|
||||||
|
|
||||||
enum class GeneralError
|
|
||||||
{
|
|
||||||
GeneralError = 1,
|
|
||||||
FileOpenError = 2,
|
|
||||||
FileReadError = 3,
|
|
||||||
FileWriteError = 4,
|
|
||||||
ELCNotImplemented = 5,
|
|
||||||
LicenceTypeNotImplemented = 6,
|
|
||||||
CompatibilityTypeNotImplemented = 7,
|
|
||||||
ELCMismatch = 8,
|
|
||||||
CRCMismatch = 9,
|
|
||||||
EncryptError = 10,
|
|
||||||
DecryptError = 11,
|
|
||||||
ParamMissing = 12,
|
|
||||||
IvanlidParam = 13,
|
|
||||||
SDCardReadError = 50,
|
|
||||||
LicenceReadError = 51,
|
|
||||||
LicenceSizeMismatch = 52,
|
|
||||||
LicenceSizeCardMismatch = 53,
|
|
||||||
LicenceMismatch = 54,
|
|
||||||
LicenceCRCMismatch = 54,
|
|
||||||
ItemsCountMismatch = 61
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class ELCType
|
|
||||||
{
|
|
||||||
ELC1 = 1,
|
|
||||||
ELC2 = 2,
|
|
||||||
ELC3 = 3
|
|
||||||
};
|
|
||||||
enum class ELCSubType
|
|
||||||
{
|
|
||||||
DEFAULT = 1
|
|
||||||
}; // subtype = dataVersion
|
|
||||||
enum class LicenceType
|
|
||||||
{
|
|
||||||
EOS_EOV,
|
|
||||||
DDTS,
|
|
||||||
DRT
|
|
||||||
}; //
|
|
||||||
enum class HeaderType
|
|
||||||
{
|
|
||||||
DEFAULT = 0
|
|
||||||
}; ////subtype = version
|
|
||||||
|
|
||||||
enum class EncryptionType
|
|
||||||
{
|
|
||||||
CID_AES256 = 10,
|
|
||||||
FIX_AES256 = 20
|
|
||||||
};
|
|
||||||
enum class BinaryType
|
|
||||||
{
|
|
||||||
FILE = 1,
|
|
||||||
BASE64 = 2
|
|
||||||
};
|
|
||||||
enum class PlcType
|
|
||||||
{
|
|
||||||
WAGO = 1,
|
|
||||||
TECO = 2
|
|
||||||
};
|
|
||||||
enum class FileNameGenerationType
|
|
||||||
{
|
|
||||||
DEFAULT = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Mapping
|
|
||||||
{
|
|
||||||
unordered_map<string, LicenceType> licMapTypes = {{"EOV_OSV", LicenceType::EOS_EOV}, {"DDTS", LicenceType::DDTS}, {"DRT", LicenceType::DRT}};
|
|
||||||
unordered_map<string, EncryptionType> licMapEncryption = {{"CID_AES256", EncryptionType::CID_AES256}, {"FIX_AES256", EncryptionType::FIX_AES256}};
|
|
||||||
unordered_map<string, PlcType> licMapPlcType = {{"WAGO", PlcType::WAGO}, {"TECO", PlcType::TECO}};
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ErrorMessage
|
|
||||||
{
|
|
||||||
int code = 0;
|
|
||||||
string message = "";
|
|
||||||
};
|
|
||||||
|
|
||||||
struct LicenceIdentification
|
|
||||||
{
|
|
||||||
ELCType licElcType = ELCType::ELC2;
|
|
||||||
LicenceType licLicenceType;
|
|
||||||
string licTypeName = "";
|
|
||||||
PlcType licPlcType;
|
|
||||||
|
|
||||||
uint8_t licenceVersion = 1; // verze licence, určuje kodování, pojmenování souborů
|
|
||||||
uint8_t licenceIndex = 0;
|
|
||||||
uint8_t revision;
|
|
||||||
uint8_t licCompatibility = 0; // identikator hlavního ELC. 0 = nedefinová a vrací se defaultní k danému ELC
|
|
||||||
uint16_t licItemsCount = 0;
|
|
||||||
string cid_cds_path = "";
|
|
||||||
string licenceFilePath = "";
|
|
||||||
};
|
|
||||||
|
|
||||||
/// @brief obecná struktura pro reader
|
|
||||||
struct LicenceInfoGeneral
|
|
||||||
{
|
|
||||||
int reqDataPointsCount = 0;
|
|
||||||
unordered_map<int, int> licences = {};
|
|
||||||
};
|
|
||||||
|
|
||||||
/// @brief obecná struktura polozky licence, defaultní kompatibilita
|
|
||||||
struct LicenceItem
|
|
||||||
{
|
|
||||||
int protocolId = -1;
|
|
||||||
int dataPointsCount = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* struktury pro ELC 1 */
|
|
||||||
//defaultní struktura pro ELC 1
|
|
||||||
struct LicenceELC1Info
|
|
||||||
{
|
|
||||||
bool isValid {false};
|
|
||||||
};
|
|
||||||
|
|
||||||
//struktura ELC1, kompatibilita 1
|
|
||||||
struct LicenceELC1Info_1
|
|
||||||
{
|
|
||||||
unordered_map<int, int> licences = {};
|
|
||||||
};
|
|
||||||
|
|
||||||
//defaultni struktura polozky licence ELC 1
|
|
||||||
struct LicenceELC1Item
|
|
||||||
{
|
|
||||||
int protocolId = -1;
|
|
||||||
int dataPointsCount = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* struktury pro ELC 2 */
|
|
||||||
//defaultní struktura pro ELC 2
|
|
||||||
struct LicenceELC2Info
|
|
||||||
{
|
|
||||||
unordered_map<int, int> licences = {};
|
|
||||||
};
|
|
||||||
|
|
||||||
struct LicenceELC2Info_1
|
|
||||||
{
|
|
||||||
unordered_map<int, int> licences = {};
|
|
||||||
};
|
|
||||||
|
|
||||||
//defaultni struktura polozky ELC 2
|
|
||||||
struct LicenceELC2Item
|
|
||||||
{
|
|
||||||
int protocolId = -1;
|
|
||||||
int dataPointsCount = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
//struktura polozky ELC 2,
|
|
||||||
struct LicenceELC2Item_1
|
|
||||||
{
|
|
||||||
int protocolId = -1;
|
|
||||||
int dataPointsCount = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class LicenceException : public std::exception
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
LicenceException(int errorCode, const std::string &errorMessage)
|
|
||||||
: errorCode_(errorCode), errorMessage_(errorMessage) {}
|
|
||||||
|
|
||||||
const char *what() const noexcept override
|
|
||||||
{
|
|
||||||
return errorMessage_.c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
int getErrorCode() const
|
|
||||||
{
|
|
||||||
return errorCode_;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string &getErrorMessage() const
|
|
||||||
{
|
|
||||||
return errorMessage_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
int errorCode_;
|
|
||||||
std::string errorMessage_;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,265 +0,0 @@
|
|||||||
#ifndef PLC_LICENCE1_COMMON_H
|
|
||||||
#define PLC_LICENCE1_COMMON_H
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include "licenceCommon.h"
|
|
||||||
#include "SDCard.h"
|
|
||||||
|
|
||||||
/// @brief společná třída pro reader a generátor ELC1
|
|
||||||
class LicenceELC1
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
LicenceELC1();
|
|
||||||
LicenceELC1(LicenceIdentification &licIdentification);
|
|
||||||
~LicenceELC1();
|
|
||||||
|
|
||||||
bool getSDData(); // reads SD card
|
|
||||||
string getLicenceName(BYTE licPostfix); // get proper licencename
|
|
||||||
string getLicenceName();
|
|
||||||
void initCrypto();
|
|
||||||
LicenceIdentification lIdentification;
|
|
||||||
|
|
||||||
string cid_cdsPath = "";
|
|
||||||
string licenceFilePath = "";
|
|
||||||
|
|
||||||
Mapping mapping;
|
|
||||||
|
|
||||||
ErrorMessage errorMessage;
|
|
||||||
|
|
||||||
#define MAX_LICENCE_COUNT 100
|
|
||||||
|
|
||||||
enum InputLicenceType
|
|
||||||
{
|
|
||||||
EOSEOV = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
enum BinaryGenerationType
|
|
||||||
{
|
|
||||||
Base64Cout = 1,
|
|
||||||
File = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
enum PlcLicenceType
|
|
||||||
{
|
|
||||||
LicenceOther = 0,
|
|
||||||
LicenceEov = 1
|
|
||||||
};
|
|
||||||
enum LidIdType
|
|
||||||
{
|
|
||||||
Ddts = 1,
|
|
||||||
EovOsv = 2
|
|
||||||
};
|
|
||||||
enum PrefixType
|
|
||||||
{
|
|
||||||
ELC1 = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef uint32_t DWORD;
|
|
||||||
typedef uint16_t WORD;
|
|
||||||
typedef uint8_t BYTE;
|
|
||||||
typedef uint32_t UDINT;
|
|
||||||
typedef uint32_t DATE;
|
|
||||||
typedef uint8_t USINT;
|
|
||||||
typedef int32_t DINT;
|
|
||||||
typedef uint16_t UINT;
|
|
||||||
typedef int16_t INT;
|
|
||||||
|
|
||||||
/// @brief identifikace licence
|
|
||||||
typedef struct LicenceIdent
|
|
||||||
{
|
|
||||||
WORD licPrefixType = 0; // WORD; typ licencniho souboru - pro kazdy prefig je jiny typ souboru a jiny zpusob zpracovani dat [sifrovani, podpis, komprese, ...]
|
|
||||||
WORD licHeaderType = 0; //: WORD; typ hlavicky kriptovane casti licencniho souboru
|
|
||||||
WORD licDataType = 0; //: WORD; typ licence - pro kazdou hlavicku jsou samostatne typy licenci - mohou byt i shodne s typem jine hlavicky
|
|
||||||
WORD licSubType = 0; //: WORD; slouceny typ hlavicku a typ licence => typ hlavicky * 256 + typ licence
|
|
||||||
WORD licIDType = 0; //: WORD; id aplikace, pro kterou je licence urcena => 1 = ddts, 2 = eov-osv
|
|
||||||
BYTE licPostfix = 0; //: BYTE; rozliseni licence pro stejny typ - napr. pokud mam 2x SW pro DRT na 2 nezavisle ED
|
|
||||||
} LicenceIdent;
|
|
||||||
|
|
||||||
/// @brief struktura pro přípravu dat na generování
|
|
||||||
typedef struct LicenceSourceData
|
|
||||||
{
|
|
||||||
|
|
||||||
BYTE startGen; // na nabeznou hranu se vygeneruje licence
|
|
||||||
BYTE loadSD; //: BOOL; na nabeznou hranu se nacte SD karta
|
|
||||||
// zadavane hodnoty
|
|
||||||
BYTE licType_id; // vybrany typ licence
|
|
||||||
char licDescription1[40] = {}; //: STRING(39); jmeno stanice
|
|
||||||
char licDescription2[20] = {}; //: STRING(19); jmeno rozvadece
|
|
||||||
BYTE licPostfix; // rozliseni licence pro stejny typ - napr. pokud mam 2x SW pro DRT na 2 nezavisle ED
|
|
||||||
BYTE enInit; //: BOOL; inicializace (promazani) adresare pro licence
|
|
||||||
// interne generovane hodnoty
|
|
||||||
WORD licType; //: WORD; hlavicka licence
|
|
||||||
BYTE licIdOk; //: BOOL; korektne zvoleny typ licence
|
|
||||||
string licPostfixIdent; //[2]; //: STRING(2); vygenerovany postfix z cisla pro rozliseni postfixu v souborech a textech
|
|
||||||
} LicenceSourceData;
|
|
||||||
|
|
||||||
/// @brief struktura obsahující dodatečné informace k licenci
|
|
||||||
typedef struct PlcData
|
|
||||||
{
|
|
||||||
string plcType = "";
|
|
||||||
string licenceType = ""; // typ
|
|
||||||
string licenceVersion = "1";
|
|
||||||
string licenceName = ""; // název
|
|
||||||
string station = ""; // stanice
|
|
||||||
string distributor = ""; // rozvadec
|
|
||||||
} PlcData;
|
|
||||||
|
|
||||||
/*
|
|
||||||
MID (Manufacturer ID): 8 bits - Identifies the manufacturer of the SD card.
|
|
||||||
OID (OEM/Application ID): 16 bits - Identifies the OEM and application-specific information.
|
|
||||||
PNM (Product Name): 40 bits - A string representing the product name of the SD card.
|
|
||||||
PRV (Product Revision): 8 bits - The product revision/version.
|
|
||||||
PSN (Product Serial Number): 32 bits - A unique serial number assigned to the SD card during manufacturing.
|
|
||||||
MDT (Manufacturing Date): 12 bits - Represents the manufacturing date of the SD card.
|
|
||||||
CRC (CRC7 Checksum): 7 bits - A cyclic redundancy check for error detection.
|
|
||||||
unused: 4 bits - Reserved for future use.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// @brief struktura pro načtení CIS a CSD dat
|
|
||||||
typedef struct SDData
|
|
||||||
{
|
|
||||||
BYTE isCorrectLoad = 0; // SD karta je korektne nactena //bool vs byte ?
|
|
||||||
BYTE CID_nibble[32] = {0}; // surova data CID ze souboru
|
|
||||||
BYTE CID[16] = {0}; // prekodovane CID informace
|
|
||||||
BYTE manufacturerID = 0; // ID vyrobce 1B -> Byte 15
|
|
||||||
char oemID[2] = {}; // ID aplikace/oem 2B -> Byte 13-14 // oemID: !!STRING(3);
|
|
||||||
char name[5] = {}; // jmeno produktu 5B -> Byte 8-12 !!STRING(6);
|
|
||||||
BYTE productRevision_hw = 0;
|
|
||||||
BYTE productRevision_sw = 0;
|
|
||||||
float productRevision = 0; // revize produktu 1B [bcd sh] -> Byte 7, bity 0-3 = revize HW, bity 4-7 = revize SW
|
|
||||||
DWORD serialNumber = 0; // seriove cislo karty 4B -> Byte 3-6
|
|
||||||
WORD manufacturerDate_year = 0;
|
|
||||||
BYTE manufacturerDate_month = 0;
|
|
||||||
char manufacturerDate[10] = {}; //: STRING(10); // datum vyroby 2B [bcd -yym] -> Byte 1-2, bity 0-3 = mesic, bity 4-11 = posledni cislice roku or roku 2000, bity 12-15 nepouzito
|
|
||||||
BYTE CRCOK = 0; // CRC 1B -> Byte 0, bity 1-7, bit 0 je vzdy = 1
|
|
||||||
BYTE CSD_nibble[32] = {}; //: ARRAY [0..31] OF BYTE; // surova data CSD ze souboru
|
|
||||||
BYTE CSD[16] = {}; //: ARRAY [0..15] OF BYTE; // prekodovane CSD informace
|
|
||||||
UDINT cardSize = 0; //: UDINT; // velikost SD karty
|
|
||||||
BYTE cardGSize = 0; // prepocitana velikost na GB
|
|
||||||
} CidData;
|
|
||||||
|
|
||||||
// nekodovana cast licence
|
|
||||||
|
|
||||||
/// @brief nekryptovaná hlavička licence
|
|
||||||
typedef struct LicenceDataMainHeaderELC
|
|
||||||
{
|
|
||||||
BYTE licType = 0;
|
|
||||||
; // typ licence => duplicitni polozka s hlavickou kodovane casti licence - pouze pro ucely dekodovani dat
|
|
||||||
BYTE dummy1 = 0;
|
|
||||||
WORD licSubType = 0; // horni byte = typ hlavicky kodovane casti, spodni byte = typ dat polozkove casti => duplicitni casti s id a hlavickou kodovane casti - pouze pro ucely dekodovani
|
|
||||||
char description[80] = {}; // viditelny popis licincniho souboru
|
|
||||||
UDINT sizeData = 0; // velikost kodovane casti licence v Bytech
|
|
||||||
} LicenceDataMainHeaderELC;
|
|
||||||
|
|
||||||
// hlavní struktura licence
|
|
||||||
typedef struct LicenceDataMainELC
|
|
||||||
{
|
|
||||||
// prefix MUSI zustat jako prvni prvek struktury a MUSI byt typu DWORD
|
|
||||||
DWORD prefix = 0; // urcuje strukturu dat citelne casti licencniho souboru [teto struktury] + zpusob sifrovani, dig, podpis, kompresi... dat
|
|
||||||
LicenceDataMainHeaderELC licHeader{}; // nekodovana cast licence
|
|
||||||
} LicenceDataMain;
|
|
||||||
|
|
||||||
// polozkova cast licence verze 1.0
|
|
||||||
typedef struct LicenceDataItem
|
|
||||||
{
|
|
||||||
WORD protoId = 0; // id protokolu pro ktery je licence
|
|
||||||
WORD licCount = 0; // pocet datovych bodu licence
|
|
||||||
DWORD data1 = 0; // doplnkove nahodne cislo, slouzi pro overeni licence v runtime
|
|
||||||
} LicenceDataItem;
|
|
||||||
|
|
||||||
// identifikace kodovane casti licence - !!! MUSI yustat pro vsechny verze STEJNA !!!
|
|
||||||
typedef struct LicenceDataId
|
|
||||||
{
|
|
||||||
WORD version = 0; // verze hlavicky
|
|
||||||
WORD rez = 0;
|
|
||||||
UDINT cardSize = 0;
|
|
||||||
} LicenceDataId;
|
|
||||||
|
|
||||||
typedef struct LicenceDataHeader
|
|
||||||
{
|
|
||||||
BYTE licType = 0; // typ licence => 0...neznamy (chyba), 1...DDTS, 2...EOV-OSV
|
|
||||||
BYTE licReserve = 0; // rezerva
|
|
||||||
WORD licVersion = 0; //: WORD; verze polozkove casti licence
|
|
||||||
DATE licDate = 0; // datum vygenerovani licence
|
|
||||||
char licDescription1[40] = {}; // licDescription1: STRING(39); stanice, pro kterou byla licence generovana
|
|
||||||
char licDescription2[20] = {}; // STRING(19); rozvadec, pro ktery byla licence generovana
|
|
||||||
USINT licCount = 0; // aktivni pocet dat polozkove casti licence
|
|
||||||
BYTE licDummy = 0; // rezerva
|
|
||||||
WORD licReservew = 0; // rezerva
|
|
||||||
} LicenceDataHeader;
|
|
||||||
|
|
||||||
// kodovana cast licence verze 1.1 s polozkovou casi licence verze 1.0
|
|
||||||
typedef struct LicenceData
|
|
||||||
{
|
|
||||||
LicenceDataId id{}; // id !!! MUSI zustat na PRVNIM miste struktury
|
|
||||||
LicenceDataHeader header{};
|
|
||||||
LicenceDataItem items[MAX_LICENCE_COUNT] = {}; // polozkova cast licence
|
|
||||||
WORD dummy = 0; // pro zarovnani struktur - jinak nebude fungovat vypocet a kontrola CRC !!!
|
|
||||||
WORD crc = 0; // kontrolni kod - !!! MUSI zustat na konci struktury
|
|
||||||
} LicenceData;
|
|
||||||
|
|
||||||
typedef struct LicenceRetData
|
|
||||||
{
|
|
||||||
BYTE retCode = 0; // navratovy kod funkce pro nacteni SD
|
|
||||||
DINT subCode = 0; // doplnkova informace chyby
|
|
||||||
std::string text = ""; // textovy popis navratove hodnoty
|
|
||||||
bool isDone = false; // operace korektne dokoncena
|
|
||||||
} LicenceRetData;
|
|
||||||
|
|
||||||
typedef struct CryptData
|
|
||||||
{
|
|
||||||
bool initDone = false;
|
|
||||||
DWORD cryptDataAddress = 0; // adresa na data, ktera se maji cryptovat
|
|
||||||
UINT cryptDataSize = 0; // velikostdat, ktera semaji cryptovat
|
|
||||||
BYTE aesInitVector[15] = {0}; //] : ARRAY [0..14] OF BYTE;// AES 128 bit IV
|
|
||||||
BYTE aesKey[32] = {0}; // : ARRAY [0..31] OF BYTE; // AES 256 bit key
|
|
||||||
DINT aesRetVal = 0; // navratova hodnota AES
|
|
||||||
DWORD retDataAddress = 0; // adresa na ulozeni cryptovana dat
|
|
||||||
UINT retDataSize = 0; // velikost cryptovanych dat
|
|
||||||
LicenceData *licenseData;
|
|
||||||
} CryptData;
|
|
||||||
|
|
||||||
const BYTE licMaxCount = 100;
|
|
||||||
const WORD cEzLic_p78ou3_IDType_DDTS = 1; // aplikace DDTS
|
|
||||||
const WORD cEzLic_p78ou3_IDType_EOVOSV = 2; // aplikace EOV-OSV
|
|
||||||
const WORD cEzLic_p78ou3_IDType_DRT = 3; // aplikace DRT
|
|
||||||
const DWORD cEzLic_p78ou3_CheckLicNumber_ERR = 0xFFFFFFFF; // 16#FFFFFFFF; // chybna identifikace licence
|
|
||||||
const DWORD cEzLic_p78ou3_CheckLicNumber_EOV1 = 3781234965; // cislo pro overeni licence EOV, OSV verze 1
|
|
||||||
const BYTE cEzLic_p78ou3_CheckLicNumberId_ERR = 0; // id licence pro neidentifikovanou licenci
|
|
||||||
const BYTE cEzLic_p78ou3_CheckLicNumberId_EOV1 = 1; // id licence pro EOV, OSV verze 1
|
|
||||||
const BYTE cEzLic_p78ou3_MaxCheckLicNumberId = cEzLic_p78ou3_CheckLicNumberId_EOV1; // pocet identifikatoru licenci
|
|
||||||
const DWORD cEzLic_p78ou3_CheckLicNumber[2] = {cEzLic_p78ou3_CheckLicNumber_ERR, cEzLic_p78ou3_CheckLicNumber_EOV1};
|
|
||||||
const WORD cEzLic_p78ou3_LicPrefixType_ELC1 = 1; // prefix typ1 = pouze zasifrovani dat
|
|
||||||
const WORD cEzLic_p78ou3_HeaderType_10 = 10; // hlavicka kriptovane casti verze 1.0
|
|
||||||
const WORD cEzLic_p78ou3_DataType_10 = 10; // data licence verze 1.0
|
|
||||||
const WORD cEzLic_p78ou3_SubType_10_10 = 0x0A0A; // subtype - verze hlavicky + verze data -> cEzLic_p78ou3_HeaderType_XX * 256 + cEzLic_p78ou3_DataType_XX
|
|
||||||
// ID aplikace
|
|
||||||
|
|
||||||
const BYTE cnibblescount11 = 32;
|
|
||||||
|
|
||||||
CryptData cryptData; // structure for encryp
|
|
||||||
CidData sdData; // data loaded from SD card
|
|
||||||
|
|
||||||
|
|
||||||
SDCard sdCard;
|
|
||||||
|
|
||||||
string cidString = "";
|
|
||||||
char cid[32] = {};
|
|
||||||
string csdString = "";
|
|
||||||
char csd[32] = {}; // CSD
|
|
||||||
string stationName; // name of station
|
|
||||||
string distributor; // name of switch
|
|
||||||
const char *dataFileName; // name of xml containing data (if not taken from commandline)
|
|
||||||
WORD licType = 2; // type of licence
|
|
||||||
BinaryGenerationType binaryGeneration = BinaryGenerationType::Base64Cout; // typ generování binárního souboru
|
|
||||||
|
|
||||||
string dataLicenceType = ""; // type of licence from xmlFile;
|
|
||||||
string dataLicenceVersion = ""; // version type of licence from xmlFile;
|
|
||||||
string dataCryptoVersion = ""; // version of crypting from xmlFile
|
|
||||||
string dataGenerationType = ""; // version of dataGeneration from xmlFile
|
|
||||||
string dataLicenceDataFileName = ""; // name of licence file to read
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
#ifndef PLC_LICENCE2_COMMON_H
|
|
||||||
#define PLC_LICENCE2_COMMON_H
|
|
||||||
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include "licenceCommon.h"
|
|
||||||
#include "SDCard.h"
|
|
||||||
|
|
||||||
/// @brief společná třída pro pro reader i generator licence typu ELC2
|
|
||||||
class LicenceELC2
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
LicenceELC2();
|
|
||||||
LicenceELC2(LicenceIdentification &licIdentification);
|
|
||||||
~LicenceELC2();
|
|
||||||
|
|
||||||
string cid_cdsPath = "";
|
|
||||||
string licenceFilePath = "";
|
|
||||||
|
|
||||||
Mapping mapping;
|
|
||||||
|
|
||||||
ErrorMessage errorMessage;
|
|
||||||
|
|
||||||
struct LicenceId
|
|
||||||
{
|
|
||||||
char licIdent[5] = {'E', 'L', 'C', '0', '_'};
|
|
||||||
};
|
|
||||||
|
|
||||||
// struct __attribute__((__packed__)) LicencePublicHeader
|
|
||||||
struct LicenceIdentDataHeader
|
|
||||||
{
|
|
||||||
BYTE licenceType = 0; // EOSEOV, DRT ...
|
|
||||||
BYTE licenceTypeVersion = 1; // verze licence, urcuje nuance sifrování a pojmenování souborů
|
|
||||||
BYTE licenceIndex = 0; // puvodní post fix, identifikátor pro více licencí
|
|
||||||
BYTE compatibilityVersion = 1; // udava verzi komplet PrivateContent
|
|
||||||
BYTE licItemCount = 0; // počet licenčních bodů
|
|
||||||
WORD publicHeaderLength = 0; // délka veřejné hlavičy
|
|
||||||
WORD cardSize = 0; // velikost SD karty
|
|
||||||
DWORD serialNumber = 0; // seriove cislo karty
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
struct licDataItem
|
|
||||||
{
|
|
||||||
WORD protoId = 0; // id protokolu pro ktery je licence
|
|
||||||
WORD licCount = 0; // pocet datovych bodu licence
|
|
||||||
char dummy[64] = {}; // dummy pro větší velikost licence v případě méně licenčních bodů
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PublicHeader
|
|
||||||
{
|
|
||||||
string version = "";
|
|
||||||
string projectDescription = "";
|
|
||||||
string date = "";
|
|
||||||
string licenceType = "";
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PrivateContent // privátní šifrovaná část
|
|
||||||
{
|
|
||||||
LicenceIdentDataHeader licenceIdentHeader;
|
|
||||||
vector<licDataItem> dataItems;
|
|
||||||
WORD crc = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct LicenceBody
|
|
||||||
{
|
|
||||||
LicenceId licId;
|
|
||||||
LicenceIdentDataHeader licenceIdentHeader;
|
|
||||||
string publicHeader = ""; // JSON
|
|
||||||
PrivateContent privateContent;
|
|
||||||
};
|
|
||||||
|
|
||||||
LicenceBody licBody;
|
|
||||||
SDCard sdCard;
|
|
||||||
LicenceIdentification lIdentification;
|
|
||||||
vector<unsigned char> cryptPrivateContent(const std::vector<unsigned char> &content);
|
|
||||||
vector<unsigned char> decryptPrivateContent(const std::vector<unsigned char> &content);
|
|
||||||
void initVector(BYTE (&iVector)[], BYTE (&key)[]);
|
|
||||||
string getLicenceName();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
#ifndef UTILS_H_
|
|
||||||
#define UTILS_H_
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <vector>
|
|
||||||
#include <chrono>
|
|
||||||
#include <libgen.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
typedef uint8_t BYTE;
|
|
||||||
typedef uint16_t WORD;
|
|
||||||
typedef uint32_t DWORD;
|
|
||||||
typedef uint32_t DATE;
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
struct DateAndTime {
|
|
||||||
uint16_t date; // DATE data type in CODESYS
|
|
||||||
uint16_t time; // TIME data type in CODESYS
|
|
||||||
};
|
|
||||||
|
|
||||||
void generatePause();
|
|
||||||
std::string right(const std::string& sourceString, size_t numChars);
|
|
||||||
void getCharsFromString(const string source, char *charArray);
|
|
||||||
uint16_t calculateCRC16(const uint8_t* data, size_t length);
|
|
||||||
WORD getCurrentDateAsCODESYSDate();
|
|
||||||
DWORD getCurrentDateAsCODESYSDateDword();
|
|
||||||
DateAndTime getCurrentDateTimeAsCODESYSDateTime();
|
|
||||||
DATE getLicDate();
|
|
||||||
string getDate();
|
|
||||||
int encrypt(const unsigned char *plaintext, int plaintext_len, unsigned char *key, unsigned char *iv, unsigned char *ciphertext);
|
|
||||||
unsigned short crc16(const unsigned char* data_p, unsigned char length);
|
|
||||||
int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char *key, unsigned char *iv, unsigned char *plaintext);
|
|
||||||
string convertToString(char* a, int size);
|
|
||||||
string base64_encode_ai(const std::string &input);
|
|
||||||
unordered_map<string, string> getArguments(int argc, char *argv[]);
|
|
||||||
void getCharsFromString(string& source, char *charArray, size_t length);
|
|
||||||
string getCompletePath(string fileName);
|
|
||||||
void appendStringToVector(const std::string& str, std::vector<unsigned char>& charVector);
|
|
||||||
uint16_t calculateCRC16(std::vector<unsigned char>& charVector);
|
|
||||||
uint16_t calculateCRC16(std::vector<char> &charVector);
|
|
||||||
uint16_t calculateCRC16(std::vector<unsigned char> &charVector, int removeCount);
|
|
||||||
uint32_t bytesToDword(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4);
|
|
||||||
uint32_t bytesToWord(uint8_t byte1, uint8_t byte2);
|
|
||||||
vector<unsigned char> joinVectors(const std::vector<unsigned char>& vector1, const std::vector<unsigned char>& vector2);
|
|
||||||
bool readFile(string fileName, vector<char> &output);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
#ifndef ELC1_READER__H
|
|
||||||
#define ELC1_READER__H
|
|
||||||
|
|
||||||
#include "utils.h"
|
|
||||||
#include "licenceCommon.h"
|
|
||||||
#include "licenceELC1.h"
|
|
||||||
#include "SDCard.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace Reader
|
|
||||||
{
|
|
||||||
class Licence1 : public LicenceELC1
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
LicenceELC1Info licenceInfo;
|
|
||||||
|
|
||||||
Licence1();
|
|
||||||
~Licence1();
|
|
||||||
Licence1(LicenceIdentification &licIdentification);
|
|
||||||
|
|
||||||
bool readLicence(LicenceInfoGeneral *licences);
|
|
||||||
bool getLicenceInfo(void *ptr);
|
|
||||||
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
|
|
||||||
void getLicenceItems();
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
#ifndef ELC2_READER_H
|
|
||||||
#define ELC2_READER_H
|
|
||||||
|
|
||||||
#include "utils.h"
|
|
||||||
#include "licenceCommon.h"
|
|
||||||
#include "licenceELC2.h"
|
|
||||||
#include "SDCard.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace Reader
|
|
||||||
{
|
|
||||||
class Licence2 : public LicenceELC2
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
LicenceELC2Info licenceInfo;
|
|
||||||
|
|
||||||
Licence2();
|
|
||||||
~Licence2();
|
|
||||||
Licence2(LicenceIdentification &licIdentification);
|
|
||||||
|
|
||||||
bool readLicence(LicenceInfoGeneral *licences);
|
|
||||||
bool getLicenceInfo(void *ptr);
|
|
||||||
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
|
|
||||||
void getLicenceItems();
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#ifndef ELC3_READER__H
|
|
||||||
#define ELC3_READER__H
|
|
||||||
|
|
||||||
namespace Reader
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
#ifndef LICENCE_READER_H_
|
|
||||||
#define LICENCE_READER_H_
|
|
||||||
|
|
||||||
#include "utils.h"
|
|
||||||
#include "licReaderELC1.h"
|
|
||||||
#include "licReaderELC2.h"
|
|
||||||
#include "licReaderELC3.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace Reader;
|
|
||||||
|
|
||||||
|
|
||||||
struct InitStructure
|
|
||||||
{
|
|
||||||
int licenceType = 0;
|
|
||||||
int licenceVersion = 0;
|
|
||||||
int licenceIndex = 0;
|
|
||||||
int compatibility = 0;
|
|
||||||
string licenceFilePath = "";
|
|
||||||
string cid_csd_filePath = "";
|
|
||||||
};
|
|
||||||
|
|
||||||
class LicenceReader
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
int elcSwitchType;
|
|
||||||
string operationErrors = "";
|
|
||||||
bool argumentsCorrect = false;
|
|
||||||
ErrorMessage error;
|
|
||||||
Licence2 *licence2;
|
|
||||||
Licence1 *licence1;
|
|
||||||
|
|
||||||
|
|
||||||
LicenceReader();
|
|
||||||
~LicenceReader();
|
|
||||||
bool init(int elcType, InitStructure &initStructure);
|
|
||||||
bool initread(int elcType, InitStructure &initStructure);
|
|
||||||
bool getLicenceInfo(void *returnStructure);
|
|
||||||
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
|
|
||||||
|
|
||||||
LicenceInfoGeneral licenceInfo;
|
|
||||||
|
|
||||||
private:
|
|
||||||
LicenceIdentification licIdentification;
|
|
||||||
string configFileName = "";
|
|
||||||
void *licence = nullptr;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
#define LINUX 1
|
|
||||||
// #define WINDOWS 1
|
|
||||||
|
|
||||||
#include "licenceReader.h"
|
|
||||||
|
|
||||||
/// @brief hlavní funkce
|
|
||||||
/// @param argc
|
|
||||||
/// @param argv parametry pro generování licence
|
|
||||||
/// @return
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
InitStructure initStructure;
|
|
||||||
initStructure.licenceType = (int)LicenceType::EOS_EOV;
|
|
||||||
initStructure.licenceVersion = 1;
|
|
||||||
initStructure.licenceIndex = 0;
|
|
||||||
initStructure.licenceFilePath = ""; // cesta k licenčnímu souboru
|
|
||||||
// initStructure.compatibility = 0; v případě kompatibility 0 či nezadané je výstup defaultní.
|
|
||||||
// pro ELC 1 LicenceELC1Info je to isValid, pro ELC 2 strukura { int protocolId = -1; int dataPointsCount = 0; }
|
|
||||||
initStructure.cid_csd_filePath = ""; // cesta k cidu/csd pro načtení a kontrolu licence
|
|
||||||
|
|
||||||
//verze původní ELC 1
|
|
||||||
LicenceReader licenceReaderELC1{};
|
|
||||||
if (licenceReaderELC1.initread(1, initStructure)) // iniciacni nacteni
|
|
||||||
{
|
|
||||||
LicenceELC1Info info; // struktura pro ELC1. Nemá tam asi nic jiného smysl nez true/false
|
|
||||||
if (licenceReaderELC1.getLicenceInfo(&info))
|
|
||||||
{
|
|
||||||
if (info.isValid)
|
|
||||||
cout << "Platna licence ELC1 \n";
|
|
||||||
else
|
|
||||||
cout << "Neplatna licence ELC1\n";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
cout << "CHYBA: " << licenceReaderELC1.error.message;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cout << "CHYBA: " << licenceReaderELC1.error.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
// verze ELC 2 pro jeden protokol
|
|
||||||
LicenceReader licenceReaderELC2{};
|
|
||||||
if (licenceReaderELC2.initread(2, initStructure)) // iniciacni nacteni
|
|
||||||
{
|
|
||||||
// v případě kompatibility 0, či nezadané výstup nativně je defaultní.
|
|
||||||
// v případně nenulové kompatibility, třeba 1, přidáme číslo kompatibility.
|
|
||||||
//Tedy pro ELC1 to bude LicenceELC1_1, pro ELC LicenceELC2_1
|
|
||||||
LicenceELC2Item info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31)
|
|
||||||
// if ()
|
|
||||||
int protocolId = 333;
|
|
||||||
|
|
||||||
// if (initStructure.compatibility == 1) //ukazka kompatibilita 1
|
|
||||||
// {
|
|
||||||
// LicenceELC2Item_1 info; //jiná struktura, zbytek stejný
|
|
||||||
// if (licenceReaderELC2.getLicenceItemInfo(protocolId, &info))
|
|
||||||
// {
|
|
||||||
// cout << "Pocet licencních bodu pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
|
|
||||||
// }
|
|
||||||
//...........
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (licenceReaderELC2.getLicenceItemInfo(protocolId, &info))
|
|
||||||
{
|
|
||||||
cout << "Pocet licencních bodu pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
cout << "CHYBA: " << licenceReaderELC2.error.message;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cout << "CHYBA: " << licenceReaderELC2.error.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
LicenceReader licenceReaderCompleteELC2{};
|
|
||||||
//verze ELC 2 kompletní načtení
|
|
||||||
if (licenceReaderCompleteELC2.init(2, initStructure)) // iniciacni nacteni
|
|
||||||
{
|
|
||||||
LicenceELC2Info info;
|
|
||||||
int protocolId = 333;
|
|
||||||
|
|
||||||
if (licenceReaderCompleteELC2.getLicenceInfo(&info))
|
|
||||||
{
|
|
||||||
if (info.licences.count(protocolId) > 0)
|
|
||||||
cout << "Pocet bodu z vectoru pro protokol : " << protocolId << ": " << info.licences.at(protocolId) << "\n";
|
|
||||||
else
|
|
||||||
cout << "Pro tento protokol nejsou definovay licencni body\n";
|
|
||||||
cout << "Vypis vsech licencnich bodu: " << endl;
|
|
||||||
for (const auto &pair : info.licences)
|
|
||||||
{
|
|
||||||
std::cout << "<" << pair.first << ", " << pair.second << ">" << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
cout << "CHYBA: " << licenceReaderCompleteELC2.error.message;
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cout << "CHYBA: " << licenceReaderCompleteELC2.error.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
cout << "Obecna chyba\n";
|
|
||||||
}
|
|
||||||
return SUCCES;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,143 +0,0 @@
|
|||||||
#include "utils.h"
|
|
||||||
#include "SDCard.h"
|
|
||||||
|
|
||||||
SDCard::SDCard()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
SDCard::SDCard(const string cds_cid_Path)
|
|
||||||
{
|
|
||||||
this->filePath = cds_cid_Path;
|
|
||||||
if (getCIDFromFile() == false)
|
|
||||||
return;
|
|
||||||
if (getCSDFromFile() == false)
|
|
||||||
return;
|
|
||||||
this->isLoaded = SDCard::readSDCard();
|
|
||||||
}
|
|
||||||
|
|
||||||
SDCard::SDCard(string cid, string csd)
|
|
||||||
{
|
|
||||||
for (unsigned int i = 0; i < cid.length(); i++)
|
|
||||||
this->cid[i] = cid[i];
|
|
||||||
for (unsigned int i = 0; i < csd.length(); i++)
|
|
||||||
this->csd[i] = csd[i];
|
|
||||||
|
|
||||||
this->isLoaded = SDCard::readSDCard();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SDCard::readSDCard()
|
|
||||||
{
|
|
||||||
|
|
||||||
BYTE cHexNibbleToNo[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
|
||||||
0, 0, 0, 0, 0, 0, 0,
|
|
||||||
10, 11, 12, 13, 14, 15,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0,
|
|
||||||
10, 11, 12, 13, 14, 15,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
||||||
|
|
||||||
for (int i = 0; i < CID_LENGTH; i++)
|
|
||||||
this->cardData.CID_nibble[i] = (BYTE)cid[i];
|
|
||||||
|
|
||||||
for (int i = 0; i < cnibblescount / 2; i++)
|
|
||||||
{
|
|
||||||
this->cardData.CID[i] = cHexNibbleToNo[this->cardData.CID_nibble[2 * i]] << 4 | cHexNibbleToNo[this->cardData.CID_nibble[2 * i + 1]];
|
|
||||||
}
|
|
||||||
|
|
||||||
this->cardData.manufacturerID = this->cardData.CID[0];
|
|
||||||
this->cardData.oemID[0] = this->cardData.CID[1];
|
|
||||||
this->cardData.oemID[1] = this->cardData.CID[2];
|
|
||||||
this->cardData.name[0] = this->cardData.CID[3];
|
|
||||||
this->cardData.name[1] = this->cardData.CID[4];
|
|
||||||
this->cardData.name[2] = this->cardData.CID[5];
|
|
||||||
this->cardData.name[3] = this->cardData.CID[6];
|
|
||||||
this->cardData.name[4] = this->cardData.CID[7];
|
|
||||||
this->cardData.productRevision_hw = cHexNibbleToNo[this->cardData.CID[16]];
|
|
||||||
this->cardData.productRevision_sw = cHexNibbleToNo[this->cardData.CID[17]];
|
|
||||||
|
|
||||||
if (this->cardData.productRevision_sw < 10)
|
|
||||||
this->cardData.productRevision = (float)this->cardData.productRevision_hw + ((float)this->cardData.productRevision_sw * 0.1);
|
|
||||||
else
|
|
||||||
this->cardData.productRevision = (float)this->cardData.productRevision_hw + ((float)this->cardData.productRevision_sw * 0.01);
|
|
||||||
|
|
||||||
this->cardData.serialNumber = this->cardData.CID[9] << 24 | this->cardData.CID[10] << 16 | this->cardData.CID[11] << 8 | this->cardData.CID[12];
|
|
||||||
|
|
||||||
// CSD
|
|
||||||
for (int i = 0; i < CSD_LENGTH; i++)
|
|
||||||
this->cardData.CSD_nibble[i] = (BYTE)csd[i];
|
|
||||||
|
|
||||||
for (int i = 0; i < cnibblescount / 2; i++)
|
|
||||||
{
|
|
||||||
this->cardData.CSD[i] = cHexNibbleToNo[this->cardData.CSD_nibble[2 * i]] << 4 | cHexNibbleToNo[this->cardData.CSD_nibble[2 * i + 1]];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->cardData.CSD_nibble[0] == 0x34)
|
|
||||||
{
|
|
||||||
this->cardData.cardSize = this->cardData.CSD[7] << 16 | this->cardData.CSD[8] << 8 | this->cardData.CSD[9];
|
|
||||||
this->cardData.cardGSize = (this->cardData.cardSize + 1) / 2048;
|
|
||||||
}
|
|
||||||
|
|
||||||
BYTE sdCrc = 0;
|
|
||||||
for (int i = 0; i <= 14; i++)
|
|
||||||
{
|
|
||||||
BYTE sdChar = this->cardData.CID[i];
|
|
||||||
for (int j = 0; j <= 7; j++)
|
|
||||||
{
|
|
||||||
sdCrc = sdCrc << 1;
|
|
||||||
if ((sdChar ^ sdCrc) & 0x80)
|
|
||||||
sdCrc = sdCrc ^ 0x09;
|
|
||||||
sdChar = sdChar << 1;
|
|
||||||
}
|
|
||||||
sdCrc = sdCrc & 0x7F;
|
|
||||||
}
|
|
||||||
this->cardData.CRCOK = ((sdCrc << 1) | 1) == this->cardData.CID[15];
|
|
||||||
this->cardData.crcCorrect = (int)this->cardData.CID[15] == (int)((sdCrc << 1) | 1);
|
|
||||||
return this->cardData.crcCorrect;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SDCard::getCIDFromFile()
|
|
||||||
{
|
|
||||||
vector<char> content;
|
|
||||||
if (readFile(this->filePath + "cid", content) == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (content.size() >= CID_LENGTH)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < 32; i++)
|
|
||||||
this->cid[i] = content[i];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SDCard::getCSDFromFile()
|
|
||||||
{
|
|
||||||
vector<char> content;
|
|
||||||
if (readFile(this->filePath + "csd", content) == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (content.size() >= CSD_LENGTH)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < 32; i++)
|
|
||||||
this->csd[i] = content[i];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<licence elc="2" xmlVersion="1" revision="1" compatibility="1">
|
|
||||||
<licenceType licenceVersion="1" licenceIndex="0">EOV_OSV</licenceType>
|
|
||||||
<plcType>WAGO</plcType>
|
|
||||||
<licenceName>Licence pro EOV_OSV</licenceName>
|
|
||||||
<station>eov.ceskatrebova.ddts.cz</station>
|
|
||||||
<distributor>eov2</distributor>
|
|
||||||
<project>Projekt XXX stanice YYY</project>
|
|
||||||
<items>
|
|
||||||
<item>
|
|
||||||
<name>Položka licence 1</name>
|
|
||||||
<protoId>111</protoId>
|
|
||||||
<dataPointsCount>100</dataPointsCount>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<name>Položka licence 2</name>
|
|
||||||
<protoId>222</protoId>
|
|
||||||
<dataPointsCount>200</dataPointsCount>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<name>Položka licence 3</name>
|
|
||||||
<protoId>333</protoId>
|
|
||||||
<dataPointsCount>300</dataPointsCount>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<name>Položka licence 3</name>
|
|
||||||
<protoId>444</protoId>
|
|
||||||
<dataPointsCount>1600</dataPointsCount>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<name>Položka licence 4</name>
|
|
||||||
<protoId>555</protoId>
|
|
||||||
<dataPointsCount>1999</dataPointsCount>
|
|
||||||
</item>
|
|
||||||
</items>
|
|
||||||
|
|
||||||
</licence>
|
|
||||||
@@ -1,218 +0,0 @@
|
|||||||
#include "licenceELC1.h"
|
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
#define CID_LENGTH 32
|
|
||||||
#define CSD_LENGTH 32
|
|
||||||
|
|
||||||
const std::string cEzLic_p78ou3_sdinfofilepath = "/sys/block/mmcblk0/device/";
|
|
||||||
const std::string cEzLic_p78ou3_licencfilepath_f21 = "/mnt/mmc/ez_sys/licence/";
|
|
||||||
const std::string cEzLic_p78ou3_licencfilepath_f17 = "/home/admin/ez/licence/";
|
|
||||||
const string cEzLic_p78ou3_licencfilepath_f10 = "/root/ez_sys/licence/";
|
|
||||||
const WORD maxDataToFile = 10000; // velikost datoveho bufferu pro ulozeni dat licence
|
|
||||||
|
|
||||||
const BYTE licMaxCount = 100;
|
|
||||||
const DWORD cEzLic_p78ou3_CheckLicNumber_ERR = 0xFFFFFFFF; // 16#FFFFFFFF; // chybna identifikace licence
|
|
||||||
const DWORD cEzLic_p78ou3_CheckLicNumber_EOV1 = 3781234965; // cislo pro overeni licence EOV, OSV verze 1
|
|
||||||
const BYTE cEzLic_p78ou3_CheckLicNumberId_ERR = 0; // id licence pro neidentifikovanou licenci
|
|
||||||
const BYTE cEzLic_p78ou3_CheckLicNumberId_EOV1 = 1; // id licence pro EOV, OSV verze 1
|
|
||||||
const BYTE cEzLic_p78ou3_MaxCheckLicNumberId = cEzLic_p78ou3_CheckLicNumberId_EOV1; // pocet identifikatoru licenci
|
|
||||||
const DWORD cEzLic_p78ou3_CheckLicNumber[] = {cEzLic_p78ou3_CheckLicNumber_ERR, cEzLic_p78ou3_CheckLicNumber_EOV1};
|
|
||||||
const WORD cEzLic_p78ou3_LicPrefixType_ELC1 = 1; // prefix typ1 = pouze zasifrovani dat
|
|
||||||
const WORD cEzLic_p78ou3_HeaderType_10 = 10; // hlavicka kriptovane casti verze 1.0
|
|
||||||
const WORD cEzLic_p78ou3_DataType_10 = 10; // data licence verze 1.0
|
|
||||||
const WORD cEzLic_p78ou3_SubType_10_10 = 0x0A0A; // subtype - verze hlavicky + verze data -> cEzLic_p78ou3_HeaderType_XX * 256 + cEzLic_p78ou3_DataType_XX
|
|
||||||
// ID aplikace
|
|
||||||
const WORD cEzLic_p78ou3_IDType_DDTS = 1; // aplikace DDTS
|
|
||||||
const WORD cEzLic_p78ou3_IDType_EOVOSV = 2; // aplikace EOV-OSV
|
|
||||||
const WORD cEzLic_p78ou3_IDType_DRT = 3; // aplikace DRT
|
|
||||||
// std::string cEzLic_p78ou3_IDTypeStrData11[] = {"neznamo", "DDTS", "EOV-OSV", "DRT"};
|
|
||||||
const BYTE cnibblescount1 = 32;
|
|
||||||
std::string cSDMonthStr1[] = {"-", "I.", "II.", "III.", "IV.", "V.", "VI.", "VII.", "VIII.", "IX.", "X.", "XI.", "XII.", "-", "-", "-"};
|
|
||||||
BYTE cHexNibble_to_No1[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
|
||||||
0, 0, 0, 0, 0, 0, 0,
|
|
||||||
10, 11, 12, 13, 14, 15,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0,
|
|
||||||
10, 11, 12, 13, 14, 15,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
||||||
|
|
||||||
const string eoseovLicenceType = "EOV_OSV";
|
|
||||||
|
|
||||||
LicenceELC1::LicenceELC1() {}
|
|
||||||
|
|
||||||
LicenceELC1::~LicenceELC1() {}
|
|
||||||
|
|
||||||
LicenceELC1::LicenceELC1(LicenceIdentification &licIdentification) : lIdentification(licIdentification)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LicenceELC1::getSDData()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < CID_LENGTH; i++) this->sdData.CID_nibble[i] = (BYTE)cid[i];
|
|
||||||
|
|
||||||
for (int i = 0; i < cnibblescount / 2; i++)
|
|
||||||
{
|
|
||||||
this->sdData.CID[i] = cHexNibble_to_No1[this->sdData.CID_nibble[2 * i]] << 4 | cHexNibble_to_No1[this->sdData.CID_nibble[2 * i + 1]];
|
|
||||||
}
|
|
||||||
|
|
||||||
this->sdData.manufacturerID = this->sdData.CID[0];
|
|
||||||
this->sdData.oemID[0] = this->sdData.CID[1];
|
|
||||||
this->sdData.oemID[1] = this->sdData.CID[2];
|
|
||||||
this->sdData.name[0] = this->sdData.CID[3];
|
|
||||||
this->sdData.name[1] = this->sdData.CID[4];
|
|
||||||
this->sdData.name[2] = this->sdData.CID[5];
|
|
||||||
this->sdData.name[3] = this->sdData.CID[6];
|
|
||||||
this->sdData.name[4] = this->sdData.CID[7];
|
|
||||||
this->sdData.productRevision_hw = cHexNibble_to_No1[this->sdData.CID[16]];
|
|
||||||
this->sdData.productRevision_sw = cHexNibble_to_No1[this->sdData.CID[17]];
|
|
||||||
|
|
||||||
if (this->sdData.productRevision_sw < 10)
|
|
||||||
this->sdData.productRevision = (float)this->sdData.productRevision_hw + ((float)this->sdData.productRevision_sw * 0.1);
|
|
||||||
else
|
|
||||||
this->sdData.productRevision = (float)this->sdData.productRevision_hw + ((float)this->sdData.productRevision_sw * 0.01);
|
|
||||||
|
|
||||||
this->sdData.serialNumber = this->sdData.CID[9] << 24 | this->sdData.CID[10] << 16 | this->sdData.CID[11] << 8 | this->sdData.CID[12];
|
|
||||||
this->sdData.manufacturerDate_year = cHexNibble_to_No1[this->sdData.CID_nibble[27]] * 10 + cHexNibble_to_No1[this->sdData.CID_nibble[28]] + 2000;
|
|
||||||
this->sdData.manufacturerDate_month = cHexNibble_to_No1[this->sdData.CID_nibble[29]];
|
|
||||||
string date = cSDMonthStr1[this->sdData.manufacturerDate_month] + std::to_string(this->sdData.manufacturerDate_year);
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < date.length(); i++)
|
|
||||||
this->sdData.manufacturerDate[i] = date[i];
|
|
||||||
|
|
||||||
// CSD
|
|
||||||
for (unsigned int i = 0; i < CSD_LENGTH; i++) this->sdData.CSD_nibble[i] = (BYTE)csd[i];
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < cnibblescount / 2; i++)
|
|
||||||
{
|
|
||||||
this->sdData.CSD[i] = cHexNibble_to_No1[this->sdData.CSD_nibble[2 * i]] << 4 | cHexNibble_to_No1[this->sdData.CSD_nibble[2 * i + 1]];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->sdData.CSD_nibble[0] == 0x34)
|
|
||||||
{
|
|
||||||
this->sdData.cardSize = this->sdData.CSD[7] << 16 | this->sdData.CSD[8] << 8 | this->sdData.CSD[9];
|
|
||||||
this->sdData.cardGSize = (this->sdData.cardSize + 1) / 2048;
|
|
||||||
}
|
|
||||||
|
|
||||||
BYTE sdCrc = 0;
|
|
||||||
for (int i = 0; i <= 14; i++)
|
|
||||||
{
|
|
||||||
BYTE sdChar = this->sdData.CID[i];
|
|
||||||
for (int j = 0; j <= 7; j++)
|
|
||||||
{
|
|
||||||
sdCrc = sdCrc << 1;
|
|
||||||
if ((sdChar ^ sdCrc) & 0x80)
|
|
||||||
sdCrc = sdCrc ^ 0x09;
|
|
||||||
sdChar = sdChar << 1;
|
|
||||||
}
|
|
||||||
sdCrc = sdCrc & 0x7F;
|
|
||||||
}
|
|
||||||
this->sdData.CRCOK = ((sdCrc << 1) | 1) == this->sdData.CID[15];
|
|
||||||
|
|
||||||
return (int)this->sdData.CID[15] == (int)((sdCrc << 1) | 1);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void LicenceELC1::initCrypto()
|
|
||||||
{
|
|
||||||
if (this->licType == cEzLic_p78ou3_IDType_EOVOSV)
|
|
||||||
{
|
|
||||||
this->cryptData.aesInitVector[0] = this->sdData.CID[10];
|
|
||||||
this->cryptData.aesInitVector[1] = this->sdData.CID[12];
|
|
||||||
this->cryptData.aesInitVector[2] = this->sdData.CID[11];
|
|
||||||
this->cryptData.aesInitVector[3] = this->sdData.CID[9];
|
|
||||||
this->cryptData.aesInitVector[4] = this->sdData.CID_nibble[22] - 15;
|
|
||||||
this->cryptData.aesInitVector[5] = this->sdData.CID_nibble[24] - 15;
|
|
||||||
this->cryptData.aesInitVector[6] = this->sdData.CID_nibble[25] - 15;
|
|
||||||
this->cryptData.aesInitVector[7] = this->sdData.CID_nibble[21] - 15;
|
|
||||||
memcpy(&this->cryptData.aesInitVector[8], &this->cryptData.aesInitVector[0], 8);
|
|
||||||
|
|
||||||
this->cryptData.aesKey[0] = this->sdData.CID[12];
|
|
||||||
this->cryptData.aesKey[1] = this->sdData.CID_nibble[23] - 15;
|
|
||||||
this->cryptData.aesKey[2] = this->sdData.CID_nibble[25] - 15;
|
|
||||||
this->cryptData.aesKey[3] = this->sdData.CID[11];
|
|
||||||
this->cryptData.aesKey[4] = this->sdData.CID[9];
|
|
||||||
this->cryptData.aesKey[5] = this->sdData.CID_nibble[21] - 15;
|
|
||||||
this->cryptData.aesKey[6] = 97 + this->sdData.CID[9] % 25;
|
|
||||||
this->cryptData.aesKey[7] = this->sdData.CID_nibble[22] - 15;
|
|
||||||
memcpy(&this->cryptData.aesKey[8], &this->cryptData.aesKey[0], 8);
|
|
||||||
memcpy(&this->cryptData.aesKey[16], &this->cryptData.aesKey[6], 8);
|
|
||||||
memcpy(&this->cryptData.aesKey[24], &this->cryptData.aesKey[12], 8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
string LicenceELC1::getLicenceName()
|
|
||||||
{
|
|
||||||
string result = "";
|
|
||||||
char prefixChar = 97;
|
|
||||||
int licIndex = lIdentification.licenceIndex;
|
|
||||||
|
|
||||||
// natvrdo, stará ELC
|
|
||||||
result = "ezlic_eovosv" + to_string(licIndex) + "_";
|
|
||||||
result += prefixChar + (this->sdCard.cardData.CID[12] % 25);
|
|
||||||
result += prefixChar + (this->sdCard.cardData.CID[10] % 25);
|
|
||||||
result += prefixChar + (this->sdCard.cardData.CID_nibble[22] % 25);
|
|
||||||
result += prefixChar + ((this->sdCard.cardData.CID_nibble[23] * 2) % 25);
|
|
||||||
result += prefixChar + (this->sdCard.cardData.CID_nibble[24] % 25);
|
|
||||||
result += prefixChar + ((this->sdCard.cardData.CID_nibble[25] * 3) % 25);
|
|
||||||
result += prefixChar + (this->sdCard.cardData.CID[9] % 25);
|
|
||||||
result += prefixChar + (this->sdCard.cardData.CID[11] % 25);
|
|
||||||
result += prefixChar + (this->sdCard.cardData.CID[2] % 25);
|
|
||||||
result += prefixChar + (this->sdCard.cardData.CID[1] % 25);
|
|
||||||
result += prefixChar + (this->sdCard.cardData.CID[3] % 25);
|
|
||||||
result += ".lic";
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @brief get proper licencename
|
|
||||||
/// @param licPostfix
|
|
||||||
/// @return
|
|
||||||
string LicenceELC1::getLicenceName(BYTE licPostfix)
|
|
||||||
{
|
|
||||||
string result = "";
|
|
||||||
char prefixChar = 97;
|
|
||||||
|
|
||||||
if (licType == PlcLicenceType::LicenceOther)
|
|
||||||
{
|
|
||||||
result = "ezlic_";
|
|
||||||
result += prefixChar + (this->sdData.CID[12] % 25);
|
|
||||||
result += prefixChar + (this->sdData.CID[10] % 25);
|
|
||||||
result += prefixChar + (this->sdData.CID_nibble[22] % 25);
|
|
||||||
result += prefixChar + ((this->sdData.CID_nibble[23] * 2) % 25);
|
|
||||||
result += prefixChar + (this->sdData.CID_nibble[24] % 25);
|
|
||||||
result += prefixChar + ((this->sdData.CID_nibble[25] * 3) % 25);
|
|
||||||
result += prefixChar + (this->sdData.CID[9] % 25);
|
|
||||||
result += prefixChar + (this->sdData.CID[11] % 25);
|
|
||||||
result += prefixChar + (this->sdData.CID[2] % 25);
|
|
||||||
result += prefixChar + (this->sdData.CID[1] % 25);
|
|
||||||
result += prefixChar + (this->sdData.CID[3] % 25);
|
|
||||||
result += ".lic";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result = "ezlic_eovosv" + to_string(licPostfix) + "_";
|
|
||||||
result += prefixChar + (this->sdData.CID[12] % 25);
|
|
||||||
result += prefixChar + (this->sdData.CID[10] % 25);
|
|
||||||
result += prefixChar + (this->sdData.CID_nibble[22] % 25);
|
|
||||||
result += prefixChar + ((this->sdData.CID_nibble[23] * 2) % 25);
|
|
||||||
result += prefixChar + (this->sdData.CID_nibble[24] % 25);
|
|
||||||
result += prefixChar + ((this->sdData.CID_nibble[25] * 3) % 25);
|
|
||||||
result += prefixChar + (this->sdData.CID[9] % 25);
|
|
||||||
result += prefixChar + (this->sdData.CID[11] % 25);
|
|
||||||
result += prefixChar + (this->sdData.CID[2] % 25);
|
|
||||||
result += prefixChar + (this->sdData.CID[1] % 25);
|
|
||||||
result += prefixChar + (this->sdData.CID[3] % 25);
|
|
||||||
result += ".lic";
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
@@ -1,172 +0,0 @@
|
|||||||
#include "licenceELC2.h"
|
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
|
|
||||||
LicenceELC2::LicenceELC2(){}
|
|
||||||
|
|
||||||
LicenceELC2::~LicenceELC2(){}
|
|
||||||
|
|
||||||
LicenceELC2::LicenceELC2(LicenceIdentification &licIdentification): lIdentification(licIdentification)
|
|
||||||
{}
|
|
||||||
|
|
||||||
/// @brief get proper licencename
|
|
||||||
/// @param licPostfix
|
|
||||||
/// @return
|
|
||||||
string LicenceELC2::getLicenceName()
|
|
||||||
{
|
|
||||||
string result = "";
|
|
||||||
char prefixChar = 97;
|
|
||||||
int licType = (int)lIdentification.licLicenceType;
|
|
||||||
int lVersion = lIdentification.licenceVersion;
|
|
||||||
|
|
||||||
unordered_map<int, string> baseString;
|
|
||||||
baseString.insert(std::pair<int, string>((int)LicenceType::EOS_EOV, "ezlic_eovosv"));
|
|
||||||
baseString.insert(std::pair<int, string>((int)LicenceType::DDTS, "ezlic_ddts"));
|
|
||||||
baseString.insert(std::pair<int, string>((int)LicenceType::DRT, "ezlic_drt"));
|
|
||||||
|
|
||||||
struct Index
|
|
||||||
{
|
|
||||||
int index[11];
|
|
||||||
};
|
|
||||||
|
|
||||||
std::unordered_map<int, Index> indexes;
|
|
||||||
Index indexes1 = {7, 16, 20, 23, 18, 4, 9, 11, 6, 9, 13};
|
|
||||||
Index indexes2 = {12, 10, 22, 23, 24, 25, 9, 11, 2, 1, 3}; // puvodní indexy
|
|
||||||
Index indexes3 = {8, 13, 11, 9, 7, 11, 10, 13, 5, 20, 19};
|
|
||||||
|
|
||||||
indexes.insert(std::pair<int, Index>(1, indexes1));
|
|
||||||
indexes.insert(std::pair<int, Index>(2, indexes2));
|
|
||||||
indexes.insert(std::pair<int, Index>(3, indexes3));
|
|
||||||
|
|
||||||
result = baseString.at(licType) + to_string(lIdentification.licenceIndex) + "_";
|
|
||||||
|
|
||||||
result += prefixChar + ((this->sdCard.cardData.CID[indexes.at(lVersion).index[0]] + (lIdentification.licenceIndex * 11)) % 25);
|
|
||||||
result += prefixChar + ((this->sdCard.cardData.CID[indexes.at(lVersion).index[1]] + (lIdentification.licenceIndex * 39)) % 25);
|
|
||||||
|
|
||||||
result += prefixChar + ((this->sdCard.cardData.CID_nibble[indexes.at(lVersion).index[2]] + (lIdentification.licenceIndex * 1)) % 25);
|
|
||||||
result += prefixChar + ((this->sdCard.cardData.CID_nibble[indexes.at(lVersion).index[3]] * 2) % 25);
|
|
||||||
result += prefixChar + ((this->sdCard.cardData.CID_nibble[indexes.at(lVersion).index[4]] + (lIdentification.licenceIndex * 5)) % 25);
|
|
||||||
result += prefixChar + ((this->sdCard.cardData.CID_nibble[indexes.at(lVersion).index[5]] * 3) % 25);
|
|
||||||
|
|
||||||
result += prefixChar + ((this->sdCard.cardData.CID[indexes.at(lVersion).index[6]] + (lIdentification.licenceIndex * 52)) % 25);
|
|
||||||
result += prefixChar + ((this->sdCard.cardData.CID[indexes.at(lVersion).index[7]] + (lIdentification.licenceIndex * 34)) % 25);
|
|
||||||
result += prefixChar + ((this->sdCard.cardData.CID[indexes.at(lVersion).index[8]] + (lIdentification.licenceIndex * 21)) % 25);
|
|
||||||
result += prefixChar + ((this->sdCard.cardData.CID[indexes.at(lVersion).index[9]] + (lIdentification.licenceIndex * 47)) % 25);
|
|
||||||
result += prefixChar + ((this->sdCard.cardData.CID[indexes.at(lVersion).index[10]] + (lIdentification.licenceIndex * 7)) % 25);
|
|
||||||
|
|
||||||
result += ".lic";
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<unsigned char> LicenceELC2::cryptPrivateContent(const std::vector<unsigned char> &content)
|
|
||||||
{
|
|
||||||
|
|
||||||
BYTE initVector[15] = {};
|
|
||||||
BYTE aesKey[32] = {};
|
|
||||||
|
|
||||||
LicenceELC2::initVector(initVector, aesKey);
|
|
||||||
|
|
||||||
unsigned char encrypted[10000] = {};
|
|
||||||
const unsigned char *plainTextArray = content.data();
|
|
||||||
int finalEncryptedLength = encrypt(plainTextArray, content.size(), aesKey, initVector, encrypted);
|
|
||||||
|
|
||||||
if (finalEncryptedLength <= 0) throw LicenceException((int)GeneralError::EncryptError, "Chyba při kryptování.");
|
|
||||||
|
|
||||||
std::vector<unsigned char> result(encrypted, encrypted + finalEncryptedLength);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<unsigned char> LicenceELC2::decryptPrivateContent(const std::vector<unsigned char> &content)
|
|
||||||
{
|
|
||||||
|
|
||||||
BYTE initVector[15] = {0};
|
|
||||||
BYTE aesKey[32] = {0};
|
|
||||||
|
|
||||||
LicenceELC2::initVector(initVector, aesKey);
|
|
||||||
|
|
||||||
const unsigned char *encryptedData = content.data();
|
|
||||||
unsigned char decrypted[10000] = {};
|
|
||||||
|
|
||||||
int decrypted_len = decrypt(encryptedData, content.size(), aesKey, initVector, decrypted);
|
|
||||||
if (decrypted_len <= 0) throw LicenceException((int)GeneralError::DecryptError, "Chyba při dekryptování.");
|
|
||||||
|
|
||||||
std::vector<unsigned char> result(decrypted, decrypted + decrypted_len);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LicenceELC2::initVector(BYTE (&iVector)[], BYTE (&key)[])
|
|
||||||
{
|
|
||||||
|
|
||||||
struct Vector15
|
|
||||||
{
|
|
||||||
int vec[15];
|
|
||||||
};
|
|
||||||
|
|
||||||
Vector15 vec1 = {this->sdCard.cardData.CID[10],
|
|
||||||
this->sdCard.cardData.CID[12],
|
|
||||||
this->sdCard.cardData.CID[11],
|
|
||||||
this->sdCard.cardData.CID[9],
|
|
||||||
this->sdCard.cardData.CID_nibble[22] - 15,
|
|
||||||
this->sdCard.cardData.CID_nibble[24] - 15,
|
|
||||||
this->sdCard.cardData.CID_nibble[25] - 15,
|
|
||||||
this->sdCard.cardData.CID_nibble[21] - 15,
|
|
||||||
9, 10, 11, 12, 13, 14, 15};
|
|
||||||
Vector15 vec2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; //TODO přidat smysluplnější indexy
|
|
||||||
Vector15 vec3 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
|
|
||||||
|
|
||||||
std::unordered_map<int, Vector15> vectors;
|
|
||||||
vectors.insert(std::pair<int, Vector15>(1, vec1));
|
|
||||||
vectors.insert(std::pair<int, Vector15>(2, vec2));
|
|
||||||
vectors.insert(std::pair<int, Vector15>(3, vec3));
|
|
||||||
|
|
||||||
struct Key32
|
|
||||||
{
|
|
||||||
int key[32];
|
|
||||||
};
|
|
||||||
|
|
||||||
Key32 key1 = {this->sdCard.cardData.CID[12],
|
|
||||||
this->sdCard.cardData.CID[23] - 15,
|
|
||||||
this->sdCard.cardData.CID[25] - 15,
|
|
||||||
this->sdCard.cardData.CID[11],
|
|
||||||
this->sdCard.cardData.CID[9],
|
|
||||||
this->sdCard.cardData.CID_nibble[21],
|
|
||||||
this->sdCard.cardData.CID[9] % 25,
|
|
||||||
this->sdCard.cardData.CID_nibble[22] - 15,
|
|
||||||
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
|
||||||
Key32 key2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
|
|
||||||
Key32 key3 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
|
|
||||||
|
|
||||||
std::unordered_map<int, Key32> keys;
|
|
||||||
keys.insert(std::pair<int, Key32>(1, key1));
|
|
||||||
keys.insert(std::pair<int, Key32>(2, key2));
|
|
||||||
keys.insert(std::pair<int, Key32>(3, key3));
|
|
||||||
|
|
||||||
int lVersion = lIdentification.licenceVersion;
|
|
||||||
|
|
||||||
iVector[0] = vectors.at(lVersion).vec[0];
|
|
||||||
iVector[1] = vectors.at(lVersion).vec[1];
|
|
||||||
iVector[2] = vectors.at(lVersion).vec[2];
|
|
||||||
iVector[3] = vectors.at(lVersion).vec[3];
|
|
||||||
iVector[4] = vectors.at(lVersion).vec[4];
|
|
||||||
iVector[5] = vectors.at(lVersion).vec[5];
|
|
||||||
iVector[6] = vectors.at(lVersion).vec[6];
|
|
||||||
iVector[7] = vectors.at(lVersion).vec[7];
|
|
||||||
|
|
||||||
memcpy(&iVector[8], &iVector[0], 8);
|
|
||||||
|
|
||||||
key[0] = keys.at(lVersion).key[0];
|
|
||||||
key[1] = keys.at(lVersion).key[1];
|
|
||||||
key[2] = keys.at(lVersion).key[2];
|
|
||||||
key[3] = keys.at(lVersion).key[3];
|
|
||||||
key[4] = keys.at(lVersion).key[4];
|
|
||||||
key[5] = keys.at(lVersion).key[5];
|
|
||||||
key[6] = keys.at(lVersion).key[6];
|
|
||||||
key[7] = keys.at(lVersion).key[7];
|
|
||||||
memcpy(&key[8], &key[0], 8);
|
|
||||||
memcpy(&key[16], &key[6], 8);
|
|
||||||
memcpy(&key[24], &key[12], 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,462 +0,0 @@
|
|||||||
|
|
||||||
#include <openssl/conf.h>
|
|
||||||
#include <openssl/ssl.h> /* core library */
|
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
const std::string base64_chars =
|
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
||||||
|
|
||||||
const char base64_url_alphabet[] = {
|
|
||||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
|
||||||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
|
||||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
|
||||||
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
||||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_'};
|
|
||||||
|
|
||||||
void getCharsFromString(string &source, char *charArray, size_t length)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < length; i++)
|
|
||||||
{
|
|
||||||
charArray[i] = source[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void getCharsFromString(string source, char *charArray)
|
|
||||||
{
|
|
||||||
size_t length = source.length();
|
|
||||||
for (size_t i = 0; i < length; i++)
|
|
||||||
{
|
|
||||||
charArray[i] = source[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string right(const std::string &sourceString, size_t numChars)
|
|
||||||
{
|
|
||||||
if (numChars >= sourceString.size())
|
|
||||||
{
|
|
||||||
return sourceString; // If numChars is greater or equal to the string size, return the whole string.
|
|
||||||
}
|
|
||||||
return sourceString.substr(sourceString.size() - numChars);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t calculateCRC16(const uint8_t *data, size_t length)
|
|
||||||
{
|
|
||||||
const uint16_t polynomial = 0xA001; // CRC16-CCITT polynomial
|
|
||||||
uint16_t crc = 0xFFFF; // Initial value
|
|
||||||
|
|
||||||
for (size_t i = 0; i < length; i++)
|
|
||||||
{
|
|
||||||
crc ^= data[i]; // XOR with the current data byte
|
|
||||||
|
|
||||||
for (int j = 0; j < 8; j++)
|
|
||||||
{
|
|
||||||
if (crc & 0x0001)
|
|
||||||
{
|
|
||||||
crc = (crc >> 1) ^ polynomial;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
crc = crc >> 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return crc;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t crc16(const unsigned char *data_p, unsigned char length)
|
|
||||||
{
|
|
||||||
uint16_t x;
|
|
||||||
uint16_t crc = 0xFFFF;
|
|
||||||
|
|
||||||
while (length--)
|
|
||||||
{
|
|
||||||
x = crc >> 8 ^ *data_p++;
|
|
||||||
x ^= x >> 4;
|
|
||||||
crc = (crc << 8) ^ ((unsigned short)(x << 12)) ^ ((unsigned short)(x << 5)) ^ ((unsigned short)x);
|
|
||||||
}
|
|
||||||
return crc;
|
|
||||||
}
|
|
||||||
|
|
||||||
DATE getLicDate()
|
|
||||||
{
|
|
||||||
time_t ttime = time(0);
|
|
||||||
tm *local_time = localtime(&ttime);
|
|
||||||
int hoursSeconds = 3600 * local_time->tm_hour;
|
|
||||||
int minutesSeconds = 60 * local_time->tm_min;
|
|
||||||
int seconds = 1 * local_time->tm_sec;
|
|
||||||
int totalSeconds = hoursSeconds + minutesSeconds + seconds;
|
|
||||||
|
|
||||||
#ifdef WINDOWS
|
|
||||||
DATE dateOnly = ttime - totalSeconds + 7200; // (pro windows); // 7200 + vteřina za dvě hodiny pro srování
|
|
||||||
#else
|
|
||||||
DATE dateOnly = ttime - totalSeconds;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return dateOnly;
|
|
||||||
}
|
|
||||||
|
|
||||||
string getDate()
|
|
||||||
{
|
|
||||||
auto r = std::chrono::system_clock::now();
|
|
||||||
auto rp = std::chrono::system_clock::to_time_t(r);
|
|
||||||
std::string h(ctime(&rp)); // converting to c++ string
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
int encrypt(const unsigned char *plaintext, int plaintext_len, unsigned char *key,
|
|
||||||
unsigned char *iv, unsigned char *ciphertext)
|
|
||||||
{
|
|
||||||
EVP_CIPHER_CTX *ctx;
|
|
||||||
|
|
||||||
int len;
|
|
||||||
|
|
||||||
int ciphertext_len;
|
|
||||||
|
|
||||||
/* Create and initialise the context */
|
|
||||||
if (!(ctx = EVP_CIPHER_CTX_new()))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Initialise the encryption operation. IMPORTANT - ensure you use a key
|
|
||||||
* and IV size appropriate for your cipher
|
|
||||||
* In this example we are using 256 bit AES (i.e. a 256 bit key). The
|
|
||||||
* IV size for *most* modes is the same as the block size. For AES this
|
|
||||||
* is 128 bits
|
|
||||||
*/
|
|
||||||
if (1 != EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Provide the message to be encrypted, and obtain the encrypted output.
|
|
||||||
* EVP_EncryptUpdate can be called multiple times if necessary
|
|
||||||
*/
|
|
||||||
if (1 != EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, plaintext_len))
|
|
||||||
return -1;
|
|
||||||
ciphertext_len = len;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Finalise the encryption. Further ciphertext bytes may be written at
|
|
||||||
* this stage.
|
|
||||||
*/
|
|
||||||
if (1 != EVP_EncryptFinal_ex(ctx, ciphertext + len, &len))
|
|
||||||
return -1;
|
|
||||||
ciphertext_len += len;
|
|
||||||
|
|
||||||
/* Clean up */
|
|
||||||
EVP_CIPHER_CTX_free(ctx);
|
|
||||||
|
|
||||||
return ciphertext_len;
|
|
||||||
}
|
|
||||||
|
|
||||||
int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char *key,
|
|
||||||
unsigned char *iv, unsigned char *plaintext)
|
|
||||||
{
|
|
||||||
EVP_CIPHER_CTX *ctx;
|
|
||||||
|
|
||||||
int len;
|
|
||||||
|
|
||||||
int plaintext_len;
|
|
||||||
|
|
||||||
/* Create and initialise the context */
|
|
||||||
if (!(ctx = EVP_CIPHER_CTX_new()))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Initialise the decryption operation. IMPORTANT - ensure you use a key
|
|
||||||
* and IV size appropriate for your cipher
|
|
||||||
* In this example we are using 256 bit AES (i.e. a 256 bit key). The
|
|
||||||
* IV size for *most* modes is the same as the block size. For AES this
|
|
||||||
* is 128 bits
|
|
||||||
*/
|
|
||||||
if (1 != EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Provide the message to be decrypted, and obtain the plaintext output.
|
|
||||||
* EVP_DecryptUpdate can be called multiple times if necessary.
|
|
||||||
*/
|
|
||||||
if (1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len))
|
|
||||||
return -1;
|
|
||||||
plaintext_len = len;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Finalise the decryption. Further plaintext bytes may be written at
|
|
||||||
* this stage.
|
|
||||||
*/
|
|
||||||
if (1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
plaintext_len += len;
|
|
||||||
|
|
||||||
/* Clean up */
|
|
||||||
EVP_CIPHER_CTX_free(ctx);
|
|
||||||
|
|
||||||
return plaintext_len;
|
|
||||||
}
|
|
||||||
|
|
||||||
// converts character array
|
|
||||||
// to string and returns it
|
|
||||||
string convertToString(char *a, int size)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
string s = "";
|
|
||||||
for (i = 0; i < size; i++)
|
|
||||||
{
|
|
||||||
s = s + a[i];
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string base64_decode(const std::string &in)
|
|
||||||
{
|
|
||||||
std::string out;
|
|
||||||
std::vector<int> T(256, -1);
|
|
||||||
unsigned int i;
|
|
||||||
for (i = 0; i < 64; i++)
|
|
||||||
T[base64_url_alphabet[i]] = i;
|
|
||||||
|
|
||||||
int val = 0, valb = -8;
|
|
||||||
for (i = 0; i < in.length(); i++)
|
|
||||||
{
|
|
||||||
unsigned char c = in[i];
|
|
||||||
if (T[c] == -1)
|
|
||||||
break;
|
|
||||||
val = (val << 6) + T[c];
|
|
||||||
valb += 6;
|
|
||||||
if (valb >= 0)
|
|
||||||
{
|
|
||||||
out.push_back(char((val >> valb) & 0xFF));
|
|
||||||
valb -= 8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string base64_encode_ai(const std::string &input)
|
|
||||||
{
|
|
||||||
std::string encoded;
|
|
||||||
|
|
||||||
size_t input_length = input.length();
|
|
||||||
size_t i = 0;
|
|
||||||
|
|
||||||
while (i < input_length)
|
|
||||||
{
|
|
||||||
unsigned char input_chunk[3] = {0};
|
|
||||||
size_t chunk_size = 0;
|
|
||||||
|
|
||||||
// Fill the input chunk with up to 3 bytes from the input string
|
|
||||||
for (size_t j = 0; j < 3; ++j)
|
|
||||||
{
|
|
||||||
if (i < input_length)
|
|
||||||
{
|
|
||||||
input_chunk[j] = input[i++];
|
|
||||||
++chunk_size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Encode the input chunk into 4 Base64 characters
|
|
||||||
encoded += base64_chars[(input_chunk[0] & 0xFC) >> 2];
|
|
||||||
encoded += base64_chars[((input_chunk[0] & 0x03) << 4) |
|
|
||||||
((input_chunk[1] & 0xF0) >> 4)];
|
|
||||||
encoded += (chunk_size > 1)
|
|
||||||
? base64_chars[((input_chunk[1] & 0x0F) << 2) |
|
|
||||||
((input_chunk[2] & 0xC0) >> 6)]
|
|
||||||
: '=';
|
|
||||||
encoded += (chunk_size > 2)
|
|
||||||
? base64_chars[input_chunk[2] & 0x3F]
|
|
||||||
: '=';
|
|
||||||
}
|
|
||||||
|
|
||||||
return encoded;
|
|
||||||
}
|
|
||||||
|
|
||||||
unordered_map<string, string> getArguments(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
const char splitChar = '=';
|
|
||||||
unordered_map<string, string> 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;
|
|
||||||
|
|
||||||
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];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result.insert(make_pair(argName, argValue));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
string getCompletePath(string fileName)
|
|
||||||
{
|
|
||||||
#ifdef WINDOWS
|
|
||||||
return fileName;
|
|
||||||
#else
|
|
||||||
char path[PATH_MAX + 1] = {};
|
|
||||||
ssize_t length = readlink("/proc/self/exe", path, PATH_MAX);
|
|
||||||
path[length] = '\0';
|
|
||||||
string result = string(dirname(path)) + "/" + fileName;
|
|
||||||
return result;
|
|
||||||
// return std::string( result, (count > 0) ? count : 0 );
|
|
||||||
// std::filesystem::path exePath = std::filesystem::canonical("/proc/self/exe"); // / std::filesystem::path(argv[0]));
|
|
||||||
// std::filesystem::path fullPathOther = exePath.parent_path() / fileName;
|
|
||||||
// std::string fullPathStrOther = fullPathOther.string();
|
|
||||||
// return fullPathStrOther;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void appendStringToVector(const std::string &str, std::vector<unsigned char> &charVector)
|
|
||||||
{
|
|
||||||
size_t strLength = str.length();
|
|
||||||
for (size_t i = 0; i < strLength; ++i)
|
|
||||||
{
|
|
||||||
charVector.push_back(static_cast<unsigned char>(str[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t calculateCRC16(std::vector<char> &charVector)
|
|
||||||
{
|
|
||||||
const uint16_t polynomial = 0xA001; // CRC16-CCITT polynomial
|
|
||||||
uint16_t crc = 0xFFFF; // Initial value
|
|
||||||
|
|
||||||
size_t length = charVector.size();
|
|
||||||
|
|
||||||
for (size_t i = 0; i < length; i++)
|
|
||||||
{
|
|
||||||
crc ^= charVector[i]; // XOR with the current data byte
|
|
||||||
|
|
||||||
for (int j = 0; j < 8; j++)
|
|
||||||
{
|
|
||||||
if (crc & 0x0001)
|
|
||||||
{
|
|
||||||
crc = (crc >> 1) ^ polynomial;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
crc = crc >> 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return crc;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t calculateCRC16(std::vector<unsigned char> &charVector)
|
|
||||||
{
|
|
||||||
const uint16_t polynomial = 0xA001; // CRC16-CCITT polynomial
|
|
||||||
uint16_t crc = 0xFFFF; // Initial value
|
|
||||||
|
|
||||||
size_t length = charVector.size();
|
|
||||||
|
|
||||||
for (size_t i = 0; i < length; i++)
|
|
||||||
{
|
|
||||||
crc ^= charVector[i]; // XOR with the current data byte
|
|
||||||
|
|
||||||
for (int j = 0; j < 8; j++)
|
|
||||||
{
|
|
||||||
if (crc & 0x0001)
|
|
||||||
{
|
|
||||||
crc = (crc >> 1) ^ polynomial;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
crc = crc >> 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return crc;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t calculateCRC16(std::vector<unsigned char> &charVector, int removeCount)
|
|
||||||
{
|
|
||||||
const uint16_t polynomial = 0xA001; // CRC16-CCITT polynomial
|
|
||||||
uint16_t crc = 0xFFFF; // Initial value
|
|
||||||
|
|
||||||
size_t length = charVector.size();
|
|
||||||
length = length-removeCount;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < length; i++)
|
|
||||||
{
|
|
||||||
crc ^= charVector[i]; // XOR with the current data byte
|
|
||||||
|
|
||||||
for (int j = 0; j < 8; j++)
|
|
||||||
{
|
|
||||||
if (crc & 0x0001)
|
|
||||||
{
|
|
||||||
crc = (crc >> 1) ^ polynomial;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
crc = crc >> 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return crc;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t bytesToDword(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
|
|
||||||
{
|
|
||||||
return static_cast<uint32_t>(byte1) |
|
|
||||||
(static_cast<uint32_t>(byte2) << 8) |
|
|
||||||
(static_cast<uint32_t>(byte3) << 16) |
|
|
||||||
(static_cast<uint32_t>(byte4) << 24);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t bytesToWord(uint8_t byte1, uint8_t byte2)
|
|
||||||
{
|
|
||||||
return static_cast<uint32_t>(byte1) | (static_cast<uint32_t>(byte2) << 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<unsigned char> joinVectors(const std::vector<unsigned char> &vector1, const std::vector<unsigned char> &vector2)
|
|
||||||
{
|
|
||||||
std::vector<unsigned char> result;
|
|
||||||
result.insert(result.end(), vector1.begin(), vector1.end());
|
|
||||||
result.insert(result.end(), vector2.begin(), vector2.end());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool readFile(string fileName, vector<char> &output)
|
|
||||||
{
|
|
||||||
std::ifstream file(fileName, std::ios::in | std::ios::binary);
|
|
||||||
|
|
||||||
if (file.is_open() != 1)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
char byte;
|
|
||||||
while (file.get(byte))
|
|
||||||
{
|
|
||||||
// Convert the char to unsigned char and push it into the vector
|
|
||||||
output.push_back(byte);
|
|
||||||
}
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
9f54495344434954615ad803c50171bf
|
|
||||||
6 . x4 <20><><EFBFBD> .. nt$6 &<26> manfid 6 <20><><EFBFBD>
|
|
||||||
cid "6 <10> fwrev 6 Jm<4A> csd ,6 gEd$
|
|
||||||
subsystem 46 <20><><EFBFBD>%
|
|
||||||
driver (6 <20><><EFBFBD>- ocr -6 <20><><EFBFBD>? power *6 <>4L type 6 <20>1M date #6 <20>rTP hwrev )6 n<>yR dsr '6 <20>` serial 6 NN<4E>m erase_size <20>6 <20>6<EFBFBD>m block 6 <20><><EFBFBD>n uevent 6 <18><>o ssr 6 <1E>q scr &6 &<26><>y oemid !6 <20><><EFBFBD>y ( preferred_erase_size %6 <20><><EFBFBD> name
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
400e00325b5900003be77f800a400043
|
|
||||||
|
|
||||||
Binary file not shown.
Binary file not shown.
@@ -1,29 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<licence elc="2" xmlVersion="1" revision="1" compatibility="1">
|
|
||||||
<licenceType licenceVersion="1" licenceIndex="0">EOV_OSV</licenceType>
|
|
||||||
<plcType>wago</plcType>
|
|
||||||
<licenceName>Licence pro EOV_OSV</licenceName>
|
|
||||||
<project>testovaci projekt</project>
|
|
||||||
<items>
|
|
||||||
<item>
|
|
||||||
<name>pt_Ez_iec104c</name>
|
|
||||||
<protoId>5</protoId>
|
|
||||||
<dataPointsCount>2500</dataPointsCount>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<name>pt_Ez_iec104s</name>
|
|
||||||
<protoId>6</protoId>
|
|
||||||
<dataPointsCount>15000</dataPointsCount>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<name>pt_Ez_mdbipc</name>
|
|
||||||
<protoId>9</protoId>
|
|
||||||
<dataPointsCount>250</dataPointsCount>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<name>pt_Ez_mdbips</name>
|
|
||||||
<protoId>10</protoId>
|
|
||||||
<dataPointsCount>400</dataPointsCount>
|
|
||||||
</item>
|
|
||||||
</items>
|
|
||||||
</licence>
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<licence elc="2" xmlVersion="1" revision="1" compatibility="1">
|
|
||||||
<licenceType licenceVersion="1" licenceIndex="0">EOV_OSV</licenceType>
|
|
||||||
<plcType>WAGO</plcType>
|
|
||||||
<licenceName>Licence pro EOV_OSV</licenceName>
|
|
||||||
<station>odb.zaluzi.drt.cz</station>
|
|
||||||
<distributor>POZ8</distributor>
|
|
||||||
<project>Projekt XXX stanice YYY</project>
|
|
||||||
<items>
|
|
||||||
<item>
|
|
||||||
<name>Položka licence 1</name>
|
|
||||||
<protoId>111</protoId>
|
|
||||||
<dataPointsCount>40000</dataPointsCount>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<name>Položka licence 2</name>
|
|
||||||
<protoId>222</protoId>
|
|
||||||
<dataPointsCount>51000</dataPointsCount>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<name>Položka licence 3</name>
|
|
||||||
<protoId>333</protoId>
|
|
||||||
<dataPointsCount>62000</dataPointsCount>
|
|
||||||
</item>
|
|
||||||
</items>
|
|
||||||
|
|
||||||
</licence>
|
|
||||||
@@ -1,265 +0,0 @@
|
|||||||
#include <licenceReader.h>
|
|
||||||
|
|
||||||
ELCType licElcType = ELCType::ELC2;
|
|
||||||
LicenceType licLicenceType;
|
|
||||||
PlcType licPlcType;
|
|
||||||
|
|
||||||
uint8_t licenceVersion = 1; // verze licence, určitě kodování, pojmenování souborů
|
|
||||||
uint8_t licenceIndex = 0;
|
|
||||||
uint8_t revision;
|
|
||||||
uint8_t licCompatibility = 1; // identikator hlavního ELC
|
|
||||||
|
|
||||||
LicenceReader::LicenceReader()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @brief provede pouze inicialazaci čtecí třídy
|
|
||||||
/// @param elcType
|
|
||||||
/// @param initStructure
|
|
||||||
/// @return
|
|
||||||
bool LicenceReader::init(int elcType, InitStructure &initStructure)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (elcType > 3)
|
|
||||||
{
|
|
||||||
error.code = (int)GeneralError::ELCNotImplemented;
|
|
||||||
error.message = "ELC není implementováno.";
|
|
||||||
throw LicenceException((int)GeneralError::ELCNotImplemented, error.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->licIdentification.licElcType = (ELCType)elcType;
|
|
||||||
this->licIdentification.licLicenceType = (LicenceType)initStructure.licenceType;
|
|
||||||
this->licIdentification.licenceVersion = licenceVersion;
|
|
||||||
this->licIdentification.licenceIndex = licenceIndex;
|
|
||||||
this->licIdentification.licCompatibility = initStructure.compatibility;
|
|
||||||
}
|
|
||||||
catch (const LicenceException &ex)
|
|
||||||
{
|
|
||||||
error.code = ex.getErrorCode();
|
|
||||||
error.message = ex.getErrorMessage();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
elcSwitchType = elcType * 10 + licCompatibility;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @brief provede inicializaci čtecí třídy a zároveň načte licenční body do obecné struktury
|
|
||||||
/// @param elcType
|
|
||||||
/// @param licenceType
|
|
||||||
/// @param licenceVersion
|
|
||||||
/// @param licenceIndex
|
|
||||||
/// @param compatibility
|
|
||||||
/// @return
|
|
||||||
bool LicenceReader::initread(int elcType, InitStructure &initStructure)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
elcSwitchType = elcType * 10 + initStructure.compatibility;
|
|
||||||
|
|
||||||
if (init(elcType, initStructure))
|
|
||||||
{
|
|
||||||
switch (this->licIdentification.licElcType)
|
|
||||||
{
|
|
||||||
case ELCType::ELC1:
|
|
||||||
{
|
|
||||||
Reader::Licence1 licenceELC1 = Reader::Licence1(this->licIdentification);
|
|
||||||
this->licence1 = &licenceELC1;
|
|
||||||
licenceELC1.cid_cdsPath = initStructure.cid_csd_filePath;
|
|
||||||
licenceELC1.licenceFilePath = initStructure.licenceFilePath;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this->licence1->readLicence(&this->licenceInfo);
|
|
||||||
}
|
|
||||||
catch (const LicenceException &ex)
|
|
||||||
{
|
|
||||||
error.code = ex.getErrorCode();
|
|
||||||
error.message = ex.getErrorMessage();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ELCType::ELC2:
|
|
||||||
{
|
|
||||||
Reader::Licence2 licenceELC2 = Reader::Licence2(this->licIdentification);
|
|
||||||
this->licence2 = &licenceELC2;
|
|
||||||
licenceELC2.cid_cdsPath = initStructure.cid_csd_filePath;
|
|
||||||
licenceELC2.licenceFilePath = initStructure.licenceFilePath;
|
|
||||||
this->licence2->readLicence(&this->licenceInfo);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ELCType::ELC3:
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
throw LicenceException((int)GeneralError::ELCNotImplemented, "Toto ELC není implementováno");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (const LicenceException &ex)
|
|
||||||
{
|
|
||||||
error.code = ex.getErrorCode();
|
|
||||||
error.message = ex.getErrorMessage();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true; // TODO testy
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @brief vrací informace o licenčím bodu na základě id protocolu a předané návratové struktury
|
|
||||||
/// @param protocolId
|
|
||||||
/// @param returnItemStructure
|
|
||||||
/// @return
|
|
||||||
bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
switch (this->licIdentification.licElcType)
|
|
||||||
{
|
|
||||||
case ELCType::ELC1:
|
|
||||||
{
|
|
||||||
if (!this->licIdentification.licCompatibility) // defaultní kompatibilita
|
|
||||||
{
|
|
||||||
LicenceELC1Info *resultPtr = static_cast<LicenceELC1Info *>(returnItemStructure);
|
|
||||||
if (this->licenceInfo.licences.count(1)) // stare eov má natvrdo "id" 1.
|
|
||||||
resultPtr->isValid = true;
|
|
||||||
else
|
|
||||||
resultPtr->isValid = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Kompatibilita není implementována.");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ELCType::ELC2:
|
|
||||||
{
|
|
||||||
if (!this->licIdentification.licCompatibility) // defaultní kompatibilita
|
|
||||||
{
|
|
||||||
LicenceELC2Item *resultPtr = static_cast<LicenceELC2Item *>(returnItemStructure);
|
|
||||||
resultPtr->protocolId = protocolId;
|
|
||||||
if (this->licenceInfo.licences.count(protocolId))
|
|
||||||
resultPtr->dataPointsCount = this->licenceInfo.licences.at(protocolId);
|
|
||||||
else
|
|
||||||
resultPtr->dataPointsCount = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
switch (this->licIdentification.licCompatibility)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
// kod pro kompatibilitu 1
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Kompatibilita není implementována.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ELCType::ELC3:
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
error.code = -1;
|
|
||||||
error.message = "Nepodařilo se identifikovat licenci";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (const LicenceException &ex)
|
|
||||||
{
|
|
||||||
error.code = ex.getErrorCode();
|
|
||||||
error.message = ex.getErrorMessage();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @brief vrací informace o všech licenčních bodech základě předané návratové struktury
|
|
||||||
/// @param returnStructure
|
|
||||||
/// @return
|
|
||||||
bool LicenceReader::getLicenceInfo(void *returnStructure)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
switch (this->licIdentification.licElcType)
|
|
||||||
{
|
|
||||||
case ELCType::ELC1:
|
|
||||||
{ // old eoseov
|
|
||||||
if (!this->licIdentification.licCompatibility) // defaultní kompatibilita
|
|
||||||
{
|
|
||||||
LicenceELC1Info *resultPtr = static_cast<LicenceELC1Info *>(returnStructure);
|
|
||||||
|
|
||||||
if (this->licenceInfo.licences.count(1)) // starý EOS má natvrdo "id" 1
|
|
||||||
{
|
|
||||||
resultPtr->isValid = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
resultPtr->isValid = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
switch (this->licIdentification.licCompatibility)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
// kod pro kompatibilitu 1
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Kompatibilita není implementována.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ELCType::ELC2:
|
|
||||||
{
|
|
||||||
if (!this->licIdentification.licCompatibility) // defaultní kompatibilita
|
|
||||||
{
|
|
||||||
Reader::Licence2 licenceELC2 = Reader::Licence2(this->licIdentification);
|
|
||||||
licenceELC2.readLicence(&this->licenceInfo);
|
|
||||||
licenceELC2.getLicenceInfo(returnStructure);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
switch (this->licIdentification.licCompatibility)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
// kod pro kompatibilitu 1
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Kompatibilita není implementována.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ELCType::ELC3:
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (const LicenceException &ex)
|
|
||||||
{
|
|
||||||
error.code = ex.getErrorCode();
|
|
||||||
error.message = ex.getErrorMessage();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
LicenceReader::~LicenceReader()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<licence elc="2" xmlVersion="1" revision="1" compatibility="1">
|
|
||||||
<licenceType licenceVersion="1" licenceIndex="0">EOV_OSV</licenceType>
|
|
||||||
<plcType>WAGO</plcType>
|
|
||||||
<licenceName>Licence pro EOV_OSV</licenceName>
|
|
||||||
<station>eov.ceskatrebova.ddts.cz</station>
|
|
||||||
<distributor>eov2</distributor>
|
|
||||||
<project>Projekt XXX stanice YYY</project>
|
|
||||||
<items>
|
|
||||||
<item>
|
|
||||||
<name>Položka licence 1</name>
|
|
||||||
<protoId>111</protoId>
|
|
||||||
<dataPointsCount>100</dataPointsCount>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<name>Položka licence 2</name>
|
|
||||||
<protoId>222</protoId>
|
|
||||||
<dataPointsCount>200</dataPointsCount>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<name>Položka licence 3</name>
|
|
||||||
<protoId>333</protoId>
|
|
||||||
<dataPointsCount>300</dataPointsCount>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<name>Položka licence 3</name>
|
|
||||||
<protoId>444</protoId>
|
|
||||||
<dataPointsCount>1600</dataPointsCount>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<name>Položka licence 4</name>
|
|
||||||
<protoId>555</protoId>
|
|
||||||
<dataPointsCount>1999</dataPointsCount>
|
|
||||||
</item>
|
|
||||||
</items>
|
|
||||||
|
|
||||||
</licence>
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
#include "licReaderELC1.h"
|
|
||||||
|
|
||||||
namespace Reader
|
|
||||||
{
|
|
||||||
Licence1::Licence1() {}
|
|
||||||
|
|
||||||
Licence1::~Licence1() {}
|
|
||||||
|
|
||||||
Licence1::Licence1(LicenceIdentification &licIdentification) : LicenceELC1(licIdentification)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @brief načte seznam licenčních bodů do obecné struktury
|
|
||||||
/// @param licences
|
|
||||||
/// @return
|
|
||||||
bool Licence1::readLicence(LicenceInfoGeneral *licences)
|
|
||||||
{
|
|
||||||
sdCard = SDCard(this->cid_cdsPath);
|
|
||||||
if (sdCard.isLoaded == false) throw LicenceException((int)GeneralError::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath);
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < CID_LENGTH;i++) this->cid[i] = sdCard.cid[i];
|
|
||||||
for (unsigned int i = 0; i < CSD_LENGTH;i++) this->csd[i] = sdCard.csd[i];
|
|
||||||
|
|
||||||
if (getSDData() == false) throw LicenceException((int)GeneralError::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath);
|
|
||||||
|
|
||||||
string licFileName = getLicenceName(0);
|
|
||||||
string licFilePath = this->licenceFilePath + licFileName;
|
|
||||||
|
|
||||||
char licFileNameToRead[licFilePath.length()+1] = {};
|
|
||||||
getCharsFromString(licFilePath, licFileNameToRead, licFilePath.length());
|
|
||||||
|
|
||||||
FILE *licenceFile;
|
|
||||||
char ch;
|
|
||||||
|
|
||||||
licenceFile = fopen(licFileNameToRead, "rb");
|
|
||||||
|
|
||||||
if (licenceFile == nullptr) throw LicenceException((int)GeneralError::LicenceReadError, "LicenceReadError: " + licFilePath);
|
|
||||||
|
|
||||||
fseek(licenceFile, 0, SEEK_END);
|
|
||||||
const int size = ftell(licenceFile);
|
|
||||||
fseek(licenceFile, 0, SEEK_SET);
|
|
||||||
|
|
||||||
if (size <= 0) throw LicenceException((int)GeneralError::LicenceSizeMismatch, "LicenceSizeMismatch: " + licFilePath);
|
|
||||||
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
unsigned char licenceContent[size];
|
|
||||||
|
|
||||||
for (int i = 0; i < size; i++)
|
|
||||||
{
|
|
||||||
ch = fgetc(licenceFile);
|
|
||||||
licenceContent[i] = ch;
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(licenceFile);
|
|
||||||
|
|
||||||
LicenceDataMainELC licenceHeader{};
|
|
||||||
LicenceData licEncryptedData{};
|
|
||||||
|
|
||||||
memcpy(&licenceHeader, licenceContent, sizeof(LicenceDataMainELC));
|
|
||||||
|
|
||||||
const int sizeOfEncryptedData = size - sizeof(LicenceDataMainELC);
|
|
||||||
unsigned char encryptedData[sizeOfEncryptedData] = {};
|
|
||||||
for (int i = 0; i < sizeOfEncryptedData; i++)
|
|
||||||
encryptedData[i] = licenceContent[i + sizeof(LicenceDataMainELC)];
|
|
||||||
|
|
||||||
BYTE prefixType = (int)licenceContent[3] - 0x30;
|
|
||||||
if (prefixType == PrefixType::ELC1)
|
|
||||||
{
|
|
||||||
if (licenceHeader.licHeader.sizeData > 0)
|
|
||||||
{
|
|
||||||
if (licenceHeader.licHeader.licSubType == cEzLic_p78ou3_SubType_10_10)
|
|
||||||
{
|
|
||||||
initCrypto();
|
|
||||||
|
|
||||||
unsigned char decrypted[2000] = {};
|
|
||||||
int decrypted_len = decrypt(encryptedData, sizeof(encryptedData), cryptData.aesKey, cryptData.aesInitVector, decrypted);
|
|
||||||
|
|
||||||
if (sizeof(licEncryptedData) != decrypted_len)
|
|
||||||
{
|
|
||||||
throw LicenceException((int)GeneralError::LicenceSizeMismatch, "License size mismatch ");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
memcpy(&licEncryptedData, decrypted, sizeof(licEncryptedData));
|
|
||||||
|
|
||||||
if (licEncryptedData.id.version == cEzLic_p78ou3_HeaderType_10 && licEncryptedData.header.licVersion == cEzLic_p78ou3_HeaderType_10)
|
|
||||||
{
|
|
||||||
if (licEncryptedData.header.licType == cEzLic_p78ou3_IDType_EOVOSV)
|
|
||||||
{
|
|
||||||
if (licEncryptedData.header.licCount > 0)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < licMaxCount; i++)
|
|
||||||
{
|
|
||||||
licences->licences.insert(pair<int, int>(licEncryptedData.items[i].protoId, licEncryptedData.items[i].licCount));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw LicenceException((int)GeneralError::ItemsCountMismatch, "ItemsCountMismatch");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw LicenceException((int)GeneralError::LicenceMismatch, "Licence mismatch");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw LicenceException((int)GeneralError::LicenceMismatch, "Licence mismatch");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw LicenceException((int)GeneralError::LicenceReadError, "Licence error");
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
#include "licReaderELC2.h"
|
|
||||||
|
|
||||||
namespace Reader
|
|
||||||
{
|
|
||||||
|
|
||||||
Licence2::Licence2() {}
|
|
||||||
|
|
||||||
Licence2::~Licence2() {}
|
|
||||||
|
|
||||||
Licence2::Licence2(LicenceIdentification &licIdentification) : LicenceELC2(licIdentification)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @brief načte seznam licenčních bodů do obecné struktury
|
|
||||||
/// @param licences
|
|
||||||
/// @return
|
|
||||||
bool Licence2::readLicence(LicenceInfoGeneral *licences)
|
|
||||||
{
|
|
||||||
sdCard = SDCard(this->cid_cdsPath);
|
|
||||||
if (sdCard.isLoaded == false)
|
|
||||||
throw LicenceException((int)GeneralError::SDCardReadError, "Nepodařilo se načíst SD kartu., cesta: " + cid_cdsPath);
|
|
||||||
|
|
||||||
string licFileName = getLicenceName();
|
|
||||||
string licFilePath = this->licenceFilePath + licFileName;
|
|
||||||
|
|
||||||
vector<char> content;
|
|
||||||
if (readFile(licFilePath, content) == false)
|
|
||||||
{
|
|
||||||
throw LicenceException((int)GeneralError::FileOpenError, "Chyba otevření souboru licence: " + licFilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->licBody.licId.licIdent[0] = content[0];
|
|
||||||
this->licBody.licId.licIdent[1] = content[1];
|
|
||||||
this->licBody.licId.licIdent[2] = content[2];
|
|
||||||
this->licBody.licId.licIdent[3] = content[3];
|
|
||||||
this->licBody.licId.licIdent[4] = content[4];
|
|
||||||
|
|
||||||
this->licBody.licenceIdentHeader.licenceType = content[5];
|
|
||||||
this->licBody.licenceIdentHeader.licenceTypeVersion = content[6];
|
|
||||||
this->licBody.licenceIdentHeader.licenceIndex = content[7];
|
|
||||||
this->licBody.licenceIdentHeader.compatibilityVersion = content[8];
|
|
||||||
this->licBody.licenceIdentHeader.licItemCount = content[9];
|
|
||||||
this->licBody.licenceIdentHeader.publicHeaderLength = bytesToWord(content[10], content[11]);
|
|
||||||
this->licBody.licenceIdentHeader.cardSize = bytesToWord(content[12], content[13]);
|
|
||||||
this->licBody.licenceIdentHeader.serialNumber = bytesToDword(content[14], content[15], content[16], content[17]);
|
|
||||||
|
|
||||||
//~~~uint16_t crcPublic = bytesToWord(content[18 + licBody.licenceIdentHeader.publicHeaderLength], content[19 + licBody.licenceIdentHeader.publicHeaderLength]);
|
|
||||||
|
|
||||||
int elcVersion = (int)licBody.licId.licIdent[3] - 48; // verze je text, musí se odečíst 48
|
|
||||||
|
|
||||||
if (elcVersion != (int)this->lIdentification.licElcType)
|
|
||||||
{
|
|
||||||
throw LicenceException((int)GeneralError::ELCMismatch, "Nesouhlasí ELC.");
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<unsigned char> publicPart(content.begin(), content.begin() + 18 + this->licBody.licenceIdentHeader.publicHeaderLength);
|
|
||||||
|
|
||||||
#ifdef CRCCHECK
|
|
||||||
cout << "CRC read public size: " << publicPart.size() << "\n";
|
|
||||||
cout << "CRC read public: " << calculateCRC16(publicPart) << "\n";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
vector<unsigned char> encryptedPart(content.begin() + licBody.licenceIdentHeader.publicHeaderLength + 18, content.begin() + content.size());
|
|
||||||
|
|
||||||
vector<unsigned char> privateContentDecrypted;
|
|
||||||
privateContentDecrypted = decryptPrivateContent(encryptedPart);
|
|
||||||
|
|
||||||
#ifdef CRCCHECK
|
|
||||||
cout << "CRC read private size: " << privateContentDecrypted.size() << "\n";
|
|
||||||
cout << "CRC read private: " << calculateCRC16(privateContentDecrypted) << "\n";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// cout << "privateContentDecrypted content length: " << privateContentDecrypted.size() << "\n";
|
|
||||||
// for (auto x : privateContentDecrypted) cout << (int)x << "-";
|
|
||||||
// cout << "\n";
|
|
||||||
|
|
||||||
LicenceBody licBodyDecrypted;
|
|
||||||
licBodyDecrypted.licenceIdentHeader.licenceType = privateContentDecrypted[0];
|
|
||||||
licBodyDecrypted.licenceIdentHeader.licenceTypeVersion = privateContentDecrypted[1];
|
|
||||||
licBodyDecrypted.licenceIdentHeader.licenceIndex = privateContentDecrypted[2];
|
|
||||||
licBodyDecrypted.licenceIdentHeader.compatibilityVersion = privateContentDecrypted[3];
|
|
||||||
licBodyDecrypted.licenceIdentHeader.licItemCount = privateContentDecrypted[4];
|
|
||||||
licBodyDecrypted.licenceIdentHeader.publicHeaderLength = bytesToWord(privateContentDecrypted[5], privateContentDecrypted[6]);
|
|
||||||
licBodyDecrypted.licenceIdentHeader.cardSize = bytesToWord(privateContentDecrypted[7], privateContentDecrypted[8]);
|
|
||||||
licBodyDecrypted.licenceIdentHeader.serialNumber = bytesToDword(privateContentDecrypted[9], privateContentDecrypted[10], privateContentDecrypted[11], privateContentDecrypted[12]);
|
|
||||||
|
|
||||||
if (licBodyDecrypted.licenceIdentHeader.licItemCount != this->licBody.licenceIdentHeader.licItemCount)
|
|
||||||
{
|
|
||||||
throw LicenceException((int)GeneralError::ItemsCountMismatch, "Nesouhlasí počet položek licence.");
|
|
||||||
}
|
|
||||||
|
|
||||||
int index = 13;
|
|
||||||
for (int i = 0; i < this->licBody.licenceIdentHeader.licItemCount; i++)
|
|
||||||
{
|
|
||||||
licDataItem item;
|
|
||||||
item.protoId = bytesToWord(privateContentDecrypted[index], privateContentDecrypted[index + 1]);
|
|
||||||
item.licCount = bytesToWord(privateContentDecrypted[index + 2], privateContentDecrypted[index + 3]);
|
|
||||||
index += sizeof(licDataItem);
|
|
||||||
this->licBody.privateContent.dataItems.push_back(item);
|
|
||||||
this->licenceInfo.licences.insert(pair<int, int>(item.protoId, item.licCount));
|
|
||||||
licences->licences.insert(pair<int, int>(item.protoId, item.licCount));
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t crcComplete = bytesToWord(privateContentDecrypted[index], privateContentDecrypted[index + 1]);
|
|
||||||
|
|
||||||
vector<unsigned char> completeVector = joinVectors(publicPart, privateContentDecrypted);
|
|
||||||
if (calculateCRC16(completeVector, 2) != crcComplete) throw LicenceException((int)GeneralError::LicenceCRCMismatch, "Nesouhlasí CRC.");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Licence2::getLicenceInfo(void *returnStructure)
|
|
||||||
{
|
|
||||||
if (returnStructure != nullptr)
|
|
||||||
{
|
|
||||||
LicenceELC2Info *resultPtr = static_cast<LicenceELC2Info *>(returnStructure);
|
|
||||||
for (auto item : this->licBody.privateContent.dataItems)
|
|
||||||
{
|
|
||||||
resultPtr->licences.insert(pair<int, int>(item.protoId, item.licCount));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
errorMessage.code = 1;
|
|
||||||
errorMessage.message = "Error: Null pointer!";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#include "licReaderELC3.h"
|
|
||||||
|
|
||||||
namespace Reader
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user