Index: yc_bt.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_bt.h	(revision 920)
+++ /YC3121_SDK/fw/sdk/yc_bt.h	(working copy)
@@ -74,6 +74,7 @@
 #define BIT_CANCEL_BT_RECONNECT           46
 #define BIT_LE_SET_VISIBILITY             47
 #define BIT_BT_SET_VISIBILITY             48
+#define BIT_LE_SEND_ENC_RSP               49
 /*CMD*/
 #define HCI_CMD_SET_BT_ADDR               0x00  //设置 BT3.0 地址
 #define HCI_CMD_SET_BLE_ADDR              0x01  //设置 BLE 地址
@@ -103,6 +104,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_LE_SEND_ENC_RSP           0x62
 #define HCI_CMD_ADD_SERVICE_CHARAC_UUID   0x75
 #define	HCI_CMD_DELETE_CUSTOMIZE_SERVICE  0x76
 #define	HCI_CMD_ADD_SERVICE_UUID          0x77
@@ -164,6 +166,14 @@
 #define HCI_EVENT_HFP_STOP_DIALING        0xB4  /*HFP来电取消*/
 #define HCI_EVENT_BT_PIN_OR_KEY_MISSING   0xB5  /*BT配对信息删除*/
 
+
+#define HCI_EVENT_LE_ENC_INFO             0xC0  /*BLE配对信息*/
+#define HCI_EVENT_LE_LL_START_ENC         0xC1  /*BLE LL收到start_enc_req*/
+#define HCI_EVENT_LE_LL_ENC_REQ           0xC2  /*BLE LL收到enc_req*/
+
+
+
+
 /**
   * @brief  event code enum definition
   */
@@ -199,7 +209,10 @@
     HFP_CONNECT             =HCI_EVENT_HFP_CONNECTED,
     HFP_START_DIALING       =HCI_EVENT_HFP_START_DIALING,
     HFP_STOP_DIALING        =HCI_EVENT_HFP_STOP_DIALING,
-    BT_PIN_OR_KEY_MISSING   =HCI_EVENT_BT_PIN_OR_KEY_MISSING
+    BT_PIN_OR_KEY_MISSING   =HCI_EVENT_BT_PIN_OR_KEY_MISSING,
+    BLE_ENC_INFO            =HCI_EVENT_LE_ENC_INFO,
+    BLE_START_ENC           =HCI_EVENT_LE_LL_START_ENC,
+    BLE_ENC_REQ             =HCI_EVENT_LE_LL_ENC_REQ
 } BT_EventCodeEnum;
 
 /**
@@ -217,6 +230,19 @@
   BT_PARING_MODE_CONFIRM,
 }BT_PARING_MODE_Def;
 
+/**
+  * @brief  PARING MODE
+  *         0x00:pincode
+  *         0x01:just work
+  *         0x02:passkey
+ **/
+typedef enum
+{
+  BLE_PARING_MODE_NONE = 0,
+  BLE_PARING_MODE_JUSTWORK,
+  BLE_PARING_MODE_PASSKEY,
+}BLE_PARING_MODE_Def;
+
 typedef struct
 {
     uint8_t* pBuf;
@@ -238,7 +264,7 @@
 typedef struct
 {
     uint8_t size;           /* Max size of the value */
-    uint8_t attribute[20];  /* Value of the attribute */
+    uint8_t attribute[255];  /* Value of the attribute */
 }GATT_AttributeData;
 
 // attribute
@@ -484,7 +510,7 @@
   * @retval TRUE:set ble paring success
   *         FALSE:set ble paring  failed
   */
-Boolean BT_SetLEParing(uint8_t mode);
+Boolean BT_SetLEParing(BLE_PARING_MODE_Def mode);
 
 /**
   * @brief    Send ble adv data
@@ -626,14 +652,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
+  *         service_length: service size
   * @retval none
   */
-uint16_t BT_AddBleBlockService(const GATT_Attribute *service_table, uint8_t service_index_max, uint16_t service_handle);
+uint16_t BT_AddBleBlockService(uint8_t *service_table, uint8_t service_length);
+
 
 /**
   * @brief  Read the received bluetooth data from receive buffer
@@ -812,5 +839,16 @@
   */
 Boolean BT_SetWakeupGpio(uint8_t islow_wakeup, uint32_t GPIO_Pin0_Pin31, uint16_t GPIO_Pin32_Pin47);
 
+
+
+/**
+  * @brief  Send ble ll_enc_rsp
+  * @param  none
+  * @retval TRUE:success
+  *         FALSE:fail
+  */
+Boolean BT_SendBleLLEncRsp(void);
+
+
 #endif
 
Index: yc_bt.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_bt.c	(revision 920)
+++ /YC3121_SDK/fw/sdk/yc_bt.c	(working copy)
@@ -3,7 +3,7 @@
 #include "yc_timer.h"
 #include "yc_ipc.h"
 
-#define BT_LOG	0
+#define     BT_LOG    0
 #define     BT_ERROR_LOG
 
 
@@ -716,7 +716,7 @@
     return FALSE;
 }
 
