blob: 45b8c2874b33ef046ad82cba8e76630be52c113a [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Gopichand Nakkala92f07d82013-01-08 21:16:34 -08002 * Copyright (c) 2012-2013, 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/*
Jeff Johnson32d95a32012-09-10 13:15:23 -070022 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -070023 *
24 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
25 *
26 *
27 * Permission to use, copy, modify, and/or distribute this software for
28 * any purpose with or without fee is hereby granted, provided that the
29 * above copyright notice and this permission notice appear in all
30 * copies.
31 *
32 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
33 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
35 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
36 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
37 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
38 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
39 * PERFORMANCE OF THIS SOFTWARE.
40 */
41
42
43/*============================================================================
44 FILE: vos_diag.c
45
46 OVERVIEW: This source file contains definitions for vOS diag APIs
47
48 DEPENDENCIES:
49
50 Copyright (c) 2007 QUALCOMM Incorporated.
51 All Rights Reserved.
52 Qualcomm Confidential and Proprietary
53============================================================================*/
54
55#include "vos_types.h"
56#include "i_vos_diag_core_log.h"
57#include "i_vos_diag_core_event.h"
58#include "wlan_hdd_main.h"
59#include "wlan_nlink_common.h"
60#include "vos_sched.h"
61#include "wlan_ptt_sock_svc.h"
62
63
64#define PTT_MSG_DIAG_CMDS_TYPE 0x5050
65
66#define DIAG_TYPE_LOGS 1
67#define DIAG_TYPE_EVENTS 2
68
69#define DIAG_SWAP16(A) ((((tANI_U16)(A) & 0xff00) >> 8) | (((tANI_U16)(A) & 0x00ff) << 8))
70
71
72
73typedef struct event_report_s
74{
75 v_U32_t diag_type;
76 v_U16_t event_id;
77 v_U16_t length;
78} event_report_t;
79
80
81/**---------------------------------------------------------------------------
82
83 \brief vos_log_set_code() -
84
85 This function sets the logging code in the given log record.
86
87 \param - ptr - Pointer to the log header type.
88 - code - log code.
89 \return - None
90
91 --------------------------------------------------------------------------*/
92
93void vos_log_set_code (v_VOID_t *ptr, v_U16_t code)
94{
95 if (ptr)
96 {
97 /* All log packets are required to start with 'log_header_type'. */
98 ((log_hdr_type *) ptr)->code = code;
99 }
100
101}
102
103/**---------------------------------------------------------------------------
104
105 \brief vos_log_set_length() -
106
107 This function sets the length field in the given log record.
108
109 \param - ptr - Pointer to the log header type.
110 - length - log length.
111
112 \return - None
113
114 --------------------------------------------------------------------------*/
115
116void vos_log_set_length (v_VOID_t *ptr, v_U16_t length)
117{
118 if(ptr)
119 {
120 /* All log packets are required to start with 'log_header_type'. */
121 ((log_hdr_type *) ptr)->len = (v_U16_t) length;
122 }
123}
124
125/**---------------------------------------------------------------------------
126
127 \brief vos_log_submit() -
128
129 This function sends the log data to the ptt socket app only if it is registered with the driver.
130
131 \param - ptr - Pointer to the log header type.
132
133 \return - None
134
135 --------------------------------------------------------------------------*/
136
137void vos_log_submit(v_VOID_t *plog_hdr_ptr)
138{
139
140 log_hdr_type *pHdr = (log_hdr_type*) plog_hdr_ptr;
141
142 tAniHdr *wmsg = NULL;
143 v_U8_t *pBuf;
144 hdd_adapter_t *pAdapter;
145 v_CONTEXT_t pVosContext= NULL;
146 v_U16_t data_len;
147 v_U16_t total_len;
148
149
150 /*Get the global context */
151 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
152
153 /*Get the Hdd Context */
154 pAdapter = ((VosContextType*)(pVosContext))->pHDDContext;
155
156 /* Send the log data to the ptt app only if it is registered with the wlan driver*/
157 if(pAdapter->ptt_pid)
158 {
159 data_len = pHdr->len;
160
161 total_len = sizeof(tAniHdr)+sizeof(v_U32_t)+data_len;
162
163 pBuf = (v_U8_t*)vos_mem_malloc(total_len);
164
165 if(!pBuf)
166 {
167 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "vos_mem_malloc failed\n");
168 return;
169 }
170
171 vos_mem_zero((v_VOID_t*)pBuf,total_len);
172
173 wmsg = (tAniHdr*)pBuf;
174 wmsg->type = PTT_MSG_DIAG_CMDS_TYPE;
175 wmsg->length = total_len;
176 wmsg->length = DIAG_SWAP16(wmsg->length);
177 pBuf += sizeof(tAniHdr);
178
179
180 /* Diag Type events or log */
181 *(v_U32_t*)pBuf = DIAG_TYPE_LOGS;
182 pBuf += sizeof(v_U32_t);
183
184
185 memcpy(pBuf, pHdr,data_len);
186
187 if(pAdapter->ptt_pid)
188 {
189 if( ptt_sock_send_msg_to_app(wmsg, 0, ANI_NL_MSG_PUMAC, pAdapter->ptt_pid) < 0) {
190
191 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, ("Ptt Socket error sending message to the app!!\n"));
192 return;
193 }
194
195 }
196 vos_mem_free((v_VOID_t*)wmsg);
197 }
198 return;
199}
200
201/**---------------------------------------------------------------------------
202
203 \brief vos_event_report_payload() -
204
205 This function sends the event data to the ptt socket app only if it is registered with the driver.
206
207 \param - ptr - Pointer to the log header type.
208
209 \return - None
210
211 --------------------------------------------------------------------------*/
212
213void vos_event_report_payload(v_U16_t event_Id, v_U16_t length, v_VOID_t *pPayload)
214{
215
216
217 tAniHdr *wmsg = NULL;
218 v_U8_t *pBuf;
219 hdd_adapter_t *pAdapter;
220 v_CONTEXT_t pVosContext= NULL;
221 event_report_t *pEvent_report;
222 v_U16_t total_len;
223
224 /*Get the global context */
225 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
226
227 /*Get the Hdd Context */
228 pAdapter = ((VosContextType*)(pVosContext))->pHDDContext;
229
230
231 /* Send the log data to the ptt app only if it is registered with the wlan driver*/
232 if(pAdapter->ptt_pid)
233 {
234 total_len = sizeof(tAniHdr)+sizeof(event_report_t)+length;
235
236 pBuf = (v_U8_t*)vos_mem_malloc(total_len);
237
238 if(!pBuf)
239 {
240 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "vos_mem_malloc failed\n");
241 return;
242 }
243 wmsg = (tAniHdr*)pBuf;
244 wmsg->type = PTT_MSG_DIAG_CMDS_TYPE;
245 wmsg->length = total_len;
246 wmsg->length = DIAG_SWAP16(wmsg->length);
247 pBuf += sizeof(tAniHdr);
248
249 pEvent_report = (event_report_t*)pBuf;
250 pEvent_report->diag_type = DIAG_TYPE_EVENTS;
251 pEvent_report->event_id = event_Id;
252 pEvent_report->length = length;
253
254 pBuf += sizeof(event_report_t);
255
256 memcpy(pBuf, pPayload,length);
257
258 if( ptt_sock_send_msg_to_app(wmsg, 0, ANI_NL_MSG_PUMAC, pAdapter->ptt_pid) < 0) {
259
260 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, ("Ptt Socket error sending message to the app!!\n"));
261 return;
262 }
263
264 vos_mem_free((v_VOID_t*)wmsg);
265 }
266
267 return;
268
269}