mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-07-08 06:00:53 -07:00
Removing windows specific code. Everything now compile and work the same for the three OS
This commit is contained in:
parent
f7e3ed8287
commit
4cd41f34ea
16 changed files with 70 additions and 2795 deletions
39
client/COMPILING
Normal file
39
client/COMPILING
Normal file
|
@ -0,0 +1,39 @@
|
|||
The client compiles on Linux, Mac OS X and Windows (MinGW/MSYS).
|
||||
|
||||
it requires:
|
||||
- gcc
|
||||
- libpthread
|
||||
- libreadline
|
||||
- libusb
|
||||
|
||||
and optionally libQT
|
||||
|
||||
|
||||
To compile, just run "make".
|
||||
|
||||
|
||||
==========
|
||||
= MingGW =
|
||||
==========
|
||||
It is known to work using:
|
||||
- MingW 5.1.6
|
||||
- MSYS 1.0.11
|
||||
- libpthread 2.8.0 (from MinGW or directly from pthread-win32)
|
||||
- readline 5.0 from gnuwin32
|
||||
- libusb-win32-device-bin-0.1.12.2
|
||||
Be careful here, it is *NOT* working with the filter version!
|
||||
You have to use the device version and use the inf-wizard
|
||||
to create a driver for your proxmark and install it.
|
||||
|
||||
|
||||
============
|
||||
= Mac OS X =
|
||||
============
|
||||
|
||||
macport stuff should do ;)
|
||||
|
||||
============
|
||||
= Linux =
|
||||
============
|
||||
|
||||
|
|
@ -7,7 +7,6 @@ LDLIBS = -L/opt/local/lib -L/usr/local/lib -lusb -lreadline -lpthread
|
|||
LDFLAGS = $(COMMON_FLAGS)
|
||||
CFLAGS = -std=gnu99 -I. -I../include -I../common -I/opt/local/include -Wall -Wno-unused-function $(COMMON_FLAGS) -g3
|
||||
|
||||
WINLIBS = -lgdi32 -lsetupapi
|
||||
CXXFLAGS = $(shell pkg-config --cflags QtCore QtGui 2>/dev/null) -Wall
|
||||
QTLDLIBS = $(shell pkg-config --libs QtCore QtGui 2>/dev/null)
|
||||
|
||||
|
@ -33,8 +32,6 @@ CMDSRCS = \
|
|||
|
||||
CMDOBJS = $(CMDSRCS:.c=.o)
|
||||
|
||||
ifeq ($(shell echo ""),)
|
||||
|
||||
ifeq ($(shell uname),Darwin)
|
||||
CXXFLAGS = -I/Library/Frameworks/QtGui.framework/Versions/Current/Headers -I/Library/Frameworks/QtCore.framework/Versions/Current/Headers
|
||||
QTLDLIBS = -framework QtGui -framework QtCore
|
||||
|
@ -52,20 +49,12 @@ endif
|
|||
|
||||
RM = rm -f
|
||||
BINS = proxmark3 snooper cli flasher
|
||||
CLEAN = cli flasher proxmark3 snooper *.o $(CMDOBJS) *.moc.cpp
|
||||
else
|
||||
RM = del
|
||||
BINS = prox.exe
|
||||
CLEAN = prox.exe
|
||||
endif
|
||||
CLEAN = cli cli.exe flasher flasher.exe proxmark3 proxmark3.exe snooper snooper.exe *.o $(CMDOBJS) *.moc.cpp
|
||||
|
||||
all: $(BINS)
|
||||
|
||||
all-static: LDLIBS:=-static $(LDLIBS)
|
||||
all-static: snooper cli flasher
|
||||
|
||||
prox.exe: prox.o wingui.o $(CMDOBJS) flash.o
|
||||
$(CC) $(CFLAGS) $(DEFINES) -o prox.exe prox.o wingui.o $(CMDOBJS) flash.c $(WINLIBS)
|
||||
|
||||
proxmark3: LDLIBS+=$(QTLDLIBS)
|
||||
proxmark3: proxmark3.o $(CMDOBJS) proxusb.o $(QTGUI)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <stdio.h>
|
||||
#include "sleep.h"
|
||||
#include "ui.h"
|
||||
#include "proxusb.h"
|
||||
#include "cmdmain.h"
|
||||
|
|
|
@ -46,16 +46,6 @@ int CmdQuit(const char *Cmd)
|
|||
void WaitForResponse(uint32_t response_type)
|
||||
{
|
||||
while (received_command != response_type) {
|
||||
#ifdef WIN32
|
||||
// FIXME: Do we really need this under windows or is it
|
||||
// just some historical code?
|
||||
// pthread seems to be availabe for win32 nowadays
|
||||
// so we should be able to port the code and get rid
|
||||
// of this part.
|
||||
UsbCommand c;
|
||||
if (ReceiveCommandPoll(&c))
|
||||
UsbCommandReceived(&c);
|
||||
#endif
|
||||
msleep(10); // XXX ugh
|
||||
}
|
||||
received_command = CMD_UNKNOWN;
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#include <setupapi.h>
|
||||
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
|
||||
BOOL UsbConnect(void);
|
||||
#endif
|
||||
#include <proxusb.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "sleep.h"
|
||||
#include "proxusb.h"
|
||||
#include "flash.h"
|
||||
#include "elf.h"
|
||||
|
||||
|
@ -194,7 +188,7 @@ unsigned int EnterFlashState(void)
|
|||
if (state & DEVICE_INFO_FLAG_CURRENT_MODE_OS) {
|
||||
fprintf(stderr,"Entering flash-mode...\n");
|
||||
UsbCommand c;
|
||||
bzero(&c, sizeof(c));
|
||||
memset(&c, 0, sizeof (c));
|
||||
|
||||
if ((state & DEVICE_INFO_FLAG_BOOTROM_PRESENT) && (state & DEVICE_INFO_FLAG_OSIMAGE_PRESENT)) {
|
||||
/* New style handover: Send CMD_START_FLASH, which will reset the board and
|
||||
|
@ -212,15 +206,10 @@ unsigned int EnterFlashState(void)
|
|||
fprintf(stderr,"Waiting for Proxmark to reappear on USB... ");
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
Sleep(1000);
|
||||
while (!UsbConnect()) { Sleep(1000); }
|
||||
#else
|
||||
CloseProxmark();
|
||||
sleep(1);
|
||||
|
||||
while (!OpenProxmark(0)) { sleep(1); }
|
||||
#endif
|
||||
fprintf(stderr,"Found.\n");
|
||||
|
||||
return GetProxmarkState();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "sleep.h"
|
||||
#include "proxusb.h"
|
||||
#include "flash.h"
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,412 +0,0 @@
|
|||
/*++
|
||||
|
||||
Copyright (c) 1996 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
HIDSDI.H
|
||||
|
||||
Abstract:
|
||||
|
||||
This module contains the PUBLIC definitions for the
|
||||
code that implements the HID dll.
|
||||
|
||||
Environment:
|
||||
|
||||
Kernel & user mode
|
||||
|
||||
--*/
|
||||
|
||||
|
||||
#ifndef _HIDSDI_H
|
||||
#define _HIDSDI_H
|
||||
|
||||
#include <pshpack4.h>
|
||||
|
||||
//#include "wtypes.h"
|
||||
|
||||
//#include <windef.h>
|
||||
//#include <win32.h>
|
||||
//#include <basetyps.h>
|
||||
|
||||
//typedef LONG NTSTATUS;
|
||||
#include "hidusage.h"
|
||||
#include "hidpi.h"
|
||||
|
||||
typedef struct _HIDD_CONFIGURATION {
|
||||
PVOID cookie;
|
||||
ULONG size;
|
||||
ULONG RingBufferSize;
|
||||
} HIDD_CONFIGURATION, *PHIDD_CONFIGURATION;
|
||||
|
||||
typedef struct _HIDD_ATTRIBUTES {
|
||||
ULONG Size; // = sizeof (struct _HIDD_ATTRIBUTES)
|
||||
|
||||
//
|
||||
// Vendor ids of this hid device
|
||||
//
|
||||
USHORT VendorID;
|
||||
USHORT ProductID;
|
||||
USHORT VersionNumber;
|
||||
|
||||
//
|
||||
// Additional fields will be added to the end of this structure.
|
||||
//
|
||||
} HIDD_ATTRIBUTES, *PHIDD_ATTRIBUTES;
|
||||
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetAttributes (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PHIDD_ATTRIBUTES Attributes
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
Fill in the given HIDD_ATTRIBUTES structure with the attributes of the
|
||||
given hid device.
|
||||
|
||||
--*/
|
||||
|
||||
|
||||
void __stdcall
|
||||
HidD_GetHidGuid (
|
||||
OUT LPGUID HidGuid
|
||||
);
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetPreparsedData (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PHIDP_PREPARSED_DATA * PreparsedData
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
Given a handle to a valid Hid Class Device Object, retrieve the preparsed
|
||||
data for the device. This routine will allocate the appropriately
|
||||
sized buffer to hold this preparsed data. It is up to client to call
|
||||
HidP_FreePreparsedData to free the memory allocated to this structure when
|
||||
it is no longer needed.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device that the client obtains using
|
||||
a call to CreateFile on a valid Hid device string name.
|
||||
The string name can be obtained using standard PnP calls.
|
||||
|
||||
PreparsedData An opaque data structure used by other functions in this
|
||||
library to retrieve information about a given device.
|
||||
|
||||
Return Value:
|
||||
TRUE if successful.
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_FreePreparsedData (
|
||||
IN PHIDP_PREPARSED_DATA PreparsedData
|
||||
);
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_FlushQueue (
|
||||
IN HANDLE HidDeviceObject
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
Flush the input queue for the given HID device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device that the client obtains using
|
||||
a call to CreateFile on a valid Hid device string name.
|
||||
The string name can be obtained using standard PnP calls.
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetConfiguration (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PHIDD_CONFIGURATION Configuration,
|
||||
IN ULONG ConfigurationLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
Get the configuration information for this Hid device
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
Configuration A configuration structure. HidD_GetConfiguration MUST
|
||||
be called before the configuration can be modified and
|
||||
set using HidD_SetConfiguration
|
||||
|
||||
ConfigurationLength That is ``sizeof (HIDD_CONFIGURATION)''. Using this
|
||||
parameter, we can later increase the length of the
|
||||
configuration array and not break older apps.
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_SetConfiguration (
|
||||
IN HANDLE HidDeviceObject,
|
||||
IN PHIDD_CONFIGURATION Configuration,
|
||||
IN ULONG ConfigurationLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
Set the configuration information for this Hid device...
|
||||
|
||||
NOTE: HidD_GetConfiguration must be called to retrieve the current
|
||||
configuration information before this information can be modified
|
||||
and set.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
Configuration A configuration structure. HidD_GetConfiguration MUST
|
||||
be called before the configuration can be modified and
|
||||
set using HidD_SetConfiguration
|
||||
|
||||
ConfigurationLength That is ``sizeof (HIDD_CONFIGURATION)''. Using this
|
||||
parameter, we can later increase the length of the
|
||||
configuration array and not break older apps.
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetFeature (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PVOID ReportBuffer,
|
||||
IN ULONG ReportBufferLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
Retrieve a feature report from a HID device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
ReportBuffer The buffer that the feature report should be placed
|
||||
into. The first byte of the buffer should be set to
|
||||
the report ID of the desired report
|
||||
|
||||
ReportBufferLength The size (in bytes) of ReportBuffer. This value
|
||||
should be greater than or equal to the
|
||||
FeatureReportByteLength field as specified in the
|
||||
HIDP_CAPS structure for the device
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_SetFeature (
|
||||
IN HANDLE HidDeviceObject,
|
||||
IN PVOID ReportBuffer,
|
||||
IN ULONG ReportBufferLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
Send a feature report to a HID device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
ReportBuffer The buffer of the feature report to send to the device
|
||||
|
||||
ReportBufferLength The size (in bytes) of ReportBuffer. This value
|
||||
should be greater than or equal to the
|
||||
FeatureReportByteLength field as specified in the
|
||||
HIDP_CAPS structure for the device
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetNumInputBuffers (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PULONG NumberBuffers
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
This function returns the number of input buffers used by the specified
|
||||
file handle to the Hid device. Each file object has a number of buffers
|
||||
associated with it to queue reports read from the device but which have
|
||||
not yet been read by the user-mode app with a handle to that device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
NumberBuffers Number of buffers currently being used for this file
|
||||
handle to the Hid device
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_SetNumInputBuffers (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT ULONG NumberBuffers
|
||||
);
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
This function sets the number of input buffers used by the specified
|
||||
file handle to the Hid device. Each file object has a number of buffers
|
||||
associated with it to queue reports read from the device but which have
|
||||
not yet been read by the user-mode app with a handle to that device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
NumberBuffers New number of buffers to use for this file handle to
|
||||
the Hid device
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetPhysicalDescriptor (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PVOID Buffer,
|
||||
IN ULONG BufferLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
This function retrieves the raw physical descriptor for the specified
|
||||
Hid device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
Buffer Buffer which on return will contain the physical
|
||||
descriptor if one exists for the specified device
|
||||
handle
|
||||
|
||||
BufferLength Length of buffer (in bytes)
|
||||
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetManufacturerString (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PVOID Buffer,
|
||||
IN ULONG BufferLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
This function retrieves the manufacturer string from the specified
|
||||
Hid device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
Buffer Buffer which on return will contain the manufacturer
|
||||
string returned from the device. This string is a
|
||||
wide-character string
|
||||
|
||||
BufferLength Length of Buffer (in bytes)
|
||||
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetProductString (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PVOID Buffer,
|
||||
IN ULONG BufferLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
This function retrieves the product string from the specified
|
||||
Hid device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
Buffer Buffer which on return will contain the product
|
||||
string returned from the device. This string is a
|
||||
wide-character string
|
||||
|
||||
BufferLength Length of Buffer (in bytes)
|
||||
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetIndexedString (
|
||||
IN HANDLE HidDeviceObject,
|
||||
IN ULONG StringIndex,
|
||||
OUT PVOID Buffer,
|
||||
IN ULONG BufferLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
This function retrieves a string from the specified Hid device that is
|
||||
specified with a certain string index.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
StringIndex Index of the string to retrieve
|
||||
|
||||
Buffer Buffer which on return will contain the product
|
||||
string returned from the device. This string is a
|
||||
wide-character string
|
||||
|
||||
BufferLength Length of Buffer (in bytes)
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetSerialNumberString (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PVOID Buffer,
|
||||
IN ULONG BufferLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
This function retrieves the serial number string from the specified
|
||||
Hid device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
Buffer Buffer which on return will contain the serial number
|
||||
string returned from the device. This string is a
|
||||
wide-character string
|
||||
|
||||
BufferLength Length of Buffer (in bytes)
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
|
||||
#include <poppack.h>
|
||||
|
||||
#endif
|
|
@ -1,263 +0,0 @@
|
|||
/*++
|
||||
|
||||
Copyright (c) 1996, 1997 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
HIDUSAGE.H
|
||||
|
||||
Abstract:
|
||||
|
||||
Public Definitions of HID USAGES.
|
||||
|
||||
Environment:
|
||||
|
||||
Kernel & user mode
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef __HIDUSAGE_H__
|
||||
#define __HIDUSAGE_H__
|
||||
|
||||
//
|
||||
// Usage Pages
|
||||
//
|
||||
|
||||
typedef USHORT USAGE, *PUSAGE;
|
||||
|
||||
#define HID_USAGE_PAGE_GENERIC ((USAGE) 0x01)
|
||||
#define HID_USAGE_PAGE_SIMULATION ((USAGE) 0x02)
|
||||
#define HID_USAGE_PAGE_VR ((USAGE) 0x03)
|
||||
#define HID_USAGE_PAGE_SPORT ((USAGE) 0x04)
|
||||
#define HID_USAGE_PAGE_GAME ((USAGE) 0x05)
|
||||
#define HID_USAGE_PAGE_KEYBOARD ((USAGE) 0x07)
|
||||
#define HID_USAGE_PAGE_LED ((USAGE) 0x08)
|
||||
#define HID_USAGE_PAGE_BUTTON ((USAGE) 0x09)
|
||||
#define HID_USAGE_PAGE_ORDINAL ((USAGE) 0x0A)
|
||||
#define HID_USAGE_PAGE_TELEPHONY ((USAGE) 0x0B)
|
||||
#define HID_USAGE_PAGE_CONSUMER ((USAGE) 0x0C)
|
||||
#define HID_USAGE_PAGE_DIGITIZER ((USAGE) 0x0D)
|
||||
#define HID_USAGE_PAGE_UNICODE ((USAGE) 0x10)
|
||||
#define HID_USAGE_PAGE_ALPHANUMERIC ((USAGE) 0x14)
|
||||
|
||||
|
||||
//
|
||||
// Usages from Generic Desktop Page (0x01)
|
||||
//
|
||||
|
||||
#define HID_USAGE_GENERIC_POINTER ((USAGE) 0x01)
|
||||
#define HID_USAGE_GENERIC_MOUSE ((USAGE) 0x02)
|
||||
#define HID_USAGE_GENERIC_JOYSTICK ((USAGE) 0x04)
|
||||
#define HID_USAGE_GENERIC_GAMEPAD ((USAGE) 0x05)
|
||||
#define HID_USAGE_GENERIC_KEYBOARD ((USAGE) 0x06)
|
||||
#define HID_USAGE_GENERIC_KEYPAD ((USAGE) 0x07)
|
||||
#define HID_USAGE_GENERIC_SYSTEM_CTL ((USAGE) 0x80)
|
||||
|
||||
#define HID_USAGE_GENERIC_X ((USAGE) 0x30)
|
||||
#define HID_USAGE_GENERIC_Y ((USAGE) 0x31)
|
||||
#define HID_USAGE_GENERIC_Z ((USAGE) 0x32)
|
||||
#define HID_USAGE_GENERIC_RX ((USAGE) 0x33)
|
||||
#define HID_USAGE_GENERIC_RY ((USAGE) 0x34)
|
||||
#define HID_USAGE_GENERIC_RZ ((USAGE) 0x35)
|
||||
#define HID_USAGE_GENERIC_SLIDER ((USAGE) 0x36)
|
||||
#define HID_USAGE_GENERIC_DIAL ((USAGE) 0x37)
|
||||
#define HID_USAGE_GENERIC_WHEEL ((USAGE) 0x38)
|
||||
#define HID_USAGE_GENERIC_HATSWITCH ((USAGE) 0x39)
|
||||
#define HID_USAGE_GENERIC_COUNTED_BUFFER ((USAGE) 0x3A)
|
||||
#define HID_USAGE_GENERIC_BYTE_COUNT ((USAGE) 0x3B)
|
||||
#define HID_USAGE_GENERIC_MOTION_WAKEUP ((USAGE) 0x3C)
|
||||
#define HID_USAGE_GENERIC_VX ((USAGE) 0x40)
|
||||
#define HID_USAGE_GENERIC_VY ((USAGE) 0x41)
|
||||
#define HID_USAGE_GENERIC_VZ ((USAGE) 0x42)
|
||||
#define HID_USAGE_GENERIC_VBRX ((USAGE) 0x43)
|
||||
#define HID_USAGE_GENERIC_VBRY ((USAGE) 0x44)
|
||||
#define HID_USAGE_GENERIC_VBRZ ((USAGE) 0x45)
|
||||
#define HID_USAGE_GENERIC_VNO ((USAGE) 0x46)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_POWER ((USAGE) 0x81)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_SLEEP ((USAGE) 0x82)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_WAKE ((USAGE) 0x83)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_CONTEXT_MENU ((USAGE) 0x84)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MAIN_MENU ((USAGE) 0x85)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_APP_MENU ((USAGE) 0x86)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_HELP_MENU ((USAGE) 0x87)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MENU_EXIT ((USAGE) 0x88)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MENU_SELECT ((USAGE) 0x89)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MENU_RIGHT ((USAGE) 0x8A)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MENU_LEFT ((USAGE) 0x8B)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MENU_UP ((USAGE) 0x8C)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MENU_DOWN ((USAGE) 0x8D)
|
||||
|
||||
//
|
||||
// Usages from Simulation Controls Page (0x02)
|
||||
//
|
||||
|
||||
#define HID_USAGE_SIMULATION_RUDDER ((USAGE) 0xBA)
|
||||
#define HID_USAGE_SIMULATION_THROTTLE ((USAGE) 0xBB)
|
||||
|
||||
//
|
||||
// Virtual Reality Controls Page (0x03)
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// Sport Controls Page (0x04)
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// Game Controls Page (0x05)
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// Keyboard/Keypad Page (0x07)
|
||||
//
|
||||
|
||||
// Error "keys"
|
||||
#define HID_USAGE_KEYBOARD_NOEVENT ((USAGE) 0x00)
|
||||
#define HID_USAGE_KEYBOARD_ROLLOVER ((USAGE) 0x01)
|
||||
#define HID_USAGE_KEYBOARD_POSTFAIL ((USAGE) 0x02)
|
||||
#define HID_USAGE_KEYBOARD_UNDEFINED ((USAGE) 0x03)
|
||||
|
||||
// Letters
|
||||
#define HID_USAGE_KEYBOARD_aA ((USAGE) 0x04)
|
||||
#define HID_USAGE_KEYBOARD_zZ ((USAGE) 0x1D)
|
||||
// Numbers
|
||||
#define HID_USAGE_KEYBOARD_ONE ((USAGE) 0x1E)
|
||||
#define HID_USAGE_KEYBOARD_ZERO ((USAGE) 0x27)
|
||||
// Modifier Keys
|
||||
#define HID_USAGE_KEYBOARD_LCTRL ((USAGE) 0xE0)
|
||||
#define HID_USAGE_KEYBOARD_LSHFT ((USAGE) 0xE1)
|
||||
#define HID_USAGE_KEYBOARD_LALT ((USAGE) 0xE2)
|
||||
#define HID_USAGE_KEYBOARD_LGUI ((USAGE) 0xE3)
|
||||
#define HID_USAGE_KEYBOARD_RCTRL ((USAGE) 0xE4)
|
||||
#define HID_USAGE_KEYBOARD_RSHFT ((USAGE) 0xE5)
|
||||
#define HID_USAGE_KEYBOARD_RALT ((USAGE) 0xE6)
|
||||
#define HID_USAGE_KEYBOARD_RGUI ((USAGE) 0xE7)
|
||||
#define HID_USAGE_KEYBOARD_SCROLL_LOCK ((USAGE) 0x47)
|
||||
#define HID_USAGE_KEYBOARD_NUM_LOCK ((USAGE) 0x53)
|
||||
#define HID_USAGE_KEYBOARD_CAPS_LOCK ((USAGE) 0x39)
|
||||
// Funtion keys
|
||||
#define HID_USAGE_KEYBOARD_F1 ((USAGE) 0x3A)
|
||||
#define HID_USAGE_KEYBOARD_F12 ((USAGE) 0x45)
|
||||
|
||||
#define HID_USAGE_KEYBOARD_RETURN ((USAGE) 0x28)
|
||||
#define HID_USAGE_KEYBOARD_ESCAPE ((USAGE) 0x29)
|
||||
#define HID_USAGE_KEYBOARD_DELETE ((USAGE) 0x2A)
|
||||
|
||||
#define HID_USAGE_KEYBOARD_PRINT_SCREEN ((USAGE) 0x46)
|
||||
|
||||
// and hundreds more...
|
||||
|
||||
//
|
||||
// LED Page (0x08)
|
||||
//
|
||||
|
||||
#define HID_USAGE_LED_NUM_LOCK ((USAGE) 0x01)
|
||||
#define HID_USAGE_LED_CAPS_LOCK ((USAGE) 0x02)
|
||||
#define HID_USAGE_LED_SCROLL_LOCK ((USAGE) 0x03)
|
||||
#define HID_USAGE_LED_COMPOSE ((USAGE) 0x04)
|
||||
#define HID_USAGE_LED_KANA ((USAGE) 0x05)
|
||||
#define HID_USAGE_LED_POWER ((USAGE) 0x06)
|
||||
#define HID_USAGE_LED_SHIFT ((USAGE) 0x07)
|
||||
#define HID_USAGE_LED_DO_NOT_DISTURB ((USAGE) 0x08)
|
||||
#define HID_USAGE_LED_MUTE ((USAGE) 0x09)
|
||||
#define HID_USAGE_LED_TONE_ENABLE ((USAGE) 0x0A)
|
||||
#define HID_USAGE_LED_HIGH_CUT_FILTER ((USAGE) 0x0B)
|
||||
#define HID_USAGE_LED_LOW_CUT_FILTER ((USAGE) 0x0C)
|
||||
#define HID_USAGE_LED_EQUALIZER_ENABLE ((USAGE) 0x0D)
|
||||
#define HID_USAGE_LED_SOUND_FIELD_ON ((USAGE) 0x0E)
|
||||
#define HID_USAGE_LED_SURROUND_FIELD_ON ((USAGE) 0x0F)
|
||||
#define HID_USAGE_LED_REPEAT ((USAGE) 0x10)
|
||||
#define HID_USAGE_LED_STEREO ((USAGE) 0x11)
|
||||
#define HID_USAGE_LED_SAMPLING_RATE_DETECT ((USAGE) 0x12)
|
||||
#define HID_USAGE_LED_SPINNING ((USAGE) 0x13)
|
||||
#define HID_USAGE_LED_CAV ((USAGE) 0x14)
|
||||
#define HID_USAGE_LED_CLV ((USAGE) 0x15)
|
||||
#define HID_USAGE_LED_RECORDING_FORMAT_DET ((USAGE) 0x16)
|
||||
#define HID_USAGE_LED_OFF_HOOK ((USAGE) 0x17)
|
||||
#define HID_USAGE_LED_RING ((USAGE) 0x18)
|
||||
#define HID_USAGE_LED_MESSAGE_WAITING ((USAGE) 0x19)
|
||||
#define HID_USAGE_LED_DATA_MODE ((USAGE) 0x1A)
|
||||
#define HID_USAGE_LED_BATTERY_OPERATION ((USAGE) 0x1B)
|
||||
#define HID_USAGE_LED_BATTERY_OK ((USAGE) 0x1C)
|
||||
#define HID_USAGE_LED_BATTERY_LOW ((USAGE) 0x1D)
|
||||
#define HID_USAGE_LED_SPEAKER ((USAGE) 0x1E)
|
||||
#define HID_USAGE_LED_HEAD_SET ((USAGE) 0x1F)
|
||||
#define HID_USAGE_LED_HOLD ((USAGE) 0x20)
|
||||
#define HID_USAGE_LED_MICROPHONE ((USAGE) 0x21)
|
||||
#define HID_USAGE_LED_COVERAGE ((USAGE) 0x22)
|
||||
#define HID_USAGE_LED_NIGHT_MODE ((USAGE) 0x23)
|
||||
#define HID_USAGE_LED_SEND_CALLS ((USAGE) 0x24)
|
||||
#define HID_USAGE_LED_CALL_PICKUP ((USAGE) 0x25)
|
||||
#define HID_USAGE_LED_CONFERENCE ((USAGE) 0x26)
|
||||
#define HID_USAGE_LED_STAND_BY ((USAGE) 0x27)
|
||||
#define HID_USAGE_LED_CAMERA_ON ((USAGE) 0x28)
|
||||
#define HID_USAGE_LED_CAMERA_OFF ((USAGE) 0x29)
|
||||
#define HID_USAGE_LED_ON_LINE ((USAGE) 0x2A)
|
||||
#define HID_USAGE_LED_OFF_LINE ((USAGE) 0x2B)
|
||||
#define HID_USAGE_LED_BUSY ((USAGE) 0x2C)
|
||||
#define HID_USAGE_LED_READY ((USAGE) 0x2D)
|
||||
#define HID_USAGE_LED_PAPER_OUT ((USAGE) 0x2E)
|
||||
#define HID_USAGE_LED_PAPER_JAM ((USAGE) 0x2F)
|
||||
#define HID_USAGE_LED_REMOTE ((USAGE) 0x30)
|
||||
#define HID_USAGE_LED_FORWARD ((USAGE) 0x31)
|
||||
#define HID_USAGE_LED_REVERSE ((USAGE) 0x32)
|
||||
#define HID_USAGE_LED_STOP ((USAGE) 0x33)
|
||||
#define HID_USAGE_LED_REWIND ((USAGE) 0x34)
|
||||
#define HID_USAGE_LED_FAST_FORWARD ((USAGE) 0x35)
|
||||
#define HID_USAGE_LED_PLAY ((USAGE) 0x36)
|
||||
#define HID_USAGE_LED_PAUSE ((USAGE) 0x37)
|
||||
#define HID_USAGE_LED_RECORD ((USAGE) 0x38)
|
||||
#define HID_USAGE_LED_ERROR ((USAGE) 0x39)
|
||||
#define HID_USAGE_LED_SELECTED_INDICATOR ((USAGE) 0x3A)
|
||||
#define HID_USAGE_LED_IN_USE_INDICATOR ((USAGE) 0x3B)
|
||||
#define HID_USAGE_LED_MULTI_MODE_INDICATOR ((USAGE) 0x3C)
|
||||
#define HID_USAGE_LED_INDICATOR_ON ((USAGE) 0x3D)
|
||||
#define HID_USAGE_LED_INDICATOR_FLASH ((USAGE) 0x3E)
|
||||
#define HID_USAGE_LED_INDICATOR_SLOW_BLINK ((USAGE) 0x3F)
|
||||
#define HID_USAGE_LED_INDICATOR_FAST_BLINK ((USAGE) 0x40)
|
||||
#define HID_USAGE_LED_INDICATOR_OFF ((USAGE) 0x41)
|
||||
#define HID_USAGE_LED_FLASH_ON_TIME ((USAGE) 0x42)
|
||||
#define HID_USAGE_LED_SLOW_BLINK_ON_TIME ((USAGE) 0x43)
|
||||
#define HID_USAGE_LED_SLOW_BLINK_OFF_TIME ((USAGE) 0x44)
|
||||
#define HID_USAGE_LED_FAST_BLINK_ON_TIME ((USAGE) 0x45)
|
||||
#define HID_USAGE_LED_FAST_BLINK_OFF_TIME ((USAGE) 0x46)
|
||||
#define HID_USAGE_LED_INDICATOR_COLOR ((USAGE) 0x47)
|
||||
#define HID_USAGE_LED_RED ((USAGE) 0x48)
|
||||
#define HID_USAGE_LED_GREEN ((USAGE) 0x49)
|
||||
#define HID_USAGE_LED_AMBER ((USAGE) 0x4A)
|
||||
#define HID_USAGE_LED_GENERIC_INDICATOR ((USAGE) 0x3B)
|
||||
|
||||
//
|
||||
// Button Page (0x09)
|
||||
//
|
||||
// There is no need to label these usages.
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// Ordinal Page (0x0A)
|
||||
//
|
||||
// There is no need to label these usages.
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// Telephony Device Page (0x0B)
|
||||
//
|
||||
|
||||
#define HID_USAGE_TELEPHONY_PHONE ((USAGE) 0x01)
|
||||
#define HID_USAGE_TELEPHONY_ANSWERING_MACHINE ((USAGE) 0x02)
|
||||
#define HID_USAGE_TELEPHONY_MESSAGE_CONTROLS ((USAGE) 0x03)
|
||||
#define HID_USAGE_TELEPHONY_HANDSET ((USAGE) 0x04)
|
||||
#define HID_USAGE_TELEPHONY_HEADSET ((USAGE) 0x05)
|
||||
#define HID_USAGE_TELEPHONY_KEYPAD ((USAGE) 0x06)
|
||||
#define HID_USAGE_TELEPHONY_PROGRAMMABLE_BUTTON ((USAGE) 0x07)
|
||||
|
||||
//
|
||||
// and others...
|
||||
//
|
||||
|
||||
|
||||
#endif
|
282
client/prox.c
282
client/prox.c
|
@ -1,282 +0,0 @@
|
|||
#include <windows.h>
|
||||
#include <setupapi.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
//extern "C" {
|
||||
#include "include/hidusage.h"
|
||||
#include "include/hidpi.h"
|
||||
#include "include/hidsdi.h"
|
||||
//}
|
||||
|
||||
#include "flash.h"
|
||||
#include "usb_cmd.h"
|
||||
#include "ui.h"
|
||||
|
||||
#define OUR_VID 0x9ac4
|
||||
#define OUR_PID 0x4b8f
|
||||
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
|
||||
|
||||
int offline = 0;
|
||||
HANDLE UsbHandle;
|
||||
extern unsigned int current_command;
|
||||
extern struct partition partitions[];
|
||||
|
||||
static void ShowError(void)
|
||||
{
|
||||
char buf[1024];
|
||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
|
||||
buf, sizeof(buf), NULL);
|
||||
printf("ERROR: %s", buf);
|
||||
}
|
||||
|
||||
BOOL UsbConnect(void)
|
||||
{
|
||||
typedef void (__stdcall *GetGuidProc)(GUID *);
|
||||
typedef BOOLEAN (__stdcall *GetAttrProc)(HANDLE, HIDD_ATTRIBUTES *);
|
||||
typedef BOOLEAN (__stdcall *GetPreparsedProc)(HANDLE,
|
||||
PHIDP_PREPARSED_DATA *);
|
||||
typedef NTSTATUS (__stdcall *GetCapsProc)(PHIDP_PREPARSED_DATA, PHIDP_CAPS);
|
||||
GetGuidProc getGuid;
|
||||
GetAttrProc getAttr;
|
||||
GetPreparsedProc getPreparsed;
|
||||
GetCapsProc getCaps;
|
||||
|
||||
HMODULE h = LoadLibrary("hid.dll");
|
||||
getGuid = (GetGuidProc)GetProcAddress(h, "HidD_GetHidGuid");
|
||||
getAttr = (GetAttrProc)GetProcAddress(h, "HidD_GetAttributes");
|
||||
getPreparsed = (GetPreparsedProc)GetProcAddress(h, "HidD_GetPreparsedData");
|
||||
getCaps = (GetCapsProc)GetProcAddress(h, "HidP_GetCaps");
|
||||
|
||||
GUID hidGuid;
|
||||
getGuid(&hidGuid);
|
||||
|
||||
HDEVINFO devInfo;
|
||||
devInfo = SetupDiGetClassDevs(&hidGuid, NULL, NULL,
|
||||
DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
|
||||
|
||||
SP_DEVICE_INTERFACE_DATA devInfoData;
|
||||
devInfoData.cbSize = sizeof(devInfoData);
|
||||
|
||||
int i;
|
||||
for(i = 0;; i++) {
|
||||
if(!SetupDiEnumDeviceInterfaces(devInfo, 0, &hidGuid, i, &devInfoData))
|
||||
{
|
||||
if(GetLastError() != ERROR_NO_MORE_ITEMS) {
|
||||
// printf("SetupDiEnumDeviceInterfaces failed\n");
|
||||
}
|
||||
// printf("done list\n");
|
||||
SetupDiDestroyDeviceInfoList(devInfo);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// printf("item %d:\n", i);
|
||||
|
||||
DWORD sizeReqd = 0;
|
||||
if(!SetupDiGetDeviceInterfaceDetail(devInfo, &devInfoData,
|
||||
NULL, 0, &sizeReqd, NULL))
|
||||
{
|
||||
if(GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
|
||||
// printf("SetupDiGetDeviceInterfaceDetail (0) failed\n");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
SP_DEVICE_INTERFACE_DETAIL_DATA *devInfoDetailData =
|
||||
(SP_DEVICE_INTERFACE_DETAIL_DATA *)malloc(sizeReqd);
|
||||
devInfoDetailData->cbSize = sizeof(*devInfoDetailData);
|
||||
|
||||
if(!SetupDiGetDeviceInterfaceDetail(devInfo, &devInfoData,
|
||||
devInfoDetailData, 87, NULL, NULL))
|
||||
{
|
||||
// printf("SetupDiGetDeviceInterfaceDetail (1) failed\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
char *path = devInfoDetailData->DevicePath;
|
||||
|
||||
UsbHandle = CreateFile(path, /*GENERIC_READ |*/ GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
|
||||
FILE_FLAG_OVERLAPPED, NULL);
|
||||
|
||||
if(UsbHandle == INVALID_HANDLE_VALUE) {
|
||||
ShowError();
|
||||
// printf("CreateFile failed: for '%s'\n", path);
|
||||
continue;
|
||||
}
|
||||
|
||||
HIDD_ATTRIBUTES attr;
|
||||
attr.Size = sizeof(attr);
|
||||
if(!getAttr(UsbHandle, &attr)) {
|
||||
ShowError();
|
||||
// printf("HidD_GetAttributes failed\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
// printf("VID: %04x PID %04x\n", attr.VendorID, attr.ProductID);
|
||||
|
||||
if(attr.VendorID != OUR_VID || attr.ProductID != OUR_PID) {
|
||||
CloseHandle(UsbHandle);
|
||||
// printf(" nope, not us\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
// printf ("got it!\n");
|
||||
CloseHandle(UsbHandle);
|
||||
|
||||
UsbHandle = CreateFile(path, GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
|
||||
FILE_FLAG_OVERLAPPED, NULL);
|
||||
|
||||
if(UsbHandle == INVALID_HANDLE_VALUE) {
|
||||
ShowError();
|
||||
// printf("Error, couldn't open our own handle as desired.\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
PHIDP_PREPARSED_DATA pp;
|
||||
getPreparsed(UsbHandle, &pp);
|
||||
HIDP_CAPS caps;
|
||||
|
||||
if(getCaps(pp, &caps) != HIDP_STATUS_SUCCESS) {
|
||||
// printf("getcaps failed\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// printf("input/out report %d/%d\n", caps.InputReportByteLength,
|
||||
// caps.OutputReportByteLength);
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool ReceiveCommandPoll(UsbCommand *c)
|
||||
{
|
||||
static BOOL ReadInProgress = FALSE;
|
||||
static OVERLAPPED Ov;
|
||||
static BYTE Buf[65];
|
||||
static DWORD HaveRead;
|
||||
|
||||
if(!ReadInProgress) {
|
||||
memset(&Ov, 0, sizeof(Ov));
|
||||
ReadFile(UsbHandle, Buf, 65, &HaveRead, &Ov);
|
||||
if(GetLastError() != ERROR_IO_PENDING) {
|
||||
ShowError();
|
||||
exit(-1);
|
||||
}
|
||||
ReadInProgress = TRUE;
|
||||
}
|
||||
|
||||
if(HasOverlappedIoCompleted(&Ov)) {
|
||||
ReadInProgress = FALSE;
|
||||
|
||||
if(!GetOverlappedResult(UsbHandle, &Ov, &HaveRead, FALSE)) {
|
||||
ShowError();
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
memcpy(c, Buf+1, 64);
|
||||
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void ReceiveCommand(UsbCommand *c)
|
||||
{
|
||||
while(!ReceiveCommandPoll(c)) {
|
||||
Sleep(0);
|
||||
}
|
||||
}
|
||||
|
||||
void SendCommand(UsbCommand *c)
|
||||
{
|
||||
BYTE buf[65];
|
||||
buf[0] = 0;
|
||||
memcpy(buf+1, c, 64);
|
||||
|
||||
DWORD written;
|
||||
OVERLAPPED ov;
|
||||
|
||||
memset(&ov, 0, sizeof(ov));
|
||||
WriteFile(UsbHandle, buf, 65, &written, &ov);
|
||||
if(GetLastError() != ERROR_IO_PENDING) {
|
||||
ShowError();
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
while(!HasOverlappedIoCompleted(&ov)) {
|
||||
Sleep(0);
|
||||
}
|
||||
|
||||
if(!GetOverlappedResult(UsbHandle, &ov, &written, FALSE)) {
|
||||
ShowError();
|
||||
exit(-1);
|
||||
}
|
||||
current_command = c->cmd;
|
||||
}
|
||||
|
||||
static void usage(char **argv)
|
||||
{
|
||||
int i;
|
||||
printf("Usage: %s gui\n", argv[0]);
|
||||
printf(" %s offline\n", argv[0]);
|
||||
printf(" %s areas file.elf\n", argv[0]);
|
||||
printf(" Known areas are:");
|
||||
for(i=0; partitions[i].name != NULL; i++) {
|
||||
fprintf(stderr, " %s", partitions[i].name);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
if(argc < 2) {
|
||||
usage(argv);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// Only do this if NOT in offline mode
|
||||
if (strcmp(argv[1], "offline"))
|
||||
{
|
||||
for(;;) {
|
||||
if(UsbConnect()) {
|
||||
break;
|
||||
}
|
||||
if(i == 0) {
|
||||
printf("...no device connected, polling for it now\n");
|
||||
}
|
||||
if(i > 50000) {
|
||||
printf("Could not connect to USB device; exiting.\n");
|
||||
return -1;
|
||||
}
|
||||
i++;
|
||||
Sleep(5);
|
||||
}
|
||||
}
|
||||
|
||||
if(strcmp(argv[1], "gui")==0) {
|
||||
ShowGui();
|
||||
} else if(strcmp(argv[1], "offline")==0) {
|
||||
offline = 1;
|
||||
ShowGui();
|
||||
}
|
||||
|
||||
/* Count area arguments */
|
||||
int areas = 0, offset=-1, length=0;
|
||||
while(find_next_area(argv[1], &offset, &length)) areas++;
|
||||
|
||||
if(areas != argc - 2) {
|
||||
usage(argv);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
do_flash(argv);
|
||||
return 0;
|
||||
}
|
|
@ -35,6 +35,7 @@ static void *usb_receiver(void *targ)
|
|||
}
|
||||
|
||||
pthread_exit(NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *main_loop(void *targ)
|
||||
|
@ -70,6 +71,7 @@ static void *main_loop(void *targ)
|
|||
|
||||
ExitGraphics();
|
||||
pthread_exit(NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
|
|
@ -3,4 +3,4 @@
|
|||
|
||||
#define PROXPROMPT "proxmark3> "
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -6,10 +6,16 @@
|
|||
#include <strings.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "sleep.h"
|
||||
#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "usb_cmd.h"
|
||||
|
||||
// It seems to be missing for mingw
|
||||
#ifndef ETIMEDOUT
|
||||
#define ETIMEDOUT 116
|
||||
#endif
|
||||
|
||||
usb_dev_handle *devh = NULL;
|
||||
static unsigned int claimed_iface = 0;
|
||||
unsigned char return_on_error = 0;
|
||||
|
@ -37,7 +43,7 @@ void SendCommand(UsbCommand *c)
|
|||
usb_close(devh);
|
||||
devh = NULL;
|
||||
}
|
||||
while(!(devh=OpenProxmark(0))) { sleep(1); }
|
||||
while(!OpenProxmark(0)) { sleep(1); }
|
||||
printf(PROXPROMPT);
|
||||
fflush(NULL);
|
||||
|
||||
|
@ -49,7 +55,7 @@ bool ReceiveCommandPoll(UsbCommand *c)
|
|||
{
|
||||
int ret;
|
||||
|
||||
bzero(c, sizeof(UsbCommand));
|
||||
memset(c, 0, sizeof (UsbCommand));
|
||||
ret = usb_bulk_read(devh, 0x82, (char*)c, sizeof(UsbCommand), 500);
|
||||
if (ret<0) {
|
||||
if (ret != -ETIMEDOUT) {
|
||||
|
@ -64,7 +70,7 @@ bool ReceiveCommandPoll(UsbCommand *c)
|
|||
usb_close(devh);
|
||||
devh = NULL;
|
||||
}
|
||||
while(!(devh=OpenProxmark(0))) { sleep(1); }
|
||||
while(!OpenProxmark(0)) { sleep(1); }
|
||||
printf(PROXPROMPT);
|
||||
fflush(NULL);
|
||||
|
||||
|
@ -130,7 +136,7 @@ usb_dev_handle* OpenProxmark(int verbose)
|
|||
usb_dev_handle *handle = NULL;
|
||||
unsigned int iface;
|
||||
|
||||
#ifndef __APPLE__
|
||||
#ifdef __linux__
|
||||
handle = findProxmark(verbose, &iface);
|
||||
if (!handle)
|
||||
return NULL;
|
||||
|
@ -143,20 +149,28 @@ usb_dev_handle* OpenProxmark(int verbose)
|
|||
if (!handle)
|
||||
return NULL;
|
||||
|
||||
#ifndef __APPLE__
|
||||
#ifdef __linux__
|
||||
/* detach kernel driver first */
|
||||
ret = usb_detach_kernel_driver_np(handle, iface);
|
||||
/* don't complain if no driver attached */
|
||||
if (ret<0 && ret != -61 && verbose)
|
||||
fprintf(stderr, "detach kernel driver failed: (%d) %s!\n", ret, usb_strerror());
|
||||
#endif
|
||||
|
||||
// Needed for Windows. Optional for Mac OS and Linux
|
||||
ret = usb_set_configuration(handle, 1);
|
||||
if (ret < 0) {
|
||||
if (verbose)
|
||||
fprintf(stderr, "configuration set failed: %s!\n", usb_strerror());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = usb_claim_interface(handle, iface);
|
||||
if (ret < 0) {
|
||||
if (verbose)
|
||||
fprintf(stderr, "claim failed: %s!\n", usb_strerror());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
claimed_iface = iface;
|
||||
devh = handle;
|
||||
return handle;
|
||||
|
@ -166,4 +180,5 @@ void CloseProxmark(void)
|
|||
{
|
||||
usb_release_interface(devh, claimed_iface);
|
||||
usb_close(devh);
|
||||
devh = NULL;
|
||||
}
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#ifndef WIN32
|
||||
#include <usb.h>
|
||||
#endif
|
||||
#include "usb_cmd.h"
|
||||
|
||||
extern unsigned char return_on_error;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "sleep.h"
|
||||
#include "ui.h"
|
||||
#include "proxusb.h"
|
||||
#include "cmdmain.h"
|
||||
|
|
|
@ -10,11 +10,6 @@ int offline;
|
|||
|
||||
static char *logfilename = "proxmark3.log";
|
||||
|
||||
// FIXME: ifndef not really nice...
|
||||
// We should eventually get rid of it once
|
||||
// we fully factorize the code between *nix and windows
|
||||
// (using pthread and alikes...)
|
||||
#ifndef WIN32
|
||||
void PrintAndLog(char *fmt, ...)
|
||||
{
|
||||
va_list argptr, argptr2;
|
||||
|
@ -41,7 +36,6 @@ void PrintAndLog(char *fmt, ...)
|
|||
}
|
||||
va_end(argptr2);
|
||||
}
|
||||
#endif
|
||||
|
||||
void SetLogFilename(char *fn)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue