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 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); 107 int getNdpScheduleUpdate(struct nlattr **tb_vendor, NanDataPathScheduleUpdateInd *event); 108 public: 109 NanCommand(wifi_handle handle, int id, u32 vendor_id, u32 subcmd); 110 static NanCommand* instance(wifi_handle handle); 111 virtual ~NanCommand(); 112 113 // This function implements creation of NAN specific Request 114 // based on the request type 115 virtual wifi_error create(); 116 virtual wifi_error requestEvent(); 117 virtual int handleResponse(WifiEvent &reply); 118 virtual int handleEvent(WifiEvent &event); 119 wifi_error setCallbackHandler(NanCallbackHandler nHandler); 120 121 122 //Functions to fill the vendor data appropriately 123 wifi_error putNanEnable(transaction_id id, const NanEnableRequest *pReq); 124 wifi_error putNanDisable(transaction_id id); 125 wifi_error putNanPublish(transaction_id id, const NanPublishRequest *pReq); 126 wifi_error putNanPublishCancel(transaction_id id, const NanPublishCancelRequest *pReq); 127 wifi_error putNanSubscribe(transaction_id id, const NanSubscribeRequest *pReq); 128 wifi_error putNanSubscribeCancel(transaction_id id, const NanSubscribeCancelRequest *pReq); 129 wifi_error putNanTransmitFollowup(transaction_id id, const NanTransmitFollowupRequest *pReq); 130 wifi_error putNanStats(transaction_id id, const NanStatsRequest *pReq); 131 wifi_error putNanConfig(transaction_id id, const NanConfigRequest *pReq); 132 wifi_error putNanTCA(transaction_id id, const NanTCARequest *pReq); 133 wifi_error putNanBeaconSdfPayload(transaction_id id, const NanBeaconSdfPayloadRequest *pReq); 134 wifi_error getNanStaParameter(wifi_interface_handle iface, NanStaParameter *pRsp); 135 wifi_error putNanCapabilities(transaction_id id); 136 wifi_error putNanDebugCommand(NanDebugParams debug, int debug_msg_length); 137 138 /* Functions for NAN error translation 139 For NanResponse, NanPublishTerminatedInd, NanSubscribeTerminatedInd, 140 NanDisabledInd, NanTransmitFollowupInd: 141 function to translate firmware specific errors 142 to generic freamework error along with the error string 143 */ 144 void NanErrorTranslation(NanInternalStatusType firmwareErrorRecvd, 145 u32 valueRcvd, 146 void *pRsp, 147 bool is_ndp_rsp); 148 }; 149 #endif /* __WIFI_HAL_NAN_COMMAND_H__ */ 150 151