[Feature][Modem]Update MTK MODEM V1.6 baseline version: MOLY.NR15.R3.MD700.IVT.MP1MR3.MP.V1.6

MTK modem version: MT2735_IVT_MOLY.NR15.R3.MD700.IVT.MP1MR3.MP.V1.6.tar.gz
RF  modem version: NA

Change-Id: I45a4c2752fa9d1a618beacd5d40737fb39ab64fb
diff --git a/mcu/protocol/dispatcher/src/dispatcher_if.c b/mcu/protocol/dispatcher/src/dispatcher_if.c
new file mode 100644
index 0000000..24ed82f
--- /dev/null
+++ b/mcu/protocol/dispatcher/src/dispatcher_if.c
@@ -0,0 +1,477 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*******************************************************************************
+ * Filename:
+ * ---------
+ *   dispatcher_if.c
+ *
+ * Project:
+ * --------
+ *   VMOLY
+ *
+ * Description:
+ * ------------
+ *   Dispatcher public interface implementation.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *******************************************************************************/
+
+#include "dispatcher_if.h"
+#include "dispatcher_struct.h"
+#include "global_def.h"
+#include "dispatcher_msgid.h"
+#include "qmu_bm_util.h"
+#include "md_sap.h"
+#include "dispatcher_debug.h"
+#include "dispatcher_data_path_trace_utmd.h"
+/**
+ * ipcore registered dl callback to dispatcher
+ */
+static dispatcher_dlvr_dl_did_f  g_funcptr_ipcore_dl_did_cbk;
+static kal_bool wtunnel_cbk_set = KAL_FALSE;
+
+
+/**
+ * init function for dispatcher module
+ * init the global control context & register DL callback with wifi tunnel
+ */
+kal_bool dispatcher_init(void)
+{
+    //wtunnel_reg_dl_cbk(dispatcher_on_dl_did_cbk)
+    //DISPATCHER_REGISTER_DL_DID_CBK(dispatcher_on_dl_did_cbk);
+    //memset(g_dispatcher_cntx, 0, sizeof(g_dispatcher_cntx));
+    dispatcher_init_control_cntx();
+    MD_TRC_DISPATCHER_TR_INIT_ENTRY();
+    return KAL_TRUE;
+}
+
+
+/**
+ * reset function for dispatcher module
+ * reset the global control context & reset globals
+ */
+kal_bool dispatcher_reset(void)
+{
+    //memset(g_dispatcher_cntx, 0, sizeof(g_dispatcher_cntx));
+    dispatcher_init_control_cntx();
+    g_funcptr_ipcore_dl_did_cbk = NULL;
+    dispatcher_ctrl_set_current_protoidx(0);
+    MD_TRC_DISPATCHER_TR_RESET_ENTRY();
+    return KAL_TRUE;
+}
+
+
+/**
+ * ILM function for dispatcher module
+ * handle corresponding ILM for control path
+ * update the bearer and cid binding status to dispatcher control context 
+ */
+void dispatcher_on_ilm(ilm_struct *p_ilm)
+{
+    kal_uint8 curr_protoidx = p_ilm->dest_mod_id - MOD_DISPATCHER;
+    dispatcher_ctrl_set_current_protoidx(curr_protoidx);
+    switch (p_ilm->msg_id) {
+        /*WO->DISPATCHER bearer related*/
+    case MSG_ID_N3EPC_DISPATCHER_BEARER_ACT_REQ:
+        if(KAL_FALSE == wtunnel_cbk_set) {
+            DISPATCHER_REGISTER_DL_DID_CBK(dispatcher_on_dl_did_cbk);
+            wtunnel_cbk_set = KAL_TRUE;
+        }
+        n3epc_dispatcher_bearer_act_req(
+            (n3epc_dispatcher_bearer_act_req_struct*)p_ilm->local_para_ptr);
+        break;
+
+    case MSG_ID_N3EPC_DISPATCHER_BEARER_DEACT_REQ:
+        n3epc_dispatcher_bearer_deact_req(
+            (n3epc_dispatcher_bearer_deact_req_struct*)p_ilm->local_para_ptr);
+        break;
+
+        /*WO->DISPATCHER binding related*/
+    case MSG_ID_N3EPC_DISPATCHER_PDN_BIND_REQ:
+        n3epc_dispatcher_pdn_bind_req(
+            (n3epc_dispatcher_pdn_bind_req_struct*)p_ilm->local_para_ptr,
+            p_ilm->src_mod_id);
+        break;
+
+    case MSG_ID_N3EPC_DISPATCHER_PDN_UNBIND_REQ:
+        n3epc_dispatcher_pdn_unbind_req(
+            (n3epc_dispatcher_pdn_unbind_req_struct*)p_ilm->local_para_ptr,
+            p_ilm->src_mod_id);
+        break;
+
+        /*DISPATCHER->IPCORE binding related*/
+    case MSG_ID_IPCORE_DISPATCHER_PDN_BIND_RSP:
+        ipcore_dispatcher_pdn_bind_rsp(
+            (ipcore_dispatcher_pdn_bind_rsp_struct*)p_ilm->local_para_ptr);
+        break;
+#ifdef ATEST_SYS_DISPATCHER
+    case MSG_ID_N3EPC_DISPATCHER_PDN_BIND_CNF:
+    case MSG_ID_N3EPC_DISPATCHER_PDN_UNBIND_CNF:
+        dispatcher_ut_handling_n3epc_ilm(p_ilm);
+        break;
+#endif
+    default:
+        MD_TRC_DISPATCHER_TR_ILM_WRONG_MSG_ID(p_ilm->msg_id);
+        break;
+    }
+}
+
+
+/**
+ * DL callback register to Dispatcher module
+ * Ipcore register its DL callback via this API
+ */
+void dispatcher_reg_cbk_dlvr_dl_did(dispatcher_dlvr_dl_did_f pf_dlvr_did)
+{
+    //need to set the ipcore dl callback
+    g_funcptr_ipcore_dl_did_cbk = pf_dlvr_did;
+
+}
+
+
+/******************************************************************
+****************Data path functions******************************
+*****************************************************************/
+
+/**
+ * DL callback from wifi tunnel (wtunnel->dispatcher->ipcore)
+ * 1. bearer id validataion first & convert to pdn_id
+ * 2. get binding state for pdn_id
+ * 3. forward data to ipcore by pdn_id
+ * 4. drop the DID if anything fails
+ */
+void dispatcher_on_dl_did_cbk(kal_uint8 bearer_id, upcm_did* p_head,
+                              upcm_did* p_tail, kal_uint8 protocol_idx)
+{
+    //dispatch to the Ipcore by checking the dlcbk registered or not
+    kal_bool is_bearer_active = KAL_FALSE;
+    MD_TRC_DISPATCHER_DATA_TRACE_RCV_DL_DID(bearer_id, p_head, p_tail, protocol_idx);
+    
+    if (IS_VALID_BEARERID(bearer_id))
+    {
+        is_bearer_active = dispatcher_check_is_bearer_active_by_bearerid(bearer_id, protocol_idx);
+        if (KAL_TRUE == is_bearer_active)
+        {
+            dispatcher_forward_dl_did_to_ipc(bearer_id, p_head, p_tail, protocol_idx);
+            return;
+        }
+    }
+    /*bearer id is not valid,drop did here*/
+    //upcm_did_dest_q(p_head, p_tail);
+    MD_TRC_DISPATCHER_TR_DL_DID_DROP_BEARER_STATS(bearer_id, is_bearer_active, p_head, p_tail);
+    DISPATCHER_DROP_DL_DID(bearer_id, p_head, p_tail, protocol_idx);
+}
+
+
+void dispatcher_forward_dl_did_to_ipc(kal_uint8 bearer_id, upcm_did* p_head,
+                              upcm_did* p_tail, kal_uint8 protocol_idx)
+{
+    kal_uint32 pdn_id = 0;
+    DISPATCHER_CONVERT_BEARERID_TO_PDNID(bearer_id, pdn_id);
+    if (g_funcptr_ipcore_dl_did_cbk) {
+        MD_TRC_DISPATCHER_DATA_TRACE_FORWARD_DL_DID(pdn_id, p_head, p_tail, protocol_idx);
+        g_funcptr_ipcore_dl_did_cbk(pdn_id, p_head, p_tail, protocol_idx);
+    } else {
+        MD_TRC_DISPATCHER_TR_DL_DID_DROP_NULL_CBK(p_head, p_tail);
+        DISPATCHER_DROP_DL_DID(bearer_id, p_head, p_tail, protocol_idx);
+    }
+}
+
+
+void dispatcher_drop_dl_did(kal_uint8 bearer_id, upcm_did* p_head,
+                            upcm_did* p_tail, kal_uint8 protocol_idx)
+{
+    upcm_did_dest_q_free_buf(p_head, p_tail);
+}
+
+/**
+ * UL GPD flow (ipcore->dispatcher->wtunnel or UPCM)
+ * 1. ebi validataion first, is of wifi bearer, active
+ * 2. get binding state for ebi
+ * 3. forward data to wtunnel by bearerid
+ * 4. if not forward to wifitunnel, forward to UPCM
+ */
+void dispatcher_rcv_ul_gpd_by_ebi(kal_uint32 ebi, qbm_gpd* p_head, qbm_gpd* p_tail, kal_uint8 protocol_idx)
+{
+    kal_bool is_bearer_active = KAL_FALSE;
+    dispatcher_bind_state_enum bind_state;
+    /*bearer id value is of wifi & bearer is bind with dispatcher*/
+    MD_TRC_DISPATCHER_DATA_TRACE_RCV_UL_GPD_BY_EBI(ebi, p_head, p_tail, protocol_idx);
+    if (IS_VALID_BEARERID(ebi))
+    {
+        is_bearer_active = dispatcher_check_is_bearer_active_by_bearerid(ebi, protocol_idx);
+        bind_state = dispatcher_get_bind_state_by_bearerid(ebi, protocol_idx);
+
+        if ((DISPATCHER_PDN_ST_BIND == bind_state) &&
+            (KAL_TRUE == is_bearer_active))
+        {
+            DISPATCHER_FORWARD_UL_GPD_WTUNNEL(ebi, p_head, p_tail, protocol_idx);
+            return;
+        }
+    }
+
+    DISPATCHER_FORWARD_UL_GPD_UPCM_BY_EBI(ebi, p_head, p_tail, protocol_idx);
+
+}
+
+
+/**
+ * UL GPD flow (ipcore->dispatcher->wtunnel or UPCM)
+ * 1. pdn_id validataion first & convert to bearer_id
+ * 2. get binding state for pdn_id
+ * 3. forward data to wtunnel by bearerid
+ * 4. drop the DID if anything fails
+ * 5. if pdn_id not of wifi, forward to UPCM
+ */
+void dispatcher_rcv_ul_gpd_by_pdn(ip_type_e ip_type, kal_uint32 pdn_id,
+                                  qbm_gpd* p_head, qbm_gpd* p_tail,
+                                  kal_uint8 protocol_idx)
+{
+    /*pdn_id belong to wifi pdn*/
+    MD_TRC_DISPATCHER_DATA_TRACE_RCV_UL_GPD(pdn_id, p_head, p_tail, protocol_idx);
+    if (IS_PDNID_OF_WIFI(pdn_id))
+    {
+        dispatcher_bind_state_enum bind_state = dispatcher_get_bind_state_by_pdnid(pdn_id, protocol_idx);
+        kal_bool is_bearer_active = dispatcher_check_is_bearer_active_by_pdnid(pdn_id, protocol_idx);
+        if ((DISPATCHER_PDN_ST_BIND == bind_state) &&
+            (KAL_TRUE == is_bearer_active))
+        {
+            //wifi tunnel ul gpd interface without ip_type
+            kal_uint8 bearer_id = 0;
+            DISPATCHER_CONVERT_PDNID_TO_BEARERID(pdn_id, bearer_id);
+            DISPATCHER_FORWARD_UL_GPD_WTUNNEL(bearer_id, p_head, p_tail, protocol_idx);
+        } else {
+            //should drop this here
+            MD_TRC_DISPATCHER_TR_UL_GPD_DROP(pdn_id, is_bearer_active, bind_state, p_head, p_tail);
+            DISPATCHER_DROP_UL_GPD(pdn_id, p_head, p_tail, protocol_idx);
+        }
+    } else {
+        //call UPCM UL GPD interface
+        MD_TRC_DISPATCHER_DATA_TRACE_FORWARD_UL_GPD_UPCM(pdn_id, p_head, p_tail, protocol_idx);
+        DISPATCHER_FORWARD_UL_GPD_UPCM(ip_type, pdn_id, p_head, p_tail, protocol_idx);
+    }
+}
+
+
+void dispatcher_drop_ul_gpd(kal_uint32 pdn_id, qbm_gpd* p_head,
+                            qbm_gpd* p_tail, kal_uint8 protocol_idx)
+{
+    qbmt_dest_q(p_head, p_tail);
+}
+
+
+/**
+ * dispatcher UL META interface IPCORE->Dispatcher->wtunnel or UPCM)
+ * meta Q query to lhif & process each meta index 
+ * if meta belong to wifi pdn then convert to gpd & keep accumulate for same PDN
+ * forward the gpd list to wtunnel
+ * forward the lhif q to upcm to release meta
+ */
+void dispatcher_rcv_ul_meta_queue(kal_uint16 start_idx, kal_uint16 end_idx,
+                                  LHIF_QUEUE_TYPE queue_type)
+{
+    kal_uint16 read_idx;
+    lhif_meta_tbl_t *meta_tbl;
+    lhif_meta_tbl_t *meta;
+    kal_uint16 tbl_size;
+
+    qbm_gpd *head_gpd_p = NULL;
+    qbm_gpd *tail_gpd_p =  NULL;
+    kal_uint8 previous_bearer_id = 0;
+    kal_uint8 previous_proto_idx = 0;
+
+    read_idx = start_idx;
+    MD_TRC_DISPATCHER_DATA_TRACE_RCV_UL_META(queue_type, start_idx, end_idx);
+    //Query meta table
+    DIPSTACHER_QUERY_META_TBL((kal_uint32 **)&meta_tbl, &tbl_size, queue_type);
+    //check each meta index and process
+    do {
+        meta = &meta_tbl[read_idx];
+        //meta is not ignore & pdn state is bind
+
+        if (!meta->ignore && IS_PDNID_OF_WIFI(meta->pdn))
+        {
+            //check bind & bearer status both
+            dispatcher_bind_state_enum bind_state = dispatcher_get_bind_state_by_pdnid(meta->pdn, meta->protocol_idx);
+            kal_bool is_bearer_active = dispatcher_check_is_bearer_active_by_pdnid(meta->pdn, meta->protocol_idx);
+            
+            if ((DISPATCHER_PDN_ST_BIND == bind_state) &&
+                (KAL_TRUE == is_bearer_active))
+            {
+                kal_uint8 curr_bearer_id;
+                kal_uint8 curr_proto_idx;
+                kal_uint8 *ip_packet = NULL;
+                kal_uint32 length = 0;
+                qbm_gpd *curr_gpd_p;
+                kal_uint8 *gpd_data_p;
+                DISPATCHER_CONVERT_PDNID_TO_BEARERID(meta->pdn, curr_bearer_id);
+                curr_proto_idx = meta->protocol_idx;
+                length = meta->length;
+                ip_packet = meta->vrb_addr;
+                if (1 != qbmt_alloc_q_no_tail(QBM_TYPE_NET_UL_SHRD,
+                    1,
+                    (void**) &curr_gpd_p,
+                    (void**) &curr_gpd_p))
+                {
+                    //gpd allocation failed
+                    MD_TRC_DISPATCHER_TR_GPD_ALLOC_FAILED(read_idx);
+                    meta->ignore = KAL_TRUE;
+                    DISPATCHER_FREE_META_VRB(meta);
+                    goto drop;
+                }
+                MD_TRC_DISPATCHER_DATA_TRACE_ALLOC_GPD_INFO(read_idx, meta->pdn, curr_gpd_p);
+                QBM_CACHE_INVALID(ip_packet, length);
+                //find the data ptr
+                dispatcher_utils_set_gpd_datalen(curr_gpd_p, length, (void**) &gpd_data_p);
+                kal_mem_cpy(gpd_data_p, ip_packet, length);
+                QBM_CACHE_FLUSH(gpd_data_p, length);
+
+                meta->ignore = KAL_TRUE;
+                //dpcopro_rbuf_release(meta->vrb_addr, meta->length);
+                DISPATCHER_FREE_META_VRB(meta);
+
+                if ((NULL == head_gpd_p) && (NULL == tail_gpd_p))
+                {
+                    head_gpd_p = tail_gpd_p = curr_gpd_p;
+                    previous_bearer_id = curr_bearer_id;
+                    previous_proto_idx = curr_proto_idx;
+                }
+                else
+                {
+                    if ((previous_bearer_id == curr_bearer_id) &&
+                        (previous_proto_idx == curr_proto_idx))
+                    {
+                        //prev & current gpd can be clubbed together so update tail gpd
+                        QBM_DES_SET_NEXT(tail_gpd_p, curr_gpd_p);
+                        tail_gpd_p = curr_gpd_p;
+                        MD_TRC_DISPATCHER_DATA_TRACE_CLUB_GPD_INFO(head_gpd_p, tail_gpd_p);
+                    }
+                    else
+                    {
+                        //previous GPD & curr gpd are of different bearer or proto
+                        //call made to wtunnel for previous gpd head tail
+                        DISPATCHER_FORWARD_UL_GPD_WTUNNEL(previous_bearer_id,
+                            head_gpd_p, tail_gpd_p, previous_proto_idx);
+                        //now update the variable
+                        previous_bearer_id = curr_bearer_id;
+                        previous_proto_idx = curr_proto_idx;
+                        head_gpd_p = tail_gpd_p = curr_gpd_p;
+                    }
+                }
+            } /*PDN state is not bind and by any how the ipcore has send this to Dispatcher*/
+            else
+            {
+                /*PDN is in range of wifi PDN & not bind*/
+                MD_TRC_DISPATCHER_TR_IGR_META_INDEX(read_idx, meta->pdn, bind_state, is_bearer_active);
+                meta->ignore = KAL_TRUE;
+                //dpcopro_rbuf_release(meta->vrb_addr, meta->length);
+                DISPATCHER_FREE_META_VRB(meta);
+            }
+        }
+
+drop:
+        read_idx ++;
+        if (read_idx == tbl_size) {
+            read_idx = 0;
+        }
+    } while (read_idx != end_idx);
+
+    /*if any allocated gpd is there*/
+    if(head_gpd_p) {
+        DISPATCHER_FORWARD_UL_GPD_WTUNNEL(previous_bearer_id, head_gpd_p,
+            tail_gpd_p, previous_proto_idx);
+    }
+    /*forward to upcm to release meta & process non wifi pdn meta idxs*/
+    MD_TRC_DISPATCHER_DATA_TRACE_FORWARD_UL_META(queue_type, start_idx, end_idx);
+    DISPATCHER_FORWARD_UL_META_UPCM(start_idx, end_idx, queue_type);
+}
+
+
+kal_bool dispatcher_wtunnel_ul_send(kal_uint8 bearer_id, qbm_gpd *head,
+                                    qbm_gpd *tail, kal_uint8 proto_idx)
+{
+    MD_TRC_DISPATCHER_DATA_TRACE_FORWARD_UL_GPD_WTUNNEL(bearer_id, head, tail, proto_idx);
+    //actual wtunnel cbk here
+    wtunnel_upp_ul_send(bearer_id, head, tail, proto_idx);
+    return KAL_TRUE;
+}
+
+
+
+void dispatcher_utils_set_gpd_datalen(void *p_gpd, kal_uint32 datalen,
+                                      void **p_payload)
+{
+    kal_uint8* p_data = NULL;
+
+    ASSERT(p_gpd && p_payload);
+
+    if (QBM_DES_GET_BDP(p_gpd)) {
+        void* p_bd = NULL;
+
+        /* set p_bd data ptr */
+        p_bd = QBM_DES_GET_DATAPTR(p_gpd);
+
+        p_data = (kal_uint8*) QBM_DES_GET_DATAPTR(p_bd);
+
+        /* set p_bd data len */
+        QBM_DES_SET_DATALEN(p_bd, datalen);
+
+        /* set p_bd checksum */
+        qbm_cal_set_checksum(p_bd);
+    } else {
+        p_data = (kal_uint8*) QBM_DES_GET_DATAPTR(p_gpd);
+    }
+
+    /* set p_gpd data len */
+    QBM_DES_SET_DATALEN(p_gpd, datalen);
+
+    /* set p_gpd checksum */
+    qbm_cal_set_checksum(p_gpd);
+
+    *p_payload = (void*)(p_data);
+}
+
+
+/*adding for mini dump , reset sensitive data*/
+#if defined(__SENSITIVE_DATA_MOSAIC__)
+void dispatcher_module_clean(void)
+{
+    dispatcher_clean_private_data();
+}
+#endif