Ubuntu 16.04 Server 安装 TL-WN821N 无线网卡驱动 作者: 萧禹 时间: 2016-10-10 分类: Ubuntu 访问: 1,950 次 最近搞个了 Mini 服务器, 安装了 Ubuntu, 手上有一块 TL-WN821N 无线网卡可以使用, 但官方提供的驱动不支持当前安装的 Ubuntu 版本, 所以产生了自编译驱动的想法. 系统版本: Ubuntu 16.04.1 LTS Server amd64 内核版本: 4.4.0-31-generic gcc 版本: 5.4.0 20160609 make 版本: GNU Make 4.1 硬件版本: V5 英文官网驱动及源码下载: [点击](http://www.tp-link.com/en/download/TL-WN821N.html#Driver)   > 上图红框中标注的是压缩包中源码基于内核版本编写的, 如使用不同内核将产生一些错误. ## 编译并安装驱动 **注意:** > 如果采用 UEFI Secure Boot 启动, 且内核有并开启了模块签名检测, 就要对 8192eu.ko 签名, 详情看 [参考1].  > 目录结构 清理目录 `$sudo make clean` 生成模块 `$sudo make` 生成密钥 `$openssl req -new -x509 -newkey rsa:2048 -keyout 8192eu.priv -outform DER -out 8192eu.der -nodes -days 36500 -subj "/CN=Descriptive name/"` 安装证书 `$sudo mokutil --import 8192eu.der` 重启系统: 开机导入证书, 详情看 [参考2]. 签名模块: `$sudo /usr/src/linux-headers-$(uname -r)/scripts/sign-file sha256 ./8192eu.priv ./8192eu.der ./8192eu.ko` 安装模块: `$make install` 载入模块: `$modprobe 8192eu` 未签名又开启检测则报错: > modprobe: ERROR: could not insert '8192eu': Required key not available 完成!  ## 编译中的错误处理 /mnt/usb/Driver/include/rtw_debug.h:242:7: note: in expansion of macro ‘_seqdump’ if(_seqdump(sel, fmt, ##arg)) /*rtw_warn_on(1)*/; \ ^ /mnt/usb/Driver/core/rtw_cmd.c:3308:3: note: in expansion of macro ‘DBG_871X_SEL_NL’ DBG_871X_SEL_NL(sel, "retry_cnt:%u\n", info->retry_cnt); ^ /mnt/usb/Driver/include/rtw_debug.h:187:19: error: void value not ignored as it ought to be #define _seqdump seq_printf ^ /mnt/usb/Driver/include/rtw_debug.h:242:7: note: in expansion of macro ‘_seqdump’ if(_seqdump(sel, fmt, ##arg)) /*rtw_warn_on(1)*/; \ ^ /mnt/usb/Driver/core/rtw_cmd.c:3311:3: note: in expansion of macro ‘DBG_871X_SEL_NL’ DBG_871X_SEL_NL(sel, "rssi:%u\n", info->rssi); ^ /mnt/usb/Driver/include/rtw_debug.h:187:19: error: void value not ignored as it ought to be #define _seqdump seq_printf ^ /mnt/usb/Driver/include/rtw_debug.h:242:7: note: in expansion of macro ‘_seqdump’ if(_seqdump(sel, fmt, ##arg)) /*rtw_warn_on(1)*/; \ ^ /mnt/usb/Driver/core/rtw_cmd.c:3314:3: note: in expansion of macro ‘DBG_871X_SEL_NL’ DBG_871X_SEL_NL(sel, "byte5:%s%s\n" ^ scripts/Makefile.build:258: recipe for target '/mnt/usb/Driver/core/rtw_cmd.o' failed make[2]: *** [/mnt/usb/Driver/core/rtw_cmd.o] Error 1 Makefile:1403: recipe for target '_module_/mnt/usb/Driver' failed make[1]: *** [_module_/mnt/usb/Driver] Error 2 make[1]: Leaving directory '/usr/src/linux-headers-4.4.0-31-generic' Makefile:1696: recipe for target 'modules' failed make: *** [modules] Error 2 sxsfeq@ubuntu-J1900:/mnt/usb/Driver$ clear sxsfeq@ubuntu-J1900:/mnt/usb/Driver$ make "******************************************" "NO SKRC,we will use default KSRC" "******************************************" make ARCH=x86_64 CROSS_COMPILE= -C /lib/modules/4.4.0-31-generic/build M=/mnt/usb/Driver modules make[1]: Entering directory '/usr/src/linux-headers-4.4.0-31-generic' "******************************************" "NO SKRC,we will use default KSRC" "******************************************" CC [M] /mnt/usb/Driver/core/rtw_cmd.o In file included from /mnt/usb/Driver/include/drv_types.h:95:0, from /mnt/usb/Driver/core/rtw_cmd.c:22: /mnt/usb/Driver/include/hal_com.h:413:13: error: ‘file_path’ redeclared as different kind of symbol extern char file_path[PATH_LENGTH_MAX]; ^ In file included from include/linux/compat.h:15:0, from include/linux/ethtool.h:15, from include/linux/netdevice.h:42, from /mnt/usb/Driver/include/osdep_service_linux.h:35, from /mnt/usb/Driver/include/osdep_service.h:41, from /mnt/usb/Driver/include/drv_types.h:32, from /mnt/usb/Driver/core/rtw_cmd.c:22: include/linux/fs.h:2572:14: note: previous declaration of ‘file_path’ was here extern char *file_path(struct file *, char *, int); ^ In file included from /mnt/usb/Driver/include/drv_types.h:65:0, from /mnt/usb/Driver/core/rtw_cmd.c:22: /mnt/usb/Driver/core/rtw_cmd.c: In function ‘btinfo_evt_dump’: /mnt/usb/Driver/include/rtw_debug.h:187:19: error: void value not ignored as it ought to be #define _seqdump seq_printf ^ /mnt/usb/Driver/include/rtw_debug.h:242:7: note: in expansion of macro ‘_seqdump’ if(_seqdump(sel, fmt, ##arg)) /*rtw_warn_on(1)*/; \ ^ /mnt/usb/Driver/core/rtw_cmd.c:3293:2: note: in expansion of macro ‘DBG_871X_SEL_NL’ DBG_871X_SEL_NL(sel, "cid:0x%02x, len:%u\n", info->cid, info->len); ^ /mnt/usb/Driver/include/rtw_debug.h:187:19: error: void value not ignored as it ought to be #define _seqdump seq_printf ^ /mnt/usb/Driver/include/rtw_debug.h:242:7: note: in expansion of macro ‘_seqdump’ if(_seqdump(sel, fmt, ##arg)) /*rtw_warn_on(1)*/; \ ^ /mnt/usb/Driver/core/rtw_cmd.c:3296:3: note: in expansion of macro ‘DBG_871X_SEL_NL’ DBG_871X_SEL_NL(sel, "byte2:%s%s%s%s%s%s%s%s\n" ^ /mnt/usb/Driver/include/rtw_debug.h:187:19: error: void value not ignored as it ought to be #define _seqdump seq_printf ^ /mnt/usb/Driver/include/rtw_debug.h:242:7: note: in expansion of macro ‘_seqdump’ if(_seqdump(sel, fmt, ##arg)) /*rtw_warn_on(1)*/; \ ^ /mnt/usb/Driver/core/rtw_cmd.c:3308:3: note: in expansion of macro ‘DBG_871X_SEL_NL’ DBG_871X_SEL_NL(sel, "retry_cnt:%u\n", info->retry_cnt); ^ /mnt/usb/Driver/include/rtw_debug.h:187:19: error: void value not ignored as it ought to be #define _seqdump seq_printf ^ /mnt/usb/Driver/include/rtw_debug.h:242:7: note: in expansion of macro ‘_seqdump’ if(_seqdump(sel, fmt, ##arg)) /*rtw_warn_on(1)*/; \ ^ /mnt/usb/Driver/core/rtw_cmd.c:3311:3: note: in expansion of macro ‘DBG_871X_SEL_NL’ DBG_871X_SEL_NL(sel, "rssi:%u\n", info->rssi); ^ /mnt/usb/Driver/include/rtw_debug.h:187:19: error: void value not ignored as it ought to be #define _seqdump seq_printf ^ /mnt/usb/Driver/include/rtw_debug.h:242:7: note: in expansion of macro ‘_seqdump’ if(_seqdump(sel, fmt, ##arg)) /*rtw_warn_on(1)*/; \ ^ /mnt/usb/Driver/core/rtw_cmd.c:3314:3: note: in expansion of macro ‘DBG_871X_SEL_NL’ DBG_871X_SEL_NL(sel, "byte5:%s%s\n" ^ scripts/Makefile.build:258: recipe for target '/mnt/usb/Driver/core/rtw_cmd.o' failed make[2]: *** [/mnt/usb/Driver/core/rtw_cmd.o] Error 1 Makefile:1403: recipe for target '_module_/mnt/usb/Driver' failed make[1]: *** [_module_/mnt/usb/Driver] Error 2 make[1]: Leaving directory '/usr/src/linux-headers-4.4.0-31-generic' Makefile:1696: recipe for target 'modules' failed make: *** [modules] Error 2 以上错误的解决方法: seq_printf ->不在具有返回值所以调用以获取返回值来判断的地方错了, 例: "if(seq_printf(...));" 相当于 "if (void);", 修改源码中 if 的判断. DBG_871X_SEL_NL -> 都是由于 seq_printf 引发的错误. "Driver/include/hal_com.h->file_path" 与 "include/linux/fs.h->file_path" -> 重名了, 重名名 file_path_own 并重命名调用它的所有源码. macro "__DATE__" might prevent reproducible builds [-Werror=date-time] -> 在 gcc 4.9 后出现, 修改为 "null" 带双引号去掉对宏的引用. /Driver/os_dep/linux/ioctl_cfg80211.c:919:4: error: too few arguments to function ‘cfg80211_disconnected’-> 源码与内核源码不匹配,配参数少了, 在第1个参数后加 "NULL, ". /Driver/os_dep/linux/rtw_cfgvendor.c:143:2: error: too few arguments to function ‘cfg80211_vendor_event_alloc' -> 内核与内核源码不匹配, 参数少了, 在第1个参数后加 "NULL, " ## 开机自动连接 WiFi 编辑 `sudo nano /etc/network/interfaces` # TL-WN821N auto wlx3c46d8e08c1b #ifconfig 中的名字 allow-hotplug wlan0 iface wlx3c46d8e08c1b inet static #address 192.168.3.123 address 192.168.2.123 netmask 255.255.255.0 #geteway 192.168.3.1 geteway 192.168.2.1 pre-up wpa_supplicant -B -i wlx3c46d8e08c1b -c /etc/wpa_supplicant/wpa_supplicant.conf ### 参考 1 [Why do I get “Required key not available” when install 3rd party kernel modules or after a kernel upgrade?](http://askubuntu.com/questions/762254/why-do-i-get-required-key-not-available-when-install-3rd-party-kernel-modules) 2 [Systemtap UEFI Secure Boot Support](https://sourceware.org/systemtap/wiki/SecureBoot) 3 [linux内核模块签名 - Always look out for number one.](http://blog.csdn.net/liumangxiong/article/details/18730111) 4 [android 安装内核module,提示Required key not available](http://blog.csdn.net/lewif/article/details/49305385) 5 [uefi - Why do I get "Required key not available" when install 3rd party kernel modules or after a kernel upgrade? - Ask Ubuntu](http://askubuntu.com/questions/762254/why-do-i-get-required-key-not-available-when-install-3rd-party-kernel-modules) 5 [SecureBoot - 维基的SystemTap](https://sourceware.org/systemtap/wiki/SecureBoot) 7 [UEFI/SecureBoot](https://wiki.ubuntu.com/UEFI/SecureBoot) 标签: Ubuntu tl-wn821n 文章版权:萧禹的博客 - 这个人很懒, 什么都没写 本文链接:https://www.flysfeq.site/index.php/archives/19/ 转载请注明文章原始出处 !