1 /* Hey EMACS -*- linux-c -*- */
2 /* $Id$ */
3 
4 /*  libticalcs2 - hand-helds support library, a part of the TiLP project
5  *  Copyright (C) 1999-2005  Romain Liévin
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software Foundation,
19  *  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef __TICALCS__
23 #define __TICALCS__
24 
25 #ifdef HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28 
29 #include <ticables.h>
30 #include <tifiles.h>
31 
32 #include "export3.h"
33 #include <glib.h>
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 	/***********************/
40 	/* Types & Definitions */
41 	/***********************/
42 
43 /* Versioning */
44 
45 #ifdef __WIN32__
46 # define LIBCALCS_VERSION "1.1.9"
47 #else
48 # define LIBCALCS_VERSION VERSION
49 #endif
50 
51 #define LIBCALCS_REQUIRES_LIBTICONV_VERSION	"1.1.5"	// useless with pkg-config
52 #define LIBCALCS_REQUIRES_LIBTIFILES_VERSION	"1.1.0"	// useless with pkg-config
53 #define LIBCALCS_REQUIRES_LIBTICABLES_VERSION	"1.3.5"	// useless with pkg-config
54 
55 /* Types */
56 
57 // Name of the root node for 'Variables' & 'Applications' tree
58 #define VAR_NODE_NAME "Variables"
59 #define APP_NODE_NAME "Applications"
60 
61 #define ERROR_ABORT (256) /* fixed in error.h */
62 #define ERROR_EOT   (262) /* fixed in error.h */
63 
64 /**
65  * CalcScreenFormat:
66  *
67  * An enumeration which contains the following calculator types:
68  **/
69 typedef enum
70 {
71 	SCREEN_FULL,
72 	SCREEN_CLIPPED
73 } CalcScreenFormat;
74 
75 /**
76  * CalcPixelFormat:
77  *
78  * An enumeration which defines the format of screenshot images:
79  */
80 typedef enum
81 {
82 	CALC_PIXFMT_MONO = 1,         // Monochrome (1 bpp)
83 	CALC_PIXFMT_GRAY_4 = 2,       // Grayscale (4 bpp - Nspire)
84 	CALC_PIXFMT_RGB_565_LE = 3,   // RGB (16 bpp little-endian - Nspire CX / 84+CSE / 83PCE / 84+CE)
85 	CALC_PIXFMT_RGB_5_6_5 = 3     // Ditto
86 } CalcPixelFormat;
87 
88 /**
89  * CalcPathType:
90  *
91  * An enumeration which contains the path type:
92  **/
93 typedef enum
94 {
95 	PATH_FULL,
96 	PATH_LOCAL
97 } CalcPathType;
98 
99 /**
100  * CalcMemType:
101  *
102  * An enumeration which contains the different memory sizes:
103  **/
104 typedef enum
105 {
106 	MEMORY_NONE = 0,
107 	MEMORY_FREE = (1<<0),
108 	MEMORY_USED = (1<<1),
109 } CalcMemType;
110 
111 // To clean-up !
112 /**
113  * CalcMode:
114  *
115  * An enumeration which contains different mask modes:
116  **/
117 typedef enum
118 {
119 	MODE_NORMAL = 0,
120 
121 	// For sending vars
122 	MODE_SEND_ONE_VAR  = (1 << 1),   // Send single var or first var of group (TI82/85 only)
123 	MODE_SEND_LAST_VAR = (1 << 2),   // Send last var of group file (TI82/85 only)
124 
125 	MODE_SEND_EXEC_ASM = (1 << 3),   // Send and execute assembly (TI82/85 only; dangerous!)
126 
127 	// Miscellaneous
128 	MODE_LOCAL_PATH    = (1 << 4),   // Local path (full by default)
129 	MODE_BACKUP        = (1 << 5),   // Keep archive attribute
130 } CalcMode;
131 
132 /**
133  * CalcRomDumpSize:
134  *
135  * An enumeration which contains the following ROM dump sizes:
136  **/
137 typedef enum
138 {
139 	ROMSIZE_AUTO  = 0,
140 	ROMSIZE_48KB  = 48,     /* TI-80 */
141 	ROMSIZE_128KB = 128,    /* TI-82, TI-85 */
142 	ROMSIZE_256KB = 256,    /* TI-83, TI-86 */
143 	ROMSIZE_512KB = 512,    /* TI-83+ */
144 	ROMSIZE_1MB   = 1024,   /* TI-84+, TI-92, TI-82A */
145 	ROMSIZE_2MB   = 2048,   /* TI-83+SE, TI-84+SE, TI-89, TI-92 II, TI-92+, TI-84+T */
146 	ROMSIZE_4MB   = 4096,   /* TI-84+CSE, TI-89T, V200, TI-83PCE, TI-84+CE */
147 } CalcDumpSize;
148 
149 /**
150  * CalcShellType:
151  *
152  * An enumeration which contains the shell to use with ROM dumping:
153  **/
154 typedef enum
155 {
156 	SHELL_NONE = 4,
157 	SHELL_USGARD,
158 	SHELL_ZSHELL
159 } CalcShellType;
160 
161 /**
162  * CalcProductIDs:
163  *
164  * An enumeration which contains the product IDs used by TI graphing calculators:
165  **/
166 typedef enum
167 {
168 	PRODUCT_ID_NONE = 0x00,
169 	PRODUCT_ID_TI92P = 0x01,
170 	PRODUCT_ID_TI73 = 0x02,
171 	PRODUCT_ID_TI89 = 0x03,
172 	PRODUCT_ID_TI83P = 0x04,
173 	// No known calculator uses 0x05
174 	// No known calculator uses 0x06
175 	// No known calculator uses 0x07
176 	PRODUCT_ID_TIV200 = 0x08,
177 	PRODUCT_ID_TI89T = 0x09,
178 	PRODUCT_ID_TI84P = 0x0A,
179 	PRODUCT_ID_TI82A = 0x0B,
180 	PRODUCT_ID_NSPIRE_CAS = 0x0C, // The Nspire CAS+ prototypes also uses 0x0C, but libti*/tilp do not handle their unique communication protocol.
181 	PRODUCT_ID_LABCRADLE = 0x0D, // Included for completeness, not handled by libticalcs.
182 	PRODUCT_ID_NSPIRE_NONCAS = 0x0E,
183 	PRODUCT_ID_NSPIRE_CX_CAS = 0x0F, // Yes, two completely different models use ID 0x0F.
184 	PRODUCT_ID_TI84PCSE = 0x0F,
185 	PRODUCT_ID_NSPIRE_CX_NONCAS = 0x10,
186 	PRODUCT_ID_NSPIRE_CM_CAS = 0x11,
187 	PRODUCT_ID_NSPIRE_CM_NONCAS = 0x12,
188 	PRODUCT_ID_TI83PCE = 0x13, // These two similar models use the same ID as well.
189 	PRODUCT_ID_TI84PCE = 0x13,
190 	PRODUCT_ID_TI84PT = 0x1B
191 } CalcProductIDs;
192 
193 /**
194  * CalcOperations:
195  *
196  * An enumeration which contains the different supported operations:
197  **/
198 typedef enum
199 {
200 	FTS_NONE = 0,
201 
202 	OPS_ISREADY     = (1 << 0),
203 	OPS_KEYS        = (1 << 1),
204 	OPS_SCREEN      = (1 << 2),
205 	OPS_DIRLIST     = (1 << 3),
206 	OPS_BACKUP      = (1 << 4),
207 	OPS_VARS        = (1 << 5),
208 	OPS_FLASH       = (1 << 6),
209 	OPS_IDLIST      = (1 << 7),
210 	OPS_CLOCK       = (1 << 8),
211 	OPS_ROMDUMP     = (1 << 9),
212 	OPS_VERSION     = (1 << 10),
213 	OPS_NEWFLD      = (1 << 11),
214 	OPS_DELVAR      = (1 << 12),
215 	OPS_OS          = (1 << 13),
216 	OPS_RENAME      = (1 << 14),
217 	OPS_CHATTR      = (1 << 21),
218 
219 	FTS_SILENT      = (1 << 15),
220 	FTS_FOLDER      = (1 << 16),
221 	FTS_MEMFREE     = (1 << 17),
222 	FTS_FLASH       = (1 << 18),
223 	FTS_CERT        = (1 << 19),
224 	FTS_BACKUP      = (1 << 20),
225 	FTS_NONSILENT   = (1 << 22)
226 
227 } CalcFeatures;
228 
229 /**
230  * CalcAction:
231  *
232  * An enumeration which contains the action taken on a variable
233  **/
234 typedef enum
235 {
236 	ACT_NONE = 0,
237 	ACT_RENAME, ACT_OVER, ACT_SKIP,
238 } CalcAction;
239 
240 /**
241  * InfosMask:
242  *
243  * An enumeration which contains the different flags supported by CalcInfos:
244  **/
245 typedef enum
246 {
247 	INFOS_PRODUCT_NUMBER = (1 << 0), /* obsolete (never used) */
248 	INFOS_PRODUCT_NAME   = (1 << 1),
249 	INFOS_MAIN_CALC_ID   = (1 << 2), /* obsolete, replaced by INFOS_PRODUCT_ID */
250 	INFOS_HW_VERSION     = (1 << 3),
251 	INFOS_LANG_ID        = (1 << 4),
252 	INFOS_SUB_LANG_ID    = (1 << 5),
253 	INFOS_DEVICE_TYPE    = (1 << 6),
254 	INFOS_BOOT_VERSION   = (1 << 7),
255 	INFOS_OS_VERSION     = (1 << 8),
256 	INFOS_RAM_PHYS       = (1 << 9),
257 	INFOS_RAM_USER       = (1 << 10),
258 	INFOS_RAM_FREE       = (1 << 11),
259 	INFOS_FLASH_PHYS     = (1 << 12),
260 	INFOS_FLASH_USER     = (1 << 13),
261 	INFOS_FLASH_FREE     = (1 << 14),
262 	INFOS_LCD_WIDTH      = (1 << 15),
263 	INFOS_LCD_HEIGHT     = (1 << 16),
264 	INFOS_BATTERY        = (1 << 17),
265 	INFOS_BOOT2_VERSION  = (1 << 18),
266 	INFOS_RUN_LEVEL      = (1 << 19),
267 	INFOS_BPP            = (1 << 20),
268 	INFOS_CLOCK_SPEED    = (1 << 21),
269 	INFOS_PRODUCT_ID     = (1 << 22),
270 	INFOS_EXACT_MATH     = (1 << 23),
271 	INFOS_CLOCK_SUPPORT  = (1 << 24),
272 	INFOS_COLOR_SCREEN   = (1 << 25),
273 
274 	// INFOS_MORE_INFOS     = (1 << 30), /* Some day ? Reserved value for signaling more bits are available elsewhere */
275 	INFOS_CALC_MODEL     = 0x80000000
276 } InfosMask;
277 
278 /**
279  * CalcFnctsIdx:
280  *
281  * Index of function in the #CalcFncts structure:
282  **/
283 typedef enum
284 {
285 	FNCT_IS_READY=0,
286 	FNCT_SEND_KEY,
287 	FNCT_EXECUTE,
288 	FNCT_RECV_SCREEN,
289 	FNCT_GET_DIRLIST,
290 	FNCT_GET_MEMFREE,
291 	FNCT_SEND_BACKUP,
292 	FNCT_RECV_BACKUP,
293 	FNCT_SEND_VAR,
294 	FNCT_RECV_VAR,
295 	FNCT_SEND_VAR_NS,
296 	FNCT_RECV_VAR_NS,
297 	FNCT_SEND_APP,
298 	FNCT_RECV_APP,
299 	FNCT_SEND_OS,
300 	FNCT_RECV_IDLIST,
301 	FNCT_DUMP_ROM1,
302 	FNCT_DUMP_ROM2,
303 	FNCT_SET_CLOCK,
304 	FNCT_GET_CLOCK,
305 	FNCT_DEL_VAR,
306 	FNCT_NEW_FOLDER,
307 	FNCT_GET_VERSION,
308 	FNCT_SEND_CERT,
309 	FNCT_RECV_CERT,
310 	FNCT_RENAME,
311 	FNCT_CHATTR,
312 	FNCT_SEND_ALL_VARS_BACKUP,
313 	FNCT_RECV_ALL_VARS_BACKUP,
314 	FNCT_LAST // Keep this one last
315 } CalcFnctsIdx;
316 
317 #define FNCT_DUMP_ROM FNCT_DUMP_ROM2
318 
319 /**
320  * TigMode:
321  *
322  * An enumeration which contains the data to save in tigroup:
323  **/
324 typedef enum
325 {
326 	TIG_NONE    = 0,
327 	TIG_RAM     = (1 << 0),
328 	TIG_ARCHIVE = (1 << 1),
329 	TIG_FLASH   = (1 << 2),
330 	TIG_BACKUP  = (1 << 3),
331 	TIG_ALL     = 7,
332 } TigMode;
333 
334 //! Size of the header of a \a DUSBRawPacket
335 #define DUSB_HEADER_SIZE (4+1)
336 
337 /**
338  * DUSBRawPacket:
339  *
340  * Raw packet for the DUSB (84+(SE), 89T) protocol.
341  **/
342 typedef struct
343 {
344 	uint32_t size;       ///< raw packet size
345 	uint8_t  type;       ///< raw packet type
346 
347 	uint8_t  data[1023]; ///< raw packet data
348 } DUSBRawPacket;
349 
350 //! Size of the header of a \a NSPRawPacket
351 #define NSP_HEADER_SIZE (16)
352 //! Size of the data contained in \a NSPRawPacket
353 #define NSP_DATA_SIZE   (254)
354 
355 /**
356  * NSPRawPacket:
357  *
358  * Raw packet for the Nspire NavNet protocol.
359  **/
360 typedef struct
361 {
362 	uint16_t  unused;
363 	uint16_t  src_addr;
364 	uint16_t  src_port;
365 	uint16_t  dst_addr;
366 	uint16_t  dst_port;
367 	uint16_t  data_sum;
368 	uint8_t   data_size;
369 	uint8_t   ack;
370 	uint8_t   seq;
371 	uint8_t   hdr_sum;
372 
373 	uint8_t   data[NSP_DATA_SIZE];
374 } NSPRawPacket;
375 
376 /**
377  * CalcScreenCoord:
378  * @format: returns full or clipped image (#CalcScreenFormat)
379  * @width: real width
380  * @height: real height
381  * @clipped_width: clipped width (89 for instance)
382  * @clipped_height: clipped height (89 for instance)
383  * @pixel_format: format of pixel data (#CalcPixelFormat)
384  *
385  * A structure used for storing screen size.
386  **/
387 typedef struct
388 {
389 	int		format;
390 
391 	unsigned int width;
392 	unsigned int height;
393 
394 	unsigned int clipped_width;
395 	unsigned int clipped_height;
396 
397 	CalcPixelFormat pixel_format;
398 } CalcScreenCoord;
399 
400 /**
401  * TreeInfo:
402  * @model: hand-held model
403  * @type: var or app list (VAR_NODE_NAME or APP_NODE_NAME)
404  * @mem_used: memory used (depends on hand-held model)
405  * @mem_free: memory free (depends on hand-held model)
406  *
407  * A structure used for storing information about a directory list tree.
408  **/
409 typedef struct
410 {
411 	CalcModel	model;
412 	const char*	type;
413 
414 	int			mem_mask;	// tells which field is filled
415 	uint32_t	mem_used;
416 	uint32_t	mem_free;
417 } TreeInfo;
418 
419 /**
420  * KeyPair:
421  * @name: name of key (like "ESC")
422  * @value: value of key (like 264)
423  *
424  * A structure which contains a TI scancode.
425  **/
426 typedef struct
427 {
428 	char*		name;
429 	uint16_t	value;
430 } KeyPair;
431 
432 /**
433  * CalcKey:
434  * @key_name: name of key
435  *
436  * A structure which contains a TI scancode with key modifiers.
437  * FIXME: use KeyPair structure to pack infos !
438  **/
439 typedef struct
440 {
441 	char*	key_name;	// Name of key
442 
443 	KeyPair	normal;		// normal key
444 	KeyPair	shift;		// SHIFT key (TI9x)
445 	KeyPair	second;		// 2ND key (all)
446 	KeyPair diamond;	// CTRL key (TI92)
447 	KeyPair alpha;		// ALPHA key (83+,89)
448 
449 } CalcKey;
450 
451 typedef struct
452 {
453 	const char	*key_name;
454 
455 	const char	*normal_name;
456 	uint16_t	normal_value;
457 	const char	*shift_name;
458 	uint16_t	shift_value;
459 	const char	*second_name;
460 	uint16_t	second_value;
461 	const char	*diamond_name;
462 	uint16_t	diamond_value;
463 	const char	*alpha_name;
464 	uint16_t	alpha_value;
465 } OldCalcKeys_;
466 
467 /**
468  * CalcClock:
469  * @year: year
470  * @month:
471  * @day:
472  * @hours:
473  * @minutes:
474  * @seconds:
475  * @time_format: 12 or 24
476  * @date_format: 1 or 6
477  *
478  * A structure used for clock management.
479  **/
480 typedef struct
481 {
482 	uint16_t	year;
483 	uint8_t	month;
484 	uint8_t	day;
485 
486 	uint8_t	hours;
487 	uint8_t	minutes;
488 	uint8_t	seconds;
489 
490 	uint8_t	time_format;
491 	uint8_t	date_format;
492 
493 	int		state;
494 } CalcClock;
495 
496 /**
497  * CalcUpdate:
498  * @text: a text to display about the current operation (locale used is those defined by tifiles_transcoding_set)
499  * @cancel: set to 1 if transfer have to be cancelled
500  * @rate: data rate of cable
501  * @cnt1: current counter for link transfer operations (ticalcs2 only)
502  * @max1: max value of this counter
503  * @cnt2: current count for intermediate operations (ticalcs2 only)
504  * @max2: max value of this counter
505  * @cnt3: current counter for global operations (used by ticalcs2 or tilp)
506  * @max3: max value of this counter
507  * @mask: which cntX is/are used (unused)
508  * @type: pbar type (unused)
509  * @start: init internal vars
510  * @stop: release internal vars
511  * @refresh: pass control to GUI for refresh
512  * @pbar: refresh pprogress bar
513  * @label: refresh label
514  *
515  * Refresh/progress functions
516  * This structure allows to implement a kind of callbacks mechanism (which
517  * allow libCalcs to interact with user without being dependant of a GUI).
518  **/
519 typedef struct
520 {
521 	char	text[256];
522 	int		cancel;
523 
524 	float	rate;
525 	int		cnt1;
526 	int		max1;
527 
528 	int		cnt2;
529 	int		max2;
530 
531 	int		cnt3;
532 	int		max3;
533 
534 	int		mask;
535 	int		type;
536 
537 	void	(*start)	(void);
538 	void	(*stop)		(void);
539 	void	(*refresh)	(void);
540 	void	(*pbar)		(void);
541 	void	(*label)	(void);
542 } CalcUpdate;
543 
544 typedef struct _CalcFncts	CalcFncts;
545 typedef struct _CalcHandle	CalcHandle;
546 
547 // convenient wrappers: will be removed later !
548 #define update_				(handle->updat)
549 #define update_start()		handle->updat->start()
550 #define update_pbar()       handle->updat->pbar()
551 #define update_label()      handle->updat->label()
552 #define update_refresh()    handle->updat->refresh()
553 #define update_stop()       handle->updat->stop()
554 
555 typedef VarEntry	VarRequest;	// alias
556 
557 /**
558  * CalcInfos:
559  * @os: OS version like "3.01"
560  * @bios: BIOS (boot) version like 2.01
561  *
562  * A structure used to pass arguments.
563  **/
564 typedef struct
565 {
566 	CalcModel	model;
567 	InfosMask	mask;
568 
569 	char		product_name[64];
570 	char		product_id[32];
571 	uint32_t	product_number;		// obsolete, replaced by product_id
572 	char		main_calc_id[32];	// obsolete, replaced by product_id
573 	uint16_t	hw_version;			// hand-held-dependent
574 	uint8_t		language_id;
575 	uint8_t		sub_lang_id;
576 	uint16_t	device_type;		// hand-held-dependent
577 	char		boot_version[16];
578 	char		boot2_version[16];
579 	char		os_version[16];
580 	uint64_t	ram_phys;
581 	uint64_t	ram_user;
582 	uint64_t	ram_free;
583 	uint64_t	flash_phys;
584 	uint64_t	flash_user;
585 	uint64_t	flash_free;
586 	uint16_t	lcd_width;
587 	uint16_t	lcd_height;
588 	uint8_t		battery;			// 0 = low, 1 = good
589 	uint8_t		run_level;			// 1 = boot, 2 = OS
590 	uint16_t	bits_per_pixel;		// 1, 4 or 16
591 	uint16_t	clock_speed;
592 	uint8_t		exact_math;
593 	uint8_t		clock_support;
594 	uint8_t		color_screen;
595 } CalcInfos;
596 
597 /**
598  * CalcFncts:
599  * @model: link cable model (CalcModel).
600  * @name: name of hand-held like "TI89"
601  * @fullname: complete name of hand-held like "TI-89"
602  * @description: description of hand-held like "TI89 calculator"
603  * @features: supported operations (CalcOperations)
604  * @counters: defines which CalcUpdate counters have to be refreshed (indexed by CalcFnctsIdx)
605  * @is_ready: check whether calculator is ready
606  * @send_key: send key value
607  * @execute: remotely execute a program or application
608  * @recv_screen: request a screendump
609  * @get_dirlist: request a listing of variables, folders (if any) and apps (if any)
610  * @send_backup: send a backup
611  * @recv_backup: request a backup
612  * @send_var: send a variable (silent mode)
613  * @recv_var: request a variable silent mode)
614  * @send_var_ns: send a variable (non-silent mode)
615  * @recv_var_ns: receive a variable (non-silent mode)
616  * @send_flash: send a FLASH app/os
617  * @recv_flash: request a FLASH app/os
618  * @recv_idlist: request hand-held IDLIST
619  * @dump_rom_1: dump the hand-held ROM: send dumper (if any)
620  * @dump_rom_2: dump the hand-held ROM: launch dumper
621  * @set_clock: set date/time
622  * @get_clock: get date/time
623  * @del_var: delete variable
624  * @new_fld: create new folder (if supported)
625  * @get_version: returns Boot code & OS version
626  * @send_cert: send certificate stuff
627  * @recv_cert: receive certificate stuff
628  * @rename_var: rename a variable
629  * @change_attr: change attributes of a variable
630  * @send_all_vars_backup: send a fake backup (set of files and FlashApps)
631  * @recv_all_vars_backup: request a fake backup (set of files and FlashApps)
632  *
633  * A structure used for handling a hand-held.
634  * !!! This structure is for private use !!!
635  **/
636 struct _CalcFncts
637 {
638 	const int		model;
639 	const char*		name;
640 	const char*		fullname;
641 	const char*		description;
642 	const int		features;
643 	const CalcProductIDs	product_id;
644 	const char*		counters[FNCT_LAST];
645 
646 	int		(*is_ready)		(CalcHandle*);
647 
648 	int		(*send_key)		(CalcHandle*, uint32_t);
649 	int		(*execute)		(CalcHandle*, VarEntry*, const char*);
650 
651 	int		(*recv_screen)	(CalcHandle*, CalcScreenCoord*, uint8_t**);
652 
653 	int		(*get_dirlist)	(CalcHandle*, GNode** vars, GNode** apps);
654 	int		(*get_memfree)	(CalcHandle*, uint32_t* ram, uint32_t* flash);
655 
656 	int		(*send_backup)	(CalcHandle*, BackupContent*);
657 	int		(*recv_backup)	(CalcHandle*, BackupContent*);
658 
659 	int		(*send_var)		(CalcHandle*, CalcMode, FileContent*);
660 	int		(*recv_var)		(CalcHandle*, CalcMode, FileContent*, VarRequest*);
661 
662 	int		(*send_var_ns)	(CalcHandle*, CalcMode, FileContent*);
663 	int		(*recv_var_ns)	(CalcHandle*, CalcMode, FileContent*, VarEntry**);
664 
665 	int		(*send_app)		(CalcHandle*, FlashContent*);
666 	int		(*recv_app)		(CalcHandle*, FlashContent*, VarRequest*);
667 
668 	int		(*send_os)		(CalcHandle*, FlashContent*);
669 	int		(*recv_idlist)	(CalcHandle*, uint8_t*);
670 
671 	int		(*dump_rom_1)	(CalcHandle*);
672 	int		(*dump_rom_2)	(CalcHandle*, CalcDumpSize, const char *filename);
673 
674 	int		(*set_clock)	(CalcHandle*, CalcClock* clock);
675 	int		(*get_clock)	(CalcHandle*, CalcClock* clock);
676 
677 	int		(*del_var)		(CalcHandle*, VarRequest*);
678 	int		(*new_fld)		(CalcHandle*, VarRequest*);
679 
680 	int		(*get_version)	(CalcHandle*, CalcInfos*);
681 
682 	int		(*send_cert)	(CalcHandle*, FlashContent*);
683 	int		(*recv_cert)	(CalcHandle*, FlashContent*);
684 
685 	int		(*rename_var)	(CalcHandle*, VarRequest*, VarRequest*);
686 	int		(*change_attr)	(CalcHandle*, VarRequest*, FileAttr);
687 
688 	int		(*send_all_vars_backup)	(CalcHandle*, FileContent*);
689 	int		(*recv_all_vars_backup)	(CalcHandle*, FileContent*);
690 
691 };
692 
693 /**
694  * CalcHandle:
695  * @model: cable model
696  * @calc: calculator functions
697  * @update: callbacks for GUI interaction
698  * @unused1: unused member kept for API compatibility purposes
699  * @buffer: allocated data buffer for internal use
700  * @buffer2: allocated data buffer for internal use
701  * @open: device has been opened
702  * @busy: transfer is in progress
703  * @cable: handle on cable used with this model
704  * @attached: set if a cable has been attached
705  * @priv: private per-handle data
706  *
707  * A structure used to store information as a handle.
708  * !!! This structure is for private use !!!
709  **/
710 struct _CalcHandle
711 {
712 	CalcModel	model;
713 	CalcFncts*	calc;
714 	CalcUpdate*	updat;
715 
716 	void*		unused1;
717 	void*		buffer; // used as data buffer
718 	void*		buffer2;
719 
720 	int			open;
721 	int			busy;
722 
723 	CableHandle* cable;
724 	int			attached;
725 
726 	struct {
727 		uint32_t dusb_rpkt_maxlen; // max length of data in raw packet
728 		unsigned int progress_blk_size; // refresh pbars every once in a while.
729 		unsigned int progress_min_size; // don't refresh if packet is smaller than some amount.
730 		unsigned int romdump_std_blk; // number of full-size blocks
731 		unsigned int romdump_sav_blk; // number of compressed blocks
732 		void * dusb_vtl_pkt_list;
733 		void * dusb_cpca_list;
734 		void * nsp_vtl_pkt_list;
735 		uint8_t nsp_seq_pc;
736 		uint8_t nsp_seq;
737 		uint16_t nsp_src_port;
738 		uint16_t nsp_dst_port;
739 	} priv;
740 };
741 
742 /**
743  * DeviceOptions:
744  * @cable_model: model
745  * @cable_port: port
746  * @cable_timeout: timeout in tenth of seconds
747  * @cable_delay: inter-bit delay in µs
748  * @calc_model: calculator model
749  *
750  * A convenient structure free of use by the user.
751  **/
752 typedef struct
753 {
754 	CableModel	cable_model;
755 	CablePort	cable_port;
756 	int			cable_timeout;
757 	int			cable_delay;
758 
759 	CalcModel	calc_model;
760 } DeviceOptions;
761 
762 // namespace scheme: library_class_function like ticalcs_fext_get
763 
764 	/****************/
765 	/* Entry points */
766 	/****************/
767 
768 	TIEXPORT3 int TICALL ticalcs_library_init(void);
769 	TIEXPORT3 int TICALL ticalcs_library_exit(void);
770 
771 	/*********************/
772 	/* General functions */
773 	/*********************/
774 
775 	// ticalcs.c
776 	TIEXPORT3 const char* TICALL ticalcs_version_get(void);
777 	TIEXPORT3 uint32_t    TICALL ticalcs_supported_calcs(void);
778 
779 	TIEXPORT3 CalcHandle* TICALL ticalcs_handle_new(CalcModel model);
780 	TIEXPORT3 int         TICALL ticalcs_handle_del(CalcHandle *handle);
781 	TIEXPORT3 int         TICALL ticalcs_handle_show(CalcHandle *handle);
782 
783 	TIEXPORT3 int TICALL ticalcs_cable_attach(CalcHandle *handle, CableHandle*);
784 	TIEXPORT3 int TICALL ticalcs_cable_detach(CalcHandle *handle);
785 
786 	TIEXPORT3 int TICALL ticalcs_update_set(CalcHandle *handle, CalcUpdate*);
787 
788 	TIEXPORT3 int TICALL ticalcs_model_supports_dbus(CalcModel model);
789 	TIEXPORT3 int TICALL ticalcs_model_supports_dusb(CalcModel model);
790 	TIEXPORT3 int TICALL ticalcs_model_supports_nsp(CalcModel model);
791 
792 	// error.c
793 	TIEXPORT3 int         TICALL ticalcs_error_get (int number, char **message);
794 	TIEXPORT3 int         TICALL ticalcs_error_free (char *message);
795 
796 	// calc_xx.c
797 	TIEXPORT3 CalcFeatures TICALL ticalcs_calc_features(CalcHandle *handle);
798 
799 	TIEXPORT3 int TICALL ticalcs_calc_isready(CalcHandle *handle);
800 
801 	TIEXPORT3 int TICALL ticalcs_calc_send_key(CalcHandle *handle, uint32_t);
802 	TIEXPORT3 int TICALL ticalcs_calc_execute(CalcHandle *handle, VarEntry*, const char*);
803 
804 	TIEXPORT3 int TICALL ticalcs_calc_recv_screen(CalcHandle *handle, CalcScreenCoord* sc, uint8_t** bitmap);
805 	TIEXPORT3 int TICALL ticalcs_calc_recv_screen_rgb888(CalcHandle *handle, CalcScreenCoord* sc, uint8_t** bitmap);
806 	TIEXPORT3 void TICALL ticalcs_free_screen(uint8_t * bitmap);
807 
808 	TIEXPORT3 int TICALL ticalcs_calc_get_dirlist(CalcHandle *handle, GNode** vars, GNode **apps);
809 	TIEXPORT3 int TICALL ticalcs_calc_get_memfree(CalcHandle *handle, uint32_t* ram, uint32_t *flash);
810 
811 	TIEXPORT3 int TICALL ticalcs_calc_send_backup(CalcHandle *handle, BackupContent*);
812 	TIEXPORT3 int TICALL ticalcs_calc_recv_backup(CalcHandle *handle, BackupContent*);
813 
814 	TIEXPORT3 int TICALL ticalcs_calc_send_var(CalcHandle *handle, CalcMode, FileContent*);
815 	TIEXPORT3 int TICALL ticalcs_calc_recv_var(CalcHandle *handle, CalcMode, FileContent*, VarRequest*);
816 
817 	TIEXPORT3 int TICALL ticalcs_calc_send_var_ns(CalcHandle *handle, CalcMode, FileContent*);
818 	TIEXPORT3 int TICALL ticalcs_calc_recv_var_ns(CalcHandle *handle, CalcMode, FileContent*, VarEntry**);
819 
820 	TIEXPORT3 int TICALL ticalcs_calc_send_app(CalcHandle *handle, FlashContent*);
821 	TIEXPORT3 int TICALL ticalcs_calc_recv_app(CalcHandle *handle, FlashContent*, VarRequest*);
822 
823 	TIEXPORT3 int TICALL ticalcs_calc_send_os(CalcHandle *handle, FlashContent*);
824 	TIEXPORT3 int TICALL ticalcs_calc_recv_idlist(CalcHandle *handle, uint8_t*);
825 
826 	TIEXPORT3 int TICALL ticalcs_calc_dump_rom_1(CalcHandle *handle);
827 	TIEXPORT3 int TICALL ticalcs_calc_dump_rom_2(CalcHandle *handle, CalcDumpSize, const char *filename);
828 
829 	TIEXPORT3 int TICALL ticalcs_calc_set_clock(CalcHandle *handle, CalcClock* clock);
830 	TIEXPORT3 int TICALL ticalcs_calc_get_clock(CalcHandle *handle, CalcClock* clock);
831 
832 	TIEXPORT3 int TICALL ticalcs_calc_new_fld(CalcHandle *handle, VarRequest*);
833 	TIEXPORT3 int TICALL ticalcs_calc_del_var(CalcHandle *handle, VarRequest*);
834 
835 	TIEXPORT3 int TICALL ticalcs_calc_get_version(CalcHandle *handle, CalcInfos*);
836 
837 	TIEXPORT3 int TICALL ticalcs_calc_send_cert(CalcHandle *handle, FlashContent*);
838 	TIEXPORT3 int TICALL ticalcs_calc_recv_cert(CalcHandle *handle, FlashContent*);
839 
840 	TIEXPORT3 int TICALL ticalcs_calc_rename_var(CalcHandle *handle, VarRequest*, VarRequest*);
841 	TIEXPORT3 int TICALL ticalcs_calc_change_attr(CalcHandle *handle, VarRequest*, FileAttr);
842 
843 	TIEXPORT3 int TICALL ticalcs_calc_send_all_vars_backup(CalcHandle *handle, FileContent*);
844 	TIEXPORT3 int TICALL ticalcs_calc_recv_all_vars_backup(CalcHandle *handle, FileContent*);
845 
846 	TIEXPORT3 int TICALL ticalcs_calc_send_tigroup(CalcHandle *handle, TigContent*, TigMode);
847 	TIEXPORT3 int TICALL ticalcs_calc_recv_tigroup(CalcHandle *handle, TigContent*, TigMode);
848 
849 	// calc_xx.c: convenient functions
850 	TIEXPORT3 int TICALL ticalcs_calc_send_backup2(CalcHandle *handle, const char*);
851 	TIEXPORT3 int TICALL ticalcs_calc_recv_backup2(CalcHandle *handle, const char*);
852 
853 	TIEXPORT3 int TICALL ticalcs_calc_send_var2(CalcHandle *handle, CalcMode, const char*);
854 	TIEXPORT3 int TICALL ticalcs_calc_recv_var2(CalcHandle *handle, CalcMode, const char*, VarRequest*);
855 
856 	TIEXPORT3 int TICALL ticalcs_calc_send_var_ns2(CalcHandle *handle, CalcMode, const char*);
857 	TIEXPORT3 int TICALL ticalcs_calc_recv_var_ns2(CalcHandle *handle, CalcMode, const char*, VarEntry**);
858 
859 	TIEXPORT3 int TICALL ticalcs_calc_send_app2(CalcHandle *handle, const char*);
860 	TIEXPORT3 int TICALL ticalcs_calc_recv_app2(CalcHandle *handle, const char*, VarRequest*);
861 
862 	TIEXPORT3 int TICALL ticalcs_calc_send_cert2(CalcHandle *handle, const char*);
863 	TIEXPORT3 int TICALL ticalcs_calc_recv_cert2(CalcHandle *handle, const char*);
864 
865 	TIEXPORT3 int TICALL ticalcs_calc_send_os2(CalcHandle *handle, const char*);
866 
867 	TIEXPORT3 int TICALL ticalcs_calc_send_tigroup2(CalcHandle *handle, const char*, TigMode);
868 	TIEXPORT3 int TICALL ticalcs_calc_recv_tigroup2(CalcHandle *handle, const char*, TigMode);
869 
870 	// dirlist.c
871 	TIEXPORT3 void TICALL ticalcs_dirlist_destroy(GNode** tree);
872 	TIEXPORT3 void TICALL ticalcs_dirlist_display(GNode*  tree);
873 
874 	TIEXPORT3 int TICALL ticalcs_dirlist_ram_used(GNode* tree);
875 	TIEXPORT3 int TICALL ticalcs_dirlist_flash_used(GNode* vars, GNode* apps);
876 
877 	TIEXPORT3 unsigned int TICALL ticalcs_dirlist_ve_count(GNode* tree);
878 	TIEXPORT3 VarEntry *TICALL ticalcs_dirlist_ve_exist(GNode* tree, VarEntry *entry);
879 	TIEXPORT3 void TICALL ticalcs_dirlist_ve_add(GNode* tree, VarEntry *entry);
880 	TIEXPORT3 void TICALL ticalcs_dirlist_ve_del(GNode* tree, VarEntry *entry);
881 
882 	// type2str.c
883 	TIEXPORT3 const char*  TICALL ticalcs_model_to_string(CalcModel model);
884 	TIEXPORT3 CalcModel    TICALL ticalcs_string_to_model (const char *str);
885 
886 	TIEXPORT3 const char*      TICALL ticalcs_scrfmt_to_string(CalcScreenFormat format);
887 	TIEXPORT3 CalcScreenFormat TICALL ticalcs_string_to_scrfmt(const char *str);
888 
889 	TIEXPORT3 const char*  TICALL ticalcs_pathtype_to_string(CalcPathType type);
890 	TIEXPORT3 CalcPathType TICALL ticalcs_string_to_pathtype(const char *str);
891 
892 	TIEXPORT3 const char*  TICALL ticalcs_memtype_to_string(CalcMemType type);
893 	TIEXPORT3 CalcMemType  TICALL ticalcs_string_to_memtype(const char *str);
894 
895 	TIEXPORT3 int TICALL ticalcs_infos_to_string(CalcInfos *infos, char *str, uint32_t maxlen);
896 
897 	// clock.c
898 	TIEXPORT3 const char*  TICALL ticalcs_clock_format2date(CalcModel model, int value);
899 	TIEXPORT3 int          TICALL ticalcs_clock_date2format(CalcModel model, const char *format);
900 	TIEXPORT3 int          TICALL ticalcs_clock_show(CalcModel model, CalcClock* s);
901 
902 	// screen.c
903 	TIEXPORT3 int TICALL ticalcs_screen_convert_bw_to_rgb888(const uint8_t * src, unsigned int width, unsigned int height, uint8_t * dst);
904 	TIEXPORT3 int TICALL ticalcs_screen_convert_bw_to_blurry_rgb888(const uint8_t * src, unsigned int width, unsigned int height, uint8_t * dst);
905 	TIEXPORT3 int TICALL ticalcs_screen_convert_gs4_to_rgb888(const uint8_t * src, unsigned int width, unsigned int height, uint8_t * dst);
906 	TIEXPORT3 int TICALL ticalcs_screen_convert_rgb565le_to_rgb888(const uint8_t * src, unsigned int width, unsigned int height, uint8_t * dst);
907 	TIEXPORT3 int TICALL ticalcs_screen_convert_native_to_rgb888(CalcPixelFormat format, const uint8_t * src, unsigned int width, unsigned int height, uint8_t * dst);
908 	TIEXPORT3 int TICALL ticalcs_screen_nspire_rle_uncompress(CalcPixelFormat format, const uint8_t * src, uint32_t input_size, uint8_t * dst, uint32_t max_output_size);
909 	TIEXPORT3 int TICALL ticalcs_screen_84pcse_rle_uncompress(const uint8_t * src, uint32_t src_length, uint8_t * dst, uint32_t dst_length);
910 
911 	// tikeys.c
912 	TIEXPORT3 const CalcKey* TICALL ticalcs_keys_73 (uint8_t ascii_code);
913 	TIEXPORT3 const CalcKey* TICALL ticalcs_keys_83 (uint8_t ascii_code);
914 	TIEXPORT3 const CalcKey* TICALL ticalcs_keys_83p(uint8_t ascii_code);
915 	TIEXPORT3 const CalcKey* TICALL ticalcs_keys_86 (uint8_t ascii_code);
916 	TIEXPORT3 const CalcKey* TICALL ticalcs_keys_89 (uint8_t ascii_code);
917 	TIEXPORT3 const CalcKey* TICALL ticalcs_keys_92p(uint8_t ascii_code);
918 
919 	// probe.c
920 	TIEXPORT3 int TICALL ticalcs_probe_calc  (CableHandle* cable, CalcModel* model);
921 	TIEXPORT3 int TICALL ticalcs_probe_usb_calc(CableHandle* cable, CalcModel* model);
922 
923 	TIEXPORT3 int TICALL ticalcs_probe(CableModel c_model, CablePort c_port, CalcModel* model, int all);
924 
925 	TIEXPORT3 CalcModel TICALL ticalcs_device_info_to_model(const CableDeviceInfo *info);
926 	TIEXPORT3 CalcModel TICALL ticalcs_remap_model_from_usb(CableModel cable, CalcModel calc);
927 	TIEXPORT3 CalcModel TICALL ticalcs_remap_model_to_usb(CableModel cable, CalcModel calc);
928 
929 	// dbus_pkt.c
930 	TIEXPORT3 int TICALL dbus_send(CalcHandle *handle, uint8_t target, uint8_t cmd, uint16_t length, const uint8_t* data);
931 	TIEXPORT3 int TICALL dbus_recv(CalcHandle *handle, uint8_t* host, uint8_t* cmd, uint16_t* length, uint8_t* data);
932 	TIEXPORT3 int TICALL dbus_recv_header(CalcHandle *handle, uint8_t* host, uint8_t* cmd, uint16_t* length);
933 	TIEXPORT3 int TICALL dbus_recv_data(CalcHandle *handle, uint16_t* length, uint8_t* data);
934 
935 	// dusb_rpkt.c
936 	TIEXPORT3 int TICALL dusb_send(CalcHandle *handle, DUSBRawPacket* pkt);
937 	TIEXPORT3 int TICALL dusb_recv(CalcHandle *handle, DUSBRawPacket* pkt);
938 
939 	// nsp_rpkt.c
940 	TIEXPORT3 int TICALL nsp_send(CalcHandle *handle, NSPRawPacket* pkt);
941 	TIEXPORT3 int TICALL nsp_recv(CalcHandle *handle, NSPRawPacket* pkt);
942 
943 	/************************/
944 	/* Deprecated functions */
945 	/************************/
946 
947 #ifdef __cplusplus
948 }
949 #endif
950 
951 #endif
952