NFC Apdu Response 67 00 (wrong length) on Android using isodep - android
i tried to send extended APDU command into Desfire card on Android.
i was select the application on the card and success.
but when i tried to authentication process and send this command, i got response 67 00 (wrong length)
i send data :
00820000288C9D8E3837E8E47514E9010801C1615E65E677A21DC40E07B32DF6DE24EED3D6CD950BA8CB5E738528
where:
CLA : 0x00
INS : 0x82
P1 : 0x00
P2 : 0x00
Lc : 0x28 //(40 bytes)
data :
0x8C, 0x9D, 0x8E, 0x38, 0x37, 0xE8, 0xE4, 0x75, 0x14, 0xE9, 0x01, 0x08, 0x01, 0xC1
, 0x61, 0x5E, 0x65, 0xE6, 0x77, 0xA2, 0x1D, 0xC4, 0x0E, 0x07, 0xB3, 0x2D, 0xF6, 0xDE
, 0x24, 0xEE, 0xD3, 0xD6, 0xCD, 0x95, 0x0B, 0xA8, 0xCB, 0x5E, 0x73, 0x85
**Le : 0x28 (expected return length)**
i think there is nothing wrong with the command structure, but why the response is 67 00
i am using isodep library.
please some one help me..
Related
Arduino ESP8266 HTTPS server How to install SSL certificate
I made HTTP server on my NodeMCU ESP8266 board using ESP8266WebServer library. I would like to convert it to the HTTPS server, so I used ESP8266WebServerSecure library, bought SSL certificate and got 3 files: certificate.cert dv_ca.pem private.pem Could someone explain me how should I install it on my server? Below my code when I was trying to launch https server with self-generated certificate, but there was a problem to connect it using android application(Trust anchor not found for Android SSL connection). #include <Arduino.h> #include <ESP8266WebServer.h> #include <ESP8266WebServerSecure.h> #include <ESP8266mDNS.h> #include <ArduinoJson.h> #define output4 4 #define output5 5 #define input0 A0 const char* ssid = "SSID"; const char* password = "password"; //HTTPS server object, port number 443 BearSSL::ESP8266WebServerSecure server(443); static const char serverCert[] PROGMEM = R"EOF( -----BEGIN CERTIFICATE----- -----END CERTIFICATE----- )EOF"; static const char serverKey[] PROGMEM = R"EOF( -----BEGIN PRIVATE KEY----- -----END PRIVATE KEY----- )EOF"; void handleNotFound() { String message = "No such a data or incorrect request..."; server.send(404, "text/plain", message); } void changeStatus(){ //Parsing request argument to string String postBody = server.arg("plain"); //Changing output value condition if(server.hasArg("number")&&server.hasArg("status")){ int pinNumber = server.arg("number").toInt(); if(server.arg("status")=="on"){ digitalWrite(pinNumber, HIGH); } else if(server.arg("status")=="off"){ digitalWrite(pinNumber, LOW); } } else { handleNotFound(); } Serial.println("Argument: "+postBody); server.send(200, "text/plain", postBody); } void getStatus(){ //Creating json document DynamicJsonDocument doc(200); //Pushing data to json document if(digitalRead(output4)==LOW){ JsonObject out4 = doc.createNestedObject("sensor 4"); out4["name"] = "output4"; out4["value"] = 0; } else { JsonObject out4 = doc.createNestedObject("sensor 4"); out4["name"] = "output4"; out4["value"] = 1; } if(digitalRead(output5)==LOW){ JsonObject out5 = doc.createNestedObject("sensor 5"); out5["name"] = "output5"; out5["value"] = 0; } else { JsonObject out5 = doc.createNestedObject("sensor 5"); out5["name"] = "output5"; out5["value"] = 1; } //Getting analog input value JsonObject in0 = doc.createNestedObject("sensor 0"); in0["name"] = "input0"; in0["value"] = analogRead(A0); //Variable co String outputData = ""; serializeJsonPretty(doc, outputData); server.send(200, "application/json", outputData); } void setup() { // put your setup code here, to run once: Serial.begin(115200); // Initialize the output variables as outputs pinMode(output5, OUTPUT); pinMode(output4, OUTPUT); // Set outputs to LOW digitalWrite(output5, LOW); digitalWrite(output4, LOW); //Get current time configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov"); //Start wifi connection WiFi.begin(ssid, password); delay(100); Serial.println("Trying to connect wifi network"); while(WiFi.status() != WL_CONNECTED){ Serial.print("."); delay(500); } Serial.println(""); Serial.print("Connected to "); Serial.println(WiFi.SSID()); Serial.print("IP adress: "); Serial.println(WiFi.localIP()); //Handling requests server.on("/", HTTP_GET, getStatus); server.on("/led", HTTP_GET, changeStatus); //Setting server certificate and key server.getServer().setRSACert(new BearSSL::X509List(serverCert), new BearSSL::PrivateKey(serverKey)); // Start server server.begin(); Serial.println("Secured server ready"); } void loop() { // put your main code here, to run repeatedly: // Handling incoming client requests in loop server.handleClient(); }
The code is from examples of ESP8266. Change the certificate except testing purposes. You can get a certificate from internet or generate it with make-self-signed-cert.sh which is located in ESP8266WiFi/examples/WiFiHTTPSServer. Before execution of make-self-signed-cert.sh, modify the script.Find your-name-here and replace it with your name or organization name. Then execute the script. At the end of the execution, there will be new files that named as key.h and x509.h. Certificate codes are in the two new files. Copy&paste them into the arduino code. #include <ESP8266WiFi.h> #ifndef STASSID #define STASSID "your-ssid" #define STAPSK "your-password" #endif const char* ssid = STASSID; const char* password = STAPSK; // The certificate is stored in PMEM static const uint8_t x509[] PROGMEM = { 0x30, 0x82, 0x01, 0x3d, 0x30, 0x81, 0xe8, 0x02, 0x09, 0x00, 0xfe, 0x56, 0x46, 0xf2, 0x78, 0xc6, 0x51, 0x17, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x26, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x45, 0x53, 0x50, 0x38, 0x32, 0x36, 0x36, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x09, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x37, 0x30, 0x33, 0x31, 0x38, 0x31, 0x34, 0x34, 0x39, 0x31, 0x38, 0x5a, 0x17, 0x0d, 0x33, 0x30, 0x31, 0x31, 0x32, 0x35, 0x31, 0x34, 0x34, 0x39, 0x31, 0x38, 0x5a, 0x30, 0x26, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x45, 0x53, 0x50, 0x38, 0x32, 0x36, 0x36, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x09, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x30, 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30, 0x48, 0x02, 0x41, 0x00, 0xc6, 0x72, 0x6c, 0x12, 0xe1, 0x20, 0x4d, 0x10, 0x0c, 0xf7, 0x3a, 0x2a, 0x5a, 0x49, 0xe2, 0x2d, 0xc9, 0x7a, 0x63, 0x1d, 0xef, 0xc6, 0xbb, 0xa3, 0xd6, 0x6f, 0x59, 0xcb, 0xd5, 0xf6, 0xbe, 0x34, 0x83, 0x33, 0x50, 0x80, 0xec, 0x49, 0x63, 0xbf, 0xee, 0x59, 0x94, 0x67, 0x8b, 0x8d, 0x81, 0x85, 0x23, 0x24, 0x06, 0x52, 0x76, 0x55, 0x9d, 0x18, 0x09, 0xb3, 0x3c, 0x10, 0x40, 0x05, 0x01, 0xf3, 0x02, 0x03, 0x01, 0x00, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x41, 0x00, 0x69, 0xdc, 0x6c, 0x9b, 0xa7, 0x62, 0x57, 0x7e, 0x03, 0x01, 0x45, 0xad, 0x9a, 0x83, 0x90, 0x3a, 0xe7, 0xdf, 0xe8, 0x8f, 0x46, 0x00, 0xd3, 0x5f, 0x2b, 0x0a, 0xde, 0x92, 0x1b, 0xc5, 0x04, 0xc5, 0xc0, 0x76, 0xf4, 0xf6, 0x08, 0x36, 0x97, 0x27, 0x82, 0xf1, 0x60, 0x76, 0xc2, 0xcd, 0x67, 0x6c, 0x4b, 0x6c, 0xca, 0xfd, 0x97, 0xfd, 0x33, 0x9e, 0x12, 0x67, 0x6b, 0x98, 0x7e, 0xd5, 0x80, 0x8f }; // And so is the key. These could also be in DRAM static const uint8_t rsakey[] PROGMEM = { 0x30, 0x82, 0x01, 0x3a, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, 0xc6, 0x72, 0x6c, 0x12, 0xe1, 0x20, 0x4d, 0x10, 0x0c, 0xf7, 0x3a, 0x2a, 0x5a, 0x49, 0xe2, 0x2d, 0xc9, 0x7a, 0x63, 0x1d, 0xef, 0xc6, 0xbb, 0xa3, 0xd6, 0x6f, 0x59, 0xcb, 0xd5, 0xf6, 0xbe, 0x34, 0x83, 0x33, 0x50, 0x80, 0xec, 0x49, 0x63, 0xbf, 0xee, 0x59, 0x94, 0x67, 0x8b, 0x8d, 0x81, 0x85, 0x23, 0x24, 0x06, 0x52, 0x76, 0x55, 0x9d, 0x18, 0x09, 0xb3, 0x3c, 0x10, 0x40, 0x05, 0x01, 0xf3, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x40, 0x35, 0x0b, 0x74, 0xd3, 0xff, 0x15, 0x51, 0x44, 0x0f, 0x13, 0x2e, 0x9b, 0x0f, 0x93, 0x5c, 0x3f, 0xfc, 0xf1, 0x17, 0xf9, 0x72, 0x94, 0x5e, 0xa7, 0xc6, 0xb3, 0xf0, 0xfe, 0xc9, 0x6c, 0xb1, 0x1e, 0x83, 0xb3, 0xc6, 0x45, 0x3a, 0x25, 0x60, 0x7c, 0x3d, 0x92, 0x7d, 0x53, 0xec, 0x49, 0x8d, 0xb5, 0x45, 0x10, 0x99, 0x9b, 0xc6, 0x22, 0x3a, 0x68, 0xc7, 0x13, 0x4e, 0xb6, 0x04, 0x61, 0x21, 0x01, 0x02, 0x21, 0x00, 0xea, 0x8c, 0x21, 0xd4, 0x7f, 0x3f, 0xb6, 0x91, 0xfa, 0xf8, 0xb9, 0x2d, 0xcb, 0x36, 0x36, 0x02, 0x5f, 0xf0, 0x0c, 0x6e, 0x87, 0xaa, 0x5c, 0x14, 0xf6, 0x56, 0x8e, 0x12, 0x92, 0x25, 0xde, 0xb3, 0x02, 0x21, 0x00, 0xd8, 0x99, 0x01, 0xf1, 0x04, 0x0b, 0x98, 0xa3, 0x71, 0x56, 0x1d, 0xea, 0x6f, 0x45, 0xd1, 0x36, 0x70, 0x76, 0x8b, 0xab, 0x69, 0x30, 0x58, 0x9c, 0xe0, 0x45, 0x97, 0xe7, 0xb6, 0xb5, 0xef, 0xc1, 0x02, 0x21, 0x00, 0xa2, 0x01, 0x06, 0xc0, 0xf2, 0xdf, 0xbc, 0x28, 0x1a, 0xb4, 0xbf, 0x9b, 0x5c, 0xd8, 0x65, 0xf7, 0xbf, 0xf2, 0x5b, 0x73, 0xe0, 0xeb, 0x0f, 0xcd, 0x3e, 0xd5, 0x4c, 0x2e, 0x91, 0x99, 0xec, 0xb7, 0x02, 0x20, 0x4b, 0x9d, 0x46, 0xd7, 0x3c, 0x01, 0x4c, 0x5d, 0x2a, 0xb0, 0xd4, 0xaa, 0xc6, 0x03, 0xca, 0xa0, 0xc5, 0xac, 0x2c, 0xe0, 0x3f, 0x4d, 0x98, 0x71, 0xd3, 0xbd, 0x97, 0xe5, 0x55, 0x9c, 0xb8, 0x41, 0x02, 0x20, 0x02, 0x42, 0x9f, 0xd1, 0x06, 0x35, 0x3b, 0x42, 0xf5, 0x64, 0xaf, 0x6d, 0xbf, 0xcd, 0x2c, 0x3a, 0xcd, 0x0a, 0x9a, 0x4d, 0x7c, 0xad, 0x29, 0xd6, 0x36, 0x57, 0xd5, 0xdf, 0x34, 0xeb, 0x26, 0x03 }; // Create an instance of the server // specify the port to listen on as an argument WiFiServerSecure server(443); void setup() { Serial.begin(115200); // prepare GPIO2 pinMode(2, OUTPUT); digitalWrite(2, 0); // Connect to WiFi network Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); // Set the certificates from PMEM (if using DRAM remove the _P from the call) server.setServerKeyAndCert_P(rsakey, sizeof(rsakey), x509, sizeof(x509)); // Start the server server.begin(); Serial.println("Server started"); // Print the IP address Serial.println(WiFi.localIP()); } void loop() { // Check if a client has connected WiFiClientSecure client = server.available(); if (!client) { return; } // Wait until the client sends some data Serial.println("new client"); unsigned long timeout = millis() + 3000; while (!client.available() && millis() < timeout) { delay(1); } if (millis() > timeout) { Serial.println("timeout"); client.flush(); client.stop(); return; } // Read the first line of the request String req = client.readStringUntil('\r'); Serial.println(req); client.flush(); // Match the request int val; if (req.indexOf("/gpio/0") != -1) { val = 0; } else if (req.indexOf("/gpio/1") != -1) { val = 1; } else { Serial.println("invalid request"); client.print("HTTP/1.1 404 Not Found\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html><body>Not found</body></html>"); return; } // Set GPIO2 according to the request digitalWrite(2, val); client.flush(); // Prepare the response String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now "; s += (val) ? "high" : "low"; s += "</html>\n"; // Send the response to the client client.print(s); delay(1); Serial.println("Client disconnected"); // The client will actually be disconnected // when the function returns and 'client' object is detroyed }
Control relay over USB from Android
I have this USB Relay and I'd like to control from an Android phone. (There is a similar post here but it explains how do it from a Linux shell. By looking at that code i figured i'd be able to solve it - apparently not.) The device lists in lsusb: Bus 002 Device 011: ID 16c0:05df VOTI Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 1.10 bDeviceClass 0 (Defined at Interface level) bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 8 idVendor 0x16c0 VOTI idProduct 0x05df bcdDevice 1.00 iManufacturer 1 iProduct 2 iSerial 0 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 34 bNumInterfaces 1 bConfigurationValue 1 iConfiguration 0 bmAttributes 0x80 (Bus Powered) MaxPower 20mA Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 1 bInterfaceClass 3 Human Interface Device bInterfaceSubClass 0 No Subclass bInterfaceProtocol 0 None iInterface 0 HID Device Descriptor: bLength 9 bDescriptorType 33 bcdHID 1.01 bCountryCode 0 Not supported bNumDescriptors 1 bDescriptorType 34 Report wDescriptorLength 22 Report Descriptors: ** UNAVAILABLE ** Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0008 1x 8 bytes bInterval 20 I find it strange that the end point is defined as "EP IN". In my mind it should be "EP OUT" since the direction should be "host->device". Anyway, I use the Android USB manager to create a connection and then initialize the USbRequest for an interrupt based end point. Android permissions and all that is handled so the device is connected successfully. Snippet for sending data. It runs in a separate thread following the Android guidelines: UsbRequest request = new UsbRequest(); synchronized (mUsbLock) { if (mUsbConnection != null && mUsbEndPointIn != null) { if (!request.initialize(mUsbConnection, mUsbEndPointIn)) { Log.e(TAG, "Unable to initialize UsbRequest. Thread exits"); return; } else { if (DEBUG) { Log.d(TAG, String.format("Usb request is initialized")); } } } else { Log.e(TAG, "Usb communication is not up and running. The worker thread should never be started."); return; } } mRunning.set(true); while (mRunning.get()) { if (DEBUG) { Log.d(TAG, String.format("Waiting for data to be sent to end point")); } WorkPackage wp = mWorkQueue.take(); // send the package. byte[] data = wp.getData(); if (!request.queue(ByteBuffer.wrap(data), data.length)) { Log.e(TAG, "Unable to queue to send data on UsbRequest."); continue; } else { if (DEBUG) { Log.d(TAG, String.format("Usb request is queued on end point, ep=%s", printUsbEndpoint(mUsbEndPointIn))); } } } It seems everything is fine, no errors occur and the request is queued on the end point but then nothing happens at all. I don't get any message back that the request has been handled. Since the supplier won't release the on/off commands I tried variants based on the Linux post (above). None seem to work though. Supplier only release Windows binary lib. Sending 8 byte packages (according to max package): public static byte[] SET_RELAY_ON = {(byte) 0xff, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}; public static byte[] SET_RELAY_OFF = {(byte) 0xfd, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}; Help appreciated.
So, i figured out how to do this. I will write the solution here in case someone else is having a similar problem. I had to snoop the USB traffic to understand what to actually send. It turned out that the defined interrupt end point was not used at all. So, the communication with the device was not interrupt based but instead using the control transfer type on end point 0. So, using the Android USB API this translates into: Open device (device->host direction): int r = mUsbConnection.controlTransfer(0xa1, 0x01, 0x0300, 0x00, buffer, buffer.length, 500); Open relay '1' (host->device direction). byte[] buffer = {(byte) 0xff, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}; int r = mUsbConnection.controlTransfer(0x21, 0x09, 0x0300, 0x00, buffer, buffer.length, 500); Note, the second parameter in the buffer (0x01) is the relay number (in case you have >1 relay on the board). I only had one. close relay '1' (host->device direction): byte[] buffer = {(byte) 0xfd, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}; int r = mUsbConnection.controlTransfer(0x21, 0x09, 0x0300, 0x00, buffer, buffer.length, 500);
I have found the project in Github which is similar with this it (for who is looking it) https://github.com/gigacycle/AndroidHidUsbRelayControl I have tested this code and I can confirm that it works well with the USB relay board.
What is / how do I find the universal ibeacon identifier?
I am trying to write an android application to interface with iBeacons, but I need to find the start of the UUID / major / minor characteristics in the byte array. Through look at a couple of resources including this question, it seems like ALL iBeacons transmit some pattern in the byte array that is the same that identifies them as iBeacons. I asked another question recently and got a useful answer, link here but 1) I haven't been able to test it's functionality (waiting on my device) and 2) I want to know how it is working. So my questions: What is that pattern? Can I find it just by searching that array for the pattern? And is the UUID / Major / Minor always a predefined number of spots in the array from that identifying pattern? Thanks!
So after looking around on a few different sites, I have found that 3 people list their patterns as 02 01 06 1A FF 4C 00 02 15 or 02 01 1A 1A FF 4C 00 02 15 which isn't super helpful, since the 4C 00 appears to just be the Apple identifier, which I'm assuming could switch based on the manufacturer (Estimote, GE, Apple, whatever). However, it appears that the 02 15 is static, so I'm using that. My solution for finding it basically is just searching the byte array that I get for the first occurrence of that sequence of 2 bytes, and starting right after that I grab the next 16 as the UUID, the next 2 after that as the Major, and the next 2 after that as the Minor. So to clarify with code: //adPacket is an array I created to represent an iBeacon ad for testing byte[] adPacket = {(byte) 0xd6, (byte) 0xbe, (byte) 0x89, (byte) 0x8e, 0x40, 0x24, 0x05, (byte) 0xa2, 0x17, 0x6e, 0x3d, 0x71, 0x02, 0x01, 0x06, 0x1A, (byte) 0xFF, 0x4C, 0x00, 0x02, 0x15, (byte) 0xe2, (byte) 0xc5, 0x6d, (byte) 0xb5, (byte) 0xdf, (byte) 0xfb, 0x48, (byte) 0xd2, (byte) 0xb0, 0x60, (byte) 0xd0, (byte) 0xf5, (byte) 0xa7, 0x10, (byte) 0x96, (byte) 0xe0, 0x00, 0x00, 0x00, 0x00, (byte) 0xc5, 0x52, (byte) 0xab, (byte) 0x8d, 0x38, (byte) 0xa5}; byte[] pattern = {0x02, 0x15}; int startIndex = findAdPacketEnd(adPacket, pattern) + 1; if(startIndex == 0){ System.out.println("Pattern not found"); return;} int endIndex = startIndex + 21; ArrayList<Byte> tempArray = new ArrayList<Byte>(); for(int i = startIndex; i<endIndex; i++){ tempArray.add(adPacket[i]); } byte[] proxUUID = new byte[16]; for(int i = 0; i<16; i++){ proxUUID[i] = tempArray.get(i); } byte[] major = new byte[2]; major[0] = tempArray.get(16); major[1] = tempArray.get(17); byte[] minor = new byte[2]; minor[0] = tempArray.get(18); minor[1] = tempArray.get(19); ... where my findAdPacketEnd function is (not the most efficient but it works): private static int findAdPacketEnd(byte[] adPacket, byte[] pattern){ //return -1 if pattern is too long if(adPacket.length < pattern.length) return -1; //iterate over adPacket for(int i = 0; i<adPacket.length - pattern.length; i++){ System.out.println("Searching Ad Packet"); //iterate over pattern for(int j = 0; j<pattern.length; j++){ //compare wherever you are in the adpacket to the pattern, break if it doesn't match if(adPacket[i+j] != pattern[j]) break; // if you get to the end of the pattern and there wasn't a mismatch, return the index if(j == pattern.length-1) return i+pattern.length-1; } } //pattern not found return -1; }
How to do authentication for MIFARE Ultralight C on Android
I used an android APP (NFC tag info by NXP) to read my MIFARE Ultraglith C tag and it shows the tag has NXP default key "BREAKMEIFYOUCAN!" on page 0x2C to 0x2F. But I was still failing to authenticate this tag use this key. // NXP default key: BREAKMEIFYOUCAN! (16 bytes) byte[] mifareULCDefaultKey = { (byte) 0x49, (byte) 0x45, (byte) 0x4D, (byte) 0x4B, (byte) 0x41, (byte) 0x45, (byte) 0x52, (byte) 0x42, (byte) 0x21, (byte) 0x4E, (byte) 0x41, (byte) 0x43, (byte) 0x55, (byte) 0x4F, (byte) 0x59, (byte) 0x46 }; In details, I got following result: 1st authentication command: 1A00 response of 1st authentication command: AFCCF489BFB7B98605 ek(RndB): CCF489BFB7B98605 IV 1: 0000000000000000 RndB: 6183511C5B7EF046 RndA: 6E262630E299F94F RndB': 83511C5B7EF04661 RndA || RndB': 6E262630E299F94F83511C5B7EF04661 IV 2: CCF489BFB7B98605 ek(RndA || RndB'): AB7AF6C6E76675F52B9FF40021A8E2D6 2nd authentication command: AFAB7AF6C6E76675F52B9FF40021A8E2D6 But I still got "Transceive failed" IOException after sending 2nd authentication command. I'm sure the tag is still connected before sending 2nd authentication command. I have cost 8+ hours on this issue, but still cannot move ahead. Anyone can help?
I had the same problem. The problem is that you are using the wrong Diversified Key for Authentication.
Wifi printer not printing the pages android
I have using the following code: Socket client = new Socket(etIp.getText().toString(), 515); String printText = "This is a print test from Wifi"; byte[] mybytearray = printText.getBytes(); OutputStream outputStream = client.getOutputStream(); outputStream.write(mybytearray, 0, mybytearray.length); //write file to the output stream byte by byte outputStream.flush(); outputStream.close(); client.close(); Socket connection opened, and no exception while complete process of write data in output stream. But printer not eject the page. Please help me what I have did wrong.
I think you need to send few more data for it to eject and let the printer know. For Epson L355 I am appending a byte array at the end of my string. byte[] EjectByteArray = {0X00, 0X0D, 0X0C, 0X1B, 0X40, 0X1B, 0X28, 0X52, 0X08, 0X00, 0X00, 0X52, 0X45, 0X4D, 0X4F, 0X54, 0X45, 0X31, 0X4C, 0X44, 0X00, 0X00, 0X1B, 0X00, 0X00, 0X00, 0X1B, 0X40, 0X1B, 0X28, 0X52, 0X08, 0X00, 0X00, 0X52, 0X45, 0X4D, 0X4F, 0X54, 0X45, 0X31, 0X4C, 0X44, 0X00, 0X00, 0X4A, 0X45, 0X01, 0X00, 0X00, 0X1B, 0X00, 0X00, 0X00}; You may need to run a Port sniffer and try to capture the last byte array being passed after a print is finished. It would give you a clue on how you should send an eject command. This is one works on me using port 9100 on Epson L355 outputStream.write(mybytearray, 0, mybytearray.length); outputStream.write(EjectByteArray, 0, EjectByteArray.length); outputStream.flush(); outputStream.close(); client.close();
Add \n end of the line.this is work for me String printText = "Finally its working \n";