Index: yc_bt.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_bt.h	(revision 901)
+++ /YC3121_SDK/fw/sdk/yc_bt.h	(working copy)
@@ -71,6 +71,9 @@
 #define BIT_SET_GPIO_WAKEUPE              43
 #define BIT_SET_RTC_WAKEUP                44
 #define BIT_CREAT_BT_RECONNECT            45
+#define BIT_CANCEL_BT_RECONNECT           46
+#define BIT_LE_SET_VISIBILITY             47
+#define BIT_BT_SET_VISIBILITY             48
 /*CMD*/
 #define HCI_CMD_SET_BT_ADDR               0x00  //设置 BT3.0 地址
 #define HCI_CMD_SET_BLE_ADDR              0x01  //设置 BLE 地址
@@ -100,6 +103,7 @@
 #define HCI_CMD_SET_TX_POWER              0x42
 #define HCI_CMD_REJECT_JUSTWORK           0x49
 #define HCI_CMD_LE_SET_FIXED_PASSKEY      0x61
+#define HCI_CMD_ADD_SERVICE_CHARAC_UUID   0x75
 #define	HCI_CMD_DELETE_CUSTOMIZE_SERVICE  0x76
 #define	HCI_CMD_ADD_SERVICE_UUID          0x77
 #define	HCI_CMD_ADD_CHARACTERISTIC_UUID   0x78
@@ -113,6 +117,9 @@
 #define HCI_CMD_SEND_UDP_DATA             0x84 //发送UDP数据
 #define HCI_CMD_SEND_BIG_DATA             0x85 //发送TCP大包数据
 #define HCI_CMD_CREAT_BT_RECONNECT        0xB1 //BT开始回连
+#define HCI_CMD_CANCEL_BT_RECONNECT       0xB2 //BT取消回连
+#define HCI_CMD_LE_SET_VISIBILITY_REQ     0xB3 //LE设置可见
+#define HCI_CMD_BT_SET_VISIBILITY_REQ     0xB4 //BT设备可见
 #define HCI_CMD_SET_LPM_MODE              0xff //开关低功耗
 
 
@@ -155,6 +162,7 @@
 #define HCI_EVENT_HFP_CONNECTED           0xB2  /*HFP连接*/
 #define HCI_EVENT_HFP_START_DIALING       0xB3  /*HFP来电*/
 #define HCI_EVENT_HFP_STOP_DIALING        0xB4  /*HFP来电取消*/
+#define HCI_EVENT_BT_PIN_OR_KEY_MISSING   0xB5  /*BT配对信息删除*/
 
 /**
   * @brief  event code enum definition
@@ -190,7 +198,8 @@
     BT_RECONNECT_FAIL       =HCI_EVENT_BT_RECONNECT_FAIL,
     HFP_CONNECT             =HCI_EVENT_HFP_CONNECTED,
     HFP_START_DIALING       =HCI_EVENT_HFP_START_DIALING,
-    HFP_STOP_DIALING        =HCI_EVENT_HFP_STOP_DIALING
+    HFP_STOP_DIALING        =HCI_EVENT_HFP_STOP_DIALING,
+    BT_PIN_OR_KEY_MISSING   =HCI_EVENT_BT_PIN_OR_KEY_MISSING
 } BT_EventCodeEnum;
 
 /**
@@ -217,6 +226,29 @@
     int WriteIndex;
 } BT_BufTypeDef;
 
+
+// uuid
+typedef struct
+{
+    uint8_t size;
+    uint8_t uuid[16];
+}GATT_uuid;
+
+// attribute_data
+typedef struct
+{
+    uint8_t size;           /* Max size of the value */
+    uint8_t attribute[20];  /* Value of the attribute */
+}GATT_AttributeData;
+
+// attribute
+typedef struct
+{
+    GATT_uuid uuid;
+    GATT_AttributeData attribute_data;
+}GATT_Attribute;
+
+
 /**
   * @brief   Set the address of the bluetooth 3.0 device
   * @param  bt_addr: pointer to  address(6 bytes)
@@ -265,6 +297,22 @@
   */
 Boolean BT_SetVisibility(Boolean bt_discoverable, Boolean bt_connectability, Boolean ble_discoverable);
 
