Решено: Сеть через USB

Knoppix

Модераторы: Warderer, Модераторы разделов

IMB
Сообщения: 2567
ОС: Debian

Решено: Сеть через USB

Сообщение IMB »

Используется Debian 6.0.4, необходимо связать его по USB с платой на которой также работает Linux, по USB должны ходить сетевые пакеты.
В списке модулей были обнаружены:

Код: Выделить всё

$ /sbin/modinfo rndis_host
filename:       /lib/modules/2.6.32-5-686/updates/drivers/net/usb/rndis_host.ko
license:        GPL
description:    USB Host side RNDIS driver
author:         David Brownell
alias:          usb:v*p*d*dc*dsc*dp*icE0isc01ip03*
alias:          usb:v*p*d*dc*dsc*dp*icEFisc01ip01*
alias:          usb:v*p*d*dc*dsc*dp*ic02isc02ipFF*
alias:          usb:v1630p0042d*dc*dsc*dp*ic02isc02ipFF*
depends:        usbnet,cdc_ether,usbcore
vermagic:       2.6.32-5-686 SMP mod_unload modversions 686

$ /sbin/modinfo usbnet
filename:       /lib/modules/2.6.32-5-686/updates/drivers/net/usb/usbnet.ko
license:        GPL
description:    USB network driver framework
author:         David Brownell
depends:        mii,compat,usbcore
vermagic:       2.6.32-5-686 SMP mod_unload modversions 686
parm:           msg_level:Override default message level (int)

Начальное состояние сети:

Код: Выделить всё

$ ip l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:21:91:0c:74:e6 brd ff:ff:ff:ff:ff:ff
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0f:ea:ce:b1:28 brd ff:ff:ff:ff:ff:ff

После загрузки модулей, пробовал загружать отдельно и оба сразу, нового сетевого устройства usb0, хотя название и не принципиально, не появилось.
dmesg для rndis_host:

Код: Выделить всё

[122249.044429] Compat-wireless backport release: compat-wireless-2011-07-19-5-g91e9e9f
[122249.044436] Backport based on linux-next.git next-20110722
[122249.056541] usbcore: registered new interface driver cdc_ether
[122249.060363] usbcore: registered new interface driver rndis_host

dmesg для usbnet:

Код: Выделить всё

[122332.689131] Compat-wireless backport release: compat-wireless-2011-07-19-5-g91e9e9f
[122332.689137] Backport based on linux-next.git next-20110722

В случае rndis_host, насколько я понимаю, новый интерфейс регистрируется, но почему-то не получает MAC-адреса, а так как в сетевых устройствах я его не вижу, то и присвоить ему параметры я не могу.
Вопрос - как можно организовать сеть через usb?
Спасибо.
Спасибо сказали:
watashiwa_daredeska
Бывший модератор
Сообщения: 4038
Статус: Искусственный интеллект (pre-alpha)
ОС: Debian GNU/Linux

Re: Решено: Сеть через USB

Сообщение watashiwa_daredeska »

Что появляется в /var/log/syslog хоста при подключении платы по USB?
И lsusb после подключения.

P.S. А лучше даже lsusb -v
Спасибо сказали:
IMB
Сообщения: 2567
ОС: Debian

Re: Решено: Сеть через USB

Сообщение IMB »

Когда к плате подключена USB-камера:

Код: Выделить всё

[127214.018977] usb 2-2: new full speed USB device using uhci_hcd and address 24
[127214.164069] usb 2-2: not running at top speed; connect to a high speed hub
[127214.199076] usb 2-2: New USB device found, idVendor=0ac8, idProduct=3450
[127214.199085] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[127214.199091] usb 2-2: Product: Venus USB2.0 Camera
[127214.199096] usb 2-2: Manufacturer: Vimicro Corp.
[127214.199310] usb 2-2: configuration #1 chosen from 1 choice
[127214.205205] uvcvideo: Found UVC 1.00 device Venus USB2.0 Camera (0ac8:3450)
[127214.209310] input: Venus USB2.0 Camera as /devices/pci0000:00/0000:00:1d.0/usb2/2-2/2-2:1.0/input/input8

lsusb

Код: Выделить всё

