Giter Club home page Giter Club logo

android-pn532-hce's Introduction

android-pn532-hce

Python NFC example for PN532 to receive a unique id (uid) of an android device or simple nfc tags (for auth, whatever).

Concept

For deeper info check this link by Mohamed Hamdaoui. He communicated between two phones, some of the android code is used from him: https://medium.com/the-almanac/how-to-build-a-simple-smart-card-emulator-reader-for-android-7975fae4040f

tl;dr

Default: Card Reader sends APDU (Application Protocol Data Unit Command) -> tag will respond with uid. Issue: Android device responds with either '01020304' or different id every time you hold it to the reader. Solution: Android allows Host-based Card Emulation (HCE), so it may behave like a simple nfc tag / smart card. It can take APDU commands and return APDU responses.

Installing the android app will register an APDU service with an AID (in this example 'A0000001020304'). The reader (PN532) sends an APDU command containing this AID, the android device executes our registered service and sends back a local generated unique id (stored/persistent). No need to run the app after installation, service will do the job in background. Device can be locked, but screen needs to be on (android security policy).

PN532

This is running on my Pi. The PN532 board needs to be connected via UART (because i2c / spi is not supported by nfcpy lib which will be used). Check some tutorials for this, if you haven't connected it yet. In this example libnfc is not neccessary.

Install & Run

install pip3 if not installed:

sudo apt-get install python3-pip

install nfcpy:

pip3 install -U nfcpy

Clone this repository:

git clone https://github.com/Lexycon/android-pn532-hce.git
cd android-pn532-hce

And finally run the main.py file. It's an example how to use the PN532.py class.

python3 main.py

Android

Either build this whole project by your own or use the prebuilt apk: releases

Copy the apk file to the phone and install it. The UI shows the generated uid. Delete application data to get a new id.

android-pn532-hce's People

Contributors

lexycon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.