// binary representation
// attribute size in bytes (16), flags(16), handle (16), uuid (16/128), value(...)

#ifndef _LE_SMARTBOX_MODULE_H
#define _LE_SMARTBOX_MODULE_H

#include <stdint.h>
#include "bt_common.h"
#include "ble_user.h"
#include "btstack/btstack_typedef.h"

#if TCFG_PAY_ALIOS_ENABLE
#define  UPAY_ONE_PROFILE          1  //同一个pofile
#else
#define  UPAY_ONE_PROFILE          0
#endif

#if (TCFG_BLE_DEMO_SELECT == DEF_BLE_DEMO_RCSP_DEMO)
//
// gatt profile include file, generated by jieli gatt_inc_generator.exe
//
static const uint8_t profile_data[] = {
    //////////////////////////////////////////////////////
    //
    // 0x0001 PRIMARY_SERVICE    1800
    //
    //////////////////////////////////////////////////////
    0x0a, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x28, 0x00, 0x18,

    /* CHARACTERISTIC,    2a00, READ | WRITE | DYNAMIC, */
    // 0x0002 CHARACTERISTIC 2a00 READ | WRITE | DYNAMIC
    0x0d, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, 0x28, 0x0a, 0x03, 0x00, 0x00, 0x2a,
    // 0x0003 VALUE 2a00 READ | WRITE | DYNAMIC
    0x08, 0x00, 0x0a, 0x01, 0x03, 0x00, 0x00, 0x2a,

    //////////////////////////////////////////////////////
    //
    // 0x0004 PRIMARY_SERVICE    1801
    //
    //////////////////////////////////////////////////////
    0x0a, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x28, 0x01, 0x18,

    /* CHARACTERISTIC,    2a05, INDICATE, */
    // 0x0005 CHARACTERISTIC 2a05 INDICATE
    0x0d, 0x00, 0x02, 0x00, 0x05, 0x00, 0x03, 0x28, 0x20, 0x06, 0x00, 0x05, 0x2a,
    // 0x0006 VALUE 2a05 INDICATE
    0x08, 0x00, 0x20, 0x00, 0x06, 0x00, 0x05, 0x2a,
    // 0x0007 CLIENT_CHARACTERISTIC_CONFIGURATION
    0x0a, 0x00, 0x0a, 0x01, 0x07, 0x00, 0x02, 0x29, 0x00, 0x00,

    //////////////////////////////////////////////////////
    //
    // 0x0004 PRIMARY_SERVICE  ae00
    //
    //////////////////////////////////////////////////////
    0x0a, 0x00, 0x02, 0x00, 0x08, 0x00, 0x00, 0x28, 0x00, 0xae,

    /* CHARACTERISTIC,  ae01, WRITE_WITHOUT_RESPONSE | DYNAMIC, */
    // 0x0009 CHARACTERISTIC ae01 WRITE_WITHOUT_RESPONSE | DYNAMIC
    0x0d, 0x00, 0x02, 0x00, 0x09, 0x00, 0x03, 0x28, 0x04, 0x0a, 0x00, 0x01, 0xae,
    // 0x000a VALUE ae01 WRITE_WITHOUT_RESPONSE | DYNAMIC
    0x08, 0x00, 0x04, 0x01, 0x0a, 0x00, 0x01, 0xae,

    /* CHARACTERISTIC,  ae02, NOTIFY, */
    // 0x000b CHARACTERISTIC ae02 NOTIFY
    0x0d, 0x00, 0x02, 0x00, 0x0b, 0x00, 0x03, 0x28, 0x10, 0x0c, 0x00, 0x02, 0xae,
    // 0x000c VALUE ae02 NOTIFY
    0x08, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x02, 0xae,
    // 0x000d CLIENT_CHARACTERISTIC_CONFIGURATION
    0x0a, 0x00, 0x0a, 0x01, 0x0d, 0x00, 0x02, 0x29, 0x00, 0x00,

    //////////////////////////////////////////////////////
    //
    // 0x000e PRIMARY_SERVICE  fee7
    //
    //////////////////////////////////////////////////////
    0x0a, 0x00, 0x02, 0x00, 0x0e, 0x00, 0x00, 0x28, 0xe7, 0xfe,

    /* CHARACTERISTIC,  fec9, READ | DYNAMIC, */
    // 0x000f CHARACTERISTIC fec9 READ | DYNAMIC
    0x0d, 0x00, 0x02, 0x00, 0x0f, 0x00, 0x03, 0x28, 0x02, 0x10, 0x00, 0xc9, 0xfe,
    // 0x0010 VALUE fec9 READ | DYNAMIC
    0x08, 0x00, 0x02, 0x01, 0x10, 0x00, 0xc9, 0xfe,

    /* CHARACTERISTIC,  fea1, READ | NOTIFY | DYNAMIC, */
    // 0x0011 CHARACTERISTIC fea1 READ | NOTIFY | DYNAMIC
    0x0d, 0x00, 0x02, 0x00, 0x11, 0x00, 0x03, 0x28, 0x12, 0x12, 0x00, 0xa1, 0xfe,
    // 0x0012 VALUE fea1 READ | NOTIFY | DYNAMIC
    0x08, 0x00, 0x12, 0x01, 0x12, 0x00, 0xa1, 0xfe,
    // 0x0013 CLIENT_CHARACTERISTIC_CONFIGURATION
    0x0a, 0x00, 0x0a, 0x01, 0x13, 0x00, 0x02, 0x29, 0x00, 0x00,

#if UPAY_ONE_PROFILE
//////////////////////////////////////////////////////
    //
    // 0x0030 PRIMARY_SERVICE    3802
    //
    //////////////////////////////////////////////////////
    0x0a, 0x00, 0x02, 0x00, 0x30, 0x00, 0x00, 0x28, 0x02, 0x38,

    /* CHARACTERISTIC,    4a02, READ | WRITE | NOTIFY | DYNAMIC, */
    // 0x0031 CHARACTERISTIC 4a02 READ | WRITE | NOTIFY | DYNAMIC
    0x0d, 0x00, 0x02, 0x00, 0x31, 0x00, 0x03, 0x28, 0x1a, 0x32, 0x00, 0x02, 0x4a,
    // 0x0032 VALUE 4a02 READ | WRITE | NOTIFY | DYNAMIC
    0x08, 0x00, 0x1a, 0x01, 0x32, 0x00, 0x02, 0x4a,
    // 0x0033 CLIENT_CHARACTERISTIC_CONFIGURATION
    0x0a, 0x00, 0x0a, 0x01, 0x33, 0x00, 0x02, 0x29, 0x00, 0x00,
    /*0x0034 CHARACTERISTIC_USER_DESCRIPTION,READ | WRITE |DYNAMIC，*/
    0x08, 0x00, 0x0a, 0x01, 0x34, 0x00, 0x02, 0x4b,
#endif

    // END
    0x00, 0x00,
};
//
// characteristics <--> handles
//
#define ATT_CHARACTERISTIC_2a00_01_VALUE_HANDLE 0x0003
#define ATT_CHARACTERISTIC_2a00_01_VALUE_HANDLE 0x0003
#define ATT_CHARACTERISTIC_2a05_01_VALUE_HANDLE 0x0006
#define ATT_CHARACTERISTIC_2a05_01_CLIENT_CONFIGURATION_HANDLE 0x0007

