ft_fnc_misc_ex.c 15.4 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
/*****************************************************************************
 *
 * Filename:
 * ---------
 *   ft_fnc_misc_ex.c
 *
 * Project:
 * --------
 *   MAUI
 *
 * Description:
 * ------------
 *  Misc Function
 *
 * 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!
 *
 *
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/

/*************************************************************************
 * Include Statements for KAL
 *************************************************************************/
#include "stack_common.h"
#include "stack_msgs.h"
#include "app_ltlcom.h"
#include "fctycomp_config.h"
#include "stack_config.h"
#include "kal_general_types.h"
#include "kal_public_api.h"
/**************************************************************************
 * FT header
 *************************************************************************/
#include "ft_msg.h"
#include "ft_private.h"
#include "ft_fnc_misc_ex.h"
/**************************************************************************
 * Custom header
 *************************************************************************/
#include "meta_customize.h"
#if defined(__TC01_ERS_SUPPORT__)
// FIXME: remove the compile option wrapping after GOLF QM
#include "ers_type.h"
#include "ers_api.h"
#endif // #if defined(__TC01_ERS_SUPPORT__)

kal_uint16 ft_gl_misc_ex_token = 0;
kal_uint8  *ft_gl_misc_ex_buf = NULL;
kal_uint8  FT_MISC_EX_SendCnf(FT_MISC_EX_CNF *ft_misc_ret, peer_buff_struct *peer_buff)
{

    ilm_struct          *ilm_ptr;
    FT_MISC_EX_CNF  *ptrMsg;

    if( NULL == (ilm_ptr=FT_ALLOC_MSG(sizeof(FT_MISC_EX_CNF))) ) {
        return 1;
    }

    /* if ptrMsg != NULL*/
    ptrMsg = (FT_MISC_EX_CNF *)ilm_ptr->local_para_ptr;

    // assign primitive id
    ptrMsg->header.ft_msg_id = FT_MISC_EX_CMD_CNF_ID;

    // assign return structure
    ptrMsg->type = ft_misc_ret->type;

    // copy the result directly without checking its cmd type
    kal_mem_cpy(&(ptrMsg->result), &(ft_misc_ret->result), sizeof(FT_MISC_EX_CNF_U));

    ptrMsg->status = ft_misc_ret->status;

    // assign peer buffer
    if( NULL != peer_buff )
    {
        ilm_ptr->peer_buff_ptr = peer_buff;
    }

    //FT_SEND_MSG(MOD_FT, MOD_TST, FT_TST_SAP, MSG_ID_FT_TO_TST, ilm_ptr);
    _FT_SendFtMsgByToken(MOD_FT, MOD_TST, FT_TST_SAP, MSG_ID_FT_TO_TST, ilm_ptr,ft_gl_misc_ex_token);
    return 0;
}

#if defined(__TC01_ERS_SUPPORT__)
void FT_ReadERS_Data(ilm_struct *ptrMsg)
{
    kal_uint16        pdu_length_in;
    kal_char          *pdu_ptr_in;
    FT_MISC_EX_CNF      misc_ex_cnf;
    kal_int32         ers_data_size;
    kal_uint8         *p_ers_data ;
    kal_int32         ers_data_idx;
    kal_uint32        u4CurOffset = 0;




    misc_ex_cnf.type = FT_MISC_EX_OP_GET_ERS_DATA;
    misc_ex_cnf.status = FT_CNF_FAIL;  // default value
    ers_data_size = ERS_query_size(); //wise_query_ERS_size();

    if( NULL != ptrMsg->peer_buff_ptr )
    {
        pdu_ptr_in = get_pdu_ptr( ptrMsg->peer_buff_ptr, &pdu_length_in );
    }
    kal_mem_cpy(&ers_data_idx, pdu_ptr_in, 4);
    p_ers_data = (kal_uint8*)ERS_query_content_by_idx(ers_data_idx);//wise_query_ERS_content((WCHAR *)pdu_ptr_in);

    // organize the buffer, and send it sequentially to PC side
    if(p_ers_data != NULL)
    {
        // allocate the peer buffer to send to PC-side
        while(u4CurOffset < ers_data_size)
        {

            peer_buff_struct *peer_buff = NULL;
            kal_char *pdu_ptr = NULL;
            kal_uint16   pdu_length = 0;
            kal_uint16  u2_cur_len = FT_MISC_EX_DATA_FRAME_SIZE; // default: 1800 bytes to send

            misc_ex_cnf.result.m_rErsDataFrm.m_u4TotalSize = ers_data_size;
            misc_ex_cnf.result.m_rErsDataFrm.m_u4CurOffset = u4CurOffset;
            if(u4CurOffset+FT_MISC_EX_DATA_FRAME_SIZE >= ers_data_size)
            {
                misc_ex_cnf.result.m_rErsDataFrm.m_bLastFrm = true;
                u2_cur_len =  ers_data_size - u4CurOffset;
            }
            else
                misc_ex_cnf.result.m_rErsDataFrm.m_bLastFrm = false;

            // allocate a peer buffer
            if( NULL != (peer_buff=construct_peer_buff(u2_cur_len,  0, 0, TD_CTRL)) )
            {
                pdu_ptr = get_pdu_ptr( peer_buff, &pdu_length );
                kal_mem_cpy(pdu_ptr, p_ers_data+u4CurOffset , u2_cur_len);
                peer_buff->pdu_len = u2_cur_len;
            }
            misc_ex_cnf.status = FT_CNF_OK;
            FT_MISC_EX_SendCnf(&misc_ex_cnf, peer_buff);
            kal_sleep_task(50);

            peer_buff = NULL;// the mem will be released by FT task when copy to TST buffer
            u4CurOffset += u2_cur_len;


        }

    }
    else
    {
        misc_ex_cnf.status = 0xFF;
        FT_MISC_EX_SendCnf(&misc_ex_cnf, NULL);
    }

}
#endif // #if defined(__TC01_ERS_SUPPORT__)

