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 = skb_put(skb, sizeof(*hdr) + arr_len);
24
25 hdr->type = cpu_to_le16(tlv_id);
26 hdr->len = cpu_to_le16(arr_len);
27 memcpy(hdr->val, arr, arr_len);
28 }
29
qtnf_cmd_skb_put_tlv_tag(struct sk_buff * skb,u16 tlv_id)30 static inline void qtnf_cmd_skb_put_tlv_tag(struct sk_buff *skb, u16 tlv_id)
31 {
32 struct qlink_tlv_hdr *hdr = skb_put(skb, sizeof(*hdr));
33
34 hdr->type = cpu_to_le16(tlv_id);
35 hdr->len = cpu_to_le16(0);
36 }
37
qtnf_cmd_skb_put_tlv_u8(struct sk_buff * skb,u16 tlv_id,u8 value)38 static inline void qtnf_cmd_skb_put_tlv_u8(struct sk_buff *skb, u16 tlv_id,
39 u8 value)
40 {
41 struct qlink_tlv_hdr *hdr = skb_put(skb, sizeof(*hdr) + sizeof(value));
42
43 hdr->type = cpu_to_le16(tlv_id);
44 hdr->len = cpu_to_le16(sizeof(value));
45 *hdr->val = value;
46 }
47
qtnf_cmd_skb_put_tlv_u16(struct sk_buff * skb,u16 tlv_id,u16 value)48 static inline void qtnf_cmd_skb_put_tlv_u16(struct sk_buff *skb,
49 u16 tlv_id, u16 value)
50 {
51 struct qlink_tlv_hdr *hdr = skb_put(skb, sizeof(*hdr) + sizeof(value));
52 __le16 tmp = cpu_to_le16(value);
53
54 hdr->type = cpu_to_le16(tlv_id);
55 hdr->len = cpu_to_le16(sizeof(value));
56 memcpy(hdr->val, &tmp, sizeof(tmp));
57 }
58
qtnf_cmd_skb_put_tlv_u32(struct sk_buff * skb,u16 tlv_id,u32 value)59 static inline void qtnf_cmd_skb_put_tlv_u32(struct sk_buff *skb,
60 u16 tlv_id, u32 value)
61 {
62 struct qlink_tlv_hdr *hdr = skb_put(skb, sizeof(*hdr) + sizeof(value));
63 __le32 tmp = cpu_to_le32(value);
64
65 hdr->type = cpu_to_le16(tlv_id);
66 hdr->len = cpu_to_le16(sizeof(value));
67 memcpy(hdr->val, &tmp, sizeof(tmp));
68 }
69
70 u16 qlink_iface_type_to_nl_mask(u16 qlink_type);
71 u8 qlink_chan_width_mask_to_nl(u16 qlink_mask);
72 void qlink_chandef_q2cfg(struct wiphy *wiphy,
73 const struct qlink_chandef *qch,
74 struct cfg80211_chan_def *chdef);
75 void qlink_chandef_cfg2q(const struct cfg80211_chan_def *chdef,
76 struct qlink_chandef *qch);
77 enum qlink_hidden_ssid qlink_hidden_ssid_nl2q(enum nl80211_hidden_ssid nl_val);
78 bool qtnf_utils_is_bit_set(const u8 *arr, unsigned int bit,
79 unsigned int arr_max_len);
80 void qlink_acl_data_cfg2q(const struct cfg80211_acl_data *acl,
81 struct qlink_acl_data *qacl);
82 enum qlink_band qlink_utils_band_cfg2q(enum nl80211_band band);
83 enum qlink_dfs_state qlink_utils_dfs_state_cfg2q(enum nl80211_dfs_state state);
84 u32 qlink_utils_chflags_cfg2q(u32 cfgflags);
85 void qlink_utils_regrule_q2nl(struct ieee80211_reg_rule *rule,
86 const struct qlink_tlv_reg_rule *tlv_rule);
87
88 #endif /* _QTN_FMAC_QLINK_UTIL_H_ */
89