SlideShare a Scribd company logo
1 of 28
Linux USB drivers
by Satyam
USB drivers
USB core drivers
Architecture independent kernel subsystem.
Implements the USB bus specification.
USB host drivers
Different drivers for each USB control hardware.
Usually available in the Board Support Package.
Architecture and platform dependent.
USB device drivers
Drivers for devices on the USB bus.
USB device controller drivers
For Linux systems with just a USB device controller
USB gadget
drivers
PLATFORM DEPENDENT
Supports the chip connecting to the USB bus.
PLATFORM INDEPENDENT
Ethernet gadget: implements networking
through USB
Storage gadget: makes the host see a USB
storage device
USB SUPPORT ARCHITECTURE
SUPPORT
USB device driver
USB Core
USB host controller
SYSTEM CALL INTERFACE
Other drivers
Hardware (USB DEVICE)
USER APPLICATION USERSPACE
KERNAL
TYPES OF USB HOST
CONTROLLER
1. OHCI (Open Host Controller Interface):
->Compaq’s implementation for USB 1.0 and USB 1.1
->Also used for some firmware devices
2.UHCI (Universal Host Controller Interface):
->Intel implementation for USB 2.0
3.EHCI (Extended Host Controller Interface):
->Only one to provide high speed transfer (USB 2.0)
4.SL811
->host controller, manufactured by Cypress.
->It has 256MB of internal SRAM buffer.
USB transfer speed
LowSpeed: up to 1.5 Mbps Since USB 1.0
FullSpeed: up to 12 Mbps Since USB 1.1
HiSpeed: up to 480 Mbps Since USB 2.0
USB descriptors
Device Represent the devices connected to the USB bus.
Example: USB speaker with volume control buttons.
Configurations Represent the state of the device.
Examples: Active, Standby, Initialization
Interfaces Logical devices.
Examples: speaker, volume control buttons.
Endpoints Unidirectional communication pipes.
Either IN (device to computer) or OUT (computer to device).
TYPES OF ENDPOINTS
Control endpoints: device control, accessing information, small transfers.
Guaranteed bandwidth.
Interrupt endpoints: data transfer at a fixed rate. Guaranteed bandwidth.
Bulk endpoints: use all remaining bandwidth. No bandwidth or latency
guarantee.
Isochronous endpoints:guaranteed speed. Possible data loss.
USB Request Blocks(URB)
An URB consists of all relevant information to execute any USB transaction
Any communication between the host and device is done asynchronously using USB
Request Blocks (urbs).
They are similar to packets in network communications.
Every endpoint can handle a queue of urbs.
Every urb has a completion handler.
A driver may allocate many urbs for a single endpoint, or reuse the same urb for
different endpoints.
The urb structure
PIPES FOR URB’s
Control pipes
usb_sndctrlpipe(), usb_rcvctrlpipe()
Bulk pipes
usb_sndbulkpipe(), usb_rcvbulkpipe()
Interrupt pipes
usb_sndintpipe(), usb_rcvintpipe()
Isochronous pipes
usb_sndisocpipe(), usb_rcvisocpipe()
Creating an URB’s
struct urb *usb_alloc_urb(int isoframes, int mem_flags)
Allocating URB’s isoframes->for isochronous transfer,’0’ for others
mem_flags->holds the memory allocation flag which allows to control the
block
Note: we must do the error handling if allocation fails it returns NULL
Eg:urb = usb_alloc_urb(0, GFP_KERNEL);
if(urb!=0)
printk(KERN_ALERT “Allocation failed”);
Freeing URB
void usb_free_urb(struct urb *urb);
Note : if the allocation dint return a completion call back or not been use it
can deallocate by itself .
Initializing urb’s
interrupt urbs
bulk urbs
control urbs
isochronous urbs(has to be done manually by driver,no function
available).
Function for Initilizing URB’s
void usb_fill_int_urb (
struct urb *urb, // urb to be initialized
struct usb_device *dev, // device to send the urb to
unsigned int pipe, // pipe (endpoint and device specific)
void*transfer_buffer, //transferbuffer
int buffer_length, // transfer buffer size usb_complete_t complete, // completion
handler
void *context, // context (for handler)
int interval // Scheduling interval (for interrupt URB’s)
unsigned char *setup_packet;//for control urbs
interval->low speed in ms/high speed in (1/8)ms
SUBMITTING URB’s
int usb_submit_urb(struct urb *urb, int mem_flags)
mem_flags is used for internal allocations performed by usb_submit_urb().
Settings that should be used:
GFP_ATOMIC: called from code which cannot sleep: a urb completion
handler, hard or soft interrupts. Or called when the caller holds a spinlock.
GPF_NOIO: in some cases when block storage is used.
GFP_KERNEL: in other cases.
Return Values-usb_sumit_urb
Out of memory (-ENOMEM)
Unplugged device (-ENODEV)
Stalled endpoint (-EPIPE)
Too many queued ISO transfers (-EAGAIN)
Too many requested ISO frames (-EFBIG)
Invalid INT interval (-EINVAL)
More than one packet for INT (-EINVAL)
however on submissmision urb->status will be -EINPROGRESS,it is suggested that we should not lookinto
unless we get a completion call.
Cancelling URB’s
There are two ways
->asynchronous cancel: int usb_unlink_urb(struct urb *urb);
->synchronously cancel: void usb_kill_urb(struct urb *urb);
Completion Handlers
After the data transfer successfully completed.
urb->status == 0
Error(s) happened during the transfer.
The urb was unlinked by the USB core.
urb>status should only be checked from the completion handler
Some of the Transfer Status
ECONNRESET: The urb was unlinked by usb_unlink_urb().
ENOENT: The urb was stopped by usb_kill_urb().
ENODEV: Device removed. Often preceded by a burst of other errors,
since the hub driver doesn't detect device removal events immediately.
EINPROGRESS:Urb not completed yet.
Writing USB drivers
checking which device support which driver.
passing the information from the user space to find the right driver during
hot-plug event.
driver needs to call right probe function and disconnect function.
All these information can be derived from usb_device_id structure.
(include/linux/mod_devicetable.h)
Declaring supported devices
USB_DEVICE(vendor, product)
Creates a usb_device_id structure which can be used to
match only the specified vendor and product ids.
Created usb_device_id structures are declared
with the MODULE_DEVICE_TABLE() macro
Drivers need to announce the devices they support in usb_device_id
structures.
Driver Registration
usb_register() to register our driver
static struct usb_driver mtouchusb_driver = {
.name = "mtouchusb",
.probe = mtouchusb_probe,
.disconnect = mtouchusb_disconnect,
.id_table = mtouchusb_devices,
};
static int __init mtouchusb_init(void)
{
return usb_register(&mtouchusb_driver);
}
Driver unregistration
usb_deregister() to register your driver
static void __exit mtouchusb_cleanup(void)
{
usb_deregister(&mtouchusb_driver);
}
probe() and disconnect() functions
The probe() function is called by the USB core to see if the driver is willing to
manage a particular interface on a device.
The driver should then make checks on the information passed to it about the
device.
If it decides to manage the interface, the probe() function will return 0.
Otherwise, it will return a negative value.
The disconnect() function is called by the USB core when a driver should no
longer control the device (even if the driver is still loaded), and should do some
cleanup.
Transfering without URB’s
The kernel provides two usb_bulk_msg()
and usb_control_msg() helper functions that make it possible to transfer
simple bulk and control messages
Constrains of transfering without
URB’s
These functions are synchronous and will make our code sleep
We cannot cancel our requests, as we have no handle on the URB used
internally
Thank you

More Related Content

What's hot

Yocto project and open embedded training
Yocto project and open embedded trainingYocto project and open embedded training
Yocto project and open embedded trainingH Ming
 
Useful USB Gadgets on Linux
Useful USB Gadgets on LinuxUseful USB Gadgets on Linux
Useful USB Gadgets on LinuxGary Bisson
 
XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo...
XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo...XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo...
XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo...The Linux Foundation
 
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime RipardKernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime RipardAnne Nicolas
 
Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)RuggedBoardGroup
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoCMacpaul Lin
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013Wave Digitech
 
