46 #define _WIN32_WINNT 0x400 55 #if defined(__BORLANDC__) 62 #ifndef WINAPI_PARTITION_DESKTOP 63 #define WINDOWS_WIN32_API 65 #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) 66 #define WINDOWS_WIN32_API 68 #define WINDOWS_UWP_API 72 #ifdef WINDOWS_WIN32_API 77 #pragma comment(lib, "SetupApi.lib") 78 #pragma comment(lib, "OleAut32.lib") 85 typedef struct _HIDD_ATTRIBUTES {
90 } HIDD_ATTRIBUTES, *PHIDD_ATTRIBUTES;
93 typedef VOID (__stdcall *PHidD_GetHidGuid)(LPGUID);
94 typedef BOOLEAN (__stdcall *PHidD_GetAttributes)(HANDLE, PHIDD_ATTRIBUTES);
95 typedef BOOLEAN (__stdcall *PHidD_GetManufacturerString) (HANDLE,PVOID,ULONG);
96 typedef BOOLEAN (__stdcall *PHidD_GetProductString) (HANDLE,PVOID,ULONG);
97 typedef BOOLEAN (__stdcall *PHidD_GetSerialNumberString) (HANDLE,PVOID,ULONG);
98 typedef BOOLEAN (__stdcall *PHidD_SetNumInputBuffers) (HANDLE, ULONG);
102 PHidD_GetHidGuid GetHidGuid;
103 PHidD_GetAttributes GetAttributes;
104 PHidD_GetManufacturerString GetManufacturerString;
105 PHidD_GetProductString GetProductString;
106 PHidD_GetSerialNumberString GetSerialNumberString;
107 PHidD_SetNumInputBuffers SetNumInputBuffers;
111 #ifdef WINDOWS_WIN32_API 115 typedef LONG (__stdcall *PYRegCreateKeyEx)( HKEY hKey,
116 const char * lpSubKey,
121 LPSECURITY_ATTRIBUTES lpSecurityAttributes,
123 LPDWORD lpdwDisposition);
124 typedef LONG (_stdcall *PYRegOpenKeyEx) (HKEY hKey,
const char * lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult);
125 typedef LONG (__stdcall *PYRegSetValueEx)( HKEY hKey,
132 typedef LONG (__stdcall *PYRegQueryValueEx)( HKEY hKey,
138 typedef LONG(__stdcall *PYRegDeleteValue)(HKEY hKey,
char * lpValueName);
139 typedef LONG (__stdcall *PYRegCloseKey)(HKEY hKey);
140 typedef LONG (__stdcall *PYRegDeleteKeyEx)(HKEY hKey,
char * lpSubKey, REGSAM samDesired, DWORD Reserved);
144 PYRegCreateKeyEx yRegCreateKeyEx;
145 PYRegOpenKeyEx yRegOpenKeyEx;
146 PYRegSetValueEx yRegSetValueEx;
147 PYRegQueryValueEx yRegQueryValueEx;
148 PYRegDeleteValue yRegDeleteValue;
149 PYRegCloseKey yRegCloseKey;
150 PYRegDeleteKeyEx yRegDeleteKeyEx;
155 #elif defined(OSX_API) 159 #include <IOKit/hid/IOHIDLib.h> 162 #elif defined(LINUX_API) 166 #include <libusb-1.0/libusb.h> 188 #define yMalloc(size) ySafeMalloc(__FILE_ID__,__LINE__,size) 189 #define yFree(ptr) {ySafeFree(__FILE_ID__,__LINE__,ptr);ptr=NULL;} 190 #define yTracePtr(ptr) ySafeTrace(__FILE_ID__,__LINE__,ptr) 191 #ifndef YMEMORY_ALLOW_MALLOC 194 #define malloc(size) yForbiden_malloc(size) 195 #define free(ptr) yForbiden_free(ptr) 198 #define yMalloc(size) malloc(size) 199 #define yFree(ptr) free(ptr) 200 #define yTracePtr(ptr) 203 #define yMemset(dst,val,size) memset(dst,val,size) 204 #define yMemcpy(dst,src,size) memcpy(dst,src,size) 205 #define yMemmove(dst,src,size) memmove(dst,src,size) 207 #if defined(WINDOWS_API) && defined(_MSC_VER) && !defined(WINCE) 208 #define YSTRCMP(A,B) strcmp(A,B) 209 #define YSTRNCMP(A,B,len) strncmp(A,B,len) 210 #define YSTRICMP(A,B) _stricmp(A,B) 211 #define YSTRNICMP(A,B,len) _strnicmp(A,B,len) 212 #define YSTRLEN(str) ((int)strlen(str)) 213 #elif defined(WINDOWS_API) && defined(__BORLANDC__) 214 #define YSTRCMP(A,B) strcmp(A,B) 215 #define YSTRNCMP(A,B,len) strncmp(A,B,len) 216 #define YSTRICMP(A,B) strcmpi(A,B) 217 #define YSTRNICMP(A,B,len) strncmpi(A,B,len) 218 #define YSTRLEN(str) ((int)strlen(str)) 220 #define YSTRCMP(A,B) strcmp(A,B) 221 #define YSTRNCMP(A,B,len) strncmp(A,B,len) 222 #define YSTRICMP(A,B) _stricmp(A,B) 223 #define YSTRNICMP(A,B,len) _strnicmp(A,B,len) 224 #define YSTRLEN(str) ((int)strlen(str)) 226 #define YSTRCMP(A,B) strcmp(A,B) 227 #define YSTRNCMP(A,B,len) strncmp(A,B,len) 228 #define YSTRICMP(A,B) strcasecmp(A,B) 229 #define YSTRNICMP(A,B,len) strncasecmp(A,B,len) 230 #define YSTRLEN(str) ((int)strlen(str)) 233 #define YSTRDUP(src) ystrdup_s(src) 234 #define YSTRCPY(dst,dstsize,src) ystrcpy_s(dst,dstsize,src) 235 #define YSTRCAT(dst,dstsize,src) ystrcat_s(dst,dstsize,src) 236 #define YSTRNCAT(dst,dstsize,src,len) ystrncat_s(dst,dstsize,src,len) 237 #define YSTRNCPY(dst,dstsize,src,len) ystrncpy_s(dst,dstsize,src,len) 238 #define YSPRINTF ysprintf_s 239 #define YVSPRINTF yvsprintf_s 245 int ysprintf_s(
char *dst,
unsigned dstsize,
const char *fmt ,...);
246 int yvsprintf_s (
char *dst,
unsigned dstsize,
const char * fmt, va_list arg );
247 int ymemfind(
const u8 *haystack, u32 haystack_len,
const u8 *needle, u32 needle_len);
267 #define MSC_VS2003 1310 269 #ifdef DEBUG_YAPI_REQ 270 #define YREQLOG dbglog 272 #if defined(_MSC_VER) 273 #if (_MSC_VER > MSC_VS2003) 274 #define YREQLOG(fmt,...) 276 __forceinline
void __YREQLOG(fmt,...){}
277 #define YREQLOG __YREQLOG 280 #define YREQLOG(fmt,args...) 285 #define HALLOG dbglog 287 #if defined(_MSC_VER) 288 #if (_MSC_VER > MSC_VS2003) 289 #define HALLOG(fmt,...) 291 __forceinline
void __HALLOG(fmt,...){}
292 #define HALLOG __HALLOG 295 #define HALLOG(fmt,args...) 299 #ifdef DEBUG_HAL_ENUM 300 #define HALENUMLOG dbglog 302 #if defined(_MSC_VER) 303 #if (_MSC_VER > MSC_VS2003) 304 #define HALENUMLOG(fmt,...) 307 #define HALENUMLOG __HALLOG 310 #define HALENUMLOG(fmt,args...) 315 #define TCPLOG dbglog 317 #if defined(_MSC_VER) 318 #if (_MSC_VER > MSC_VS2003) 319 #define TCPLOG(fmt,...) 321 __forceinline
void __TCPLOG(fmt,...){}
322 #define TCPLOG __TCPLOG 325 #define TCPLOG(fmt,args...) 329 #ifdef TRACE_REQUESTS 330 #define REQLOG dbglog 332 #if defined(_MSC_VER) 333 #if (_MSC_VER > MSC_VS2003) 334 #define REQLOG(fmt,...) 336 __forceinline
void __REQLOG(fmt, ...) {}
337 #define REQLOG __REQLOG 340 #define REQLOG(fmt,args...) 345 #ifdef DEBUG_DEV_ENUM 346 #define ENUMLOG dbglog 348 #if defined(_MSC_VER) 349 #if (_MSC_VER > MSC_VS2003) 350 #define ENUMLOG(fmt,...) 352 __forceinline
void __ENUMLOG(fmt,...){}
353 #define ENUMLOG __ENUMLOG 356 #define ENUMLOG(fmt,args...) 360 #ifdef DEBUG_NET_ENUM 361 #define NETENUMLOG dbglog 363 #if defined(_MSC_VER) 364 #if (_MSC_VER > MSC_VS2003) 365 #define NETENUMLOG(fmt,...) 367 __forceinline
void __NETENUMLOG(fmt,...){}
368 #define NETENUMLOG __NETENUMLOG 371 #define NETENUMLOG(fmt,args...) 377 #ifdef DEBUG_WEBSOCKET 380 #if defined(_MSC_VER) 381 #if (_MSC_VER > MSC_VS2003) 382 #define WSLOG(fmt,...) 384 __forceinline
void __WSLOG(fmt, ...) {}
385 #define WSLOG __WSLOG 388 #define WSLOG(fmt,args...) 395 int vdbglogf(
const char *fileid,
int line,
const char *fmt,va_list args);
396 int dbglogf(
const char *fileid,
int line,
const char *fmt,...);
397 #if defined(_MSC_VER) 398 #if (_MSC_VER > MSC_VS2003) 399 #define dbglog(...) dbglogf(__FILE_ID__,__LINE__, __VA_ARGS__) 401 __forceinline
int __dbglog(
const char* fmt,...) {
405 va_start( args, fmt );
406 len =
vdbglogf(
"vs2003",__LINE__,fmt,args);
410 #define dbglog __dbglog 413 #define dbglog(args...) dbglogf(__FILE_ID__,__LINE__, ## args) 417 #ifdef DEBUG_DUMP_PKT 418 void dumpAnyPacket(
char *prefix,
int ifaceno,
USB_Packet *pkt);
422 #define STRINGIFY(x) #x 423 #define TOSTRING(x) STRINGIFY(x) 429 #define yApproximateSleep(ms) Sleep(ms) 433 #define yApproximateSleep(ms) usleep(ms*1000) 436 #if defined(_MSC_VER) && (_MSC_VER > MSC_VS2003) 437 #define YFOPEN(f,filename,mode) fopen_s(f,filename,mode) 440 int YFOPEN(FILE** f,
const char *filename,
const char *mode);
444 #if defined(WINDOWS_API) && (_MSC_VER) 445 #define YDEBUG_BREAK { __debugbreak();} 447 #define YDEBUG_BREAK {__asm__("int3");} 450 #define YDEBUG_BREAK {} 453 #define YPANIC {dbglog("YPANIC:%s:%d\n",__FILE_ID__ , __LINE__);YDEBUG_BREAK} 454 #define YASSERT(x) if(!(x)){dbglog("ASSERT FAILED:%s:%d\n",__FILE_ID__ , __LINE__);YDEBUG_BREAK} 455 #define YPROPERR(call) {int tmpres=(call); if(YISERR(tmpres)) {return (YRETCODE)tmpres;}} 456 #define YERR(code) ySetErr(code,errmsg,NULL,__FILE_ID__,__LINE__) 457 #define YERRTO(code,buffer) ySetErr(code,buffer,NULL,__FILE_ID__,__LINE__) 458 #define YERRMSG(code,message) ySetErr(code,errmsg,message,__FILE_ID__,__LINE__) 459 #define YERRMSGSILENT(code,message) ySetErr(code, errmsg, message, NULL, 0) 460 #define YERRMSGTO(code,message,buffer) ySetErr(code,buffer,message,__FILE_ID__,__LINE__) 461 int ySetErr(
int code,
char *outmsg,
const char *erreur,
const char *file, u32 line);
462 int FusionErrmsg(
int code,
char *errmsg,
const char *generr,
const char *detailerr);
469 #define YPKT_VERSION_ORIGINAL_RELEASE 0x0202 498 #if defined(LINUX_API) 501 struct libusb_transfer *tr;
509 #ifdef DEBUG_PKT_TIMING 538 IOHIDManagerRef manager;
544 #ifdef WINDOWS_UWP_API 545 typedef struct _uwp_enum_item {
553 #define NBMAX_NET_HUB 32 554 #define NBMAX_USB_DEVICE_CONNECTED 256 555 #define WIN_DEVICE_PATH_LEN 512 556 #define HTTP_RAW_BUFF_SIZE (8*1024) 557 #define NB_LINUX_USB_TR 1 559 #define YWIN_EVENT_READ 0 560 #define YWIN_EVENT_INTERRUPT 1 573 #if defined(WINDOWS_API) 583 #elif defined(OSX_API) 585 CFStringRef run_loop_mode;
586 IOHIDDeviceRef devref;
588 #elif defined(LINUX_API) 589 libusb_device *devref;
590 libusb_device_handle *hdl;
605 #define NBMAX_INTERFACE_PER_DEV 1 646 #define DEVGEN_LOG_ACTIVATED 1u 647 #define DEVGEN_LOG_PENDING 2u 648 #define DEVGEN_LOG_PULLING 4u 662 #define YIO_REMOTE_CLOSE 1u 672 #define NB_MAX_STARTUP_RETRY 5u 674 #define NEXT_YPKT_NO(current) ((current+1)& YPKTNOMSK) 675 #define NEXT_IFACE_NO(current,total) (current+1<total?current+1:0) 709 typedef void (*
yNotificCallback)(
const char *serial,
const char *funcid,
const char *funcname,
const char *funcval);
727 #define MAX_YDX_PER_HUB 255 728 #define ALLOC_YDX_PER_HUB 256 733 #define NET_HUB_NOT_CONNECTION_TIMEOUT (6*1024) 774 char websocket_key[32];
828 #define TCPREQ_KEEPALIVE 1 829 #define TCPREQ_IN_USE 2 890 #define SETUPED_IFACE_CACHE_SIZE 128 920 #define YCTX_OSX_MULTIPLES_HID 1 963 #if defined(WINDOWS_API) 969 #ifdef WINDOWS_WIN32_API 971 win_reg_api registry;
973 #elif defined(OSX_API) 976 CFRunLoopRef usb_run_loop;
977 pthread_t usb_thread;
979 #elif defined(LINUX_API) 981 libusb_context *libusb;
982 pthread_t usb_thread;
987 #define TRACEFILE_NAMELEN 512 1022 void ypUpdateUSB(
const char *serial,
const char *funcid,
const char *funcname,
int funclass,
int funydx,
const char *funcval);
1035 #define FIND_FROM_SERIAL 1 1036 #define FIND_FROM_NAME 2 1037 #define FIND_FROM_ANY (FIND_FROM_SERIAL|FIND_FROM_NAME) 1077 int yapiJsonGetPath_internal(
const char *path,
const char *json_data,
int json_size,
int withHTTPheader,
const char **output,
char *errmsg);
int yUsbReadBlock(YIOHDL_internal *ioghdl, char *buffer, int len, u64 blockUntil, char *errmsg)
struct _yGenericDeviceSt yGenericDeviceSt
int yUsbOpen(YIOHDL_internal *ioghdl, const char *device, char *errmsg)
int yvsprintf_s(char *dst, unsigned dstsize, const char *fmt, va_list arg)
int yUsbReadNonBlock(YIOHDL_internal *ioghdl, char *buffer, int len, char *errmsg)
struct _yPrivDeviceSt yPrivDeviceSt
int yUsbEOF(YIOHDL_internal *ioghdl, char *errmsg)
yCRITICAL_SECTION acces_state
void ypUpdateHybrid(const char *serial, Notification_funydx funInfo, const char *funcval)
void YAPI_FUNCTION_EXPORT(* yapiDeviceUpdateCallback)(YAPI_DEVICE devdescr)
YIOHDL_internal * yiohdl_first
void ypUpdateUSB(const char *serial, const char *funcid, const char *funcname, int funclass, int funydx, const char *funcval)
void dumpYPerfEntry(yPerfMon *entry, const char *name)
int yUSBGetBooloader(const char *serial, const char *name, yInterfaceSt *iface, char *errmsg)
struct _RequestSt * requests
YRETCODE ystrcpy_s(char *dst, unsigned dstsize, const char *src)
YRETCODE yPktQueueWaitAndPopD2H(yInterfaceSt *iface, pktItem **pkt, int ms, char *errmsg)
YRETCODE yPktQueuePushH2D(yInterfaceSt *iface, const USB_Packet *pkt, char *errmsg)
void yUSBReleaseAllDevices(void)
void initDevYdxInfos(int devYdxy, yStrRef serial)
yCRITICAL_SECTION handleEv_cs
yapiDeviceUpdateCallback arrivalCallback
int yUsbClose(YIOHDL_internal *ioghdl, char *errmsg)
int FusionErrmsg(int code, char *errmsg, const char *generr, const char *detailerr)
void wpSafeUpdate(HubSt *hub, u8 devYdx, yStrRef serialref, yStrRef lnameref, yUrlRef devUrl, s8 beacon)
int yUsbFree(yContextSt *ctx, char *errmsg)
int yapiJsonGetPath_internal(const char *path, const char *json_data, int json_size, int withHTTPheader, const char **output, char *errmsg)
void(* RequestProgress)(void *context, u32 acked, u32 totalbytes)
void(* yapiRequestProgressCallback)(void *context, u32 acked, u32 totalbytes)
yPrivDeviceSt * findDev(const char *str, u32 flags)
struct _HTTPReqSt HTTPReqSt
#define MAX_ASYNC_TCPCHAN
yapiFunctionUpdateCallback functionCallback
struct _YIOHDL_internal YIOHDL_internal
void devHdlInfo(YUSBDEV hdl, yDeviceSt *infos)
yPrivDeviceSt * findDevFromIOHdl(YIOHDL_internal *hdl)
int yyySetup(yInterfaceSt *iface, char *errmsg)
yRawReportV2Cb rawReportV2Cb
int ySetErr(int code, char *outmsg, const char *erreur, const char *file, u32 line)
int yyyUSBGetInterfaces(yInterfaceSt **ifaces, int *nbifaceDetect, char *errmsg)
struct _RequestSt * openRequests
YRETCODE ystrncat_s(char *dst, unsigned dstsize, const char *src, unsigned len)
yCRITICAL_SECTION functionCallbackCS
void(* yDevInfoCallback)(const yDeviceSt *infos)
struct _RequestSt RequestSt
#define WIN_DEVICE_PATH_LEN
void yFunctionTimedUpdate(YAPI_FUNCTION fundescr, double deviceTime, const u8 *report, u32 len)
YRETCODE yPktQueuePopH2D(yInterfaceSt *iface, pktItem **pkt)
void wpSafeUnregister(yStrRef serialref)
int yyyUSB_init(yContextSt *ctx, char *errmsg)
#define SETUPED_IFACE_CACHE_SIZE
yCRITICAL_SECTION deviceCallbackCS
int yUsbSetIOAsync(YIOHDL_internal *ioghdl, yapiRequestAsyncCallback callback, void *context, char *errmsg)
#define HALENUMLOG(fmt, args...)
yapiTimedReportCallback timedReportCallback
int yyySignalOutPkt(yInterfaceSt *iface, char *errmsg)
void YAPI_FUNCTION_EXPORT(* yapiTimedReportCallback)(YAPI_FUNCTION fundesc, double timestamp, const u8 *bytes, u32 len)
int yyyUSB_stop(yContextSt *ctx, char *errmsg)
YRETCODE yapiRequestOpen(YIOHDL_internal *iohdl, int tpchan, const char *device, const char *request, int reqlen, yapiRequestAsyncCallback callback, void *context, yapiRequestProgressCallback progress_cb, void *progress_ctx, char *errmsg)
int vdbglogf(const char *fileid, int line, const char *fmt, va_list args)
yCRITICAL_SECTION updateDev_cs
void yPktQueueSetError(pktQueue *q, YRETCODE code, const char *msg)
yRawNotificationCb rawNotificationCb
YRETCODE ystrcat_s(char *dst, unsigned dstsize, const char *src)
RequestProgress progressCb
void YAPI_FUNCTION_EXPORT(* yapiFunctionUpdateCallback)(YAPI_FUNCTION fundescr, const char *value)
struct _yInterfaceSt yInterfaceSt
void yFunctionUpdate(YAPI_FUNCTION fundescr, const char *value)
YRETCODE ystrncpy_s(char *dst, unsigned dstsize, const char *src, unsigned len)
YRETCODE yPktQueuePeekH2D(yInterfaceSt *iface, pktItem **pkt)
yapiDeviceLogCallback logDeviceCallback
void(* yRawNotificationCb)(USB_Notify_Pkt *)
int dbglogf(const char *fileid, int line, const char *fmt,...)
void(* yRawReportV2Cb)(YAPI_DEVICE serialref, USB_Report_Pkt_V2 *report, int pktsize)
int yUsbTrafficPending(void)
struct _YIOHDL_internal * next
int yUsbInit(yContextSt *ctx, char *errmsg)
void freeDevYdxInfos(int devYdx)
yapiDeviceUpdateCallback changeCallback
void(* yapiRequestAsyncCallback)(void *context, const u8 *result, u32 resultlen, int retcode, const char *errmsg)
YRETCODE yPktQueuePushD2H(yInterfaceSt *iface, const USB_Packet *pkt, char *errmsg)
YRETCODE yapiPullDeviceLog(const char *serial)
void(* yRawReportCb)(YAPI_DEVICE serialref, USB_Report_Pkt_V1 *report, int pktsize)
int yUsbWrite(YIOHDL_internal *ioghdl, const char *buffer, int writelen, char *errmsg)
struct _HTTPNetHubSt HTTPNetHub
struct _RequestSt * notReq
yCRITICAL_SECTION generic_cs
int ymemfind(const u8 *haystack, u32 haystack_len, const u8 *needle, u32 needle_len)
void YAPI_FUNCTION_EXPORT(* yapiDeviceLogCallback)(YAPI_FUNCTION fundescr, const char *line)
void YAPI_FUNCTION_EXPORT(* yapiLogFunction)(const char *log, u32 loglen)
void yPktQueueFree(pktQueue *q)
YRETCODE yapiHTTPRequestSyncStartEx_internal(YIOHDL *iohdl, int tcpchan, const char *device, const char *request, int requestsize, char **reply, int *replysize, yapiRequestProgressCallback progress_cb, void *progress_ctx, char *errmsg)
unsigned int nb_startup_retry
void yyyPacketShutdown(yInterfaceSt *iface)
yCRITICAL_SECTION enum_cs
yGenericDeviceSt * yUSBGetGenericInfo(yStrRef devdescr)
yapiRequestAsyncCallback callback
int handleNetNotification(HubSt *hub)
int yyyOShdlCompare(yPrivDeviceSt *dev, yInterfaceSt *newiface)
int yUsbOpenDevDescr(YIOHDL_internal *ioghdl, yStrRef devdescr, char *errmsg)
struct _WSNetHubSt WSNetHub
YRETCODE yyySendPacket(yInterfaceSt *iface, const USB_Packet *pkt, char *errmsg)
int ysprintf_s(char *dst, unsigned dstsize, const char *fmt,...)
YRETCODE yapiPullDeviceLogEx(int devydx)
void YAPI_FUNCTION_EXPORT(* yapiHubDiscoveryCallback)(const char *serial, const char *url)
YRETCODE yUSBUpdateDeviceList(char *errmsg)
#define ALLOC_YDX_PER_HUB
void(* yNotificCallback)(const char *serial, const char *funcid, const char *funcname, const char *funcval)
u32 yapiGetCNonce(u32 nc)
char * ystrdup_s(const char *src)
yapiDeviceUpdateCallback removalCallback
YRETCODE yapiHTTPRequestSyncDone_internal(YIOHDL *iohdl, char *errmsg)
yapiHubDiscoveryCallback hubDiscoveryCallback
void ypUpdateYdx(int devydx, Notification_funydx funInfo, const char *funcval)
struct _WSChanSt WSChanSt
void yPktQueueInit(pktQueue *q)
struct _yPrivDeviceSt * next
yapiRequestAsyncCallback callback
int YFOPEN(FILE **f, const char *filename, const char *mode)
void wpSafeRegister(HubSt *hub, u8 devYdx, yStrRef serialref, yStrRef lnameref, yStrRef productref, u16 deviceid, yUrlRef devUrl, s8 beacon)
YUSBDEV findDevHdlFromStr(const char *str)