228 lines
5.9 KiB
C
228 lines
5.9 KiB
C
/* ************************************************************************** */
|
|
/* _____ _ */
|
|
/* core/devices.c |_ _|__ _ _| |__ ___ _ _ */
|
|
/* | Project: libp7 | |/ _ \| | | | '_ \ / _ \ | | | */
|
|
/* | | (_) | |_| | | | | __/ |_| | */
|
|
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
|
|
/* Last updated: 2016/10/13 07:33:17 |___/ */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
#include <libp7/internals.h>
|
|
#include <string.h>
|
|
|
|
/* ************************************************************************** */
|
|
/* Main data */
|
|
/* ************************************************************************** */
|
|
/* mask bits */
|
|
#define MASK_ALL 1
|
|
#define MASK_RESET 2
|
|
#define MASK_LINK 4
|
|
#define MASK_MCS 8
|
|
#define MASK_FLS 16
|
|
#define MASK_BACKUP 32
|
|
#define MASK_OSUPDATE_1 64
|
|
#define MASK_OSUPDATE_2 128
|
|
|
|
/* supported commands */
|
|
static unsigned int command_masks[] = {
|
|
/* MAIN SYSTEM COMMANDS */
|
|
/* - restart/reset - */
|
|
MASK_RESET,
|
|
/* - get device info - */
|
|
MASK_ALL,
|
|
/* - set link settings */
|
|
MASK_LINK,
|
|
|
|
/* unused */
|
|
0, 0, 0,
|
|
|
|
/* - set link timeout - */
|
|
MASK_RESET,
|
|
/* - verifications (OS Update) - */
|
|
MASK_ALL,
|
|
MASK_OSUPDATE_1,
|
|
MASK_OSUPDATE_1,
|
|
MASK_OSUPDATE_2,
|
|
|
|
/* unused */
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
/* MCS COMMANDS */
|
|
/* - create directory - */
|
|
MASK_MCS,
|
|
/* - delete directory - */
|
|
MASK_MCS,
|
|
/* - rename directory - */
|
|
MASK_MCS,
|
|
/* - change working directory - */
|
|
MASK_MCS,
|
|
/* - file transfer request - */
|
|
MASK_MCS,
|
|
/* - file transfer - */
|
|
MASK_MCS,
|
|
/* - delete file - */
|
|
MASK_MCS,
|
|
/* - rename file - */
|
|
MASK_MCS,
|
|
/* - copy file - */
|
|
MASK_MCS,
|
|
/* - file transfer all request - */
|
|
MASK_MCS,
|
|
/* - unknown (reset MCS?) - */
|
|
MASK_MCS,
|
|
/* - capacity transmit request - */
|
|
MASK_MCS,
|
|
/* - capacity transmit - */
|
|
MASK_MCS,
|
|
/* - file info transfer all request - */
|
|
MASK_MCS,
|
|
/* - file info transfer */
|
|
MASK_MCS,
|
|
/* - RAM image transfer request - */
|
|
MASK_MCS,
|
|
/* - RAM image transfer - */
|
|
MASK_MCS,
|
|
/* - Setup entry transfer request - */
|
|
MASK_MCS,
|
|
/* - Setup entry transfer - */
|
|
MASK_MCS,
|
|
/* - Setup entry transfer all request - */
|
|
MASK_MCS,
|
|
|
|
/* unused */
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
/* FLASH COMMANDS */
|
|
/* - create directory - */
|
|
MASK_FLS,
|
|
/* - delete directory - */
|
|
MASK_FLS,
|
|
/* - rename directory - */
|
|
MASK_FLS,
|
|
/* - change working directory - */
|
|
MASK_FLS,
|
|
/* - file transfer request - */
|
|
MASK_FLS,
|
|
/* - file transfer - */
|
|
MASK_FLS,
|
|
/* - delete file - */
|
|
MASK_FLS,
|
|
/* - rename file - */
|
|
MASK_FLS,
|
|
/* - copy file - */
|
|
MASK_FLS,
|
|
/* - file transfer all request - */
|
|
MASK_FLS,
|
|
/* - unknown (reset flash ?) - */
|
|
MASK_FLS,
|
|
/* - capacity transmit request - */
|
|
MASK_FLS,
|
|
/* - capacity transmit - */
|
|
MASK_FLS,
|
|
/* - file info transfer all request - */
|
|
MASK_FLS,
|
|
/* - file info transfer - */
|
|
MASK_FLS,
|
|
/* - flash image transfer request - */
|
|
MASK_BACKUP,
|
|
/* - flash image transfer - */
|
|
MASK_BACKUP,
|
|
/* - optimize filesystem - */
|
|
MASK_FLS,
|
|
|
|
/* OS UPDATE */
|
|
/* - CASIOWIN entry transfer request - */
|
|
MASK_BACKUP,
|
|
/* - CASIOWIN entry transfer - */
|
|
MASK_BACKUP,
|
|
/* - Bootcode transfer request - */
|
|
MASK_BACKUP,
|
|
/* - Bootcode transfer - */
|
|
MASK_BACKUP,
|
|
/* - Upload and run - */
|
|
MASK_ALL,
|
|
|
|
/* last is 0x56 */
|
|
};
|
|
|
|
/* known environments */
|
|
/* to add: fx-7400GII (Graph 25+ Pro SH3) */
|
|
/* For this list, thanks to:
|
|
* - Simon Lothar (documentation about supported commands and bootcodes)
|
|
* - Critor (lots of models) [TODO: still waiting for his input]
|
|
* - Lephenixnoir, Hackcell (some models)
|
|
*/
|
|
static p7_env_t known_environments[] = {
|
|
/* bootcodes */
|
|
{"Gy362000", "fx-7400GII/fx-9860GII bootcode",
|
|
MASK_ALL | MASK_LINK},
|
|
{"Gy363000", "fx-9750GII-2/fx-9860GII(-2) bootcode",
|
|
MASK_ALL},
|
|
{"Gy490000", "fx-7400GII-2 bootcode",
|
|
MASK_ALL | MASK_LINK},
|
|
|
|
/* fx devices */
|
|
{"Gy362007", "fx-9750GII-2 (Graph 35+ SH4)",
|
|
MASK_ALL | MASK_RESET | MASK_MCS | MASK_LINK},
|
|
{"Gy36200F", "Graph 35+E (modified fx-9750GII-2)",
|
|
MASK_ALL | MASK_RESET | MASK_MCS | MASK_LINK},
|
|
{"Gy363006", "fx-9860GII (Graph 75 SH3)",
|
|
MASK_ALL | MASK_RESET | MASK_MCS | MASK_LINK
|
|
| MASK_FLS
|
|
| MASK_OSUPDATE_1 | MASK_BACKUP},
|
|
{"Gy363007", "fx-9860GII-2 (Graph 75 SH4)",
|
|
MASK_ALL | MASK_RESET | MASK_MCS | MASK_LINK
|
|
| MASK_FLS
|
|
| MASK_OSUPDATE_1},
|
|
{"Gy36300F", "Graph 75+E (modified fx-9860GII-2)",
|
|
MASK_ALL | MASK_RESET | MASK_MCS | MASK_LINK
|
|
| MASK_FLS
|
|
| MASK_OSUPDATE_1},
|
|
|
|
/* cp devices */
|
|
{"Ly755000", "fx-CG20 (according to simlo's chm)",
|
|
MASK_ALL | MASK_MCS},
|
|
|
|
/* terminating entry */
|
|
{NULL, NULL, 0}
|
|
};
|
|
|
|
/* the default environment */
|
|
static p7_env_t default_environment =
|
|
{NULL, "Default environment",
|
|
MASK_ALL | MASK_MCS | MASK_LINK | MASK_FLS};
|
|
|
|
/* ************************************************************************** */
|
|
/* Internal functions */
|
|
/* ************************************************************************** */
|
|
/**
|
|
* p7_get_env:
|
|
* Get the environment type.
|
|
*
|
|
* @arg model the model string
|
|
* @return the device (NULL if unknown)
|
|
*/
|
|
|
|
p7_env_t *p7_get_env(const char *model)
|
|
{
|
|
for (p7_env_t *e = known_environments; e->model; e++)
|
|
if (!strcmp(model, e->model)) return (e);
|
|
return (&default_environment);
|
|
}
|
|
|
|
/**
|
|
* p7_command_is_supported:
|
|
* Check if a command is supported by the environment.
|
|
*
|
|
* @arg code command code
|
|
* @arg env the environment
|
|
* @return if it is supported (0 if not)
|
|
*/
|
|
|
|
int p7_command_is_supported(p7_commandcode_t code, const p7_env_t *env)
|
|
{
|
|
if (!env) return (1); /* we don't know, so we suppose that it is */
|
|
return (command_masks[code] & env->mask);
|
|
}
|