#ifndef __AL_BLUETOOTH_CTRL_H__
#define __AL_BLUETOOTH_CTRL_H__

#include "al_basictypes.h"

//**********************************************************************
//module 5851S
//**********************************************************************
#ifdef CONFIG_BT_5851S
#define BT_NAME_LEN_MAX 40
#define BT_HEADER_LEN 3
#define BT_TRAILER_LEN 2
#define BT_VER_LEN_MAX 40
#define BT_TEL_NUM_LEN_MAX 20
#define BT_MAC_LEN_MAX 8

#define CMD_BT_HEADER		"AT#"
#define CMD_BT_TRAILER	"rn"

#define HB_STATUS_BT_INCOMING_CALL (0x01 ) //電話呼入狀態
#define HB_STATUS_BT_OUTGOING_CALL (0x02) //電話呼出狀態
#define HB_STATUS_BT_PHONE_CALL (0x03) //通話狀態
#define HB_STATUS_BT_PHONE_RING 0x4
#define HB_STATUS_BT_PHONE_OFF_CALL 0x5

#define HB_STATUS_BT_RECONNECT (0xff) 
#define HB_STATUS_BT_WAIT_CONN (0x01) //等待連接配對
#define HB_STATUS_BT_CONNECTED ( 0x02) //藍牙連接成功，等待播放音樂
#define HB_STATUS_BT_PLAYING (0x03) //正在播放音樂
#define HB_STATUS_BT_TEL HB_STATUS_BT_PHONE_RING //電話響鈴
#define HB_STATUS_BT_PAUSE HB_STATUS_BT_CONNECTED //音樂播放暫停


typedef enum {
    BT_CMD_STANDBY = 0,
    BT_CMD_SET_BT_MODE,
    BT_CMD_GET_CONSTATUS,
    BT_CMD_GET_PLAYSTATUS,
    BT_CMD_GET_PHONESTATUS,
    BT_CMD_SET_LANG,
    BT_CMD_GET_PHONE_NUM,
	BT_CMD_GET_PAIRED_NAME,
    BT_CMD_DIS = 0x41,
    BT_CMD_PLAYPAUSE = 0x42,
    BT_CMD_PREV = 0x43,
    BT_CMD_NEXT = 0x44,
    BT_CMD_ANSWER_CALL = 0x45,
    BT_CMD_CUT_CALL = 0x46,
    BT_CMD_QUERY_STATUS = 0x47,
    BT_CMD_GET_VER = 0x48,
    BT_CMD_GET_ADC = 0x49,
    BT_CMD_SET_BT_NAME = 0x4b,
    BT_CMD_MAX,
} AL_Enum_BT_CMD;

typedef enum{
		BT_REC_STATUS = 0x41,
		BT_REC_PHONE_NUM = 0x42,
		BT_REC_PHONE_STATUS = 0x43,
		BT_REC_PAIRED_NAME = 0x44,
		BT_REC_SW_VER = 0x45,
		BT_REC_ADC_VALUE = 0x46,
} AL_Enum_BT_REC_CMD;

typedef enum{
	BT_REQ_NONE = 0,
	BT_REQ_HAD_PAIRED_NAME=0x1,
	BT_REQ_HAD_PHONE_NUM=0x2,
	BT_REQ_GET_PAIRED_NAME=0x4,
	BT_REQ_GET_PHONE_NUM=0x8,
	BT_REQ_GET_VER=0x10,
	BT_REQ_GET_ADC_VALUE=0x20,
} Al_Enum_BT_Request;

typedef enum {
    BT_STATUS_WAIT_CONN = 0x1,
    BT_STATUS_RCONNECT = 0x2,
    BT_STATUS_CONNECTED = 0x3,
    BT_STATUS_PAUSE = BT_STATUS_CONNECTED,
    BT_STATUS_PLAYING = 0x4,
    BT_STATUS_PHONE_CALL = 0x5,
    BT_STATUS_ONGOING_CALL = BT_STATUS_PHONE_CALL,
    BT_STATUS_INCOMING_CALL = 0x6,
    BT_STATUS_OUTGOING_CALL = 0x7,

    BT_SYS_STATUS_MODE_STANDBY = 0x100,
    BT_SYS_STATUS_MODE_BT = 0x200,
} Al_Enum_BT_Status;


//**********************************************************************
//module AK105XT
//**********************************************************************
#elif defined(CONFIG_BT_AK105XT)

#define BT_NAME_LEN_MAX 32
#define BT_HEADER_LEN 6
#define BT_TRAILER_LEN 6
#define BT_VER_LEN_MAX 20
#define BT_TEL_NUM_LEN_MAX 20
#define BT_MAC_LEN_MAX 8

#define CMD_BT_HEADER		"GAITEK"
#define CMD_BT_TRAILER	"KETIAG"

#define HB_STATUS_BT_WAIT_CONN (0x01) //等待連接配對
#define HB_STATUS_BT_RECONNECT (0x02) //正在自動回連設備
#define HB_STATUS_BT_CONNECTED ( 0x03) //藍牙連接成功，等待播放音樂
#define HB_STATUS_BT_PLAYING (0x04) //正在播放音樂
#define HB_STATUS_BT_PAUSE HB_STATUS_BT_CONNECTED //音樂播放暫停
#define HB_STATUS_BT_PHONE_CALL (0x05) //通話狀態
#define HB_STATUS_BT_ONGOING_CALL HB_STATUS_BT_PHONE_CALL
#define HB_STATUS_BT_INCOMING_CALL (0x06 ) //電話呼入狀態
#define HB_STATUS_BT_OUTGOING_CALL (0x07) //電話呼出狀態
#define HB_STATUS_BT_PHONE_OFF_CALL 0x8 // off call for UI notice


typedef enum {
    BT_CMD_STANDBY = 0,
    BT_CMD_SET_BT_MODE,
    BT_CMD_PLAYPAUSE,
    BT_CMD_NEXT,
    BT_CMD_PREV,
    BT_CMD_TEST,
    BT_CMD_DIS,
    BT_CMD_RECON,
    BT_CMD_SET_NAME,
    BT_CMD_RESET_CONFIG,
    BT_CMD_HEART_BEAT,
    BT_CMD_GET_NAME,
    BT_CMD_GET_MAC,
    BT_CMD_GET_PAIRED_NAME,
    BT_CMD_TEST_WAIT_CONN,
    BT_CMD_GET_PHONE_NUM,
    BT_CMD_GET_VER,
    BT_CMD_GET_CONSTATUS,
    BT_CMD_GET_PLAYSTATUS,
    BT_CMD_PHONE_ANSWER,
    BT_CMD_PHONE_REDIAL,
    BT_CMD_PHONE_REJECT,
    BT_CMD_PHONE_CNACEL,
    BT_CMD_PHONE_SWITCH_SCO,
    BT_CMD_PHONE_CONNECT_SCO,
    BT_CMD_PHONE_DISCONNECT_SCO,
    BT_CMD_SET_LANG,
    BT_CMD_GET_PHONESTATUS,
    BT_CMD_MAX,
} AL_Enum_BT_CMD;

typedef enum{
	BT_REQ_NONE = 0,
	BT_REQ_GET_NAME=0x1,
	BT_REQ_GET_MAC=0x2,
	BT_REQ_GET_PAIRED_NAME=0x4,
	BT_REQ_GET_PHONE_NUM=0x8,
	BT_REQ_GET_VER=0x10,
} Al_Enum_BT_Request;

typedef enum {
    BT_STATUS_WAIT_CONN = 0x1,
    BT_STATUS_RCONNECT = 0x2,
    BT_STATUS_CONNECTED = 0x3,
    BT_STATUS_PAUSE = BT_STATUS_CONNECTED,
    BT_STATUS_PLAYING = 0x4,
    BT_STATUS_PHONE_CALL = 0x5,
    BT_STATUS_ONGOING_CALL = BT_STATUS_PHONE_CALL,
    BT_STATUS_INCOMING_CALL = 0x6,
    BT_STATUS_OUTGOING_CALL = 0x7,

    BT_SYS_STATUS_MODE_STANDBY = 0x100,
    BT_SYS_STATUS_MODE_BT = 0x200,
} Al_Enum_BT_Status;


#elif defined(CONFIG_BT_RDA5856)

#define BT_HEADER_LEN 3
#define BT_TRAILER_LEN 3
#define BT_VER_LEN_MAX 20
#define BT_TEL_NUM_LEN_MAX 16
#define BT_MAC_LEN_MAX 8

/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/
/*BT define, must match with bt, do't modify ~~ */
#define CMD_BT_HEADER		"RB#"
#define CMD_BT_TRAILER	"#BR"

#define MAX_BT_PAIRERED_DEVICE_LIST 5
#define BT_NAME_LEN_MAX 32
#define SIZE_OF_BDADDR 6
#define SIZE_OF_LINKKEY 	16
#define SIZE_OF_DHKEY   24

typedef enum {
    BT_CMD_STANDBY = 0x0,
    BT_CMD_SET_BT_RECEIVE_MODE = 0x1,
	BT_CMD_SET_BT_SEND_MODE = 0x2,
	BT_CMD_CHANGE_MODE = 0x3,	//one by one change mode
    BT_CMD_PLAYPAUSE = 0x4,	//play<->pause
    BT_CMD_NEXT = 0x5,	//next
    BT_CMD_PREV = 0x6,	//prev
    BT_CMD_TEST = 0x7,
    BT_CMD_DISCONNECT = 0x8,
    BT_CMD_RECONNECT = 0x9,
    BT_CMD_SET_NAME = 0xa,
    BT_CMD_RESET_CONFIG = 0xb,
    BT_CMD_HEART_BEAT = 0xc,
    BT_CMD_GET_NAME = 0xd,
    BT_CMD_GET_MAC = 0xe,
    BT_CMD_GET_PAIRED_NAME = 0xf,
    BT_CMD_TEST_WAIT_CONN = 0x10,
    BT_CMD_GET_PHONE_NUM = 0x11,
    BT_CMD_GET_VER = 0x12,
    BT_CMD_GET_CONSTATUS = 0x13,
    BT_CMD_GET_PLAYSTATUS = 0x14,
    BT_CMD_PHONE_ANSWER = 0x15,
    BT_CMD_PHONE_REDIAL = 0x16,
    BT_CMD_PHONE_REJECT = 0x17,
    BT_CMD_PHONE_CNACEL = 0x18,
    BT_CMD_PHONE_SWITCH_SCO = 0x19,
    BT_CMD_PHONE_CONNECT_SCO = 0x1a,
    BT_CMD_PHONE_DISCONNECT_SCO = 0x1b,
    BT_CMD_SET_LANG = 0x1c,
    BT_CMD_GET_PHONESTATUS = 0x1d,
	BT_CMD_RETURN_BT_CMD_STATUS = 0x1e,
	BT_CMD_BTINQUIRY = 0x1f,
	BT_CMD_BTINQUIRYCANCEL = 0x20,
	BT_CMD_BTCONNECT = 0x21,
	BT_CMD_UPDATE_TVBTADDRS = 0x22,
	BT_CMD_SET_BT_MODE = 0x23,
	BT_CMD_UPDATE_TVBTINQUIRYOVER = 0x24,
	BT_CMD_GET_PAIRERED_DEVICE = 0x25,
	BT_CMD_RESP_PAIRERED_DEVICE = 0x26,
	BT_CMD_GET_CONNECTED_DEVICE = 0x27,
	BT_CMD_RESP_CONNECTED_DEVICE = 0x28,
	BT_CMD_CANCEL_PAIRER = 0x29,
	BT_CMD_BT_VISIBLE = 0x2a,
	BT_CMD_BT_VOLADD = 0x2b,
	BT_CMD_BT_VOLSUB = 0x2c,
	BT_CMD_AVRCP_PASSTHROUGH = 0x2d,
	BT_CMD_SPP_PASSTHROUGH = 0x2e,
	BT_CMD_SEARCH_ALL = 0x2f,
	BT_CMD_SEND_FMFREQ = 0x30,
	BT_CMD_SEND_FMSCAN = 0x31,
	BT_CMD_RESP_NAME = 0x32,
	BT_CMD_RESP_VER = 0x33,
	BT_CMD_RESP_CONNECT_FAIL = 0x34,
	BT_CMD_GPIO_CONTROL = 0x35,
	BT_CMD_MUTE_CONTROL = 0x36,
	BT_CMD_CANCEL_ALL_PAIRER = 0x37,
	BT_CMD_SYSRESTART = 0x38,
	BT_CMD_RESP_CMD_NOACTION = 0x39,
	BT_CMD_GET_HOST_AKH = 0x3a,
	BT_CMD_PLAY_1K_AUDIO = 0x3b,
	
    BT_CMD_MAX,
} AL_Enum_BT_CMD;

typedef enum{
	BT_RESP_OK = 0,
	BT_RESP_FAIL=0x1,
	BT_RESP_ERR_CMD=0x2,
	BT_RESP_ERR_CHECKSUM=0x3,
	BT_RESP_ERR_PARAM=0x4,
	BT_RESP_MAX,
} Al_Enum_BT_RespondStatus;

typedef enum {
     BT_MODE_OFF = 0x0,
     BT_MODE_SEND = 0x1,
     BT_MODE_RECEIVE_BT = 0x2,
	 BT_MODE_RECEIVE_FM = 0x3,
	 BT_MODE_RECEIVE_LINEIN = 0x4,
	 BT_MODE_RECEIVE_USB = 0x5,
	 BT_MODE_MAX,
} Al_BTMode_t;

typedef enum {
    HB_STATUS_BT_WAIT_CONN = 0x1,
    HB_STATUS_BT_RECONNECT = 0x2,
    HB_STATUS_BT_CONNECTED = 0x3,
    HB_STATUS_BT_PAUSE = HB_STATUS_BT_CONNECTED,
    HB_STATUS_BT_PLAYING = 0x4,
    HB_STATUS_BT_PHONE_CALL = 0x5,
    HB_STATUS_BT_ONGOING_CALL = HB_STATUS_BT_PHONE_CALL,
    HB_STATUS_BT_INCOMING_CALL = 0x6,
    HB_STATUS_BT_OUTGOING_CALL = 0x7,
    HB_STATUS_BT_PHONE_OFF_CALL = 0x8,

} Al_Enum_BT_Status;

typedef enum {
    BT_AVRCP_OP_PLAY = 0x1,
    BT_AVRCP_OP_PAUSE = 0x2,
    BT_AVRCP_OP_STOP = 0x3,
    BT_AVRCP_OP_FORWARD = 0x4,
    BT_AVRCP_OP_BACKWARD = 0x5,
    BT_AVRCP_OP_VOLUME_UP = 0x6,
    BT_AVRCP_OP_VOLUME_DOWN = 0x7,
	BT_AVRCP_OP_MAX,

} Al_Enum_BT_AVRCP_OpCmd;

typedef enum {
    BT_SPP_EVENT_POWER = 0x1,
    BT_SPP_EVENT_MUTE = 0x2,
    BT_SPP_EVENT_1 = 0x3,
    BT_SPP_EVENT_2 = 0x4,
    BT_SPP_EVENT_3 = 0x5,
    BT_SPP_EVENT_4 = 0x6,
    BT_SPP_EVENT_5 = 0x7,
    BT_SPP_EVENT_6 = 0x8,
    BT_SPP_EVENT_7 = 0x9,
    BT_SPP_EVENT_8 = 0xa,
	BT_SPP_EVENT_9 = 0xb,
	BT_SPP_EVENT_DIGITAL = 0xc,
	BT_SPP_EVENT_POINT = 0xd,
	BT_SPP_EVENT_PLAY = 0xe,
	BT_SPP_EVENT_PAUSE = 0xf,
	BT_SPP_EVENT_PRE = 0x10,
	BT_SPP_EVENT_NEXT = 0x11,
	BT_SPP_EVENT_FR = 0x12,
	BT_SPP_EVENT_FF = 0x13,
	BT_SPP_EVENT_VOL_PLUS = 0x14,
	BT_SPP_EVENT_VOL_M = 0x15,
	BT_SPP_EVENT_UP = 0x16,
	BT_SPP_EVENT_DOWN = 0x17,
	BT_SPP_EVENT_LEFT = 0x18,
	BT_SPP_EVENT_RIGHT = 0x19,
	BT_SPP_EVENT_ENTER = 0x1a,
	BT_SPP_EVENT_MENU = 0x1b,
	BT_SPP_EVENT_SOURCE = 0x1C,
	BT_SPP_EVENT_CH_PLUS = 0x1d,
	BT_SPP_EVENT_RED = 0x1e,
	BT_SPP_EVENT_GREEN = 0x1f,
	BT_SPP_EVENT_YELLOW = 0x20,
	BT_SPP_EVENT_BLUE = 0x21,
	BT_SPP_EVENT_STOP = 0x22,
	BT_SPP_EVENT_0 = 0x23,
	BT_SPP_EVENT_CH_M = 0x24,
	BT_SPP_EVENT_CH_LIST = 0x25,
	BT_SPP_EVENT_SLEEP = 0x26,
	BT_SPP_EVENT_FREEZE = 0x27,
	BT_SPP_EVENT_INFO = 0x28,
	BT_SPP_EVENT_PIC_MOD = 0x29,
	BT_SPP_EVENT_SOUND_MOD = 0x2a,
	BT_SPP_EVENT_ASPECT = 0x2b,
	BT_SPP_EVENT_MTS = 0x2c,
	BT_SPP_EVENT_EPG = 0x2d,
	BT_SPP_EVENT_PIP_MENU = 0x2e,
	BT_SPP_EVENT_TVRADIO = 0x2f,
	BT_SPP_EVENT_TEXT = 0x30,
	BT_SPP_EVENT_SUBTITLE = 0x31,
	BT_SPP_EVENT_AD = 0x32,
	BT_SPP_EVENT_PLAY_PAUSE = 0x33,
	BT_SPP_EVENT_REC = 0x34,
	BT_SPP_EVENT_USB = 0x35,
	BT_SPP_EVENT_EXIT = 0x36,

	BT_SPP_EVENT_MAX,

} Al_Enum_BT_SPP_EventCmd;


typedef struct {
	UINT8 bytes[SIZE_OF_BDADDR];
} t_bdaddr;

typedef struct _AP_BT_HEART_BEAT
{    
    al_uint8 bt_mode;//g_bt_type; Al_BTMode_t
    al_uint8 bt_status;//bt status
    al_uint8 bt_ready;//bt ready; 0~1
    al_uint8 reserve[5];//reserve byte:byte[0]:app_bt_state_t;byte[1]:is_avrcp_connected;byte[2]:connecting flag;byte[3]:disconneting flag;byte[4]:abnormal disconnect flag
    t_bdaddr connectedaddr;;//connected bt
}AP_BT_HEART_BEAT;

/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/

typedef enum{
	BT_REQ_NONE = 0,
	BT_REQ_GET_NAME=0x1,
	BT_REQ_GET_MAC=0x2,
	BT_REQ_GET_PAIRED_NAME=0x4,
	BT_REQ_GET_PHONE_NUM=0x8,
	BT_REQ_GET_VER=0x10,
	BT_REQ_GET_PAIRED_DEVICE=0x20,
} Al_Enum_BT_Request;

typedef struct {
    al_uint8 len;
    al_uint8 cmd;
} Al_RBT_Cmd_Head;

//**********************************************************************
//module POL6556
//**********************************************************************
#elif defined(CONFIG_BT_POL6556)

#define BT_HEADER_LEN 3
#define BT_TRAILER_LEN 3
#define BT_VER_LEN_MAX 20
#define BT_TEL_NUM_LEN_MAX 16
#define BT_MAC_LEN_MAX 8

/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/
/*BT define, must match with bt, do't modify ~~ */
#define CMD_BT_HEADER		"\xAC\x69"

#define MAX_BT_PAIRERED_DEVICE_LIST 5
#define BT_NAME_LEN_MAX 40
#define SIZE_OF_BDADDR 6
#define SIZE_OF_LINKKEY 	16
#define SIZE_OF_DHKEY   24

typedef enum {
    //CMD common
    BT_CMD_ACK_OK = 0x0,
    BT_CMD_ACK_ERR = 0x1,
    
    //MCU->BT
	BT_CMD_SET_BT_POWER_ON = 0x2,
	BT_CMD_STANDBY = 0x3,	//BT_CMD_SET_BT_POWER_OFF

	//BT->MCU
    BT_CMD_REPORT_CONNECT_RESULTS = 0x4,	
    BT_CMD_REPORT_DISCONNECT_RESULTS = 0x5,	

    //MCU->BT
    BT_CMD_BTINQUIRY  = 0x6,//BT_CMD_SET_INQUIRY_START	
    BT_CMD_BTINQUIRYCANCEL  = 0x7,//BT_CMD_SET_INQUIRY_STOP
    BT_CMD_BTCONNECT  = 0x8,//BT_CMD_SET_CONNECT
    BT_CMD_DISCONNECT = 0x9,//BT_CMD_SET_DISCONNECT

    //BT->MCU
    BT_CMD_REPORT_CONNECT_STATUS = 0xa,
    BT_CMD_REPORT_INQUIRY_COMPLETE = 0xb,
    BT_CMD_REPORT_INQUIRY_RESULTS = 0xc,
    BT_CMD_REPORT_RECEIVE_BT_CTRL_CMD = 0xd,

   
    BT_CMD_SET_BT_MUSIC_VOL_VALUE = 0xe,
    BT_CMD_SET_POWER_ON_TO_WAIT_CONN = 0xf,
    BT_CMD_SET_POWER_ON_TO_TX_NOT_ACTION = 0x10,
    
    BT_CMD_SET_AUDIO_CHANNEL_INPUT_SELECT = 0x11,
    BT_CMD_GET_AUDIO_CHANNEL_INPUT_SELECT = 0x12,
    BT_CMD_REPORT_AUDIO_CHANNEL_INPUT_SELECT = 0x13,
    
    BT_CMD_SET_POWER_ON_RX = 0x40,
    BT_CMD_SET_POWER_ON_TX = 0x41,
    BT_CMD_GET_RX_OR_TX_MODE = 0x42,
    BT_CMD_REPORT_BT_RX_OR_TX_MODE = 0x43,
    BT_CMD_GET_CONSTATUS  = 0x44,//BT_CMD_GET_BT_CONNECT_STATE 
    BT_CMD_REPORT_CONNECT_STATE_WITH_ADDR_AND_NAME = 0x45,

    BT_CMD_GET_BT_INQUIRY_STATUS = 0x46,
    BT_CMD_REPORT_BT_INQUIRY_STATUS = 0x47,
    
    BT_CMD_GET_BT_MUSIC_STATUS = 0x48,
    BT_CMD_REPORT_BT_MUSIC_STATUS = 0x49,
    
    BT_CMD_SET_BT_CTRL_CMD = 0x4A,
    BT_CMD_GET_BT_MUSIC_VOL_RESULTS = 0x4B,
	BT_CMD_REPORT_BT_MUSIC_VOL_RESULTS = 0x4C,
	
	BT_CMD_GET_BT_MUTE_STATUS = 0x4D,
	BT_CMD_REPORT_BT_MUTE_STATUS = 0x4E,
	
	BT_CMD_SET_BT_TONE_VOL_VALUE = 0x4F,
	BT_CMD_GET_BT_TONE_VOL_RESULTS = 0x50,
	BT_CMD_REPORT_BT_TONE_VOL_RESULTS = 0x51,
	
	BT_CMD_SET_BT_TO_TEST_MODE = 0xA0,
	BT_CMD_SET_NAME = 0xA1,//BT_CMD_SET_BT_LOCAL_NAME
	BT_CMD_GET_NAME  = 0xA2,//BT_CMD_GET_BT_LOCAL_NAME
	BT_CMD_REPORT_BT_LOCAL_NAME = 0xA3,

	BT_CMD_GET_VER  = 0xA4,//BT_CMD_GET_BT_VERSION
	BT_CMD_REPORT_BT_VERSION = 0xA5,
	
    BT_CMD_MAX,
    BT_CMD_SET_LANG,
    BT_CMD_GET_MAC,
    BT_CMD_GET_PAIRERED_DEVICE,
    BT_CMD_GET_PAIRED_NAME,
    BT_CMD_SET_BT_MODE,
    BT_CMD_GPIO_CONTROL,
    BT_CMD_PLAY_1K_AUDIO,
    BT_CMD_MUTE_CONTROL,
    BT_CMD_CANCEL_PAIRER,
    BT_CMD_CANCEL_ALL_PAIRER,
    BT_CMD_BT_VISIBLE,
    BT_CMD_GET_CONNECTED_DEVICE,
    BT_CMD_PREV,
    BT_CMD_PLAYPAUSE,
    BT_CMD_NEXT,
    BT_CMD_GET_PHONE_NUM,
    BT_CMD_GET_PLAYSTATUS,
    BT_CMD_GET_PHONESTATUS,
} AL_Enum_BT_CMD;

typedef enum{
	BT_RESP_OK = 0,
	BT_RESP_FAIL=0x1,
	BT_RESP_ERR_CMD=0x2,
	BT_RESP_ERR_CHECKSUM=0x3,
	BT_RESP_ERR_PARAM=0x4,
	BT_RESP_MAX,
} Al_Enum_BT_RespondStatus;

typedef enum {
     BT_MODE_OFF = 0x0,
     BT_MODE_ON = 0x1,
     BT_MODE_SEND = 0x2,
     BT_MODE_RECEIVE_BT = 0x3,
	 BT_MODE_RECEIVE_FM = 0x4,
	 BT_MODE_RECEIVE_LINEIN = 0x5,
	 BT_MODE_RECEIVE_USB = 0x6,
	 BT_MODE_MAX,
} Al_BTMode_t;

typedef enum {
    HB_STATUS_BT_WAIT_CONN = 0x1,
    HB_STATUS_BT_RECONNECT = 0x2,
    HB_STATUS_BT_CONNECTED = 0x3,
    HB_STATUS_BT_PAUSE = HB_STATUS_BT_CONNECTED,
    HB_STATUS_BT_PLAYING = 0x4,
    HB_STATUS_BT_PHONE_CALL = 0x5,
    HB_STATUS_BT_ONGOING_CALL = HB_STATUS_BT_PHONE_CALL,
    HB_STATUS_BT_INCOMING_CALL = 0x6,
    HB_STATUS_BT_OUTGOING_CALL = 0x7,
    HB_STATUS_BT_PHONE_OFF_CALL = 0x8,

} Al_Enum_BT_Status;

typedef enum {
    BT_AVRCP_OP_PLAY = 0x1,
    BT_AVRCP_OP_PAUSE = 0x2,
    BT_AVRCP_OP_STOP = 0x3,
    BT_AVRCP_OP_FORWARD = 0x4,
    BT_AVRCP_OP_BACKWARD = 0x5,
    BT_AVRCP_OP_VOLUME_UP = 0x6,
    BT_AVRCP_OP_VOLUME_DOWN = 0x7,
	BT_AVRCP_OP_MAX,

} Al_Enum_BT_AVRCP_OpCmd;

typedef enum {
    BT_SPP_EVENT_POWER = 0x1,
    BT_SPP_EVENT_MUTE = 0x2,
    BT_SPP_EVENT_1 = 0x3,
    BT_SPP_EVENT_2 = 0x4,
    BT_SPP_EVENT_3 = 0x5,
    BT_SPP_EVENT_4 = 0x6,
    BT_SPP_EVENT_5 = 0x7,
    BT_SPP_EVENT_6 = 0x8,
    BT_SPP_EVENT_7 = 0x9,
    BT_SPP_EVENT_8 = 0xa,
	BT_SPP_EVENT_9 = 0xb,
	BT_SPP_EVENT_DIGITAL = 0xc,
	BT_SPP_EVENT_POINT = 0xd,
	BT_SPP_EVENT_PLAY = 0xe,
	BT_SPP_EVENT_PAUSE = 0xf,
	BT_SPP_EVENT_PRE = 0x10,
	BT_SPP_EVENT_NEXT = 0x11,
	BT_SPP_EVENT_FR = 0x12,
	BT_SPP_EVENT_FF = 0x13,
	BT_SPP_EVENT_VOL_PLUS = 0x14,
	BT_SPP_EVENT_VOL_M = 0x15,
	BT_SPP_EVENT_UP = 0x16,
	BT_SPP_EVENT_DOWN = 0x17,
	BT_SPP_EVENT_LEFT = 0x18,
	BT_SPP_EVENT_RIGHT = 0x19,
	BT_SPP_EVENT_ENTER = 0x1a,
	BT_SPP_EVENT_MENU = 0x1b,
	BT_SPP_EVENT_SOURCE = 0x1C,
	BT_SPP_EVENT_CH_PLUS = 0x1d,
	BT_SPP_EVENT_RED = 0x1e,
	BT_SPP_EVENT_GREEN = 0x1f,
	BT_SPP_EVENT_YELLOW = 0x20,
	BT_SPP_EVENT_BLUE = 0x21,
	BT_SPP_EVENT_STOP = 0x22,
	BT_SPP_EVENT_0 = 0x23,
	BT_SPP_EVENT_CH_M = 0x24,
	BT_SPP_EVENT_CH_LIST = 0x25,
	BT_SPP_EVENT_SLEEP = 0x26,
	BT_SPP_EVENT_FREEZE = 0x27,
	BT_SPP_EVENT_INFO = 0x28,
	BT_SPP_EVENT_PIC_MOD = 0x29,
	BT_SPP_EVENT_SOUND_MOD = 0x2a,
	BT_SPP_EVENT_ASPECT = 0x2b,
	BT_SPP_EVENT_MTS = 0x2c,
	BT_SPP_EVENT_EPG = 0x2d,
	BT_SPP_EVENT_PIP_MENU = 0x2e,
	BT_SPP_EVENT_TVRADIO = 0x2f,
	BT_SPP_EVENT_TEXT = 0x30,
	BT_SPP_EVENT_SUBTITLE = 0x31,
	BT_SPP_EVENT_AD = 0x32,
	BT_SPP_EVENT_PLAY_PAUSE = 0x33,
	BT_SPP_EVENT_REC = 0x34,
	BT_SPP_EVENT_USB = 0x35,
	BT_SPP_EVENT_EXIT = 0x36,

	BT_SPP_EVENT_MAX,

} Al_Enum_BT_SPP_EventCmd;


typedef struct {
	UINT8 bytes[SIZE_OF_BDADDR];
} t_bdaddr;


/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/

typedef enum{
	BT_REQ_NONE = 0,
	BT_REQ_GET_NAME=0x1,
	BT_REQ_GET_MAC=0x2,
	BT_REQ_GET_PAIRED_NAME=0x4,
	BT_REQ_GET_PHONE_NUM=0x8,
	BT_REQ_GET_VER=0x10,
	BT_REQ_GET_PAIRED_DEVICE=0x20,
} Al_Enum_BT_Request;

typedef struct {
    al_uint8 len;
    al_uint8 cmd;
} Al_RBT_Cmd_Head;

typedef struct {
    al_uint8 FrameHead_L;
    al_uint8 FrameHead_H;
    al_uint8 FrameLen_L;
    al_uint8 FrameLen_H;
    al_uint8 FrameId;
    al_uint8 Cmd_id;
    al_uint8 Cmd_value_len;
    al_uint* Cmd_value;
    al_uint8 CheckSum_L;
    al_uint8 CheckSum_H;
} Al_PBT_Frame_St;


