Sergey Matyukevich | ff233cb5 | 2019-01-14 09:39:45 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */ |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 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> |
Igor Mitsyanko | fac7f9b | 2017-09-21 14:34:30 -0700 | [diff] [blame] | 9 | #include <net/cfg80211.h> |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 10 | |
| 11 | #include "qlink.h" |
| 12 | |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 13 | static inline void |
| 14 | qtnf_cmd_skb_put_buffer(struct sk_buff *skb, const u8 *buf_src, size_t len) |
| 15 | { |
yuan linyu | b952f4d | 2017-06-18 22:52:04 +0800 | [diff] [blame] | 16 | skb_put_data(skb, buf_src, len); |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 17 | } |
| 18 | |
| 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 | { |
Igor Mitsyanko | 8b0b5f1 | 2020-01-27 10:46:53 +0000 | [diff] [blame] | 23 | struct qlink_tlv_hdr *hdr; |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 24 | |
Igor Mitsyanko | 8b0b5f1 | 2020-01-27 10:46:53 +0000 | [diff] [blame] | 25 | hdr = skb_put(skb, sizeof(*hdr) + round_up(arr_len, QLINK_ALIGN)); |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 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 | |
Sergey Matyukevich | 9fe504a | 2019-01-14 09:39:40 +0000 | [diff] [blame] | 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 | |
Sergey Matyukevich | 41c8fa0 | 2017-07-28 02:06:52 +0300 | [diff] [blame] | 42 | u16 qlink_iface_type_to_nl_mask(u16 qlink_type); |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 43 | u8 qlink_chan_width_mask_to_nl(u16 qlink_mask); |
Igor Mitsyanko | fac7f9b | 2017-09-21 14:34:30 -0700 | [diff] [blame] | 44 | void qlink_chandef_q2cfg(struct wiphy *wiphy, |
| 45 | const struct qlink_chandef *qch, |
| 46 | struct cfg80211_chan_def *chdef); |
Igor Mitsyanko | f99201c | 2017-10-04 18:38:08 -0700 | [diff] [blame] | 47 | void qlink_chandef_cfg2q(const struct cfg80211_chan_def *chdef, |
| 48 | struct qlink_chandef *qch); |
Igor Mitsyanko | 8b5f4aa | 2017-10-04 18:38:07 -0700 | [diff] [blame] | 49 | enum qlink_hidden_ssid qlink_hidden_ssid_nl2q(enum nl80211_hidden_ssid nl_val); |
Igor Mitsyanko | 4d2a7a1 | 2017-12-19 14:28:54 +0300 | [diff] [blame] | 50 | bool qtnf_utils_is_bit_set(const u8 *arr, unsigned int bit, |
| 51 | unsigned int arr_max_len); |
Vasily Ulyanov | f1398fd | 2017-12-19 14:28:56 +0300 | [diff] [blame] | 52 | void qlink_acl_data_cfg2q(const struct cfg80211_acl_data *acl, |
| 53 | struct qlink_acl_data *qacl); |
Igor Mitsyanko | 2c31129 | 2019-03-20 10:03:53 +0000 | [diff] [blame] | 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); |
Igor Mitsyanko | c698bce | 2019-03-20 10:03:57 +0000 | [diff] [blame] | 57 | void qlink_utils_regrule_q2nl(struct ieee80211_reg_rule *rule, |
| 58 | const struct qlink_tlv_reg_rule *tlv_rule); |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 59 | |
Igor Mitsyanko | 8b0b5f1 | 2020-01-27 10:46:53 +0000 | [diff] [blame] | 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 | |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 73 | #endif /* _QTN_FMAC_QLINK_UTIL_H_ */ |