233 lines
6.3 KiB
C
233 lines
6.3 KiB
C
/* *****************************************************************************
|
|
* protocol/seven/devices.c -- libp7 known devices.
|
|
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
|
*
|
|
* This file is part of libp7.
|
|
* libp7 is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation; either version 3.0 of the License,
|
|
* or (at your option) any later version.
|
|
*
|
|
* libp7 is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
* See the GNU Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with libp7; if not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* One of the Protocol 7 problems is that it has too few errors, and one of
|
|
* them, the 0x04 error (`p7_err_generic`), can mean many things. Knowing the
|
|
* device we're talking to, and its capabilities, help us reduce the number
|
|
* of possible errors it can be.
|
|
* ************************************************************************** */
|
|
#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_OSUPDATE_1 64
|
|
#define MASK_OSUPDATE_2 128
|
|
|
|
/* supported commands */
|
|
static unsigned int command_masks[] = {
|
|
/* [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, delete, rename directory */
|
|
MASK_MCS, MASK_MCS, MASK_MCS,
|
|
|
|
/* change working directory */
|
|
MASK_MCS,
|
|
|
|
/* file transfer request, file transfer */
|
|
MASK_MCS, MASK_MCS,
|
|
|
|
/* delete, rename, copy file */
|
|
MASK_MCS, MASK_MCS, MASK_MCS,
|
|
|
|
/* file transfer all request */
|
|
MASK_MCS,
|
|
|
|
/* reset the MCS */
|
|
MASK_MCS,
|
|
|
|
/* capacity transmit request, capacity transmit */
|
|
MASK_MCS, MASK_MCS,
|
|
|
|
/* file info transfer all request, file info transfer */
|
|
MASK_MCS, MASK_MCS,
|
|
|
|
/* RAM image transfer request, RAM image transfer */
|
|
MASK_ALL, MASK_ALL,
|
|
|
|
/* Setup entry transfer request, setup entry transfer,
|
|
* setup entry transfer all request */
|
|
MASK_MCS, MASK_MCS, MASK_MCS,
|
|
|
|
/* unused */
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
/* [FLASH COMMANDS] */
|
|
/* create, delete, rename directory */
|
|
MASK_FLS, MASK_FLS, MASK_FLS,
|
|
|
|
/* change working directory */
|
|
MASK_FLS,
|
|
|
|
/* file transfer request, file transfer */
|
|
MASK_FLS, MASK_FLS,
|
|
|
|
/* delete, rename, copy file */
|
|
MASK_FLS, MASK_FLS, MASK_FLS,
|
|
|
|
/* file transfer all request */
|
|
MASK_FLS,
|
|
|
|
/* reset a filesystem */
|
|
MASK_FLS,
|
|
|
|
/* capacity transmit request */
|
|
MASK_FLS,
|
|
|
|
/* capacity transmit */
|
|
MASK_FLS,
|
|
|
|
/* file info transfer all request, file info transfer */
|
|
MASK_FLS, MASK_FLS,
|
|
|
|
/* flash image transfer request, flash image transfer */
|
|
MASK_ALL, MASK_ALL,
|
|
|
|
/* optimize filesystem */
|
|
MASK_FLS,
|
|
|
|
/* [OS UPDATE] */
|
|
/* CASIOWIN entry transfer request, CASIOWIN entry transfer */
|
|
MASK_ALL, MASK_ALL,
|
|
|
|
/* Bootcode transfer request, bootcode transfer */
|
|
MASK_ALL, MASK_ALL,
|
|
|
|
/* 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 (quite a few models);
|
|
* - Lephenixnoir, Hackcell (some but less 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 */
|
|
{"Gy490006", "fx-7400GII (Graph 25)",
|
|
MASK_ALL | MASK_RESET | MASK_MCS | MASK_LINK},
|
|
{"Gy49000F", "Graph 25+E (modified fx-7400GII-2)",
|
|
MASK_ALL | MASK_RESET | MASK_MCS | MASK_LINK},
|
|
{"Gy363004", "fx-9860G (Graph 85)",
|
|
MASK_ALL | MASK_RESET | MASK_MCS | MASK_LINK
|
|
| MASK_FLS},
|
|
{"Gy362006", "fx-9750GII (Graph 25+Pro)",
|
|
MASK_ALL | MASK_RESET | MASK_MCS | MASK_LINK},
|
|
{"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},
|
|
{"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},
|
|
|
|
/* cg 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(unsigned int 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);
|
|
}
|