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
26class NanCommand : public WifiVendorCommand
27{
28private:
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 getNanPublishReplied(NanPublishRepliedInd *event);
50    int getNanPublishTerminated(NanPublishTerminatedInd *event);
51    int getNanMatch(NanMatchInd *event);
52    int getNanMatchExpired(NanMatchExpiredInd *event);
53    int getNanSubscribeTerminated(NanSubscribeTerminatedInd *event);
54    int getNanFollowup(NanFollowupInd *event);
55    int getNanDiscEngEvent(NanDiscEngEventInd *event);
56    int getNanDisabled(NanDisabledInd *event);
57    int getNanTca(NanTCAInd *event);
58    int getNanBeaconSdfPayload(NanBeaconSdfPayloadInd *event);
59    //Internal cleanup function
60    void cleanup();
61
62    static NanCommand *mNanCommandInstance;
63
64    // Other private helper functions
65    int calcNanTransmitPostDiscoverySize(
66        const NanTransmitPostDiscovery *pPostDiscovery);
67    void fillNanSocialChannelParamVal(
68        const NanSocialChannelScanParams *pScanParams,
69        u32* pChannelParamArr);
70    u32 getNanTransmitPostConnectivityCapabilityVal(
71        const NanTransmitPostConnectivityCapability *pCapab);
72    void fillNanTransmitPostDiscoveryVal(
73        const NanTransmitPostDiscovery *pTxDisc,
74        u8 *pOutValue);
75    int calcNanFurtherAvailabilityMapSize(
76        const NanFurtherAvailabilityMap *pFam);
77    void fillNanFurtherAvailabilityMapVal(
78        const NanFurtherAvailabilityMap *pFam,
79        u8 *pOutValue);
80
81    void getNanReceivePostConnectivityCapabilityVal(
82        const u8* pInValue,
83        NanReceivePostConnectivityCapability *pRxCapab);
84    void getNanReceiveSdeaCtrlParams(const u8* pInValue,
85        NanSdeaCtrlParams *pPeerSdeaParams);
86    int getNanReceivePostDiscoveryVal(const u8 *pInValue,
87                                      u32 length,
88                                      NanReceivePostDiscovery *pRxDisc);
89    int getNanFurtherAvailabilityMap(const u8 *pInValue,
90                                     u32 length,
91                                     u8* num_chans,
92                                     NanFurtherAvailabilityChannel *pFac);
93    void handleNanStatsResponse(NanStatsType stats_type,
94                                char* rspBuf,
95                                NanStatsResponse *pRsp,
96                                u32 message_len);
97
98    //Function which unparses the data and calls the NotifyResponse
99    int handleNdpResponse(NanResponseType ndpCmdtyp, struct nlattr **tb_vendor);
100    int handleNdpIndication(u32 ndpCmdType, struct nlattr **tb_vendor);
101    int getNdpRequest(struct nlattr **tb_vendor, NanDataPathRequestInd *event);
102    int getNdpConfirm(struct nlattr **tb_vendor, NanDataPathConfirmInd *event);
103    int getNdpEnd(struct nlattr **tb_vendor, NanDataPathEndInd *event);
104    int getNanTransmitFollowupInd(NanTransmitFollowupInd *event);
105    int getNanRangeRequestReceivedInd(NanRangeRequestInd *event);
106    int getNanRangeReportInd(NanRangeReportInd *event);
107public:
108    NanCommand(wifi_handle handle, int id, u32 vendor_id, u32 subcmd);
109    static NanCommand* instance(wifi_handle handle);
110    virtual ~NanCommand();
111
112    // This function implements creation of NAN specific Request
113    // based on  the request type
114    virtual int create();
115    virtual int requestEvent();
116    virtual int handleResponse(WifiEvent &reply);
117    virtual int handleEvent(WifiEvent &event);
118    int setCallbackHandler(NanCallbackHandler nHandler);
119
120
121    //Functions to fill the vendor data appropriately
122    int putNanEnable(transaction_id id, const NanEnableRequest *pReq);
123    int putNanDisable(transaction_id id);
124    int putNanPublish(transaction_id id, const NanPublishRequest *pReq);
125    int putNanPublishCancel(transaction_id id, const NanPublishCancelRequest *pReq);
126    int putNanSubscribe(transaction_id id, const NanSubscribeRequest *pReq);
127    int putNanSubscribeCancel(transaction_id id, const NanSubscribeCancelRequest *pReq);
128    int putNanTransmitFollowup(transaction_id id, const NanTransmitFollowupRequest *pReq);
129    int putNanStats(transaction_id id, const NanStatsRequest *pReq);
130    int putNanConfig(transaction_id id, const NanConfigRequest *pReq);
131    int putNanTCA(transaction_id id, const NanTCARequest *pReq);
132    int putNanBeaconSdfPayload(transaction_id id, const NanBeaconSdfPayloadRequest *pReq);
133    int getNanStaParameter(wifi_interface_handle iface, NanStaParameter *pRsp);
134    int putNanCapabilities(transaction_id id);
135    int putNanDebugCommand(NanDebugParams debug, int debug_msg_length);
136
137    /* Functions for NAN error translation
138       For NanResponse, NanPublishTerminatedInd, NanSubscribeTerminatedInd,
139       NanDisabledInd, NanTransmitFollowupInd:
140       function to translate firmware specific errors
141       to generic freamework error along with the error string
142    */
143    void NanErrorTranslation(NanInternalStatusType firmwareErrorRecvd,
144                             u32 valueRcvd,
145                             void *pRsp,
146                             bool is_ndp_rsp);
147};
148#endif /* __WIFI_HAL_NAN_COMMAND_H__ */
149
150