18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */ 28c2ecf20Sopenharmony_ci/* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#ifndef _QTN_FMAC_QLINK_UTIL_H_ 58c2ecf20Sopenharmony_ci#define _QTN_FMAC_QLINK_UTIL_H_ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include <linux/types.h> 88c2ecf20Sopenharmony_ci#include <linux/skbuff.h> 98c2ecf20Sopenharmony_ci#include <net/cfg80211.h> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include "qlink.h" 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cistatic inline void 148c2ecf20Sopenharmony_ciqtnf_cmd_skb_put_buffer(struct sk_buff *skb, const u8 *buf_src, size_t len) 158c2ecf20Sopenharmony_ci{ 168c2ecf20Sopenharmony_ci skb_put_data(skb, buf_src, len); 178c2ecf20Sopenharmony_ci} 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_cistatic inline void qtnf_cmd_skb_put_tlv_arr(struct sk_buff *skb, 208c2ecf20Sopenharmony_ci u16 tlv_id, const u8 arr[], 218c2ecf20Sopenharmony_ci size_t arr_len) 228c2ecf20Sopenharmony_ci{ 238c2ecf20Sopenharmony_ci struct qlink_tlv_hdr *hdr; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci hdr = skb_put(skb, sizeof(*hdr) + round_up(arr_len, QLINK_ALIGN)); 268c2ecf20Sopenharmony_ci hdr->type = cpu_to_le16(tlv_id); 278c2ecf20Sopenharmony_ci hdr->len = cpu_to_le16(arr_len); 288c2ecf20Sopenharmony_ci memcpy(hdr->val, arr, arr_len); 298c2ecf20Sopenharmony_ci} 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cistatic inline void qtnf_cmd_skb_put_tlv_u32(struct sk_buff *skb, 328c2ecf20Sopenharmony_ci u16 tlv_id, u32 value) 338c2ecf20Sopenharmony_ci{ 348c2ecf20Sopenharmony_ci struct qlink_tlv_hdr *hdr = skb_put(skb, sizeof(*hdr) + sizeof(value)); 358c2ecf20Sopenharmony_ci __le32 tmp = cpu_to_le32(value); 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci hdr->type = cpu_to_le16(tlv_id); 388c2ecf20Sopenharmony_ci hdr->len = cpu_to_le16(sizeof(value)); 398c2ecf20Sopenharmony_ci memcpy(hdr->val, &tmp, sizeof(tmp)); 408c2ecf20Sopenharmony_ci} 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ciu16 qlink_iface_type_to_nl_mask(u16 qlink_type); 438c2ecf20Sopenharmony_ciu8 qlink_chan_width_mask_to_nl(u16 qlink_mask); 448c2ecf20Sopenharmony_civoid qlink_chandef_q2cfg(struct wiphy *wiphy, 458c2ecf20Sopenharmony_ci const struct qlink_chandef *qch, 468c2ecf20Sopenharmony_ci struct cfg80211_chan_def *chdef); 478c2ecf20Sopenharmony_civoid qlink_chandef_cfg2q(const struct cfg80211_chan_def *chdef, 488c2ecf20Sopenharmony_ci struct qlink_chandef *qch); 498c2ecf20Sopenharmony_cienum qlink_hidden_ssid qlink_hidden_ssid_nl2q(enum nl80211_hidden_ssid nl_val); 508c2ecf20Sopenharmony_cibool qtnf_utils_is_bit_set(const u8 *arr, unsigned int bit, 518c2ecf20Sopenharmony_ci unsigned int arr_max_len); 528c2ecf20Sopenharmony_civoid qlink_acl_data_cfg2q(const struct cfg80211_acl_data *acl, 538c2ecf20Sopenharmony_ci struct qlink_acl_data *qacl); 548c2ecf20Sopenharmony_cienum qlink_band qlink_utils_band_cfg2q(enum nl80211_band band); 558c2ecf20Sopenharmony_cienum qlink_dfs_state qlink_utils_dfs_state_cfg2q(enum nl80211_dfs_state state); 568c2ecf20Sopenharmony_ciu32 qlink_utils_chflags_cfg2q(u32 cfgflags); 578c2ecf20Sopenharmony_civoid qlink_utils_regrule_q2nl(struct ieee80211_reg_rule *rule, 588c2ecf20Sopenharmony_ci const struct qlink_tlv_reg_rule *tlv_rule); 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci#define qlink_for_each_tlv(_tlv, _start, _datalen) \ 618c2ecf20Sopenharmony_ci for (_tlv = (const struct qlink_tlv_hdr *)(_start); \ 628c2ecf20Sopenharmony_ci (const u8 *)(_start) + (_datalen) - (const u8 *)_tlv >= \ 638c2ecf20Sopenharmony_ci (int)sizeof(*_tlv) && \ 648c2ecf20Sopenharmony_ci (const u8 *)(_start) + (_datalen) - (const u8 *)_tlv >= \ 658c2ecf20Sopenharmony_ci (int)sizeof(*_tlv) + le16_to_cpu(_tlv->len); \ 668c2ecf20Sopenharmony_ci _tlv = (const struct qlink_tlv_hdr *)(_tlv->val + \ 678c2ecf20Sopenharmony_ci round_up(le16_to_cpu(_tlv->len), QLINK_ALIGN))) 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci#define qlink_tlv_parsing_ok(_tlv_last, _start, _datalen) \ 708c2ecf20Sopenharmony_ci ((const u8 *)(_tlv_last) == \ 718c2ecf20Sopenharmony_ci (const u8 *)(_start) + round_up(_datalen, QLINK_ALIGN)) 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci#endif /* _QTN_FMAC_QLINK_UTIL_H_ */ 74