usb虚拟网卡与串口

usb虚拟网卡与串口

依赖的驱动模块

# usb
cp /work/code/kernel_gitee/kernel_imx/fs/configfs/configfs.ko ./fixShell/so/
cp /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/libcomposite.ko ./fixShell/so/

# 网络
cp /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/function/u_ether.ko ./fixShell/so/
cp /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/function/usb_f_rndis.ko ./fixShell/so/
cp /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/function/usb_f_ecm.ko ./fixShell/so/
cp /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/function/usb_f_ncm.ko ./fixShell/so/
cp /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/./legacy/g_ether.ko ./fixShell/so/

# 串口
cp /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/function/u_serial.ko ./fixShell/so/
cp /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/function/usb_f_serial.ko ./fixShell/so/
cp /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/./legacy/g_serial.ko ./fixShell/so/


insmod /work/code/kernel_gitee/kernel_imx/fs/configfs/configfs.ko
insmod /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/libcomposite.ko

insmod /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/function/u_ether.ko 
insmod /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/function/usb_f_rndis.ko 
insmod /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/function/usb_f_ecm.ko 
insmod /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/function/usb_f_ncm.ko 
insmod /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/./legacy/g_ether.ko 


insmod  /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/function/u_serial.ko 
insmod  /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/function/usb_f_serial.ko 
insmod  /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/./legacy/g_serial.ko use_acm=0

虚拟网卡

https://blog.csdn.net/zhenglie110/article/details/80223167

术语

  • RemoteNDIS

编译

    这里使用模块
    Device Drivers —>
        [*] USB support —>
            <*> USB Gadget Support —>
                         Ethernet Gadget (with CDC Ethernet support)
                         [*] RNDIS support

使用

开发板设置

必须确保USB是工作在slave模式的,这个地方6ul的板子控制电平即可

echo 0 > /tmp/gpio/IO_USB0_PWR/value

ifconfig usb0 192.168.77.55 netmask 255.255.255.0
route add default gw 192.168.77.1

HOST设置

# 搜索kindle_rndis.inf_amd64
运行 5-runasadmin_register-CA-cer.cmd
安装 kindle_rndis.inf
设置主机IP

虚拟串口

参考网址

https://developer.ridgerun.com/wiki/index.php/How_to_use_USB_CDC_ACM_and_MS_composite_Linux_gadget_driver

https://blog.csdn.net/hbcbgcx/article/details/88198771
https://blog.csdn.net/yazhouren/article/details/80196344

使用

开发板

# 这里的use_acm=0 表示的就是从设备
insmod  /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/function/u_serial.ko 
insmod  /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/function/usb_f_serial.ko 
insmod  /work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/./legacy/g_serial.ko use_acm=0

host

1. 驱动签名禁止
2. 安装 linux-cdc-acm.inf 修改uid 设备管理器中查看硬件id
3. 串口打开 这里只能在子系统类的unix下使用 win10

错误处理

以下错误可能有两种情况: 1 未设置为从模式 2 不支持同时使用虚拟网卡和虚拟串口

udc-core: couldn't find an available UDC - added [g_serial] to list of pending

调试记录(驱动依赖)

直接安装g_ether,提示找不到符号依赖,搜索 usb_get_function_instance,或者更好的是在ubuntu下使用modinfo,然后使用find -name xxx.ko

insmod  g_ether.ko
g_ether: Unknown symbol usb_get_function_instance (err 0)

vmuser@ubuntu:~/work/code/kernel_gitee/kernel_imx/drivers/usb/gadget$ modinfo ./legacy/g_ether.ko
filename:       /home/vmuser/work/code/kernel_gitee/kernel_imx/drivers/usb/gadget/./legacy/g_ether.ko
license:        GPL
author:         David Brownell, Benedikt Spanger
description:    RNDIS/Ethernet Gadget
srcversion:     5E4C828D24F6E477C9CB5EE
depends:        libcomposit

如下搜索

modinfo drivers/usb/gadget/./legacy/g_ether.ko
find -name "configfs.ko"
find -name "libcomposite.ko"
find -name "u_ether.ko"
find -name "usb_f_rndis.ko"
modinfo ./drivers/usb/gadget/function/usb_f_rndis.ko

完整的依赖如下

[root@EPC-M6Y2C kernel_imx]# lsmod
Module                  Size  Used by    Not tainted
g_ether                 5247  0
usb_f_ecm               6843  1
usb_f_rndis            16183  2 g_ether
u_ether                12156  3 g_ether,usb_f_ecm,usb_f_rndis
libcomposite           44608  3 g_ether,usb_f_ecm,usb_f_rndis
configfs               24103  4 usb_f_ecm,usb_f_rndis,libcomposite


然后依赖查找安装


insmod  ./drivers/usb/gadget/function/u_serial.ko
insmod ./drivers/usb/gadget/function/usb_f_serial.ko
insmod drivers/usb/gadget/./legacy/g_serial.ko


[root@EPC-M6Y2C kernel_imx]# lsmod
Module                  Size  Used by    Not tainted
usb_f_serial            3061  0
u_serial                9720  1 usb_f_serial
g_serial                3693  0
g_ether                 5247  0
usb_f_ecm               6843  1
usb_f_rndis            16183  2 g_ether
u_ether                12156  3 g_ether,usb_f_ecm,usb_f_rndis
libcomposite           44608  5 usb_f_serial,g_serial,g_ether,usb_f_ecm,usb_f_rndis
configfs               24103  5 usb_f_serial,usb_f_ecm,usb_f_rndis,libcomposite



insmod  u_serial.ko
insmod  libcomposite.ko
insmod   usb_f_serial.ko
insmod  usb_f_obex.ko
insmod  usb_f_acm.ko
insmod  g_serial.ko use_acm=0  # 这个是从
posted @ 2021-04-19 13:18  zongzi10010  阅读(2718)  评论(0编辑  收藏  举报