Bus 002 Device 024: ID 0ac8:3450 Z-Star Microelectronics Corp.

Bus 002 Device 024: ID 0ac8:3450 Z-Star Microelectronics Corp.
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass          239 Miscellaneous Device
  bDeviceSubClass         2 ?
  bDeviceProtocol         1 Interface Association
  bMaxPacketSize0        64
  idVendor           0x0ac8 Z-Star Microelectronics Corp.
  idProduct          0x3450
  bcdDevice            1.00
  iManufacturer           1 Vimicro Corp.
  iProduct                2 Venus USB2.0 Camera
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength          353
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              320mA
    Interface Association:
      bLength                 8
      bDescriptorType        11
      bFirstInterface         0
      bInterfaceCount         2
      bFunctionClass         14 Video
      bFunctionSubClass       3 Video Interface Collection
      bFunctionProtocol       0
      iFunction               2 Venus USB2.0 Camera
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      1 Video Control
      bInterfaceProtocol      0
      iInterface              2 Venus USB2.0 Camera
      VideoControl Interface Descriptor:
        bLength                13
        bDescriptorType        36
        bDescriptorSubtype      1 (HEADER)
        bcdUVC               1.00
        wTotalLength           79
        dwClockFrequency       30.000000MHz
        bInCollection           1
        baInterfaceNr( 0)       1
      VideoControl Interface Descriptor:
        bLength                18
        bDescriptorType        36
        bDescriptorSubtype      2 (INPUT_TERMINAL)
        bTerminalID             1
        wTerminalType      0x0201 Camera Sensor
        bAssocTerminal          0
        iTerminal               0
        wObjectiveFocalLengthMin      0
        wObjectiveFocalLengthMax      0
        wOcularFocalLength            0
        bControlSize                  3
        bmControls           0x00000000
      VideoControl Interface Descriptor:
        bLength                11
        bDescriptorType        36
        bDescriptorSubtype      5 (PROCESSING_UNIT)
      Warning: Descriptor too short
        bUnitID                 2
        bSourceID               1
        wMaxMultiplier          0
        bControlSize            2
        bmControls     0x0000043b
          Brightness
          Contrast
          Saturation
          Sharpness
          Gamma
          Power Line Frequency
        iProcessing             0
        bmVideoStandards     0x 9
          None
          SECAM - 625/50
      VideoControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      3 (OUTPUT_TERMINAL)
        bTerminalID             3
        wTerminalType      0x0101 USB Streaming
        bAssocTerminal          0
        bSourceID               2
        iTerminal               0
      VideoControl Interface Descriptor:
        bLength                28
        bDescriptorType        36
        bDescriptorSubtype      6 (EXTENSION_UNIT)
        bUnitID                 4
        guidExtensionCode         {e3deaebb-c2ec-4d42-802c-72f2eb3dfb57}
        bNumControl             8
        bNrPins                 1
        baSourceID( 0)          1
        bControlSize            3
        bmControls( 0)       0x59
        bmControls( 1)       0x80
        bmControls( 2)       0x80
        iExtension              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x000a  1x 10 bytes
        bInterval               5
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      VideoStreaming Interface Descriptor:
        bLength                            14
        bDescriptorType                    36
        bDescriptorSubtype                  1 (INPUT_HEADER)
        bNumFormats                         1
        wTotalLength                      115
        bEndPointAddress                  130
        bmInfo                              0
        bTerminalLink                       3
        bStillCaptureMethod                 1
        bTriggerSupport                     1
        bTriggerUsage                       1
        bControlSize                        1
        bmaControls( 0)                    27
      VideoStreaming Interface Descriptor:
        bLength                            27
        bDescriptorType                    36
        bDescriptorSubtype                  4 (FORMAT_UNCOMPRESSED)
        bFormatIndex                        1
        bNumFrameDescriptors                2
        guidFormat                            {59555932-0000-1000-8000-00aa00389b71}
        bBitsPerPixel                      16
        bDefaultFrameIndex                  1
        bAspectRatioX                       0
        bAspectRatioY                       0
        bmInterlaceFlags                 0x00
          Interlaced stream or variable: No
          Fields per frame: 1 fields
          Field 1 first: No
          Field pattern: Field 1 only
          bCopyProtect                      0
      VideoStreaming Interface Descriptor:
        bLength                            34
        bDescriptorType                    36
        bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
        bFrameIndex                         1
        bmCapabilities                   0x01
          Still image supported
        wWidth                            320
        wHeight                           240
        dwMinBitRate                   768000
        dwMaxBitRate                196608000
        dwMaxVideoFrameBufferSize      153600
        dwDefaultFrameInterval        2000000
        bFrameIntervalType                  2
        dwFrameInterval( 0)           2000000
        dwFrameInterval( 1)           4000000
      VideoStreaming Interface Descriptor:
        bLength                            34
        bDescriptorType                    36
        bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
        bFrameIndex                         2
        bmCapabilities                   0x01
          Still image supported
        wWidth                            160
        wHeight                           120
        dwMinBitRate                   768000
        dwMaxBitRate                196608000
        dwMaxVideoFrameBufferSize       38400
        dwDefaultFrameInterval        1000000
        bFrameIntervalType                  2
        dwFrameInterval( 0)           1000000
        dwFrameInterval( 1)           2000000
      VideoStreaming Interface Descriptor:
        bLength                             6
        bDescriptorType                    36
        bDescriptorSubtype                 13 (COLORFORMAT)
        bColorPrimaries                     1 (BT.709,sRGB)
        bTransferCharacteristics            1 (BT.709)
        bMatrixCoefficients                 4 (SMPTE 170M (BT.601))
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       1
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x0080  1x 128 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       2
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x0100  1x 256 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       3
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x0180  1x 384 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       4
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       5
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x0300  1x 768 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       6
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x0380  1x 896 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       7
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x03fe  1x 1022 bytes
        bInterval               1
Device Qualifier (for other device speed):
  bLength                10
  bDescriptorType         6
  bcdUSB               2.00
  bDeviceClass          239 Miscellaneous Device
  bDeviceSubClass         2 ?
  bDeviceProtocol         1 Interface Association
  bMaxPacketSize0        64
  bNumConfigurations      1
Device Status:     0x0000
  (Bus Powered)

Если к плате камера не подключена, то при подсоединении сообщения отсутствуют.
Спасибо сказали:
watashiwa_daredeska
Бывший модератор
Сообщения: 4038
Статус: Искусственный интеллект (pre-alpha)
ОС: Debian GNU/Linux

Re: Решено: Сеть через USB

Сообщение watashiwa_daredeska »

IMB писал(а):
11.05.2012 20:09
Когда к плате подключена USB-камера:

Код: Выделить всё

    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      1 Video Control
      bInterfaceProtocol      0
      iInterface              2 Venus USB2.0 Camera
...
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
А с чего Вы вообще взяли, что оно может работать как USB-сетевуха? Для примера, вот так выглядит часть описания Samsung Nexus S в режиме эмуляции USB-сетевухи:

Код: Выделить всё

    Interface Association:
      bLength                 8
      bDescriptorType        11
      bFirstInterface         0
      bInterfaceCount         2
      bFunctionClass        224 Wireless
      bFunctionSubClass       1 Radio Frequency
      bFunctionProtocol       3 RNDIS
      iFunction               3 Nexus
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass       224 Wireless
      bInterfaceSubClass      1 Radio Frequency
      bInterfaceProtocol      3 RNDIS
      iInterface              1 RNDIS Communications Control
Спасибо сказали:
Аватара пользователя
Aviator
Сообщения: 65
ОС: Debian GNU/Linux amd64

Re: Решено: Сеть через USB

Сообщение Aviator »

Конфиг ядра, которое запускается на плате покажите, пожалуйста. Дело в том, что хостом у вас является "большой брат" с Debian. Сама же плата должна выдавать себя за клиента. Обязательно должна быть отключена подача питания на разъём USB, на этой плате, Для того, чтобы перевести USB-порт на плате в режим клиента, надо в ядре включить поддержку USB-гаджетов (CONFIG_USB_GADGET) и далее включить ethernet-гаджет (CONFIG_USB_ETH, CONFIG_USB_ETH_EEM), а RNDIS (CONFIG_USB_ETH_RNDIS) я отключал, в случае с линуксами она не нужна.
Это можно как сразу включать в ядро, так и компилировать модулями, при подгрузке которых USB-порт будет переключаться в режим гаджета.
Вот в этом случае и появятся сетевые интерфейсы usb0 на обоих концах, которые конфигурируются уже стандартными средствами.
С уважением, Сергей.
Спасибо сказали:
IMB
Сообщения: 2567
ОС: Debian

