cake
/
libp7
Archived
1
0
Fork 1
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
libp7/include/libp7/packet.h

313 lines
6.7 KiB
C

/* ************************************************************************** */
/* _____ _ */
/* libp7/packet.h |_ _|__ _ _| |__ ___ _ _ */
/* | Project: libp7 | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/10/13 07:36:52 |___/ */
/* */
/* ************************************************************************** */
#ifndef LIBP7_PACKET_H
# define LIBP7_PACKET_H
# define MAX_COMMAND_ARGUMENT_SIZE 32
# define MAX_VRAM_SIZE 1024 /* increase in case of other vram formats */
# define MAX_VRAM_WIDTH 128
# define MAX_VRAM_HEIGHT 64
# ifdef __cplusplus
extern "C" {
# endif
/* ************************************************************************** */
/* Useful structures */
/* ************************************************************************** */
/**
* p7_version_t:
* Version ("xx.xx.xx" + type).
*/
typedef struct {
unsigned int major;
unsigned int minor;
unsigned int rev;
char type[9];
} p7_version_t;
/**
* p7_protocolversion_t:
* Protocol version ("x.xx").
*/
typedef struct {
unsigned int major;
unsigned int minor;
} p7_protocolversion_t;
/**
* p7_packettype_t:
* Packet type.
*/
typedef enum {
p7_pt_cmd = 0x01,
p7_pt_data = 0x02,
p7_pt_roleswp = 0x03,
p7_pt_check = 0x05,
p7_pt_ack = 0x06,
p7_pt_ohp = 0x0B,
p7_pt_error = 0x15,
p7_pt_terminate = 0x18
} p7_packettype_t;
/**
* p7_packetscreen_t:
* Packet screen type.
*/
typedef enum {
p7_pscr_typ01
} p7_packetscreen_t;
/**
* p7_packetcommand_t:
* Packet command ID.
*/
typedef enum {
/* System commands */
p7_cc_sys_reset = 0x00,
p7_cc_sys_getdevinfo = 0x01,
p7_cc_sys_setlink = 0x02,
p7_cc_sys_setlinktimeout = 0x06,
p7_cc_osu_check1 = 0x07,
p7_cc_osu_check2 = 0x08,
p7_cc_osu_check3 = 0x09,
p7_cc_osu_check4 = 0x0A,
/* Flash commands */
p7_cc_fls_mkdir = 0x40,
p7_cc_fls_rmdir = 0x41,
p7_cc_fls_mvdir = 0x42,
p7_cc_fls_cwd = 0x43,
p7_cc_fls_req = 0x44,
p7_cc_fls_send = 0x45,
p7_cc_fls_del = 0x46,
p7_cc_fls_mv = 0x47,
p7_cc_fls_cp = 0x48,
p7_cc_fls_recvall = 0x49,
p7_cc_fls_reset = 0x4A,
p7_cc_fls_recvcap = 0x4B,
p7_cc_fls_sendcap = 0x4C,
p7_cc_fls_recvinfo_all = 0x4D,
p7_cc_fls_sendinfo = 0x4E,
p7_cc_fls_optimize = 0x51,
/* backup commands */
p7_cc_bak_reqrom = 0x4F,
p7_cc_bak_sendrom = 0x50,
p7_cc_bak_reqcasiowin = 0x52,
p7_cc_bak_sendcasiowin = 0x53,
p7_cc_bak_reqboot = 0x54,
p7_cc_bak_sendboot = 0x55,
/* OS Update commands */
p7_cc_osu_upandrun = 0x56 /* upload and run */
} p7_commandcode_t;
/**
* p7_packetcommandoverwrite_t:
* Defines the behaviour if file already exists.
*
* Moo.
*/
typedef enum {
p7_cow_request_confirmation_before_overwriting = 0x00,
p7_cow_terminate_if_file_exists = 0x01,
p7_cow_force_overwrite = 0x02
} p7_commandoverwrite_t;
/**
* p7_errcode_t:
* Error codes.
*/
typedef enum {
p7_ec_resend = 0x01,
p7_ec_overwrite = 0x02,
p7_ec_overwrite_noresponse = 0x03,
p7_ec_overwrite_impossible = 0x04,
p7_ec_fullmem = 0x05
} p7_errcode_t;
/**
* p7_termtype_t:
* Termination type.
*/
typedef enum {
p7_tmt_default = 0x00,
p7_tmt_user = 0x01,
p7_tmt_timeouts = 0x02,
p7_tmt_overwrite = 0x03
} p7_termtype_t;
/* ************************************************************************** */
/* Packet parts specific to one packet type */
/* ************************************************************************** */
/**
* p7_packetcommand_t:
* Command packet data fields.
*/
typedef struct {
p7_commandcode_t code;
/* normal command */
p7_commandoverwrite_t overwrite;
unsigned int datatype; /* TODO: libg1m */
p7uint_t filesize;
/* - i know, big, but i don't want to allocate manually each time :( - */
char args[6][MAX_COMMAND_ARGUMENT_SIZE];
/* up_and_run command */
p7uint_t uploadsize;
p7uint_t loadaddr;
p7uint_t straddr;
} p7_packetcommand_t;
/**
* p7_packetdata_t:
* Data packet data fields.
*/
typedef struct {
/* total number of data packets, id of the current one */
p7ushort_t total, id;
/* data and data size */
unsigned char data[256];
p7ushort_t size;
} p7_packetdata_t;
/**
* p7_packetcheck_t:
* Check packet data fields.
*/
typedef struct {
int initial;
} p7_packetcheck_t;
/**
* p7_packetack_t:
* Extended ack packet data fields.
*/
typedef struct {
/* check if is extended */
int extended;
/* check if is file overwriting confirmation */
int overwrite;
/* preprogrammed ROM info looks wiped out */
int preprog_rom_wiped;
/* preprogrammed ROM capacity */
p7uint_t preprog_rom_capacity;
/* preprogrammed ROM version */
p7_version_t preprog_rom_version;
/* flash ROM capacity */
p7uint_t flash_rom_capacity;
/* RAM capacity */
p7uint_t ram_capacity;
/* bootcode info looks wiped out */
int bootcode_wiped;
/* bootcode version */
p7_version_t bootcode_version;
/* bootcode offset */
p7uint_t bootcode_offset;
/* bootcode_size */
p7uint_t bootcode_size;
/* OS code version */
p7_version_t os_version;
/* OS code offset */
p7uint_t os_offset;
/* OS code size */
p7uint_t os_size;
/* protocol version */
p7_protocolversion_t protocol_version;
/* product ID */
char product_id[17];
/* name set by user in SYSTEM */
char username[17];
/* hardware and processor identifiers */
char hwid[9], cpuid[17];
} p7_packetack_t;
/**
* p7_packeterr_t:
* Error packet data fields.
*/
typedef struct {
p7_errcode_t code;
} p7_packeterr_t;
/**
* p7_packetterm_t:
* Terminate packet data fields.
*/
typedef struct {
p7_termtype_t reason;
} p7_packetterm_t;
/**
* p7_packetscr_t:
* Screen packet data fields.
*/
typedef struct {
p7_packetscreen_t type;
unsigned char vram[MAX_VRAM_SIZE];
} p7_packetscr_t;
/* ************************************************************************** */
/* The packet definition */
/* ************************************************************************** */
/**
* p7_packet_t:
* Packet representation.
*
* Easy to read.
*/
typedef struct {
/* main info */
p7_packettype_t type;
/* for command packet */
p7_packetcommand_t command;
/* for data packet */
p7_packetdata_t data;
/* for check packet */
p7_packetcheck_t check;
/* for ack packet */
p7_packetack_t ack;
/* for error packet */
p7_packeterr_t error;
/* for terminate packet */
p7_packetterm_t term;
/* for screen packet */
p7_packetscr_t screen;
} p7_packet_t;
# ifdef __cplusplus
}
# endif
#endif /* LIBP7_PACKET_H */