|
@@ -74,6 +74,7 @@ static void shellmatta_ymodem_reset(shellmatta_handle_t handle, bool doCancel)
|
|
inst->ymodem.fileSize = 0u;
|
|
inst->ymodem.fileSize = 0u;
|
|
inst->ymodem.pauseRequested = false;
|
|
inst->ymodem.pauseRequested = false;
|
|
inst->ymodem.pollCyclesLeft = 0u;
|
|
inst->ymodem.pollCyclesLeft = 0u;
|
|
|
|
+ inst->ymodem.cancelCounter = 0u;
|
|
|
|
|
|
#ifdef SHELLMATTA_TRANSPORT
|
|
#ifdef SHELLMATTA_TRANSPORT
|
|
/** .-# reenable transport layer optional mode */
|
|
/** .-# reenable transport layer optional mode */
|
|
@@ -105,7 +106,8 @@ shellmatta_retCode_t processPacket(shellmatta_handle_t handle)
|
|
else
|
|
else
|
|
{
|
|
{
|
|
/** -# calculate packet size - when it is the last packet this is limited by the file size */
|
|
/** -# calculate packet size - when it is the last packet this is limited by the file size */
|
|
- if((inst->ymodem.totalBytesReceived + inst->ymodem.packet.size) > inst->ymodem.fileSize)
|
|
|
|
|
|
+ if((0u != inst->ymodem.fileSize) &&
|
|
|
|
+ (inst->ymodem.totalBytesReceived + inst->ymodem.packet.size) > inst->ymodem.fileSize)
|
|
{
|
|
{
|
|
packetSize = inst->ymodem.fileSize % inst->ymodem.packet.size;
|
|
packetSize = inst->ymodem.fileSize % inst->ymodem.packet.size;
|
|
}
|
|
}
|
|
@@ -261,18 +263,25 @@ shellmatta_retCode_t shellmatta_ymodem_processByte(shellmatta_handle_t handle, c
|
|
shellmatta_instance_t *inst = (shellmatta_instance_t*)handle;
|
|
shellmatta_instance_t *inst = (shellmatta_instance_t*)handle;
|
|
shellmatta_retCode_t ret;
|
|
shellmatta_retCode_t ret;
|
|
|
|
|
|
- /** -# check if session is cancelled -accept only if ymodem is between packets */
|
|
|
|
- if(('\x03' == byte) && (inst->ymodem.state == SHELLMATTA_YMODEM_WAIT_FOR_START))
|
|
|
|
|
|
+ /** -# check if session is cancelled - accept only if ymodem is between packets */
|
|
|
|
+ if((('\x03' == byte) || (YMODEM_CA == byte)) && (inst->ymodem.state == SHELLMATTA_YMODEM_WAIT_FOR_START))
|
|
{
|
|
{
|
|
- /** -# explicitly reset ymodem with cancel, if it was active */
|
|
|
|
- shellmatta_ymodem_reset(handle, true);
|
|
|
|
|
|
+ inst->ymodem.cancelCounter ++;
|
|
|
|
|
|
- utils_terminateInput(inst);
|
|
|
|
|
|
+ /** -# cancel after at least 2 cancel characters */
|
|
|
|
+ if(inst->ymodem.cancelCounter >= 2u)
|
|
|
|
+ {
|
|
|
|
+ /** -# explicitly reset ymodem with cancel, if it was active */
|
|
|
|
+ shellmatta_ymodem_reset(handle, true);
|
|
|
|
+
|
|
|
|
+ utils_terminateInput(inst);
|
|
|
|
|
|
- ret = SHELLMATTA_ERROR;
|
|
|
|
|
|
+ ret = SHELLMATTA_ERROR;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
|
|
+ inst->ymodem.cancelCounter = 0u;
|
|
ret = ymodem_stateMachine(handle, (uint8_t)byte);
|
|
ret = ymodem_stateMachine(handle, (uint8_t)byte);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -300,8 +309,9 @@ shellmatta_retCode_t shellmatta_ymodem_poll(shellmatta_handle_t handle)
|
|
{
|
|
{
|
|
ret = SHELLMATTA_OK;
|
|
ret = SHELLMATTA_OK;
|
|
/** -# check if the received data matches the file size */
|
|
/** -# check if the received data matches the file size */
|
|
- if((inst->ymodem.totalBytesReceived < inst->ymodem.fileSize) ||
|
|
|
|
- ((inst->ymodem.totalBytesReceived - inst->ymodem.fileSize) >= YMODEM_PACKET_SIZE_1K))
|
|
|
|
|
|
+ if((0u != inst->ymodem.fileSize) &&
|
|
|
|
+ ((inst->ymodem.totalBytesReceived < inst->ymodem.fileSize) ||
|
|
|
|
+ ((inst->ymodem.totalBytesReceived - inst->ymodem.fileSize) >= YMODEM_PACKET_SIZE_1K)))
|
|
{
|
|
{
|
|
ret = SHELLMATTA_ERROR;
|
|
ret = SHELLMATTA_ERROR;
|
|
}
|
|
}
|