SlideShare a Scribd company logo
1 of 29
Download to read offline
1




       Linux USB to
    Ethernet development

        spec. overview
         kernel backend
        driver interfaces




      Copyright © 2009 by Tom J.P.Sun   All rights reserved.
2


                  USB Overview(1)
      USB 1.1/2.0 Spec. For S/W engineer:
        Chap 5 “USB Data Flow Model”
        Chap 9 “USB Device Framework”
        Chap 10 “USB Host : H/W and S/W”

             client                      function
    S/W                                                                  Logical 
                                                                         connection
              USB                          USB 
             system                       device

                                                                         Physical
    H/W     USB Bus                      USB Bus                         connection
            interface                    interface
                        USB cable

                      Copyright © 2009 by Tom J.P.Sun   All rights reserved.
3


                    USB Overview(2)

                   client


             USB system

               Usb­core (bus driver)

                     HC driver
                                                                  USB device F/W
    UHCI or OHCI
                                                                  USB device H/W
                                         USB bus
               HC H/W SIE



                       Copyright © 2009 by Tom J.P.Sun   All rights reserved.
4


       USB communication flow

    Communication
                                  Client S/W, driver
    flow


                                                                 buffers



              pipes



      Interface
                                                                 End points
                               USB logical device



                  Copyright © 2009 by Tom J.P.Sun   All rights reserved.
5


                       USB transfer types
            Control Transfer
               device enumeration use this type ( issued by USBD 
               (bus driver))
               client driver can use it ( same concept  as “IOCTL”) 
               for “device specific commands”
            Bulk Transfer
               reliable, but not realtime ­­­ scanner,printer
            Isochronous Transfer
               near realtime, but not reliable ­­­ usbcam
            Interrupt Transfer
               reliable, realtime, but limit in bandwidth ­­­ mouse
            Important Concept
    cncpt
               USB is Master­Slave model
               USB­On­The­Go is peer­to­peer model

                          Copyright © 2009 by Tom J.P.Sun   All rights reserved.
6


               USB Descriptor Hierarchy

                                  device descriptor



                                                                 Configuration
           Configuration
                                                                       2
                 1



       Interface 0   Interface 1       Interface 1                   Interface 0    Interface 1
           AS0           AS0               AS1                           AS1            AS0



    Endpoint    Endpoint       Endpoint                            More endpoint 
       1           2              3                                 descriptors



                           Copyright © 2009 by Tom J.P.Sun   All rights reserved.
7



    USB device request




     Copyright © 2009 by Tom J.P.Sun   All rights reserved.
8


      USB standard commands
         (bRequest value)
    GET_STATUS                                         0
    CLEAR_FEATURE                                      1
    Reserved for future use                            2
    SET_FEATURE                                        3
    Reserved for future use                            4
    SET_ADDRESS                                        5
    GET_DESCRIPTOR                                     6
    SET_DESCRIPTOR                                     7
    GET_CONFIGURATION                                  8
    SET_CONFIGURATION                                  9
    GET_INTERFACE                                     10
    SET_INTERFACE                                     11
    SYNCH_FRAME                                       12




               Copyright © 2009 by Tom J.P.Sun   All rights reserved.
9

     9620 vendor commands
        (bRequest value)
    DM_READ_REGS                                      0
    DM_WRITE_REGS                                     1
    DM_READ_MEMS                                      2
    DM_WRITE_REG                                      3
    DM_WRITE_MEMS                                     5
    DM_WRITE_MEM                                      7




           Copyright © 2009 by Tom J.P.Sun   All rights reserved.
10


                     Configure Device
     When USB Device Plugged in, USBD + driver
     should complete the device enumeration steps
                         1    get dev descriptor
                                            dev descriptor
                         2    set address

                         3    get dev descriptor
             Host                           dev descriptor                 Device

                          4    set cfg

                          5    set itf



         1     2    done by USBD
                                            CATC can see these transfers...
         3     4    5 done by client
                       Copyright © 2009 by Tom J.P.Sun   All rights reserved.
11


             USB Core API Layers

             USB device           USB device                USB device
               driver               driver                    driver


     upper
     API
                       USBD = USB core ( usb.c )
     lower
     API

             USB UHCI                USB OHCI                    other USB
               driver                  driver                    HC driver


                           ready




                 Copyright © 2009 by Tom J.P.Sun   All rights reserved.
