blob: 230a10a41c7ab2587de5c0fbc821479f2e8d6dc2 [file] [log] [blame]
Sergey Matyukevichff233cb52019-01-14 09:39:45 +00001/* SPDX-License-Identifier: GPL-2.0+ */
2/* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */
Igor Mitsyanko98f44cb2017-05-11 14:51:01 -07003
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>
Igor Mitsyankofac7f9b2017-09-21 14:34:30 -07009#include <net/cfg80211.h>
Igor Mitsyanko98f44cb2017-05-11 14:51:01 -070010
11#include "qlink.h"
12
Igor Mitsyanko98f44cb2017-05-11 14:51:01 -070013static inline void
14qtnf_cmd_skb_put_buffer(struct sk_buff *skb, const u8 *buf_src, size_t len)
15{
yuan linyub952f4d2017-06-18 22:52:04 +080016 skb_put_data(skb, buf_src, len);
Igor Mitsyanko98f44cb2017-05-11 14:51:01 -070017}
18
19static 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{
Igor Mitsyanko8b0b5f12020-01-27 10:46:53 +000023 struct qlink_tlv_hdr *hdr;
Igor Mitsyanko98f44cb2017-05-11 14:51:01 -070024
Igor Mitsyanko8b0b5f12020-01-27 10:46:53 +000025 hdr = skb_put(skb, sizeof(*hdr) + round_up(arr_len, QLINK_ALIGN));
Igor Mitsyanko98f44cb2017-05-11 14:51:01 -070026 hdr->type = cpu_to_le16(tlv_id);
27 hdr->len = cpu_to_le16(arr_len);
28 memcpy(hdr->val, arr, arr_len);
29}
30
Sergey Matyukevich9fe504a2019-01-14 09:39:40 +000031static 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
Sergey Matyukevich41c8fa02017-07-28 02:06:52 +030042u16 qlink_iface_type_to_nl_mask(u16 qlink_type);
Igor Mitsyanko98f44cb2017-05-11 14:51:01 -070043u8 qlink_chan_width_mask_to_nl(u16 qlink_mask);
Igor Mitsyankofac7f9b2017-09-21 14:34:30 -070044void qlink_chandef_q2cfg(struct wiphy *wiphy,
45 const struct qlink_chandef *qch,
46 struct cfg80211_chan_def *chdef);
Igor Mitsyankof99201c2017-10-04 18:38:08 -070047void qlink_chandef_cfg2q(const struct cfg80211_chan_def *chdef,
48 struct qlink_chandef *qch);
Igor Mitsyanko8b5f4aa2017-10-04 18:38:07 -070049enum qlink_hidden_ssid qlink_hidden_ssid_nl2q(enum nl80211_hidden_ssid nl_val);
Igor Mitsyanko4d2a7a12017-12-19 14:28:54 +030050bool qtnf_utils_is_bit_set(const u8 *arr, unsigned int bit,
51 unsigned int arr_max_len);
Vasily Ulyanovf1398fd2017-12-19 14:28:56 +030052void qlink_acl_data_cfg2q(const struct cfg80211_acl_data *acl,
53 struct qlink_acl_data *qacl);
Igor Mitsyanko2c311292019-03-20 10:03:53 +000054enum qlink_band qlink_utils_band_cfg2q(enum nl80211_band band);
55enum qlink_dfs_state qlink_utils_dfs_state_cfg2q(enum nl80211_dfs_state state);
56u32 qlink_utils_chflags_cfg2q(u32 cfgflags);
Igor Mitsyankoc698bce2019-03-20 10:03:57 +000057void qlink_utils_regrule_q2nl(struct ieee80211_reg_rule *rule,
58 const struct qlink_tlv_reg_rule *tlv_rule);
Igor Mitsyanko98f44cb2017-05-11 14:51:01 -070059
Igor Mitsyanko8b0b5f12020-01-27 10:46:53 +000060#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
Igor Mitsyanko98f44cb2017-05-11 14:51:01 -070073#endif /* _QTN_FMAC_QLINK_UTIL_H_ */