#endif

#define BT_INPUT_SIZE_MAX 128

#define GET_BT_SYS_MODE(x)	((x>>16)&0xf)
#define GET_BT_STATE(x)	(x&0xf)

#define HB_STATUS_MODE_STANDBY (0x100)
#define HB_STATUS_MODE_BT (0x200)

typedef struct BT_MessageBody_t_ {
#if defined(CONFIG_BT_RDA5856)||defined(CONFIG_BT_POL6556)
	al_uint32 dMessage;
	al_uint32 dParam;
	al_uint8 dMessageCmd;
	al_uint8 dCmdSize;
	al_uint8 *pdata;
#else
	al_uint32 dMessage;
	al_uint32 dParam;
#endif
} BT_MessageBody_t;

typedef enum {
    BT_MESSAGE_MODE = 0x1,
    BT_MESSAGE_CON_STATUS,
    BT_MESSAGE_PLAYER,
    BT_MESSAGE_PHONE,
    BT_MESSAGE_BT_NAME,
    BT_MESSAGE_PAIRED_NAME,
    BT_MESSAGE_MAC,
    BT_MESSAGE_VER,
    BT_MESSAGE_PHONE_NUM,
    BT_MESSAGE_ADC_VALUE,
    BT_MESSAGE_MAX,
} BT_Message_t;


#if defined(CONFIG_BT_RDA5856)||defined(CONFIG_BT_POL6556)
typedef int (*BT_ModCbk_pf) (BT_MessageBody_t message);
#else
typedef int (*BT_ModCbk_pf) (BT_Message_t message, al_uint32 arg);
#endif

typedef struct BT_ModualCfg_t_ {
    BT_ModCbk_pf pfCallBack;
} BT_ModualCfg_t;

/*//non-used
typedef enum {
    BT_ERR_NULL = 0,
    BT_ERR_CMD,
    BT_ERR_CHECKSUM,
    BT_ERR_PARAM,
    BT_ERR_FAIL,
    BT_ERR_MAX,
} Al_Enum_BT_ERRCode;
*/
typedef enum {
    BT_LANG_EN = 0,
    BT_LANG_CN,
    BT_LANG_MAX,
} Al_Enum_BT_Lang;

typedef struct {
    al_uint8 header[6];
    al_uint8 *data;
} Al_BT_Packet, *Al_BT_pPacket;

typedef struct {
    al_uint16 crc;
    al_uint8 cmd;
    al_uint8 len;
} Al_BT_Cmd_Head;

typedef struct {
    Al_BT_Cmd_Head head;
    al_uint32 result;
} Al_BT_Respond_Cmd_Head;

typedef struct {
    Al_BT_Cmd_Head head;
    al_uint8 name[BT_NAME_LEN_MAX];
} Al_BT_Name_Packet;

typedef struct {
    Al_BT_Cmd_Head head;
    al_uint8 localMac[6];
    al_uint8 reserve[2];
} Al_BT_Get_MAC_Packet;

typedef struct {
    Al_BT_Cmd_Head head;
    al_uint8 remoteMac[6];
    al_uint8 reserve[2];
} Al_BT_Test_Packet;

typedef struct {
    Al_BT_Cmd_Head head;
    al_uint8 number[20];
} Al_BT_Get_Phone_Num_Packet;

typedef struct {
    Al_BT_Cmd_Head head;
    al_uint8 ver[20];
} Al_BT_Get_Ver_Packet;

typedef struct {
    Al_BT_Cmd_Head head;
    al_uint32 lang;
} Al_BT_Set_Lang_Packet;

al_int Al_Bluetooth_Listener(void *argv);
al_int32 Al_Bluetooth_Set_Action(al_uint8 inCmd, al_uint8 * data, al_uint8 size);
al_int32 Al_Bluetooth_Get_Action(al_uint8 inCmd, void * data);
#if defined(CONFIG_BT_POL6556)
int Al_Bluetooth_calc_uartdata_checksum(al_uint8 *p_data, int len);
#endif
#if defined(CONFIG_BT_RDA5856)||defined(CONFIG_BT_POL6556)
al_int32 Al_Bluetooth_Set_BT_requestState(al_uint8 inCmd);
#endif
#if defined(CONFIG_BT_RDA5856)
int Al_Bluetooth_calc_uartdata_checksum(char *p_data, int len);
al_int8 Al_Bluetooth_HostCalcAKH(al_uint16 rec,al_uint16 *number,al_uint16 *akh);
#endif

#endif
