In this article, I want to discuss some basics of the Linux PCI/PCIe drivers development. I think this issue is not properly covered, and some existing information is might be outdated. I will show basic concepts and important structures, and this is might be a good beginner guide for newbie driver developers.
Tag: linux
Linux block device driver
My article about character devices is quite popular, so I decided to write something about another big class of devices in Linux – block devices. This type of device is used to access various storage hardware types – hard disks, SSD, etc. Here I want to describe blk-mq based devices in modern (>= 5.0) Linux kernels and a previous type…
C++ in Linux kernel
Linux kernel is written in C (and in Assembly in platform-specific portions) language. C language is the only language allowed to write kernel modules. And there is no problem in most cases. But sometimes, some stranger things may be required. Let’s see how to use C++ for the Linux kernel modules.
Printing sk_buff data
Sometimes when working with network packets inside the Linux kernel, it might be very useful to print packet contents to see what is actually going on. Here I’m describing how to print packet from sk_buff structure and analyze this data with Wireshark. In this short note, I will not describe capturing the packets inside the kernel but only show how…
Modifying Linux network routes using netlink
Last time we talked about getting a Linux routing table with a simple Netlink code. Now it’s time to do more interesting stuff. Let’s add and delete some routes using the power of the Netlink!
Simple logger with STDOUT, Files and syslog support for C projects in Linux
In this little note, I want to describe a simple logging module for C programs in Linux. I’m using this code for years in my projects. This module supports different types of output “targets” – files, syslog, and stdout.
Getting Linux routing table using netlink
In the previous article, we discussed the monitoring of the network interfaces using Netlink. Now it’s time to do something more complex and interesting. Let’s discover how to get and print the system routing table like “ip route” command.
Simple Linux character device driver
A character device is one of the simplest ways to communicate with a module in the Linux kernel. These devices are presented as special files in a /dev directory and support direct reading and writing of any data, byte by byte, like a stream. Actually, most of the pseudo-devices in /dev are character devices: serial ports, modems, sound, and video…
Connecting HTU21D temperature/humidity sensor to the Raspberry PI using simple C i2c interface
Previously in my projects, I’m always used well-known DHT22 (AM2302) temperature/humidity sensors. But I found that these sensors are not very stable and subject to hung. In my case, this device is worked for about two weeks and then stops responding until the power is rebooted. This is absolutely unacceptable on some distant and autonomous devices. After some googling, I…
Monitoring Linux networking state using netlink
Once in my work, I needed to monitor all changes in the Linux networking subsystem: adding or deleting IP addresses, routes, etc. Maybe the best way to do this is to use socket-based Netlink technology. Using Netlink, we can “subscribe” to some network-related notifications from the kernel. It’s also possible to send commands to the network stack and change the…