1 /* Copyright (c) 2015, The Linux Foundation. All rights reserved.
2  *
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions
5  * are met:
6  *  * Redistributions of source code must retain the above copyright
7  *    notice, this list of conditions and the following disclaimer.
8  *  * Redistributions in binary form must reproduce the above
9  *    copyright notice, this list of conditions and the following
10  *    disclaimer in the documentation and/or other materials provided
11  *    with the distribution.
12  *  * Neither the name of The Linux Foundation nor the names of its
13  *    contributors may be used to endorse or promote products derived
14  *    from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef __WIFI_HAL_WIFILOGGER_COMMAND_H__
30 #define __WIFI_HAL_WIFILOGGER_COMMAND_H__
31 
32 #include "common.h"
33 #include "cpp_bindings.h"
34 #include "wifi_logger.h"
35 #include "wifilogger_diag.h"
36 #include "vendor_definitions.h"
37 
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #endif /* __cplusplus */
42 
43 #define POWER_EVENTS_RB_BUF_SIZE 2048
44 #define POWER_EVENTS_NUM_BUFS    4
45 
46 #define CONNECTIVITY_EVENTS_RB_BUF_SIZE 4096
47 #define CONNECTIVITY_EVENTS_NUM_BUFS    4
48 
49 #define PKT_STATS_RB_BUF_SIZE 4096
50 #define PKT_STATS_NUM_BUFS    32
51 
52 #define DRIVER_PRINTS_RB_BUF_SIZE 4096
53 #define DRIVER_PRINTS_NUM_BUFS    128
54 
55 #define FIRMWARE_PRINTS_RB_BUF_SIZE 4096
56 #define FIRMWARE_PRINTS_NUM_BUFS    128
57 
58 enum rb_info_indices {
59     POWER_EVENTS_RB_ID = 0,
60     CONNECTIVITY_EVENTS_RB_ID = 1,
61     PKT_STATS_RB_ID = 2,
62     DRIVER_PRINTS_RB_ID = 3,
63     FIRMWARE_PRINTS_RB_ID = 4,
64 };
65 
66 typedef struct {
67   void (*on_firmware_memory_dump) (char *buffer,
68                                    int buffer_size);
69 
70 } WifiLoggerCallbackHandler;
71 
72 
73 class WifiLoggerCommand : public WifiVendorCommand
74 {
75 private:
76     WifiLoggerCallbackHandler mHandler;
77     char                      *mVersion;
78     int                       mVersionLen;
79     u32                       *mSupportedSet;
80     int                       mRequestId;
81     bool                      mWaitforRsp;
82     bool                      mMoreData;
83     WLAN_DRIVER_WAKE_REASON_CNT *mGetWakeStats;
84 public:
85 
86     WifiLoggerCommand(wifi_handle handle, int id, u32 vendor_id, u32 subcmd);
87 
88     static WifiLoggerCommand* instance(wifi_handle handle);
89     virtual ~WifiLoggerCommand();
90 
91     // This function implements creation of WifiLogger specific Request
92     // based on  the request type
93     virtual int create();
94     virtual int requestEvent();
95     virtual int requestResponse();
96     virtual int handleResponse(WifiEvent &reply);
97     virtual int handleEvent(WifiEvent &event);
98     int setCallbackHandler(WifiLoggerCallbackHandler nHandler);
99     virtual void unregisterHandler(u32 subCmd);
100 
101     /* Takes wait time in seconds. */
102     virtual int timed_wait(u16 wait_time);
103     virtual void waitForRsp(bool wait);
104     virtual void setVersionInfo(char *buffer, int buffer_size);
105     virtual void setFeatureSet(u32 *support);
106     virtual void getWakeStatsRspParams(
107                     WLAN_DRIVER_WAKE_REASON_CNT *wifi_wake_reason_cnt);
108 };
109 void rb_timerhandler(hal_info *info);
110 wifi_error wifi_logger_ring_buffers_init(hal_info *info);
111 void wifi_logger_ring_buffers_deinit(hal_info *info);
112 void push_out_all_ring_buffers(hal_info *info);
113 void send_alert(hal_info *info, int reason_code);
114 #ifdef __cplusplus
115 }
116 #endif /* __cplusplus */
117 #endif /* __WIFI_HAL_WIFILOGGER_COMMAND_H__ */
118