Corrected serial management, made libg1m required.
This commit is contained in:
parent
12d746516b
commit
ce30879d04
|
@ -28,7 +28,7 @@
|
|||
VERSION := $(MAJOR).$(MINOR)$(if $(INDEV),-indev)
|
||||
|
||||
# Runtime libs (later: libg1m and libfontcharacter)
|
||||
RLIBS := $(if $(USE_LIBG1M),libg1m)
|
||||
RLIBS := libg1m
|
||||
|
||||
# Compilation time libs
|
||||
LIBS := zlib $(if $(USE_LIBUSB),libusb-1.0) $(RLIBS)
|
||||
|
|
|
@ -70,7 +70,6 @@ Build options:
|
|||
--windows build DLLs and .libs instead of ELF and archives
|
||||
--optimize-size optimize size instead of speed
|
||||
--no-libusb do not use libusb
|
||||
--no-libg1m do not use libg1m
|
||||
--no-file do not use the libc FILE interface
|
||||
--no-manpages do not make and install manpages
|
||||
--loglevel=LEVEL library log level [$loglevel]
|
||||
|
@ -265,7 +264,6 @@ cat <<EOF
|
|||
TARGET := $target
|
||||
OPTIMIZE_SIZE := $optimize_size
|
||||
USE_LIBUSB := $libusb
|
||||
USE_LIBG1M := $libg1m
|
||||
LOG_LEVEL := $loglevel
|
||||
INIT_TRIES := $init_tries
|
||||
|
||||
|
|
|
@ -116,7 +116,6 @@ extern int p7_comlist(p7_list_device_t callback, void *cookie);
|
|||
/* De-initialization */
|
||||
extern void p7_exit(p7_handle_t *handle);
|
||||
|
||||
# ifndef P7_DISABLED_LIBG1M
|
||||
/* ************************************************************************** */
|
||||
/* MCS interaction */
|
||||
/* ************************************************************************** */
|
||||
|
@ -127,8 +126,6 @@ extern int p7_mcs_list(p7_handle_t *handle, p7_mcslist_t callback,
|
|||
/* Request a file */
|
||||
extern int p7_mcs_request(p7_handle_t *handle, g1m_mcsfile_t **file,
|
||||
g1m_mcshead_t *head, p7_disp_t disp);
|
||||
|
||||
# endif
|
||||
/* ************************************************************************** */
|
||||
/* Storage memory interaction */
|
||||
/* ************************************************************************** */
|
||||
|
|
|
@ -41,7 +41,6 @@
|
|||
# ifndef max
|
||||
# define max(A, B) ((A) > (B) ? (A) : (B))
|
||||
# endif
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Maximum buffer sizes */
|
||||
/* ************************************************************************** */
|
||||
|
@ -52,19 +51,21 @@
|
|||
|
||||
/* The maximum size of the encoded data field.
|
||||
* > id (4 bytes) + total (4 bytes) + encoded data
|
||||
*
|
||||
* The worst case is where every byte has to be encoded (an '\' has to be
|
||||
* added), so the size of the worst (biggest) case is MAX_RAWDFLD_SIZE * 2. */
|
||||
|
||||
# define MAX_ENCDFLD_SIZE (8 + (MAX_RAWDATA_SIZE * 2))
|
||||
|
||||
/* The maximum packet size. Used to be :
|
||||
* > t + st + ext + encoded D field + checksum + nullbyte
|
||||
* > t + st + ext + encoded D field + checksum + null byte
|
||||
* > 8 + MAX_ENCDFLD_SIZE + 2 + 1
|
||||
*
|
||||
* But with OHP (screen streaming) introduction, this size wasn't enough to
|
||||
* store screen streaming packets. So we use the OHP packet size as a
|
||||
* reference, even for normal protocol, in case user launches "normal" packet
|
||||
* mode and the calculator sends OHP packets. The formula is :
|
||||
* mode and the calculator sends OHP packets. The formula is:
|
||||
*
|
||||
* > ohp type + (subheader) + pic data + checksum */
|
||||
|
||||
# define MAX_PACKET_SIZE (6 + 18 + MAX_VRAM_SIZE + 2)
|
||||
|
@ -103,6 +104,7 @@ extern int p7_command_is_supported(unsigned int code, const p7_env_t *env);
|
|||
# define p7_intflag_term 0x0080 /* should terminate at exit */
|
||||
# define p7_intflag_nocheck 0x0100 /* should not read the next checksum */
|
||||
# define p7_intflag_adjscreen 0x0200 /* adjust to get the screenstream begin */
|
||||
# define p7_intflag_check 0x0400 /* make the initial check */
|
||||
|
||||
/* handle structure */
|
||||
struct p7_handle_s {
|
||||
|
@ -125,9 +127,7 @@ struct p7_handle_s {
|
|||
p7_packet_t _response_data;
|
||||
|
||||
/* MCS head */
|
||||
# ifndef P7_DISABLED_LIBG1M
|
||||
g1m_mcshead_t mcshead;
|
||||
# endif
|
||||
|
||||
/* raw sending packet buffers */
|
||||
unsigned char _send_buffers[2][MAX_PACKET_SIZE];
|
||||
|
@ -146,7 +146,7 @@ extern int _p7_finit(p7_handle_t **handle, unsigned int flags,
|
|||
/* Protocol 7.00 Packet I/O utilities */
|
||||
/* ************************************************************************** */
|
||||
/* start communication */
|
||||
extern int p7_seven_start(p7_handle_t *handle, int check);
|
||||
extern int p7_seven_start(p7_handle_t *handle);
|
||||
extern int p7_seven_end(p7_handle_t *handle);
|
||||
|
||||
/* decode packets */
|
||||
|
|
|
@ -26,7 +26,11 @@
|
|||
/* ************************************************************************** */
|
||||
/* Common structures */
|
||||
/* ************************************************************************** */
|
||||
/* And here is the libp7 packet representation: */
|
||||
/* For now, libp7 has a common packet representation for all protocols.
|
||||
* It contains all the possible fields, but depending on the protocol and the
|
||||
* packet type, only some of them are actually set.
|
||||
*
|
||||
* Here is the structure: */
|
||||
|
||||
typedef struct {
|
||||
/* main info */
|
||||
|
@ -54,11 +58,14 @@ typedef struct {
|
|||
unsigned int height, width;
|
||||
uint8_t vram[MAX_VRAM_SIZE];
|
||||
} p7_packet_t;
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Get private members from the handle */
|
||||
/* ************************************************************************** */
|
||||
/* Get the packet representation from the handle. */
|
||||
/* Since the handle structure is private, here are methods to extract
|
||||
* things from it. */
|
||||
|
||||
extern const p7_stream_t *p7_get_stream(p7_handle_t *handle);
|
||||
extern const p7_server_t *p7_get_info(p7_handle_t *handle);
|
||||
extern const p7_packet_t *p7_get_response(p7_handle_t *handle);
|
||||
|
||||
#endif /* LIBP7_PACKETIO_H */
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
/* *****************************************************************************
|
||||
* libp7/protocol/legacy.h -- libp7 legacy protocol packet I/O interface.
|
||||
* Copyright (C) 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/>.
|
||||
*
|
||||
* Aside from the public and easy interface described in `libp7.h`, you may
|
||||
* want to have more control on the communication. This file is one of
|
||||
* the ones: it allows you to exchange packets directly, using legacy protocols
|
||||
* (libp7 internals will take care of the odd details).
|
||||
* ************************************************************************** */
|
||||
#ifndef LIBP7_PROTOCOL_LEGACY_H
|
||||
# define LIBP7_PROTOCOL_LEGACY_H
|
||||
# include <libp7/types.h>
|
||||
# include <libp7/stream.h>
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
/* In these protocols, there are two types of packets: one-byte packets,
|
||||
* and multi-byte packets (headers, headers data, data). libg1m manages
|
||||
* multi-byte packets, we only have to manage one-byte packets here. */
|
||||
/* ************************************************************************** */
|
||||
/* Checks */
|
||||
/* ************************************************************************** */
|
||||
/* At the beginning of the communication, the active side sends one of two
|
||||
* possible bytes: 0x15 if the communication is supposed to be interactive,
|
||||
* 0x16 if not. */
|
||||
|
||||
# define p7_legacy_start_interactive 0x15
|
||||
# define p7_legacy_start_noninteractive 0x16
|
||||
|
||||
/* Then the passive side is supposed to send an initial packet confirmation: */
|
||||
|
||||
# define p7_legacy_start_ack 0x13
|
||||
/* ************************************************************************** */
|
||||
/* Main communication */
|
||||
/* ************************************************************************** */
|
||||
/* The active side starts by sending a header (starting with 0x3A, ':').
|
||||
* The passive side then answers with either an ACK (0x06), or
|
||||
* an overwrite error (0x21) if the file already exists.
|
||||
*
|
||||
* If we, as te active side, are in an overwrite confirmation situation,
|
||||
* we can either send an ABORT (0x15) to not overwrite, or an ACK if it
|
||||
* accepts. If we have something else than an ACK after the overwrite
|
||||
* confirmation, then this means that the passive side cannot overwrite.
|
||||
*
|
||||
* Once the header is accepted, the active side sends the header data parts
|
||||
* and the data parts corresponding to the headers.
|
||||
*
|
||||
* For the headers or (headers) data parts, there is a checksum. If this
|
||||
* checksum isn't right, the passive side asks the header/part again, with
|
||||
* the 0x2B error. If the header data type is unknown, the passive side
|
||||
* sends 0x24 (or 0x00?). If the header has some errors, the passive side
|
||||
* sends 0x51, and the transfer aborts. */
|
||||
|
||||
# define p7_legacy_unknown 0x00 /* zero length data, send no more, ok? */
|
||||
# define p7_legacy_ack 0x06
|
||||
# define p7_legacy_abort 0x15 /* "something is wrong with the header" */
|
||||
# define p7_legacy_exists 0x21 /* file exists, overwrite? */
|
||||
# define p7_legacy_cafixunknown 0x22 /* this is in cafix. */
|
||||
# define p7_legacy_unknown_type 0x24 /* or out of memory? */
|
||||
# define p7_legacy_resend 0x2B
|
||||
# define p7_legacy_errors 0x51
|
||||
|
||||
/* TODO: what the hell is interactive? */
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
#endif /* LIBP7_PROTOCOL_LEGACY_H */
|
|
@ -17,9 +17,9 @@
|
|||
* along with libp7; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Aside from the public and easy interface described in `libp7.h`, you may
|
||||
* want to have more control on the communication. This file is the one: it
|
||||
* allows you to exchange packets directly, using Protocol 7 (libp7 internals
|
||||
* will take care of the odd details).
|
||||
* want to have more control on the communication. This file is one of
|
||||
* the ones: it allows you to exchange packets directly, using Protocol 7.00
|
||||
* (libp7 internals will take care of the odd details).
|
||||
* ************************************************************************** */
|
||||
#ifndef LIBP7_PROTOCOL_SEVEN_H
|
||||
# define LIBP7_PROTOCOL_SEVEN_H
|
||||
|
@ -242,8 +242,8 @@ extern int p7_seven_send_cmd_data(p7_handle_t *handle, p7ushort_t subtype,
|
|||
* passive side. Then, once the command is ACK-ed, according to the command,
|
||||
* different packet flows can occur. Here are a few characteristic examples:
|
||||
*
|
||||
* - File action. For example, file removing require nothing after the command
|
||||
* confirmation;
|
||||
* - Simple action. For example, file removing require nothing after the
|
||||
* command confirmation;
|
||||
* - File sending. After the overwrite flow, the active side sends data
|
||||
* packets containing the file data (`p7_send_buffer`/`p7_send_data`);
|
||||
* - File receiving. The active side sends a role swap packet, then the
|
||||
|
|
|
@ -27,7 +27,6 @@ static inline int p7_seven_send_cmd##C(p7_handle_t *handle) { \
|
|||
/* ************************************************************************** */
|
||||
/* Main Memory command formats */
|
||||
/* ************************************************************************** */
|
||||
# ifndef P7_DISABLED_LIBG1M
|
||||
/* Interact with an MCS file */
|
||||
# define p7_sevencmd_mcsfile(C, CODE) \
|
||||
static inline int p7_send_cmd##C(p7_handle_t *handle, \
|
||||
|
@ -35,10 +34,6 @@ static inline int p7_send_cmd##C(p7_handle_t *handle, \
|
|||
return (p7_seven_send_cmd_data(handle, CODE, 0, head->_rawtype, 0, \
|
||||
(char*)head->_dirname, (char*)head->name, (char*)head->_group, \
|
||||
NULL, NULL, NULL)); }
|
||||
|
||||
# else
|
||||
# define p7_sevencmd_mcsfile(C, CODE)
|
||||
# endif
|
||||
/* ************************************************************************** */
|
||||
/* Storage command formats */
|
||||
/* ************************************************************************** */
|
||||
|
|
|
@ -41,9 +41,6 @@ extern int p7_serve_directly(p7_handle_t *handle,
|
|||
extern int p7_serve(p7_handle_t *handle, p7_server_t *info,
|
||||
p7_filesystem_t *filesystems);
|
||||
|
||||
/* The libp7 server information extractor */
|
||||
extern const p7_server_t *p7_get_info(p7_handle_t *handle);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
|
|
@ -251,9 +251,6 @@ extern int p7_sinit(p7_handle_t **h, unsigned int flags,
|
|||
const char *name, p7_stream_t stream,
|
||||
const p7_streamsettings_t *settings);
|
||||
|
||||
/* Extract the stream out of the handle. */
|
||||
extern const p7_stream_t *p7_get_stream(p7_handle_t *handle);
|
||||
|
||||
/* Default stream serial settings utilities.
|
||||
* `p7_initcomm` initializes a stream settings structure. */
|
||||
extern void p7_initcomm(p7_streamsettings_t *settings);
|
||||
|
|
|
@ -33,9 +33,7 @@
|
|||
# else
|
||||
# include <alloca.h>
|
||||
# endif
|
||||
# ifndef P7_DISABLED_LIBG1M
|
||||
# include <libg1m.h>
|
||||
# endif
|
||||
# include <libg1m.h>
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
@ -88,31 +86,36 @@ extern const size_t p7_handle_size;
|
|||
/* ************************************************************************** */
|
||||
/* Callbacks */
|
||||
/* ************************************************************************** */
|
||||
/* This callback is for serial devices listing ; for each device found, the
|
||||
/* p7_list_device_t:
|
||||
* This callback is for serial devices listing; for each device found, the
|
||||
* callback is found with its device. */
|
||||
|
||||
typedef void (*p7_list_device_t)(void*, const char*);
|
||||
|
||||
/* This callback is for `p7_getscreen`: when a screen is received, it is called
|
||||
/* p7_screenfunc_t:
|
||||
* This callback is for `p7_getscreen`: when a screen is received, it is called
|
||||
* with the width, the height and the pixels, and returns either 1 if we should
|
||||
* continue, or 0 if we should stop. */
|
||||
|
||||
typedef int (*p7_screenfunc_t)(int, int, uint32_t**);
|
||||
|
||||
/* This callback is for displaying the progress of an operation (usually
|
||||
/* p7_disp_t:
|
||||
* This callback is for displaying the progress of an operation (usually
|
||||
* file/data transfer). It receives the packet ID and the total number of
|
||||
* packets. For initialization of the display, this callback is called with
|
||||
* a packet ID superior to the number of packets. */
|
||||
|
||||
typedef void (*p7_disp_t)(p7ushort_t, p7ushort_t);
|
||||
|
||||
/* This callback is for if a confirmation needs to be obtained from the user
|
||||
/* p7_confirm_t:
|
||||
* This callback is for if a confirmation needs to be obtained from the user
|
||||
* (usually before overwriting a file). Returns 0 if the user has denied,
|
||||
* and something else if he has confirmed. */
|
||||
|
||||
typedef int (*p7_confirm_t)(void);
|
||||
|
||||
/* This callback is for storage file listing.
|
||||
/* p7_list_t:
|
||||
* This callback is for storage file listing.
|
||||
* The first argument is the cookie, the second argument is the
|
||||
* directory name (NULL if the file is as root), the third argument is the
|
||||
* file name (NULL if the entry is a directory), and the last argument
|
||||
|
@ -120,13 +123,11 @@ typedef int (*p7_confirm_t)(void);
|
|||
|
||||
typedef void (*p7_list_t)(void*, const char*, const char*, p7uint_t);
|
||||
|
||||
#ifndef P7_DISABLED_LIBG1M
|
||||
/* Basically the same as the previous one, but with the main memory.
|
||||
/* p7_mcslist_t:
|
||||
* Basically the same as the previous one, but with the main memory.
|
||||
* The MCS head given by libg1m contains the complementary information. */
|
||||
|
||||
typedef void (*p7_mcslist_t)(void*, const g1m_mcshead_t*);
|
||||
|
||||
#endif
|
||||
/* ************************************************************************** */
|
||||
/* Useful types */
|
||||
/* ************************************************************************** */
|
||||
|
@ -191,14 +192,16 @@ typedef struct {
|
|||
* information (fields used while serving). */
|
||||
|
||||
typedef struct {
|
||||
/* filesystem name */
|
||||
/* filesystem metadata */
|
||||
const char *name;
|
||||
void *cookie;
|
||||
|
||||
/* directory commands */
|
||||
int (*directory_exists)(const char *dirname);
|
||||
int (*create_directory)(const char *dirname);
|
||||
int (*delete_directory)(const char *dirname);
|
||||
int (*rename_directory)(const char *dirname, const char *newdir);
|
||||
int (*directory_exists)(void *cookie, const char *dirname);
|
||||
int (*create_directory)(void *cookie, const char *dirname);
|
||||
int (*delete_directory)(void *cookie, const char *dirname);
|
||||
int (*rename_directory)(void *cookie, const char *dirname,
|
||||
const char *newdir);
|
||||
|
||||
/* working things - only libp7 should manipulate those */
|
||||
char *working_directory, _wd[257];
|
||||
|
|
|
@ -112,7 +112,8 @@ int p7_sinit(p7_handle_t **h, unsigned int flags,
|
|||
handle->_flags = 0;
|
||||
if (alloc) handle->_flags |= p7_intflag_alloc;
|
||||
if (flags & P7_ACTIVE) handle->_flags |= p7_intflag_active;
|
||||
if (flags & P7_TERM) handle->_flags |= p7_intflag_term;
|
||||
if (flags & P7_TERM) handle->_flags |= p7_intflag_term;
|
||||
if (flags & P7_CHECK) handle->_flags |= p7_intflag_check;
|
||||
|
||||
/* prepare the name */
|
||||
if (name) {
|
||||
|
@ -129,8 +130,7 @@ int p7_sinit(p7_handle_t **h, unsigned int flags,
|
|||
p7_setcomm(&handle->_stream, &handle->_settings);
|
||||
|
||||
/* if active, start */
|
||||
if ((handle->_flags & p7_intflag_active)
|
||||
&& (err = p7_seven_start(handle, flags & P7_CHECK))) {
|
||||
if ((err = p7_seven_start(handle))) {
|
||||
p7_exit(*h); *h = NULL;
|
||||
return (err);
|
||||
}
|
||||
|
@ -138,7 +138,6 @@ int p7_sinit(p7_handle_t **h, unsigned int flags,
|
|||
/* initialization went alright */
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* De-initialization */
|
||||
/* ************************************************************************** */
|
||||
|
|
|
@ -87,12 +87,25 @@ int p7_write(p7_stream_t *stream, const void *data, size_t size)
|
|||
|
||||
int p7_setcomm(p7_stream_t *stream, const p7_streamsettings_t *settings)
|
||||
{
|
||||
if (stream->flags & p7_streamflag_usb || !stream->setcomm)
|
||||
if (stream->flags & p7_streamflag_usb) {
|
||||
logr_info("Stream is an USB device!");
|
||||
return (0);
|
||||
}
|
||||
if (!stream->setcomm) {
|
||||
logr_info("No communication manager for this stream.");
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* get the default settings if necessary */
|
||||
p7_streamsettings_t localsettings;
|
||||
if (!settings) {
|
||||
settings = &localsettings;
|
||||
p7_initcomm(&localsettings);
|
||||
}
|
||||
|
||||
/* describe the settings */
|
||||
#if LOGLEVEL <= ll_info
|
||||
const char *es[] = {"disabled", "enabled", "handshake", "<unknown>"};
|
||||
const char *es[] = {"disabled", "enabled", "handshake", "disabled"};
|
||||
|
||||
logr_info("Setting serial settings: %u%c%c",
|
||||
settings->speed, ~settings->flags & P7_PARENB ? 'N'
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
|
||||
int p7_legacy_start(p7_handle_t *handle)
|
||||
{
|
||||
|
||||
|
||||
/* receive the attention request */
|
||||
unsigned char byte;
|
||||
p7_read(handle->stream, &byte, 1, 0);
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
* along with libp7; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************** */
|
||||
#include <libp7/internals.h>
|
||||
#define checkflags (p7_intflag_active | p7_intflag_check)
|
||||
#define endflags (p7_intflag_active | p7_intflag_term)
|
||||
|
||||
/**
|
||||
* p7_seven_start:
|
||||
|
@ -26,13 +28,17 @@
|
|||
* @return the error, if any.
|
||||
*/
|
||||
|
||||
int p7_seven_start(p7_handle_t *handle, int check)
|
||||
int p7_seven_start(p7_handle_t *handle)
|
||||
{
|
||||
if ((handle->_flags & checkflags) != checkflags)
|
||||
return (0);
|
||||
|
||||
/* start */
|
||||
int err = 0;
|
||||
log_info("so we're active? let's do what active people do then!");
|
||||
|
||||
/* send initial check */
|
||||
if (check) {
|
||||
if (handle->_flags & p7_intflag_check) {
|
||||
log_info("sending initial check packet");
|
||||
if ((err = p7_seven_send_ini_check(handle))) {
|
||||
log_fatal("couldn't send check/didn't receive answer");
|
||||
|
@ -78,23 +84,22 @@ int p7_seven_start(p7_handle_t *handle, int check)
|
|||
|
||||
int p7_seven_end(p7_handle_t *handle)
|
||||
{
|
||||
int err;
|
||||
if ((handle->_flags & endflags) != endflags
|
||||
|| ~handle->_flags & p7_intflag_terminated)
|
||||
return (0);
|
||||
|
||||
if (handle->_flags & p7_intflag_active
|
||||
&& ~handle->_flags & p7_intflag_terminated
|
||||
&& handle->_flags & p7_intflag_term) {
|
||||
/* send the termination packet */
|
||||
log_info("we were active, send sending terminate packet");
|
||||
if ((err = p7_seven_send_term(handle))) {
|
||||
log_warn("couldn't send terminate packet, already disconnected?");
|
||||
return (err);
|
||||
}
|
||||
/* send the termination packet */
|
||||
log_info("we were active, send sending terminate packet");
|
||||
int err = p7_seven_send_term(handle);
|
||||
if (err) {
|
||||
log_warn("couldn't terminate, already disconnected?");
|
||||
return (err);
|
||||
}
|
||||
|
||||
/* check ack */
|
||||
if (response.type != p7_seven_type_ack) {
|
||||
log_warn("answer to terminate packet wasn't ack!");
|
||||
return (p7_error_unknown);
|
||||
}
|
||||
/* check ack */
|
||||
if (response.type != p7_seven_type_ack) {
|
||||
log_warn("answer to terminate packet wasn't ack!");
|
||||
return (p7_error_unknown);
|
||||
}
|
||||
|
||||
/* no error! */
|
||||
|
|
|
@ -300,6 +300,7 @@ static int p7_seven_recv_main(p7_handle_t *handle)
|
|||
else log_error("Unknown encoding: %.3s", s->enc);
|
||||
#endif
|
||||
|
||||
/* FIXME: check size according to format? */
|
||||
image_size = p7_getascii(s->size, 6);
|
||||
log_info("Image size: %uB", image_size);
|
||||
handle->_flags |= p7_intflag_nocheck;
|
||||
|
@ -308,6 +309,12 @@ static int p7_seven_recv_main(p7_handle_t *handle)
|
|||
return (p7_error_checksum);
|
||||
}
|
||||
|
||||
/* check if we should skip */
|
||||
if (!response.pictype || image_size > MAX_VRAM_SIZE) {
|
||||
p7_skip(&handle->_stream, image_size); /* FIXME: checksum? */
|
||||
return (p7_error_unknown);
|
||||
}
|
||||
|
||||
/* complete packet */
|
||||
size_t hdsize = received;
|
||||
log_info("Get screen content (%uo)", image_size);
|
||||
|
|
|
@ -117,12 +117,14 @@ static int setcomm_for_fd(const int fd, const p7_streamsettings_t *settings)
|
|||
case P7_B38400: speed = B38400; break;
|
||||
case P7_B57600: speed = B57600; break;
|
||||
case P7_B115200: speed = B115200; break;
|
||||
default: return (p7_error_unsupported);
|
||||
default:
|
||||
logr_info("Speed was unsupported by termios: %u", settings->speed);
|
||||
return (p7_error_unsupported);
|
||||
}
|
||||
|
||||
/* get the current configuration */
|
||||
struct termios term;
|
||||
if (!tcgetattr(fd, &term))
|
||||
if (tcgetattr(fd, &term) < 0)
|
||||
return (p7_error_unknown);
|
||||
|
||||
/* set the speed */
|
||||
|
@ -130,14 +132,13 @@ static int setcomm_for_fd(const int fd, const p7_streamsettings_t *settings)
|
|||
cfsetospeed(&term, speed);
|
||||
|
||||
/* input flags */
|
||||
term.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR
|
||||
term.c_iflag &= ~(IGNBRK | IGNCR | BRKINT | PARMRK | ISTRIP | INLCR
|
||||
| ICRNL | IGNPAR | IXON | IXOFF);
|
||||
if (~settings->flags & P7_PARENB) term.c_iflag |= IGNPAR;
|
||||
if (settings->flags & P7_XONMASK) term.c_iflag |= IXON;
|
||||
if (settings->flags & P7_XOFFMASK) term.c_iflag |= IXOFF;
|
||||
|
||||
/* output flags, local modes */
|
||||
term.c_oflag &= ~(OPOST);
|
||||
term.c_oflag = 0;
|
||||
term.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
|
||||
|
||||
/* control flags */
|
||||
|
@ -156,15 +157,18 @@ static int setcomm_for_fd(const int fd, const p7_streamsettings_t *settings)
|
|||
if (tcsetattr(fd, TCSANOW, &term))
|
||||
return (p7_error_unknown);
|
||||
|
||||
/* get line status */
|
||||
int status; if (ioctl(fd, TIOCMGET, &status) >= 0) status = 0;
|
||||
status &= ~(TIOCM_DTR | TIOCM_RTS);
|
||||
|
||||
/* activate DTR and RTS */
|
||||
int status = 0;
|
||||
if ((settings->flags & P7_DTRMASK) == P7_DTRCTL_ENABLE
|
||||
|| (settings->flags & P7_DTRMASK) == P7_DTRCTL_HANDSHAKE)
|
||||
status |= TIOCM_DTR;
|
||||
if ((settings->flags & P7_RTSMASK) == P7_RTSCTL_ENABLE
|
||||
|| (settings->flags & P7_RTSMASK) == P7_RTSCTL_HANDSHAKE)
|
||||
status |= TIOCM_RTS;
|
||||
if (status && ioctl(fd, TIOCMBIS, &status) < 0)
|
||||
if (status && ioctl(fd, TIOCMSET, &status) < 0)
|
||||
return (p7_error_unknown);
|
||||
|
||||
/* no error! */
|
||||
|
@ -476,6 +480,8 @@ int p7_sopen_streams(p7_stream_t *stream, const char *path,
|
|||
stream->setcomm = p7_streams_setcomm;
|
||||
stream->settm = p7_streams_settm;
|
||||
stream->close = p7_streams_close;
|
||||
|
||||
/* end */
|
||||
err = 0;
|
||||
fail:
|
||||
if (err) {
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* along with libp7; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************** */
|
||||
#include <libp7/internals.h>
|
||||
#ifndef P7_DISABLED_LIBG1M
|
||||
|
||||
/**
|
||||
* p7_mcs_list:
|
||||
|
@ -82,5 +81,3 @@ int p7_mcs_list(p7_handle_t *handle, p7_mcslist_t callback, void *cookie)
|
|||
return (p7_error_unknown);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* along with libp7; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************** */
|
||||
#include <libp7/internals.h>
|
||||
#ifndef P7_DISABLED_LIBG1M
|
||||
|
||||
/**
|
||||
* p7_mcs_request:
|
||||
|
@ -92,5 +91,3 @@ fail:
|
|||
free(tmp);
|
||||
return (err);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -202,7 +202,7 @@ static int create_directory(p7_server_cookie_t *cookie, p7_handle_t *handle)
|
|||
/* create the directory */
|
||||
if (!fs->create_directory || !sdir)
|
||||
return (p7_error_unknown);
|
||||
int err = (*fs->create_directory)(sdir);
|
||||
int err = (*fs->create_directory)(fs->cookie, sdir);
|
||||
if (err) return (err);
|
||||
|
||||
/* send ack */
|
||||
|
@ -226,7 +226,7 @@ static int delete_directory(p7_server_cookie_t *cookie, p7_handle_t *handle)
|
|||
/* delete the directory */
|
||||
if (!fs->delete_directory || !sdir)
|
||||
return (p7_error_unknown);
|
||||
int err = (*fs->delete_directory)(sdir);
|
||||
int err = (*fs->delete_directory)(fs->cookie, sdir);
|
||||
if (err) return (err);
|
||||
|
||||
/* send ack */
|
||||
|
@ -250,7 +250,7 @@ static int rename_directory(p7_server_cookie_t *cookie, p7_handle_t *handle)
|
|||
/* rename the directory */
|
||||
if (!fs->rename_directory || !sdir || !response.args[1])
|
||||
return (p7_error_unknown);
|
||||
int err = (*fs->rename_directory)(sdir, response.args[1]);
|
||||
int err = (*fs->rename_directory)(fs->cookie, sdir, response.args[1]);
|
||||
if (err) return (err);
|
||||
|
||||
/* send ack */
|
||||
|
@ -276,7 +276,7 @@ static int change_working_directory(p7_server_cookie_t *cookie,
|
|||
if (!response.args[0])
|
||||
fs->working_directory = NULL;
|
||||
else if (fs->directory_exists
|
||||
&& (*fs->directory_exists)(response.args[0])) {
|
||||
&& (*fs->directory_exists)(fs->cookie, response.args[0])) {
|
||||
log_info("Directory does not exist, not changing!");
|
||||
return (p7_error_unknown);
|
||||
} else {
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
# Initialize the variables
|
||||
no_file=
|
||||
no_libusb=
|
||||
no_libg1m=
|
||||
version=
|
||||
maintainer='anon <anon@localhost>'
|
||||
|
||||
|
@ -13,7 +12,6 @@ maintainer='anon <anon@localhost>'
|
|||
for arg ; do case "$arg" in
|
||||
--no-file) no_file=y ;;
|
||||
--no-libusb) no_libusb=y ;;
|
||||
--no-libg1m) no_libg1m=y ;;
|
||||
--version=*) version="${arg#*=}" ;;
|
||||
--maintainer=*) maintainer="${arg#*=}" ;;
|
||||
*) echo "'${arg}': Did not read." >&2 ;;
|
||||
|
@ -88,14 +86,6 @@ if [ "$no_libusb" ]; then cat <<_EOF
|
|||
_EOF
|
||||
fi
|
||||
|
||||
# libg1m part
|
||||
if [ "$no_libg1m" ]; then cat <<_EOF
|
||||
/* libg1m is disabled */
|
||||
# define P7_DISABLED_LIBG1M 1
|
||||
|
||||
_EOF
|
||||
fi
|
||||
|
||||
# End of the file.
|
||||
cat <<_EOF
|
||||
#endif /* LIBP7_CONFIG_H */
|
||||
|
|
Reference in New Issue