--- /dev/null
+/*
+ * Copyright 2008, Tollef Fog Heen <tfheen@err.no>
+ *
+ * Licensed 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * ISO 13239 CRC 16 implementation
+ */
+
+#include "crc13239.h"
+
+void crc_init(unsigned short *c) {
+ *c = 0xffff;
+}
+
+void crc_update(unsigned short *c, unsigned char val) {
+ int i, j;
+ m_crc ^= val;
+ for (i = 0; i < 8; i++) {
+ j = m_crc & 1;
+ m_crc >>= 1;
+ if (j) m_crc ^= 0x8408;
+ }
+
+}
+
+unsigned short crc_get_full(unsigned char *data, size_t len, bool onecomp) {
+ unsigned short c;
+ crc_init(&c);
+ while (bcnt--)
+ crc_update(&c, *bp++);
+ return onecomp ? ~c : c;
+}
+
+bool crc_check(unsigned short *c, char *crc) {
+ return (((c & 0xff) == crc[0]) &&
+ ((c >> 8) == crc[1]));
+}
--- /dev/null
+/*
+ * Copyright 2008, Tollef Fog Heen <tfheen@err.no>
+ *
+ * Licensed 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ */
+
+#ifndef _CRC13239_H
+#define _CRC13239_H
+#define CRC_OK_RESIDUE 0xf0b8
+
+void crc_init(unsigned short *c);
+void crc_update(unsigned short *c, unsigned char *val);
+unsigned short crc_get_full(unsigned char *data, size_t len, bool onecomp);
+bool crc_check(unsigned short *c, char *crc);
+
+#endif /* _CRC13239_H */