1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */
3 
4 #ifndef _QTN_FMAC_QLINK_UTIL_H_
5 #define _QTN_FMAC_QLINK_UTIL_H_
6 
7 #include <linux/types.h>
8 #include <linux/skbuff.h>
9 #include <net/cfg80211.h>
10 
11 #include "qlink.h"
12 
13 static inline void
qtnf_cmd_skb_put_buffer(struct sk_buff * skb,const u8 * buf_src,size_t len)14 qtnf_cmd_skb_put_buffer(struct sk_buff *skb, const u8 *buf_src, size_t len)
15 {
16 	skb_put_data(skb, buf_src, len);
17 }
18 
qtnf_cmd_skb_put_tlv_arr(struct sk_buff * skb,u16 tlv_id,const u8 arr[],size_t arr_len)19 static inline void qtnf_cmd_skb_put_tlv_arr(struct sk_buff *skb,
20 					    u16 tlv_id, const u8 arr[],
21 					    size_t arr_len)
22 {
23 	struct qlink_tlv_hdr *hdr;
24 
25 	hdr = skb_put(skb, sizeof(*hdr) + round_up(arr_len, QLINK_ALIGN));
26 	hdr->type = cpu_to_le16(tlv_id);
27 	hdr->len = cpu_to_le16(arr_len);
28 	memcpy(hdr->val, arr, arr_len);
29 }
30 
qtnf_cmd_skb_put_tlv_u32(struct sk_buff * skb,u16 tlv_id,u32 value)31 static inline void qtnf_cmd_skb_put_tlv_u32(struct sk_buff *skb,
32 					    u16 tlv_id, u32 value)
33 {
34 	struct qlink_tlv_hdr *hdr = skb_put(skb, sizeof(*hdr) + sizeof(value));
35 	__le32 tmp = cpu_to_le32(value);
36 
37 	hdr->type = cpu_to_le16(tlv_id);
38 	hdr->len = cpu_to_le16(sizeof(value));
39 	memcpy(hdr->val, &tmp, sizeof(tmp));
40 }
41 
42 u16 qlink_iface_type_to_nl_mask(u16 qlink_type);
43 u8 qlink_chan_width_mask_to_nl(u16 qlink_mask);
44 void qlink_chandef_q2cfg(struct wiphy *wiphy,
45 			 const struct qlink_chandef *qch,
46 			 struct cfg80211_chan_def *chdef);
47 void qlink_chandef_cfg2q(const struct cfg80211_chan_def *chdef,
48 			 struct qlink_chandef *qch);
49 enum qlink_hidden_ssid qlink_hidden_ssid_nl2q(enum nl80211_hidden_ssid nl_val);
50 bool qtnf_utils_is_bit_set(const u8 *arr, unsigned int bit,
51 			   unsigned int arr_max_len);
52 void qlink_acl_data_cfg2q(const struct cfg80211_acl_data *acl,
53 			  struct qlink_acl_data *qacl);
54 enum qlink_band qlink_utils_band_cfg2q(enum nl80211_band band);
55 enum qlink_dfs_state qlink_utils_dfs_state_cfg2q(enum nl80211_dfs_state state);
56 u32 qlink_utils_chflags_cfg2q(u32 cfgflags);
57 void qlink_utils_regrule_q2nl(struct ieee80211_reg_rule *rule,
58 			      const struct qlink_tlv_reg_rule *tlv_rule);
59 
60 #define qlink_for_each_tlv(_tlv, _start, _datalen)			\
61 	for (_tlv = (const struct qlink_tlv_hdr *)(_start);		\
62 	     (const u8 *)(_start) + (_datalen) - (const u8 *)_tlv >=	\
63 		(int)sizeof(*_tlv) &&					\
64 	     (const u8 *)(_start) + (_datalen) - (const u8 *)_tlv >=	\
65 		(int)sizeof(*_tlv) + le16_to_cpu(_tlv->len);		\
66 	     _tlv = (const struct qlink_tlv_hdr *)(_tlv->val +		\
67 		round_up(le16_to_cpu(_tlv->len), QLINK_ALIGN)))
68 
69 #define qlink_tlv_parsing_ok(_tlv_last, _start, _datalen)	\
70 	((const u8 *)(_tlv_last) == \
71 		(const u8 *)(_start) + round_up(_datalen, QLINK_ALIGN))
72 
73 #endif /* _QTN_FMAC_QLINK_UTIL_H_ */
74