BootupSrvProtocol.c 36.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
/*****************************************************************************
*  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:
 * ---------
 *  BootupSrvProtocol.c
 *
 * Project:
 * --------
 *  MAUI
 *
 * Description:
 * ------------
 *  Mode & L4C power-on controller of bootup.
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/

/****************************************************************************
 * Include
 ****************************************************************************/

#include "MMI_features.h"
#include "BootupSrv.h"
#include "UtilitySrvGprot.h"
#include "mmi_msg_struct.h"
#include "ModeSwitchAppGProt.h"
#include "ModeSwitchSrvGProt.h"
#include "PhoneSetup.h"


#include "MMIDataType.h"
#include "kal_general_types.h"
#include "BootupSrvIprot.h"
#include "stack_config.h"
#include "mmi_frm_queue_gprot.h"
#include "app_ltlcom.h"
#include "MMI_common_app_trc.h"
#include "DebugInitDef_Int.h"
#include "kal_trace.h"
#include "mmi_common_app_trc.h"
#include "stack_msgs.h"
#include "mmi_frm_events_gprot.h"
#include "stack_common.h"
#include "kal_public_api.h"
#include "l4c_nw_cmd.h"
#include "mmi_frm_utility_gprot.h"
#include "SimCtrlSrvGprot.h"


/****************************************************************************
 * Typedef
 ****************************************************************************/

typedef struct
{
#if (MMI_MAX_SIM_NUM >= 2)
    U8 dual_sim_mode_setting;
#endif

    MMI_BOOL sim_inited;
    srv_bootup_protocol_query_enum query_setting;

    struct
    {
        /* The bit set of SIMs which need to send CFUN_STATE_REQ with 1 */
        //srv_bootup_sim_bit_set to_be_enabled;
        /* The bit set of SIMs which CFUN_STATE_REQ was sent */
        srv_bootup_sim_bit_set cfun_sent;
        /* The bit set of SIMs which is being waited for response */
        srv_bootup_sim_bit_set waiting;
        /* The bit set of SIMs which CFUN_STATE_RSP was received */
        srv_bootup_sim_bit_set cfun_rsp;
    } control;

    void *user_data;
    srv_bootup_work_completed_callback completed_callback;
} srv_bootup_protocol_cntx_struct;


/****************************************************************************
 * Global variables
 ****************************************************************************/

static srv_bootup_protocol_cntx_struct g_srv_bootup_protocol_cntx;


/****************************************************************************
 * Local functions
 ****************************************************************************/

#if (MMI_MAX_SIM_NUM >= 2)
static U8 srv_bootup_sim_status_update_ind_received(void *msg);
static void srv_bootup_protocol_boot_multiple_sims(srv_bootup_protocol_mode_enum mode);
#endif

static MMI_BOOL srv_bootup_protocol_l4_response_hdlr(void *msg, S32 src_mod);

#if (MMI_MAX_SIM_NUM == 1)
static MMI_BOOL srv_bootup_protocol_cfun_state_rsp_hdlr(void *msg, S32 src_mod);
#else
static MMI_BOOL srv_bootup_protocol_efun_state_rsp_hdlr(void *msg, S32 src_mod);
#endif


#ifdef __MMI_TELEPHONY_SUPPORT__
/*****************************************************************************
 * FUNCTION
 *  srv_bootup_protocol_init
 * DESCRIPTION
 *  Initialize the protocol module of bootup service.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void srv_bootup_protocol_init(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    
    /*
     * Do not set protocol event handlers here because the bootup main flow
     * will clean all of them.
     */

    //g_srv_bootup_protocol_cntx.query_setting = SRV_BOOTUP_PROTOCOL_QUERY_INVALID;
    
#if (MMI_MAX_SIM_NUM >= 2)
    //g_srv_bootup_protocol_cntx.sim_inited = MMI_FALSE;
#endif
    //g_srv_bootup_protocol_cntx.control.cfun_sent = 0;

    srv_boootup_cv_init();

#if (MMI_MAX_SIM_NUM >= 2)
    mmi_frm_set_multi_protocol_event_handler(MSG_ID_MMI_SMU_SIM_STATUS_UPDATE_IND, srv_bootup_sim_status_update_ind_received);
#endif
}
#endif