USB Universal Serial Bus
USB Universal Serial BusUSB Universal Serial Bus
USB Universal Serial BusVarun Kambrath
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New HardwareRuggedBoardGroup
 
Linux power management: are you doing it right?
Linux power management: are you doing it right?Linux power management: are you doing it right?
Linux power management: are you doing it right?Chris Simmonds
 

What's hot (20)

BusyBox for Embedded Linux
BusyBox for Embedded LinuxBusyBox for Embedded Linux
BusyBox for Embedded Linux
 
Android Things : Building Embedded Devices
Android Things : Building Embedded DevicesAndroid Things : Building Embedded Devices
Android Things : Building Embedded Devices
 
Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
Yocto project and open embedded training
Yocto project and open embedded trainingYocto project and open embedded training
Yocto project and open embedded training
 
Useful USB Gadgets on Linux
Useful USB Gadgets on LinuxUseful USB Gadgets on Linux
Useful USB Gadgets on Linux
 
XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo...
XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo...XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo...
XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo...
 
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime RipardKernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
 
USB Drivers
USB DriversUSB Drivers
USB Drivers
 
Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)
 
Programming guide for linux usb device drivers
Programming guide for linux usb device driversProgramming guide for linux usb device drivers
Programming guide for linux usb device drivers
 
Usb 2
Usb 2Usb 2
Usb 2
 
Embedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernelEmbedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernel
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoC
 
Getting started with BeagleBone Black - Embedded Linux
Getting started with BeagleBone Black - Embedded LinuxGetting started with BeagleBone Black - Embedded Linux
Getting started with BeagleBone Black - Embedded Linux
 
Network automation (NetDevOps) with Ansible
Network automation (NetDevOps) with AnsibleNetwork automation (NetDevOps) with Ansible
Network automation (NetDevOps) with Ansible
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013
 
USB Universal Serial Bus
USB Universal Serial BusUSB Universal Serial Bus
USB Universal Serial Bus
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New Hardware
 
Qemu Introduction
Qemu IntroductionQemu Introduction
Qemu Introduction
 
Linux power management: are you doing it right?
Linux power management: are you doing it right?Linux power management: are you doing it right?
Linux power management: are you doing it right?
 

Similar to Linux Usb overview

Study of USB Device Drivers under Linux _1_
Study of USB Device Drivers under Linux _1_Study of USB Device Drivers under Linux _1_
Study of USB Device Drivers under Linux _1_Ganesh Kamath
 
HKG18-110 - net_mdev: Fast path user space I/O
HKG18-110 - net_mdev: Fast path user space I/OHKG18-110 - net_mdev: Fast path user space I/O
HKG18-110 - net_mdev: Fast path user space I/OLinaro
 
Steps to build and run oai
Steps to build and run oaiSteps to build and run oai
Steps to build and run oaissuser38b887
 
FreeBSD and Drivers
FreeBSD and DriversFreeBSD and Drivers
FreeBSD and DriversKernel TLV
 
Eekol 2012 jan04_int_ems_an_01
Eekol 2012 jan04_int_ems_an_01Eekol 2012 jan04_int_ems_an_01
Eekol 2012 jan04_int_ems_an_01KaoMao
 
Study on Android Emulator
Study on Android EmulatorStudy on Android Emulator
Study on Android EmulatorSamael Wang
 
Project ACRN USB mediator introduction
Project ACRN USB mediator introductionProject ACRN USB mediator introduction
Project ACRN USB mediator introductionProject ACRN
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal BootloaderSatpal Parmar
 
Linux or unix interview questions
Linux or unix interview questionsLinux or unix interview questions
Linux or unix interview questionsTeja Bheemanapally
 
Linuxdd[1]
Linuxdd[1]Linuxdd[1]
Linuxdd[1]mcganesh
 

Similar to Linux Usb overview (20)

Usb old
Usb oldUsb old
Usb old
 
Cp33551556
Cp33551556Cp33551556
Cp33551556
 
Cp33551556
Cp33551556Cp33551556
Cp33551556
 
Us bdrv tips2
Us bdrv tips2Us bdrv tips2
Us bdrv tips2
 
Study of USB Device Drivers under Linux _1_
Study of USB Device Drivers under Linux _1_Study of USB Device Drivers under Linux _1_
Study of USB Device Drivers under Linux _1_
 
HKG18-110 - net_mdev: Fast path user space I/O
HKG18-110 - net_mdev: Fast path user space I/OHKG18-110 - net_mdev: Fast path user space I/O
HKG18-110 - net_mdev: Fast path user space I/O
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
 
Un se-bu
Un se-buUn se-bu
Un se-bu
 
Steps to build and run oai
Steps to build and run oaiSteps to build and run oai
Steps to build and run oai
 
Driver_linux
Driver_linuxDriver_linux
Driver_linux
 