+/**
+  * @brief  Set visibility mode.
+  * @param  ble_discoverable:0--ble_discoverable OFF;1--ble_discoverable ON.
+  * @retval TRUE:set visibility success.
+  *         FALSE:set visibility failed
+  */
+Boolean BT_BleSetVisibility(Boolean ble_discoverable);
+
+/**
+  * @brief  Set visibility mode.
+  * @param  bt_discoverable: 0--bt_discoverable OFF;1--bt_discoverable ON.
+  *         bt_connectability:0--bt_connectability OFF;1--bt_connectability ON.
+  * @retval TRUE:set visibility success.
+  *         FALSE:set visibility failed
+  */
+Boolean BT_BtSetVisibility(Boolean bt_discoverable, Boolean bt_connectability);
 
 /**
   * @brief  Bt send spp(bt3.0) data
@@ -359,6 +407,14 @@
 Boolean BT_Creat_Reconnect(uint8_t *NvData, int len);
 
 /**
+  * @brief  bt cancel reconnect
+  * @param  none
+  * @retval TRUE:bt cancel reconnect success.
+  *         FALSE:bt cancel reconnect failed
+  */
+Boolean BT_Cancel_Reconnect(void);
+
+/**
   * @brief  Bt Enter Sleep mode(enter_hibernate)
   * @param  none
   * @retval TRUE:enter sleep mode success
@@ -571,6 +627,15 @@
 uint16_t BT_AddBleCharacteristic(uint8_t* ble_Characteristic_uuid, uint16_t service_Characteristic_payload_len);
 
 /**
+  * @brief  Ble add block gatt service
+  * @param  service_table: service table
+  *         service_index_max: service index_max_num
+  *         service_handle: service handle number
+  * @retval none
+  */
+uint16_t BT_AddBleBlockService(const GATT_Attribute *service_table, uint8_t service_index_max, uint16_t service_handle);
+
+/**
   * @brief  Read the received bluetooth data from receive buffer
   * @param  pbuf:the output buffer,255 bytes is enough
   *
@@ -747,5 +812,8 @@
   */
 Boolean BT_SetWakeupGpio(uint8_t islow_wakeup, uint32_t GPIO_Pin0_Pin31, uint16_t GPIO_Pin32_Pin47);
 
+
+
+
 #endif
 
Index: yc_bt.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_bt.c	(revision 901)
+++ /YC3121_SDK/fw/sdk/yc_bt.c	(working copy)
@@ -277,6 +277,54 @@
     return FALSE;
 }
 
+Boolean BT_BleSetVisibility(Boolean ble_discoverable)
+{
+    HCI_TypeDef msg;
+    uint8_t visibility_data = 0;
+    if (ble_discoverable == 1)
+        visibility_data = visibility_data | 0x04;
+
+    msg.opcode = HCI_CMD_LE_SET_VISIBILITY_REQ;
+    msg.DataLen = 0x01;
+    msg.p_data = &visibility_data;
+    BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_LE_SET_VISIBILITY);
+    SendCMD(&msg);
+    StartTick=SysTick_GetTick();
+    do
+    {
+        if(BT_BIT_GET(HCI_CMD_BIT_FLAG,BIT_LE_SET_VISIBILITY))
+        {
+            return TRUE;
+        }
+    }  while(!SysTick_IsTimeOut(StartTick,BTTIMEOUT));
+    return FALSE;
+}
+
+Boolean BT_BtSetVisibility(Boolean bt_discoverable, Boolean bt_connectability)
+{
+    HCI_TypeDef msg;
+    uint8_t visibility_data = 0;
+    if (bt_discoverable == 1)
+        visibility_data = visibility_data | 0x01;
+    if (bt_connectability == 1)
+        visibility_data = visibility_data | 0x02;
+
+    msg.opcode = HCI_CMD_BT_SET_VISIBILITY_REQ;
+    msg.DataLen = 0x01;
+    msg.p_data = &visibility_data;
+    BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_BT_SET_VISIBILITY);
+    SendCMD(&msg);
+    StartTick=SysTick_GetTick();
+    do
+    {
+        if(BT_BIT_GET(HCI_CMD_BIT_FLAG,BIT_BT_SET_VISIBILITY))
+        {
+            return TRUE;
+        }
+    }  while(!SysTick_IsTimeOut(StartTick,BTTIMEOUT));
+    return FALSE;
+}
+
 Boolean BT_SetBtName(uint8_t * bt_name, uint16_t name_len)
 {
     HCI_TypeDef msg;
@@ -518,6 +566,25 @@
     return FALSE;
 }
 
+Boolean BT_Cancel_Reconnect(void)
+{
+    HCI_TypeDef msg;
+    msg.opcode = HCI_CMD_CANCEL_BT_RECONNECT;
+    msg.DataLen = 0;
+    msg.p_data = NULL;
+    BT_BIT_CLEAR(HCI_CMD_BIT_FLAG, BIT_CANCEL_BT_RECONNECT);
+    SendCMD(&msg);
+    StartTick = SysTick_GetTick();
+    do
+    {
+        if (BT_BIT_GET(HCI_CMD_BIT_FLAG, BIT_CANCEL_BT_RECONNECT))
+        {
+            return TRUE;
+        }
+    }while (!SysTick_IsTimeOut(StartTick, BTTIMEOUT));
+    return FALSE;
+}
+
 Boolean BT_EnterSleepMode(void)
 {
     HCI_TypeDef msg;
@@ -891,6 +958,65 @@
     return 0x00;
 }
 
+#define BLESVCLOG 1
+uint16_t BT_AddBleBlockService(const GATT_Attribute *service_table, uint8_t service_index_max, uint16_t service_handle)
+{
+	uint8_t loop_assist_idx = 0, uuid_inner_idx = 0;
+
+	uint8_t ble_service[MAX_TCP_DATA_LEN] = {0};
+    uint8_t ble_inf_table[MAX_TCP_DATA_LEN] = {0};
+    uint16_t ble_inf_idx = 0;
+    #if BLESVCLOG
+    uint8_t temp_index = 0;
+    #endif
+
+	for (loop_assist_idx = 0; loop_assist_idx < service_index_max; loop_assist_idx++)
+	{
+        #if BLESVCLOG
+		temp_index = ble_inf_idx;
+        #endif
+		ble_inf_table[ble_inf_idx++] = service_handle & 0xff;
+		ble_inf_table[ble_inf_idx++] = service_handle >> 8;
+		service_handle++;
+
+		ble_inf_table[ble_inf_idx++] = service_table[loop_assist_idx].uuid.size;
+		for (uuid_inner_idx = 0; uuid_inner_idx < service_table[loop_assist_idx].uuid.size; uuid_inner_idx++)
+		{
+			ble_inf_table[ble_inf_idx++] = service_table[loop_assist_idx].uuid.uuid[uuid_inner_idx];
+		}
+
+		ble_inf_table[ble_inf_idx++] = service_table[loop_assist_idx].attribute_data.size;
+		for (uuid_inner_idx = 0; uuid_inner_idx < service_table[loop_assist_idx].attribute_data.size; uuid_inner_idx++)
+		{
+			ble_inf_table[ble_inf_idx++] = service_table[loop_assist_idx].attribute_data.attribute[uuid_inner_idx];
+		}
+        #if BLESVCLOG
+		for (int i = temp_index; i < ble_inf_idx; i++)
+			MyPrintf("%02x ", ble_inf_table[i]);
+		MyPrintf("\r\n");
+        #endif
+	}
+    #if BLESVCLOG
+	MyPrintf("size: %d \r\n", ble_inf_idx);
+    #endif
+
+    HCI_TypeDef msg;
+    msg.opcode = HCI_CMD_ADD_SERVICE_CHARAC_UUID;
+    msg.DataLen = ble_inf_idx;
+    msg.p_data  = ble_inf_table;
+    BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_ADD_UUID);
+    SendCMD(&msg);
+    StartTick=SysTick_GetTick();
+    do
+    {
+        if(BT_BIT_GET(HCI_CMD_BIT_FLAG,BIT_ADD_UUID))
+        {
+            return TRUE;
+        }
+    }  while(!SysTick_IsTimeOut(StartTick,BTTIMEOUT));
+    return FALSE;
+}
+
 Boolean BT_DnsReq( uint8_t *dns_data,int len)
 {
     uint8_t format_dns[DOMAIN_MAX_LEN];
@@ -1183,6 +1309,7 @@
             case HCI_EVENT_HFP_CONNECTED:
             case HCI_EVENT_HFP_START_DIALING:
             case HCI_EVENT_HFP_STOP_DIALING:
+            case HCI_EVENT_BT_PIN_OR_KEY_MISSING:
 
                 //		SaveData((uint8_t *)&hci_bt,hci_bt.DataLen+3);
                 SaveData((uint8_t*)&hci_bt,3);
@@ -1215,6 +1342,20 @@
                     }
                     break;
 
+                case HCI_CMD_LE_SET_VISIBILITY_REQ:
+                    if(!hci_bt.p_data[1])
+                    {
+                        BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_LE_SET_VISIBILITY);
+                    }
+                    break;
+
+                case HCI_CMD_BT_SET_VISIBILITY_REQ:
+                    if(!hci_bt.p_data[1])
+                    {
+                        BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_BT_SET_VISIBILITY);
+                    }
+                    break;
+
                 case HCI_CMD_SET_BT_NAME:
                     if(!hci_bt.p_data[1])
                     {
@@ -1437,6 +1578,20 @@
                         BT_BIT_SET(HCI_CMD_BIT_FLAG, BIT_CREAT_BT_RECONNECT);
                     }
                     break;
+
+                case HCI_CMD_CANCEL_BT_RECONNECT:
+                    if (!hci_bt.p_data[1])
+                    {
+                        BT_BIT_SET(HCI_CMD_BIT_FLAG, BIT_CANCEL_BT_RECONNECT);
+                    }
+                    break;
+                case HCI_CMD_ADD_SERVICE_CHARAC_UUID:
+                    if (!hci_bt.p_data[1])
+                    {
+                        BT_BIT_SET(HCI_CMD_BIT_FLAG, BIT_ADD_UUID);
+                    }
+                    break;
+
                 default:
 #ifdef BT_ERROR_LOG
                     MyPrintf("bt 06 cmd err\n");
@@ -1519,7 +1674,8 @@
             TempOpcode==PASSKEY||\
             TempOpcode==BT_RECONNECT_FAIL||\
             TempOpcode==HFP_CONNECT||\
-            TempOpcode==HFP_STOP_DIALING
+            TempOpcode==HFP_STOP_DIALING||\
+            TempOpcode==BT_PIN_OR_KEY_MISSING
 		)
     {
         SkipData(3);
