element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Internet of Things
  • Technologies
  • More
Internet of Things
Blog Digital Logic µFR NFC Card Reader - part 5: refactor, look back at initial design
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Internet of Things to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 19 Dec 2020 8:10 PM Date Created
  • Views 950 views
  • Likes 2 likes
  • Comments 1 comment
  • infineon
  • security2go
  • apdu
  • smartcard
  • nfc
Related
Recommended

Digital Logic µFR NFC Card Reader - part 5: refactor, look back at initial design

Jan Cumps
Jan Cumps
19 Dec 2020

Follow up on my project to create an object oriented framework for smart card use.

In this article I want to add vendor-specific card functionality.

That is when I I find out that I'd better relocate some functions away from the Reader classes, to avoid that I have to adapt that family for any card I want to support.

image

 

 

In my original design, the Reader created the Card objects.

Depending on the card standard, it would create the appropriate object.

But now, I want to add a special card, the Infineon Security2Go card. It's a ISO14443 card, but it runs a custom application.

There are (as always) several way to model this.

In this post, I choose to create a new class that inherits from the ClassISO14443, and add behaviour for the Infineon card.

image

Side bar

In a later phase I think I want to change this - again.

In stead of inheriting and adding methods to support the card's application , I think about building a different set of classes that represent the application.

And leave the Card tree for industry standard cards... open for discussion.

 

What I learned while extending the card class for the Infineon card, I'd also had to extend the Reader class to.

To make it recognise Infineon cards and learn how to create an object of the custom class for them.

But the Reader doesn't change. It uses the same protocols, functions, .... . So that's unfortunate, that it has this binding with any possible card.

The Reader class was intended to deal with the NFC hardware. So I should not contaminate it with non-reader related tasks.

 

So I moved the createCard() family of functions out of the Reader family, and moved it (for now) to the Factory family.

 

From:

Card* UfrReader::getCard() {
  //...
  // if DL_MIFARE_MINI, the ID is to be ignored.
  // Create an ISO14443_4 card
  Card *card = NULL;
  if (lpucSak == DL_MIFARE_MINI) {
    card = new CardISO14443(this, lpucSak, id, lpucUidSize);
  } else {
    std::copy(std::begin(aucUid), std::end(aucUid), id.begin());
    card = new Card(this, lpucSak, id, lpucUidSize);
  }
  return card;
}

 

To:

Card* UfrFactory::getCard(Reader *reader) {
  //...
  // if DL_MIFARE_MINI, the ID is to be ignored.
  // Create an ISO14443_4 card
  Card *card = NULL;
  if (lpucSak == DL_MIFARE_MINI) {
    card = new CardISO14443(reader, lpucSak, id, lpucUidSize);
  } else {
    std::copy(std::begin(aucUid), std::end(aucUid), id.begin());
    card = new Card(reader, lpucSak, id, lpucUidSize);
  }
  return card;
}

 

So it's out of the Reader family. That one can concentrate on standard functionality again.

For programs that need to work with an Infineon card, I created a dedicated factory:

class S2GoFactory: public UfrFactory {
public:
  static CardS2Go * getCard(Reader *reader) {
     //...
    CardS2Go *card = NULL;
    card = new CardS2Go(reader, lpucSak, id, lpucUidSize);
     return card;
  }
};

 

Side bar

Future design:

Having worked with the framework for a while now, I am thinking to loosen several bounds:

  • a Reader family of classes, that can deal with several reader makes
  • a Card family of classes that can detect cards and create correct objects to represent those cards. Based on standards
  • an Application class of objects that can execute the apps running on certain types of smart cards (APDU, maybe java card apps)
  • Seperate classes if bonding between these objects is required, but I don't want to introduce dependencies between the families ...

 

As with the previous posts, the current version of the app is attached. It checks the ID of a Security2Go card.

 

int main() {
  Reader *reader = NULL;
  try {
    reader = S2GoFactory::getReader();
    while (!reader->hasCard()) {
      usleep(500);
    }
    CardS2Go *crd = S2GoFactory::getCard(reader);
    std::cout << "this is an ISO14443 capable card" << std::endl;
    crd->setISO14443_4();
    crd->selectApp();
    crd->unsetISO14443_4();

    S2GoFactory::releaseCard(crd, reader);
    crd = NULL;
  } catch (const UrfException &e) {
    std::cerr << e.what() << ": 0x" << std::hex << e.getError() << std::dec
        << std::endl;
  }
  S2GoFactory::releaseReader(reader);
  reader = NULL;
  return 0;
}

 

Related Blog
Blockchain - Talk Directly to the Infineon 2Go Smart Cards API
NFC Card Reader Protocol of Digital Logic µFR - part 0: intent
µFR NFC Card Reader - part 1: first C program for Linux (RPi, BB, ...)
µFR NFC Card Reader - part 2: first C++ program
µFR NFC Card Reader - part 3: C++ Class to handle ISO14443 / APDU cards
µFR NFC Card Reader - part 4: first meaningful ISO14443 / APDU conversation
µFR NFC Card Reader - part 5: refactor, look back at initial design
Attachments:
digitallogic_rfc_cpp_20201219.zip
  • Sign in to reply
  • DAB
    DAB over 4 years ago

    Nice update Jan.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube