私はAndroidとPN532 RFIDモジュール間の通信を行うためにlibnfcの周りにC++ラッパーを構築しようとしています。nfc_initiator_transceive_bytes()を使用してlibnfcで大きなAPDUコマンドを送信できません
これは私をたくさん助けた:http://nfc-tools.org/index.php/Libnfc:APDU_example
このコードは(私はバイトなど任意のヘッダを送信していないよ)本体はmessage
に含まれているAPDUコマンドを送信し、response
に応答を読み込むためのものです。
問題:message
は文字を超えた場合、私はバッファオーバーフローがエラーを検出し得ます。さもなければ、それは完全にうまくいく私はエラーがNFCライブラリによってスローされたとは思わない。
bool send(const std::string &message, std::string &response){
std::vector<uint8_t> apduCmd(message.begin(), message.end());
uint8_t *capdu = &apduCmd[0];
size_t capdulen = apduCmd.size();
uint8_t rapdu[10];
size_t rapdulen = 10;
// BUFFER OVERFLOW HERE
int res = nfc_initiator_transceive_bytes(m_nfcDevice, capdu, capdulen, rapdu, rapdulen, 500);
if (res<0) {
return false;
}
if(res<2 || rapdu[res-2] != 0x90 || rapdu[res-1] != 0x00){
return false;
}
// byteArrayToString omitting the last two bytes
response = byteArrayToString(rapdu, 0, res-2);
return true;
}
拡張APDUのサポートを探す必要があるかもしれません - あなたのAndroidデバイスがデータ長> 255バイトのAPDUをサポートしていないことが問題です。cla [1] + ins [1] + param [2] + lc [1] + data [255] + le [1] = 261 bytes' –