SlideShare une entreprise Scribd logo
1  sur  36
Télécharger pour lire hors ligne
Writing a Linux driver
for an unknown device
Ľubomír Rintel <lkundrak@v3.sk>
LinuxAlt 2013, Brno
BTC: 1GrpeEj18B6X7QFbh794bFGnZLRhVMqwL8
Linux 2.4?
Linux 2.2?
Linux 2.0?
Great hardware support!
Our device
●

Unknown to Linux

●

No documentation

●

No Google hits for chip

●

Desperate users in
Ubuntu forums
No Linux support at all!
The Plan
●

Make it work in Windows

●

Capture what happens

●

Find image data

●

Mimic the behavior in userspace

●

Transform into a kernel module
USB
USB Architecture
●

Network of Host, Hubs and Devices
USB Addresses
●

Bus & Device number

Host
Device 1:1
Hub

Device 2:1
Hub
Device 2:2
Flash Drive

Device 3:1
Mouse
USB Addresses
$ lsusb
Bus 001
Bus 002
Bus 002
Bus 003
$ lsusb
...

Device
Device
Device
Device
-v

001:
001:
002:
001:

ID
ID
ID
ID

1d6b:0002
1337:abcd
1337:0123
dead:b4b3

Linux Foundation 2.0 root hub
Trololol USB 1.1 Hub
Trololol Flash Drive
Random Mouse
USB Device
●

Self-describing

●

Endpoints
●

CONTROL

●

INTERRUPT

●

BULK

●

ISOCHRONOUS

●

Endpoints grouped into Interfaces

●

Interfaces grouped into Configurations
Our device
Device
Alternate setting 0
Endpoints:

Alternate setting 1
Endpoints:

0x81 Isochronous IN
0x82 Bulk
IN

0x81 Isochronous IN
0x82 Bulk
IN

0x83 Bulk
0x84 Interrupt

0x83 Bulk
0x84 Interrupt

IN
IN

IN
IN
The Plan
●

Make it work in Windows

●

Capture what happens

●

Find image data

●

Mimic the behavior in userspace

●

Transform into a kernel module
Do try this
at home!
Windows & VirtualBox
Wireshark & usbmon
What did we see
●

Number of CONTROL requests

●

ISOCHRONOUS packets once capture starts
RGB

R R R R R R R R
G G G G G G G G
B B B B B B B B
YUV2
Y Y Y Y U1 U1 U1 U1
Y Y Y Y V1 V1 V1 V1
Y Y Y Y U2 U2 U2 U2
Y Y Y Y V2 V2 V2 V2
LibUSB
●

We could replay the traffic

●

In userspace – no kernel hacking needed

●

C, Python & Perl bindings

●

Now we need to find start & end of the picture
Test image
0xff00ff00

0xaaaaaaaa

0x00ff00ff
0x00000000
0x80808080
Frame format
88 01 00 00
88 01 00 01

...

88 01 02 cf
88 02 80 00

...

88 02 82 cf
88 03 00 00

...

xx xx xx xx

• 240

00 00 00 00

• 15

Frame number
●
Even/odd
●
Chunk number 0 – 0x2cf = 719
●

740 x 480 YUV2 Interlaced (NTSC)
To kernel!
To kernel!
●

Booooring!

●

A module

●

USB framework
●

●

Video4Linux2
●

●

Linux Device Drivers: http://lwn.net/Kernel/LDD3/

LWN Series: http://lwn.net/Articles/203924/

Videobuf2
●

LWN Article: http://lwn.net/Articles/447435/
Video4Linux2

Videobuf2

Userspace

USB

Our code

Hardware

Architecture
Video4Linux2
●

Provide a device with known API
●

●

read(), write()

●

ioctl()

●

●

open(), close()

mmap()

Negotiate format with userspace
Videobuf2
●

Manages buffers of frames

●

Connects to Video4Linux2
●

read(), write(), mmap()

●

some ioctl()s
–

Start/stop capture

–

Exchange buffers with userspace
USB framework
●

●

Setup the device
Allocate buffers for exchange of data with
device

●

Handle start/stop

●

Isochronous callbacks
●

Copy data from USB buffers to Videobuf2 buffers
Video4Linux2

Videobuf2

Userspace

USB

Our code

Hardware

Architecture
Works!
Community
Free Software
●

Mainline Linux 3.11
●

●

drivers/media/usb/usbtv

Contributions
●

Review

●

Bug fixes

●

Features!
Questions?
See you!

http://base48.cz
#base48@irc.freenode.net

Did you find this useful? My Bitcoin address is:
1GrpeEj18B6X7QFbh794bFGnZLRhVMqwL8

Contenu connexe

Tendances

