내 안드로이드와 PN532 RFID 모듈 사이의 통신을 위해 libnfc 주위에 C++ 래퍼를 작성하려고합니다. 이 코드는 몸이 message
에 포함 된 APDU 명령을 (내가 어떤 헤더 바이트 등을 전송하고 있지 않다) 보내 response
에 응답을 읽기위한 것입니다 http://nfc-tools.org/index.php/Libnfc:APDU_examplenfc_initiator_transceive_bytes()를 사용하여 libnfc와 함께 커다란 APDU 명령을 보낼 수 없습니다.
:
이
나에게 많은 도움이되었습니다.문제 : 262 문자를 초과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의 지원을 찾아야 할 수도 있습니다. 안드로이드 장치가 데이터 길이> 255 바이트 인 cla [1] + ins [1] + param [2] + lc로 APDU를 지원하지 않을 수 있습니다. [1] + data [255] + le [1] = 261 bytes' –