⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hallock.c

📁 一个免费的SMART CARD OS系统。
💻 C
字号:
/* ============================================================================   Project Name : jayaCard   Module Name  : proto/hal/simu/hallock.c   Version : $Id: hallock.c,v 1.9 2004/04/23 20:29:16 dgil Exp $	Description: Locks    The Original Code is jayaCard code.    The Initial Developer of the Original Code is Gilles Dumortier.    Portions created by the Initial Developer are Copyright (C) 2002-2004 the    Initial Developer. All Rights Reserved.    Contributor(s):    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; see http://www.gnu.org/licenses/gpl.html   History Rev	Description   041603 dgil	wrote it from scratch   ============================================================================*/#include "precomp.h"/* =========================================================================	__hal_lock()	returns a lock (LOCK_UNSET == unset; other value set). By design, the 	lock cell must have the 0x00 value to be unset; otherwise the cell 	should be considered as locked.	secure: use the global semaphore   ========================================================================= */jbyte __hal_lock(jbyte LockNum){	LOCAL(jbyte,byLock);	/* should be done by the caller: gGlobalSem = JSEC_OK; */	LOG1("LOCK","__hal_lock() - enter for lock %d",LockNum);	/* read the first cell of the lock */	gGlobalSem++;	byLock = HAL_EEPROM_READ_BYTE(BASE_OTP+LockNum);	LOG2("LOCK","__hal_lock() - first read for lock %d : %.2X",LockNum,byLock);	/* read the second cell of the lock and be sure it has the same value */	byLock = byLock - HAL_EEPROM_READ_BYTE(BASE_OTP+LockNum+8);	LOG2("LOCK","__hal_lock() - second read for lock %d : %.2X",LockNum,byLock);	gGlobalSem++;	/* returns the byLock */	if (byLock==0x00) {		/* re-read the lock :		 		validate it is the same value +				validate that cell1 != cell2 if cell1 != 0x00		*/		byLock = LOCK_UNSET + HAL_EEPROM_READ_BYTE(BASE_OTP+LockNum);		LOG2("LOCK","__hal_lock() - validate for lock %d : %.2X",LockNum,byLock);	}	LOG2("HAL","__hal_lock(locknum=%d) returns 0x%.2X",LockNum,byLock);	return byLock;}/* =========================================================================	__hal_setlock()	Set a lock. Default implementation is to replace the 0x00 cell value 	with a JSEC_FAIL cell value.	secure: use the global semaphore   ========================================================================= */void __hal_setlock(jbyte LockNum){	/* should be done by the caller: gGlobalSem = JSEC_OK; */	LOG1("LOCK","__hal_setlock(%d) enter",LockNum);	/* set the lock in the first cell */	HAL_EEPROM_WRITE_BYTE(BASE_OTP+LockNum,JSEC_FAIL);	/* flash detection */	gGlobalSem++;	/* set the lock in the second cell */	HAL_EEPROM_WRITE_BYTE(BASE_OTP+LockNum+8,JSEC_FAIL);	/* re-read the lock to be sure it is NO MORE unset */	if (HAL_LOCK(LockNum)==LOCK_UNSET) {		LOG1("ATTACK","__hal_setlock(%d)",LockNum);		HAL_HALT();		return;	}	/* flash detection */	gGlobalSem--;	LOG1("HAL","__hal_setlock(%d) LOCK SET.",LockNum);}/* =========================================================================	That's all folks !   ========================================================================= */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -