예제 #1
0
void pan_op_activate(int service)
{
    bt_pan_activate_req_struct msg;
    btmtk_os_memset((U8 *)&msg, 0, sizeof(bt_pan_activate_req_struct));
    msg.service = service;
    BTCMD_SendMessage(MSG_ID_BT_PAN_ACTIVATE_REQ, MOD_EXTERNAL, &msg, sizeof(msg));
}
예제 #2
0
void btmtk_pan_deactivate_req(void)
{
    bt_pan_op_struct msg;

    btmtk_os_memset((U8 *)&msg, 0, sizeof(bt_pan_op_struct));
    msg.op = BT_PAN_OP_DEACTIVATE;
    pan_process_cmd(&msg, sizeof(bt_pan_op_struct));
}
예제 #3
0
void pan_op_disconnect(BD_ADDR *bt_addr)
{
    bt_pan_disconnect_req_struct msg;

    btmtk_os_memset((U8 *)&msg, 0, sizeof(bt_pan_disconnect_req_struct));
    btmtk_os_memcpy((U8 *)&msg.bt_addr, bt_addr, sizeof(msg.bt_addr));
    BTCMD_SendMessage(MSG_ID_BT_PAN_DISCONNECT_REQ, MOD_EXTERNAL, &msg, sizeof(msg));
}
예제 #4
0
void btmtk_pan_activate_req(int service)
{
    bt_pan_op_struct msg;

    btmtk_os_memset((U8 *)&msg, 0, sizeof(bt_pan_op_struct));
    msg.op = BT_PAN_OP_ACTIVATE;
    msg.service = service;
    pan_process_cmd(&msg, sizeof(bt_pan_op_struct));
}
예제 #5
0
/*---------------------------------------------------------------------------
 *            HidSdpCallback()
 *---------------------------------------------------------------------------
 *
 * Synopsis:  Makes a callback to the application with query response.
 */
void HidSdpCallback(HidChannel *Channel, BtStatus Status)
{
    /* Indicate the query response to the application */
    HidAppCallback(Channel, HIDEVENT_QUERY_CNF, Status,
                   &Channel->queryRsp, (U16)(sizeof(HidQueryRsp)));

    hid_free(Channel->queryRsp.descriptorList);
    btmtk_os_memset((U8 *)&Channel->queryRsp, 0, sizeof(Channel->queryRsp));
}
예제 #6
0
static void fmp_clear_connection(fmp_context_struct *cntx)
{
    cntx->bActive = FALSE;

    // free resources
    
    btmtk_os_memset((U8 *)cntx, 0, sizeof(fmp_context_struct));

}
예제 #7
0
void btmtk_pan_disconnect_req(U8 *device_addr)
{
    bt_pan_op_struct msg;

    btmtk_os_memset((U8 *)&msg, 0, sizeof(bt_pan_op_struct));
    msg.op = BT_PAN_OP_DISCONNECT;
    btmtk_os_memcpy((U8 *)&msg.addr, device_addr, sizeof(msg.addr));

    pan_process_cmd(&msg, sizeof(bt_pan_op_struct));
}
예제 #8
0
void pan_op_connect(bt_pan_service_enum local_service, bt_pan_service_enum remote_service, BD_ADDR *bt_addr)
{
    bt_pan_connect_req_struct msg;

    btmtk_os_memset((U8 *)&msg, 0, sizeof(bt_pan_connect_req_struct));

    msg.local_service = local_service;
    msg.remote_service = remote_service;
    btmtk_os_memcpy((U8 *)&msg.bt_addr, bt_addr, sizeof(msg.bt_addr));
    BTCMD_SendMessage(MSG_ID_BT_PAN_CONNECT_REQ, MOD_EXTERNAL, &msg, sizeof(msg));
}
예제 #9
0
U8 Hid_Init_Parser(HidParseData*	tmpHidParser)
{
	//HidParseData*	tmpHidParser = (HidParseData*)hid_malloc(sizeof(HidParseData));
	if(!tmpHidParser)
	{
		bt_prompt_trace(MOD_BT,"[HID]HidParseData hid_malloc error");
		return 0;
	}
	
	tmpHidParser->reportDesc = NULL;
	tmpHidParser->usageQueue = (HidUsage*)hid_malloc(HID_USAGE_MAX * sizeof(HidUsage));
	if(!tmpHidParser->usageQueue)
	{
		bt_prompt_trace(MOD_BT,"[HID]usageQueue hid_malloc error");
		return 0;
	}

	btmtk_os_memset((U8*) tmpHidParser->usageQueue, 0, sizeof(HID_USAGE_MAX * sizeof(HidUsage)));

	tmpHidParser->usageSize = 0;
	tmpHidParser->usageNum = 0;
	tmpHidParser->reportDescLength = 0;
	tmpHidParser->logicalMAX = 0;
	tmpHidParser->logicalMIN = 0;
	tmpHidParser->physicalMAX = 0;
	tmpHidParser->physicalMIN = 0;
	tmpHidParser->reportCount = 0;
	tmpHidParser->reportSize = 0;
	tmpHidParser->reportID = 0;
	tmpHidParser->usagePage = 0;
	tmpHidParser->unitExponent = 0;
	tmpHidParser->unit = 0;

	tmpHidParser->pos = 0;
	tmpHidParser->collectionArray = (HidUsageCollection*)hid_malloc(HID_COLLECTION_MAX * sizeof(HidUsageCollection));
	btmtk_os_memset((HidUsageCollection*) tmpHidParser->collectionArray, 0, sizeof(HID_COLLECTION_MAX * sizeof(HidUsageCollection)));
	tmpHidParser->collectionIndex = 0;
	//return tmpHidParser;
	Hid_Init_KeyArray();
	return 1;
}
예제 #10
0
/*---------------------------------------------------------------------------
 *            HidStartServiceQuery()
 *---------------------------------------------------------------------------
 *
 * Synopsis:  Initiate the SDP service query for a HID device.
 *
 * Return:    See SDP_Query().
 */
