Esempio n. 1
0
/*****************************************************************************
 * FUNCTION
 *  dcd_wbxml_stag_hdlr
 * DESCRIPTION
 *  this function is used to get attrname by token 
 * PARAMETERS
 *  resv          [IN]        Reserved
 *  tagname       [IN]        Element name string
 *  attr          [IN]        Attribute list
 * RETURNS
 *  void
 *****************************************************************************/
static void dcd_wbxml_stag_hdlr(void * resv, const kal_char  *tagname, const kal_char **attr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	int i;
	int len;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	if ( mmi_dcd_stricmp(tagname, "sl") == 0)
	{
		i = 0;
		while ( attr[i] != NULL)
		{
			if ( mmi_dcd_stricmp(attr[i], "href") == 0)
			{
				i++;
				len  = strlen(attr[i]);
				g_sl_url_p = get_ctrl_buffer(len+1);
				strcpy(g_sl_url_p, attr[i]);
			}
			else if ( mmi_dcd_stricmp(attr[i], "action") == 0)
			{
				i++;
				len  = strlen(attr[i]);
				g_sl_action_p = get_ctrl_buffer(len+1);
				strcpy(g_sl_action_p, attr[i]);
			}
			i++;
		}
	}
}
Esempio n. 2
0
/*****************************************************************************
 * FUNCTION
 *  dcd_xml_start_elem_hdlr
 * DESCRIPTION
 *  this function is used to get tagname by token 
 * PARAMETERS
 * data        [IN]        Reserved
 * el          [IN]        Element name string
 * attr        [IN]        Attribute list
 *  error       [IN]        [out]       Error code
 * RETURNS   
 *  if < 0: failed(?)
 *****************************************************************************/
static void dcd_xml_start_elem_hdlr(void *data, const kal_char*el, const kal_char**attr, kal_int32 error)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	int i;
	int len;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	if ( mmi_dcd_stricmp(el, "sl") == 0)
	{
		i = 0;
		while ( attr[i] != NULL)
		{
			if ( mmi_dcd_stricmp(attr[i], "href") == 0)
			{
				i++;
				len  = strlen(attr[i]);
				g_sl_url_p = get_ctrl_buffer(len+1);
				strcpy(g_sl_url_p, attr[i]);
			}
			else if ( mmi_dcd_stricmp(attr[i], "action") == 0)
			{
				i++;
				len  = strlen(attr[i]);
				g_sl_action_p = get_ctrl_buffer(len+1);
				strcpy(g_sl_action_p, attr[i]);
			}
			i++;
		}
	}
}
Esempio n. 3
0
/*****************************************************************************
 * FUNCTION
 *  l4c_nw_reg_state_mind
 * DESCRIPTION
 *  
 * PARAMETERS
 *
 * RETURNS
 *  void
 *****************************************************************************/
void l4c_nw_reg_state_mind(kal_uint8 gsm_state, kal_uint8 gprs_state, kal_uint32 cause)
{
    kal_uint16 infBuffSize = 0;
    kal_uint8 *infBuff = NULL;
    mbci_context_struct *mbci_ptr = MBCI_PTR;

    mbci_ptr->NwError = cause;

    if (MBCI_PTR->state != MBCI_STATE_OPEN)
    {
        return;
    }

    // CS registration state
    if (mbci_ptr->gsm_state != gsm_state)
    {
        infBuff = (kal_uint8*)get_ctrl_buffer(sizeof(mbim_registration_state_info_struct) + 64);  // 64 byte reserve for ProviderId and ProviderName
        infBuffSize = mbci_get_registration_state_info(MBCI_SRC, (kal_uint8*)infBuff);
        mbci_status_ind(MBIM_CID_REGISTER_STATE, MBIM_UUID_BASIC_CONNECT, infBuffSize, infBuff);
        free_ctrl_buffer(infBuff);
    }

    // PS packet service state
    if (mbci_ptr->gprs_state != gprs_state)
    {
        infBuff = (kal_uint8*)get_ctrl_buffer(sizeof(mbim_packet_service_info_struct));
        infBuffSize = mbci_get_packet_service_info(MBCI_SRC, (kal_uint8*)infBuff);
        mbci_status_ind(MBIM_CID_PACKET_SERVICE, MBIM_UUID_BASIC_CONNECT, infBuffSize, infBuff);
        free_ctrl_buffer(infBuff);
    }

    mbci_ptr->gsm_state = gsm_state;
    mbci_ptr->gprs_state = gprs_state;
}
Esempio n. 4
0
/*****************************************************************************
 * FUNCTION
 *  format_asking_string
 * DESCRIPTION
 *  Add mid_name and "?" into string.
 * PARAMETERS
 *  string_id       [IN]        String ID
 * RETURNS
 *
 *****************************************************************************/
static PU8 format_asking_string(U16 string_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_int32 string_len = mmi_ucs2strlen(GetString(string_id));
    kal_wchar *mid_name = get_running_mid_name();

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (mid_name == NULL)
    {
        mid_name = (kal_wchar*) GetString(STR_SCR_JAVA_CAPTION);
    }
    if (asking_string_buffer != NULL)
    {
        free_ctrl_buffer(asking_string_buffer);
    }
    asking_string_buffer = (kal_wchar*) get_ctrl_buffer((string_len + mmi_ucs2strlen((S8*) mid_name) + 2) << 1);
    mmi_ucs2cpy((S8*) asking_string_buffer, GetString(string_id));
    mmi_ucs2cpy((S8*) (asking_string_buffer + string_len), (S8*) mid_name);
    string_len += mmi_ucs2strlen((S8*) mid_name);
    asking_string_buffer[string_len] = '?';
    asking_string_buffer[string_len + 1] = 0;
    return (PU8) asking_string_buffer;
}
void SP_Strm_Enable( ilm_struct *ilm_ptr )
{
   UART_CTRL_OPEN_T data;
   DCL_STATUS status;
   cmux_dlc_connect_ind_struct *local_para;
   
   if (intSStrmControl != NULL )
      return;
   local_para = (cmux_dlc_connect_ind_struct *)ilm_ptr->local_para_ptr;
   
   if( ss_enh_mutex == NULL) // no delete mutex
      ss_enh_mutex = kal_create_enh_mutex( "SP_STRM_ENH_MUTEX" );
   intSStrmControl = (SpStrmControl *)get_ctrl_buffer(sizeof(SpStrmControl));
   intSStrmControl->ul_ready = KAL_FALSE;
   intSStrmControl->ul_sample_count = 0;
   intSStrmControl->port = local_para->port;
   kal_prompt_trace(MOD_L1SP, "SS port %d", intSStrmControl->port);
#if !defined(SS_UNIT_TEST)   
   data.u4OwenrId = MOD_MED;
   intSStrmControl->cmux_handle = DclSerialPort_Open(intSStrmControl->port, 0);
   status = DclSerialPort_Control(intSStrmControl->cmux_handle, SIO_CMD_OPEN, (DCL_CTRL_DATA_T*)&data);
   ASSERT(STATUS_OK == status);
#endif
   L1SP_Register_Strm_Handler( spStrmOnHandler, spStrmOffHandler, spStrmCallback );
}
Esempio n. 6
0
/**
 * Get Path for requested size
 */
kal_int16 FT_GetAvailableDrive(kal_int32 size)
{
#if !defined(__LOW_COST_SUPPORT_ULC__)
    kal_int16 drv_letter       = -1;
    kal_int16 i                = 0;
    kal_uint32 dev[4]          = {FS_DRIVE_I_SYSTEM, FS_DRIVE_V_NORMAL, FS_DRIVE_V_REMOVABLE, FS_DRIVE_V_EXTERNAL};
    kal_wchar *pathname        = NULL;
    pathname = (kal_wchar*)get_ctrl_buffer(FT_FAT_MAX_FULLPATH);
    if(pathname)
    {
        for(i=0;i<4;i++)
        {
            drv_letter = FS_GetDrive(dev[i], 1, FS_NO_ALT_DRIVE);
            if(drv_letter > 0)
            {
                kal_wsprintf(pathname, "%c:\\", drv_letter);
                if(size < FT_GetDiskFreeSpace(pathname))
                {
                    break;
                }
            }
        }
    }
    else
    {
        ASSERT(0);
    }
    free_ctrl_buffer(pathname);
    return drv_letter;
#else // #if !defined(__LOW_COST_SUPPORT_ULC__)
    return -1;
#endif // #if defined(__LOW_COST_SUPPORT_ULC__)
}
Esempio n. 7
0
/*****************************************************************************
* FUNCTION
*   tcm_config_packets_add
* DESCRIPTION
*   This procedure adds config options.
*
* PARAMETERS
*   si_db_ptr            IN     Pointer to SIB
*   no_of_nodes_to_add   IN     nodes to be added
* RETURNS
*   void
* GLOBALS AFFECTED
*   N/A
*****************************************************************************/
void tcm_config_packets_add ( SESSION_INFO_PTR si_db_ptr, 
                              kal_uint8 no_of_nodes_to_add )
{
    tcm_protocol_config_packet_struct *head_node_ptr     = NULL;
    tcm_protocol_config_packet_struct *node_to_add_ptr   = NULL;
    kal_uint8                         nodes_count        = 0;

    head_node_ptr = &si_db_ptr->prot_options_struct;
    while (head_node_ptr->next_ptr != NULL )
    {
      head_node_ptr = head_node_ptr->next_ptr;
    }
    
    while ( nodes_count < no_of_nodes_to_add)
    {
      node_to_add_ptr  = (tcm_protocol_config_packet_struct *)
               get_ctrl_buffer (sizeof(tcm_protocol_config_packet_struct));
               
      // kal_prompt_trace(MOD_TCM, "tcm_config_packets_add allocate: %x", node_to_add_ptr);// Carlson temp add, can remove this
      node_to_add_ptr->next_ptr = NULL;
      head_node_ptr->next_ptr = node_to_add_ptr;
      head_node_ptr = node_to_add_ptr; /* Danny fix bug. 03.11.01 */
      nodes_count = nodes_count + 1;
    }
    
    return;
}
MHdl *PCM_Strm_Rec_Open(void(*handler)( MHdl *handle, Media_Event event ), void *param)
{
   MHdl *hdl;
   pcmStrmMediaHdl *ihdl;

   ihdl = (pcmStrmMediaHdl*)get_ctrl_buffer( sizeof(pcmStrmMediaHdl) );
   memset(ihdl, 0, sizeof(pcmStrmMediaHdl));
   hdl = (MHdl *) ihdl;

   ihdl->pcmStrm.dedicated_mode = AM_IsSpeechOn();

   mhdlInit( hdl, 0, NULL );

   hdl->handler   = handler;
   hdl->state     = WAV_STATE_IDLE;
   ihdl->pcmStrm.isPlayback    = false;

   hdl->Close     = pcmStrmMFClose;
   hdl->Pause     = pcmStrmMFPause;
   hdl->Stop      = pcmStrmMFStop;
   hdl->Process   = pcmStrmMFProcess;
   hdl->Record    = pcmStrmMFRecord;
   hdl->Resume    = pcmStrmMFResume;

   kal_trace( TRACE_FUNC, L1AUDIO_OPEN_STREAM, MEDIA_FORMAT_PCM_8K );

   return hdl;
}
kal_int32 init_gt818_download_module( kal_uint16 cur_ver, kal_uint8 *firmware_ptr )
{
    kal_int32 ret = 0;

    outbuf = (kal_uint8 *)get_ctrl_buffer( MAX_BUFFER_LEN );
    inbuf  = (kal_uint8 *)get_ctrl_buffer( MAX_BUFFER_LEN );
    dbgbuf = (kal_char *)get_ctrl_buffer( MAX_BUFFER_LEN );
    
    
    if ( ( outbuf == NULL ) ||
         ( inbuf == NULL ) ||
         ( dbgbuf == NULL ) )
    {
        EXT_ASSERT(0, (kal_uint32)outbuf, (kal_uint32)inbuf, (kal_uint32)dbgbuf);
        return 0;
    }

    CTP_DWN_DEBUG_LINE_TRACE();
 
    //rst_handle = DclGPIO_Open(DCL_GPIO, GPIO_CTP_SHUTDN_PIN);
    //int_handle = DclGPIO_Open(DCL_GPIO, GPIO_CTP_INT_PIN);
    int_handle = DclGPIO_Open(DCL_GPIO, gpio_ctp_eint_pin);
    rst_handle = DclGPIO_Open(DCL_GPIO, gpio_ctp_reset_pin);
    DclGPIO_Control(rst_handle, GPIO_CMD_SET_MODE_0, NULL);
    DclGPIO_Control(int_handle, GPIO_CMD_SET_MODE_0, NULL);
    DclGPIO_Control(int_handle, GPIO_CMD_SET_DIR_OUT, NULL);
    ret = gt818_downloader_probe( cur_ver, firmware_ptr );
    //DclGPIO_Control(int_handle, GPIO_CMD_SET_DIR_IN, NULL);
    //DclGPIO_Control(int_handle, GPIO_CMD_SET_MODE_1, NULL);
    DclGPIO_Control(int_handle, GPIO_CMD_WRITE_HIGH, NULL);

    DclGPIO_Control(rst_handle, GPIO_CMD_WRITE_HIGH, NULL);
    kal_sleep_task(5);
    DclGPIO_Control(rst_handle, GPIO_CMD_WRITE_LOW, NULL);
    kal_sleep_task(5);
    DclGPIO_Control(rst_handle, GPIO_CMD_WRITE_HIGH, NULL);
    kal_sleep_task(120);

    free_ctrl_buffer( outbuf );
    free_ctrl_buffer( inbuf );
    free_ctrl_buffer( dbgbuf );

    if ( downloader_errno )
        EXT_ASSERT( 0, downloader_errno, 0, 0 );

    return ret;
}
/*****************************************************************************
 * FUNCTION
 *  tp_ps_handling_at_indication
 * DESCRIPTION
 *  This function is used to handle the response/URC data from MOD_ATCI
 *
 * PARAMETERS
 *  channelId             [IN]              
 *  buf             [IN]       
 *  iDataLen        [IN]       
 *
 * RETURNS
 * void
 *****************************************************************************/
