Files
hsb/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/PIN.c
2017-12-04 15:18:32 +00:00

161 lines
4.3 KiB
C

// -----------------------------------------------------------------------------
/// @file PIN.c
/// @brief Description
// -----------------------------------------------------------------------------
// Micro-Key bv
// Industrieweg 28, 9804 TG Noordhorn
// Postbus 92, 9800 AB Zuidhorn
// The Netherlands
// Tel: +31 594 503020
// Fax: +31 594 505825
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision$
/// $Author$
/// $Date$
// (c) 2017 Micro-Key bv
// -----------------------------------------------------------------------------
/// @file PIN.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include <string.h>
#include "PIN.h"
#include "Logger.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
static ErrorStatus PIN_verifyInsertedPins(struct PIN* self);
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
void PIN_generateDefaultPIN(struct PIN* self)
{
self->firstDigit = 0;
self->secondDigit = 1;
self->thirdDigit = 2;
self->fourthDigit = 3;
}
bool PIN_isOK(struct PIN* self, char* const pin)
{
bool returnValue = false;
if (pin[0] == self->firstDigit)
{
if (pin[1] == self->secondDigit)
{
if (pin[2] == self->thirdDigit)
{
if (pin[3] == self->fourthDigit)
{
returnValue = true;
}
}
}
}
return returnValue;
}
void PIN_changePinFirstInsert(struct PIN* self, char* const firstPinInsert)
{
int loopCounter;
if (firstPinInsert != NULL)
{
for (loopCounter = 0; loopCounter < PIN_NUMBER_OF_DIGITS; loopCounter++)
{
self->pinchangeFirstInsert[loopCounter] = firstPinInsert[loopCounter];
}
}
}
ErrorStatus PIN_changePinSecondInsert(struct PIN* self, char* const secondPinInsert)
{
ErrorStatus returnValue = SUCCESS;
int loopCounter;
if (secondPinInsert != NULL)
{
for (loopCounter = 0; loopCounter < PIN_NUMBER_OF_DIGITS; loopCounter++)
{
self->pinchangeSecondInsert[loopCounter] = secondPinInsert[loopCounter];
}
}
returnValue = PIN_verifyInsertedPins(self);
// Verify both PINs
if (returnValue == SUCCESS)
{
self->firstDigit = self->pinchangeFirstInsert[0];
self->secondDigit = self->pinchangeFirstInsert[1];
self->thirdDigit = self->pinchangeFirstInsert[2];
self->fourthDigit = self->pinchangeFirstInsert[3];
}
return returnValue;
}
static ErrorStatus PIN_verifyInsertedPins(struct PIN* self)
{
ErrorStatus returnValue = SUCCESS;
if (returnValue == SUCCESS)
{
if (strlen(self->pinchangeFirstInsert) != PIN_NUMBER_OF_DIGITS)
{
returnValue = ERROR;
}
}
if (returnValue == SUCCESS)
{
if (strlen(self->pinchangeSecondInsert) != PIN_NUMBER_OF_DIGITS)
{
returnValue = ERROR;
}
}
if (returnValue == SUCCESS)
{
if(strncmp(self->pinchangeFirstInsert, self->pinchangeSecondInsert, PIN_NUMBER_OF_DIGITS) != 0)
{
// Inserted PINs are not equal
returnValue = ERROR;
}
}
return returnValue;
}