1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __WIFI_HAL_LLSTATSCOMMAND_H__
18 #define __WIFI_HAL_LLSTATSCOMMAND_H__
19 
20 #include <stdint.h>
21 #include <fcntl.h>
22 #include <sys/socket.h>
23 #include <netlink/genl/genl.h>
24 #include <netlink/genl/family.h>
25 #include <netlink/genl/ctrl.h>
26 #include <linux/rtnetlink.h>
27 #include <netpacket/packet.h>
28 #include <linux/filter.h>
29 #include <linux/errqueue.h>
30 
31 #include <linux/pkt_sched.h>
32 #include <netlink/object-api.h>
33 #include <netlink/netlink.h>
34 #include <netlink/socket.h>
35 #include <net/if.h>
36 
37 #include "nl80211_copy.h"
38 #include "common.h"
39 #include "cpp_bindings.h"
40 #include <hardware_legacy/link_layer_stats.h>
41 
42 #ifdef __GNUC__
43 #define PRINTF_FORMAT(a,b) __attribute__ ((format (printf, (a), (b))))
44 #define STRUCT_PACKED __attribute__ ((packed))
45 #else
46 #define PRINTF_FORMAT(a,b)
47 #define STRUCT_PACKED
48 #endif
49 
50 #ifdef __cplusplus
51 extern "C"
52 {
53 #endif /* __cplusplus */
54 
55 typedef struct{
56     u32 stats_clear_rsp_mask;
57     u8 stop_rsp;
58 } LLStatsClearRspParams;
59 
60 typedef struct{
61     wifi_iface_stat *iface_stat;
62     int num_radios;
63     wifi_radio_stat *radio_stat;
64 } LLStatsResultsParams;
65 
66 typedef enum{
67     eLLStatsSetParamsInvalid = 0,
68     eLLStatsClearRspParams,
69 } eLLStatsRspRarams;
70 
71 class LLStatsCommand: public WifiVendorCommand
72 {
73 private:
74     static LLStatsCommand *mLLStatsCommandInstance;
75 
76     LLStatsClearRspParams mClearRspParams;
77 
78     LLStatsResultsParams mResultsParams;
79 
80     wifi_stats_result_handler mHandler;
81 
82     wifi_request_id mRequestId;
83 
84     u32 mRadioStatsSize;
85 
86     // mNumRadios is decoded from tb_vendor[QCA_WLAN_VENDOR_ATTR_LL_STATS_NUM_RADIOS]
87     // nNumRadiosAllocated is the actual radio stats received.
88     u8 mNumRadios;
89     u8 mNumRadiosAllocated;
90 
91     LLStatsCommand(wifi_handle handle, int id, u32 vendor_id, u32 subcmd);
92 
93 public:
94     static LLStatsCommand* instance(wifi_handle handle);
95 
96     virtual ~LLStatsCommand();
97 
98     // This function implements creation of LLStats specific Request
99     // based on  the request type
100     virtual wifi_error create();
101 
102     virtual void setSubCmd(u32 subcmd);
103 
104     virtual void initGetContext(u32 reqid);
105 
106     virtual wifi_error requestResponse();
107 
108     virtual wifi_error notifyResponse();
109 
110     virtual int handleResponse(WifiEvent &reply);
111 
112     virtual void getClearRspParams(u32 *stats_clear_rsp_mask, u8 *stop_rsp);
113 
114     virtual wifi_error get_wifi_iface_stats(wifi_iface_stat *stats,
115                                             struct nlattr **tb_vendor);
116 
117     virtual void setHandler(wifi_stats_result_handler handler);
118 
119     virtual void clearStats();
120 };
121 
122 #ifdef __cplusplus
123 }
124 #endif /* __cplusplus */
125 #endif
126