1ff233cb5SSergey Matyukevich /* SPDX-License-Identifier: GPL-2.0+ */ 2ff233cb5SSergey Matyukevich /* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */ 398f44cb0SIgor Mitsyanko 498f44cb0SIgor Mitsyanko #ifndef _QTN_FMAC_QLINK_UTIL_H_ 598f44cb0SIgor Mitsyanko #define _QTN_FMAC_QLINK_UTIL_H_ 698f44cb0SIgor Mitsyanko 798f44cb0SIgor Mitsyanko #include <linux/types.h> 898f44cb0SIgor Mitsyanko #include <linux/skbuff.h> 9fac7f9bfSIgor Mitsyanko #include <net/cfg80211.h> 1098f44cb0SIgor Mitsyanko 1198f44cb0SIgor Mitsyanko #include "qlink.h" 1298f44cb0SIgor Mitsyanko 1398f44cb0SIgor Mitsyanko static inline void 1498f44cb0SIgor Mitsyanko qtnf_cmd_skb_put_buffer(struct sk_buff *skb, const u8 *buf_src, size_t len) 1598f44cb0SIgor Mitsyanko { 16b952f4dfSyuan linyu skb_put_data(skb, buf_src, len); 1798f44cb0SIgor Mitsyanko } 1898f44cb0SIgor Mitsyanko 1998f44cb0SIgor Mitsyanko static inline void qtnf_cmd_skb_put_tlv_arr(struct sk_buff *skb, 2098f44cb0SIgor Mitsyanko u16 tlv_id, const u8 arr[], 2198f44cb0SIgor Mitsyanko size_t arr_len) 2298f44cb0SIgor Mitsyanko { 23*8b0b5f1bSIgor Mitsyanko struct qlink_tlv_hdr *hdr; 2498f44cb0SIgor Mitsyanko 25*8b0b5f1bSIgor Mitsyanko hdr = skb_put(skb, sizeof(*hdr) + round_up(arr_len, QLINK_ALIGN)); 2698f44cb0SIgor Mitsyanko hdr->type = cpu_to_le16(tlv_id); 2798f44cb0SIgor Mitsyanko hdr->len = cpu_to_le16(arr_len); 2898f44cb0SIgor Mitsyanko memcpy(hdr->val, arr, arr_len); 2998f44cb0SIgor Mitsyanko } 3098f44cb0SIgor Mitsyanko 319fe504a1SSergey Matyukevich static inline void qtnf_cmd_skb_put_tlv_u32(struct sk_buff *skb, 329fe504a1SSergey Matyukevich u16 tlv_id, u32 value) 339fe504a1SSergey Matyukevich { 349fe504a1SSergey Matyukevich struct qlink_tlv_hdr *hdr = skb_put(skb, sizeof(*hdr) + sizeof(value)); 359fe504a1SSergey Matyukevich __le32 tmp = cpu_to_le32(value); 369fe504a1SSergey Matyukevich 379fe504a1SSergey Matyukevich hdr->type = cpu_to_le16(tlv_id); 389fe504a1SSergey Matyukevich hdr->len = cpu_to_le16(sizeof(value)); 399fe504a1SSergey Matyukevich memcpy(hdr->val, &tmp, sizeof(tmp)); 409fe504a1SSergey Matyukevich } 419fe504a1SSergey Matyukevich 4241c8fa0cSSergey Matyukevich u16 qlink_iface_type_to_nl_mask(u16 qlink_type); 4398f44cb0SIgor Mitsyanko u8 qlink_chan_width_mask_to_nl(u16 qlink_mask); 44fac7f9bfSIgor Mitsyanko void qlink_chandef_q2cfg(struct wiphy *wiphy, 45fac7f9bfSIgor Mitsyanko const struct qlink_chandef *qch, 46fac7f9bfSIgor Mitsyanko struct cfg80211_chan_def *chdef); 47f99201cbSIgor Mitsyanko void qlink_chandef_cfg2q(const struct cfg80211_chan_def *chdef, 48f99201cbSIgor Mitsyanko struct qlink_chandef *qch); 498b5f4aa7SIgor Mitsyanko enum qlink_hidden_ssid qlink_hidden_ssid_nl2q(enum nl80211_hidden_ssid nl_val); 504d2a7a1cSIgor Mitsyanko bool qtnf_utils_is_bit_set(const u8 *arr, unsigned int bit, 514d2a7a1cSIgor Mitsyanko unsigned int arr_max_len); 52f1398fd2SVasily Ulyanov void qlink_acl_data_cfg2q(const struct cfg80211_acl_data *acl, 53f1398fd2SVasily Ulyanov struct qlink_acl_data *qacl); 542c31129fSIgor Mitsyanko enum qlink_band qlink_utils_band_cfg2q(enum nl80211_band band); 552c31129fSIgor Mitsyanko enum qlink_dfs_state qlink_utils_dfs_state_cfg2q(enum nl80211_dfs_state state); 562c31129fSIgor Mitsyanko u32 qlink_utils_chflags_cfg2q(u32 cfgflags); 57c698bce0SIgor Mitsyanko void qlink_utils_regrule_q2nl(struct ieee80211_reg_rule *rule, 58c698bce0SIgor Mitsyanko const struct qlink_tlv_reg_rule *tlv_rule); 5998f44cb0SIgor Mitsyanko 60*8b0b5f1bSIgor Mitsyanko #define qlink_for_each_tlv(_tlv, _start, _datalen) \ 61*8b0b5f1bSIgor Mitsyanko for (_tlv = (const struct qlink_tlv_hdr *)(_start); \ 62*8b0b5f1bSIgor Mitsyanko (const u8 *)(_start) + (_datalen) - (const u8 *)_tlv >= \ 63*8b0b5f1bSIgor Mitsyanko (int)sizeof(*_tlv) && \ 64*8b0b5f1bSIgor Mitsyanko (const u8 *)(_start) + (_datalen) - (const u8 *)_tlv >= \ 65*8b0b5f1bSIgor Mitsyanko (int)sizeof(*_tlv) + le16_to_cpu(_tlv->len); \ 66*8b0b5f1bSIgor Mitsyanko _tlv = (const struct qlink_tlv_hdr *)(_tlv->val + \ 67*8b0b5f1bSIgor Mitsyanko round_up(le16_to_cpu(_tlv->len), QLINK_ALIGN))) 68*8b0b5f1bSIgor Mitsyanko 69*8b0b5f1bSIgor Mitsyanko #define qlink_tlv_parsing_ok(_tlv_last, _start, _datalen) \ 70*8b0b5f1bSIgor Mitsyanko ((const u8 *)(_tlv_last) == \ 71*8b0b5f1bSIgor Mitsyanko (const u8 *)(_start) + round_up(_datalen, QLINK_ALIGN)) 72*8b0b5f1bSIgor Mitsyanko 7398f44cb0SIgor Mitsyanko #endif /* _QTN_FMAC_QLINK_UTIL_H_ */ 74