The header, prior to bitstuffing, contains a 4-byte logical ID field, a 2-byte length field, and a 2-byte checksum. The checksum of n bytes of data is computed as follows:
unsigned char data[ ];
unsigned short checksum = 0xa1e8;
for (i = 0; i < n; i++)
{
checksum += data[i];
checksum = (checksum << 3) + (checksum >> 13);
}