#define ATT_CHARACTERISTIC_ae01_01_VALUE_HANDLE 0x000a
#define ATT_CHARACTERISTIC_ae02_01_VALUE_HANDLE 0x000c
#define ATT_CHARACTERISTIC_ae02_01_CLIENT_CONFIGURATION_HANDLE 0x000d
// #define ATT_CHARACTERISTIC_ae01_01_VALUE_HANDLE 0x0082
// #define ATT_CHARACTERISTIC_ae02_01_VALUE_HANDLE 0x0084
// #define ATT_CHARACTERISTIC_ae02_01_CLIENT_CONFIGURATION_HANDLE 0x0085
// #define ATT_CHARACTERISTIC_2a00_01_VALUE_HANDLE 0x0003
// #define ATT_CHARACTERISTIC_ae01_01_VALUE_HANDLE 0x0006
// #define ATT_CHARACTERISTIC_ae02_01_VALUE_HANDLE 0x0008
// #define ATT_CHARACTERISTIC_ae02_01_CLIENT_CONFIGURATION_HANDLE 0x0009
// #define ATT_CHARACTERISTIC_ae03_01_VALUE_HANDLE 0x000b
// #define ATT_CHARACTERISTIC_ae04_01_VALUE_HANDLE 0x000d
// #define ATT_CHARACTERISTIC_ae04_01_CLIENT_CONFIGURATION_HANDLE 0x000e
// #define ATT_CHARACTERISTIC_ae05_01_VALUE_HANDLE 0x0010
// #define ATT_CHARACTERISTIC_ae05_01_CLIENT_CONFIGURATION_HANDLE 0x0011
// #define ATT_CHARACTERISTIC_ae10_01_VALUE_HANDLE 0x0013
#define ATT_CHARACTERISTIC_fec9_01_VALUE_HANDLE 0x0010
#define ATT_CHARACTERISTIC_fea1_01_VALUE_HANDLE 0x0012
#define ATT_CHARACTERISTIC_fea1_01_CLIENT_CONFIGURATION_HANDLE 0x0013