static void tp_ps_handling_at_indication(kal_uint8  channelId, kal_char *buf, kal_uint16 iDataLen)
{
    kal_char *data;
    
    if (tp_callback == NULL || tp_port_begin == -1)
    {
        if (tp_callback == NULL)
        {
            kal_prompt_trace(
                    stack_get_active_module_id(),
                    "[Hdlr] ERROR: havn't register TP callback function");
        }
        else if (tp_port_begin == -1)
        {
            kal_prompt_trace(
                    stack_get_active_module_id(),
                    "[Hdlr] ERROR: havn't start PS, please call tp_ps_start first");
        }

        // buffer the URC
        if (channelId == RMMI_MSG_BASED_URC_CHANNEL)
        {
            kal_prompt_trace(
                    stack_get_active_module_id(),
                    "[Hdlr] Buffer the URC: %s", buf);
            if ( (tp_urc_buffer_len + iDataLen) > MAX_TP_URC_BUFFER_LENGTH)
            {
                kal_prompt_trace(
                    stack_get_active_module_id(),
                    "[Hdlr] URC buffer is full, clean the buffer", buf);

                tp_urc_buffer_len = 0;
            }
            
            if (iDataLen > MAX_TP_URC_BUFFER_LENGTH)
            {
               kal_prompt_trace(
                    stack_get_active_module_id(),
                    "[Hdlr] ERROR: the URC is too large, please increase the URC buffer");
            }
            else
            {
                kal_mem_cpy(tp_urc_buffer+tp_urc_buffer_len, buf, iDataLen);
                tp_urc_buffer_len += iDataLen;
            }
        }
    }
    else
    {

        data = get_ctrl_buffer(iDataLen);
        kal_mem_cpy(data, buf, iDataLen);
        
        tp_callback(channelId, data, iDataLen, 1);
        
        free_ctrl_buffer(data);
    }

}
Esempio n. 11
0
static BOOL mmi_da_wps_send_set_channel_req(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    wps_set_channel_req_struct      *set_channel_req;
    peer_buff_struct                *peer_buff_ptr = NULL;
    wps_set_channel_req_var_struct  set_channel_req_var;
    U16                             len, pdu_length;
    U16                             msg_len, ref_count;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    DA_WPS_TRACE(MMI_DA_WPS_TRACE_GROUP, MMI_DA_OMA_SEND_SET_CHANNEL_REQ);

    set_channel_req = (wps_set_channel_req_struct *) construct_local_para(sizeof(wps_set_channel_req_struct), TD_CTRL);
    msg_len = set_channel_req->msg_len;
    ref_count = set_channel_req->ref_count;
    memset(set_channel_req, 0 , sizeof(wps_set_channel_req_struct));
    set_channel_req->msg_len = msg_len;
    set_channel_req->ref_count = ref_count;
    set_channel_req->use_default = KAL_TRUE;
    set_channel_req_var.static_header_len = len =
        strlen("User-Agent: ")+
        strlen((S8*)da_wps_context.user_agent)+
        strlen("\r\n")+
        strlen(STATIC_HEADER);
    set_channel_req_var.static_header = get_ctrl_buffer((len+1));
    sprintf((S8*)set_channel_req_var.static_header,"User-Agent: %s\r\n%s",
            da_wps_context.user_agent, STATIC_HEADER);

    pdu_length= wps_pun_var_part(WPS_PUN_SIZE,MSG_ID_WPS_SET_CHANNEL_REQ,&set_channel_req_var,NULL);

    if( pdu_length > 0)
    {
        peer_buff_ptr = construct_peer_buff(pdu_length, 0, 0, TD_RESET);
        if (wps_pun_var_part(WPS_PUN_PACK, MSG_ID_WPS_SET_CHANNEL_REQ, &set_channel_req_var, get_pdu_ptr(peer_buff_ptr, &len)) !=
            pdu_length)
        {
            free_peer_buff(peer_buff_ptr);
            peer_buff_ptr = NULL;
        }
    }

    free_ctrl_buffer(set_channel_req_var.static_header);

    mmi_da_send_ilm(set_channel_req, peer_buff_ptr, MSG_ID_WPS_SET_CHANNEL_REQ, MOD_WPS);

    SetProtocolEventHandler((PsFuncPtr) mmi_da_wps_recv_set_channel_rsp, MSG_ID_WPS_SET_CHANNEL_RSP);
    return MMI_TRUE;
}
Esempio n. 12
0
/*****************************************************************************
 * FUNCTION
 *  l4c_sms_new_msg_pdu_mind
 * DESCRIPTION
 *  
 * PARAMETERS
 *
 * RETURNS
 *  void
 *****************************************************************************/
void l4c_sms_new_msg_pdu_mind(kal_uint8 mti, void *data, kal_uint16 packed_peer_buff_len)
{
    if (MBCI_PTR->state != MBCI_STATE_OPEN)
    {
        return;
    }

    if (mti == SMSAL_MTI_DELIVER)
    {
        kal_uint16 infBuffSize = 0;
        kal_uint8 *infBuff = NULL;
        mbim_sms_read_info_struct ind;
        MBIM_OL_PAIR_LIST SmsRefList;
        mbim_sms_pdu_record_struct pdu;

        infBuffSize = sizeof(ind) + sizeof(SmsRefList) + sizeof(pdu);
        infBuff = (kal_uint8*)get_ctrl_buffer(infBuffSize);

        ind.Format = MBIMSmsFormatPdu;
        ind.ElementCount = 1;

        SmsRefList.offset = sizeof(ind);
        SmsRefList.size = sizeof(pdu);

        pdu.MessageIndex = MBIM_MESSAGE_INDEX_NONE;
        pdu.MessageStatus = MBIMSmsStatusNew;
        pdu.PduDataOffset = 16;

        if (packed_peer_buff_len <= 183)
        {
            pdu.PduDataSize = packed_peer_buff_len;
        }
        else
        {
            DEBUG_ASSERT(0);
            pdu.PduDataSize = 183;
        }
        
        kal_mem_cpy((void*)pdu.DataBuffer, data, pdu.PduDataSize);

        // Copy to infBuff
        mbci_infBuff_cpy(infBuff, 0, sizeof(ind), (void*)&ind);
        mbci_infBuff_cpy(infBuff, sizeof(ind), sizeof(SmsRefList), (void*)&SmsRefList); 
        mbci_infBuff_cpy(infBuff, sizeof(ind) + sizeof(SmsRefList), sizeof(pdu), (void*)&pdu);         

        mbci_status_ind(MBIM_CID_SMS_READ, MBIM_UUID_SMS, infBuffSize, infBuff);
        free_ctrl_buffer(infBuff);
    }
}
Esempio n. 13
0
void BleServiceDbLoadRecord(void)
{
    if (BleDbCtx(loadCount) == 0)

    {
        Report(("[BleDB] Loading record..."));

//        kal_trace(BT_TRACE_BLE_PROFILES, BLEDB_LOADRECORD);

        BT_GattRegisterConnectedEvent(&BleDbCtx(gattHandler), BleServiceDbGattEventCallback);

        BleDbCtx(bondingHandler).callback = BleServiceDbBondingCb;
        ATTDB_RegisterBondStatus(&BleDbCtx(bondingHandler));

        if (btmtk_fs_is_dir_exist((const U8*)BLE_SERVICE_DATABASE_FILE))
        {
            S32 fd;
            S32 pos_current;
            S32 pos_end;
            ble_service_db *db_node;
            
            fd = btmtk_fs_open((const U8*)BLE_SERVICE_DATABASE_FILE, BTMTK_FS_READ_ONLY);
            if (fd < 0)
            {
                // file is not exist
                goto exit;
            }

            pos_end = btmtk_fs_seek(fd, 0, BTMTK_FS_SEEK_END);
            pos_current = btmtk_fs_seek(fd, 0, BTMTK_FS_SEEK_BEGIN);

            while (pos_current < pos_end)
            {
                db_node = (ble_service_db *)get_ctrl_buffer(sizeof(ble_service_db));
                OS_MemSet((U8 *)db_node, 0, sizeof(ble_service_db));
                
                btmtk_fs_read(fd, (U8 *)db_node + sizeof(ListEntry), sizeof(ble_service_db) - sizeof(ListEntry));
                pos_current += (sizeof(ble_service_db) - sizeof(ListEntry));

                InsertTailList(&BleDbCtx(servicedbList), &db_node->node);
            }
            btmtk_fs_close(fd);
        }
    }

exit:
    BleDbCtx(loadCount)++;
}
Esempio n. 14
0
/*****************************************************************************
 * FUNCTION
 *  l4c_sim_status_update_mind
 * DESCRIPTION
 *  
 * PARAMETERS
 * 
 * RETURNS
 *  void
 *****************************************************************************/