12




                   USB

       spec. overview
       kernel backend
       driver interfaces




     Copyright © 2009 by Tom J.P.Sun   All rights reserved.
13


                 USB driver structure(1)
     struct usb_driver {
             const char *name;
             void* (*probe) (
                     struct usb_interface *
                     const struct usb_device_id *id_table);
             void (*disconnect)
                     (struct usb_device *, void *);
             ...
             const struct usb_device_id *id_table;
             struct device_driver driver;
     };


     @name: module name
     @probe: called to see if the driver will handle this USB interface , if
     it is, return zero, otherwise return a negative error code.
     @disconnect: called when the interface is no longer accessible.
     @id_table: USB use this table to support hotplugging, export this
     id_table with MODULE_DEVICE_TABLE( ) macro.
     @driver: driver modle core driver structure

                          Copyright © 2009 by Tom J.P.Sun   All rights reserved.
14


                 USB driver structure(2)
     On device attachment,
     USB framework walk                     USBD
     through the id_table


                  usb_register( )
                                                            First enter point on
                                                            device match
                         usb_driver


                                                             my_probe( )
                                                             …
                                                             my_disconnect( )
                                                             …
                    id_table : match list
                    1st match dev
                    2nd match dev
                    …                                       On device detachment,
                                                            USB framework call this.


                          Copyright © 2009 by Tom J.P.Sun   All rights reserved.
15


                 Standard Commands
        USBD provides USB standard
        commands
     usb_set_configuration( struct usb_device* dev, int cfg);
     usb_set_interface(struct usb_device*, int itf, int alt);
     usb_get_descriptor(…);
     usb_get_string(…);
     usb_get_status(…);



     kenrel_source/drivers/usb/core/message.c




                       Copyright © 2009 by Tom J.P.Sun   All rights reserved.
16



                    The USB data path
                                                                                    Can isolate driver,
                                                                                    when proving h/w
                   App               App
                                                 Linux O.S. Interface

                                             Network
                             FS
                                             (TCP/IP)
                                                                              App open the usb device
                                                                              interface, direct transfer
                                                                              data to the USB HC
       In          PCI                         USB
     Kernel     subsystem                    subsystem                        App open socket,
                                                                              data transferred by
                                                                              Network and USB
                   PCI                           USB                          driver
                  driver                         driver
                                       H/W

     EtherNet               PCI                  USB                    EtherNet
       Chip                 bus                  HC                       Chip


                           Copyright © 2009 by Tom J.P.Sun   All rights reserved.
17



                          The usbnet mini­driver
                                           The mini-driver interface
                                           ...
                        Network            tx_fixup( )
                        (TCP/IP)           rx_fixup( )
                                           ...                             asix


                         usbnet                                         dm9601
                          driver
                       framework
                                                                         ...other
     The usbnet module manages:
                                                                          client
                                                                         drivers
     1. skb flow control with the Network layer
     2. urb flow control with the USB bus driver
                                                          The mini-driver only take simple work
                                                          for device-specific fixups.
     so, the performance issue should be little
     between each mini-driver, (Yes !
     performance depends major on the H/W)




                                     Copyright © 2009 by Tom J.P.Sun   All rights reserved.
18




                   USB

        spec. overview
       kernel backend
       driver interfaces




     Copyright © 2009 by Tom J.P.Sun   All rights reserved.
19



                  dm9601_rx_fixup( )
     Object: correct the contents of skb ( data for
     the network layer ), which is device specific.
     e.g. dm9620 h/w give us data with length in
     the first 2 bytes, rx_fixup( ) should remove it
     before passing to the network layer
                                                           Mini-driver interface
     static const struct driver_info dm9601_info = {
              .description        = "Davicom DM9601 USB Ethernet",
              .flags              = FLAG_ETHER,
              .bind               = dm9601_bind,
              .rx_fixup           = dm9601_rx_fixup,
              .tx_fixup           = dm9601_tx_fixup,
              .status             = dm9601_status,
              .link_reset         = dm9601_link_reset,
              .reset              = dm9601_link_reset,
     };



                       Copyright © 2009 by Tom J.P.Sun   All rights reserved.