FreeBSD and Drivers
FreeBSD and DriversFreeBSD and Drivers
FreeBSD and Drivers
 
Usb Overview
Usb OverviewUsb Overview
Usb Overview
 
Eekol 2012 jan04_int_ems_an_01
Eekol 2012 jan04_int_ems_an_01Eekol 2012 jan04_int_ems_an_01
Eekol 2012 jan04_int_ems_an_01
 
Study on Android Emulator
Study on Android EmulatorStudy on Android Emulator
Study on Android Emulator
 
Project ACRN USB mediator introduction
Project ACRN USB mediator introductionProject ACRN USB mediator introduction
Project ACRN USB mediator introduction
 
Iphone ifuse
Iphone ifuseIphone ifuse
Iphone ifuse
 
Notes for LX0-101 Linux
Notes for LX0-101 Linux Notes for LX0-101 Linux
Notes for LX0-101 Linux
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal Bootloader
 
Linux or unix interview questions
Linux or unix interview questionsLinux or unix interview questions
Linux or unix interview questions
 
Linuxdd[1]
Linuxdd[1]Linuxdd[1]
Linuxdd[1]
 

Recently uploaded

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Recently uploaded (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Linux Usb overview

  • 2. USB drivers USB core drivers Architecture independent kernel subsystem. Implements the USB bus specification. USB host drivers Different drivers for each USB control hardware. Usually available in the Board Support Package. Architecture and platform dependent. USB device drivers Drivers for devices on the USB bus. USB device controller drivers For Linux systems with just a USB device controller
  • 3. USB gadget drivers PLATFORM DEPENDENT Supports the chip connecting to the USB bus. PLATFORM INDEPENDENT Ethernet gadget: implements networking through USB Storage gadget: makes the host see a USB storage device
  • 4. USB SUPPORT ARCHITECTURE SUPPORT USB device driver USB Core USB host controller SYSTEM CALL INTERFACE Other drivers Hardware (USB DEVICE) USER APPLICATION USERSPACE KERNAL
  • 5. TYPES OF USB HOST CONTROLLER 1. OHCI (Open Host Controller Interface): ->Compaq’s implementation for USB 1.0 and USB 1.1 ->Also used for some firmware devices 2.UHCI (Universal Host Controller Interface): ->Intel implementation for USB 2.0 3.EHCI (Extended Host Controller Interface): ->Only one to provide high speed transfer (USB 2.0) 4.SL811 ->host controller, manufactured by Cypress. ->It has 256MB of internal SRAM buffer.
  • 6. USB transfer speed LowSpeed: up to 1.5 Mbps Since USB 1.0 FullSpeed: up to 12 Mbps Since USB 1.1 HiSpeed: up to 480 Mbps Since USB 2.0
  • 7. USB descriptors Device Represent the devices connected to the USB bus. Example: USB speaker with volume control buttons. Configurations Represent the state of the device. Examples: Active, Standby, Initialization Interfaces Logical devices. Examples: speaker, volume control buttons. Endpoints Unidirectional communication pipes. Either IN (device to computer) or OUT (computer to device).
  • 8. TYPES OF ENDPOINTS Control endpoints: device control, accessing information, small transfers. Guaranteed bandwidth. Interrupt endpoints: data transfer at a fixed rate. Guaranteed bandwidth. Bulk endpoints: use all remaining bandwidth. No bandwidth or latency guarantee. Isochronous endpoints:guaranteed speed. Possible data loss.
  • 9. USB Request Blocks(URB) An URB consists of all relevant information to execute any USB transaction Any communication between the host and device is done asynchronously using USB Request Blocks (urbs). They are similar to packets in network communications. Every endpoint can handle a queue of urbs. Every urb has a completion handler. A driver may allocate many urbs for a single endpoint, or reuse the same urb for different endpoints.
  • 11. PIPES FOR URB’s Control pipes usb_sndctrlpipe(), usb_rcvctrlpipe() Bulk pipes usb_sndbulkpipe(), usb_rcvbulkpipe() Interrupt pipes usb_sndintpipe(), usb_rcvintpipe() Isochronous pipes usb_sndisocpipe(), usb_rcvisocpipe()
  • 12. Creating an URB’s struct urb *usb_alloc_urb(int isoframes, int mem_flags) Allocating URB’s isoframes->for isochronous transfer,’0’ for others mem_flags->holds the memory allocation flag which allows to control the block Note: we must do the error handling if allocation fails it returns NULL Eg:urb = usb_alloc_urb(0, GFP_KERNEL); if(urb!=0) printk(KERN_ALERT “Allocation failed”);
  • 13. Freeing URB void usb_free_urb(struct urb *urb); Note : if the allocation dint return a completion call back or not been use it can deallocate by itself .
  • 14. Initializing urb’s interrupt urbs bulk urbs control urbs isochronous urbs(has to be done manually by driver,no function available).
  • 15. Function for Initilizing URB’s void usb_fill_int_urb ( struct urb *urb, // urb to be initialized struct usb_device *dev, // device to send the urb to unsigned int pipe, // pipe (endpoint and device specific) void*transfer_buffer, //transferbuffer int buffer_length, // transfer buffer size usb_complete_t complete, // completion handler void *context, // context (for handler) int interval // Scheduling interval (for interrupt URB’s) unsigned char *setup_packet;//for control urbs interval->low speed in ms/high speed in (1/8)ms
  • 16. SUBMITTING URB’s int usb_submit_urb(struct urb *urb, int mem_flags) mem_flags is used for internal allocations performed by usb_submit_urb(). Settings that should be used: GFP_ATOMIC: called from code which cannot sleep: a urb completion handler, hard or soft interrupts. Or called when the caller holds a spinlock. GPF_NOIO: in some cases when block storage is used. GFP_KERNEL: in other cases.
  • 17. Return Values-usb_sumit_urb Out of memory (-ENOMEM) Unplugged device (-ENODEV) Stalled endpoint (-EPIPE) Too many queued ISO transfers (-EAGAIN) Too many requested ISO frames (-EFBIG) Invalid INT interval (-EINVAL) More than one packet for INT (-EINVAL) however on submissmision urb->status will be -EINPROGRESS,it is suggested that we should not lookinto unless we get a completion call.
  • 18. Cancelling URB’s There are two ways ->asynchronous cancel: int usb_unlink_urb(struct urb *urb); ->synchronously cancel: void usb_kill_urb(struct urb *urb);
  • 19. Completion Handlers After the data transfer successfully completed. urb->status == 0 Error(s) happened during the transfer. The urb was unlinked by the USB core. urb>status should only be checked from the completion handler
  • 20. Some of the Transfer Status ECONNRESET: The urb was unlinked by usb_unlink_urb(). ENOENT: The urb was stopped by usb_kill_urb(). ENODEV: Device removed. Often preceded by a burst of other errors, since the hub driver doesn't detect device removal events immediately. EINPROGRESS:Urb not completed yet.
  • 21. Writing USB drivers checking which device support which driver. passing the information from the user space to find the right driver during hot-plug event. driver needs to call right probe function and disconnect function. All these information can be derived from usb_device_id structure. (include/linux/mod_devicetable.h)
  • 22. Declaring supported devices USB_DEVICE(vendor, product) Creates a usb_device_id structure which can be used to match only the specified vendor and product ids. Created usb_device_id structures are declared with the MODULE_DEVICE_TABLE() macro Drivers need to announce the devices they support in usb_device_id structures.
  • 23. Driver Registration usb_register() to register our driver static struct usb_driver mtouchusb_driver = { .name = "mtouchusb", .probe = mtouchusb_probe, .disconnect = mtouchusb_disconnect, .id_table = mtouchusb_devices, }; static int __init mtouchusb_init(void) { return usb_register(&mtouchusb_driver); }
  • 24. Driver unregistration usb_deregister() to register your driver static void __exit mtouchusb_cleanup(void) { usb_deregister(&mtouchusb_driver); }
  • 25. probe() and disconnect() functions The probe() function is called by the USB core to see if the driver is willing to manage a particular interface on a device. The driver should then make checks on the information passed to it about the device. If it decides to manage the interface, the probe() function will return 0. Otherwise, it will return a negative value. The disconnect() function is called by the USB core when a driver should no longer control the device (even if the driver is still loaded), and should do some cleanup.
  • 26. Transfering without URB’s The kernel provides two usb_bulk_msg() and usb_control_msg() helper functions that make it possible to transfer simple bulk and control messages
  • 27. Constrains of transfering without URB’s These functions are synchronous and will make our code sleep We cannot cancel our requests, as we have no handle on the URB used internally