Controlling USB Flash Drive Controllers: Expose of Hidden Features
Controlling USB Flash Drive Controllers: Expose of Hidden FeaturesControlling USB Flash Drive Controllers: Expose of Hidden Features
Controlling USB Flash Drive Controllers: Expose of Hidden Features
xabean
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
elliando dias
 
งานนำเสนอ Amd
งานนำเสนอ Amdงานนำเสนอ Amd
งานนำเสนอ Amd
Nubow
 
"Безопасные Биткоин-транзакции без специального оборудования", Алексей Каракулов
"Безопасные Биткоин-транзакции без специального оборудования", Алексей Каракулов"Безопасные Биткоин-транзакции без специального оборудования", Алексей Каракулов
"Безопасные Биткоин-транзакции без специального оборудования", Алексей Каракулов
HackIT Ukraine
 
chilug-bbone-20140118-151216015606
chilug-bbone-20140118-151216015606chilug-bbone-20140118-151216015606
chilug-bbone-20140118-151216015606
Drew Fustini
 
D1T3-Anto-Joseph-Droid-FF
D1T3-Anto-Joseph-Droid-FFD1T3-Anto-Joseph-Droid-FF
D1T3-Anto-Joseph-Droid-FF
Anthony Jose
 

Tendances (14)

Controlling USB Flash Drive Controllers: Expose of Hidden Features
Controlling USB Flash Drive Controllers: Expose of Hidden FeaturesControlling USB Flash Drive Controllers: Expose of Hidden Features
Controlling USB Flash Drive Controllers: Expose of Hidden Features
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
 
Hp prodesk
Hp prodeskHp prodesk
Hp prodesk
 
A Science Project: Building a sound card based on the Covox Speech Thing
A Science Project: Building a sound card based on the Covox Speech ThingA Science Project: Building a sound card based on the Covox Speech Thing
A Science Project: Building a sound card based on the Covox Speech Thing
 
งานนำเสนอ Amd
งานนำเสนอ Amdงานนำเสนอ Amd
งานนำเสนอ Amd
 
How to port Tizen:Common to open source hardware devices?
How to port Tizen:Common to open source hardware devices? How to port Tizen:Common to open source hardware devices?
How to port Tizen:Common to open source hardware devices?
 
"Безопасные Биткоин-транзакции без специального оборудования", Алексей Каракулов
"Безопасные Биткоин-транзакции без специального оборудования", Алексей Каракулов"Безопасные Биткоин-транзакции без специального оборудования", Алексей Каракулов
"Безопасные Биткоин-транзакции без специального оборудования", Алексей Каракулов
 
MinnowBoard MAX: Open Source Hardware 64-bit x86 Single Board Computer
MinnowBoard MAX: Open Source Hardware  64-bit x86 Single Board ComputerMinnowBoard MAX: Open Source Hardware  64-bit x86 Single Board Computer
MinnowBoard MAX: Open Source Hardware 64-bit x86 Single Board Computer
 
Manual pc chipp
Manual pc chippManual pc chipp
Manual pc chipp
 
chilug-bbone-20140118-151216015606
chilug-bbone-20140118-151216015606chilug-bbone-20140118-151216015606
chilug-bbone-20140118-151216015606
 
D1T3-Anto-Joseph-Droid-FF
D1T3-Anto-Joseph-Droid-FFD1T3-Anto-Joseph-Droid-FF
D1T3-Anto-Joseph-Droid-FF
 
Lt2013 uefisb.talk
Lt2013 uefisb.talkLt2013 uefisb.talk
Lt2013 uefisb.talk
 
Reflections on Trusting Trust
Reflections on Trusting TrustReflections on Trusting Trust
Reflections on Trusting Trust
 
Let's hack cheap hardware 2016 edition
Let's hack cheap hardware 2016 editionLet's hack cheap hardware 2016 edition
Let's hack cheap hardware 2016 edition
 

Similaire à LinuxAlt 2013: Writing a driver for unknown USB device

Pumping stationone20140628 real-timeprogrammingwithbeaglebonepr_us.pptx
Pumping stationone20140628 real-timeprogrammingwithbeaglebonepr_us.pptxPumping stationone20140628 real-timeprogrammingwithbeaglebonepr_us.pptx
Pumping stationone20140628 real-timeprogrammingwithbeaglebonepr_us.pptx
Amit Tripathi
 
hashdays 2011: Ange Albertini - Such a weird processor - messing with x86 opc...
hashdays 2011: Ange Albertini - Such a weird processor - messing with x86 opc...hashdays 2011: Ange Albertini - Such a weird processor - messing with x86 opc...
hashdays 2011: Ange Albertini - Such a weird processor - messing with x86 opc...
Area41
 
