mirror of
https://github.com/RfidResearchGroup/RFIDtools.git
synced 2026-05-12 11:19:59 -07:00
libnfc communication recovery.
This commit is contained in:
@@ -44,8 +44,6 @@ public class AppMain extends BaseActivity {
|
||||
initActions();
|
||||
|
||||
gotoFragment(appMainDevicesFragment);
|
||||
|
||||
startActivity(new Intent(this, PM3FlasherMainActivity.class));
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
|
||||
@@ -71,12 +71,6 @@ public final class LocalComBridgeAdapter implements Serializable {
|
||||
if (serverSocket != null) {
|
||||
Log.d(LOG_TAG, "服务套接字堵塞等待连接中!");
|
||||
socket = serverSocket.accept();
|
||||
if (isHasClient) {
|
||||
isHasClient = false;
|
||||
Log.e(LOG_TAG, "The server only once online supported.");
|
||||
Log.e(LOG_TAG, "please disconnect your previous con.");
|
||||
continue;
|
||||
}
|
||||
if (socket != null) {
|
||||
synchronized (LOCK) {
|
||||
isHasClient = true;
|
||||
|
||||
@@ -48,6 +48,10 @@ public abstract class AbsUsbBulkTransfer implements DriverInterface<String, UsbM
|
||||
private UsbEndpoint mEpIn = null;
|
||||
//USB写端点
|
||||
private UsbEndpoint mEpOut = null;
|
||||
// 流实现!
|
||||
private BulkOutputStream outputStream;
|
||||
private BulkInputStream inputStream;
|
||||
|
||||
|
||||
//私有构造方法,避免被直接调用
|
||||
protected AbsUsbBulkTransfer() {
|
||||
@@ -221,6 +225,8 @@ public abstract class AbsUsbBulkTransfer implements DriverInterface<String, UsbM
|
||||
return false;
|
||||
}
|
||||
//全部链接初始化成功,返回TRUE告诉调用者可以开始尝试通信
|
||||
inputStream = new BulkInputStream(mCon, mEpIn);
|
||||
outputStream = new BulkOutputStream(mCon, mEpOut);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -249,11 +255,11 @@ public abstract class AbsUsbBulkTransfer implements DriverInterface<String, UsbM
|
||||
|
||||
@Override
|
||||
public OutputStream getOutput() {
|
||||
return new BulkOutputStream(mCon, mEpOut);
|
||||
return outputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInput() {
|
||||
return new BulkInputStream(mCon, mEpIn);
|
||||
return inputStream;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ add_library(nfc SHARED
|
||||
conf.c tools.c
|
||||
log.c log-printf.c
|
||||
chips/pn53x.c
|
||||
buses/uart_posix.c
|
||||
buses/com_uart.c
|
||||
drivers/pn532_uart.c
|
||||
drivers/acr122_usb.c
|
||||
drivers/pn53x_usb.c
|
||||
|
||||
@@ -5,25 +5,15 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <jni.h>
|
||||
|
||||
// can't use, he always is null!
|
||||
typedef void *serial_port;
|
||||
bool c_open();
|
||||
|
||||
jint initBuffer(JNIEnv *env, jclass type, jobject send_buffer, jobject recv_buffer);
|
||||
void c_close();
|
||||
|
||||
jint syncLength(JNIEnv *env, jclass type);
|
||||
int c_read(uint8_t *pbtRx, size_t szRx, int timeout);
|
||||
|
||||
jint syncTimeout(JNIEnv *env, jclass type);
|
||||
|
||||
int c_open();
|
||||
|
||||
int c_close();
|
||||
|
||||
int c_flush();
|
||||
|
||||
int c_read(uint8_t *pbtRx, const size_t szRx, int timeout);
|
||||
|
||||
int c_write(const uint8_t *pbtTx, const size_t szTx, int timeout);
|
||||
int c_write(const uint8_t *pbtTx, size_t szTx, int timeout);
|
||||
|
||||
#endif // __NFC_BUS_UART_H__
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#include <uart.h>
|
||||
#include <nfc/nfc.h>
|
||||
#include <tools.h>
|
||||
#include "com.h"
|
||||
|
||||
// Serial port that we are communicating with the PM3 on.
|
||||
static serial_port sp = INVALID_SERIAL_PORT;
|
||||
|
||||
bool c_open() {
|
||||
sp = uart_open("socket:DXL.COM.ASL", 115200);
|
||||
return sp != INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
void c_close() {
|
||||
if (sp != INVALID_SERIAL_PORT) {
|
||||
uart_close(sp);
|
||||
}
|
||||
}
|
||||
|
||||
int c_read(uint8_t *pbtRx, size_t szRx, int timeout) {
|
||||
if (sp != INVALID_SERIAL_PORT) {
|
||||
uart_reconfigure_timeouts(88);
|
||||
size_t recvLen = 0;
|
||||
size_t *pRecvLen = &recvLen;
|
||||
if (uart_receive(sp, pbtRx, szRx, pRecvLen) == NFC_SUCCESS) {
|
||||
return recvLen;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int c_write(const uint8_t *pbtTx, size_t szTx, int timeout) {
|
||||
if (sp != INVALID_SERIAL_PORT) {
|
||||
uart_reconfigure_timeouts((uint32_t) timeout);
|
||||
return uart_send(sp, pbtTx, szTx);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -64,7 +64,6 @@ Thanks to d18c7db and Okko for example code
|
||||
#include <string.h>
|
||||
|
||||
#include <nfc/nfc.h>
|
||||
#include <com.h>
|
||||
#include <pn53x.h>
|
||||
|
||||
#include "nfc-internal.h"
|
||||
@@ -400,6 +399,11 @@ static nfc_device *
|
||||
acr122_usb_open(const nfc_context *context, const nfc_connstring connstring) {
|
||||
nfc_device *pnd = NULL;
|
||||
|
||||
if (!c_open()) {
|
||||
// 串口打开失败!
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO 自实现区域
|
||||
* */
|
||||
@@ -455,17 +459,6 @@ acr122_usb_close(nfc_device *pnd) {
|
||||
acr122_usb_ack(pnd);
|
||||
pn53x_idle(pnd);
|
||||
c_close();
|
||||
//TODO 不需要底层关闭
|
||||
/*int res;
|
||||
if ((res = usb_release_interface(DRIVER_DATA(pnd)->pudh, 0)) < 0) {
|
||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR,
|
||||
"Unable to release USB interface (%s)", _usb_strerror(res));
|
||||
}
|
||||
|
||||
if ((res = usb_close(DRIVER_DATA(pnd)->pudh)) < 0) {
|
||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR,
|
||||
"Unable to close USB connection (%s)", _usb_strerror(res));
|
||||
}*/
|
||||
pn53x_data_free(pnd);
|
||||
nfc_device_free(pnd);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
|
||||
#include <nfc/nfc.h>
|
||||
#include <pn53x.h>
|
||||
#include <uart.h>
|
||||
|
||||
#include "nfc-internal.h"
|
||||
#include "com.h"
|
||||
@@ -77,8 +78,6 @@ pn532_uart_scan(const nfc_context *context, nfc_connstring connstrings[],
|
||||
size_t device_found = 0;
|
||||
//打开设备
|
||||
if (!c_open()) { return 0; }
|
||||
//刷新可能残留的字节
|
||||
c_flush();
|
||||
nfc_connstring connstring;
|
||||
snprintf(connstring, sizeof(nfc_connstring), "%s:%s:%"PRIu32, PN532_UART_DRIVER_NAME,
|
||||
"115200", PN532_UART_DEFAULT_SPEED);
|
||||
@@ -148,9 +147,12 @@ pn532_uart_close(nfc_device *pnd) {
|
||||
static nfc_device *
|
||||
pn532_uart_open(const nfc_context *context, const nfc_connstring connstring) {
|
||||
nfc_device *pnd = NULL;
|
||||
//不需要参数
|
||||
c_open();
|
||||
c_flush();
|
||||
|
||||
if (!c_open()) {
|
||||
// 串口打开失败!
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// We have a connection
|
||||
pnd = nfc_device_new(context, connstring);
|
||||
if (!pnd) {
|
||||
@@ -215,7 +217,6 @@ pn532_uart_wakeup(nfc_device *pnd) {
|
||||
static int
|
||||
pn532_uart_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout) {
|
||||
int res = 0;
|
||||
c_flush();
|
||||
switch (CHIP_DATA(pnd)->power_mode) {
|
||||
case LOWVBAT: {
|
||||
/** PN532C106 wakeup. */
|
||||
@@ -398,7 +399,6 @@ pn532_uart_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, in
|
||||
// The PN53x command is done and we successfully received the reply
|
||||
return len;
|
||||
error:
|
||||
c_flush();
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,18 +62,6 @@ Thanks to d18c7db and Okko for example code
|
||||
|
||||
#define DRIVER_DATA(pnd) ((struct pn53x_usb_data*)(pnd->driver_data))
|
||||
|
||||
// 暂时处理
|
||||
|
||||
int c_open(){}
|
||||
|
||||
int c_close(){}
|
||||
|
||||
int c_flush(){}
|
||||
|
||||
int c_read(uint8_t *pbtRx, const size_t szRx, int timeout){}
|
||||
|
||||
int c_write(const uint8_t *pbtTx, const size_t szTx, int timeout){}
|
||||
|
||||
const nfc_modulation_type no_target_support[] = {0};
|
||||
|
||||
typedef enum {
|
||||
@@ -243,6 +231,11 @@ static nfc_device *
|
||||
pn53x_usb_open(const nfc_context *context, const nfc_connstring connstring) {
|
||||
nfc_device *pnd = NULL;
|
||||
|
||||
if (!c_open()) {
|
||||
// 串口打开失败!
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Allocate memory for the device info and specification, fill it and return the info
|
||||
pnd = nfc_device_new(context, connstring);
|
||||
if (!pnd) {
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Generic uart / rs232/ serial port library
|
||||
*
|
||||
* Copyright (c) 2013, Roel Verdult
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holders nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @file uart.h
|
||||
*/
|
||||
|
||||
#ifndef _UART_H_
|
||||
#define _UART_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <endian.h>
|
||||
|
||||
/* serial_port is declared as a void*, which you should cast to whatever type
|
||||
* makes sense to your connection method. Both the posix and win32
|
||||
* implementations define their own structs in place.
|
||||
*/
|
||||
typedef void *serial_port;
|
||||
|
||||
/* Returned by uart_open if the serial port specified was invalid.
|
||||
*/
|
||||
#define INVALID_SERIAL_PORT (void*)(~1)
|
||||
|
||||
/* Returned by uart_open if the serial port specified is in use by another
|
||||
* process.
|
||||
*/
|
||||
#define CLAIMED_SERIAL_PORT (void*)(~2)
|
||||
|
||||
/* Given a user-specified port name, connect to the port and return a structure
|
||||
* used for future references to that port.
|
||||
*
|
||||
* On errors, this method returns INVALID_SERIAL_PORT or CLAIMED_SERIAL_PORT.
|
||||
*/
|
||||
serial_port uart_open(const char *pcPortName, uint32_t speed);
|
||||
|
||||
/* Closes the given port.
|
||||
*/
|
||||
void uart_close(const serial_port sp);
|
||||
|
||||
/* Reads from the given serial port for up to 30ms.
|
||||
* pbtRx: A pointer to a buffer for the returned data to be written to.
|
||||
* pszMaxRxLen: The maximum data size we want to be sent.
|
||||
* pszRxLen: The number of bytes that we were actually sent.
|
||||
*
|
||||
* Returns TRUE if any data was fetched, even if it was less than pszMaxRxLen.
|
||||
*
|
||||
* Returns FALSE if there was an error reading from the devices. Note that a
|
||||
* partial read may have completed into the buffer by the corresponding
|
||||
* implementation, so pszRxLen should be checked to see if any data was written.
|
||||
*/
|
||||
int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uint32_t *pszRxLen);
|
||||
|
||||
/* Sends a buffer to a given serial port.
|
||||
* pbtTx: A pointer to a buffer containing the data to write.
|
||||
* len: The amount of data to be sent.
|
||||
*/
|
||||
int uart_send(const serial_port sp, const uint8_t *pbtTx, const uint32_t len);
|
||||
|
||||
/* Sets the current speed of the serial port, in baud.
|
||||
*/
|
||||
bool uart_set_speed(serial_port sp, const uint32_t uiPortSpeed);
|
||||
|
||||
/* Gets the current speed of the serial port, in baud.
|
||||
*/
|
||||
uint32_t uart_get_speed(const serial_port sp);
|
||||
|
||||
/* Reconfigure timeouts
|
||||
*/
|
||||
int uart_reconfigure_timeouts(uint32_t value);
|
||||
#endif // _UART_H_
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#ifndef __NFC_BUS_UART_H__
|
||||
# define __NFC_BUS_UART_H__
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <jni.h>
|
||||
|
||||
// can't use, he always is null!
|
||||
typedef void *serial_port;
|
||||
|
||||
jint initBuffer(JNIEnv *env, jclass type, jobject send_buffer, jobject recv_buffer);
|
||||
|
||||
jint syncLength(JNIEnv *env, jclass type);
|
||||
|
||||
jint syncTimeout(JNIEnv *env, jclass type);
|
||||
|
||||
int c_open();
|
||||
|
||||
int c_close();
|
||||
|
||||
int c_flush();
|
||||
|
||||
int c_read(uint8_t *pbtRx, const size_t szRx, int timeout);
|
||||
|
||||
int c_write(const uint8_t *pbtTx, const size_t szTx, int timeout);
|
||||
|
||||
#endif // __NFC_BUS_UART_H__
|
||||
Submodule pm3rdv4rrg/src/main/cpp/proxmark3 updated: d348844873...d55a147ca9
Reference in New Issue
Block a user