android_kernel_oneplus_msm8998/drivers/input/fingerprint/goodix/netlink.c
liochen 8148b9d900 Synchronize codes for OnePlus5 & 5T OxygenOS 9.0.0
kernel device tree source code for OnePlus 5 & 5T P device

Change-Id: I84f40e66833ea1ce30eb1d9a710d6e1529e9e637
2018-12-26 11:02:39 +08:00

98 lines
1.7 KiB
C

/*
* netlink interface
*
* Copyright (c) 2017 Goodix
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/timer.h>
#include <linux/time.h>
#include <linux/types.h>
#include <net/sock.h>
#include <net/netlink.h>
#define NETLINK_TEST 25
#define MAX_MSGSIZE 32
static int pid = -1;
struct sock *gf_nl_sk = NULL;
void sendnlmsg(char *message)
{
struct sk_buff *skb_1;
struct nlmsghdr *nlh;
int len = NLMSG_SPACE(MAX_MSGSIZE);
int slen = 0;
int ret = 0;
if (!message || !gf_nl_sk || !pid)
return ;
skb_1 = alloc_skb(len, GFP_KERNEL);
if (!skb_1) {
pr_err("alloc_skb error\n");
return;
}
slen = strlen(message);
nlh = nlmsg_put(skb_1, 0, 0, 0, MAX_MSGSIZE, 0);
NETLINK_CB(skb_1).portid = 0;
NETLINK_CB(skb_1).dst_group = 0;
message[slen] = '\0';
memcpy(NLMSG_DATA(nlh), message, slen+1);
ret = netlink_unicast(gf_nl_sk, skb_1, pid, MSG_DONTWAIT);
if (!ret)
pr_err("send msg failed ret 0x%x\n", ret);
}
void nl_data_ready(struct sk_buff *__skb)
{
struct sk_buff *skb;
struct nlmsghdr *nlh;
char str[100];
skb = skb_get (__skb);
if(skb->len >= NLMSG_SPACE(0))
{
nlh = nlmsg_hdr(skb);
memcpy(str, NLMSG_DATA(nlh), sizeof(str));
pid = nlh->nlmsg_pid;
kfree_skb(skb);
}
}
int netlink_init(void)
{
struct netlink_kernel_cfg netlink_cfg;
memset(&netlink_cfg, 0, sizeof(struct netlink_kernel_cfg));
netlink_cfg.groups = 0;
netlink_cfg.flags = 0;
netlink_cfg.input = nl_data_ready;
netlink_cfg.cb_mutex = NULL;
gf_nl_sk = netlink_kernel_create(&init_net, NETLINK_TEST,
&netlink_cfg);
if(!gf_nl_sk){
pr_err("create netlink socket error\n");
return 1;
}
return 0;
}
void netlink_exit(void)
{
if(gf_nl_sk != NULL){
netlink_kernel_release(gf_nl_sk);
gf_nl_sk = NULL;
}
pr_info("self module exited\n");
}