/*****************************************************************************
 * FUNCTION
 *  srv_bootup_emit_sim_slot_ready_event
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_bootup_emit_sim_slot_ready_event(void)
{
#if (MMI_MAX_SIM_NUM >= 2)
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_sim_enum sim;
    S32 i;
    S32 n_inserted;
    U32 inserted_sims_bit_set;
    srv_bootup_sim_slot_ready_evt_struct ready_evt;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    n_inserted = 0;
    inserted_sims_bit_set = 0;

    for (i = 0, sim = MMI_SIM1; i < MMI_SIM_TOTAL; i++, sim <<= 1)
    {
        srv_bootup_sim_cntx_struct *sim_cntx = srv_bootup_get_sim_cntx(sim);
        if (sim_cntx->is_inserted)
        {
            n_inserted++;
            inserted_sims_bit_set |= sim;
        }
    }

    MMI_FRM_INIT_EVENT(&ready_evt, EVT_ID_SRV_BOOTUP_SIM_SLOT_READY);
    ready_evt.n_inserted = n_inserted;
    ready_evt.inserted_sims = inserted_sims_bit_set;
    /* srv_bootup_emit_sim_slot_ready_event() will not be called in app's callstack */
    MMI_FRM_CB_EMIT_EVENT(&ready_evt);
#endif /* (MMI_MAX_SIM_NUM >= 2) */
}


/*****************************************************************************
 * FUNCTION
 *  srv_bootup_init_sim_callback_proc
 * DESCRIPTION
 *  Callback the completed callback
 * PARAMETERS
 *  *evt        [IN]
 * RETURNS
 *  mmi_ret
 *****************************************************************************/
static mmi_ret srv_bootup_init_sim_callback_proc(mmi_event_struct *evt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_srv_bootup_protocol_cntx.completed_callback != NULL)
    {
        srv_bootup_work_completed_callback callback;
        void *user_data;
        
        callback = g_srv_bootup_protocol_cntx.completed_callback;
        user_data = g_srv_bootup_protocol_cntx.user_data;
        g_srv_bootup_protocol_cntx.completed_callback = NULL;
        g_srv_bootup_protocol_cntx.user_data = NULL;
        
        srv_bootup_emit_sim_slot_ready_event();
        callback(user_data);
    }

    return MMI_RET_OK;
}


/*****************************************************************************
 * Please refer to BootupSrvIprot.h
 *****************************************************************************/
void srv_bootup_init_sim_module(
        srv_bootup_work_completed_callback completed_callback,
        void *user_data)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(SRV_BOOTUP_TRC_GROUP, TRC_SRV_BOOTUP_INIT_SIM_MODULE, (U32)completed_callback);

    g_srv_bootup_protocol_cntx.user_data = user_data;
    g_srv_bootup_protocol_cntx.completed_callback = completed_callback;

    if (g_srv_bootup_protocol_cntx.sim_inited)
    {
        mmi_event_struct evt;
            
        MMI_FRM_INIT_EVENT(&evt, 0);
        MMI_FRM_POST_EVENT(&evt, srv_bootup_init_sim_callback_proc, NULL);
    }
}


/* mmi_smu_sim_status_update_ind_struct is not available on single SIM project */
#if (MMI_MAX_SIM_NUM >= 2)
/*****************************************************************************
 * FUNCTION
 *  srv_bootup_sim_status_update_ind_received
 * DESCRIPTION
 *  The handler of SMU_SIM_STATUS_UPDATE_IND.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static U8 srv_bootup_sim_status_update_ind_received(void *msg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_bootup_sim_cntx_struct *sim_cntx;
    mmi_smu_sim_status_update_ind_struct *sim_status_update_ind;
    S32 i;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    sim_status_update_ind = (mmi_smu_sim_status_update_ind_struct*)msg;

    for (i = 0; i < MMI_SIM_TOTAL; i++)
    {
        mmi_sim_enum sim = mmi_frm_index_to_sim(i);
        sim_cntx = srv_bootup_get_sim_cntx(sim);
		#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
		#endif
		sim_cntx->is_inserted = ((sim_status_update_ind->sim_inserted_status & sim) != 0);
    }

    /* We don't callback again if SIM already inited */
    if (!g_srv_bootup_protocol_cntx.sim_inited)
    {
        g_srv_bootup_protocol_cntx.sim_inited = MMI_TRUE;

        /*
         * Post callback, so that SimCtrl status can be updated first,
         * then continue booting.
         */
        if (g_srv_bootup_protocol_cntx.completed_callback != NULL)
        {
            mmi_event_struct evt;
                
            MMI_FRM_INIT_EVENT(&evt, 0);
            MMI_FRM_POST_EVENT(&evt, srv_bootup_init_sim_callback_proc, NULL);
        }
    }

    return (U8)MMI_FALSE;
}
#endif /* (MMI_MAX_SIM_NUM >= 2) */


