[Feature]Upload Modem source code

Change-Id: Id4294f30faced84d3e6fd6d5e61e1111bf287a37
diff --git a/mcu/protocol/interface/general/tftlib_common_struct.h b/mcu/protocol/interface/general/tftlib_common_struct.h
new file mode 100644
index 0000000..3e819f3
--- /dev/null
+++ b/mcu/protocol/interface/general/tftlib_common_struct.h
@@ -0,0 +1,427 @@
+/*****************************************************************************
+*  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) 2012
+*
+*  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:
+ * ---------
+ *   tftlib_common_struct.h
+ *
+ * Project:
+ * --------
+ *   MOLY
+ *
+ * Description:
+ * ------------
+ *   TFT library common structure
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ * ==========================================================================
+ * $Log$
+ *
+ * 09 18 2020 terence.kuo
+ * [MOLY00560403] [Mouton][R0][operator_IOT] Both active and hold call gets disconnected.
+ * . Further error handling for pf precedence conflict without dedicated bearer deactivation.
+ *
+ * 04 15 2020 terence.kuo
+ * [MOLY00508241] Memory reduction - l4 ps cid reduction and reduce maximum number of support flow
+ * 1. Support setting null for pf_act_list parameter.
+ * 2. Support qos flow deactivation.
+ * 3. Record qr's precedence into context in tftlib_set_user_defined_tft() if rate is 5g.
+ * 4. Add primitive traces to record current applied qr/ tft status for analysis.
+ * 5. trace enhancement
+ *
+ * 04 06 2020 terence.kuo
+ * [MOLY00508241] Memory reduction - l4 ps cid reduction and reduce maximum number of support flow
+ * . Add primitive traces to record current applied qr/ tft status for analysis.
+ *
+ * 01 02 2020 terence.kuo
+ * [MOLY00468375] [IODT][MT6885][Petrus][MP1][ZTE][Lab][5GSM][China][Xian][F60][N41][core1,vpe0,tc0(vpe3)] Fatal Error (0x823, 0x2000, 0xcccccccc) - NAS
+ * 	
+ * . Reduce the control buffer size when handling packet filter action list.
+ *
+ * 09 23 2019 terence.kuo
+ * [MOLY00442505] Update for March CR and trace enhancements.
+ * 	
+ * . Update for March CR and trace enhancements.
+ *
+ * 09 04 2019 terence.kuo
+ * [MOLY00434754] Upgrade CGTFT to support 5GC
+ * 	
+ * . Update CGTFT behaviors in tftlib.
+ *
+ * 03 26 2019 jeffery.chen
+ * [MOLY00393456] [Gen97][VMOLY] 45G InterRAT & interSystem feature
+ * 	
+ * 	[TFTLIB] interface part.
+ *
+ * 03 26 2019 jeffery.chen
+ * [MOLY00393456] [Gen97][VMOLY] 45G InterRAT & interSystem feature
+ * 	
+ * 	[TFTLIB] interface part.
+ *
+ * 12 14 2018 jeffery.chen
+ * [MOLY00372635] [VMOLY] L4/TCM/TFTLIB/VGSM phase2 check-in
+ * 	
+ * 	[TFTLIB] phase2 check-in.
+ *
+ * 09 14 2018 jeffery.chen
+ * [MOLY00306148] [NAS] pangu giant CR
+ * 	
+ * 	[TFTLIB] pass 1st NAS MoDIS IT.
+ *
+ * 08 17 2018 jeffery.chen
+ * [MOLY00306148] [NAS] pangu giant CR
+ * [TFTLIB] re-architecture.
+ *
+ * 08 17 2018 max.mo
+ * [MOLY00306148] [NAS] pangu giant CR
+ * .changes from Norman's CBr
+ *
+ * 07 20 2018 max.mo
+ * [MOLY00339905] [Gen97] porting of MOD_VGSM
+ * [Protocol build tag]
+ * [Is CL self testable: YES]
+ * [Group CL list: NO]
+ *
+ * 10 16 2016 renhuang.liu
+ * [MOLY00205035][TFTLIB] Memory management in TFT internal
+ *
+ * 11 17 2014 jeffery.chen
+ * [MOLY00084634] [UMOLY][R10][R11] NAS check-in from 6291_DEV to UMOLY
+ * [R10][R11] NAS check-in from 6291_DEV to UMOLY
+ *
+ * 09 10 2014 jeffery.chen
+ * [MOLY00078264] [UMOLY][R10][R11] NAS check-in from CBr to 6291_DEV
+ * [R10][R11] NAS check-in from CBr to 6291_DEV
+ *
+ * 12 25 2013 joe.chang
+ * [MOLY00051497] [MOLY][NRSPCA] NRSPCA phase 2 implementation
+ * [TFTLIB] Check-in related changes
+ *
+ * 04 12 2013 joe.chang
+ * [MOLY00014197] TFTLIB new feature
+ * [MT6290][TFTLIB] update TFT parameter list with new structure
+ *
+ * 12 04 2012 joe.chang
+ * [MOLY00007051] [MT7208][LTE Single Mode] enum rename & memory allocation mechansim change
+ *
+ * 11 07 2012 joe.chang
+ * [MOLY00005322] TATAKA merge to MOLY
+ * [Joe] TFTLIB part is check in done.
+ ****************************************************************************/
+
+
+#ifndef TFTLIB_COMMON_STRUCT_H_
+#define TFTLIB_COMMON_STRUCT_H_
+
+
+#include "kal_general_types.h"
+#include "tftlib_common_enum.h"
+
+
+/*struct declaration */
+
+
+/* IPv4 remote address and subnet mask struct (WORD(4-byte) array, used by UPCM only) */      
+typedef struct
+{
+    kal_uint32 addr;
+    kal_uint32 mask;
+}remote_v4addr_struct;
+
+
+/* IPv6 remote address and subnet mask struct (WORD(4-byte) array, used by UPCM only) */
+typedef struct 
+{
+    kal_uint32 addr[4]; 
+    kal_uint32 mask[4];
+}remote_v6addr_struct;
+
+typedef remote_v4addr_struct local_v4addr_struct;
+typedef remote_v6addr_struct local_v6addr_struct;
+
+/* Packet filter struct for SM/ESM, TCM, L4C, & UPCM */
+typedef struct 
+{
+    pf_own_entity_enum  pf_own_entity;  // Indicate UE or NW owns this PF            
+    kal_uint8           qri;            // QuS Rule ID where the packet filter belongs to
+    kal_uint8           id;             // Packet filter index
+    kal_uint8           precedence;     // Packet filter evaluation precedence index
+    pf_direction_enum   direction;      // Direction of the packet filter
+
+    kal_uint32          bitmap;         // Used to indicate which of the following field exist
+
+    kal_bool            match_all_type;
+    
+    union
+    {
+        remote_v4addr_struct v4;
+        remote_v6addr_struct v6;
+    }remote_addr;                       // Remote address and subnet mask (WORD(4-byte) array, used by UPCM only)
+   
+    union
+    {
+        local_v4addr_struct v4;
+        local_v6addr_struct v6;
+    }local_addr;                        // Local address and subnet mask (WORD(4-byte) array, used by UPCM only)
+
+    kal_uint8           remote_addr_and_mask[MAX_REMOTE_ADDR_AND_MASK_LEN]; /* ----------------- Remote address and subnet mask (byte array) ----------------*
+                                                                             *                                                                               *
+                                                                             * IPv4: addr =  0 ~  3                                                          *    
+                                                                             *       mask =  4 ~  7                                                          *
+                                                                             * <NOTE1: Length of IPv4 addr + mask = IPV4_REMOTE_ADDR_AND_MASK_LEN(8)>        *
+                                                                             *                                                                               *
+                                                                             * IPv6: addr =  0 ~ 15                                                          *
+                                                                             *       mask = 16 ~ 31                                                          *
+                                                                             * <NOTE2: Length of IPv6 addr + mask = IPV6_REMOTE_ADDR_AND_MASK_LEN(32)>       *
+                                                                             *                                                                               *
+                                                                             * <NOTE3: MAX_REMOTE_ADDR_AND_MASK_LEN is set as IPV6_REMOTE_ADDR_AND_MASK_LEN> *
+                                                                             *                                                                               *
+                                                                             * ------------------------------------------------------------------------------*
+                                                                             */
+                                                                             
+    kal_uint8           local_addr_and_mask[MAX_LOCAL_ADDR_AND_MASK_LEN];   /* ----------------- Local address and subnet mask (byte array) -----------------*
+                                                                             *                                                                               *
+                                                                             * IPv4: addr =  0 ~  3                                                          *    
+                                                                             *       mask =  4 ~  7                                                          *
+                                                                             * <NOTE1: Length of IPv4 addr + mask = IPV4_LOCAL_ADDR_AND_MASK_LEN(8)>         *
+                                                                             *                                                                               *
+                                                                             * IPv6: addr =  0 ~ 15                                                          *
+                                                                             *       mask = 16 ~ 31                                                          *
+                                                                             * <NOTE2: Length of IPv6 addr + mask = IPV6_LOCAL_ADDR_AND_MASK_LEN(32)>        *
+                                                                             *                                                                               *
+                                                                             * <NOTE3: MAX_LOCAL_ADDR_AND_MASK_LEN is set as IPV6_LOCAL_ADDR_AND_MASK_LEN>   *
+                                                                             *                                                                               *
+                                                                             * ------------------------------------------------------------------------------*
+                                                                             */
+                                                                             
+    kal_uint8           protocol_nxt_hdr;   // Protocol number (IPv4) / Next header (IPv6)
+
+    kal_uint16          local_port_low;     // Single local port / Local port range (low)
+    kal_uint16          local_port_high;    //       (N/A)       / Local port range (high)
+    
+    kal_uint16          remote_port_low;    // Single remote port / Remote port range (low)
+    kal_uint16          remote_port_high;   //       (N/A)        / Remote port range (high)
+
+    kal_uint32          spi;                // IPsec security parameter index
+    
+    kal_uint8           tos;                // Type of service (IPv4) / Traffic class (IPv6)
+    kal_uint8           tos_msk;            // Type of service mask (IPv4) / Traffic class mask (IPv6)
+    
+    kal_uint32          flow_label;         // Flow label (IPv6)
+}pkt_filter_struct;
+
+/* Common deact list: union of deact_bearer_list_struct and deact_qr_list_sturct */
+typedef struct {
+    kal_uint8   deact_num;
+    kal_uint8   deact_list[TFTLIB_MAX_DEACT_LIST_NUM];
+    kal_bool    has_dqr;
+    tft_validate_result_enum cause;
+} tft_deact_list_struct;
+
+/* PDP/EPS bearer context deactivation list for SM/ESM */
+typedef struct {
+    kal_uint8   deact_num;                              // Number of deactivated bearer due to packet filter conflict
+    kal_uint8   deact_list[TFTLIB_MAX_BEARER_CTXT_NUM]; // Deactivated bearer context list
+} tft_deact_bearer_list_struct;
+
+/* QoS Rule deactivation list for VGSM */
+typedef struct {
+    kal_uint8   deact_num;                              // Number of deactivated QoS Rule due to packet filter conflict
+    kal_uint8   deact_list[TFTLIB_MAX_QR_NUM];          // Deactivated QoS Rule context list
+    kal_bool    has_dqr;                                // TRUE if there is Default QR in deact list.
+    tft_validate_result_enum cause;
+} tft_deact_qr_list_struct;
+
+/* Packet filter action struct for UPCM */
+typedef struct 
+{
+    kal_uint8           bearer_id;  // EPS bearer ID/NSAPI where the packet filter belongs to
+    kal_uint8           qri;        // QuS Rule ID where the packet filter belongs to
+    kal_uint8           old_qfi;    // Old QoS Flow ID where the Qos Rule belongs to
+    kal_uint8           qfi;        // New QoS Flow ID 
+    pkt_filter_act_enum action;     // Update action for the packet filter
+    pkt_filter_struct   pkt_filter; // Content of the new packet filter
+} pkt_filter_act_struct;
+
+
+/* Packet filter action list struct for TCM, UPCM */
+typedef struct 
+{
+    kal_uint8               pkt_filter_num;                              // Number of packet filters to be update in the following list
+    pkt_filter_act_struct   *pkt_filter_list[MAX_PACKET_FILTER_NUM * 2]; // List of packet filters to be update and each with specific EPS bearer ID/NSAPI & action
+} pkt_filter_act_list_struct;
+
+/* Packet filter action list link-list node for VGSM, TCM, UPCM */
+typedef struct _pkt_filters_act_list_node_struct {
+    pkt_filter_act_list_struct pkt_filters; // Packet filters Action in a QoS Rule
+    struct _pkt_filters_act_list_node_struct *next; // Point to the next pkt_filters act list in the next QoS Rule
+} pkt_filters_act_list_node_struct;
+
+/* TFT PDU struct for SM/ESM, TCM */
+typedef struct {
+    kal_uint16  length;   // length of the TFT raw data: upgrade to uint16 for 5G
+    kal_uint8   *data;    // TFT raw data
+} tft_pdu_struct;
+
+
+typedef struct {
+    kal_uint8   auth_token_len;                                             // length of authorization token
+    kal_uint8   auth_token[MAX_AUTHORIZATION_TOKEN_LEN];                    // authorization token
+    kal_uint8   flow_id_num;                                                // number of flow identifiers
+    kal_uint8   flow_id_list[MAX_FLOW_IDENTIFIER_NUM][FLOW_IDENTIFIER_LEN]; /* flow identifier list 
+                                                                             * (NOTE: an authtoken can follow one or more flow identifiers,
+                                                                             *        and each flow identifier is FLOW_IDENTIFIER_LEN (4 byte) long)
+                                                                             */
+} tft_authtoken_flowid_struct;
+
+
+typedef struct {
+    kal_uint8   linked_pf_id_num;                           // Number of linked packet filter IDs carried in linked_pf_id_list[]
+    kal_uint8   linked_pf_id_list[MAX_PACKET_FILTER_NUM];   /* Linked packet filter ID list
+                                                             * (NOTE1: Used to indicate to NW the change for which service applies to)
+                                                             * (NOTE2: Will appear when, 1. GBR changes, 2. TFT operation = 'Add packet filters to existing TFT')
+                                                             */
+                                                             
+    kal_uint8                       authtoken_flowid_num;                            // Number of authtoken_flowid group in authtoken_flowid_list[]
+    tft_authtoken_flowid_struct     authtoken_flowid_list[MAX_AUTHTOKEN_FLOWID_NUM]; // Authorization and flow identifier group list
+
+} tft_parameter_list_struct;
+
+/* TFT struct for SM/ESM, TCM, L4C */
+typedef struct {
+    kal_uint8                   cid;                                    // context id
+    kal_bool                    est_wo_tft;                             // indicate whether TFT is established without TFT
+    tft_operation_enum          tft_opcode;                             // TFT operation code
+    kal_bool                    ebit;                                   // Indicate whether parameter list exists
+    kal_bool                    is_default_bearer;                      // (234G) Indicate whether it's primary pdp/ default bearer
+    
+    kal_bool                    dqr_bit;                                // (5G)Indicate whether the QoS rule is the default QoS rule
+    kal_bool                    qri_present;                            // (5G)
+    kal_uint8                   qri;                                    // (5G) QoS rule id
+    kal_bool                    qr_precedence_present;                   // (5G)
+    kal_uint8                   qr_precedence;                          // (5G) precedence value of QoS rule
+    kal_bool                    qfi_present;                            // (5G)
+    kal_uint8                   qfi;                                    // (5G) QoS Flow Id
+    kal_bool                    psi_present;                            // (5G)
+    kal_uint8                   psi;                                    // (5G) PDU session id
+    
+    kal_uint8                   pf_num;                                 // Number of packet filter carried in pf_list[]
+    pkt_filter_struct           pf_list[MAX_PACKET_FILTER_NUM];         // Packet filter list
+    tft_parameter_list_struct   parameter_list;                         // (234G)Parameter list
+    
+} tft_info_struct;
+
+typedef struct {
+    kal_uint16  length;   // length of the QoS Rules raw data
+    kal_uint8   *data;    // raw data of QoS Rules
+} qrs_raw_struct;
+
+/* A memory reduction version of tft_info_struct struct.
+ * The type of pf_list is change from pkt_filter_struct to pkt_filter_struct* (pointer) */
+typedef struct {
+    kal_uint8                   cid;                                    // context id
+    kal_bool                    est_wo_tft;                             // indicate whether TFT is established without TFT
+    tft_operation_enum          tft_opcode;                             // TFT operation code
+    kal_bool                    ebit;                                   // Indicate whether parameter list exists
+    kal_bool                    is_default_bearer;                      // (234G) Indicate whether it's primary pdp/ default bearer
+    
+    kal_bool                    dqr_bit;                                // (5G)Indicate whether the QoS rule is the default QoS rule
+    kal_bool                    qri_present;                            // (5G)
+    kal_uint8                   qri;                                    // (5G) QoS rule id
+    kal_bool                    qr_precedence_present;                  // (5G)
+    kal_uint8                   qr_precedence;                          // (5G) precedence value of QoS rule
+    kal_bool                    qfi_present;                            // (5G)
+    kal_uint8                   qfi;                                    // (5G) QoS Flow Id
+    kal_bool                    psi_present;                            // (5G)
+    kal_uint8                   psi;                                    // (5G) PDU session id
+    
+    kal_uint8                   pf_num;                                 // Number of packet filter carried in pf_list[]
+    pkt_filter_struct           *pf_list[MAX_PACKET_FILTER_NUM];        // Pointers to packet filter list
+    tft_parameter_list_struct   parameter_list;                         // (234G)Parameter list    
+} tft_info_w_pf_ptr_struct;
+
+/* TFT info list */
+typedef struct {
+    kal_uint8           tft_num;
+    tft_info_struct     tft_info[ 1 + TFTLIB_MAX_QR_NUM_PER_PDUS]; // +1 for 234G TFT
+} tft_info_list_struct;
+
+/* rqos rule struct */
+typedef struct {
+    kal_bool            rule_in_use;    //
+    kal_uint8           rule_idx;       // = pf idx
+    kal_uint8           qri;            // (5G) QoS rule id
+    kal_uint8           qr_precedence;  // (5G) precedence value of QoS rule
+    kal_uint8           psi;            // (5G) PDU session id
+    kal_uint8           qfi;            // (5G) QoS Flow Id
+    kal_uint32          t3583;
+    pkt_filter_struct   pf;             // packet filter
+    
+} tftlib_rqos_rule_struct;
+
+
+// pdus info
+typedef struct {
+    kal_uint8                   cid;                                    // context id
+    kal_uint8                   qos_flow_id;                            // (5G) QoS Flow Id
+    kal_uint8                   qos_rule_id;                            // (5G) QoS Rule Id
+    kal_uint8                   qr_precedence;                          // (5G) precedence value of QoS rule
+    kal_bool                    dqr_bit;                                // (5G)Indicate whether the QoS rule is the default QoS rule
+} qos_rule_info_struct;
+
+typedef struct {
+    kal_uint8               psi;                                        // (5G) pdu session id
+    kal_uint8               qos_flow_count;
+    kal_uint8               qos_rule_list_len;
+
+    // psi's info
+    qos_rule_info_struct    qos_rule_list[TFTLIB_MAX_QR_NUM_PER_PDUS];  // (5G) QoS Rule Id List
+} pdus_info_struct;
+
+
+// bearer info
+typedef struct {
+    kal_uint8                   ebi;                                    // in 23G: nsapi       
+
+    // ebi's info
+    kal_uint8                   cid;                                    
+    // kal_uint8                   link_ebi;                               // in 23G: nsapi of primary cid
+} bearer_info_struct;
+
+#endif /* TFTLIB_COMMON_STRUCT_H_ */