台式机上弄了个USB无线网卡,无线网卡是EDUP-N1556,也就是RTL8192C的驱动,然后Centos5.5上肯定没有这个,折腾到了凌晨一点才搞定!
原因是iwconfig无法支持wpa,如果无线路由器是wpa加密的,要使用wpa_supplicant工具来生成连接密钥和启动无线网卡。
无线网卡是在京东上买的:http://item.jd.com/844287.html,EDUP-N1556,实际上芯片是RTL8188C_8192C_USB_linux_v4.0.2。
驱动下载:http://www.edup.cn/showinfo559.aspx,linux下需要下载源码编译。
安装kernel
编译驱动时需要kernel的开发包。可以从光盘源安装:
sudo mkdir -p /media/cdrom &&
sudo mount /dev/cdrom /media/cdrom &&
sudo yum --disablerepo=* --enablerepo=c5-media install -y kernel-devel kernel-xen-kernel
安装完成后就可以开始编译驱动。
编译驱动
驱动源码解压后的目录是:RTL8188C_8192C_USB_linux_v4.0.2_9000.20130911
下面有install.sh,可以直接执行:
sudo bash install.sh
没有网络只能通过usb拷贝驱动代码到centos5.5上面,然后编译时报错:
[winlin@localhost RTL8188C_8192C_USB_linux_v4.0.2_9000.20130911]$ sudo bash install.sh
/home/winlin/tools/RTL8188C_8192C_USB_linux_v4.0.2_9000.20130911/driver/rtl8188C_8192C_usb_linux_v4.0.2_9000.20130911/include/osdep_service.h:865: error: redefinition of ‘skb_tail_pointer’
include/linux/skbuff.h:922: error: previous definition of ‘skb_tail_pointer’ was here
一大堆这个错误。查看代码:
vi driver/rtl8188C_8192C_usb_linux_v4.0.2_9000.20130911/include/osdep_service.h
行数是865行:
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22))
// Porting from linux kernel, for compatible with old kernel.
static inline unsigned char *skb_tail_pointer(const struct sk_buff *skb)
{
return skb->tail;
}
static inline void skb_reset_tail_pointer(struct sk_buff *skb)
{
skb->tail = skb->data;
}
static inline void skb_set_tail_pointer(struct sk_buff *skb, const int offset)
{
skb->tail = skb->data + offset;
}
查看centos5.5的内核:
[winlin@localhost RTL8188C_8192C_USB_linux_v4.0.2_9000.20130911]$ uname -r
2.6.18-194.el5xen
也就是说,centos使用的内核很老,但是这些比较新的函数自己合并过去了的,所以只需要把上面的函数注释掉就可以:
#if 0 && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22))
// Porting from linux kernel, for compatible with old kernel.
static inline unsigned char *skb_tail_pointer(const struct sk_buff *skb)
{
return skb->tail;
}
static inline void skb_reset_tail_pointer(struct sk_buff *skb)
{
skb->tail = skb->data;
}
在最前面的宏定义判断那里加上#if 0 &&。然后重新执行sudo bash install.sh,安装成功,内核模块已经安装好了:
[root@localhost RTL8188C_8192C_USB_linux_v4.0.2_9000.20130911]# lsmod|grep 8192cu
8192cu 662208 0
下面就可以编译wpa工具,以及使用ifconfig管理网卡。
IFCONFIG
驱动编译安装好后,就可以用ifconfig打开设备,扫描附近的无线网络了。
如果没有iwlist和iwconfig可以编译:
cd RTL8188C_8192C_USB_linux_v4.0.2_9000.20130911/wireless_tools/wireless_tools.30.rtl && make
首先,看看设备叫什么:
[root@localhost wireless_tools.30.rtl]# ./iwconfig
wlan0 IEEE 802.11bg ESSID:"winlin-1st" Nickname:"<WIFI@REALTEK>"
Mode:Managed Frequency:2.472 GHz Access Point: B0:48:7A:39:5F:F6
Bit Rate:54 Mb/s Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off
Encryption key:****-****-****-****-****-****-****-**** Security mode:open
Power Management:off
Link Quality=99/100 Signal level=51/100 Noise level=0/100
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
上面是已经连接上的无线网卡信息,可见名字叫做wlan0。
然后,用ifconfig打开设备:
[root@localhost wireless_tools.30.rtl]# ifconfig wlan0 up && ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr E8:4E:06:17:5C:8E
inet addr:192.168.1.113 Bcast:255.255.255.255 Mask:255.255.255.0
inet6 addr: fe80::ea4e:6ff:fe17:5c8e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3360 errors:0 dropped:36 overruns:0 frame:0
TX packets:4886 errors:0 dropped:2 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:392496 (383.2 KiB) TX bytes:5934066 (5.6 MiB)
接着,看有哪些无线网络可以连:
[root@localhost wireless_tools.30.rtl]# ./iwlist wlan0 scan
Cell 01 - Address: B0:48:7A:39:5F:F6
ESSID:"winlin-1st"
Protocol:IEEE 802.11bg
Mode:Master
Frequency:2.472 GHz (Channel 13)
Encryption key:on
Bit Rates:54 Mb/s
Extra:wpa_ie=dd160050f20101000050f2041000050f202
IE: WPA Version 1
Group Cipher : CCMP
Pairwise Ciphers (1) : CCMP
Authentication Suites (1) : PSK
Extra:rsn_ie=30140100000fac0401000fac020100
IE: IEEE 802.11i/WPA2 Version 1
Group Cipher : CCMP
Pairwise Ciphers (1) : CCMP
Authentication Suites (1) : PSK
Preauthentication Supported
Quality=99/100 Signal level=51/100
下面就可以用wpa工具连接网络了。 iwconfig无法连接wpa加密的网络。
WPA工具
编译wpa工具:
cd RTL8188C_8192C_USB_linux_v4.0.2_9000.20130911/wpa_supplicant_hostapd &&
tar xf wpa_supplicant_hostapd-0.8_rtw_r7475.20130812.tar.gz &&
cd wpa_supplicant_hostapd-0.8_rtw_r7475.20130812 &&
cd wpa_supplicant/ &&
make
然后使用命令生成配置文件:
./wpa_passphrase winlin-1st 8u23j302j >winlin-1st.conf
其中,winlin-1st是要连接的那个无线网络的ssid,后面的8u23j302j是密码,这个会生成配置文件。
启动和配置无线网卡,连接到winlin-1st网络:
./wpa_supplicant -i wlan0 -c winlin-1st.conf
然后使用dhclient获取IP:
sudo dhclient wlan0
可以写入/etc/rc.local:
# winlin
echo "start wlan0 network"
nohup /home/winlin/tools/wpa/wpa_supplicant -i wlan0 -c /home/winlin/tools/wpa/winlin-1st.conf >/dev/null 2>&1 &
sleep 2 && echo "dhclient wlan0" && dhclient wlan0
echo "ok for winlin"
启动后,等会就发现正常获取了ip。用iwconfig看也连接上了。
ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr E8:4E:06:17:5C:8E
inet addr:192.168.1.113 Bcast:255.255.255.255 Mask:255.255.255.0
inet6 addr: fe80::ea4e:6ff:fe17:5c8e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3914 errors:0 dropped:36 overruns:0 frame:0
TX packets:5309 errors:0 dropped:2 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:461213 (450.4 KiB) TX bytes:6025999 (5.7 MiB)
iwconfig wlan0
wlan0 IEEE 802.11bg ESSID:"winlin-1st" Nickname:"<WIFI@REALTEK>"
Mode:Managed Frequency:2.472 GHz Access Point: B0:48:7A:39:5F:F6
Bit Rate:54 Mb/s Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off
Encryption key:****-****-****-****-****-****-****-**** Security mode:open
Power Management:off
Link Quality=100/100 Signal level=56/100 Noise level=0/100
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
注意一定不能用iwconfig来配置网卡连接wpa网络,连不上的。
使用网络
后面使用网络就简单了:
[root@localhost ~]# curl http://ossrs.net
<!DOCTYPE html>
<html>
<head>
<title>开源的SRS</title>
<meta charset="utf-8">
<script type="text/javascript">
var url = "srs.release/releases/index.html";
setTimeout(function(){
window.location.href = url;
}, 1000);
</script>
</head>
<body>
<div><a href="srs.release/releases/index.html" target="_self">正在跳转中...</a></div>
<div><a href="http://www.miitbeian.gov.cn">京ICP备14026077号</a></div>
</body>
</html>
正常使用就可以了。
Winlin 2014.11