/*****************************************************************************************
*  Copyright (c) 2004, Beijing Senselock Data Security Centre
*  All rights reserved.
*
*  Filename£ºsample_8.c
*          
*  Briefs£º  The purpose of this snippet is to demonstrate how to change DEV_PIN and USR_PIN
*            of a directory.
*            
*            
*  History:        
*  --------------------------------------------------------        
*            11/08/2004 v1.0.0.0 Lihua created
*            
*            
*******************************************************************************************/

#include <stdio.h>
#include <conio.h>
#include <assert.h>

#include "..\..\inc\win32\sense4.h"
#include "..\..\common\common.h"


int main(int argc, char* argv[])
{
	SENSE4_CONTEXT stS4Ctx = {0};
	unsigned long dwResult = 0;

	unsigned char lpOldPin[] = "123456781234567812345678";
	unsigned long dwOldPinLen = sizeof(lpOldPin)-1;
	unsigned char lpNewPin[] = "zaq12wsxcde34rfvbgt56yhn";
	unsigned long dwNewPinLen = sizeof(lpNewPin)-1;

	unsigned char lpOldUsrPin[] = "12345678";
	unsigned long dwOldUsrPinLen = sizeof(lpOldUsrPin)-1;
	unsigned char lpNewUsrPin[] = "zaq12wsx";
	unsigned long dwNewUsrPinLen = sizeof(lpNewUsrPin)-1;
	
	printf("Open first SenseLock EL device...\n");
	if (!(dwResult = OpenS4ByIndex(FIRST_S4_INDEX, &stS4Ctx)))
	{
		return 1;
	} 
	printf("Success!\n");
	
	printf("Change to root directory...\n");
	dwResult = S4ChangeDir(&stS4Ctx, "\\");
	if (dwResult != S4_SUCCESS) 
	{
		printf("Change directory failed! <error code: 0x%08x>\n",dwResult);
		S4Close(&stS4Ctx);
		return dwResult;
	}
	printf("Success!\n");
  

	printf("Change DEV_PIN of root directory...\n");
	dwResult = S4ChangePin(&stS4Ctx,lpOldPin,dwOldPinLen,lpNewPin,dwNewPinLen,S4_DEV_PIN);
	if (dwResult != S4_SUCCESS) 
	{
		printf("Change DEV_PIN of root directory failed! <error code: 0x%08x>\n",dwResult);
		S4Close(&stS4Ctx);
		return dwResult;
	}
	printf("Success!\n");
	
	printf("Change USER_PIN of root directory...\n");
	dwResult = S4ChangePin(&stS4Ctx,lpOldUsrPin,dwOldUsrPinLen,lpNewUsrPin,dwNewUsrPinLen,S4_USER_PIN);
	if (dwResult != S4_SUCCESS) 
	{
		printf("Change USER_PIN of root directory failed! <error code: 0x%08x>\n",dwResult);
		S4Close(&stS4Ctx);
		return dwResult;
	}
	printf("Success!\n");
	
	ResetAndCloseS4(&stS4Ctx);

    getch(); 
	return dwResult;
}





















