/* Needed because CRCs are transmitted in bit-reversed order compared to the rest of the BTLE packet. See BT spec, Vol 6, Part B, Section 1.2.  */
static guint32 reverse_bits_per_byte(const guint32 val)
/* Needed because CRCs are transmitted in bit-reversed order compared to the rest of the BTLE packet. See BT spec, Vol 6, Part B, Section 1.2.  */
static guint32 reverse_bits_per_byte(const guint32 val)
{
    const guint8 nibble_rev[16] = {
        0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe,
        0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf
    };
    guint32 retval = 0;
    unsigned byte_index;
    for (byte_index=0; byte_index<4; byte_index++) {
        guint shiftA = byte_index*8;
        guint shiftB = shiftA+4;
        retval |= (nibble_rev[((val >> shiftA) & 0xf)] << shiftB);
        retval |= (nibble_rev[((val >> shiftB) & 0xf)] << shiftA);
    }
    return retval;
}