1 /*
2  * Copyright (c) 2012-2017, 2019-2020 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /******************************************************************************
21 * wlan_nlink_srv.h
22 *
23 * wlan_nlink_srv is used to RX/TX Netlink messages from user space to kernel
24 * modules and vice versa. Kernel modules must register a message handler for a
25 * message type so that the wlan_nlink_srv can invoke the corresponding msg handler
26 * whenever a Netlink message of a particular type has been received from an
27 * application.  In the opposite direction, wlan_nlink_srv provides a mechanism
28 * which kernel modules can use to send Netlink messages to applications.
29 *
30 ******************************************************************************/
31 
32 #ifndef WLAN_NLINK_SRV_H
33 #define WLAN_NLINK_SRV_H
34 
35 #include <linux/skbuff.h>
36 #include <net/netlink.h>
37 #include <wlan_nlink_common.h>
38 
39 #define INVALID_PID -1
40 #define NLINK_MAX_CALLBACKS (WLAN_NL_MSG_MAX - WLAN_NL_MSG_BASE)
41 
42 typedef int (*nl_srv_msg_callback)(struct sk_buff *skb);
43 
44 /**
45  * cld80211_oem_send_reply() - API to send cld80211 msg
46  * @skb: Sk buffer
47  * @hdr: nl80211hdr pointer
48  * @nest: pointer of vendor nested attribute
49  * @flags: Flags
50  *
51  * API to send cld80211 msg to applications
52  *
53  * Return: None
54  */
55 void cld80211_oem_send_reply(struct sk_buff *msg, void *hdr,
56 				    struct nlattr *nest, int flags);
57 
58 /**
59  * nl80211hdr_put() - API to allocate skb for cld80211 msg
60  * @hdr: nl80211hdr pointer
61  * @portid: Port ID
62  * @nest: pointer of vendor nested attribute
63  * @flags: Flags
64  *
65  * API to allocate skb for cld80211 msg
66  *
67  * Return: Pointer to skbuff
68  */
69 
70 struct sk_buff *
71 cld80211_oem_rsp_alloc_skb(uint32_t portid, void **hdr, struct nlattr **nest,
72 			   int *flags);
73 int nl_srv_init(void *wiphy, int proto);
74 void nl_srv_exit(void);
75 int nl_srv_register(tWlanNlModTypes msg_type, nl_srv_msg_callback msg_handler);
76 int nl_srv_unregister(tWlanNlModTypes msg_type,
77 		      nl_srv_msg_callback msg_handler);
78 
79 #ifdef CNSS_GENL
80 int nl_srv_ucast(struct sk_buff *skb, int dst_pid, int flag,
81 			int app_id, int mcgroup_id);
82 int nl_srv_bcast(struct sk_buff *skb, int mcgroup_id, int app_id);
83 
84 /**
85  * nl80211hdr_put() - API to fill genlmsg header
86  * @skb: Sk buffer
87  * @portid: Port ID
88  * @seq: Sequence number
89  * @flags: Flags
90  * @cmd: Command id
91  *
92  * API to fill genl message header for broadcast events to user space
93  *
94  * Return: Pointer to user specific header/payload
95  */
96 void *nl80211hdr_put(struct sk_buff *skb, uint32_t portid,
97 		     uint32_t seq, int flags, uint8_t cmd);
98 #else
99 int nl_srv_ucast(struct sk_buff *skb, int dst_pid, int flag);
100 int nl_srv_bcast(struct sk_buff *skb);
101 #endif
102 
103 int nl_srv_is_initialized(void);
104 void nl_srv_ucast_oem(struct sk_buff *skb, int dst_pid, int flag);
105 
106 #endif
107