oddělení, čištění, kontrola ELC1
This commit is contained in:
@@ -47,15 +47,6 @@ enum class GeneralError
|
||||
ItemsCountMismatch = 61
|
||||
};
|
||||
|
||||
// unordered_map<GeneralError, string> mapGeneralErrors = {
|
||||
// {GeneralError::SDCardReadError, "Nepodařilo se načíst SD kartu."},
|
||||
// {GeneralError::ItemsCountMismatch, "Nesouhlasí počet položek licence."},
|
||||
// {GeneralError::LicenceSizeMismatch, "Nesouhlasí velikost souboru licence."},
|
||||
// {GeneralError::LicenceSizeCardMismatch, "Nesouhlasí velikost SD karty."},
|
||||
// {GeneralError::LicenceMismatch, "Nesouhlasí licence."},
|
||||
// {GeneralError::ItemsCountMismatch, "Nesouhlasí počet položek licence."}
|
||||
// };
|
||||
|
||||
enum class ELCType
|
||||
{
|
||||
ELC1 = 1,
|
||||
@@ -120,14 +111,19 @@ struct LicenceIdentification
|
||||
uint8_t licenceVersion = 1; // verze licence, určuje kodování, pojmenování souborů
|
||||
uint8_t licenceIndex = 0;
|
||||
uint8_t revision;
|
||||
uint8_t licCompatibility = 1; // identikator hlavního ELC
|
||||
|
||||
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
|
||||
{
|
||||
@@ -135,103 +131,54 @@ struct LicenceItem
|
||||
int dataPointsCount = 0;
|
||||
};
|
||||
|
||||
/// @brief struktura polozky licence, kompatibilita 1
|
||||
struct LicenceItemCompatibility1
|
||||
{
|
||||
int protocolId = -1;
|
||||
int dataPointsCount = 0;
|
||||
};
|
||||
|
||||
/// @brief struktura polozky licence, kompatibilita 2
|
||||
struct LicenceItemCompatibility2
|
||||
{
|
||||
int protocolId = -1;
|
||||
int dataPointsCount = 0;
|
||||
};
|
||||
|
||||
/// @brief struktura polozky licence, kompatibilita 3
|
||||
struct LicenceItemCompatibility3
|
||||
{
|
||||
int protocolId = -1;
|
||||
int dataPointsCount = 0;
|
||||
};
|
||||
|
||||
|
||||
struct LicenceItem11
|
||||
{
|
||||
int protocolId = -1;
|
||||
int dataPointsCount = 0;
|
||||
};
|
||||
|
||||
struct LicenceItem21
|
||||
{
|
||||
int protocolId = -1;
|
||||
int dataPointsCount = 0;
|
||||
};
|
||||
|
||||
struct LicenceItem31
|
||||
{
|
||||
int protocolId = -1;
|
||||
int dataPointsCount = 0;
|
||||
};
|
||||
|
||||
/// @brief základní struktura, seznam polozek licencí
|
||||
struct LicenceInfo
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
unordered_map<int, int> licences = {};
|
||||
};
|
||||
|
||||
/// @brief základní struktura, seznam polozek licencí, kompatibilita 1
|
||||
struct LicenceInfoCompatibility1
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
unordered_map<int, int> licences = {};
|
||||
};
|
||||
|
||||
/// @brief základní struktura, seznam polozek licencí, kompatibilita 2
|
||||
struct LicenceInfoCompatibility2
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
unordered_map<int, int> licences = {};
|
||||
};
|
||||
|
||||
/// @brief základní struktura, seznam polozek licencí, kompatibilita 3
|
||||
struct LicenceInfoCompatibility3
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
unordered_map<int, int> licences = {};
|
||||
};
|
||||
|
||||
struct LicenceInfo1
|
||||
/* struktury pro ELC 1 */
|
||||
//defaultní struktura pro ELC 1
|
||||
struct LicenceELC1Info
|
||||
{
|
||||
bool isValid {false};
|
||||
};
|
||||
|
||||
struct LicenceInfo11
|
||||
//struktura ELC1, kompatibilita 1
|
||||
struct LicenceELC1Info_1
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
unordered_map<int, int> licences = {};
|
||||
};
|
||||
|
||||
struct LicenceInfo21
|
||||
//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
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
unordered_map<int, int> licences = {};
|
||||
};
|
||||
|
||||
struct LicenceInfo31
|
||||
struct LicenceELC2Info_1
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
unordered_map<int, int> licences = {};
|
||||
};
|
||||
|
||||
struct LicenceInfoGeneral
|
||||
//defaultni struktura polozky ELC 2
|
||||
struct LicenceELC2Item
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
unordered_map<int, int> licences = {};
|
||||
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:
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//#define LINUX 1
|
||||
#define WINDOWS 1
|
||||
|
||||
#ifndef UTILS_H_
|
||||
#define UTILS_H_
|
||||
|
||||
@@ -12,6 +9,7 @@
|
||||
#include <format>
|
||||
#include <libgen.h> // dirname
|
||||
#include <climits>
|
||||
#include <unistd.h>
|
||||
|
||||
typedef uint8_t BYTE;
|
||||
typedef uint16_t WORD;
|
||||
|
||||
@@ -7,19 +7,20 @@
|
||||
#include <stdint.h>
|
||||
#include "pugixml.hpp"
|
||||
#include "licenceCommon.h"
|
||||
#include "licenceELC11.h"
|
||||
#include "licenceELC21.h"
|
||||
#include "licenceELC31.h"
|
||||
// #include "licenceELC11.h"
|
||||
// #include "licenceELC21.h"
|
||||
// #include "licenceELC31.h"
|
||||
|
||||
#include "licGenELC1.h"
|
||||
#include "licGenELC2.h"
|
||||
#include "licGenELC3.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
class LicenceGenerator
|
||||
{
|
||||
|
||||
public:
|
||||
struct LicData
|
||||
{
|
||||
string station = "";
|
||||
@@ -32,31 +33,27 @@ class LicenceGenerator
|
||||
pugi::xml_document *doc;
|
||||
};
|
||||
|
||||
public:
|
||||
LicData licData;
|
||||
int elcSwitchType;
|
||||
string operationErrors = "";
|
||||
pugi::xml_document doc;
|
||||
bool argumentsCorrect = false;
|
||||
ErrorMessage error;
|
||||
LicenceELC11 *licence11;
|
||||
LicenceELC21 *licence21;
|
||||
LicenceELC31 *licence31;
|
||||
// LicenceELC11 *licence11;
|
||||
// LicenceELC21 *licence21;
|
||||
// LicenceELC31 *licence31;
|
||||
Mapping mapping;
|
||||
|
||||
|
||||
LicenceGenerator();
|
||||
~LicenceGenerator();
|
||||
LicenceGenerator(string uid, string cid, string csd, string dataFileName);
|
||||
|
||||
|
||||
void createLicenceFile();
|
||||
|
||||
|
||||
LicenceInfoGeneral licenceInfo;
|
||||
|
||||
|
||||
private:
|
||||
LicenceIdentification licIdentification;
|
||||
LicData licData;
|
||||
string configFileName = "";
|
||||
|
||||
void *licence = nullptr;
|
||||
@@ -66,7 +63,6 @@ private:
|
||||
void createLicenceELC1();
|
||||
void createLicenceELC2();
|
||||
void createLicenceELC3();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -944,13 +944,17 @@ namespace pugi
|
||||
char _memory[192];
|
||||
|
||||
// Non-copyable semantics
|
||||
xml_document(const xml_document&);
|
||||
xml_document& operator=(const xml_document&);
|
||||
// xml_document(const xml_document&);
|
||||
// xml_document& operator=(const xml_document&);
|
||||
|
||||
void create();
|
||||
void destroy();
|
||||
|
||||
public:
|
||||
|
||||
xml_document(const xml_document&);
|
||||
xml_document& operator=(const xml_document&);
|
||||
|
||||
// Default constructor, makes empty document
|
||||
xml_document();
|
||||
|
||||
|
||||
@@ -1,281 +0,0 @@
|
||||
#ifndef PLC_LICENCE11_H
|
||||
#define PLC_LICENCE11_H
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <vector>
|
||||
#include <wchar.h>
|
||||
#include <time.h>
|
||||
#include <map>
|
||||
#include <stdint.h>
|
||||
#include "licenceCommon.h"
|
||||
#include "SDCard.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#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;
|
||||
|
||||
/// @brief licence class
|
||||
class LicenceELC11
|
||||
{
|
||||
|
||||
enum class Error11
|
||||
{
|
||||
SDCardReadError = 50,
|
||||
LicenceReadError = 51,
|
||||
LicenceSizeMismatch = 52,
|
||||
LicenceSizeCardMismatch = 53,
|
||||
LicenceMismatch = 54,
|
||||
ItemsCountMismatch = 61
|
||||
};
|
||||
|
||||
// unordered_map<Error11, string> map11Errors = {
|
||||
// {Error11::SDCardReadError, "Nepodařilo se načíst SD kartu."},
|
||||
// {Error11::ItemsCountMismatch, "Nesouhlasí počet položek licence."}
|
||||
// };
|
||||
|
||||
private:
|
||||
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
|
||||
|
||||
CryptData cryptData; // structure for encryp
|
||||
CidData sdData; // data loaded from SD card
|
||||
|
||||
void processConfigFile(string &dataFileName); //process data from config file
|
||||
void getSDData(); // reads SD card
|
||||
string getLicenceName(BYTE licPostfix); // get proper licencename
|
||||
string getLicenceName();
|
||||
void initCrypto();
|
||||
bool createEosEovLicence(); // create licence for EOV_OSV
|
||||
bool readEosEovLicence(string dataFileName);
|
||||
LicenceIdentification lIdentification;
|
||||
|
||||
public:
|
||||
|
||||
string operationErrors = "";
|
||||
ErrorMessage errorMessage;
|
||||
string cid_cdsPath = ""; //"c:\\_projects\\LicenceGenerator\\output\\"; ///sys/block/mmcblk0/device/
|
||||
string licenceFilePath = ""; //"c:\\_projects\\LicenceGenerator\\output\\";
|
||||
|
||||
LicenceELC11();
|
||||
~LicenceELC11();
|
||||
|
||||
LicenceELC11(string cid, string csd, string binaryType, string dataFileName);
|
||||
LicenceELC11(LicenceIdentification & licIdentification);
|
||||
|
||||
bool createLicence(); // creates licence
|
||||
bool readLicence(LicenceInfoGeneral * licences);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,130 +0,0 @@
|
||||
#ifndef PLC_LICENCE21_H
|
||||
#define PLC_LICENCE21_H
|
||||
|
||||
#include "utils.h"
|
||||
#include <stdint.h>
|
||||
#include <unordered_map>
|
||||
#include "licenceCommon.h"
|
||||
#include "pugixml.hpp"
|
||||
#include "SDCard.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class LicenceELC21
|
||||
{
|
||||
|
||||
struct LicData
|
||||
{
|
||||
string station = "";
|
||||
string distributor = "";
|
||||
string licenceName = "";
|
||||
string projectDescription = "";
|
||||
string cid = ""; // CID z SD karty
|
||||
string csd = ""; // CSD z SD karty
|
||||
string uid = ""; // jedinečný identifikátor z jiného systému
|
||||
pugi::xml_document *doc;
|
||||
};
|
||||
|
||||
public:
|
||||
ErrorMessage errorMessage;
|
||||
LicenceInfo21 licenceInfo;
|
||||
string cid_cdsPath = ""; //"c:\\_projects\\LicenceGenerator\\output\\"; ///sys/block/mmcblk0/device/
|
||||
string licenceFilePath = ""; //"c:\\_projects\\LicenceGenerator\\output\\";
|
||||
|
||||
LicenceELC21();
|
||||
~LicenceELC21();
|
||||
LicenceELC21(LicenceIdentification &licIdentification, LicData &licData);
|
||||
LicenceELC21(LicenceIdentification &licIdentification);
|
||||
LicenceELC21(LicData &licData);
|
||||
bool createLicence();
|
||||
bool readLicence(LicenceInfoGeneral *licences);
|
||||
int getDataPointsCount(int protocolId);
|
||||
bool getLicenceInfo(void *ptr);
|
||||
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
|
||||
|
||||
enum class Error21
|
||||
{
|
||||
SDCardReadError = 50,
|
||||
LicenceReadError = 51,
|
||||
LicenceSizeMismatch = 52,
|
||||
LicenceSizeCardMismatch = 53,
|
||||
LicenceMismatch = 54,
|
||||
ItemsCountMismatch = 61
|
||||
};
|
||||
|
||||
unordered_map<Error21, string> map21Errors = {
|
||||
{Error21::SDCardReadError, "Nepodařilo se načíst SD kartu."},
|
||||
{Error21::ItemsCountMismatch, "Nesouhlasí počet položek licence."},
|
||||
{Error21::LicenceSizeMismatch, "Nesouhlasí velikost souboru licence."},
|
||||
{Error21::LicenceSizeCardMismatch, "Nesouhlasí velikost SD karty."},
|
||||
{Error21::LicenceMismatch, "Nesouhlasí licence."},
|
||||
{Error21::ItemsCountMismatch, "Nesouhlasí počet položek licence."},
|
||||
};
|
||||
|
||||
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 = "";
|
||||
int crc = 0;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
private:
|
||||
int licItemCount = 0;
|
||||
LicenceBody licBody;
|
||||
LicenceIdentification lIdentification;
|
||||
LicData lData;
|
||||
SDCard sdCard;
|
||||
void getHeader();
|
||||
string getVersion(int middleVersion);
|
||||
void getLicenceItems();
|
||||
bool processInputConfiguration();
|
||||
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();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,43 +0,0 @@
|
||||
#ifndef PLC_LICENCE31_H
|
||||
#define PLC_LICENCE31_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "utils.h"
|
||||
#include "licenceCommon.h"
|
||||
#include "pugixml.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class LicenceELC31
|
||||
{
|
||||
struct LicData
|
||||
{
|
||||
string station = "";
|
||||
string distributor = "";
|
||||
string licenceName = "";
|
||||
string projectDescription = "";
|
||||
string cid = ""; // CID z SD karty
|
||||
string csd = ""; // CSD z SD karty
|
||||
string uid = ""; // jedinečný identifikátor z jiného systému
|
||||
pugi::xml_document *doc;
|
||||
};
|
||||
|
||||
LicData lData;
|
||||
bool processInputConfiguration();
|
||||
LicenceIdentification lIdentification;
|
||||
|
||||
|
||||
public:
|
||||
LicenceELC31();
|
||||
~LicenceELC31();
|
||||
LicenceELC31(LicData & licData);
|
||||
LicenceELC31(LicenceIdentification & licIdentification);
|
||||
void createLicence();
|
||||
void readLicence();
|
||||
int getDataPointsCount(int protocolId);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Reader
|
||||
{
|
||||
public:
|
||||
|
||||
LicenceInfo21 licenceInfo;
|
||||
LicenceELC1Info licenceInfo;
|
||||
|
||||
Licence1();
|
||||
~Licence1();
|
||||
|
||||
@@ -13,15 +13,13 @@ namespace Reader
|
||||
class Licence2 : public LicenceELC2
|
||||
{
|
||||
public:
|
||||
LicenceInfo21 licenceInfo;
|
||||
LicenceELC2Info licenceInfo;
|
||||
|
||||
|
||||
Licence2();
|
||||
~Licence2();
|
||||
Licence2(LicenceIdentification &licIdentification);
|
||||
|
||||
bool readLicence(LicenceInfoGeneral *licences);
|
||||
int getDataPointsCount(int protocolId);
|
||||
bool getLicenceInfo(void *ptr);
|
||||
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
|
||||
void getLicenceItems();
|
||||
|
||||
Reference in New Issue
Block a user