openwrt系统实现netlink双向通信

本文介绍在openwrt系统下,如何在无线AP中添加并实现netlink模块,以实现用户态与内核态的双向通信。包括内核态代码的初始化netlink、添加收发模块,以及用户态代码的编写和编译,最终在AP中成功进行通信的测试结果。
摘要由CSDN通过智能技术生成

无线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
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值