ol_rx_defrag.h 5.0 KB

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