void l4c_sim_status_update_mind()
{
    kal_uint16 infBuffSize;
    kal_uint8 *infBuff = NULL;            

    if (MBCI_PTR->state != MBCI_STATE_OPEN)
    {
        return;
    }

    infBuff = (kal_uint8*)get_ctrl_buffer(sizeof(mbim_subscriber_ready_info_struct) + sizeof(mbim_subscriber_ready_info_databuffer_struct));   
    infBuffSize = mbci_get_subscriber_ready_info(MBCI_SRC, infBuff, sizeof(mbim_subscriber_ready_info_struct) + sizeof(mbim_subscriber_ready_info_databuffer_struct));

    mbci_status_ind(MBIM_CID_SUBSCRIBER_READY_STATUS, MBIM_UUID_BASIC_CONNECT, infBuffSize, infBuff);
    free_ctrl_buffer(infBuff);
}
Esempio n. 15
0
void BleServiceDbUpdateRecord(ble_service_db *servicedb)
{
    S32 fd;
    S32 pos_current;
    S32 pos_end;
    U32 mode = BTMTK_FS_READ_WRITE;
    U8 *db_buff;

    if (!btmtk_fs_is_dir_exist((const U8*)BLE_SERVICE_DATABASE_FILE))
    {
        mode |= BTMTK_FS_CREATE;
    }

    fd = btmtk_fs_open((const U8*)BLE_SERVICE_DATABASE_FILE, mode);
    if (fd < 0)
    {
        return;
    }

    pos_end = btmtk_fs_seek(fd, 0, BTMTK_FS_SEEK_END);
    pos_current = btmtk_fs_seek(fd, 0, BTMTK_FS_SEEK_BEGIN);

    db_buff = (U8 *)get_ctrl_buffer(sizeof(ble_service_db) - sizeof(ListEntry));
    
    while (pos_current < pos_end)
    {
        btmtk_fs_read(fd, db_buff, sizeof(ble_service_db) - sizeof(ListEntry));
        if (OS_MemCmp(db_buff, 6, servicedb->bdAddr.addr, 6))
        {
            btmtk_fs_seek(fd, pos_current, BTMTK_FS_SEEK_BEGIN);
            break;
        }
        pos_current += (sizeof(ble_service_db) - sizeof(ListEntry));
    }

    free_ctrl_buffer(db_buff);

    Report(("[BleDB] Update record in file, seek offset: %d", pos_current));
//    kal_trace(BT_TRACE_BLE_PROFILES, BLEDB_UPDATERECORD_OFFSET, pos_current);
    btmtk_fs_write(fd, ((U8 *)servicedb) + sizeof(ListEntry), sizeof(ble_service_db) - sizeof(ListEntry));
    btmtk_fs_close(fd);
    
}
/*****************************************************************************
 * FUNCTION
 *  custom_nvram_get_database_key
 * DESCRIPTION
 *  to get the custom database key
 * PARAMETERS
 *  key_buffer          [OUT]   the output buffer to save key
 *  buffer_size         [IN]    the size of key buffer
 * RETURNS
 *  0: Fail
 *  n: the lenghth of database key
 *****************************************************************************/
kal_int32 custom_nvram_get_database_key(kal_uint8 *key_buffer, kal_uint32 buffer_size)
{
#ifdef __NVRAM_SECRET_DATA__
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    CUST_SECRET_DATA_ST* tmp_buffer;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (buffer_size < NVRAM_DATABASE_KEY_SIZE)
    {
        return 0;
    }

    buffer_size = sizeof(custom_secret_data);

    tmp_buffer = (CUST_SECRET_DATA_ST*) get_ctrl_buffer(buffer_size);

#ifdef __MTK_TARGET__
    if (SST_Get_NVRAM_Key((kal_uint32*)&custom_secret_data, (kal_uint32*) tmp_buffer, &buffer_size))
   	{
        memcpy(key_buffer, tmp_buffer->m_custom_database_key, NVRAM_DATABASE_KEY_SIZE);

        buffer_size = NVRAM_DATABASE_KEY_SIZE;
   	}
   	else
   	{
       	buffer_size = 0;
   	}
#else
    memcpy(key_buffer, custom_secret_data.m_custom_database_key, NVRAM_DATABASE_KEY_SIZE);
#endif /* __MTK_TARGET__ */

    free_ctrl_buffer((kal_uint8*)tmp_buffer);

    return buffer_size;
#else
	  return 0;
#endif
}
MHdl *PCM_Strm_Open(void(*handler)( MHdl *handle, Media_Event event ), void *param)
{
   MHdl *hdl;
   pcmStrmMediaHdl *ihdl;
   Media_PCM_Stream_Param *pcm_param = (Media_PCM_Stream_Param *) param;

#if defined(__WAV_DECODE_SWIP__) && !defined(MED_NOT_PRESENT)
   if(!pcm_param->forceVoice)
   {
      return PCM_Strm_Open_cilent(handler, param);
   }
#endif

   ihdl = (pcmStrmMediaHdl*)get_ctrl_buffer( sizeof(pcmStrmMediaHdl) );
   memset(ihdl, 0, sizeof(pcmStrmMediaHdl));
   hdl = (MHdl *) ihdl;
   mhdlInit( hdl, 0, NULL );

   hdl->handler   = handler;
   hdl->state     = WAV_STATE_IDLE;
   ihdl->pcmStrm.isPlayback    = true;
   ihdl->pcmStrm.isStereo      = pcm_param->isStereo;
   ihdl->pcmStrm.bitPerSample  = pcm_param->bitPerSample;
   ihdl->pcmStrm.sampleFreq    = pcm_param->sampleFreq;
   ihdl->pcmStrm.is8KVoice     = pcm_param->forceVoice;
   if(pcm_param->forceVoice == true) {
   	  L1SP_PCMPlayback_SetFlag();
   }

   hdl->Close     = pcmStrmMFClose;
   hdl->Pause     = pcmStrmMFPause;
   hdl->Stop      = pcmStrmMFStop;
   hdl->Process   = pcmStrmMFProcess;
   hdl->Play      = pcmStrmMFPlay;
   hdl->Resume    = pcmStrmMFResume;

   kal_trace( TRACE_FUNC, L1AUDIO_OPEN_STREAM, MEDIA_FORMAT_PCM_8K );

   return hdl;
}
extern  void  asnMemAlloc(void *pVoid, void ** ppBuffer, unsigned long size)
{
   /**
    * For MCDDLL, malloc() from C Standard Library is used;
    * otherwise, memory allocation from KAL is used.
    */
	AsnContext *pContext = (AsnContext*) pVoid;
    if(size == 0)
    {
      *ppBuffer = (void *)0;
      return;
    }

    /*added for memory limit*/
    if(max_size_tolerance > 0)
    {
        if(size > max_size_tolerance)
        {
            UA1_ERROR(16);
        }
    }

    if (pContext->pMemAllocFunc != NULL)
    {
        pContext->pMemAllocFunc(ppBuffer, size, __FILE__, __LINE__);
    }
    else
    {
#ifdef  MCD_DLL_EXPORT
        *ppBuffer = (void *)malloc(size);
        memset(*ppBuffer ,0,size);
#else
        *ppBuffer = (void*) get_ctrl_buffer(size);
#endif 
        if(*ppBuffer == NULL)
        {
            ASSERT(0);
        }
    }
}
Esempio n. 19
0
ble_service_db *BleServiceDbGetRecord(BD_ADDR *bd_addr)
{
    ble_service_db *servicedb;
    BtStatus bonding_status;
    BtDeviceRecord record;

    bonding_status = SEC_FindDeviceRecord(bd_addr, &record);
    servicedb = BleServiceDbFindRecord(bd_addr);
    if (servicedb != NULL)
    {
        if (bonding_status == BT_STATUS_SUCCESS)
        {
            goto exit;
        }
        else
        {
            /* Here the device is unbonded */
            BleServiceDbRemoveRecord(bd_addr);
            //RemoveEntryList(&servicedb->node);
            OS_MemSet((U8 *)servicedb + sizeof(ListEntry) + sizeof(BD_ADDR), 0, 
                                sizeof(ble_service_db) - sizeof(ListEntry) - sizeof(BD_ADDR));
            goto exit;
        }
    }

    servicedb = (ble_service_db *)get_ctrl_buffer(sizeof(ble_service_db));
    OS_MemSet((U8 *)servicedb, 0, sizeof(ble_service_db));
    servicedb->bdAddr = *bd_addr;
    InsertTailList(&BleDbCtx(servicedbList), (ListEntry *)&servicedb->node);
    if (bonding_status == BT_STATUS_SUCCESS)
    {
        BleServiceDbUpdateRecord(servicedb);
    }
    Report(("[BleDB] new record, bonding status: 0x%x",bonding_status));    
//    kal_trace(BT_TRACE_BLE_PROFILES, BLEDB_GETRECORD_NEW, bonding_status);

exit:
    return servicedb;
}
Media_Status wavRecordAppendable( Media_Format format, FS_HANDLE fs, Media_Record_File_Info *info )
{
   uint8 *pBuf;
   Media_Status status;
   uint32 len;
   
   // To initialize info
   memset(info, 0, sizeof(Media_Record_File_Info));

   // Get the file size
   if (FS_NO_ERROR != FS_GetFileSize(fs, &info->fileSize) )
      return MEDIA_READ_FAIL;

   // To get the enough wav header which is supported by MediaTek
   pBuf = (uint8*)get_ctrl_buffer( 60*sizeof(uint8) );
   memset(pBuf, 0, 60*sizeof(uint8));

   if ( FS_NO_ERROR != FS_Read(fs, pBuf, 60, &len) ) {
      status = MEDIA_READ_FAIL;
   } else {
      // Parse the wav header
      status = wavParseRecordFile(pBuf, len, info);
   }

   free_ctrl_buffer( pBuf );
   
   // Compare the file information and wav format
   if (status == MEDIA_SUCCESS)
   {
      // Type mismatch
      if (format != info->format)
         return MEDIA_FAIL;
   }
   
   return status;
}
static kal_bool process_gt818_ctp_cmd( kal_uint8 action, kal_uint32 data_len, kal_uint8 *data_str )
{
    kal_uint16 ret_len = 0;
    kal_uint16 i;
    kal_uint16 inlen;
    kal_uint16 offset;
    STS_CTRL_COMMAND_T cmd;
    DCL_HANDLE handle;
    kal_uint8 *ctp_buffer = NULL;
    kal_uint8 *result = NULL;
    
    ctp_buffer = (kal_uint8 *)get_ctrl_buffer( 1024 );
    
    if ( ctp_buffer == NULL )
        EXT_ASSERT(0, (int)ctp_buffer, 0, 0);
        
    cmd.u4Command = action;
    cmd.pVoid1 = (void *)data_str;
    cmd.pVoid2 = (void *)&result;
    
    handle = DclSTS_Open( DCL_TS, 0 );
    DclSTS_Control( handle, STS_CMD_COMMAND, (DCL_CTRL_DATA_T *)&cmd );   
    DclSTS_Close(handle);     
    
    if ( action == DCL_CTP_COMMAND_GET_VERSION )
        ret_len = 6;
        
    if ( action == DCL_CTP_COMMAND_GET_CONFIG )
        ret_len = 106;
            
    if ( action == DCL_CTP_COMMAND_GET_DIFF_DATA )
        ret_len = 162;      

    if ( action == DCL_CTP_COMMAND_GET_FW_BUFFER )
    {
        offset = data_str[0]*256 + data_str[1];
        inlen = data_str[2];
        memcpy( &result[offset], &data_str[3], inlen);
        
        if ( inlen != 128 )
        {
            #define GT818_FW_STRING  "ctp_firmware_rusklmeoxkwjadfjnklruo3"
            kal_int16   drv_letter;
            FS_HANDLE fs_handle;
            UINT writen;
            kal_wchar   CTP_FIRMWARE_PATH[64];
                    
            drv_letter = FS_GetDrive(FS_DRIVE_V_NORMAL, 2, FS_DRIVE_I_SYSTEM | FS_DRIVE_V_NORMAL);
            kal_wsprintf( CTP_FIRMWARE_PATH, "%c:\\%s", drv_letter, GT818_FW_STRING );    
            fs_handle = FS_Open( CTP_FIRMWARE_PATH, FS_CREATE_ALWAYS | FS_READ_WRITE );
            FS_Write(fs_handle, (kal_uint8 *) result , offset+inlen, &writen);
            FS_Close( fs_handle );
        }            
    }
    
    kal_sprintf( (kal_char *)ctp_buffer, "+EGCMD: " );
            
    for ( i = 0 ; i < ret_len ; i++ )
        kal_sprintf( (kal_char *)&ctp_buffer[strlen((char *)(ctp_buffer))], "%02X", result[i] );            
        
    rmmi_write_unsolicitedResultCode( ctp_buffer, strlen((kal_char *)(ctp_buffer)), KAL_TRUE, 1, NULL );    
    
    free_ctrl_buffer( ctp_buffer );
    
    return KAL_TRUE;
}
Esempio n. 22
0
/*****************************************************************************
 * FUNCTION
 *  phb_search_fake
 * DESCRIPTION
 *  This is phb_read_fake function of PHB module.
 *  Fakes reading state to meet piggyback requirement of write, delete operation.
 *  
 *  Prerequisite:
 *  1. Candidates must be selected first.
 *  2. phb_query_method_enum must be set to control_block->piggyback
 *  3. One entry of l4cphb_phb_entry_array_struct is always allocated
 * PARAMETERS
 *  control_block       [?]         
 *  ilm_ptr             [IN]        The primitives
 *  type                [IN]        
 *  given_pattern       [?]         
 * RETURNS
 *  void
 *****************************************************************************/
