You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MainClass.cpp 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // Created by robin on 8/8/15.
  3. //
  4. #include <iostream>
  5. #include <sysexits.h>
  6. #include <DBO/StringUtils.h>
  7. #include <Business/FreeFareDeviceBusiness.h>
  8. #include "DBO/Result.h"
  9. #include "Business/LibNfcBusiness.h"
  10. #include "Business/FreeFareDeviceBusiness.h"
  11. #include "CommandLineParser.h"
  12. #include "MainClass.h"
  13. MainClass::MainClass(int argc, char *argv[])
  14. : _argc(argc)
  15. , _argv(argv)
  16. {
  17. }
  18. int MainClass::main()
  19. {
  20. std::cout << "LibNfc version: " << LibNfcBusiness::getVersion() << std::endl;
  21. LibNfcBusiness libNfc;
  22. auto init = libNfc.init();
  23. if (!init) {
  24. init.print();
  25. return 1;
  26. }
  27. auto devicesResult = libNfc.getDevices();
  28. if (!devicesResult) {
  29. devicesResult.print();
  30. return 2;
  31. }
  32. auto devices = devicesResult.getData();
  33. if (devices.size() == 0) {
  34. std::cerr << "No NFC device found" << std::endl;
  35. return 3;
  36. }
  37. std::cout << "Found " << devices.size() << " devices: " << std::endl;
  38. for (size_t i = 0; i < devices.size(); ++i) {
  39. std::cout << devices[i]->getConnStr() << std::endl;
  40. }
  41. auto device = devices[0];
  42. auto open = device->open();
  43. if (!open) {
  44. open.print();
  45. return 4;
  46. }
  47. FreeFareDeviceBusiness freeFareDevice(device);
  48. auto tags = freeFareDevice.getTags();
  49. if (!tags) {
  50. tags.print();
  51. return 5;
  52. }
  53. std::cout << "Found " << tags.getData().size() << " tags:" << std::endl;
  54. for (size_t i = 0; i < tags.getData().size(); ++i) {
  55. auto tag = tags.getData()[i];
  56. std::cout << "UID: " << tag->getUid() << std::endl;
  57. std::cout << "Type: " << tag->getType() << std::endl;
  58. for(int i = 0; i < 16; ++i) {
  59. std::cout << "+Sector: " << i << std::endl;
  60. for (int j = 0; j < 4; ++j) {
  61. auto sector = tag->readBlock(i, j, StringUtils::humanToRaw("8829da9daf76").getData(), MFC_KEY_A);
  62. if (!sector) {
  63. sector.print();
  64. }
  65. else {
  66. std::cout << StringUtils::rawToHuman(sector.getData()) << std::endl;
  67. }
  68. }
  69. }
  70. }
  71. device->close();
  72. libNfc.clean();
  73. return 0;
  74. }