2003-04-16 15:49:59 +00:00
|
|
|
|
#include <xvt.h>
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
#include <applicat.h>
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include <dongle.h>
|
|
|
|
|
#include <isamrpc.h>
|
2006-12-13 16:22:33 +00:00
|
|
|
|
#include <modaut.h>
|
|
|
|
|
#include <scanner.h>
|
1998-02-13 13:46:18 +00:00
|
|
|
|
#include <utility.h>
|
2006-12-13 16:22:33 +00:00
|
|
|
|
#include <xvtility.h>
|
|
|
|
|
#include <urldefid.h>
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
2003-04-30 15:46:08 +00:00
|
|
|
|
// Dongle stuff
|
1998-02-13 13:46:18 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#ifndef _DEMO_
|
|
|
|
|
|
|
|
|
|
#define USERADR 26952
|
|
|
|
|
#define AGAADR 26953
|
2003-04-30 15:46:08 +00:00
|
|
|
|
#define REFKEY (unsigned char*)"CAMPOKEY"
|
|
|
|
|
#define VERKEY (unsigned char*)"<22>pو<70>c<EFBFBD><"
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
2002-07-03 14:48:48 +00:00
|
|
|
|
#pragma pack(push, 1)
|
1998-05-28 10:09:12 +00:00
|
|
|
|
|
1998-02-13 13:46:18 +00:00
|
|
|
|
struct TEutronHeader
|
|
|
|
|
{
|
1999-07-16 14:59:11 +00:00
|
|
|
|
char _serno[8]; // 8
|
|
|
|
|
unsigned short _year_assist; // 10
|
|
|
|
|
unsigned short _max_users; // 12
|
|
|
|
|
unsigned long _last_date; // 16
|
|
|
|
|
unsigned long _scad_date; // 20
|
|
|
|
|
unsigned long _checksum; // 24
|
|
|
|
|
unsigned short _version; // 26
|
|
|
|
|
unsigned short _patch; // 28
|
|
|
|
|
unsigned short _offset_to_bits; // 30
|
|
|
|
|
unsigned short _size_of_bits; // 32
|
1998-02-13 13:46:18 +00:00
|
|
|
|
};
|
|
|
|
|
|
1999-07-16 14:59:11 +00:00
|
|
|
|
struct TEutronFooter
|
|
|
|
|
{
|
|
|
|
|
unsigned long _size; // Should be sizeof(TEutronFooter)
|
|
|
|
|
unsigned long _checksum; // Much smarter position than header
|
|
|
|
|
unsigned long _filler1;
|
|
|
|
|
unsigned long _filler2;
|
|
|
|
|
unsigned long _filler3;
|
|
|
|
|
unsigned long _filler4;
|
|
|
|
|
unsigned long _filler5;
|
|
|
|
|
unsigned long _last_assist; // Last date of assistance query
|
|
|
|
|
unsigned long _assistance[MAX_DONGLE_ASSIST]; // Pre-payed assistance
|
|
|
|
|
|
|
|
|
|
unsigned long checksum(bool set);
|
|
|
|
|
bool valid();
|
|
|
|
|
TEutronFooter();
|
|
|
|
|
};
|
|
|
|
|
|
2002-07-03 14:48:48 +00:00
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
1999-07-16 14:59:11 +00:00
|
|
|
|
TEutronFooter::TEutronFooter()
|
|
|
|
|
{
|
|
|
|
|
const int s = sizeof(TEutronFooter);
|
|
|
|
|
memset(&_size, 0, s);
|
|
|
|
|
_size = s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned long TEutronFooter::checksum(bool set)
|
|
|
|
|
{
|
|
|
|
|
if (set) _size = sizeof(TEutronFooter);
|
|
|
|
|
|
|
|
|
|
const word offset = sizeof(_size) + sizeof(_checksum);
|
|
|
|
|
byte* ptr = (byte*)(&_size) + offset;
|
|
|
|
|
const word len = word(_size - offset);
|
|
|
|
|
|
|
|
|
|
unsigned long cs = 0;
|
|
|
|
|
for (word i = 0; i < len; i++, ptr++)
|
2003-06-06 08:57:05 +00:00
|
|
|
|
cs += *ptr | ~(short(*ptr << 8));
|
1999-07-16 14:59:11 +00:00
|
|
|
|
if (set) _checksum = cs;
|
|
|
|
|
return cs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TEutronFooter::valid()
|
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
|
if (_size == 0 || _checksum == 0)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return false;
|
|
|
|
|
return _checksum == checksum(false);
|
1999-07-16 14:59:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-02-13 13:46:18 +00:00
|
|
|
|
#endif // _DEMO_
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// Current dongle
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
static TDongle* _dongle = NULL;
|
|
|
|
|
|
|
|
|
|
TDongle& dongle()
|
|
|
|
|
{
|
|
|
|
|
if (_dongle == NULL)
|
|
|
|
|
_dongle = new TDongle;
|
|
|
|
|
return *_dongle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool destroy_dongle()
|
|
|
|
|
{
|
|
|
|
|
bool ok = _dongle != NULL;
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
delete _dongle;
|
2003-04-30 15:46:08 +00:00
|
|
|
|
_dongle = NULL;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// Bit helper functions
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
inline bool test_bit(word w, int b)
|
|
|
|
|
{
|
|
|
|
|
bool on = (w & (1 << b)) != 0;
|
|
|
|
|
return on;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
inline void set_bit(word& w, int b, bool on = true)
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
|
|
|
|
if (on)
|
|
|
|
|
w |= 1 << b;
|
|
|
|
|
else
|
|
|
|
|
w &= ~(1 << b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void reset_bit(word& w, byte b)
|
|
|
|
|
{
|
|
|
|
|
w &= ~(1 << b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TDongle
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
TDongle::TDongle()
|
|
|
|
|
: _hardware(_dongle_unknown), _type(_no_dongle), _serno(0xFFFF),
|
2009-05-20 15:36:38 +00:00
|
|
|
|
_max_users(1), _year_assist(2009), _dirty(false), _OEM(-1)
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
|
|
|
|
memset(_eprom, 0, sizeof(_eprom));
|
1999-07-16 14:59:11 +00:00
|
|
|
|
memset(_assist, 0, sizeof(_assist));
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TDongle::~TDongle()
|
|
|
|
|
{
|
|
|
|
|
if (_serno != 0xFFFF)
|
|
|
|
|
logout();
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
const TString& TDongle::administrator(TString* pwd) const
|
1999-03-22 15:55:50 +00:00
|
|
|
|
{
|
2007-03-30 13:51:17 +00:00
|
|
|
|
if (_admin.blank())
|
2009-05-20 15:36:38 +00:00
|
|
|
|
oem();
|
1999-03-22 15:55:50 +00:00
|
|
|
|
if (pwd)
|
|
|
|
|
*pwd = _admpwd;
|
|
|
|
|
return _admin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1998-02-13 13:46:18 +00:00
|
|
|
|
// Data punta ad un array di 4 words
|
|
|
|
|
// Deve essere cosi' per problemi del C,
|
|
|
|
|
// non trasformare in array: pena di morte!
|
|
|
|
|
void TDongle::garble(word* data) const
|
|
|
|
|
{
|
|
|
|
|
#ifndef _DEMO_
|
|
|
|
|
switch (_hardware)
|
|
|
|
|
{
|
|
|
|
|
case _dongle_hardlock:
|
2003-04-30 15:46:08 +00:00
|
|
|
|
xvt_dongle_hl_crypt(data);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
break;
|
|
|
|
|
case _dongle_eutron:
|
2003-04-30 15:46:08 +00:00
|
|
|
|
xvt_dongle_sl_crypt(data);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDongle::already_programmed() const
|
|
|
|
|
{
|
|
|
|
|
#ifndef _DEMO_
|
|
|
|
|
if (_hardware == _dongle_hardlock)
|
|
|
|
|
{
|
|
|
|
|
word data[4];
|
|
|
|
|
memcpy(data, &_eprom[60], sizeof(data));
|
|
|
|
|
garble(data);
|
|
|
|
|
|
|
|
|
|
if (data[0] < 1997 || data[0] > 2997)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return false;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
if (data[1] == 0 || data[1] >= 10000)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return false;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
const TDate today(TODAY);
|
2003-09-10 14:09:14 +00:00
|
|
|
|
const long giulio = *((const long*)&data[2]);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
const long yyyymmdd = today.julian2date(giulio);
|
|
|
|
|
const TDate d(yyyymmdd);
|
|
|
|
|
if (d.year() < 1997 || d > today)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return false;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
} else
|
|
|
|
|
if (_hardware == _dongle_eutron)
|
|
|
|
|
{
|
|
|
|
|
const TEutronHeader* eh = (const TEutronHeader*)_eprom;
|
|
|
|
|
if (eh->_serno[0] == 0 || eh->_checksum == 0)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return false; // Really virgin.
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
unsigned long cs = 0;
|
|
|
|
|
for (byte* ptr = (byte*)_eprom; ptr < (byte*)&eh->_checksum; ptr++)
|
2003-06-06 08:57:05 +00:00
|
|
|
|
cs += *ptr | ~(short(*ptr << 8));
|
1998-02-13 13:46:18 +00:00
|
|
|
|
if (eh->_checksum != cs)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return false; // Malicious programming!
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
#endif // _DEMO_
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return true;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifndef _DEMO_
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
void TDongle::set_developer_permissions()
|
|
|
|
|
{
|
2009-02-03 09:14:30 +00:00
|
|
|
|
if (_serno == 0 && is_power_station())
|
|
|
|
|
{
|
|
|
|
|
_module.set(255); // Last module on key
|
|
|
|
|
_module.set(); // Activate all modules
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_module.reset(-1);
|
|
|
|
|
_module.set(0, true);
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-01 09:44:03 +00:00
|
|
|
|
_shown.reset();
|
2006-12-13 16:22:33 +00:00
|
|
|
|
|
|
|
|
|
_max_users = 1;
|
|
|
|
|
_last_update = TDate(TODAY);
|
2007-03-16 13:33:09 +00:00
|
|
|
|
_year_assist = 3000;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1998-02-13 13:46:18 +00:00
|
|
|
|
bool TDongle::hardlock_login(bool test_all_keys)
|
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
bool ok = true;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
_type = _user_dongle;
|
|
|
|
|
if (test_all_keys)
|
|
|
|
|
{
|
2003-04-30 15:46:08 +00:00
|
|
|
|
xvt_dongle_hl_logout();
|
|
|
|
|
if (xvt_dongle_hl_login(AGAADR, REFKEY, VERKEY))
|
1998-02-13 13:46:18 +00:00
|
|
|
|
_type = _aga_dongle;
|
|
|
|
|
}
|
2003-04-30 15:46:08 +00:00
|
|
|
|
xvt_dongle_hl_logout();
|
|
|
|
|
ok = xvt_dongle_hl_login(USERADR, REFKEY, VERKEY) != 0;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
_hardware = _dongle_hardlock;
|
|
|
|
|
|
2003-04-30 15:46:08 +00:00
|
|
|
|
xvt_dongle_hl_read_block((unsigned char*)_eprom);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
word data[4];
|
|
|
|
|
memcpy(data, _eprom, sizeof(data));
|
|
|
|
|
garble(data);
|
|
|
|
|
|
|
|
|
|
if (data[0] == 0xFAE8)
|
|
|
|
|
_serno = data[1];
|
|
|
|
|
else
|
|
|
|
|
{
|
1998-03-13 10:25:37 +00:00
|
|
|
|
if (data[0] == 0x3283 || data[0] == 0xA3AA) // chiave programmatori !!
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
1998-05-28 07:31:27 +00:00
|
|
|
|
if (_type == _user_dongle)
|
|
|
|
|
_type = _developer_dongle;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
_serno = 0;
|
2007-12-10 09:48:34 +00:00
|
|
|
|
#ifdef DBG
|
|
|
|
|
if (test_all_keys && is_power_station())
|
|
|
|
|
_type = _aga_dongle;
|
|
|
|
|
#endif
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
_max_users = 1;
|
|
|
|
|
_last_update = TDate(TODAY);
|
|
|
|
|
_year_assist = _last_update.year();
|
|
|
|
|
|
2006-05-11 11:59:31 +00:00
|
|
|
|
if (_type == _user_dongle) //chiave cliente
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
|
|
|
|
const bool already = already_programmed();
|
|
|
|
|
|
1998-11-04 18:04:26 +00:00
|
|
|
|
_module.reset(); // Disattiva tutti i moduli
|
2007-06-01 09:44:03 +00:00
|
|
|
|
_shown.reset();
|
1998-02-13 13:46:18 +00:00
|
|
|
|
const int last_word = already ? 12 : 4;
|
|
|
|
|
word data[4];
|
|
|
|
|
|
|
|
|
|
// Legge flag di attivazione dei moduli
|
|
|
|
|
for (int i = 0; i < last_word; i += 4)
|
|
|
|
|
{
|
|
|
|
|
memcpy(data, &_eprom[48+i], sizeof(data));
|
|
|
|
|
garble(data);
|
|
|
|
|
if (data[3] == _serno) // Validate block
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < 3; j++)
|
|
|
|
|
{
|
|
|
|
|
word parola = data[j] ^ _serno;
|
|
|
|
|
if (parola)
|
|
|
|
|
{
|
|
|
|
|
for (int b = 15; b >= 0; b--)
|
|
|
|
|
{
|
|
|
|
|
if (test_bit(parola, b))
|
|
|
|
|
{
|
|
|
|
|
const word bit = i * 12 + j * 16 + b;
|
|
|
|
|
_module.set(bit+1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-12-13 16:22:33 +00:00
|
|
|
|
_module.set(0, true); // Forza l'attivazione della base
|
1998-11-04 18:04:26 +00:00
|
|
|
|
|
1998-02-13 13:46:18 +00:00
|
|
|
|
// Legge anno di assitenza e numero massimo di utenti
|
|
|
|
|
memcpy(data, &_eprom[60], sizeof(data));
|
|
|
|
|
garble(data);
|
|
|
|
|
|
|
|
|
|
if (already)
|
|
|
|
|
{
|
|
|
|
|
_year_assist = data[0];
|
|
|
|
|
_max_users = data[1];
|
2003-09-23 14:47:55 +00:00
|
|
|
|
const long giulio = *((const long*)&data[2]);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
const long yyyymmdd = _last_update.julian2date(giulio);
|
|
|
|
|
_last_update = yyyymmdd;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2001-06-25 10:41:20 +00:00
|
|
|
|
_year_assist = 0;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
_dirty = true;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2006-12-13 16:22:33 +00:00
|
|
|
|
else
|
|
|
|
|
set_developer_permissions();
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
_type = _no_dongle;
|
|
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDongle::eutron_login(bool test_all_keys)
|
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
bool ok = false;
|
2002-07-03 14:48:48 +00:00
|
|
|
|
|
2006-10-31 09:47:42 +00:00
|
|
|
|
const char* labels[3] = { "AGA.INFORMATICA", "AGA.CAMPO", "25EBAI" };
|
|
|
|
|
TDongleType types[3] = { _aga_dongle, _user_dongle, _developer_dongle };
|
|
|
|
|
for (int k = test_all_keys ? 0 : 1; k < 3; k++)
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
2003-04-30 15:46:08 +00:00
|
|
|
|
const unsigned char* pwd = (const unsigned char*)::encode(labels[k]);
|
|
|
|
|
ok = xvt_dongle_sl_login((const unsigned char*)labels[k], pwd) != 0;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
_hardware = _dongle_eutron;
|
|
|
|
|
_type = types[k];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
_serno = 0;
|
|
|
|
|
_max_users = 1;
|
|
|
|
|
_last_update = TDate(TODAY);
|
|
|
|
|
_year_assist = _last_update.year();
|
|
|
|
|
|
2006-05-11 11:59:31 +00:00
|
|
|
|
if (_type == _user_dongle) //chiave cliente
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
1998-11-04 18:04:26 +00:00
|
|
|
|
_module.reset(); // Disattiva tutti i moduli
|
1998-02-13 13:46:18 +00:00
|
|
|
|
if (read_words(0, sizeof(TEutronHeader) / 2, _eprom))
|
|
|
|
|
{
|
|
|
|
|
const TEutronHeader* eh = (const TEutronHeader*)_eprom;
|
|
|
|
|
TString16 serno; serno.strncpy(eh->_serno, 8);
|
|
|
|
|
_serno = unsigned(atol(serno));
|
|
|
|
|
if (already_programmed())
|
|
|
|
|
{
|
|
|
|
|
_max_users = eh->_max_users;
|
1999-07-16 14:59:11 +00:00
|
|
|
|
_last_update = eh->_last_date;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
_year_assist = eh->_year_assist;
|
|
|
|
|
|
1999-07-16 14:59:11 +00:00
|
|
|
|
// Calcola il numero della word dove cominciano i bit di attivazione
|
|
|
|
|
unsigned short otb = eh->_offset_to_bits;
|
1999-07-21 09:18:16 +00:00
|
|
|
|
if (otb == 0) otb = 16; // Compatibile Hardlock
|
1999-07-16 14:59:11 +00:00
|
|
|
|
|
|
|
|
|
unsigned short sob = eh->_size_of_bits;
|
1999-07-21 09:18:16 +00:00
|
|
|
|
if (sob == 0) sob = 16; // Compatibile Hardlock
|
1999-07-16 14:59:11 +00:00
|
|
|
|
|
|
|
|
|
word data[64];
|
|
|
|
|
if (read_words(otb, sob, data))
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
|
|
|
|
int module = 1;
|
1999-07-16 14:59:11 +00:00
|
|
|
|
for (word w = 0; w < sob; w++)
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
|
|
|
|
for (int b = 0; b < 16; b++)
|
|
|
|
|
{
|
|
|
|
|
if (test_bit(data[w], b))
|
|
|
|
|
_module.set(module);
|
|
|
|
|
module++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-07-16 14:59:11 +00:00
|
|
|
|
|
|
|
|
|
memset(_assist, 0, sizeof(_assist)); // Azzera pre-pagato
|
|
|
|
|
TEutronFooter ef;
|
|
|
|
|
if (read_words(otb+sob, sizeof(ef)/2, (word*)&ef))
|
|
|
|
|
{
|
|
|
|
|
if (ef.valid())
|
|
|
|
|
{
|
|
|
|
|
_last_assist = ef._last_assist;
|
|
|
|
|
memcpy(_assist, ef._assistance, sizeof(_assist));
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2006-12-13 16:22:33 +00:00
|
|
|
|
_dirty = true;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
2006-12-13 16:22:33 +00:00
|
|
|
|
_module.set(0, true); // Forza l'attivazione della base
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
2006-12-13 16:22:33 +00:00
|
|
|
|
else
|
|
|
|
|
set_developer_permissions();
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDongle::network_login(bool test_all_keys)
|
|
|
|
|
{
|
2005-05-16 23:44:23 +00:00
|
|
|
|
const char* appname = main_app().name();
|
|
|
|
|
|
2004-03-31 12:48:16 +00:00
|
|
|
|
if (network() && ok())
|
2005-05-16 23:44:23 +00:00
|
|
|
|
rpc_UserLogout(appname);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
TConfig ini(CONFIG_INSTALL, "Server");
|
|
|
|
|
const char* server = ini.get("Dongle");
|
2004-03-31 12:48:16 +00:00
|
|
|
|
// const char* guest = "******";
|
|
|
|
|
// const TString16 appname = main_app().name();
|
|
|
|
|
// const char* utente = (!main_app().is_running() && appname == "ba0100") ? guest : (const char *) user();
|
|
|
|
|
const char* utente = user();
|
2002-12-18 10:56:10 +00:00
|
|
|
|
|
1998-07-20 13:07:00 +00:00
|
|
|
|
const bool ok = rpc_UserLogin(server, utente, "******", appname);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
_hardware = _dongle_network;
|
|
|
|
|
_type = _user_dongle;
|
|
|
|
|
_serno = rpc_DongleNumber();
|
|
|
|
|
_max_users = 1;
|
|
|
|
|
_last_update = TDate(TODAY);
|
|
|
|
|
_year_assist = rpc_DongleYear();
|
|
|
|
|
rpc_DongleModules(_module);
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // _DEMO_
|
|
|
|
|
|
1998-05-28 10:09:12 +00:00
|
|
|
|
int TDongle::can_try_server() const
|
|
|
|
|
{
|
2003-04-16 15:49:59 +00:00
|
|
|
|
if (xvt_sys_dongle_server_is_running())
|
1998-05-28 10:09:12 +00:00
|
|
|
|
return 3;
|
2009-05-20 15:36:38 +00:00
|
|
|
|
const TString& dongle = ini_get_string(CONFIG_INSTALL, "Server", "Dongle");
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return dongle.full();
|
1998-05-28 10:09:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-02-13 13:46:18 +00:00
|
|
|
|
bool TDongle::login(bool test_all_keys)
|
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
bool ok = true;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
#ifdef _DEMO_
|
2009-04-27 15:18:07 +00:00
|
|
|
|
_hardware = _dongle_unknown;
|
1998-05-28 07:31:27 +00:00
|
|
|
|
_type = _user_dongle;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
_serno = 0;
|
|
|
|
|
_max_users = 1;
|
|
|
|
|
_last_update = TDate(TODAY);
|
|
|
|
|
_year_assist = _last_update.year();
|
2007-06-01 09:44:03 +00:00
|
|
|
|
_module.set(ENDAUT); // Last module on key
|
|
|
|
|
_module.set(); // Activate all modules
|
|
|
|
|
_shown.reset();
|
1998-02-13 13:46:18 +00:00
|
|
|
|
#else
|
|
|
|
|
if (_type != _no_dongle) // Already logged in
|
|
|
|
|
logout();
|
1998-05-28 10:09:12 +00:00
|
|
|
|
|
|
|
|
|
TDongleHardware hw = _hardware;
|
|
|
|
|
if (hw == _dongle_unknown)
|
|
|
|
|
{
|
2002-12-18 10:56:10 +00:00
|
|
|
|
if (can_try_server())
|
1998-05-28 10:09:12 +00:00
|
|
|
|
{
|
|
|
|
|
hw = _dongle_network;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1999-01-19 09:15:17 +00:00
|
|
|
|
TConfig ini(CONFIG_INSTALL, "Main");
|
1998-05-28 10:09:12 +00:00
|
|
|
|
hw = (TDongleHardware)ini.get_int("Donglehw");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
switch(hw)
|
|
|
|
|
{
|
|
|
|
|
case _dongle_hardlock:
|
|
|
|
|
ok = hardlock_login(test_all_keys);
|
|
|
|
|
break;
|
|
|
|
|
case _dongle_eutron:
|
|
|
|
|
ok = eutron_login(test_all_keys);
|
|
|
|
|
break;
|
1998-06-23 14:30:08 +00:00
|
|
|
|
case _dongle_network:
|
1998-02-13 13:46:18 +00:00
|
|
|
|
ok = network_login(test_all_keys);
|
1998-05-28 10:09:12 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2006-12-13 16:22:33 +00:00
|
|
|
|
ok = false;
|
1998-05-28 10:09:12 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (!ok)
|
1998-05-28 07:31:27 +00:00
|
|
|
|
{
|
|
|
|
|
// retry login for various dongles ...
|
1998-05-28 10:09:12 +00:00
|
|
|
|
const int use_server = can_try_server();
|
2002-12-18 10:56:10 +00:00
|
|
|
|
if (use_server != 3) // Non sono obbligato ad usare il Dongle Server
|
1998-05-28 10:09:12 +00:00
|
|
|
|
{
|
|
|
|
|
if (!ok && hw != _dongle_eutron)
|
|
|
|
|
ok = eutron_login(test_all_keys);
|
|
|
|
|
if (!ok && hw != _dongle_hardlock)
|
|
|
|
|
ok = hardlock_login(test_all_keys);
|
|
|
|
|
}
|
2002-12-18 10:56:10 +00:00
|
|
|
|
|
|
|
|
|
if (ok)
|
1998-05-28 10:09:12 +00:00
|
|
|
|
{
|
1999-01-19 09:15:17 +00:00
|
|
|
|
TConfig ini(CONFIG_INSTALL, "Main");
|
1998-05-28 10:09:12 +00:00
|
|
|
|
ini.set("Donglehw",(int)_hardware);
|
|
|
|
|
}
|
1998-05-28 07:31:27 +00:00
|
|
|
|
}
|
1998-02-13 13:46:18 +00:00
|
|
|
|
#endif
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDongle::logout()
|
|
|
|
|
{
|
|
|
|
|
#ifndef _DEMO_
|
|
|
|
|
if (_type != _no_dongle)
|
|
|
|
|
{
|
|
|
|
|
switch (_hardware)
|
|
|
|
|
{
|
|
|
|
|
case _dongle_hardlock:
|
2003-04-30 15:46:08 +00:00
|
|
|
|
xvt_dongle_hl_logout();
|
1998-02-13 13:46:18 +00:00
|
|
|
|
break;
|
|
|
|
|
case _dongle_eutron:
|
2003-04-30 15:46:08 +00:00
|
|
|
|
xvt_dongle_sl_logout();
|
1998-02-13 13:46:18 +00:00
|
|
|
|
break;
|
|
|
|
|
case _dongle_network:
|
2005-05-16 23:44:23 +00:00
|
|
|
|
rpc_UserLogout(main_app().name());
|
1998-02-13 13:46:18 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
_type = _no_dongle;
|
|
|
|
|
_serno = 0xFFFF;
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return true;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Data punta ad un array di 4 words
|
|
|
|
|
// Deve essere cosi' per problemi del C,
|
|
|
|
|
// non trasformare in array: pena di morte!
|
|
|
|
|
bool TDongle::read_words(word reg, word len, word* ud) const
|
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
bool ok = false;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
#ifndef _DEMO_
|
|
|
|
|
switch (_hardware)
|
|
|
|
|
{
|
|
|
|
|
case _dongle_hardlock:
|
|
|
|
|
{
|
|
|
|
|
for (word i = 0; i < len; i++)
|
2003-04-30 15:46:08 +00:00
|
|
|
|
xvt_dongle_hl_read(reg+i, &ud[i]);
|
2006-12-13 16:22:33 +00:00
|
|
|
|
ok = true;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case _dongle_eutron:
|
2003-04-30 15:46:08 +00:00
|
|
|
|
while (len > 0)
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
2003-04-30 15:46:08 +00:00
|
|
|
|
const unsigned short size = (len <= 16) ? len : 16;
|
|
|
|
|
ok = xvt_dongle_sl_read_block(reg, size, ud) != 0;
|
|
|
|
|
if (!ok)
|
1999-07-16 14:59:11 +00:00
|
|
|
|
{
|
2003-04-30 15:46:08 +00:00
|
|
|
|
yesnofatal_box("EUTRON read error");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
len -= size;
|
|
|
|
|
reg += size;
|
|
|
|
|
ud += size;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
#endif // _DEMO_
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Data punta ad un array di 4 words
|
|
|
|
|
// Deve essere cosi' per problemi del C,
|
|
|
|
|
// non trasformare in array: pena di morte!
|
|
|
|
|
bool TDongle::write_words(word reg, word len, word* data) const
|
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
bool ok = false;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
#ifndef _DEMO_
|
|
|
|
|
switch(_hardware)
|
|
|
|
|
{
|
|
|
|
|
case _dongle_hardlock:
|
|
|
|
|
{
|
|
|
|
|
for (word r = 0; r < len; r++)
|
|
|
|
|
{
|
|
|
|
|
const word address = reg+r;
|
2003-04-30 15:46:08 +00:00
|
|
|
|
ok = xvt_dongle_hl_write(address, data[r]) != 0;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case _dongle_eutron:
|
2003-04-30 15:46:08 +00:00
|
|
|
|
while (len > 0)
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
2003-04-30 15:46:08 +00:00
|
|
|
|
const unsigned short size = (len <= 16) ? len : 16;
|
|
|
|
|
ok = xvt_dongle_sl_write_block(reg, size, data) != 0;
|
|
|
|
|
if (!ok)
|
|
|
|
|
break;
|
|
|
|
|
len -= size;
|
|
|
|
|
reg += size;
|
|
|
|
|
data += size;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
2003-04-30 15:46:08 +00:00
|
|
|
|
break;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
#endif // _DEMO_
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-20 15:36:38 +00:00
|
|
|
|
int TDongle::oem() const
|
2006-12-13 16:22:33 +00:00
|
|
|
|
{
|
2009-05-20 15:36:38 +00:00
|
|
|
|
if (_OEM < 0)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
{
|
2009-01-15 16:55:07 +00:00
|
|
|
|
TString& firm = (TString&) _reseller;
|
2009-01-15 15:08:18 +00:00
|
|
|
|
TString& campo = (TString&) _product;
|
2009-01-15 16:55:07 +00:00
|
|
|
|
TString& breve = (TString&) _shortname;
|
2009-05-20 15:36:38 +00:00
|
|
|
|
TString& admin = (TString&)_admin;
|
|
|
|
|
TString& admpwd = (TString&)_admpwd;
|
|
|
|
|
int& oem = (int&)_OEM;
|
2009-01-12 15:24:09 +00:00
|
|
|
|
|
|
|
|
|
//nuovo metodo di rilevamento producer (dalla 10.0 in avanti); il producer sta nel file oem.ini sotto la cartella
|
|
|
|
|
//setup, sia nel CD che soprattutto nel programma installato
|
2009-05-20 15:36:38 +00:00
|
|
|
|
TConfig ini(CONFIG_OEM, "MAIN");
|
|
|
|
|
oem = ini.get_int("OEM", NULL, -1, -1);
|
|
|
|
|
if (oem >= 0)
|
2009-01-12 15:24:09 +00:00
|
|
|
|
{
|
2009-05-20 15:36:38 +00:00
|
|
|
|
TString8 para; para << "OEM_" << oem;
|
|
|
|
|
ini.set_paragraph(para);
|
|
|
|
|
campo = decode(ini.get("Product"));
|
|
|
|
|
firm = decode(ini.get("Reseller"));
|
|
|
|
|
breve = decode(ini.get("Name"));
|
|
|
|
|
admin = decode(ini.get("Administrator"));
|
|
|
|
|
admpwd = decode(ini.get("Password"));
|
2009-01-12 15:24:09 +00:00
|
|
|
|
}
|
2009-05-20 15:36:38 +00:00
|
|
|
|
|
2009-01-12 15:24:09 +00:00
|
|
|
|
if (firm.blank()) //vecchio metodo di rilevamento del producer: sta in install.ini
|
|
|
|
|
{
|
2009-05-20 15:36:38 +00:00
|
|
|
|
firm = decode(ini_get_string(CONFIG_GENERAL, "Main", "Producer"));
|
2009-01-15 16:55:07 +00:00
|
|
|
|
campo = breve = " ";
|
2009-01-12 15:24:09 +00:00
|
|
|
|
}
|
2009-01-15 15:08:18 +00:00
|
|
|
|
//nuovo metodo: cerca produttore (Name) e prodotto (Product)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
if (firm.blank())
|
|
|
|
|
{
|
|
|
|
|
ignore_xvt_errors(true);
|
|
|
|
|
char* p = firm.get_buffer(80);
|
|
|
|
|
xvt_res_get_str(STR_FIRMNAME, p, firm.size());
|
|
|
|
|
ignore_xvt_errors(false);
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-20 15:36:38 +00:00
|
|
|
|
if (admin.blank())
|
|
|
|
|
{
|
|
|
|
|
admin = decode(ini_get_string(CONFIG_GENERAL, "Main", "Administrator"));
|
|
|
|
|
if (admin.blank())
|
|
|
|
|
{
|
|
|
|
|
admin = "ADMIN";
|
|
|
|
|
admpwd = "ad.min";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (admpwd.blank())
|
|
|
|
|
{
|
|
|
|
|
admpwd = decode(ini_get_string(CONFIG_GENERAL, "Main", "Password"));
|
|
|
|
|
if (admpwd.blank())
|
|
|
|
|
{
|
|
|
|
|
admpwd = admin;
|
|
|
|
|
admpwd.lower();
|
|
|
|
|
admpwd.insert(".", 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-15 15:08:18 +00:00
|
|
|
|
if (campo.blank())
|
|
|
|
|
campo = "Campo Enterprise";
|
2006-12-13 16:22:33 +00:00
|
|
|
|
if (firm.blank())
|
2009-01-15 15:08:18 +00:00
|
|
|
|
firm = "AGA informatica s.r.l.";
|
2009-01-15 16:55:07 +00:00
|
|
|
|
if (breve.blank())
|
|
|
|
|
breve = "Campo";
|
2009-05-20 15:36:38 +00:00
|
|
|
|
|
|
|
|
|
if (oem < 0)
|
|
|
|
|
oem = firm.starts_with("AGA ") ? 0 : 1;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
}
|
2009-05-20 15:36:38 +00:00
|
|
|
|
return _OEM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ritorna il nome della ditta che vende il programma attuale
|
|
|
|
|
const TString& TDongle::reseller() const
|
|
|
|
|
{
|
|
|
|
|
if (_reseller.empty())
|
|
|
|
|
oem();
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return _reseller;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-15 15:08:18 +00:00
|
|
|
|
const TString& TDongle::product() const
|
|
|
|
|
{
|
|
|
|
|
if (_product.empty())
|
2009-05-20 15:36:38 +00:00
|
|
|
|
oem();
|
2009-01-15 15:08:18 +00:00
|
|
|
|
return _product;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-15 16:55:07 +00:00
|
|
|
|
const TString& TDongle::shortname() const
|
|
|
|
|
{
|
|
|
|
|
if (_shortname.empty())
|
2009-05-20 15:36:38 +00:00
|
|
|
|
oem();
|
2009-01-15 16:55:07 +00:00
|
|
|
|
return _shortname;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
bool TDongle::active(word module) const
|
|
|
|
|
{
|
2009-05-20 15:36:38 +00:00
|
|
|
|
const bool yes = (module < ENDAUT) && _module[module] && shown(module);
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return yes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDongle::activate(word module, bool on)
|
|
|
|
|
{
|
|
|
|
|
bool ok = module < ENDAUT;
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
2007-06-01 09:44:03 +00:00
|
|
|
|
_module.set(module, on && shown(module));
|
2006-12-13 16:22:33 +00:00
|
|
|
|
_dirty = true;
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
1998-02-13 13:46:18 +00:00
|
|
|
|
#ifndef _DEMO_
|
|
|
|
|
|
|
|
|
|
bool TDongle::burn_hardlock()
|
|
|
|
|
{
|
|
|
|
|
word data[4];
|
|
|
|
|
|
|
|
|
|
const TDate today(TODAY);
|
|
|
|
|
const bool already = already_programmed();
|
|
|
|
|
if (already)
|
|
|
|
|
{
|
|
|
|
|
memcpy(data, &_eprom[60], sizeof(data));
|
|
|
|
|
garble(data);
|
|
|
|
|
if (data[0] < 1997 || data[0] > 2997)
|
|
|
|
|
return error_box("On Line Assistance error.");
|
|
|
|
|
if (data[1] == 0 || data[1] >= 10000)
|
|
|
|
|
return error_box("Bad users number.");
|
2003-09-23 14:47:55 +00:00
|
|
|
|
const long val = *((const long*)&data[2]);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
const long yyyymmdd = today.julian2date(val);
|
|
|
|
|
const TDate date(yyyymmdd);
|
|
|
|
|
if (date > today)
|
|
|
|
|
return error_box("Too late sir: key has already expired!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data[0] = _year_assist;
|
|
|
|
|
data[1] = _max_users;
|
2003-09-23 14:47:55 +00:00
|
|
|
|
long* val = (long*)&data[2];
|
|
|
|
|
*val = today.date2julian();
|
1998-02-13 13:46:18 +00:00
|
|
|
|
garble(data);
|
|
|
|
|
write_words(60, 4, data);
|
|
|
|
|
_last_update = today;
|
|
|
|
|
|
|
|
|
|
// Il primo bit della memoria della chiave corrisponde al modulo uno
|
|
|
|
|
// non allo zero (che e' la base ed e' sempre attivo)
|
|
|
|
|
word module = 1;
|
|
|
|
|
for (int octect = 0; octect < 3; octect++)
|
|
|
|
|
{
|
|
|
|
|
for(int parola = 0; parola < 3; parola++)
|
|
|
|
|
{
|
|
|
|
|
word& p = data[parola];
|
|
|
|
|
p = 0;
|
|
|
|
|
for (int bit = 0; bit < 16; bit++)
|
|
|
|
|
{
|
|
|
|
|
if (active(module))
|
|
|
|
|
set_bit(p, bit);
|
|
|
|
|
module++;
|
|
|
|
|
}
|
|
|
|
|
p ^= _serno;
|
|
|
|
|
}
|
|
|
|
|
data[3] = _serno;
|
|
|
|
|
garble(data);
|
|
|
|
|
write_words(48 + 4*octect, 4, data);
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return true;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDongle::burn_eutron()
|
|
|
|
|
{
|
|
|
|
|
TEutronHeader* eh = (TEutronHeader*)_eprom;
|
|
|
|
|
memset(eh, 0, sizeof(TEutronHeader));
|
|
|
|
|
|
|
|
|
|
_last_update = TDate(TODAY);
|
1998-05-28 07:31:27 +00:00
|
|
|
|
sprintf(eh->_serno, "%lu", (unsigned long)_serno);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
eh->_year_assist = _year_assist;
|
|
|
|
|
eh->_max_users = _max_users;
|
|
|
|
|
eh->_last_date = atol(_last_update.string(ANSI));
|
|
|
|
|
eh->_scad_date = 0;
|
|
|
|
|
|
|
|
|
|
unsigned long cs = 0;
|
|
|
|
|
for (byte* ptr = (byte*)_eprom; ptr < (byte*)&eh->_checksum; ptr++)
|
2003-06-06 08:57:05 +00:00
|
|
|
|
cs += *ptr | ~(short(*ptr << 8));
|
1998-02-13 13:46:18 +00:00
|
|
|
|
eh->_checksum = cs;
|
|
|
|
|
|
1999-07-16 14:59:11 +00:00
|
|
|
|
const word otb = sizeof(TEutronHeader) / 2;
|
|
|
|
|
const word sob = 16;
|
|
|
|
|
eh->_offset_to_bits = otb;
|
|
|
|
|
eh->_size_of_bits = sob;
|
|
|
|
|
|
|
|
|
|
bool ok = write_words(0, otb, _eprom);
|
|
|
|
|
|
1998-02-13 13:46:18 +00:00
|
|
|
|
if (ok)
|
|
|
|
|
{
|
1999-07-16 14:59:11 +00:00
|
|
|
|
word data[sob]; memset(data, 0, sizeof(data));
|
1998-02-13 13:46:18 +00:00
|
|
|
|
for (int module = 1; module < 256; module++)
|
|
|
|
|
{
|
|
|
|
|
if (active(module))
|
|
|
|
|
{
|
|
|
|
|
word& w = data[(module-1) / 16];
|
2006-12-13 16:22:33 +00:00
|
|
|
|
set_bit(w, (module-1) % 16, true);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1999-07-16 14:59:11 +00:00
|
|
|
|
ok = write_words(otb, sob, data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
TEutronFooter ef;
|
|
|
|
|
CHECK(sizeof(ef._assistance) == sizeof(_assist), "Assistance size mismatch");
|
|
|
|
|
ef._last_assist = _last_assist.year()*10000L + _last_assist.month()*100L + _last_assist.day();
|
|
|
|
|
memcpy(ef._assistance, _assist, sizeof(_assist));
|
2006-12-13 16:22:33 +00:00
|
|
|
|
ef.checksum(true);
|
1999-07-16 14:59:11 +00:00
|
|
|
|
ok = write_words(otb+sob, word(ef._size/2), (word*)&ef);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
#endif // _DEMO_
|
|
|
|
|
|
|
|
|
|
bool TDongle::burn()
|
|
|
|
|
{
|
|
|
|
|
bool ok = local() && _type == _user_dongle;
|
|
|
|
|
|
|
|
|
|
#ifndef _DEMO_
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
switch(_hardware)
|
|
|
|
|
{
|
|
|
|
|
case _dongle_hardlock: ok = burn_hardlock(); break;
|
|
|
|
|
case _dongle_eutron : ok = burn_eutron(); break;
|
|
|
|
|
default : break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
if (ok)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
_dirty = false;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
1999-07-16 14:59:11 +00:00
|
|
|
|
|
|
|
|
|
#define BIT31 (1L<<31)
|
|
|
|
|
#define MSK31 (~BIT31)
|
|
|
|
|
|
|
|
|
|
real TDongle::residual_assist(int index, bool lire) const
|
|
|
|
|
{
|
|
|
|
|
real imp;
|
|
|
|
|
if (index >= 0 && index < MAX_DONGLE_ASSIST)
|
|
|
|
|
{
|
|
|
|
|
imp = (_assist[index] & MSK31) / 100.0;
|
|
|
|
|
if (lire)
|
|
|
|
|
{ imp *= 1936.27; imp.round(-2); }
|
|
|
|
|
}
|
|
|
|
|
return imp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDongle::can_require_assist(int index) const
|
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
bool ok = false;
|
1999-07-16 14:59:11 +00:00
|
|
|
|
if (index >= 0 && index < MAX_DONGLE_ASSIST)
|
|
|
|
|
{
|
|
|
|
|
const TDate oggi(TODAY);
|
|
|
|
|
if (oggi == _last_assist)
|
|
|
|
|
ok = (_assist[index] & BIT31) == 0;
|
|
|
|
|
else
|
|
|
|
|
ok = oggi > _last_assist;
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDongle::require_assist(int index, real imp, bool lire)
|
|
|
|
|
{
|
|
|
|
|
imp *= 100;
|
|
|
|
|
if (lire) { imp /= 1936.27; imp.round(2); }
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
bool ok = false;
|
1999-07-16 14:59:11 +00:00
|
|
|
|
if (imp > ZERO)
|
|
|
|
|
{
|
|
|
|
|
if (can_require_assist(index))
|
|
|
|
|
{
|
|
|
|
|
const TDate oggi(TODAY);
|
|
|
|
|
if (oggi > _last_assist)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < MAX_DONGLE_ASSIST; i++)
|
|
|
|
|
_assist[index] &= MSK31;
|
|
|
|
|
_last_assist = oggi;
|
|
|
|
|
}
|
|
|
|
|
_assist[index] &= MSK31;
|
|
|
|
|
_assist[index] += imp.integer();
|
|
|
|
|
_assist[index] |= BIT31;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
_dirty = true;
|
1999-07-16 14:59:11 +00:00
|
|
|
|
ok = burn();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDongle::pay_assist(int index, real imp, bool lire)
|
|
|
|
|
{
|
|
|
|
|
bool ok = imp > ZERO;
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
imp *= 100;
|
|
|
|
|
if (lire) { imp /= 1936.27; imp.round(2); }
|
|
|
|
|
|
|
|
|
|
unsigned long old_bit31 = _assist[index] & BIT31;
|
|
|
|
|
_assist[index] &= MSK31;
|
|
|
|
|
_assist[index] -= imp.integer();
|
|
|
|
|
_assist[index] |= old_bit31;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
_dirty = true;
|
1999-07-16 14:59:11 +00:00
|
|
|
|
ok = burn();
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
2004-03-12 15:08:44 +00:00
|
|
|
|
}
|
2006-12-13 16:22:33 +00:00
|
|
|
|
|
|
|
|
|
const TString_array& TDongle::info() const
|
|
|
|
|
{
|
|
|
|
|
if (_info.items() == 0)
|
|
|
|
|
{
|
|
|
|
|
TScanner scanner("campo.aut");
|
|
|
|
|
for (int aut = 0; ; aut++)
|
|
|
|
|
{
|
2008-10-22 14:17:48 +00:00
|
|
|
|
const TString& row = scanner.line();
|
2007-01-25 15:42:56 +00:00
|
|
|
|
if (row.blank())
|
2006-12-13 16:22:33 +00:00
|
|
|
|
break;
|
2007-01-25 15:42:56 +00:00
|
|
|
|
|
2008-10-22 14:17:48 +00:00
|
|
|
|
TToken_string* tok = new TToken_string;
|
|
|
|
|
tok->strncpy(row, 3);
|
|
|
|
|
const TString& name = row.mid(3);
|
2007-01-25 15:42:56 +00:00
|
|
|
|
if (name.full())
|
2008-10-22 14:17:48 +00:00
|
|
|
|
*tok << dictionary_translate(name);
|
2006-12-13 16:22:33 +00:00
|
|
|
|
((TString_array&)_info).add(tok);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return _info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
word TDongle::module_name2code(const char* mod) const
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
if (mod && *mod && xvt_str_compare_ignoring_case(mod, "sy") != 0)
|
|
|
|
|
{
|
|
|
|
|
if (real::is_natural(mod))
|
|
|
|
|
{
|
|
|
|
|
i = atoi(mod);
|
|
|
|
|
// Trasforma i numeri da 74 a 77 nei codici da M74AUT a M77AUT
|
|
|
|
|
if (i >= 74 && i <= 77)
|
|
|
|
|
i += M74AUT-74;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const TString_array& modinfo = info();
|
|
|
|
|
for (i = modinfo.last(); i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
if (modinfo.row(i).starts_with(mod, true))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return word(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TString& TDongle::module_code2name(word mod) const
|
|
|
|
|
{
|
|
|
|
|
const TString_array& modinfo = info();
|
|
|
|
|
if (mod < modinfo.items())
|
|
|
|
|
return modinfo.row(mod).left(2);
|
|
|
|
|
return EMPTY_STRING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TString& TDongle::module_code2desc(word mod) const
|
|
|
|
|
{
|
|
|
|
|
const TString_array& modinfo = info();
|
2009-05-20 15:36:38 +00:00
|
|
|
|
return mod < modinfo.items() ? modinfo.row(mod).mid(3) : EMPTY_STRING;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-23 11:37:37 +00:00
|
|
|
|
const TString& TDongle::module_name2desc(const char* mod) const
|
|
|
|
|
{
|
|
|
|
|
const word cod = module_name2code(mod);
|
|
|
|
|
if (cod == 0)
|
|
|
|
|
{
|
|
|
|
|
if (xvt_str_compare_ignoring_case(mod, "sy") == 0)
|
|
|
|
|
return get_tmp_string() = TR("Sistema");
|
|
|
|
|
}
|
|
|
|
|
return module_code2desc(cod);
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
bool TDongle::shown(word code) const
|
|
|
|
|
{
|
2007-06-01 09:44:03 +00:00
|
|
|
|
bool yes = code < ENDAUT;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
if (yes)
|
|
|
|
|
{
|
2007-06-01 09:44:03 +00:00
|
|
|
|
yes = _shown[code];
|
|
|
|
|
if (!yes) // Puo' voler dire "nascosto" ma anche "non ho mai controllato"
|
2006-12-13 16:22:33 +00:00
|
|
|
|
{
|
2007-06-01 09:44:03 +00:00
|
|
|
|
const TString4 mod = module_code2name(code);
|
|
|
|
|
yes = mod.not_empty();
|
2009-05-20 15:36:38 +00:00
|
|
|
|
if (yes && code > BAAUT && code < ENDAUT)
|
2007-06-01 09:44:03 +00:00
|
|
|
|
{
|
2009-05-20 15:36:38 +00:00
|
|
|
|
TAuto_token_string ee = ini_get_string(CONFIG_GENERAL, mod, "OEM"); // Modern OEM handling
|
|
|
|
|
if (ee.full())
|
|
|
|
|
yes = ee.get_pos(oem()) >= 0;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (ini_get_bool(CONFIG_GENERAL, mod, "Ee")) // Legacy Enterprise Edition
|
|
|
|
|
yes = oem() == 0;
|
|
|
|
|
}
|
2007-06-01 09:44:03 +00:00
|
|
|
|
}
|
|
|
|
|
if (yes)
|
|
|
|
|
((TBit_array&)_shown).set(code); // Setto il flag di visibilta' per la prossima volta
|
2006-12-13 16:22:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return yes;
|
|
|
|
|
}
|