📄 hallock.c
字号:
/* ============================================================================ Project Name : jayaCard Module Name : proto/hal/avr/hallock.c Version : $Id: hallock.c,v 1.4 2004/01/11 09:56:32 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 073103 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; */ /* read the first cell of the lock */ gGlobalSem++; byLock = HAL_EEPROM_READ_BYTE(BASE_OTP+LockNum); /* 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); 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); } 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; */ /* 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) { /* __x under attack */ HAL_HALT(); return; } /* flash detection */ gGlobalSem--;}/* ========================================================================= That's all folks ! ========================================================================= */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -