mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-11 20:24:04 +00:00
trivial: Add CRC8 as well
This commit is contained in:
parent
6f5e35a3ea
commit
44ae2a75e4
@ -2336,6 +2336,32 @@ fu_common_get_esp_for_path (const gchar *esp_path, GError **error)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_common_crc8:
|
||||
* @buf: memory buffer
|
||||
* @bufsz: sizeof buf
|
||||
*
|
||||
* Returns the cyclic redundancy check value for the given memory buffer.
|
||||
*
|
||||
* Returns: CRC value
|
||||
*
|
||||
* Since: 1.5.0
|
||||
**/
|
||||
guint8
|
||||
fu_common_crc8 (const guint8 *buf, gsize bufsz)
|
||||
{
|
||||
guint32 crc = 0;
|
||||
for (gsize j = bufsz; j > 0; j--) {
|
||||
crc ^= (*(buf++) << 8);
|
||||
for (guint32 i = 8; i; i--) {
|
||||
if (crc & 0x8000)
|
||||
crc ^= (0x1070 << 3);
|
||||
crc <<= 1;
|
||||
}
|
||||
}
|
||||
return ~((guint8) (crc >> 8));
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_common_crc16:
|
||||
* @buf: memory buffer
|
||||
|
@ -240,6 +240,8 @@ FuVolume *fu_common_get_esp_for_path (const gchar *esp_path,
|
||||
GError **error);
|
||||
FuVolume *fu_common_get_esp_default (GError **error);
|
||||
|
||||
guint8 fu_common_crc8 (const guint8 *buf,
|
||||
gsize bufsz);
|
||||
guint16 fu_common_crc16 (const guint8 *buf,
|
||||
gsize bufsz);
|
||||
guint32 fu_common_crc32 (const guint8 *buf,
|
||||
|
@ -111,6 +111,7 @@ static void
|
||||
fu_common_crc_func (void)
|
||||
{
|
||||
guint8 buf[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
|
||||
g_assert_cmpint (fu_common_crc8 (buf, sizeof(buf)), ==, 0x7A);
|
||||
g_assert_cmpint (fu_common_crc16 (buf, sizeof(buf)), ==, 0x4DF1);
|
||||
g_assert_cmpint (fu_common_crc32 (buf, sizeof(buf)), ==, 0x40EFAB9E);
|
||||
}
|
||||
|
@ -616,6 +616,7 @@ LIBFWUPDPLUGIN_1.5.0 {
|
||||
fu_common_crc16;
|
||||
fu_common_crc32;
|
||||
fu_common_crc32_full;
|
||||
fu_common_crc8;
|
||||
fu_common_filename_glob;
|
||||
fu_common_is_cpu_intel;
|
||||
fu_device_bind_driver;
|
||||
|
@ -9,21 +9,6 @@
|
||||
|
||||
#include "fu-vli-common.h"
|
||||
|
||||
guint8
|
||||
fu_vli_common_crc8 (const guint8 *buf, gsize bufsz)
|
||||
{
|
||||
guint32 crc = 0;
|
||||
for (gsize j = bufsz; j > 0; j--) {
|
||||
crc ^= (*(buf++) << 8);
|
||||
for (guint32 i = 8; i; i--) {
|
||||
if (crc & 0x8000)
|
||||
crc ^= (0x1070 << 3);
|
||||
crc <<= 1;
|
||||
}
|
||||
}
|
||||
return (guint8) (crc >> 8);
|
||||
}
|
||||
|
||||
const gchar *
|
||||
fu_vli_common_device_kind_to_string (FuVliDeviceKind device_kind)
|
||||
{
|
||||
|
@ -43,6 +43,3 @@ const gchar *fu_vli_common_device_kind_to_string (FuVliDeviceKind device_kind);
|
||||
FuVliDeviceKind fu_vli_common_device_kind_from_string (const gchar *device_kind);
|
||||
guint32 fu_vli_common_device_kind_get_size (FuVliDeviceKind device_kind);
|
||||
guint32 fu_vli_common_device_kind_get_offset (FuVliDeviceKind device_kind);
|
||||
|
||||
guint8 fu_vli_common_crc8 (const guint8 *buf,
|
||||
gsize bufsz);
|
||||
|
@ -12,7 +12,7 @@
|
||||
guint8
|
||||
fu_vli_usbhub_header_crc8 (FuVliUsbhubHeader *hdr)
|
||||
{
|
||||
return fu_vli_common_crc8 ((const guint8 *) hdr, sizeof(*hdr) - 1);
|
||||
return ~fu_common_crc8 ((const guint8 *) hdr, sizeof(*hdr) - 1);
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user