void FT_Handle_CNF_From_NVRAM(ilm_struct* ptrMsgCnf)
{
    FT_MISC_EX_CNF misc_ex_cnf;
    peer_buff_struct *peer_buff_ret = NULL;  // default value
    misc_ex_cnf.status = FT_CNF_FAIL;  // default value
    switch (ptrMsgCnf->msg_id)
    {
#if defined(__MOD_NVRAM__)&& defined(__SYSDRV_BACKUP_DISK_RAW__)
        case  MSG_ID_NVRAM_CREATE_IMAGE_CNF:
        {
            nvram_create_image_cnf_struct *cnf = (nvram_create_image_cnf_struct*)ptrMsgCnf->local_para_ptr;
            misc_ex_cnf.type = (FT_MISC_EX_CMD_TYPE)cnf->access_id;//FT_MISC_EX_OP_COPY_NVRAM_TO_BP_AREA;
            misc_ex_cnf.status = cnf->result;
            break;
        }
        case MSG_ID_NVRAM_VERIFY_IMAGE_CNF:
        {
            nvram_verify_image_cnf_struct *cnf = (nvram_verify_image_cnf_struct*)ptrMsgCnf->local_para_ptr;
            misc_ex_cnf.type = (FT_MISC_EX_CMD_TYPE)cnf-> access_id; //FT_MISC_EX_OP_VERIFY_BP_AREA;
            misc_ex_cnf.status = FT_CNF_OK;
            if(cnf->result == NVRAM_ERRNO_SUCCESS)
                misc_ex_cnf.result.m_u4BPStatus = META_BP_AREA_STATUS_OK;
            else if(cnf->result == NVRAM_ERRNO_IMAGE_EMPTY)
                misc_ex_cnf.result.m_u4BPStatus = META_BP_AREA_STATUS_EMPTY;
            else if(cnf->result == NVRAM_ERRNO_IMAGE_BROKEN)
                misc_ex_cnf.result.m_u4BPStatus = META_BP_AREA_STATUS_BROKEN;
            else if(cnf->result == NVRAM_ERRNO_IMAGE_DATA_NOT_SYNC)
                misc_ex_cnf.result.m_u4BPStatus = META_BP_AREA_STATUS_NO_SYNC;
            else{
                misc_ex_cnf.status = FT_CNF_FAIL;
                misc_ex_cnf.result.m_u4BPStatus = cnf->result;
            }
            break;
        }
#endif // end of #if defined(__MOD_NVRAM__)&& defined(__SYSDRV_BACKUP_DISK_RAW__)
        case MSG_ID_NVRAM_SDS_CNF:
        {
        #ifndef __SYSDRV_BACKUP_DISK__
            if(!Custom_META_SdsSupported())
            {
                misc_ex_cnf.type = FT_MISC_EX_OP_BACKUP_TO_SDS;
                misc_ex_cnf.status = FT_CNF_FAIL;
                misc_ex_cnf.result.m_u4SDSStatus = 0;
            }
            else
        #endif
            {
                nvram_sds_cnf_struct* cnf = (nvram_sds_cnf_struct*)ptrMsgCnf->local_para_ptr;
                misc_ex_cnf.type = (FT_MISC_EX_CMD_TYPE)cnf->access_id;
                misc_ex_cnf.status = FT_CNF_OK;
                misc_ex_cnf.result.m_u4SDSStatus = cnf->result;
            }
            break;
        }
        default:
            return;
    }
    FT_MISC_EX_SendCnf(&misc_ex_cnf,peer_buff_ret);
}



