don / cordova-plugin-hce

Cordova plugin for Host Card Emulation (HCE)
Other
28 stars 15 forks source link

How to make this plugin work #12

Open Vartex05 opened 6 years ago

Vartex05 commented 6 years ago

Has anyone experience with this plugin ? I would like to make it work, but iam a little lost. Actual example would be nice. Iam trying to make ionic app, that will emulate nfc tag, but so far i was unsuccesful :(

rikkipitt commented 6 years ago

@Vartex05 any luck in integrating this with Ionic?

I found a fork of the phonegap NFC plugin that adds HCE support: https://github.com/jalbersol/phonegap-nfc

Did you manage to get anything working?

Vartex05 commented 6 years ago

Nothing so far :/ Did u find out how to make it work? Or some other example/solution?

rikkipitt commented 6 years ago

I made a fork of the original phonegap-nfc plugin and built in some of the ideas from jalbersol/phonegap-nfc (as it was far too long winded and difficult to properly rebase).

From there, I abandoned the project as we've changed paths our end.

If you'd like to pick it up, let me know. I think you'll need to change the way the phonegap-nfc plugin starts the NFC functionality (to prevent Android Beaming).

enableForegroundDispatch vs enableReaderMode

https://stackoverflow.com/a/33789176

Vartex05 commented 6 years ago

Ah, thats a pity, iam a little lost in this, a working example or some tutorial how to make it work would really help me.

don commented 6 years ago

@Vartex05 There is a demo app that uses the Google card reader sample see https://github.com/don/cordova-plugin-hce#hce-demo-app

Vartex05 commented 6 years ago

yea i saw that, but i dont really understand, how do i know which aid to use. Or where do i get this APDU command. I want to emulate mifare tag.

don commented 6 years ago

HCE emulates smart cards. APDU commands are the commands used exchange of data between the reader and the card. The reader will send you a command and you need to respond. To do this you'll need to get the Mifare Classic specification and implement many of the commands for things like get uid, handing keys, authenticate sector, read block, write block, etc. This is a lot of work to implement. You'll need an intimate understanding of the inner working of Mifare. If you're luck you can find another implementation and port it over.

This plugin was written for one customer's specific needs. There might be other commands you can use to implement what you want in the Android SDK. See the Host-based Card Emulation docs

If you're looking to just send data from Android to a NFC reader the Peer to Peer sharing NDEF messages is a much easier way to go.

yaro08 commented 5 years ago

Hi @don,

Right now, I tried with your example cordova code and with ionic but "registerCommandCallback" never fires. I don't know why... My second device is in NFC Read mode (NFC Tools app from Google Play)

This is my code:

....

`import { HCE } from '@ionic-native/hce';

@Component({ templateUrl: 'app.html' }) export class MyApp { rootPage:any = HomePage;

constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, public hce: HCE) { platform.ready().then(() => { statusBar.styleDefault(); splashScreen.hide();

  console.log("platform ready go to register command callback");

  hce.registerCommandCallback(this.onCommand,err=>alert(err));

});

}

onCommand(command){ /// never fires here... console.log("I onCommand... well"); } }`

When you said

To do this you'll need to get the Mifare Classic specification and implement many of the commands for things like get uid, handing keys, authenticate sector, read block, write block, etc. This is a lot of work to implement. You'll need an intimate understanding of the inner working of Mifare. If you're luck you can find another implementation and port it over.

It can do in JS only or need do in the both code (js and java plugin)

Your plugin works without "cordova-plugin-hce" java plugin?

Thanks a lot,

Regards

woaichunchunma commented 5 years ago

嗨@don,

现在,我尝试使用你的示例cordova代码和离子,但“registerCommandCallback”永远不会触发。我不知道为什么......我的第二台设备处于NFC读取模式(来自Google Play的NFC Tools应用程序)

这是我的代码:

....

来自'@ ionic-native / hce'的'import {HCE};

@component({ templateUrl:'app.html' }) 导出类MyApp { rootPage:any = HomePage;

构造函数(platform:Platform,statusBar:StatusBar,splashScreen:SplashScreen,public hce:HCE){ platform.ready()。then(()=> { statusBar.styleDefault(); splashScreen.hide();

  console.log("platform ready go to register command callback");

  hce.registerCommandCallback(this.onCommand,err=>alert(err));

});

}

onCommand(command){///永远不会在这里触发... console.log(“我onCommand ...... well”); } }`

当你说

要做到这一点,你需要获得Mifare Classic规范并实现许多命令,例如get uid,处理密钥,验证扇区,读取块,写入块等。这是很多工作要实现的。你需要对Mifare的内部工作有一个深入的了解。如果你运气好,你可以找到另一个实现并将其移植。

它只能在JS中执行或者需要在两个代码中执行(js和java插件)

你的插件没有“cordova-plugin-hce”java插件吗?

非常感谢,

问候

I have met the same problem as you. My English is not very good. I can only say something about it. First of all, plug-ins are no problem. Maybe what you need is the AID of the card reader. Just pass in AID when installing plug-ins.

CuiShiKang commented 5 years ago

嗨@don, 现在,我尝试使用你的示例cordova代码和离子,但“registerCommandCallback”永远不会触发。我不知道为什么......我的第二台设备处于NFC读取模式(来自Google Play的NFC Tools应用程序) 这是我的代码: .... 来自'@ ionic-native / hce'的'import {HCE}; @component({ templateUrl:'app.html' }) 导出类MyApp { rootPage:any = HomePage; 构造函数(platform:Platform,statusBar:StatusBar,splashScreen:SplashScreen,public hce:HCE){ platform.ready()。then(()=> { statusBar.styleDefault(); splashScreen.hide();

  console.log("platform ready go to register command callback");

  hce.registerCommandCallback(this.onCommand,err=>alert(err));

});

} onCommand(command){///永远不会在这里触发... console.log(“我onCommand ...... well”); } }` 当你说

要做到这一点,你需要获得Mifare Classic规范并实现许多命令,例如get uid,处理密钥,验证扇区,读取块,写入块等。这是很多工作要实现的。你需要对Mifare的内部工作有一个深入的了解。如果你运气好,你可以找到另一个实现并将其移植。

它只能在JS中执行或者需要在两个代码中执行(js和java插件) 你的插件没有“cordova-plugin-hce”java插件吗? 非常感谢, 问候

I have met the same problem as you. My English is not very good. I can only say something about it. First of all, plug-ins are no problem. Maybe what you need is the AID of the card reader. Just pass in AID when installing plug-ins.

Hello, I read your reply, you said that plug-in is no problem, do you successfully implement it, I need to use mobile phones to simulate M1 card, see your reply you should be a Chinese, do you have similar functions to achieve?