/* * secret_knock_lib.c * * Created on: 03/12/2013 * Author: Filipe Ribeiro */ #include "secret_knock_lib.h" unsigned char recordMode; unsigned char stupidUser; unsigned long int elapseTime; unsigned long int knockBuffer[KNOCK_MAX_SEQ]; unsigned long int passwordBuffer[KNOCK_MAX_SEQ]; unsigned char passwordLength; unsigned char knockIndex; /* * portInit * * Initialize ports * */ void portInit(void) { // Port 1 P1DIR = PORT1_DIR; P1REN = PUSH_BUTTON; P1OUT = PUSH_BUTTON; P1IE = PUSH_BUTTON + PIEZO_PIN; P1IES = PUSH_BUTTON; P1IFG = 0x00; // Port 2 P2DIR = PORT2_DIR; } /* * timerAInit * * Initialize timer to work in up mode with SMCLK clock source * */ void timerAInit(unsigned char timerAMask) { if(timerAMask & TIMER_A_0) { TA0CCR0 = 1000; TA0CTL = TASSEL_2+MC_1; } if(timerAMask & TIMER_A_1) { TA1CCTL0 = CCIE; TA1CCR0 = 1000; TA1CTL = TASSEL_2+MC_1; } } /* * knockReset * * Reset knockIndex and clear knockBuffer. * */ void knockReset(void){ unsigned char i; knockIndex = 0; for(i=0;imaxInterval) maxInterval=knockBuffer[i]; if(maxInterval == 0) return ; // Normalize intervals and record secret knock for(i=1;i passwordBuffer[i]) knockError = knockBuffer[i]-passwordBuffer[i]; else knockError = passwordBuffer[i] - knockBuffer[i]; if(knockError> KNOCK_TOLERANCE) return KNOCK_NOT_OK; totalError += knockError; } // In case this if statement is ignored alter the optimization configurations: project -> properties -> build -> msp430 compiler -> optimization -> optimization level = 1 if(totalError > TOTAL_TOLERANCE) return KNOCK_NOT_OK; return KNOCK_OK; } /* * knockInit * * Reset all program flags and password buffer * Initialize ports and timer * */ void knockInit(void) { unsigned char i; // Reset record mode recordMode = RECORD_MODE_OFF; // Reset elapse time counter elapseTime = 0; // Set index to beginning of the buffer knockIndex = 0; // Reset blocking flag stupidUser = 0; // Reset knock code for(i=0;i