| Remote Access Control |

# common.h File Reference

## Detailed Description

Header file for application common functions.

This file contains the prototypes for common functions needed by the Remote Keyless Entry application. The implementation is found in the common.c file.

- File: common.h
- Compiler: IAR EWAVR 4.11B
- Supported devices: ATtiny45/85
- AppNote: AVR411 - Secure Rolling Code Algorithm for Wireless Link

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.h.

`#include <ioavr.h>`
`#include <inavr.h>`
`#include <stdbool.h>`

Include dependency graph for common.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Typedefs
typedef uint8_t | byte
typedef short | int16_t
typedef long | int32_t
typedef signed char | int8_t
typedef unsigned short | uint16_t
typedef unsigned long | uint32_t
typedef unsigned char | uint8_t
## Functions
void | addConstant (byte *bytes, const byte *constant, byte count)
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)

## Typedef Documentation

typedef uint8_t byte

Handy typedef. Very readable.

Definition at line 65 of file common.h.

typedef short int16_t

Definition at line 60 of file common.h.

typedef long int32_t

Definition at line 62 of file common.h.

typedef signed char int8_t

Definition at line 58 of file common.h.

typedef unsigned short uint16_t

Definition at line 61 of file common.h.

typedef unsigned long uint32_t

Definition at line 63 of file common.h.

typedef unsigned char uint8_t

Definition at line 59 of file common.h.

## Function Documentation

void addConstant | ( | byte * | bytes,
|  | const byte * | constant,
|  | byte | count |
| ) |  |  |

XOR 'count' bytes from 'constant' buffer into 'bytes'.

Definition at line 67 of file common.c.

Referenced by calcCMAC(), cipher(), invCipher(), invKeyExpansion(), and keyExpansion().

    00068 {
    00069         // Copy to temporary variables for optimization.
    00070         byte * tempBlock = bytes;
    00071         const byte * tempSource = constant;
    00072         byte tempCount = count;
    00073         byte tempValue;
    00074
    00075         do {
    00076                  // Add in GF(2), ie. XOR.
    00077                 tempValue = *tempBlock ^ *tempSource++;
    00078                 *tempBlock++ = tempValue;
    00079         } while( --tempCount );
    00080 }

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 84 of file common.c.

    00086 {
    00087         // Copy to temporary variables for optimization.
    00088         byte * tempDestination = bytes;
    00089         byte tempCount = count;
    00090         byte tempValue;
    00091         EEAR = (uint16_t) constant;
    00092
    00093         do {
    00094                 EECR |= (1<<EERE);
    00095                 ++EEAR;
    00096                 tempValue = *tempDestination ^ EEDR; // Add in GF(2), ie. XOR.
    00097                 *tempDestination++ = tempValue;
    00098         } while( --tempCount );
    00099 }

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(), cipher(), invKeyExpansion(), keyExpansion(), and prepareInvCipher().

    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 123 of file common.c.

Referenced by learnMode(), and main().

    00125 {
    00126         // Copy to temporary variables for optimization.
    00127         byte * tempDest = destination;
    00128         byte tempCount = count;
    00129         EEAR = (uint16_t) source;
    00130
    00131         do {
    00132                 EECR |= (1<<EERE);
    00133                 ++EEAR;
    00134                 *tempDest++ = EEDR;
    00135         } while( --tempCount );
    00136 }

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 103 of file common.c.

Referenced by learnMode().

    00105 {
    00106         // Copy to temporary variables for optimization.
    00107         const byte * tempSrc = source;
    00108         byte tempCount = count;
    00109         do {} while( EECR & (1<<EEPE) );
    00110         EEAR = (uint16_t) destination;
    00111
    00112         do {
    00113                 EEDR = *tempSrc++;
    00114                 EECR |= (1<<EEMPE);
    00115                 EECR |= (1<<EEPE);
    00116                 do {} while( EECR & (1<<EEPE) );
    00117                 ++EEAR;
    00118         } while( --tempCount );
    00119 }

@DOC_TITLE@