BtStatus HidStartServiceQuery(HidChannel *Channel)
{
    BtStatus status = BT_STATUS_FAILED;
    sdap_service_search_multi_attribute_struct search_pattern;
    ReportDescriptorList* reportDescriptorList = NULL;
    HidParseData*	hpd ;
	
    reportDescriptorList = HidFindReportDescriptorByAddr(Channel->cmgrHandler.remDev->bdAddr);
    if(reportDescriptorList != NULL && Channel->state == HID_STATE_OPEN)
    {
		Channel->queryRsp.descriptorLen = reportDescriptorList->reportDescriptorLength;
		Channel->queryRsp.descriptorList = (U8*)hid_malloc(reportDescriptorList->reportDescriptorLength);
		btmtk_os_memset((U8*) Channel->queryRsp.descriptorList, 0, reportDescriptorList->reportDescriptorLength); 			
		btmtk_os_memcpy((U8*) Channel->queryRsp.descriptorList, reportDescriptorList->reportDescriptor, reportDescriptorList->reportDescriptorLength);
		hpd = (HidParseData*)hid_malloc(sizeof(HidParseData));
		Hid_Init_Parser(hpd);
				Channel->reportCons[0] = (HidReportConstructor*)hid_malloc(HID_REPORT_ID_MAX * sizeof(HidReportConstructor));
		btmtk_os_memset((U8*) Channel->reportCons[0], 0, HID_REPORT_ID_MAX * sizeof(HidReportConstructor));
		
		if(HidAddDescriptor(Channel) == BT_STATUS_SUCCESS)
			bt_prompt_trace(MOD_BT,"[HID]HidAddDescriptor Successed!");
		else
			bt_prompt_trace(MOD_BT,"[HID]HidAddDescriptor failed!");
        
		Hid_Free_Parser(hpd);
		Channel->flags &= ~CHNL_FLAG_SERVICE_QUERY;
		HidSdpCallback(Channel, BT_STATUS_SUCCESS);
		return BT_STATUS_SUCCESS;
    }
    else
    {
	    search_pattern.rm = Channel->cmgrHandler.remDev;
	    search_pattern.sqt = &Channel->sdpQueryToken;
	    search_pattern.uuid = SC_HUMAN_INTERFACE_DEVICE;
	    search_pattern.callback = HidSdpEventHandler;
	    search_pattern.attribute_num = sizeof(bt_hid_attr_id_list)/sizeof(bt_hid_attr_id_list[0]);
	    search_pattern.attribute_id = bt_hid_attr_id_list;
	    status = SDAP_ServiceSearchMultipleAttribute2(search_pattern);
	    return status;
    }
} 
예제 #11
0
void btmtk_pan_connect_req(bt_pan_service_enum local_service, bt_pan_service_enum remote_service, U8 *device_addr)
{
    bt_pan_op_struct msg;

    btmtk_os_memset((U8 *)&msg, 0, sizeof(bt_pan_op_struct));
    msg.op = BT_PAN_OP_CONNECT;
    msg.local_service = local_service;
    msg.remote_service = remote_service;
    btmtk_os_memcpy((U8 *)&msg.addr, device_addr, sizeof(msg.addr));

    pan_process_cmd(&msg, sizeof(bt_pan_op_struct));
}
예제 #12
0
static BtStatus _time_gatt_notify_value(TimePacket *pkt, U16 value_handle, U16 size, U8 *data) {
	BtGattOp *gatt_op = &pkt->gatt_op;
	TimeSTransport *pChnl = (TimeSTransport *) pkt->chnl;

	btmtk_os_memset((U8 *) gatt_op, 0, sizeof(gatt_op));
	InitializeListEntry(&gatt_op->op.node);
	gatt_op->apCb = time_gatt_notify_value_callback;
	pkt->success_flag = 0;
	pkt->gatt_params.vno.handle = value_handle;
	pkt->gatt_params.vno.size = size;
	pkt->gatt_params.vno.data = data;
	gatt_op->parms.p.valueNotifications = &pkt->gatt_params.vno;

	return BT_GATT_Notifications(pChnl->handler.bdc->link, gatt_op);
}
예제 #13
0
static BtStatus _time_gatt_read_characteristic_descriptor(TimePacket *pkt, U16 desc_handle) {
	BtGattOp *gatt_op = &pkt->gatt_op;
	TimeCTransport *pChnl = (TimeCTransport *) pkt->chnl;

	OS_Report("[Time] %s(), handle: %d", __FUNCTION__, desc_handle);

	btmtk_os_memset((U8 *) gatt_op, 0, sizeof(BtGattOp));
	InitializeListEntry(&gatt_op->op.node);
	gatt_op->apCb = time_gatt_ap_callback;
	pkt->success_flag = 0;
	pkt->gatt_params.rds.handle = desc_handle;
	gatt_op->parms.p.readCharDescriptors = &pkt->gatt_params.rds;

	return BT_GATT_ReadCharacteristicDescriptors(pChnl->handler.remDev, gatt_op);
}
예제 #14
0
void btmtk_pan_connection_authorize_rsp(U8 *device_addr, BT_BOOL result)
{
    BT_PAN_DEVICE *dev = pan_find_device_by_addr(device_addr);
    bt_pan_connection_authorize_rsp_struct msg;

    assert(dev != NULL);

    /* even if authorization is deny, set state as connecting, and wait for disconnected event */
    pan_set_state(dev, BT_PAN_APP_STAT_CONNECTING);

    btmtk_os_memset((U8 *)&msg, 0, sizeof(bt_pan_connection_authorize_rsp_struct));

    msg.accept = result;
    btmtk_os_memcpy((U8 *)&msg.bt_addr, device_addr, sizeof(msg.bt_addr));
    BTCMD_SendMessage(MSG_ID_BT_PAN_CONNECTION_AUTHORIZE_RSP, MOD_EXTERNAL, &msg, sizeof(msg));
}
예제 #15
0
static BtStatus _time_gatt_discovery_characteristic_descriptors(
		TimePacket *pkt, U16 start, U16 end) {

	BtGattOp *gatt_op = &pkt->gatt_op;
	TimeCTransport *pChnl = (TimeCTransport *) pkt->chnl;

	OS_Report("[Time] %s(), handle range: %d to %d", __FUNCTION__, start, end);

	btmtk_os_memset((U8 *) gatt_op, 0, sizeof(BtGattOp));
	InitializeListEntry(&gatt_op->op.node);
	gatt_op->apCb = time_gatt_ap_callback;
	pkt->success_flag = 0;
	pkt->gatt_params.dds.startHandle = start;
	pkt->gatt_params.dds.endHandle = end;
	gatt_op->parms.p.allCharDescriptors= &pkt->gatt_params.dds;

	return BT_GATT_DiscoveryAllCharacteristicDescriptors(pChnl->handler.remDev, gatt_op);
}
예제 #16
0
BtStatus _time_gatt_write_without_response(TimePacket *pkt, U16 char_handle) {
	BtGattOp *gatt_op = &pkt->gatt_op;
	TimeCTransport *pChnl = (TimeCTransport *) pkt->chnl;
	U8 value = (U8) pkt->value;

	OS_Report("[Time] %s(), handle: %d", __FUNCTION__, char_handle);

	btmtk_os_memset((U8 *) gatt_op, 0, sizeof(BtGattOp));
	InitializeListEntry(&gatt_op->op.node);
	gatt_op->apCb = time_gatt_ap_callback;
	pkt->success_flag = 0;
	pkt->gatt_params.wch_wo_rsp.handle = char_handle;
	pkt->gatt_params.wch_wo_rsp.size = 1;
	pkt->gatt_params.wch_wo_rsp.data = &value;
	gatt_op->parms.p.writeWithoutResponse = &pkt->gatt_params.wch_wo_rsp;

	return BT_GATT_WriteWithoutResponse(pChnl->handler.remDev, gatt_op);
}
예제 #17
0
void SimServerAuthorize(RfChannel *Channel, BD_ADDR bdAddr)
{
	SIMAPCallbackParms parms;
	btbm_bd_addr_t bd_addr;

	/* record the current channel*/
	cur_rfchannel = Channel;

	SIM(simServer)[0].substate |= BT_MMI_AUTH_REQ_SENT;
		
	btmtk_os_memset((kal_uint8*) & bd_addr, 0, sizeof(btbm_bd_addr_t));
	CONVERT_ARRAY2BDADDR(&bd_addr, bdAddr.addr);
	
	
#if 0 // Reserved for MAUI
	bt_simap_auth_req->lap = 0;
	bt_simap_auth_req->uap = 0;
	bt_simap_auth_req->nap = 0;
	bt_simap_auth_req->lap = bd_addr.lap;
	bt_simap_auth_req->uap = bd_addr.uap;
	bt_simap_auth_req->nap = bd_addr.nap;
#endif
	parms.p.simap_auth_req.lap = 0;
	parms.p.simap_auth_req.uap = 0;
	parms.p.simap_auth_req.nap = 0;
	parms.p.simap_auth_req.lap = bd_addr.lap;
	parms.p.simap_auth_req.uap = bd_addr.uap;
	parms.p.simap_auth_req.nap = bd_addr.nap;

	/* Send AUTH_REQ msg to MMI */
#if 0 // Reserved for MAUI
	bt_send_msg(
		MSG_ID_BT_SIMAP_AUTH_REQ,
		MOD_MMI,
		BT_APP_SAP,
		(local_para_struct*) bt_simap_auth_req,
		NULL);
#endif

	parms.event = SIMAP_EVENT_AUTH_REQ;
	parms.dstMod = MOD_MMI;
	SIMAPCB(&parms);

}
예제 #18
0
static BtStatus _time_gatt_discovery_characteristic_by_uuid(
		TimePacket *pkt, U16 uuid, U16 start, U16 end) {
	BtGattOp *gatt_op = &pkt->gatt_op;
	TimeCTransport *pChnl = (TimeCTransport *) pkt->chnl;

	OS_Report("[Time] %s(), uuid: %x, handle range: %d to %d", __FUNCTION__, uuid, start, end);

	btmtk_os_memset((U8 *) gatt_op, 0, sizeof(BtGattOp));
	InitializeListEntry(&gatt_op->op.node);
	gatt_op->apCb = time_gatt_ap_callback;
	pkt->success_flag = 0;
	pkt->gatt_params.dch_uuid.startHandle = start;
	pkt->gatt_params.dch_uuid.endHandle = end;
	pkt->gatt_params.dch_uuid.type = 0x02;
	pkt->gatt_params.dch_uuid.uuid16[0] = uuid & 0xff;
	pkt->gatt_params.dch_uuid.uuid16[1] = uuid >> 8;
	gatt_op->parms.p.charByUUID = &pkt->gatt_params.dch_uuid;

	return BT_GATT_DiscoveryCharacteristicByUUID(pChnl->handler.remDev, gatt_op);
}
예제 #19
0
BtStatus HidCacheReportDescriptor(BD_ADDR addr, U8* HidDescriptorList, U32 length)
{
    U8 i = 0;
	
    for (i = 0; i < HID_MAX_REPORT_DESCRIPTOR_NUM; i++)
    {
        if (!CachedReportDescriptor[i].inUse)
        {
            btmtk_os_memcpy(CachedReportDescriptor[i].BtAddr.addr, addr.addr, 6);
            CachedReportDescriptor[i].inUse = TRUE;
            CachedReportDescriptor[i].reportDescriptor = (U8*)hid_malloc(length);
            if(!CachedReportDescriptor[i].reportDescriptor)
            {
                bt_prompt_trace(MOD_BT,"[HID]CachedReportDescriptor[i].reportDescriptor hid_malloc error");
                return BT_STATUS_FAILED;
            }
            btmtk_os_memset(CachedReportDescriptor[i].reportDescriptor, 0 ,length);
            btmtk_os_memcpy(CachedReportDescriptor[i].reportDescriptor, HidDescriptorList, length);
            CachedReportDescriptor[i].reportDescriptorLength = length;
            break;
        }
    }
    return BT_STATUS_SUCCESS;
}
예제 #20
0
S32 btmtk_goep_fs_findfirst(U8 *ucFolderPath, bt_ftp_find_struct **findstruct, bt_ftp_obj_info_struct *ftp_file_info) {
#ifdef BTMTK_GOEP_USE_WIN32_FS
    char sdir[256];
    char filter[64];
    U32 test_arrtibe;
    struct _wfinddata_t c_file;
    long hFile;
    bt_ftp_find_struct *pfind;

    GOEP_MEMSET((U8 *)ftp_file_info, 0, sizeof(bt_ftp_obj_info_struct) );

    ext_ucs2_str_n_to_asc_str(sdir, ucFolderPath, sizeof(sdir));

    // keep the previous folder path
    g_oldcwd[0] = 0;
    if ( NULL == _wgetcwd( (U16 *)g_oldcwd, sizeof(g_oldcwd)/2 ) ) {
        /// cannot keep the current folder
        GOEP_Report("[FS][ERR] fail to get cwd bufsize:(%d) err:%d!", sizeof(g_oldcwd)/2, GetLastError());
        return EXT_FS_ERR;
    }

    printf( "[fs] getcwd is '%s'\n", g_oldcwd);
    printf( "[fs] fs findfirst '%s' \n", sdir );
    _wchdir( (U16 *) ucFolderPath );


    ext_strncpy (filter, "*.*", 64);
    hFile = _wfindfirst(L"*.*", &c_file);

    if( -1 == hFile ) {
        return EXT_FS_ERR;
    } else {
        //plong = (long * )malloc(sizeof(long));
        pfind = (bt_ftp_find_struct *) malloc( sizeof(bt_ftp_find_struct) );
        *findstruct = pfind;

        if( *findstruct == NULL ) {
            return EXT_FS_ERR;
        }
        ((bt_ftp_find_struct *)*findstruct)->hFile = hFile;

        ext_ucs2ncpy( (S8 *) ftp_file_info->file_name, (const S8 *) c_file.name, sizeof(ftp_file_info->file_name)/2);
        update_win32_file_time(ftp_file_info);
        test_arrtibe = (_A_SUBDIR & c_file.attrib);
        if( _A_SUBDIR == test_arrtibe) {
            ftp_file_info->isFile = FALSE;
        } else {
            ftp_file_info->isFile = TRUE;
        }
        return EXT_FS_OK;
    }
#endif

#ifdef BTMTK_ON_WISE
    U8 *filter;
    S32 hFile;
    S32 len;
    bt_ftp_find_struct *pfind;
    FS_DOSDirEntry dir_entry;
    U8 filename[ BTMTK_EP_MAX_FILENAME_LEN ]; /// output

    //ext_ucs2ncpy (filter, (const U8 *)L"\\*.*", sizeof(filter)/2);
    len = ext_ucs2strlen((const S8*)ucFolderPath)*2 + 10;
    filter = (U8 *) get_ctrl_buffer( len ); // plus L"\\*.*"
    if( NULL == filter ) {
        return EXT_FS_ERR;
    }
    btmtk_os_memset( filter, 0, len);
    ext_ucs2ncpy( (U8 *) filter,  (const U8 *) ucFolderPath , len-2);
    ext_ucs2ncat( (U8 *) filter, (const U8 *) L"\\*.*", len-2);

    ext_ucs2ncpy((S8 *)filename, (const U8 *)L"", (sizeof(filename)/2)-1);

    hFile = (S32) FS_FindFirst(
                (const WCHAR*)filter,
                0,
                0,
                &dir_entry,
                (U16*) filename,
                sizeof(filename) );
    if( NULL == filter ) {
        free_ctrl_buffer(filter);
        filter = NULL;
    }
    if ( hFile >= 0) {
        GOEP_MEMSET((U8 *)ftp_file_info, 0, sizeof(bt_ftp_obj_info_struct) );
        pfind = (bt_ftp_find_struct *) get_ctrl_buffer( sizeof(bt_ftp_find_struct) );
        *findstruct = pfind;
        if( *findstruct == NULL ) {
            FS_FindClose( (FS_HANDLE) hFile );
            return EXT_FS_ERR;
        }
        ((bt_ftp_find_struct *)*findstruct)->hFile = hFile;

        static_convert_DirEntry_to_file_info( &dir_entry, ftp_file_info , filename);

        return EXT_FS_OK;
    } else {
        return EXT_FS_ERR;
    }

#endif

#ifdef BTMTK_ON_LINUX

    int ret;
    int err_num;

    bt_ext_log("[GOEP_FS] btmtk_goep_fs_findfirst(): Linux Version.");

    ext_chset_ucs2_to_utf8_string((U8 *) g_folder_path, sizeof(g_folder_path)-1, ucFolderPath);
    // strncpy(g_folder_path, ucFolderPath, sizeof(g_folder_path));
    bt_ext_log("[GOEP_FS] g_folder_path: %s", g_folder_path);

    g_opened_dir = opendir( g_folder_path);
    if (g_opened_dir == NULL) {
        err_num = errno;
        bt_ext_err("[FS_ERR] opendir() failed. %s", (char*) strerror(err_num));
        return EXT_FS_ERR;
    }

    return static_linux_fill_file_info(ftp_file_info);

#endif

    return EXT_FS_ERR;
}
예제 #21
0
/*****************************************************************************
 * FUNCTION
 *  SimSrvCallback
 * DESCRIPTION
 *  
 * PARAMETERS
 *  Server      [IN]        
 *  Parms       [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void SimSrvCallback(SimServer *Server, SimCallbackParms *Parms)
{
    SimCardReaderStatus cardRdrStatus;
    SimCardStatus statusChange = SIM_CARD_STATUS_UNKNOWN;
    SimResultCode result = SIM_RESULT_NO_REASON;
    BtStatus status;
    U8 *ptr;
    U16 len;

    switch (Parms->event)
    {
        case SAEVENT_SERVER_OPEN_IND:
            /* When receiving this event, SimServer will send CONNECT_RSP event back to client */
            if ((status = SIM_ServerRespondOpenInd(Server, SIM_CONN_STATUS_OK)) != BT_STATUS_PENDING)
            {
                kal_trace(TRACE_GROUP_1, BT_SIMAP_CON_NOT_ACCEPTED_IN_SRVCALLBACK, status);
                /* In this case means that sending of CONNECT_RSP is failed */
                /* Return value from RF_CloseChannel() may be BT_STATUS_IN_PROGRRESS(presenting rfchannel state is DLC_STATE_DISC_PENDING) */
                status = SimApCloseRFCommChnl(&(Server->rfChannel));
                if ((status != BT_STATUS_PENDING) && (status != BT_STATUS_IN_PROGRESS) && (status != BT_STATUS_SUCCESS))
                {
                    /* Report(("SERVER_OPEN_IND and RF_CloseChannel error, status=%d",status)); */
                    kal_trace(TRACE_GROUP_1, BT_SIMAP_SHOW_ONE_BYTE, status);
                    Assert(0);
                }
            }
            else
            {
                kal_trace(TRACE_GROUP_1, BT_SIMAP_CON_ACCEPTED_IN_SRVCALLBACK);
            }
            break;

        case SAEVENT_SERVER_OPEN:
            kal_trace(TRACE_GROUP_1, BT_SIMAP_CON_OPEN_IN_SRVCALLBACK, Parms->status);
            if (Parms->status == BT_STATUS_SUCCESS)
            {
#if 0 // Reserved for MAUI
		  bt_simap_connect_ind_struct *bt_simap_connect_ind = NULL;
#endif
            	  SIMAPCallbackParms parms;

                /* Allocated a connection id for SIM Access Profile (SC_SIM_ACCESS: 0x112D) */
                SIM(connect_id)[0] = BTBMProfileAllocateConnIndex(SC_SIM_ACCESS, Parms->ptrs.remDev->bdAddr);
                SIM(allocated_connect_id)[0] = KAL_TRUE;
#if 0 // Reserved for MAUI
                bt_simap_connect_ind = construct_local_para(sizeof(bt_simap_connect_ind_struct), TD_UL);
                /* Reset lap,uap,nap to zero */
                bt_simap_connect_ind->lap = 0;
                bt_simap_connect_ind->uap = 0;
                bt_simap_connect_ind->nap = 0;

                memcpy(&(bt_simap_connect_ind->lap), &Parms->ptrs.remDev->bdAddr.addr[0], 3);
                bt_simap_connect_ind->uap = Parms->ptrs.remDev->bdAddr.addr[3];
                memcpy(&(bt_simap_connect_ind->nap), (U16*) & Parms->ptrs.remDev->bdAddr.addr[4], 2);

                bt_simap_connect_ind->cid = SIM(connect_id)[0];

                bt_send_msg(
                    MSG_ID_BT_SIMAP_CONNECT_IND,
                    MOD_MMI,
                    BT_APP_SAP,
                    (local_para_struct*) bt_simap_connect_ind,
                    NULL);
#endif
		  parms.event = SIMAP_EVENT_CONNECT_IND;
		  parms.dstMod = MOD_MMI;
		  parms.p.simap_connect_ind.cid = SIM(connect_id)[0];
		  parms.p.simap_connect_ind.lap = 0;
		  parms.p.simap_connect_ind.uap = 0;
		  parms.p.simap_connect_ind.nap = 0;
                btmtk_os_memcpy((U8 *)&(parms.p.simap_connect_ind.lap), &Parms->ptrs.remDev->bdAddr.addr[0], 3);
                parms.p.simap_connect_ind.uap = Parms->ptrs.remDev->bdAddr.addr[3];
                btmtk_os_memcpy((U8 *)&(parms.p.simap_connect_ind.nap), (U8 *) &Parms->ptrs.remDev->bdAddr.addr[4], 2);
                SIMAPCB(&parms);
            }
            else
            {
                /* Handle the failed OPEN Event */
                /* Return value from RF_CloseChannel() may be BT_STATUS_IN_PROGRRESS(presenting rfchannel state is DLC_STATE_DISC_PENDING) */
                status = SimApCloseRFCommChnl(&(Server->rfChannel));
                if ((status != BT_STATUS_PENDING) && (status != BT_STATUS_IN_PROGRESS) && (status != BT_STATUS_SUCCESS))
                {
                    /* Report(("SERVER_OPEN and RF_CloseChannel err, status=%d",status)); */
                    kal_trace(TRACE_GROUP_1, BT_SIMAP_SHOW_ONE_BYTE, status);
                    Assert(0);
                }
            }
            break;

        case SAEVENT_SERVER_CLOSE_IND:
            kal_trace(TRACE_GROUP_1, BT_SIMAP_CON_CLOSED_IND_IN_SRVCALLBACK, Parms->status);
            break;

        case SAEVENT_SERVER_CLOSED:
            kal_trace(TRACE_GROUP_1, BT_SIMAP_CLOSED_IN_SRVCALLBACK, Parms->status);
            /* Determine that if is is necessary to notify SIM task to start recovery mechanism */
			Report(("[BT SIMAP_svr]SAEVENT_SERVER_CLOSED: substate=%d", SIM(simServer)[0].substate));

			//clear the RF channel
			cur_rfchannel = NULL;

            if (SIM(simServer)[0].substate & BT_REJECT_SECOND_CLIENT_SESSION)
            {
                SIM(simServer)[0].substate &= (~BT_REJECT_SECOND_CLIENT_SESSION);
                /* Report(("This closed event is due to SimServer is serving one client now, so reject another seesion")); */
                kal_trace(TRACE_GROUP_1, BT_SIMAP_CLOSED_EVENT_DUE_TO_REJECT_SECOND_CLIENT);
                return;
            }

            if ((SIM(simServer)[0].substate & BT_SIM_CONNECT_REQ_SENT) &&
                (SIM(simServer)[0].substate & BT_SIM_CONNECT_CNF_RECV) && (SIM(simServer)[0].atr.dataLen == 0))
            {
                //Report(("CONNECT_CNF from SIM task is error, Send DISC_REQ to SIM task is not necessary when CLOSED in SimServer")); 
                //Report(("Case0:In SimSrvCallback():SimServer is available again!"));
                kal_trace(TRACE_GROUP_1, BT_SIMAP_SRVCALLBACK_CASE0);
                SIM(simServer)[0].substate = 0;
                SIM(simServer)[0].available = TRUE;
            }
            else if (SIM(simServer)[0].substate & BT_SIM_CONNECT_REQ_SENT)
            {
                /* Because the SIM task may notify other modules to enter remote SIM mode, it is necessary to recovery as normal mode */
                /* Through sending disconnect_req to SIM task to notify it */

                /* Check if timer for DISC_Graceful is still runing */
                if (SIM(simServer)[0].substate & BT_APP_DISCONNECT_REQ_RECV)
                {
                    /* Report(("In SimSrvCallback() recv CLOSED, check timer for DISC_Graceful type")); */
                    kal_trace(TRACE_GROUP_1, BT_SIMAP_SRVCALLBACK_RECV_CLOSED_CHECK_TIMER);
                    bt_simap_stop_timer(&SIM(simap_event_id));
                }

                /* Send BT_SIM_DISCONNECT_REQ message to SIM task */
                SIM(simServer)[0].substate |= BT_SIM_DISCONNECT_REQ_SENT;

            #if 0
#ifdef __SIMAP_TESTER_

            if(SIM(simServer)[0].test_mode == 1)
                bt_fakesim_disconnect_req_hdlr();
            else if(SIM(simServer)[0].test_mode == 2)
                bt_send_msg(MSG_ID_BT_SIM_DISCONNECT_REQ, MOD_SIM, PS_SIM_SAP, NULL, NULL);
#endif
            #endif /* 0 */ 
                if (SIM(simServer)[0].exec_mode == 0)
                {
#ifdef __SIMAP_MAUI__
                    bt_send_msg(MSG_ID_BT_SIM_DISCONNECT_REQ, MOD_SIM, PS_SIM_SAP, NULL, NULL);
#else
		      SIMAPCallbackParms parms;
		      parms.event = SIM_EVENT_DISCONNECT_REQ;
		      parms.dstMod = MOD_SIM;
		      SIMAPCB(&parms);
#endif
                }
            #ifdef __SIMAP_UT_
                else if (SIM(simServer)[0].exec_mode == 1)
                {
                    bt_fakesim_disconnect_req_hdlr();
                }
            #endif /* __SIMAP_UT_ */ 

            }
            else
            {
                /* Note: substate field has two bytes, if U8 is used the substate (e.g., 0x1000) will be narrowed to 0x00 : 2006-12-28 */
                U32 oldsubstate = SIM(simServer)[0].substate;

                kal_trace(TRACE_GROUP_1, BT_SIMAP_SIMSERVER_AVAILABLE_IN_SRVCALLBACK, oldsubstate);
                /* Report(("Case1:In SimSrvCallback():SimServer is available again, and Simserver substate=%d",oldsubstate)); */

                /*
                 * Check if this CLOSED Event is triggered due to receive MMI's DEACTIVATE_REQ in SimServer's CONNECT_PENDING state
                 * If SimServer has not yet send CONNECT_REQ to SIM task, this case is matched (No necessary to notify SIM task)
                 * The DEACTIVATE_CNF is returned here directly
                 * At that time, we call RF_CloseChannel() to trigger this event
                 */

                if (SIM(simServer)[0].substate & BT_APP_DEACTIVATE_REQ_RECV)
                {
#if 0 // Reserved for MAUI
                    bt_simap_deactivate_cnf_struct *bt_simap_deactivate_cnf = construct_local_para(sizeof(bt_simap_deactivate_cnf_struct), TD_UL);
#endif
		      SIMAPCallbackParms parms;

                    /* Using this func to deregister rfcomm server channel and sdp record of SIM Access Profile */
                    Assert(SIM_DeregisterServer(Server) == BT_STATUS_SUCCESS);
                    /* Report(("This case is SimServer closed then RFCOMM closed due to MMI Deactivate Req, return Deactivate_CNF with ok")); */
                    kal_trace(TRACE_GROUP_1, BT_SIMAP_SIMSRV_CLOSED_RFCOMM_CLOSED_DUE_TO_DEACTIVATE_REQ);

                    SIM(simServer)[0].simserver_activate_status = SIM_SERVER_STATUS_DEACTIVATED;

                    /* This means that SIM Access Profile connection is closed, check if conneciton_id is still allocated */
                    if (SIM(allocated_connect_id)[0] == KAL_TRUE)
                    {
                        BTBMProfileReleaseConnIndex(SIM(connect_id)[0]);
                        SIM(allocated_connect_id)[0] = KAL_FALSE;
                        /* Report(("Release SIM Acces Profile connect_id in Case 1")); */
                        kal_trace(TRACE_GROUP_1, BT_SIMAP_RELEASE_SAP_CONID_CASE1);
                    }
#if 0 // Reserved for MAUI
		      bt_simap_deactivate_cnf->result = TRUE;
                    bt_send_msg(
                        MSG_ID_BT_SIMAP_DEACTIVATE_CNF,
                        MOD_MMI,
                        BT_APP_SAP,
                        (local_para_struct*) bt_simap_deactivate_cnf,
                        NULL);
#endif
		      parms.event = SIMAP_EVENT_DEACTIVATE_CNF;
		      parms.dstMod = MOD_MMI;
		      parms.p.simap_deactivate_cnf.result = TRUE;
		      SIMAPCB(&parms);
                }

                /* 
                 * [MAUI_02129303]: As the AUTH_REQ is not responded by MMI & remote device close the RFCOMM channel (timed-out), 
                 * we have to report this event to MMI to sync the status.
                 */
                else if (BT_MMI_AUTH_REQ_SENT == (SIM(simServer)[0].substate & BT_MMI_AUTH_REQ_SENT))
                {
                	SIMAPCallbackParms parms;
                     btbm_bd_addr_t bd_addr;

                     btmtk_os_memset((kal_uint8*) & bd_addr, 0, sizeof(btbm_bd_addr_t));
                     CONVERT_ARRAY2BDADDR(&bd_addr, Server->remDev->bdAddr.addr);

		       parms.event = SIMAP_EVENT_AUTH_REQ_TIMEOUT_RFCLOSED_IND;
		       parms.dstMod = MOD_MMI;
		       parms.p.simap_auth_req_timeout_rfclose_ind.lap = bd_addr.lap;
		       parms.p.simap_auth_req_timeout_rfclose_ind.uap = bd_addr.uap;
		       parms.p.simap_auth_req_timeout_rfclose_ind.nap = bd_addr.nap;
		       SIMAPCB(&parms);
                }

                SIM(simServer)[0].substate = 0;
                SIM(simServer)[0].available = TRUE;

                if (SIM_SERVER_STATUS_DEACTIVATING == SIM(simServer)[0].simserver_activate_status)
                {
                	/* Deactivate now.*/
                	bt_simap_deactivate_req_hdlr();
                }

            }

            break;

        case SAEVENT_SERVER_STATUS_REQ:

            if (Parms->status == BT_STATUS_SUCCESS)
            {
                if (SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_POWERED_ON)
                {
                    statusChange = SIM_CARD_STATUS_RESET;
                }
                else if (!(SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_POWERED_ON) &&
                         (SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT))
                {
                    statusChange = SIM_CARD_STATUS_INSERTED;
                }
                else if (!(SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT))
                {
                    statusChange = SIM_CARD_STATUS_REMOVED;
                }

            }
            else if (Parms->status == BT_STATUS_FAILED)
            {
                statusChange = SIM_CARD_STATUS_NOT_ACCESSIBLE;
            }

            if ((status = SIM_ServerSendStatus(Server, statusChange)) != BT_STATUS_PENDING)
            {
                kal_trace(TRACE_GROUP_1, BT_SIMAP_FAILED_SEND_STATUS_IND_IN_SRVCALLBACK, status);
            }
            else
            {
                kal_trace(TRACE_GROUP_1, BT_SIMAP_SEND_STATUS_IND_IN_SRVCALLBACK);
            }
            break;

        case SAEVENT_SERVER_ATR_REQ:
			//kal_trace(TRACE_GROUP_1, BT_SIMAP_SIMCARDREADER_STATUS, SIM(simServer)[0].current_simcardreader_status);
			Report(("[BT SIMAP]current_simcardreader_status=0x%x", SIM(simServer)[0].current_simcardreader_status));
            if ((SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_POWERED_ON) &&
                (SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT))
            {
                result = SIM_RESULT_OK;
                ptr = SIM(simServer)[0].atr.data;
                len = SIM(simServer)[0].atr.dataLen;

            }
            else if (SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT)
            {
                /* Alread off : This case is POWERED_OFF but CARD_PRESENT */
                result = SIM_RESULT_CARD_ALREADY_OFF;
                len = 0;
                ptr = NULL;
            }
            else if (!(SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT))
            {
                /* No card inserted */
                /* Note: it is impossible that POWERED_ON but CARD_NOT_PRESENT; so this is CARD_NOT_PRESENT case */
                result = SIM_RESULT_CARD_REMOVED;
                len = 0;
                ptr = NULL;
            }

            status = SIM_ServerAtrRsp(Server, len, ptr, result);
            kal_trace(TRACE_GROUP_1, BT_SIMAP_FAILED_SEND_ATR_RSP_IN_SRVCALLBACK, result, status);
            if (status != BT_STATUS_SUCCESS)
            {
                status = SimApCloseRFCommChnl(&(SIM(simServer)[0].rfChannel));
                Assert((status == BT_STATUS_PENDING) || (status == BT_STATUS_IN_PROGRESS));
            }
            break;

        case SAEVENT_SERVER_APDU_REQ:

            if ((SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_POWERED_ON) &&
                (SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT))
            {

                if (SIM(simServer)[0].exec_mode == 0)
                {
#ifdef __SIMAP_MAUI__
                    bt_sim_apdu_req_struct *apdu_req = NULL;
#else
		      SIMAPCallbackParms parms;
#endif
                    SIM(simServer)[0].substate |= BT_SIM_APDU_REQ_SENT;
                    kal_trace(TRACE_GROUP_1, BT_SIMAP_SEND_APDU_TO_SIM_IN_SRVCALLBACK);
#ifdef __SIMAP_MAUI__
                    /* Send APDU request to SIM task */
                    apdu_req = construct_local_para(sizeof(bt_sim_apdu_req_struct), TD_UL);

                    apdu_req->apdu_req_len = Parms->ptrs.msg->parm.apdu.dataLen;
                    OS_MemSet(apdu_req->apdu_req, 0, APDU_REQ_MAX_LEN);
                    OS_MemCopy(apdu_req->apdu_req, Parms->ptrs.msg->parm.apdu.data, apdu_req->apdu_req_len);

                    apdu_req->transport_protocol_type = SIM(simServer)[0].current_transport_protocol_type;
                    bt_send_msg(MSG_ID_BT_SIM_APDU_REQ, MOD_SIM, PS_SIM_SAP, (local_para_struct*) apdu_req, NULL);
#else
		      parms.event = SIM_EVENT_APDU_REQ;
		      parms.dstMod = MOD_SIM;
		      parms.p.sim_apdu_req.apdu_req_len = Parms->ptrs.msg->parm.apdu.dataLen;
		      btmtk_os_memset(parms.p.sim_apdu_req.apdu_req, 0, APDU_REQ_MAX_LEN);
		      btmtk_os_memcpy(parms.p.sim_apdu_req.apdu_req, Parms->ptrs.msg->parm.apdu.data, parms.p.sim_apdu_req.apdu_req_len);
		      parms.p.sim_apdu_req.transport_protocol_type = SIM(simServer)[0].current_transport_protocol_type;
		      SIMAPCB(&parms);
#endif
                }
            #ifdef __SIMAP_UT_
                else if (SIM(simServer)[0].exec_mode == 1)
                {

                    bt_fakesim_apdu_req_hdlr(Parms->ptrs.msg->parm.apdu.dataLen, Parms->ptrs.msg->parm.apdu.data);
                }
            #endif /* __SIMAP_UT_ */ 
            }
            else if (SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT)
            {
                /* Alread off : This case is POWERED_OFF but CARD_PRESENT */
                result = SIM_RESULT_CARD_ALREADY_OFF;
                ptr = NULL;
                len = 0;
                status = SIM_ServerApduRsp(&SIM(simServer)[0], len, ptr, result);
                kal_trace(TRACE_GROUP_1, BT_SIMAP_SEND_APDU_RSP_TO_CLIENT, result, status, 1);
                if (status != BT_STATUS_SUCCESS)
                {
                    status = SimApCloseRFCommChnl(&(SIM(simServer)[0].rfChannel));
                    Assert((status == BT_STATUS_PENDING) || (status == BT_STATUS_IN_PROGRESS));

                }
            }
            else if (!(SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT))
            {
                /* No card inserted */
                /* Note: it is impossible that POWERED_ON but CARD_NOT_PRESENT; so this is CARD_NOT_PRESENT case */
                result = SIM_RESULT_CARD_REMOVED;
                ptr = NULL;
                len = 0;
                status = SIM_ServerApduRsp(&SIM(simServer)[0], len, ptr, result);
                kal_trace(TRACE_GROUP_1, BT_SIMAP_SEND_APDU_RSP_TO_CLIENT, result, status, 2);
                if (status != BT_STATUS_SUCCESS)
                {
                    Assert(0);
                }
            }
            break;

        case SAEVENT_SERVER_SIM_OFF_REQ:

            if ((SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_POWERED_ON) &&
                (SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT))
            {
                /* In this case: must SIM_CRS_CARD_POWERED_ON and SIM_CRS_CARD_PRESENT are satisfied at the same time */
                /* Send POWER_OFF_REQ to SIM task */
                kal_trace(TRACE_GROUP_1, BT_SIM_SEND_POWER_OFF_TO_SIM_IN_SRVCALLBACK);
                SIM(simServer)[0].substate |= BT_SIM_POWER_OFF_REQ_SENT;

                if (SIM(simServer)[0].exec_mode == 0)
                {
#ifdef __SIMAP_MAUI__
                    bt_send_msg(MSG_ID_BT_SIM_POWER_OFF_REQ, MOD_SIM, PS_SIM_SAP, NULL, NULL);
#else
		      SIMAPCallbackParms parms;
		      parms.event = SIM_EVENT_POWER_OFF_REQ;
		      parms.dstMod = MOD_SIM;
		      SIMAPCB(&parms);
#endif
                }

            #ifdef __SIMAP_UT_
                else if (SIM(simServer)[0].exec_mode == 1)
                {
                    bt_fakesim_poweroff_req_hdlr();
                }
            #endif /* __SIMAP_UT_ */ 
                return;
            }
            else if (SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT)
            {
                /* Alread off : This case is POWERED_OFF but CARD_PRESENT */
                result = SIM_RESULT_CARD_ALREADY_OFF;
            }
            else if (!(SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT))
            {
                /* No card inserted */
                /* Note: it is impossible that POWERED_ON but CARD_NOT_PRESENT; so this is CARD_NOT_PRESENT case */
                result = SIM_RESULT_CARD_REMOVED;
            }

            /* Send POWER_OFF_RSP to client */
            status = SIM_ServerSimOffRsp(Server, result);
            kal_trace(TRACE_GROUP_1, BT_SIMAP_POWER_OFF_RSP_TO_CLIENT, result, status);
            if (status != BT_STATUS_SUCCESS)
            {
                status = SimApCloseRFCommChnl(&(SIM(simServer)[0].rfChannel));
                Assert((status == BT_STATUS_PENDING) || (status == BT_STATUS_IN_PROGRESS));

            }
            break;

        case SAEVENT_SERVER_SIM_ON_REQ:
            /* if current information is enough to return rsp, then sends rsp in this function */
            /* POWE_ON_REQ only let client to request T at 0 (T=0) */

            if ((SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_POWERED_ON) &&
                (SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT))
            {
                result = SIM_RESULT_CARD_ALREADY_ON;
            }
            else if (SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT)
            {
                /*
                 * Because SIM card is already off, so current_transport_protocol_type is invalid
                 * Set T=0 directly and send BT_SIM_RESET_REQ to sim task!
                 */
                if (SIM(simServer)[0].supported_transport_protocol_type_capability == 2 ||
                    SIM(simServer)[0].supported_transport_protocol_type_capability == 0)
                {
                    SIM(simServer)[0].substate |= BT_SIM_RESET_REQ_SENT_POWER_ON;

                    if (SIM(simServer)[0].exec_mode == 0)
                    {
#ifdef __SIMAP_MAUI__
			   bt_sim_reset_req_struct *reset_req = NULL;
                        reset_req = construct_local_para(sizeof(bt_sim_reset_req_struct), TD_UL);
                        reset_req->transport_protocol_type = 0; /* default using T=0 transport protocol type */
                        bt_send_msg(
                            MSG_ID_BT_SIM_RESET_REQ,
                            MOD_SIM,
                            PS_SIM_SAP,
                            (local_para_struct*) reset_req,
                            NULL);
#else
			   SIMAPCallbackParms parms;
			   parms.event = SIM_EVENT_RESET_REQ;
			   parms.dstMod = MOD_SIM;
			   parms.p.sim_reset_req.transport_protocol_type = 0;
			   SIMAPCB(&parms);
#endif
                    }
                #ifdef __SIMAP_UT_
                    else if (SIM(simServer)[0].exec_mode == 1)
                    {
                        bt_fakesim_poweron_req_hdlr();
                    }
                #endif /* __SIMAP_UT_ */ 
                    return;
                }
                else if (SIM(simServer)[0].supported_transport_protocol_type_capability == 1)
                {
                    /* SIM Card only supports T=1: RESET Error! because not support T=0, RESET_REQ uses T=0! */
                    result = SIM_RESULT_CARD_NOT_ACCESSIBLE;
                }

            }
            else if (!(SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT))
            {
                /* Note: it is impossible that POWERED_ON but CARD_NOT_PRESENT; so this is CARD_NOT_PRESENT case */
                result = SIM_RESULT_CARD_REMOVED;
            }
            else
            {
                kal_trace(TRACE_GROUP_1, BT_SIMAP_NO_RULES_PROCESS_SIM_ON_REQ_IN_SRVCALLBACK);
                Assert(0);
            }

            /* Send SIM_POWER_ON_RSP to sim client with result code */
            status = SIM_ServerSimOnRsp(Server, result);
            kal_trace(TRACE_GROUP_1, BT_SIMAP_SEND_POWER_ON_RSP_TO_CLIENT_IN_SRVCALLBACK, result, status);
            if (status != BT_STATUS_SUCCESS)
            {
                status = SimApCloseRFCommChnl(&(SIM(simServer)[0].rfChannel));
                Assert((status == BT_STATUS_PENDING) || (status == BT_STATUS_IN_PROGRESS));

            }
            break;

        case SAEVENT_SERVER_SET_TRANS_PROT_REQ:

        #if SET_T_SUPPORTED == TRUE
            /* if current information is enough to return rsp, then sends rsp in this function */
            /* Set Transport Protocol Type Req will ask to reset the SIM Card */
            SIM(simServer)[0].client_requested_transport_protocol_type = Parms->ptrs.msg->parm.protocolId;
            /* Report(("In SimSrvCallback(): client requested T type=%d",SIM(simServer)[0].client_requested_transport_protocol_type)); */
            kal_trace(
                TRACE_GROUP_1,
                BT_SIMAP_CLIENT_REQ_T_TYPE,
                SIM(simServer)[0].client_requested_transport_protocol_type);
            if ((SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_POWERED_ON) &&
                (SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT))
            {
                if (SIM(simServer)[0].supported_transport_protocol_type_capability == 2)
                {
                    /* SIM Card supports both T=0 and T=1: Send BT_SIM_RESET_REQ msg to SIM task */

                    if (SIM(simServer)[0].current_transport_protocol_type != Parms->ptrs.msg->parm.protocolId)
                    {
                        Assert((SIM(simServer)[0].current_transport_protocol_type == 0) ||
                               (SIM(simServer)[0].current_transport_protocol_type == 1));
                        SIM(simServer)[0].substate |= BT_SIM_RESET_REQ_SENT_SET_T;

                        if (SIM(simServer)[0].exec_mode == 0)
                        {
#ifdef __SIMAP_MAUI__
				bt_sim_reset_req_struct *reset_req = NULL;
                            reset_req = construct_local_para(sizeof(bt_sim_reset_req_struct), TD_UL);
                            reset_req->transport_protocol_type = Parms->ptrs.msg->parm.protocolId;
                            bt_send_msg(
                                MSG_ID_BT_SIM_RESET_REQ,
                                MOD_SIM,
                                PS_SIM_SAP,
                                (local_para_struct*) reset_req,
                                NULL);
#else
				SIMAPCallbackParms parms;
				parms.event = SIM_EVENT_RESET_REQ;
				parms.dstMod = MOD_SIM;
				parms.p.sim_reset_req.transport_protocol_type = Parms->ptrs.msg->parm.protocolId;
				SIMAPCB(&parms);
#endif
                        }
                    #ifdef __SIMAP_UT_
                        else if (SIM(simServer)[0].exec_mode == 1)
                        {
                            bt_fakesim_set_transprotocol_type_req_hdlr();
                        }
                    #endif /* __SIMAP_UT_ */ 

                        return;
                    }
                    else
                    {
                        /* Requested T type is the same as current T type, send rsp to sim client directly */
                        SIM(simServer)[0].substate |= BT_SIM_RESET_REQ_SENT_SET_T;
                        result = SIM_RESULT_OK;
                    }
                }
                else if (SIM(simServer)[0].supported_transport_protocol_type_capability == 1 ||
                         SIM(simServer)[0].supported_transport_protocol_type_capability == 0)
                {
                    /* In this case: SIM card only supports T=0 or T=1 and current_transport_protocol_type is equal to supported_transport_protocol_type_capability */
                    if (SIM(simServer)[0].current_transport_protocol_type != Parms->ptrs.msg->parm.protocolId)
                    {
                        /* Send REST_RSP with error code: Can't accessible to SIM Client */
                        /*
                         * In this case: Send SET_T_RSP first 
                         * then in Open state PACKET_HANDLED EVENT: send STATUS_IND with card not accessible 
                         */
                        /* Report(("SET T=0/T=1 but only support T=1/T=0, Send SET_T_RSP first then STATUS_IND with card not accessible later")); */
                        kal_trace(TRACE_GROUP_1, BT_SIMAP_SET_T0_T1_NOT_SUPPORT_T1_T0);
                        SIM(simServer)[0].substate |= BT_SIM_RESET_REQ_SENT_SET_T;
                        result = SIM_RESULT_NOT_SUPPORTED;
                    }
                    else
                    {
                        /* Requested T type is the same as current T type, send rsp to sim client directly */
                        result = SIM_RESULT_OK;
                    }
                }
            }
            else if ((!(SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_POWERED_ON)) &&
                     (SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT))
            {

                result = SIM_RESULT_CARD_ALREADY_OFF;
            }
            else if (!(SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT))
            {
                result = SIM_RESULT_CARD_REMOVED;
            }
        #else /* SET_T_SUPPORTED == TRUE */
            result = SIM_RESULT_NOT_SUPPORTED;
        #endif /* SET_T_SUPPORTED == TRUE */
            /* Send SIM_SET_TRANSPORT_PROTOCOL_TYPE_RSP to sim client with result code */
            status = SIM_ServerSetTransProtRsp(Server, result);
            kal_trace(TRACE_GROUP_1, BT_SIMAP_SEND_SET_T_RSP_TO_CLIENT_IN_SRVCALLBACK, result, status);
            if (status != BT_STATUS_SUCCESS)
            {
                Assert(0);
            }
            break;

        case SAEVENT_SERVER_RESET_SIM_REQ:
            /* if current information is enough to return rsp, then sends rsp in this function */
            /* RESET_REQ only let client to request T at 0 (T=0) */

            if ((SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_POWERED_ON) &&
                (SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT))
            {
                /*
                 * The original following state is wrong! 
                 * Because as long as one bit (SIM_CRS_CARD_POWERED_ON or SIM_CRS_CARD_PRESENT) is set in current_simcardreader_status, condition is true!
                 * if((SIM(simServer)[0].current_simcardreader_status & (SIM_CRS_CARD_POWERED_ON | SIM_CRS_CARD_PRESENT))) 
                 */

                /* In this case, must POWERED_ON and CARD_PRESERT are statisfied at the same time */
                if (SIM(simServer)[0].supported_transport_protocol_type_capability == 2)
                {
                    /* SIM Card supports both T=0 and T=1: Send BT_SIM_RESET_REQ msg to SIM task */
                    Assert((SIM(simServer)[0].current_transport_protocol_type == 0) ||
                           (SIM(simServer)[0].current_transport_protocol_type == 1));
                    SIM(simServer)[0].substate |= BT_SIM_RESET_REQ_SENT;

                    if (SIM(simServer)[0].exec_mode == 0)
                    {
#ifdef __SIMAP_MAUI__
			   bt_sim_reset_req_struct *reset_req = NULL;
                        reset_req = construct_local_para(sizeof(bt_sim_reset_req_struct), TD_UL);
                        reset_req->transport_protocol_type = 0; /* default using T=0 transport protocol type */
                        bt_send_msg(
                            MSG_ID_BT_SIM_RESET_REQ,
                            MOD_SIM,
                            PS_SIM_SAP,
                            (local_para_struct*) reset_req,
                            NULL);
#else
			   SIMAPCallbackParms parms;
			   parms.event = SIM_EVENT_RESET_REQ;
			   parms.dstMod = MOD_SIM;
			   parms.p.sim_reset_req.transport_protocol_type = 0;
			   SIMAPCB(&parms);
#endif
                    }
                #ifdef __SIMAP_UT_
                    else if (SIM(simServer)[0].exec_mode == 1)
                    {
                        bt_fakesim_reset_req_hdlr();
                    }
                #endif /* __SIMAP_UT_ */ 

                    return;
                }
                else if (SIM(simServer)[0].supported_transport_protocol_type_capability == 1)
                {
                    /* SIM Card only supports T=1: RESET Error! because not support T=0, RESET_REQ uses T=0! */
                    Assert(SIM(simServer)[0].supported_transport_protocol_type_capability == SIM(simServer)[0].current_transport_protocol_type);
                    /* Send REST_RSP with error code: Can't accessible to SIM Client */
                    result = SIM_RESULT_CARD_NOT_ACCESSIBLE;
                }
                else if (SIM(simServer)[0].supported_transport_protocol_type_capability == 0)
                {
                    /* SIM Card only supports T=0: Send BT_SIM_RESET_REQ msg to SIM task */
                    Assert(SIM(simServer)[0].supported_transport_protocol_type_capability == SIM(simServer)[0].current_transport_protocol_type);
                    SIM(simServer)[0].substate |= BT_SIM_RESET_REQ_SENT;

                    if (SIM(simServer)[0].exec_mode == 0)
                    {
#ifdef __SIMAP_MAUI__
			   bt_sim_reset_req_struct *reset_req = NULL;
                        reset_req = construct_local_para(sizeof(bt_sim_reset_req_struct), TD_UL);
                        reset_req->transport_protocol_type = 0; /* default using T=0 transport protocol type */
                        bt_send_msg(
                            MSG_ID_BT_SIM_RESET_REQ,
                            MOD_SIM,
                            PS_SIM_SAP,
                            (local_para_struct*) reset_req,
                            NULL);
#else
			   SIMAPCallbackParms parms;
			   parms.event = SIM_EVENT_RESET_REQ;
			   parms.dstMod = MOD_SIM;
			   parms.p.sim_reset_req.transport_protocol_type = 0;
			   SIMAPCB(&parms);
#endif
                    }
                #ifdef __SIMAP_UT_
                    else if (SIM(simServer)[0].exec_mode == 1)
                    {
                        bt_fakesim_reset_req_hdlr();
                    }
                #endif /* __SIMAP_UT_ */ 
                    return;
                }
            }
            else if (SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT)
            {
                /* This case is SIM_CRS_CARD_PRESENT(0x40) with SIM_CRS_CARD_POWERED_OFF(0x00) */
                /* Send REST_RSP with error code: Card powered off to SIM Client */
                result = SIM_RESULT_CARD_ALREADY_OFF;
            }
            else if (!(SIM(simServer)[0].current_simcardreader_status & SIM_CRS_CARD_PRESENT))
            {
                /* Send REST_RSP with error code: Card Removed to SIM Client */
                /* Note: it is impossible that POWERED_ON but CRS_NOT_PRESENT case, so this is CARD_NOT_PRESENT case */
                result = SIM_RESULT_CARD_REMOVED;
            }
            else
            {
                kal_trace(TRACE_GROUP_1, BT_SIMAP_NO_RULES_PROCESS_RESET_REQ_IN_SRVCALLBACK);
                Assert(0);
            }

            /* Send SIM_RESET_RSP to sim client with result code */
            status = SIM_ServerResetSimRsp(Server, result);
            kal_trace(TRACE_GROUP_1, BT_SIMAP_SEND_RESET_RSP_TO_CLIENT_IN_SRVCALLBACK, result, status);
            if (status != BT_STATUS_SUCCESS)
            {
                status = SimApCloseRFCommChnl(&(SIM(simServer)[0].rfChannel));
                Assert((status == BT_STATUS_PENDING) || (status == BT_STATUS_IN_PROGRESS));
            }
            break;

        case SAEVENT_SERVER_CARD_READER_STATUS_REQ:
            cardRdrStatus = SIM(simServer)[0].current_simcardreader_status;
            status = SIM_ServerCardReaderStatusRsp(Server, cardRdrStatus, SIM_RESULT_OK);
            kal_trace(TRACE_GROUP_1, BT_SIMAP_SEND_CARD_RDS_RSP_TO_CLIENT_IN_SRVCALLBACK, result, status);
            if (status != BT_STATUS_SUCCESS)
            {
                status = SimApCloseRFCommChnl(&(SIM(simServer)[0].rfChannel));
                Assert((status == BT_STATUS_PENDING) || (status == BT_STATUS_IN_PROGRESS));
            }

            break;

        case SAEVENT_SERVER_STATUS_SENT:
            kal_trace(TRACE_GROUP_1, BT_SIMAP_STATUS_IND_SENT_IN_SRVCALLBACK, Parms->status);
            /* Note that the STATUS_SENT Event may be failed, handle this case here */
            if (Parms->status != BT_STATUS_SUCCESS)
            {
                if (Server->state == SIM_SERVER_STATE_CONN_PENDING)
                {
                    /* In CONNECT_PENDING state, this means that STATUS_IND(with reset) is sent failed */
                    /* Close this SIM Access Profile connection */
                    /* Return value from RF_CloseChannel() may be BT_STATUS_IN_PROGRRESS(presenting rfchannel state is DLC_STATE_DISC_PENDING) */
                    status = SimApCloseRFCommChnl(&(Server->rfChannel));
                    if ((status != BT_STATUS_PENDING) && (status != BT_STATUS_IN_PROGRESS) && (status != BT_STATUS_SUCCESS))
                    {
                        /* Report(("SERVER_STATUS_SENT and RF_CloseChannel err, status=%d",status)); */
                        kal_trace(TRACE_GROUP_1, BT_SIMAP_SHOW_ONE_BYTE, status);
                        Assert(0);
                    }
                }
                else if (Server->state == SIM_SERVER_STATE_OPEN)
                {   /* Ignore it */
                }
                else
                {
                    /* Send STATUS_IND in wrong SimServer's state and send this event fail */
                    Assert(0);
                }
            }
            break;
    }
}
예제 #22
0
void fmp_adp_init(void)
{
    //g_service_flags = 0;
    btmtk_os_memset((U8 *)&fmp_cntx, 0, sizeof(fmp_cntx));
}
예제 #23
0
/*---------------------------------------------------------------------------
 *            HidSdpParseDescriptorList()
 *---------------------------------------------------------------------------
 *
 * Synopsis:  Parses the SDP query response for an 16 bit value.
 *
 * Return:    (see SDP_ParseAttributes)
 */
static void HidSdpParseDescriptorList(HidChannel *Channel, U8 *in_value, U16 in_len, U8 result)
{
   // HidParseData	*hpd;
    //hpd = Hid_Init_Parser();

    if (in_value == NULL)
    {
        return;
    }
	
    if (!(Channel->queryRsp.queryFlags & SDPQ_FLAG_DESCRIPTOR_LIST)) {

        if (in_len == 0) {
            return;
        }
        
        //if ((result == BT_STATUS_SDP_CONT_STATE) &&
	     if(Channel->queryRsp.descriptorLenOffset == 0)
        {
            U8 elemType = 0;
            U8 elemSizeDescpt = 0;			
            U8 elemSize = 0;			
            U8 elemAddSize = 0;			
            U8 offset = 0;
            U8 i = 0;
			
            /* Only the first packet is preceded with data element header. The packet
              * in continuation sequence is raw data.
              */

            while (offset + Channel->queryRsp.descriptorLen < in_len) 
            {
                elemType = SDP_GetElemType(in_value[offset]);
                elemSizeDescpt = SDP_GetElemSize(in_value[offset]);
                switch (elemType)
                {
                    case DETD_SEQ:
                        if (elemSizeDescpt == DESD_ADD_8BITS) 
                        {
                            offset = offset + 1;
                        }
                        else if (elemSizeDescpt == DESD_ADD_16BITS) 
                        {
                            offset = offset + 2;
                        }
                        else if (elemSizeDescpt == DESD_ADD_32BITS) 
                        {
                            offset = offset + 4;
                        }
                        break;
						
                    case DETD_UINT:
                        if (elemSizeDescpt > DESD_16BYTES) 
                        {
                            return;
                        }
                        else
                        {
                            elemSize = HidSdpGetValidSize(elemSizeDescpt);
                            offset += elemSize;
                        }
                        break;
						
                    case DETD_TEXT:
                        if (elemSizeDescpt == DESD_ADD_8BITS) 
                        {
                            elemAddSize = 1;
                        }
                        else if (elemSizeDescpt == DESD_ADD_16BITS) 
                        {
                            elemAddSize = 2;
                        }
                        else if (elemSizeDescpt == DESD_ADD_32BITS) 
                        {
                            elemAddSize = 4;
                        }

                        for (i = 0; i < elemAddSize; i++)
                        {
                            Channel->queryRsp.descriptorLen = (Channel->queryRsp.descriptorLen << 8) | (in_value[offset + i + 1]);
                        }
                        offset = offset + elemAddSize;
                        break;
						
                    default:
                        // other data element shall not be come out in HID attribute list						
                        break;
                }

                offset++;
            }

            if((in_len - offset) <= 0)
            {
                return;
            }

            /* Allocate a new buffer */
            Channel->queryRsp.descriptorList = (U8 *)hid_malloc((U32)Channel->queryRsp.descriptorLen);
            if (Channel->queryRsp.descriptorList == NULL)
            {
                return;
            }
            btmtk_os_memset(Channel->queryRsp.descriptorList, 0, Channel->queryRsp.descriptorLen);

            /* Copy whatever data is available */
            btmtk_os_memcpy(Channel->queryRsp.descriptorList, in_value + offset, in_len - offset);
			
            Channel->queryRsp.descriptorLenOffset = in_len - offset;
        }
        else
        {
            btmtk_os_memcpy(Channel->queryRsp.descriptorList + Channel->queryRsp.descriptorLenOffset, 
				        in_value, in_len);

            /* in case that there is more continuation packet */
            Channel->queryRsp.descriptorLenOffset += in_len;		
	/*
	   if(Hid_SdpParse(Channel, hpd) == BT_STATUS_SUCCESS)
		bt_prompt_trace(MOD_BT,"[HID]Successed  SDP parser ");
	   else if(Hid_SdpParse(Channel, hpd) == BT_STATUS_FAILED)
	   	bt_prompt_trace(MOD_BT,"[HID]Failed  SDP parser ");
	   Hid_Free_Parser(hpd);*/
        }

        kal_trace(BT_TRACE_G2_PROFILES,HID_SDP_PARSEATTRIBUTES_SUCCEEDED_BYTES_READ__xD_UPDATED_BUFF_LEN__xD , in_len, Channel->queryRsp.descriptorLenOffset);

        if (result == BT_STATUS_SUCCESS)
        {
            Channel->queryRsp.queryFlags |= SDPQ_FLAG_DESCRIPTOR_LIST;
        }
    }

}
예제 #24
0
void HidSdpEventHandler(SdpQueryToken *sqt, U8 result, U8 attr_idx, U8 *attr_val)
{
    HidChannel     *channel = ContainingRecord(sqt, 
                                               HidChannel, sdpQueryToken);
    ReportDescriptorList* reportDescriptorList = NULL;
    HidParseData*	hpd ;
    kal_trace(BT_TRACE_G2_PROFILES,BT_HID_SDP_QUERY_CALLBACK_x02X ,result);

    switch (result) 
    {
        case BT_STATUS_SDP_CONT_STATE:
            kal_trace(BT_TRACE_G2_PROFILES,HID_SDP_SUCCESSFULLY);
            HidVerifySdpQueryRsp(channel, bt_hid_attr_id_list[attr_idx], attr_val, sqt->availValueLen, result);  
            break;

        case BT_STATUS_SUCCESS:
            HidVerifySdpQueryRsp(channel, bt_hid_attr_id_list[attr_idx], attr_val, sqt->availValueLen, result);
            if (channel->bSDPDiscPending)
            {
                HidClearConnection(channel, result, 0);
            }
            else 
            {
				hpd = (HidParseData*)hid_malloc(sizeof(HidParseData));
				Hid_Init_Parser(hpd);
                		channel->reportCons[0] = (HidReportConstructor*)hid_malloc(HID_REPORT_ID_MAX * sizeof(HidReportConstructor));
				btmtk_os_memset((U8*) channel->reportCons[0], 0, HID_REPORT_ID_MAX * sizeof(HidReportConstructor));

				reportDescriptorList = HidFindReportDescriptorByAddr(channel->cmgrHandler.remDev->bdAddr);
				
				if(reportDescriptorList != NULL )
				{		
					btmtk_os_memset(reportDescriptorList->BtAddr.addr, 0, 6);
					reportDescriptorList->inUse = FALSE;
					hid_free(reportDescriptorList->reportDescriptor);
					reportDescriptorList->reportDescriptorLength = 0;
				}
				
				HidCacheReportDescriptor(channel->cmgrHandler.remDev->bdAddr, channel->queryRsp.descriptorList, channel->queryRsp.descriptorLen);
				
        		if(HidAddDescriptor(channel) == BT_STATUS_SUCCESS)
        			bt_prompt_trace(MOD_BT,"[HID]HidAddDescriptor Successed!");
        		else
        			bt_prompt_trace(MOD_BT,"[HID]HidAddDescriptor failed!");   
                
				Hid_Free_Parser(hpd);
                channel->flags &= ~CHNL_FLAG_SERVICE_QUERY;
                HidSdpCallback(channel, result);
            }
            break;
		case BT_STATUS_NOSERVICES:
			{
				static const U8 HidDescriptorList[] = 
				{
				    HID_DESCRIPTOR
				};
				channel->queryRsp.descriptorLen = HID_DESCRIPTOR_LEN;
				channel->queryRsp.descriptorList = (U8*)hid_malloc(HID_DESCRIPTOR_LEN);
				btmtk_os_memset((U8*) channel->queryRsp.descriptorList, 0, HID_DESCRIPTOR_LEN);				
				btmtk_os_memcpy((U8*) channel->queryRsp.descriptorList, HidDescriptorList, HID_DESCRIPTOR_LEN);
				hpd = (HidParseData*)hid_malloc(sizeof(HidParseData));
				Hid_Init_Parser(hpd);
                		channel->reportCons[0] = (HidReportConstructor*)hid_malloc(HID_REPORT_ID_MAX * sizeof(HidReportConstructor));
				btmtk_os_memset((U8*) channel->reportCons[0], 0, HID_REPORT_ID_MAX * sizeof(HidReportConstructor));

                if(HidAddDescriptor(channel) == BT_STATUS_SUCCESS)
                    bt_prompt_trace(MOD_BT,"[HID]HidAddDescriptor Successed!");
                else
                    bt_prompt_trace(MOD_BT,"[HID]HidAddDescriptor failed!");
                
				Hid_Free_Parser(hpd);
                channel->flags &= ~CHNL_FLAG_SERVICE_QUERY;
                HidSdpCallback(channel, BT_STATUS_SUCCESS);
				break;
			}
        case BT_STATUS_CONNECTION_FAILED:
        case BT_STATUS_FAILED:
        default:
            channel->flags &= ~CHNL_FLAG_SERVICE_QUERY;
            HidClearConnection(channel, result, 0);
            break;
    }

}
예제 #25
0
void Hid_Reset_UsageQueue(HidParseData  *hpd)
{
	hpd->usageSize = 0;
	hpd->usageNum = 0;
	btmtk_os_memset((U8*) hpd->usageQueue, 0 ,HID_USAGE_MAX *sizeof(HidUsage));
}
예제 #26
0
/*
* @param ucFilename ucs2 filename
* @u4MaxLen bytes
*/
BT_BOOL btmtk_goep_get_private_filepath(U8 type, const U8 *ucFilename, U8 *ucOutFilepath, U32 u4MaxLen) {
    BT_BOOL l_bret = FALSE;

#if defined(BTMTK_ON_WISESDK)
    //SDK
    U8 tempPath[512];
    U8 l_u2RootPath[512];

    btmtk_os_memset( l_u2RootPath, 0, sizeof(l_u2RootPath));
    ext_chset_utf8_to_ucs2_string( l_u2RootPath, sizeof(l_u2RootPath)-2, g_bt_dir_buf);
    if( FALSE == btmtk_goep_is_folder_exist( (const U16*) l_u2RootPath) ) {
        GOEP_Report("[GOEP] btmtk_goep_get_private_filepath no root folder");
        return FALSE;
    }

    /// <sdk root path>\\xxx\\@btmtk\\ folder
    ext_ucs2ncpy( (S8*)tempPath, l_u2RootPath, sizeof(tempPath)/2);
    ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\Component\\MBT\\HWAdapt\\MTK\\LIB\\@btmtk", sizeof(tempPath)/2);
    if( 0 != ext_ucs2strlen((const S8*)tempPath) && FALSE == btmtk_goep_is_folder_exist((const U16*)tempPath) ) {
        btmtk_goep_create_folder((const U16*)tempPath);
    }

    switch(type) {
    case 0:  /// <sdk root path>\\xxx\\@btmtk\\ .
        ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\", sizeof(tempPath)/2);
        ext_ucs2ncat( (S8*)tempPath, ucFilename, sizeof(tempPath)/2);
        ext_ucs2ncpy((S8 *) ucOutFilepath, tempPath, u4MaxLen );
        if( ext_ucs2strlen((const S8*)ucOutFilepath) == ext_ucs2strlen((const S8*)tempPath) ) {
            l_bret = TRUE;
        }

        break;
    case 1:  /// <sdk root path>\\xxx\\@btmtk\\profile
        ext_ucs2ncpy( (S8*)tempPath, l_u2RootPath, sizeof(tempPath)/2);
        ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\Component\\MBT\\HWAdapt\\MTK\\LIB\\@btmtk\\profile", sizeof(tempPath)/2);
        if( FALSE == btmtk_goep_is_folder_exist((const U16*)tempPath) ) {
            btmtk_goep_create_folder((const U16*)tempPath);
        }
        ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\", sizeof(tempPath)/2);
        ext_ucs2ncat( (S8*)tempPath, ucFilename, sizeof(tempPath)/2);
        ext_ucs2ncpy((S8 *) ucOutFilepath, tempPath, u4MaxLen );
        if( ext_ucs2strlen((const S8*)ucOutFilepath) == ext_ucs2strlen((const S8*)tempPath) ) {
            l_bret = TRUE;
        }

        break;
    case 2:  /// <sdk root path>\\xxx\\@btmtk\\data
        ext_ucs2ncpy( (S8*)tempPath, l_u2RootPath, sizeof(tempPath)/2);
        ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\Component\\MBT\\HWAdapt\\MTK\\LIB\\@btmtk\\data", sizeof(tempPath)/2);
        if( FALSE == btmtk_goep_is_folder_exist((const U16*)tempPath) ) {
            btmtk_goep_create_folder((const U16*)tempPath);
        }
        ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\", sizeof(tempPath)/2);
        ext_ucs2ncat( (S8*)tempPath, ucFilename, sizeof(tempPath)/2);
        ext_ucs2ncpy((S8 *) ucOutFilepath, tempPath, u4MaxLen );
        if( ext_ucs2strlen((const S8*)ucOutFilepath) == ext_ucs2strlen((const S8*)tempPath) ) {
            l_bret = TRUE;
        }
        break;
    default:
        GOEP_Report("[OBEX][Err] btmtk_goep_get_private_filepath fail param:%d");
        break;
    }

#else
    // Target
    U8 tempPath[512];

    switch(type) {
    case 0: /// Z:\\@btmtk
        ext_ucs2ncpy( (S8 *) tempPath, (const S8*)L"Z:\\@btmtk", sizeof( tempPath ) );
        break;
    case 1: /// C:\\@btmtk\\profiles
        ext_ucs2ncpy( (S8 *) tempPath, (const S8*)L"C:\\@btmtk\\profiles", sizeof( tempPath ) );
        break;
    case 2: /// C:\\@btmtk\\data
        ext_ucs2ncpy( (S8 *) tempPath, (const S8*)L"C:\\@btmtk\\data", sizeof( tempPath ) );
        break;
    default:
        break;
    }

    if( 0 != ext_ucs2strlen((const S8*)tempPath) ) {
        if (FALSE == btmtk_goep_is_folder_exist( (const U16*) tempPath) ) {
            btmtk_goep_create_folder((const U16*)tempPath);
        }
        ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\", sizeof(tempPath)/2);
        ext_ucs2ncat( (S8*)tempPath, (const S8*)ucFilename, sizeof(tempPath)/2);

        ext_ucs2ncpy( (S8 *)ucOutFilepath, (const S8*)tempPath, u4MaxLen);
        if( ext_ucs2strlen((const S8*)ucOutFilepath) == ext_ucs2strlen((const S8*)tempPath) ) {
            l_bret = TRUE;
        }
    }

#endif
    return l_bret;
}