/*****************************************************************************
 * Please refer to BootupSrvIprot.h
 *****************************************************************************/
MMI_BOOL srv_bootup_sim_is_inserted(mmi_sim_enum sim)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_bootup_sim_cntx_struct *sim_cntx;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    /*
     * This status is known only after srv_bootup_init_sim_module()
     * was called.
     */
    MMI_ASSERT(g_srv_bootup_protocol_cntx.sim_inited);

    sim_cntx = srv_bootup_get_sim_cntx(sim);

    MMI_TRACE(SRV_BOOTUP_TRC_GROUP, TRC_SRV_BOOTUP_SIM_IS_INSERTED, sim, sim_cntx->is_inserted);
    
    return (sim_cntx->is_inserted);
}


#if (MMI_MAX_SIM_NUM == 1)
/*****************************************************************************
 * FUNCTION
 *  srv_bootup_active_l4
 * DESCRIPTION
 *  Send CFUN_STATE_REQ to specified module.
 * PARAMETERS
 *  l4_mod      [IN] MOD_L4C or MOD_L4C_2
 *  enable_rf   [IN] Enable RF
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_bootup_activate_l4(U16 l4_mod, MMI_BOOL enable_rf)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_nw_cfun_state_req_struct *cfun_state_req;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    cfun_state_req = OslConstructDataPtr(sizeof(mmi_nw_cfun_state_req_struct));

    cfun_state_req->cfun_state = (enable_rf ? 1 : 4);
    mmi_frm_send_ilm(
        l4_mod,
        MSG_ID_MMI_NW_CFUN_STATE_REQ,
        (oslParaType*)cfun_state_req,
        NULL);
}
#endif /* (MMI_MAX_SIM_NUM == 1) */


#if (MMI_MAX_SIM_NUM >= 2)
/*****************************************************************************
 * FUNCTION
 *  srv_bootup_protocol_efun_state_rsp_hdlr
 * DESCRIPTION
 *  The handler of EFUN_STATE_RSP.
 *  This function only sets the flag of EFUN_STATE_RSP received.
 * PARAMETERS
 *  sim     [IN] Which protocol
 *  msg     [IN] Unused
 * RETURNS
 *  Always MMI_FALSE
 *****************************************************************************/
static MMI_BOOL srv_bootup_protocol_efun_state_rsp_hdlr(void *msg, S32 src_mod)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_bootup_protocol_cntx_struct *cntx;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    cntx = &g_srv_bootup_protocol_cntx;

    cntx->control.cfun_rsp = MMI_SIM_ALL;

    mmi_frm_clear_protocol_event_handler(MSG_ID_MMI_NW_EFUN_STATE_RSP, (PsIntFuncPtr)srv_bootup_protocol_efun_state_rsp_hdlr); // Gemini+
    
    return MMI_FALSE;
}


/*****************************************************************************
 * FUNCTION
 *  srv_bootup_activate_l4_ext
 * DESCRIPTION
 *  Send EFUN_STATE_REQ to specified module.
 * PARAMETERS
 *  user_mode    [IN]
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_bootup_activate_l4_ext(srv_bootup_sim_bit_set user_mode)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_nw_efun_state_req_struct *efun_state_req;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    efun_state_req = OslConstructDataPtr(sizeof(mmi_nw_efun_state_req_struct));

    efun_state_req->efun_state = user_mode;
    mmi_frm_send_ilm(
        MOD_L4C,
        MSG_ID_MMI_NW_EFUN_STATE_REQ,
        (oslParaType*)efun_state_req,
        NULL);
}
#endif /* (MMI_MAX_SIM_NUM >= 2) */


/*****************************************************************************
 * FUNCTION
 *  srv_bootup_protocol_is_activated
 * DESCRIPTION
 *  The protocol layer is activated.
 *  That is, CFUN_STATE_REQ was sent. If not, we should ignore
 *  SMU_PASSWORD_REQUIRED_IND or SMU_FAIL_IND from the layer.
 *
 *  [MAUI_01782781] SMU_FAIL_IND arrives before animation.
 *  SMU_FAIL_IND may be received right after SMU_RESET_REQ, before the 
 *  CFUN_STATE_REQ. We should ignore the SMU_FAIL_IND. After mode is decided
 *  and CFUN_STATE_REQ is sent, another SMU_FAIL_IND will be received.
 *  This way may result less rick than modifying PowerOnNormalMode() or other
 *  place; let SMU_FAIL_IND will be found and processed once as previous.
 * PARAMETERS
 *  sim     [IN] Protocol layer
 * RETURNS
 *  CFUN_STATE_REQ of the protocol layer was sent.
 *****************************************************************************/
MMI_BOOL srv_bootup_protocol_is_activated(mmi_sim_enum sim)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return (MMI_BOOL)((g_srv_bootup_protocol_cntx.control.cfun_sent & sim) != 0);
}


/*****************************************************************************
 * FUNCTION
 *  srv_bootup_protocol_get_query_setting
 * DESCRIPTION
 *  Get query setting for dual SIM project.
 * PARAMETERS
 *  void
 * RETURNS
 *  Query setting
 *****************************************************************************/
srv_bootup_protocol_query_enum srv_bootup_protocol_get_query_setting(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_srv_bootup_protocol_cntx.query_setting == SRV_BOOTUP_PROTOCOL_QUERY_INVALID)
    {
#if (MMI_MAX_SIM_NUM >= 2)
        switch (srv_mode_switch_get_switch_type())
        {
            case SRV_MODE_SWITCH_STATIC_MODE:
                g_srv_bootup_protocol_cntx.query_setting = SRV_BOOTUP_PROTOCOL_QUERY_APPLY_DEFAULT;
                break;

           // case SRV_MODE_SWITCH_DYNAMIC_MODE:
             //   g_srv_bootup_protocol_cntx.query_setting = SRV_BOOTUP_PROTOCOL_QUERY_ASK_USER;
               // break;

            default:
                g_srv_bootup_protocol_cntx.query_setting = SRV_BOOTUP_PROTOCOL_QUERY_ASK_USER;
                break;
        }
    
#else /* Single SIM */

    #ifdef __FLIGHT_MODE_SUPPORT__
        if (srv_mode_switch_is_query_mode_enabled())
        {
            g_srv_bootup_protocol_cntx.query_setting = SRV_BOOTUP_PROTOCOL_QUERY_ASK_USER;
        }
        else
        {
            g_srv_bootup_protocol_cntx.query_setting = SRV_BOOTUP_PROTOCOL_QUERY_APPLY_DEFAULT;
        }
    #else /* __FLIGHT_MODE_SUPPORT__ */
        g_srv_bootup_protocol_cntx.query_setting = SRV_BOOTUP_PROTOCOL_QUERY_APPLY_DEFAULT;
    #endif /* __FLIGHT_MODE_SUPPORT__ */

#endif
    }

    MMI_TRACE(SRV_BOOTUP_TRC_GROUP, TRC_SRV_BOOTUP_QUERY_SETTING, g_srv_bootup_protocol_cntx.query_setting);

    return g_srv_bootup_protocol_cntx.query_setting;
}


/*****************************************************************************
 * FUNCTION
 *  srv_bootup_write_mode_selection_to_system
 * DESCRIPTION
 *  Write mode selection to system
 * PARAMETERS
 *  mode    [IN] Bootup ptococol mode.
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_bootup_write_mode_selection_to_system(
                srv_bootup_protocol_mode_enum mode)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_mode_switch_type_enum setting_mode;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    setting_mode = SRV_MODE_SWITCH_ALL_OFF;
    
    switch (mode)
    {
#if (MMI_MAX_SIM_NUM >= 2)
        default:
            MMI_ASSERT(mode <= SRV_BOOTUP_PROTOCOL_MODE_ALL_SIM);
            setting_mode = (srv_mode_switch_type_enum)mode; /* Gemini+: bit operation for mode setting so it has to be the same in bootup module and mode switch module */
            break;

