无线AP(openwrt系统)中实现netlink双向通信
最近在做一个关于车联网项目,需要用户态和内核态进行通信,于是在网上搜索相关资料,但网上大都是讲解如何实现netlink以及netlink原理,并未涉及如何在openwrt系统中添加netlink模块。故在这里讲解如何在openwrt系统中添加netlink模块。
内核态代码
**1、**初始化netlink
首先需要编译好openwrt系统(至于如何编译可参考网上资料,这里不再赘述),
进入上图所示目录,找到init.c文件,在int __init ath9k_init函数添加下面注释代码
static int __init ath9k_init(void)
{
int error;
error = ath_ahb_init();
if (error < 0) {
error = -ENODEV;
goto err_out;
}
error = ath_pci_init();
if (error < 0) {
pr_err("No PCI devices found, driver not installed\n");
error = -ENODEV;
goto err_ahb_exit;
}
//jeff-2019.5.9
netlink_init();
//end
return 0;
err_ahb_exit:
ath_ahb_exit();
err_out:
return error;
}
module_init(ath9k_init);
在ath9k_exit函数中添加下面注释代码块
static void __exit ath9k_exit(void)
{
is_ath9k_unloaded = true;
//jeff-2019.5.9
netlink_exit();
//end
ath_ahb_exit();
ath_pci_exit();
pr_info("%s: Driver unloaded\n", dev_info);
}
module_exit(ath9k_exit);
在ath9k.h文件中添加下面注释代码
static inline int ath_ahb_init(void) { return 0; };
static inline void ath_ahb_exit(void) {};
#endif
//jeff-2019.5.9
int netlink_init(void);
int stringlength(char *s);
void send_netlink_data(char *message);
void recv_netlink_data(struct sk_buff *__skb);
void netlink_exit(void);
//end
#endif /* ATH9K_H */
2、添加netlink收发模块
在上面目录中,找到main.c文件,添加下面头文件
//jeff-2019.5.9
#include &l