xmodem.c revision 199767f8919635c4928607450d9e0abb932109ce
/*-
* Copyright (c) 2006 M. Warner Losh. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software is derived from software provide by Kwikbyte who specifically
* disclaimed copyright on the code. This version of xmodem has been nearly
* completely rewritten, but the CRC is from the original.
*
* $FreeBSD$
*/
#include "lib.h"
#define PACKET_SIZE 128
/* Line control codes */
#define TO 10
/*
* int GetRecord(char , char *)
* This private function receives a x-modem record to the pointer and
* returns non-zero on success.
*/
static int
{
int size;
int ch;
unsigned chk, j;
chk = 0;
goto err;
goto err;
goto err;
goto err;
goto err;
for (j = 0; j < 8; ++j) {
if (chk & 0x8000)
else
}
}
chk &= 0xFFFF;
goto err;
goto err;
return (1);
err:;
// We should allow for resend, but we don't.
return (0);
}
/*
* int xmodem_rx(char *)
* This global function receives a x-modem transmission consisting of
* (potentially) several blocks. Returns the number of bytes received or
* -1 on error.
*/
int
{
packetNumber = 1;
starting = 1;
while (1) {
if (starting)
putchar('C');
continue;
return (dest - startAddress);
}
starting = 0;
// Xmodem packets: SOH PKT# ~PKT# 128-bytes CRC16
return (-1);
dest += PACKET_SIZE;
packetNumber++;
}
// the loop above should return in all cases
return (-1);
}