Un échange d'information autour de la carte KeyDuino
 
HomeHome  FAQFAQ  RegisterRegister  Log inLog in  

Share | 
 

 HCE connnectivity

View previous topic View next topic Go down 
AuthorMessage
raul
Newbie
Newbie


Messages : 3
Reputation : 0
Date d'inscription : 2017-08-18

PostSubject: HCE connnectivity   Wed 23 Aug - 16:47

Hi, Actually i work in my project off a smart lock. I buy a keyduino for this. My idea was that use my smartphone like a key that de smart lock off the door can recognize me (my smartphone). But if I scan the tag of my smartphone (using the code tag identification) all the time change and show numbers random.
I want to find a way to solve that problem.
Back to top Go down
raul
Newbie
Newbie


Messages : 3
Reputation : 0
Date d'inscription : 2017-08-18

PostSubject: Re: HCE connnectivity   Wed 23 Aug - 18:18


I try to use hce_unlock code but this is the result
Back to top Go down
MrStein
KeyDuino TEAM
avatar

Messages : 60
Reputation : 3
Date d'inscription : 2015-10-10
Age : 24
Localisation : Lille, FRANCE

PostSubject: Re: HCE connnectivity   Thu 24 Aug - 13:46

To use HCE you will need an application with a defined AID LIKE THIS ONE from frugalprototype.com
in this APK, the AID is 0xF0, 0x46, 0x52, 0x55, 0x47, 0x41, 0x4c. (F0 + "FRUGAL").
Here is the new code exemple with the AID:

Code:

/*
This sketch is made to be used with an HCE (Host-based Card Emulation) application, for example to unlock a door.
KeyDuino sends an APDU command to select an Application ID, and receives an answer from the app.
You can then compare the answer with what you expect, and proceed to unlocking if it matches.

Author: Raymond Borenstein - CITC-EuraRFID

Compatible with KeyDuino 5.1

Join http://keyduino.forumsactifs.com/ to ask your questions, suggest your ideas, and show your projects!
*/

#include <KeyDuino.h>

KeyDuino keyDuino;

uint8_t openingCode[] = {
  0x01, 0x02, 0x03, 0x37, 0x90, 0x00 }; //90 00 is the success code, you need to add it - the rest of the code is the same as the one defined in the HCE application

void setup()
{    
  Serial.begin(115200);
  Serial.println("-------Peer to Peer HCE--------");

  keyDuino.begin();
}

void loop()
{
  bool success;

  uint8_t responseLength = 32;

  Serial.println("Waiting for an HCE Application...");

  // set shield to inListPassiveTarget
  success = keyDuino.inListPassiveTarget(PN532_MIFARE_ISO14443A); //If it doesn't work with your device, you can try with PN532_ISO14443B

  if(success) {

    Serial.println("Found something!");

    uint8_t selectApdu[] = {
      0x00, /* CLA */
      0xA4, /* INS */
      0x04, /* P1  */
      0x00, /* P2  */
      0x07, /* Length of AID  */
      0xF0, 0x46, 0x52, 0x55, 0x47, 0x41, 0x4c, /* AID defined on HCE App */
      };

    uint8_t response[32];  

    success = keyDuino.inDataExchange(selectApdu, sizeof(selectApdu), response, &responseLength);

    if(success) {

      Serial.print("responseLength: ");
      Serial.println(responseLength);

      Serial.print("response: ");
      keyDuino.PrintHex(&response[0], responseLength);
      
      if (sizeof(openingCode)/sizeof(uint8_t) == responseLength && memcmp(response, openingCode, responseLength) == 0){
        //Response is correct, do whatever you need here
        Serial.println("Opening!");
      } else {
        Serial.println("Incorrect response, not opening...");
      }
    }
    else {
      Serial.println("Failed sending SELECT AID");
    }
  }
  delay(1000);
}


If you want more information, here is a good tutorial (sadly in french) with the source of the apk: https://www.frugalprototype.com/android-nfc-hce/
Back to top Go down
http://keyduino.forumsactifs.com
raul
Newbie
Newbie


Messages : 3
Reputation : 0
Date d'inscription : 2017-08-18

PostSubject: Re: HCE connnectivity   Fri 25 Aug - 14:25

Thanks Mr stein you help me a lot I love you
Back to top Go down
Sponsored content




PostSubject: Re: HCE connnectivity   

Back to top Go down
 
HCE connnectivity
View previous topic View next topic Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
KeyDuino forum :: KeyDuino projects & tutorial :: Projects :: Idea / proposition of project-
Jump to: