Wifi-Hal: Introduce support for NAN Publish Replied Ind

Bring in support for NAN Publish Replied Indication.

Bug: 35195773
Test: integration (sl4a) tests
Change-Id: I9751e4cb498a2e99f90a81e7c4119eff66cdb8e6
CRs-Fixed: 2079318
diff --git a/qcwcn/wifi_hal/nan_i.h b/qcwcn/wifi_hal/nan_i.h
index 7202751..b0b33eb 100644
--- a/qcwcn/wifi_hal/nan_i.h
+++ b/qcwcn/wifi_hal/nan_i.h
@@ -347,7 +347,7 @@
 {
     u16 ttl;
     u16 period;
-    u32 reserved:1;
+    u32 replyIndFlag:1;
     u32 publishType:2;
     u32 txType:1;
     u32 rssiThresholdFlag:1;
@@ -407,6 +407,27 @@
     u16 reserved;
 } NanPublishTerminatedIndMsg, *pNanPublishTerminatedIndMsg;
 
+/* Params for NAN Publish Replied Ind */
+typedef struct PACKED
+{
+  u32  matchHandle;
+} NanPublishRepliedIndParams;
+
+/* NAN Publish Replied Ind */
+typedef struct PACKED
+{
+    NanMsgHeader fwHeader;
+    NanPublishRepliedIndParams publishRepliedIndParams;
+    /*
+     * Excludes TLVs
+     *
+     * Required: MAC Address
+     * Optional: Received RSSI Value
+     *
+     */
+    u8 ptlv[];
+} NanPublishRepliedIndMsg, *pNanPublishRepliedIndMsg;
+
 /* NAN Subscribe Service Req */
 typedef struct PACKED
 {
@@ -974,6 +995,7 @@
   Definition of various NanIndication(events)
 */
 typedef enum {
+    NAN_INDICATION_PUBLISH_REPLIED         =0,
     NAN_INDICATION_PUBLISH_TERMINATED      =1,
     NAN_INDICATION_MATCH                   =2,
     NAN_INDICATION_MATCH_EXPIRED           =3,
diff --git a/qcwcn/wifi_hal/nan_ind.cpp b/qcwcn/wifi_hal/nan_ind.cpp
index f2adf61..a57f228 100644
--- a/qcwcn/wifi_hal/nan_ind.cpp
+++ b/qcwcn/wifi_hal/nan_ind.cpp
@@ -35,6 +35,15 @@
 
     ALOGV("handleNanIndication msg_id:%u", msg_id);
     switch (msg_id) {
+    case NAN_INDICATION_PUBLISH_REPLIED:
+        NanPublishRepliedInd publishRepliedInd;
+        memset(&publishRepliedInd, 0, sizeof(publishRepliedInd));
+        res = getNanPublishReplied(&publishRepliedInd);
+        if (!res && mHandler.EventPublishReplied) {
+            (*mHandler.EventPublishReplied)(&publishRepliedInd);
+        }
+        break;
+
     case NAN_INDICATION_PUBLISH_TERMINATED:
         NanPublishTerminatedInd publishTerminatedInd;
         memset(&publishTerminatedInd, 0, sizeof(publishTerminatedInd));
@@ -165,7 +174,7 @@
 
     switch (pHeader->msgId) {
     case NAN_MSG_ID_PUBLISH_REPLIED_IND:
-        return NAN_INDICATION_UNKNOWN;
+        return NAN_INDICATION_PUBLISH_REPLIED;
     case NAN_MSG_ID_PUBLISH_TERMINATED_IND:
         return NAN_INDICATION_PUBLISH_TERMINATED;
     case NAN_MSG_ID_MATCH_IND:
@@ -195,6 +204,55 @@
     }
 }
 
+int NanCommand::getNanPublishReplied(NanPublishRepliedInd *event)
+{
+    if (event == NULL || mNanVendorEvent == NULL) {
+        ALOGE("%s: Invalid input argument event:%p mNanVendorEvent:%p",
+              __func__, event, mNanVendorEvent);
+        return WIFI_ERROR_INVALID_ARGS;
+    }
+
+    pNanPublishRepliedIndMsg pRsp = (pNanPublishRepliedIndMsg)mNanVendorEvent;
+    event->requestor_instance_id = pRsp->publishRepliedIndParams.matchHandle;
+
+    event->rssi_value = 0;
+    u8 *pInputTlv = pRsp->ptlv;
+    NanTlv outputTlv;
+    u16 readLen = 0;
+    int remainingLen = (mNanDataLen - \
+        (sizeof(NanMsgHeader)));
+
+    if (remainingLen <= 0) {
+        ALOGI("%s: No TLV's present",__func__);
+        return WIFI_SUCCESS;
+    }
+    while ((remainingLen > 0) &&
+           (0 != (readLen = NANTLV_ReadTlv(pInputTlv, &outputTlv)))) {
+        switch (outputTlv.type) {
+        case NAN_TLV_TYPE_MAC_ADDRESS:
+            if (outputTlv.length > sizeof(event->addr)) {
+                outputTlv.length = sizeof(event->addr);
+            }
+            memcpy(event->addr, outputTlv.value, outputTlv.length);
+            break;
+        case NAN_TLV_TYPE_RECEIVED_RSSI_VALUE:
+            if (outputTlv.length > sizeof(event->rssi_value)) {
+                outputTlv.length = sizeof(event->rssi_value);
+            }
+            memcpy(&event->rssi_value, outputTlv.value,
+                   outputTlv.length);
+            break;
+        default:
+            ALOGI("Unknown TLV type skipped");
+            break;
+        }
+        remainingLen -= readLen;
+        pInputTlv += readLen;
+        memset(&outputTlv, 0, sizeof(outputTlv));
+    }
+    return WIFI_SUCCESS;
+}
+
 int NanCommand::getNanPublishTerminated(NanPublishTerminatedInd *event)
 {
     if (event == NULL || mNanVendorEvent == NULL) {
diff --git a/qcwcn/wifi_hal/nan_req.cpp b/qcwcn/wifi_hal/nan_req.cpp
index 2868ffb..00a1a3b 100644
--- a/qcwcn/wifi_hal/nan_req.cpp
+++ b/qcwcn/wifi_hal/nan_req.cpp
@@ -610,7 +610,8 @@
 
     pFwReq->publishServiceReqParams.ttl = pReq->ttl;
     pFwReq->publishServiceReqParams.period = pReq->period;
-    pFwReq->publishServiceReqParams.reserved = 0;
+    pFwReq->publishServiceReqParams.replyIndFlag =
+                                   (pReq->recv_indication_cfg & BIT_3) ? 0 : 1;
     pFwReq->publishServiceReqParams.publishType = pReq->publish_type;
     pFwReq->publishServiceReqParams.txType = pReq->tx_type;
 
diff --git a/qcwcn/wifi_hal/nancommand.h b/qcwcn/wifi_hal/nancommand.h
index 6b2624f..763544f 100644
--- a/qcwcn/wifi_hal/nancommand.h
+++ b/qcwcn/wifi_hal/nancommand.h
@@ -46,6 +46,7 @@
     //based on the indication type
     int handleNanIndication();
     //Various Functions to get the appropriate indications
+    int getNanPublishReplied(NanPublishRepliedInd *event);
     int getNanPublishTerminated(NanPublishTerminatedInd *event);
     int getNanMatch(NanMatchInd *event);
     int getNanMatchExpired(NanMatchExpiredInd *event);