android - Can't receive APDU data with Arduino NFC module -


i'm trying use hce on lg g2 , send data arduino uno elechouse nfc module 2.0.

the problem nfc.indataexchange(selectapdu, sizeof(selectapdu), response, &responselength) returns false. what's going wrong?

on arduino forums, misterfrench got working , i'm doing things using same principle. took following android hce examples , send rubbish data:

@override public byte[] processcommandapdu(byte[] commandapdu, bundle extras) {     log.i(tag, "received apdu: " + bytearraytohexstring(commandapdu));     // if apdu matches select aid command service,     // send loyalty card account number, followed select_ok status trailer (0x9000).     if (arrays.equals(select_apdu, commandapdu)) {          stringbuilder stringbuilder = new stringbuilder();         stringbuilder.append(build.manufacturer);         stringbuilder.append("#");         stringbuilder.append(build.model);         stringbuilder.append(((telephonymanager)getsystemservice(context.telephony_service)).getdeviceid());         string data = stringbuilder.tostring();         log.i(tag, "data send");          return concatarrays(data.getbytes(), select_ok_sw);     } else {         return unknown_cmd_sw;     } } 

and on arduino side, took code arduino forum , changed little. looks like

void loop(void) {     bool success;     serial.println("waiting iso14443a card");      success = nfc.inlistpassivetarget();     if(success) {         serial.println("found something!");         uint8_t selectapdu[] = {            0x00, /* cla */           0xa4, /* ins */           0x04, /* p1  */           0x00, /* p2  */           0x05, /* length of aid  */           0xf2, 0x22, 0x22, 0x22, 0x22,           0x00  /* le  */};          uint8_t response[256];         uint8_t responselength = sizeof(response);          success = nfc.indataexchange(selectapdu, sizeof(selectapdu), response, &responselength);          if(success) {             serial.print("raw: ");             (int = 0; < responselength; ) {                 serial.print(response[i++]);                 serial.print(" ");             }             serial.println(" ");              (int = 0; < responselength; i++) {                 serial.print((char)response[i]);                 serial.print(" ");             }             serial.println(" ");         }         else{             serial.println("failed sending select aid");          }     }     else {         serial.println("didn't find anything!");     }     delay(1000); } 

i'm using arduino uno, nfc library "pn532" https://github.com/elechouse/pn532

obviously these lines cause problem:

uint8_t response[256]; uint8_t responselength = sizeof(response);  success = nfc.indataexchange(selectapdu, sizeof(selectapdu), response, &responselength); 

in first line, create array of 256 bytes. in next line assign size of array 8-bit unsigned integer (uint8_t) variable. uint8_t can hold value between 0 , 255 (= 2^8-1). thus, size of response (= 256) cause overflow. results in responselength being set 0 (= 256 modulo 2^8). consequently, response length feed nfc.indataexchange() short hold response.

so using

uint8_t response[255]; uint8_t responselength = sizeof(response); 

should work.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -