فهرست منبع

add the MESH and other example demo

supperthomas 4 سال پیش
والد
کامیت
707c3bcb46

+ 218 - 0
Kconfig

@@ -0,0 +1,218 @@
+
+# Kconfig file for package BTSTACK
+menuconfig PKG_USING_BTSTACK
+    select RT_USING_LIBC
+    select RT_USING_PTHREADS
+    select RT_USING_POSIX
+    select RT_USING_POSIX_TERMIOS
+    bool "BTSTACK: embedded btstack"
+    default n
+
+if PKG_USING_BTSTACK
+    config _GNU_SOURCE
+    int 
+    default 1
+    config HAVE_DIRENT_STRUCTURE
+    int 
+    default 1
+    config HAVE_DIR_STRUCTURE
+    int 
+    default 1
+    
+    config PKG_BTSTACK_PATH
+        string
+        default "/packages/iot/btstack"
+        
+menu "Bluetooth Role support"
+
+    config PKG_BTSTACK_ROLE_PERIPHERAL
+    bool "Peripheral Role support"
+    select PKG_BTSTACK_ROLE_BROADCASTER
+    default y
+    help
+        Select this for LE Peripheral role support.
+
+    config PKG_BTSTACK_ROLE_CENTRAL
+    bool "Central Role support"
+    select PKG_BTSTACK_ROLE_OBSERVER
+    default n
+    help
+        Select this for LE Central role support.
+
+    config PKG_BTSTACK_ROLE_BROADCASTER
+    bool "Broadcaster Role support"
+    default y
+    help
+        Select this for LE Broadcaster role support.
+
+    config PKG_BTSTACK_ROLE_OBSERVER
+    bool "Observer Role support"
+    help
+        Select this for LE Observer role support.
+
+endmenu
+
+
+menu "Bluetooth Mesh support"
+    config PKG_BTSTACK_MESH
+    bool "Bluetooth Mesh support"
+    default n
+    depends on PKG_BTSTACK_ROLE_BROADCASTER && PKG_BTSTACK_ROLE_OBSERVER
+    help
+        This option enables Bluetooth Mesh support. The specific
+        features that are available may depend on other features
+        that have been enabled in the stack, such as GATT support.
+endmenu
+
+menu "Bluetooth SMP support"
+    config PKG_BTSTACK_SMP
+    bool "Bluetooth SMP support"
+    default n
+    help
+        This option enables Bluetooth Mesh support. The specific
+        features that are available may depend on other features
+        that have been enabled in the stack, such as GATT support.
+        
+
+        
+endmenu
+
+# example
+choice
+    prompt "Bluetooth Samples"
+    default PKG_BTSTACK_SAMPLE_LE_COUNTER
+    help
+        select the BTSTACK samples
+        
+    config PKG_BTSTACK_SAMPLE_DISABLE
+    bool "Not enable sample"
+         
+    config PKG_BTSTACK_SAMPLE_LE_BLUFI_SERVER
+    bool "[LE_SRV] rtthread blufi server"
+    select BTSTACK_ROLE_PERIPHERAL
+    
+
+    config PKG_BTSTACK_SAMPLE_LE_COUNTER
+    bool "[LE_SRV] BLE peripheral le counter"
+    select BTSTACK_ROLE_PERIPHERAL
+    
+    config PKG_BTSTACK_SAMPLE_LE_DATA_CHANNEL_SERVER
+    bool "[LE_SRV] BLE peripheral le data channel server"
+    select BTSTACK_ROLE_PERIPHERAL
+
+    
+    config PKG_BTSTACK_SAMPLE_LE_STREAMER
+    bool "[LE_SRV] Nordic le streamer server"
+    select BTSTACK_ROLE_PERIPHERAL  
+    
+    config PKG_BTSTACK_SAMPLE_NORDIC_LE_COUNTER
+    bool "[LE_SRV] Nordic le counter server"
+    select BTSTACK_ROLE_PERIPHERAL 
+
+    config PKG_BTSTACK_SAMPLE_ATT_DELAYED_RESPONSE
+    bool "[LE_SRV] gatt dealyed response"
+    select BTSTACK_ROLE_PERIPHERAL  
+    
+    config PKG_BTSTACK_SAMPLE_SM_PAIRING_PERIPHERAL
+    bool "[LE_SMP_SRV] smp peripherals"
+    select BTSTACK_ROLE_PERIPHERAL      
+    
+    config PKG_BTSTACK_SAMPLE_GATT_STREAMER_PERIPHERAL
+    bool "[LE_SRV] gatt streamer peipheral"
+    select BTSTACK_ROLE_PERIPHERAL   
+    
+    config PKG_BTSTACK_SAMPLE_ANCS_CLIENT_DEMO
+    bool "[LE_SRV] ancs_client_demo"
+    select BTSTACK_ROLE_PERIPHERAL 
+    
+    config PKG_BTSTACK_SAMPLE_MESH_DEMO
+    bool "[MESH_NODE] MESH DEMO"
+    select BTSTACK_ROLE_PERIPHERAL  
+    select PKG_BTSTACK_MESH
+    select PKG_BTSTACK_SMP
+ 
+
+    config PKG_BTSTACK_SAMPLE_TMALL_MESH_DEMO
+    bool "[MESH_NODE] MESH DEMO ON TMALL ALIGEN"
+    select BTSTACK_ROLE_PERIPHERAL  
+    select PKG_BTSTACK_MESH
+    select PKG_BTSTACK_SMP 
+    
+endchoice
+
+# btstack config
+
+if PKG_BTSTACK_SMP
+    config ENABLE_ECC_P256
+    bool 
+    default y
+endif
+
+if PKG_BTSTACK_MESH
+    config ENABLE_MESH
+    bool 
+    default y
+
+    config ENABLE_MESH_ADV_BEARER
+    bool 
+    default y
+    
+    config ENABLE_MESH_GATT_BEARER
+    bool 
+    default y   
+    
+    config ENABLE_MESH_PB_ADV
+    bool 
+    default y   
+
+    config ENABLE_MESH_PB_GATT
+    bool 
+    default y   
+    
+    config ENABLE_MESH_PROXY_SERVER
+    bool 
+    default y   
+    
+    config ENABLE_MESH_PROVISIONER
+    bool 
+    default y 
+  
+
+    config MAX_NR_MESH_TRANSPORT_KEYS
+    int 
+    default 16  
+    
+    config MAX_NR_MESH_VIRTUAL_ADDRESSES
+    int 
+    default 16 
+    
+    config MAX_NR_MESH_SUBNETS
+    int 
+    default 2  
+
+    config MAX_NR_MESH_NETWORK_KEYS
+    int 
+    default 3      
+    
+endif
+
+    choice
+        prompt "Version"
+        default PKG_USING_BTSTACK_LATEST_VERSION
+        help
+            Select the package version
+
+        config PKG_USING_BTSTACK_V001
+            bool "v0.0.1"
+
+        config PKG_USING_BTSTACK_LATEST_VERSION
+            bool "latest"
+    endchoice
+          
+    config PKG_BTSTACK_VER
+       string
+       default "v0.0.1"    if PKG_USING_BTSTACK_V001
+       default "latest"    if PKG_USING_BTSTACK_LATEST_VERSION
+
+endif
+

