yproto.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * $Id: yproto.h 28489 2017-09-12 13:19:37Z seb $
4  *
5  * Definitions and prototype common to all supported OS
6  *
7  * - - - - - - - - - License information: - - - - - - - - -
8  *
9  * Copyright (C) 2011 and beyond by Yoctopuce Sarl, Switzerland.
10  *
11  * Yoctopuce Sarl (hereafter Licensor) grants to you a perpetual
12  * non-exclusive license to use, modify, copy and integrate this
13  * file into your software for the sole purpose of interfacing
14  * with Yoctopuce products.
15  *
16  * You may reproduce and distribute copies of this file in
17  * source or object form, as long as the sole purpose of this
18  * code is to interface with Yoctopuce products. You must retain
19  * this notice in the distributed source file.
20  *
21  * You should refer to Yoctopuce General Terms and Conditions
22  * for additional information regarding your rights and
23  * obligations.
24  *
25  * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
26  * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
27  * WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS
28  * FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO
29  * EVENT SHALL LICENSOR BE LIABLE FOR ANY INCIDENTAL, SPECIAL,
30  * INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
31  * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR
32  * SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT
33  * LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR
34  * CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON THE
35  * BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF
36  * WARRANTY, OR OTHERWISE.
37  *
38  *********************************************************************/
39 
40 #ifndef YPROTO_H
41 #define YPROTO_H
42 
43 #include "ydef.h"
44 #ifdef WINDOWS_API
45 #ifndef _WIN32_WINNT
46 #define _WIN32_WINNT 0x400
47 #endif
48 #endif
49 #include "yapi.h"
50 #include "ytcp.h"
51 #ifdef WINDOWS_API
52 /**************************************************************
53 * WINDOWS SPECIFIC HEADER
54 ***************************************************************/
55 #if defined(__BORLANDC__)
56 #pragma warn -8019
57 #include <windows.h>
58 #pragma warn +8019
59 #else
60 #include <windows.h>
61 #endif
62 #ifndef WINAPI_PARTITION_DESKTOP
63 #define WINDOWS_WIN32_API
64 #else
65 #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
66 #define WINDOWS_WIN32_API
67 #else
68 #define WINDOWS_UWP_API
69 #endif
70 #endif
71 
72 #ifdef WINDOWS_WIN32_API
73 #include <dbt.h>
74 
75 #include <SetupAPI.h>
76 #ifdef _MSC_VER
77 #pragma comment(lib, "SetupApi.lib")
78 #pragma comment(lib, "OleAut32.lib")
79 
80 #endif
81 /**************************************************************
82 * WINDOWS HID ACCES FOR WINODWS
83 ***************************************************************/
84 
85 typedef struct _HIDD_ATTRIBUTES {
86  ULONG Size;
87  USHORT VendorID;
88  USHORT ProductID;
89  USHORT VersionNumber;
90 } HIDD_ATTRIBUTES, *PHIDD_ATTRIBUTES;
91 
92 //Pointers to a HID function used
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);
99 
100 typedef struct{
101  HINSTANCE hHID;
102  PHidD_GetHidGuid GetHidGuid;
103  PHidD_GetAttributes GetAttributes;
104  PHidD_GetManufacturerString GetManufacturerString;
105  PHidD_GetProductString GetProductString;
106  PHidD_GetSerialNumberString GetSerialNumberString;
107  PHidD_SetNumInputBuffers SetNumInputBuffers;
108 }win_hid_api;
109 #endif
110 
111 #ifdef WINDOWS_WIN32_API
112 
113 //Pointers to a registry function used
114 
115 typedef LONG (__stdcall *PYRegCreateKeyEx)( HKEY hKey,
116  const char * lpSubKey,
117  DWORD Reserved,
118  LPTSTR lpClass,
119  DWORD dwOptions,
120  REGSAM samDesired,
121  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
122  PHKEY phkResult,
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,
126  char * lpValueName,
127  DWORD Reserved,
128  DWORD dwType,
129  const BYTE *lpData,
130  DWORD cbData);
131 
132 typedef LONG (__stdcall *PYRegQueryValueEx)( HKEY hKey,
133  char * lpValueName,
134  LPDWORD lpReserved,
135  LPDWORD lpType,
136  LPBYTE lpData,
137  LPDWORD lpcbData);
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);
141 
142 typedef struct{
143  HINSTANCE hREG;
144  PYRegCreateKeyEx yRegCreateKeyEx;
145  PYRegOpenKeyEx yRegOpenKeyEx;
146  PYRegSetValueEx yRegSetValueEx;
147  PYRegQueryValueEx yRegQueryValueEx;
148  PYRegDeleteValue yRegDeleteValue;
149  PYRegCloseKey yRegCloseKey;
150  PYRegDeleteKeyEx yRegDeleteKeyEx;
151 }win_reg_api;
152 
153 #endif
154 
155 #elif defined(OSX_API)
156 /*****************************************************************************
157  OSX SPECIFIC HEADER
158  ****************************************************************************/
159 #include <IOKit/hid/IOHIDLib.h>
160 
161 
162 #elif defined(LINUX_API)
163 /*****************************************************************************
164  LINUX SPECIFIC HEADER
165  ****************************************************************************/
166 #include <libusb-1.0/libusb.h>
167 #endif
168 
169 /*****************************************************************************
170  MISC GLOBAL INCLUDES:
171  ****************************************************************************/
172 
173 #include "yfifo.h"
174 #include "yhash.h"
175 #include "ykey.h"
176 #include <stdlib.h>
177 #include <stdarg.h>
178 #include <string.h>
179 #include <ctype.h>
180 
181 /*****************************************************************************
182  MEMORY MANAGEMENT FUNCTION:
183  ****************************************************************************/
184 //#define YSAFE_MEMORY
185 
186 #include "ymemory.h"
187 #ifdef YSAFE_MEMORY
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
192 #undef malloc
193 #undef free
194 #define malloc(size) yForbiden_malloc(size)
195 #define free(ptr) yForbiden_free(ptr)
196 #endif
197 #else
198 #define yMalloc(size) malloc(size)
199 #define yFree(ptr) free(ptr)
200 #define yTracePtr(ptr)
201 #endif
202 
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)
206 
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))
219 #elif defined(WINCE)
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))
225 #else
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))
231 #endif
232 
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
240 char *ystrdup_s(const char *src);
241 YRETCODE ystrcpy_s(char *dst, unsigned dstsize, const char *src);
242 YRETCODE ystrncpy_s(char *dst,unsigned dstsize,const char *src,unsigned len);
243 YRETCODE ystrcat_s(char *dst, unsigned dstsize,const char *src);
244 YRETCODE ystrncat_s(char *dst, unsigned dstsize,const char *src,unsigned len);
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);
248 
249 
250 //#define DEBUG_YAPI_REQ
251 //#define DEBUG_HAL
252 //#define DEBUG_HAL_ENUM
253 //#define DEBUG_DEV_ENUM
254 //#define DEBUG_DEV_ENUM_VERBOSE
255 //#define DEBUG_NET_ENUM
256 //#define DEBUG_NOTIFICATION
257 //#define DEBUG_NET_NOTIFICATION
258 //#define DEBUG_DUMP_PKT
259 //#define DEBUG_USB_TRAFIC
260 //#define TRACE_NET_HUB
261 //#define DEBUG_TRACE_FILE "c:\\tmp\\tracefile.txt"
262 //#define DEBUG_TCP
263 //#define DEBUG_WEBSOCKET
264 //#define TRACE_REQUESTS
265 //#define DEBUG_MISSING_PACKET
266 
267 #define MSC_VS2003 1310
268 
269 #ifdef DEBUG_YAPI_REQ
270 #define YREQLOG dbglog
271 #else
272 #if defined(_MSC_VER)
273 #if (_MSC_VER > MSC_VS2003)
274 #define YREQLOG(fmt,...)
275 #else
276 __forceinline void __YREQLOG(fmt,...){}
277 #define YREQLOG __YREQLOG
278 #endif
279 #else
280 #define YREQLOG(fmt,args...)
281 #endif
282 #endif
283 
284 #ifdef DEBUG_HAL
285 #define HALLOG dbglog
286 #else
287 #if defined(_MSC_VER)
288 #if (_MSC_VER > MSC_VS2003)
289 #define HALLOG(fmt,...)
290 #else
291 __forceinline void __HALLOG(fmt,...){}
292 #define HALLOG __HALLOG
293 #endif
294 #else
295 #define HALLOG(fmt,args...)
296 #endif
297 #endif
298 
299 #ifdef DEBUG_HAL_ENUM
300 #define HALENUMLOG dbglog
301 #else
302 #if defined(_MSC_VER)
303 #if (_MSC_VER > MSC_VS2003)
304 #define HALENUMLOG(fmt,...)
305 #else
306 __forceinline void HALENUMLOG(fmt,...){}
307 #define HALENUMLOG __HALLOG
308 #endif
309 #else
310 #define HALENUMLOG(fmt,args...)
311 #endif
312 #endif
313 
314 #ifdef DEBUG_TCP
315 #define TCPLOG dbglog
316 #else
317 #if defined(_MSC_VER)
318 #if (_MSC_VER > MSC_VS2003)
319 #define TCPLOG(fmt,...)
320 #else
321 __forceinline void __TCPLOG(fmt,...){}
322 #define TCPLOG __TCPLOG
323 #endif
324 #else
325 #define TCPLOG(fmt,args...)
326 #endif
327 #endif
328 
329 #ifdef TRACE_REQUESTS
330 #define REQLOG dbglog
331 #else
332 #if defined(_MSC_VER)
333 #if (_MSC_VER > MSC_VS2003)
334 #define REQLOG(fmt,...)
335 #else
336 __forceinline void __REQLOG(fmt, ...) {}
337 #define REQLOG __REQLOG
338 #endif
339 #else
340 #define REQLOG(fmt,args...)
341 #endif
342 #endif
343 
344 
345 #ifdef DEBUG_DEV_ENUM
346 #define ENUMLOG dbglog
347 #else
348 #if defined(_MSC_VER)
349 #if (_MSC_VER > MSC_VS2003)
350 #define ENUMLOG(fmt,...)
351 #else
352 __forceinline void __ENUMLOG(fmt,...){}
353 #define ENUMLOG __ENUMLOG
354 #endif
355 #else
356 #define ENUMLOG(fmt,args...)
357 #endif
358 #endif
359 
360 #ifdef DEBUG_NET_ENUM
361 #define NETENUMLOG dbglog
362 #else
363 #if defined(_MSC_VER)
364 #if (_MSC_VER > MSC_VS2003)
365 #define NETENUMLOG(fmt,...)
366 #else
367 __forceinline void __NETENUMLOG(fmt,...){}
368 #define NETENUMLOG __NETENUMLOG
369 #endif
370 #else
371 #define NETENUMLOG(fmt,args...)
372 #endif
373 #endif
374 
375 
376 
377 #ifdef DEBUG_WEBSOCKET
378 #define WSLOG dbglog
379 #else
380 #if defined(_MSC_VER)
381 #if (_MSC_VER > MSC_VS2003)
382 #define WSLOG(fmt,...)
383 #else
384 __forceinline void __WSLOG(fmt, ...) {}
385 #define WSLOG __WSLOG
386 #endif
387 #else
388 #define WSLOG(fmt,args...)
389 #endif
390 #endif
391 
392 
393 
394 
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__)
400 #else
401 __forceinline int __dbglog(const char* fmt,...) {
402  int len;
403  va_list args;
404 
405  va_start( args, fmt );
406  len = vdbglogf("vs2003",__LINE__,fmt,args);
407  va_end(args);
408  return len;
409 }
410 #define dbglog __dbglog
411 #endif
412 #else
413 #define dbglog(args...) dbglogf(__FILE_ID__,__LINE__, ## args)
414 #endif
415 
416 
417 #ifdef DEBUG_DUMP_PKT
418 void dumpAnyPacket(char *prefix,int ifaceno,USB_Packet *pkt);
419 #endif
420 
421 
422 #define STRINGIFY(x) #x
423 #define TOSTRING(x) STRINGIFY(x)
424 
425 /*****************************************************************************
426  MISC DEFINITION
427  ****************************************************************************/
428 #ifdef WINDOWS_API
429 #define yApproximateSleep(ms) Sleep(ms)
430 #else
431 #include <unistd.h>
432 #include <stdio.h>
433 #define yApproximateSleep(ms) usleep(ms*1000)
434 #endif
435 //secure fopen
436 #if defined(_MSC_VER) && (_MSC_VER > MSC_VS2003)
437 #define YFOPEN(f,filename,mode) fopen_s(f,filename,mode)
438 #else
439 #include <stdio.h>
440 int YFOPEN(FILE** f, const char *filename, const char *mode);
441 #endif
442 
443 #if 0
444 #if defined(WINDOWS_API) && (_MSC_VER)
445 #define YDEBUG_BREAK { __debugbreak();}
446 #else
447 #define YDEBUG_BREAK {__asm__("int3");}
448 #endif
449 #else
450 #define YDEBUG_BREAK {}
451 #endif
452 
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);
463 
464 
465 /*****************************************************************************
466  OLD version fo protocol that are supported
467 ****************************************************************************/
468 
469 #define YPKT_VERSION_ORIGINAL_RELEASE 0x0202
470 
471 /*****************************************************************************
472  PERFORMANCE TEST DEFINITIONS (very old)
473 ****************************************************************************/
474 typedef struct
475 {
477  u64 count;
478  u64 leave;
479  u64 tmp;
480 } yPerfMon;
481 
482 void dumpYPerfEntry(yPerfMon *entry,const char *name);
483 
484 
485 /*****************************************************************************
486  INTERNAL STRUCTURES and DEFINITIONS
487 ****************************************************************************/
488 
489 // MISC packet definitions
490 #pragma pack(push,1)
491 typedef struct{
492  u8 dummy;
494 } OS_USB_Packet;
495 #pragma pack(pop)
496 
497 
498 #if defined(LINUX_API)
499 typedef struct {
500  struct _yInterfaceSt *iface;
501  struct libusb_transfer *tr;
502  USB_Packet tmppkt;
503 } linRdTr;
504 #endif
505 
506 // packet queue stuff
507 typedef struct _pktItem{
509 #ifdef DEBUG_PKT_TIMING
510  u64 time;
511  u64 ospktno;
512 #endif
513  struct _pktItem *next;
514 } pktItem;
515 
516 
517 typedef struct {
520  int count;
522  u64 totalPop;
524  char errmsg[YOCTO_ERRMSG_LEN];
528 } pktQueue;
529 
530 //pktQueue Helpers
531 void yPktQueueInit(pktQueue *q);
532 void yPktQueueFree(pktQueue *q);
533 void yPktQueueSetError(pktQueue *q,YRETCODE code, const char * msg);
534 
535 #ifdef OSX_API
536 
537 typedef struct {
538  IOHIDManagerRef manager;
539  yCRITICAL_SECTION hidMCS;
540 } OSX_HID_REF;
541 
542 #endif
543 
544 #ifdef WINDOWS_UWP_API
545 typedef struct _uwp_enum_item {
546  u16 vendorid;
547  u16 devicid;
548  //String ^serial;
549  //String ^id;
550 } uwp_enum_item;
551 #endif
552 
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
558 
559 #define YWIN_EVENT_READ 0
560 #define YWIN_EVENT_INTERRUPT 1
561 
562 typedef struct _yInterfaceSt {
563  u16 vendorid;
564  u16 deviceid;
565  u16 ifaceno;
567  char serial[YOCTO_SERIAL_LEN*2];
568  struct {
569  u32 yyySetupDone:1;
570  } flags;
573 #if defined(WINDOWS_API)
574  char devicePath[WIN_DEVICE_PATH_LEN];
575  yThread io_thread;
576  HANDLE wrHDL;
577  OVERLAPPED rdOL;
578  HANDLE rdHDL;
579  HANDLE EV[2];
580  u32 rdpending;
581  OS_USB_Packet tmpd2hpkt;
582  OS_USB_Packet tmph2dpkt;
583 #elif defined(OSX_API)
584  OSX_HID_REF hid;
585  CFStringRef run_loop_mode;
586  IOHIDDeviceRef devref;
587  USB_Packet tmprxpkt;
588 #elif defined(LINUX_API)
589  libusb_device *devref;
590  libusb_device_handle *hdl;
591  u8 rdendp;
592  u8 wrendp;
593  linRdTr *rdTr;
594  linRdTr *wrTr;
595  int ioError;
596 #endif
597 } yInterfaceSt;
598 
599 YRETCODE yPktQueuePushD2H(yInterfaceSt *iface,const USB_Packet *pkt, char * errmsg);
600 YRETCODE yPktQueueWaitAndPopD2H(yInterfaceSt *iface,pktItem **pkt,int ms,char * errmsg);
601 YRETCODE yPktQueuePushH2D(yInterfaceSt *iface,const USB_Packet *pkt, char * errmsg);
604 
605 #define NBMAX_INTERFACE_PER_DEV 1
606 typedef enum
607 {
608  YDEV_UNPLUGGED=0, // device has been plugged by the past but is no more
609  // -> YDEV_WORKING or YDEV_NOTRESPONDING
610  YDEV_WORKING, // device is plugged and running
611  // -> YDEV_UNPLUGGED
612  YDEV_NOTRESPONDING // device has not repsond to StartDevice and we will never try to speak with it
613  // -> none
614 } YDEV_STATUS;
615 
616 
617 typedef enum
618 {
623 } YENU_ACTION;
624 
625 typedef enum
626 {
628  YRUN_AVAIL, // device is available for a request
629  YRUN_REQUEST, // device has be reserved for a request
630  YRUN_BUSY, // device is doing IO for the request
631  YRUN_IDLE, // device is doing IO for the idle thread
632  YRUN_ERROR, // device has been stopped because an IO error
633 } YRUN_STATUS;
634 
635 typedef enum
636 {
642 } YHTTP_STATUS;
643 
644 
645 // structure that contain generic device information (usb and netowrk)
646 #define DEVGEN_LOG_ACTIVATED 1u
647 #define DEVGEN_LOG_PENDING 2u
648 #define DEVGEN_LOG_PULLING 4u
649 typedef struct _yGenericDeviceSt {
650  yStrRef serial; // set only once at init -> no need to use the mutex
651  u32 flags;
655  double deviceTime;
657 
658 void initDevYdxInfos(int devYdxy, yStrRef serial);
659 void freeDevYdxInfos(int devYdx);
660 
661 
662 #define YIO_REMOTE_CLOSE 1u
663 
664 typedef struct{
665  u8 flags;
666  u64 timeout;
669  void *context;
670 } USB_HDL;
671 
672 #define NB_MAX_STARTUP_RETRY 5u
673 
674 #define NEXT_YPKT_NO(current) ((current+1)& YPKTNOMSK)
675 #define NEXT_IFACE_NO(current,total) (current+1<total?current+1:0)
676 
677 // structure that contain all information about a device
678 typedef struct _yPrivDeviceSt{
680  YUSBDEV yhdl; // unique YHANDLE to identify device during execution
681  YDEV_STATUS dStatus; // detection status
682  YENU_ACTION enumAction; // action to triger at end of enumeration
683  YRUN_STATUS rstatus; // running status of the device (valid only on working dev)
684  char errmsg[YOCTO_ERRMSG_LEN];
685  unsigned int nb_startup_retry;
689  yDeviceSt infos; // device infos
699  char *replybuf; // Used to buffer request result
700  int replybufsize; // allocated size of replybuf
705 } yPrivDeviceSt;
706 
707 
708 typedef void (*yDevInfoCallback)(const yDeviceSt *infos);
709 typedef void (*yNotificCallback)(const char *serial, const char *funcid, const char *funcname, const char *funcval);
710 
711 typedef enum {
717 
718 typedef enum {
724 } NET_HUB_STATE;
725 
726 // If made bigger than 255, change plenty of u8 into u16 and pray
727 #define MAX_YDX_PER_HUB 255
728 #define ALLOC_YDX_PER_HUB 256
729 // NetHubSt flags
730 //#define NETH_F_MANDATORY 1
731 //#define NETH_F_SEND_PING_NOTIFICATION 2
732 
733 #define NET_HUB_NOT_CONNECTION_TIMEOUT (6*1024)
734 
735 typedef struct _HTTPNetHubSt {
736  // the following fields are for the notification helper thread only
738  // the following fields are used by hub net enum and notification helper thread
739  u64 lastTraffic; // time of the last data received on the notification socket (in ms)
740  // the following fields are used for authentication to the hub, and require mutex access
741  char *s_user;
742  char *s_realm;
743  char *s_pwd;
744  char *s_nonce;
745  char *s_opaque;
746  u8 s_ha1[16]; // computed when realm is received if pwd is not NULL
747  u32 nc; // reset each time a new nonce is received
748 } HTTPNetHub;
749 
750 
751 
753 {
759 };
760 
761 typedef struct _WSChanSt {
768 }WSChanSt;
769 
770 typedef struct _WSNetHubSt {
771  enum WS_BASE_STATE base_state;
772  enum WS_BASE_STATE strym_state;
773  char serial[YOCTO_SERIAL_LEN];
774  char websocket_key[32];
778  u32 nounce;
795 } WSNetHub;
796 
797 
798 typedef struct _HubSt {
799  yUrlRef url; // hub base URL, or INVALID_HASH_IDX if unused
800  // misc flag that are maped to int for efficency and thread safety
804  int writeProtected; // admin password detected
808  char *name;
811  yFifoBuf not_fifo; // notification fifo
812  u8 not_buffer[1024]; // buffer for the fifo
815  u64 lastAttempt; // time of the last connection attempt (in ms)
816  u64 attemptDelay; // delay until next attemps (in ms)
818  u8 devYdxMap[ALLOC_YDX_PER_HUB]; // maps hub's internal devYdx to our WP devYdx //fixme:
819  int errcode; // in case an error occured
820  char errmsg[YOCTO_ERRMSG_LEN];
821  yCRITICAL_SECTION access; // CS for field that need to be protected agains concurency (these filed start with cs_
822  // implementations specific struct
825 } HubSt;
826 
827 
828 #define TCPREQ_KEEPALIVE 1
829 #define TCPREQ_IN_USE 2
830 
831 
832 typedef struct _HTTPReqSt {
833  YSOCKET skt; // socket used to talk to the device
834  YSOCKET reuseskt; // socket to reuse for next query, when keepalive is true
835 } HTTPReqSt;
836 
837 typedef struct _WSReqSt
838 {
839  int channel;
840  int asyncId;
841  u32 iohdl;
842  struct _RequestSt *next;
843  u8* requestbuf; // Used to store the request to send
844  int requestsize; // the size of the request
845  int requestpos; // the pos of the request that need to be sent
848 } WSReqSt;
849 
850 typedef enum
851 {
853 } RequestState;
854 
855 typedef void(*RequestProgress)(void *context, u32 acked, u32 totalbytes);
856 
857 
858 typedef struct _RequestSt {
859  HubSt *hub; // pointer to the NetHubSt handling the device
861  yEvent finished; // event seted when this request can be reused
862  RequestState state; // state of the request (fixme: currenty only use by WS)
863  char *headerbuf; // Used to store all lines of the HTTP header (with the double \r\n)
864  int headerbufsize; // allocated size of requestbuf
865  char *bodybuf; // Used to store the body of the POST request
866  int bodybufsize; // allocated size of the body of the POST request
867  int bodysize; // effective size of the body of the POST request
868  u8 *replybuf; // Used to buffer request result
869  int replybufsize; // allocated size of replybuf
870  int replysize; // write pointer within replybuf
871  int replypos; // read pointer within replybuf; -1 when not ready to start reading
872  int retryCount; // number of authorization attempts
873  int errcode; // in case an error occured
874  char errmsg[YOCTO_ERRMSG_LEN];
875  u64 open_tm; // timestamp of the start of a connection used to detect timout of the device
876  // (must be reset if we reuse the socket)
877  u64 write_tm; // timestamp of the last successfully write of the request
878  u64 read_tm; // timestamp of the last received packet (must be reset if we reuse the socket)
879  u64 timeout_tm; // the maximum time to live of this connection
880  u32 flags; // flags for keepalive and no expiration
881  yAsbUrlProto proto; // the type of protocol used for this request (same information as the one contained in the hub url)
883  void *context;
885  void *progressCtx;
888 } RequestSt;
889 
890 #define SETUPED_IFACE_CACHE_SIZE 128
891 
892 
893 typedef struct {
894  char *serial;
896  u8 *settings;
899  int global_progress; //-1:error 0-99:working 100:success
900  char global_message[YOCTO_ERRMSG_LEN]; // the last message or the error
901  const char* fileid;
902  int line;
904 
905 
906 typedef struct _YIOHDL_internal {
908  u64 ioid;
909  u8 type;
910  u8 pad8;
911  u16 pad16;
912  union {
916  };
918 
919 
920 #define YCTX_OSX_MULTIPLES_HID 1
921 // structure that contain information about the API
922 typedef struct{
923  //yapi CS
927  // global inforation on all devices
930  // usb stuff
935  int nbdevs;
940  // network discovery info
942  RequestSt* tcpreq[ALLOC_YDX_PER_HUB]; // indexed by our own DevYdx
948  // SSDP stuff
949  SSDPInfos SSDP; // socket used to talk to the device
950  // Public callbacks
959  // Programing api
961  // OS specifics variables
963 #if defined(WINDOWS_API)
964  HANDLE apiLock;
965  HANDLE nameLock;
966  yCRITICAL_SECTION prevEnum_cs;
967  int prevEnumCnt;
968  yInterfaceSt *prevEnum;
969 #ifdef WINDOWS_WIN32_API
970  win_hid_api hid;
971  win_reg_api registry;
972 #endif
973 #elif defined(OSX_API)
974  u32 osx_flags;
975  OSX_HID_REF hid;
976  CFRunLoopRef usb_run_loop;
977  pthread_t usb_thread;
978  USB_THREAD_STATE usb_thread_state;
979 #elif defined(LINUX_API)
980  yCRITICAL_SECTION string_cache_cs;
981  libusb_context *libusb;
982  pthread_t usb_thread;
983  USB_THREAD_STATE usb_thread_state;
984 #endif
985  } yContextSt;
986 
987 #define TRACEFILE_NAMELEN 512
988 
989 extern char ytracefile[];
990 extern yContextSt *yContext;
991 
992 YRETCODE yapiPullDeviceLogEx(int devydx);
993 YRETCODE yapiPullDeviceLog(const char *serial);
994 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);
995 
996 /*****************************************************************
997  * PLATFORM SPECIFIC USB code
998 *****************************************************************/
999 
1000 
1001 // for devices detection
1002 int yyyUSB_init(yContextSt *ctx, char *errmsg);
1003 int yyyUSB_stop(yContextSt *ctx, char *errmsg);
1004 int yyyUSBGetInterfaces(yInterfaceSt **ifaces,int *nbifaceDetect,char *errmsg);
1005 int yyyOShdlCompare(yPrivDeviceSt *dev, yInterfaceSt *newiface);
1006 int yyySetup(yInterfaceSt *iface,char *errmsg);
1007 YRETCODE yyySendPacket( yInterfaceSt *iface,const USB_Packet *pkt,char *errmsg);
1008 int yyySignalOutPkt(yInterfaceSt *iface, char *errmsg);
1009 // close all stuff of setup
1010 void yyyPacketShutdown(yInterfaceSt *iface);
1011 
1012 
1013 /*****************************************************************************
1014  ENUMERATION RELATED FUNCTION
1015 ******************************************************************************/
1016 
1017 //some early declarations
1018 void wpSafeRegister(HubSt *hub, u8 devYdx, yStrRef serialref,yStrRef lnameref, yStrRef productref, u16 deviceid, yUrlRef devUrl,s8 beacon);
1019 void wpSafeUpdate(HubSt *hub, u8 devYdx, yStrRef serialref,yStrRef lnameref, yUrlRef devUrl, s8 beacon);
1020 void wpSafeUnregister(yStrRef serialref);
1021 
1022 void ypUpdateUSB(const char *serial, const char *funcid, const char *funcname, int funclass, int funydx, const char *funcval);
1023 void ypUpdateYdx(int devydx, Notification_funydx funInfo, const char *funcval);
1024 void ypUpdateHybrid(const char *serial, Notification_funydx funInfo, const char *funcval);
1025 
1026 /*****************************************************************
1027  * yStream API with cycling logic and yyPacket API
1028 *****************************************************************/
1029 
1030 /**********************************************************************
1031  GENERIC DEVICE LIST FUNCTION
1032  **********************************************************************/
1033 
1034 // return the yDeviceSt *from a matching string (serial or name)
1035 #define FIND_FROM_SERIAL 1
1036 #define FIND_FROM_NAME 2
1037 #define FIND_FROM_ANY (FIND_FROM_SERIAL|FIND_FROM_NAME)
1038 yPrivDeviceSt *findDev(const char *str,u32 flags);
1039 
1040 
1041 // return the YHANDLE from a matching string (serial or name)
1042 YUSBDEV findDevHdlFromStr(const char *str);
1044 void devHdlInfo(YUSBDEV hdl,yDeviceSt *infos);
1045 
1046 YRETCODE yUSBUpdateDeviceList(char *errmsg);
1047 void yUSBReleaseAllDevices(void);
1048 
1049 /*****************************************************************************
1050  USB REQUEST FUNCTIONS
1051  ***************************************************************************/
1052 
1053 int yUsbInit(yContextSt *ctx,char *errmsg);
1054 int yUsbFree(yContextSt *ctx,char *errmsg);
1055 int yUsbIdle(void);
1056 int yUsbTrafficPending(void);
1058 
1059 int yUsbOpenDevDescr(YIOHDL_internal *ioghdl, yStrRef devdescr, char *errmsg);
1060 int yUsbOpen(YIOHDL_internal *ioghdl, const char *device, char *errmsg);
1061 int yUsbSetIOAsync(YIOHDL_internal *ioghdl, yapiRequestAsyncCallback callback, void *context, char *errmsg);
1062 int yUsbWrite(YIOHDL_internal *ioghdl, const char *buffer, int writelen,char *errmsg);
1063 int yUsbReadNonBlock(YIOHDL_internal *ioghdl, char *buffer, int len,char *errmsg);
1064 int yUsbReadBlock(YIOHDL_internal *ioghdl, char *buffer, int len,u64 blockUntil,char *errmsg);
1065 int yUsbEOF(YIOHDL_internal *ioghdl,char *errmsg);
1066 int yUsbClose(YIOHDL_internal *ioghdl,char *errmsg);
1067 
1068 int yUSBGetBooloader(const char *serial, const char * name, yInterfaceSt *iface,char *errmsg);
1069 
1070 // Misc helper
1071 int handleNetNotification(HubSt *hub);
1072 u32 yapiGetCNonce(u32 nc);
1073 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);
1074 YRETCODE yapiHTTPRequestSyncDone_internal(YIOHDL *iohdl, char *errmsg);
1075 void yFunctionUpdate(YAPI_FUNCTION fundescr, const char *value);
1076 void yFunctionTimedUpdate(YAPI_FUNCTION fundescr, double deviceTime, const u8 *report, u32 len);
1077 int yapiJsonGetPath_internal(const char *path, const char *json_data, int json_size, int withHTTPheader, const char **output, char *errmsg);
1078 #endif
yUrlRef url
Definition: yproto.h:799
int yUsbReadBlock(YIOHDL_internal *ioghdl, char *buffer, int len, u64 blockUntil, char *errmsg)
Definition: ystream.c:2728
struct _yGenericDeviceSt yGenericDeviceSt
pktItem tmptxpkt
Definition: yproto.h:695
int yUsbOpen(YIOHDL_internal *ioghdl, const char *device, char *errmsg)
Definition: ystream.c:2566
int yvsprintf_s(char *dst, unsigned dstsize, const char *fmt, va_list arg)
Definition: ymemory.c:357
int yUsbReadNonBlock(YIOHDL_internal *ioghdl, char *buffer, int len, char *errmsg)
Definition: ystream.c:2684
u64 first_write_tm
Definition: yproto.h:846
#define NBMAX_NET_HUB
Definition: yproto.h:553
struct _yPrivDeviceSt yPrivDeviceSt
pktItem * last
Definition: yproto.h:519
u32 uploadRate
Definition: yproto.h:791
int rw_access
Definition: yproto.h:801
int mandatory
Definition: yproto.h:803
int yUsbEOF(YIOHDL_internal *ioghdl, char *errmsg)
Definition: ystream.c:2771
YSOCKET skt
Definition: yproto.h:833
yCRITICAL_SECTION acces_state
Definition: yproto.h:679
yCRITICAL_SECTION access
Definition: yproto.h:821
void ypUpdateHybrid(const char *serial, Notification_funydx funInfo, const char *funcval)
Definition: ystream.c:300
u8 * replybuf
Definition: yproto.h:868
yStrRef user
Definition: yproto.h:779
void YAPI_FUNCTION_EXPORT(* yapiDeviceUpdateCallback)(YAPI_DEVICE devdescr)
Definition: yapi.h:68
YSOCKET skt
Definition: yproto.h:782
yStrRef pass
Definition: yproto.h:780
u64 lastTraffic
Definition: yproto.h:739
int bodysize
Definition: yproto.h:867
void * yCRITICAL_SECTION
Definition: ydef.h:366
YIOHDL_internal * yiohdl_first
Definition: yproto.h:938
void ypUpdateUSB(const char *serial, const char *funcid, const char *funcname, int funclass, int funydx, const char *funcval)
Definition: ystream.c:255
void dumpYPerfEntry(yPerfMon *entry, const char *name)
Definition: ystream.c:2353
int nbdevs
Definition: yproto.h:935
u8 flags
Definition: yproto.h:665
int yUSBGetBooloader(const char *serial, const char *name, yInterfaceSt *iface, char *errmsg)
Definition: yprog.c:463
u64 attemptDelay
Definition: yproto.h:816
void * YIOHDL
Definition: ydef.h:260
struct _RequestSt * requests
Definition: yproto.h:767
yFifoBuf logFifo
Definition: yproto.h:653
u64 devListExpires
Definition: yproto.h:817
s32 YAPI_FUNCTION
Definition: ydef.h:217
yHash yStrRef
Definition: ydef.h:214
YRETCODE ystrcpy_s(char *dst, unsigned dstsize, const char *src)
Definition: ymemory.c:277
yFifoBuf mainfifo
Definition: yproto.h:783
int replysize
Definition: yproto.h:870
YRETCODE yPktQueueWaitAndPopD2H(yInterfaceSt *iface, pktItem **pkt, int ms, char *errmsg)
Definition: ystream.c:1128
YRETCODE yPktQueuePushH2D(yInterfaceSt *iface, const USB_Packet *pkt, char *errmsg)
Definition: ystream.c:1145
yCRITICAL_SECTION access
Definition: yproto.h:860
yHash yUrlRef
Definition: ydef.h:215
USB_Packet pkt
Definition: yproto.h:493
void yUSBReleaseAllDevices(void)
Definition: ystream.c:2182
yStrRef serial
Definition: yproto.h:805
USB_Packet pkt
Definition: yproto.h:508
void initDevYdxInfos(int devYdxy, yStrRef serial)
Definition: yapi.c:379
u32 tcpRoundTripTime
Definition: yproto.h:789
struct _HubSt HubSt
u64 count
Definition: yproto.h:477
yCRITICAL_SECTION handleEv_cs
Definition: yproto.h:925
u64 timeout_tm
Definition: yproto.h:879
u64 timeout
Definition: yproto.h:666
YDEV_STATUS dStatus
Definition: yproto.h:681
yapiDeviceUpdateCallback arrivalCallback
Definition: yproto.h:953
int websocket_key_len
Definition: yproto.h:775
int yUsbClose(YIOHDL_internal *ioghdl, char *errmsg)
Definition: ystream.c:2811
u64 bws_read_tm
Definition: yproto.h:786
void * context
Definition: yproto.h:669
yEvent emptyEvent
Definition: yproto.h:527
int FusionErrmsg(int code, char *errmsg, const char *generr, const char *detailerr)
Definition: ystream.c:112
u64 tmp
Definition: yproto.h:479
void wpSafeUpdate(HubSt *hub, u8 devYdx, yStrRef serialref, yStrRef lnameref, yUrlRef devUrl, s8 beacon)
Definition: yapi.c:659
NET_HUB_STATE
Definition: yproto.h:718
RequestState
Definition: yproto.h:850
yDeviceSt infos
Definition: yproto.h:689
u64 bws_timeout_tm
Definition: yproto.h:785
int yUsbFree(yContextSt *ctx, char *errmsg)
Definition: ystream.c:2410
yContextSt * yContext
Definition: ystream.c:59
int requestpos
Definition: yproto.h:845
pktItem * curtxpkt
Definition: yproto.h:693
int yapiJsonGetPath_internal(const char *path, const char *json_data, int json_size, int withHTTPheader, const char **output, char *errmsg)
Definition: yapi.c:3912
u64 bws_open_tm
Definition: yproto.h:784
void(* RequestProgress)(void *context, u32 acked, u32 totalbytes)
Definition: yproto.h:855
void(* yapiRequestProgressCallback)(void *context, u32 acked, u32 totalbytes)
Definition: ydef.h:866
yPrivDeviceSt * findDev(const char *str, u32 flags)
Definition: ystream.c:2269
struct _HTTPReqSt HTTPReqSt
YUSBIO hdl
Definition: yproto.h:914
u32 iohdl
Definition: yproto.h:841
u8 * fifo_buffer
Definition: yproto.h:793
#define MAX_ASYNC_TCPCHAN
Definition: ydef.h:771
yEvent notEmptyEvent
Definition: yproto.h:526
yapiFunctionUpdateCallback functionCallback
Definition: yproto.h:956
struct _YIOHDL_internal YIOHDL_internal
char * s_realm
Definition: yproto.h:742
void devHdlInfo(YUSBDEV hdl, yDeviceSt *infos)
Definition: ystream.c:2334
yPrivDeviceSt * findDevFromIOHdl(YIOHDL_internal *hdl)
Definition: ystream.c:2310
u32 remoteNounce
Definition: yproto.h:777
int yyySetup(yInterfaceSt *iface, char *errmsg)
yRawReportV2Cb rawReportV2Cb
Definition: yproto.h:945
int ySetErr(int code, char *outmsg, const char *erreur, const char *file, u32 line)
Definition: ystream.c:72
int writeProtected
Definition: yproto.h:804
int yyyUSBGetInterfaces(yInterfaceSt **ifaces, int *nbifaceDetect, char *errmsg)
u64 lastUploadAckTime
Definition: yproto.h:763
struct _RequestSt * openRequests
Definition: yproto.h:794
#define YOCTO_SERIAL_LEN
Definition: ydef.h:420
YRETCODE ystrncat_s(char *dst, unsigned dstsize, const char *src, unsigned len)
Definition: ymemory.c:337
yCRITICAL_SECTION functionCallbackCS
Definition: yproto.h:947
HTTPReqSt http
Definition: yproto.h:886
#define YOCTO_ERRMSG_LEN
Definition: ydef.h:418
YUSBIO hdl
Definition: yproto.h:667
void(* yDevInfoCallback)(const yDeviceSt *infos)
Definition: yproto.h:708
struct _pktItem pktItem
struct _RequestSt RequestSt
#define WIN_DEVICE_PATH_LEN
Definition: yproto.h:555
Definition: yproto.h:798
YHTTP_STATUS
Definition: yproto.h:635
yCRITICAL_SECTION cs
Definition: yproto.h:525
int retryCount
Definition: yproto.h:813
void yFunctionTimedUpdate(YAPI_FUNCTION fundescr, double deviceTime, const u8 *report, u32 len)
Definition: yapi.c:237
YRETCODE yPktQueuePopH2D(yInterfaceSt *iface, pktItem **pkt)
Definition: ystream.c:1176
u64 totalPop
Definition: yproto.h:522
void wpSafeUnregister(yStrRef serialref)
Definition: yapi.c:703
int yyyUSB_init(yContextSt *ctx, char *errmsg)
int pktAckDelay
Definition: yproto.h:697
#define SETUPED_IFACE_CACHE_SIZE
Definition: yproto.h:890
u64 totalPush
Definition: yproto.h:521
int replybufsize
Definition: yproto.h:869
char * bodybuf
Definition: yproto.h:865
Definition: yfifo.h:59
char ytracefile[]
Definition: ystream.c:64
YDEV_STATUS
Definition: yproto.h:606
u32 notifAbsPos
Definition: yproto.h:814
yCRITICAL_SECTION deviceCallbackCS
Definition: yproto.h:946
WS_BASE_STATE
Definition: yproto.h:752
YRETCODE
Definition: ydef.h:376
int retryCount
Definition: yproto.h:872
yCRITICAL_SECTION io_cs
Definition: yproto.h:937
YRETCODE status
Definition: yproto.h:523
int yUsbSetIOAsync(YIOHDL_internal *ioghdl, yapiRequestAsyncCallback callback, void *context, char *errmsg)
Definition: ystream.c:2602
HubSt * hub
Definition: yproto.h:859
#define HALENUMLOG(fmt, args...)
Definition: yproto.h:310
pktItem * currxpkt
Definition: yproto.h:691
int yUsbIdle(void)
Definition: ystream.c:2441
NET_HUB_STATE state
Definition: yproto.h:810
FUpdateContext fuCtx
Definition: yproto.h:960
yAsbUrlProto proto
Definition: yproto.h:809
yapiTimedReportCallback timedReportCallback
Definition: yproto.h:957
u32 lastUtcUpdate
Definition: yproto.h:690
int yyySignalOutPkt(yInterfaceSt *iface, char *errmsg)
u8 * settings
Definition: yproto.h:896
u64 next_startup_attempt
Definition: yproto.h:686
u64 totaltime
Definition: yproto.h:476
pktQueue txQueue
Definition: yproto.h:572
void YAPI_FUNCTION_EXPORT(* yapiTimedReportCallback)(YAPI_FUNCTION fundesc, double timestamp, const u8 *bytes, u32 len)
Definition: yapi.h:78
u64 read_tm
Definition: yproto.h:878
void * progressCtx
Definition: yproto.h:885
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)
Definition: yapi.c:3189
int vdbglogf(const char *fileid, int line, const char *fmt, va_list args)
Definition: ystream.c:189
s32 YUSBIO
Definition: ydef.h:238
char * serial
Definition: yproto.h:894
char * name
Definition: yproto.h:808
yCRITICAL_SECTION updateDev_cs
Definition: yproto.h:924
char * s_opaque
Definition: yproto.h:745
WSNetHub ws
Definition: yproto.h:824
u64 lastAttempt
Definition: yproto.h:815
yInterfaceSt iface
Definition: yproto.h:698
RequestSt * ws
Definition: yproto.h:915
void yPktQueueSetError(pktQueue *q, YRETCODE code, const char *msg)
Definition: ystream.c:985
pktQueue rxQueue
Definition: yproto.h:571
yAsbUrlProto proto
Definition: yproto.h:881
yRawNotificationCb rawNotificationCb
Definition: yproto.h:943
pktItem * first
Definition: yproto.h:518
YRETCODE ystrcat_s(char *dst, unsigned dstsize, const char *src)
Definition: ymemory.c:293
RequestState state
Definition: yproto.h:862
WSReqSt ws
Definition: yproto.h:887
int remoteVersion
Definition: yproto.h:776
RequestProgress progressCb
Definition: yproto.h:884
void YAPI_FUNCTION_EXPORT(* yapiFunctionUpdateCallback)(YAPI_FUNCTION fundescr, const char *value)
Definition: yapi.h:75
int settings_len
Definition: yproto.h:897
struct _yInterfaceSt yInterfaceSt
void yFunctionUpdate(YAPI_FUNCTION fundescr, const char *value)
Definition: yapi.c:225
yRawReportCb rawReportCb
Definition: yproto.h:944
YRETCODE ystrncpy_s(char *dst, unsigned dstsize, const char *src, unsigned len)
Definition: ymemory.c:308
int YSOCKET
Definition: ydef.h:236
SSDPInfos SSDP
Definition: yproto.h:949
char * s_pwd
Definition: yproto.h:743
yEvent finished
Definition: yproto.h:861
void * context
Definition: yproto.h:883
YRETCODE yPktQueuePeekH2D(yInterfaceSt *iface, pktItem **pkt)
Definition: ystream.c:1160
USB_THREAD_STATE
Definition: yproto.h:711
u16 ifaceno
Definition: yproto.h:565
yapiDeviceLogCallback logDeviceCallback
Definition: yproto.h:952
void(* yRawNotificationCb)(USB_Notify_Pkt *)
Definition: yapi.h:1054
YUSBDEV yhdl
Definition: yproto.h:680
int dbglogf(const char *fileid, int line, const char *fmt,...)
Definition: ystream.c:222
void(* yRawReportV2Cb)(YAPI_DEVICE serialref, USB_Report_Pkt_V2 *report, int pktsize)
Definition: yapi.h:1056
char * s_user
Definition: yproto.h:741
int yUsbTrafficPending(void)
Definition: ystream.c:2535
struct _YIOHDL_internal * next
Definition: yproto.h:907
int replypos
Definition: yproto.h:871
u32 nounce
Definition: yproto.h:778
u16 deviceid
Definition: yproto.h:564
u32 lastUploadAckBytes
Definition: yproto.h:762
int bodybufsize
Definition: yproto.h:866
int yUsbInit(yContextSt *ctx, char *errmsg)
Definition: ystream.c:2401
yAsbUrlProto
Definition: yhash.h:179
int s_next_async_id
Definition: yproto.h:781
void freeDevYdxInfos(int devYdx)
Definition: yapi.c:388
yapiDeviceUpdateCallback changeCallback
Definition: yproto.h:954
yThread thread
Definition: yproto.h:898
void(* yapiRequestAsyncCallback)(void *context, const u8 *result, u32 resultlen, int retcode, const char *errmsg)
Definition: ydef.h:864
double deviceTime
Definition: yproto.h:655
YRUN_STATUS rstatus
Definition: yproto.h:683
u8 * devYdxMap
Definition: yproto.h:703
USB_HDL pendingIO
Definition: yproto.h:687
YRETCODE yPktQueuePushD2H(yInterfaceSt *iface, const USB_Packet *pkt, char *errmsg)
Definition: ystream.c:1097
YRETCODE yapiPullDeviceLog(const char *serial)
Definition: yapi.c:563
u8 * http_raw_buf
Definition: yproto.h:702
void(* yRawReportCb)(YAPI_DEVICE serialref, USB_Report_Pkt_V1 *report, int pktsize)
Definition: yapi.h:1055
int detecttype
Definition: yproto.h:932
int headerbufsize
Definition: yproto.h:864
int replybufsize
Definition: yproto.h:700
int yUsbWrite(YIOHDL_internal *ioghdl, const char *buffer, int writelen, char *errmsg)
Definition: ystream.c:2628
int send_ping
Definition: yproto.h:802
Definition: ythread.h:61
struct _RequestSt * next
Definition: yproto.h:842
struct _HTTPNetHubSt HTTPNetHub
int count
Definition: yproto.h:520
yPrivDeviceSt * devs
Definition: yproto.h:934
yThread net_thread
Definition: yproto.h:807
YUSBDEV devhdlcount
Definition: yproto.h:933
struct _RequestSt * notReq
Definition: yproto.h:737
yCRITICAL_SECTION generic_cs
Definition: yproto.h:928
YRUN_STATUS
Definition: yproto.h:625
int ymemfind(const u8 *haystack, u32 haystack_len, const u8 *needle, u32 needle_len)
Definition: ymemory.c:373
void YAPI_FUNCTION_EXPORT(* yapiDeviceLogCallback)(YAPI_FUNCTION fundescr, const char *line)
Definition: yapi.h:83
WakeUpSocket wuce
Definition: yproto.h:806
char * replybuf
Definition: yproto.h:699
void YAPI_FUNCTION_EXPORT(* yapiLogFunction)(const char *log, u32 loglen)
Definition: yapi.h:65
void yPktQueueFree(pktQueue *q)
Definition: ystream.c:928
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)
Definition: yapi.c:3348
YHTTP_STATUS httpstate
Definition: yproto.h:688
char * s_nonce
Definition: yproto.h:744
int global_progress
Definition: yproto.h:899
unsigned int nb_startup_retry
Definition: yproto.h:685
int errcode
Definition: yproto.h:873
YSOCKET reuseskt
Definition: yproto.h:834
u64 leave
Definition: yproto.h:478
void yyyPacketShutdown(yInterfaceSt *iface)
yCRITICAL_SECTION enum_cs
Definition: yproto.h:931
yStrRef serial
Definition: yproto.h:650
YENU_ACTION
Definition: yproto.h:617
u64 write_tm
Definition: yproto.h:877
u32 flags
Definition: yproto.h:880
u32 tcpMaxWindowSize
Definition: yproto.h:790
int errcode
Definition: yproto.h:819
yGenericDeviceSt * yUSBGetGenericInfo(yStrRef devdescr)
char * firmwarePath
Definition: yproto.h:895
yFifoBuf http_fifo
Definition: yproto.h:701
const char * fileid
Definition: yproto.h:901
char * headerbuf
Definition: yproto.h:863
u64 next_transmit_tm
Definition: yproto.h:787
yapiRequestAsyncCallback callback
Definition: yproto.h:882
yEvent exitSleepEvent
Definition: yproto.h:926
u64 lastUploadRateTime
Definition: yproto.h:765
int handleNetNotification(HubSt *hub)
Definition: yapi.c:1677
int channel
Definition: yproto.h:839
u64 last_write_tm
Definition: yproto.h:847
int yyyOShdlCompare(yPrivDeviceSt *dev, yInterfaceSt *newiface)
u32 lastUploadRateBytes
Definition: yproto.h:764
int devs_capacity
Definition: yproto.h:936
u16 pkt_version
Definition: yproto.h:566
int yUsbOpenDevDescr(YIOHDL_internal *ioghdl, yStrRef devdescr, char *errmsg)
Definition: ystream.c:2553
struct _WSNetHubSt WSNetHub
YRETCODE yyySendPacket(yInterfaceSt *iface, const USB_Packet *pkt, char *errmsg)
Definition: ystream.c:1199
u64 open_tm
Definition: yproto.h:875
int requestsize
Definition: yproto.h:844
int ysprintf_s(char *dst, unsigned dstsize, const char *fmt,...)
Definition: ymemory.c:298
YRETCODE yapiPullDeviceLogEx(int devydx)
Definition: yapi.c:474
yFifoBuf not_fifo
Definition: yproto.h:811
void YAPI_FUNCTION_EXPORT(* yapiHubDiscoveryCallback)(const char *serial, const char *url)
Definition: yapi.h:81
YRETCODE yUSBUpdateDeviceList(char *errmsg)
Definition: ystream.c:2191
#define ALLOC_YDX_PER_HUB
Definition: yproto.h:728
void(* yNotificCallback)(const char *serial, const char *funcid, const char *funcname, const char *funcval)
Definition: yproto.h:709
u32 yapiGetCNonce(u32 nc)
Definition: yapi.c:2750
char * ystrdup_s(const char *src)
Definition: ymemory.c:284
int asyncId
Definition: yproto.h:840
yapiDeviceUpdateCallback removalCallback
Definition: yproto.h:955
yapiLogFunction log
Definition: yproto.h:951
YRETCODE yapiHTTPRequestSyncDone_internal(YIOHDL *iohdl, char *errmsg)
Definition: yapi.c:3398
yapiHubDiscoveryCallback hubDiscoveryCallback
Definition: yproto.h:958
void ypUpdateYdx(int devydx, Notification_funydx funInfo, const char *funcval)
Definition: ystream.c:286
struct _WSReqSt WSReqSt
s32 YUSBDEV
Definition: ydef.h:239
struct _pktItem * next
Definition: yproto.h:513
struct _WSChanSt WSChanSt
void yPktQueueInit(pktQueue *q)
Definition: ystream.c:919
yCRITICAL_SECTION access
Definition: yproto.h:766
struct _yPrivDeviceSt * next
Definition: yproto.h:704
u16 vendorid
Definition: yproto.h:563
u32 io_counter
Definition: yproto.h:939
yapiRequestAsyncCallback callback
Definition: yproto.h:668
int YFOPEN(FILE **f, const char *filename, const char *mode)
Definition: ystream.c:130
void wpSafeRegister(HubSt *hub, u8 devYdx, yStrRef serialref, yStrRef lnameref, yStrRef productref, u16 deviceid, yUrlRef devUrl, s8 beacon)
Definition: yapi.c:599
YUSBDEV findDevHdlFromStr(const char *str)
Definition: ystream.c:2299
u64 connectionTime
Definition: yproto.h:788
YENU_ACTION enumAction
Definition: yproto.h:682
HTTPNetHub http
Definition: yproto.h:823
u8 * requestbuf
Definition: yproto.h:843


yoctopuce_altimeter
Author(s): Anja Sheppard
autogenerated on Mon Jun 10 2019 15:49:11