void phb_search_fake(
        control_block_type *control_block,
        ilm_struct *ilm_ptr,
        phb_type_enum type,
        l4_addr_bcd_struct *given_pattern)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    l4cphb_phb_entry_array_struct *phb_entry_array;
    l4_addr_bcd_struct *num_pattern;
    name_num_index_type *name_num_index;
    data_entry_struct *data_entry;
    peer_buff_struct *peer_buf_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, FUNC_PHB_SEARCH_FAKE);

   /**
    * First, allocate memory to temporarily store given entry,
    * since we have to verify telephone number, and put it into local paramter.
    *
    * Don't forget to release it!
    */
    num_pattern = (l4_addr_bcd_struct*) get_ctrl_buffer(sizeof(l4_addr_bcd_struct));
    kal_mem_cpy(num_pattern, (void const*)given_pattern, sizeof(l4_addr_bcd_struct));

    phb_entry_array = (l4cphb_phb_entry_array_struct*) l4cphb_alloc_peer_buf(&peer_buf_ptr, 1);
    control_block->need_free_peer = KAL_TRUE;

   /**
    * Read SOP:
    * phb_control_block_set_param(),
    * phb_control_block_set(),
    * phb_control_block_set_IO(),
    * se_control_block()
    */
    /* num_pattern is temporarily stored in local_param_ptr */
    phb_control_block_set_param(control_block, SEARCH_CONTINUE, num_pattern, peer_buf_ptr);
    phb_control_block_set(
        control_block,
        phb_search_continue,
        phb_search_handler,
        phb_search_err_handler,
        SEARCH_CONTINUE);

   /**
    * Read specific record for verification.
    */
    phb_control_block_set_IO(control_block, type, (kal_uint16) PHB_INVALID_VALUE, 1);

    /* set storage, record_index, primary_ID, and secondary_ID */
    name_num_index = (name_num_index_type*) control_block->candidate_name_num_index;
    data_entry =
        &name_num_index->data_entry_table.table[name_num_index->num_index.table[control_block->candidate].position];

    phb_se_set_control_block(control_block, OP_READ, data_entry->storage, data_entry->record_index);

   /**
    * Since phb_se_set_control_block() modifies control_block->proc_stage,
    * it has to be restored.
    */
    control_block->proc_stage = SEARCH_CONTINUE;

    control_block->data = (kal_uint8*) & control_block->temp_entry;
    control_block->length = phb_data_desc_get_record_size(phb_data_desc_get_desc_by_ID(control_block->primary_ID, control_block->storage));
}
Esempio n. 23
0
/*****************************************************************************
 * FUNCTION
 *  aud_media_get_audio_format_in_video
 * DESCRIPTION
 *  This function is to get the audio format in video
 * PARAMETERS
 *
 * RETURNS
 * kal_uint8   result
 *****************************************************************************/
