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 
24 class NanCommand : public WifiVendorCommand
25 {
26 private:
27     NanCallbackHandler mHandler;
28     char *mNanVendorEvent;
29     u32 mNanDataLen;
30     NanStaParameter *mStaParam;
31 
32     //Function to check the initial few bytes of data to
33     //determine whether NanResponse or NanEvent
34     int isNanResponse();
35     //Function which unparses the data and calls the NotifyResponse
36     int handleNanResponse();
37     //Function which will parse the mVendorData and gets
38     // the rsp_data appropriately.
39     int getNanResponse(transaction_id *id, NanResponseMsg *pRsp);
40     //Function which will return the Nan Indication type based on
41     //the initial few bytes of mVendorData
42     NanIndicationType getIndicationType();
43     //Function which calls the necessaryIndication callback
44     //based on the indication type
45     int handleNanIndication();
46     //Various Functions to get the appropriate indications
47     int getNanPublishTerminated(NanPublishTerminatedInd *event);
48     int getNanMatch(NanMatchInd *event);
49     int getNanMatchExpired(NanMatchExpiredInd *event);
50     int getNanSubscribeTerminated(NanSubscribeTerminatedInd *event);
51     int getNanFollowup(NanFollowupInd *event);
52     int getNanDiscEngEvent(NanDiscEngEventInd *event);
53     int getNanDisabled(NanDisabledInd *event);
54     int getNanTca(NanTCAInd *event);
55     int getNanBeaconSdfPayload(NanBeaconSdfPayloadInd *event);
56     //Internal cleanup function
57     void cleanup();
58 
59     static NanCommand *mNanCommandInstance;
60 
61     // Other private helper functions
62     int calcNanTransmitPostDiscoverySize(
63         const NanTransmitPostDiscovery *pPostDiscovery);
64     void fillNanSocialChannelParamVal(
65         const NanSocialChannelScanParams *pScanParams,
66         u32* pChannelParamArr);
67     u32 getNanTransmitPostConnectivityCapabilityVal(
68         const NanTransmitPostConnectivityCapability *pCapab);
69     void fillNanTransmitPostDiscoveryVal(
70         const NanTransmitPostDiscovery *pTxDisc,
71         u8 *pOutValue);
72     int calcNanFurtherAvailabilityMapSize(
73         const NanFurtherAvailabilityMap *pFam);
74     void fillNanFurtherAvailabilityMapVal(
75         const NanFurtherAvailabilityMap *pFam,
76         u8 *pOutValue);
77 
78     void getNanReceivePostConnectivityCapabilityVal(
79         const u8* pInValue,
80         NanReceivePostConnectivityCapability *pRxCapab);
81     int getNanReceivePostDiscoveryVal(const u8 *pInValue,
82                                       u32 length,
83                                       NanReceivePostDiscovery *pRxDisc);
84     int getNanFurtherAvailabilityMap(const u8 *pInValue,
85                                      u32 length,
86                                      u8* num_chans,
87                                      NanFurtherAvailabilityChannel *pFac);
88     void handleNanStatsResponse(NanStatsType stats_type,
89                                 char* rspBuf,
90                                 NanStatsResponse *pRsp);
91 
92 public:
93     NanCommand(wifi_handle handle, int id, u32 vendor_id, u32 subcmd);
94     static NanCommand* instance(wifi_handle handle);
95     virtual ~NanCommand();
96 
97     // This function implements creation of NAN specific Request
98     // based on  the request type
99     virtual int create();
100     virtual int requestEvent();
101     virtual int handleResponse(WifiEvent &reply);
102     virtual int handleEvent(WifiEvent &event);
103     int setCallbackHandler(NanCallbackHandler nHandler);
104 
105 
106     //Functions to fill the vendor data appropriately
107     int putNanEnable(transaction_id id, const NanEnableRequest *pReq);
108     int putNanDisable(transaction_id id);
109     int putNanPublish(transaction_id id, const NanPublishRequest *pReq);
110     int putNanPublishCancel(transaction_id id, const NanPublishCancelRequest *pReq);
111     int putNanSubscribe(transaction_id id, const NanSubscribeRequest *pReq);
112     int putNanSubscribeCancel(transaction_id id, const NanSubscribeCancelRequest *pReq);
113     int putNanTransmitFollowup(transaction_id id, const NanTransmitFollowupRequest *pReq);
114     int putNanStats(transaction_id id, const NanStatsRequest *pReq);
115     int putNanConfig(transaction_id id, const NanConfigRequest *pReq);
116     int putNanTCA(transaction_id id, const NanTCARequest *pReq);
117     int putNanBeaconSdfPayload(transaction_id id, const NanBeaconSdfPayloadRequest *pReq);
118     int getNanStaParameter(wifi_interface_handle iface, NanStaParameter *pRsp);
119     int putNanCapabilities(transaction_id id);
120 };
121 #endif /* __WIFI_HAL_NAN_COMMAND_H__ */
122 
123