20



                  dm9601_tx_fixup( )
     Object: correct the contents of skb ( data for
     the network layer ), which is device specific.
     e.g. dm9620 h/w need data with length in
     the first 2 bytes, tx_fixup( ) should add it
     before passing to the chip

     static const struct driver_info dm9601_info = {
              .description        = "Davicom DM9601 USB Ethernet",
              .flags              = FLAG_ETHER,
              .bind               = dm9601_bind,
              .rx_fixup           = dm9601_rx_fixup,
              .tx_fixup           = dm9601_tx_fixup,
              .status             = dm9601_status,
              .link_reset         = dm9601_link_reset,
              .reset              = dm9601_link_reset,
     };


                       Copyright © 2009 by Tom J.P.Sun   All rights reserved.
21



                  vendor commands(1)
     static int dm_read(struct usbnet *dev, u8 reg, u16 length, void *data)
     {
               devdbg(dev, "dm_read() reg=0x%02x length=%d", reg, length);
               return usb_control_msg(dev->udev,
                                         usb_rcvctrlpipe(dev->udev, 0),
                                         DM_READ_REGS,
                                         USB_DIR_IN | USB_TYPE_VENDOR |
                                         USB_RECIP_DEVICE,
                                         0, reg, data, length,
                                         USB_CTRL_SET_TIMEOUT);
     }




                         Copyright © 2009 by Tom J.P.Sun   All rights reserved.
22



                    vendor commands (2)
     static int dm_write(struct usbnet *dev, u8 reg, u16 length, void *data)
     {

               return usb_control_msg(dev->udev,
                                        usb_sndctrlpipe(dev->udev, 0),
                                        DM_WRITE_REGS,
                                        USB_DIR_OUT | USB_TYPE_VENDOR |
                                        USB_RECIP_DEVICE,
                                        0, reg, data, length,
                                        USB_CTRL_SET_TIMEOUT);
     }




         Concept: The vendor commands are used to setup h/w , while
         the real data are transferred by b-in , b-out pipes,
         not the control pipe.



                           Copyright © 2009 by Tom J.P.Sun   All rights reserved.
23



     Device ID & Vendor ID 




     u
     s
     e                                          Use this information to
                                                load driver when plug-in...

         Copyright © 2009 by Tom J.P.Sun   All rights reserved.
24



                  Appendix : libusb
      Bypass driver, direct call via the
      USB subsystem.
      Package 0.1.12 (simple, but not well
      support thread )
     we need header files:
     #> apt-get src libusb-dev
     (get libusb-0.1.12 under the same directory)

     Makefile:
     usbtest: usbtest.c
             gcc -g -Wall $< -o $@ -I./libusb-0.1.12 -lusb

     ( assume usbtest.c is the our test program using the
     libusb , use root to test...)

                    Copyright © 2009 by Tom J.P.Sun   All rights reserved.
25



            Example usage of libusb (1)
     Include headers:

     #include "linux.h"
     #include "usbi.h"



     Initial setup provided by libusb

     usb_init();
     usb_find_busses();
     usb_find_devices();




                        Copyright © 2009 by Tom J.P.Sun   All rights reserved.
26



            Example usage of libusb (2)
     Get our device:

            for (usb_bus = usb_busses;
                 usb_bus;
                 usb_bus = usb_bus->next) {
                    for (dev = usb_bus->devices;
                         dev;
                         dev = dev->next) {
                            if ((dev->descriptor.idVendor
                                 == VENDOR_ID) &&
                                (dev->descriptor.idProduct
                                 == PRODUCT_ID))
                                    return dev;
                    }
            }




                       Copyright © 2009 by Tom J.P.Sun   All rights reserved.
27



              Example usage of libusb (3)
     Open:

     usb_handle = usb_open(usb_dev);


     B-out:

     mk_raw(buf, SZBUF); /* prepare data in buf*/
     retval = usb_bulk_write(usb_handle, ep_bulk_out,
     (char*)buf, SZBUF, 5000);

     B-in:

     memset(buf, 0, SZBUF);
     retval = usb_bulk_read(usb_handle, ep_bulk_in,
     (char*)buf, SZBUF, 5000);




                      Copyright © 2009 by Tom J.P.Sun   All rights reserved.