void FT_MISC_EX_Operation(ilm_struct *ptrMsg)
{
#if defined(__TC01_ERS_SUPPORT__)
    kal_char*             pdu_ptr;
    kal_uint16            pdu_length;
#endif // #if defined(__TC01_ERS_SUPPORT__)
    ilm_struct*           ptr_ilm;
    FT_MISC_EX_CNF        misc_ex_cnf;
    FT_MISC_EX_REQ*       p_req = (FT_MISC_EX_REQ *)ptrMsg->local_para_ptr;
    peer_buff_struct*     peer_buff_ret = NULL;  // default value

    misc_ex_cnf.type     = p_req->type;
    misc_ex_cnf.status   = FT_CNF_FAIL;
    ft_gl_misc_ex_token  = p_req->header.token;
    switch(p_req->type)
    {
        case FT_MISC_EX_OP_GET_ERS_COUNT:
        {
#if defined(__TC01_ERS_SUPPORT__)
            misc_ex_cnf.result.m_i4ErsDataCount = ERS_query_count(); //wise_query_ERS_count();
#else // #if defined(__TC01_ERS_SUPPORT__)
            misc_ex_cnf.result.m_i4ErsDataCount = 0;
#endif // #if !defined(__TC01_ERS_SUPPORT__)
            misc_ex_cnf.status = FT_CNF_OK;
            break;
        }
        case FT_MISC_EX_OP_GET_ERS_DATA_INFO_BY_INDEX:
        {
#if defined(__TC01_ERS_SUPPORT__)
            ers_info_struct ers_info;
            ERS_query_info(p_req->cmd.m_i4ErsDataIndex, &ers_info);
            misc_ex_cnf.result.m_rErsDataTime.sec = ers_info.ers_ctime.sec;
            misc_ex_cnf.result.m_rErsDataTime.min = ers_info.ers_ctime.min;
            misc_ex_cnf.result.m_rErsDataTime.hour = ers_info.ers_ctime.hour;
            misc_ex_cnf.result.m_rErsDataTime.day = ers_info.ers_ctime.day;
            misc_ex_cnf.result.m_rErsDataTime.mon = ers_info.ers_ctime.mon;
            misc_ex_cnf.result.m_rErsDataTime.wday = ers_info.ers_ctime.wday;
            misc_ex_cnf.result.m_rErsDataTime.year = ers_info.ers_ctime.year;

            if( NULL != (peer_buff_ret=construct_peer_buff((2+1)*2, 0, 0, TD_CTRL)) ) // defined in mcu\external_mmi\wise\bal\sys\include\ws_dbg_type.h
            {
                pdu_ptr = get_pdu_ptr( peer_buff_ret, &pdu_length );
                // copy filename
                //kal_mem_cpy(pdu_ptr, (void *)ers_info.ers_filename, (kal_wstrlen(ers_info.ers_filename)+1)*2);
                kal_mem_cpy(pdu_ptr, (void*)&(p_req->cmd.m_i4ErsDataIndex), sizeof(kal_int32));
                kal_mem_set(pdu_ptr+4, 0x0, 2);
                peer_buff_ret->pdu_len = 6; //(kal_wstrlen(ers_info.ers_filename)+1)*2;
            }
            misc_ex_cnf.status = FT_CNF_OK;
#else // #if defined(__TC01_ERS_SUPPORT__)
            misc_ex_cnf.status = FT_CNF_FAIL;
#endif // #if !defined(__TC01_ERS_SUPPORT__)
            break;
        }
        case FT_MISC_EX_OP_GET_ERS_SIZE:
        {
#if defined(__TC01_ERS_SUPPORT__)
            misc_ex_cnf.result.m_u4ErsDataSize = ERS_query_size(); //wise_query_ERS_size();
#else // #if defined(__TC01_ERS_SUPPORT__)
            misc_ex_cnf.result.m_u4ErsDataSize = 0;
#endif // #if !defined(__TC01_ERS_SUPPORT__)
            misc_ex_cnf.status = FT_CNF_OK;
            break;
        }
        case  FT_MISC_EX_OP_GET_ERS_DATA: // send message to NVRAM task to read ERS data
        {
#if defined(__TC01_ERS_SUPPORT__)
            FT_ReadERS_Data(ptrMsg);
            return;
#else // #if defined(__TC01_ERS_SUPPORT__)
            misc_ex_cnf.status = FT_CNF_FAIL;
#endif // #if !defined(__TC01_ERS_SUPPORT__)
            break;
        }

#if defined(__MOD_NVRAM__) && defined(__SYSDRV_BACKUP_DISK_RAW__)
        case FT_MISC_EX_OP_COPY_NVRAM_TO_BP_AREA:
        {
            nvram_create_image_req_struct *ptrMsg;
            ptr_ilm = FT_ALLOC_OTHER_MSG( sizeof(nvram_create_image_req_struct) );

            ptrMsg = (nvram_create_image_req_struct *)ptr_ilm->local_para_ptr;

            ptrMsg->access_id = (kal_uint8)FT_MISC_EX_OP_COPY_NVRAM_TO_BP_AREA;
            ptrMsg->image_type = NVRAM_IMAGE_TYPE_DEFAULT;
            FT_SEND_MSG(MOD_FT, MOD_NVRAM, PS_NVRAM_SAP, MSG_ID_NVRAM_CREATE_IMAGE_REQ, ptr_ilm);// wait READ_CNF

            return;
        }
        case FT_MISC_EX_OP_VERIFY_BP_AREA:
        {
            nvram_verify_image_req_struct *ptrMsg;
            ptr_ilm = FT_ALLOC_OTHER_MSG( sizeof(nvram_verify_image_req_struct) );

            ptrMsg = (nvram_verify_image_req_struct *)ptr_ilm->local_para_ptr;

            ptrMsg->access_id = (kal_uint8)FT_MISC_EX_OP_VERIFY_BP_AREA;
            ptrMsg->image_type = NVRAM_IMAGE_TYPE_DEFAULT;
            ptrMsg->fast_verify =  (kal_bool)p_req->cmd.u1BPAreaFastCheck;
            FT_SEND_MSG(MOD_FT, MOD_NVRAM, PS_NVRAM_SAP, MSG_ID_NVRAM_VERIFY_IMAGE_REQ, ptr_ilm);// wait READ_CNF

            return;
        }
#endif // end of #if defined(__MOD_NVRAM__) && defined(__SYSDRV_BACKUP_DISK_RAW__)
        case FT_MISC_EX_OP_BACKUP_TO_SDS:
        {
#ifndef __SYSDRV_BACKUP_DISK__
            if(!Custom_META_SdsSupported())
            {
                misc_ex_cnf.status = FT_CNF_FAIL;
                break;
            }
            else
#endif // #if defined(__SYSDRV_BACKUP_DISK__)                 
            {
                nvram_sds_req_struct* ptrMsg;
                ptr_ilm = FT_ALLOC_OTHER_MSG(sizeof(nvram_sds_req_struct));
                ASSERT(ptr_ilm);
                ptrMsg = (nvram_sds_req_struct *)ptr_ilm->local_para_ptr;
                ptrMsg->access_id = (kal_uint8)FT_MISC_EX_OP_BACKUP_TO_SDS;
                // the access mode is defined in nvram_enums.h (nvram_sds_access_enum)
                ptrMsg->access_mode = (nvram_sds_access_enum)p_req->cmd.mode;
                FT_SEND_MSG(MOD_FT, MOD_NVRAM, PS_NVRAM_SAP, MSG_ID_NVRAM_SDS_REQ, ptr_ilm);
                return;
            }
        }
        default:
            return;
    }
    FT_MISC_EX_SendCnf(&misc_ex_cnf, peer_buff_ret);
}
kal_uint32 FT_MiscExCheckFunctionSupported(kal_uint32 query_op_code)
{
    kal_uint32 cnf_code;
    if(FT_MISC_EX_OP_END> query_op_code)
    {
        if( query_op_code == FT_MISC_EX_OP_GET_ERS_SIZE ||
                query_op_code == FT_MISC_EX_OP_GET_ERS_DATA
          )
        {
#ifdef WISDOM_MMI
/* under construction !*/
#else
            cnf_code = FT_CNF_FAIL;
#endif

        }
        else if(query_op_code == FT_MISC_EX_OP_COPY_NVRAM_TO_BP_AREA ||
                query_op_code == FT_MISC_EX_OP_VERIFY_BP_AREA
               )
        {
#if defined(__MOD_NVRAM__) && defined(__SYSDRV_BACKUP_DISK_RAW__)
            cnf_code = FT_CNF_OK;
#else
            cnf_code = FT_CNF_FAIL;
#endif

        }
        else if(query_op_code == FT_MISC_EX_OP_BACKUP_TO_SDS)
        {
#if defined(__SYSDRV_BACKUP_DISK__)
            cnf_code = FT_CNF_OK;
#else
            if(Custom_META_SdsSupported() == KAL_TRUE)
            {
                cnf_code = FT_CNF_OK;
            }
            else
            {
                cnf_code = FT_CNF_FAIL;
            }
#endif
        }
        /*******************************
         * obsoleted op codes
         ******************************/
        else if(query_op_code == FT_MISC_EX_OP_OBSOLETED1 ||
                query_op_code == FT_MISC_EX_OP_OBSOLETED2)
        {
            cnf_code = FT_CNF_FAIL;
        }
        else
        {
            cnf_code = FT_CNF_OK;
        }
    }
    else
    {
        cnf_code = FT_CNF_FAIL;
    }
    return cnf_code;
}