+ 127 - 4
SConscript

@@ -11,8 +11,6 @@ platform/posix/btstack_uart_block_posix.c
 platform/posix/btstack_tlv_posix.c
 platform/posix/btstack_run_loop_posix.c
 
-rtt_adapter/rtt_btstack_gatt_blufi.c
-
 chipset/bcm/btstack_chipset_bcm.c
 chipset/bcm/btstack_chipset_bcm_download_firmware.c
 
@@ -45,17 +43,142 @@ src/ble/gatt-service/battery_service_server.c
 
 port/posix-h4-bcm/btstack_main.c
 rtt_adapter/rtt_btstack_adapter.c
+
+src/btstack_crypto.c
 ''')
 
 
 path =  [cwd]
 path += [cwd + '/src']
-path += [cwd + '/example/inc']
+
 path += [cwd + '/platform/posix']
 path += [cwd + '/chipset/bcm']
 path += [cwd + '/port/posix-h4-bcm']
 path += [cwd + '/rtt_adapter']
+path += [cwd + '/src/ble/gatt-service']
+
+#MESH
+if GetDepend(['PKG_BTSTACK_MESH']):
+     path += [cwd + '/src/mesh']
+     src += Split("""
+			src/mesh/adv_bearer.c
+			src/mesh/mesh_access.c
+			src/mesh/beacon.c
+			src/mesh/gatt_bearer.c
+			src/mesh/mesh.c
+			src/mesh/mesh_crypto.c
+			src/mesh/mesh_configuration_client.c
+			src/mesh/mesh_configuration_server.c
+			src/mesh/mesh_foundation.c
+			src/mesh/mesh_generic_default_transition_time_client.c
+			src/mesh/mesh_generic_default_transition_time_server.c
+			src/mesh/mesh_generic_level_client.c
+			src/mesh/mesh_generic_level_server.c
+			src/mesh/mesh_generic_on_off_client.c
+			src/mesh/mesh_generic_on_off_server.c
+			src/mesh/mesh_health_server.c
+			src/mesh/mesh_iv_index_seq_number.c
+			src/mesh/mesh_keys.c
+			src/mesh/mesh_lower_transport.c
+			src/mesh/mesh_network.c
+			src/mesh/mesh_peer.c
+			src/mesh/mesh_proxy.c
+			src/mesh/mesh_node.c
+			src/mesh/mesh_upper_transport.c
+			src/mesh/mesh_virtual_addresses.c
+			src/mesh/pb_adv.c
+			src/mesh/pb_gatt.c
+			src/mesh/provisioning.c
+			src/mesh/provisioning_device.c
+			src/mesh/provisioning_provisioner.c
+			src/ble/gatt-service/mesh_provisioning_service_server.c
+			src/ble/gatt-service/mesh_proxy_service_server.c
+        """)  
+
+
+
+
+
+#example
+
+if GetDepend('PKG_BTSTACK_SAMPLE_DISABLE') == False:
+     path += [cwd + '/example/inc']
+
+
+if GetDepend(['PKG_BTSTACK_SAMPLE_LE_COUNTER']):
+     example_src = Split("""
+        example/gatt_counter.c
+        """)
+        
+if GetDepend(['PKG_BTSTACK_SAMPLE_LE_DATA_CHANNEL_SERVER']):
+     example_src = Split("""
+        example/le_data_channel_server.c
+        """)
+        
+if GetDepend(['PKG_BTSTACK_SAMPLE_LE_DATA_CHANNEL_SERVER']):
+     example_src = Split("""
+        example/le_data_channel_server.c
+        """)
+        
+if GetDepend(['PKG_BTSTACK_SAMPLE_LE_BLUFI_SERVER']):
+     example_src = Split("""
+        rtt_adapter/rtt_btstack_gatt_blufi.c
+        """)
+        
+if GetDepend(['PKG_BTSTACK_SAMPLE_LE_STREAMER']):
+     example_src = Split("""
+        example/nordic_spp_le_streamer.c
+        src/ble/gatt-service/nordic_spp_service_server.c
+        """)  
+ 
+if GetDepend(['PKG_BTSTACK_SAMPLE_NORDIC_LE_COUNTER']):
+     example_src = Split("""
+        example/nordic_spp_le_counter.c
+        src/ble/gatt-service/nordic_spp_service_server.c
+        """)  
+
+if GetDepend(['PKG_BTSTACK_SAMPLE_ATT_DELAYED_RESPONSE']):
+     example_src = Split("""
+        example/att_delayed_response.c
+        """)  
+
+
+if GetDepend(['PKG_BTSTACK_SAMPLE_SM_PAIRING_PERIPHERAL']):
+     example_src = Split("""
+        example/sm_pairing_peripheral.c
+        """)       
+
+if GetDepend(['PKG_BTSTACK_SAMPLE_GATT_STREAMER_PERIPHERAL']):
+     example_src = Split("""
+        example/gatt_streamer_server.c
+        """)       
+        
+if GetDepend(['PKG_BTSTACK_SAMPLE_ANCS_CLIENT_DEMO']):
+     example_src = Split("""
+        example/ancs_client_demo.c
+        src/ble/ancs_client.c
+        src/ble/gatt_client.c
+        """)   
+        
+if GetDepend(['PKG_BTSTACK_SAMPLE_MESH_DEMO']):
+     example_src = Split("""
+        example/mesh_node_demo.c
+        """)  
+        
+if GetDepend(['PKG_BTSTACK_SAMPLE_TMALL_MESH_DEMO']):
+     example_src = Split("""
+        rtt_adapter/mesh_node_demo_tmall.c
+        """)        
+          
+LOCAL_CCFLAGS = ''
+if rtconfig.CROSS_TOOL == 'keil':
+    LOCAL_CCFLAGS += ' --gnu'
+
+
+group = DefineGroup('RTT_BTSTACK', src, depend = [''], CPPPATH = path, LOCAL_CCFLAGS = LOCAL_CCFLAGS)
 
-group = DefineGroup('RTT_BTSTACK', src, depend = [''], CPPPATH = path)
+if GetDepend('PKG_BTSTACK_SAMPLE_DISABLE') == False:
+    group = group + DefineGroup('btstack_example', example_src, depend = [''], CPPPATH = path)
+    
 
 Return('group')

+ 85 - 67
chipset/bcm/btstack_chipset_bcm.c

@@ -48,6 +48,8 @@
 #include <stddef.h>   /* NULL */
 #include <stdio.h> 
 #include <string.h>   /* memcpy */
+#include <rt_ota.h>
+#include <fal.h>
 
 #include "btstack_control.h"
 #include "btstack_debug.h"
@@ -106,9 +108,9 @@ static void chipset_set_bd_addr_command(bd_addr_t addr, uint8_t *hci_cmd_buffer)
 #ifdef HAVE_POSIX_FILE_IO
 
 static const char * hcd_file_path;
-static const char * hcd_folder_path = ".";
+static const char * hcd_folder_path = "";
 static int hcd_fd;
-static char matched_file[1000];
+//static char matched_file[1000];
 
 
 static void chipset_init(const void * config){
@@ -125,13 +127,19 @@ static void chipset_init(const void * config){
 static const uint8_t download_command[] = {0x2e, 0xfc, 0x00};
 
 static btstack_chipset_result_t chipset_next_command(uint8_t * hci_cmd_buffer){
+    static int hcd_file_length;
     if (hcd_fd < 0){
+        const struct fal_partition *hcd_part = fal_partition_find("bt_image");
         log_info("chipset-bcm: hcd_file_path open file %s", hcd_file_path);
         hcd_fd = open(hcd_file_path, O_RDONLY);
         if (hcd_fd < 0){
             log_error("chipset-bcm: can't open file %s", hcd_file_path);
             return BTSTACK_CHIPSET_NO_INIT_SCRIPT;
         }
+        hcd_file_length = rt_ota_get_raw_fw_size(hcd_part);
+        if(hcd_file_path <= 0){
+             return BTSTACK_CHIPSET_NO_INIT_SCRIPT;
+        }
     }
 
     // send download firmware command
@@ -145,7 +153,7 @@ static btstack_chipset_result_t chipset_next_command(uint8_t * hci_cmd_buffer){
     do {
         // read command
         int res = read(hcd_fd, hci_cmd_buffer, 3);
-        if (res == 0){
+        if (init_script_offset == hcd_file_length){
             log_info("chipset-bcm: end of file, size %u", init_script_offset);
             close(hcd_fd);
             return BTSTACK_CHIPSET_DONE;
@@ -179,80 +187,90 @@ void btstack_chipset_bcm_set_hcd_folder_path(const char * path){
     hcd_folder_path = path;
 }
 
-static int equal_ignore_case(const char *str1, const char *str2){
-    if (!str1 || !str2) return (1);
-    int i = 0;
-    while (true){
-        if (!str1[i] && !str2[i]) return 1;
-        if (tolower(str1[i]) != tolower(str2[i])) return 0;
-        if (!str1[i] || !str2[i]) return 0;
-        i++;
-    }
-}
+//static int equal_ignore_case(const char *str1, const char *str2){
+//    if (!str1 || !str2) return (1);
+//    int i = 0;
+//    while (true){
+//        if (!str1[i] && !str2[i]) return 1;
+//        if (tolower(str1[i]) != tolower(str2[i])) return 0;
+//        if (!str1[i] || !str2[i]) return 0;
+//        i++;
+//    }
+//}
 
 // assumption starts with BCM or bcm
-#define MAX_DEVICE_NAME_LEN 15
+#define MAX_DEVICE_NAME_LEN 25
 void btstack_chipset_bcm_set_device_name(const char * device_name){
     // ignore if file path already set
+    int fd = -1;
     if (hcd_file_path) {
         log_error("chipset-bcm: set device name called %s although path %s already set", device_name, hcd_file_path);
         return;
     } 
-    // construct filename for long variant
-    if (strlen(device_name) > MAX_DEVICE_NAME_LEN){
-        log_error("chipset-bcm: device name %s too long", device_name);
-        return;
-    }
-    char filename_complete[MAX_DEVICE_NAME_LEN+5];
-    strcpy(filename_complete, device_name);
-    strcat(filename_complete, ".hcd");
-
-    // construct short variant without revision info
-    char filename_short[MAX_DEVICE_NAME_LEN+5];
-    strcpy(filename_short, device_name);
-    int len = strlen(filename_short);
-    while (len > 3){
-        char c = filename_short[len-1];
-        if (isdigit(c) == 0) break;
-        len--;
-    }    
-    if (len > 3){
-        filename_short[len-1] = 0;
-    }
-    strcat(filename_short, ".hcd");
-    log_info("chipset-bcm: looking for %s and %s", filename_short, filename_complete);
-
-    // find in folder
-    DIR *dirp = opendir(hcd_folder_path);
-    int match_short = 0;
-    int match_complete = 0;
-    if (!dirp){
-        log_error("chipset-bcm: could not get directory for %s", hcd_folder_path);
-        return;
-    }
-    while (true){
-        struct dirent *dp = readdir(dirp);
-        if (!dp) break;
-        if (equal_ignore_case(filename_complete, dp->d_name)){
-            match_complete = 1;
-            continue;
-        }
-        if (equal_ignore_case(filename_short, dp->d_name)){
-            match_short = 1;            
-        }
-    }
-    closedir(dirp);
-    if (match_complete){
-        sprintf(matched_file, "%s/%s", hcd_folder_path, filename_complete);
-        hcd_file_path = matched_file;
-        return;
-    }
-    if (match_short){
-        sprintf(matched_file, "%s/%s", hcd_folder_path, filename_short);
-        hcd_file_path = matched_file;
+    fd = open(device_name,O_RDONLY);
+    if(fd < 0 )
+    {
+        log_error("cannot open bluetooth firmware %s", device_name);
         return;
     }
-    log_error("chipset-bcm: could not find %s or %s, please provide .hcd file in %s", filename_complete, filename_short, hcd_folder_path);
+    close(fd);
+    hcd_file_path = device_name;
+
+    // construct filename for long variant
+//    if (strlen(device_name) > MAX_DEVICE_NAME_LEN){
+//        log_error("chipset-bcm: device name %s too long", device_name);
+//        return;
+//    }
+//    char filename_complete[MAX_DEVICE_NAME_LEN+5];
+//    strcpy(filename_complete, device_name);
+//    //strcat(filename_complete, ".hcd");
+//
+//    // construct short variant without revision info
+//    char filename_short[MAX_DEVICE_NAME_LEN+5];
+//    strcpy(filename_short, device_name);
+//    int len = strlen(filename_short);
+//    while (len > 3){
+//        char c = filename_short[len-1];
+//        if (isdigit(c) == 0) break;
+//        len--;
+//    }
+//    if (len > 3){
+//        filename_short[len-1] = 0;
+//    }
+//   // strcat(filename_short, ".hcd");
+//    log_info("chipset-bcm: looking for %s and %s", filename_short, filename_complete);
+//
+//    // find in folder
+//    DIR *dirp = opendir(hcd_folder_path);
+//    int match_short = 0;
+//    int match_complete = 0;
+//    if (!dirp){
+//        log_error("chipset-bcm: could not get directory for %s", hcd_folder_path);
+//        return;
+//    }
+//    while (true){
+//        struct dirent *dp = readdir(dirp);
+//        if (!dp) break;
+//        if (equal_ignore_case(filename_complete, dp->d_name)){
+//            match_complete = 1;
+//            continue;
+//        }
+//        if (equal_ignore_case(filename_short, dp->d_name)){
+//            match_short = 1;
+//        }
+//    }
+//    closedir(dirp);
+//    if (match_complete){
+//        sprintf(matched_file, "%s/%s", hcd_folder_path, filename_complete);
+//        hcd_file_path = matched_file;
+//        return;
+//    }
+//    if (match_short){
+//        sprintf(matched_file, "%s/%s", hcd_folder_path, filename_short);
+//        hcd_file_path = matched_file;
+//        return;
+//    }
+//    log_error("chipset-bcm: could not find %s or %s, please provide firmware in %s", filename_complete, filename_short, hcd_folder_path);
 }
 
 #else

+ 8 - 5
platform/posix/btstack_run_loop_posix.c

@@ -53,11 +53,12 @@
 #include "btstack_linked_list.h"
 #include "btstack_debug.h"
 
+#include <rtthread.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/select.h>
 #include <sys/time.h>
 #include <time.h>
+#include <sys/select.h>
 #include <unistd.h>
 
 static void btstack_run_loop_posix_dump_timer(void);
@@ -123,10 +124,14 @@ static bool btstack_run_loop_posix_remove_timer(btstack_timer_source_t *ts){
 
 static void btstack_run_loop_posix_dump_timer(void){
     btstack_linked_item_t *it;
+#ifdef ENABLE_LOG_INFO
     int i = 0;
+#endif
     for (it = (btstack_linked_item_t *) timers; it ; it = it->next){
+#ifdef ENABLE_LOG_INFO
         btstack_timer_source_t *ts = (btstack_timer_source_t*) it;
-        log_info("timer %u (%p): timeout %u\n", i, ts, ts->timeout);
+        log_info("timer %u (%p): timeout %u\n", i++, ts, ts->timeout);
+#endif
     }
 }
 
@@ -184,9 +189,7 @@ static uint32_t btstack_run_loop_posix_get_time_ms(void){
     clock_gettime(CLOCK_MONOTONIC, &now_ts);
     time_ms = (uint32_t) timespec_diff_milis(&init_ts, &now_ts);
 #else
-    struct timeval tv;
-    gettimeofday(&tv, NULL);
-    time_ms = (uint32_t) ((tv.tv_sec  - init_tv.tv_sec) * 1000) + (tv.tv_usec / 1000);
+    time_ms = rt_tick_get()*1000ULL/RT_TICK_PER_SECOND;
 #endif
     return time_ms;
 }

+ 2 - 2
port/posix-h4-bcm/btstack_config.h

@@ -4,7 +4,7 @@
 
 #ifndef __BTSTACK_CONFIG
 #define __BTSTACK_CONFIG
-
+#include "rtthread.h"
 // Port related features
 #define HAVE_MALLOC
 #define HAVE_POSIX_FILE_IO
@@ -19,7 +19,7 @@
 #define ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE
 #define ENABLE_LE_CENTRAL
 #define ENABLE_LE_PERIPHERAL
-//#define ENABLE_LE_SECURE_CONNECTIONS
+//#define ENABLE_ECC_P256
 //#define ENABLE_MICRO_ECC_FOR_LE_SECURE_CONNECTIONS
 #define ENABLE_LE_DATA_CHANNELS
 #define ENABLE_LE_DATA_LENGTH_EXTENSION

+ 87 - 76
port/posix-h4-bcm/btstack_main.c

@@ -69,32 +69,33 @@
 #include "btstack_chipset_bcm.h"
 #include "btstack_chipset_bcm_download_firmware.h"
 
-int btstack_main(int argc, const char * argv[]);
+int btstack_main(int argc, const char *argv[]);
 
-#define TLV_DB_PATH_PREFIX "btstack_"
+#define TLV_DB_PATH_PREFIX "/flash/btstack_"
 #define TLV_DB_PATH_POSTFIX ".tlv"
 static char tlv_db_path[100];
-static const btstack_tlv_t * tlv_impl;
-static btstack_tlv_posix_t   tlv_context;
+static const btstack_tlv_t *tlv_impl;
+static btstack_tlv_posix_t tlv_context;
 
 static hci_transport_config_uart_t transport_config = {
     HCI_TRANSPORT_CONFIG_UART,
     115200,
-    115200,  // main baudrate
-    1,       // flow control
+    115200, // main baudrate
+    1,      // flow control
     NULL,
 };
 static btstack_uart_config_t uart_config;
 
 static int main_argc;
-static const char ** main_argv;
+static const char **main_argv;
 
 static btstack_packet_callback_registration_t hci_event_callback_registration;
 
-static void sigint_handler(int param){
+static void sigint_handler(int param)
+{
     UNUSED(param);
 
-    printf("CTRL-C - SIGINT received, shutting down..\n");   
+    printf("CTRL-C - SIGINT received, shutting down..\n");
     log_info("sigint_handler: shutting down");
 
     // reset anyway
@@ -103,100 +104,104 @@ static void sigint_handler(int param){
     // power down
     hci_power_control(HCI_POWER_OFF);
     hci_close();
-    log_info("Good bye, see you.\n");    
-//    exit(0);
+    log_info("Good bye, see you.\n");
+    //    exit(0);
 }
 
 static int led_state = 0;
-void hal_led_toggle(void){
+void hal_led_toggle(void)
+{
     led_state = 1 - led_state;
     printf("LED State %u\n", led_state);
 }
 
-static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
+static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
+{
     bd_addr_t addr;
-    if (packet_type != HCI_EVENT_PACKET) return;
-    switch (hci_event_packet_get_type(packet)){
-        case BTSTACK_EVENT_STATE:
-            if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) break;
-            gap_local_bd_addr(addr);
-            printf("BTstack up and running at %s\n",  bd_addr_to_str(addr));
-            // setup TLV
-//            strcpy(tlv_db_path, TLV_DB_PATH_PREFIX);
-//            strcat(tlv_db_path, bd_addr_to_str(addr));
-//            strcat(tlv_db_path, TLV_DB_PATH_POSTFIX);
-//            tlv_impl = btstack_tlv_posix_init_instance(&tlv_context, tlv_db_path);
-//            btstack_tlv_set_instance(tlv_impl, &tlv_context);
-//#ifdef ENABLE_CLASSIC
-//            hci_set_link_key_db(btstack_link_key_db_tlv_get_instance(tlv_impl, &tlv_context));
-//#endif
-//#ifdef ENABLE_BLE
-//            le_device_db_tlv_configure(tlv_impl, &tlv_context);
-//#endif
-            break;
-        default:
+    if (packet_type != HCI_EVENT_PACKET)
+        return;
+    switch (hci_event_packet_get_type(packet))
+    {
+    case BTSTACK_EVENT_STATE:
+        if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING)
             break;
+        gap_local_bd_addr(addr);
+        printf("BTstack up and running at %s\n", bd_addr_to_str(addr));
+        // setup TLV
+        //            strcpy(tlv_db_path, TLV_DB_PATH_PREFIX);
+        //            strcat(tlv_db_path, bd_addr_to_str(addr));
+        //            strcat(tlv_db_path, TLV_DB_PATH_POSTFIX);
+        //            tlv_impl = btstack_tlv_posix_init_instance(&tlv_context, tlv_db_path);
+        //            btstack_tlv_set_instance(tlv_impl, &tlv_context);
+        //#ifdef ENABLE_CLASSIC
+        //            hci_set_link_key_db(btstack_link_key_db_tlv_get_instance(tlv_impl, &tlv_context));
+        //#endif
+        //#ifdef ENABLE_BLE
+        //            le_device_db_tlv_configure(tlv_impl, &tlv_context);
+        //#endif
+        break;
+    default:
+        break;
     }
 }
 
-
 static void phase2(int status);
-int bt_stack_main(int argc, const char * argv[]){
+void bt_stack_main(void *param)
+{
 
     /// GET STARTED with BTstack ///
     btstack_memory_init();
 
     // use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT
     //const char * pklg_path = "/tmp/hci_dump.pklg";
-   // hci_dump_open(NULL, HCI_DUMP_STDOUT);
-   // printf("Packet Log: %s\n", pklg_path);
-
-                strcpy(tlv_db_path, TLV_DB_PATH_PREFIX);
-             //   strcat(tlv_db_path, bd_addr_to_str(addr));
-                strcat(tlv_db_path, TLV_DB_PATH_POSTFIX);
-                tlv_impl = btstack_tlv_posix_init_instance(&tlv_context, tlv_db_path);
-                btstack_tlv_set_instance(tlv_impl, &tlv_context);
-    #ifdef ENABLE_CLASSIC
-                hci_set_link_key_db(btstack_link_key_db_tlv_get_instance(tlv_impl, &tlv_context));
-    #endif
-    #ifdef ENABLE_BLE
-                le_device_db_tlv_configure(tlv_impl, &tlv_context);
-    #endif
+    // hci_dump_open(NULL, HCI_DUMP_STDOUT);
+    // printf("Packet Log: %s\n", pklg_path);
+
+    strcpy(tlv_db_path, TLV_DB_PATH_PREFIX);
+    //   strcat(tlv_db_path, bd_addr_to_str(addr));
+    strcat(tlv_db_path, TLV_DB_PATH_POSTFIX);
+    tlv_impl = btstack_tlv_posix_init_instance(&tlv_context, tlv_db_path);
+    btstack_tlv_set_instance(tlv_impl, &tlv_context);
+#ifdef ENABLE_CLASSIC
+    hci_set_link_key_db(btstack_link_key_db_tlv_get_instance(tlv_impl, &tlv_context));
+#endif
+#ifdef ENABLE_BLE
+    le_device_db_tlv_configure(tlv_impl, &tlv_context);
+#endif
     // setup run loop
     btstack_run_loop_init(btstack_run_loop_posix_get_instance());
-        
+
     // pick serial port and configure uart block driver
     transport_config.device_name = "/dev/uart3"; // RedBear IoT pHAT breakout board
 
     // get BCM chipset driver
-    const btstack_chipset_t * chipset = btstack_chipset_bcm_instance();
+    const btstack_chipset_t *chipset = btstack_chipset_bcm_instance();
     chipset->init(&transport_config);
 
     // set chipset name
-    btstack_chipset_bcm_set_device_name("BCM43430A1");
+    btstack_chipset_bcm_set_device_name("/dev/bt_image");
 
     // setup UART driver
-    const btstack_uart_block_t * uart_driver = btstack_uart_block_posix_instance();
+    const btstack_uart_block_t *uart_driver = btstack_uart_block_posix_instance();
 
     // extract UART config from transport config
-    uart_config.baudrate    = transport_config.baudrate_init;
+    uart_config.baudrate = transport_config.baudrate_init;
     uart_config.flowcontrol = transport_config.flowcontrol;
     uart_config.device_name = transport_config.device_name;
     uart_driver->init(&uart_config);
 
-#define BT_AP6212_PIN    GET_PIN(B, 1)
-     rt_pin_mode(BT_AP6212_PIN, PIN_MODE_OUTPUT);
-     
-     rt_pin_write(BT_AP6212_PIN, PIN_LOW);
-     HAL_Delay(1000);
-     rt_pin_write(BT_AP6212_PIN, PIN_HIGH);
-     HAL_Delay(1000);
+#define BT_AP6212_PIN GET_PIN(I, 11)
+    rt_pin_mode(BT_AP6212_PIN, PIN_MODE_OUTPUT);
 
+    rt_pin_write(BT_AP6212_PIN, PIN_LOW);
+    HAL_Delay(1000);
+    rt_pin_write(BT_AP6212_PIN, PIN_HIGH);
+    HAL_Delay(1000);
 
     // setup HCI (to be able to use bcm chipset driver)
     // init HCI
-    const hci_transport_t * transport = hci_transport_h4_instance(uart_driver);
-    hci_init(transport, (void*) &transport_config);
+    const hci_transport_t *transport = hci_transport_h4_instance(uart_driver);
+    hci_init(transport, (void *)&transport_config);
     hci_set_chipset(btstack_chipset_bcm_instance());
 
     // inform about BTstack state
@@ -206,39 +211,46 @@ int bt_stack_main(int argc, const char * argv[]){
     // handle CTRL-c
     signal(SIGINT, sigint_handler);
 
-    main_argc = argc;
-    main_argv = argv;
-
     // phase #1 download firmware
     printf("Phase 1: Download firmware\n");
 
     // phase #2 start main app
     btstack_chipset_bcm_download_firmware(uart_driver, transport_config.baudrate_main, &phase2);
 
-    bd_addr_t own_address = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
+    //default mac
+    bd_addr_t own_address = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
+
+    //config mac
+    own_address[0] = 0x41; //A
+    own_address[1] = 0x52; //R
+    own_address[2] = 0x54; //T
+    own_address[3] = *(rt_uint8_t *)(UID_BASE + 4);
+    own_address[4] = *(rt_uint8_t *)(UID_BASE + 2);
+    own_address[5] = *(rt_uint8_t *)(UID_BASE + 0);
+
     hci_set_bd_addr(own_address);
     // go
-    btstack_run_loop_execute();    
-    return 0;
+    btstack_run_loop_execute();
 }
 
 void bt_stack_port_main(void)
 {
     static rt_thread_t tid1 = RT_NULL;
 
-       tid1 = rt_thread_create("bt_stack",
+    tid1 = rt_thread_create("bt_stack",
                             bt_stack_main, RT_NULL,
                             4096,
                             5, 5);
-       if (tid1 != RT_NULL)
-            rt_thread_startup(tid1);
-        return RT_EOK;
+    if (tid1 != RT_NULL)
+        rt_thread_startup(tid1);
 }
 MSH_CMD_EXPORT(bt_stack_port_main, btstack start);
 
-static void phase2(int status){
+static void phase2(int status)
+{
 
-    if (status){
+    if (status)
+    {
         printf("Download firmware failed\n");
         return;
     }
@@ -248,4 +260,3 @@ static void phase2(int status){
     // setup app
     btstack_main(main_argc, main_argv);
 }
-

+ 8 - 7
rtt_adapter/rtt_btstack_adapter.c

@@ -74,13 +74,14 @@ static int uart_sample(int argc, char *argv[])
     {
         rt_strncpy(uart_name, SAMPLE_UART_NAME, RT_NAME_MAX);
     }
-#define BT_AP6212_PIN    GET_PIN(E, 1)
-     rt_pin_mode(BT_AP6212_PIN, PIN_MODE_OUTPUT);
-
-     rt_pin_write(BT_AP6212_PIN, PIN_LOW);
-     rt_thread_mdelay(1000);
-     rt_pin_write(BT_AP6212_PIN, PIN_HIGH);
-     rt_thread_mdelay(1000);
+#define BT_AP6212_PIN GET_PIN(I, 11)
+    rt_pin_mode(BT_AP6212_PIN, PIN_MODE_OUTPUT);
+
+    rt_pin_write(BT_AP6212_PIN, PIN_LOW);
+    HAL_Delay(1000);
+    rt_pin_write(BT_AP6212_PIN, PIN_HIGH);
+    HAL_Delay(1000);
+    rt_kprintf("\r\n =====helloworld=====\r\n ");
     /* ?????????? */
     if(serial == NULL)
     {

+ 108 - 79
rtt_adapter/rtt_btstack_gatt_blufi.c

@@ -19,31 +19,32 @@
 #include "btstack.h"
 #include "rtthread.h"
 
+#include "wifi.h"
+
 #define HEARTBEAT_PERIOD_MS 1000
 
-static int  le_notification_enabled;
+static int le_notification_enabled = 0;
 static btstack_timer_source_t heartbeat;
 static btstack_packet_callback_registration_t hci_event_callback_registration;
 static hci_con_handle_t con_handle;
 
-
-static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
-static uint16_t att_read_callback(hci_con_handle_t con_handle, uint16_t att_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size);
+static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
+static uint16_t att_read_callback(hci_con_handle_t con_handle, uint16_t att_handle, uint16_t offset, uint8_t *buffer, uint16_t buffer_size);
 static int att_write_callback(hci_con_handle_t con_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size);
-static void  heartbeat_handler(struct btstack_timer_source *ts);
-static void beat(void);
+static void heartbeat_handler(struct btstack_timer_source *ts);
+//static void beat(void);
 
 const uint8_t adv_data[] = {
     // Flags general discoverable, BR/EDR not supported
-    0x02, BLUETOOTH_DATA_TYPE_FLAGS, 0x05, 
+    0x02, BLUETOOTH_DATA_TYPE_FLAGS, 0x05,
     // Name
-    0x0b, BLUETOOTH_DATA_TYPE_COMPLETE_LOCAL_NAME, 'L', 'E', ' ', 'C', 'o', 'u', 'n', 't', 'e', 'r', 
+    0x0b, BLUETOOTH_DATA_TYPE_COMPLETE_LOCAL_NAME, 'A', 'R', 'T', '-', 'P', 'i', ' ', ' ', ' ', ' ',
     // Incomplete List of 16-bit Service Class UUIDs -- FF10 - only valid for testing!
 };
 const uint8_t adv_data_len = sizeof(adv_data);
 
-static void le_counter_setup(void){
-
+static void le_counter_setup(void)
+{
 
     l2cap_init();
 
@@ -54,7 +55,7 @@ static void le_counter_setup(void){
     sm_init();
 
     // setup ATT server
-    att_server_init(profile_data, att_read_callback, att_write_callback);    
+    att_server_init(profile_data, att_read_callback, att_write_callback);
 
     // setup advertisements
     uint16_t adv_int_min = 0x0030;
@@ -63,7 +64,7 @@ static void le_counter_setup(void){
     bd_addr_t null_addr;
     memset(null_addr, 0, 6);
     gap_advertisements_set_params(adv_int_min, adv_int_max, adv_type, 0, null_addr, 0x07, 0x00);
-    gap_advertisements_set_data(adv_data_len, (uint8_t*) adv_data);
+    gap_advertisements_set_data(adv_data_len, (uint8_t *)adv_data);
     gap_advertisements_enable(1);
 
     // register for HCI events
@@ -79,7 +80,7 @@ static void le_counter_setup(void){
     btstack_run_loop_add_timer(&heartbeat);
 
     // beat once
- //   beat();
+    //   beat();
 }
 /* LISTING_END */
 
@@ -90,15 +91,15 @@ static void le_counter_setup(void){
  * and request a ATT_EVENT_CAN_SEND_NOW to send a notification if enabled see Listing heartbeat.
  */
 
- /* LISTING_START(heartbeat): Hearbeat Handler */
-static int  counter = 0;
+/* LISTING_START(heartbeat): Hearbeat Handler */
+//static int counter = 0;
 static char counter_string[1024];
-static int  counter_string_len;
+static int counter_string_len;
 static uint32_t send_buffer_index = 0;
-static uint8_t send_buffer_complete= 1;
+static uint8_t send_buffer_complete = 1;
 #define GATT_SEND_MAX_SIZE 20
 
-#define BLUFI_RECV_BUFF_SIZE  200
+#define BLUFI_RECV_BUFF_SIZE 200
 struct basl_blufi_recv_data
 {
     uint8_t buf[BLUFI_RECV_BUFF_SIZE];
@@ -106,7 +107,6 @@ struct basl_blufi_recv_data
     uint8_t recv_offset;
 };
 
-
 static struct basl_blufi_recv_data blufi_data;
 uint8_t bsal_blufi_push_data(struct basl_blufi_recv_data *blufi_data, uint8_t length, uint8_t *data)
 {
@@ -121,7 +121,7 @@ uint8_t bsal_blufi_push_data(struct basl_blufi_recv_data *blufi_data, uint8_t le
         blufi_data->recv_offset = 0;
         memset(blufi_data->buf, 0, blufi_data->alloc_len);
     }
-    printf("\r\n====length:%d   \r\n",length);
+    log_debug("\r\n====length:%d   \r\n", length);
     memcpy(&blufi_data->buf[blufi_data->recv_offset], data, length);
     blufi_data->recv_offset += length;
     //check the data
@@ -132,39 +132,41 @@ uint8_t bsal_blufi_push_data(struct basl_blufi_recv_data *blufi_data, uint8_t le
     return 0;
 }
 
-static int bt_stack_blufi_send(uint8_t *string, uint32_t length)
+int bt_stack_blufi_send(uint8_t *string, uint32_t length)
 {
     memcpy(counter_string, string, length);
     counter_string_len = length;
-    if(le_notification_enabled)
+    if (le_notification_enabled)
     {
-        printf("\r\n===start send string====\r\n");
+        log_debug("\r\n===start send string====\r\n");
         send_buffer_complete = 0;
         send_buffer_index = 0;
     }
-    else {
-        printf("\r\n===le_notification_enabled:%d can't send====\r\n",le_notification_enabled);
+    else
+    {
+        log_error("\r\n===le_notification_enabled:%d can't send====\r\n", le_notification_enabled);
         return -1;
     }
     return 0;
 }
 
-void bt_send_api(void){
+void bt_send_api(void)
+{
     uint8_t wifi_status = 1;
-    uint8_t ip_address[4]={192,168,1,1};
-    char temp_string[100] ={0};
+    uint8_t ip_address[4] = {192, 168, 1, 1};
+    char temp_string[100] = {0};
     uint32_t temp_length = 0;
-   // counter_string_len = sprintf(counter_string, "{wifi:'%s'}", wifi_status?"on":"off");
-    temp_length = sprintf(temp_string, "{wifi:'%s', url:' http://%d.%d.%d.%d/index.html'}", wifi_status?"on":"off",ip_address[0],ip_address[1],ip_address[2],ip_address[3]);
-    printf("\r\n======counter_string_len:%d======\r\n",temp_length);
+    // counter_string_len = sprintf(counter_string, "{wifi:'%s'}", wifi_status?"on":"off");
+    temp_length = sprintf(temp_string, "{wifi:'%s', url:' http://%d.%d.%d.%d/index.html'}", wifi_status ? "on" : "off", ip_address[0], ip_address[1], ip_address[2], ip_address[3]);
+    log_debug("\r\n======counter_string_len:%d======\r\n", temp_length);
 
-    bt_stack_blufi_send(temp_string, temp_length);
+    bt_stack_blufi_send((uint8_t *)temp_string, temp_length);
 }
-
 MSH_CMD_EXPORT(bt_send_api, send data);
 
-static void heartbeat_handler(struct btstack_timer_source *ts){
-    if(send_buffer_complete == 1)
+static void heartbeat_handler(struct btstack_timer_source *ts)
+{
+    if (send_buffer_complete == 1)
     {
         //tx complete no need
         //printf("\r\n === tx complete===\r\n ");
@@ -172,13 +174,14 @@ static void heartbeat_handler(struct btstack_timer_source *ts){
         btstack_run_loop_add_timer(ts);
         return;
     }
-    if ((le_notification_enabled)&&(counter_string_len!=0)) {
+    if ((le_notification_enabled) && (counter_string_len != 0))
+    {
         att_server_request_can_send_now_event(con_handle);
     }
 
     btstack_run_loop_set_timer(ts, HEARTBEAT_PERIOD_MS);
     btstack_run_loop_add_timer(ts);
-} 
+}
 /* LISTING_END */
 
 /* 
@@ -190,36 +193,40 @@ static void heartbeat_handler(struct btstack_timer_source *ts){
  */
 
 /* LISTING_START(packetHandler): Packet Handler */
-static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
+static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
+{
     UNUSED(channel);
     UNUSED(size);
     uint8_t send_length = 0;
 
-    switch (packet_type) {
-        case HCI_EVENT_PACKET:
-            switch (hci_event_packet_get_type(packet)) {
-                case HCI_EVENT_DISCONNECTION_COMPLETE:
-                    le_notification_enabled = 0;
-                    break;
-                case ATT_EVENT_CAN_SEND_NOW:
-                    if((counter_string_len-send_buffer_index) > GATT_SEND_MAX_SIZE)
-                    {
-                        send_length = GATT_SEND_MAX_SIZE;
-                    }
-                    else {
-                        send_length = counter_string_len-send_buffer_index;
-                    }
-                    att_server_notify(con_handle,ATT_CHARACTERISTIC_FF01_01_VALUE_HANDLE, (uint8_t*) (counter_string+send_buffer_index), send_length);
-                    send_buffer_index += send_length;
-                    printf("\r\n====send length= %d ==left:%s===\r\n",send_length,(uint8_t*) (counter_string+send_buffer_index));
-                    if(send_buffer_index >= counter_string_len)
-                    {
-                        //send complete
-                        send_buffer_complete = 1;
-                    }
-                    break;
+    switch (packet_type)
+    {
+    case HCI_EVENT_PACKET:
+        switch (hci_event_packet_get_type(packet))
+        {
+        case HCI_EVENT_DISCONNECTION_COMPLETE:
+            le_notification_enabled = 0;
+            break;
+        case ATT_EVENT_CAN_SEND_NOW:
+            if ((counter_string_len - send_buffer_index) > GATT_SEND_MAX_SIZE)
+            {
+                send_length = GATT_SEND_MAX_SIZE;
+            }
+            else
+            {
+                send_length = counter_string_len - send_buffer_index;
+            }
+            att_server_notify(con_handle, ATT_CHARACTERISTIC_FF01_01_VALUE_HANDLE, (uint8_t *)(counter_string + send_buffer_index), send_length);
+            send_buffer_index += send_length;
+            log_debug("\r\n====send length= %d ==left:%s===\r\n", send_length, (uint8_t *)(counter_string + send_buffer_index));
+            if (send_buffer_index >= counter_string_len)
+            {
+                //send complete
+                send_buffer_complete = 1;
             }
             break;
+        }
+        break;
     }
 }
 /* LISTING_END */
@@ -239,19 +246,20 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
 // - if buffer == NULL, don't copy data, just return size of value
 // - if buffer != NULL, copy data and return number bytes copied
 // @param offset defines start of attribute value
-static uint16_t att_read_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){
-//    UNUSED(connection_handle);
-    uint8_t string[]={192,168,0,1};
-        printf("\r\n read the att %x, %x, offset:%x,buffer:%p, buffer_size:%x\r\n",connection_handle, att_handle, offset, buffer, buffer_size);
+static uint16_t att_read_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t offset, uint8_t *buffer, uint16_t buffer_size)
+{
+    //    UNUSED(connection_handle);
+    uint8_t string[] = {192, 168, 0, 1};
+    log_debug("\r\n read the att %x, %x, offset:%x,buffer:%p, buffer_size:%x\r\n", connection_handle, att_handle, offset, buffer, buffer_size);
 
-       if (att_handle == ATT_CHARACTERISTIC_FF01_01_VALUE_HANDLE){
-            return att_read_callback_handle_blob((const uint8_t *)string, 4, offset, buffer, buffer_size);
-        }
+    if (att_handle == ATT_CHARACTERISTIC_FF01_01_VALUE_HANDLE)
+    {
+        return att_read_callback_handle_blob((const uint8_t *)string, 4, offset, buffer, buffer_size);
+    }
     return 0;
 }
 /* LISTING_END */
 
-
 /*
  * @section ATT Write
  *
@@ -261,29 +269,50 @@ static uint16_t att_read_callback(hci_con_handle_t connection_handle, uint16_t a
  */
 
 /* LISTING_START(attWrite): ATT Write */
-static int att_write_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size){
+static int att_write_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size)
+{
     UNUSED(transaction_mode);
     UNUSED(offset);
     UNUSED(buffer_size);
-    
-    printf("\r\n write the att %x, %x, offset:%x,buffer:%p, buffer_size:%x transaction_mode %d \r\n",connection_handle, att_handle, offset, buffer, buffer_size, transaction_mode);
-    if(att_handle == ATT_CHARACTERISTIC_FF01_01_CLIENT_CONFIGURATION_HANDLE)
+
+    log_debug("\r\n write the att %x, %x, offset:%x,buffer:%p, buffer_size:%x transaction_mode %d \r\n", connection_handle, att_handle, offset, buffer, buffer_size, transaction_mode);
+    if (att_handle == ATT_CHARACTERISTIC_FF01_01_CLIENT_CONFIGURATION_HANDLE)
     {
         le_notification_enabled = little_endian_read_16(buffer, 0) == GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION;
-        printf("\r\n deal with the notify le_notification_enabled:%d %x, %x\r\n",le_notification_enabled,buffer[0],buffer[1]);
+        log_debug("\r\n deal with the notify le_notification_enabled:%d %x, %x\r\n", le_notification_enabled, buffer[0], buffer[1]);
     }
-    if(att_handle == ATT_CHARACTERISTIC_FF01_01_VALUE_HANDLE)
+    if (att_handle == ATT_CHARACTERISTIC_FF01_01_VALUE_HANDLE)
     {
-        printf("\r\n recv data: %s length :%d\r\n", buffer, buffer_size);
-        uint8_t ret =  bsal_blufi_push_data(&blufi_data, buffer_size, buffer);
+        log_debug("\r\n recv data: %s length :%d\r\n", buffer, buffer_size);
+        uint8_t ret = bsal_blufi_push_data(&blufi_data, buffer_size, buffer);
         if (ret == 0xff)
         {
+            if (!wifi_is_ready())
+            {
+                wifi_connect((char *)blufi_data.buf);
+            }
+            else
+            {
+                int retry_cnt = 3;
+                char *wifi_status = wifi_status_get();
+
+                while (retry_cnt)
+                {
+                    if (bt_stack_blufi_send((uint8_t *)wifi_status, strlen(wifi_status)) < 0)
+                    {
+                        retry_cnt--;
+                    }
+                    else
+                    {
+                        break;
+                    }
+                }
+            }
             //the data is ready
-            printf("\r\n BLUFI: THE RECEIVE DATA IS :%s \r\n", blufi_data.buf);
+            log_debug("\r\n BLUFI: THE RECEIVE DATA IS :%s \r\n", blufi_data.buf);
         }
     }
 
-
     con_handle = connection_handle;
     return 0;
 }

+ 1 - 0
src/hci_dump.c

@@ -339,6 +339,7 @@ void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t
     int res = 0;
     res = write (dump_file, &header, header_len);
     res = write (dump_file, packet, len );
+    res=res;
     UNUSED(res);
 #endif