28



            Example usage of libusb (4)
     Control pipe:
     usb_control_msg(handle, 0x000000c0, DM_READ_REGS,
                     0,0xff & reg,data,length,5000);

     prototype: libusb-0.1.12/linux.c
     int usb_control_msg(
                  usb_dev_handle *dev,
                  int requesttype,
                  int request,
                  int value,
                  int index,
                  char *bytes,
                  int size,
                  int timeout);




                      Copyright © 2009 by Tom J.P.Sun   All rights reserved.
29



              The End




     Copyright © 2009 by Tom J.P.Sun   All rights reserved.

More Related Content

What's hot

Overview of cryptography and enhancements on z/VSE 4.3
Overview of cryptography and enhancements on z/VSE 4.3Overview of cryptography and enhancements on z/VSE 4.3
Overview of cryptography and enhancements on z/VSE 4.3IBM India Smarter Computing
 
Sony Anycast AWS-G500E
Sony Anycast AWS-G500ESony Anycast AWS-G500E
Sony Anycast AWS-G500EAV ProfShop
 
Datavideo MS-1000
Datavideo MS-1000Datavideo MS-1000
Datavideo MS-1000AV ProfShop
 
Power Mac G5 ( Late 2005) Technical Specifications
Power  Mac  G5 ( Late 2005)    Technical  SpecificationsPower  Mac  G5 ( Late 2005)    Technical  Specifications
Power Mac G5 ( Late 2005) Technical SpecificationsSocial Media Marketing
 
Sun fire x2250 technical training presentation
Sun fire x2250 technical training presentationSun fire x2250 technical training presentation
Sun fire x2250 technical training presentationxKinAnx
 
Cots moves to multicore: AMD
Cots moves to multicore: AMDCots moves to multicore: AMD
Cots moves to multicore: AMDKonrad Witte
 
Cisco UCS - Servidores
Cisco  UCS  - ServidoresCisco  UCS  - Servidores
Cisco UCS - ServidoresBruno Banha
 
AMD Analyst Day 2009: Rick Bergman
AMD Analyst Day 2009: Rick BergmanAMD Analyst Day 2009: Rick Bergman
AMD Analyst Day 2009: Rick BergmanAMD
 
Hardware assisted Virtualization in Embedded
Hardware assisted Virtualization in EmbeddedHardware assisted Virtualization in Embedded
Hardware assisted Virtualization in EmbeddedThe Linux Foundation
 
AMD Opteron 6200 and 4200 Series Presentation
AMD Opteron 6200 and 4200 Series PresentationAMD Opteron 6200 and 4200 Series Presentation
AMD Opteron 6200 and 4200 Series PresentationAMD
 

What's hot (16)

Overview of cryptography and enhancements on z/VSE 4.3
Overview of cryptography and enhancements on z/VSE 4.3Overview of cryptography and enhancements on z/VSE 4.3
Overview of cryptography and enhancements on z/VSE 4.3
 
Sony Anycast AWS-G500E
Sony Anycast AWS-G500ESony Anycast AWS-G500E
Sony Anycast AWS-G500E
 
Datavideo MS-1000
Datavideo MS-1000Datavideo MS-1000
Datavideo MS-1000
 
JVC SR-HD1500
JVC SR-HD1500JVC SR-HD1500
JVC SR-HD1500
 
Power Mac G5 ( Late 2005) Technical Specifications
Power  Mac  G5 ( Late 2005)    Technical  SpecificationsPower  Mac  G5 ( Late 2005)    Technical  Specifications
Power Mac G5 ( Late 2005) Technical Specifications
 
Sun fire x2250 technical training presentation
Sun fire x2250 technical training presentationSun fire x2250 technical training presentation
Sun fire x2250 technical training presentation
 
Craneboard
CraneboardCraneboard
Craneboard
 
Ether sam testing methodology
Ether sam testing methodologyEther sam testing methodology
Ether sam testing methodology
 
Cots moves to multicore: AMD
Cots moves to multicore: AMDCots moves to multicore: AMD
Cots moves to multicore: AMD
 
Cisco UCS - Servidores
Cisco  UCS  - ServidoresCisco  UCS  - Servidores
Cisco UCS - Servidores
 
