Inter Edsion添加USB有线网卡解决办法

虽然都知道Inter Edison有一个无线WiFi,但是如果想像树莓派那样使用有线网卡怎么办呢(比如建一个ap热点或者需要桥接网络)。因为Edison没有有线网卡,所以只有添加一个USB网卡咯。

当然,现在的USB网卡还没有驱动,你可以在inter Edison的交叉编译环境(http://www.arduino.cn/thread-10595-1-1.html)中定制ipk包或者固件给Edison添加驱动(http://www.arduino.cn/thread-17006-1-2.html),在指向的帖子里设置你的网卡驱动,装上去就好了。

如果你根据上述操作,现在应该有了网卡驱动,然后还要dhcp工具,如果要开热点,就还需要hostapd和网络桥接工具batctl(大致就是开一个端口,用端口转发数据包)。这个软件你可以在刷固件的时候添加到固件里面;也可以制作ipk包给Edison安装;还可以给Edison安装kernel header(编译安装各种驱动程序必须依赖kernel-dev_3.10.17-r0_edison.ipk),然后安装依赖batman-adv库,最后编译安装batctl(需要下载安装,资源自给度娘一下吧微笑)。

下面做一下搬砖的搬工(inter Edison 官网),讲一下怎么定制batctl的ipk包(其实我也不会,看了才会的微笑)。这里我假设你是有Edison的交叉编译环境的,我将要在交叉编译环境里定制ipk,如果没有交叉编译环境就在上面的链接里按教程做一个。

先进入交叉编译环境cd edison-src,如果没有初始化就弄一下,老手无视。

device-software/setup.sh
source poky/oe-init-build-env

进入工作目录

   cd ./ edison-src/bulid/

然后配置bitbake的配置文件batctl_2014.4.0.bb

mkdir -p device-software/meta-edison-distro/recipes-support/batman/

cat > device-software/meta-edison-distro/recipes-support/batman/batctl_2014.4.0.bb <<EOF

DESCRIPTION = "Control application for B.A.T.M.A.N. routing protocol kernel module for multi-hop ad-hoc mesh networks."
HOMEPAGE = "http://www.open-mesh.net/"
SECTION = "console/network"
PRIORITY = "optional"

LICENSE = "GPLv2+"
LIC_FILES_CHKSUM = "file://../license-destdir/${PN}/generic_GPLv2;md5=801f80980d171dd6425610833a22dbe6"

RDEPENDS_${PN} = "kernel-module-batman-adv"
DEPENDS = "libnl"


SRC_URI = "http://downloads.open-mesh.net/batman/stable/sources/batctl/batctl-${PV}.tar.gz\
     file://patch.patch"
SRC_URI[md5sum] = "f3a14565699313258ee6ba3de783eb0a"
SRC_URI[sha256sum] = "77509ed70232ebc0b73e2fa9471ae13b12d6547d167dda0a82f7a7fad7252c36"

EXTRA_OEMAKE = 'STAGING_INC="${STAGING_INC}"'

do_compile() {
  oe_runmake
}

do_install() {
  install -d ${D}${bindir}
  install -m 0755 batctl ${D}${bindir}
}
EOF



然后上面的包的版本下载好像有问题,如果出错,大家可以将版本号改一下,设置成绝对路径,当然md5校验和sha256校验都要改的,当然你也可以删掉,上面的LICENSE当然也可以CLOSE掉的

然后设置路径

mkdir -p device-software/meta-edison-distro/recipes-support/batman/files
cat > device-software/meta-edison-distro/recipes-support/batman/files/patch.patch <<EOF

--- a/Makefile  2015-02-27 09:10:45.768409932 +0100
+++ b/Makefile  2015-02-27 09:11:32.710554513 +0100
@@ -29,7 +29,7 @@
MANPAGE = man/batctl.8

 # batctl flags and options
-CFLAGS += -Wall -W -std=gnu99 -fno-strict-aliasing -MD -MP
+CFLAGS += -Wall -W -std=gnu99 -fno-strict-aliasing -MD -MP –I${STAGING_INC}/libnl3
CPPFLAGS += -D_GNU_SOURCE
LDLIBS += -lm
EOF


然后btibake

bitbake batctl

然后你就可以在 build/tmp/deploy/ipk/core2-32/batctl_2014.4.0-r0_core2-32.ipk.(路径和你版本号有关)找到定制好的ipk包了。然后在你的Edison中opkg install就可以安装了。

插入过后载入模块,没有就装一个

root@edison:~/  modprobe batman-adv

查看模块信息:

modinfo batman-adv

01 root@edison:~/ # batctl if add enp0s17u1
02 root@edison:~/ # batctl if
03 enp0s17u1: active

查看网卡

:~# ifconfig -a
enp0s17u1 Link encap:Ethernet  HWaddr 00:e0:4c:36:44:37
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

好啦,现在你已经看到网卡了,如果网卡像下面这样没启动的话

~# ifconfig
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

usb0      Link encap:Ethernet  HWaddr 02:00:86:a4:97:0d
          inet addr:192.168.2.15  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

那就启动对应的网卡

~# ifconfig enp0s17u1 up

然后准备为网卡启动udhcp服务

找到对应的服务文件

 find / -name *udhcp*
/var/lib/opkg/info/busybox-udhcpc.control
/var/lib/opkg/info/busybox-udhcpc.list
/etc/systemd/system/busybox-udhcpc.service
/etc/hostapd/udhcpd-for-hostapd.conf
/etc/hostapd/udhcpd-for-hostapd-eth0.conf
/etc/udhcpc.d
/etc/wpa_supplicant/udhcpd-p2p.conf
/sbin/udhcpc
/usr/share/udhcpc
/usr/share/common-licenses/busybox-udhcpc
/usr/sbin/udhcpd
/usr/lib/opkg/alternatives/udhcpc
/usr/lib/opkg/alternatives/udhcpd

然后打开/lib/下udhcp为hostapd开启的服务文件

vi /lib/systemd/system/udhcpd-for-hostapd.service

[Unit]
Description=udhcpd daemon for hostapd
Requires=hostapd.service
After=hostapd.service
StopWhenUnneeded=true

[Service]
Type=simple
ExecStartPre=/sbin/ifconfig wlp0s17u1 192.168.42.1 up
ExecStart=/usr/sbin/udhcpd -f -S /etc/hostapd/udhcpd-for-hostapd.conf
Restart=on-failure
RestartSec=1

[Install]
WantedBy=multi-user.target

再根据里面的内容将wifi设备换成有线设备名称,然后更换ip地址池,然后更改/etc/hostapd/udhcpd-for-hostapd.conf,改为/etc/hostapd/udhcpd-for-hostapd-eth0.conf

,保存新文件Ufilename

然后写/etc/hostapd/udhcpd-for-hostapd-eth0.conf文件

[Unit]
Description=udhcpd daemon for hostapd
Requires=hostapd.service
After=hostapd.service
StopWhenUnneeded=true

[Service]
Type=simple
ExecStartPre=/sbin/ifconfig enp0s17u1 192.168.43.1 up
ExecStart=/usr/sbin/udhcpd -f -S /etc/hostapd/udhcpd-for-hostapd.conf
Restart=on-failure
RestartSec=1

[Install]
WantedBy=multi-user.target

里面的具体参数根据自己设定设置,保存/etc/hostapd/udhcpd-for-hostapd-eth0.conf

然后udhcpc -i enp0s17u1 -S启动udhcpc服务

~# udhcpc -i enp0s17u1 -S
udhcpc (v1.22.1) started
Sending discover...
Sending select for 192.168.0.190...
Lease of 192.168.0.190 obtained, lease time 3600
/etc/udhcpc.d/50default: Adding DNS 192.168.0.1
/etc/udhcpc.d/50default: Adding DNS 192.168.1.1
这里udhcpc已经启动了,你已经可以通过有线网卡上网了。

然后开始桥接网络,建立ap

先找到hostapd的配置文件hostapd.conf

find / -name hostapd.conf

获取到路径之后,就直接打开,更改里面的配置文件

interface=wlan0               #分享wifi的无线网卡
bridge=br0  
driver=nl80211              #网卡驱动
ssid=xiao106347              #热点ssid
hw_mode=g  
channel=1
dtim_period=1  
rts_threshold=2347  
fragm_threshold=2346  
auth_algs=3  
wpa=1           #加密类型wpa2
wpa_passphrase=12345678                #热点密钥
wpa_key_mgmt=WPA-PSK  
wpa_pairwise=TKIP CCMP  
rsn_pairwise=CCMP 
里面的东西很多,但是大概更改这些配置就ok了,其他默认的就好了。


然后添加网桥

brctl adbr br0  
然后添加网卡设备
<pre name="code" class="ruby">brctl addif br0 eth0
brctl addif br0 wlan0 
#brctl addif br0 wlan0时出现错误:can't add wlan0 to bridge br0: Operation not supported,运行 iw dev wlan0 set 4addr on(<pre name="code" class="ruby">这里还要装iw管理工具,我觉得应该可以用其他工具代替,但是<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;">这个</span><span style="font-size: 12px; font-family: Arial, Helvetica, sans-serif;">4addr我查了半天只知道大致是个框架,到底是什么东西我也不知道,所以不知道用什么工具代替这条命令,望知道的告知一下,谢谢</span><span style="font-size: 12px; font-family: Arial, Helvetica, sans-serif;">)</span>

 
 
ifconfig br0 192.168.2.236 netmask 255.255.255.0 #网桥在同一个逻辑网段转发数据包,所以建立一个和网络同一个网段的IP,但这是为了方便管理,其实也可以不要这些东西,网桥还是能正常工作
route add default gw 192.168.2.254

然后启动网桥

ifconfig br0 up


然后开启热点

hostapd /file/hostapd.conf #路径就是刚刚搜索出来的路径

然后就ok了











  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值