-Boolean BT_SetLEParing(uint8_t mode)
+Boolean BT_SetLEParing(BLE_PARING_MODE_Def mode)
 {
     HCI_TypeDef msg;
     msg.opcode = HCI_CMD_LE_SET_PAIRING;
@@ -878,6 +878,27 @@
     return FALSE;
 }
 
+
+Boolean BT_SendBleLLEncRsp(void)
+{
+    HCI_TypeDef msg;
+    msg.opcode = HCI_CMD_LE_SEND_ENC_RSP;
+    msg.DataLen = 0x00;
+    msg.p_data = NULL;
+    BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_LE_SEND_ENC_RSP);
+    SendCMD(&msg);
+    StartTick=SysTick_GetTick();
+    do
+    {
+        if(BT_BIT_GET(HCI_CMD_BIT_FLAG,BIT_LE_SEND_ENC_RSP))
+        {
+            return TRUE;
+        }
+    } while(!SysTick_IsTimeOut(StartTick,BTTIMEOUT));
+    return FALSE;
+}
+
+
 Boolean BT_SetCOD(uint8_t * bt_cod)
 {
     HCI_TypeDef msg;
@@ -958,52 +979,13 @@
     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
 
+uint16_t BT_AddBleBlockService(uint8_t *service_table, uint8_t service_length)
+{
     HCI_TypeDef msg;
     msg.opcode = HCI_CMD_ADD_SERVICE_CHARAC_UUID;
-    msg.DataLen = ble_inf_idx;
-    msg.p_data  = ble_inf_table;
+    msg.DataLen = service_length;
+    msg.p_data  = service_table;
     BT_BIT_CLEAR(HCI_CMD_BIT_FLAG,BIT_ADD_UUID);
     SendCMD(&msg);
     StartTick=SysTick_GetTick();
@@ -1017,6 +999,9 @@
     return FALSE;
 }
 
+
+
+
 Boolean BT_DnsReq( uint8_t *dns_data,int len)
 {
     uint8_t format_dns[DOMAIN_MAX_LEN];
@@ -1263,7 +1248,7 @@
                 break;
 
             case HCI_EVENT_BLE_DATA_RECEIVED:
-//                  SaveData((uint8_t *)&hci_bt,hci_bt.DataLen+3);
+//              SaveData((uint8_t *)&hci_bt,hci_bt.DataLen+3);
                 SaveData((uint8_t*)&hci_bt,3);
                 SaveData(hci_bt.p_data,hci_bt.DataLen);
                 PacketNum++;
@@ -1310,8 +1295,11 @@
             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);
+            case HCI_EVENT_LE_ENC_INFO:
+            case HCI_EVENT_LE_LL_START_ENC:
+            case HCI_EVENT_LE_LL_ENC_REQ:
+            
+                //		SaveData((uint8_t *)&hci_bt,hci_bt.DataLen+3);
                 SaveData((uint8_t*)&hci_bt,3);
                 SaveData(hci_bt.p_data,hci_bt.DataLen);
                 PacketNum++;
@@ -1592,6 +1580,13 @@
                     }
                     break;
 
+                case HCI_CMD_LE_SEND_ENC_RSP:
+                    if(!hci_bt.p_data[1])
+                    {
+                        BT_BIT_SET(HCI_CMD_BIT_FLAG,BIT_LE_SEND_ENC_RSP);
+                    }
+                    break;
+                    
                 default:
 #ifdef BT_ERROR_LOG
                     MyPrintf("bt 06 cmd err\n");
@@ -1675,8 +1670,10 @@
             TempOpcode==BT_RECONNECT_FAIL||\
             TempOpcode==HFP_CONNECT||\
             TempOpcode==HFP_STOP_DIALING||\
-            TempOpcode==BT_PIN_OR_KEY_MISSING
-        )
+            TempOpcode==BT_PIN_OR_KEY_MISSING||\
+            TempOpcode==BLE_START_ENC||\
+            TempOpcode==BLE_ENC_REQ
+      )
     {
         SkipData(3);
     }
