alex 2d41198b3e Patch level :
Files correlati     :
Ricompilazione Demo : [ ]
Commento            :
Progetti e altra roba per Linux


git-svn-id: svn://10.65.10.50/trunk@11293 c028cbd2-c16b-5b4b-a496-9718f37d4682
2003-06-26 17:31:45 +00:00

184 lines
6.5 KiB
C
Executable File

/****************************************************************************/
/** **/
/** Hardlock RUS Demo Program **/
/** **/
/** This demo program is based on the Hardlock application interface, **/
/** called API, to access a Hardlock via a local or a remote port. **/
/** To access the Hardlock remote, HL-Server must be installed first. **/
/** **/
/** Aladdin Knowledge Systems, Germany **/
/** **/
/** Note **/
/** ---- **/
/** The following demo program is not meant to represent a real good **/
/** implementation of software protection into your application. It **/
/** demonstrates the basic use of the Hardlock API functions and is **/
/** thus as short and simple as possible. Please read the manual **/
/** carefully to get an insight in the strategy of the implementation. **/
/** Please keep in mind that there is no general solution for a good **/
/** protection. We provide you with the necessary functions, the **/
/** implementation itself is up to you and your imagination. **/
/** **/
/** Revision history **/
/** ----------------
*** $Log: not supported by cvs2svn $
*** Revision 1.3 2000/02/03 16:42:13 chris
*** adapted to new error message routine (HL_ERRMSG)
***
***
*** Revision 1.2 1999/10/13 16:28:54 chris
*** fixed printf argument
***
*** Revision 1.1 1999/10/13 16:14:30 chris
*** Initial revision
**/
/****************************************************************************/
#include <stdio.h>
#include <string.h>
#include "hlapi_c.h"
#include "demo.h"
/* ------------------------------------------------------------------------ */
/* Module address of Hardlock test device and RefKey/VerKey. We generated */
/* the VerifyKey with Latteccino. The API use the keys to identify the */
/* Hardlock with the correct encoding. */
/* The keys defined here are only valid for the demo module. */
/* You have to change module address AND VerKey for your specific Hardlock! */
/* ------------------------------------------------------------------------ */
#define MODAD 29809
Byte RefKey[8] = {'H','A','R','D','L','O','C','K'};
Byte VerKey[8] = {0x18,0x4C,0x97,0xF0,0xC0,0x7A,0x08,0x88};
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
int main(void)
{
Word res; /* Return value from subroutines */
Long SlotCnt = 0;
Long MaxUser = 0;
Long CurrentUser = 0;
Long MaxCounter = 0;
Long CurrentCounter = 0;
Long ID = 0;
Word Year, Month, Day;
printf("\n+-------------------------+");
printf("\n| Hardlock RUS Query Test |");
printf("\n+-------------------------+\n");
/* ------------------------------------- */
/* First we need to initialize the API : */
/* ------------------------------------- */
res = HLM_LOGIN(MODAD, DONT_CARE, RefKey, VerKey, svk, 0, 0);
if(res != STATUS_OK)
{
printf(" Login: %s\n", HL_ERRMSG(res, 0, NULL, NULL));
return (res);
}
printf("\n RUS Hardlock with Module address: %d\n", MODAD);
res = HL_ACCINF();
switch (res)
{
case LOCAL_DEVICE:
printf(" The Hardlock access is\t\t : Local\n");
break;
case NET_DEVICE:
printf(" The Hardlock access is\t\t : Remote\n");
break;
default:
printf(" The Hardlock access is\t\t : No access\n");
break;
}
/* Check for a RUS Hardlock and display the RUS ID: */
/* ------------------------------------------------ */
printf("\n");
printf(" Checking global data\n");
printf(" ====================\n");
res = HLM_ISRUSHL(&ID);
if (res == STATUS_OK)
printf(" RUS ID : %lu (0x%lx)\n", ID, ID);
else
printf(" RUS ID : %s\n", HL_ERRMSG(res, 0, NULL, NULL));
/* Now read the global expiration date: */
/* ------------------------------------ */
res = HLM_CHECKEXPDATE(0, &Year, &Month, &Day);
if (res == STATUS_OK || res == RUS_DATE_EXPIRED)
{
printf(" ExpDate : Day:%d Month:%d Year:%d", Day, Month, Year);
if (res == RUS_DATE_EXPIRED)
printf(" (Expired)\n");
else
printf("\n");
}
else
printf(" ExpDate : %s\n", HL_ERRMSG(res, 0, NULL, NULL));
/* Check the counter but don't increment it: */
/* ----------------------------------------- */
res = HLM_CHECKCOUNTER(0, &MaxCounter, &CurrentCounter);
if (res == STATUS_OK)
{
printf(" MaxCounter : %ld\n", MaxCounter);
printf(" CurCounter : %ld\n", CurrentCounter);
}
else
printf(" Counter : %s\n", HL_ERRMSG(res, 0, NULL, NULL));
/* Retrieve the slot data and try a ocuppy and free: */
/* ------------------------------------------------- */
printf("\n Now Checking slot 1 to 4:\n");
for (SlotCnt = 1; SlotCnt < 5; SlotCnt++)
{
printf("\n");
printf(" Checking slot #%ld\n", SlotCnt);
printf(" =================\n");
res = HLM_OCCUPYSLOT(SlotCnt);
if (res == STATUS_OK)
printf(" Occupy : OK\n");
else
printf(" Occupy : %s\n", HL_ERRMSG(res, 0, NULL, NULL));
res = HLM_CHECKSLOT(SlotCnt, &MaxUser, &CurrentUser);
if (res == STATUS_OK)
{
printf(" MaxUser : %ld\n", MaxUser);
printf(" CurUser : %ld\n", CurrentUser);
}
else
printf(" User Count : %s\n", HL_ERRMSG(res, 0, NULL, NULL));
res = HLM_CHECKEXPDATE(SlotCnt, &Year, &Month, &Day);
if (res == STATUS_OK || res == RUS_DATE_EXPIRED)
{
printf(" ExpDate : Day:%d Month:%d Year:%d", Day, Month, Year);
if (res == RUS_DATE_EXPIRED)
printf(" (Expired)\n");
else
printf("\n");
}
else
printf(" ExpDate : %s\n", HL_ERRMSG(res, 0, NULL, NULL));
res = HLM_FREESLOT(SlotCnt);
if (res == STATUS_OK)
printf(" Free : OK\n");
else
printf(" Free : %s\n", HL_ERRMSG(res, 0, NULL, NULL));
}
/* ---------------------------------------------- */
/* At last we have to release the API structure. */
/* ---------------------------------------------- */
return (HL_LOGOUT());
}