11 * CALCULATE THE CHECKSUM
15 #define X25_INIT_CRC 0xffff
16 #define X25_VALIDATE_CRC 0xf0b8
19 * @brief Accumulate the X.25 CRC by adding one char at a time.
21 * The checksum function adds the hash of one char at a time to the
22 * 16 bit checksum (uint16_t).
24 * @param data new char to hash
25 * @param crcAccum the already accumulated checksum
27 static inline void crc_accumulate(uint8_t data
, uint16_t *crcAccum
)
29 /*Accumulate one byte of data into the CRC*/
32 tmp
= data
^ (uint8_t)(*crcAccum
& 0xff);
34 *crcAccum
= (*crcAccum
>> 8) ^ (tmp
<< 8) ^ (tmp
<< 3) ^ (tmp
>> 4);
38 * @brief Initiliaze the buffer for the X.25 CRC
40 * @param crcAccum the 16 bit X.25 CRC
42 static inline void crc_init(uint16_t *crcAccum
)
44 *crcAccum
= X25_INIT_CRC
;
49 * @brief Calculates the X.25 checksum on a byte buffer
51 * @param pBuffer buffer containing the byte array to hash
52 * @param length length of the byte array
53 * @return the checksum over the buffer bytes
55 static inline uint16_t crc_calculate(const uint8_t *pBuffer
, uint16_t length
)
61 crc_accumulate(*pBuffer
++, &crcTmp
);
67 * @brief Accumulate the X.25 CRC by adding an array of bytes
69 * The checksum function adds the hash of one char at a time to the
70 * 16 bit checksum (uint16_t).
72 * @param data new bytes to hash
73 * @param crcAccum the already accumulated checksum
75 static inline void crc_accumulate_buffer(uint16_t *crcAccum
, const char *pBuffer
, uint8_t length
)
77 const uint8_t *p
= (const uint8_t *)pBuffer
;
80 crc_accumulate(*p
++, crcAccum
);
85 #endif /* _CHECKSUM_H_ */