Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
EmbeddedLinuxProject
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christoph-Anton Schwierz
EmbeddedLinuxProject
Commits
2a443c48
Commit
2a443c48
authored
4 months ago
by
fdai7354
Browse files
Options
Downloads
Patches
Plain Diff
CRC32 added
parent
48346ff0
Branches
Branches containing commit
No related tags found
1 merge request
!1
Kernel module
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Kernel/kernel_M.c
+17
-0
17 additions, 0 deletions
Kernel/kernel_M.c
with
17 additions
and
0 deletions
Kernel/kernel_M.c
+
17
−
0
View file @
2a443c48
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
#include
<linux/cdev.h>
// For cdev
#include
<linux/cdev.h>
// For cdev
#include
<linux/device.h>
// For device_create, class_create
#include
<linux/device.h>
// For device_create, class_create
#include
<linux/slab.h>
// For kmalloc, kfree
#include
<linux/slab.h>
// For kmalloc, kfree
#include
<linux/crc32.h>
// Include CRC32
#define DEVICE_NAME "packet_receiver"
#define DEVICE_NAME "packet_receiver"
#define CLASS_NAME "packet_class"
#define CLASS_NAME "packet_class"
...
@@ -51,6 +52,11 @@ static struct file_operations fops = {
...
@@ -51,6 +52,11 @@ static struct file_operations fops = {
.
release
=
packet_release
,
//not used
.
release
=
packet_release
,
//not used
};
};
// CRC32 Calculation Function
static
u32
calculate_crc32
(
const
char
*
data
,
size_t
len
)
{
return
crc32
(
0
,
data
,
len
);
}
// ====================== Device Open ======================
// ====================== Device Open ======================
static
int
packet_open
(
struct
inode
*
inode
,
struct
file
*
file
)
{
static
int
packet_open
(
struct
inode
*
inode
,
struct
file
*
file
)
{
printk
(
KERN_INFO
"packet_receiver: Device opened.
\n
"
);
printk
(
KERN_INFO
"packet_receiver: Device opened.
\n
"
);
...
@@ -124,6 +130,17 @@ static ssize_t packet_write(struct file *filp, const char __user *buf, size_t le
...
@@ -124,6 +130,17 @@ static ssize_t packet_write(struct file *filp, const char __user *buf, size_t le
printk
(
KERN_INFO
" value_id_1=%d value_1=
\"
%s
\"\n
"
,
value_id_1
,
value_str_1
);
printk
(
KERN_INFO
" value_id_1=%d value_1=
\"
%s
\"\n
"
,
value_id_1
,
value_str_1
);
printk
(
KERN_INFO
" crc=0x%lX
\n
"
,
crc_val
);
printk
(
KERN_INFO
" crc=0x%lX
\n
"
,
crc_val
);
// Calculate CRC32 for the received data excluding the CRC field
size_t
crc_len
=
strrchr
(
recv_buffer
,
'C'
)
-
recv_buffer
;
u32
calculated_crc
=
calculate_crc32
(
recv_buffer
,
crc_len
);
if
(
calculated_crc
==
received_crc
)
{
printk
(
KERN_INFO
"packet_receiver: CRC check passed!
\n
"
);
}
else
{
printk
(
KERN_ERR
"packet_receiver: CRC mismatch! Expected: 0x%08X, Received: 0x%08lX
\n
"
,
calculated_crc
,
received_crc
);
}
// Return the number of bytes written
// Return the number of bytes written
return
len
;
return
len
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment