OpenWrt支持usb tethering

OpenWrt支持usb tethering

一、概述

OpenWrt支持usb tethering的应用场景主要是,手机打开usb网络共享(Android)或个人热点(iOS),经过USB的连接,使OpenWrt能够通过手机上网。

二、依赖的package

make menuconfig,选择以下package

Kernel modules  --->
    USB Support  --->
        <*> kmod-usb-net............... Kernel modules for USB-to-Ethernet convertors
        <*> kmod-usb-ohci............................... Support for OHCI controllers
        <*> kmod-usb-uhci............................... Support for UHCI controllers
        <*> kmod-usb2................................... Support for USB2 controllers

Utilities  --->
    <*> libimobiledevice-utils............ A library that talks to Apple devices.
    <*> libplist-utils............................. Apple property list converter
    <*> libusbmuxd-utils......................... USB multiplexing daemon utilies
    <*> usbmuxd.......................................... USB multiplexing daemon

三、相关配置

1. Android

Android Phone一般在“更多无线连接”的选项中,会有“USB共享网络”的设置,将手机通过USB线插到OpenWrt上,在OpenWrt中,cat /proc/net/dev查看新增加的网络设备,Android一般是usb0

=================================USB插入前=================================
root@OpenWrt:/# cat /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
  ifb0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
 ath01: 1764811   12421    0    0    0     0          0         0        0       0    0    9    0     0       0          0
 wifi0:       0 3866050    0    0    0     0          0         0        0 1365801    0    0    0     0       0          0
    lo:    1623      16    0    0    0     0          0         0     1623      16    0    0    0     0       0          0
  eth1:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
  eth0: 40394826  370218    0    9    0     0          0         0   270259    2553    0    0    0     0       0          0
  ifb1:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
  ath0:       0       0    0    0    0     0          0         0        0       0    0  517    0     0       0          0
br-lan:       0       0    0    0    0     0          0         0    26272     514    0    0    0     0       0          0
 bond0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
root@OpenWrt:/# 
root@OpenWrt:/# 
root@OpenWrt:/# 
=================================USB插入后=================================
root@OpenWrt:/# cat /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
  ifb0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
 ath01: 1783886   12477    0    0    0     0          0         0        0       0    0    9    0     0       0          0
 wifi0:       0 3870560    0    0    0     0          0         0        0 1368549    0    0    0     0       0          0
    lo:    1623      16    0    0    0     0          0         0     1623      16    0    0    0     0       0          0
  usb0:    1322      12    0    0    0     0          0         0     1730       8    0    0    0     0       0          0
  eth1:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
  eth0: 40487860  370954    0    9    0     0          0         0   272917    2564    0    0    0     0       0          0
  ifb1:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
  ath0:       0       0    0    0    0     0          0         0        0       0    0  518    0     0       0          0
br-lan:       0       0    0    0    0     0          0         0    26322     515    0    0    0     0       0          0
 bond0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0

在USB共享网络的情况下,OpenWrt应当使用usb0作为WAN,并通过手机访问网络,这里只共享/etc/config/network的配置,其他如firewall等配置根据自己需要进行修改。
增加下面这一段:

config interface 'usb0'
    option ifname 'usb0'
    option proto 'dhcp'

执行ubus call network reload后,就可以通过ifconfig查看新生成的usb0网卡,并且会有IP,这个IP是Android phone通过dhcp分配的,一般为192.168.42.XXX(网关IP一般为192.168.42.129,可以通过查看Android源码,发现是硬编码写进去的)。

2. iOS

1)首先确认内核ipheth.c中,有能够支持iOS设备的product id。
2)iPhone的USB tethering需要usbmuxd进程的运行。usbmuxd并不会自动运行,因此可以在OpenWrt终端手动启动,或制作以下开机自启动脚本,并enable(/etc/init.d/usbmuxd enable):

root@OpenWrt:/# cat /etc/init.d/usbmuxd 
#!/bin/sh /etc/rc.common
# Copyright (c) 2011-2012 OpenWrt.org
START=99

stop() {
    killall usbmuxd
}

start() {
    if [ ! -d "/var/lib/lockdown" ];then
        mkdir -p /var/lib/lockdown
    fi

    ./usr/sbin/usbmuxd &
}

在usbmuxd进程启动的前提下,iPhone在“设置”->“个人热点”,打开后,通过USB连接OpenWrt。
同样,通过cat /proc/net/dev查看新增加的网络设备,iOS一般是eth2
/etc/config/network中增加下面一段,其他firewall的配置根据自己需要进行修改。

config interface 'eth2'
    option ifname 'eth2'
    option proto 'dhcp'

执行ubus call network reload后,就可以通过ifconfig查看新生成的eth2网卡,并且会有IP,一般为172.20.10.XXX(网关IP为172.20.10.1)。
3)问题
如果在插入iPhone时,内核ipheth没有出现“Apple iPhone USB Ethernet device attached”的debug信息,原因一般是内核ipheth不支持手里的iOS设备。

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值