From dcbbb05f50b253c4c679ea75d81198af300908cd Mon Sep 17 00:00:00 2001 From: MurphyZhao Date: Thu, 6 Sep 2018 11:00:36 +0800 Subject: [PATCH] =?UTF-8?q?[components][ymodem]=20=E4=BF=AE=E5=A4=8D=20ymo?= =?UTF-8?q?dem=20=E4=B8=8D=E6=94=AF=E6=8C=81=20secureCRT=20=E4=B8=8B=20102?= =?UTF-8?q?4=E5=AD=97=E8=8A=82=E4=BC=A0=E8=BE=93=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MurphyZhao --- components/utilities/ymodem/ymodem.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/components/utilities/ymodem/ymodem.c b/components/utilities/ymodem/ymodem.c index 1643429647..a1f21cf6c6 100644 --- a/components/utilities/ymodem/ymodem.c +++ b/components/utilities/ymodem/ymodem.c @@ -122,6 +122,7 @@ static rt_err_t _rym_do_handshake( enum rym_code code; rt_size_t i; rt_uint16_t recv_crc, cal_crc; + rt_size_t data_sz; ctx->stage = RYM_STAGE_ESTABLISHING; /* send C every second, so the sender could know we are waiting for it. */ @@ -131,26 +132,36 @@ static rt_err_t _rym_do_handshake( code = _rym_read_code(ctx, RYM_CHD_INTV_TICK); if (code == RYM_CODE_SOH) + { + data_sz = _RYM_SOH_PKG_SZ; break; + } + else if(code == RYM_CODE_STX) + { + data_sz = _RYM_STX_PKG_SZ; + break; + } } if (i == tm_sec) + { return -RYM_ERR_TMO; + } - i = _rym_read_data(ctx, _RYM_SOH_PKG_SZ-1); - if (i != (_RYM_SOH_PKG_SZ-1)) + i = _rym_read_data(ctx, data_sz-1); + if (i != (data_sz-1)) return -RYM_ERR_DSZ; /* sanity check */ if (ctx->buf[1] != 0 || ctx->buf[2] != 0xFF) return -RYM_ERR_SEQ; - recv_crc = (rt_uint16_t)(*(ctx->buf+_RYM_SOH_PKG_SZ-2) << 8) | *(ctx->buf+_RYM_SOH_PKG_SZ-1); - cal_crc = CRC16(ctx->buf+3, _RYM_SOH_PKG_SZ-5); + recv_crc = (rt_uint16_t)(*(ctx->buf+data_sz-2) << 8) | *(ctx->buf+data_sz-1); + cal_crc = CRC16(ctx->buf+3, data_sz-5); if (recv_crc != cal_crc) return -RYM_ERR_CRC; /* congratulations, check passed. */ - if (ctx->on_begin && ctx->on_begin(ctx, ctx->buf+3, 128) != RYM_CODE_ACK) + if (ctx->on_begin && ctx->on_begin(ctx, ctx->buf+3, data_sz-5) != RYM_CODE_ACK) return -RYM_ERR_CAN; return RT_EOK;