#if TCFG_PAY_ALIOS_ENABLE

#if UPAY_ONE_PROFILE == 0
static const uint8_t profile_data_upay[] = {
    //////////////////////////////////////////////////////
    //
    // 0x0001 PRIMARY_SERVICE    1800
    //
    //////////////////////////////////////////////////////
    0x0a, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x28, 0x00, 0x18,

    /* CHARACTERISTIC,    2a00, READ | WRITE | DYNAMIC, */
    // 0x0002 CHARACTERISTIC 2a00 READ | WRITE | DYNAMIC
    0x0d, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, 0x28, 0x0a, 0x03, 0x00, 0x00, 0x2a,
    // 0x0003 VALUE 2a00 READ | WRITE | DYNAMIC
    0x08, 0x00, 0x0a, 0x01, 0x03, 0x00, 0x00, 0x2a,

    //////////////////////////////////////////////////////
    //
    // 0x0004 PRIMARY_SERVICE    1801
    //
    //////////////////////////////////////////////////////
    0x0a, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x28, 0x01, 0x18,

    /* CHARACTERISTIC,    2a05, INDICATE, */
    // 0x0005 CHARACTERISTIC 2a05 INDICATE
    0x0d, 0x00, 0x02, 0x00, 0x05, 0x00, 0x03, 0x28, 0x20, 0x06, 0x00, 0x05, 0x2a,
    // 0x0006 VALUE 2a05 INDICATE
    0x08, 0x00, 0x20, 0x00, 0x06, 0x00, 0x05, 0x2a,
    // 0x0007 CLIENT_CHARACTERISTIC_CONFIGURATION
    0x0a, 0x00, 0x0a, 0x01, 0x07, 0x00, 0x02, 0x29, 0x00, 0x00,


    //////////////////////////////////////////////////////
    //
    // 0x0030 PRIMARY_SERVICE    3802
    //
    //////////////////////////////////////////////////////
    0x0a, 0x00, 0x02, 0x00, 0x30, 0x00, 0x00, 0x28, 0x02, 0x38,

    /* CHARACTERISTIC,    4a02, READ | WRITE | NOTIFY | DYNAMIC, */
    // 0x0031 CHARACTERISTIC 4a02 READ | WRITE | NOTIFY | DYNAMIC
    0x0d, 0x00, 0x02, 0x00, 0x31, 0x00, 0x03, 0x28, 0x1a, 0x32, 0x00, 0x02, 0x4a,
    // 0x0032 VALUE 4a02 READ | WRITE | NOTIFY | DYNAMIC
    0x08, 0x00, 0x1a, 0x01, 0x32, 0x00, 0x02, 0x4a,
    // 0x0033 CLIENT_CHARACTERISTIC_CONFIGURATION
    0x0a, 0x00, 0x0a, 0x01, 0x33, 0x00, 0x02, 0x29, 0x00, 0x00,
    /*0x0034 CHARACTERISTIC_USER_DESCRIPTION,READ | WRITE |DYNAMIC，*/
    0x08, 0x00, 0x0a, 0x01, 0x34, 0x00, 0x02, 0x4b,

    // END
    0x00, 0x00,
};

#endif

//
// characteristics <--> handles
//
#define ATT_CHARACTERISTIC_4a02_01_VALUE_HANDLE 0x0032
#define ATT_CHARACTERISTIC_4a02_01_CLIENT_CONFIGURATION_HANDLE 0x0033
#define ATT_CHARACTERISTIC_4a02_01_UNKOWN_DESCRIPTION_HANDLE 0x0034
#endif


#if UNISOC_ESIM_TEST
#define ATT_CHARACTERISTIC_6e400002_b5a3_f393_e0a9_e50e24dcca9e_01_VALUE_HANDLE 0x0015
#define ATT_CHARACTERISTIC_6e400003_b5a3_f393_e0a9_e50e24dcca9e_01_VALUE_HANDLE 0x0016
#define ATT_CHARACTERISTIC_6e400003_b5a3_f393_e0a9_e50e24dcca9e_01_CLIENT_CONFIGURATION_HANDLE 0x0017
#endif // UNISOC_ESIM_TEST

//===========================================================================================

#define JL_OPCODE_SET_ADV 							    0xC0
#define	JL_OPCODE_GET_ADV  								0xC1
#define JL_OPCODE_ADV_DEVICE_NOTIFY 					0xC2
#define JL_OPCODE_ADV_NOTIFY_SETTING 					0xC3
#define JL_OPCODE_ADV_DEVICE_REQUEST					0xC4

#define ATTR_TYPE_BAT_VALUE  			(0)
#define ATTR_TYPE_EDR_NAME   			(1)
#define ATTR_TYPE_KEY_SETTING  			(2)
#define ATTR_TYPE_LED_SETTING  			(3)
#define ATTR_TYPE_MIC_SETTING  			(4)
#define ATTR_TYPE_WORK_MODE  			(5)
#define ATTR_TYPE_PRODUCT_MESSAGE  		(6)
#define ATTR_TYPE_TIME_STAMP			(7)
#define ATTR_TYPE_EQ_SETTING			(8)
#define ATTR_TYPE_HIGH_LOW_VOL			(9)
#define ATTR_TYPE_VOL_SETTING			(10)
#define ATTR_TYPE_MISC_SETTING			(11)
#define ATTR_TYPE_COLOR_LED_SETTING 	(12)
#define ATTR_TYPE_KARAOKE_EQ_SETTING	(13)

#ifndef JL_SMART_BOX_CUSTOM_APP_EN
//rcsp功能模块使能
#define RCSP_ADV_NAME_SET_ENABLE        1
#define RCSP_ADV_KEY_SET_ENABLE         0
#define RCSP_ADV_LED_SET_ENABLE         1
#define RCSP_ADV_MIC_SET_ENABLE         0
#define RCSP_ADV_WORK_SET_ENABLE        0
#define RCSP_ADV_EQ_SET_ENABLE          1
#define RCSP_ADV_MUSIC_INFO_ENABLE      1
#define RCSP_ADV_HIGH_LOW_SET			1
#define RCSP_ADV_PRODUCT_MSG_ENABLE     1
#define RCSP_ADV_FIND_DEVICE_ENABLE     1
#define RCSP_ADV_COLOR_LED_SET_ENABLE   1
#define RCSP_ADV_KARAOKE_SET_ENABLE		1
#define RCSP_ADV_KARAOKE_EQ_SET_ENABLE	1
#endif

enum {
    BT_ADV_ENABLE,
    BT_ADV_DISABLE,
    BT_ADV_SET_EDR_CON_FLAG,
    BT_ADV_SET_BAT_CHARGE_L,
    BT_ADV_SET_BAT_CHARGE_R,
    BT_ADV_SET_BAT_CHARGE_C,
    BT_ADV_SET_BAT_PERCENT_L,
    BT_ADV_SET_BAT_PERCENT_R,
    BT_ADV_SET_BAT_PERCENT_C,
    BT_ADV_SET_NOTIFY_EN,
};

// BT_ADV_SET_EDR_CON_FLAG
#define SECNE_DISMISS			(0x00)
#define SECNE_UNCONNECTED		(0x01)
#define SECNE_CONNECTED			(0x02)
#define SECNE_CONNECTING		(0x03)
#define SECNE_CONNECTINLESS		(0x04)

enum {
    TWS_ADV_SEQ_CHANGE = 0,
    TWS_VERSON_INFO,
};

extern int  bt_ble_adv_ioctl(u32 cmd, u32 priv, u8 mode);
extern void bt_adv_seq_change(void);
void ble_app_disconnect(void);
void bt_ble_rcsp_adv_enable(void);
void bt_ble_rcsp_adv_disable(void);
void ble_profile_again_init(u8 enable);
u8 get_ble_adv_notify(void);
void set_ble_adv_notify(u8 en);
u8 get_connect_flag(void);
void set_connect_flag(u8 value);
hci_con_handle_t smartbox_get_con_handle(void);
int smartbox_set_adv_enable(void *priv, u32 en);
void ble_module_enable(u8 en);
ble_state_e smartbox_get_ble_work_state(void);
extern void le_smartbox_bt_ble_adv_enable(u8 enable);
int ble_dongle_send_custom_data(u8 *data, u16 len);

void notify_update_connect_parameter(u8 table_index);
#endif
#endif
