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