qcacmn: Move Spectral Netlink APIs to os_if layer
Spectral Netlink related APIs are currently present in target_if layer, move them to os_if layer. Change-Id: I86a5495f6ec8aa85a2e9639902503a522b023f8e CRs-Fixed: 2151548
Cette révision appartient à :

révisé par
snandini

Parent
82032dd2a4
révision
101778698b
54
os_if/linux/spectral/inc/os_if_spectral_netlink.h
Fichier normal
54
os_if/linux/spectral/inc/os_if_spectral_netlink.h
Fichier normal
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2017-2018 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for
|
||||
* any purpose with or without fee is hereby granted, provided that the
|
||||
* above copyright notice and this permission notice appear in all
|
||||
* copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
||||
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _OS_IF_SPECTRAL_NETLINK_H
|
||||
#define _OS_IF_SPECTRAL_NETLINK_H
|
||||
|
||||
#include <net/netlink.h>
|
||||
#include <wlan_objmgr_pdev_obj.h>
|
||||
|
||||
/* NETLINK related declarations */
|
||||
#if (KERNEL_VERSION(2, 6, 31) > LINUX_VERSION_CODE)
|
||||
void os_if_spectral_nl_data_ready(struct sock *sk, int len);
|
||||
#else
|
||||
void os_if_spectral_nl_data_ready(struct sk_buff *skb);
|
||||
#endif /* VERSION CHECK */
|
||||
|
||||
#ifndef NETLINK_ATHEROS
|
||||
#define NETLINK_ATHEROS (NETLINK_GENERIC + 1)
|
||||
#endif
|
||||
#define MAX_SPECTRAL_PAYLOAD 1500
|
||||
|
||||
/* Init's network namespace */
|
||||
extern struct net init_net;
|
||||
|
||||
/**
|
||||
* os_if_spectral_netlink_init() - Initialize Spectral Netlink data structures
|
||||
* and register the NL handlers with Spectral target_if
|
||||
* @pdev: Pointer to pdev
|
||||
*
|
||||
* Sending Netlink messages to application layer and de-initialization of
|
||||
* netlink related data structures are defined in os_if layer,
|
||||
* they need to be registered with Spectral target_if
|
||||
*
|
||||
* Return: None
|
||||
*/
|
||||
void os_if_spectral_netlink_init(struct wlan_objmgr_pdev *pdev);
|
||||
|
||||
#endif /* _OS_IF_SPECTRAL_NETLINK_H */
|
416
os_if/linux/spectral/src/os_if_spectral_netlink.c
Fichier normal
416
os_if/linux/spectral/src/os_if_spectral_netlink.c
Fichier normal
@@ -0,0 +1,416 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2017-2018 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for
|
||||
* any purpose with or without fee is hereby granted, provided that the
|
||||
* above copyright notice and this permission notice appear in all
|
||||
* copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
||||
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <os_if_spectral_netlink.h>
|
||||
#include <spectral_cmn_api_i.h>
|
||||
#include <spectral_defs_i.h>
|
||||
|
||||
struct sock *os_if_spectral_nl_sock;
|
||||
static atomic_t spectral_nl_users = ATOMIC_INIT(0);
|
||||
|
||||
#if (KERNEL_VERSION(2, 6, 31) > LINUX_VERSION_CODE)
|
||||
void
|
||||
os_if_spectral_nl_data_ready(struct sock *sk, int len)
|
||||
{
|
||||
spectral_debug("%d", __LINE__);
|
||||
}
|
||||
|
||||
#else
|
||||
void
|
||||
os_if_spectral_nl_data_ready(struct sk_buff *skb)
|
||||
{
|
||||
spectral_debug("%d", __LINE__);
|
||||
}
|
||||
#endif /* VERSION */
|
||||
|
||||
/**
|
||||
* os_if_spectral_init_nl_cfg() - Initialize netlink kernel
|
||||
* configuration parameters
|
||||
* @cfg : Pointer to netlink_kernel_cfg
|
||||
*
|
||||
* Initialize netlink kernel configuration parameters required
|
||||
* for spectral module
|
||||
*
|
||||
* Return: None
|
||||
*/
|
||||
#if KERNEL_VERSION(3, 6, 0) <= LINUX_VERSION_CODE
|
||||
static void
|
||||
os_if_spectral_init_nl_cfg(struct netlink_kernel_cfg *cfg)
|
||||
{
|
||||
cfg->groups = 1;
|
||||
cfg->input = os_if_spectral_nl_data_ready;
|
||||
}
|
||||
#else
|
||||
static void
|
||||
os_if_spectral_init_nl_cfg(struct netlink_kernel_cfg *cfg)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* os_if_spectral_create_nl_sock() - Create Netlink socket
|
||||
* @cfg : Pointer to netlink_kernel_cfg
|
||||
*
|
||||
* Create Netlink socket required for spectral module
|
||||
*
|
||||
* Return: None
|
||||
*/
|
||||
#if KERNEL_VERSION(3, 7, 0) <= LINUX_VERSION_CODE
|
||||
static void
|
||||
os_if_spectral_create_nl_sock(struct netlink_kernel_cfg *cfg)
|
||||
{
|
||||
os_if_spectral_nl_sock =
|
||||
(struct sock *)netlink_kernel_create(&init_net,
|
||||
NETLINK_ATHEROS, cfg);
|
||||
}
|
||||
#elif KERNEL_VERSION(3, 6, 0) <= LINUX_VERSION_CODE
|
||||
static void
|
||||
os_if_spectral_create_nl_sock(struct netlink_kernel_cfg *cfg)
|
||||
{
|
||||
os_if_spectral_nl_sock =
|
||||
(struct sock *)netlink_kernel_create(&init_net,
|
||||
NETLINK_ATHEROS,
|
||||
THIS_MODULE, cfg);
|
||||
}
|
||||
#elif (KERNEL_VERSION(2, 6, 31) > LINUX_VERSION_CODE)
|
||||
static void
|
||||
os_if_spectral_create_nl_sock(struct netlink_kernel_cfg *cfg)
|
||||
{
|
||||
os_if_spectral_nl_sock =
|
||||
(struct sock *)netlink_kernel_create(
|
||||
NETLINK_ATHEROS, 1,
|
||||
&os_if_spectral_nl_data_ready,
|
||||
THIS_MODULE);
|
||||
}
|
||||
#else
|
||||
#if (KERNEL_VERSION(3, 10, 0) <= LINUX_VERSION_CODE)
|
||||
static void
|
||||
os_if_spectral_create_nl_sock(struct netlink_kernel_cfg *cfg)
|
||||
{
|
||||
memset(cfg, 0, sizeof(*cfg));
|
||||
cfg->groups = 1;
|
||||
cfg->input = &os_if_spectral_nl_data_ready;
|
||||
os_if_spectral_nl_sock =
|
||||
(struct sock *)netlink_kernel_create(&init_net,
|
||||
NETLINK_ATHEROS, cfg);
|
||||
}
|
||||
#else
|
||||
static void
|
||||
os_if_spectral_create_nl_sock(struct netlink_kernel_cfg *cfg)
|
||||
{
|
||||
os_if_spectral_nl_sock =
|
||||
(struct sock *)netlink_kernel_create(
|
||||
&init_net,
|
||||
NETLINK_ATHEROS, 1,
|
||||
&os_if_spectral_nl_data_ready,
|
||||
NULL, THIS_MODULE);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* os_if_spectral_init_nl() - Initialize netlink data structures for
|
||||
* spectral module
|
||||
* @pdev : Pointer to pdev
|
||||
*
|
||||
* Return: 0 on success else failure
|
||||
*/
|
||||
static int
|
||||
os_if_spectral_init_nl(struct wlan_objmgr_pdev *pdev)
|
||||
{
|
||||
struct pdev_spectral *ps = NULL;
|
||||
struct netlink_kernel_cfg cfg;
|
||||
|
||||
memset(&cfg, 0, sizeof(cfg));
|
||||
if (!pdev) {
|
||||
spectral_err("PDEV is NULL!");
|
||||
return -EINVAL;
|
||||
}
|
||||
ps = wlan_objmgr_pdev_get_comp_private_obj(pdev,
|
||||
WLAN_UMAC_COMP_SPECTRAL);
|
||||
|
||||
if (!ps) {
|
||||
spectral_err("PDEV SPECTRAL object is NULL!");
|
||||
return -EINVAL;
|
||||
}
|
||||
os_if_spectral_init_nl_cfg(&cfg);
|
||||
|
||||
if (!os_if_spectral_nl_sock) {
|
||||
os_if_spectral_create_nl_sock(&cfg);
|
||||
|
||||
if (!os_if_spectral_nl_sock) {
|
||||
spectral_err("NETLINK_KERNEL_CREATE FAILED");
|
||||
return -ENODEV;
|
||||
}
|
||||
}
|
||||
ps->spectral_sock = os_if_spectral_nl_sock;
|
||||
|
||||
if (!ps->spectral_sock) {
|
||||
spectral_err("ps->spectral_sock is NULL");
|
||||
return -ENODEV;
|
||||
}
|
||||
atomic_inc(&spectral_nl_users);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* os_if_spectral_destroy_netlink() - De-initialize netlink data structures for
|
||||
* spectral module
|
||||
* @pdev : Pointer to pdev
|
||||
*
|
||||
* Return: Success/Failure
|
||||
*/
|
||||
static int
|
||||
os_if_spectral_destroy_netlink(struct wlan_objmgr_pdev *pdev)
|
||||
{
|
||||
struct pdev_spectral *ps = NULL;
|
||||
|
||||
if (!pdev) {
|
||||
spectral_err("PDEV is NULL!");
|
||||
return -EINVAL;
|
||||
}
|
||||
ps = wlan_objmgr_pdev_get_comp_private_obj(pdev,
|
||||
WLAN_UMAC_COMP_SPECTRAL);
|
||||
|
||||
if (!ps) {
|
||||
spectral_err("PDEV SPECTRAL object is NULL!");
|
||||
return -EINVAL;
|
||||
}
|
||||
ps->spectral_sock = NULL;
|
||||
if (atomic_dec_and_test(&spectral_nl_users)) {
|
||||
sock_release(os_if_spectral_nl_sock->sk_socket);
|
||||
os_if_spectral_nl_sock = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* os_if_spectral_prep_skb() - Prepare socket buffer
|
||||
* @pdev : Pointer to pdev
|
||||
*
|
||||
* Prepare socket buffer to send the data to application layer
|
||||
*
|
||||
* Return: NLMSG_DATA of the created skb or NULL if no memory
|
||||
*/
|
||||
void *
|
||||
os_if_spectral_prep_skb(struct wlan_objmgr_pdev *pdev)
|
||||
{
|
||||
struct pdev_spectral *ps = NULL;
|
||||
struct nlmsghdr *spectral_nlh = NULL;
|
||||
|
||||
if (!pdev) {
|
||||
spectral_err("PDEV is NULL!");
|
||||
return NULL;
|
||||
}
|
||||
ps = wlan_objmgr_pdev_get_comp_private_obj(pdev,
|
||||
WLAN_UMAC_COMP_SPECTRAL);
|
||||
|
||||
if (!ps) {
|
||||
spectral_err("PDEV SPECTRAL object is NULL!");
|
||||
return NULL;
|
||||
}
|
||||
ps->skb = dev_alloc_skb(MAX_SPECTRAL_PAYLOAD);
|
||||
|
||||
if (!ps->skb) {
|
||||
spectral_err("allocate skb (len=%u) failed",
|
||||
MAX_SPECTRAL_PAYLOAD);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
skb_put(ps->skb, MAX_SPECTRAL_PAYLOAD);
|
||||
spectral_nlh = (struct nlmsghdr *)ps->skb->data;
|
||||
|
||||
OS_MEMZERO(spectral_nlh,
|
||||
sizeof(*spectral_nlh));
|
||||
|
||||
/*
|
||||
* Possible bug that size of struct spectral_samp_msg and
|
||||
* SPECTRAL_MSG differ by 3 bytes so we miss 3 bytes
|
||||
*/
|
||||
|
||||
spectral_nlh->nlmsg_len =
|
||||
NLMSG_SPACE(sizeof(struct spectral_samp_msg));
|
||||
spectral_nlh->nlmsg_pid = 0;
|
||||
spectral_nlh->nlmsg_flags = 0;
|
||||
|
||||
return NLMSG_DATA(spectral_nlh);
|
||||
}
|
||||
|
||||
#if (KERNEL_VERSION(2, 6, 31) > LINUX_VERSION_CODE)
|
||||
static inline void
|
||||
os_if_init_spectral_skb_dst_pid(
|
||||
struct sk_buff *skb,
|
||||
struct pdev_spectral *ps)
|
||||
{
|
||||
NETLINK_CB(skb).dst_pid =
|
||||
ps->spectral_pid;
|
||||
}
|
||||
#else
|
||||
static inline void
|
||||
os_if_init_spectral_skb_dst_pid(
|
||||
struct sk_buff *skb,
|
||||
struct pdev_spectral *ps)
|
||||
{
|
||||
}
|
||||
#endif /* VERSION - field deprecated by newer kernels */
|
||||
|
||||
#if KERNEL_VERSION(3, 7, 0) > LINUX_VERSION_CODE
|
||||
static inline void
|
||||
os_if_init_spectral_skb_pid_portid(struct sk_buff *skb)
|
||||
{
|
||||
NETLINK_CB(skb).pid = 0; /* from kernel */
|
||||
}
|
||||
#else
|
||||
static inline void
|
||||
os_if_init_spectral_skb_pid_portid(struct sk_buff *skb)
|
||||
{
|
||||
NETLINK_CB(skb).portid = 0; /* from kernel */
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* os_if_spectral_nl_unicast_msg() - Sends unicast Spectral message to user
|
||||
* space
|
||||
* @pdev : Pointer to pdev
|
||||
*
|
||||
* Return: void
|
||||
*/
|
||||
static int
|
||||
os_if_spectral_nl_unicast_msg(struct wlan_objmgr_pdev *pdev)
|
||||
{
|
||||
struct pdev_spectral *ps = NULL;
|
||||
int status;
|
||||
|
||||
if (!pdev) {
|
||||
spectral_err("PDEV is NULL!");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ps = wlan_objmgr_pdev_get_comp_private_obj(pdev,
|
||||
WLAN_UMAC_COMP_SPECTRAL);
|
||||
if (!ps) {
|
||||
spectral_err("PDEV SPECTRAL object is NULL!");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!ps->skb) {
|
||||
spectral_err("Socket buffer is null");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!ps->spectral_sock) {
|
||||
spectral_err("Spectral Socket is invalid");
|
||||
dev_kfree_skb(ps->skb);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
os_if_init_spectral_skb_dst_pid(ps->skb, ps);
|
||||
|
||||
os_if_init_spectral_skb_pid_portid(ps->skb);
|
||||
|
||||
/* to mcast group 1<<0 */
|
||||
NETLINK_CB(ps->skb).dst_group = 0;
|
||||
|
||||
status = netlink_unicast(ps->spectral_sock,
|
||||
ps->skb,
|
||||
ps->spectral_pid, MSG_DONTWAIT);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* os_if_spectral_nl_bcast_msg() - Sends broadcast Spectral message to user
|
||||
* space
|
||||
* @pdev : Pointer to pdev
|
||||
*
|
||||
* Return: void
|
||||
*/
|
||||
static int
|
||||
os_if_spectral_nl_bcast_msg(struct wlan_objmgr_pdev *pdev)
|
||||
{
|
||||
#if (KERNEL_VERSION(2, 6, 31) >= LINUX_VERSION_CODE)
|
||||
fd_set write_set;
|
||||
#endif
|
||||
int status;
|
||||
struct pdev_spectral *ps = NULL;
|
||||
|
||||
#if (KERNEL_VERSION(2, 6, 31) >= LINUX_VERSION_CODE)
|
||||
FD_ZERO(&write_set);
|
||||
#endif
|
||||
|
||||
if (!pdev) {
|
||||
spectral_err("PDEV is NULL!");
|
||||
return -EINVAL;
|
||||
}
|
||||
ps = wlan_objmgr_pdev_get_comp_private_obj(pdev,
|
||||
WLAN_UMAC_COMP_SPECTRAL);
|
||||
|
||||
if (!ps) {
|
||||
spectral_err("PDEV SPECTRAL object is NULL!");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!ps->skb) {
|
||||
spectral_err("Socket buffer is null");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!ps->spectral_sock) {
|
||||
dev_kfree_skb(ps->skb);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
status = netlink_broadcast(ps->spectral_sock,
|
||||
ps->skb,
|
||||
0, 1, GFP_ATOMIC);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void
|
||||
os_if_spectral_netlink_init(struct wlan_objmgr_pdev *pdev)
|
||||
{
|
||||
struct spectral_nl_cb nl_cb = {0};
|
||||
struct spectral_context *sptrl_ctx;
|
||||
|
||||
if (!pdev) {
|
||||
spectral_err("PDEV is NULL!");
|
||||
return;
|
||||
}
|
||||
|
||||
sptrl_ctx = spectral_get_spectral_ctx_from_pdev(pdev);
|
||||
|
||||
if (!sptrl_ctx) {
|
||||
spectral_err("Spectral context is NULL!");
|
||||
return;
|
||||
}
|
||||
|
||||
os_if_spectral_init_nl(pdev);
|
||||
|
||||
/* Register Netlink handlers */
|
||||
nl_cb.get_nbuff = os_if_spectral_prep_skb;
|
||||
nl_cb.send_nl_bcast = os_if_spectral_nl_bcast_msg;
|
||||
nl_cb.send_nl_unicast = os_if_spectral_nl_unicast_msg;
|
||||
nl_cb.destroy_netlink = os_if_spectral_destroy_netlink;
|
||||
|
||||
if (sptrl_ctx->sptrlc_register_netlink_cb)
|
||||
sptrl_ctx->sptrlc_register_netlink_cb(pdev, &nl_cb);
|
||||
}
|
||||
EXPORT_SYMBOL(os_if_spectral_netlink_init);
|
Référencer dans un nouveau ticket
Bloquer un utilisateur