summaryrefslogtreecommitdiffstats
path: root/call/crc.c
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>1999-06-07 10:23:42 +0200
committerRalf Baechle <ralf@linux-mips.org>1999-06-07 10:23:42 +0200
commit0fceb64d25ff3d9586549bb43d971c5eef904330 (patch)
treed4799d0fd53a3d8ae342c84f8ad4fb2ca2f14de0 /call/crc.c
Import ax25-apps 0.0.1 from tarballax25-apps-0.0.1
Diffstat (limited to 'call/crc.c')
-rw-r--r--call/crc.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/call/crc.c b/call/crc.c
new file mode 100644
index 0000000..637b0f5
--- /dev/null
+++ b/call/crc.c
@@ -0,0 +1,38 @@
+
+/* tnt: Hostmode Terminal for TNC
+ Copyright (C) 1993 by Mark Wahl
+ For license details see documentation
+ Procedures for autobin-checksum (crc.c)
+ created: Mark Wahl DL4YBG 94/01/17
+ updated: Mark Wahl DL4YBG 94/01/17
+*/
+
+static int crcbit[8] = {
+ 0x9188,0x48c4,0x2462,0x1231,0x8108,0x4084,0x2042,0x1021
+ };
+
+static int bittab[8] = { 128,64,32,16,8,4,2,1 };
+
+static int crctab[256];
+
+void init_crc(void)
+{
+ int i,j;
+
+ for (i = 0; i < 256; i++) {
+ crctab[i] = 0;
+ for (j = 0; j < 8; j++) {
+ if ((bittab[j] & i) != 0) {
+ crctab[i] = crctab[i] ^ crcbit[j];
+ }
+ }
+ }
+}
+
+/* calculate checksum for autobin-protocol */
+unsigned int calc_crc(unsigned char* buf, int n, unsigned crc)
+{
+ while (--n >= 0)
+ crc = (crctab[(crc >> 8)] ^ ((crc << 8) | *buf++)) & 0xffff;
+ return crc;
+}