Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/next/external/cache/sources/hcitools/monitor/crc.c
Views: 3959
/*1*2* BlueZ - Bluetooth protocol stack for Linux3*4* Copyright (C) 2011-2012 Intel Corporation5* Copyright (C) 2004-2010 Marcel Holtmann <[email protected]>6*7*8* This library is free software; you can redistribute it and/or9* modify it under the terms of the GNU Lesser General Public10* License as published by the Free Software Foundation; either11* version 2.1 of the License, or (at your option) any later version.12*13* This library is distributed in the hope that it will be useful,14* but WITHOUT ANY WARRANTY; without even the implied warranty of15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU16* Lesser General Public License for more details.17*18* You should have received a copy of the GNU Lesser General Public19* License along with this library; if not, write to the Free Software20* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA21*22*/2324#ifdef HAVE_CONFIG_H25#include <config.h>26#endif2728#include "crc.h"2930uint32_t crc24_bit_reverse(uint32_t value)31{32uint32_t result = 0;33uint8_t i;3435for (i = 0; i < 24; i++)36result |= ((value >> i) & 1) << (23 - i);3738return result;39}4041uint32_t crc24_calculate(uint32_t preset, const uint8_t *data, uint8_t len)42{43uint32_t state = preset;44uint8_t i;4546for (i = 0; i < len; i++) {47uint8_t n, cur = data[i];4849for (n = 0; n < 8; n++) {50int next_bit = (state ^ cur) & 1;5152cur >>= 1;53state >>= 1;54if (next_bit) {55state |= 1 << 23;56state ^= 0x5a6000;57}58}59}6061return state;62}6364uint32_t crc24_reverse(uint32_t crc, const uint8_t *data, uint8_t len)65{66uint32_t state = crc;67uint8_t i;6869for (i = 0; i < len; i++) {70uint8_t n, cur = data[len - i - 1];7172for (n = 0; n < 8; n++) {73int top_bit = state >> 23;7475state = (state << 1) & 0xffffff;76state |= top_bit ^ ((cur >> (7 - n)) & 1);77if (top_bit)78state ^= 0xb4c000;79}80}8182return state;83}848586