1 /*
2 * Copyright (c) 2011-2017, 2019 The Linux Foundation. All rights reserved.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #ifndef _OL_RX_DEFRAG_H_
20 #define _OL_RX_DEFRAG_H_
21
22 #include <qdf_nbuf.h>
23 #include <cds_ieee80211_common.h>
24 #include <qdf_util.h>
25 #include <qdf_types.h>
26 #include <qdf_mem.h>
27 #include <ol_txrx_internal.h>
28 #include <ol_txrx_dbg.h>
29
30 #define DEFRAG_IEEE80211_KEY_LEN 8
31 #define DEFRAG_IEEE80211_FCS_LEN 4
32
33 struct ol_rx_defrag_cipher {
34 const char *ic_name;
35 uint16_t ic_header;
36 uint8_t ic_trailer;
37 uint8_t ic_miclen;
38 };
39
40 enum {
41 OL_RX_DEFRAG_ERR,
42 OL_RX_DEFRAG_OK,
43 OL_RX_DEFRAG_PN_ERR
44 };
45
46 #define ol_rx_defrag_copydata(buf, offset, len, _to) \
47 qdf_nbuf_copy_bits(buf, offset, len, _to)
48
49 #define ol_rx_defrag_len(buf) \
50 qdf_nbuf_len(buf)
51
52 void
53 ol_rx_fraglist_insert(htt_pdev_handle htt_pdev,
54 qdf_nbuf_t *head_addr,
55 qdf_nbuf_t *tail_addr,
56 qdf_nbuf_t frag, uint8_t *all_frag_present);
57
58 void ol_rx_defrag_waitlist_add(struct ol_txrx_peer_t *peer, unsigned int tid);
59
60 void ol_rx_defrag_waitlist_remove(struct ol_txrx_peer_t *peer,
61 unsigned int tid);
62
63 void ol_rx_defrag_waitlist_flush(struct ol_txrx_pdev_t *pdev);
64
65 void
66 ol_rx_defrag(ol_txrx_pdev_handle pdev,
67 struct ol_txrx_peer_t *peer, unsigned int tid,
68 qdf_nbuf_t frag_list);
69
70 int
71 ol_rx_frag_tkip_decap(ol_txrx_pdev_handle pdev,
72 qdf_nbuf_t msdu, uint16_t hdrlen);
73
74 int
75 ol_rx_frag_wep_decap(ol_txrx_pdev_handle pdev,
76 qdf_nbuf_t nbuf, uint16_t hdrlen);
77
78 void ol_rx_defrag_nwifi_to_8023(ol_txrx_pdev_handle pdev, qdf_nbuf_t msdu);
79
80 void
81 ol_rx_defrag_qos_decap(ol_txrx_pdev_handle pdev,
82 qdf_nbuf_t nbuf, uint16_t hdrlen);
83
84 int
85 ol_rx_frag_tkip_demic(ol_txrx_pdev_handle pdev,
86 const uint8_t *key, qdf_nbuf_t msdu, uint16_t hdrlen);
87
88 int
89 ol_rx_frag_ccmp_decap(ol_txrx_pdev_handle pdev,
90 qdf_nbuf_t nbuf, uint16_t hdrlen);
91
92 int
93 ol_rx_frag_ccmp_demic(ol_txrx_pdev_handle pdev,
94 qdf_nbuf_t wbuf, uint16_t hdrlen);
95
96 uint16_t ol_rx_frag_hdrsize(const void *data);
97
98 void ol_rx_defrag_michdr(const struct ieee80211_frame *wh0, uint8_t hdr[]);
99
100 void
101 ol_rx_reorder_store_frag(ol_txrx_pdev_handle pdev,
102 struct ol_txrx_peer_t *peer,
103 unsigned int tid, uint16_t seq_num, qdf_nbuf_t frag);
104
105 qdf_nbuf_t
106 ol_rx_defrag_decap_recombine(htt_pdev_handle htt_pdev,
107 qdf_nbuf_t frag_list, uint16_t hdrsize);
108
109 int
110 ol_rx_defrag_mic(ol_txrx_pdev_handle pdev,
111 const uint8_t *key,
112 qdf_nbuf_t wbuf,
113 uint16_t off, uint16_t data_len, uint8_t mic[]);
114
115 void
116 ol_rx_reorder_flush_frag(htt_pdev_handle htt_pdev,
117 struct ol_txrx_peer_t *peer,
118 unsigned int tid, uint16_t seq_num);
119
xor_block(uint8_t * b,const uint8_t * a,qdf_size_t len)120 static inline void xor_block(uint8_t *b, const uint8_t *a, qdf_size_t len)
121 {
122 qdf_size_t i;
123
124 for (i = 0; i < len; i++)
125 b[i] ^= a[i];
126 }
127
rotl(uint32_t val,int bits)128 static inline uint32_t rotl(uint32_t val, int bits)
129 {
130 return (val << bits) | (val >> (32 - bits));
131 }
132
rotr(uint32_t val,int bits)133 static inline uint32_t rotr(uint32_t val, int bits)
134 {
135 return (val >> bits) | (val << (32 - bits));
136 }
137
xswap(uint32_t val)138 static inline uint32_t xswap(uint32_t val)
139 {
140 return ((val & 0x00ff00ff) << 8) | ((val & 0xff00ff00) >> 8);
141 }
142
143 static inline uint32_t
get_le32_split(uint8_t b0,uint8_t b1,uint8_t b2,uint8_t b3)144 get_le32_split(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3)
145 {
146 return b0 | (b1 << 8) | (b2 << 16) | (b3 << 24);
147 }
148
get_le32(const uint8_t * p)149 static inline uint32_t get_le32(const uint8_t *p)
150 {
151 return get_le32_split(p[0], p[1], p[2], p[3]);
152 }
153
put_le32(uint8_t * p,uint32_t v)154 static inline void put_le32(uint8_t *p, uint32_t v)
155 {
156 p[0] = (v) & 0xff;
157 p[1] = (v >> 8) & 0xff;
158 p[2] = (v >> 16) & 0xff;
159 p[3] = (v >> 24) & 0xff;
160 }
161
ol_rx_defrag_concat(qdf_nbuf_t dst,qdf_nbuf_t src)162 static inline uint8_t ol_rx_defrag_concat(qdf_nbuf_t dst, qdf_nbuf_t src)
163 {
164 /*
165 * Inside qdf_nbuf_cat, if it is necessary to reallocate dst
166 * to provide space for src, the headroom portion is copied from
167 * the original dst buffer to the larger new dst buffer.
168 * (This is needed, because the headroom of the dst buffer
169 * contains the rx desc.)
170 */
171 if (qdf_nbuf_cat(dst, src))
172 return OL_RX_DEFRAG_ERR;
173
174 /* Free source buffer */
175 qdf_nbuf_free(src);
176
177 return OL_RX_DEFRAG_OK;
178 }
179
180 #define michael_block(l, r) \
181 do { \
182 r ^= rotl(l, 17); \
183 l += r; \
184 r ^= xswap(l); \
185 l += r; \
186 r ^= rotl(l, 3); \
187 l += r; \
188 r ^= rotr(l, 2); \
189 l += r; \
190 } while (0)
191
192 #endif
193