#else /* (MMI_MAX_SIM_NUM >= 2) */

#ifdef __FLIGHT_MODE_SUPPORT__
        case SRV_BOOTUP_PROTOCOL_MODE_FLIGHT_MODE:
            setting_mode = SRV_MODE_SWITCH_FLIGHT_MODE;
            break;
#endif /* __FLIGHT_MODE_SUPPORT__ */

        case SRV_BOOTUP_PROTOCOL_MODE_NORMAL_MODE:
            setting_mode = SRV_MODE_SWITCH_NORMAL_MODE;
            break;

        default:
            MMI_ASSERT(MMI_FALSE);
            break;

#endif /* (MMI_MAX_SIM_NUM >= 2) */
    }

	srv_mode_switch_set_current_mode(setting_mode);
}


#if (MMI_MAX_SIM_NUM >= 2)
/*****************************************************************************
 * FUNCTION
 *  srv_bootup_protocol_get_to_be_enabled_sim_set
 * DESCRIPTION
 *  This function returns the control flags of the contract to L4C/L4C_2
 *  by bootup mode.
 * PARAMETERS
 *  mode    [IN] Bootup mode.
 * RETURNS
 *  Control flags which controls the modes of L4C & L4C_2.
 *****************************************************************************/
static srv_bootup_sim_bit_set srv_bootup_protocol_get_to_be_enabled_sim_set(
                                srv_bootup_protocol_mode_enum mode)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_bootup_sim_bit_set to_be_enabled;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    to_be_enabled = 0;

#if (MMI_MAX_SIM_NUM == 2)
    if (mode == SRV_BOOTUP_PROTOCOL_MODE_DUAL_SIM)
    {
        /*
         * Refer to the mode table in Bootup HLD
         */
        if (srv_bootup_sim_is_inserted(MMI_SIM1))
        {
            to_be_enabled |= MMI_SIM1;
        }
        if (srv_bootup_sim_is_inserted(MMI_SIM2))
        {
            to_be_enabled |= MMI_SIM2;
        }
        if (to_be_enabled == 0)
        {
            /* To enable emergency call through SIM1 */
            to_be_enabled = MMI_SIM1;
        }
    }
    else
#endif /* (MMI_MAX_SIM_NUM == 2) */
    {
        to_be_enabled = mode;
    }

    return to_be_enabled;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_bootup_dual_sim_start_bootup_by_mode
 * DESCRIPTION
 *  Start bootup procedure by the mode. It will start to send request to L4C
 *  and L4C_2.
 * PARAMETERS
 *  Mode    [IN] Bootup SIM mode.
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_bootup_protocol_boot_multiple_sims(srv_bootup_protocol_mode_enum mode)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    //srv_bootup_sim_bit_set to_be_enabled;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    //to_be_enabled = srv_bootup_protocol_get_to_be_enabled_sim_set(mode);
    //g_srv_bootup_protocol_cntx.control.to_be_enabled = to_be_enabled;

    srv_bootup_activate_l4_ext(srv_bootup_protocol_get_to_be_enabled_sim_set(mode));
    g_srv_bootup_protocol_cntx.control.cfun_sent = MMI_SIM_ALL;

    /*
     * waiting flag will be cleaned once the SMU_PASSWORD_REQUIRED_IND or
     * SMU_FAIL_IND arrived. If all waiting flags are cleaned, the callback
     * will be called to notify completion of L4C power-on.
     */
    g_srv_bootup_protocol_cntx.control.waiting = MMI_SIM_ALL;

    g_srv_bootup_protocol_cntx.control.cfun_rsp = 0;

#if (MMI_MAX_SIM_NUM == 1)
    mmi_frm_set_single_protocol_event_handler(MSG_ID_MMI_NW_CFUN_STATE_RSP, (PsIntFuncPtr)srv_bootup_protocol_cfun_state_rsp_hdlr); // Gemini+
#else
    mmi_frm_set_single_protocol_event_handler(MSG_ID_MMI_NW_EFUN_STATE_RSP, (PsIntFuncPtr)srv_bootup_protocol_efun_state_rsp_hdlr); // Gemini+
#endif
}

#endif /* (MMI_MAX_SIM_NUM >= 2) */


#if (MMI_MAX_SIM_NUM == 1)
/*****************************************************************************
 * FUNCTION
 *  srv_bootup_protocol_boot_single_sim
 * DESCRIPTION
 *  Bootup protocol on single SIM project.
 * PARAMETERS
 *  mode    [IN] Protocol mode
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_bootup_protocol_boot_single_sim(srv_bootup_protocol_mode_enum mode)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#ifdef __FLIGHT_MODE_SUPPORT__
    if (mode == SRV_BOOTUP_PROTOCOL_MODE_FLIGHT_MODE)
    {
        //g_srv_bootup_protocol_cntx.control.to_be_enabled = 0;
        srv_bootup_activate_l4(MOD_L4C, MMI_FALSE);
    }
    else /* SRV_BOOTUP_PROTOCOL_MODE_NORMAL_MODE */
#endif
    {
        //g_srv_bootup_protocol_cntx.control.to_be_enabled = MMI_SIM1;
        srv_bootup_activate_l4(MOD_L4C, MMI_TRUE);
    }

    /*
     * waiting flag will be cleaned once the SMU_PASSWORD_REQUIRED_IND or
     * SMU_FAIL_IND arrived. If it is cleaned, the callback will be called
     * to notify the completion of L4C power-on.
     */
    g_srv_bootup_protocol_cntx.control.waiting = MMI_SIM1;
    g_srv_bootup_protocol_cntx.control.cfun_rsp = 0;
    g_srv_bootup_protocol_cntx.control.cfun_sent = MMI_SIM1;

    mmi_frm_set_single_protocol_event_handler(MSG_ID_MMI_NW_CFUN_STATE_RSP, (PsIntFuncPtr)srv_bootup_protocol_cfun_state_rsp_hdlr);
}
#endif


/*****************************************************************************
 * FUNCTION
 *  srv_bootup_protocol_l4_response_hdlr
 * DESCRIPTION
 *  Handler for the ready notification from L4C or L4C_2.
 *  The ready notification is via SMU_PASSWORD_REQUIRED_IND or 
 *  SMU_FAIL_IND. This handler is used to listen to them.
 * PARAMETERS
 *  sim     [IN] Which protocol
 *  msg     [IN] Unused. The content may be smu_password_required_ind or
 *               smu_fail_ind, don't assume its type.
 * RETURNS
 *  Always MMI_FALSE; means continue message routing.
 *****************************************************************************/
static MMI_BOOL srv_bootup_protocol_l4_response_hdlr(void *msg, S32 src_mod)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_sim_enum sim;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    sim = mmi_frm_l4c_mod_to_sim((module_type)src_mod);

    #ifdef __INVALID_SIM_RECOVERY__
    if(srv_sim_ctrl_invalid_sim_recovery_get_status(sim) == MMI_TRUE)
    {
        return MMI_FALSE;
    }
    #endif

    if ((g_srv_bootup_protocol_cntx.control.waiting & sim) == 0)
    {
        /* Already arrived before or we are not waiting for it. */
        return MMI_FALSE;
    }

    /* The protocol layer we are waiting for arrived, clear the corresponding bit */
    g_srv_bootup_protocol_cntx.control.waiting &= ~sim;

    MMI_TRACE(SRV_BOOTUP_TRC_GROUP, TRC_SRV_BOOTUP_PROTOCOL_L4_RESPONSE,
        sim, g_srv_bootup_protocol_cntx.control.waiting);

    if (g_srv_bootup_protocol_cntx.control.waiting == 0 && /* all arrived */
        g_srv_bootup_protocol_cntx.completed_callback != NULL)
    {
        /* Notify client protocol layers are ready */
        g_srv_bootup_protocol_cntx.completed_callback(
            g_srv_bootup_protocol_cntx.user_data);
    }

    return MMI_FALSE;
}


#if (MMI_MAX_SIM_NUM == 1)
/*****************************************************************************
 * FUNCTION
 *  srv_bootup_protocol_cfun_state_rsp_hdlr
 * DESCRIPTION
 *  The handler of CFUN_STATE_RSP.
 *  This function only sets the flag of CFUN_STATE_RSP received.
 * PARAMETERS
 *  sim     [IN] Which protocol
 *  msg     [IN] Unused
 * RETURNS
 *  Always MMI_FALSE
 *****************************************************************************/
static MMI_BOOL srv_bootup_protocol_cfun_state_rsp_hdlr(void *msg, S32 src_mod)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_sim_enum sim;
    srv_bootup_protocol_cntx_struct *cntx;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    sim = mmi_frm_l4c_mod_to_sim(src_mod);
    cntx = &g_srv_bootup_protocol_cntx;

    if (cntx->control.cfun_rsp & sim)
    {
        /* We already received the CFUN_STATE_RSP from the protocol layer */
        return MMI_FALSE;
    }

    cntx->control.cfun_rsp |= sim;

    if (cntx->control.cfun_sent != 0 &&     /* CFUN_STATE_REQ has been sent */
        cntx->control.cfun_rsp == cntx->control.cfun_sent) /* All CFUN_STATE_RSP arrived */
    {
        mmi_frm_clear_protocol_event_handler(MSG_ID_MMI_NW_CFUN_STATE_RSP, (PsIntFuncPtr)srv_bootup_protocol_cfun_state_rsp_hdlr);
    }

    return MMI_FALSE;
}
#endif /* (MMI_MAX_SIM_NUM == 1) */ 


/*****************************************************************************
 * FUNCTION
 *  srv_bootup_protocol_is_ready
 * DESCRIPTION
 *  To query whether all CFUN_STATE_RSPs are received.
 * PARAMETERS
 *  void
 * RETURNS
 *  All CFUN_STATE_RSPs are received.
 *****************************************************************************/
MMI_BOOL srv_bootup_protocol_is_ready(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_bootup_protocol_cntx_struct *cntx;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    cntx = &g_srv_bootup_protocol_cntx;
    
    return (MMI_BOOL)(cntx->control.cfun_sent != 0 &&     /* CFUN_STATE_REQ has been sent */
        cntx->control.waiting == 0 &&           /* L4C responded completely */
        cntx->control.cfun_rsp == cntx->control.cfun_sent); /* All CFUN_STATE_RSP arrived */
}


/*****************************************************************************
 * Please refer to BootupSrvIprot.h
 *****************************************************************************/
void srv_bootup_boot_protocol(
        srv_bootup_protocol_mode_enum mode,
        srv_bootup_work_completed_callback completed_callback,
        void *user_data)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* We can not boot protocol twice */
    MMI_ASSERT(g_srv_bootup_protocol_cntx.control.cfun_sent == 0);

    MMI_TRACE(SRV_BOOTUP_TRC_GROUP, TRC_SRV_BOOTUP_BOOT_PROTOCOL, mode);

#if !defined(__FLIGHT_MODE_SUPPORT__) && (MMI_MAX_SIM_NUM == 1)
    /* Normal mode only */
    mode = SRV_BOOTUP_PROTOCOL_MODE_NORMAL_MODE;
#endif
    
    g_srv_bootup_protocol_cntx.completed_callback = completed_callback;
    g_srv_bootup_protocol_cntx.user_data = user_data;

    mmi_frm_set_multi_protocol_event_handler(MSG_ID_MMI_SMU_PASSWORD_REQUIRED_IND, (PsIntFuncPtr)srv_bootup_protocol_l4_response_hdlr);
    mmi_frm_set_multi_protocol_event_handler(MSG_ID_MMI_SMU_FAIL_IND, (PsIntFuncPtr)srv_bootup_protocol_l4_response_hdlr);

#if (MMI_MAX_SIM_NUM >= 2)
    if (srv_mode_switch_is_network_service_available()) // if not power on with flight mode directly, then update the user setting to nvram
#else
    if (srv_bootup_protocol_get_query_setting() == SRV_BOOTUP_PROTOCOL_QUERY_ASK_USER) // for single sim project, update user setting to memory
#endif
    {
        /* Inform mode switching user's selection */
        srv_bootup_write_mode_selection_to_system(mode);
    }

#if (MMI_MAX_SIM_NUM >= 2)
    srv_bootup_protocol_boot_multiple_sims(mode);
#else
    srv_bootup_protocol_boot_single_sim(mode);
#endif

    srv_bootup_sec_init_for_protocol();
}