kal_uint8 aud_stretch_is_aduio_in_video_PP_support(kal_wchar *file_name, kal_uint8 *data, kal_uint32 data_len, kal_int16 data_format)
{
#if defined(MED_PURE_AUDIO)
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    MP4_Parser_Status eMp4ParserRet;
    FSAL_Status eFSALRet;
    kal_uint8 result;
    kal_bool is_file_opened = KAL_FALSE;
    kal_bool has_aud_track;
    kal_bool is_PP_support = KAL_FALSE;
    Media_Format audio_format;
    kal_uint32 filesize;
    kal_uint32 index;
    kal_uint64 temp;
    STFSAL stFSAL_ROM;
    kal_uint8 *fsal_rom_buf;

    STMp4Parser *stMp4Parser_aud;
    STFSAL *stFSAL_aud;
    STFSAL *stFSAL_aud_stsz;
    STFSAL *stFSAL_aud_stco;
    STFSAL *stFSAL_aud_aud_data;
    kal_uint32 *mp4_aud_buf;
    kal_uint32 *mp4_aud_data_buf;
    kal_uint32 *mp4_aud_stco_buf;
    kal_uint32 *mp4_aud_stsz_buf;
    kal_uint32 *mp4_aud_stbl_buf;
    FS_FileLocationHint *aud_seek_hint;
  
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    /* Open file for playing */
    stFSAL_aud = (STFSAL*)get_ctrl_buffer(sizeof(STFSAL));    
    eFSALRet = FSAL_Open(stFSAL_aud, (void*)file_name, FSAL_READ); 

    if (eFSALRet != FSAL_OK)
    {
        result = MED_RES_OPEN_FILE_FAIL;
        goto pure_audio_error_out;
    }
    is_file_opened = KAL_TRUE;

    /* Allocate working buffer for operation */    
    stMp4Parser_aud = (STMp4Parser*)get_ctrl_buffer(sizeof(STMp4Parser));
    stFSAL_aud_stsz = (STFSAL*)get_ctrl_buffer(sizeof(STFSAL));
    stFSAL_aud_stco = (STFSAL*)get_ctrl_buffer(sizeof(STFSAL));
    stFSAL_aud_aud_data = (STFSAL*)get_ctrl_buffer(sizeof(STFSAL));
    mp4_aud_buf = (kal_uint32*)med_alloc_ext_mem( AUD_MP4_FSAL_BUF_SIZE*sizeof(kal_uint32) );
    mp4_aud_data_buf = (kal_uint32*)med_alloc_ext_mem( AUD_MP4_FSAL_BUF_SIZE*sizeof(kal_uint32) );
    mp4_aud_stco_buf = (kal_uint32*)med_alloc_ext_mem( AUD_MP4_STCO_BUF_SIZE*sizeof(kal_uint32) );
    mp4_aud_stsz_buf = (kal_uint32*)med_alloc_ext_mem( AUD_MP4_STSZ_BUF_SIZE*sizeof(kal_uint32) );
    mp4_aud_stbl_buf = (kal_uint32*)med_alloc_ext_mem( AUD_MP4_STBL_BUF_SIZE*sizeof(kal_uint32) );
    aud_seek_hint = (FS_FileLocationHint*)med_alloc_ext_mem( AUD_DEC_SEEK_HINT_SIZE*sizeof(FS_FileLocationHint) );

    /* Set buffer for FSAL */
    FSAL_SetBuffer(stFSAL_aud, AUD_MP4_FSAL_BUF_SIZE, (kal_uint8*)mp4_aud_buf);

    /* Set seek hint */
    eFSALRet = FSAL_GetFileSize(stFSAL_aud, &filesize);
    if (eFSALRet != FSAL_OK)
    {
        result = MED_RES_OPEN_FILE_FAIL;
        goto pure_audio_error_out;
    }

    for (index = 0; index < AUD_DEC_SEEK_HINT_SIZE; index++)
    {
        temp = ((kal_uint64) filesize * (kal_uint64) (index + 1)) / (kal_uint64) (AUD_DEC_SEEK_HINT_SIZE + 1);
        aud_seek_hint[index].Index = (kal_uint32) temp;
    }
    DRM_set_seek_hint(stFSAL_aud->hFile, AUD_DEC_SEEK_HINT_SIZE, aud_seek_hint);

    /* Creat MP4 parser */
    eMp4ParserRet = MP4_Parse(stMp4Parser_aud, stFSAL_aud);

    if (eMp4ParserRet != MP4_PARSER_OK && eMp4ParserRet != MP4_PARSER_WARNING_TRAILING_GARBAGE)
    {
        result = MED_RES_BAD_FORMAT;
        goto pure_audio_error_out;
    }

    /* Check if there's audio track */
    MP4_MetaHasAudioTrack(stMp4Parser_aud, &has_aud_track);
    if (!has_aud_track)
    {
        result = MED_RES_MP4_NO_AUDIO_TRACK;
        goto pure_audio_error_out;
    }

    /* Prepare cache table */
    eMp4ParserRet = MP4_STBL_CacheTablePreprocess(
                        stMp4Parser_aud, 
                        mp4_aud_stbl_buf, 
                        AUD_MP4_STBL_BUF_SIZE);
                        
    if (eMp4ParserRet != MP4_PARSER_OK)
    {
        result = MED_RES_BAD_FORMAT;
        goto pure_audio_error_out;
    }    

    /* FSAL aud data */
    eFSALRet = FSAL_Open_Attach(stFSAL_aud_aud_data, stFSAL_aud);
    
    if (eFSALRet != FSAL_OK)
    {
        result = MED_RES_OPEN_FILE_FAIL;
        goto pure_audio_error_out;
    }
    FSAL_SetBuffer(stFSAL_aud_aud_data, AUD_MP4_FSAL_BUF_SIZE, (kal_uint8*)mp4_aud_data_buf);

    /* FASL stco */
    eFSALRet = FSAL_Open_Attach(stFSAL_aud_stco, stFSAL_aud);
    if (eFSALRet != FSAL_OK)
    {
        result = MED_RES_OPEN_FILE_FAIL;
        goto pure_audio_error_out;
    }
    FSAL_SetBuffer(stFSAL_aud_stco, AUD_MP4_STCO_BUF_SIZE, (kal_uint8*)mp4_aud_stco_buf);

    /* FSAL stsz */
    eFSALRet = FSAL_Open_Attach(stFSAL_aud_stsz, stFSAL_aud);
    if (eFSALRet != FSAL_OK)
    {
        result = MED_RES_OPEN_FILE_FAIL;
        goto pure_audio_error_out;
    }
    FSAL_SetBuffer(stFSAL_aud_stsz, AUD_MP4_STSZ_BUF_SIZE, (kal_uint8*)mp4_aud_stsz_buf);

    /* Set FSAL to MP4 Parser */
    MP4_Audio_SetFSAL(stMp4Parser_aud, stFSAL_aud_aud_data);    
    MP4_SetFSAL_STCO(stMp4Parser_aud, MP4_TRACK_AUDIO, stFSAL_aud_stco);
    MP4_SetFSAL_STSZ(stMp4Parser_aud, MP4_TRACK_AUDIO, stFSAL_aud_stsz);
    MP4_UpdateSampleCount(stMp4Parser_aud, MP4_TRACK_AUDIO);

    /* Get Audio Type */
    audio_format = MP4_Audio_Type_To_Media_Format(MP4_GetAudioType(stMp4Parser_aud));
    AUD_VALUE_TRACE(audio_format, -1, __LINE__);

    /* The audio format in 3GP/MP4 file */
    switch (audio_format)
    {
        /* Check AMR / AMR-WB by format enum directly */
    #ifdef AMR_DECODE    
        case MEDIA_FORMAT_AMR:
    #ifdef AMRWB_DECODE        
        case MEDIA_FORMAT_AMR_WB:
    #endif         
            is_PP_support = AudioPP_TS_IsSupport((Media_Format) audio_format, NULL);
            break;
    #endif /*AMR_DECODE*/

        /* Need to wrap audio data in FSAL ROM file for check function */
    #if defined(AAC_DECODE)            
        case MEDIA_FORMAT_AAC:
        {
            kal_uint32 uSampleNo;
            kal_uint32 num_bytes;

            /* Seek to front and read a small range of data */
            eMp4ParserRet =  MP4_Audio_TimeToSampleNo(stMp4Parser_aud, 0, &uSampleNo );
            if(eMp4ParserRet != MP4_PARSER_OK)
            {
                result = MED_RES_FAIL;
                goto pure_audio_error_out; 
            }
            eMp4ParserRet =  MP4_Audio_Seek(stMp4Parser_aud, uSampleNo);
            if(eMp4ParserRet != MP4_PARSER_OK)
            {
                result = MED_RES_FAIL;
                goto pure_audio_error_out; 
            }

            /* Read audio data into buffer and set it to FSAL ROM file */
            fsal_rom_buf = (kal_uint8*)med_alloc_ext_mem( AUD_STRETCH_FSAL_ROM_SIZE*sizeof(kal_uint8) );
            eMp4ParserRet = MP4_Audio_Read(stMp4Parser_aud, fsal_rom_buf, AUD_STRETCH_FSAL_ROM_SIZE, &num_bytes);

            if((eMp4ParserRet != MP4_PARSER_OK) && (eMp4ParserRet != MP4_PARSER_READ_EOF))
            {
                med_free_ext_mem((void**)&fsal_rom_buf);
                result = MED_RES_FAIL;
                goto pure_audio_error_out;             
            }

            FSAL_Direct_SetRamFileSize(&stFSAL_ROM, num_bytes);
            eFSALRet = FSAL_Open(&stFSAL_ROM, (void*)fsal_rom_buf, FSAL_ROMFILE);

            if (eFSALRet != FSAL_OK)
            {
                med_free_ext_mem((void**)&fsal_rom_buf);            
                result = MED_RES_OPEN_FILE_FAIL;
                goto pure_audio_error_out;
            }

            /* check time stretch support by using extract audio data in FSAL ROM file */
            is_PP_support = AudioPP_TS_IsSupport((Media_Format) audio_format, &stFSAL_ROM);

            med_free_ext_mem((void**)&fsal_rom_buf);
            break;
        }            
    #endif /*AAC_DECODE*/            

        default:
            result = MED_RES_INVALID_FORMAT;
            goto pure_audio_error_out;
            break;
    }

    if (is_PP_support)
    {
        result = MED_RES_OK;
    }
    else
    {
        result = MED_RES_UNSUPPORTED_SPEED;
    }
     
pure_audio_error_out:
    if (is_file_opened)
    {
        FSAL_Close(stFSAL_aud);

        free_ctrl_buffer(stMp4Parser_aud);        
        free_ctrl_buffer(stFSAL_aud_stsz);
        free_ctrl_buffer(stFSAL_aud_stco);
        free_ctrl_buffer(stFSAL_aud_aud_data);
        med_free_ext_mem((void**)&mp4_aud_buf);
        med_free_ext_mem((void**)&mp4_aud_data_buf);
        med_free_ext_mem((void**)&mp4_aud_stco_buf);
        med_free_ext_mem((void**)&mp4_aud_stsz_buf);
        med_free_ext_mem((void**)&mp4_aud_stbl_buf);     
        med_free_ext_mem((void**)&aud_seek_hint);
    }

    free_ctrl_buffer(stFSAL_aud);

    return result;

#else
    return MED_RES_INVALID_FORMAT;
#endif /* #if defined(MED_PURE_AUDIO) */

}
Esempio n. 24
0
static void BleServiceDbRemoveRecord(const BD_ADDR *bd_addr)
{
    S32 fd;
    S32 fd_temp;
    S32 pos_current;
    S32 pos_end;
    U8 *db_buff;
    U8 *buffer;
    
    if (!btmtk_fs_is_dir_exist((const U8*)BLE_SERVICE_DATABASE_FILE))
    {
        return;
    }
    
    fd = btmtk_fs_open((const U8*)BLE_SERVICE_DATABASE_FILE, BTMTK_FS_READ_WRITE);
    if (fd < 0)
    {
        return;
    }

    pos_end = btmtk_fs_seek(fd, 0, BTMTK_FS_SEEK_END);
    pos_current = btmtk_fs_seek(fd, 0, BTMTK_FS_SEEK_BEGIN);

    db_buff = (U8 *)get_ctrl_buffer(sizeof(ble_service_db) - sizeof(ListEntry));
    while (pos_current < pos_end)
    {
        btmtk_fs_read(fd, db_buff, sizeof(ble_service_db) - sizeof(ListEntry));
        if (OS_MemCmp(db_buff, 6, bd_addr->addr, 6))
        {
            break;
        }
        pos_current += (sizeof(ble_service_db) - sizeof(ListEntry));
    }
    free_ctrl_buffer(db_buff);

    if (pos_current == pos_end)
    {
        Report(("[BleDB] Remove record, NOT FOUND!"));    
//        kal_trace(BT_TRACE_BLE_PROFILES, BLEDB_REMOVERECORD_NOTFOUND);.
        return;
    }

    /* Case 1:  If there is only one database, delete the file directly */
    if (pos_end - pos_current == sizeof(ble_service_db) - sizeof(ListEntry))
    {
        Report(("[BleDB] Remove record, delete file directly..."));    
    
//        kal_trace(BT_TRACE_BLE_PROFILES, BLEDB_REMOVERECORD_DELETEFILE);
        btmtk_fs_delete((const U8 *)BLE_SERVICE_DATABASE_FILE);
        return;
    }

    /* Case 2:  If there is more than one database, create a new temp file, 
    *   move the left database to the temp file, delete the original database
    *   file, and rename the temp file as the new database file. 
    */
    fd_temp = btmtk_fs_open((const U8*)BLE_SERVICE_DATABASE_TEMP_FILE, BTMTK_FS_READ_WRITE | BTMTK_FS_CREATE);
    if (fd_temp < 0)
    {
        return;
    }

    if (pos_current > 0)
    {
        /* Move first half of the database to temp file */
        buffer = (U8 *)get_ctrl_buffer(pos_current);
        btmtk_fs_seek(fd, 0, BTMTK_FS_SEEK_BEGIN);
        btmtk_fs_read(fd, buffer, pos_current);
        btmtk_fs_write(fd_temp, buffer, pos_current);
        free_ctrl_buffer(buffer);
        
    }
    pos_current = btmtk_fs_seek(fd, sizeof(ble_service_db) - sizeof(ListEntry), BTMTK_FS_SEEK_CURRENT);

    if (pos_current < pos_end)
    {
        /* Move first half of the database to temp file */
        buffer = (U8 *)get_ctrl_buffer(pos_end - pos_current);
        btmtk_fs_read(fd, buffer, pos_end - pos_current);
        btmtk_fs_write(fd_temp, buffer, pos_end - pos_current);
        free_ctrl_buffer(buffer);
    }

    Report(("[BleDB] pos cur: %d, pos end: %d", pos_current, pos_end));

    btmtk_fs_close(fd);
    btmtk_fs_close(fd_temp);

    btmtk_fs_delete((const U8 *)BLE_SERVICE_DATABASE_FILE);
    btmtk_fs_rename((const U8 *)BLE_SERVICE_DATABASE_TEMP_FILE, (const U8 *)BLE_SERVICE_DATABASE_FILE);
}
/*****************************************************************************
 * FUNCTION
 *  nvram_config_com_port
 * DESCRIPTION
 *  To init COM port setting
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void custom_em_nvram_config_com_port(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint8 *buffer = NULL;
    kal_bool result;
#if defined(__BOOT_FOR_USBAT__) && defined(__MTK_TARGET__)
    kal_bool for_usbat = KAL_FALSE;
#endif
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    buffer = (kal_uint8*) get_ctrl_buffer(NVRAM_EF_PORT_SETTING_SIZE);

    if (buffer)
    {
        port_setting_struct *port_setting;

        #if defined(MT6280) && defined(__MODEM_CCCI_EXIST__) && defined(__SMART_PHONE_MODEM__) 
        result = nvram_external_read_data(NVRAM_EF_PORT_SETTING_LID, 2,  buffer, NVRAM_EF_PORT_SETTING_SIZE);
        #else
        result = nvram_external_read_data(NVRAM_EF_PORT_SETTING_LID, 1, buffer, NVRAM_EF_PORT_SETTING_SIZE);
        #endif

        /* Ok, now config UART/IrCOMM ports for L4 and TST, and filters to TST */
        if (result)
        {
        #if defined(__BOOT_FOR_USBAT__) && defined(__MTK_TARGET__)
            for_usbat = INT_IsBootForUSBAT();
        #endif
            
            
            port_setting = (port_setting_struct*) buffer;

        #ifdef __TST_MODULE__

        #ifdef __IRDA_SUPPORT__
            if ( (uart_port_irda == (UART_PORT) port_setting->tst_port_ps) ||
                 (uart_port_irda == (UART_PORT) port_setting->tst_port_l1))
            {
                init_ircomm_module();
                IRDA_Open();
            }
        #endif /* __IRDA_SUPPORT__ */
        
        #if defined(__BOOT_FOR_USBAT__) && defined(__MTK_TARGET__)
            if (for_usbat)
            {
                TST_PORT = (UART_PORT) uart_port1;
                TST_PORT_L1 = (UART_PORT) uart_port1;
            }
            else
        #endif
            {
                TST_PORT = (UART_PORT) port_setting->tst_port_ps;
                TST_PORT_L1 = (UART_PORT) port_setting->tst_port_l1;
            }
        
            TST_BAUDRATE = port_setting->tst_baudrate_ps;
            TST_BAUDRATE_L1 = port_setting->tst_baudrate_l1;

        #ifndef L4_NOT_PRESENT
            #if defined(__BOOT_FOR_USBAT__) && defined(__MTK_TARGET__)
                if (for_usbat)
                {
                    PS_UART_PORT = (UART_PORT) uart_port_usb;
                }
                else
            #endif
                {
                    PS_UART_PORT = (UART_PORT) port_setting->ps_port;
                }
            PS_BAUDRATE = port_setting->ps_baudrate;
            
        #endif /* L4_NOT_PRESENT */
                		                		
        #if defined(__DSP_FCORE4__)	
            TST_PORT_DSP = (UART_PORT) port_setting->tst_port_dsp;
            TST_BAUDRATE_DSP = port_setting->tst_baud_rate_dsp;
        #endif	//#if defined(__DSP_FCORE4__)	
        
        #endif /* __TST_MODULE__ */

            High_Speed_SIM = port_setting->High_Speed_SIM_Enabled;

            if (High_Speed_SIM)
            {
                // remove
            }

            SWDBG_Profile = port_setting->swdbg;
            UART_POWER_SETTING = port_setting->uart_power_setting;
            CTI_UART_PORT = port_setting->cti_uart_port;
            CTI_BAUD_RATE = port_setting->cti_baudrate;

        #ifdef __TST_WRITE_TO_FILE__
            TST_OUTPUT_MODE = port_setting->tst_output_mode;
        #endif
        
        #if defined(__USB_LOGGING__)
            g_usb_logging_mode = port_setting->usb_logging_mode;
        #endif
            
        #ifdef __MTK_TARGET__
        #ifndef __L1_STANDALONE__
            /* To determine if in META mode */
            if (FACTORY_BOOT != kal_query_boot_mode())
            {
                //kal_bool enable;

                if (custom_em_is_uart_used(uart_port1))
                {
                    custom_em_uart_turnon_power(uart_port1, KAL_TRUE);
                }
                else
                {
                    custom_em_uart_turnon_power(uart_port1, KAL_FALSE);
                }
            #ifndef __SMART_PHONE_MODEM__
                if (custom_em_is_uart_used(uart_port2))
                {
                    custom_em_uart_turnon_power(uart_port2, KAL_TRUE);
                }
                else
                {
                    custom_em_uart_turnon_power(uart_port2, KAL_FALSE);
                }
           
                if (custom_em_is_uart_used(uart_port3))
                {
                    custom_em_uart_turnon_power(uart_port3, KAL_TRUE); 
                }
                else
                {
                    custom_em_uart_turnon_power(uart_port3, KAL_FALSE);
                }
            #endif
            }
            else    /* In META Mode, Turn on every UART power */
        #endif /* __L1_STANDALONE__ */
            {
            #ifndef __SMART_PHONE_MODEM__
                custom_em_uart_turnon_power(uart_port1, KAL_TRUE);
                custom_em_uart_turnon_power(uart_port2, KAL_TRUE);
                custom_em_uart_turnon_power(uart_port3, KAL_TRUE);
            #endif
            }
        #endif /* __MTK_TARGET__ */
#ifdef __MULTIPLE_PPP_DIALUP_SUPPORT__ //TRIPLE_PPP for MT6280 IOT
            //20120917, support SPEECH(DCT) + TRIPLE PPP IOT test cases
            // Target USB Enum,    Function,    Initial Owner,    PC Device Naming
            //             usb,    PPP1,        ATCI,             MTK Modem
            //            usb2,    PPP23/CMUX,  ATCI,             MTK Modem
            //            usb3,    AT,          ATCI,             Application Port
            //            usb4,    Speech,      ATCI,             Speech Port
            //            usb5,    Catcher Log, TST,              Debug Port
			TST_PORT = uart_port_usb5;
			TST_PORT_L1 = uart_port_usb5;
			PS_UART_PORT = uart_port_usb2; //20120917, support SPEECH(DCT) + TRIPLE PPP IOT test cases
			g_usb_cdrom_config = 1;
#else			
            g_usb_cdrom_config = port_setting->usb_cdrom_config;
#endif /* __MULTIPLE_PPP_DIALUP_SUPPORT__ */

        #ifdef __SPEECH_OVER_USB__
        #ifdef __MTK_TARGET__
            SPEECH_PORT = port_setting->speech_port; //uart_port_usb4;
        #endif
        #endif
        }

        free_ctrl_buffer(buffer);
    }

    buffer = NULL;

#if (!defined(L4_NOT_PRESENT)) || defined(__TST_MODULE__)
    /* If L4 or TST exist */

    buffer = (kal_uint8*) get_ctrl_buffer(NVRAM_EF_TST_FILTER_SIZE);

    if (buffer != NULL)
    {
        result = nvram_external_read_data(NVRAM_EF_TST_FILTER_LID, 1, buffer, NVRAM_EF_TST_FILTER_SIZE);

        /* Ok, now config UART/IrCOMM ports for L4 and TST, and filters to TST */
        if (result)
        {
        #ifdef __TST_MODULE__
            tst_init_filters((kal_char*) buffer, NVRAM_EF_TST_FILTER_SIZE);
        #endif
        }

        free_ctrl_buffer(buffer);
    }
    #if defined(__TST_MODULE__) && defined(__MTK_TARGET__)

    //Shengkai: check if we need to enable the spare ram logging mechanism
    buffer = (kal_uint8*) get_ctrl_buffer(NVRAM_EF_TST_CONFIG_SIZE);

    if (buffer != NULL)
    {
        result = nvram_external_read_data(NVRAM_EF_TST_CONFIG_LID, 1, buffer, NVRAM_EF_TST_CONFIG_SIZE);

        if (result)
        {
            extern kal_bool tst_spare_ram_nvram_enabled_flag;
            extern kal_bool tst_alc_logging_enable;
            extern kal_bool tst_usb_dma_logging_enabled_flag;
			extern kal_uint8 tst_meta_mode_trace_nvram_enable_flag;
			extern kal_bool tst_is_auto_memory_dump;
            tst_spare_ram_nvram_enabled_flag = ((tst_config_struct_t *)buffer)->spare_logging_enabled;
            tst_usb_dma_logging_enabled_flag = ((tst_config_struct_t *)buffer)->usb_dma_logging_enable;
			tst_meta_mode_trace_nvram_enable_flag = ((tst_config_struct_t *)buffer)->meta_mode_trace_enable;
			if(tst_meta_mode_trace_nvram_enable_flag != 1 && tst_meta_mode_trace_nvram_enable_flag != 2)
				tst_meta_mode_trace_nvram_enable_flag = 0;			
			if(tst_meta_mode_trace_nvram_enable_flag == 2)
				tst_is_auto_memory_dump = KAL_TRUE;
			
            
            if (((tst_config_struct_t *)buffer)->malmo_disable == 1)
              tst_alc_logging_enable = KAL_FALSE;
            else 
              tst_alc_logging_enable = KAL_TRUE;
            //tst_alc_logging_enable = ~(((tst_config_struct_t *)buffer)->malmo_disable);
        }

        free_ctrl_buffer(buffer);
    }
    #endif //    #if defined(__TST_MODULE__) && defined(__MTK_TARGET__)    

