1/*
2 * MibDbg.c
3 *
4 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 *  * Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *  * Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in
15 *    the documentation and/or other materials provided with the
16 *    distribution.
17 *  * Neither the name Texas Instruments nor the names of its
18 *    contributors may be used to endorse or promote products derived
19 *    from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/***************************************************************************/
35/*                                                                         */
36/*    MODULE:   MibDbg.c                                                 */
37/*    PURPOSE:  MIB debug implementation                                    */
38/*                                                                         */
39/***************************************************************************/
40
41#include "MibDbg.h"
42#include "TWDriver.h"
43#include "report.h"
44#include "osApi.h"
45
46/*
47 ***********************************************************************
48 *	Internal functions definitions
49 ***********************************************************************
50 */
51
52static void mibDbgGetArpIpTable(TI_HANDLE hTWD)
53{
54	TI_STATUS status = TI_OK;
55    TMib mib;
56    TI_INT32 i;
57
58	/* init */
59	mib.aMib = MIB_arpIpAddressesTable;
60	mib.aData.ArpIpAddressesTable.FilteringEnable = 0;
61	for ( i = 0 ; i < IP_V4_ADDR_LEN ; i++ )
62	{
63		mib.aData.ArpIpAddressesTable.addr[i] = 0;
64	}
65
66	status = TWD_ReadMib(hTWD,NULL,NULL,(void*)&mib);
67	if (status != TI_OK)
68	{
69		WLAN_OS_REPORT(("Get ARP Table failed\n"));
70		return;
71	}
72
73	/* print ARP Table */
74    WLAN_OS_REPORT(("ARP IP Table:\n"));
75    WLAN_OS_REPORT(("FilteringEnable: %s (%d)\n",
76				   (mib.aData.ArpIpAddressesTable.FilteringEnable)?"Enable":"Disable",
77				   mib.aData.ArpIpAddressesTable.FilteringEnable));
78    WLAN_OS_REPORT(("ArpIpAddress: %d.%d.%d.%d\n",
79					mib.aData.ArpIpAddressesTable.addr[0],
80					mib.aData.ArpIpAddressesTable.addr[1],
81					mib.aData.ArpIpAddressesTable.addr[2],
82					mib.aData.ArpIpAddressesTable.addr[3]));
83}
84
85static void mibDbgGetGroupAddressTable(TI_HANDLE hTWD)
86{
87	TI_STATUS status = TI_OK;
88    TMib mib;
89    TI_INT32 i,j;
90
91	/* init */
92	mib.aMib 										= MIB_dot11GroupAddressesTable;
93	mib.aData.GroupAddressTable.bFilteringEnable 	= 0;
94	mib.aData.GroupAddressTable.nNumberOfAddresses 	= 0;
95    for ( i = 0 ; i < MIB_MAX_MULTICAST_GROUP_ADDRS ; i++ )
96	{
97		for ( j = 0 ; j < MAC_ADDR_LEN ; j++ )
98		{
99			mib.aData.GroupAddressTable.aGroupTable[i][j]	= 0;
100		}
101	}
102
103	status = TWD_ReadMib(hTWD,NULL,NULL,(void*)&mib);
104	if (status != TI_OK)
105	{
106		WLAN_OS_REPORT(("Get Group Address Table failed\n"));
107		return;
108	}
109
110	/* print Group Address Table */
111    WLAN_OS_REPORT(("Group addresses Table:\n"));
112    WLAN_OS_REPORT(("FilteringEnable: %s (%d)\n",
113				   (mib.aData.GroupAddressTable.bFilteringEnable)?"Enable":"Disable",
114				   mib.aData.GroupAddressTable.bFilteringEnable));
115    WLAN_OS_REPORT(("nNumberOfAddresses: %d\n",
116				   mib.aData.GroupAddressTable.nNumberOfAddresses));
117
118    WLAN_OS_REPORT(("Group addresses: \n"));
119    for ( i = 0 ; i < MIB_MAX_MULTICAST_GROUP_ADDRS ; i++ )
120		WLAN_OS_REPORT(("%x:%x:%x:%x:%x:%x\n",
121						mib.aData.GroupAddressTable.aGroupTable[i][0],
122						mib.aData.GroupAddressTable.aGroupTable[i][1],
123						mib.aData.GroupAddressTable.aGroupTable[i][2],
124						mib.aData.GroupAddressTable.aGroupTable[i][3],
125						mib.aData.GroupAddressTable.aGroupTable[i][4],
126						mib.aData.GroupAddressTable.aGroupTable[i][5]));
127}
128
129static void mibDbgGetCounterTable(TI_HANDLE hTWD)
130{
131	TI_STATUS status = TI_OK;
132    TMib mib;
133
134	/* init */
135	mib.aMib 								= MIB_countersTable;
136	mib.aData.CounterTable.FCSErrorCount	= 0;
137	mib.aData.CounterTable.PLCPErrorCount	= 0;
138	mib.aData.CounterTable.SeqNumMissCount	= 0;
139
140	status = TWD_ReadMib(hTWD,NULL,NULL,(void*)&mib);
141	if (status != TI_OK)
142	{
143		WLAN_OS_REPORT(("Get Counter Table failed\n"));
144		return;
145	}
146
147	/* print Counter Table */
148    WLAN_OS_REPORT(("FCS error count= %d \nPLCP  error count = %d \nSeq error count= %d\n",
149					mib.aData.CounterTable.FCSErrorCount,
150					mib.aData.CounterTable.PLCPErrorCount,
151					mib.aData.CounterTable.SeqNumMissCount));
152
153}
154
155static void mibDbgModifyCtsToSelf(TI_HANDLE hTWD, void* pParam)
156{
157	TI_STATUS status = TI_OK;
158    TMib mib;
159
160	if (pParam == NULL)
161	{
162		WLAN_OS_REPORT(("Modify CTS To Self failed: No Parameter received\n"));
163		return;
164	}
165
166	/* init */
167	mib.aMib					= MIB_ctsToSelf;
168	mib.aData.CTSToSelfEnable 	= 0;
169	mib.aData.CTSToSelfEnable 	= *(TI_UINT32*)pParam;
170
171	status = TWD_WriteMib(hTWD, &mib);
172	if (status != TI_OK)
173	{
174		WLAN_OS_REPORT(("Modify CTS To Self failed\n"));
175		return;
176	}
177	WLAN_OS_REPORT(("Modify CTS To Self OK\n"));
178
179	WLAN_OS_REPORT(("CtsToSelf = %s (%d)\n",
180				   mib.aData.CTSToSelfEnable?"Enable":"Disable",
181				   mib.aData.CTSToSelfEnable));
182	WLAN_OS_REPORT(("CTS to self: [0 - Disable, 1 - Enable]\n"));
183}
184
185static void mibDbgGetCtsToSelf(TI_HANDLE hTWD)
186{
187	TI_STATUS status = TI_OK;
188    TMib mib;
189
190	/* init */
191	mib.aMib					= MIB_ctsToSelf;
192	mib.aData.CTSToSelfEnable 	= 0;
193
194	status = TWD_ReadMib(hTWD,NULL,NULL,(void*)&mib);
195	if (status != TI_OK)
196	{
197		WLAN_OS_REPORT(("Get CTS To Self failed\n"));
198		return;
199	}
200
201	WLAN_OS_REPORT(("CtsToSelf = %s (%d)\n",
202				   mib.aData.CTSToSelfEnable?"Enable":"Disable",
203				   mib.aData.CTSToSelfEnable));
204	WLAN_OS_REPORT(("CTS to self: [0 - Disable, 1 - Enable]\n"));
205}
206
207static void mibDbgSetMaxRxLifetime(TI_HANDLE hTWD, void* pParam)
208{
209	TI_STATUS status = TI_OK;
210    TMib mib;
211
212	if (pParam == NULL)
213	{
214		WLAN_OS_REPORT(("Set Maximum Rx Life Time failed: No Parameter received\n"));
215		return;
216	}
217
218	/* init */
219	mib.aMib 						= MIB_dot11MaxReceiveLifetime;
220	mib.aData.MaxReceiveLifeTime 	= *(TI_UINT32*)pParam;
221
222	status = TWD_WriteMib(hTWD, &mib);
223	if (status != TI_OK)
224	{
225		WLAN_OS_REPORT(("Set Maximum Rx Life Time failed\n"));
226		return;
227	}
228}
229
230/*
231 ***********************************************************************
232 *	External functions definitions
233 ***********************************************************************
234 */
235void mibDbgPrintFunctions(void)
236{
237	WLAN_OS_REPORT(("\n          MIB Dbg Functions   \n"));
238	WLAN_OS_REPORT(("--------------------------------------\n"));
239
240	WLAN_OS_REPORT(("2101 - Print ARP Table\n"));
241	WLAN_OS_REPORT(("2102 - Print Group Address Table\n"));
242	WLAN_OS_REPORT(("2103 - Print Counter Table\n"));
243	WLAN_OS_REPORT(("2104 - Print Modify CTS to Self\n"));
244	WLAN_OS_REPORT(("2105 - Print Max RX Life Time\n"));
245}
246
247void MibDebugFunction(TI_HANDLE hTWD ,TI_UINT32 funcType, void* pParam)
248{
249	if (hTWD == NULL)
250	{
251		return;
252	}
253
254	switch (funcType)
255	{
256	case DBG_MIB_PRINT_HELP:
257		mibDbgPrintFunctions();
258		break;
259	case DBG_MIB_GET_ARP_TABLE:
260		mibDbgGetArpIpTable(hTWD);
261		break;
262	case DBG_MIB_GET_GROUP_ADDRESS_TABLE:
263		mibDbgGetGroupAddressTable(hTWD);
264		break;
265	case DBG_MIB_GET_COUNTER_TABLE:
266		mibDbgGetCounterTable(hTWD);
267		break;
268	case DBG_MIB_MODIFY_CTS_TO_SELF:
269		mibDbgModifyCtsToSelf(hTWD, pParam);
270		break;
271	case DBG_MIB_GET_CTS_TO_SELF:
272		mibDbgGetCtsToSelf(hTWD);
273		break;
274	case DBG_MIB_SET_MAX_RX_LIFE_TIME:
275		mibDbgSetMaxRxLifetime(hTWD, pParam);
276		break;
277	default:
278        WLAN_OS_REPORT(("MIB Debug: Invalid function type in MIB Debug function: %d\n", funcType));
279		break;
280	}
281}
282