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_NAN_COMMAND_H__
18 #define __WIFI_HAL_NAN_COMMAND_H__
19 
20 #include "common.h"
21 #include "cpp_bindings.h"
22 #include "wifi_hal.h"
23 #include "vendor_definitions.h"
24 #include "nan_cert.h"
25 
26 class NanCommand : public WifiVendorCommand
27 {
28 private:
29     NanCallbackHandler mHandler;
30     char *mNanVendorEvent;
31     u32 mNanDataLen;
32     NanStaParameter *mStaParam;
33 
34     //Function to check the initial few bytes of data to
35     //determine whether NanResponse or NanEvent
36     int isNanResponse();
37     //Function which unparses the data and calls the NotifyResponse
38     int handleNanResponse();
39     //Function which will parse the mVendorData and gets
40     // the rsp_data appropriately.
41     int getNanResponse(transaction_id *id, NanResponseMsg *pRsp);
42     //Function which will return the Nan Indication type based on
43     //the initial few bytes of mVendorData
44     NanIndicationType getIndicationType();
45     //Function which calls the necessaryIndication callback
46     //based on the indication type
47     int handleNanIndication();
48     //Various Functions to get the appropriate indications
49     int getNanPublishTerminated(NanPublishTerminatedInd *event);
50     int getNanMatch(NanMatchInd *event);
51     int getNanMatchExpired(NanMatchExpiredInd *event);
52     int getNanSubscribeTerminated(NanSubscribeTerminatedInd *event);
53     int getNanFollowup(NanFollowupInd *event);
54     int getNanDiscEngEvent(NanDiscEngEventInd *event);
55     int getNanDisabled(NanDisabledInd *event);
56     int getNanTca(NanTCAInd *event);
57     int getNanBeaconSdfPayload(NanBeaconSdfPayloadInd *event);
58     //Internal cleanup function
59     void cleanup();
60 
61     static NanCommand *mNanCommandInstance;
62 
63     // Other private helper functions
64     int calcNanTransmitPostDiscoverySize(
65         const NanTransmitPostDiscovery *pPostDiscovery);
66     void fillNanSocialChannelParamVal(
67         const NanSocialChannelScanParams *pScanParams,
68         u32* pChannelParamArr);
69     u32 getNanTransmitPostConnectivityCapabilityVal(
70         const NanTransmitPostConnectivityCapability *pCapab);
71     void fillNanTransmitPostDiscoveryVal(
72         const NanTransmitPostDiscovery *pTxDisc,
73         u8 *pOutValue);
74     int calcNanFurtherAvailabilityMapSize(
75         const NanFurtherAvailabilityMap *pFam);
76     void fillNanFurtherAvailabilityMapVal(
77         const NanFurtherAvailabilityMap *pFam,
78         u8 *pOutValue);
79 
80     void getNanReceivePostConnectivityCapabilityVal(
81         const u8* pInValue,
82         NanReceivePostConnectivityCapability *pRxCapab);
83     void getNanReceiveSdeaCtrlParams(const u8* pInValue,
84         NanSdeaCtrlParams *pPeerSdeaParams);
85     int getNanReceivePostDiscoveryVal(const u8 *pInValue,
86                                       u32 length,
87                                       NanReceivePostDiscovery *pRxDisc);
88     int getNanFurtherAvailabilityMap(const u8 *pInValue,
89                                      u32 length,
90                                      u8* num_chans,
91                                      NanFurtherAvailabilityChannel *pFac);
92     void handleNanStatsResponse(NanStatsType stats_type,
93                                 char* rspBuf,
94                                 NanStatsResponse *pRsp,
95                                 u32 message_len);
96 
97     //Function which unparses the data and calls the NotifyResponse
98     int handleNdpResponse(NanResponseType ndpCmdtyp, struct nlattr **tb_vendor);
99     int handleNdpIndication(u32 ndpCmdType, struct nlattr **tb_vendor);
100     int getNdpRequest(struct nlattr **tb_vendor, NanDataPathRequestInd *event);
101     int getNdpConfirm(struct nlattr **tb_vendor, NanDataPathConfirmInd *event);
102     int getNdpEnd(struct nlattr **tb_vendor, NanDataPathEndInd *event);
103     int getNanTransmitFollowupInd(NanTransmitFollowupInd *event);
104     int getNanRangeRequestReceivedInd(NanRangeRequestInd *event);
105     int getNanRangeReportInd(NanRangeReportInd *event);
106 public:
107     NanCommand(wifi_handle handle, int id, u32 vendor_id, u32 subcmd);
108     static NanCommand* instance(wifi_handle handle);
109     virtual ~NanCommand();
110 
111     // This function implements creation of NAN specific Request
112     // based on  the request type
113     virtual int create();
114     virtual int requestEvent();
115     virtual int handleResponse(WifiEvent &reply);
116     virtual int handleEvent(WifiEvent &event);
117     int setCallbackHandler(NanCallbackHandler nHandler);
118 
119 
120     //Functions to fill the vendor data appropriately
121     int putNanEnable(transaction_id id, const NanEnableRequest *pReq);
122     int putNanDisable(transaction_id id);
123     int putNanPublish(transaction_id id, const NanPublishRequest *pReq);
124     int putNanPublishCancel(transaction_id id, const NanPublishCancelRequest *pReq);
125     int putNanSubscribe(transaction_id id, const NanSubscribeRequest *pReq);
126     int putNanSubscribeCancel(transaction_id id, const NanSubscribeCancelRequest *pReq);
127     int putNanTransmitFollowup(transaction_id id, const NanTransmitFollowupRequest *pReq);
128     int putNanStats(transaction_id id, const NanStatsRequest *pReq);
129     int putNanConfig(transaction_id id, const NanConfigRequest *pReq);
130     int putNanTCA(transaction_id id, const NanTCARequest *pReq);
131     int putNanBeaconSdfPayload(transaction_id id, const NanBeaconSdfPayloadRequest *pReq);
132     int getNanStaParameter(wifi_interface_handle iface, NanStaParameter *pRsp);
133     int putNanCapabilities(transaction_id id);
134     int putNanDebugCommand(NanDebugParams debug, int debug_msg_length);
135 
136     /* Functions for NAN error translation
137        For NanResponse, NanPublishTerminatedInd, NanSubscribeTerminatedInd,
138        NanDisabledInd, NanTransmitFollowupInd:
139        function to translate firmware specific errors
140        to generic freamework error along with the error string
141     */
142     void NanErrorTranslation(NanInternalStatusType firmwareErrorRecvd,
143                              u32 valueRcvd,
144                              void *pRsp);
145 };
146 #endif /* __WIFI_HAL_NAN_COMMAND_H__ */
147 
148