1*5113495bSYour Name /*
2*5113495bSYour Name * Copyright (c) 2014-2019 The Linux Foundation. All rights reserved.
3*5113495bSYour Name *
4*5113495bSYour Name * Permission to use, copy, modify, and/or distribute this software for
5*5113495bSYour Name * any purpose with or without fee is hereby granted, provided that the
6*5113495bSYour Name * above copyright notice and this permission notice appear in all
7*5113495bSYour Name * copies.
8*5113495bSYour Name *
9*5113495bSYour Name * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10*5113495bSYour Name * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11*5113495bSYour Name * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12*5113495bSYour Name * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13*5113495bSYour Name * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14*5113495bSYour Name * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15*5113495bSYour Name * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16*5113495bSYour Name * PERFORMANCE OF THIS SOFTWARE.
17*5113495bSYour Name */
18*5113495bSYour Name
19*5113495bSYour Name /*========================================================================
20*5113495bSYour Name
21*5113495bSYour Name \file epping_main.c
22*5113495bSYour Name
23*5113495bSYour Name \brief WLAN End Point Ping test tool implementation
24*5113495bSYour Name
25*5113495bSYour Name ========================================================================*/
26*5113495bSYour Name
27*5113495bSYour Name /*--------------------------------------------------------------------------
28*5113495bSYour Name Include Files
29*5113495bSYour Name ------------------------------------------------------------------------*/
30*5113495bSYour Name #include <cds_api.h>
31*5113495bSYour Name #include <cds_sched.h>
32*5113495bSYour Name #include <linux/etherdevice.h>
33*5113495bSYour Name #include <linux/firmware.h>
34*5113495bSYour Name #include <linux/delay.h>
35*5113495bSYour Name #include <wni_api.h>
36*5113495bSYour Name #include <wlan_ptt_sock_svc.h>
37*5113495bSYour Name #include <linux/wireless.h>
38*5113495bSYour Name #include <net/cfg80211.h>
39*5113495bSYour Name #include <linux/rtnetlink.h>
40*5113495bSYour Name #include <linux/semaphore.h>
41*5113495bSYour Name #include <linux/delay.h>
42*5113495bSYour Name #include <linux/ctype.h>
43*5113495bSYour Name #include "epping_main.h"
44*5113495bSYour Name #include "epping_internal.h"
45*5113495bSYour Name
epping_cookie_init(epping_context_t * pEpping_ctx)46*5113495bSYour Name int epping_cookie_init(epping_context_t *pEpping_ctx)
47*5113495bSYour Name {
48*5113495bSYour Name uint32_t i, j;
49*5113495bSYour Name
50*5113495bSYour Name pEpping_ctx->cookie_list = NULL;
51*5113495bSYour Name pEpping_ctx->cookie_count = 0;
52*5113495bSYour Name for (i = 0; i < MAX_COOKIE_SLOTS_NUM; i++) {
53*5113495bSYour Name pEpping_ctx->s_cookie_mem[i] =
54*5113495bSYour Name qdf_mem_malloc(sizeof(struct epping_cookie) *
55*5113495bSYour Name MAX_COOKIE_SLOT_SIZE);
56*5113495bSYour Name if (!pEpping_ctx->s_cookie_mem[i])
57*5113495bSYour Name goto error;
58*5113495bSYour Name }
59*5113495bSYour Name qdf_spinlock_create(&pEpping_ctx->cookie_lock);
60*5113495bSYour Name
61*5113495bSYour Name for (i = 0; i < MAX_COOKIE_SLOTS_NUM; i++) {
62*5113495bSYour Name struct epping_cookie *cookie_mem = pEpping_ctx->s_cookie_mem[i];
63*5113495bSYour Name for (j = 0; j < MAX_COOKIE_SLOT_SIZE; j++) {
64*5113495bSYour Name epping_free_cookie(pEpping_ctx, &cookie_mem[j]);
65*5113495bSYour Name }
66*5113495bSYour Name }
67*5113495bSYour Name return 0;
68*5113495bSYour Name error:
69*5113495bSYour Name for (i = 0; i < MAX_COOKIE_SLOTS_NUM; i++) {
70*5113495bSYour Name if (pEpping_ctx->s_cookie_mem[i]) {
71*5113495bSYour Name qdf_mem_free(pEpping_ctx->s_cookie_mem[i]);
72*5113495bSYour Name pEpping_ctx->s_cookie_mem[i] = NULL;
73*5113495bSYour Name }
74*5113495bSYour Name }
75*5113495bSYour Name return -ENOMEM;
76*5113495bSYour Name }
77*5113495bSYour Name
78*5113495bSYour Name /* cleanup cookie queue */
epping_cookie_cleanup(epping_context_t * pEpping_ctx)79*5113495bSYour Name void epping_cookie_cleanup(epping_context_t *pEpping_ctx)
80*5113495bSYour Name {
81*5113495bSYour Name int i;
82*5113495bSYour Name qdf_spin_lock_bh(&pEpping_ctx->cookie_lock);
83*5113495bSYour Name pEpping_ctx->cookie_list = NULL;
84*5113495bSYour Name pEpping_ctx->cookie_count = 0;
85*5113495bSYour Name qdf_spin_unlock_bh(&pEpping_ctx->cookie_lock);
86*5113495bSYour Name for (i = 0; i < MAX_COOKIE_SLOTS_NUM; i++) {
87*5113495bSYour Name if (pEpping_ctx->s_cookie_mem[i]) {
88*5113495bSYour Name qdf_mem_free(pEpping_ctx->s_cookie_mem[i]);
89*5113495bSYour Name pEpping_ctx->s_cookie_mem[i] = NULL;
90*5113495bSYour Name }
91*5113495bSYour Name }
92*5113495bSYour Name }
93*5113495bSYour Name
epping_free_cookie(epping_context_t * pEpping_ctx,struct epping_cookie * cookie)94*5113495bSYour Name void epping_free_cookie(epping_context_t *pEpping_ctx,
95*5113495bSYour Name struct epping_cookie *cookie)
96*5113495bSYour Name {
97*5113495bSYour Name qdf_spin_lock_bh(&pEpping_ctx->cookie_lock);
98*5113495bSYour Name cookie->next = pEpping_ctx->cookie_list;
99*5113495bSYour Name pEpping_ctx->cookie_list = cookie;
100*5113495bSYour Name pEpping_ctx->cookie_count++;
101*5113495bSYour Name qdf_spin_unlock_bh(&pEpping_ctx->cookie_lock);
102*5113495bSYour Name }
103*5113495bSYour Name
epping_alloc_cookie(epping_context_t * pEpping_ctx)104*5113495bSYour Name struct epping_cookie *epping_alloc_cookie(epping_context_t *pEpping_ctx)
105*5113495bSYour Name {
106*5113495bSYour Name struct epping_cookie *cookie;
107*5113495bSYour Name
108*5113495bSYour Name qdf_spin_lock_bh(&pEpping_ctx->cookie_lock);
109*5113495bSYour Name cookie = pEpping_ctx->cookie_list;
110*5113495bSYour Name if (cookie) {
111*5113495bSYour Name pEpping_ctx->cookie_list = cookie->next;
112*5113495bSYour Name pEpping_ctx->cookie_count--;
113*5113495bSYour Name }
114*5113495bSYour Name qdf_spin_unlock_bh(&pEpping_ctx->cookie_lock);
115*5113495bSYour Name return cookie;
116*5113495bSYour Name }
117*5113495bSYour Name
epping_get_dummy_mac_addr(tSirMacAddr macAddr)118*5113495bSYour Name void epping_get_dummy_mac_addr(tSirMacAddr macAddr)
119*5113495bSYour Name {
120*5113495bSYour Name macAddr[0] = 69; /* E */
121*5113495bSYour Name macAddr[1] = 80; /* P */
122*5113495bSYour Name macAddr[2] = 80; /* P */
123*5113495bSYour Name macAddr[3] = 73; /* I */
124*5113495bSYour Name macAddr[4] = 78; /* N */
125*5113495bSYour Name macAddr[5] = 71; /* G */
126*5113495bSYour Name }
127*5113495bSYour Name
epping_hex_dump(void * data,int buf_len,const char * str)128*5113495bSYour Name void epping_hex_dump(void *data, int buf_len, const char *str)
129*5113495bSYour Name {
130*5113495bSYour Name EPPING_LOG(QDF_TRACE_LEVEL_FATAL, "%s: E, %s", __func__, str);
131*5113495bSYour Name
132*5113495bSYour Name EPPING_HEX_DUMP(QDF_TRACE_LEVEL_INFO, data, buf_len);
133*5113495bSYour Name
134*5113495bSYour Name EPPING_LOG(QDF_TRACE_LEVEL_FATAL, "%s: X %s", __func__, str);
135*5113495bSYour Name }
136*5113495bSYour Name
epping_get_qdf_ctx(void)137*5113495bSYour Name void *epping_get_qdf_ctx(void)
138*5113495bSYour Name {
139*5113495bSYour Name qdf_device_t *qdf_ctx;
140*5113495bSYour Name
141*5113495bSYour Name qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
142*5113495bSYour Name return qdf_ctx;
143*5113495bSYour Name }
144*5113495bSYour Name
epping_log_packet(epping_adapter_t * adapter,EPPING_HEADER * eppingHdr,int ret,const char * str)145*5113495bSYour Name void epping_log_packet(epping_adapter_t *adapter,
146*5113495bSYour Name EPPING_HEADER *eppingHdr, int ret, const char *str)
147*5113495bSYour Name {
148*5113495bSYour Name if (eppingHdr->Cmd_h & EPPING_LOG_MASK) {
149*5113495bSYour Name EPPING_LOG(QDF_TRACE_LEVEL_FATAL,
150*5113495bSYour Name "%s: cmd = %d, seqNo = %u, flag = 0x%x, ret = %d, "
151*5113495bSYour Name "txCount = %lu, txDrop = %lu, txBytes = %lu,"
152*5113495bSYour Name "rxCount = %lu, rxDrop = %lu, rxBytes = %lu\n",
153*5113495bSYour Name str, eppingHdr->Cmd_h, eppingHdr->SeqNo,
154*5113495bSYour Name eppingHdr->CmdFlags_h, ret,
155*5113495bSYour Name adapter->stats.tx_packets,
156*5113495bSYour Name adapter->stats.tx_dropped,
157*5113495bSYour Name adapter->stats.tx_bytes,
158*5113495bSYour Name adapter->stats.rx_packets,
159*5113495bSYour Name adapter->stats.rx_dropped,
160*5113495bSYour Name adapter->stats.rx_bytes);
161*5113495bSYour Name }
162*5113495bSYour Name }
163*5113495bSYour Name
epping_log_stats(epping_adapter_t * adapter,const char * str)164*5113495bSYour Name void epping_log_stats(epping_adapter_t *adapter, const char *str)
165*5113495bSYour Name {
166*5113495bSYour Name EPPING_LOG(QDF_TRACE_LEVEL_FATAL,
167*5113495bSYour Name "%s: txCount = %lu, txDrop = %lu, tx_bytes = %lu, "
168*5113495bSYour Name "rxCount = %lu, rxDrop = %lu, rx_bytes = %lu, tx_acks = %u\n",
169*5113495bSYour Name str,
170*5113495bSYour Name adapter->stats.tx_packets,
171*5113495bSYour Name adapter->stats.tx_dropped,
172*5113495bSYour Name adapter->stats.tx_bytes,
173*5113495bSYour Name adapter->stats.rx_packets,
174*5113495bSYour Name adapter->stats.rx_dropped,
175*5113495bSYour Name adapter->stats.rx_bytes,
176*5113495bSYour Name adapter->pEpping_ctx->total_tx_acks);
177*5113495bSYour Name }
178*5113495bSYour Name
epping_set_kperf_flag(epping_adapter_t * adapter,HTC_ENDPOINT_ID eid,uint8_t kperf_flag)179*5113495bSYour Name void epping_set_kperf_flag(epping_adapter_t *adapter,
180*5113495bSYour Name HTC_ENDPOINT_ID eid, uint8_t kperf_flag)
181*5113495bSYour Name {
182*5113495bSYour Name adapter->pEpping_ctx->kperf_num_rx_recv[eid] = 0;
183*5113495bSYour Name adapter->pEpping_ctx->kperf_num_tx_acks[eid] = 0;
184*5113495bSYour Name }
185