Shuttle Highlights 2011 (EN)
Shuttle Highlights 2011 (EN)Shuttle Highlights 2011 (EN)
Shuttle Highlights 2011 (EN)
 
IBM zEnterprise FAQs
IBM zEnterprise  FAQsIBM zEnterprise  FAQs
IBM zEnterprise FAQs
 
Cis82 e2-1-packet forwarding
Cis82 e2-1-packet forwardingCis82 e2-1-packet forwarding
Cis82 e2-1-packet forwarding
 
AMD Analyst Day 2009: Rick Bergman
AMD Analyst Day 2009: Rick BergmanAMD Analyst Day 2009: Rick Bergman
AMD Analyst Day 2009: Rick Bergman
 
Hardware assisted Virtualization in Embedded
Hardware assisted Virtualization in EmbeddedHardware assisted Virtualization in Embedded
Hardware assisted Virtualization in Embedded
 
AMD Opteron 6200 and 4200 Series Presentation
AMD Opteron 6200 and 4200 Series PresentationAMD Opteron 6200 and 4200 Series Presentation
AMD Opteron 6200 and 4200 Series Presentation
 

Similar to Linux usb2ether

Project ACRN USB mediator introduction
Project ACRN USB mediator introductionProject ACRN USB mediator introduction
Project ACRN USB mediator introductionProject ACRN
 
Design Of A Usb Device Driver (Overview)
Design Of A Usb Device Driver (Overview)Design Of A Usb Device Driver (Overview)
Design Of A Usb Device Driver (Overview)allankliu
 
Usb In A Nutshell
Usb In A NutshellUsb In A Nutshell
Usb In A Nutshellallankliu
 
Introduction to SCSI over FCP for Linux on System z
Introduction to SCSI over FCP for Linux on System zIntroduction to SCSI over FCP for Linux on System z
Introduction to SCSI over FCP for Linux on System zIBM India Smarter Computing
 
USB 3.0 CAPTURE HDMI 4K with Loop-through for Image redistribution
USB 3.0 CAPTURE HDMI 4K with Loop-through for Image redistributionUSB 3.0 CAPTURE HDMI 4K with Loop-through for Image redistribution
USB 3.0 CAPTURE HDMI 4K with Loop-through for Image redistributionNaoto MATSUMOTO
 
Алексей Мисник - USB устройства для пентеста
Алексей Мисник - USB устройства для пентестаАлексей Мисник - USB устройства для пентеста
Алексей Мисник - USB устройства для пентестаHackIT Ukraine
 
Usb in-a-nutshell
Usb in-a-nutshellUsb in-a-nutshell
Usb in-a-nutshellboybk88
 
Chapter_2_CCNA2
Chapter_2_CCNA2Chapter_2_CCNA2
Chapter_2_CCNA2sunabozu
 
High Definition Fuzzing; Exploring HDMI vulnerabilities
High Definition Fuzzing; Exploring HDMI vulnerabilitiesHigh Definition Fuzzing; Exploring HDMI vulnerabilities
High Definition Fuzzing; Exploring HDMI vulnerabilitiesE Hacking
 
Paper id 252014121
Paper id 252014121Paper id 252014121
Paper id 252014121IJRAT
 
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
 
“Automation Testing for Embedded Systems”
“Automation Testing for Embedded Systems” “Automation Testing for Embedded Systems”
“Automation Testing for Embedded Systems” GlobalLogic Ukraine
 

Similar to Linux usb2ether (20)

XS Oracle 2009 PV USB
XS Oracle 2009 PV USBXS Oracle 2009 PV USB
XS Oracle 2009 PV USB
 
Usb In-a-Nutshell
Usb In-a-NutshellUsb In-a-Nutshell
Usb In-a-Nutshell
 
USB Drivers
USB DriversUSB Drivers
USB Drivers
 
Project ACRN USB mediator introduction
Project ACRN USB mediator introductionProject ACRN USB mediator introduction
Project ACRN USB mediator introduction
 
Design Of A Usb Device Driver (Overview)
Design Of A Usb Device Driver (Overview)Design Of A Usb Device Driver (Overview)
Design Of A Usb Device Driver (Overview)
 
