Remote Access Control


common.c File Reference


Detailed Description

Source file for application common functions.

This file contains the function implementation for common functions needed by the Remote Keyless Entry application. Refer to the common.h file for more details.

Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Name
Revision
1193
Date
2006-10-31 14:21:08 +0100 (ti, 31 okt 2006)

Copyright (c) 2006, Atmel Corporation All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file common.c.

#include "common.h"

Include dependency graph for common.c:

Go to the source code of this file.

Functions

void addConstantFromEEPROM (byte *bytes, const byte __eeprom *constant, byte count)
void copyBytes (byte *destination, const byte *source, byte count)
void copyBytesFromEEPROM (byte *destination, const byte __eeprom *source, byte count)
void copyBytesToEEPROM (byte __eeprom *destination, const byte *source, byte count)


Function Documentation

void addConstantFromEEPROM ( byte bytes,
const byte __eeprom *  constant,
byte  count 
)

XOR 'count' bytes from 'constant' buffer in EEPROM into 'bytes' buffer in SRAM.

Definition at line 67 of file common.c.

Referenced by calcCMAC(), calcKeySchedule(), and cipherLookup().

00069 {
00070         // Copy to temporary variables for optimization.
00071         byte * tempDestination = bytes;
00072         byte tempCount = count;
00073         byte tempValue;
00074         EEAR = (unsigned short int) constant;
00075 
00076         do {
00077                 EECR |= (1<<EERE);
00078                 ++EEAR;
00079                 tempValue = *tempDestination ^ EEDR; // Add in GF(2), ie. XOR.
00080                 *tempDestination++ = tempValue;
00081         } while( --tempCount );
00082 }

void copyBytes ( byte destination,
const byte source,
byte  count 
)

Copy 'count' bytes from 'source' buffer to 'destination' buffer in SRAM.

Definition at line 53 of file common.c.

Referenced by calcCMAC(), and calcKeySchedule().

00054 {
00055         // Copy to temporary variables for optimization.
00056         byte * tempDest = destination;
00057         const byte * tempSrc = source;
00058         byte tempCount = count;
00059 
00060         do {
00061                 *tempDest++ = *tempSrc++;
00062         } while( --tempCount );
00063 }

void copyBytesFromEEPROM ( byte destination,
const byte __eeprom *  source,
byte  count 
)

Copy 'count' bytes from 'source' buffer in EEPROM to 'destination' buffer in SRAM.

Definition at line 106 of file common.c.

Referenced by calcKeySchedule(), and transmitTeachMessage().

00108 {
00109         // Copy to temporary variables for optimization.
00110         byte * tempDest = destination;
00111         byte tempCount = count;
00112         EEAR = (unsigned short int) source;
00113 
00114         do {
00115                 EECR |= (1<<EERE);
00116                 ++EEAR;
00117                 *tempDest++ = EEDR;
00118         } while( --tempCount );
00119 }

void copyBytesToEEPROM ( byte __eeprom *  destination,
const byte source,
byte  count 
)

Copy 'count' bytes from 'source' buffer in SRAM to 'destination' buffer in EEPROM.

Definition at line 86 of file common.c.

Referenced by calcCMACSubkey(), and calcKeySchedule().

00088 {
00089         // Copy to temporary variables for optimization.
00090         const byte * tempSrc = source;
00091         byte tempCount = count;
00092         do {} while( EECR & (1<<EEWE) );
00093         EEAR = (uint16_t) destination;
00094 
00095         do {
00096                 EEDR = *tempSrc++;
00097                 EECR |= (1<<EEMWE);
00098                 EECR |= (1<<EEWE);
00099                 do {} while( EECR & (1<<EEWE) );
00100                 ++EEAR;
00101         } while( --tempCount );
00102 }

@DOC_TITLE@
Generated on Fri Aug 8 11:03:22 2008 for AVR411 Secure Rolling Code Algorithm (Transmitter) by doxygen 1.4.7