epping_helper.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Copyright (c) 2014-2018 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. \file epping_main.c
  20. \brief WLAN End Point Ping test tool implementation
  21. ========================================================================*/
  22. /*--------------------------------------------------------------------------
  23. Include Files
  24. ------------------------------------------------------------------------*/
  25. #include <cds_api.h>
  26. #include <cds_sched.h>
  27. #include <linux/etherdevice.h>
  28. #include <linux/firmware.h>
  29. #include <linux/delay.h>
  30. #include <wni_api.h>
  31. #include <wlan_ptt_sock_svc.h>
  32. #include <linux/wireless.h>
  33. #include <net/cfg80211.h>
  34. #include <linux/rtnetlink.h>
  35. #include <linux/semaphore.h>
  36. #include <linux/delay.h>
  37. #include <linux/ctype.h>
  38. #include "epping_main.h"
  39. #include "epping_internal.h"
  40. int epping_cookie_init(epping_context_t *pEpping_ctx)
  41. {
  42. uint32_t i, j;
  43. pEpping_ctx->cookie_list = NULL;
  44. pEpping_ctx->cookie_count = 0;
  45. for (i = 0; i < MAX_COOKIE_SLOTS_NUM; i++) {
  46. pEpping_ctx->s_cookie_mem[i] =
  47. qdf_mem_malloc(sizeof(struct epping_cookie) *
  48. MAX_COOKIE_SLOT_SIZE);
  49. if (pEpping_ctx->s_cookie_mem[i] == NULL) {
  50. EPPING_LOG(QDF_TRACE_LEVEL_FATAL,
  51. "%s: no mem for cookie (idx = %d)", __func__,
  52. i);
  53. goto error;
  54. }
  55. }
  56. qdf_spinlock_create(&pEpping_ctx->cookie_lock);
  57. for (i = 0; i < MAX_COOKIE_SLOTS_NUM; i++) {
  58. struct epping_cookie *cookie_mem = pEpping_ctx->s_cookie_mem[i];
  59. for (j = 0; j < MAX_COOKIE_SLOT_SIZE; j++) {
  60. epping_free_cookie(pEpping_ctx, &cookie_mem[j]);
  61. }
  62. }
  63. return 0;
  64. error:
  65. for (i = 0; i < MAX_COOKIE_SLOTS_NUM; i++) {
  66. if (pEpping_ctx->s_cookie_mem[i]) {
  67. qdf_mem_free(pEpping_ctx->s_cookie_mem[i]);
  68. pEpping_ctx->s_cookie_mem[i] = NULL;
  69. }
  70. }
  71. return -ENOMEM;
  72. }
  73. /* cleanup cookie queue */
  74. void epping_cookie_cleanup(epping_context_t *pEpping_ctx)
  75. {
  76. int i;
  77. qdf_spin_lock_bh(&pEpping_ctx->cookie_lock);
  78. pEpping_ctx->cookie_list = NULL;
  79. pEpping_ctx->cookie_count = 0;
  80. qdf_spin_unlock_bh(&pEpping_ctx->cookie_lock);
  81. for (i = 0; i < MAX_COOKIE_SLOTS_NUM; i++) {
  82. if (pEpping_ctx->s_cookie_mem[i]) {
  83. qdf_mem_free(pEpping_ctx->s_cookie_mem[i]);
  84. pEpping_ctx->s_cookie_mem[i] = NULL;
  85. }
  86. }
  87. }
  88. void epping_free_cookie(epping_context_t *pEpping_ctx,
  89. struct epping_cookie *cookie)
  90. {
  91. qdf_spin_lock_bh(&pEpping_ctx->cookie_lock);
  92. cookie->next = pEpping_ctx->cookie_list;
  93. pEpping_ctx->cookie_list = cookie;
  94. pEpping_ctx->cookie_count++;
  95. qdf_spin_unlock_bh(&pEpping_ctx->cookie_lock);
  96. }
  97. struct epping_cookie *epping_alloc_cookie(epping_context_t *pEpping_ctx)
  98. {
  99. struct epping_cookie *cookie;
  100. qdf_spin_lock_bh(&pEpping_ctx->cookie_lock);
  101. cookie = pEpping_ctx->cookie_list;
  102. if (cookie != NULL) {
  103. pEpping_ctx->cookie_list = cookie->next;
  104. pEpping_ctx->cookie_count--;
  105. }
  106. qdf_spin_unlock_bh(&pEpping_ctx->cookie_lock);
  107. return cookie;
  108. }
  109. void epping_get_dummy_mac_addr(tSirMacAddr macAddr)
  110. {
  111. macAddr[0] = 69; /* E */
  112. macAddr[1] = 80; /* P */
  113. macAddr[2] = 80; /* P */
  114. macAddr[3] = 73; /* I */
  115. macAddr[4] = 78; /* N */
  116. macAddr[5] = 71; /* G */
  117. }
  118. void epping_hex_dump(void *data, int buf_len, const char *str)
  119. {
  120. char *buf = (char *)data;
  121. int i;
  122. printk("%s: E, %s\n", __func__, str);
  123. for (i = 0; (i + 7) < buf_len; i += 8) {
  124. printk("%02x %02x %02x %02x %02x %02x %02x %02x\n",
  125. buf[i],
  126. buf[i + 1],
  127. buf[i + 2],
  128. buf[i + 3],
  129. buf[i + 4], buf[i + 5], buf[i + 6], buf[i + 7]);
  130. }
  131. /* Dump the bytes in the last line */
  132. for (; i < buf_len; i++) {
  133. printk("%02x ", buf[i]);
  134. }
  135. printk("\n%s: X %s\n", __func__, str);
  136. }
  137. void *epping_get_qdf_ctx(void)
  138. {
  139. qdf_device_t *qdf_ctx;
  140. qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
  141. return qdf_ctx;
  142. }
  143. void epping_log_packet(epping_adapter_t *adapter,
  144. EPPING_HEADER *eppingHdr, int ret, const char *str)
  145. {
  146. if (eppingHdr->Cmd_h & EPPING_LOG_MASK) {
  147. EPPING_LOG(QDF_TRACE_LEVEL_FATAL,
  148. "%s: cmd = %d, seqNo = %u, flag = 0x%x, ret = %d, "
  149. "txCount = %lu, txDrop = %lu, txBytes = %lu,"
  150. "rxCount = %lu, rxDrop = %lu, rxBytes = %lu\n",
  151. str, eppingHdr->Cmd_h, eppingHdr->SeqNo,
  152. eppingHdr->CmdFlags_h, ret,
  153. adapter->stats.tx_packets,
  154. adapter->stats.tx_dropped,
  155. adapter->stats.tx_bytes,
  156. adapter->stats.rx_packets,
  157. adapter->stats.rx_dropped,
  158. adapter->stats.rx_bytes);
  159. }
  160. }
  161. void epping_log_stats(epping_adapter_t *adapter, const char *str)
  162. {
  163. EPPING_LOG(QDF_TRACE_LEVEL_FATAL,
  164. "%s: txCount = %lu, txDrop = %lu, tx_bytes = %lu, "
  165. "rxCount = %lu, rxDrop = %lu, rx_bytes = %lu, tx_acks = %u\n",
  166. str,
  167. adapter->stats.tx_packets,
  168. adapter->stats.tx_dropped,
  169. adapter->stats.tx_bytes,
  170. adapter->stats.rx_packets,
  171. adapter->stats.rx_dropped,
  172. adapter->stats.rx_bytes,
  173. adapter->pEpping_ctx->total_tx_acks);
  174. }
  175. void epping_set_kperf_flag(epping_adapter_t *adapter,
  176. HTC_ENDPOINT_ID eid, uint8_t kperf_flag)
  177. {
  178. adapter->pEpping_ctx->kperf_num_rx_recv[eid] = 0;
  179. adapter->pEpping_ctx->kperf_num_tx_acks[eid] = 0;
  180. }