Usb In A Nutshell
Usb In A NutshellUsb In A Nutshell
Usb In A Nutshell
 
Introduction to SCSI over FCP for Linux on System z
Introduction to SCSI over FCP for Linux on System zIntroduction to SCSI over FCP for Linux on System z
Introduction to SCSI over FCP for Linux on System z
 
An1003 usb
An1003 usbAn1003 usb
An1003 usb
 
USB 3.0 CAPTURE HDMI 4K with Loop-through for Image redistribution
USB 3.0 CAPTURE HDMI 4K with Loop-through for Image redistributionUSB 3.0 CAPTURE HDMI 4K with Loop-through for Image redistribution
USB 3.0 CAPTURE HDMI 4K with Loop-through for Image redistribution
 
Алексей Мисник - USB устройства для пентеста
Алексей Мисник - USB устройства для пентестаАлексей Мисник - USB устройства для пентеста
Алексей Мисник - USB устройства для пентеста
 
Usb in-a-nutshell
Usb in-a-nutshellUsb in-a-nutshell
Usb in-a-nutshell
 
Chapter_2_CCNA2
Chapter_2_CCNA2Chapter_2_CCNA2
Chapter_2_CCNA2
 
Networking with Linux on System z
Networking with Linux on System zNetworking with Linux on System z
Networking with Linux on System z
 
High Definition Fuzzing; Exploring HDMI vulnerabilities
High Definition Fuzzing; Exploring HDMI vulnerabilitiesHigh Definition Fuzzing; Exploring HDMI vulnerabilities
High Definition Fuzzing; Exploring HDMI vulnerabilities
 
Paper id 252014121
Paper id 252014121Paper id 252014121
Paper id 252014121
 
Advance of usb
Advance of usb Advance of usb
Advance of usb
 
Xctu
XctuXctu
Xctu
 
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
 
Embedded I/O Management
Embedded I/O ManagementEmbedded I/O Management
Embedded I/O Management
 
“Automation Testing for Embedded Systems”
“Automation Testing for Embedded Systems” “Automation Testing for Embedded Systems”
“Automation Testing for Embedded Systems”
 

More from Tom Sun

Retrolambda+bolts
Retrolambda+boltsRetrolambda+bolts
Retrolambda+boltsTom Sun
 
Cloud radio 閃電秀
Cloud radio 閃電秀Cloud radio 閃電秀
Cloud radio 閃電秀Tom Sun
 
健康報告:德國飲食
健康報告:德國飲食健康報告:德國飲食
健康報告:德國飲食Tom Sun
 
iOs app 101
iOs app 101iOs app 101
iOs app 101Tom Sun
 
Whos Fault
Whos FaultWhos Fault
Whos FaultTom Sun
 
小巫婆麗特拉
小巫婆麗特拉小巫婆麗特拉
小巫婆麗特拉Tom Sun
 
Serial Pnp
Serial PnpSerial Pnp
Serial PnpTom Sun
 

More from Tom Sun (8)

Retrolambda+bolts
Retrolambda+boltsRetrolambda+bolts
Retrolambda+bolts
 
Pioc
PiocPioc
Pioc
 
Cloud radio 閃電秀
Cloud radio 閃電秀Cloud radio 閃電秀
Cloud radio 閃電秀
 
健康報告:德國飲食
健康報告:德國飲食健康報告:德國飲食
健康報告:德國飲食
 
iOs app 101
iOs app 101iOs app 101
iOs app 101
 
Whos Fault
Whos FaultWhos Fault
Whos Fault
 
小巫婆麗特拉
小巫婆麗特拉小巫婆麗特拉
小巫婆麗特拉
 
Serial Pnp
Serial PnpSerial Pnp
Serial Pnp
 

Recently uploaded

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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.pptxHampshireHUG
 
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
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
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 MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
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
 
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...Neo4j
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
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 interpreternaman860154
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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 WorkerThousandEyes
 