Re: Решено: Сеть через USB

Сообщение IMB »

Вот с платой, сейчас использую FreeScale iMX53 QSB, как раз проблем и нет. На ней после загрузке модуля g_ether появился интерфейс usb0 и я его могу конфигурировать. Подключение платы с PC буду осуществлять через USB-OTG платы.
Проблема на "большом брате", сейчас попробую скомпилировать для него тоже g_ether.
Спасибо сказали:
IMB
Сообщения: 2567
ОС: Debian

Re: Решено: Сеть через USB

Сообщение IMB »

watashiwa_daredeska писал(а):
11.05.2012 22:26
А с чего Вы вообще взяли, что оно может работать как USB-сетевуха? Для примера, вот так выглядит часть описания Samsung Nexus S в режиме эмуляции USB-сетевухи:

Не затруднит ли Вас уточнить один момент - используется обычный кабель или с устройством шёл некий специализированный?
Спасибо сказали:
watashiwa_daredeska
Бывший модератор
Сообщения: 4038
Статус: Искусственный интеллект (pre-alpha)
ОС: Debian GNU/Linux

Re: Решено: Сеть через USB

Сообщение watashiwa_daredeska »

IMB писал(а):
12.05.2012 09:52
используется обычный кабель или с устройством шёл некий специализированный?
Обычный.
Спасибо сказали:
IMB
Сообщения: 2567
ОС: Debian

Re: Решено: Сеть через USB

Сообщение IMB »

Всё, заработало, спасибо всем!
Оказался важен порядок работы, заработало при такой последовательности:
1. соединить компьютеры кабелем
2, на плате загрузить модуль g_ether.ko, должен появится интерфейс usb0
3. после этого на host появился интерфейс usb0
4. конфигурируем интерфейсы и работаем

Если кому интересно, то вот небольшое тестирование пропускной способности:
плата

Код: Выделить всё

3: usb0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP q0
    link/ether be:74:4b:3b:c2:b8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.250.2/24 brd 192.168.250.255 scope global usb0

PC

Код: Выделить всё

4: usb0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 26:2e:35:10:9e:2b brd ff:ff:ff:ff:ff:ff
    inet 192.168.250.1/24 brd 192.168.250.255 scope global usb0
    inet6 fe80::242e:35ff:fe10:9e2b/64 scope link
       valid_lft forever preferred_lft forever

PC

Код: Выделить всё

$ iperf -s
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[  4] local 192.168.250.1 port 5001 connected with 192.168.250.2 port 54180
[ ID] Interval       Transfer     Bandwidth
[  4]  0.0-10.1 sec    139 MBytes    116 Mbits/sec

$ iperf -c 192.168.250.2
------------------------------------------------------------
Client connecting to 192.168.250.2, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[  3] local 192.168.250.1 port 45452 connected with 192.168.250.2 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec    153 MBytes    128 Mbits/sec

плата

Код: Выделить всё

$ iperf -c 192.168.250.1
------------------------------------------------------------
Client connecting to 192.168.250.1, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[  3] local 192.168.250.2 port 54180 connected with 192.168.250.1 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec   139 MBytes   116 Mbits/sec

$ iperf -s
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[  4] local 192.168.250.2 port 5001 connected with 192.168.250.1 port 45452
[ ID] Interval       Transfer     Bandwidth
[  4]  0.0-10.1 sec   153 MBytes   128 Mbits/sec
Спасибо сказали:
Аватара пользователя
Aviator
Сообщения: 65
ОС: Debian GNU/Linux amd64

Re: Решено: Сеть через USB

Сообщение Aviator »

У меня с AT91SAM9G45 выходило около 160 мбит/с...
С уважением, Сергей.
Спасибо сказали: