yu.dong | c33b307 | 2024-08-21 23:14:49 -0700 | [diff] [blame^] | 1 | /***************************************************************************** |
| 2 | * Copyright Statement: |
| 3 | * -------------------- |
| 4 | * This software is protected by Copyright and the information contained |
| 5 | * herein is confidential. The software may not be copied and the information |
| 6 | * contained herein may not be used or disclosed except with the written |
| 7 | * permission of MediaTek Inc. (C) 2012 |
| 8 | * |
| 9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| 12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| 18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| 19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| 20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| 21 | * |
| 22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| 23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| 26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 27 | * |
| 28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| 29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| 30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| 31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| 32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| 33 | * |
| 34 | *****************************************************************************/ |
| 35 | |
| 36 | /***************************************************************************** |
| 37 | * |
| 38 | * Filename: |
| 39 | * --------- |
| 40 | * mt_task.c |
| 41 | * |
| 42 | * Project: |
| 43 | * -------- |
| 44 | * UMOLYA |
| 45 | * |
| 46 | * Description: |
| 47 | * ------------ |
| 48 | * MT_Framework task implement |
| 49 | * |
| 50 | * Author: |
| 51 | * ------- |
| 52 | * ------- |
| 53 | * |
| 54 | * |
| 55 | * ========================================================================== |
| 56 | * $Log$ |
| 57 | * |
| 58 | * |
| 59 | ****************************************************************************/ |
| 60 | |
| 61 | /*****************************************************************************/ |
| 62 | /* Includes */ |
| 63 | /*****************************************************************************/ |
| 64 | #include "mt.h" |
| 65 | #include "mte_if.h" |
| 66 | #include "mt_dispatcher.h" |
| 67 | #include "mtf_msgid.h" |
| 68 | #include "em_msgid.h" |
| 69 | #include "dhl_trace.h" |
| 70 | #include "dhl_def.h" |
| 71 | |
| 72 | #include "srv_modid.h" |
| 73 | |
| 74 | #include "tst_msgid.h" |
| 75 | #include "tst_sap.h" |
| 76 | |
| 77 | #include "nvram_defs.h" |
| 78 | #include "nvram_interface.h" |
| 79 | #include "nvram_msgid.h" |
| 80 | |
| 81 | |
| 82 | /*****************************************************************************/ |
| 83 | /* Define */ |
| 84 | /*****************************************************************************/ |
| 85 | |
| 86 | #define MT_MAGIC_FORMATTER (0x8877) |
| 87 | #define MT_MAGIC_ELEMENT (0x5566) |
| 88 | |
| 89 | #define MT_FORMATTER_MASK (0x1111) |
| 90 | |
| 91 | /*****************************************************************************/ |
| 92 | /* Global variables */ |
| 93 | /*****************************************************************************/ |
| 94 | mt_context_t mt; |
| 95 | event_scheduler *mtf_event_scheduler; |
| 96 | /*****************************************************************************/ |
| 97 | /* External functions */ |
| 98 | /*****************************************************************************/ |
| 99 | extern nvram_ltable_entry_struct logical_data_item_table_mtf[]; |
| 100 | |
| 101 | /*****************************************************************************/ |
| 102 | /* Internal functions */ |
| 103 | /*****************************************************************************/ |
| 104 | |
| 105 | /*****************************************************************************/ |
| 106 | /* Function Body */ |
| 107 | /*****************************************************************************/ |
| 108 | |
| 109 | |
| 110 | void |
| 111 | mt_register_formatter(mt_formatter_t *formatter) |
| 112 | { |
| 113 | int result; |
| 114 | EXT_ASSERT(formatter, 0, 0, 0); |
| 115 | EXT_ASSERT(formatter->fmt_id < MT_FMT_MAX, formatter->fmt_id, MT_FMT_MAX, 0); |
| 116 | |
| 117 | result = mt_dispatcher_entry_init(formatter, MT_MAGIC_FORMATTER, formatter->ilm_msg_id, MT_FORMATTER_MASK); |
| 118 | EXT_ASSERT(result == 0, result, 0, formatter->ilm_msg_id); |
| 119 | |
| 120 | mt.formatter[formatter->fmt_id] = formatter; |
| 121 | |
| 122 | if (formatter->fmt_id != MT_FMT_ILM) { |
| 123 | result = mt_dispatcher_add_entry(&mt.formatter_list, formatter->ilm_msg_id, formatter); |
| 124 | EXT_ASSERT(result == 0, result, formatter->fmt_id, 0); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | void |
| 129 | mt_register_mte_rule(mte_rule_t *mte_rule) |
| 130 | { |
| 131 | mt_register_mte_rule_with_mask(mte_rule, RULE_CODE_MASK_FLAG_ALL_ON); |
| 132 | } |
| 133 | |
| 134 | void |
| 135 | mt_register_mte_rule_with_mask(mte_rule_t *mte_rule, kal_uint32 rule_code_mask) |
| 136 | { |
| 137 | int result; |
| 138 | mt_formatter_t *f; |
| 139 | |
| 140 | EXT_ASSERT(mte_rule, 0, 0, 0); |
| 141 | EXT_ASSERT(mte_rule->fmt_id < MT_FMT_MAX, mte_rule, mte_rule->fmt_id, mte_rule->code); |
| 142 | EXT_ASSERT(mte_rule->execute, mte_rule, mte_rule->fmt_id, mte_rule->code); |
| 143 | |
| 144 | result = mt_dispatcher_entry_init(mte_rule, MT_MAGIC_ELEMENT, mte_rule->code, rule_code_mask); |
| 145 | EXT_ASSERT(result == 0, result, mte_rule->fmt_id, mte_rule->code); |
| 146 | |
| 147 | f = mt.formatter[mte_rule->fmt_id]; |
| 148 | EXT_ASSERT(f, mte_rule->fmt_id, mte_rule, 0); |
| 149 | |
| 150 | result = mt_dispatcher_add_entry(&f->element_list, mte_rule->code, mte_rule); |
| 151 | EXT_ASSERT(result == 0, result, mte_rule->code, mte_rule); |
| 152 | } |
| 153 | |
| 154 | |
| 155 | kal_bool mt_send_to_framework(ilm_struct *ilm_ptr) |
| 156 | { |
| 157 | if(ilm_ptr->msg_id == MSG_ID_DHL_MT_ICD_IND || |
| 158 | ilm_ptr->msg_id == MSG_ID_DHL_MT_PEER_TRACE_IND || |
| 159 | #ifdef __IMS_SUPPORT__ |
| 160 | ilm_ptr->msg_id == MSG_ID_EM_IMC_SIP_INFO_IND || |
| 161 | #endif |
| 162 | ilm_ptr->msg_id == MSG_ID_EM_RRCE_NW_PEER_MSG_INFO_IND) |
| 163 | { |
| 164 | //ICD or PEER_TRACE formatter would use Peer buffer |
| 165 | hold_peer_buff(ilm_ptr->peer_buff_ptr); |
| 166 | } |
| 167 | |
| 168 | hold_local_para(ilm_ptr->local_para_ptr); |
| 169 | ilm_ptr->dest_mod_id = MOD_MT; |
| 170 | ilm_ptr->sap_id = MTF_SAP; |
| 171 | //provide temp solution wariting for DMF confirm how to handle peer_buff == NULL |
| 172 | if(ilm_ptr->msg_id == MSG_ID_DHL_MT_ICD_IND && NULL == ilm_ptr->peer_buff_ptr){ |
| 173 | dhl_print(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_MT, "[MT][Warning] cancel to DMF: null ICD info"); |
| 174 | return KAL_FALSE; |
| 175 | } |
| 176 | msg_send(ilm_ptr); |
| 177 | return KAL_TRUE; |
| 178 | } |
| 179 | |
| 180 | kal_bool |
| 181 | mt_task_init() |
| 182 | { |
| 183 | mtf_event_scheduler = evshed_create("MTFEvs", MOD_MT, 0, MAX_DELAY_UNLIMITED); |
| 184 | evshed_set_index(mtf_event_scheduler, MTF_USER_TIMER_ID); |
| 185 | |
| 186 | mt_dispatcher_init(); |
| 187 | mt_formatters_init(); |
| 188 | mt_elements_init(); |
| 189 | |
| 190 | nvram_ltable_register(logical_data_item_table_mtf); |
| 191 | return KAL_TRUE; |
| 192 | } |
| 193 | |
| 194 | kal_bool |
| 195 | mt_task_reset(void) |
| 196 | { |
| 197 | evshed_delete_all_events(mtf_event_scheduler); |
| 198 | mt_elements_reset(); |
| 199 | return KAL_TRUE; |
| 200 | } |
| 201 | |
| 202 | |
| 203 | extern void mte_att_set_em_filters(); |
| 204 | extern void mte_att_set_icd_filters(); |
| 205 | void mt_tst_inject_string_hdlr(ilm_struct *ilm_ptr) |
| 206 | { |
| 207 | tst_module_string_inject_struct *msg_ptr; |
| 208 | |
| 209 | msg_ptr = (tst_module_string_inject_struct*) ilm_ptr->local_para_ptr; |
| 210 | |
| 211 | switch(msg_ptr->index) |
| 212 | { |
| 213 | |
| 214 | default: |
| 215 | break; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | void |
| 220 | mt_task_main(task_entry_struct* task_entry_ptr) |
| 221 | { |
| 222 | ilm_struct current_ilm; |
| 223 | |
| 224 | kal_set_active_module_id(MOD_MT); |
| 225 | dhl_print(TRACE_STATE, DHL_USER_FLAG_NONE, MOD_MT, "enter mt_task_main"); |
| 226 | |
| 227 | mt_elements_init_proc(); |
| 228 | |
| 229 | while(1) { |
| 230 | mt_formatter_t *f; |
| 231 | mt_msginfo_t m; |
| 232 | mte_rule_t *r = NULL; |
| 233 | |
| 234 | msg_receive_extq(¤t_ilm); |
| 235 | |
| 236 | |
| 237 | if (current_ilm.msg_id == MSG_ID_TST_INJECT_STRING) |
| 238 | { |
| 239 | mt_tst_inject_string_hdlr(¤t_ilm); |
| 240 | continue; |
| 241 | } |
| 242 | |
| 243 | if(current_ilm.msg_id == MSG_ID_TIMER_EXPIRY) |
| 244 | { |
| 245 | kal_uint16 timer_indx = evshed_get_index(¤t_ilm); |
| 246 | if(timer_indx == MTF_USER_TIMER_ID) |
| 247 | { |
| 248 | evshed_timer_handler(mtf_event_scheduler); |
| 249 | } |
| 250 | continue; |
| 251 | } |
| 252 | if(current_ilm.msg_id == MSG_ID_NVRAM_WRITE_CNF) |
| 253 | { |
| 254 | mt_nvram_write_cnf_hdlr(¤t_ilm); |
| 255 | destroy_ilm(¤t_ilm); |
| 256 | continue; |
| 257 | } |
| 258 | |
| 259 | if (!(f = mt_dispatcher_find_entry(&mt.formatter_list, current_ilm.msg_id, NULL))) { |
| 260 | f = mt.formatter[MT_FMT_ILM]; |
| 261 | } |
| 262 | if (!f) { |
| 263 | continue; |
| 264 | } |
| 265 | mt_dispatcher_verify(f, MT_MAGIC_FORMATTER); |
| 266 | |
| 267 | |
| 268 | f->extract_msginfo(¤t_ilm, &m);// put current ilm content to msginfo |
| 269 | |
| 270 | |
| 271 | while ((r = mt_dispatcher_find_entry(&f->element_list, m.code, r))) { |
| 272 | mt_dispatcher_verify(r, MT_MAGIC_ELEMENT); |
| 273 | r->code = m.code;// for masking code user to get current code |
| 274 | r->execute(r, m.msg, m.msg_size); |
| 275 | } |
| 276 | destroy_ilm(¤t_ilm); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | #ifndef STANDALONE_TEST |
| 281 | kal_bool |
| 282 | mt_create(comptask_handler_struct **handle) |
| 283 | { |
| 284 | static const comptask_handler_struct task_handler_info = |
| 285 | { |
| 286 | mt_task_main, /* task entry function */ |
| 287 | mt_task_init, /* task initialization function */ |
| 288 | mt_task_reset /* task reset handler */ |
| 289 | }; |
| 290 | |
| 291 | *handle = (comptask_handler_struct *)&task_handler_info; |
| 292 | return KAL_TRUE; |
| 293 | } |
| 294 | #endif |