#endif /* (!defined(L4_NOT_PRESENT)) || defined(__TST_MODULE__) */
}
Esempio n. 26
0
U32 bpp_compose_vcard_to_xhtml(BTMTK_FS_HANDLE fh, U16* vcard_file)
{
	btmtk_vcard_data_struct *p_vcard = NULL;
	S32 parse_rst;
	U8* cdata;
    int data_len, write_len;        
    S32  ret;
    U32 total_len = 0;

	BT_BPP_FUNC_ENTRY(BPP_COMPOSE_VCARD2XHTML);

	/* Parsing */
	p_vcard = get_ctrl_buffer(sizeof(btmtk_vcard_data_struct));
	OS_MemSet((U8*)p_vcard, 0, sizeof(btmtk_vcard_data_struct));

	parse_rst = btmtk_vcard_parse_file_to_struct(vcard_file, p_vcard);
	BT_BPP_TRACE_INFO_ARG1(BPP_PARSE_VCARD_FILE2STRUCT_RETURN, parse_rst);

	if (parse_rst != BTMTK_VCD_ERR_OK)
	{
		/* failed */
		free_ctrl_buffer(p_vcard);
		return 0;
	}

	/* Composing */

	/* 1. prologue */
	cdata = bpp_get_xhtml_prologue();
    data_len = strlen((char*)cdata);
    ret = bpp_fs_write(fh, cdata, data_len, &write_len);
	total_len += write_len;

	/* 2. head */
	cdata = (U8* )vcard_xhtml_head_template;
    data_len = strlen((char*)cdata);
    ret = bpp_fs_write(fh, cdata, data_len, &write_len);
	total_len += write_len;

	/* 3. body start */
	cdata = (U8* )vcard_xhtml_body_start;
    data_len = strlen((char*)cdata);
    ret = bpp_fs_write(fh, cdata, data_len, &write_len);
	total_len += write_len;

	/* 4. vCard attributes */
	write_len = bpp_compose_vcard_attr_to_xhtml(fh, p_vcard);
	total_len += write_len;

	/* 5. body end */
	cdata = (U8* )vcard_xhtml_body_end;
    data_len = strlen((char*)cdata);
    ret = bpp_fs_write(fh, cdata, data_len, &write_len);
	total_len += write_len;

	
	if (p_vcard)
		free_ctrl_buffer(p_vcard);
	
	return total_len;
}
Esempio n. 27
0
static U32 bpp_compose_vcard_attr_to_xhtml(BTMTK_FS_HANDLE fh, btmtk_vcard_data_struct *p_vcard)
{
    U32 total_len = 0;
    //U32 data_len, write_len;
    int data_len, write_len;
    S8* pbuf = NULL;
	U8* pvalue = NULL;
	U8* pname = NULL;
    U8 field;
	int ret;
#define BPP_TMP_BUF_LEN 512	
	
	pbuf = get_ctrl_buffer(BPP_TMP_BUF_LEN);
	
    for (field = 0; field < BPP_VCARD_FIELD_TOTAL; field++)
    {
    	/* get value */
		
    	switch (field)
    	{
	    case BPP_VCARD_FIELD_NAME:
			{
				int fnlen, lnlen;

				fnlen = strlen((char*)p_vcard->first_name);
				lnlen = strlen((char*)p_vcard->second_name);
				if ((fnlen > 0) && (lnlen > 0))
				{
					pname = get_ctrl_buffer(fnlen + lnlen + 2);
					strcpy((char*)pname, (char*)p_vcard->first_name);
					strcat((char*)pname, (char*)p_vcard->second_name);
					pvalue = pname;
				}
				else
				{
					pvalue = fnlen > 0 ? p_vcard->first_name : p_vcard->second_name;
				}
				/* compose */
		    	sprintf(pbuf, vcard_xhtml_attr_template, bpp_vcard_field_str[field], pvalue);
				/* write to file */
			    data_len = strlen((char*)pbuf);
			    ret = bpp_fs_write(fh, pbuf, data_len, &write_len);
				total_len += write_len;
				if (pname)
				{
					free_ctrl_buffer(pname);
					pname = NULL;
				}						
	    	}
		
			/* get the next item */
			continue;
			
	    case BPP_VCARD_FIELD_TEL_CELL:
			pvalue = p_vcard->cell_num;
			break;
	    case BPP_VCARD_FIELD_TEL_HOME:
			pvalue = p_vcard->home_num;
			break;
	    case BPP_VCARD_FIELD_CMPNY:
			pvalue = p_vcard->company;
			break;
	    case BPP_VCARD_FIELD_EMAIL:
			pvalue = p_vcard->email;
			break;
	    case BPP_VCARD_FIELD_TEL_WORK:
			pvalue = p_vcard->office_num;
			break;
	    case BPP_VCARD_FIELD_TEL_FAX:
			pvalue = p_vcard->fax_num;
			break;
	    case BPP_VCARD_FIELD_BIRTHDAY:
			pvalue = p_vcard->birthday;
			break;
	    case BPP_VCARD_FIELD_TITLE:
			pvalue = p_vcard->title;
			break;
	    case BPP_VCARD_FIELD_URL:                    
			pvalue = p_vcard->url;
			break;
	    case BPP_VCARD_FIELD_ADR_POBOX:
			pvalue = p_vcard->postbox;
			break;
	    case BPP_VCARD_FIELD_ADR_EXTENSION:
			pvalue = p_vcard->extension;
			break;
	    case BPP_VCARD_FIELD_ADR_STREET:
			pvalue = p_vcard->street;
			break;
	    case BPP_VCARD_FIELD_ADR_CITY:
			pvalue = p_vcard->city;
			break;
	    case BPP_VCARD_FIELD_ADR_STATE:
			pvalue = p_vcard->state;
			break;
	    case BPP_VCARD_FIELD_ADR_POSTALCODE:
			pvalue = p_vcard->postcode;
			break;
	    case BPP_VCARD_FIELD_ADR_COUNTRY:
			pvalue = p_vcard->country;
			break;			
	    case BPP_VCARD_FIELD_NOTE:
			pvalue = p_vcard->note;
			break;			
			
	    default:
			pvalue = NULL;
	    	break;
    	}

		if (pvalue && (strlen((char*)pvalue) > 0))
		{
			/* compose */
	    	sprintf(pbuf, vcard_xhtml_attr_template, bpp_vcard_field_str[field], pvalue);

			/* write to file */
		    data_len = strlen((char*)pbuf);
		    ret = bpp_fs_write(fh, pbuf, data_len, &write_len);
			total_len += write_len;
		}
    }

	if (pbuf)
		free_ctrl_buffer(pbuf);

#undef BPP_TMP_BUF_LEN

	return total_len;
}
void FT_WriteTo_NVRAM(ft_nvram_write_req_struct_T* req, peer_buff_struct* peer_buff, ilm_struct* ptrMsg)
{
    ilm_struct  ilm_ptr;
    nvram_write_req_struct *nvram_ptr_loc_para;
    kal_uint16             pdu_length;
    kal_uint8              *pdu_ptr = get_peer_buff_pdu( peer_buff, &pdu_length );
#ifdef __NVRAM_SECRET_DATA__
    kal_bool  bPassCheck = KAL_FALSE;
    kal_int32 err_code = 0xFE;
    kal_uint8 key[256]; // at most 256 bytes
    kal_int32 real_key_len;
    real_key_len = custom_nvram_get_database_key(key, sizeof(key));
    if(req->msg_num == 2 && real_key_len >0) // we must wait until we collect all
    {
        if(req->msg_idx == 0) // allocate a peer buffer to store it.
        {
            if(p_g_pbs_ft_nvram != NULL) // free previous buffer
            {
                free_peer_buff(p_g_pbs_ft_nvram);
                p_g_pbs_ft_nvram = NULL;
            }
            // allocate a new peer buffer
            if( NULL != (p_g_pbs_ft_nvram=construct_peer_buff(pdu_length, 0, 0, TD_CTRL)) )
            {
                p_g_u1_ft_nvram_pdu_ptr = get_peer_buff_pdu( p_g_pbs_ft_nvram, &g_u2_ft_nvram_pdu_length );
                kal_mem_cpy(p_g_u1_ft_nvram_pdu_ptr, pdu_ptr , pdu_length);
                p_g_pbs_ft_nvram->pdu_len = pdu_length;
            }
            return; // wait for next message
        }
        else // the second message with encrpted data
        {
            kal_int32 i;
            RC4_CNXT cnxt;
            kal_uint8 *output_data = (kal_uint8*) get_ctrl_buffer(g_u2_ft_nvram_pdu_length);  // since at most 2k bytes
            if(p_g_u1_ft_nvram_pdu_ptr!=NULL)
            {
                // get the key
                //real_key_len =  custom_nvram_get_database_key(key, sizeof(key));
                if(real_key_len >0) // get the key
                {
                    // deciphered the input data
                    che_rc4_set_key((RC4_CNXT *)&cnxt, (kal_uint32)real_key_len, (kal_uint8 *)key);
                    che_rc4((RC4_CNXT *)&cnxt, p_g_u1_ft_nvram_pdu_ptr , g_u2_ft_nvram_pdu_length, key, real_key_len, CHE_MODE_NULL, output_data);
                    for(i=0; i<g_u2_ft_nvram_pdu_length; i++)
                    {
                        if(output_data[i] != pdu_ptr[i])
                        {
                            err_code = 0xFD;
                            break;
                        }
                    }
                    if(i == g_u2_ft_nvram_pdu_length)
                    {
                        bPassCheck = true;
                    }
                }
            }
            else
            {
                err_code = 0xFC;
            }
            free_ctrl_buffer(output_data);
        }
    }
    else
    {
        if(real_key_len == 0 || g_b_ft_nvram_proc_locally == true) // sec not ON
            bPassCheck = true;
    }
    if(!bPassCheck)
    {
        // invoke:
        nvram_write_cnf_struct  cnf_result;
        cnf_result.file_idx = req->file_idx;
        cnf_result.para = req->para;
        cnf_result.result = err_code;
        // allocate a peer buffer to stored the output data for debug
        FT_WriteTo_NVRAM_CNF(&cnf_result);
        return;
    }
    if(real_key_len >0 &&
            req->msg_num == 2 &&
            p_g_pbs_ft_nvram != NULL) // re-assign the pdu_ptr, and free the buffer
    {
        kal_mem_cpy(pdu_ptr, p_g_u1_ft_nvram_pdu_ptr,pdu_length);
        free_peer_buff(p_g_pbs_ft_nvram);
        p_g_pbs_ft_nvram = NULL;
    }
#endif // #ifdef __NVRAM_SECRET_DATA__
    FT_ALLOC_OTHER_MSG(&ilm_ptr ,sizeof(nvram_write_req_struct));
    nvram_ptr_loc_para=(nvram_write_req_struct *)(ilm_ptr.local_para_ptr);
    nvram_ptr_loc_para->file_idx=req->file_idx;/* LID */
    nvram_ptr_loc_para->para=req->para;
    nvram_ptr_loc_para->access_id=0 ; // change it!
#ifdef _LOW_COST_SINGLE_BANK_FLASH_
    {
        // stop RF
        L1TST_Stop();
    }
#endif // #ifdef _LOW_COST_SINGLE_BANK_FLASH_
    // keep a runtime buffer of the written value for updating L1 runtime
    // FIX: ACCESS OUT-OF BOUND
    if(pdu_length > sizeof(ft_rf_data_pt))
    {
        kal_mem_cpy(&ft_rf_data_pt, pdu_ptr, sizeof(ft_rf_data_pt));
    }
    else
    {
        kal_mem_cpy(&ft_rf_data_pt, pdu_ptr, pdu_length);
    }
    ilm_ptr.peer_buff_ptr = peer_buff;
    /* FT_SEND_MSG(src_mod, dest_mod, sap_id, msg_id, ilm_ptr) */
    FT_SEND_MSG(MOD_FT, MOD_NVRAM, PS_NVRAM_SAP, MSG_ID_NVRAM_WRITE_REQ, &ilm_ptr);
    if(ptrMsg != NULL)
       ptrMsg->peer_buff_ptr=NULL;/* make sure the NVRAM will release the mem*/
}
Esempio n. 29
0
/*****************************************************************************
 * FUNCTION
 *  jpush_alarm_add
 * DESCRIPTION
 *  Add one entry to the alarm registry.
 *  If the entry already exists return previous alarm time.
 *  On succesful registration, write a new copy of the file to disk.
 * PARAMETERS
 *  str             [?]     
 *  alarm           [IN]        
 *  lastalarm       [?]      
 * RETURNS
 *  
 *****************************************************************************/
int jpush_alarm_add(char *str, kal_int64 alarm, kal_int64 *lastalarm)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    alarmentry_struct *alarmp;
    alarmentry_struct *lastp = g_jpush_alarmlist_ptr;
    alarmentry_struct *pe = NULL;
    kal_char *storage_name;
    kal_char *midlet_name;
    kal_int32 alarm_num = 0;
    kal_uint32 alarm_period;
    kal_int32 i;
    kal_int32 storage_len, midlet_len;
    kal_int32 midletid;
    kal_char tmp_buf[16];
    kal_char *tmp_str;
    kal_int32 tmp_len = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#ifdef __SUPPORT_JAVA_PUSH__
    kal_trace(TRACE_FUNC, JPUSH_ALARM_ADD);
#if defined(J2ME_SLIM_MEMORY_SUPPORT)
    if (FS_GetDevStatus(SRV_FMGR_CARD_DRV, FS_MOUNT_STATE_ENUM) != FS_NO_ERROR)
    {
        return;
    }
