📄 rmmi_bt.c
字号:
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*****************************************************************************
* Filename:
* ---------
* rmmi_bt.c
*
* Description:
* ------------
* This file implements the AT parser and command handler for Bluetooth
*
* Author:
* -------
* -------
*==============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*==============================================================================
*
*****************************************************************************/
#define RMMI_BT_C
#include <stdio.h>
#include <string.h>
#include "kal_release.h"
#include "stack_common.h"
#include "stack_msgs.h"
#include "app_buff_alloc.h"
#include "app_ltlcom.h" /* Task message communiction */
#include "stack_timer.h"
#include "l4c_msghdlr.h"
#include "ps2sim_struct.h"
#include "sim_common_enums.h"
#include "smu_common_enums.h"
#include "csmss_common_enums.h"
#ifdef __MCD__
#include "mcd_l4_common.h"
#else
#include "l4_common.h"
#endif
#include "l4c_common_enum.h"
#include "rmmi_common_enum.h"
#include "rmmi_context.h"
#include "l4c_context.h"
#include "layer4_context.h"
#include "l4_trc.h"
#include "rmmi_bt.h"
#include "gpio_sw.h"
#include "pmic6318_sw.h"
#include "uart_sw.h"
#include "device.h"
#include "eint.h"
#ifdef __BT_DEBUG__
#include "rtc_sw.h"
#endif
#if defined(__MMI_FMI__) && defined(__BTVCSR_HP__)
#include "bt_user_config.h"
/* cause: 0 normal, 1 panic, 2 assert */
void l4c_bt_close_log_file( kal_uint8 cause );
#define RMMI_MAX_BT_CMD_NUM 25
extern UART_PORT PS_UART_PORT;
//extern kal_uint8 rmmi_aux_PDNhandle;
static kal_bool rmmi_wakeup_flag = KAL_FALSE;
static kal_bool rmmi_hostwk_flag=KAL_FALSE;
static eventid rmmi_wakup_timer, rmmi_sco_protection_timer,rmmi_hostwk_timer;
static kal_uint8 rmmi_sco_protection_counter = 0;
kal_uint8 rmmi_bt_l1sm_handle;
eventid data_select_timer;
bt_cmd_queue_struct rmmi_bt_cmd_queue;
extern void l4c_bt_wkdur_timeout_hdlr(void);
extern void l4c_bt_stop_wkdur_timer(void);
extern void l4c_bt_start_wkdur_timer(void);
extern void l4c_bt_start_hostwksig_timer(void);
extern void l4c_bt_stop_hostwksig_timer(void);
extern void l4c_bt_hostwksig_timeout_hdlr(void);
extern module_type UART_GetOwnerID(UART_PORT port);
extern void l4c_send_clip_ind_to_bt(void);
const kal_char * const RMMI_BT_CMD_TABLE[RMMI_MAX_BT_CMD_NUM]
={
"WAKEOK=",
"OK",
"+CINQRES=",
"+CINQCFM=",
"+CPINREQ=",
"+CPINCFM=",
"+CRFCSTAT=",
"+CSCOSTAT=",
"+VDS=",
"+CKPD=",
"ERROR=",
"+CPROFILE=",
"AT+NREC=",
//"AT+BVRA=",
"AT+BINP=",
"+CSTAT=",
"+CBD=",
"+PSGET:",
"+LNAME=",
"+CRREG",
"+RNR=",
"+CCFG",
"+CLINK=",
"+VGS=",
"+DLIST="
};
RMMI_EXT_CMD_FUNCTION const
rmmi_bt_cmd_ft[RMMI_MAX_BT_CMD_NUM]
= {
rmmi_bt_wakeok_hdlr,
rmmi_bt_ok_hdlr,
rmmi_bt_cinqres_hdlr,
rmmi_bt_cinqcfm_hdlr,
rmmi_bt_cpinreq_hdlr,
rmmi_bt_cpincfm_hdlr,
rmmi_bt_crfcstat_hdlr,
rmmi_bt_cscostat_hdlr,
rmmi_bt_vgs_hdlr,
rmmi_bt_ckpd_hdlr,
rmmi_bt_error_hdlr,
rmmi_bt_cprofile_hdlr,
rmmi_bt_nrec_hdlr,
//rmmi_bt_bvra_hdlr,
rmmi_bt_binq_hdlr,
rmmi_bt_cstat_hdlr,
rmmi_bt_cbd_hdlr,
rmmi_bt_getps_hdlr,
rmmi_bt_lname_hdlr,
rmmi_bt_crreg_hdlr,
rmmi_bt_rnr_hdlr,
rmmi_bt_ccfg_hdlr,
rmmi_bt_clink_hdlr,
rmmi_bt_vgs_hdlr,
rmmi_bt_dlist_hdlr
};
extern kal_bool rmmi_bt_str_validator ( rmmi_string_struct *source_string_ptr,
kal_uint8 delimiter,
kal_uint16 max_length,
kal_uint8 *str,
kal_bool skip_bs);
extern kal_bool rmmi_bt_hex_validator (rmmi_string_struct *source_string_ptr,
kal_uint8 delimiter,
kal_uint16 maxlen,
kal_uint8 *addr);
extern void rmmi_result_code_fmttr(kal_uint8 rsp_type, kal_uint16 cause);
void rmmi_bt_init(void)
{
UART_PORT bt_port;
UARTDCBStruct bt_dcb;
bt_port = BT_GetPort_Setting(&bt_dcb);
#ifdef DCM_ENABLE
UART_TurnOnPower(bt_port, KAL_TRUE);
#endif
UART_Open (bt_port, MOD_L4C);
UART_SleepOnTx_Enable(bt_port, uart_sleep_on_tx_allow);
UART_SetDCBConfig (bt_port, &bt_dcb, MOD_L4C);
UART_ConfigEscape (bt_port, RMMI_CHAR_PLUS, 1000, MOD_L4C);
RMMI_PTR->BT_port = KAL_FALSE;
RMMI_PTR->BT_string = NULL;
RMMI_PTR->BT_as_serial_port = KAL_FALSE;
RMMI_PTR->BT_auth = 1;
RMMI_PTR->BT_visible = 0; /* Hide */
RMMI_PTR->cmd_from_BT = KAL_FALSE;
#ifdef __BT_DEBUG__
RMMI_PTR->BT_file_handle = NULL; //BT_DEBUG
#endif
//to get identical l1sm handle for BT rmmi instead of using rmmi_aux_PDNhandle
rmmi_bt_l1sm_handle = L1SM_GetHandle();
#ifdef __RMMI_BT_DEBUG__
//L1SM_SleepDisable(rmmi_aux_PDNhandle);//for test load :doesn't allow system to sleep
L1SM_SleepDisable(rmmi_bt_l1sm_handle);//for test load :doesn't allow system to sleep
#endif
//init rmmi_bt_cmd_queue
rmmi_bt_cmd_queue_init();
}
void print_as_hex(kal_uint8 * data, kal_uint8 * str, kal_uint8 len)
{
kal_uint16 i=0, j=0;
ASSERT ((data != NULL) && (str != NULL));
while (j < len)
{
i += kal_sprintf((char *)str+i, "%02x", data[j]);
j++;
}
str[i] = '\0';
}
/*****************************************************************************
* FUNCTION
* rmmi_bt_passcmd()
* DESCRIPTION
* +BT= <data>
* This function passes the data to UART3, for develop testing & debugging
* PARAMETERS
*
* RETURNS
* none.
* GLOBALS AFFECTED
* none.
*****************************************************************************/
void rmmi_bt_passcmd (rmmi_string_struct *source_string_ptr)
{
kal_uint8 string[100];
kal_uint8 len;
strcpy((char*)string, (char*)&source_string_ptr->string_ptr[source_string_ptr->index]);
len = strlen((char*)string);
string[len-1]=0 ; // remove <CR>
rmmi_bt_send_btcmd(string);
}
/*****************************************************************************
* FUNCTION
* rmmi_bt_cmd_processor()
* DESCRIPTION
* This function try to find the valid BT command
* PARAMETERS
*
* RETURNS
* none.
* GLOBALS AFFECTED
* none.
*****************************************************************************/
kal_bool rmmi_bt_cmd_processor (
rmmi_string_struct *source_string_ptr,
kal_uint16 cmd_length
)
{
kal_uint16 temp_index = source_string_ptr->index;
kal_bool ret_val = KAL_FALSE;
//try to find the possible command beginning charactors
while ((source_string_ptr->string_ptr[source_string_ptr->index] != RMMI_CHAR_PLUS) &&
(source_string_ptr->string_ptr[source_string_ptr->index] != RMMI_CHAR_A) &&
(source_string_ptr->string_ptr[source_string_ptr->index] != RMMI_CHAR_E) &&
(source_string_ptr->string_ptr[source_string_ptr->index] != RMMI_CHAR_W) &&
(source_string_ptr->string_ptr[source_string_ptr->index] != RMMI_CHAR_O) &&
(source_string_ptr->index < cmd_length ) )
{
source_string_ptr->index++;
}
if (source_string_ptr->index == cmd_length )
{
//reach the end of the command, cannot be BT cmd, reset the index and return FALSE
source_string_ptr->index = temp_index;
return KAL_FALSE;
}
else
{
//start with "+ A E W O", check if it is a BT cmd.
ret_val = rmmi_bt_cmd_validator(source_string_ptr);
source_string_ptr->index = temp_index;
return ret_val ;
}
}
/*****************************************************************************
* FUNCTION
* rmmi_bt_cmd_validator()
* DESCRIPTION
* This function checks the BT_CMD_TABLE to validate if it is a BT cmd.
* PARAMETERS
*
* RETURNS
* none.
* GLOBALS AFFECTED
* none.
*****************************************************************************/
kal_bool rmmi_bt_cmd_validator ( rmmi_string_struct *source_string_ptr)
{
kal_uint8 i;
char * str;
/* we use "+BT= <data>" to send <data> to UART3 */
if (strncmp((char*)&(source_string_ptr->string_ptr[source_string_ptr->index]), "+BT=", 4) == 0)
{
source_string_ptr->index += 4;
rmmi_bt_passcmd(source_string_ptr );
/* debug information */
kal_trace(TRACE_GROUP_3, RMMI_BT_READ, source_string_ptr->string_ptr[0],
source_string_ptr->string_ptr[1],
source_string_ptr->string_ptr[2],
source_string_ptr->string_ptr[3],
source_string_ptr->string_ptr[4],
source_string_ptr->string_ptr[5],
source_string_ptr->string_ptr[6],
source_string_ptr->string_ptr[7],
source_string_ptr->string_ptr[8],
source_string_ptr->string_ptr[9],
source_string_ptr->string_ptr[10],
source_string_ptr->string_ptr[11]);
return KAL_TRUE;
}
/*
else if (strncmp((char*)&(source_string_ptr->string_ptr[source_string_ptr->index]), "AT+EMBT=", 8) == 0)
{
// move to rmmi_embt_hdlr() in rmmi_validator.c
// to turn on/off test mode and set friendly name.
}
*/
/* compare to each entry of BT_CMD_TABLE */
for(i = 0 ; i < RMMI_MAX_BT_CMD_NUM; i++ )
{
str = (char*)RMMI_BT_CMD_TABLE[i];
if (strncmp((char*)&(source_string_ptr->string_ptr[source_string_ptr->index]), str, strlen(str)) == 0)
{
//The BT command is found!!!
#ifdef __BT_DEBUG__
//BT_DEBUG: write the received command to the log file
if (RMMI_PTR->BT_file_handle >0)
{
kal_int32 ret_v;
kal_uint16 str_len;
kal_uint32 len;
str_len = strlen((char*)source_string_ptr->string_ptr);
ret_v = FS_Write(RMMI_PTR->BT_file_handle,
(kal_uint8 *)source_string_ptr->string_ptr,
str_len,
&len );
if((str_len != len) || (ret_v != FS_NO_ERROR))
kal_print("Write to BT log fail");
}
#endif
/* debug information */
kal_trace(TRACE_GROUP_3, RMMI_BT_READ, source_string_ptr->string_ptr[0],
source_string_ptr->string_ptr[1],
source_string_ptr->string_ptr[2],
source_string_ptr->string_ptr[3],
source_string_ptr->string_ptr[4],
source_string_ptr->string_ptr[5],
source_string_ptr->string_ptr[6],
source_string_ptr->string_ptr[7],
source_string_ptr->string_ptr[8],
source_string_ptr->string_ptr[9],
source_string_ptr->string_ptr[10],
source_string_ptr->string_ptr[11]);
source_string_ptr->index += strlen(str); //move the index for later parsing
(rmmi_bt_cmd_ft [i]) ( source_string_ptr ); //call the command handler
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -