[RF433 Rolling Code] KeeLoq remote control made with Arduino?

Hello,

Does anyone know if an alternative code to receive signal from the KeeLoq controller made for Arduino should be subject to the license conditions imposed by Microchip?

Microchip offers the KeeLoq standard under a license to use.

There are 3 types of KeeLoq, Classic (HCSxxx), Advanced (MCS3122) and Ultimate (MCS3142) (AES128).

HCxxx:
• HCS200 • HCS360 • HCS500 • HCS201 • HCS361 • HCS512 • HCS300 • HCS362 • HCS515 • HCS301 • HCS410 • HCS320 • HCS412

I found a code for HCS301 (I don't know if it works):

#define LED_PIN        13
#define HCS_RECIEVER_PIN  2    // Pin al que está conectado el receptor para los mandos.
 byte Canal;

class HCS301 {
public:
   unsigned BatteryLow : 1;  // En el llavero estaba la batería.
   unsigned Repeat : 1; // повторная посылка
   unsigned BtnNoSound : 1;
   unsigned BtnOpen : 1;
   unsigned BtnClose : 1;
   unsigned BtnRing : 1;
   unsigned long SerialNum;
   unsigned long Encript;
   

   void print();
};

volatile boolean  HCS_Listening = true;
byte        HCS_preamble_count = 0;
uint32_t      HCS_last_change = 0;
uint32_t      HCS_start_preamble = 0;
uint8_t       HCS_bit_counter;        // счетчик считанных бит данных
uint8_t       HCS_bit_array[66];        // массив считанных бит данных
#define       HCS_TE    400         // типичная длительность имульса Te
#define       HCS_Te2_3 600         // HCS_TE * 3 / 2

HCS301 hcs301;

#define HCS_DEBUG_

#ifdef HCS_DEBUG

uint16_t HCS_PulseDuration[12];
uint16_t HCS_BitDuration[66];
uint32_t HCS_msg_duration;

struct dta_ {
   uint16_t delay;
   byte f;
   byte st;
};

volatile dta_ arr[1000];
volatile int poz_a = 0,poz_b = 0;
#endif

void HCS301::print(){
   String btn;

   if (BtnRing == 1) btn += "Ring";
   if (BtnClose == 1) btn += "Close";
   if (BtnOpen == 1) btn += "Open";
   if (BtnNoSound == 1) btn += "NoSound";

   String it2;

   it2 += " Serie ";
   it2 += SerialNum;
   it2 += " ";

   it2 += "Rolling Code ";
   it2 += Encript;

   it2 += btn;
   it2 += " BatteryLow=";
   it2 += BatteryLow;
   it2 += " Rep=";
   it2 += Repeat;

   //Serial.println(it2);
   Serial.print("Canal ");
   Serial.print(Canal,HEX);
   Serial.print("\t");
   Serial.print("Serie ");
   Serial.print(SerialNum,HEX);
   Serial.print("\t");
   Serial.print("Rolling Code ");
   Serial.print(Encript,HEX);
   Serial.println("");


}

void setup() {
   
   Serial.begin(9600);
   attachInterrupt(0, HCS_interrupt, CHANGE);

   pinMode(LED_PIN, OUTPUT);
   pinMode(HCS_RECIEVER_PIN, INPUT);
}

void loop() {

   if(HCS_Listening == false){

     HCS301 msg;
     memcpy(&msg,&hcs301,sizeof(HCS301));

     msg.print();
     #ifdef HCS_DEBUG
     if(msg.SerialNum != 639){

       Serial.println("Raw >>>>>>>>>>>>>>>>>>>>>>>");
       while(1){
         if(poz_b == poz_a) break;
         Serial.println(String(poz_b)+String("   
")+String(arr[poz_b].delay)+String("   ")+String(arr[poz_b].f == 0 ? 
"LOW":"HIGH")+String("   ")+String(arr[poz_b].st));
         poz_b++;
       }
       Serial.println("Data >>>>>>>>>>>>>>>>>>>>>>>");
       for(int i = 0;i<66;i++){  Serial.println(HCS_bit_array[i]);   }
     } else {

     }
     poz_a = 0,poz_b = 0;
     #endif

     HCS_Listening = true;
   }
}

//

void HCS_interrupt(){

   if(HCS_Listening == false){
     return;
   }

   uint32_t cur_timestamp = micros();
   uint8_t  cur_status = digitalRead(HCS_RECIEVER_PIN);
   uint32_t pulse_duration = cur_timestamp - HCS_last_change;
   HCS_last_change     = cur_timestamp;

   #ifdef HCS_DEBUG
   if(poz_a < 999){
     arr[poz_a].delay = pulse_duration;
     arr[poz_a].f = cur_status == HIGH ? 0 : 1;
     poz_a++;
   }
   #endif

   // ловим преамбулу
   if(HCS_preamble_count < 12){
     if(cur_status == HIGH){
       if( ((pulse_duration > 200) && (pulse_duration < 400)) || HCS_preamble_count == 0){
         // начало импульса преамбулы
         if(HCS_preamble_count == 0){
           HCS_start_preamble = cur_timestamp; // Отметим время старта преамбулы
         }
       } else {
         // поймали какую то фигню, неправильная пауза между импульсами
         HCS_preamble_count = 0; // сбрасываем счетчик пойманных импульсов преамбулы
         goto exit;

       }
     } else {
       // конец импульса преамбулы
       if((pulse_duration > 400) && (pulse_duration < 600)){
         #ifdef HCS_DEBUG
           HCS_PulseDuration[HCS_preamble_count] = pulse_duration;
         #endif
         // поймали импульс преамбулы
         HCS_preamble_count ++;
         #ifdef HCS_DEBUG
         arr[poz_a-1].st = HCS_preamble_count;
         #endif
         if(HCS_preamble_count == 12){
           // словили преамбулу
           //HCS_Te = (cur_timestamp - HCS_start_preamble) / 23;  // вычисляем длительность базового импульса Te
           //HCS_Te2_3 = HCS_Te * 3 / 2;
           HCS_bit_counter = 0;
           goto exit;
         }
       } else {
         // поймали какую то фигню
         HCS_preamble_count = 0; // сбрасываем счетчик пойманных импульсов преамбулы
         goto exit;
       }
     }
   }


   // ловим данные
   if(HCS_preamble_count == 12){
     if(cur_status == HIGH){
       if(((pulse_duration > 300) && (pulse_duration < 900)) || HCS_bit_counter == 0){
         // начало импульса данных
       } else {
         // неправильная пауза между импульсами
         HCS_preamble_count = 0;
         goto exit;
       }
     } else {
       // конец импульса данных
       if((pulse_duration > 300) && (pulse_duration < 900)){
         HCS_bit_array[65 - HCS_bit_counter] = (pulse_duration >
HCS_Te2_3) ? 0 : 1; // импульс больше, чем половина от Те * 3 поймали 0, иначе 1

         #ifdef HCS_DEBUG
         HCS_BitDuration[HCS_bit_counter] = pulse_duration;
         #endif
         HCS_bit_counter++;
         #ifdef HCS_DEBUG
         arr[poz_a-1].st = HCS_bit_counter;
         #endif
         if(HCS_bit_counter == 66){
           // поймали все биты данных

           HCS_Listening = false;  // отключем прослушку приемника, отправляем пойманные данные на обработку
           HCS_preamble_count = 0; // сбрасываем счетчик пойманных импульсов преамбулы
           #ifdef HCS_DEBUG
           HCS_msg_duration = cur_timestamp - HCS_start_preamble;
           #endif

           hcs301.Repeat = HCS_bit_array[0];
           hcs301.BatteryLow = HCS_bit_array[1];
           hcs301.BtnNoSound = HCS_bit_array[2];
           hcs301.BtnOpen = HCS_bit_array[3];
           hcs301.BtnClose = HCS_bit_array[4];
           hcs301.BtnRing = HCS_bit_array[5];

           Canal=HCS_bit_array[5]+2*HCS_bit_array[4]+4*HCS_bit_array[3]+8*HCS_bit_array[2];

           hcs301.SerialNum = 0;
           for(int i = 6; i < 34;i++){
             hcs301.SerialNum = (hcs301.SerialNum << 1) + HCS_bit_array[i];
           };

           uint32_t Encript = 0;
           for(int i = 34; i < 66;i++){
              Encript = (Encript << 1) + HCS_bit_array[i];
           };
           hcs301.Encript = Encript;
         }
       } else {
         // поймали хрень какую то, отключаемся
         HCS_preamble_count = 0;
         goto exit;
       }
     }
   }

   exit:;

   //digitalWrite(LED_PIN,cur_status);
}

As I understand it, to work with KeeLoq it is necessary to accept the conditions, this one is for the decoder (and it has for the encoder):

Terms and Conditions:

End User License Agreement for
Microchip KEELOQ(r) Decoder Software and Proprietary Documentation

IMPORTANT - READ CAREFULLY. This License Agreement is a legal agreement between you (either an individual or a single entity) and Microchip Technology Incorporated and its subsidiary Microchip Technology (Barbados) Incorporated (in the aggregate referred to as "Microchip") for Microchip’s KEELOQ® Software (hereinafter the "Software") and accompanying proprietary documentation (hereinafter the "Proprietary Documentation"). The Software and Proprietary Documentation provided herewith are intended, and supplied to you, for use solely and exclusively in a system that incorporates Microchip encoder and Microchip decoder products and for no other use or purpose whatsoever. Microchip will license the Software and Proprietary Documentation to you only if you first accept the terms of this agreement. By indicating acceptance below, or by otherwise installing, copying or using the Software or Proprietary Documentation, you are agreeing to be bound by the terms of this agreement. If you do not agree to the terms of this agreement, so indicate below and promptly destroy the software or return the unused Software for a full refund of moneys paid, if any.

THE SOFTWARE AND PROPRIETARY DOCUMENTATION MAY BE ACCESSED ONLY IF YOU ACCEPT THE TERMS AND CONDITIONS OF THIS LICENSE AGREEMENT. PLEASE INDICATE YOUR ACCEPTANCE OR NON-ACCEPTANCE BY SELECTING "I ACCEPT" OR "I DO NOT ACCEPT" AS INDICATED BELOW.

The Software and Proprietary Documentation are protected by U.S. copyright laws and international copyright treaties, as well as other intellectual property laws and treaties.

  1. Ownership and Title.

    All right, title and interest, including intellectual property rights, in and to the Software and the Proprietary Documentation shall remain in Microchip. The Software and Proprietary Documentation are licensed pursuant to this agreement, not sold. Microchip owns all proprietary rights to the KEELOQ® secure access control technology, including, but not limited to, code hopping, bi-directional authentication and self learning as implemented in KEELOQ® technology including all hardware and software implementations of the technology. Microchip reserves all rights not expressly granted to you.

  2. Grant of Limited License and Restrictions.

    Subject to all of the terms and conditions of this agreement, Microchip grants to you a worldwide, fully paid-up, non-exclusive license to reproduce, have reproduced, market, sell, distribute and use the Software, for the sole and limited purpose of integrating the Software into your own "conforming systems" that you will distribute. Conforming systems are those systems, which incorporate Microchip encoder and Microchip decoder products in the same system. No license is hereby granted to the Software for any other purpose and no license is granted to distribute the software in a form other than as part of a conforming system.

Subject to all of the terms and conditions of this agreement, Microchip further hereby grants to you a world-wide, fully paid-up, non-exclusive license to use the Proprietary Documentation provided with the Software internally only. The Proprietary Documentation may not be reproduced, copied or disclosed to parties other than Microchip.

You may enter into agreements or arrangements with individuals or entities other than Microchip for the reproduction of the Software; provided, however, that you, prior to any negotiations or discussion with individuals other than Microchip with respect to the reproduction of Software, first obtain an executed non- disclosure/confidentiality agreement with those individuals or entities in a form and content approved in advance by Microchip that requires all reproductions be incorporated into your conforming products. All copies of the Software created by you or for you must include at least the Microchip’s copyright, trademark and other proprietary notices.

You may not remove or alter any Microchip copyright or other proprietary rights notice contained in any portion of the Software or Proprietary Documentation that bear such a notice or in any reproductions thereof. You may not remove or alter any identifying screen that is produced by the Software.

You may modify, adapt and prepare derivative works of the Software only as necessary to incorporate the Software into your conforming products, and may distribute any such derivative works as part of your conforming products without additional license or fees, subject to all of the terms and conditions of this agreement. You may not prepare derivative works of the Proprietary Documentation.

This license is not transferable or sub-licensable. Neither this agreement nor any rights, licenses or obligations hereunder, may be assigned by you without the prior written approval of Microchip.

This license does not allow any sublicense, distribution or disclosure of the Software source code or Proprietary Documentation or any other proprietary rights to any third party in any circumstance or manner, and you agree that you will not engage in any such sublicensing, disclosure or distribution.

You may use the Software only with respect to the manufacture and sale of your own conforming products. You have no right to sell, assign, lend, rent, lease or otherwise transfer all or any portion of the Software or the proprietary rights for the Software except as expressly set forth herein, and this agreement grants no additional manufacturing, sales or marketing rights. You may not permit others to use or access the Software or Proprietary Documentation except as expressly permitted.

You may not reverse engineer (by disassembly, decompilation or otherwise) the Software and may not copy or reproduce all or any portion of the Software, except and only to the extent that such activity is specifically allowed by this agreement or expressly permitted by applicable law notwithstanding the foregoing limitations. You may not copy or reproduce all or any portion of the Proprietary Documentation without the express written consent of Microchip.

  1. Confidentiality.

    You agree not to disclose confidential information respecting the Software and Proprietary Documentation to any third party. Confidential information shall not include any information which is in or becomes part of the public domain or which is independently developed or which is independently obtained free from any obligation of confidentiality.

  2. Termination of Agreement.

    Without prejudice to any other rights, Microchip may terminate this agreement if you fail to comply with the terms and conditions of this agreement. Upon termination, you will immediately destroy all copies of the Software and will return all Proprietary Documentation. You will have a reasonable period after the termination of this Agreement to sell the existing inventory of your conforming systems.

  3. Indemnity.

    You will indemnify and hold Microchip, its related companies and its suppliers harmless for, from and against, any claims or liabilities, including without limitation product liability claims, arising out of the use, reproduction or distribution of your products that incorporate the Software, or any unauthorized use or sale by you of your product or any unauthorized use or disclosure of any information regarding the Software, the Proprietary Documentation or any other proprietary rights of Microchip.

  4. Limited Warranty and Limited Liability.

    The only warranty made by Microchip is that the original physical media in which the Software is embodied and which are distributed by Microchip shall be free of defects in materials and workmanship for a period of 90 days after delivery to you. Microchip’s and its suppliers’ entire liability and your exclusive remedy shall be limited to the replacement of the original physical media, if defective, within a reasonable period of time.

EXCEPT AS SPECIFICALLY PROVIDED IN THE PREVIOUS TWO SENTENCES, THE
SOFTWARE AND PROPRIETARY DOCUMENTATION IS PROVIDED "AS IS" WITHOUT
WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
LIMITATION, ANY WARRANTY OF MERCHANTABILITY, WARRANTY OF FITNESS FOR
A PARTICULAR PURPOSE, AND WARRANTY OF NON-INFRINGEMENT OF ANY
INTELLECTUAL PROPERTY RIGHT OF A THIRD PARTY.

THE ENTIRE RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE AND
OTHER DOCUMENTATION PROVIDED UNDER THIS AGREEMENT IS ASSUMED BY YOU,
AND MICROCHIP DISCLAIMS ALL RESPONSIBILITY FOR THE ACCURACY OR
APPLICATION OR OF ERRORS OR OMISSIONS IN THE SOFTWARE AND DOES NOT
WARRANT THE FUNCTIONS CONTAINED IN THE SOFTWARE WILL MEET YOUR
REQUIREMENTS OR THAT THE OPERATION OF THE SOFTWARE WILL BE
UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS IN THE SOFTWARE WILL
BE CORRECTED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR ANY DIRECT,
INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS
OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR
SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO
ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR
OTHER SIMILAR COSTS.

  1. Patent and Copyright Infringement.

    YOU ACKNOWLEDGE THAT (a) KEELOQ® SOFTWARE, EMBEDDED TECHNOLOGY,
    OR SERVICES RELATED THERETO ( HEREAFTER "KEELOQ") PERTAIN TO
    ENCODING AND DECODING FUNCTIONS, (b) THE DESIGN OF ALL ASPECTS
    OF ANY PRODUCT(S) OR SYSTEM(S) EMPLOYING KEELOQ IS SOLELY YOUR
    RESPONSIBILITY, AND (c) IT IS SOLELY YOUR RESPONSIBILITY TO
    DETERMINE WHETHER YOUR PRODUCTS OR SYSTEMS EMPLOYING KEELOQ
    INFRINGE A PATENT, COPYRIGHT, OR OTHER PROPRIETARY RIGHTS OF
    THIRD PARTIES. YOU AGREE THAT MICROCHIP SHALL HAVE NO OBLIGATION
    TO INDEMNIFY OR DEFEND YOU IN THE EVENT THAT A THIRD PARTY
    ASSERTS OR PROVES A CLAIM THAT ONE OR MORE OF YOUR SYSTEMS OR
    PRODUCTS EMPLOYING KEELOQ INFRINGE A THIRD PARTY’S PATENTS,
    COPYRIGHTS, OR OTHER PROPRIETARY RIGHTS (HEREINAFTER A "CLAIM").
    YOU HEREBY WAIVE ANY RIGHT TO CAUSE MICROCHIP TO DEFEND OR
    INDEMNIFY YOU OR ANY OF YOUR CUSTOMERS IN CONNECTION WITH A
    CLAIM, INCLUDING BUT NOT LIMITED TO ANY SUCH RIGHT AS MAY BE
    IMPOSED OR IMPLIED BY LAW, STATUTE, OR COMMON LAW.

    IF A SUIT OR PROCEEDING IS BROUGHT AGAINST MICROCHIP BASED ON A
    CLAIM THAT KEELOQ SUPPLIED BY MICROCHIP TO YOU CONSTITUTE
    INFRINGEMENT OF A PATENT, COPYRIGHT, DATA BASE RIGHT, TRADEMARK
    OR OTHER INTELLECTUAL PROPERTY RIGHT WHERE THE ALLEGED
    INFRINGEMENT IS BASED ON (a) MICROCHIP’S COMPLIANCE WITH YOUR
    DESIGNS OR SPECIFICATIONS, OR (b) YOUR USE OF KEELOQ IN
    COMBINATION WITH ANY OTHER PRODUCT OR IN A PROCESS (WHETHER
    DIRECT OR CONTRIBUTORY INFRINGEMENT), OR (c) YOUR OR ANYONE
    ELSE’S MODIFICATION OF KEELOQ AFTER MICROCHIP DELIVERS IT TO
    YOU, OR (d) YOUR USE OF KEELOQ IN A MANNER FOR WHICH IT WAS NOT
    DESIGNED, YOU SHALL DEFEND MICROCHIP AGAINST SUCH CLAIM AND
    SHALL INDEMNIFY MICROCHIP AND HOLD MICROCHIP HARMLESS FOR, FROM
    AND AGAINST ALL DAMAGES AND COSTS AWARDED AGAINST MICROCHIP.

    THE FOREGOING STATES THE SOLE AND EXCLUSIVE REMEDY AND LIABILITY
    OF THE PARTIES FOR INTELLECTUAL PROPERTY INFRINGEMENT. IN NO
    EVENT SHALL MICROCHIP BE LIABLE TO YOU OR YOUR CUSTOMERS FOR ANY
    SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL DAMAGES FOR
    INTELLECTUAL PROPERTY INFRINGEMENT, INCLUDING BUT NOT LIMITED TO
    ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION.

  2. General.

    Nothing in this agreement constitutes a waiver of Microchip’s
    rights under U.S. copyright laws or any other federal, state,
    local or foreign law. You are responsible for installation,
    management and operation of the Software. This agreement shall
    be construed, interpreted and governed by the laws of the State
    of Arizona, without regard to its conflicts of laws provisions.
    If any provision of this agreement is found void or
    unenforceable, the remainder of the agreement will remain valid
    and enforceable according to its terms. If any remedy provided
    is determined to have failed of its essential purpose, all
    limitations of liability and exclusion of damages set forth in
    the limited warranty shall remain in effect.

You agree to comply with all export laws, restrictions and regulations
of the U.S. Department of Commerce or other United States or foreign
agency or authority.

If you have any questions concerning this agreement, please write
Microchip Technology Inc. 2355 W. Chandler Blvd. Chandler, AZ 85224
USA, ATTN: Legal Department

Copyright © 2006, Microchip Technology Incorporated, 2355 West
Chandler Blvd, Chandler, AZ 85224-6199, U.S.A. All rights reserved.
Microchip and KEELOQ® are registered trademarks of Microchip
Technology Incorporated. Decoder 071906

I found a code for PIC18F too:

TB003 - An Introduction to KeeLoq Code Hopping:

AN1683A - Introduction to Ultimate KeeLoq Technology:

DS50033B - Programming KEELOQ Devices with the PRO MATE II Device Programmer:

AN745 - Modular Mid-Range PICmicro KeeLoq Decoder in C:
00745a_c.pdf (318.9 KB)
An745_c.zip (17.1 KB)

1 Like

Arduino Keeloq library

Keeloq is just an encryption scheme, with a proprietary hardware implementation, and has been cracked. If you are making a commercial product, you will of course research patent issues and/or license it from Microchip. As a hobby project for yourself, go ahead and use it.

Is Keeloq of special interest, compared to some other, probably better scheme?

2 Likes

Nice reference, thank you!

I was thinking about using KeeLoq for easy replacement after a few years.

Maybe using HCS201 + HCS500, but the datasheets are pretty confusing.

1 Like

About breaking the code, I already knew, thanks:

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.