#endif
    jpush_timer_mutex_lock(); 
    *lastalarm = 0;

    storage_name = jpush_push_getstoragename(str, 2, &storage_len);
    midlet_name = jpush_push_getstoragename(str, 0, &midlet_len);
    tmp_str = jpush_push_getstoragename(str, 3, &tmp_len);
    memcpy(tmp_buf, tmp_str, tmp_len);
    tmp_buf[tmp_len] = 0;
    sscanf(tmp_buf, "%d", &midletid);

	
    /* Check if the entry already exists? */
    for (alarmp = g_jpush_alarmlist_ptr; alarmp; alarmp = alarmp->next)
    {
        alarm_num++;

        if (strncmp(midlet_name, alarmp->midlet, midlet_len) == 0 &&
            strncmp(storage_name, alarmp->storagename, storage_len) == 0 &&
            midletid == alarmp->midletid &&
            alarmp->midlet[midlet_len] == 0 && alarmp->storagename[storage_len] == 0)
        {
            kal_int64 temp = alarmp->wakeup;
            *lastalarm = alarmp->wakeup; // 20110321: Fix MIDP OTA TCK: PushRegistry WakeUp

            kal_trace(TRACE_FUNC, JPUSH_ALARM_ADD_REGISTERED);
            
           
            /* Cancel timer, Fix to check if valid event */
            if (alarmp->event_id)
            {
             
                jpush_alarm_cancel(&alarmp->event_id);
                              
            }
            for (i = 0; i < MAX_PUSH_REGISTRY; i++)
            {
                /* remove the push indication memorized by MMI */
                if (g_mmi_java_push_cntx.push_entry_used[i])
                {
                    if (strcmp(alarmp->storagename, g_mmi_java_push_cntx.push_entry[i].mids_storage_name) == 0 &&
						alarmp->midletid == g_mmi_java_push_cntx.push_entry[i].mid_id &&
                        strcmp(alarmp->midlet, g_mmi_java_push_cntx.push_entry[i].mid_class_name) == 0)
                    {
                        jpush_search_and_delete_persistent_push(
                            0,
                            g_mmi_java_push_cntx.push_entry[i].pushalarm_type,
                            g_mmi_java_push_cntx.push_entry[i].mid_class_name,
                            g_mmi_java_push_cntx.push_entry[i].mid_id,
                            g_mmi_java_push_cntx.push_entry[i].mids_storage_name,
                            NULL,
                            NULL,
                            NULL,
                            NULL,
                            KAL_TRUE);
                        g_mmi_java_push_cntx.push_entry_used[i] = KAL_FALSE;
                        g_mmi_java_push_cntx.push_entry[i].mids_storage_name = NULL;
                    }
                }
            }
            alarmp->event_id = NULL;

            if (alarm == 0)
            {
                /* Remove an entry. */
                if (alarmp == g_jpush_alarmlist_ptr)
                {
                    g_jpush_alarmlist_ptr = alarmp->next;
                }
                else
                {
                    lastp->next = alarmp->next;
                }

                alarmp->next = NULL;
                free_ctrl_buffer(alarmp->midlet);
                alarmp->midlet = NULL;
                free_ctrl_buffer(alarmp->storagename);
                alarmp->storagename = NULL;
                free_ctrl_buffer(alarmp);

                jpush_alarm_save();

            }
            else
            {
                /* Replace an entry. */
                alarmp->wakeup = alarm;
                alarmp->executed = 0;

                if (alarm >= CurrentTime_md())
                {

                    alarm_period = j2me_ms_2_tick(alarm - CurrentTime_md());
                                       
                    alarmp->event_id = jpush_alarm_set(alarmp, alarm_period);

                    jpush_alarm_save();
                }
                else
                {
                    j2me_alarm_timeout_handler(alarmp);
                }
            }

            ///*lastalarm = temp; // 20110321: Reomved for MIDP OTA TCK: PushRegistry WakeUp
            jpush_timer_mutex_unlock(); 
            return 0;
        }

        lastp = alarmp;
    }
    g_timealarm_count = alarm_num;
    kal_trace(TRACE_FUNC, JPUSH_ALARM_ADD_NEW,(g_timealarm_count));

    /* Add a new entry. */
    if (alarm &&
        alarm_num + g_push_length < MAX_PUSH_REGISTRY &&
        ((pe = (alarmentry_struct*) get_ctrl_buffer(sizeof(alarmentry_struct))) != NULL))
    {
        pe->next = g_jpush_alarmlist_ptr;
        pe->wakeup = alarm;
        pe->executed = 0;

        pe->midlet = jvm_str_dup(midlet_name, midlet_len);

        pe->storagename = jvm_str_dup(storage_name, storage_len);

        pe->midletid = midletid;

        pe->alarm_game_type = 0;

        if ((pe->midlet == NULL) || (pe->midletid <= 0) || (pe->storagename == NULL))
        {
            free_ctrl_buffer(pe->midlet);
            pe->midlet = NULL;
            free_ctrl_buffer(pe->storagename);
            pe->storagename = NULL;
            free_ctrl_buffer(pe);
            pe = NULL;
        }
        else
        {
            g_jpush_alarmlist_ptr = pe;

            /* Set timer */
            if(alarm > CurrentTime_md())
            {
                alarm_period = j2me_ms_2_tick(alarm - CurrentTime_md());
                pe->event_id = jpush_alarm_set(pe, alarm_period);
          
            }
            else
            {
                j2me_alarm_timeout_handler(pe);
            }
        }
    }

    if (pe == NULL)
    {
        jpush_timer_mutex_unlock(); 
        return (-2);
    }
    
    jpush_timer_mutex_unlock(); 
    jpush_alarm_save();  
#endif
    return (0);
}
Esempio n. 30
0
/*****************************************************************************
 * FUNCTION
 *  jpush_alarm_parse
 * DESCRIPTION
 *  Parse the persistent alaram registry from disk into the
 *  in memory cache representation.
 * PARAMETERS
 *  pushfd      [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
int jpush_alarm_parse(kal_int32 pushfd)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    char buffer[MAX_PUSH_LINE + 1];
    kal_char tmp_buf[25] = {0}; //maximun for 64bits  wake up time
    kal_bool eof = KAL_FALSE;
    int i;
    alarmentry_struct *pe;
    kal_char *tmp_str;
    kal_int32 tmp_len = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, JPUSH_ALARM_PARSE); 
    jpush_timer_mutex_lock(); 
    while (eof == KAL_FALSE)
    {
        /* Read a line at a time */
        for (i = 0; i < MAX_PUSH_LINE; i++)
        {
            tmp_len = jvm_file_read(pushfd, &buffer[i], 1);

            /* EOF */
            if (tmp_len == 0 || tmp_len == -1)
            {
                eof = KAL_TRUE;
                break;
            }

            /* EOL */
            if ((buffer[i] == '\n') || (i == MAX_PUSH_LINE))
            {
                buffer[i] = 0;
                break;
            }
            /* Ignore carriage returns */
            if (buffer[i] == '\r')
            {
                i--;
            }
        }
		pushlist_len = i; 
        /* Skip comment lines which begin  with '#' */
        if (eof == KAL_FALSE && buffer[0] != '#')
        {
            if ((pe = (alarmentry_struct*) get_ctrl_buffer(sizeof(alarmentry_struct))) != NULL)
            {
                kal_trace(TRACE_FUNC, JPUSH_ALARM_PARSE_START);             
                
                pe->next = g_jpush_alarmlist_ptr;

                tmp_str = pushstorage(buffer, 0, &tmp_len);
                kal_mem_cpy(tmp_buf, tmp_str, tmp_len);
                tmp_buf[tmp_len] = 0;                 
                pe->executed = atoi(tmp_str);

                tmp_str = pushstorage(buffer, 1, &tmp_len);
                pe->midlet = jvm_str_dup(tmp_str, tmp_len);
                
                MMI_PRINT(MOD_JAM,TRACE_FUNC,"jpush_alarm_parse: midlet = %s",pe->midlet);

				        tmp_str = pushstorage(buffer, 2, &tmp_len);
                kal_mem_cpy(tmp_buf, tmp_str, tmp_len);
			    pe->wakeup = ((((kal_int64)tmp_buf[0]) << 56) & 0xff00000000000000) |
					         ((((kal_int64)tmp_buf[1]) << 48) & 0x00ff000000000000) |
					         ((((kal_int64)tmp_buf[2]) << 40) & 0x0000ff0000000000) |
					         ((((kal_int64)tmp_buf[3]) << 32) & 0x000000ff00000000) |
					         ((((kal_int64)tmp_buf[4]) << 24) & 0x00000000ff000000) |
					         ((((kal_int64)tmp_buf[5]) << 16) & 0x0000000000ff0000) |
					         ((((kal_int64)tmp_buf[6]) << 8) & 0x000000000000ff00) |
					         (((kal_int64)tmp_buf[7]) & 0x00000000000000ff);

                tmp_str = pushstorage(buffer, 3, &tmp_len);
                pe->storagename = jvm_str_dup(tmp_str, tmp_len);

                tmp_str = pushstorage(buffer, 4, &tmp_len);
                kal_mem_cpy(tmp_buf, tmp_str, tmp_len);
				pe->midletid = ((tmp_buf[0] & 0xFF) << 24) | ((tmp_buf[1] & 0xFF) << 16) | ((tmp_buf[2] & 0xFF) << 8) | (tmp_buf[3] & 0xFF);

                tmp_str = pushstorage(buffer, 5, &tmp_len);
                kal_mem_cpy(tmp_buf, tmp_str, tmp_len);
                pe->alarm_game_type = tmp_buf[0] & 0xFF;
                
                kal_trace(TRACE_FUNC, JPUSH_ALARM_PARSE_END); 

                /* for fix the issue : the store data is incorrect due to unknown reason */
                if ((pe->midlet == NULL) || 
                    (pe->storagename == NULL) ||
                    (pe->midletid == 0) || 
                    (pe->wakeup < 0) || 
                    (pe->alarm_game_type >= GAMETYPE_INVALID_TYPE) || 
                    (pe->executed < 0))
                {
                    if (pe->midlet)
                    {
                        free_ctrl_buffer(pe->midlet);
                    }
                    if (pe->storagename)
                    {
                        free_ctrl_buffer(pe->storagename);
                    }
                    g_jpush_alarmlist_ptr = pe->next;
                    free_ctrl_buffer(pe);
                    pe = NULL;
                    
                    kal_trace(TRACE_FUNC, JPUSH_ALARM_PARSE_ERROR_AND_DROP);                     
                    
                }
                else
                {
                    kal_uint32 alarm_period;

                    g_jpush_alarmlist_ptr = pe;

                    if ((pe->wakeup) >= CurrentTime_md())
                    {

                        /* Set timer */
                        alarm_period = j2me_ms_2_tick(pe->wakeup - CurrentTime_md());
                        kal_trace(TRACE_FUNC, JPUSH_ALARM_PARSE_A_NON_TIMEOUT_PUSH,alarm_period);                         
                        
                        pe->event_id = jpush_alarm_set(pe, alarm_period);
                    }
                    else
                    {
                        kal_trace(TRACE_FUNC, JPUSH_ALARM_PARSE_A_TIMEOUT_PUSH);      
                        
                        /*for fix the issue : the timeouthandler is too fast to interrupt the parse */
                        /*                    because the Aplix CurrentTime_md() will process timeout msg */
                        pe->event_id = jpush_alarm_set(pe, 2500);
                    }

                }
            }
            else
            {
                jpush_timer_mutex_unlock(); 
                /* alarmListFree(); */
                return -2;
            }
        }
    }
    jpush_timer_mutex_unlock(); 
    return 0;
}