Share the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development BoardShare the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development Board
Jian-Hong Pan
 

Similaire à LinuxAlt 2013: Writing a driver for unknown USB device (20)

Let's begin io t with $10
Let's begin io t with $10Let's begin io t with $10
Let's begin io t with $10
 
Hardware hacking
Hardware hackingHardware hacking
Hardware hacking
 
CONFidence 2017: Hacking embedded with OpenWrt (Vladimir Mitiouchev)
CONFidence 2017: Hacking embedded with OpenWrt (Vladimir Mitiouchev)CONFidence 2017: Hacking embedded with OpenWrt (Vladimir Mitiouchev)
CONFidence 2017: Hacking embedded with OpenWrt (Vladimir Mitiouchev)
 
Rapid SPi Device Driver Development over USB
Rapid SPi Device Driver Development over USBRapid SPi Device Driver Development over USB
Rapid SPi Device Driver Development over USB
 
BKK16-105 HALs for LITE
BKK16-105 HALs for LITEBKK16-105 HALs for LITE
BKK16-105 HALs for LITE
 
Ghosterr
GhosterrGhosterr
Ghosterr
 
Porting Android
Porting AndroidPorting Android
Porting Android
 
Headless Android at AnDevCon3
Headless Android at AnDevCon3Headless Android at AnDevCon3
Headless Android at AnDevCon3
 
Dragon board 410c workshop - slideshow
Dragon board 410c workshop - slideshowDragon board 410c workshop - slideshow
Dragon board 410c workshop - slideshow
 
Multipilot pres-ufficiale def
Multipilot pres-ufficiale defMultipilot pres-ufficiale def
Multipilot pres-ufficiale def
 
BadUSB, and what you should do about it
BadUSB, and what you should do about itBadUSB, and what you should do about it
BadUSB, and what you should do about it
 
SoC Idling for unconf COSCUP 2016
SoC Idling for unconf COSCUP 2016SoC Idling for unconf COSCUP 2016
SoC Idling for unconf COSCUP 2016
 
Pumping stationone20140628 real-timeprogrammingwithbeaglebonepr_us.pptx
Pumping stationone20140628 real-timeprogrammingwithbeaglebonepr_us.pptxPumping stationone20140628 real-timeprogrammingwithbeaglebonepr_us.pptx
Pumping stationone20140628 real-timeprogrammingwithbeaglebonepr_us.pptx
 
Tac Presentation October 72014- Raspberry PI
Tac Presentation October 72014- Raspberry PITac Presentation October 72014- Raspberry PI
Tac Presentation October 72014- Raspberry PI
 
hashdays 2011: Ange Albertini - Such a weird processor - messing with x86 opc...
hashdays 2011: Ange Albertini - Such a weird processor - messing with x86 opc...hashdays 2011: Ange Albertini - Such a weird processor - messing with x86 opc...
hashdays 2011: Ange Albertini - Such a weird processor - messing with x86 opc...
 
Share the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development BoardShare the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development Board
 
Raspberry Pi and Amateur Radio - 2020 update
Raspberry Pi and Amateur Radio - 2020 updateRaspberry Pi and Amateur Radio - 2020 update
Raspberry Pi and Amateur Radio - 2020 update
 
Dx diag
Dx diagDx diag
Dx diag
 
Introduction and course Details of Embedded Linux Platform Developer Training
Introduction and course Details of Embedded Linux Platform Developer TrainingIntroduction and course Details of Embedded Linux Platform Developer Training
Introduction and course Details of Embedded Linux Platform Developer Training
 
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021
 

Plus de Lubomir Rintel (7)

Namespaces for Kazimir
Namespaces for KazimirNamespaces for Kazimir
Namespaces for Kazimir
 
Linux Kernel Debugging Essentials workshop
Linux Kernel Debugging Essentials workshopLinux Kernel Debugging Essentials workshop
Linux Kernel Debugging Essentials workshop
 
Namespaces in Linux
Namespaces in LinuxNamespaces in Linux
Namespaces in Linux
 
A journey through the years of UNIX and Linux service management
A journey through the years of UNIX and Linux service managementA journey through the years of UNIX and Linux service management
A journey through the years of UNIX and Linux service management
 
Practical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingPractical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profiling
 
SELinux basics
SELinux basicsSELinux basics
SELinux basics
 
Brno meetr: Packaging Ruby Gems into RPM
Brno meetr: Packaging Ruby Gems into RPMBrno meetr: Packaging Ruby Gems into RPM
Brno meetr: Packaging Ruby Gems into RPM
 

Dernier

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
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
vu2urc
 

Dernier (20)

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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
 
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)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

LinuxAlt 2013: Writing a driver for unknown USB device