USB for LINUX part 1

Today i start usb development using linux/usbdevice_fs.h, maybe it will be easy to use usb.h, but its better to use linux/usbdevice_fs.h to make some development in usb linux driver. Yes, you know that linux/usbdevice_fs.h is linux kernel API.

Some reason that i will not usb.h from libusb that it not base from linux so if i would make driver maybe better using ioctl api to get access from user perspective. On reference 2 some error detected that issue summoning because asm/uaccses not found in this code.

On reference 3 give better explained from usb using kernel. This how you must read. If you wanna read reference 4 you will know how the usb driver written, reference 4 provide example code. There are some failure like detecting device on refences 4.


if you get some reference you will get some header you will need
#include <linux/module.h>
#include <linux/init.h>

#include <linux/slab.h> /* kmalloc() */
#include <linux/usb.h> /* USB stuff */
#include <linux/mutex.h> /* mutexes */
#include <linux/ioctl.h>

#include <linux/uaccess.h> /* copy_*_user */

if you get linux/uaccess.h from your code you will get copy_from_user and copy_to_user. Thats mean you will get some access to the kernel. If you wanna make some driver on linux kernel you need to init the module but in this case you need serveral function: but actuarlly the syntax
static int __init usb_ml_init(void)
{
int result;

DBG_INFO("Register driver");
result = usb_register(&ml_driver);
if (result) {
DBG_ERR("registering driver failed");
} else {
DBG_INFO("driver registered successfully");
}

return result;
}
And you will get some struct like mil_driver but actually this is i will get from function
static struct usb_driver ml_driver = {
.name = "missile_launcher",
.id_table = ml_table,
.probe = ml_probe,
.disconnect = ml_disconnect,
};
Some article in reference 6 use outdate kernel so if you wanna set your kernel maybe you must learn much form another resource.

Ok am gonna rage now, so i wanna make mile stone to make this stuff clear. Fist i must to do is just how to detect usb and auto detect when i use dmesg command.

Milestone 1

I will make some kernel driver and just read and send it to dmesg using printk. Ok, now lets move on reference 7, on this section i will copy and paste this code and try some plug and unplug with my own usb device if its works i will go to milestone 2.

Some several error occured when i compile those code on my arch linux pc and now i gonna find the solution. And then unfortunnatelly usb header isn't default of linux kernel (maybe), some include directory not give usb.h on linux kernel mode. This will fucking shit.

And on reference 7 this code still not working. So i must find another alternatives.

Finally i make some progres about the code Thanks to Greg Kroah Hartman

Reference :

1. Article for Linux driver
2. Ioctl
3. https://www.kernel.org/doc/html/latest/driver-api/usb/writing_usb_driver.html
4. Some sample USB
5. Checking point for usb

Comments

Popular posts from this blog

Apolonian dan Dynosian Sekaligus

Install Driver WiFi

Privacy ADB GMS