Recently uploaded (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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 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
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
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
 
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...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 

Linux usb2ether

  • 1. 1 Linux USB to Ethernet development spec. overview kernel backend driver interfaces Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 2. 2 USB Overview(1) USB 1.1/2.0 Spec. For S/W engineer: Chap 5 “USB Data Flow Model” Chap 9 “USB Device Framework” Chap 10 “USB Host : H/W and S/W” client function S/W Logical  connection USB  USB  system device Physical H/W USB Bus  USB Bus  connection interface interface USB cable Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 3. 3 USB Overview(2) client USB system Usb­core (bus driver) HC driver USB device F/W UHCI or OHCI USB device H/W USB bus HC H/W SIE Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 4. 4 USB communication flow Communication Client S/W, driver flow buffers pipes Interface End points USB logical device Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 5. 5 USB transfer types Control Transfer device enumeration use this type ( issued by USBD  (bus driver)) client driver can use it ( same concept  as “IOCTL”)  for “device specific commands” Bulk Transfer reliable, but not realtime ­­­ scanner,printer Isochronous Transfer near realtime, but not reliable ­­­ usbcam Interrupt Transfer reliable, realtime, but limit in bandwidth ­­­ mouse Important Concept cncpt USB is Master­Slave model USB­On­The­Go is peer­to­peer model Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 6. 6 USB Descriptor Hierarchy device descriptor Configuration Configuration 2 1 Interface 0 Interface 1 Interface 1 Interface 0 Interface 1 AS0 AS0 AS1 AS1 AS0 Endpoint Endpoint Endpoint More endpoint  1 2 3 descriptors Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 7. 7 USB device request Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 8. 8 USB standard commands (bRequest value) GET_STATUS 0 CLEAR_FEATURE 1 Reserved for future use 2 SET_FEATURE 3 Reserved for future use 4 SET_ADDRESS 5 GET_DESCRIPTOR 6 SET_DESCRIPTOR 7 GET_CONFIGURATION 8 SET_CONFIGURATION 9 GET_INTERFACE 10 SET_INTERFACE 11 SYNCH_FRAME 12 Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 9. 9 9620 vendor commands (bRequest value) DM_READ_REGS 0 DM_WRITE_REGS 1 DM_READ_MEMS 2 DM_WRITE_REG 3 DM_WRITE_MEMS 5 DM_WRITE_MEM 7 Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 10. 10 Configure Device When USB Device Plugged in, USBD + driver should complete the device enumeration steps 1 get dev descriptor dev descriptor 2 set address 3 get dev descriptor Host dev descriptor Device 4 set cfg 5 set itf 1 2 done by USBD CATC can see these transfers... 3 4 5 done by client Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 11. 11 USB Core API Layers USB device USB device USB device driver driver driver upper API USBD = USB core ( usb.c ) lower API USB UHCI USB OHCI other USB driver driver HC driver ready Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 12. 12 USB spec. overview kernel backend driver interfaces Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 13. 13 USB driver structure(1) struct usb_driver { const char *name; void* (*probe) ( struct usb_interface * const struct usb_device_id *id_table); void (*disconnect) (struct usb_device *, void *); ... const struct usb_device_id *id_table; struct device_driver driver; }; @name: module name @probe: called to see if the driver will handle this USB interface , if it is, return zero, otherwise return a negative error code. @disconnect: called when the interface is no longer accessible. @id_table: USB use this table to support hotplugging, export this id_table with MODULE_DEVICE_TABLE( ) macro. @driver: driver modle core driver structure Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 14. 14 USB driver structure(2) On device attachment, USB framework walk USBD through the id_table usb_register( ) First enter point on device match usb_driver my_probe( ) … my_disconnect( ) … id_table : match list 1st match dev 2nd match dev … On device detachment, USB framework call this. Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 15. 15 Standard Commands USBD provides USB standard commands usb_set_configuration( struct usb_device* dev, int cfg); usb_set_interface(struct usb_device*, int itf, int alt); usb_get_descriptor(…); usb_get_string(…); usb_get_status(…); kenrel_source/drivers/usb/core/message.c Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 16. 16 The USB data path Can isolate driver, when proving h/w App App Linux O.S. Interface Network FS (TCP/IP) App open the usb device interface, direct transfer data to the USB HC In PCI USB Kernel subsystem subsystem App open socket, data transferred by Network and USB PCI USB driver driver driver H/W EtherNet PCI USB EtherNet Chip bus HC Chip Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 17. 17 The usbnet mini­driver The mini-driver interface ... Network tx_fixup( ) (TCP/IP) rx_fixup( ) ... asix usbnet dm9601 driver framework ...other The usbnet module manages: client drivers 1. skb flow control with the Network layer 2. urb flow control with the USB bus driver The mini-driver only take simple work for device-specific fixups. so, the performance issue should be little between each mini-driver, (Yes ! performance depends major on the H/W) Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 18. 18 USB spec. overview kernel backend driver interfaces Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 19. 19 dm9601_rx_fixup( ) Object: correct the contents of skb ( data for the network layer ), which is device specific. e.g. dm9620 h/w give us data with length in the first 2 bytes, rx_fixup( ) should remove it before passing to the network layer Mini-driver interface static const struct driver_info dm9601_info = { .description = "Davicom DM9601 USB Ethernet", .flags = FLAG_ETHER, .bind = dm9601_bind, .rx_fixup = dm9601_rx_fixup, .tx_fixup = dm9601_tx_fixup, .status = dm9601_status, .link_reset = dm9601_link_reset, .reset = dm9601_link_reset, }; Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 20. 20 dm9601_tx_fixup( ) Object: correct the contents of skb ( data for the network layer ), which is device specific. e.g. dm9620 h/w need data with length in the first 2 bytes, tx_fixup( ) should add it before passing to the chip static const struct driver_info dm9601_info = { .description = "Davicom DM9601 USB Ethernet", .flags = FLAG_ETHER, .bind = dm9601_bind, .rx_fixup = dm9601_rx_fixup, .tx_fixup = dm9601_tx_fixup, .status = dm9601_status, .link_reset = dm9601_link_reset, .reset = dm9601_link_reset, }; Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 21. 21 vendor commands(1) static int dm_read(struct usbnet *dev, u8 reg, u16 length, void *data) { devdbg(dev, "dm_read() reg=0x%02x length=%d", reg, length); return usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0), DM_READ_REGS, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 0, reg, data, length, USB_CTRL_SET_TIMEOUT); } Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 22. 22 vendor commands (2) static int dm_write(struct usbnet *dev, u8 reg, u16 length, void *data) { return usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), DM_WRITE_REGS, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 0, reg, data, length, USB_CTRL_SET_TIMEOUT); } Concept: The vendor commands are used to setup h/w , while the real data are transferred by b-in , b-out pipes, not the control pipe. Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 23. 23 Device ID & Vendor ID  u s e Use this information to load driver when plug-in... Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 24. 24 Appendix : libusb Bypass driver, direct call via the USB subsystem. Package 0.1.12 (simple, but not well support thread ) we need header files: #> apt-get src libusb-dev (get libusb-0.1.12 under the same directory) Makefile: usbtest: usbtest.c gcc -g -Wall $< -o $@ -I./libusb-0.1.12 -lusb ( assume usbtest.c is the our test program using the libusb , use root to test...) Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 25. 25 Example usage of libusb (1) Include headers: #include "linux.h" #include "usbi.h" Initial setup provided by libusb usb_init(); usb_find_busses(); usb_find_devices(); Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 26. 26 Example usage of libusb (2) Get our device: for (usb_bus = usb_busses; usb_bus; usb_bus = usb_bus->next) { for (dev = usb_bus->devices; dev; dev = dev->next) { if ((dev->descriptor.idVendor == VENDOR_ID) && (dev->descriptor.idProduct == PRODUCT_ID)) return dev; } } Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 27. 27 Example usage of libusb (3) Open: usb_handle = usb_open(usb_dev); B-out: mk_raw(buf, SZBUF); /* prepare data in buf*/ retval = usb_bulk_write(usb_handle, ep_bulk_out, (char*)buf, SZBUF, 5000); B-in: memset(buf, 0, SZBUF); retval = usb_bulk_read(usb_handle, ep_bulk_in, (char*)buf, SZBUF, 5000); Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 28. 28 Example usage of libusb (4) Control pipe: usb_control_msg(handle, 0x000000c0, DM_READ_REGS, 0,0xff & reg,data,length,5000); prototype: libusb-0.1.12/linux.c int usb_control_msg( usb_dev_handle *dev, int requesttype, int request, int value, int index, char *bytes, int size, int timeout); Copyright © 2009 by Tom J.P.Sun All rights reserved.
  • 29. 29 The End Copyright © 2009 by Tom J.P.Sun All rights reserved.