Changed|Added(scripts/termux-nfc): support all NFC APIs #214
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add all APIs (78 in total) listed in the official doc for all NFC technologies (NfcA, NfcB, NfcF, NfcV, IsoDep, Ndef, MifareClassic, MifareUltralight, NfcBarcode, NdefFormatable).
See also termux/termux-api#796.
The API call request in JSON format is passed into stdin of termux-api in the format of:
{"op": "discoverTag"}{"op": "api", "class": "<CLASSNAME>", "method": "<METHODNAME>", "args": [<ARG1>, <ARG2>, ...]}This is a thin wrapper around the native APIs without UI ergonomic considerations. It's supposed to be used e.g. in bash as a coprocess. To directly use it as a REPL, use
rlwrap termux-nfc -.Examples
Normal usage
$ termux-nfc - {"op": "discoverTag"} {"status":"success","result":{"id":{"format":"hex","value":"DEADBEEF"},"techList": "android.nfc.tech.IsoDep","android.nfc.tech.NfcA","android.nfc.tech.MifareClassic"]}} {"op": "api", "class":"IsoDep", "method": "connect", "args": []} {"status": "success"} {"op": "api", "class":"IsoDep", "method": "transceive", "args": [{"format": "hex", "value": "00A40000023F00"}]} {"status": "success", "result": {"format": "hex", "value": "01020304DEADBEEF"}}} {"op": "api", "class":"TagTechnology", "method": "close", "args": []} {"status": "success"} {"op": "api", "class":"MifareClassic", "method": "connect", "args": []} {"status": "success"} {"op": "api", "class":"MifareClassic", "method": "authenticateSectorWithKeyA", "args": [0, {"format":"hex","value":"FFFFFFFFFFFFFFFF"}]} {"status": "success", "result": true} {"op": "api", "class":"MifareClassic", "method": "readBlock", "args": [0]} {"status": "success", "result": {"format": "hex", "value": {"format": "hex", "value": "01020304DEADBEEF"}}} {"op": "api", "class":"TagTechnology", "method": "close", "args": []} {"status": "success"}Lines with
"op"are your console inputs, while lines with"status"are output from termux-api.As REPL
With rlwrap, you can use advanced command-line editing keybinds like up/down.
One-liner
With the help of bash herestring, commands can be typed before they are invoked:
As bash coprocess
coproc NFC_REPL { termux-nfc - ; } function run-nfc { local msg="$1" echo "$msg" >&"${NFC_REPL[1]}" local response read -r response <&"${NFC_REPL[0]}" echo "$response" } run-nfc '{"op": "discoverTag"}' run-nfc '{"op": "api", "class":"IsoDep", "method": "connect", "args": []}' run-nfc '{"op": "api", "class":"IsoDep", "method": "transceive", "args": [{"format": "hex", "value": "00A40000023F00"}]}' run-nfc '{"op": "api", "class":"TagTechnology", "method": "close", "args": []}'