2013-07-13 00:01:37 +02:00
|
|
|
/****************************************************************************
|
2016-07-01 14:48:22 +02:00
|
|
|
* apps/include/system/zmodem.h
|
2013-07-13 00:01:37 +02:00
|
|
|
*
|
2021-06-11 08:28:21 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2013-07-13 00:01:37 +02:00
|
|
|
*
|
2021-06-11 08:28:21 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-13 00:01:37 +02:00
|
|
|
*
|
2021-06-11 08:28:21 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2013-07-13 00:01:37 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-06-11 08:28:21 +02:00
|
|
|
/* References:
|
|
|
|
* "The ZMODEM Inter Application File Transfer Protocol", Chuck Forsberg,
|
|
|
|
* Omen Technology Inc., October 14, 1988
|
|
|
|
*/
|
|
|
|
|
2016-07-01 14:48:22 +02:00
|
|
|
#ifndef __APPS_INCLUDE_SYSTEM_ZMODEM_H
|
|
|
|
#define __APPS_INCLUDE_SYSTEM_ZMODEM_H
|
2013-07-13 00:01:37 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
2021-06-11 11:07:52 +02:00
|
|
|
|
2013-07-13 00:01:37 +02:00
|
|
|
/* Configuration ************************************************************/
|
2013-07-13 21:19:15 +02:00
|
|
|
|
|
|
|
/* The default device used by the Zmodem commands if the -d option is not
|
|
|
|
* provided on the sz or rz command line.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_SYSTEM_ZMODEM_DEVNAME
|
|
|
|
# define CONFIG_SYSTEM_ZMODEM_DEVNAME "/dev/console"
|
|
|
|
#endif
|
|
|
|
|
2013-07-15 01:01:23 +02:00
|
|
|
/* The size of one buffer used to read data from the remote peer. The total
|
|
|
|
* buffering capability is SYSTEM_ZMODEM_RCVBUFSIZE plus the size of the RX
|
|
|
|
* buffer in the device driver. If you are using a serial driver with, say,
|
|
|
|
* USART0. That that buffering capability includes USART0_RXBUFFERSIZE.
|
|
|
|
* This total buffering capability must be significantly larger than
|
|
|
|
* SYSTEM_ZMODEM_PKTBUFSIZE (larger due streaming race conditions, data
|
|
|
|
* expansion due to escaping, and possible protocol overhead).
|
|
|
|
*/
|
2013-07-13 00:01:37 +02:00
|
|
|
|
|
|
|
#ifndef CONFIG_SYSTEM_ZMODEM_RCVBUFSIZE
|
|
|
|
# define CONFIG_SYSTEM_ZMODEM_RCVBUFSIZE 512
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Data may be received in gulps of varying size and alignment. Received
|
2020-02-22 19:52:12 +01:00
|
|
|
* packets data is properly unescaped, aligned and packed into a packet
|
2013-07-15 01:01:23 +02:00
|
|
|
* buffer of this size.
|
2013-07-13 00:01:37 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_SYSTEM_ZMODEM_PKTBUFSIZE
|
|
|
|
# define CONFIG_SYSTEM_ZMODEM_PKTBUFSIZE 512
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* The size of one transmit buffer used for composing messages sent to the
|
|
|
|
* remote peer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_SYSTEM_ZMODEM_SNDBUFSIZE
|
|
|
|
# define CONFIG_SYSTEM_ZMODEM_SNDBUFSIZE 512
|
|
|
|
#endif
|
|
|
|
|
2020-02-22 19:52:12 +01:00
|
|
|
/* Absolute paths are not accepted. This configuration value must be
|
2013-07-13 00:01:37 +02:00
|
|
|
* set to provide the path to the file storage directory (such as a
|
|
|
|
* mountpoint directory).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_SYSTEM_ZMODEM_MOUNTPOINT
|
|
|
|
# define CONFIG_SYSTEM_ZMODEM_MOUNTPOINT "/tmp"
|
|
|
|
#endif
|
|
|
|
|
2017-05-11 21:40:03 +02:00
|
|
|
/* CONFIG_SYSTEM_ZMODEM_RCVSAMPLE indicates the local sender can sample
|
2013-07-14 03:57:04 +02:00
|
|
|
* reverse channel while sending. This means in particular, that Zmodem can
|
|
|
|
* detect if data is received from the remote receiver while streaming a file
|
2022-01-05 16:34:05 +01:00
|
|
|
* to the remote receiver. Support for such asynchronous incoming data
|
2013-07-14 03:57:04 +02:00
|
|
|
* notification is needed to support interruption of the file transfer by
|
|
|
|
* the remote receiver.
|
|
|
|
*
|
|
|
|
* This capapability is not yet supported. There are only incomplete hooks
|
|
|
|
* in the code now!
|
|
|
|
*/
|
|
|
|
|
2013-07-16 01:50:17 +02:00
|
|
|
#ifdef CONFIG_SYSTEM_ZMODEM_RCVSAMPLE
|
|
|
|
# warning CONFIG_SYSTEM_ZMODEM_RCVSAMPLE not yet supported
|
2013-07-14 03:57:04 +02:00
|
|
|
# undef CONFIG_SYSTEM_ZMODEM_RCVSAMPLE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* CONFIG_SYSTEM_ZMODEM_SENDATTN indicates that the local sender retains
|
|
|
|
* an attention string that will be sent to the remote receiver
|
|
|
|
*
|
|
|
|
* This capapability is not yet supported. There are only incomplete hooks
|
|
|
|
* in the code now!
|
|
|
|
*/
|
|
|
|
|
2013-07-16 01:50:17 +02:00
|
|
|
#ifdef CONFIG_SYSTEM_ZMODEM_SENDATTN
|
|
|
|
# warning CONFIG_SYSTEM_ZMODEM_SENDATTN not yet supported
|
2013-07-14 03:57:04 +02:00
|
|
|
# undef CONFIG_SYSTEM_ZMODEM_SENDATTN
|
|
|
|
#endif
|
|
|
|
|
2013-07-13 00:01:37 +02:00
|
|
|
/* Response time for sender to respond to requests */
|
|
|
|
|
|
|
|
#ifndef CONFIG_SYSTEM_ZMODEM_RESPTIME
|
|
|
|
# define CONFIG_SYSTEM_ZMODEM_RESPTIME 10
|
|
|
|
#endif
|
|
|
|
|
2013-07-16 00:21:20 +02:00
|
|
|
/* When rz starts, it must wait a for the remote end to start the file
|
|
|
|
* transfer. This may take longer than the normal response time. This
|
|
|
|
* value may be set to tune that longer timeout value.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_SYSTEM_ZMODEM_CONNTIME
|
|
|
|
# define CONFIG_SYSTEM_ZMODEM_CONNTIME 30
|
|
|
|
#endif
|
|
|
|
|
2013-07-13 00:01:37 +02:00
|
|
|
/* Receiver serial number */
|
|
|
|
|
|
|
|
#ifndef CONFIG_SYSTEM_ZMODEM_SERIALNO
|
|
|
|
# define CONFIG_SYSTEM_ZMODEM_SERIALNO 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Max receive errors before canceling the transfer */
|
|
|
|
|
|
|
|
#ifndef CONFIG_SYSTEM_ZMODEM_MAXERRORS
|
|
|
|
# define CONFIG_SYSTEM_ZMODEM_MAXERRORS 20
|
|
|
|
#endif
|
|
|
|
|
2013-07-15 20:33:35 +02:00
|
|
|
/* Some MMC/SD drivers may fail if large transfers are attempted. As a bug
|
|
|
|
* workaround, you can set the maximum write size with this configuration.
|
|
|
|
* The default value of 0 means no write limit.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_SYSTEM_ZMODEM_WRITESIZE
|
|
|
|
# define CONFIG_SYSTEM_ZMODEM_WRITESIZE 0
|
|
|
|
#endif
|
|
|
|
|
2020-02-22 19:52:12 +01:00
|
|
|
/* Absolute paths in received file names are not accepted. This
|
2013-07-15 20:33:35 +02:00
|
|
|
* configuration value must be set to provide the path to the file storage
|
|
|
|
* directory (such as a mountpoint directory).
|
|
|
|
*
|
2020-02-23 05:51:44 +01:00
|
|
|
* Names of file send by the sz command, on the other hand, must be absolute
|
2013-07-15 20:33:35 +02:00
|
|
|
* paths beginning with '/'.
|
|
|
|
*/
|
|
|
|
|
2013-07-13 00:01:37 +02:00
|
|
|
#ifndef CONFIG_SYSTEM_ZMODEM_MOUNTPOINT
|
|
|
|
# define CONFIG_SYSTEM_ZMODEM_MOUNTPOINT "/tmp"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Types
|
|
|
|
****************************************************************************/
|
2021-06-11 11:07:52 +02:00
|
|
|
|
2013-07-13 00:01:37 +02:00
|
|
|
/* Opaque handles returned by initialization functions */
|
|
|
|
|
|
|
|
typedef FAR void *ZMHANDLE;
|
|
|
|
typedef FAR void *ZMRHANDLE;
|
|
|
|
typedef FAR void *ZMSHANDLE;
|
|
|
|
|
|
|
|
/* Enumerations describing arguments to zms_initialize() */
|
|
|
|
|
|
|
|
enum zm_xfertype_e
|
|
|
|
{
|
|
|
|
XM_XFERTYPE_NORMAL = 0, /* Normal file transfer */
|
|
|
|
XM_XFERTYPE_BINARY = 1, /* Binary transfer */
|
|
|
|
XM_XFERTYPE_ASCII = 2, /* Convert \n to local EOL convention */
|
|
|
|
XM_XFERTYPE_RESUME = 3 /* Resume interrupted transfer or append to file. */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum zm_option_e
|
|
|
|
{
|
|
|
|
XM_OPTION_NONE = 0, /* Transfer if source newer or longer */
|
|
|
|
XM_OPTION_NEWL = 1, /* Transfer if source newer or longer */
|
|
|
|
XM_OPTION_CRC = 2, /* Transfer if different CRC or length */
|
|
|
|
XM_OPTION_APPEND = 3, /* Append to existing file, if any */
|
|
|
|
XM_OPTION_REPLACE = 4, /* Replace existing file */
|
|
|
|
XM_OPTION_NEW = 5, /* Transfer if source is newer */
|
|
|
|
XM_OPTION_DIFF = 6, /* Transfer if dates or lengths different */
|
|
|
|
XM_OPTION_CREATE = 7, /* Protect: transfer only if dest doesn't exist */
|
|
|
|
XM_OPTION_RENAME = 8 /* Change filename if destination exists */
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define EXTERN extern "C"
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: zmr_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialize for Zmodem receive operation
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* remfd - The R/W file/socket descriptor to use for communication with the
|
|
|
|
* remote peer.
|
|
|
|
*
|
2013-07-13 21:19:15 +02:00
|
|
|
* Returned Value:
|
|
|
|
* An opaque handle that can be use with zmr_receive() and zmr_release().
|
|
|
|
*
|
2013-07-13 00:01:37 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
ZMRHANDLE zmr_initialize(int remfd);
|
|
|
|
|
2013-07-13 21:19:15 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: zmr_receive
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Receive file(s) sent from the remote peer.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2018-08-23 14:33:39 +02:00
|
|
|
* handle - The handler created by zmr_initialize().
|
|
|
|
* pathname - The name of the local path to hold the file
|
2013-07-13 21:19:15 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero on success; a negated errno value on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-08-23 14:33:39 +02:00
|
|
|
int zmr_receive(ZMRHANDLE handle, FAR const char *pathname);
|
2013-07-13 21:19:15 +02:00
|
|
|
|
2013-07-13 00:01:37 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: zmr_release
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Called by the user when there are no more files to receive.
|
|
|
|
*
|
2013-07-13 21:19:15 +02:00
|
|
|
* Input Parameters:
|
|
|
|
* handle - The handler created by zmr_initialize().
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero on success; a negated errno value on failure.
|
|
|
|
*
|
2013-07-13 00:01:37 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int zmr_release(ZMRHANDLE);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: zms_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialize for Zmodem send operation. The overall usage is as follows:
|
|
|
|
*
|
|
|
|
* 1) Call zms_initialize() to create the partially initialized struct
|
|
|
|
* zm_state_s instance.
|
|
|
|
* 2) Make any custom settings in the struct zms_state_s instance.
|
|
|
|
* 3) Create a stream instance to get the "file" to transmit and add
|
|
|
|
* the filename to pzms
|
|
|
|
* 4) Call zms_upload() to transfer the file.
|
|
|
|
* 5) Repeat 3) and 4) to transfer as many files as desired.
|
|
|
|
* 6) Call zms_release() when the final file has been transferred.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* remfd - The R/W file/socket descriptor to use for communication with the
|
|
|
|
* remote peer.
|
|
|
|
*
|
2013-07-13 21:19:15 +02:00
|
|
|
* Returned Value:
|
|
|
|
* An opaque handle that can be use with zmx_send() and zms_release()
|
|
|
|
*
|
2013-07-13 00:01:37 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
ZMSHANDLE zms_initialize(int remfd);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: zms_send
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Send a file.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2022-01-05 16:34:05 +01:00
|
|
|
* handle - Handle previously returned by xms_initialize()
|
2013-07-13 21:19:15 +02:00
|
|
|
* filename - The name of the local file to transfer
|
2013-07-13 00:01:37 +02:00
|
|
|
* rfilename - The name of the remote file name to create
|
2013-07-13 21:19:15 +02:00
|
|
|
* option - Describes optional transfer behavior
|
|
|
|
* f1 - The F1 transfer flags
|
|
|
|
* skip - True: Skip if file not present at receiving end.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero on success; a negated errno value on failure.
|
2013-07-13 00:01:37 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int zms_send(ZMSHANDLE handle, FAR const char *filename,
|
|
|
|
FAR const char *rfilename, enum zm_xfertype_e xfertype,
|
|
|
|
enum zm_option_e option, bool skip);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: zms_release
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Called by the user when there are no more files to send.
|
|
|
|
*
|
2013-07-13 21:19:15 +02:00
|
|
|
* Input Parameters:
|
|
|
|
* handle - The handler created by zms_initialize().
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero on success; a negated errno value on failure.
|
|
|
|
*
|
2013-07-13 00:01:37 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int zms_release(ZMSHANDLE handle);
|
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-07-01 14:48:22 +02:00
|
|
|
#endif /* __APPS_INCLUDE_SYSTEM_ZMODEM_H */
|