diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..bcf0a108 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,29 @@ +name: C/C++ CI + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: checkout ambz2_sdk main branch + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + path: ambz2_sdk + + - name: Build is + run: | + echo "Setting up build environment" + cd ambz2_sdk/project/realtek_amebaz2_v0_example/GCC-RELEASE/ + make clean + echo "Building firmware image" + make is + echo "Build image completed" + make clean + diff --git a/AmebaZ2 LZMA flash layout_customer.pptx b/AmebaZ2 LZMA flash layout_customer.pptx index 8a665a6d..77af266e 100644 Binary files a/AmebaZ2 LZMA flash layout_customer.pptx and b/AmebaZ2 LZMA flash layout_customer.pptx differ diff --git a/component/common/api/at_cmd/atcmd_lwip.c b/component/common/api/at_cmd/atcmd_lwip.c index 68df9e00..ccff24da 100644 --- a/component/common/api/at_cmd/atcmd_lwip.c +++ b/component/common/api/at_cmd/atcmd_lwip.c @@ -167,7 +167,7 @@ void socket_close(void) static void server_start(void *param) { int s_mode; - int s_sockfd, s_newsockfd; + int s_sockfd = 0, s_newsockfd; socklen_t s_client; struct sockaddr_in s_serv_addr, s_cli_addr; int s_local_port; @@ -603,8 +603,8 @@ static void client_start(void *param) { int c_mode; int c_remote_port; - char c_remote_addr[16]; - int c_sockfd; + char c_remote_addr[16] = {0}; + int c_sockfd = 0; struct sockaddr_in c_serv_addr; int error_no = 0; #if ATCMD_VER == ATVER_2 @@ -974,6 +974,7 @@ void fATP3(void *arg){ printf("[ATP3]Usage: ATP3=REMOTE_IP\n\r"); goto exit; } + memset(remote_addr, '\0', sizeof(remote_addr)); strncpy((char*)remote_addr, (char*)arg, sizeof(remote_addr)); printf("[ATP3]: _AT_TRANSPORT_REMOTE_IP_ [%s]\n\r", remote_addr); @@ -2966,7 +2967,7 @@ extern char log_buf[LOG_SERVICE_BUFLEN]; extern struct netif xnetif[NET_IF_NUM]; extern int atcmd_sntp(char* hostname); -static int select_check = 0; +static int select_check = 1; static unsigned char _tx_buffer[MAX_BUFFER]; static unsigned char _rx_buffer[MAX_BUFFER]; @@ -3134,7 +3135,7 @@ static void server_start(void *param) ( void ) param; int s_mode; - int s_sockfd, s_newsockfd; + int s_sockfd = 0, s_newsockfd = 0; socklen_t s_client; struct sockaddr_in s_serv_addr, s_cli_addr; int s_local_port; @@ -3868,8 +3869,8 @@ static void client_start(void *param) int select_task_suspend = 0; int c_mode; int c_remote_port; - char c_remote_addr[16]; - int c_sockfd; + char c_remote_addr[16] = {0}; + int c_sockfd = 0; struct sockaddr_in c_serv_addr; int error_no = 0; #if ATCMD_VER == ATVER_2 @@ -3957,7 +3958,7 @@ static void client_start(void *param) /*********************************************************** * SSL 1. Setup stuff for this ssl connection ************************************************************/ - if (select_check && (!select_task_suspend)) { + if (select_check && (!select_task_suspend) && atcmd_select_task != NULL) { vTaskSuspend(atcmd_select_task); select_task_suspend = 1; } @@ -4314,7 +4315,8 @@ void fATP3(void *arg){ printf("[ATP3]Usage: ATP3=REMOTE_IP\n\r"); goto exit; } - strncpy((char*)remote_addr, (char*)arg, sizeof(remote_addr)); + memset((char*)remote_addr, '\0', sizeof(remote_addr)); + strncpy((char*)remote_addr, (char*)arg, sizeof(remote_addr) - 1); printf("[ATP3]: _AT_TRANSPORT_REMOTE_IP_ [%s]\n\r", remote_addr); exit: @@ -5002,7 +5004,9 @@ void fATPC(void *arg){ error_no = 5; goto err_exit; } - +#if defined(ATCMD_SUPPORT_SSL) && ATCMD_SUPPORT_SSL + printf("\r\n[ATPC] Use ATRV to start auto receive\r\n"); +#endif goto exit; err_exit: if(clientnode) @@ -5377,7 +5381,7 @@ void fATPR(void *arg){ memset(rx_buffer, 0, rx_buffer_size); if(curnode->protocol == NODE_MODE_SSL) { - if (select_check && (!select_task_suspend)) { + if (select_check && (!select_task_suspend) && atcmd_select_task != NULL) { vTaskSuspend(atcmd_select_task); select_task_suspend = 1; } @@ -6071,9 +6075,23 @@ int atcmd_lwip_receive_data(node *curnode, u8 *buffer, u16 buffer_size, int *rec ret = select(curnode->sockfd + 1, &readfds, NULL, NULL, &tv); if(!((ret > 0)&&(FD_ISSET(curnode->sockfd, &readfds)))) { - //AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS, - // "[ATPR] No receive event for con_id %d", curnode->con_id); - goto exit; +#if (ATCMD_VER == ATVER_2) && ATCMD_SUPPORT_SSL + if(curnode->protocol == NODE_MODE_SSL) + { + if(mbedtls_ssl_get_bytes_avail((mbedtls_ssl_context *)curnode->context) == 0) + { + //AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS, + // "[ATPR] No receive event for con_id %d", curnode->con_id); + goto exit; + } + } + else +#endif // #if (ATCMD_VER == ATVER_2) && ATCMD_SUPPORT_SSL + { + //AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS, + // "[ATPR] No receive event for con_id %d", curnode->con_id); + goto exit; + } } if(curnode->protocol == NODE_MODE_UDP) //udp server receive from client @@ -6159,7 +6177,7 @@ int atcmd_lwip_receive_data(node *curnode, u8 *buffer, u16 buffer_size, int *rec } exit: if(error_no == 0) - *recv_size = size; + *recv_size = size; else{ #if (ATCMD_VER == ATVER_2) && ATCMD_SUPPORT_SSL if(curnode->protocol == NODE_MODE_SSL){ @@ -6204,7 +6222,7 @@ static void select_task(void *param) //TCP Server must receive data from the seed continue; } - error_no = atcmd_lwip_receive_data(curnode, rx_buffer, packet_size, &recv_size, udp_clientaddr, &udp_clientport); + error_no = atcmd_lwip_receive_data(curnode, rx_buffer, packet_size, &recv_size, udp_clientaddr, &udp_clientport); if(error_no==7 || error_no == 8){ #if CONFIG_LOG_SERVICE_LOCK log_service_lock(); @@ -6459,7 +6477,7 @@ void fATRV(void *arg){ AT_DBG_MSG(AT_FLAG_LWIP, AT_DBG_ALWAYS, "[ATRV] already enter auto receive mode"); } else{ - if (select_check) vTaskSuspend(atcmd_select_task); + if (select_check && atcmd_select_task != NULL) vTaskSuspend(atcmd_select_task); if(start_autorecv_task()) error_no = 2; } @@ -7091,4 +7109,4 @@ void at_transport_init(void) log_module_init(at_transport_init); #endif -#endif /*CONFIG_USE_POLARSSL*/ +#endif /*CONFIG_USE_POLARSSL*/ \ No newline at end of file diff --git a/component/common/api/at_cmd/atcmd_lwip.h b/component/common/api/at_cmd/atcmd_lwip.h index 0c94b6dd..4ba8253f 100644 --- a/component/common/api/at_cmd/atcmd_lwip.h +++ b/component/common/api/at_cmd/atcmd_lwip.h @@ -78,6 +78,7 @@ typedef struct ns struct ns* nextseed; #if (ATCMD_VER == ATVER_2) && ATCMD_SUPPORT_SSL void *context; + void *ssl_conf; #endif } node; diff --git a/component/common/api/at_cmd/atcmd_sys.c b/component/common/api/at_cmd/atcmd_sys.c index ae44b038..a9ed1012 100644 --- a/component/common/api/at_cmd/atcmd_sys.c +++ b/component/common/api/at_cmd/atcmd_sys.c @@ -62,14 +62,20 @@ static char cBuffer[512]; #if defined(CONFIG_PLATFORM_8710C) extern void sys_uart_download_mode(void); +extern void sys_download_mode(u8 mode); void fATXX(void *arg) { #if defined(CONFIG_BUILD_NONSECURE) && (CONFIG_BUILD_NONSECURE==1) flash_t flash_Ptable; + device_mutex_lock(RT_DEV_LOCK_FLASH); flash_erase_sector(&flash_Ptable, 0x00000000); + device_mutex_unlock(RT_DEV_LOCK_FLASH); sys_reset(); #else - sys_uart_download_mode(); + u8 download_mode = 0; + if (arg) + download_mode = (unsigned char) atoi((const char *)arg); + sys_download_mode(download_mode); #endif } #endif @@ -139,6 +145,7 @@ void fATSK(void *arg) int argc = 0; char *argv[MAX_ARGC] = {0}; u8 key[16]; + u32 key32[16]; AT_DBG_MSG(AT_FLAG_RDP, AT_DBG_ALWAYS, "[ATSK]: _AT_SYSTEM_RDP/RSIP_CONFIGURE_"); if(!arg){ @@ -167,10 +174,14 @@ void fATSK(void *arg) AT_DBG_MSG(AT_FLAG_RDP, AT_DBG_ALWAYS, "[ATSK] Err: RDP key length should be 16 bytes"); return; } - - sscanf(argv[2], "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - &key[0], &key[1], &key[2], &key[3], &key[4], &key[5], &key[6], &key[7], - &key[8], &key[9], &key[10], &key[11], &key[12], &key[13], &key[14], &key[15]); + + memset(key32, 0, sizeof(key32)); + sscanf(argv[2], "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + &key32[0], &key32[1], &key32[2], &key32[3], &key32[4], &key32[5], &key32[6], &key32[7], + &key32[8], &key32[9], &key32[10], &key32[11], &key32[12], &key32[13], &key32[14], &key32[15]); + for(i=0; i<16; i++){ + key[i] = key32[i] & 0xFF; + } EFUSE_RDP_KEY(key); AT_DBG_MSG(AT_FLAG_RDP, AT_DBG_ALWAYS, "[ATSK] Set RDP key done"); @@ -190,17 +201,21 @@ void fATSK(void *arg) AT_DBG_MSG(AT_FLAG_RDP, AT_DBG_ALWAYS, "[ATSK] Err: RSIP key length should be 16 bytes"); return; } - - sscanf(argv[2], "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - &key[0], &key[1], &key[2], &key[3], &key[4], &key[5], &key[6], &key[7], - &key[8], &key[9], &key[10], &key[11], &key[12], &key[13], &key[14], &key[15]); + + memset(key32, 0, sizeof(key32)); + sscanf(argv[2], "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + &key32[0], &key32[1], &key32[2], &key32[3], &key32[4], &key32[5], &key32[6], &key32[7], + &key32[8], &key32[9], &key32[10], &key32[11], &key32[12], &key32[13], &key32[14], &key32[15]); + for(i=0; i<16; i++){ + key[i] = key32[i] & 0xFF; + } EFUSE_OTF_KEY(key); AT_DBG_MSG(AT_FLAG_RDP, AT_DBG_ALWAYS, "[ATSK] Set RSIP key done"); }else if(strcmp(argv[1], "SB_EN") == 0){ u8 data = 0; u32 efuse_ctrl = HAL_READ32(SYSTEM_CTRL_BASE, REG_SYS_EFUSE_CTRL); - + EFUSERead8(efuse_ctrl, 0xD3, &data, L25EOUTVOLTAGE); if ((data & EFUSE_PHYSICAL_SBOOT_ON) != 0) { EFUSEWrite8(efuse_ctrl, 0xD3, data & (~EFUSE_PHYSICAL_SBOOT_ON), L25EOUTVOLTAGE); @@ -210,7 +225,7 @@ void fATSK(void *arg) } }else if(strcmp(argv[1], "SB_PK_MD5") == 0){ u8 i = 0; - + if(argc != 3){ AT_DBG_MSG(AT_FLAG_RDP, AT_DBG_ALWAYS, "[ATSK] Usage: ATSK=SB_PK_MD5[value(hex)]"); return; @@ -220,10 +235,14 @@ void fATSK(void *arg) AT_DBG_MSG(AT_FLAG_RDP, AT_DBG_ALWAYS, "[ATSK] Err: MD5 value of public key should be 16 bytes"); return; } - - sscanf(argv[2], "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - &key[0], &key[1], &key[2], &key[3], &key[4], &key[5], &key[6], &key[7], - &key[8], &key[9], &key[10], &key[11], &key[12], &key[13], &key[14], &key[15]); + + memset(key32, 0, sizeof(key32)); + sscanf(argv[2], "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + &key32[0], &key32[1], &key32[2], &key32[3], &key32[4], &key32[5], &key32[6], &key32[7], + &key32[8], &key32[9], &key32[10], &key32[11], &key32[12], &key32[13], &key32[14], &key32[15]); + for(i=0; i<16; i++){ + key[i] = key32[i] & 0xFF; + } for(i = 0; i < 16; i++) { EFUSEWrite8(HAL_READ32(SYSTEM_CTRL_BASE, REG_SYS_EFUSE_CTRL), 0xC1 + i, key[i], L25EOUTVOLTAGE); @@ -233,15 +252,15 @@ void fATSK(void *arg) }else{ AT_DBG_MSG(AT_FLAG_RDP, AT_DBG_ALWAYS, "[ATSK] Usage: ATSK=RDP_EN"); AT_DBG_MSG(AT_FLAG_RDP, AT_DBG_ALWAYS, "[ATSK] Usage: ATSK=RDP_KEY[value(hex)]"); - AT_DBG_MSG(AT_FLAG_RDP, AT_DBG_ALWAYS, "[ATSK] Example: ATSK=RDP_KEY[345487bbaa435bfe382233445ba359aa]"); + AT_DBG_MSG(AT_FLAG_RDP, AT_DBG_ALWAYS, "[ATSK] Example: ATSK=RDP_KEY[345487bbaa435bfe382233445ba359aa]"); AT_DBG_MSG(AT_FLAG_RDP, AT_DBG_ALWAYS, "[ATSK] Usage: ATSK=RSIP_EN"); AT_DBG_MSG(AT_FLAG_RDP, AT_DBG_ALWAYS, "[ATSK] Usage: ATSK=RSIP_DIS"); AT_DBG_MSG(AT_FLAG_RDP, AT_DBG_ALWAYS, "[ATSK] Usage: ATSK=RSIP_KEY[value(hex)]"); AT_DBG_MSG(AT_FLAG_RDP, AT_DBG_ALWAYS, "[ATSK] Usage: ATSK=SB_EN"); AT_DBG_MSG(AT_FLAG_RDP, AT_DBG_ALWAYS, "[ATSK] Usage: ATSK=SB_PK_MD5[value(hex)]"); - + } - + } #endif @@ -279,7 +298,9 @@ void fATSK(void *arg) int argc = 0; int ret; char *argv[MAX_ARGC] = {0}; - u8 key[PRIV_KEY_LEN],read_buffer[PRIV_KEY_LEN],read_buf_mac[MAC_LEN],hash_result[PRIV_KEY_LEN]; + u8 key[PRIV_KEY_LEN] = {0}, read_buffer[PRIV_KEY_LEN] = {0}, read_buf_mac[MAC_LEN] = {0}, hash_result[PRIV_KEY_LEN] = {0}; + u32 key32[PRIV_KEY_LEN]; + u32 sscanf_ret = 0; flash_t flash; char *ptmp; u32 offset_1, offset_2, len; @@ -287,6 +308,7 @@ void fATSK(void *arg) u32 test_mode_bit; int i; unsigned char *enc_img; + unsigned char *enc_img_tmp; u8 mac_empty[MAC_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; at_printf("[ATSK]: _AT_SYSTEM_ENABLE_SECURE_BOOT_\r\n"); @@ -295,11 +317,12 @@ void fATSK(void *arg) test_mode = HAL_READ32(0x40000000, 0x000001F4); test_mode_bit = (test_mode & BIT26)>>26; if(test_mode_bit & 0x1){ - at_printf("[ATSK] Err: the chip is still in test mode, please reset it first. \r\n"); + at_printf("[ATSK] Err: the chip is still in test mode, please reset it first.\r\n"); return; } if(!arg){ + at_printf("[ATSK] Err: argument error.\r\n"); at_printf("[ATSK] Usage: ATSK=ENC_KEY[value(string)]\r\n"); at_printf("[ATSK] Example: ATSK=ENC_KEY[000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E5F]\r\n"); at_printf("[ATSK] Usage: ATSK=HASH_KEY[value(string)]\r\n"); @@ -316,33 +339,39 @@ void fATSK(void *arg) } argc = parse_param(arg, argv); - + //verify secure boot is enabled or not, if it has been enabled, return. device_mutex_lock(RT_DEV_LOCK_EFUSE); ret = efuse_fw_verify_check(); device_mutex_unlock(RT_DEV_LOCK_EFUSE); if(ret){ - at_printf("[ATSK] Err: secure boot has been already enabled!\r\n"); + at_printf("[ATSK] Err: secure boot has been already enabled.\r\n"); return; } - - + + if(strcmp(argv[1], "ENC_KEY") == 0){ if(argc != 3){ - at_printf("[ATSK] Usage: ATSK=ENC_KEY[value(string)]\r\n"); + at_printf("[ATSK] Err: ATSK=ENC_KEY[value(string)].\r\n"); return; } if(strlen(argv[2]) != 64){ - at_printf("[ATSK] Err: ENC key length should be 32 bytes\r\n"); + at_printf("[ATSK] Err: ENC key length should be 32 bytes.\r\n"); return; } - - if(sscanf(argv[2], "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - &key[0], &key[1], &key[2], &key[3], &key[4], &key[5], &key[6], &key[7], - &key[8], &key[9], &key[10], &key[11], &key[12], &key[13], &key[14], &key[15], - &key[16], &key[17], &key[18], &key[19], &key[20], &key[21], &key[22], &key[23], - &key[24], &key[25], &key[26], &key[27], &key[28], &key[29], &key[30], &key[31])!=PRIV_KEY_LEN) + + memset(key32, 0, sizeof(key32)); + sscanf_ret = sscanf(argv[2], "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + &key32[0], &key32[1], &key32[2], &key32[3], &key32[4], &key32[5], &key32[6], &key32[7], + &key32[8], &key32[9], &key32[10], &key32[11], &key32[12], &key32[13], &key32[14], &key32[15], + &key32[16], &key32[17], &key32[18], &key32[19], &key32[20], &key32[21], &key32[22], &key32[23], + &key32[24], &key32[25], &key32[26], &key32[27], &key32[28], &key32[29], &key32[30], &key32[31]); + for(i=0; i> t) && (!((read_buffer[i] & BIT(t)) >> t))){ + at_printf("[ATSK] Err: efuse cannot rewrite because it will be messy up.\r\n"); + return; + } + } + key[i] |= (~read_buffer[i]); + } //write SS key device_mutex_lock(RT_DEV_LOCK_EFUSE); ret = efuse_susec_key_write(key); device_mutex_unlock(RT_DEV_LOCK_EFUSE); if(ret<0){ - at_printf("[ATSK] Err: ENC key write address and length error\r\n"); + at_printf("[ATSK] Err: ENC key write address and length error.\r\n"); return; } else{ - at_printf("[ATSK] Write ENC key done\r\n"); + at_printf("[ATSK] Write ENC key done.\r\n"); } - + //read SS key - //read efuse for 3 times + //read efuse for 3 times for(int j=0;j<3;j++){ //init read_buffer as 0xFF before read for(int i=0;i> t) && (!((read_buffer[i] & BIT(t)) >> t))){ + at_printf("[ATSK] Err: efuse cannot rewrite because it will be messy up.\r\n"); + return; + } + } + key[i] |= (~read_buffer[i]); + } + //write S key device_mutex_lock(RT_DEV_LOCK_EFUSE); ret = hal_sec_key_write_ext(key,0); device_mutex_unlock(RT_DEV_LOCK_EFUSE); if(ret<0){ - at_printf("[ATSK] Err: HASH key write address and length error\r\n"); + at_printf("[ATSK] Err: HASH key write address and length error.\r\n"); return; } else{ - at_printf("[ATSK] Write HASH key done\r\n"); + at_printf("[ATSK] Write HASH key done.\r\n"); } //read S key @@ -525,11 +579,11 @@ void fATSK(void *arg) ret = efuse_sec_key_write(key,0); device_mutex_unlock(RT_DEV_LOCK_EFUSE); if(ret<0){ - at_printf("[ATSK] Err: HASH key write address and length error\r\n"); + at_printf("[ATSK] Err: HASH key write address and length error.\r\n"); return; } else{ - at_printf("[ATSK] Write HASH key done\r\n"); + at_printf("[ATSK] Write HASH key done.\r\n"); } //read S key //read efuse for 3 times @@ -552,12 +606,12 @@ void fATSK(void *arg) //hash read result ret = crypto_init(); if (SUCCESS != ret) { - at_printf("[ATSK] Err: crypto engine init failed \r\n"); + at_printf("[ATSK] Err: crypto engine init failed.\r\n"); return; } ret = crypto_sha2_256(read_buffer, 32, hash_result); if (SUCCESS != ret) { - at_printf("[ATSK] Err: crypto hash key failed \r\n"); + at_printf("[ATSK] Err: crypto hash key failed.\r\n"); return; } at_printf("hash result is $"); @@ -573,16 +627,22 @@ void fATSK(void *arg) char hash_default_key[65] = "64A7433FCF027D19DDA4D446EEF8E78A22A8C33CB2C337C07366C040612EE0F2\0"; if(argc != 2){ - at_printf("[ATSK] Usage: ATSK=SB_KEY\r\n"); + at_printf("[ATSK] Err: ATSK=SB_KEY.\r\n"); return; } at_printf("\r\n1. Super Sec Key write...\r\n" ); - if((ret = sscanf(ss_default_key, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - &key[0], &key[1], &key[2], &key[3], &key[4], &key[5], &key[6], &key[7], - &key[8], &key[9], &key[10], &key[11], &key[12], &key[13], &key[14], &key[15], - &key[16], &key[17], &key[18], &key[19], &key[20], &key[21], &key[22], &key[23], - &key[24], &key[25], &key[26], &key[27], &key[28], &key[29], &key[30], &key[31]))!=PRIV_KEY_LEN) + memset(key32, 0, sizeof(key32)); + ret = sscanf(ss_default_key, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + &key32[0], &key32[1], &key32[2], &key32[3], &key32[4], &key32[5], &key32[6], &key32[7], + &key32[8], &key32[9], &key32[10], &key32[11], &key32[12], &key32[13], &key32[14], &key32[15], + &key32[16], &key32[17], &key32[18], &key32[19], &key32[20], &key32[21], &key32[22], &key32[23], + &key32[24], &key32[25], &key32[26], &key32[27], &key32[28], &key32[29], &key32[30], &key32[31]); + for(i=0; i> t) && (!((read_buffer[i] & BIT(t)) >> t))){ + at_printf("[ATSK] Err: efuse cannot rewrite because it will be messy up.\r\n"); + return; + } + } + key[i] |= (~read_buffer[i]); + } //write SS key device_mutex_lock(RT_DEV_LOCK_EFUSE); ret = efuse_susec_key_write(key); device_mutex_unlock(RT_DEV_LOCK_EFUSE); if(ret<0){ - at_printf("[ATSK] Err: ENC key write address and length error\r\n"); + at_printf("[ATSK] Err: ENC key write address and length error.\r\n"); goto ss_key_hash; } else{ - at_printf("[ATSK] Write ENC key done\r\n"); + at_printf("[ATSK] Write ENC key done.\r\n"); } //read SS key - //read efuse for 3 times + //read efuse for 3 times for(int j=0;j<3;j++){ //init read_buffer as 0xFF before read for(int i=0;i> t) && (!((read_buffer[i] & BIT(t)) >> t))){ + at_printf("[ATSK] Err: efuse cannot rewrite because it will be messy up.\r\n"); + return; + } + } + key[i] |= (~read_buffer[i]); + } //write S key device_mutex_lock(RT_DEV_LOCK_EFUSE); ret = hal_sec_key_write_ext(key,0); device_mutex_unlock(RT_DEV_LOCK_EFUSE); if(ret<0){ - at_printf("[ATSK] Err: HASH key write address and length error\r\n"); + at_printf("[ATSK] Err: HASH key write address and length error.\r\n"); return; } else{ - at_printf("[ATSK] Write HASH key done\r\n"); + at_printf("[ATSK] Write HASH key done.\r\n"); } //read S key @@ -775,11 +859,11 @@ void fATSK(void *arg) ret = efuse_sec_key_write(key,0); device_mutex_unlock(RT_DEV_LOCK_EFUSE); if(ret<0){ - at_printf("[ATSK] Err: HASH key write address and length error\r\n"); + at_printf("[ATSK] Err: HASH key write address and length error.\r\n"); return; } else{ - at_printf("[ATSK] Write HASH key done\r\n"); + at_printf("[ATSK] Write HASH key done.\r\n"); } //read S key //read efuse for 3 times @@ -802,12 +886,12 @@ void fATSK(void *arg) //hash read result ret = crypto_init(); if (SUCCESS != ret) { - at_printf("[ATSK] Err: crypto engine init failed \r\n"); + at_printf("[ATSK] Err: crypto engine init failed.\r\n"); return; } ret = crypto_sha2_256(read_buffer, 32, hash_result); if (SUCCESS != ret) { - at_printf("[ATSK] Err: crypto hash key failed \r\n"); + at_printf("[ATSK] Err: crypto hash key failed.\r\n"); return; } at_printf("hash result is $"); @@ -818,20 +902,26 @@ void fATSK(void *arg) at_printf("$\r\n"); }else if(strcmp(argv[1], "ROOT_KEY") == 0){ if(argc != 3){ - at_printf("[ATSK] Usage: ATSK=ROOT_KEY[value(string)]\r\n"); + at_printf("[ATSK] Err: ATSK=ROOT_KEY[value(string)].\r\n"); return; } if(strlen(argv[2]) != 64){ - at_printf("[ATSK] Err: ROOT key length should be 32 bytes\r\n"); + at_printf("[ATSK] Err: ROOT key length should be 32 bytes.\r\n"); return; } - - if(sscanf(argv[2], "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - &key[0], &key[1], &key[2], &key[3], &key[4], &key[5], &key[6], &key[7], - &key[8], &key[9], &key[10], &key[11], &key[12], &key[13], &key[14], &key[15], - &key[16], &key[17], &key[18], &key[19], &key[20], &key[21], &key[22], &key[23], - &key[24], &key[25], &key[26], &key[27], &key[28], &key[29], &key[30], &key[31])!=PRIV_KEY_LEN) + + memset(key32, 0, sizeof(key32)); + sscanf_ret = sscanf(argv[2], "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + &key32[0], &key32[1], &key32[2], &key32[3], &key32[4], &key32[5], &key32[6], &key32[7], + &key32[8], &key32[9], &key32[10], &key32[11], &key32[12], &key32[13], &key32[14], &key32[15], + &key32[16], &key32[17], &key32[18], &key32[19], &key32[20], &key32[21], &key32[22], &key32[23], + &key32[24], &key32[25], &key32[26], &key32[27], &key32[28], &key32[29], &key32[30], &key32[31]); + for(i=0; i= 0 && i <= 23) { + if (i==5||i==6||i==21||i==22) return 0; + else return 1; + } else return 0; +} +#endif + void fATSP(void *arg){ + int argc = 0; char *argv[MAX_ARGC] = {0}; uint32_t lock_id; uint32_t bitmap; - +#if defined(CONFIG_PLATFORM_8710C) + int sleep_duration = 0; + int wake_pin = 0; + u8 sleep_option = 0; +#endif + if (!arg) { - AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ERROR, "\r\n[ATSP] Usage: ATSP="); + AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ERROR, "\r\n[ATSP] Usage: ATSP="); at_printf("\r\n[ATSP] ERROR:1"); return; } else { - if((argc = parse_param(arg, argv)) != 2){ - AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ERROR, "\r\n[ATSP] Usage: ATSP="); + if((argc = parse_param(arg, argv)) < 2){ + AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ERROR, "\r\n[ATSP] Usage: ATSP="); at_printf("\r\n[ATSP] ERROR:1"); return; } } switch(argv[1][0]) { +#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1) case 'a': // acquire { pmu_acquire_wakelock(PMU_OS); - //at_printf("\r\n[ATSP] wakelock:0x%08x", pmu_get_wakelock_status()); + //at_printf("\r\n[ATSP] wakelock:0x%08x", pmu_get_wakelock_status()); break; } @@ -2320,26 +2586,67 @@ void fATSP(void *arg){ //at_printf("\r\n[ATSP] wakelock:0x%08x", pmu_get_wakelock_status()); break; } - case '?': // get status break; +#else /* define configUSE_WAKELOCK_PMU */ + case 'a': + case 'r': + case '?': + { + AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ERROR, "\r\n[ATSP] need to set configUSE_WAKELOCK_PMU to be 1 to use tickless feature"); + break; + } +#endif /* define configUSE_WAKELOCK_PMU */ +#if defined(CONFIG_PLATFORM_8710C) + case 'd': + { + if (argc < 3) { + AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ERROR, "\r\n[ATSP] Usage: ATSP="); + break; + } + sleep_duration = atoi(argv[2]); + if (sleep_duration) sleep_option |= DS_STIMER; + if (argc > 3) { + wake_pin = atoi(argv[3]); + if (valid_wake_pin(wake_pin)) { + gpio_irq_init(&my_GPIO_IRQ, PIN_NAME(PORT_A, wake_pin), NULL, (uint32_t)&my_GPIO_IRQ); + gpio_irq_pull_ctrl(&my_GPIO_IRQ, PullNone); + gpio_irq_set(&my_GPIO_IRQ, IRQ_FALL, 1); + sleep_option |= DS_GPIO; + } else { + AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ERROR, "\r\n[ATSP] Usage: Valid pin are A0-4,A7-20,A23"); + } + } + + if (sleep_option) DeepSleep(sleep_option, sleep_duration, 0); + break; + } + + default: + AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ERROR, "\r\n[ATSP] Usage: ATSP="); + at_printf("\r\n[ATSP] ERROR:2"); + return; +#else /* defined CONFIG_PLATFORM_8710C */ default: AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ERROR, "\r\n[ATSP] Usage: ATSP="); at_printf("\r\n[ATSP] ERROR:2"); return; +#endif /* defined CONFIG_PLATFORM_8710C */ } +#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1) bitmap = pmu_get_wakelock_status(); at_printf("\r\n[ATSP] OK:%s", (bitmap&BIT(PMU_OS))?"1":"0"); -} #endif +} + void fATSE(void *arg){ int argc = 0; int echo = 0, mask = gDbgFlag, dbg_lv = gDbgLevel; char *argv[MAX_ARGC] = {0}; int err_no = 0; - AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ALWAYS, "[ATSE]: _AT_SYSTEM_ECHO_DBG_SETTING"); + AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ALWAYS, "[ATSE]: _AT_SYSTEM_ECHO_DBG_SETTING"); if(!arg){ AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ERROR, "[ATSE] Usage: ATSE=,,"); err_no = 1; @@ -2847,9 +3154,7 @@ log_item_t at_sys_items[] = { {"ATS?", fATSh,}, // list all AT command {"ATSR", fATSR,}, // system restart {"ATSV", fATSV,}, // show version info -#if defined(CONFIG_PLATFORM_8195A) {"ATSP", fATSP,}, // power saving mod -#endif {"ATSE", fATSE,}, // enable and disable echo #if CONFIG_WLAN {"ATSY", fATSY,}, // factory reset diff --git a/component/common/api/at_cmd/atcmd_wifi.c b/component/common/api/at_cmd/atcmd_wifi.c index eacb7e36..0688750e 100644 --- a/component/common/api/at_cmd/atcmd_wifi.c +++ b/component/common/api/at_cmd/atcmd_wifi.c @@ -432,7 +432,7 @@ void fATWq(void *arg) #endif void fATWS(void *arg){ - char buf[32] = {0}; + char buf[33] = {0}; u8 *channel_list = NULL; u8 *pscan_config = NULL; int num_channel = 0; @@ -453,9 +453,11 @@ void fATWS(void *arg){ goto exit; } if(arg){ - strncpy(buf, arg, sizeof(buf)); + memset((char *)buf, '\0', sizeof(buf)); + strncpy((char *)buf, (char*)arg, sizeof(buf)-1); argc = parse_param(buf, argv); - if(argc < 2){ + if(argc <= 2){ + printf("[ATWS]Usage: ATWS=channel_num[channel_1,...,channel_n]\n\r"); ret = RTW_BADARG; #if ATCMD_VER == ATVER_2 error_no = 1; @@ -630,7 +632,7 @@ void fATWx(void *arg){ int count; rtw_mac_t mac_list[AP_STA_NUM]; } client_info; - + memset(&client_info, 0, sizeof(client_info)); client_info.count = AP_STA_NUM; wifi_get_associated_client_list(&client_info, sizeof(client_info)); @@ -720,7 +722,8 @@ void fATW0(void *arg){ goto exit; } printf("[ATW0]: _AT_WLAN_SET_SSID_ [%s]\n\r", (char*)arg); - strncpy((char *)wifi.ssid.val, (char*)arg, sizeof(wifi.ssid.val)); + memset((char *)wifi.ssid.val, '\0', sizeof(wifi.ssid.val)); + strncpy((char *)wifi.ssid.val, (char*)arg, sizeof(wifi.ssid.val) - 1); wifi.ssid.len = strlen((char*)arg); exit: #if defined(CONFIG_INIC_CMD_RSP) && CONFIG_INIC_CMD_RSP @@ -739,7 +742,8 @@ void fATW1(void *arg){ } printf("[ATW1]: _AT_WLAN_SET_PASSPHRASE_ [%s]\n\r", (char*)arg); - strncpy((char *)password, (char*)arg, sizeof(password)); + memset((char *)password,'\0', sizeof(password)); + strncpy((char *)password, (char*)arg, sizeof(password) - 1); wifi.password = password; wifi.password_len = strlen((char*)arg); exit: @@ -787,7 +791,8 @@ void fATW3(void *arg){ ret = RTW_BADARG; goto exit; } - strncpy((char *)ap.ssid.val, (char*)arg, sizeof(ap.ssid.val)); + memset((char *)ap.ssid.val, '\0', sizeof(ap.ssid.val)); + strncpy((char *)ap.ssid.val, (char*)arg, sizeof(ap.ssid.val) - 1); printf("[ATW3]: _AT_WLAN_AP_SET_SSID_ [%s]\n\r", ap.ssid.val); exit: @@ -805,7 +810,8 @@ void fATW4(void *arg){ ret = RTW_BADARG; goto exit; } - strncpy((char *)password, (char*)arg, sizeof(password)); + memset((char *)ap.ssid.val, '\0', sizeof(ap.ssid.val)); + strncpy((char *)password, (char*)arg, sizeof(password) - 1); ap.password = password; ap.password_len = strlen((char*)arg); printf("[ATW4]: _AT_WLAN_AP_SET_SEC_KEY_ [%s]\n\r", ap.password); @@ -1125,7 +1131,7 @@ void fATWC(void *arg){ /* To avoid gcc warnings */ ( void ) arg; - int mode, ret; + int mode = 0, ret = 0; unsigned long tick1 = xTaskGetTickCount(); unsigned long tick2, tick3; char empty_bssid[6] = {0}, assoc_by_bssid = 0; @@ -1293,7 +1299,8 @@ void fATWs(void *arg){ char *argv[MAX_ARGC] = {0}; printf("[ATWs]: _AT_WLAN_SCAN_WITH_SSID_ [%s]\n\r", (char*)wifi.ssid.val); if(arg){ - strncpy(buf, arg, sizeof(buf)); + memset(buf, '\0', sizeof(buf)); + strncpy(buf, arg, sizeof(buf) - 1); argc = parse_param(buf, argv); if(argc == 2){ scan_buf_len = atoi(argv[1]); @@ -1854,7 +1861,7 @@ void fATXP(void *arg) int argc = 0; char *argv[MAX_ARGC] = {0}; int ret = 0; - int mode, dtim; + int mode = 0, dtim = 0; int tdma_slot_period, tdma_rfon_period_len_1, tdma_rfon_period_len_2, tdma_rfon_period_len_3; #if defined(CONFIG_INIC_CMD_RSP) && CONFIG_INIC_CMD_RSP char *res = NULL; diff --git a/component/common/api/at_cmd/log_service.c b/component/common/api/at_cmd/log_service.c index 53ee8916..61b8d658 100644 --- a/component/common/api/at_cmd/log_service.c +++ b/component/common/api/at_cmd/log_service.c @@ -1,13 +1,11 @@ #include #include #include -#include "FreeRTOS.h" #if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1) #include "freertos_pmu.h" #endif #include "log_service.h" -#include "task.h" -#include "semphr.h" +#include "osdep_service.h" #include "main.h" //#include "wifi_util.h" #include "atcmd_wifi.h" @@ -46,11 +44,11 @@ char log_buf[LOG_SERVICE_BUFLEN]; char log_history[LOG_HISTORY_LEN][LOG_SERVICE_BUFLEN]; static unsigned int log_history_count = 0; #endif -xSemaphoreHandle log_rx_interrupt_sema = NULL; +_sema log_rx_interrupt_sema = NULL; #if CONFIG_LOG_SERVICE_LOCK -xSemaphoreHandle log_service_sema = NULL; +_sema log_service_sema = NULL; #endif -extern xSemaphoreHandle uart_rx_interrupt_sema; +extern _sema uart_rx_interrupt_sema; #if CONFIG_INIC_EN extern unsigned char inic_cmd_ioctl; @@ -237,8 +235,10 @@ void* log_handler(char *cmd) token = strtok(copy, "="); param = strtok(NULL, "\0"); #endif - if(token && (strlen(token) <= 4)) - strcpy(tok, token); + if(token && (strlen(token) <= 4)) { + memset(tok, '\0',sizeof(tok)); + strncpy(tok, token, sizeof(tok) - 1); + } else{ //printf("\n\rAT Cmd format error!\n"); return NULL; @@ -268,7 +268,8 @@ int parse_param(char *buf, char **argv) if(buf == NULL) goto exit; - strcpy(temp_buf, buf); + memset(temp_buf, '\0', sizeof(temp_buf)); + strncpy(temp_buf, buf, sizeof(temp_buf) - 1); while((argc < MAX_ARGC) && (*buf_pos != '\0')) { while((*buf_pos == ',') || (*buf_pos == '[') || (*buf_pos == ']')){ @@ -460,7 +461,7 @@ void log_service(void *param) #else _AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ALWAYS, "\n\r[MEM] After do cmd, available heap %d\n\r", xPortGetFreeHeapSize()); #endif - _AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ALWAYS, "\r\n\n#\r\n"); //"#" is needed for mp tool + _AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ALWAYS, "\r\n\n# "); //"#" is needed for mp tool #if (defined(CONFIG_EXAMPLE_UART_ATCMD) && CONFIG_EXAMPLE_UART_ATCMD) if(atcmd_lwip_is_tt_mode()) at_printf(STR_END_OF_ATDATA_RET); diff --git a/component/common/api/lwip_netconf.c b/component/common/api/lwip_netconf.c index f4f53f42..5936d18e 100644 --- a/component/common/api/lwip_netconf.c +++ b/component/common/api/lwip_netconf.c @@ -690,9 +690,9 @@ void LwIP_SetDNS(struct ip_addr* dns) #endif void LwIP_UseStaticIP(struct netif *pnetif) { - struct ip_addr ipaddr; - struct ip_addr netmask; - struct ip_addr gw; + struct ip_addr ipaddr = {0}; + struct ip_addr netmask = {0}; + struct ip_addr gw = {0}; /* Static address used */ if(pnetif->name[1] == '0'){ diff --git a/component/common/api/wifi/wifi_conf.c b/component/common/api/wifi/wifi_conf.c index dc1c6a61..210686f3 100644 --- a/component/common/api/wifi/wifi_conf.c +++ b/component/common/api/wifi/wifi_conf.c @@ -806,7 +806,7 @@ int wifi_connect( int key_id, void *semaphore) { - _sema join_semaphore; + _sema join_semaphore = {0}; rtw_result_t result = RTW_SUCCESS; u8 wep_hex = 0; u8 wep_pwd[14] = {0}; @@ -1023,7 +1023,7 @@ int wifi_connect_bssid( int key_id, void *semaphore) { - _sema join_semaphore; + _sema join_semaphore = {0}; rtw_result_t result = RTW_SUCCESS; u8 wep_hex = 0; u8 wep_pwd[14] = {0}; @@ -1277,7 +1277,7 @@ int wifi_set_mac_address(char * mac) int wifi_get_mac_address(char * mac) { int ret = 0; - char buf[32]; + char buf[32] = {0}; rtw_memset(buf, 0, sizeof(buf)); rtw_memcpy(buf, "read_mac", 8); ret = wext_private_command_with_retval(WLAN0_NAME, buf, buf, 32); @@ -1443,7 +1443,7 @@ int wifi_set_channel_plan(uint8_t channel_plan) int wifi_get_channel_plan(uint8_t *channel_plan) { int ret = 0; - char buf[24]; + char buf[24] = {0}; char *ptmp; rtw_memset(buf, 0, sizeof(buf)); @@ -1715,7 +1715,7 @@ int wifi_set_mode(rtw_mode_t mode) #ifdef CONFIG_WLAN_SWITCH_MODE rtw_mode_t curr_mode, next_mode; #if defined(CONFIG_AUTO_RECONNECT) && CONFIG_AUTO_RECONNECT - u8 autoreconnect_mode; + u8 autoreconnect_mode = 0; #endif #endif device_mutex_lock(RT_DEV_LOCK_WLAN); @@ -2279,6 +2279,16 @@ void wifi_scan_done_hdl( char* buf, int buf_len, int flags, void* userdata) return; } +void wifi_scan_done_hdl_mcc( char* buf, int buf_len, int flags, void* userdata) +{ +#if SCAN_USE_SEMAPHORE + rtw_up_sema(&scan_result_handler_ptr.scan_semaphore); +#else + scan_result_handler_ptr.scan_running = 0; +#endif + return; +} + //int rtk_wifi_scan(char *buf, int buf_len, xSemaphoreHandle * semaphore) int wifi_scan(rtw_scan_type_t scan_type, rtw_bss_type_t bss_type, @@ -2692,6 +2702,133 @@ int wifi_scan_networks(rtw_scan_result_handler_t results_handler, void* user_dat rtw_memset((void *)&scan_result_handler_ptr, 0, sizeof(scan_result_handler_ptr)); return RTW_ERROR; } + +/* + * SCAN_DONE_INTERVAL is the interval between each channel scan done, + * to make AP mode can send beacon during this interval. + * It is to fix client disconnection when doing wifi scan in AP/concurrent mode. + * User can fine tune SCAN_DONE_INTERVAL value. + */ +#define SCAN_DONE_INTERVAL 100 //100ms + +/* + * Noted : the scan channel list needs to be modified depending on user's channel plan. + */ +#define SCAN_CHANNEL_NUM 13 //2.4GHz +u8 scan_channel_list[SCAN_CHANNEL_NUM] = {1,2,3,4,5,6,7,8,9,10,11,12,13}; + +int wifi_scan_networks_mcc(rtw_scan_result_handler_t results_handler, void* user_data) +{ + unsigned int max_ap_size = 64; + u8 channel_index; + u8 pscan_config; + int ret; + + /* lock 2s to forbid suspend under scan */ + rtw_wakelock_timeout(2*1000); + + for(channel_index=0;channel_index 0) + { + rtw_msleep_os(5); + count --; + } + if(count == 0){ + printf("\n\r[%d]WiFi: Scan is running. Wait 1s timeout.", rtw_get_current_time()); + return RTW_TIMEOUT; + } + } + + if(channel_index != 0) + vTaskDelay(SCAN_DONE_INTERVAL); + + scan_result_handler_ptr.scan_running = 1; + scan_result_handler_ptr.scan_start_time = rtw_get_current_time(); +#endif + if(channel_index == 0){ + scan_result_handler_ptr.gscan_result_handler = results_handler; + + scan_result_handler_ptr.max_ap_size = max_ap_size; + scan_result_handler_ptr.ap_details = (rtw_scan_result_t*)rtw_zmalloc(max_ap_size*sizeof(rtw_scan_result_t)); + if(scan_result_handler_ptr.ap_details == NULL){ + goto err_exit; + } + rtw_memset(scan_result_handler_ptr.ap_details, 0, max_ap_size*sizeof(rtw_scan_result_t)); + + scan_result_handler_ptr.pap_details = (rtw_scan_result_t**)rtw_zmalloc(max_ap_size*sizeof(rtw_scan_result_t*)); + if(scan_result_handler_ptr.pap_details == NULL) + goto error2_with_result_ptr; + rtw_memset(scan_result_handler_ptr.pap_details, 0, max_ap_size*sizeof(rtw_scan_result_t*)); + + scan_result_handler_ptr.scan_cnt = 0; + + scan_result_handler_ptr.scan_complete = RTW_FALSE; + scan_result_handler_ptr.user_data = user_data; + wifi_reg_event_handler(WIFI_EVENT_SCAN_RESULT_REPORT, wifi_scan_each_report_hdl, NULL); + wifi_reg_event_handler(WIFI_EVENT_SCAN_DONE, wifi_scan_done_hdl_mcc, NULL); + } + if(channel_index == SCAN_CHANNEL_NUM-1){ + wifi_unreg_event_handler(WIFI_EVENT_SCAN_DONE, wifi_scan_done_hdl_mcc); + wifi_reg_event_handler(WIFI_EVENT_SCAN_DONE, wifi_scan_done_hdl, NULL); + } + + pscan_config = PSCAN_ENABLE; + //set partial scan for entering to listen beacon quickly + ret = wifi_set_pscan_chan(&scan_channel_list[channel_index], &pscan_config, 1); + if(ret < 0){ +#if SCAN_USE_SEMAPHORE + rtw_up_sema(&scan_result_handler_ptr.scan_semaphore); +#else + scan_result_handler_ptr.scan_running = 0; +#endif + if(channel_index == SCAN_CHANNEL_NUM-1) { + wifi_scan_done_hdl(NULL, 0, 0, NULL); + } + continue; + } + + if ( wext_set_scan(WLAN0_NAME, NULL, 0, (RTW_SCAN_COMMAMD<<4 | RTW_SCAN_TYPE_ACTIVE | (RTW_BSS_TYPE_ANY << 8))) != RTW_SUCCESS) + { + goto error1_with_result_ptr; + } + } + + return RTW_SUCCESS; + +error1_with_result_ptr: + wifi_unreg_event_handler(WIFI_EVENT_SCAN_DONE, wifi_scan_done_hdl_mcc); + wifi_unreg_event_handler(WIFI_EVENT_SCAN_RESULT_REPORT, wifi_scan_each_report_hdl); + wifi_unreg_event_handler(WIFI_EVENT_SCAN_DONE, wifi_scan_done_hdl); + rtw_free((u8*)scan_result_handler_ptr.pap_details); + scan_result_handler_ptr.pap_details = NULL; + +error2_with_result_ptr: + rtw_free((u8*)scan_result_handler_ptr.ap_details); + scan_result_handler_ptr.ap_details = NULL; + +err_exit: + rtw_memset((void *)&scan_result_handler_ptr, 0, sizeof(scan_result_handler_ptr)); + return RTW_ERROR; +} + //----------------------------------------------------------------------------// int wifi_set_pscan_chan(__u8 * channel_list,__u8 * pscan_config, __u8 length) { @@ -3388,7 +3525,7 @@ int wifi_get_antenna_info(unsigned char *antenna) { int ret = 0; int ant; - char buf[32]; + char buf[32] = {0}; rtw_memset(buf, 0, sizeof(buf)); rtw_memcpy(buf, "get_ant_info", 12); ret = wext_private_command_with_retval(WLAN0_NAME, buf, buf, 32); @@ -3408,6 +3545,7 @@ void wifi_suspend_softap(void) int count; rtw_mac_t mac_list[AP_STA_NUM]; } client_info; + memset(&client_info, 0, sizeof(client_info)); client_info.count = AP_STA_NUM; wifi_get_associated_client_list(&client_info, sizeof(client_info)); for(client_number = 0; client_number < client_info.count; client_number ++) { @@ -3423,6 +3561,7 @@ void wifi_suspend_softap_beacon(void) int count; rtw_mac_t mac_list[AP_STA_NUM]; } client_info; + memset(&client_info, 0, sizeof(client_info)); client_info.count = AP_STA_NUM; wifi_get_associated_client_list(&client_info, sizeof(client_info)); for(client_number = 0; client_number < client_info.count; client_number ++) { @@ -3692,4 +3831,25 @@ u32 wifi_set_pmf(unsigned char pmf_mode){ #endif #endif +#ifdef CONFIG_MCC_STA_AP_MODE +extern int rltk_wlan_txrpt_statistic(const char *ifname, rtw_fw_txrpt_stats_t *txrpt_stats); +extern int rltk_wlan_ccx_txrpt_retry(rtw_fw_txrpt_retry_t *txrpt_retry); +extern void rltk_wlan_enable_ccx_txrpt(const char *ifname, int enable); + +int wifi_get_txrpt_statistic(const char *ifname, rtw_fw_txrpt_stats_t *txrpt_stats) +{ + return rltk_wlan_txrpt_statistic(ifname, txrpt_stats); +} + +int wifi_get_ccx_txrpt_retry(rtw_fw_txrpt_retry_t *txrpt_retry) +{ + return rltk_wlan_ccx_txrpt_retry(txrpt_retry); +} + +void wifi_enable_ccx_txrpt(const char *ifname, int enable) +{ + rltk_wlan_enable_ccx_txrpt(ifname, enable); +} +#endif + #endif //#if CONFIG_WLAN diff --git a/component/common/api/wifi/wifi_simple_config.c b/component/common/api/wifi/wifi_simple_config.c index f4c3ddba..e5de34ee 100644 --- a/component/common/api/wifi/wifi_simple_config.c +++ b/component/common/api/wifi/wifi_simple_config.c @@ -1,8 +1,7 @@ #include #include #include -#include "FreeRTOS.h" -#include "task.h" +#include "osdep_service.h" #include "main.h" #include "udp.h" #include @@ -75,8 +74,8 @@ static int is_need_connect_to_AP = 0; static u8 mac_addr[6]; extern int get_sc_profile_fmt(void); -extern int get_sc_profile_info(void *fmt_info_t); -extern int get_sc_dsoc_info(void *dsoc_info_t); +extern void get_sc_profile_info(void *fmt_info_t); +extern void get_sc_dsoc_info(void *dsoc_info_t); extern int rtl_dsoc_parse(u8 *mac_addr, u8 *buf, void *userdata, unsigned int *len); void filter1_add_enable(void); extern void remove_filter(void); @@ -730,7 +729,7 @@ enum sc_result SC_parse_scan_result_and_connect(scan_buf_arg* scan_buf, rtw_netw int parsed_len = 0; u8 scan_channel = 0; int i = 0; - enum sc_result ret; + enum sc_result ret = -1; u8 pscan_config = PSCAN_ENABLE | PSCAN_SIMPLE_CONFIG; memset((void*)&scan_result, 0, sizeof(struct scan_with_ssid_result)); @@ -990,10 +989,10 @@ int sc_set_val2(rtw_network_info_t *wifi) enum sc_result SC_connect_to_AP(void) { enum sc_result ret = SC_ERROR; - u8 scan_channel; + u8 scan_channel = 0; u8 pscan_config; int max_retry = 5, retry = 0; - rtw_security_t security_mode; + rtw_security_t security_mode = 0; rtw_network_info_t wifi = {0}; if(!(fixed_channel_num == 0)){ scan_channel = fixed_channel_num; diff --git a/component/common/api/wifi/wifi_util.c b/component/common/api/wifi/wifi_util.c index 0ac05f17..44a5f50c 100644 --- a/component/common/api/wifi/wifi_util.c +++ b/component/common/api/wifi/wifi_util.c @@ -69,7 +69,7 @@ int wext_set_bssid(const char *ifname, const __u8 *bssid) memcpy(iwr.u.ap_addr.sa_data, bssid, ETH_ALEN); if(bssid[ETH_ALEN]=='#' && bssid[ETH_ALEN + 1]=='@'){ - memcpy(iwr.u.ap_addr.sa_data + ETH_ALEN, bssid + ETH_ALEN, 6); + memcpy(iwr.u.ap_addr.sa_data + ETH_ALEN, bssid + ETH_ALEN, 2); } if (iw_ioctl(ifname, SIOCSIWAP, &iwr) < 0) { diff --git a/component/common/application/mqtt/MQTTClient/MQTTClient.c b/component/common/application/mqtt/MQTTClient/MQTTClient.c index f4071626..65fec30d 100644 --- a/component/common/application/mqtt/MQTTClient/MQTTClient.c +++ b/component/common/application/mqtt/MQTTClient/MQTTClient.c @@ -1,38 +1,34 @@ /******************************************************************************* - * Copyright (c) 2014, 2015 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Allan Stockdill-Mander/Ian Craggs - initial API and implementation and/or initial documentation - *******************************************************************************/ +* Copyright (c) 2014, 2017 IBM Corp. +* +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* and Eclipse Distribution License v1.0 which accompany this distribution. +* +* The Eclipse Public License is available at +* http://www.eclipse.org/legal/epl-v10.html +* and the Eclipse Distribution License is available at +* http://www.eclipse.org/org/documents/edl-v10.php. +* +* Contributors: +* Allan Stockdill-Mander/Ian Craggs - initial API and implementation and/or initial documentation +* Ian Craggs - fix for #96 - check rem_len in readPacket +* Ian Craggs - add ability to set message handler separately #6 +*******************************************************************************/ #include "MQTTClient.h" -const char * const msg_types_str[]= -{ - "Reserved", - "CONNECT", - "CONNACK", - "PUBLISH", - "PUBACK", - "PUBREC", - "PUBREL", - "PUBCOMP", - "SUBSCRIBE", - "SUBACK", - "UNSUBSCRIBE", - "UNSUBACK", - "PINGREQ", - "PINGRESP", - "DISCONNECT", - "Reserved" -}; + +#include +#include +#if defined(MQTTV5) +#include "MQTTProperties.h" +#include "MQTTV5Subscribe.h" +#include "MQTTV5Connect.h" +#include "MQTTV5Publish.h" +#include "MQTTV5Unsubscribe.h" +#endif + +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) + const char * const mqtt_status_str[]= { "MQTT_START", @@ -41,133 +37,192 @@ const char * const mqtt_status_str[]= "MQTT_RUNNING" }; +struct GetReason +{ + int code; + const char* reason; +} GetReason[] = +{ + {0, "Success | Normal disconnection | Granted QoS 0"}, + {1, "Granted QoS 1"}, + {2, "Granted QoS 2"}, + {4, "Disconnect with Will Message"}, + {16, "No matching subscribers"}, + {17, "No subscription existed"}, + {24, "Continue authentication"}, + {25, "Re-authenticate "}, + {128, "Unspecified error"}, + {129, "Malformed Packet"}, + {130, "Protocol Error"}, + {131, "Implementation specific error"}, + {132, "Unsupported Protocol Version"}, + {133, "Client Identifier not valid"}, + {134, "Bad User Name or Password"}, + {135, "Not authorized"}, + {136, "Server unavailable"}, + {137, "Server busy"}, + {138, "Banned"}, + {139, "Server shutting down"}, + {140, "Bad authentication method"}, + {141, "Keep Alive timeout"}, + {142, "Session taken over"}, + {143, "Topic Filter invalid "}, + {144, "Topic Name invalid"}, + {145, "Packet Identifier in use"}, + {146, "Packet Identifier not found"}, + {147, "Receive Maximum exceeded"}, + {148, "Topic Alias invalid"}, + {149, "Packet too large"}, + {150, "Message rate too high"}, + {151, "Quota exceeded"}, + {152, "Administrative action"}, + {153, "Payload format invalid "}, + {154, "Retain not supported"}, + {155, "QoS not supported "}, + {156, "Use another server"}, + {157, "Server moved"}, + {158, "Shared Subscriptions not supported"}, + {159, "Connection rate exceeded"}, + {160, "Maximum connect time"}, + {161, "Subscription Identifiers not supported"}, + {162, "Wildcard Subscriptions not supported"} +}; + static void NewMessageData(MessageData* md, MQTTString* aTopicName, MQTTMessage* aMessage) { - md->topicName = aTopicName; - md->message = aMessage; + md->topicName = aTopicName; + md->message = aMessage; } static int getNextPacketId(MQTTClient *c) { - return c->next_packetid = (c->next_packetid == MAX_PACKET_ID) ? 1 : c->next_packetid + 1; + return c->next_packetid = (c->next_packetid == MAX_PACKET_ID) ? 1 : c->next_packetid + 1; } static int sendPacket(MQTTClient* c, int length, Timer* timer) { - int rc = FAILURE, - sent = 0; - - while (sent < length && !TimerIsExpired(timer)) - { - rc = c->ipstack->mqttwrite(c->ipstack, &c->buf[sent], length, TimerLeftMS(timer)); - if (rc < 0) // there was an error writing the data - break; - sent += rc; - } - if (sent == length) - { - TimerCountdown(&c->ping_timer, c->keepAliveInterval); // record the fact that we have successfully sent the packet - rc = SUCCESS; - } - else{ - rc = FAILURE; - mqtt_printf(MQTT_DEBUG, "Send packet failed"); - } - - if (c->ipstack->my_socket < 0) { - c->isconnected = 0; - } - - return rc; + int rc = FAILURE, + sent = 0; + //goto exit and return failure if packet > max packet size +#if defined(MQTTV5) + //The Client MUST NOT send packets exceeding Maximum Packet Size to the Server + if(length > gMaxPacketSize) + goto exit; +#endif + while (sent < length && !TimerIsExpired(timer)) + { + rc = c->ipstack->mqttwrite(c->ipstack, &c->buf[sent], length, TimerLeftMS(timer)); + if (rc < 0) // there was an error writing the data + break; + sent += rc; + } + if (sent == length) + { + TimerCountdown(&c->last_sent, c->keepAliveInterval); // record the fact that we have successfully sent the packet + rc = SUCCESS; + } + else + rc = FAILURE; +#if defined(MQTTV5) +exit: +#endif + return rc; } void MQTTClientInit(MQTTClient* c, Network* network, unsigned int command_timeout_ms, - unsigned char* sendbuf, size_t sendbuf_size, unsigned char* readbuf, size_t readbuf_size) -{ - int i; - c->ipstack = network; - - for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) - c->messageHandlers[i].topicFilter = 0; - c->command_timeout_ms = command_timeout_ms; - c->buf = sendbuf; - c->buf_size = sendbuf_size; - c->readbuf = readbuf; - c->readbuf_size = readbuf_size; - c->isconnected = 0; - c->ping_outstanding = 0; - c->defaultMessageHandler = NULL; +unsigned char* sendbuf, size_t sendbuf_size, unsigned char* readbuf, size_t readbuf_size) +{ + int i; + c->ipstack = network; + + for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) + c->messageHandlers[i].topicFilter = 0; + c->command_timeout_ms = command_timeout_ms; + c->buf = sendbuf; + c->buf_size = sendbuf_size; + c->readbuf = readbuf; + c->readbuf_size = readbuf_size; + c->isconnected = 0; + c->cleansession = 0; + c->ping_outstanding = 0; + c->defaultMessageHandler = NULL; c->next_packetid = 1; - c->ipstack->m2m_rxevent = 0; - c->mqttstatus = MQTT_START; - TimerInit(&c->cmd_timer); - TimerInit(&c->ping_timer); + TimerInit(&c->last_sent); + TimerInit(&c->last_received); + TimerInit(&c->pingresp_timer); + c->ipstack->m2m_rxevent = 0; + c->mqttstatus = MQTT_START; + TimerInit(&c->cmd_timer); + TimerInit(&c->ping_timer); } static int decodePacket(MQTTClient* c, int* value, int timeout) { - unsigned char i; - int multiplier = 1; - int len = 0; - const int MAX_NO_OF_REMAINING_LENGTH_BYTES = 4; - - *value = 0; - do - { - int rc = MQTTPACKET_READ_ERROR; - - if (++len > MAX_NO_OF_REMAINING_LENGTH_BYTES) - { - rc = MQTTPACKET_READ_ERROR; /* bad data */ - goto exit; - } - rc = c->ipstack->mqttread(c->ipstack, &i, 1, timeout); - if (rc != 1) - goto exit; - *value += (i & 127) * multiplier; - multiplier *= 128; - } while ((i & 128) != 0); + unsigned char i; + int multiplier = 1; + int len = 0; + const int MAX_NO_OF_REMAINING_LENGTH_BYTES = 4; + + *value = 0; + do + { + int rc = MQTTPACKET_READ_ERROR; + + if (++len > MAX_NO_OF_REMAINING_LENGTH_BYTES) + { + rc = MQTTPACKET_READ_ERROR; /* bad data */ + goto exit; + } + rc = c->ipstack->mqttread(c->ipstack, &i, 1, timeout); + if (rc != 1) + goto exit; + *value += (i & 127) * multiplier; + multiplier *= 128; + } while ((i & 128) != 0); exit: - return len; + return len; } static int readPacket(MQTTClient* c, Timer* timer) { - int rc = FAILURE; - MQTTHeader header = {0}; - int len = 0; - int rem_len = 0; - - /* 1. read the header byte. This has the packet type in it */ - if (c->ipstack->mqttread(c->ipstack, c->readbuf, 1, TimerLeftMS(timer)) != 1){ - mqtt_printf(MQTT_MSGDUMP, "read packet header failed"); - goto exit; - } - len = 1; - /* 2. read the remaining length. This is variable in itself */ - decodePacket(c, &rem_len, TimerLeftMS(timer)); - len += MQTTPacket_encode(c->readbuf + 1, rem_len); /* put the original remaining length back into the buffer */ - - if(len + rem_len > c->readbuf_size){ - mqtt_printf(MQTT_WARNING, "rem_len = %d, read buffer will overflow", rem_len); - rc = BUFFER_OVERFLOW; - goto exit; - } - /* 3. read the rest of the buffer using a callback to supply the rest of the data */ - if (rem_len > 0 && (c->ipstack->mqttread(c->ipstack, c->readbuf + len, rem_len, TimerLeftMS(timer)) != rem_len)){ - mqtt_printf(MQTT_MSGDUMP, "read the rest of the data failed"); - goto exit; - } - header.byte = c->readbuf[0]; - rc = header.bits.type; + MQTTHeader header = {0}; + int len = 0; + int rem_len = 0; + + /* 1. read the header byte. This has the packet type in it */ + int rc = c->ipstack->mqttread(c->ipstack, c->readbuf, 1, TimerLeftMS(timer)); + mqtt_printf(MQTT_MSGDUMP, "read packet header failed"); + if (rc != 1) + goto exit; + + len = 1; + /* 2. read the remaining length. This is variable in itself */ + decodePacket(c, &rem_len, TimerLeftMS(timer)); + len += MQTTPacket_encode(c->readbuf + 1, rem_len); /* put the original remaining length back into the buffer */ + + if (rem_len > (c->readbuf_size - len)) + { + mqtt_printf(MQTT_WARNING, "rem_len = %d, read buffer will overflow", rem_len); + rc = BUFFER_OVERFLOW; + goto exit; + } + + /* 3. read the rest of the buffer using a callback to supply the rest of the data */ + if (rem_len > 0 && (rc = c->ipstack->mqttread(c->ipstack, c->readbuf + len, rem_len, TimerLeftMS(timer)) != rem_len)) { + rc = 0; + mqtt_printf(MQTT_MSGDUMP, "read the rest of the data failed"); + goto exit; + } + + header.byte = c->readbuf[0]; + rc = header.bits.type; + if (c->keepAliveInterval > 0) + TimerCountdown(&c->last_received, c->keepAliveInterval); // record the fact that we have successfully received a packet exit: - if (c->ipstack->my_socket < 0) { - c->isconnected = 0; - } - return rc; + return rc; } @@ -176,437 +231,271 @@ static int readPacket(MQTTClient* c, Timer* timer) // + and # can only be next to separator static char isTopicMatched(char* topicFilter, MQTTString* topicName) { - char* curf = topicFilter; - char* curn = topicName->lenstring.data; - char* curn_end = curn + topicName->lenstring.len; - - while (*curf && curn < curn_end) - { - if (*curn == '/' && *curf != '/') - break; - if (*curf != '+' && *curf != '#' && *curf != *curn) - break; - if (*curf == '+') - { // skip until we meet the next separator, or end of string - char* nextpos = curn + 1; - while (nextpos < curn_end && *nextpos != '/') - nextpos = ++curn + 1; - } - else if (*curf == '#') - curn = curn_end - 1; // skip until end of string - curf++; - curn++; - }; - - return (curn == curn_end) && (*curf == '\0'); + char* curf = topicFilter; + char* curn = topicName->lenstring.data; + char* curn_end = curn + topicName->lenstring.len; + + while (*curf && curn < curn_end) + { + if (*curn == '/' && *curf != '/') + break; + if (*curf != '+' && *curf != '#' && *curf != *curn) + break; + if (*curf == '+') + { // skip until we meet the next separator, or end of string + char* nextpos = curn + 1; + while (nextpos < curn_end && *nextpos != '/') + nextpos = ++curn + 1; + } + else if (*curf == '#') + curn = curn_end - 1; // skip until end of string + curf++; + curn++; + }; + + return (curn == curn_end) && (*curf == '\0'); } int deliverMessage(MQTTClient* c, MQTTString* topicName, MQTTMessage* message) { - int i; - int rc = FAILURE; - - // we have to find the right message handler - indexed by topic - for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) - { - if (c->messageHandlers[i].topicFilter != 0 && (MQTTPacket_equals(topicName, (char*)c->messageHandlers[i].topicFilter) || - isTopicMatched((char*)c->messageHandlers[i].topicFilter, topicName))) - { - if (c->messageHandlers[i].fp != NULL) - { - MessageData md; - NewMessageData(&md, topicName, message); - c->messageHandlers[i].fp(&md); - rc = SUCCESS; - } - } - } - - if (rc == FAILURE && c->defaultMessageHandler != NULL) - { - MessageData md; - NewMessageData(&md, topicName, message); - c->defaultMessageHandler(&md); - rc = SUCCESS; - } - - return rc; + int i; + int rc = FAILURE; + + // we have to find the right message handler - indexed by topic + for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) + { + if (c->messageHandlers[i].topicFilter != 0 && (MQTTPacket_equals(topicName, (char*)c->messageHandlers[i].topicFilter) || + isTopicMatched((char*)c->messageHandlers[i].topicFilter, topicName))) + { + if (c->messageHandlers[i].fp != NULL) + { + MessageData md; + NewMessageData(&md, topicName, message); + c->messageHandlers[i].fp(&md); + rc = SUCCESS; + } + } + } + + if (rc == FAILURE && c->defaultMessageHandler != NULL) + { + MessageData md; + NewMessageData(&md, topicName, message); + c->defaultMessageHandler(&md); + rc = SUCCESS; + } + + return rc; } int keepalive(MQTTClient* c) { - int rc = FAILURE; - - if (c->keepAliveInterval == 0) - { - rc = SUCCESS; - goto exit; - } - - if (TimerIsExpired(&c->ping_timer)) - { - if (!c->ping_outstanding) - { - Timer timer; - TimerInit(&timer); - TimerCountdownMS(&timer, 1000); - int len = MQTTSerialize_pingreq(c->buf, c->buf_size); - if (len > 0 && (rc = sendPacket(c, len, &timer)) == SUCCESS) // send the ping packet - c->ping_outstanding = 1; - } - } + int rc = SUCCESS; -exit: - return rc; -} + if (c->keepAliveInterval == 0) + goto exit; + // If we are waiting for a ping response, check if it has been too long + if (c->ping_outstanding) + { + if (TimerIsExpired(&c->pingresp_timer)) + { + rc = FAILURE; /* PINGRESP not received in keepalive interval */ + goto exit; + } + } else + { + // If we have not sent or received anything in the timeout period, + // send out a ping request + if (TimerIsExpired(&c->last_sent) || TimerIsExpired(&c->last_received)) + { + Timer timer; + + TimerInit(&timer); + TimerCountdownMS(&timer, 1000); + int len = MQTTSerialize_pingreq(c->buf, c->buf_size); + if (len > 0 && (rc = sendPacket(c, len, &timer)) == SUCCESS) + { + // send the ping packet + // Expect the PINGRESP within 2 seconds of the PINGREQ + // being sent + TimerCountdownMS(&c->pingresp_timer, 2000 ); + c->ping_outstanding = 1; + } + } + } -int cycle(MQTTClient* c, Timer* timer) -{ - // read the socket, see what work is due - unsigned short packet_type = readPacket(c, timer); - int len = 0, rc = SUCCESS; - - if (packet_type == (unsigned short)BUFFER_OVERFLOW || packet_type == (unsigned short)FAILURE) { - rc = FAILURE; - goto exit; - } - - mqtt_printf(MQTT_DEBUG, "Read packet type: %d", packet_type); - switch (packet_type) - { - case CONNACK: - case PUBACK: - case SUBACK: - break; - case PUBLISH: - { - MQTTString topicName; - MQTTMessage msg; - int intQoS; - if (MQTTDeserialize_publish(&msg.dup, &intQoS, &msg.retained, &msg.id, &topicName, - (unsigned char**)&msg.payload, (int*)&msg.payloadlen, c->readbuf, c->readbuf_size) != 1) - goto exit; - msg.qos = (enum QoS)intQoS; - deliverMessage(c, &topicName, &msg); - if (msg.qos != QOS0) - { - if (msg.qos == QOS1) - len = MQTTSerialize_ack(c->buf, c->buf_size, PUBACK, 0, msg.id); - else if (msg.qos == QOS2) - len = MQTTSerialize_ack(c->buf, c->buf_size, PUBREC, 0, msg.id); - if (len <= 0) - rc = FAILURE; - else - rc = sendPacket(c, len, timer); - - if (rc == FAILURE) - goto exit; // there was a problem - } - break; - } - case PUBREC: - { - unsigned short mypacketid; - unsigned char dup, type; - if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1) - rc = FAILURE; - else if ((len = MQTTSerialize_ack(c->buf, c->buf_size, PUBREL, 0, mypacketid)) <= 0) - rc = FAILURE; - else if ((rc = sendPacket(c, len, timer)) != SUCCESS) // send the PUBREL packet - rc = FAILURE; // there was a problem - if (rc == FAILURE) - goto exit; // there was a problem - break; - } - case PUBREL: - { - unsigned short mypacketid; - unsigned char dup, type; - if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1) - rc = FAILURE; - else if ((len = MQTTSerialize_ack(c->buf, c->buf_size, PUBCOMP, 0, mypacketid)) <= 0) - rc = FAILURE; - else if ((rc = sendPacket(c, len, timer)) != SUCCESS) // send the PUBREL packet - rc = FAILURE; // there was a problem - if (rc == FAILURE) - goto exit; // there was a problem - break; - } - case PUBCOMP: - break; - case PINGRESP: - c->ping_outstanding = 0; - break; - } exit: - keepalive(c); - if (rc == SUCCESS) - rc = packet_type; - return rc; + return rc; } -int MQTTYield(MQTTClient* c, int timeout_ms) +void MQTTCleanSession(MQTTClient* c) { - int rc = SUCCESS; - Timer timer; - - TimerInit(&timer); - TimerCountdownMS(&timer, timeout_ms); + int i = 0; - do - { - if (cycle(c, &timer) == FAILURE) - { - rc = FAILURE; - break; - } - } while (!TimerIsExpired(&timer)); - - return rc; + for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) + c->messageHandlers[i].topicFilter = NULL; } -int waitfor(MQTTClient* c, int packet_type, Timer* timer) -{ - int rc = FAILURE; - - do - { - if (TimerIsExpired(timer)) - break; // we timed out - } - while ((rc = cycle(c, timer)) != packet_type); - - return rc; -} - -int MQTTConnect(MQTTClient* c, MQTTPacket_connectData* options) +void MQTTCloseSession(MQTTClient* c) { - Timer connect_timer; - int rc = FAILURE; - MQTTPacket_connectData default_options = MQTTPacket_connectData_initializer; - int len = 0; - - if (c->isconnected) /* don't send connect packet again if we are already connected */ - goto exit; - - TimerInit(&connect_timer); - TimerCountdownMS(&connect_timer, c->command_timeout_ms); - - if (options == 0) - options = &default_options; /* set default options if none were supplied */ - - c->keepAliveInterval = options->keepAliveInterval; - TimerCountdown(&c->ping_timer, c->keepAliveInterval); - if ((len = MQTTSerialize_connect(c->buf, c->buf_size, options)) <= 0) - goto exit; - if ((rc = sendPacket(c, len, &connect_timer)) != SUCCESS) // send the connect packet - goto exit; // there was a problem - -#if defined(WAIT_FOR_ACK) - // this will be a blocking call, wait for the connack - if (waitfor(c, CONNACK, &connect_timer) == CONNACK) - { - unsigned char connack_rc = 255; - unsigned char sessionPresent = 0; - if (MQTTDeserialize_connack(&sessionPresent, &connack_rc, c->readbuf, c->readbuf_size) == 1) - rc = connack_rc; - else - rc = FAILURE; - } - else{ - mqtt_printf(MQTT_DEBUG, "Not received CONNACK"); - rc = FAILURE; - } -#endif -exit: - if (rc == SUCCESS) - c->isconnected = 1; - - return rc; + c->ping_outstanding = 0; + c->isconnected = 0; + if (c->cleansession) + MQTTCleanSession(c); } -int MQTTSubscribe(MQTTClient* c, const char* topicFilter, enum QoS qos, messageHandler messageHandler) -{ - int rc = FAILURE; - Timer timer; - int len = 0; - MQTTString topic = MQTTString_initializer; - topic.cstring = (char *)topicFilter; - - if (!c->isconnected) - goto exit; - - TimerInit(&timer); - TimerCountdownMS(&timer, c->command_timeout_ms); - - len = MQTTSerialize_subscribe(c->buf, c->buf_size, 0, getNextPacketId(c), 1, &topic, (int*)&qos); - if (len <= 0) - goto exit; - if ((rc = sendPacket(c, len, &timer)) != SUCCESS) // send the subscribe packet - goto exit; // there was a problem - -#if defined(WAIT_FOR_ACK) - if (waitfor(c, SUBACK, &timer) == SUBACK) // wait for suback - { - int count = 0, grantedQoS = -1; - unsigned short mypacketid; - if (MQTTDeserialize_suback(&mypacketid, 1, &count, &grantedQoS, c->readbuf, c->readbuf_size) == 1) - rc = grantedQoS; // 0, 1, 2 or 0x80 - if (rc != 0x80) - { - int i; - for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) - { - if (c->messageHandlers[i].topicFilter == topicFilter) - { - rc = 0; - goto exit; //already subscribed - } - } - for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) - { - if (c->messageHandlers[i].topicFilter == 0) - { - c->messageHandlers[i].topicFilter = topicFilter; - c->messageHandlers[i].fp = messageHandler; - rc = 0; - break; - } - } - } - } - else - rc = FAILURE; +int cycle(MQTTClient* c, Timer* timer) +{ + int len = 0, + rc = SUCCESS; +#if defined(MQTTV5) + MQTTProperties ackProperties = MQTTProperties_initializer; + //publish, pubrec, pubrel has total of 9 properties + MQTTProperty ack_props[9]; + ackProperties.max_count = 9; + ackProperties.array = ack_props; + int ReasonCode = -1; #endif -exit: - return rc; -} - - -int MQTTUnsubscribe(MQTTClient* c, const char* topicFilter) -{ - int rc = FAILURE; - Timer timer; - MQTTString topic = MQTTString_initializer; - topic.cstring = (char *)topicFilter; - int len = 0; - - if (!c->isconnected) + int packet_type = readPacket(c, timer); /* read the socket, see what work is due */ + mqtt_printf(MQTT_DEBUG, "Read packet type: %s", MQTTPacketIDPrint(packet_type)); + switch (packet_type) + { + default: + /* no more data to read, unrecoverable. Or read packet fails due to unexpected network error */ + rc = packet_type; goto exit; - - TimerInit(&timer); - TimerCountdownMS(&timer, c->command_timeout_ms); - - if ((len = MQTTSerialize_unsubscribe(c->buf, c->buf_size, 0, getNextPacketId(c), 1, &topic)) <= 0) - goto exit; - if ((rc = sendPacket(c, len, &timer)) != SUCCESS) // send the subscribe packet - goto exit; // there was a problem - -#if defined(WAIT_FOR_ACK) - if (waitfor(c, UNSUBACK, &timer) == UNSUBACK) - { - unsigned short mypacketid; // should be the same as the packetid above - if (MQTTDeserialize_unsuback(&mypacketid, c->readbuf, c->readbuf_size) == 1) - rc = 0; - int i; - for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) - { - if (c->messageHandlers[i].topicFilter == topicFilter) - { - c->messageHandlers[i].topicFilter = 0; - c->messageHandlers[i].fp = NULL; - } - } - } - else - rc = FAILURE; + case 0: /* timed out reading packet */ + break; + case CONNACK: + case PUBACK: + case SUBACK: + case UNSUBACK: + { + break; + } + case PUBLISH: + { + MQTTString topicName; + MQTTMessage msg; + int intQoS; + msg.payloadlen = 0; /* this is a size_t, but deserialize publish sets this as int */ + msg.id = 0; +#if defined(MQTTV5) + if (MQTTV5Deserialize_publish(&msg.dup, &intQoS, &msg.retained, &msg.id, &topicName, &ackProperties, + (unsigned char**)&msg.payload, (int*)&msg.payloadlen, c->readbuf, c->readbuf_size) != 1) +#else + if (MQTTDeserialize_publish(&msg.dup, &intQoS, &msg.retained, &msg.id, &topicName, + (unsigned char**)&msg.payload, (int*)&msg.payloadlen, c->readbuf, c->readbuf_size) != 1) #endif -exit: - return rc; -} - - -int MQTTPublish(MQTTClient* c, const char* topicName, MQTTMessage* message) -{ - int rc = FAILURE; - Timer timer; - MQTTString topic = MQTTString_initializer; - topic.cstring = (char *)topicName; - int len = 0; + goto exit; + //If a Server or Client receives a PUBLISH packet which has both QoS bits set to 1 it is a Malformed Packet. Use DISCONNECT with + //Reason Code 0x81(129) +#if defined(MQTTV5) + if (intQoS > 2) + { + if ((rc = MQTTV5Disconnect(c, 129, NULL)) != 0) + { + mqtt_printf(MQTT_INFO, "Return code from MQTT disconnect is %d\n", rc); + goto exit; + } + mqtt_printf(MQTT_INFO, "Incorrect QOS = %d, Disconnected\n", intQoS); + break; + } +#endif + msg.qos = (enum QoS)intQoS; + deliverMessage(c, &topicName, &msg); + if (msg.qos != QOS0) + { + if (msg.qos == QOS1) +#if defined(MQTTV5) + len = MQTTV5Serialize_ack(c->buf, c->buf_size, PUBACK, 0, msg.id, 0, &ackProperties); +#else + len = MQTTSerialize_ack(c->buf, c->buf_size, PUBACK, 0, msg.id); +#endif + else if (msg.qos == QOS2) +#if defined(MQTTV5) + len = MQTTV5Serialize_ack(c->buf, c->buf_size, PUBREC, 0, msg.id, 0, &ackProperties); +#else + len = MQTTSerialize_ack(c->buf, c->buf_size, PUBREC, 0, msg.id); +#endif + if (len <= 0) + rc = FAILURE; + else + { + rc = sendPacket(c, len, timer); + } + if (rc == FAILURE) + goto exit; // there was a problem + } + break; + } + break; + case PUBREC: + case PUBREL: + { + unsigned short mypacketid = 0; + unsigned char dup, type; +#if defined(MQTTV5) + if (MQTTV5Deserialize_ack(&type, &dup, &mypacketid, &ReasonCode, &ackProperties ,c->readbuf, c->readbuf_size) != 1) +#else + if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1) +#endif + { + rc = FAILURE; // there was a problem + goto exit; + } +#if defined(MQTTV5) + if ((len = MQTTV5Serialize_ack(c->buf, c->buf_size, + (packet_type == PUBREC) ? PUBREL : PUBCOMP, 0, mypacketid, 0, &ackProperties)) <= 0) +#else + if ((len = MQTTSerialize_ack(c->buf, c->buf_size, + (packet_type == PUBREC) ? PUBREL : PUBCOMP, 0, mypacketid)) <= 0) +#endif + { + rc = FAILURE; + goto exit; + } + if ((rc = sendPacket(c, len, timer)) != SUCCESS) // send the PUBREL packet + { + rc = FAILURE; // there was a problem + goto exit; + } + goto exit; // there was a problem + break; + } - if (!c->isconnected) - goto exit; + case PUBCOMP: + { + break; + } + case PINGRESP: + { + c->ping_outstanding = 0; + break; + } +#if defined(MQTTV5) + case DISCONNECT: + if(MQTTV5Deserialize_disconnect(&ackProperties, &ReasonCode, c->readbuf, c->readbuf_size) != 1){ + mqtt_printf(MQTT_DEBUG, "Deserialize DISCONNECT failed"); + } + break; +#endif + } - TimerInit(&timer); - TimerCountdownMS(&timer, c->command_timeout_ms); - - if (message->qos == QOS1 || message->qos == QOS2) - message->id = getNextPacketId(c); - - len = MQTTSerialize_publish(c->buf, c->buf_size, 0, message->qos, message->retained, message->id, - topic, (unsigned char*)message->payload, message->payloadlen); - if (len <= 0) - goto exit; - if ((rc = sendPacket(c, len, &timer)) != SUCCESS) // send the subscribe packet - goto exit; // there was a problem - -#if defined(WAIT_FOR_ACK) - if (message->qos == QOS1) - { - if (waitfor(c, PUBACK, &timer) == PUBACK) - { - unsigned short mypacketid; - unsigned char dup, type; - if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1) - rc = FAILURE; - } - else{ - rc = FAILURE; - mqtt_printf(MQTT_DEBUG, "Not received PUBACK"); - } - } - else if (message->qos == QOS2) - { - if (waitfor(c, PUBCOMP, &timer) == PUBCOMP) - { - unsigned short mypacketid; - unsigned char dup, type; - if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1) - rc = FAILURE; - } - else{ - rc = FAILURE; - mqtt_printf(MQTT_DEBUG, "Not received PUBCOMP"); - } - } -#endif exit: - return rc; -} - - -int MQTTDisconnect(MQTTClient* c) -{ - int rc = FAILURE; - Timer timer; // we might wait for incomplete incoming publishes to complete - int len = 0; - - TimerInit(&timer); - TimerCountdownMS(&timer, c->command_timeout_ms); - - len = MQTTSerialize_disconnect(c->buf, c->buf_size); - if (len > 0) - rc = sendPacket(c, len, &timer); // send the disconnect packet - - c->isconnected = 0; - - return rc; + if (keepalive(c) != SUCCESS) { + //check only keepalive FAILURE status so that previous FAILURE status can be considered as FAULT + rc = FAILURE; + } + if (rc == SUCCESS) + rc = packet_type; + return rc; } #if defined(MQTT_TASK) @@ -615,15 +504,33 @@ void MQTTSetStatus(MQTTClient* c, int mqttstatus) c->mqttstatus = mqttstatus; mqtt_printf(MQTT_INFO, "Set mqtt status to %s", mqtt_status_str[mqttstatus]); } - +#if defined(MQTTV5) +int MQTTDataHandle(MQTTClient* c, fd_set *readfd, MQTTPacket_connectData *connectData, messageHandler messageHandler, char* address, char* topic, MQTTProperties* properties, MQTTProperties* willproperties) +#else int MQTTDataHandle(MQTTClient* c, fd_set *readfd, MQTTPacket_connectData *connectData, messageHandler messageHandler, char* address, char* topic) +#endif { short packet_type = 0; int rc = 0; int mqttstatus = c->mqttstatus; int mqtt_rxevent = 0; int mqtt_fd = c->ipstack->my_socket; - +#if defined(MQTTV5) + struct subscribeOptions opts = {0, 0, 0, 0}; + opts.MaxQOS = 2; + opts.noLocal = 0; + opts.retainAsPublished = 1; + opts.retainHandling = 2; + + MQTTProperties ackproperties; + ackproperties.count = 0; + ackproperties.length = 0; + MQTTProperty ack_props[20]; + ackproperties.array = ack_props; + ackproperties.max_count = 20; + + int reasoncode = -1; +#endif mqtt_rxevent = (mqtt_fd >= 0) ? FD_ISSET( mqtt_fd, readfd) : 0; if(mqttstatus == MQTT_START) { @@ -640,7 +547,11 @@ int MQTTDataHandle(MQTTClient* c, fd_set *readfd, MQTTPacket_connectData *connec mqtt_printf(MQTT_INFO, "Start MQTT connection"); TimerInit(&c->cmd_timer); TimerCountdownMS(&c->cmd_timer, c->command_timeout_ms); +#if defined(MQTTV5) + if ((rc = MQTTV5Connect(c, connectData, properties, willproperties)) != 0){ +#else if ((rc = MQTTConnect(c, connectData)) != 0){ +#endif mqtt_printf(MQTT_INFO, "Return code from MQTT connect is %d\n", rc); goto exit; } @@ -655,52 +566,68 @@ int MQTTDataHandle(MQTTClient* c, fd_set *readfd, MQTTPacket_connectData *connec TimerCountdownMS(&timer, 1000); packet_type = readPacket(c, &timer); if(packet_type > 0 && packet_type < 15) - mqtt_printf(MQTT_DEBUG, "Read packet type is %s", msg_types_str[packet_type]); + mqtt_printf(MQTT_DEBUG, "Read packet type is %s", MQTTPacketIDPrint(packet_type)); else{ mqtt_printf(MQTT_DEBUG, "Read packet type is %d", packet_type); MQTTSetStatus(c, MQTT_START); c->ipstack->disconnect(c->ipstack); rc = FAILURE; goto exit; - } + } } switch(mqttstatus){ - case MQTT_CONNECT: - if (packet_type == CONNACK) - { - unsigned char connack_rc = 255; - unsigned char sessionPresent = 0; - if (MQTTDeserialize_connack(&sessionPresent, &connack_rc, c->readbuf, c->readbuf_size) == 1){ - rc = connack_rc; - mqtt_printf(MQTT_INFO, "MQTT Connected"); - TimerInit(&c->cmd_timer); - TimerCountdownMS(&c->cmd_timer, c->command_timeout_ms); - if ((rc = MQTTSubscribe(c, topic, QOS2, messageHandler)) != 0){ - mqtt_printf(MQTT_INFO, "Return code from MQTT subscribe is %d\n", rc); - }else{ - mqtt_printf(MQTT_INFO, "Subscribe to Topic: %s", topic); - MQTTSetStatus(c, MQTT_SUBTOPIC); - } + case MQTT_CONNECT: + if (packet_type == CONNACK) + { + unsigned char connack_rc = 255; + unsigned char sessionPresent = 0; +#if defined(MQTTV5) + if (MQTTV5Deserialize_connack(&ackproperties,&sessionPresent, &connack_rc, c->readbuf, c->readbuf_size) == 1){ +#else + if (MQTTDeserialize_connack(&sessionPresent, &connack_rc, c->readbuf, c->readbuf_size) == 1){ +#endif + rc = connack_rc; + mqtt_printf(MQTT_INFO, "MQTT Connected"); + TimerInit(&c->cmd_timer); + TimerCountdownMS(&c->cmd_timer, c->command_timeout_ms); +#if defined(MQTTV5) + if (gServerKeepAlive > 0) + c->keepAliveInterval = gServerKeepAlive; + if ((rc = MQTTV5Subscribe(c, topic, &opts, messageHandler, properties)) != 0){ +#else + if ((rc = MQTTSubscribe(c, topic, QOS2, messageHandler)) != 0){ +#endif + mqtt_printf(MQTT_INFO, "Return code from MQTT subscribe is %d\n", rc); }else{ - mqtt_printf(MQTT_DEBUG, "Deserialize CONNACK failed"); - rc = FAILURE; + mqtt_printf(MQTT_INFO, "Subscribe to Topic: %s", topic); + MQTTSetStatus(c, MQTT_SUBTOPIC); } - }else if(TimerIsExpired(&c->cmd_timer)){ - mqtt_printf(MQTT_DEBUG, "Not received CONNACK"); + }else{ + mqtt_printf(MQTT_DEBUG, "Deserialize CONNACK failed"); rc = FAILURE; } - if(rc == FAILURE){ - MQTTSetStatus(c, MQTT_START); - } - break; - case MQTT_SUBTOPIC: - if(packet_type == SUBACK){ - int count = 0, grantedQoS = -1; - unsigned short mypacketid; - int isSubscribed = 0; - if (MQTTDeserialize_suback(&mypacketid, 1, &count, &grantedQoS, c->readbuf, c->readbuf_size) == 1){ + }else if(TimerIsExpired(&c->cmd_timer)){ + mqtt_printf(MQTT_DEBUG, "Not received CONNACK"); + rc = FAILURE; + } + if(rc == FAILURE){ + MQTTSetStatus(c, MQTT_START); + } + break; + case MQTT_SUBTOPIC: + if(packet_type == SUBACK){ + int count = 0, grantedQoS = -1; + unsigned short mypacketid; + int isSubscribed = 0; +#if defined(MQTTV5) + if (MQTTV5Deserialize_suback(&mypacketid, &ackproperties, 1, &count, &grantedQoS, c->readbuf, c->readbuf_size) == 1){ +#else + if (MQTTDeserialize_suback(&mypacketid, 1, &count, &grantedQoS, c->readbuf, c->readbuf_size) == 1){ +#endif rc = grantedQoS; // 0, 1, 2 or 0x80 +#if !defined(MQTTV5) mqtt_printf(MQTT_DEBUG, "grantedQoS: %d", grantedQoS); +#endif } if (rc != 0x80) { @@ -714,15 +641,15 @@ int MQTTDataHandle(MQTTClient* c, fd_set *readfd, MQTTPacket_connectData *connec } } if(!isSubscribed) - for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) + for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) + { + if (c->messageHandlers[i].topicFilter == 0) { - if (c->messageHandlers[i].topicFilter == 0) - { - c->messageHandlers[i].topicFilter = topic; - c->messageHandlers[i].fp = messageHandler; - break; - } + c->messageHandlers[i].topicFilter = topic; + c->messageHandlers[i].fp = messageHandler; + break; } + } rc = 0; MQTTSetStatus(c, MQTT_RUNNING); } @@ -734,113 +661,813 @@ int MQTTDataHandle(MQTTClient* c, fd_set *readfd, MQTTPacket_connectData *connec MQTTSetStatus(c, MQTT_START); } break; - case MQTT_RUNNING: - if(packet_type>0){ - int len = 0; - Timer timer; - TimerInit(&timer); - TimerCountdownMS(&timer, 10000); - switch(packet_type){ - case CONNACK: - break; - case PUBACK: - { - unsigned short mypacketid; - unsigned char dup, type; - if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1) - rc = FAILURE; - break; - } - case SUBACK: - break; - case UNSUBACK: - break; - case PUBLISH: - { - MQTTString topicName; - MQTTMessage msg; - int intQoS; - if (MQTTDeserialize_publish(&msg.dup, &intQoS, &msg.retained, &msg.id, &topicName, - (unsigned char**)&msg.payload, (int*)&msg.payloadlen, c->readbuf, c->readbuf_size) != 1) - { - rc = FAILURE; - mqtt_printf(MQTT_DEBUG, "Deserialize PUBLISH failed"); - goto exit; - } - - msg.qos = (enum QoS)intQoS; - deliverMessage(c, &topicName, &msg); - if (msg.qos != QOS0) - { - if (msg.qos == QOS1){ - len = MQTTSerialize_ack(c->buf, c->buf_size, PUBACK, 0, msg.id); - mqtt_printf(MQTT_DEBUG, "send PUBACK"); - }else if (msg.qos == QOS2){ - len = MQTTSerialize_ack(c->buf, c->buf_size, PUBREC, 0, msg.id); - mqtt_printf(MQTT_DEBUG, "send PUBREC"); - }else{ - mqtt_printf(MQTT_DEBUG, "invalid QoS: %d", msg.qos); - } - if (len <= 0){ - rc = FAILURE; - mqtt_printf(MQTT_DEBUG, "Serialize_ack failed"); - goto exit; - }else{ - if((rc = sendPacket(c, len, &timer)) == FAILURE){ - MQTTSetStatus(c, MQTT_START); - goto exit; // there was a problem - } - } - } - break; - } - case PUBREC: - { - unsigned short mypacketid; - unsigned char dup, type; - if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1){ - mqtt_printf(MQTT_DEBUG, "Deserialize PUBREC failed"); - rc = FAILURE; - }else if ((len = MQTTSerialize_ack(c->buf, c->buf_size, PUBREL, 0, mypacketid)) <= 0){ - mqtt_printf(MQTT_DEBUG, "Serialize PUBREL failed"); - rc = FAILURE; - }else if ((rc = sendPacket(c, len, &timer)) != SUCCESS){ // send the PUBREL packet - rc = FAILURE; // there was a problem - MQTTSetStatus(c, MQTT_START); - } - break; + case MQTT_RUNNING: + if(packet_type>0){ + int len = 0; + Timer timer; + TimerInit(&timer); + TimerCountdownMS(&timer, 10000); + switch(packet_type){ + case CONNACK: + break; + case PUBACK: + { + unsigned short mypacketid; + unsigned char dup, type; +#if defined(MQTTV5) + if (MQTTV5Deserialize_ack(&type, &dup, &mypacketid, &reasoncode, &ackproperties, c->readbuf, c->readbuf_size) != 1){ +#else + if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1){ +#endif + rc = FAILURE; + break; + } + } + case SUBACK: + break; + case UNSUBACK: + break; + case PUBLISH: + { + MQTTString topicName; + MQTTMessage msg; + int intQoS; +#if defined(MQTTV5) + if (MQTTV5Deserialize_publish(&msg.dup, &intQoS, &msg.retained, &msg.id, &topicName, &ackproperties, + (unsigned char**)&msg.payload, (int*)&msg.payloadlen, c->readbuf, c->readbuf_size) != 1){ +#else + if (MQTTDeserialize_publish(&msg.dup, &intQoS, &msg.retained, &msg.id, &topicName, + (unsigned char**)&msg.payload, (int*)&msg.payloadlen, c->readbuf, c->readbuf_size) != 1){ +#endif + rc = FAILURE; + mqtt_printf(MQTT_DEBUG, "Deserialize PUBLISH failed"); + goto exit; + } + + msg.qos = (enum QoS)intQoS; + deliverMessage(c, &topicName, &msg); + if (msg.qos != QOS0) + { + if (msg.qos == QOS1){ +#if defined(MQTTV5) + len = MQTTV5Serialize_ack(c->buf, c->buf_size, PUBACK, 0, msg.id, 0, &ackproperties); +#else + len = MQTTSerialize_ack(c->buf, c->buf_size, PUBACK, 0, msg.id); +#endif + mqtt_printf(MQTT_DEBUG, "send PUBACK"); + }else if (msg.qos == QOS2){ +#if defined(MQTTV5) + len = MQTTV5Serialize_ack(c->buf, c->buf_size, PUBREC, 0, msg.id, 0, &ackproperties); +#else + len = MQTTSerialize_ack(c->buf, c->buf_size, PUBREC, 0, msg.id); +#endif + mqtt_printf(MQTT_DEBUG, "send PUBREC"); + }else{ + mqtt_printf(MQTT_DEBUG, "invalid QoS: %d", msg.qos); } - case PUBREL: - { - unsigned short mypacketid; - unsigned char dup, type; - if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1){ - mqtt_printf(MQTT_DEBUG, "Deserialize PUBREL failed"); - rc = FAILURE; - }else if ((len = MQTTSerialize_ack(c->buf, c->buf_size, PUBCOMP, 0, mypacketid)) <= 0){ - mqtt_printf(MQTT_DEBUG, "Serialize PUBCOMP failed"); - rc = FAILURE; - }else if ((rc = sendPacket(c, len, &timer)) != SUCCESS){ // send the PUBCOMP packet - rc = FAILURE; // there was a problem + if (len <= 0){ + rc = FAILURE; + mqtt_printf(MQTT_DEBUG, "Serialize_ack failed"); + goto exit; + }else{ + if((rc = sendPacket(c, len, &timer)) == FAILURE){ MQTTSetStatus(c, MQTT_START); + goto exit; // there was a problem } - break; } - case PUBCOMP: - break; - case PINGRESP: - c->ping_outstanding = 0; - break; } + break; + } + case PUBREC: + { + unsigned short mypacketid; + unsigned char dup, type; +#if defined(MQTTV5) + if (MQTTV5Deserialize_ack(&type, &dup, &mypacketid, &reasoncode, &ackproperties, c->readbuf, c->readbuf_size) != 1){ +#else + if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1){ +#endif + mqtt_printf(MQTT_DEBUG, "Deserialize PUBREC failed"); + rc = FAILURE; +#if defined(MQTTV5) + }else if ((len = MQTTV5Serialize_ack(c->buf, c->buf_size, PUBREL, 0, mypacketid, 0, &ackproperties)) <= 0){ +#else + }else if ((len = MQTTSerialize_ack(c->buf, c->buf_size, PUBREL, 0, mypacketid)) <= 0){ +#endif + mqtt_printf(MQTT_DEBUG, "Serialize PUBREL failed"); + rc = FAILURE; + }else if ((rc = sendPacket(c, len, &timer)) != SUCCESS){ // send the PUBREL packet + rc = FAILURE; // there was a problem + MQTTSetStatus(c, MQTT_START); + } + break; + } + case PUBREL: + { + unsigned short mypacketid; + unsigned char dup, type; +#if defined(MQTTV5) + if (MQTTV5Deserialize_ack(&type, &dup, &mypacketid, &reasoncode, &ackproperties, c->readbuf, c->readbuf_size) != 1){ +#else + if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1){ +#endif + mqtt_printf(MQTT_DEBUG, "Deserialize PUBREL failed"); + rc = FAILURE; + }else if ((len = MQTTSerialize_ack(c->buf, c->buf_size, PUBCOMP, 0, mypacketid)) <= 0){ + mqtt_printf(MQTT_DEBUG, "Serialize PUBCOMP failed"); + rc = FAILURE; + }else if ((rc = sendPacket(c, len, &timer)) != SUCCESS){ // send the PUBCOMP packet + rc = FAILURE; // there was a problem + MQTTSetStatus(c, MQTT_START); + } + break; + } + case PUBCOMP: + break; + case PINGRESP: + c->ping_outstanding = 0; + break; +#if defined(MQTTV5) + case DISCONNECT: + if(MQTTV5Deserialize_disconnect(&ackproperties, &reasoncode, c->readbuf, c->readbuf_size) != 1){ + mqtt_printf(MQTT_DEBUG, "Deserialize DISCONNECT failed"); + } + break; +#endif } - keepalive(c); - break; - default: + } + keepalive(c); + break; + default: + break; + } +exit: + return rc; +} + +#endif + +int MQTTYield(MQTTClient* c, int timeout_ms) +{ + int rc = SUCCESS; + Timer timer; + + TimerInit(&timer); + TimerCountdownMS(&timer, timeout_ms); + + do + { + if (cycle(c, &timer) == FAILURE) + { + rc = FAILURE; + break; + } + } while (!TimerIsExpired(&timer)); + + return rc; +} + +int MQTTIsConnected(MQTTClient* client) +{ + return client->isconnected; +} + +void MQTTRun(void* parm) +{ + Timer timer; + MQTTClient* c = (MQTTClient*)parm; + + TimerInit(&timer); + + while (1) + { + TimerCountdownMS(&timer, 500); /* Don't wait too long if no traffic is incoming */ + cycle(c, &timer); + } +} + + +int waitfor(MQTTClient* c, int packet_type, Timer* timer) +{ + int rc = FAILURE; + + do + { + if (TimerIsExpired(timer)) + break; // we timed out + rc = cycle(c, timer); + } + while (rc != packet_type && rc >= 0); + + return rc; +} + +int MQTTConnectWithResults(MQTTClient* c, MQTTPacket_connectData* options, MQTTConnackData* data) +{ + Timer connect_timer; + int rc = FAILURE; + MQTTPacket_connectData default_options = MQTTPacket_connectData_initializer; + int len = 0; + + if (c->isconnected) /* don't send connect packet again if we are already connected */ + goto exit; + + TimerInit(&connect_timer); + TimerCountdownMS(&connect_timer, c->command_timeout_ms); + + if (options == 0) + options = &default_options; /* set default options if none were supplied */ + + c->keepAliveInterval = options->keepAliveInterval; + c->cleansession = options->cleansession; + TimerCountdown(&c->last_received, c->keepAliveInterval); + if ((len = MQTTSerialize_connect(c->buf, c->buf_size, options)) <= 0) + goto exit; + if ((rc = sendPacket(c, len, &connect_timer)) != SUCCESS) // send the connect packet + goto exit; // there was a problem +#if defined(WAIT_FOR_ACK) + // this will be a blocking call, wait for the connack + if (waitfor(c, CONNACK, &connect_timer) == CONNACK) + { + data->rc = 0; + data->sessionPresent = 0; + if (MQTTDeserialize_connack(&data->sessionPresent, &data->rc, c->readbuf, c->readbuf_size) == 1) + rc = data->rc; + else + rc = FAILURE; + } + else + rc = FAILURE; +#endif +exit: + if (rc == SUCCESS) + { + c->isconnected = 1; + c->ping_outstanding = 0; + } + + return rc; +} + +int MQTTConnect(MQTTClient* c, MQTTPacket_connectData* options) +{ + MQTTConnackData data; + return MQTTConnectWithResults(c, options, &data); +} + +int MQTTSetMessageHandler(MQTTClient* c, const char* topicFilter, messageHandler messageHandler) +{ + int rc = FAILURE; + int i = -1; + + /* first check for an existing matching slot */ + for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) + { + if (c->messageHandlers[i].topicFilter != NULL && strcmp(c->messageHandlers[i].topicFilter, topicFilter) == 0) + { + if (messageHandler == NULL) /* remove existing */ + { + c->messageHandlers[i].topicFilter = NULL; + c->messageHandlers[i].fp = NULL; + } + rc = SUCCESS; /* return i when adding new subscription */ break; + } + } + /* if no existing, look for empty slot (unless we are removing) */ + if (messageHandler != NULL) { + if (rc == FAILURE) + { + for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) + { + if (c->messageHandlers[i].topicFilter == NULL) + { + rc = SUCCESS; + break; + } + } + } + if (i < MAX_MESSAGE_HANDLERS) + { + c->messageHandlers[i].topicFilter = topicFilter; + c->messageHandlers[i].fp = messageHandler; + } + } + return rc; +} + + +int MQTTSubscribeWithResults(MQTTClient* c, const char* topicFilter, enum QoS qos, +messageHandler messageHandler, MQTTSubackData* data) +{ + int rc = FAILURE; + Timer timer; + int len = 0; + MQTTString topic = MQTTString_initializer; + topic.cstring = (char *)topicFilter; + + if (!c->isconnected) + goto exit; + + TimerInit(&timer); + TimerCountdownMS(&timer, c->command_timeout_ms); + + len = MQTTSerialize_subscribe(c->buf, c->buf_size, 0, getNextPacketId(c), 1, &topic, (int*)&qos); + if (len <= 0) + goto exit; + if ((rc = sendPacket(c, len, &timer)) != SUCCESS) // send the subscribe packet + goto exit; // there was a problem +#if defined(WAIT_FOR_ACK) + if (waitfor(c, SUBACK, &timer) == SUBACK) // wait for suback + { + int count = 0; + unsigned short mypacketid; + data->grantedQoS = QOS0; + if (MQTTDeserialize_suback(&mypacketid, 1, &count, (int*)&data->grantedQoS, c->readbuf, c->readbuf_size) == 1) + { + if (data->grantedQoS != 0x80) + rc = MQTTSetMessageHandler(c, topicFilter, messageHandler); + } + } + else + rc = FAILURE; +#endif +exit: + if (rc == FAILURE) + MQTTCloseSession(c); + return rc; +} + +int MQTTSubscribe(MQTTClient* c, const char* topicFilter, enum QoS qos, +messageHandler messageHandler) +{ + MQTTSubackData data; + return MQTTSubscribeWithResults(c, topicFilter, qos, messageHandler, &data); +} + +int MQTTUnsubscribe(MQTTClient* c, const char* topicFilter) +{ + int rc = FAILURE; + Timer timer; + MQTTString topic = MQTTString_initializer; + topic.cstring = (char *)topicFilter; + int len = 0; + + if (!c->isconnected) + goto exit; + + TimerInit(&timer); + TimerCountdownMS(&timer, c->command_timeout_ms); + + if ((len = MQTTSerialize_unsubscribe(c->buf, c->buf_size, 0, getNextPacketId(c), 1, &topic)) <= 0) + goto exit; + if ((rc = sendPacket(c, len, &timer)) != SUCCESS) // send the subscribe packet + goto exit; // there was a problem +#if defined(WAIT_FOR_ACK) + if (waitfor(c, UNSUBACK, &timer) == UNSUBACK) + { + unsigned short mypacketid; // should be the same as the packetid above + if (MQTTDeserialize_unsuback(&mypacketid, c->readbuf, c->readbuf_size) == 1) + { + /* remove the subscription message handler associated with this topic, if there is one */ + MQTTSetMessageHandler(c, topicFilter, NULL); + } + } + else + rc = FAILURE; +#endif +exit: + if (rc == FAILURE) + MQTTCloseSession(c); + return rc; +} + +int MQTTPublish(MQTTClient* c, const char* topicName, MQTTMessage* message) +{ + int rc = FAILURE; + Timer timer; + MQTTString topic = MQTTString_initializer; + topic.cstring = (char *)topicName; + int len = 0; + + if (!c->isconnected) + goto exit; + + TimerInit(&timer); + TimerCountdownMS(&timer, c->command_timeout_ms); + + if (message->qos == QOS1 || message->qos == QOS2) + message->id = getNextPacketId(c); + + len = MQTTSerialize_publish(c->buf, c->buf_size, 0, message->qos, message->retained, message->id, + topic, (unsigned char*)message->payload, message->payloadlen); + if (len <= 0) + goto exit; + if ((rc = sendPacket(c, len, &timer)) != SUCCESS) // send the subscribe packet + goto exit; // there was a problem +#if defined(WAIT_FOR_ACK) + if (message->qos == QOS1) + { + if (waitfor(c, PUBACK, &timer) == PUBACK) + { + unsigned short mypacketid; + unsigned char dup, type; + if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1) + rc = FAILURE; + } + else + rc = FAILURE; + } + else if (message->qos == QOS2) + { + if (waitfor(c, PUBCOMP, &timer) == PUBCOMP) + { + unsigned short mypacketid; + unsigned char dup, type; + if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1) + rc = FAILURE; + } + else + rc = FAILURE; + } +#endif +exit: + if (rc == FAILURE) + MQTTCloseSession(c); + return rc; +} + +int MQTTDisconnect(MQTTClient* c) +{ + int rc = FAILURE; + Timer timer; // we might wait for incomplete incoming publishes to complete + int len = 0; + + TimerInit(&timer); + TimerCountdownMS(&timer, c->command_timeout_ms); + + len = MQTTSerialize_disconnect(c->buf, c->buf_size); + if (len > 0) + rc = sendPacket(c, len, &timer); // send the disconnect packet + MQTTCloseSession(c); + + return rc; +} + +/*******************************************************API for MQTT5.0*******************************************************************/ +/*****************************************************************************************************************************************/ +#if defined(MQTTV5) +int MQTTV5ConnectWithResults(MQTTClient* c, MQTTPacket_connectData* options, MQTTConnackData* data, MQTTProperties* connectproperties ,MQTTProperties* willproperties, MQTTProperties* connackproperties) +{ + Timer connect_timer; + int rc = FAILURE; + MQTTPacket_connectData default_options = MQTTPacket_connectData_initializer; + int len = 0; + + if (c->isconnected) /* don't send connect packet again if we are already connected */ + goto exit; + + TimerInit(&connect_timer); + TimerCountdownMS(&connect_timer, c->command_timeout_ms); + + if (options == 0) + options = &default_options; /* set default options if none were supplied */ + + c->keepAliveInterval = options->keepAliveInterval; + c->cleansession = options->cleansession; + TimerCountdown(&c->last_received, c->keepAliveInterval); + if ((len = MQTTV5Serialize_connect(c->buf, c->buf_size, options, connectproperties, willproperties)) <= 0) + goto exit; + if ((rc = sendPacket(c, len, &connect_timer)) != SUCCESS) // send the connect packet + goto exit; // there was a problem +#if defined(WAIT_FOR_ACK) + // this will be a blocking call, wait for the connack + if (waitfor(c, CONNACK, &connect_timer) == CONNACK) + { + data->rc = 0; + data->sessionPresent = 0; + if (MQTTV5Deserialize_connack(connackproperties,&data->sessionPresent, &data->rc, c->readbuf, c->readbuf_size) == 1) + rc = data->rc; + else + rc = FAILURE; + } + else{ + rc = FAILURE; + mqtt_printf(MQTT_DEBUG, "Not received CONNACK"); + } +#endif +exit: + if (rc == SUCCESS) + { + c->isconnected = 1; + c->ping_outstanding = 0; + } + + return rc; +} + +int MQTTV5Connect(MQTTClient* c, MQTTPacket_connectData* options, MQTTProperties* connectproperties, MQTTProperties* willproperties) +{ + int rc = -1; + MQTTConnackData data; +#if defined(WAIT_FOR_ACK) + MQTTProperties connackproperties; + connackproperties.count = 0; + connackproperties.length = 0; + //max 17 properties can be returned for CONNACK + MQTTProperty connack_props[17]; + connackproperties.array = connack_props; + connackproperties.max_count = 17; + rc = MQTTV5ConnectWithResults(c, options, &data, connectproperties, willproperties, &connackproperties); +#else + rc = MQTTV5ConnectWithResults(c, options, &data, connectproperties, willproperties, NULL); +#endif +#if defined(WAIT_FOR_ACK) + if (gServerKeepAlive > 0) + c->keepAliveInterval = gServerKeepAlive; +#endif + return rc; +} + +int MQTTV5SubscribeWithResults(MQTTClient* c, const char* topicFilter, struct subscribeOptions* options, +messageHandler messageHandler, MQTTSubackData* data, MQTTProperties* subproperties, MQTTProperties* subackproperties) +{ + int rc = FAILURE; + Timer timer; + int len = 0; + MQTTString topic = MQTTString_initializer; + topic.cstring = (char *)topicFilter; + + if (!c->isconnected) + goto exit; + + TimerInit(&timer); + TimerCountdownMS(&timer, c->command_timeout_ms); + + len = MQTTV5Serialize_subscribe(c->buf, c->buf_size, 0, getNextPacketId(c), subproperties ,1, &topic, NULL, options); + if (len <= 0) + goto exit; + if ((rc = sendPacket(c, len, &timer)) != SUCCESS) // send the subscribe packet + goto exit; // there was a problem +#if defined(WAIT_FOR_ACK) + if (waitfor(c, SUBACK, &timer) == SUBACK) // wait for suback + { + int count = 0; + unsigned short mypacketid; + data->grantedQoS = QOS0; + if (MQTTV5Deserialize_suback(&mypacketid, subackproperties, 1, &count, (int*)&data->grantedQoS, c->readbuf, c->readbuf_size) == 1) + { + if (data->grantedQoS != 0x80) + rc = MQTTSetMessageHandler(c, topicFilter, messageHandler); + } + } + else + rc = FAILURE; +#endif + +exit: + if (rc == FAILURE) + MQTTCloseSession(c); + return rc; +} + +int MQTTV5Subscribe(MQTTClient* c, const char* topicFilter, struct subscribeOptions* options, +messageHandler messageHandler, MQTTProperties* subproperties) +{ + int rc = -1; + MQTTSubackData data; +#if defined(WAIT_FOR_ACK) + MQTTProperties subackproperties; + subackproperties.count = 0; + subackproperties.length = 0; + //max properties returned for suback is 2 + MQTTProperty connack_props[2]; + subackproperties.array = connack_props; + subackproperties.max_count = 2; + rc = MQTTV5SubscribeWithResults(c, topicFilter, options, messageHandler, &data, subproperties, &subackproperties); +#else + rc = MQTTV5SubscribeWithResults(c, topicFilter, options, messageHandler, &data, subproperties, NULL); +#endif + return rc; + +} + +int MQTTV5Unsubscribe(MQTTClient* c, const char* topicFilter, MQTTProperties* unsubproperties, MQTTProperties* unsubackproperties, int* ReasonCode) +{ + int rc = FAILURE; + Timer timer; + MQTTString topic = MQTTString_initializer; + topic.cstring = (char *)topicFilter; + int len = 0; + + mqtt_printf(MQTT_INFO,"Unsubscribe to topic: %s", topic.cstring); + if (!c->isconnected) + goto exit; + + TimerInit(&timer); + TimerCountdownMS(&timer, c->command_timeout_ms); + + if ((len = MQTTV5Serialize_unsubscribe(c->buf, c->buf_size, 0, getNextPacketId(c), unsubproperties, 1, &topic)) <= 0) + goto exit; + if ((rc = sendPacket(c, len, &timer)) != SUCCESS) // send the subscribe packet + goto exit; // there was a problem +#if defined(WAIT_FOR_ACK) + if (waitfor(c, UNSUBACK, &timer) == UNSUBACK) + { + int count = 0; + unsigned short mypacketid; // should be the same as the packetid above + if (MQTTV5Deserialize_unsuback(&mypacketid, unsubackproperties, 1, &count, ReasonCode, c->readbuf, c->readbuf_size) == 1) + { + /* remove the subscription message handler associated with this topic, if there is one */ + MQTTSetMessageHandler(c, topicFilter, NULL); + } + } + else + rc = FAILURE; +#endif + +exit: + if (rc == FAILURE) + MQTTCloseSession(c); + return rc; +} + +int MQTTV5UnsubscribeHandle(MQTTClient* c, const char* topicFilter, MQTTProperties* unsubproperties) +{ + int rc = -1; + int ReasonCode; +#if defined(WAIT_FOR_ACK) + MQTTProperties unsubackproperties; + unsubackproperties.count = 0; + unsubackproperties.length = 0; + //max 2 properties can be returned for UNSUBACK + MQTTProperty props[2]; + unsubackproperties.array = props; + unsubackproperties.max_count = 2; + rc = MQTTV5Unsubscribe(c,topicFilter,unsubproperties,&unsubackproperties,&ReasonCode); +#else + rc = MQTTV5Unsubscribe(c,topicFilter,unsubproperties,NULL,&ReasonCode); +#endif + return rc; +} + +int MQTTV5Publish(MQTTClient* c, const char* topicName, MQTTMessage* message, MQTTProperties* pubproperties, MQTTProperties* ack, int* reasoncode) +{ + int rc = FAILURE; + Timer timer; + MQTTString topic = MQTTString_initializer; + topic.cstring = (char *)topicName; + int len = 0; + + if (!c->isconnected) + goto exit; + + TimerInit(&timer); + TimerCountdownMS(&timer, c->command_timeout_ms); + //If a Client receives a Maximum QoS from a Server, it MUST NOT send PUBLISH packets at a QoS level + //exceeding the Maximum QoS level specified + if (message->qos > gMAXQOSSpecified) + { + rc = FAILURE; + mqtt_printf(MQTT_WARNING, "MAX QOS Specified = %d, Message QOS = %d",gMAXQOSSpecified, message->qos); + goto exit; + } + //A Client receiving Retain Available set to 0 from the Server MUST NOT send a PUBLISH packet with the + //RETAIN flag set to 1 + if (message->retained > gRetainAvailable) + { + rc = FAILURE; + mqtt_printf(MQTT_WARNING, "Retailed Available = %d, Retain Flag = %d",gRetainAvailable, message->retained); + goto exit; + } + + if (message->qos == QOS1 || message->qos == QOS2) + message->id = getNextPacketId(c); + + len = MQTTV5Serialize_publish(c->buf, c->buf_size, 0, message->qos, message->retained, message->id, + topic, pubproperties, (unsigned char*)message->payload, message->payloadlen); + if (len <= 0) + goto exit; + if ((rc = sendPacket(c, len, &timer)) != SUCCESS) // send the subscribe packet + goto exit; // there was a problem +#if defined(WAIT_FOR_ACK) + if (message->qos == QOS1) + { + if (waitfor(c, PUBACK, &timer) == PUBACK) + { + unsigned short mypacketid; + unsigned char dup, type; + if (MQTTV5Deserialize_ack(&type, &dup, &mypacketid, reasoncode, ack, c->readbuf, c->readbuf_size) != 1) + rc = FAILURE; + } + else + rc = FAILURE; } + else if (message->qos == QOS2) + { + if (waitfor(c, PUBCOMP, &timer) == PUBCOMP) + { + unsigned short mypacketid; + unsigned char dup, type; + if (MQTTV5Deserialize_ack(&type, &dup, &mypacketid, reasoncode, ack, c->readbuf, c->readbuf_size) != 1) + rc = FAILURE; + } + else + rc = FAILURE; + } +#endif exit: + if (rc == FAILURE) + MQTTCloseSession(c); return rc; } +int MQTTV5PublishHandle(MQTTClient* c, const char* topicName, MQTTMessage* message, MQTTProperties* pubproperties) +{ + int rc = -1; + int ReasonCode; +#if defined(WAIT_FOR_ACK) + MQTTProperties pubcompproperties; + pubcompproperties.count = 0; + pubcompproperties.length = 0; + //max 2 properties can be returned for PUBCOMP + MQTTProperty props[2]; + pubcompproperties.array = props; + pubcompproperties.max_count = 2; + rc = MQTTV5Publish(c, topicName, message, pubproperties, &pubcompproperties, &ReasonCode); +#else + rc = MQTTV5Publish(c, topicName, message, pubproperties, NULL, &ReasonCode); #endif + return rc; +} + +int MQTTV5Disconnect(MQTTClient* c, int ReasonCode, MQTTProperties* DisconProperties) +{ + int rc = FAILURE; + Timer timer; // we might wait for incomplete incoming publishes to complete + int len = 0; + + TimerInit(&timer); + TimerCountdownMS(&timer, c->command_timeout_ms); + + len = MQTTV5Serialize_disconnect(c->buf, c->buf_size, ReasonCode, DisconProperties); + if (len > 0) + rc = sendPacket(c, len, &timer); // send the disconnect packet + c->isconnected = 0; + return rc; +} + +const char* MQTTGetReason(int ReasonCode) +{ + int i; + const char* rc; + + for (i = 0; i < ARRAY_SIZE(GetReason); ++i) + { + if (GetReason[i].code == ReasonCode) + { + rc = GetReason[i].reason; + break; + } + } + return rc; +} +#endif + +const char* MQTTPacketIDPrint(int packet_id) +{ + switch(packet_id) + { + case CONNECT: + return "CONNECT"; + case CONNACK: + return "CONNACK"; + case PUBLISH: + return "PUBLISH"; + case PUBACK: + return "PUBACK"; + case PUBREC: + return "PUBREC"; + case PUBREL: + return "PUBREL"; + case PUBCOMP: + return "PUBCOMP"; + case SUBSCRIBE: + return "SUBSCRIBE"; + case SUBACK: + return "SUBACK"; + case UNSUBSCRIBE: + return "UNSUBSCRIBE"; + case UNSUBACK: + return "UNSUBACK"; + case PINGREQ: + return "PINGREQ"; + case PINGRESP: + return "PINGRESP"; + case DISCONNECT: + return "DISCONNECT"; + default: + return ""; + } +} \ No newline at end of file diff --git a/component/common/application/mqtt/MQTTClient/MQTTClient.h b/component/common/application/mqtt/MQTTClient/MQTTClient.h index 7666e823..1e8e1abd 100644 --- a/component/common/application/mqtt/MQTTClient/MQTTClient.h +++ b/component/common/application/mqtt/MQTTClient/MQTTClient.h @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2015 IBM Corp. + * Copyright (c) 2014, 2017 IBM Corp. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -13,6 +13,7 @@ * Contributors: * Allan Stockdill-Mander/Ian Craggs - initial API and implementation and/or initial documentation * Ian Craggs - documentation and platform specific header + * Ian Craggs - add setMessageHandler function *******************************************************************************/ #if !defined(__MQTT_CLIENT_C_) @@ -36,8 +37,10 @@ #include "../MQTTPacket/MQTTPacket.h" #include "stdio.h" #include "MQTTFreertos.h" - -#define MQTT_TASK +#if defined(MQTTV5) +#include "MQTTProperties.h" +#endif +//#define MQTT_TASK #if !defined(MQTT_TASK) #define WAIT_FOR_ACK #endif @@ -67,7 +70,10 @@ enum mqtt_status{ #define MAX_MESSAGE_HANDLERS 5 /* redefinable - how many subscriptions do you want? */ #endif -enum QoS { QOS0, QOS1, QOS2 }; +enum QoS { QOS0 = 0x00, + QOS1 = 0x01, + QOS2 = 0x02, + SUBFAIL = 0x80 }; /* all failure return codes must be negative */ enum returnCode { BUFFER_OVERFLOW = -2, FAILURE = -1 };//, SUCCESS = 0 @@ -91,47 +97,59 @@ extern int TimerLeftMS(Timer*); typedef struct MQTTMessage { - enum QoS qos; - unsigned char retained; - unsigned char dup; - unsigned short id; - void *payload; - size_t payloadlen; + enum QoS qos; + unsigned char retained; + unsigned char dup; + unsigned short id; + void *payload; + size_t payloadlen; } MQTTMessage; typedef struct MessageData { - MQTTMessage* message; - MQTTString* topicName; + MQTTMessage* message; + MQTTString* topicName; } MessageData; +typedef struct MQTTConnackData +{ + unsigned char rc; + unsigned char sessionPresent; +} MQTTConnackData; + +typedef struct MQTTSubackData +{ + enum QoS grantedQoS; +} MQTTSubackData; + typedef void (*messageHandler)(MessageData*); typedef struct MQTTClient { - unsigned int next_packetid, - command_timeout_ms; - size_t buf_size, - readbuf_size; - unsigned char *buf, - *readbuf; - unsigned int keepAliveInterval; - char ping_outstanding; - int isconnected; - - struct MessageHandlers - { - const char* topicFilter; - void (*fp) (MessageData*); - } messageHandlers[MAX_MESSAGE_HANDLERS]; /* Message handlers are indexed by subscription topic */ - - void (*defaultMessageHandler) (MessageData*); - - Network* ipstack; - Timer ping_timer; - - Timer cmd_timer; - int mqttstatus; + unsigned int next_packetid, + command_timeout_ms; + size_t buf_size, + readbuf_size; + unsigned char *buf, + *readbuf; + unsigned int keepAliveInterval; + char ping_outstanding; + int isconnected; + int cleansession; + + struct MessageHandlers + { + const char* topicFilter; + void (*fp) (MessageData*); + } messageHandlers[MAX_MESSAGE_HANDLERS]; /* Message handlers are indexed by subscription topic */ + + void (*defaultMessageHandler) (MessageData*); + + Network* ipstack; + Timer last_sent, last_received, pingresp_timer; + Timer cmd_timer; + Timer ping_timer; + int mqttstatus; } MQTTClient; #define DefaultClient {0, 0, 0, 0, NULL, NULL, 0, 0, 0} @@ -145,7 +163,15 @@ typedef struct MQTTClient * @param */ DLLExport void MQTTClientInit(MQTTClient* client, Network* network, unsigned int command_timeout_ms, - unsigned char* sendbuf, size_t sendbuf_size, unsigned char* readbuf, size_t readbuf_size); + unsigned char* sendbuf, size_t sendbuf_size, unsigned char* readbuf, size_t readbuf_size); + +/** MQTT Connect - send an MQTT connect packet down the network and wait for a Connack + * The nework object must be connected to the network endpoint before calling this + * @param options - connect options + * @return success code + */ +DLLExport int MQTTConnectWithResults(MQTTClient* client, MQTTPacket_connectData* options, + MQTTConnackData* data); /** MQTT Connect - send an MQTT connect packet down the network and wait for a Connack * The nework object must be connected to the network endpoint before calling this @@ -162,6 +188,14 @@ DLLExport int MQTTConnect(MQTTClient* client, MQTTPacket_connectData* options); */ DLLExport int MQTTPublish(MQTTClient* client, const char*, MQTTMessage*); +/** MQTT SetMessageHandler - set or remove a per topic message handler + * @param client - the client object to use + * @param topicFilter - the topic filter set the message handler for + * @param messageHandler - pointer to the message handler function or NULL to remove + * @return success code + */ +DLLExport int MQTTSetMessageHandler(MQTTClient* c, const char* topicFilter, messageHandler messageHandler); + /** MQTT Subscribe - send an MQTT subscribe packet and wait for suback before returning. * @param client - the client object to use * @param topicFilter - the topic filter to subscribe to @@ -170,6 +204,15 @@ DLLExport int MQTTPublish(MQTTClient* client, const char*, MQTTMessage*); */ DLLExport int MQTTSubscribe(MQTTClient* client, const char* topicFilter, enum QoS, messageHandler); +/** MQTT Subscribe - send an MQTT subscribe packet and wait for suback before returning. + * @param client - the client object to use + * @param topicFilter - the topic filter to subscribe to + * @param message - the message to send + * @param data - suback granted QoS returned + * @return success code + */ +DLLExport int MQTTSubscribeWithResults(MQTTClient* client, const char* topicFilter, enum QoS, messageHandler, MQTTSubackData* data); + /** MQTT Subscribe - send an MQTT unsubscribe packet and wait for unsuback before returning. * @param client - the client object to use * @param topicFilter - the topic filter to unsubscribe from @@ -185,18 +228,40 @@ DLLExport int MQTTDisconnect(MQTTClient* client); /** MQTT Yield - MQTT background * @param client - the client object to use - * @param time - the time, in milliseconds, to yield for + * @param time - the time, in milliseconds, to yield for * @return success code */ DLLExport int MQTTYield(MQTTClient* client, int time); +/** MQTT isConnected + * @param client - the client object to use + * @return truth value indicating whether the client is connected to the server + */ +DLLExport int MQTTIsConnected(MQTTClient* client); + #if defined(MQTT_TASK) void MQTTSetStatus(MQTTClient* c, int mqttstatus); +#if defined(MQTTV5) +int MQTTDataHandle(MQTTClient* c, fd_set *readfd, MQTTPacket_connectData *connectData, messageHandler messageHandler, char* address, char* topic, MQTTProperties* properties, MQTTProperties* willproperties); +#else int MQTTDataHandle(MQTTClient* c, fd_set *readfd, MQTTPacket_connectData *connectData, messageHandler messageHandler, char* address, char* topic); #endif +#endif + +/** MQTTGetReason +* @param ReasonCode - reasoncode +* @return reason in string +*/ +DLLExport const char* MQTTGetReason(int ReasonCode); + +/** MQTTPacketIDPrint +* @param packet_id - packet id in integer +* @return packet id as string +*/ +DLLExport const char* MQTTPacketIDPrint(int packet_id); #if defined(__cplusplus) - } + } #endif #endif diff --git a/component/common/application/mqtt/MQTTClient/MQTTFreertos.c b/component/common/application/mqtt/MQTTClient/MQTTFreertos.c index 929a804c..f141ca45 100644 --- a/component/common/application/mqtt/MQTTClient/MQTTFreertos.c +++ b/component/common/application/mqtt/MQTTClient/MQTTFreertos.c @@ -646,7 +646,7 @@ int NetworkConnect(Network* n, char* addr, int port) int retVal = -1; struct hostent *hptr; char **pptr; - char str[32]; + char str[32] = {0}; int keepalive_enable = 1; int keep_idle = 30; diff --git a/component/common/application/mqtt/MQTTPacket/MQTTConnect.h b/component/common/application/mqtt/MQTTPacket/MQTTConnect.h index fc5f7843..f1532e10 100644 --- a/component/common/application/mqtt/MQTTPacket/MQTTConnect.h +++ b/component/common/application/mqtt/MQTTPacket/MQTTConnect.h @@ -1,8 +1,5 @@ - /******************************************************************************* - - - * Copyright (c) 2014 IBM Corp. + * Copyright (c) 2014, 2017 IBM Corp. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -15,14 +12,26 @@ * * Contributors: * Ian Craggs - initial API and implementation and/or initial documentation + * Ian Craggs - add connack return code definitions * Xiang Rong - 442039 Add makefile to Embedded C client + * Ian Craggs - fix for issue #64, bit order in connack response *******************************************************************************/ #ifndef MQTTCONNECT_H_ #define MQTTCONNECT_H_ +enum connack_return_codes +{ + MQTT_CONNECTION_ACCEPTED = 0, + MQTT_UNNACCEPTABLE_PROTOCOL = 1, + MQTT_CLIENTID_REJECTED = 2, + MQTT_SERVER_UNAVAILABLE = 3, + MQTT_BAD_USERNAME_OR_PASSWORD = 4, + MQTT_NOT_AUTHORIZED = 5, +}; + #if !defined(DLLImport) - #define DLLImport + #define DLLImport #endif #if !defined(DLLExport) #define DLLExport @@ -40,7 +49,7 @@ typedef union unsigned int willRetain : 1; /**< will retain setting */ unsigned int willQoS : 2; /**< will QoS value */ unsigned int will : 1; /**< will flag */ - unsigned int cleansession : 1; /**< clean session flag */ + unsigned int cleansession : 1; /**< cleansession flag */ unsigned int : 1; /**< unused */ } bits; #else @@ -112,20 +121,20 @@ typedef union #if defined(REVERSED) struct { + unsigned int reserved : 7; /**< unused */ unsigned int sessionpresent : 1; /**< session present flag */ - unsigned int : 7; /**< unused */ } bits; #else struct { - unsigned int : 7; /**< unused */ unsigned int sessionpresent : 1; /**< session present flag */ + unsigned int reserved: 7; /**< unused */ } bits; #endif } MQTTConnackFlags; /**< connack flags byte */ #define MQTTPacket_connectData_initializer { {'M', 'Q', 'T', 'C'}, 0, 4, {NULL, {0, NULL}}, 60, 1, 0, \ - MQTTPacket_willOptions_initializer, {NULL, {0, NULL}}, {NULL, {0, NULL}} } + MQTTPacket_willOptions_initializer, {NULL, {0, NULL}}, {NULL, {0, NULL}} } DLLExport int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData* options); DLLExport int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, int len); @@ -134,6 +143,7 @@ DLLExport int MQTTSerialize_connack(unsigned char* buf, int buflen, unsigned cha DLLExport int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connack_rc, unsigned char* buf, int buflen); DLLExport int MQTTSerialize_disconnect(unsigned char* buf, int buflen); +DLLExport int MQTTDeserialize_disconnect(unsigned char* buf, int buflen); DLLExport int MQTTSerialize_pingreq(unsigned char* buf, int buflen); #endif /* MQTTCONNECT_H_ */ diff --git a/component/common/application/mqtt/MQTTPacket/MQTTConnectClient.c b/component/common/application/mqtt/MQTTPacket/MQTTConnectClient.c index 38a2ed55..0ab6e654 100644 --- a/component/common/application/mqtt/MQTTPacket/MQTTConnectClient.c +++ b/component/common/application/mqtt/MQTTPacket/MQTTConnectClient.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 IBM Corp. + * Copyright (c) 2014, 2017 IBM Corp. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -13,10 +13,14 @@ * Contributors: * Ian Craggs - initial API and implementation and/or initial documentation *******************************************************************************/ - +#include "platform_opts.h" +#if defined(MQTTV5) +#include "V5/MQTTV5Packet.h" +#else #include "MQTTPacket.h" +#endif #include "StackTrace.h" - +#include "MQTTFreertos.h" #include /** @@ -24,7 +28,12 @@ * @param options the options to be used to build the connect packet * @return the length of buffer needed to contain the serialized version of the packet */ +#if defined(MQTTV5) +int MQTTSerialize_connectLength(MQTTPacket_connectData* options, MQTTProperties* connectProperties, + MQTTProperties* willProperties) +#else int MQTTSerialize_connectLength(MQTTPacket_connectData* options) +#endif { int len = 0; @@ -32,7 +41,7 @@ int MQTTSerialize_connectLength(MQTTPacket_connectData* options) if (options->MQTTVersion == 3) len = 12; /* variable depending on MQTT or MQIsdp */ - else if (options->MQTTVersion == 4) + else if (options->MQTTVersion >= 4) len = 10; len += MQTTstrlen(options->clientID)+2; @@ -42,6 +51,15 @@ int MQTTSerialize_connectLength(MQTTPacket_connectData* options) len += MQTTstrlen(options->username)+2; if (options->password.cstring || options->password.lenstring.data) len += MQTTstrlen(options->password)+2; +#if defined(MQTTV5) + if (options->MQTTVersion >= 5) + { + if (connectProperties) + len += MQTTProperties_len(connectProperties); + if (options->willFlag && willProperties) + len += MQTTProperties_len(willProperties); + } +#endif FUNC_EXIT_RC(len); return len; @@ -55,7 +73,17 @@ int MQTTSerialize_connectLength(MQTTPacket_connectData* options) * @param options the options to be used to build the connect packet * @return serialized length, or error if 0 */ +#if defined(MQTTV5) int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData* options) +{ + return MQTTV5Serialize_connect(buf, buflen, options, NULL, NULL); +} + +int MQTTV5Serialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData* options, + MQTTProperties* connectProperties, MQTTProperties* willProperties) +#else +int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData* options) +#endif { unsigned char *ptr = buf; MQTTHeader header = {0}; @@ -64,7 +92,12 @@ int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData int rc = -1; FUNC_ENTRY; + #if defined(MQTTV5) + if (MQTTPacket_len(len = MQTTSerialize_connectLength(options, + connectProperties, willProperties)) > buflen) + #else if (MQTTPacket_len(len = MQTTSerialize_connectLength(options)) > buflen) + #endif { rc = MQTTPACKET_BUFFER_TOO_SHORT; goto exit; @@ -76,16 +109,13 @@ int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData ptr += MQTTPacket_encode(ptr, len); /* write remaining length */ - if (options->MQTTVersion == 4) - { + if (options->MQTTVersion == 5 || options->MQTTVersion == 4) writeCString(&ptr, "MQTT"); - writeChar(&ptr, (char) 4); - } - else - { + else if (options->MQTTVersion == 3) writeCString(&ptr, "MQIsdp"); - writeChar(&ptr, (char) 3); - } + else + goto exit; + writeChar(&ptr, (char)options->MQTTVersion); flags.all = 0; flags.bits.cleansession = options->cleansession; @@ -103,9 +133,18 @@ int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData writeChar(&ptr, flags.all); writeInt(&ptr, options->keepAliveInterval); +#if defined(MQTTV5) + if (options->MQTTVersion == 5 && connectProperties) + MQTTProperties_write(&ptr, connectProperties); +#endif writeMQTTString(&ptr, options->clientID); if (options->willFlag) { +#if defined(MQTTV5) + /* write will properties */ + if (options->MQTTVersion == 5 && willProperties) + MQTTProperties_write(&ptr, willProperties); +#endif writeMQTTString(&ptr, options->will.topicName); writeMQTTString(&ptr, options->will.message); } @@ -129,7 +168,17 @@ int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData * @param len the length in bytes of the data in the supplied buffer * @return error code. 1 is success, 0 is failure */ +#if defined(MQTTV5) +int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connack_rc, unsigned char* buf, int buflen) +{ + return MQTTV5Deserialize_connack(NULL, sessionPresent, connack_rc, buf, buflen); +} + +int MQTTV5Deserialize_connack(MQTTProperties* connackProperties, unsigned char* sessionPresent, unsigned char* connack_rc, + unsigned char* buf, int buflen) +#else int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connack_rc, unsigned char* buf, int buflen) +#endif { MQTTHeader header = {0}; unsigned char* curdata = buf; @@ -151,6 +200,14 @@ int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connac flags.all = readChar(&curdata); *sessionPresent = flags.bits.sessionpresent; *connack_rc = readChar(&curdata); + +#if defined(MQTTV5) + mqtt_printf(MQTT_INFO,"Connack ReasonCode: %d, %s",*connack_rc,MQTTGetReason((int) *connack_rc)); + if (connackProperties && !MQTTProperties_read(connackProperties, &curdata, enddata)) + { + goto exit; + } +#endif rc = 1; exit: @@ -166,14 +223,36 @@ int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connac * @param packettype the message type * @return serialized length, or error if 0 */ +#if defined(MQTTV5) +int MQTTV5Serialize_zero(unsigned char* buf, int buflen, unsigned char packettype, + int reasonCode, MQTTProperties* properties); + +int MQTTSerialize_zero(unsigned char* buf, int buflen, unsigned char packettype) +{ + return MQTTV5Serialize_zero(buf, buflen, packettype, -1, NULL); +} + +int MQTTV5Serialize_zero(unsigned char* buf, int buflen, unsigned char packettype, + int reasonCode, MQTTProperties* properties) +#else int MQTTSerialize_zero(unsigned char* buf, int buflen, unsigned char packettype) +#endif { MQTTHeader header = {0}; int rc = -1; unsigned char *ptr = buf; + int len = 0; FUNC_ENTRY; - if (buflen < 2) +#if defined(MQTTV5) + if (reasonCode >= 0 && reasonCode <= 162) + { + len += 1; + if (properties) + len += MQTTProperties_len(properties); + } +#endif + if (MQTTPacket_len(len) > buflen) { rc = MQTTPACKET_BUFFER_TOO_SHORT; goto exit; @@ -182,7 +261,15 @@ int MQTTSerialize_zero(unsigned char* buf, int buflen, unsigned char packettype) header.bits.type = packettype; writeChar(&ptr, header.byte); /* write header */ - ptr += MQTTPacket_encode(ptr, 0); /* write remaining length */ + ptr += MQTTPacket_encode(ptr, len); /* write remaining length */ +#if defined(MQTTV5) + if (reasonCode >= 0 && reasonCode <= 162) + { + writeChar(&ptr, reasonCode); /* must have reasonCode before properties */ + if (properties) + MQTTProperties_write(&ptr, properties); + } +#endif rc = ptr - buf; exit: FUNC_EXIT_RC(rc); @@ -196,10 +283,33 @@ int MQTTSerialize_zero(unsigned char* buf, int buflen, unsigned char packettype) * @param buflen the length in bytes of the supplied buffer, to avoid overruns * @return serialized length, or error if 0 */ +#if defined(MQTTV5) +int MQTTSerialize_disconnect(unsigned char* buf, int buflen) +{ + return MQTTV5Serialize_disconnect(buf, buflen, -1, NULL); +} + +int MQTTV5Serialize_disconnect(unsigned char* buf, int buflen, + int reasonCode, MQTTProperties* properties) +#else int MQTTSerialize_disconnect(unsigned char* buf, int buflen) +#endif { +#if defined(MQTTV5) + return MQTTV5Serialize_zero(buf, buflen, DISCONNECT, reasonCode, properties); +#else return MQTTSerialize_zero(buf, buflen, DISCONNECT); +#endif +} + + +#if defined(MQTTV5) +int MQTTV5Serialize_auth(unsigned char* buf, int buflen, + int reasonCode, MQTTProperties* properties) +{ + return MQTTV5Serialize_zero(buf, buflen, AUTH, reasonCode, properties); } +#endif /** diff --git a/component/common/application/mqtt/MQTTPacket/MQTTConnectServer.c b/component/common/application/mqtt/MQTTPacket/MQTTConnectServer.c index 04efee25..80745150 100644 --- a/component/common/application/mqtt/MQTTPacket/MQTTConnectServer.c +++ b/component/common/application/mqtt/MQTTPacket/MQTTConnectServer.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 IBM Corp. + * Copyright (c) 2014, 2017 IBM Corp. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -12,10 +12,16 @@ * * Contributors: * Ian Craggs - initial API and implementation and/or initial documentation + * Ian Craggs - add MQTT v5 support *******************************************************************************/ +#include "platform_opts.h" #include "StackTrace.h" +#if defined(MQTTV5) +#include "V5/MQTTV5Packet.h" +#else #include "MQTTPacket.h" +#endif #include #define min(a, b) ((a < b) ? a : b) @@ -32,15 +38,39 @@ int MQTTPacket_checkVersion(MQTTString* protocol, int version) int rc = 0; if (version == 3 && memcmp(protocol->lenstring.data, "MQIsdp", - min(6, protocol->lenstring.len)) == 0) + min(6, protocol->lenstring.len)) == 0) rc = 1; else if (version == 4 && memcmp(protocol->lenstring.data, "MQTT", - min(4, protocol->lenstring.len)) == 0) + min(4, protocol->lenstring.len)) == 0) rc = 1; +#if defined(MQTTV5) + else if (version == 5 && memcmp(protocol->lenstring.data, "MQTT", + min(4, protocol->lenstring.len)) == 0) + rc = 1; +#endif return rc; } + +#if defined(MQTTV5) +int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, int len) +{ + return MQTTV5Deserialize_connect(NULL, NULL, data, buf, len); +} + +/** + * Deserializes the supplied (wire) buffer into connect data structure + * @param willProperties the V5 properties to be applied to the will message, if it exists + * @param connectProperties the V5 properties for the connect packet + * @param data the connect data structure to be filled out + * @param buf the raw buffer data, of the correct length determined by the remaining length field + * @param len the length in bytes of the data in the supplied buffer + * @return error code. 1 is success, 0 is failure + */ +int MQTTV5Deserialize_connect(MQTTProperties* willProperties, MQTTProperties* connectProperties, + MQTTPacket_connectData* data, unsigned char* buf, int len) +#else /** * Deserializes the supplied (wire) buffer into connect data structure * @param data the connect data structure to be filled out @@ -49,6 +79,7 @@ int MQTTPacket_checkVersion(MQTTString* protocol, int version) * @return error code. 1 is success, 0 is failure */ int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, int len) +#endif { MQTTHeader header = {0}; MQTTConnectFlags flags = {0}; @@ -56,7 +87,6 @@ int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, in unsigned char* enddata = &buf[len]; int rc = 0; MQTTString Protocol; - int version; int mylen = 0; FUNC_ENTRY; @@ -70,24 +100,38 @@ int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, in enddata - curdata < 0) /* do we have enough data to read the protocol version byte? */ goto exit; - version = (int)readChar(&curdata); /* Protocol version */ + data->MQTTVersion = (int)readChar(&curdata); /* Protocol version */ /* If we don't recognize the protocol version, we don't parse the connect packet on the * basis that we don't know what the format will be. */ - if (MQTTPacket_checkVersion(&Protocol, version)) + if (MQTTPacket_checkVersion(&Protocol, data->MQTTVersion)) { flags.all = readChar(&curdata); data->cleansession = flags.bits.cleansession; data->keepAliveInterval = readInt(&curdata); + #if defined(MQTTV5) + if (data->MQTTVersion == 5) + { + if (!MQTTProperties_read(connectProperties, &curdata, enddata)) + goto exit; + } + #endif if (!readMQTTLenString(&data->clientID, &curdata, enddata)) goto exit; data->willFlag = flags.bits.will; if (flags.bits.will) { + #if defined(MQTTV5) + if (data->MQTTVersion == 5) + { + if (!MQTTProperties_read(willProperties, &curdata, enddata)) + goto exit; + } + #endif data->will.qos = flags.bits.willQoS; data->will.retained = flags.bits.willRetain; if (!readMQTTLenString(&data->will.topicName, &curdata, enddata) || - !readMQTTLenString(&data->will.message, &curdata, enddata)) + !readMQTTLenString(&data->will.message, &curdata, enddata)) goto exit; } if (flags.bits.username) @@ -112,19 +156,38 @@ int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, in * Serializes the connack packet into the supplied buffer. * @param buf the buffer into which the packet will be serialized * @param buflen the length in bytes of the supplied buffer - * @param connack_rc the integer connack return code to be used + * @param connack_rc the integer connack return code to be used * @param sessionPresent the MQTT 3.1.1 sessionPresent flag + * @param connackProperties MQTT v5 properties, if NULL, then MQTT 3.1.1 connack * @return serialized length, or error if 0 */ +#if defined(MQTTV5) int MQTTSerialize_connack(unsigned char* buf, int buflen, unsigned char connack_rc, unsigned char sessionPresent) +{ + return MQTTV5Serialize_connack(buf, buflen, connack_rc, sessionPresent, NULL); +} + +int MQTTV5Serialize_connack(unsigned char* buf, int buflen, unsigned char connack_rc, unsigned char sessionPresent, + MQTTProperties* connackProperties) +#else +int MQTTSerialize_connack(unsigned char* buf, int buflen, unsigned char connack_rc, unsigned char sessionPresent) +#endif { MQTTHeader header = {0}; int rc = 0; unsigned char *ptr = buf; MQTTConnackFlags flags = {0}; + int len = 0; FUNC_ENTRY; - if (buflen < 2) + +#if defined(MQTTV5) + len = 2 + (connackProperties == NULL ? 0 : connackProperties->length); +#else + len = 2; +#endif + + if (MQTTPacket_len(len) > buflen) { rc = MQTTPACKET_BUFFER_TOO_SHORT; goto exit; @@ -133,15 +196,91 @@ int MQTTSerialize_connack(unsigned char* buf, int buflen, unsigned char connack_ header.bits.type = CONNACK; writeChar(&ptr, header.byte); /* write header */ - ptr += MQTTPacket_encode(ptr, 2); /* write remaining length */ + ptr += MQTTPacket_encode(ptr, len); /* write remaining length */ flags.all = 0; flags.bits.sessionpresent = sessionPresent; - writeChar(&ptr, flags.all); + writeChar(&ptr, flags.all); writeChar(&ptr, connack_rc); +#if defined(MQTTV5) + if (connackProperties && MQTTProperties_write(&ptr, connackProperties) < 0) + goto exit; +#endif + rc = ptr - buf; exit: FUNC_EXIT_RC(rc); return rc; -} \ No newline at end of file +} + + +#if defined(MQTTV5) +int MQTTV5Deserialize_zero(unsigned char packettype, MQTTProperties* properties, int* reasonCode, + unsigned char* buf, int buflen) +{ + MQTTHeader header = {0}; + unsigned char* curdata = buf; + unsigned char* enddata = NULL; + int rc = 0; + int mylen; + + FUNC_ENTRY; + header.byte = readChar(&curdata); + if (header.bits.type != packettype) + goto exit; + + curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */ + enddata = curdata + mylen; + + if (mylen > 0) + { + *reasonCode = readChar(&curdata); + mqtt_printf(MQTT_INFO,"%s ReasonCode: %d, %s", MQTTPacketIDPrint((int)packettype),*reasonCode,MQTTGetReason(*reasonCode)); + if (mylen > 1 && !MQTTProperties_read(properties, &curdata, enddata)) + goto exit; + } + + rc = 1; +exit: + FUNC_EXIT_RC(rc); + return rc; +} +#endif + +/** + * Deserializes the supplied (wire) buffer into connack data - return code + * @param sessionPresent the session present flag returned (only for MQTT 3.1.1) + * @param connack_rc returned integer value of the connack return code + * @param buf the raw buffer data, of the correct length determined by the remaining length field + * @param len the length in bytes of the data in the supplied buffer + * @return error code. 1 is success, 0 is failure + */ +#if defined(MQTTV5) +int MQTTV5Deserialize_disconnect(MQTTProperties* properties, int* reasonCode, + unsigned char* buf, int buflen) +{ + return MQTTV5Deserialize_zero(DISCONNECT, properties, reasonCode, buf, buflen); +} + +int MQTTV5Deserialize_auth(MQTTProperties* properties, int* reasonCode, + unsigned char* buf, int buflen) +{ + return MQTTV5Deserialize_zero(AUTH, properties, reasonCode, buf, buflen); +} +#endif + +int MQTTDeserialize_disconnect(unsigned char* buf, int buflen) +{ + unsigned char type = 0; + unsigned char dup = 0; + unsigned short packetid = 0; + int rc = 0; + + FUNC_ENTRY; + rc = MQTTDeserialize_ack(&type, &dup, &packetid, buf, buflen); + if (type == DISCONNECT) + rc = 1; + FUNC_EXIT_RC(rc); + return rc; +} diff --git a/component/common/application/mqtt/MQTTPacket/MQTTFormat.c b/component/common/application/mqtt/MQTTPacket/MQTTFormat.c index 42781e71..4439500b 100644 --- a/component/common/application/mqtt/MQTTPacket/MQTTFormat.c +++ b/component/common/application/mqtt/MQTTPacket/MQTTFormat.c @@ -39,21 +39,21 @@ int MQTTStringFormat_connect(char* strbuf, int strbuflen, MQTTPacket_connectData int strindex = 0; strindex = snprintf(strbuf, strbuflen, - "CONNECT MQTT version %d, client id %.*s, clean session %d, keep alive %d", - (int)data->MQTTVersion, data->clientID.lenstring.len, data->clientID.lenstring.data, - (int)data->cleansession, data->keepAliveInterval); + "CONNECT MQTT version %d, client id %.*s, clean session %d, keep alive %d", + (int)data->MQTTVersion, data->clientID.lenstring.len, data->clientID.lenstring.data, + (int)data->cleansession, data->keepAliveInterval); if (data->willFlag) strindex += snprintf(&strbuf[strindex], strbuflen - strindex, - ", will QoS %d, will retain %d, will topic %.*s, will message %.*s", - data->will.qos, data->will.retained, - data->will.topicName.lenstring.len, data->will.topicName.lenstring.data, - data->will.message.lenstring.len, data->will.message.lenstring.data); + ", will QoS %d, will retain %d, will topic %.*s, will message %.*s", + data->will.qos, data->will.retained, + data->will.topicName.lenstring.len, data->will.topicName.lenstring.data, + data->will.message.lenstring.len, data->will.message.lenstring.data); if (data->username.lenstring.data && data->username.lenstring.len > 0) strindex += snprintf(&strbuf[strindex], strbuflen - strindex, - ", user name %.*s", data->username.lenstring.len, data->username.lenstring.data); + ", user name %.*s", data->username.lenstring.len, data->username.lenstring.data); if (data->password.lenstring.data && data->password.lenstring.len > 0) strindex += snprintf(&strbuf[strindex], strbuflen - strindex, - ", password %.*s", data->password.lenstring.len, data->password.lenstring.data); + ", password %.*s", data->password.lenstring.len, data->password.lenstring.data); return strindex; } @@ -66,13 +66,13 @@ int MQTTStringFormat_connack(char* strbuf, int strbuflen, unsigned char connack_ int MQTTStringFormat_publish(char* strbuf, int strbuflen, unsigned char dup, int qos, unsigned char retained, - unsigned short packetid, MQTTString topicName, unsigned char* payload, int payloadlen) + unsigned short packetid, MQTTString topicName, unsigned char* payload, int payloadlen) { int strindex = snprintf(strbuf, strbuflen, - "PUBLISH dup %d, QoS %d, retained %d, packet id %d, topic %.*s, payload length %d, payload %.*s", - dup, qos, retained, packetid, - (topicName.lenstring.len < 20) ? topicName.lenstring.len : 20, topicName.lenstring.data, - payloadlen, (payloadlen < 20) ? payloadlen : 20, payload); + "PUBLISH dup %d, QoS %d, retained %d, packet id %d, topic %.*s, payload length %d, payload %.*s", + dup, qos, retained, packetid, + (topicName.lenstring.len < 20) ? topicName.lenstring.len : 20, topicName.lenstring.data, + payloadlen, (payloadlen < 20) ? payloadlen : 20, payload); return strindex; } @@ -87,7 +87,7 @@ int MQTTStringFormat_ack(char* strbuf, int strbuflen, unsigned char packettype, int MQTTStringFormat_subscribe(char* strbuf, int strbuflen, unsigned char dup, unsigned short packetid, int count, - MQTTString topicFilters[], int requestedQoSs[]) + MQTTString topicFilters[], int requestedQoSs[]) { return snprintf(strbuf, strbuflen, "SUBSCRIBE dup %d, packet id %d count %d topic %.*s qos %d", @@ -108,28 +108,31 @@ int MQTTStringFormat_unsubscribe(char* strbuf, int strbuflen, unsigned char dup, int count, MQTTString topicFilters[]) { return snprintf(strbuf, strbuflen, - "UNSUBSCRIBE dup %d, packet id %d count %d topic %.*s", - dup, packetid, count, - topicFilters[0].lenstring.len, topicFilters[0].lenstring.data); + "UNSUBSCRIBE dup %d, packet id %d count %d topic %.*s", + dup, packetid, count, + topicFilters[0].lenstring.len, topicFilters[0].lenstring.data); } +#if defined(MQTT_CLIENT) char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf, int buflen) { int index = 0; int rem_length = 0; MQTTHeader header = {0}; + int strindex = 0; header.byte = buf[index++]; index += MQTTPacket_decodeBuf(&buf[index], &rem_length); switch (header.bits.type) { + case CONNACK: { unsigned char sessionPresent, connack_rc; if (MQTTDeserialize_connack(&sessionPresent, &connack_rc, buf, buflen) == 1) - MQTTStringFormat_connack(strbuf, strbuflen, connack_rc, sessionPresent); + strindex = MQTTStringFormat_connack(strbuf, strbuflen, connack_rc, sessionPresent); } break; case PUBLISH: @@ -139,9 +142,9 @@ char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf, int qos, payloadlen; MQTTString topicName = MQTTString_initializer; if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName, - &payload, &payloadlen, buf, buflen) == 1) - MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid, - topicName, payload, payloadlen); + &payload, &payloadlen, buf, buflen) == 1) + strindex = MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid, + topicName, payload, payloadlen); } break; case PUBACK: @@ -152,7 +155,7 @@ char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf, unsigned char packettype, dup; unsigned short packetid; if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1) - MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid); + strindex = MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid); } break; case SUBACK: @@ -161,31 +164,33 @@ char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf, int maxcount = 1, count = 0; int grantedQoSs[1]; if (MQTTDeserialize_suback(&packetid, maxcount, &count, grantedQoSs, buf, buflen) == 1) - MQTTStringFormat_suback(strbuf, strbuflen, packetid, count, grantedQoSs); + strindex = MQTTStringFormat_suback(strbuf, strbuflen, packetid, count, grantedQoSs); } break; case UNSUBACK: { unsigned short packetid; if (MQTTDeserialize_unsuback(&packetid, buf, buflen) == 1) - MQTTStringFormat_ack(strbuf, strbuflen, UNSUBACK, 0, packetid); + strindex = MQTTStringFormat_ack(strbuf, strbuflen, UNSUBACK, 0, packetid); } break; case PINGREQ: case PINGRESP: case DISCONNECT: - snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]); + strindex = snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]); break; } return strbuf; } +#endif - +#if defined(MQTT_SERVER) char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf, int buflen) { int index = 0; int rem_length = 0; MQTTHeader header = {0}; + int strindex = 0; header.byte = buf[index++]; index += MQTTPacket_decodeBuf(&buf[index], &rem_length); @@ -195,8 +200,9 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf, case CONNECT: { MQTTPacket_connectData data; - if ((MQTTDeserialize_connect(&data, buf, buflen)) == 1) - MQTTStringFormat_connect(strbuf, strbuflen, &data); + int rc; + if ((rc = MQTTDeserialize_connect(&data, buf, buflen)) == 1) + strindex = MQTTStringFormat_connect(strbuf, strbuflen, &data); } break; case PUBLISH: @@ -206,9 +212,9 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf, int qos, payloadlen; MQTTString topicName = MQTTString_initializer; if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName, - &payload, &payloadlen, buf, buflen) == 1) - MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid, - topicName, payload, payloadlen); + &payload, &payloadlen, buf, buflen) == 1) + strindex = MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid, + topicName, payload, payloadlen); } break; case PUBACK: @@ -219,7 +225,7 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf, unsigned char packettype, dup; unsigned short packetid; if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1) - MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid); + strindex = MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid); } break; case SUBSCRIBE: @@ -230,8 +236,8 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf, MQTTString topicFilters[1]; int requestedQoSs[1]; if (MQTTDeserialize_subscribe(&dup, &packetid, maxcount, &count, - topicFilters, requestedQoSs, buf, buflen) == 1) - MQTTStringFormat_subscribe(strbuf, strbuflen, dup, packetid, count, topicFilters, requestedQoSs);; + topicFilters, requestedQoSs, buf, buflen) == 1) + strindex = MQTTStringFormat_subscribe(strbuf, strbuflen, dup, packetid, count, topicFilters, requestedQoSs);; } break; case UNSUBSCRIBE: @@ -241,15 +247,16 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf, int maxcount = 1, count = 0; MQTTString topicFilters[1]; if (MQTTDeserialize_unsubscribe(&dup, &packetid, maxcount, &count, topicFilters, buf, buflen) == 1) - MQTTStringFormat_unsubscribe(strbuf, strbuflen, dup, packetid, count, topicFilters); + strindex = MQTTStringFormat_unsubscribe(strbuf, strbuflen, dup, packetid, count, topicFilters); } break; case PINGREQ: case PINGRESP: case DISCONNECT: - snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]); + strindex = snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]); break; } strbuf[strbuflen] = '\0'; return strbuf; -} \ No newline at end of file +} +#endif diff --git a/component/common/application/mqtt/MQTTPacket/MQTTPacket.c b/component/common/application/mqtt/MQTTPacket/MQTTPacket.c index 83f49a4e..036bb255 100644 --- a/component/common/application/mqtt/MQTTPacket/MQTTPacket.c +++ b/component/common/application/mqtt/MQTTPacket/MQTTPacket.c @@ -1,4 +1,4 @@ -/**************************************************************************** +/******************************************************************************* * Copyright (c) 2014 IBM Corp. * * All rights reserved. This program and the accompanying materials @@ -14,6 +14,7 @@ * Ian Craggs - initial API and implementation and/or initial documentation * Sergio R. Caprile - non-blocking packet read functions for stream transport *******************************************************************************/ +#include "platform_opts.h" #include "StackTrace.h" #include "MQTTPacket.h" @@ -53,7 +54,7 @@ int MQTTPacket_encode(unsigned char* buf, int length) */ int MQTTPacket_decode(int (*getcharfn)(unsigned char*, int), int* value) { - unsigned char c; + unsigned char c = 0; int multiplier = 1; int len = 0; #define MAX_NO_OF_REMAINING_LENGTH_BYTES 4 @@ -81,23 +82,28 @@ int MQTTPacket_decode(int (*getcharfn)(unsigned char*, int), int* value) } -int MQTTPacket_len(int rem_len) +int MQTTPacket_VBIlen(int rem_len) { - rem_len += 1; /* header byte */ + int rc = 0; - /* now remaining_length field */ if (rem_len < 128) - rem_len += 1; + rc = 1; else if (rem_len < 16384) - rem_len += 2; - else if (rem_len < 2097151) - rem_len += 3; + rc = 2; + else if (rem_len < 2097152) + rc = 3; else - rem_len += 4; - return rem_len; + rc = 4; + return rc; } +int MQTTPacket_len(int rem_len) +{ + /* header byte + remaining length */ + return rem_len + 1 + MQTTPacket_VBIlen(rem_len); +} + static unsigned char* bufptr; int bufchar(unsigned char* c, int count) @@ -262,7 +268,7 @@ int MQTTPacket_equals(MQTTString* a, char* bptr) int alen = 0, blen = 0; char *aptr; - + if (a->cstring) { aptr = a->cstring; @@ -274,7 +280,7 @@ int MQTTPacket_equals(MQTTString* a, char* bptr) alen = a->lenstring.len; } blen = strlen(bptr); - + return (alen == blen) && (strncmp(aptr, bptr, alen) == 0); } @@ -306,7 +312,7 @@ int MQTTPacket_read(unsigned char* buf, int buflen, int (*getfn)(unsigned char*, /* 3. read the rest of the buffer using a callback to supply the rest of the data */ if((rem_len + len) > buflen) goto exit; - if ((*getfn)(buf + len, rem_len) != rem_len) + if (rem_len && ((*getfn)(buf + len, rem_len) != rem_len)) goto exit; header.byte = buf[0]; @@ -323,7 +329,7 @@ int MQTTPacket_read(unsigned char* buf, int buflen, int (*getfn)(unsigned char*, */ static int MQTTPacket_decodenb(MQTTTransport *trp) { - unsigned char c; + unsigned char c = 0; int rc = MQTTPACKET_READ_ERROR; FUNC_ENTRY; @@ -333,7 +339,7 @@ static int MQTTPacket_decodenb(MQTTTransport *trp) } do { int frc; - if (++(trp->len) > MAX_NO_OF_REMAINING_LENGTH_BYTES) + if (trp->len >= MAX_NO_OF_REMAINING_LENGTH_BYTES) goto exit; if ((frc=(*trp->getfn)(trp->sck, &c, 1)) == -1) goto exit; @@ -341,6 +347,7 @@ static int MQTTPacket_decodenb(MQTTTransport *trp) rc = 0; goto exit; } + ++(trp->len); trp->rem_len += (c & 127) * trp->multiplier; trp->multiplier *= 128; } while ((c & 128) != 0); @@ -388,16 +395,17 @@ int MQTTPacket_readnb(unsigned char* buf, int buflen, MQTTTransport *trp) ++trp->state; /*FALLTHROUGH*/ case 2: - /* read the rest of the buffer using a callback to supply the rest of the data */ - if ((frc=(*trp->getfn)(trp->sck, buf + trp->len, trp->rem_len)) == -1) - goto exit; - if (frc == 0) - return 0; - trp->rem_len -= frc; - trp->len += frc; - if(trp->rem_len) - return 0; - + if(trp->rem_len){ + /* read the rest of the buffer using a callback to supply the rest of the data */ + if ((frc=(*trp->getfn)(trp->sck, buf + trp->len, trp->rem_len)) == -1) + goto exit; + if (frc == 0) + return 0; + trp->rem_len -= frc; + trp->len += frc; + if(trp->rem_len) + return 0; + } header.byte = buf[0]; rc = header.bits.type; break; @@ -407,4 +415,3 @@ int MQTTPacket_readnb(unsigned char* buf, int buflen, MQTTTransport *trp) trp->state = 0; return rc; } - diff --git a/component/common/application/mqtt/MQTTPacket/V5/MQTTProperties.c b/component/common/application/mqtt/MQTTPacket/V5/MQTTProperties.c new file mode 100644 index 00000000..8762345e --- /dev/null +++ b/component/common/application/mqtt/MQTTPacket/V5/MQTTProperties.c @@ -0,0 +1,418 @@ +/******************************************************************************* +* Copyright (c) 2017 IBM Corp. +* +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* and Eclipse Distribution License v1.0 which accompany this distribution. +* +* The Eclipse Public License is available at +* http://www.eclipse.org/legal/epl-v10.html +* and the Eclipse Distribution License is available at +* http://www.eclipse.org/org/documents/edl-v10.php. +* +* Contributors: +* Ian Craggs - initial API and implementation and/or initial documentation +*******************************************************************************/ + +#include "MQTTV5Packet.h" +#include "MQTTClient.h" +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) + +struct nameToType +{ + enum PropertyNames name; + enum PropertyTypes type; +} namesToTypes[] = +{ + {PAYLOAD_FORMAT_INDICATOR, BYTE}, + {MESSAGE_EXPIRY_INTERVAL, FOUR_BYTE_INTEGER}, + {CONTENT_TYPE, UTF_8_ENCODED_STRING}, + {RESPONSE_TOPIC, UTF_8_ENCODED_STRING}, + {CORRELATION_DATA, BINARY_DATA}, + {SUBSCRIPTION_IDENTIFIER, VARIABLE_BYTE_INTEGER}, + {SESSION_EXPIRY_INTERVAL, FOUR_BYTE_INTEGER}, + {ASSIGNED_CLIENT_IDENTIFER, UTF_8_ENCODED_STRING}, + {SERVER_KEEP_ALIVE, TWO_BYTE_INTEGER}, + {AUTHENTICATION_METHOD, UTF_8_ENCODED_STRING}, + {AUTHENTICATION_DATA, BINARY_DATA}, + {REQUEST_PROBLEM_INFORMATION, BYTE}, + {WILL_DELAY_INTERVAL, FOUR_BYTE_INTEGER}, + {REQUEST_RESPONSE_INFORMATION, BYTE}, + {RESPONSE_INFORMATION, UTF_8_ENCODED_STRING}, + {SERVER_REFERENCE, UTF_8_ENCODED_STRING}, + {REASON_STRING, UTF_8_ENCODED_STRING}, + {RECEIVE_MAXIMUM, TWO_BYTE_INTEGER}, + {TOPIC_ALIAS_MAXIMUM, TWO_BYTE_INTEGER}, + {TOPIC_ALIAS, TWO_BYTE_INTEGER}, + {MAXIMUM_QOS, BYTE}, + {RETAIN_AVAILABLE, BYTE}, + {USER_PROPERTY, UTF_8_STRING_PAIR}, + {MAXIMUM_PACKET_SIZE, FOUR_BYTE_INTEGER}, + {WILDCARD_SUBSCRIPTION_AVAILABLE, BYTE}, + {SUBSCRIPTION_IDENTIFIER_AVAILABLE, BYTE}, + {SHARED_SUBSCRIPTION_AVAILABLE, BYTE} +}; + +struct nametoStringname +{ + enum PropertyNames name; + const char* namestr; +} nametoStringname[] = +{ + {PAYLOAD_FORMAT_INDICATOR, "PAYLOAD_FORMAT_INDICATOR"}, + {MESSAGE_EXPIRY_INTERVAL, "MESSAGE_EXPIRY_INTERVAL"}, + {CONTENT_TYPE, "CONTENT_TYPE"}, + {RESPONSE_TOPIC, "RESPONSE_TOPIC"}, + {CORRELATION_DATA, "CORRELATION_DATA"}, + {SUBSCRIPTION_IDENTIFIER, "SUBSCRIPTION_IDENTIFIER"}, + {SESSION_EXPIRY_INTERVAL, "SESSION_EXPIRY_INTERVAL"}, + {ASSIGNED_CLIENT_IDENTIFER, "ASSIGNED_CLIENT_IDENTIFER"}, + {SERVER_KEEP_ALIVE, "SERVER_KEEP_ALIVE"}, + {AUTHENTICATION_METHOD, "AUTHENTICATION_METHOD"}, + {AUTHENTICATION_DATA, "AUTHENTICATION_DATA"}, + {REQUEST_PROBLEM_INFORMATION, "REQUEST_PROBLEM_INFORMATION"}, + {WILL_DELAY_INTERVAL, "WILL_DELAY_INTERVAL"}, + {REQUEST_RESPONSE_INFORMATION, "REQUEST_RESPONSE_INFORMATION"}, + {RESPONSE_INFORMATION, "RESPONSE_INFORMATION"}, + {SERVER_REFERENCE, "SERVER_REFERENCE"}, + {REASON_STRING, "REASON_STRING"}, + {RECEIVE_MAXIMUM, "RECEIVE_MAXIMUM"}, + {TOPIC_ALIAS_MAXIMUM, "TOPIC_ALIAS_MAXIMUM"}, + {TOPIC_ALIAS, "TOPIC_ALIAS"}, + {MAXIMUM_QOS, "MAXIMUM_QOS"}, + {RETAIN_AVAILABLE, "RETAIN_AVAILABLE"}, + {USER_PROPERTY, "USER_PROPERTY"}, + {MAXIMUM_PACKET_SIZE, "MAXIMUM_PACKET_SIZE"}, + {WILDCARD_SUBSCRIPTION_AVAILABLE, "WILDCARD_SUBSCRIPTION_AVAILABLE"}, + {SUBSCRIPTION_IDENTIFIER_AVAILABLE, "SUBSCRIPTION_IDENTIFIER_AVAILABLE"}, + {SHARED_SUBSCRIPTION_AVAILABLE, "SHARED_SUBSCRIPTION_AVAILABLE"} +}; + +int MQTTProperty_getType(int identifier) +{ + int i, rc = -1; + + for (i = 0; i < ARRAY_SIZE(namesToTypes); ++i) + { + if (namesToTypes[i].name == identifier) + { + rc = namesToTypes[i].type; + break; + } + } + return rc; +} + +const char* MQTTProperty_stringname(int identifier) +{ + int i; + const char* rc = ""; + + for (i = 0; i < ARRAY_SIZE(nametoStringname); ++i) + { + if (nametoStringname[i].name == identifier) + { + rc = nametoStringname[i].namestr; + break; + } + } + return rc; +} + + +int MQTTProperties_len(MQTTProperties* props) +{ + /* properties length is an mbi */ + return props->length + MQTTPacket_VBIlen(props->length); +} + + +int MQTTProperties_add(MQTTProperties* props, MQTTProperty* prop) +{ + int rc = 0, type; + + if (props->count == props->max_count) + rc = -1; /* max number of properties already in structure */ + else if ((type = MQTTProperty_getType(prop->identifier)) < 0) + rc = -2; + else + { + int len = 0; + + props->array[props->count++] = *prop; + /* calculate length */ + switch (type) + { + case BYTE: + len = 1; + break; + case TWO_BYTE_INTEGER: + len = 2; + break; + case FOUR_BYTE_INTEGER: + len = 4; + break; + case VARIABLE_BYTE_INTEGER: + if (prop->value.integer4 >= 0 && prop->value.integer4 <= 127) + len = 1; + else if (prop->value.integer4 >= 128 && prop->value.integer4 <= 16383) + len = 2; + else if (prop->value.integer4 >= 16384 && prop->value.integer4 < 2097151) + len = 3; + else if (prop->value.integer4 >= 2097152 && prop->value.integer4 < 268435455) + len = 4; + break; + case BINARY_DATA: + case UTF_8_ENCODED_STRING: + len = 2 + prop->value.data.len; + break; + case UTF_8_STRING_PAIR: + len = 2 + prop->value.data.len; + len += 2 + prop->value.value.len; + break; + } + props->length += len + 1; /* add identifier byte */ + } + + return rc; +} + + +int MQTTProperty_write(unsigned char** pptr, MQTTProperty* prop) +{ + int rc = -1, + type = -1; + + type = MQTTProperty_getType(prop->identifier); + if (type >= BYTE && type <= UTF_8_STRING_PAIR) + { + writeChar(pptr, prop->identifier); + switch (type) + { + case BYTE: + writeChar(pptr, prop->value.byte); + rc = 1; + break; + case TWO_BYTE_INTEGER: + writeInt(pptr, prop->value.integer2); + rc = 2; + break; + case FOUR_BYTE_INTEGER: + writeInt4(pptr, prop->value.integer4); + rc = 4; + break; + case VARIABLE_BYTE_INTEGER: + rc = MQTTPacket_encode(*pptr, prop->value.integer4); + break; + case BINARY_DATA: + case UTF_8_ENCODED_STRING: + writeMQTTLenString(pptr, prop->value.data); + rc = prop->value.data.len + 2; /* include length field */ + break; + case UTF_8_STRING_PAIR: + writeMQTTLenString(pptr, prop->value.data); + writeMQTTLenString(pptr, prop->value.value); + rc = prop->value.data.len + prop->value.value.len + 4; /* include length fields */ + break; + } + } + return rc + 1; /* include identifier byte */ +} + + +/** +* write the supplied properties into a packet buffer +* @param pptr pointer to the buffer - move the pointer as we add data +* @param remlength the max length of the buffer +* @return whether the write succeeded or not, number of bytes written or < 0 +*/ +int MQTTProperties_write(unsigned char** pptr, MQTTProperties* properties) +{ + int rc = -1; + int i = 0, len = 0; + /* write the entire property list length first */ + *pptr += MQTTPacket_encode(*pptr, properties->length); + len = rc = 1; + for (i = 0; i < properties->count; ++i) + { + rc = MQTTProperty_write(pptr, &properties->array[i]); + if (rc < 0) + break; + else + len += rc; + } + if (rc >= 0) + rc = len; + return rc; +} + + +int MQTTProperty_read(MQTTProperty* prop, unsigned char** pptr, unsigned char* enddata) +{ + int type = -1, + len = 0; + + prop->identifier = readChar(pptr); + type = MQTTProperty_getType(prop->identifier); + if (type >= BYTE && type <= UTF_8_STRING_PAIR) + { + switch (type) + { + case BYTE: + prop->value.byte = readChar(pptr); + len = 1; + break; + case TWO_BYTE_INTEGER: + prop->value.integer2 = readInt(pptr); + len = 2; + break; + case FOUR_BYTE_INTEGER: + prop->value.integer4 = readInt4(pptr); + len = 4; + break; + case VARIABLE_BYTE_INTEGER: + len = MQTTPacket_decodeBuf(*pptr, &prop->value.integer4); + *pptr += len; + break; + case BINARY_DATA: + case UTF_8_ENCODED_STRING: + len = MQTTLenStringRead(&prop->value.data, pptr, enddata); + break; + case UTF_8_STRING_PAIR: + len = MQTTLenStringRead(&prop->value.data, pptr, enddata); + len += MQTTLenStringRead(&prop->value.value, pptr, enddata); + break; + } + } + return len + 1; /* 1 byte for identifier */ +} + + +int MQTTProperties_read(MQTTProperties* properties, unsigned char** pptr, unsigned char* enddata) +{ + int rc = 0; + int remlength = 0; + + properties->count = 0; + if (enddata - (*pptr) > 0) /* enough length to read the VBI? */ + { + *pptr += MQTTPacket_decodeBuf(*pptr, &remlength); + properties->length = remlength; + while (properties->count < properties->max_count && remlength > 0) + { + remlength -= MQTTProperty_read(&properties->array[properties->count], pptr, enddata); + properties->count++; + } + if (remlength == 0) + { + MQTTProperties_Handle(properties); + rc = 1; /* data read successfully */ + } + } + + return rc; +} + +int MQTTProperties_Handle(MQTTProperties* properties) +{ + int rc = 0; + int i = 0; + MQTTProperty *arr = properties->array; + while (arr && i < properties->count ) + { + //check for properties values that affect subequent value + MQTTProperty_check(&properties->array[i]); + if (!MQTTProperty_print(&properties->array[i])) + { + mqtt_printf(MQTT_ERROR, "Invalid Property"); + goto EXIT; + } + arr++; + i++; + } + rc = 1; +EXIT: + return rc; +} +#if defined(MQTTV5) +int MQTTProperty_check(MQTTProperty* property) +{ + switch (property->identifier) + { + case MAXIMUM_QOS: + gMAXQOSSpecified = property->value.byte; + break; + case RETAIN_AVAILABLE: + gRetainAvailable = property->value.byte; + break; + case MAXIMUM_PACKET_SIZE: + gMaxPacketSize = property->value.integer4; + break; + case SERVER_KEEP_ALIVE: + gServerKeepAlive = property->value.integer2; + default: + return 1; + } + return 1; +} +#endif + +int MQTTProperty_print(MQTTProperty* property) +{ + int type = -1; + int i = 0; + char* buf; + type = MQTTProperty_getType(property->identifier); + printf("Property ID: %s, ", MQTTProperty_stringname(property->identifier)); + if (type >= BYTE && type <= UTF_8_STRING_PAIR) + { + switch (type) + { + case BYTE: + printf("Value: %x\r\n", property->value.byte); + break; + case TWO_BYTE_INTEGER: + printf("Value: %d\r\n", property->value.integer2); + break; + case FOUR_BYTE_INTEGER: + printf("Value: %d\r\n", property->value.integer4); + break; + case VARIABLE_BYTE_INTEGER: + printf("Value: %d\r\n", property->value.integer4); + break; + case BINARY_DATA: + case UTF_8_ENCODED_STRING: + buf = property->value.data.data; + printf("Value: "); + for(i = 0;i < property->value.data.len;i++) + { + printf("%c", *buf); + buf++; + } + printf("\r\n"); + break; + case UTF_8_STRING_PAIR: + buf = property->value.data.data; + printf("String Pair Key: "); + for(i = 0;i < property->value.data.len;i++) + { + printf("%c", *buf); + buf++; + } + printf(", "); + buf = property->value.value.data; + printf("String Pair Value: "); + for(i = 0;i < property->value.value.len;i++) + { + printf("%c", *buf); + buf++; + } + printf("\r\n"); + break; + default: + //break incase of error format + return 0; + } + } + return 1; +} diff --git a/component/common/application/mqtt/MQTTPacket/V5/MQTTProperties.h b/component/common/application/mqtt/MQTTPacket/V5/MQTTProperties.h new file mode 100644 index 00000000..4f6dab16 --- /dev/null +++ b/component/common/application/mqtt/MQTTPacket/V5/MQTTProperties.h @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (c) 2017 IBM Corp. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Ian Craggs - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef __MQTTProperties_h__ + #define __MQTTProperties_h__ + +#include "platform_opts.h" + +#if defined(MQTTV5) +static int gMAXQOSSpecified = 2; +static int gRetainAvailable = 1; +static int gMaxPacketSize = 2147483647; //2^21-1 +static int gServerKeepAlive = -1; +#endif + +enum PropertyNames { + PAYLOAD_FORMAT_INDICATOR = 1, + MESSAGE_EXPIRY_INTERVAL = 2, + CONTENT_TYPE = 3, + RESPONSE_TOPIC = 8, + CORRELATION_DATA = 9, + SUBSCRIPTION_IDENTIFIER = 11, + SESSION_EXPIRY_INTERVAL = 17, + ASSIGNED_CLIENT_IDENTIFER = 18, + SERVER_KEEP_ALIVE = 19, + AUTHENTICATION_METHOD = 21, + AUTHENTICATION_DATA = 22, + REQUEST_PROBLEM_INFORMATION = 23, + WILL_DELAY_INTERVAL = 24, + REQUEST_RESPONSE_INFORMATION = 25, + RESPONSE_INFORMATION = 26, + SERVER_REFERENCE = 28, + REASON_STRING = 31, + RECEIVE_MAXIMUM = 33, + TOPIC_ALIAS_MAXIMUM = 34, + TOPIC_ALIAS = 35, + MAXIMUM_QOS = 36, + RETAIN_AVAILABLE = 37, + USER_PROPERTY = 38, + MAXIMUM_PACKET_SIZE = 39, + WILDCARD_SUBSCRIPTION_AVAILABLE = 40, + SUBSCRIPTION_IDENTIFIER_AVAILABLE = 41, + SHARED_SUBSCRIPTION_AVAILABLE = 42 +}; + +enum PropertyTypes { + BYTE, + TWO_BYTE_INTEGER, + FOUR_BYTE_INTEGER, + VARIABLE_BYTE_INTEGER, + BINARY_DATA, + UTF_8_ENCODED_STRING, + UTF_8_STRING_PAIR +}; + + +typedef struct +{ + int identifier; /* mbi */ + union { + char byte; + unsigned short integer2; + int integer4; + MQTTLenString data; + MQTTLenString value; /* for user properties */ + } value; +} MQTTProperty; + +typedef struct MQTTProperties +{ + int count; /* number of property entries */ + int max_count; + int length; /* mbi: byte length of all properties */ + MQTTProperty *array; /* array of properties */ +} MQTTProperties; + +#define MQTTProperties_initializer {0, 0, 0, NULL} + +int MQTTProperties_len(MQTTProperties* props); + +/** + * Add the property pointer to the property array, no allocation, just a reference + * @param props + * @param prop + * @return whether the write succeeded or not, number of bytes written or < 0 + */ +int MQTTProperties_add(MQTTProperties* props, MQTTProperty* prop); + +int MQTTProperties_write(unsigned char** pptr, MQTTProperties* properties); + +int MQTTProperties_read(MQTTProperties* properties, unsigned char** pptr, unsigned char* enddata); +/** + * Print out MQTT Properties + * @param properties to print + * @return success or fail + */ +int MQTTProperties_Handle(MQTTProperties* properties); +/** + * Check for properties + * @param property + * @return 0 + */ +int MQTTProperty_check(MQTTProperty* property); +/** + * Print property + * @param property + * @return 1 + */ +int MQTTProperty_print(MQTTProperty* property); +#endif \ No newline at end of file diff --git a/component/common/application/mqtt/MQTTPacket/V5/MQTTReasonCodes.h b/component/common/application/mqtt/MQTTPacket/V5/MQTTReasonCodes.h new file mode 100644 index 00000000..ee3d5430 --- /dev/null +++ b/component/common/application/mqtt/MQTTPacket/V5/MQTTReasonCodes.h @@ -0,0 +1,67 @@ +/******************************************************************************* +* Copyright (c) 2017 IBM Corp. +* +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* and Eclipse Distribution License v1.0 which accompany this distribution. +* +* The Eclipse Public License is available at +* http://www.eclipse.org/legal/epl-v10.html +* and the Eclipse Distribution License is available at +* http://www.eclipse.org/org/documents/edl-v10.php. +* +* Contributors: +* Ian Craggs - initial API and implementation and/or initial documentation +*******************************************************************************/ +#ifndef __MQTTREASONCODES_H__ +#define __MQTTREASONCODES_H__ + +enum ReasonCodes { + //SUCCESS = 0, + NORMAL_DISCONNECTION = 0, + GRANTED_QOS_0 = 0, + GRANTED_QOS_1 = 1, + GRANTED_QOS_2 = 2, + DISCONNECT_WITH_WILL_MESSAGE = 4, + NO_MATCHING_SUBSCRIBERS = 16, + NO_SUBSCRIPTION_FOUND = 17, + CONTINUE_AUTHENTICATION = 24, + RE_AUTHENTICATE = 25, + UNSPECIFIED_ERROR = 128, + MALFORMED_PACKET = 129, + PROTOCOL_ERROR = 130, + IMPLEMENTATION_SPECIFIC_ERROR = 131, + UNSUPPORTED_PROTOCOL_VERSION = 132, + CLIENT_IDENTIFIER_NOT_VALID = 133, + BAD_USER_NAME_OR_PASSWORD = 134, + NOT_AUTHORIZED = 135, + SERVER_UNAVAILABLE = 136, + SERVER_BUSY = 137, + BANNED = 138, + SERVER_SHUTTING_DOWN = 139, + BAD_AUTHENTICATION_METHOD = 140, + KEEP_ALIVE_TIMEOUT = 141, + SESSION_TAKEN_OVER = 142, + TOPIC_FILTER_INVALID = 143, + TOPIC_NAME_INVALID = 144, + PACKET_IDENTIFIER_IN_USE = 145, + PACKET_IDENTIFIER_NOT_FOUND = 146, + RECEIVE_MAXIMUM_EXCEEDED = 147, + TOPIC_ALIAS_INVALID = 148, + PACKET_TOO_LARGE = 149, + MESSAGE_RATE_TOO_HIGH = 150, + QUOTA_EXCEEDED = 151, + ADMINISTRATIVE_ACTION = 152, + PAYLOAD_FORMAT_INVALID = 153, + RETAIN_NOT_SUPPORTED = 154, + QOS_NOT_SUPPORTED = 155, + USE_ANOTHER_SERVER = 156, + SERVER_MOVED = 157, + SHARED_SUBSCRIPTION_NOT_SUPPORTED = 158, + CONNECTION_RATE_EXCEEDED = 159, + MAXIMUM_CONNECT_TIME = 160, + SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED = 161, + WILDCARD_SUBSCRIPTION_NOT_SUPPORTED = 162 +}; + +#endif \ No newline at end of file diff --git a/component/common/application/mqtt/MQTTPacket/V5/MQTTV5Connect.h b/component/common/application/mqtt/MQTTPacket/V5/MQTTV5Connect.h new file mode 100644 index 00000000..abcdb932 --- /dev/null +++ b/component/common/application/mqtt/MQTTPacket/V5/MQTTV5Connect.h @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2017 IBM Corp. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Ian Craggs - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef MQTT5CONNECT_H_ +#define MQTT5CONNECT_H_ + +#include "MQTTConnect.h" +#include "MQTTClient.h" + +DLLExport int MQTTV5Serialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData* options, + MQTTProperties* connectProperties, MQTTProperties* willProperties); + +DLLExport int MQTTV5Deserialize_connect(MQTTProperties* willProperties, + MQTTProperties* connectProperties, MQTTPacket_connectData* data, unsigned char* buf, int len); + +DLLExport int MQTTV5Serialize_connack(unsigned char* buf, int buflen, unsigned char connack_rc, + unsigned char sessionPresent, MQTTProperties* connackProperties); + +DLLExport int MQTTV5Deserialize_connack(MQTTProperties* connackProperties, + unsigned char* sessionPresent, unsigned char* connack_rc, unsigned char* buf, int buflen); + +DLLExport int MQTTV5Serialize_disconnect(unsigned char* buf, int buflen, int reasonCode, + MQTTProperties* properties); + +DLLExport int MQTTV5Deserialize_disconnect(MQTTProperties* properties, int* reasonCode, + unsigned char* buf, int buflen); + +DLLExport int MQTTV5Serialize_auth(unsigned char* buf, int buflen, int reasonCode, + MQTTProperties* properties); + +DLLExport int MQTTV5Deserialize_auth(MQTTProperties* properties, int* reasonCode, + unsigned char* buf, int buflen); + +DLLExport int MQTTV5Connect(MQTTClient* c, MQTTPacket_connectData* options, MQTTProperties* connectproperties, MQTTProperties* willproperties); + +DLLExport int MQTTV5Disconnect(MQTTClient* c, int ReasonCode, MQTTProperties* DisconProperties); +#endif /* MQTTV5CONNECT_H_ */ diff --git a/component/common/application/mqtt/MQTTPacket/V5/MQTTV5Packet.c b/component/common/application/mqtt/MQTTPacket/V5/MQTTV5Packet.c new file mode 100644 index 00000000..79915fbb --- /dev/null +++ b/component/common/application/mqtt/MQTTPacket/V5/MQTTV5Packet.c @@ -0,0 +1,79 @@ +/******************************************************************************* +* Copyright (c) 2017 IBM Corp. +* +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* and Eclipse Distribution License v1.0 which accompany this distribution. +* +* The Eclipse Public License is available at +* http://www.eclipse.org/legal/epl-v10.html +* and the Eclipse Distribution License is available at +* http://www.eclipse.org/org/documents/edl-v10.php. +* +* Contributors: +* Ian Craggs - initial API and implementation and/or initial documentation +*******************************************************************************/ + +#include "MQTTV5Packet.h" + +#include + +/** +* Writes an integer as 4 bytes to an output buffer. +* @param pptr pointer to the output buffer - incremented by the number of bytes used & returned +* @param anInt the integer to write +*/ +void writeInt4(unsigned char** pptr, int anInt) +{ + **pptr = (unsigned char)(anInt / 16777216); + (*pptr)++; + anInt %= 16777216; + **pptr = (unsigned char)(anInt / 65536); + (*pptr)++; + anInt %= 65536; + **pptr = (unsigned char)(anInt / 256); + (*pptr)++; + **pptr = (unsigned char)(anInt % 256); + (*pptr)++; +} + + +/** +* Calculates an integer from two bytes read from the input buffer +* @param pptr pointer to the input buffer - incremented by the number of bytes used & returned +* @return the integer value calculated +*/ +int readInt4(unsigned char** pptr) +{ + unsigned char* ptr = *pptr; + int value = 16777216*(*ptr) + 65536*(*(ptr+1)) + 256*(*(ptr+2)) + (*(ptr+3)); + *pptr += 4; + return value; +} + + +void writeMQTTLenString(unsigned char** pptr, MQTTLenString lenstring) +{ + writeInt(pptr, lenstring.len); + memcpy(*pptr, lenstring.data, lenstring.len); + *pptr += lenstring.len; +} + + +int MQTTLenStringRead(MQTTLenString* lenstring, unsigned char** pptr, unsigned char* enddata) +{ + int len = 0; + + /* the first two bytes are the length of the string */ + if (enddata - (*pptr) > 1) /* enough length to read the integer? */ + { + lenstring->len = readInt(pptr); /* increments pptr to point past length */ + if (&(*pptr)[lenstring->len] <= enddata) + { + lenstring->data = (char*)*pptr; + *pptr += lenstring->len; + len = 2 + lenstring->len; + } + } + return len; +} diff --git a/component/common/application/mqtt/MQTTPacket/V5/MQTTV5Packet.h b/component/common/application/mqtt/MQTTPacket/V5/MQTTV5Packet.h new file mode 100644 index 00000000..b52515dc --- /dev/null +++ b/component/common/application/mqtt/MQTTPacket/V5/MQTTV5Packet.h @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2017 IBM Corp. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Ian Craggs - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "MQTTPacket.h" + +#if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ +extern "C" { +#endif + +#include "MQTTReasonCodes.h" + +#include "MQTTProperties.h" + +#include "MQTTV5Connect.h" + +#include "MQTTV5Publish.h" + +#include "MQTTV5Subscribe.h" + +#include "MQTTV5Unsubscribe.h" + +void writeInt4(unsigned char** pptr, int anInt); +int readInt4(unsigned char** pptr); + +void writeMQTTLenString(unsigned char** pptr, MQTTLenString lenstring); + +int MQTTLenStringRead(MQTTLenString* lenstring, unsigned char** pptr, unsigned char* enddata); + +#if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ +} +#endif diff --git a/component/common/application/mqtt/MQTTPacket/V5/MQTTV5Publish.h b/component/common/application/mqtt/MQTTPacket/V5/MQTTV5Publish.h new file mode 100644 index 00000000..4c888c23 --- /dev/null +++ b/component/common/application/mqtt/MQTTPacket/V5/MQTTV5Publish.h @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2017 IBM Corp. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Ian Craggs - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#if !defined(MQTTV5PUBLISH_H_) +#define MQTTV5PUBLISH_H_ + +#if !defined(DLLImport) + #define DLLImport +#endif +#if !defined(DLLExport) + #define DLLExport +#endif + +#include "MQTTPublish.h" +#include "MQTTClient.h" + +DLLExport int MQTTV5Serialize_publish(unsigned char* buf, int buflen, unsigned char dup, int qos, unsigned char retained, + unsigned short packetid, MQTTString topicName, MQTTProperties* props, unsigned char* payload, int payloadlen); + +DLLExport int MQTTV5Deserialize_publish(unsigned char* dup, int* qos, unsigned char* retained, unsigned short* packetid, MQTTString* topicName, + MQTTProperties* props, unsigned char** payload, int* payloadlen, unsigned char* buf, int len); + +DLLExport int MQTTV5Serialize_puback(unsigned char* buf, int buflen, unsigned short packetid, + int reasonCode, MQTTProperties* properties); + +DLLExport int MQTTV5Serialize_pubrec(unsigned char* buf, int buflen, unsigned short packetid, + int reasonCode, MQTTProperties* properties); + +DLLExport int MQTTV5Serialize_pubrel(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid, + int reasonCode, MQTTProperties* properties); + +DLLExport int MQTTV5Serialize_pubcomp(unsigned char* buf, int buflen, unsigned short packetid, + int reasonCode, MQTTProperties* properties); + +DLLExport int MQTTV5Deserialize_ack(unsigned char* packettype, unsigned char* dup, unsigned short* packetid, + int *reasonCode, MQTTProperties* properties, unsigned char* buf, int buflen); + +DLLExport int MQTTV5PublishHandle(MQTTClient* c, const char* topicName, MQTTMessage* message, MQTTProperties* pubproperties); + +DLLExport int MQTTV5Serialize_ack(unsigned char* buf, int buflen, unsigned char packettype, unsigned char dup, unsigned short packetid, + int reasonCode, MQTTProperties* properties); +#endif /* MQTTV5PUBLISH_H_ */ diff --git a/component/common/application/mqtt/MQTTPacket/V5/MQTTV5Subscribe.h b/component/common/application/mqtt/MQTTPacket/V5/MQTTV5Subscribe.h new file mode 100644 index 00000000..ac9e9614 --- /dev/null +++ b/component/common/application/mqtt/MQTTPacket/V5/MQTTV5Subscribe.h @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2017 IBM Corp. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Ian Craggs - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef MQTTV5SUBSCRIBE_H_ +#define MQTTV5SUBSCRIBE_H_ + +#if !defined(DLLImport) + #define DLLImport +#endif +#if !defined(DLLExport) + #define DLLExport +#endif + +#include "MQTTClient.h" + +struct subscribeOptions +{ + unsigned char MaxQOS; /* 0 or 1 */ + unsigned char noLocal; /* 0 or 1 */ + unsigned char retainAsPublished; /* 0 or 1 */ + unsigned char retainHandling; /* 0, 1 or 2 */ +}; + +DLLExport int MQTTV5Serialize_subscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid, + MQTTProperties* properties, int count, MQTTString topicFilters[], int requestedQoSs[], struct subscribeOptions options[]); + +DLLExport int MQTTV5Deserialize_subscribe(unsigned char* dup, unsigned short* packetid, MQTTProperties* properties, + int maxcount, int* count, MQTTString topicFilters[], int requestedQoSs[], struct subscribeOptions options[], + unsigned char* buf, int len); + +DLLExport int MQTTV5Serialize_suback(unsigned char* buf, int buflen, unsigned short packetid, + MQTTProperties* properties, int count, int* reasonCodes); + +DLLExport int MQTTV5Deserialize_suback(unsigned short* packetid, MQTTProperties* properties, + int maxcount, int* count, int* reasonCodes, unsigned char* buf, int len); + +DLLExport int MQTTV5Subscribe(MQTTClient* c, const char* topicFilter, struct subscribeOptions* options, + messageHandler messageHandler, MQTTProperties* subproperties); + +#endif /* MQTTV5SUBSCRIBE_H_ */ diff --git a/component/common/application/mqtt/MQTTPacket/V5/MQTTV5Unsubscribe.h b/component/common/application/mqtt/MQTTPacket/V5/MQTTV5Unsubscribe.h new file mode 100644 index 00000000..87e98f7a --- /dev/null +++ b/component/common/application/mqtt/MQTTPacket/V5/MQTTV5Unsubscribe.h @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2017 IBM Corp. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Ian Craggs - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef MQTTV5UNSUBSCRIBE_H_ +#define MQTTV5UNSUBSCRIBE_H_ + +#if !defined(DLLImport) + #define DLLImport +#endif +#if !defined(DLLExport) + #define DLLExport +#endif + +DLLExport int MQTTV5Serialize_unsubscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid, + MQTTProperties* properties, int count, MQTTString* topicFilters); + +DLLExport int MQTTV5Deserialize_unsubscribe(unsigned char* dup, unsigned short* packetid, MQTTProperties* properties, + int maxcount, int* count, MQTTString* topicFilters, unsigned char* buf, int len); + +DLLExport int MQTTV5Serialize_unsuback(unsigned char* buf, int buflen, unsigned short packetid, + MQTTProperties* properties, int count, int* reasonCodes); + +DLLExport int MQTTV5Deserialize_unsuback(unsigned short* packetid, MQTTProperties* properties, + int maxcount, int* count, int* reasonCodes, unsigned char* buf, int len); + +int MQTTV5Deserialize_subunsuback(int type, unsigned short* packetid, MQTTProperties* properties, + int maxcount, int* count, int* reasonCodes, unsigned char* buf, int buflen); + + +#endif /* MQTTV5UNSUBSCRIBE_H_ */ diff --git a/component/common/bluetooth/realtek/sdk/board/amebaz2/lib/btgap.a b/component/common/bluetooth/realtek/sdk/board/amebaz2/lib/btgap.a index ac79dda0..970fa66b 100644 Binary files a/component/common/bluetooth/realtek/sdk/board/amebaz2/lib/btgap.a and b/component/common/bluetooth/realtek/sdk/board/amebaz2/lib/btgap.a differ diff --git a/component/common/bluetooth/realtek/sdk/board/amebaz2/lib/release_note.txt b/component/common/bluetooth/realtek/sdk/board/amebaz2/lib/release_note.txt index f09d046f..c60aca5f 100644 --- a/component/common/bluetooth/realtek/sdk/board/amebaz2/lib/release_note.txt +++ b/component/common/bluetooth/realtek/sdk/board/amebaz2/lib/release_note.txt @@ -2,6 +2,23 @@ /* * Release Note */ + v1.0.1.186 + 2022/09/28 + 1. Add API le_bond_get_pair_procedure_type. + + v1.0.1.185 + 2022/09/23 + 1. Fix a bug about timer not stop when disconnect. + + v1.0.1.184 + 2022/08/31 + 1. Add API client_send_exchange_mtu_req. + 2. Add GAP_PARAM_MASTER_INIT_GATT_MTU_REQ . + + v1.0.1.183 + 2022/08/26 + 1. Fix an exchange mtu issue. + v1.0.1.179 2022/06/10 1. Add API le_get_dev_ltk. diff --git a/component/common/bluetooth/realtek/sdk/board/amebaz2/src/hci/bt_normal_patch.c b/component/common/bluetooth/realtek/sdk/board/amebaz2/src/hci/bt_normal_patch.c index cf6de1aa..77efedcc 100644 --- a/component/common/bluetooth/realtek/sdk/board/amebaz2/src/hci/bt_normal_patch.c +++ b/component/common/bluetooth/realtek/sdk/board/amebaz2/src/hci/bt_normal_patch.c @@ -3,15 +3,15 @@ ******************************************************************************* * Copyright(c) 2019, Realtek Semiconductor Corporation. All rights reserved. ******************************************************************************* - * @file AmebaZ2_mp_chip_bt40_fw_asic_rom_patch_0x4EB7_E051_220505_1345_new.(AmebaZ2_bt_220505).bin - * @date 2022-05-05 13:45 + * @file AmebaZ2_mp_chip_bt40_fw_asic_rom_patch_0xEAB8_5FAC_220831_1640_new.(AmebaZ2_bt_220831).bin + * @date 2022-08-31 16:40 * @patch2 HCI ver: 0x42A8, LMP ver: 0x54A4, BTCOEX Version: 20151130-0202, SVN ver: 24941 - * @patch4 HCI ver: 0x4EDF, LMP ver: 0x614E, BTCOEX Version: 20151130-0202, SVN ver: 1323262286 + * @patch4 HCI ver: 0xE8F4, LMP ver: 0xEDB1, BTCOEX Version: 20151130-0202, SVN ver: 3908365745 */ const unsigned char rtlbt_fw[] = { - 0x52, 0x65, 0x61, 0x6c, 0x74, 0x65, 0x63, 0x68, 0x51, 0xe0, 0xb7, 0x4e, - 0x02, 0x00, 0x02, 0x00, 0x04, 0x00, 0xb8, 0x1f, 0x34, 0x1e, 0x30, 0x00, + 0x52, 0x65, 0x61, 0x6c, 0x74, 0x65, 0x63, 0x68, 0xac, 0x5f, 0xb8, 0xea, + 0x02, 0x00, 0x02, 0x00, 0x04, 0x00, 0xb8, 0x1f, 0xbc, 0x1d, 0x30, 0x00, 0x00, 0x00, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x63, 0x07, 0x62, 0x06, 0xd1, 0x05, 0xd0, 0x55, 0xb2, 0x40, 0x9a, @@ -698,27 +698,27 @@ const unsigned char rtlbt_fw[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xfc, 0x63, 0x07, 0x62, 0x06, 0xd1, 0x05, 0xd0, 0x5b, 0xb2, 0x40, 0x9a, - 0x5b, 0xb3, 0x5c, 0xb0, 0x42, 0x34, 0x82, 0x34, 0x80, 0xcb, 0x5b, 0xb3, - 0x40, 0xcb, 0x5b, 0xb2, 0x40, 0xea, 0x00, 0x69, 0x5a, 0xb3, 0x5b, 0xb2, - 0x60, 0xda, 0x5b, 0xb3, 0x5b, 0xb2, 0x60, 0xda, 0x5b, 0xb3, 0x5c, 0xb2, - 0x60, 0xda, 0x5c, 0xb3, 0x5c, 0xb2, 0x60, 0xda, 0x5c, 0xb3, 0x5d, 0xb2, + 0xfc, 0x63, 0x07, 0x62, 0x06, 0xd1, 0x05, 0xd0, 0x5d, 0xb2, 0x40, 0x9a, + 0x5d, 0xb3, 0x5e, 0xb0, 0x42, 0x34, 0x82, 0x34, 0x80, 0xcb, 0x5d, 0xb3, + 0x40, 0xcb, 0x5d, 0xb2, 0x40, 0xea, 0x00, 0x69, 0x5c, 0xb3, 0x5d, 0xb2, 0x60, 0xda, 0x5d, 0xb3, 0x5d, 0xb2, 0x60, 0xda, 0x5d, 0xb3, 0x5e, 0xb2, - 0x60, 0xda, 0x5e, 0xb3, 0x5e, 0xb2, 0x60, 0xda, 0xa0, 0xf0, 0x4b, 0xa0, + 0x60, 0xda, 0x5e, 0xb3, 0x5e, 0xb2, 0x60, 0xda, 0x5e, 0xb3, 0x5f, 0xb2, + 0x60, 0xda, 0x5f, 0xb3, 0x5f, 0xb2, 0x60, 0xda, 0x5f, 0xb3, 0x60, 0xb2, + 0x60, 0xda, 0x60, 0xb3, 0x60, 0xb2, 0x60, 0xda, 0xa0, 0xf0, 0x4b, 0xa0, 0xa0, 0xf0, 0x6a, 0xa0, 0x40, 0x32, 0x6d, 0xea, 0xa0, 0xf0, 0x6c, 0xa0, 0x60, 0x33, 0x60, 0x33, 0x4d, 0xeb, 0xa0, 0xf0, 0x4d, 0xa0, 0x00, 0xf6, 0x40, 0x32, 0x6d, 0xea, 0x08, 0xf0, 0x01, 0x6b, 0x6b, 0xeb, 0x6c, 0xea, 0x42, 0x33, 0xa0, 0xf0, 0x4a, 0xc0, 0xa0, 0xf0, 0x6b, 0xc0, 0x00, 0xf6, 0x42, 0x32, 0x62, 0x33, 0xa0, 0xf0, 0x6c, 0xc0, 0xa0, 0xf0, 0x4d, 0xc0, - 0x4e, 0xb3, 0x4f, 0xb2, 0x60, 0xda, 0x4f, 0xb2, 0x40, 0xea, 0x00, 0x65, - 0x4e, 0xb3, 0x4f, 0xb2, 0x60, 0xda, 0x4f, 0xb3, 0x4f, 0xb2, 0x60, 0xda, - 0x4f, 0xb3, 0x50, 0xb2, 0x66, 0xda, 0x50, 0xb2, 0x20, 0xc2, 0x50, 0xb3, - 0x50, 0xb2, 0x65, 0xda, 0x50, 0xb3, 0x51, 0xb2, 0x60, 0xda, 0x51, 0xb2, - 0x40, 0xea, 0x00, 0x65, 0x50, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x50, 0xb3, - 0x50, 0xb2, 0x60, 0xda, 0x50, 0xb2, 0x51, 0xb3, 0x60, 0xda, 0xe0, 0xf0, - 0x23, 0xc0, 0x51, 0x67, 0x44, 0x33, 0x4f, 0xb4, 0x01, 0x4a, 0x6d, 0xe4, - 0x18, 0x52, 0x00, 0x6c, 0x80, 0xcb, 0xf8, 0x61, 0x4c, 0xb3, 0x4d, 0xb2, - 0x60, 0xda, 0x4d, 0xb3, 0x4d, 0xb2, 0x60, 0xda, 0x21, 0xb2, 0xa0, 0xf0, + 0x50, 0xb3, 0x51, 0xb2, 0x60, 0xda, 0x51, 0xb2, 0x40, 0xea, 0x00, 0x65, + 0x50, 0xb3, 0x51, 0xb2, 0x60, 0xda, 0x51, 0xb3, 0x51, 0xb2, 0x60, 0xda, + 0x51, 0xb3, 0x52, 0xb2, 0x66, 0xda, 0x52, 0xb2, 0x20, 0xc2, 0x52, 0xb3, + 0x52, 0xb2, 0x65, 0xda, 0x52, 0xb3, 0x53, 0xb2, 0x60, 0xda, 0x53, 0xb2, + 0x40, 0xea, 0x00, 0x65, 0x52, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x52, 0xb3, + 0x52, 0xb2, 0x60, 0xda, 0x52, 0xb2, 0x53, 0xb3, 0x60, 0xda, 0xe0, 0xf0, + 0x23, 0xc0, 0x51, 0x67, 0x44, 0x33, 0x51, 0xb4, 0x01, 0x4a, 0x6d, 0xe4, + 0x18, 0x52, 0x00, 0x6c, 0x80, 0xcb, 0xf8, 0x61, 0x4e, 0xb3, 0x4f, 0xb2, + 0x60, 0xda, 0x4f, 0xb3, 0x4f, 0xb2, 0x60, 0xda, 0x23, 0xb2, 0xa0, 0xf0, 0x61, 0xa2, 0xa0, 0xf0, 0x80, 0xa2, 0x60, 0x33, 0x8d, 0xeb, 0xef, 0xf7, 0x1f, 0x6c, 0x8c, 0xeb, 0xa0, 0xf0, 0x60, 0xc2, 0x62, 0x33, 0xa0, 0xf0, 0x61, 0xc2, 0xa0, 0xf0, 0x6f, 0xa2, 0xa0, 0xf0, 0x8e, 0xa2, 0x60, 0x33, @@ -726,82 +726,87 @@ const unsigned char rtlbt_fw[] = { 0xa0, 0xf0, 0x71, 0xa2, 0x00, 0xf6, 0x60, 0x33, 0x8d, 0xeb, 0x01, 0x6c, 0x8d, 0xeb, 0x62, 0x34, 0xa0, 0xf0, 0x6e, 0xc2, 0xa0, 0xf0, 0x8f, 0xc2, 0x00, 0xf6, 0x62, 0x33, 0x82, 0x34, 0xa0, 0xf0, 0x71, 0xc2, 0xa0, 0xf0, - 0x90, 0xc2, 0x37, 0xb3, 0x37, 0xb2, 0x60, 0xda, 0x37, 0xb3, 0x38, 0xb2, - 0x60, 0xda, 0x38, 0xb3, 0x38, 0xb2, 0x60, 0xda, 0x38, 0xb3, 0x39, 0xb2, - 0x60, 0xda, 0x07, 0x97, 0x06, 0x91, 0x05, 0x90, 0x00, 0xef, 0x04, 0x63, - 0x30, 0x3e, 0x10, 0x80, 0x32, 0x01, 0x12, 0x80, 0x38, 0x01, 0x12, 0x80, - 0x30, 0x01, 0x12, 0x80, 0xf1, 0x39, 0x10, 0x80, 0xb1, 0x30, 0x10, 0x80, - 0xd0, 0x08, 0x12, 0x80, 0x99, 0x34, 0x10, 0x80, 0xcc, 0x05, 0x12, 0x80, - 0x39, 0x34, 0x10, 0x80, 0xd8, 0x03, 0x12, 0x80, 0xf5, 0x33, 0x10, 0x80, - 0xdc, 0x03, 0x12, 0x80, 0x05, 0x33, 0x10, 0x80, 0x04, 0x06, 0x12, 0x80, - 0xb5, 0x31, 0x10, 0x80, 0xf0, 0x06, 0x12, 0x80, 0x4d, 0x22, 0x10, 0x80, - 0xf8, 0x06, 0x12, 0x80, 0x95, 0x31, 0x10, 0x80, 0xec, 0x05, 0x12, 0x80, - 0x29, 0x36, 0x10, 0x80, 0x08, 0x07, 0x12, 0x80, 0xe9, 0x34, 0x10, 0x80, - 0x8d, 0x2d, 0x10, 0x80, 0xe8, 0x08, 0x12, 0x80, 0x0d, 0x2e, 0x10, 0x80, - 0xcc, 0x04, 0x12, 0x80, 0x01, 0x2c, 0x10, 0x80, 0x38, 0x03, 0x12, 0x80, - 0x00, 0x3c, 0x12, 0x80, 0xa9, 0x26, 0x10, 0x80, 0xe4, 0x03, 0x12, 0x80, - 0x4d, 0x26, 0x10, 0x80, 0x8c, 0x08, 0x12, 0x80, 0x6d, 0x33, 0x10, 0x80, - 0xa9, 0x30, 0x00, 0x80, 0xc5, 0x22, 0x10, 0x80, 0xa4, 0x08, 0x12, 0x80, - 0xb8, 0x08, 0x12, 0x80, 0x85, 0x27, 0x10, 0x80, 0x04, 0x3c, 0x12, 0x80, - 0xc5, 0x29, 0x10, 0x80, 0xf0, 0x05, 0x12, 0x80, 0xe9, 0x3c, 0x10, 0x80, - 0xdc, 0x28, 0x12, 0x80, 0x21, 0x25, 0x10, 0x80, 0x34, 0x05, 0x12, 0x80, - 0xbd, 0x3c, 0x10, 0x80, 0x7c, 0x00, 0x12, 0x80, 0x85, 0x3c, 0x10, 0x80, - 0xc4, 0x08, 0x12, 0x80, 0xa9, 0x3a, 0x10, 0x80, 0x2c, 0x05, 0x12, 0x80, - 0x64, 0xa4, 0x43, 0xa4, 0xe0, 0xa5, 0x60, 0x33, 0x4d, 0xe3, 0xff, 0xf7, - 0x1f, 0x6a, 0x4c, 0xeb, 0x9f, 0xf5, 0x00, 0x73, 0x00, 0x6a, 0x0c, 0x61, - 0x1f, 0xf7, 0x00, 0x6b, 0xcc, 0xeb, 0xe9, 0xe4, 0x62, 0x33, 0x62, 0xc2, - 0x41, 0x47, 0xff, 0x6b, 0x6c, 0xea, 0x41, 0xc4, 0x40, 0xc5, 0x01, 0x6a, - 0x20, 0xe8, 0x00, 0x65, 0xff, 0x6b, 0x8c, 0xeb, 0x09, 0x5b, 0x12, 0x6a, - 0x19, 0x61, 0x0c, 0x73, 0x0a, 0x60, 0x0d, 0x73, 0x0f, 0x60, 0x0b, 0x6a, - 0x4e, 0xeb, 0x01, 0x5b, 0x78, 0x67, 0x0a, 0x6a, 0x6b, 0xeb, 0x20, 0xe8, - 0x6c, 0xea, 0x08, 0xb2, 0x00, 0xf1, 0x40, 0xaa, 0xa1, 0x5a, 0x08, 0x61, - 0x20, 0xe8, 0xa0, 0x6a, 0x04, 0xb2, 0x40, 0xf0, 0x48, 0xaa, 0x1f, 0x5a, - 0x01, 0x61, 0x1e, 0x6a, 0x20, 0xe8, 0x00, 0x65, 0x10, 0x23, 0x12, 0x80, - 0x42, 0xa4, 0x04, 0xb3, 0x49, 0xe3, 0x01, 0x6b, 0x60, 0xc2, 0x20, 0xe8, - 0x01, 0x6a, 0x00, 0x65, 0x44, 0x3c, 0x12, 0x80, 0xff, 0xf7, 0x1f, 0x6a, - 0x4c, 0xed, 0x8c, 0xea, 0x09, 0x10, 0x01, 0x4a, 0x09, 0x6b, 0x7a, 0xea, - 0x01, 0x2b, 0xe5, 0xe8, 0xff, 0xf7, 0x1f, 0x6b, 0x10, 0xea, 0x6c, 0xea, - 0x08, 0xb3, 0x80, 0xf0, 0x92, 0xa3, 0x4e, 0xec, 0x09, 0x24, 0x48, 0x34, - 0x8d, 0xe3, 0x60, 0x9b, 0x80, 0xab, 0xe1, 0xf7, 0x1f, 0x6b, 0x8c, 0xeb, - 0xae, 0xeb, 0xe9, 0x23, 0x20, 0xe8, 0x00, 0x65, 0x4c, 0x0a, 0x12, 0x80, + 0x90, 0xc2, 0x39, 0xb3, 0x39, 0xb2, 0x60, 0xda, 0x39, 0xb3, 0x3a, 0xb2, + 0x60, 0xda, 0x3a, 0xb3, 0x3a, 0xb2, 0x60, 0xda, 0x3a, 0xb3, 0x3b, 0xb2, + 0x60, 0xda, 0x3b, 0xb3, 0x3b, 0xb2, 0x60, 0xda, 0x07, 0x97, 0x06, 0x91, + 0x05, 0x90, 0x00, 0xef, 0x04, 0x63, 0x00, 0x65, 0xb8, 0x3d, 0x10, 0x80, + 0x32, 0x01, 0x12, 0x80, 0x38, 0x01, 0x12, 0x80, 0x30, 0x01, 0x12, 0x80, + 0x95, 0x39, 0x10, 0x80, 0x9d, 0x30, 0x10, 0x80, 0xd0, 0x08, 0x12, 0x80, + 0x3d, 0x34, 0x10, 0x80, 0xcc, 0x05, 0x12, 0x80, 0xdd, 0x33, 0x10, 0x80, + 0xd8, 0x03, 0x12, 0x80, 0x99, 0x33, 0x10, 0x80, 0xdc, 0x03, 0x12, 0x80, + 0xa9, 0x32, 0x10, 0x80, 0x04, 0x06, 0x12, 0x80, 0x59, 0x31, 0x10, 0x80, + 0xf0, 0x06, 0x12, 0x80, 0x5d, 0x22, 0x10, 0x80, 0xf8, 0x06, 0x12, 0x80, + 0x39, 0x31, 0x10, 0x80, 0xec, 0x05, 0x12, 0x80, 0xcd, 0x35, 0x10, 0x80, + 0x08, 0x07, 0x12, 0x80, 0x8d, 0x34, 0x10, 0x80, 0x79, 0x2d, 0x10, 0x80, + 0xe8, 0x08, 0x12, 0x80, 0xf9, 0x2d, 0x10, 0x80, 0xcc, 0x04, 0x12, 0x80, + 0xed, 0x2b, 0x10, 0x80, 0x38, 0x03, 0x12, 0x80, 0x00, 0x3c, 0x12, 0x80, + 0x95, 0x26, 0x10, 0x80, 0xe4, 0x03, 0x12, 0x80, 0x39, 0x26, 0x10, 0x80, + 0x8c, 0x08, 0x12, 0x80, 0x11, 0x33, 0x10, 0x80, 0xa9, 0x30, 0x00, 0x80, + 0xd5, 0x22, 0x10, 0x80, 0xa4, 0x08, 0x12, 0x80, 0xb8, 0x08, 0x12, 0x80, + 0x71, 0x27, 0x10, 0x80, 0x04, 0x3c, 0x12, 0x80, 0xb1, 0x29, 0x10, 0x80, + 0xf0, 0x05, 0x12, 0x80, 0x7d, 0x3c, 0x10, 0x80, 0xdc, 0x28, 0x12, 0x80, + 0x5d, 0x25, 0x10, 0x80, 0x34, 0x05, 0x12, 0x80, 0x51, 0x3c, 0x10, 0x80, + 0x7c, 0x00, 0x12, 0x80, 0x19, 0x3c, 0x10, 0x80, 0xc4, 0x08, 0x12, 0x80, + 0x4d, 0x3a, 0x10, 0x80, 0x2c, 0x05, 0x12, 0x80, 0xe9, 0x24, 0x10, 0x80, + 0xd4, 0x04, 0x12, 0x80, 0x64, 0xa4, 0x43, 0xa4, 0xe0, 0xa5, 0x60, 0x33, + 0x4d, 0xe3, 0xff, 0xf7, 0x1f, 0x6a, 0x4c, 0xeb, 0x9f, 0xf5, 0x00, 0x73, + 0x00, 0x6a, 0x0c, 0x61, 0x1f, 0xf7, 0x00, 0x6b, 0xcc, 0xeb, 0xe9, 0xe4, + 0x62, 0x33, 0x62, 0xc2, 0x41, 0x47, 0xff, 0x6b, 0x6c, 0xea, 0x41, 0xc4, + 0x40, 0xc5, 0x01, 0x6a, 0x20, 0xe8, 0x00, 0x65, 0xff, 0x6b, 0x8c, 0xeb, + 0x09, 0x5b, 0x12, 0x6a, 0x19, 0x61, 0x0c, 0x73, 0x0a, 0x60, 0x0d, 0x73, + 0x0f, 0x60, 0x0b, 0x6a, 0x4e, 0xeb, 0x01, 0x5b, 0x78, 0x67, 0x0a, 0x6a, + 0x6b, 0xeb, 0x20, 0xe8, 0x6c, 0xea, 0x08, 0xb2, 0x00, 0xf1, 0x40, 0xaa, + 0xa1, 0x5a, 0x08, 0x61, 0x20, 0xe8, 0xa0, 0x6a, 0x04, 0xb2, 0x40, 0xf0, + 0x48, 0xaa, 0x1f, 0x5a, 0x01, 0x61, 0x1e, 0x6a, 0x20, 0xe8, 0x00, 0x65, + 0x10, 0x23, 0x12, 0x80, 0x42, 0xa4, 0x04, 0xb3, 0x49, 0xe3, 0x01, 0x6b, + 0x60, 0xc2, 0x20, 0xe8, 0x01, 0x6a, 0x00, 0x65, 0x44, 0x3c, 0x12, 0x80, 0xff, 0xf7, 0x1f, 0x6a, 0x4c, 0xed, 0x8c, 0xea, 0x09, 0x10, 0x01, 0x4a, 0x09, 0x6b, 0x7a, 0xea, 0x01, 0x2b, 0xe5, 0xe8, 0xff, 0xf7, 0x1f, 0x6b, 0x10, 0xea, 0x6c, 0xea, 0x08, 0xb3, 0x80, 0xf0, 0x92, 0xa3, 0x4e, 0xec, 0x09, 0x24, 0x48, 0x34, 0x8d, 0xe3, 0x60, 0x9b, 0x80, 0xab, 0xe1, 0xf7, - 0x1f, 0x6b, 0x8c, 0xeb, 0xae, 0xeb, 0xe9, 0x2b, 0x20, 0xe8, 0x00, 0x65, - 0x4c, 0x0a, 0x12, 0x80, 0xff, 0xf7, 0x1f, 0x6a, 0x8c, 0xea, 0x09, 0x10, - 0x01, 0x4a, 0x09, 0x6b, 0x7a, 0xea, 0x01, 0x2b, 0xe5, 0xe8, 0xff, 0xf7, - 0x1f, 0x6b, 0x10, 0xea, 0x6c, 0xea, 0x07, 0xb3, 0x80, 0xf0, 0x92, 0xa3, - 0x4e, 0xec, 0x06, 0x24, 0x87, 0x42, 0x13, 0x4c, 0x88, 0x34, 0x8d, 0xe3, - 0x61, 0x9b, 0xec, 0x2b, 0x20, 0xe8, 0x00, 0x65, 0x4c, 0x0a, 0x12, 0x80, - 0xfe, 0x63, 0x03, 0xd1, 0x02, 0xd0, 0xff, 0x6a, 0x8c, 0xea, 0x2a, 0xb6, - 0x2a, 0xb5, 0x2b, 0xb7, 0x2b, 0xb4, 0x2c, 0xb0, 0x28, 0x22, 0x40, 0xae, - 0xff, 0xf7, 0x1d, 0x6b, 0x0a, 0x65, 0x28, 0x67, 0x2c, 0xeb, 0x60, 0xce, - 0x28, 0xb6, 0xc0, 0xae, 0x60, 0xad, 0xff, 0xf7, 0x1f, 0x6a, 0x0e, 0x65, - 0xc0, 0xaf, 0xe8, 0x67, 0x4c, 0xeb, 0xd9, 0xe7, 0x00, 0xf4, 0x00, 0x6f, - 0xe0, 0xf3, 0x1f, 0x69, 0xeb, 0xef, 0x2c, 0xee, 0xec, 0xeb, 0xcd, 0xeb, - 0xdd, 0x67, 0x60, 0xce, 0x60, 0xae, 0x60, 0xcd, 0x60, 0xac, 0xa8, 0x67, - 0x6c, 0xea, 0x60, 0xa8, 0xec, 0xea, 0x6d, 0xe5, 0x2c, 0xeb, 0x6d, 0xea, - 0x40, 0xce, 0x40, 0xae, 0x1f, 0x10, 0x60, 0xae, 0xff, 0xf7, 0x1f, 0x6a, - 0x02, 0x69, 0x4c, 0xeb, 0x2d, 0xeb, 0x4c, 0xeb, 0x60, 0xce, 0x60, 0xad, - 0x20, 0xaf, 0x00, 0xf4, 0x00, 0x6e, 0x4c, 0xeb, 0xe0, 0xf3, 0x1f, 0x6f, - 0xcb, 0xee, 0xec, 0xe9, 0xcc, 0xeb, 0x2d, 0xeb, 0x3d, 0x67, 0x60, 0xc9, - 0x60, 0xa9, 0x60, 0xcd, 0x60, 0xac, 0x6c, 0xea, 0x60, 0xa8, 0xcc, 0xea, - 0x6c, 0xef, 0xed, 0xea, 0x40, 0xc9, 0x40, 0xa9, 0x40, 0xcc, 0x03, 0x91, - 0x02, 0x90, 0x20, 0xe8, 0x02, 0x63, 0x00, 0x65, 0x58, 0x12, 0x00, 0xb6, - 0x10, 0x12, 0x00, 0xb6, 0x34, 0x3c, 0x12, 0x80, 0x12, 0x12, 0x00, 0xb6, - 0x36, 0x3c, 0x12, 0x80, 0x38, 0x3c, 0x12, 0x80, 0xfd, 0x63, 0x05, 0x62, - 0x04, 0xd0, 0x83, 0xa4, 0x05, 0x67, 0x12, 0x6a, 0x02, 0x5c, 0x0f, 0x60, - 0x0a, 0xb2, 0x20, 0xf0, 0x68, 0xa2, 0x01, 0x6a, 0x6c, 0xea, 0x03, 0x22, - 0x01, 0x74, 0x0c, 0x6a, 0x06, 0x60, 0x07, 0xb2, 0x80, 0xca, 0x07, 0xb2, - 0x40, 0xea, 0x00, 0x65, 0x00, 0x6a, 0x40, 0xc0, 0x05, 0x97, 0x04, 0x90, - 0x00, 0xef, 0x03, 0x63, 0x10, 0x23, 0x12, 0x80, 0x3a, 0x3c, 0x12, 0x80, - 0x91, 0x23, 0x10, 0x80, 0x62, 0xa4, 0x43, 0xa4, 0x01, 0x73, 0x13, 0x61, - 0x08, 0x5a, 0x11, 0x60, 0x0a, 0xb3, 0x40, 0xc3, 0x0a, 0xb4, 0x40, 0xf0, - 0xa4, 0xac, 0x07, 0x6b, 0x4c, 0xeb, 0x80, 0xf3, 0x01, 0x6a, 0x4b, 0xea, - 0x7c, 0x33, 0xac, 0xea, 0x6d, 0xea, 0x40, 0xf0, 0x44, 0xcc, 0x20, 0xe8, - 0x00, 0x6a, 0x20, 0xe8, 0x12, 0x6a, 0x00, 0x65, 0x34, 0x03, 0x12, 0x80, - 0x10, 0x23, 0x12, 0x80, 0xfc, 0x63, 0x07, 0x62, 0x06, 0xd0, 0x0e, 0xb2, + 0x1f, 0x6b, 0x8c, 0xeb, 0xae, 0xeb, 0xe9, 0x23, 0x20, 0xe8, 0x00, 0x65, + 0x4c, 0x0a, 0x12, 0x80, 0xff, 0xf7, 0x1f, 0x6a, 0x4c, 0xed, 0x8c, 0xea, + 0x09, 0x10, 0x01, 0x4a, 0x09, 0x6b, 0x7a, 0xea, 0x01, 0x2b, 0xe5, 0xe8, + 0xff, 0xf7, 0x1f, 0x6b, 0x10, 0xea, 0x6c, 0xea, 0x08, 0xb3, 0x80, 0xf0, + 0x92, 0xa3, 0x4e, 0xec, 0x09, 0x24, 0x48, 0x34, 0x8d, 0xe3, 0x60, 0x9b, + 0x80, 0xab, 0xe1, 0xf7, 0x1f, 0x6b, 0x8c, 0xeb, 0xae, 0xeb, 0xe9, 0x2b, + 0x20, 0xe8, 0x00, 0x65, 0x4c, 0x0a, 0x12, 0x80, 0xff, 0xf7, 0x1f, 0x6a, + 0x8c, 0xea, 0x09, 0x10, 0x01, 0x4a, 0x09, 0x6b, 0x7a, 0xea, 0x01, 0x2b, + 0xe5, 0xe8, 0xff, 0xf7, 0x1f, 0x6b, 0x10, 0xea, 0x6c, 0xea, 0x07, 0xb3, + 0x80, 0xf0, 0x92, 0xa3, 0x4e, 0xec, 0x06, 0x24, 0x87, 0x42, 0x13, 0x4c, + 0x88, 0x34, 0x8d, 0xe3, 0x61, 0x9b, 0xec, 0x2b, 0x20, 0xe8, 0x00, 0x65, + 0x4c, 0x0a, 0x12, 0x80, 0xfe, 0x63, 0x03, 0xd1, 0x02, 0xd0, 0xff, 0x6a, + 0x8c, 0xea, 0x2a, 0xb6, 0x2a, 0xb5, 0x2b, 0xb7, 0x2b, 0xb4, 0x2c, 0xb0, + 0x28, 0x22, 0x40, 0xae, 0xff, 0xf7, 0x1d, 0x6b, 0x0a, 0x65, 0x28, 0x67, + 0x2c, 0xeb, 0x60, 0xce, 0x28, 0xb6, 0xc0, 0xae, 0x60, 0xad, 0xff, 0xf7, + 0x1f, 0x6a, 0x0e, 0x65, 0xc0, 0xaf, 0xe8, 0x67, 0x4c, 0xeb, 0xd9, 0xe7, + 0x00, 0xf4, 0x00, 0x6f, 0xe0, 0xf3, 0x1f, 0x69, 0xeb, 0xef, 0x2c, 0xee, + 0xec, 0xeb, 0xcd, 0xeb, 0xdd, 0x67, 0x60, 0xce, 0x60, 0xae, 0x60, 0xcd, + 0x60, 0xac, 0xa8, 0x67, 0x6c, 0xea, 0x60, 0xa8, 0xec, 0xea, 0x6d, 0xe5, + 0x2c, 0xeb, 0x6d, 0xea, 0x40, 0xce, 0x40, 0xae, 0x1f, 0x10, 0x60, 0xae, + 0xff, 0xf7, 0x1f, 0x6a, 0x02, 0x69, 0x4c, 0xeb, 0x2d, 0xeb, 0x4c, 0xeb, + 0x60, 0xce, 0x60, 0xad, 0x20, 0xaf, 0x00, 0xf4, 0x00, 0x6e, 0x4c, 0xeb, + 0xe0, 0xf3, 0x1f, 0x6f, 0xcb, 0xee, 0xec, 0xe9, 0xcc, 0xeb, 0x2d, 0xeb, + 0x3d, 0x67, 0x60, 0xc9, 0x60, 0xa9, 0x60, 0xcd, 0x60, 0xac, 0x6c, 0xea, + 0x60, 0xa8, 0xcc, 0xea, 0x6c, 0xef, 0xed, 0xea, 0x40, 0xc9, 0x40, 0xa9, + 0x40, 0xcc, 0x03, 0x91, 0x02, 0x90, 0x20, 0xe8, 0x02, 0x63, 0x00, 0x65, + 0x58, 0x12, 0x00, 0xb6, 0x10, 0x12, 0x00, 0xb6, 0x34, 0x3c, 0x12, 0x80, + 0x12, 0x12, 0x00, 0xb6, 0x36, 0x3c, 0x12, 0x80, 0x38, 0x3c, 0x12, 0x80, + 0xfd, 0x63, 0x05, 0x62, 0x04, 0xd0, 0x83, 0xa4, 0x05, 0x67, 0x12, 0x6a, + 0x02, 0x5c, 0x0f, 0x60, 0x0a, 0xb2, 0x20, 0xf0, 0x68, 0xa2, 0x01, 0x6a, + 0x6c, 0xea, 0x03, 0x22, 0x01, 0x74, 0x0c, 0x6a, 0x06, 0x60, 0x07, 0xb2, + 0x80, 0xca, 0x07, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x00, 0x6a, 0x40, 0xc0, + 0x05, 0x97, 0x04, 0x90, 0x00, 0xef, 0x03, 0x63, 0x10, 0x23, 0x12, 0x80, + 0x3a, 0x3c, 0x12, 0x80, 0xa1, 0x23, 0x10, 0x80, 0x62, 0xa4, 0x43, 0xa4, + 0x01, 0x73, 0x13, 0x61, 0x08, 0x5a, 0x11, 0x60, 0x0a, 0xb3, 0x40, 0xc3, + 0x0a, 0xb4, 0x40, 0xf0, 0xa4, 0xac, 0x07, 0x6b, 0x4c, 0xeb, 0x80, 0xf3, + 0x01, 0x6a, 0x4b, 0xea, 0x7c, 0x33, 0xac, 0xea, 0x6d, 0xea, 0x40, 0xf0, + 0x44, 0xcc, 0x20, 0xe8, 0x00, 0x6a, 0x20, 0xe8, 0x12, 0x6a, 0x00, 0x65, + 0x34, 0x03, 0x12, 0x80, 0x10, 0x23, 0x12, 0x80, 0xfc, 0x63, 0x07, 0x62, + 0x06, 0xd1, 0x05, 0xd0, 0x07, 0xb1, 0xff, 0xf7, 0x1f, 0x68, 0x40, 0xa9, + 0x4c, 0xe8, 0x06, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x00, 0xc9, 0x07, 0x97, + 0x06, 0x91, 0x05, 0x90, 0x00, 0xef, 0x04, 0x63, 0x12, 0x10, 0x00, 0xb6, + 0xbd, 0xc6, 0x01, 0x80, 0xfc, 0x63, 0x07, 0x62, 0x06, 0xd0, 0x0e, 0xb2, 0xff, 0x68, 0x8c, 0xe8, 0x81, 0x9a, 0x0d, 0xb2, 0x40, 0xea, 0x04, 0x05, 0x0f, 0x2a, 0x04, 0x92, 0x01, 0x6b, 0x6b, 0xeb, 0x60, 0xc2, 0x04, 0x92, 0x02, 0x6b, 0x61, 0xc2, 0x04, 0x92, 0x03, 0x6b, 0x62, 0xc2, 0x04, 0x92, @@ -819,498 +824,484 @@ const unsigned char rtlbt_fw[] = { 0x0b, 0xd3, 0x40, 0xee, 0x90, 0x67, 0x0b, 0x93, 0x0a, 0x92, 0xa6, 0xa0, 0x10, 0x6c, 0xad, 0xec, 0x86, 0xc0, 0x04, 0x6c, 0x04, 0xd4, 0x15, 0xb4, 0x05, 0xd4, 0x06, 0xd2, 0x51, 0xa8, 0x02, 0x6c, 0x07, 0xd2, 0x53, 0xa8, - 0x02, 0xf0, 0x00, 0x6e, 0x49, 0xf6, 0x1e, 0x6f, 0x08, 0xd2, 0x55, 0xa8, + 0x22, 0xf0, 0x03, 0x6e, 0x49, 0xf6, 0x1e, 0x6f, 0x08, 0xd2, 0x55, 0xa8, 0x0b, 0xd3, 0x09, 0xd2, 0x0e, 0xb2, 0x40, 0xea, 0xfa, 0x6d, 0x0b, 0x93, 0x01, 0x49, 0xff, 0x6a, 0x4c, 0xe9, 0x0c, 0xb2, 0x40, 0x9a, 0x43, 0xe9, 0xb2, 0x61, 0x04, 0xb2, 0x60, 0xca, 0x0f, 0x97, 0x0e, 0x91, 0x0d, 0x90, 0x00, 0xef, 0x08, 0x63, 0x52, 0x12, 0x00, 0xb6, 0x10, 0x23, 0x12, 0x80, - 0x38, 0x01, 0x12, 0x80, 0x04, 0x05, 0x12, 0x80, 0x3c, 0x3d, 0x10, 0x80, - 0xd1, 0x27, 0x01, 0x80, 0xc8, 0x03, 0x12, 0x80, 0x00, 0x6a, 0x40, 0xc5, - 0x41, 0xc5, 0x42, 0xc5, 0x43, 0xc5, 0x44, 0xc5, 0x00, 0x6a, 0x10, 0xb3, - 0x4d, 0xe3, 0xc0, 0xa3, 0xff, 0x6b, 0x07, 0x6f, 0xc4, 0x36, 0x6c, 0xee, - 0xce, 0x33, 0x6d, 0xe4, 0x60, 0xa3, 0xec, 0xee, 0x67, 0xee, 0x03, 0x6e, - 0xcc, 0xeb, 0x03, 0x73, 0x08, 0x61, 0x4e, 0x36, 0xd9, 0xe5, 0x4c, 0xef, - 0x01, 0x6b, 0x64, 0xef, 0xe0, 0xa6, 0xed, 0xeb, 0x60, 0xc6, 0x01, 0x4a, - 0xff, 0x6b, 0x6c, 0xea, 0x25, 0x5a, 0xe3, 0x61, 0x20, 0xe8, 0x00, 0x65, - 0xd8, 0xee, 0x01, 0x80, 0xfb, 0x63, 0x09, 0x62, 0x08, 0xd1, 0x07, 0xd0, - 0xff, 0x6a, 0x4c, 0xed, 0x20, 0xa4, 0x0f, 0x25, 0x14, 0x6b, 0x78, 0xe9, - 0x10, 0xb3, 0x04, 0xd3, 0x12, 0xe9, 0x4c, 0xe9, 0x81, 0x41, 0x40, 0xeb, - 0x4c, 0xec, 0x04, 0x93, 0x42, 0x30, 0x91, 0x67, 0x40, 0xeb, 0x02, 0x30, - 0x0b, 0x10, 0x1e, 0x6b, 0xf8, 0x49, 0x78, 0xe9, 0x12, 0xec, 0x01, 0x4c, - 0x4c, 0xec, 0x08, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x42, 0x30, 0x02, 0x30, - 0x01, 0x58, 0x09, 0x97, 0x08, 0x91, 0x07, 0x90, 0x58, 0x67, 0x00, 0xef, - 0x05, 0x63, 0x00, 0x65, 0x81, 0xa9, 0x01, 0x80, 0xd9, 0xa9, 0x01, 0x80, - 0xf9, 0x63, 0x0d, 0x62, 0x0c, 0xd1, 0x0b, 0xd0, 0xff, 0xf7, 0x1f, 0x69, - 0x04, 0x67, 0x9d, 0xa4, 0xac, 0xe9, 0xbc, 0xa0, 0x80, 0x34, 0x7d, 0x67, - 0xad, 0xec, 0x65, 0x5c, 0x40, 0xf0, 0x48, 0xa3, 0x40, 0xf0, 0x6c, 0xa3, - 0x04, 0x60, 0x64, 0x6c, 0x9c, 0xc0, 0x00, 0x6c, 0x9d, 0xc0, 0x99, 0xa0, - 0x0c, 0x2c, 0x98, 0xa0, 0x0a, 0x2c, 0x08, 0xd2, 0x09, 0xd3, 0x06, 0xd6, - 0x09, 0xb5, 0x40, 0xed, 0x07, 0xd7, 0x07, 0x97, 0x06, 0x96, 0x09, 0x93, - 0x08, 0x92, 0x04, 0xd2, 0x90, 0x67, 0xb1, 0x67, 0x05, 0xb2, 0x40, 0xea, - 0x05, 0xd3, 0x0d, 0x97, 0x0c, 0x91, 0x0b, 0x90, 0x00, 0xef, 0x07, 0x63, - 0xd9, 0x24, 0x10, 0x80, 0xd9, 0x6d, 0x01, 0x80, 0xfd, 0x63, 0x05, 0x62, - 0xff, 0x6a, 0x4c, 0xec, 0x03, 0x24, 0x01, 0x74, 0x08, 0x60, 0x0f, 0x10, - 0x09, 0xb3, 0xa0, 0xa3, 0x04, 0x6c, 0xad, 0xec, 0x4c, 0xec, 0x80, 0xc3, - 0x05, 0x10, 0x06, 0xb2, 0x80, 0xa2, 0xfb, 0x6b, 0x6c, 0xec, 0x80, 0xc2, - 0x04, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x05, 0x97, 0x00, 0xef, 0x03, 0x63, - 0x3e, 0x3c, 0x12, 0x80, 0x55, 0x1e, 0x01, 0x80, 0xfd, 0x63, 0x05, 0x62, - 0x0a, 0xb2, 0x60, 0xaa, 0xff, 0xf7, 0x1f, 0x6a, 0x6c, 0xea, 0x42, 0x32, - 0x3f, 0x6b, 0x6c, 0xea, 0x09, 0x5a, 0x06, 0x61, 0x06, 0xb2, 0x40, 0xaa, - 0x03, 0x22, 0x06, 0xb2, 0x40, 0xea, 0x00, 0x6c, 0x05, 0x97, 0x00, 0xef, - 0x03, 0x63, 0x00, 0x65, 0xc8, 0x10, 0x00, 0xb6, 0x3a, 0x3c, 0x12, 0x80, - 0x11, 0x27, 0x10, 0x80, 0xfd, 0x63, 0x05, 0x62, 0x04, 0xd0, 0x60, 0xa4, - 0x02, 0x6a, 0x05, 0x67, 0x6c, 0xea, 0x03, 0x22, 0x09, 0xb2, 0x40, 0xea, - 0x00, 0x65, 0x61, 0xa0, 0x40, 0x6a, 0x6c, 0xea, 0x06, 0x22, 0x07, 0xb2, - 0x40, 0xaa, 0x03, 0x22, 0x06, 0xb2, 0x40, 0xea, 0x01, 0x6c, 0x05, 0x97, - 0x04, 0x90, 0x00, 0x6a, 0x00, 0xef, 0x03, 0x63, 0x4d, 0x27, 0x10, 0x80, - 0x3a, 0x3c, 0x12, 0x80, 0x11, 0x27, 0x10, 0x80, 0xfd, 0x63, 0x05, 0x62, - 0x04, 0xd0, 0xff, 0x6a, 0xff, 0xf7, 0x1f, 0x68, 0xac, 0xea, 0x8c, 0xe8, - 0x0b, 0x22, 0x14, 0xb3, 0x08, 0x32, 0x49, 0xe3, 0x13, 0xb3, 0xa0, 0x9a, - 0x13, 0xb2, 0x40, 0xea, 0x87, 0x9b, 0x13, 0xb2, 0x40, 0xea, 0x00, 0x65, - 0x0e, 0xb3, 0x08, 0x34, 0x00, 0x6a, 0x91, 0xe3, 0x40, 0xdc, 0x87, 0x40, - 0x25, 0x4c, 0x84, 0x34, 0x91, 0xe3, 0x41, 0xcc, 0x87, 0x40, 0x01, 0x4c, - 0x88, 0x34, 0x91, 0xe3, 0x41, 0xdc, 0x87, 0x40, 0x1d, 0x4c, 0x1a, 0x48, - 0x08, 0x30, 0x84, 0x34, 0x91, 0xe3, 0x0d, 0xe3, 0x40, 0xcc, 0x41, 0xdb, - 0x05, 0x97, 0x04, 0x90, 0x00, 0xef, 0x03, 0x63, 0x4c, 0x0a, 0x12, 0x80, - 0x1c, 0x0b, 0x12, 0x80, 0xe1, 0xdd, 0x00, 0x80, 0x1d, 0xda, 0x00, 0x80, - 0xfb, 0x63, 0x09, 0x62, 0x08, 0xd1, 0x07, 0xd0, 0xff, 0xf7, 0x1f, 0x6b, - 0x6c, 0xec, 0x04, 0xd4, 0x04, 0x95, 0x59, 0xb4, 0x59, 0xb1, 0xa4, 0x32, - 0x59, 0xb5, 0x49, 0xe5, 0xc0, 0xaa, 0xa2, 0xac, 0xb5, 0xe6, 0xa2, 0xcc, - 0x00, 0x6c, 0x80, 0xca, 0x80, 0xf0, 0x93, 0xa1, 0x55, 0xb2, 0x40, 0xea, - 0x05, 0xd3, 0x82, 0x67, 0x54, 0xb2, 0x40, 0xea, 0x04, 0x95, 0x02, 0x67, - 0x05, 0x93, 0x80, 0xf0, 0x52, 0xa1, 0x4c, 0xeb, 0x0e, 0xeb, 0x80, 0xf0, - 0x0f, 0x23, 0x04, 0x95, 0x4f, 0xb2, 0x40, 0xea, 0x90, 0x67, 0x22, 0x67, - 0x57, 0x10, 0x08, 0x32, 0x4d, 0xe3, 0x40, 0x9b, 0x60, 0xaa, 0xe1, 0xf7, - 0x1f, 0x6a, 0x6c, 0xea, 0x04, 0x93, 0x4e, 0xeb, 0x49, 0xb2, 0x03, 0x2b, - 0x90, 0x67, 0x01, 0x6d, 0x02, 0x10, 0x90, 0x67, 0x00, 0x6d, 0x40, 0xea, - 0x00, 0x65, 0x87, 0x41, 0x13, 0x4c, 0x3f, 0xb2, 0x88, 0x34, 0x67, 0x40, - 0x91, 0xe2, 0x81, 0x9c, 0x13, 0x4b, 0x68, 0x33, 0x6d, 0xe2, 0x81, 0xdb, - 0x28, 0x34, 0x91, 0xe2, 0x80, 0x9c, 0x08, 0x33, 0x6d, 0xe2, 0x80, 0xdb, - 0x87, 0x41, 0x25, 0x4c, 0x84, 0x34, 0x67, 0x40, 0x91, 0xe2, 0x81, 0xac, - 0x25, 0x4b, 0x64, 0x33, 0x6d, 0xe2, 0x81, 0xcb, 0x87, 0x41, 0x01, 0x4c, - 0x88, 0x34, 0x67, 0x40, 0x91, 0xe2, 0x81, 0x9c, 0x01, 0x4b, 0x68, 0x33, - 0x6d, 0xe2, 0x81, 0xdb, 0x67, 0x40, 0x87, 0x41, 0x1d, 0x4b, 0x1d, 0x4c, - 0x84, 0x34, 0x64, 0x33, 0x6d, 0xe2, 0x89, 0xe2, 0x40, 0xaa, 0x01, 0x49, - 0x04, 0x95, 0x40, 0xcb, 0x09, 0x6a, 0x5a, 0xe9, 0x01, 0x2a, 0xe5, 0xe8, - 0xff, 0xf7, 0x1f, 0x6b, 0x05, 0xd3, 0x28, 0xb2, 0x01, 0x48, 0x10, 0xec, - 0x40, 0xea, 0x6c, 0xec, 0x09, 0x6c, 0x9a, 0xe8, 0x01, 0x2c, 0xe5, 0xe8, - 0x05, 0x93, 0x22, 0x67, 0x10, 0xe8, 0x6c, 0xe8, 0x1d, 0xb3, 0x80, 0xf0, - 0x52, 0xa3, 0x4a, 0xe9, 0xa4, 0x61, 0x0b, 0xe2, 0x00, 0x52, 0x01, 0x60, - 0x09, 0x4a, 0x19, 0xb3, 0x80, 0xf0, 0x90, 0xab, 0x30, 0x67, 0x4b, 0xe4, - 0x80, 0xf0, 0x50, 0xcb, 0x1a, 0x10, 0x28, 0x33, 0x69, 0xe2, 0x40, 0x9a, + 0x38, 0x01, 0x12, 0x80, 0x04, 0x05, 0x12, 0x80, 0xd0, 0x3c, 0x10, 0x80, + 0xd1, 0x27, 0x01, 0x80, 0xc8, 0x03, 0x12, 0x80, 0xfb, 0x63, 0x09, 0x62, + 0x08, 0xd1, 0x07, 0xd0, 0xff, 0x6a, 0x4c, 0xed, 0x20, 0xa4, 0x0f, 0x25, + 0x14, 0x6b, 0x78, 0xe9, 0x10, 0xb3, 0x04, 0xd3, 0x12, 0xe9, 0x4c, 0xe9, + 0x81, 0x41, 0x40, 0xeb, 0x4c, 0xec, 0x04, 0x93, 0x42, 0x30, 0x91, 0x67, + 0x40, 0xeb, 0x02, 0x30, 0x0b, 0x10, 0x1e, 0x6b, 0xf8, 0x49, 0x78, 0xe9, + 0x12, 0xec, 0x01, 0x4c, 0x4c, 0xec, 0x08, 0xb2, 0x40, 0xea, 0x00, 0x65, + 0x42, 0x30, 0x02, 0x30, 0x01, 0x58, 0x09, 0x97, 0x08, 0x91, 0x07, 0x90, + 0x58, 0x67, 0x00, 0xef, 0x05, 0x63, 0x00, 0x65, 0x81, 0xa9, 0x01, 0x80, + 0xd9, 0xa9, 0x01, 0x80, 0xf9, 0x63, 0x0d, 0x62, 0x0c, 0xd1, 0x0b, 0xd0, + 0xff, 0xf7, 0x1f, 0x69, 0x04, 0x67, 0x9d, 0xa4, 0xac, 0xe9, 0xbc, 0xa0, + 0x80, 0x34, 0x7d, 0x67, 0xad, 0xec, 0x65, 0x5c, 0x40, 0xf0, 0x48, 0xa3, + 0x40, 0xf0, 0x6c, 0xa3, 0x04, 0x60, 0x64, 0x6c, 0x9c, 0xc0, 0x00, 0x6c, + 0x9d, 0xc0, 0x99, 0xa0, 0x0c, 0x2c, 0x98, 0xa0, 0x0a, 0x2c, 0x08, 0xd2, + 0x09, 0xd3, 0x06, 0xd6, 0x09, 0xb5, 0x40, 0xed, 0x07, 0xd7, 0x07, 0x97, + 0x06, 0x96, 0x09, 0x93, 0x08, 0x92, 0x04, 0xd2, 0x90, 0x67, 0xb1, 0x67, + 0x05, 0xb2, 0x40, 0xea, 0x05, 0xd3, 0x0d, 0x97, 0x0c, 0x91, 0x0b, 0x90, + 0x00, 0xef, 0x07, 0x63, 0x15, 0x25, 0x10, 0x80, 0xd9, 0x6d, 0x01, 0x80, + 0xfd, 0x63, 0x05, 0x62, 0xff, 0x6a, 0x4c, 0xec, 0x03, 0x24, 0x01, 0x74, + 0x08, 0x60, 0x0f, 0x10, 0x09, 0xb3, 0xa0, 0xa3, 0x04, 0x6c, 0xad, 0xec, + 0x4c, 0xec, 0x80, 0xc3, 0x05, 0x10, 0x06, 0xb2, 0x80, 0xa2, 0xfb, 0x6b, + 0x6c, 0xec, 0x80, 0xc2, 0x04, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x05, 0x97, + 0x00, 0xef, 0x03, 0x63, 0x3e, 0x3c, 0x12, 0x80, 0x55, 0x1e, 0x01, 0x80, + 0xfd, 0x63, 0x05, 0x62, 0x0a, 0xb2, 0x60, 0xaa, 0xff, 0xf7, 0x1f, 0x6a, + 0x6c, 0xea, 0x42, 0x32, 0x3f, 0x6b, 0x6c, 0xea, 0x09, 0x5a, 0x06, 0x61, + 0x06, 0xb2, 0x40, 0xaa, 0x03, 0x22, 0x06, 0xb2, 0x40, 0xea, 0x00, 0x6c, + 0x05, 0x97, 0x00, 0xef, 0x03, 0x63, 0x00, 0x65, 0xc8, 0x10, 0x00, 0xb6, + 0x3a, 0x3c, 0x12, 0x80, 0xfd, 0x26, 0x10, 0x80, 0xfd, 0x63, 0x05, 0x62, + 0x04, 0xd0, 0x60, 0xa4, 0x02, 0x6a, 0x05, 0x67, 0x6c, 0xea, 0x03, 0x22, + 0x09, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x61, 0xa0, 0x40, 0x6a, 0x6c, 0xea, + 0x06, 0x22, 0x07, 0xb2, 0x40, 0xaa, 0x03, 0x22, 0x06, 0xb2, 0x40, 0xea, + 0x01, 0x6c, 0x05, 0x97, 0x04, 0x90, 0x00, 0x6a, 0x00, 0xef, 0x03, 0x63, + 0x39, 0x27, 0x10, 0x80, 0x3a, 0x3c, 0x12, 0x80, 0xfd, 0x26, 0x10, 0x80, + 0xfd, 0x63, 0x05, 0x62, 0x04, 0xd0, 0xff, 0x6a, 0xff, 0xf7, 0x1f, 0x68, + 0xac, 0xea, 0x8c, 0xe8, 0x0b, 0x22, 0x14, 0xb3, 0x08, 0x32, 0x49, 0xe3, + 0x13, 0xb3, 0xa0, 0x9a, 0x13, 0xb2, 0x40, 0xea, 0x87, 0x9b, 0x13, 0xb2, + 0x40, 0xea, 0x00, 0x65, 0x0e, 0xb3, 0x08, 0x34, 0x00, 0x6a, 0x91, 0xe3, + 0x40, 0xdc, 0x87, 0x40, 0x25, 0x4c, 0x84, 0x34, 0x91, 0xe3, 0x41, 0xcc, + 0x87, 0x40, 0x01, 0x4c, 0x88, 0x34, 0x91, 0xe3, 0x41, 0xdc, 0x87, 0x40, + 0x1d, 0x4c, 0x1a, 0x48, 0x08, 0x30, 0x84, 0x34, 0x91, 0xe3, 0x0d, 0xe3, + 0x40, 0xcc, 0x41, 0xdb, 0x05, 0x97, 0x04, 0x90, 0x00, 0xef, 0x03, 0x63, + 0x4c, 0x0a, 0x12, 0x80, 0x1c, 0x0b, 0x12, 0x80, 0xe1, 0xdd, 0x00, 0x80, + 0x1d, 0xda, 0x00, 0x80, 0xfb, 0x63, 0x09, 0x62, 0x08, 0xd1, 0x07, 0xd0, + 0xff, 0xf7, 0x1f, 0x6b, 0x6c, 0xec, 0x04, 0xd4, 0x04, 0x95, 0x59, 0xb4, + 0x59, 0xb1, 0xa4, 0x32, 0x59, 0xb5, 0x49, 0xe5, 0xc0, 0xaa, 0xa2, 0xac, + 0xb5, 0xe6, 0xa2, 0xcc, 0x00, 0x6c, 0x80, 0xca, 0x80, 0xf0, 0x93, 0xa1, + 0x55, 0xb2, 0x40, 0xea, 0x05, 0xd3, 0x82, 0x67, 0x54, 0xb2, 0x40, 0xea, + 0x04, 0x95, 0x02, 0x67, 0x05, 0x93, 0x80, 0xf0, 0x52, 0xa1, 0x4c, 0xeb, + 0x0e, 0xeb, 0x80, 0xf0, 0x0f, 0x23, 0x04, 0x95, 0x4f, 0xb2, 0x40, 0xea, + 0x90, 0x67, 0x22, 0x67, 0x57, 0x10, 0x08, 0x32, 0x4d, 0xe3, 0x40, 0x9b, 0x60, 0xaa, 0xe1, 0xf7, 0x1f, 0x6a, 0x6c, 0xea, 0x04, 0x93, 0x4e, 0xeb, - 0x15, 0xb2, 0x03, 0x2b, 0x91, 0x67, 0x01, 0x6d, 0x02, 0x10, 0x91, 0x67, - 0x00, 0x6d, 0x40, 0xea, 0x01, 0x49, 0x09, 0x6a, 0x5a, 0xe9, 0x01, 0x2a, - 0xe5, 0xe8, 0xff, 0xf7, 0x1f, 0x6a, 0x10, 0xe9, 0x4c, 0xe9, 0x08, 0xb2, - 0x80, 0xf0, 0x72, 0xa2, 0x2e, 0xeb, 0xe1, 0x2b, 0x80, 0xf0, 0x12, 0xc2, - 0x09, 0x97, 0x08, 0x91, 0x07, 0x90, 0x00, 0xef, 0x05, 0x63, 0x00, 0x65, - 0x70, 0x0c, 0x12, 0x80, 0x4c, 0x0a, 0x12, 0x80, 0x04, 0x3c, 0x12, 0x80, - 0x59, 0x23, 0x10, 0x80, 0x19, 0x23, 0x10, 0x80, 0xd9, 0x22, 0x10, 0x80, - 0xc5, 0x27, 0x10, 0x80, 0xfd, 0x63, 0x05, 0x62, 0x40, 0xa4, 0x05, 0x72, - 0x0d, 0x61, 0x09, 0xb2, 0x20, 0xf0, 0x4c, 0xa2, 0x61, 0xa5, 0x82, 0xa5, - 0x01, 0x72, 0x02, 0x60, 0x03, 0x72, 0x04, 0x61, 0x80, 0x34, 0x05, 0xb2, - 0x40, 0xea, 0x6d, 0xec, 0x05, 0x97, 0x00, 0x6a, 0x00, 0xef, 0x03, 0x63, - 0x78, 0x0c, 0x12, 0x80, 0x35, 0x28, 0x10, 0x80, 0xfc, 0x63, 0x07, 0x62, - 0x06, 0xd1, 0x05, 0xd0, 0x44, 0xb2, 0x80, 0xf0, 0x73, 0xa2, 0xff, 0x69, - 0x8c, 0xe9, 0x1a, 0x4b, 0x68, 0x33, 0x6d, 0xe2, 0x00, 0x6c, 0x81, 0xdb, - 0x40, 0xb3, 0x20, 0xf0, 0x6c, 0xa3, 0x01, 0x73, 0x09, 0x60, 0x03, 0x73, - 0x07, 0x60, 0x80, 0xf0, 0x73, 0xa2, 0x2c, 0x4b, 0x64, 0x33, 0x69, 0xe2, - 0x41, 0xaa, 0x19, 0x2a, 0x38, 0xb2, 0x80, 0xf0, 0x53, 0xa2, 0x39, 0xb3, - 0xe1, 0xf7, 0x1f, 0x68, 0x48, 0x32, 0x69, 0xe2, 0x40, 0xaa, 0x4c, 0xe8, - 0x36, 0xb2, 0x40, 0xea, 0x90, 0x67, 0x05, 0x2a, 0x35, 0xb2, 0x62, 0xaa, - 0x01, 0x4b, 0x62, 0xca, 0x06, 0x10, 0x34, 0xb2, 0x04, 0x30, 0x01, 0xe2, - 0x40, 0xa8, 0x01, 0x4a, 0x40, 0xc8, 0x2d, 0xb2, 0x20, 0xf0, 0x4c, 0xa2, - 0x0a, 0x22, 0x02, 0x72, 0x08, 0x60, 0x29, 0xb2, 0x80, 0xf0, 0x73, 0xa2, - 0x2c, 0x4b, 0x64, 0x33, 0x69, 0xe2, 0x41, 0xaa, 0x30, 0x2a, 0x05, 0x71, - 0x24, 0xb4, 0x2a, 0xb5, 0x2a, 0xb2, 0x09, 0x61, 0x80, 0xf0, 0x73, 0xa4, - 0x68, 0x33, 0x6d, 0xe4, 0x87, 0x9d, 0x40, 0xea, 0xa0, 0x9b, 0x27, 0xb2, - 0x08, 0x10, 0x80, 0xf0, 0x73, 0xa4, 0x68, 0x33, 0x6d, 0xe4, 0x83, 0x9d, - 0x40, 0xea, 0xa0, 0x9b, 0x23, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x19, 0xb2, - 0x80, 0xf0, 0x73, 0xa2, 0x00, 0x6c, 0x68, 0x33, 0x6d, 0xe2, 0x80, 0xdb, - 0x80, 0xf0, 0x73, 0xa2, 0xff, 0x6c, 0x01, 0x4b, 0x8c, 0xeb, 0x09, 0x6c, - 0x9b, 0xeb, 0x01, 0x2c, 0xe5, 0xe8, 0x10, 0xeb, 0x80, 0xf0, 0x73, 0xc2, - 0x80, 0xf0, 0x70, 0xaa, 0xff, 0x4b, 0x80, 0xf0, 0x70, 0xca, 0x0e, 0xb2, - 0x20, 0xf0, 0x4c, 0xa2, 0x01, 0x72, 0x02, 0x60, 0x03, 0x72, 0x0c, 0x61, - 0x09, 0xb2, 0x80, 0xf0, 0x73, 0xa2, 0x1a, 0x4b, 0x68, 0x33, 0x69, 0xe2, - 0x41, 0x9a, 0x04, 0x2a, 0x0f, 0xb2, 0x40, 0x9a, 0x40, 0xea, 0x00, 0x65, - 0x07, 0x97, 0x06, 0x91, 0x05, 0x90, 0x00, 0xef, 0x04, 0x63, 0x00, 0x65, - 0x4c, 0x0a, 0x12, 0x80, 0x78, 0x0c, 0x12, 0x80, 0x70, 0x0a, 0x12, 0x80, - 0x75, 0xca, 0x01, 0x80, 0x70, 0x0c, 0x12, 0x80, 0x04, 0x3c, 0x12, 0x80, - 0x1c, 0x0b, 0x12, 0x80, 0xe1, 0xdd, 0x00, 0x80, 0x1d, 0xda, 0x00, 0x80, - 0x89, 0xda, 0x00, 0x80, 0x30, 0x00, 0x12, 0x80, 0xfa, 0x63, 0x0b, 0x62, - 0x0a, 0xd1, 0x09, 0xd0, 0x2b, 0xb2, 0x20, 0xf0, 0x4c, 0xa2, 0x04, 0x67, - 0x49, 0x22, 0xa3, 0xa4, 0x01, 0x69, 0x00, 0x6b, 0x16, 0x10, 0x82, 0xa0, - 0x01, 0x4b, 0x68, 0x32, 0x01, 0x4a, 0x42, 0xec, 0x41, 0x61, 0x29, 0xe0, - 0x84, 0xa2, 0x43, 0xa2, 0x06, 0xd3, 0x80, 0x34, 0x4d, 0xec, 0x22, 0xb2, - 0x40, 0xea, 0x05, 0xd5, 0x06, 0x93, 0x05, 0x95, 0x35, 0x22, 0xff, 0x6a, - 0x04, 0x49, 0x4c, 0xe9, 0x4c, 0xeb, 0xa3, 0xeb, 0xe8, 0x61, 0xa3, 0xa0, - 0x01, 0x69, 0x00, 0x6a, 0x27, 0x10, 0x2d, 0xe0, 0xff, 0x6c, 0x02, 0x49, - 0x8c, 0xe9, 0x39, 0xe0, 0x84, 0xa6, 0xc3, 0xa6, 0xe3, 0xa3, 0x80, 0x34, - 0xcd, 0xec, 0x14, 0xb6, 0x20, 0xf0, 0xcc, 0xa6, 0x64, 0xa3, 0x01, 0x76, - 0x02, 0x60, 0x03, 0x76, 0x08, 0x61, 0x60, 0x33, 0xed, 0xeb, 0x11, 0xb6, - 0x64, 0x33, 0x6d, 0xe6, 0xc0, 0xab, 0x9b, 0xe6, 0xc0, 0xcb, 0xff, 0x6b, - 0x04, 0xd2, 0x06, 0xd3, 0x05, 0xd5, 0x02, 0x49, 0x0c, 0xb6, 0x40, 0xee, - 0x6c, 0xe9, 0x04, 0x92, 0x06, 0x93, 0x05, 0x95, 0x01, 0x4a, 0x6c, 0xea, - 0xa3, 0xea, 0xd7, 0x61, 0x00, 0x6a, 0x01, 0x10, 0x12, 0x6a, 0x0b, 0x97, - 0x0a, 0x91, 0x09, 0x90, 0x00, 0xef, 0x06, 0x63, 0x78, 0x0c, 0x12, 0x80, - 0x75, 0xca, 0x01, 0x80, 0x04, 0x3c, 0x12, 0x80, 0x65, 0x55, 0x00, 0x80, - 0xfa, 0x63, 0x0b, 0x62, 0x0a, 0xd1, 0x09, 0xd0, 0x04, 0xa4, 0x43, 0xa4, - 0xe6, 0x44, 0x00, 0x30, 0x20, 0xa7, 0x67, 0xa4, 0x4d, 0xe8, 0x45, 0x44, - 0x6a, 0x65, 0x40, 0xa2, 0x20, 0x31, 0x01, 0x73, 0x4d, 0xe9, 0x06, 0xd3, - 0x1b, 0x60, 0x03, 0xe9, 0x19, 0x61, 0x20, 0x58, 0x17, 0x60, 0x00, 0x6d, - 0x20, 0x6e, 0xa4, 0xc4, 0xc3, 0xc4, 0x18, 0xb2, 0x60, 0xa2, 0x0d, 0x65, - 0x01, 0x6d, 0x4b, 0x65, 0x65, 0x67, 0xaa, 0x67, 0xad, 0xeb, 0x20, 0x59, - 0x60, 0xc2, 0x08, 0x60, 0xab, 0x67, 0x68, 0x67, 0x60, 0xc7, 0xc0, 0xc5, - 0xc0, 0xa2, 0x02, 0x6d, 0xcd, 0xed, 0xa0, 0xc2, 0x0f, 0xb2, 0x40, 0xea, - 0x00, 0x65, 0x0f, 0x2a, 0x06, 0x93, 0x01, 0x73, 0x0c, 0x60, 0x0b, 0xb3, - 0x80, 0xa3, 0x01, 0x6b, 0x8c, 0xeb, 0x02, 0x23, 0x0a, 0xb3, 0x16, 0xcb, - 0x02, 0x6b, 0x8c, 0xeb, 0x02, 0x23, 0x08, 0xb3, 0x37, 0xcb, 0x00, 0x6c, - 0x04, 0xb3, 0x80, 0xc3, 0x0b, 0x97, 0x0a, 0x91, 0x09, 0x90, 0x00, 0xef, - 0x06, 0x63, 0x00, 0x65, 0x01, 0x3c, 0x12, 0x80, 0x45, 0x4d, 0x01, 0x80, - 0x10, 0x23, 0x12, 0x80, 0xfd, 0x63, 0x05, 0x62, 0x04, 0xd0, 0x33, 0xb3, - 0x20, 0xf0, 0xc8, 0xa3, 0x05, 0x67, 0x01, 0x6d, 0xac, 0xee, 0x0c, 0x6a, - 0x59, 0x2e, 0x30, 0xb2, 0xc0, 0x9a, 0x20, 0xf1, 0x4c, 0xa3, 0x20, 0xf1, - 0xea, 0xab, 0x24, 0x22, 0x01, 0xf7, 0x00, 0x6a, 0xec, 0xea, 0xa4, 0xee, - 0x43, 0x32, 0xff, 0x4d, 0xa2, 0xea, 0x1c, 0x61, 0x20, 0xf0, 0x49, 0xa3, - 0x1c, 0x6b, 0x6c, 0xea, 0x04, 0x72, 0x01, 0x60, 0x15, 0x2a, 0x24, 0xb3, - 0xb4, 0xab, 0x80, 0xf3, 0x01, 0x6a, 0x4b, 0xea, 0xac, 0xea, 0xff, 0x6d, - 0x01, 0x4d, 0xad, 0xea, 0xff, 0xf7, 0x1f, 0x6d, 0x4c, 0xed, 0x54, 0xcb, - 0x1d, 0x6a, 0xa2, 0x35, 0x4b, 0xea, 0xac, 0xea, 0x0c, 0x6d, 0xad, 0xea, - 0x20, 0xf0, 0x49, 0xc3, 0x43, 0xa4, 0x01, 0x72, 0x00, 0x6a, 0x2a, 0x61, - 0x17, 0xb2, 0x20, 0xf0, 0x8a, 0xa2, 0x40, 0x6b, 0x8d, 0xeb, 0x20, 0xf0, - 0x88, 0xa2, 0x20, 0xf0, 0x6a, 0xc2, 0x01, 0x6b, 0x8d, 0xeb, 0x20, 0xf0, - 0x68, 0xc2, 0x20, 0xf0, 0x49, 0xa2, 0x07, 0x6b, 0x4a, 0x32, 0x6c, 0xea, - 0x10, 0xb3, 0x49, 0xe3, 0x80, 0xa2, 0x10, 0xb2, 0x40, 0xea, 0x00, 0x65, - 0x01, 0x72, 0x09, 0x61, 0x0e, 0xb2, 0x40, 0xea, 0x00, 0x6c, 0xff, 0x72, - 0x04, 0x60, 0x82, 0x67, 0x0c, 0xb2, 0x40, 0xea, 0x01, 0x6d, 0x0c, 0xb2, - 0x40, 0x9a, 0x40, 0xea, 0x00, 0x65, 0x00, 0x6a, 0x40, 0xc0, 0x00, 0x6a, - 0x05, 0x97, 0x04, 0x90, 0x00, 0xef, 0x03, 0x63, 0x10, 0x23, 0x12, 0x80, - 0xc8, 0x03, 0x12, 0x80, 0x90, 0xee, 0x01, 0x80, 0xfd, 0xd0, 0x01, 0x80, - 0x6d, 0xe6, 0x01, 0x80, 0xa9, 0xe6, 0x01, 0x80, 0xd4, 0x04, 0x12, 0x80, - 0xfc, 0x63, 0x07, 0x62, 0x06, 0xd0, 0x19, 0xb0, 0x20, 0xf0, 0x4a, 0xa0, - 0x40, 0x6b, 0x4c, 0xeb, 0x00, 0x6a, 0x26, 0x23, 0x82, 0x67, 0x16, 0xb2, - 0x40, 0xea, 0x00, 0x65, 0x20, 0xf0, 0x68, 0xa0, 0x02, 0x6a, 0x4b, 0xea, - 0x6c, 0xea, 0x20, 0xf0, 0x6a, 0xa0, 0x20, 0xf0, 0x48, 0xc0, 0x41, 0x6a, - 0x4b, 0xea, 0x6c, 0xea, 0x20, 0xf0, 0x4a, 0xc0, 0x0e, 0xb2, 0x80, 0xa2, - 0x02, 0x6d, 0x0e, 0xb2, 0x40, 0xea, 0x04, 0x00, 0x9f, 0xf4, 0x07, 0x6c, - 0x0c, 0xb2, 0x40, 0xea, 0xb0, 0x67, 0x00, 0x6a, 0x7d, 0x67, 0x53, 0xc3, - 0x0e, 0x6c, 0xb0, 0x67, 0x09, 0xb2, 0x40, 0xea, 0x04, 0x6e, 0x01, 0x6a, - 0x07, 0x97, 0x06, 0x90, 0x00, 0xef, 0x04, 0x63, 0x10, 0x23, 0x12, 0x80, - 0x91, 0x40, 0x00, 0x80, 0x38, 0x05, 0x12, 0x80, 0xa9, 0xe6, 0x01, 0x80, - 0x95, 0x2b, 0x01, 0x80, 0x01, 0x4b, 0x00, 0x80, 0xfd, 0x63, 0x05, 0x62, - 0xff, 0x6a, 0x8c, 0xea, 0x05, 0x72, 0x21, 0x61, 0x14, 0xb3, 0x74, 0xab, - 0x80, 0xf3, 0x00, 0x6c, 0x8c, 0xeb, 0x03, 0x23, 0x00, 0xf3, 0x00, 0x73, - 0x09, 0x61, 0x11, 0xb4, 0xe0, 0xf1, 0x1f, 0x6b, 0xa0, 0xac, 0xac, 0xeb, - 0x00, 0xf6, 0x00, 0x6d, 0xad, 0xeb, 0x60, 0xcc, 0x0b, 0xb3, 0x20, 0xf0, - 0x8a, 0xa3, 0x40, 0x6b, 0x8c, 0xeb, 0x09, 0x23, 0x0a, 0xb4, 0xff, 0xf7, - 0x1f, 0x6d, 0x10, 0x6e, 0x60, 0xac, 0xac, 0xeb, 0xcd, 0xeb, 0xac, 0xeb, - 0x60, 0xcc, 0x82, 0x67, 0x06, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x05, 0x97, - 0x00, 0xef, 0x03, 0x63, 0x10, 0x23, 0x12, 0x80, 0x40, 0x10, 0x00, 0xb6, - 0x8e, 0x12, 0x00, 0xb6, 0x71, 0xac, 0x01, 0x80, 0xfc, 0x63, 0x07, 0x62, - 0x06, 0xd1, 0x05, 0xd0, 0x14, 0xb2, 0x40, 0x9a, 0x09, 0xd5, 0x40, 0xea, - 0x24, 0x67, 0x40, 0xd9, 0x09, 0x92, 0x02, 0x2a, 0x19, 0x10, 0x40, 0xd9, - 0x10, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x02, 0x67, 0x0d, 0xb2, 0x40, 0x9a, - 0x40, 0xea, 0x00, 0x65, 0x60, 0x99, 0x4e, 0xeb, 0xf4, 0x2b, 0x60, 0xf2, - 0x11, 0x58, 0x05, 0x61, 0x9f, 0xf5, 0x10, 0x48, 0xff, 0xf7, 0x1f, 0x6a, - 0x4c, 0xe8, 0x60, 0xf2, 0x10, 0x6a, 0x03, 0xe2, 0x09, 0x92, 0x00, 0xda, - 0x07, 0x97, 0x06, 0x91, 0x05, 0x90, 0x00, 0xef, 0x04, 0x63, 0x00, 0x65, - 0x14, 0x00, 0x12, 0x80, 0xa9, 0x38, 0x00, 0x80, 0xf9, 0x63, 0x0d, 0x62, - 0x0c, 0xd1, 0x0b, 0xd0, 0xff, 0x6a, 0xac, 0xea, 0x06, 0xd2, 0x00, 0x6a, - 0x40, 0xdc, 0x4e, 0xa4, 0x04, 0x67, 0x0f, 0x72, 0x5e, 0x60, 0x1d, 0x4a, - 0x32, 0xb3, 0x50, 0x32, 0x49, 0xe3, 0x21, 0x9a, 0x04, 0x04, 0x31, 0xb2, - 0x40, 0xea, 0x00, 0x6d, 0x04, 0x92, 0x30, 0xb4, 0xb1, 0x67, 0x0a, 0x6e, - 0x4c, 0xec, 0x86, 0x34, 0x2e, 0xb2, 0x40, 0xea, 0x04, 0xd4, 0x22, 0x67, - 0x04, 0x92, 0x40, 0xd8, 0x4f, 0xa0, 0x02, 0x72, 0x03, 0x60, 0x2b, 0xb2, - 0x2e, 0xea, 0x01, 0x2a, 0x00, 0x69, 0x25, 0xb3, 0xc0, 0xf1, 0xa2, 0xa3, - 0x0c, 0x75, 0x10, 0x61, 0x08, 0xd3, 0x07, 0xd5, 0x26, 0xb2, 0x40, 0xea, - 0x0c, 0x6c, 0x43, 0xe9, 0x08, 0x93, 0x07, 0x95, 0x07, 0x60, 0x4e, 0xa0, - 0x0c, 0x72, 0x31, 0x61, 0x01, 0x6a, 0xc0, 0xf1, 0x43, 0xc3, 0x27, 0x10, - 0x8e, 0xa0, 0x8e, 0xed, 0x11, 0x2d, 0x1e, 0xb2, 0x40, 0xea, 0x00, 0x65, - 0x23, 0xea, 0x25, 0x61, 0x06, 0x94, 0x16, 0xb2, 0x90, 0x33, 0x6d, 0xe2, - 0xc0, 0xf1, 0x46, 0x8a, 0xc0, 0xf1, 0x6c, 0x8b, 0x01, 0x4a, 0x62, 0xea, - 0x10, 0x60, 0x19, 0x10, 0x06, 0x95, 0x10, 0xb2, 0x90, 0x34, 0xb0, 0x33, - 0x6d, 0xe2, 0x91, 0xe2, 0xc0, 0xf1, 0xae, 0x8b, 0xc0, 0xf1, 0x6e, 0x8c, - 0xa2, 0xeb, 0x0d, 0x61, 0x0f, 0x6b, 0xc0, 0xf1, 0x62, 0xc2, 0x01, 0x6b, - 0x08, 0xb2, 0xc0, 0xf1, 0x63, 0xc2, 0x0d, 0xb2, 0x0f, 0x6c, 0x40, 0xea, - 0x01, 0x6d, 0x01, 0x6a, 0x01, 0x10, 0x00, 0x6a, 0x0d, 0x97, 0x0c, 0x91, - 0x0b, 0x90, 0x00, 0xef, 0x07, 0x63, 0x00, 0x65, 0x10, 0x23, 0x12, 0x80, - 0x79, 0x2e, 0x10, 0x80, 0xff, 0xff, 0x07, 0x00, 0x55, 0x65, 0x00, 0x80, - 0xff, 0xff, 0x03, 0x00, 0x81, 0x22, 0x10, 0x80, 0x6d, 0xa2, 0x01, 0x80, - 0xfc, 0x63, 0x07, 0x62, 0x06, 0xd1, 0x05, 0xd0, 0x00, 0x69, 0x04, 0x67, - 0x01, 0x6c, 0x8b, 0xec, 0x51, 0x67, 0x18, 0x10, 0x4d, 0xe0, 0x72, 0xa3, - 0x70, 0x36, 0xd9, 0xe5, 0xc0, 0xf1, 0xf0, 0xa6, 0x01, 0x4f, 0xc0, 0xf1, - 0xf0, 0xc6, 0xe7, 0x43, 0x16, 0x4f, 0xf0, 0x37, 0xf5, 0xe5, 0xe2, 0x98, - 0xe2, 0xdd, 0xc0, 0xf1, 0xac, 0x8e, 0xa2, 0xec, 0x02, 0x60, 0x85, 0x67, - 0x23, 0x67, 0x01, 0x4a, 0xff, 0x6b, 0x6c, 0xea, 0x20, 0xf0, 0x60, 0xa0, - 0x21, 0xb5, 0x63, 0xea, 0xe3, 0x61, 0x30, 0x32, 0x55, 0xe5, 0xc0, 0xf1, - 0x4c, 0x8d, 0x00, 0xf4, 0x00, 0x52, 0x09, 0x60, 0x90, 0x67, 0x1d, 0xb2, - 0x40, 0xea, 0xb1, 0x67, 0x04, 0x22, 0x20, 0xf0, 0x61, 0xa0, 0x08, 0x6a, - 0x27, 0x10, 0x18, 0xb2, 0x30, 0x33, 0x6d, 0xe2, 0xc0, 0xf1, 0x90, 0xa3, - 0xc0, 0xf1, 0x84, 0xc2, 0xc0, 0xf1, 0x8c, 0xab, 0xc0, 0xf1, 0x86, 0xca, - 0x87, 0x41, 0x16, 0x4c, 0x90, 0x34, 0x91, 0xe2, 0xa1, 0x9c, 0xc0, 0xf1, - 0x22, 0xc2, 0xc0, 0xf1, 0xa8, 0xda, 0x02, 0x6d, 0xc0, 0xf1, 0xa3, 0xc2, - 0x00, 0x6a, 0xc0, 0xf1, 0x50, 0xc3, 0xc0, 0xf1, 0x4e, 0xab, 0x02, 0x6d, - 0xc0, 0xf1, 0x4c, 0xcb, 0x42, 0x98, 0x41, 0xdc, 0x09, 0xb2, 0x40, 0xea, - 0x91, 0x67, 0x20, 0xf0, 0x61, 0xa0, 0x10, 0x6a, 0x6d, 0xea, 0x20, 0xf0, - 0x41, 0xc0, 0x07, 0x97, 0x06, 0x91, 0x05, 0x90, 0x00, 0xef, 0x04, 0x63, - 0x10, 0x23, 0x12, 0x80, 0xd9, 0x2e, 0x10, 0x80, 0x6d, 0xa2, 0x01, 0x80, - 0xfd, 0x63, 0x05, 0x62, 0x04, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x05, 0x97, - 0x01, 0x6a, 0x00, 0xef, 0x03, 0x63, 0x00, 0x65, 0xd9, 0x2f, 0x10, 0x80, - 0xfa, 0x63, 0x0b, 0x62, 0x0a, 0xd0, 0x00, 0x6b, 0x21, 0xb2, 0x60, 0xc2, - 0x21, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x21, 0xb2, 0x40, 0xa2, 0x03, 0x2a, - 0x20, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x20, 0xb2, 0x20, 0xb3, 0x80, 0xaa, - 0xe0, 0xf3, 0x1f, 0x6a, 0x4c, 0xec, 0x80, 0xcb, 0x1e, 0xb3, 0x60, 0xab, - 0x6c, 0xea, 0x1e, 0xb3, 0x40, 0xcb, 0xa3, 0x6b, 0x1d, 0xb2, 0x60, 0xca, - 0x1d, 0xb2, 0x00, 0x6b, 0x60, 0xca, 0x00, 0x6a, 0x1c, 0xb4, 0x51, 0xe4, - 0x80, 0xa4, 0x04, 0x00, 0x4d, 0xe0, 0x88, 0xc3, 0x01, 0x4a, 0xff, 0x6b, - 0x6c, 0xea, 0x0a, 0x5a, 0xf5, 0x61, 0x06, 0x04, 0x17, 0xb2, 0x40, 0xea, - 0xb0, 0x67, 0x17, 0xb4, 0xb0, 0x67, 0x17, 0xb2, 0x40, 0xea, 0x05, 0x6e, - 0x16, 0xb2, 0x00, 0x6b, 0x80, 0xf1, 0x65, 0xc2, 0x00, 0x6a, 0x15, 0xb3, + 0x49, 0xb2, 0x03, 0x2b, 0x90, 0x67, 0x01, 0x6d, 0x02, 0x10, 0x90, 0x67, + 0x00, 0x6d, 0x40, 0xea, 0x00, 0x65, 0x87, 0x41, 0x13, 0x4c, 0x3f, 0xb2, + 0x88, 0x34, 0x67, 0x40, 0x91, 0xe2, 0x81, 0x9c, 0x13, 0x4b, 0x68, 0x33, + 0x6d, 0xe2, 0x81, 0xdb, 0x28, 0x34, 0x91, 0xe2, 0x80, 0x9c, 0x08, 0x33, + 0x6d, 0xe2, 0x80, 0xdb, 0x87, 0x41, 0x25, 0x4c, 0x84, 0x34, 0x67, 0x40, + 0x91, 0xe2, 0x81, 0xac, 0x25, 0x4b, 0x64, 0x33, 0x6d, 0xe2, 0x81, 0xcb, + 0x87, 0x41, 0x01, 0x4c, 0x88, 0x34, 0x67, 0x40, 0x91, 0xe2, 0x81, 0x9c, + 0x01, 0x4b, 0x68, 0x33, 0x6d, 0xe2, 0x81, 0xdb, 0x67, 0x40, 0x87, 0x41, + 0x1d, 0x4b, 0x1d, 0x4c, 0x84, 0x34, 0x64, 0x33, 0x6d, 0xe2, 0x89, 0xe2, + 0x40, 0xaa, 0x01, 0x49, 0x04, 0x95, 0x40, 0xcb, 0x09, 0x6a, 0x5a, 0xe9, + 0x01, 0x2a, 0xe5, 0xe8, 0xff, 0xf7, 0x1f, 0x6b, 0x05, 0xd3, 0x28, 0xb2, + 0x01, 0x48, 0x10, 0xec, 0x40, 0xea, 0x6c, 0xec, 0x09, 0x6c, 0x9a, 0xe8, + 0x01, 0x2c, 0xe5, 0xe8, 0x05, 0x93, 0x22, 0x67, 0x10, 0xe8, 0x6c, 0xe8, + 0x1d, 0xb3, 0x80, 0xf0, 0x52, 0xa3, 0x4a, 0xe9, 0xa4, 0x61, 0x0b, 0xe2, + 0x00, 0x52, 0x01, 0x60, 0x09, 0x4a, 0x19, 0xb3, 0x80, 0xf0, 0x90, 0xab, + 0x30, 0x67, 0x4b, 0xe4, 0x80, 0xf0, 0x50, 0xcb, 0x1a, 0x10, 0x28, 0x33, + 0x69, 0xe2, 0x40, 0x9a, 0x60, 0xaa, 0xe1, 0xf7, 0x1f, 0x6a, 0x6c, 0xea, + 0x04, 0x93, 0x4e, 0xeb, 0x15, 0xb2, 0x03, 0x2b, 0x91, 0x67, 0x01, 0x6d, + 0x02, 0x10, 0x91, 0x67, 0x00, 0x6d, 0x40, 0xea, 0x01, 0x49, 0x09, 0x6a, + 0x5a, 0xe9, 0x01, 0x2a, 0xe5, 0xe8, 0xff, 0xf7, 0x1f, 0x6a, 0x10, 0xe9, + 0x4c, 0xe9, 0x08, 0xb2, 0x80, 0xf0, 0x72, 0xa2, 0x2e, 0xeb, 0xe1, 0x2b, + 0x80, 0xf0, 0x12, 0xc2, 0x09, 0x97, 0x08, 0x91, 0x07, 0x90, 0x00, 0xef, + 0x05, 0x63, 0x00, 0x65, 0x70, 0x0c, 0x12, 0x80, 0x4c, 0x0a, 0x12, 0x80, + 0x04, 0x3c, 0x12, 0x80, 0x69, 0x23, 0x10, 0x80, 0x29, 0x23, 0x10, 0x80, + 0xe9, 0x22, 0x10, 0x80, 0xb1, 0x27, 0x10, 0x80, 0xfd, 0x63, 0x05, 0x62, + 0x40, 0xa4, 0x05, 0x72, 0x0d, 0x61, 0x09, 0xb2, 0x20, 0xf0, 0x4c, 0xa2, + 0x61, 0xa5, 0x82, 0xa5, 0x01, 0x72, 0x02, 0x60, 0x03, 0x72, 0x04, 0x61, + 0x80, 0x34, 0x05, 0xb2, 0x40, 0xea, 0x6d, 0xec, 0x05, 0x97, 0x00, 0x6a, + 0x00, 0xef, 0x03, 0x63, 0x78, 0x0c, 0x12, 0x80, 0x21, 0x28, 0x10, 0x80, + 0xfc, 0x63, 0x07, 0x62, 0x06, 0xd1, 0x05, 0xd0, 0x44, 0xb2, 0x80, 0xf0, + 0x73, 0xa2, 0xff, 0x69, 0x8c, 0xe9, 0x1a, 0x4b, 0x68, 0x33, 0x6d, 0xe2, + 0x00, 0x6c, 0x81, 0xdb, 0x40, 0xb3, 0x20, 0xf0, 0x6c, 0xa3, 0x01, 0x73, + 0x09, 0x60, 0x03, 0x73, 0x07, 0x60, 0x80, 0xf0, 0x73, 0xa2, 0x2c, 0x4b, + 0x64, 0x33, 0x69, 0xe2, 0x41, 0xaa, 0x19, 0x2a, 0x38, 0xb2, 0x80, 0xf0, + 0x53, 0xa2, 0x39, 0xb3, 0xe1, 0xf7, 0x1f, 0x68, 0x48, 0x32, 0x69, 0xe2, + 0x40, 0xaa, 0x4c, 0xe8, 0x36, 0xb2, 0x40, 0xea, 0x90, 0x67, 0x05, 0x2a, + 0x35, 0xb2, 0x62, 0xaa, 0x01, 0x4b, 0x62, 0xca, 0x06, 0x10, 0x34, 0xb2, + 0x04, 0x30, 0x01, 0xe2, 0x40, 0xa8, 0x01, 0x4a, 0x40, 0xc8, 0x2d, 0xb2, + 0x20, 0xf0, 0x4c, 0xa2, 0x0a, 0x22, 0x02, 0x72, 0x08, 0x60, 0x29, 0xb2, + 0x80, 0xf0, 0x73, 0xa2, 0x2c, 0x4b, 0x64, 0x33, 0x69, 0xe2, 0x41, 0xaa, + 0x30, 0x2a, 0x05, 0x71, 0x24, 0xb4, 0x2a, 0xb5, 0x2a, 0xb2, 0x09, 0x61, + 0x80, 0xf0, 0x73, 0xa4, 0x68, 0x33, 0x6d, 0xe4, 0x87, 0x9d, 0x40, 0xea, + 0xa0, 0x9b, 0x27, 0xb2, 0x08, 0x10, 0x80, 0xf0, 0x73, 0xa4, 0x68, 0x33, + 0x6d, 0xe4, 0x83, 0x9d, 0x40, 0xea, 0xa0, 0x9b, 0x23, 0xb2, 0x40, 0xea, + 0x00, 0x65, 0x19, 0xb2, 0x80, 0xf0, 0x73, 0xa2, 0x00, 0x6c, 0x68, 0x33, + 0x6d, 0xe2, 0x80, 0xdb, 0x80, 0xf0, 0x73, 0xa2, 0xff, 0x6c, 0x01, 0x4b, + 0x8c, 0xeb, 0x09, 0x6c, 0x9b, 0xeb, 0x01, 0x2c, 0xe5, 0xe8, 0x10, 0xeb, + 0x80, 0xf0, 0x73, 0xc2, 0x80, 0xf0, 0x70, 0xaa, 0xff, 0x4b, 0x80, 0xf0, + 0x70, 0xca, 0x0e, 0xb2, 0x20, 0xf0, 0x4c, 0xa2, 0x01, 0x72, 0x02, 0x60, + 0x03, 0x72, 0x0c, 0x61, 0x09, 0xb2, 0x80, 0xf0, 0x73, 0xa2, 0x1a, 0x4b, + 0x68, 0x33, 0x69, 0xe2, 0x41, 0x9a, 0x04, 0x2a, 0x0f, 0xb2, 0x40, 0x9a, + 0x40, 0xea, 0x00, 0x65, 0x07, 0x97, 0x06, 0x91, 0x05, 0x90, 0x00, 0xef, + 0x04, 0x63, 0x00, 0x65, 0x4c, 0x0a, 0x12, 0x80, 0x78, 0x0c, 0x12, 0x80, + 0x70, 0x0a, 0x12, 0x80, 0x75, 0xca, 0x01, 0x80, 0x70, 0x0c, 0x12, 0x80, + 0x04, 0x3c, 0x12, 0x80, 0x1c, 0x0b, 0x12, 0x80, 0xe1, 0xdd, 0x00, 0x80, + 0x1d, 0xda, 0x00, 0x80, 0x89, 0xda, 0x00, 0x80, 0x30, 0x00, 0x12, 0x80, + 0xfa, 0x63, 0x0b, 0x62, 0x0a, 0xd1, 0x09, 0xd0, 0x2b, 0xb2, 0x20, 0xf0, + 0x4c, 0xa2, 0x04, 0x67, 0x49, 0x22, 0xa3, 0xa4, 0x01, 0x69, 0x00, 0x6b, + 0x16, 0x10, 0x82, 0xa0, 0x01, 0x4b, 0x68, 0x32, 0x01, 0x4a, 0x42, 0xec, + 0x41, 0x61, 0x29, 0xe0, 0x84, 0xa2, 0x43, 0xa2, 0x06, 0xd3, 0x80, 0x34, + 0x4d, 0xec, 0x22, 0xb2, 0x40, 0xea, 0x05, 0xd5, 0x06, 0x93, 0x05, 0x95, + 0x35, 0x22, 0xff, 0x6a, 0x04, 0x49, 0x4c, 0xe9, 0x4c, 0xeb, 0xa3, 0xeb, + 0xe8, 0x61, 0xa3, 0xa0, 0x01, 0x69, 0x00, 0x6a, 0x27, 0x10, 0x2d, 0xe0, + 0xff, 0x6c, 0x02, 0x49, 0x8c, 0xe9, 0x39, 0xe0, 0x84, 0xa6, 0xc3, 0xa6, + 0xe3, 0xa3, 0x80, 0x34, 0xcd, 0xec, 0x14, 0xb6, 0x20, 0xf0, 0xcc, 0xa6, + 0x64, 0xa3, 0x01, 0x76, 0x02, 0x60, 0x03, 0x76, 0x08, 0x61, 0x60, 0x33, + 0xed, 0xeb, 0x11, 0xb6, 0x64, 0x33, 0x6d, 0xe6, 0xc0, 0xab, 0x9b, 0xe6, + 0xc0, 0xcb, 0xff, 0x6b, 0x04, 0xd2, 0x06, 0xd3, 0x05, 0xd5, 0x02, 0x49, + 0x0c, 0xb6, 0x40, 0xee, 0x6c, 0xe9, 0x04, 0x92, 0x06, 0x93, 0x05, 0x95, + 0x01, 0x4a, 0x6c, 0xea, 0xa3, 0xea, 0xd7, 0x61, 0x00, 0x6a, 0x01, 0x10, + 0x12, 0x6a, 0x0b, 0x97, 0x0a, 0x91, 0x09, 0x90, 0x00, 0xef, 0x06, 0x63, + 0x78, 0x0c, 0x12, 0x80, 0x75, 0xca, 0x01, 0x80, 0x04, 0x3c, 0x12, 0x80, + 0x65, 0x55, 0x00, 0x80, 0xfa, 0x63, 0x0b, 0x62, 0x0a, 0xd1, 0x09, 0xd0, + 0x04, 0xa4, 0x43, 0xa4, 0xe6, 0x44, 0x00, 0x30, 0x20, 0xa7, 0x67, 0xa4, + 0x4d, 0xe8, 0x45, 0x44, 0x6a, 0x65, 0x40, 0xa2, 0x20, 0x31, 0x01, 0x73, + 0x4d, 0xe9, 0x06, 0xd3, 0x1b, 0x60, 0x03, 0xe9, 0x19, 0x61, 0x20, 0x58, + 0x17, 0x60, 0x00, 0x6d, 0x20, 0x6e, 0xa4, 0xc4, 0xc3, 0xc4, 0x18, 0xb2, + 0x60, 0xa2, 0x0d, 0x65, 0x01, 0x6d, 0x4b, 0x65, 0x65, 0x67, 0xaa, 0x67, + 0xad, 0xeb, 0x20, 0x59, 0x60, 0xc2, 0x08, 0x60, 0xab, 0x67, 0x68, 0x67, + 0x60, 0xc7, 0xc0, 0xc5, 0xc0, 0xa2, 0x02, 0x6d, 0xcd, 0xed, 0xa0, 0xc2, + 0x0f, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x0f, 0x2a, 0x06, 0x93, 0x01, 0x73, + 0x0c, 0x60, 0x0b, 0xb3, 0x80, 0xa3, 0x01, 0x6b, 0x8c, 0xeb, 0x02, 0x23, + 0x0a, 0xb3, 0x16, 0xcb, 0x02, 0x6b, 0x8c, 0xeb, 0x02, 0x23, 0x08, 0xb3, + 0x37, 0xcb, 0x00, 0x6c, 0x04, 0xb3, 0x80, 0xc3, 0x0b, 0x97, 0x0a, 0x91, + 0x09, 0x90, 0x00, 0xef, 0x06, 0x63, 0x00, 0x65, 0x01, 0x3c, 0x12, 0x80, + 0x45, 0x4d, 0x01, 0x80, 0x10, 0x23, 0x12, 0x80, 0xfd, 0x63, 0x05, 0x62, + 0x04, 0xd0, 0x33, 0xb3, 0x20, 0xf0, 0xc8, 0xa3, 0x05, 0x67, 0x01, 0x6d, + 0xac, 0xee, 0x0c, 0x6a, 0x59, 0x2e, 0x30, 0xb2, 0xc0, 0x9a, 0x20, 0xf1, + 0x4c, 0xa3, 0x20, 0xf1, 0xea, 0xab, 0x24, 0x22, 0x01, 0xf7, 0x00, 0x6a, + 0xec, 0xea, 0xa4, 0xee, 0x43, 0x32, 0xff, 0x4d, 0xa2, 0xea, 0x1c, 0x61, + 0x20, 0xf0, 0x49, 0xa3, 0x1c, 0x6b, 0x6c, 0xea, 0x04, 0x72, 0x01, 0x60, + 0x15, 0x2a, 0x24, 0xb3, 0xb4, 0xab, 0x80, 0xf3, 0x01, 0x6a, 0x4b, 0xea, + 0xac, 0xea, 0xff, 0x6d, 0x01, 0x4d, 0xad, 0xea, 0xff, 0xf7, 0x1f, 0x6d, + 0x4c, 0xed, 0x54, 0xcb, 0x1d, 0x6a, 0xa2, 0x35, 0x4b, 0xea, 0xac, 0xea, + 0x0c, 0x6d, 0xad, 0xea, 0x20, 0xf0, 0x49, 0xc3, 0x43, 0xa4, 0x01, 0x72, + 0x00, 0x6a, 0x2a, 0x61, 0x17, 0xb2, 0x20, 0xf0, 0x8a, 0xa2, 0x40, 0x6b, + 0x8d, 0xeb, 0x20, 0xf0, 0x88, 0xa2, 0x20, 0xf0, 0x6a, 0xc2, 0x01, 0x6b, + 0x8d, 0xeb, 0x20, 0xf0, 0x68, 0xc2, 0x20, 0xf0, 0x49, 0xa2, 0x07, 0x6b, + 0x4a, 0x32, 0x6c, 0xea, 0x10, 0xb3, 0x49, 0xe3, 0x80, 0xa2, 0x10, 0xb2, + 0x40, 0xea, 0x00, 0x65, 0x01, 0x72, 0x09, 0x61, 0x0e, 0xb2, 0x40, 0xea, + 0x00, 0x6c, 0xff, 0x72, 0x04, 0x60, 0x82, 0x67, 0x0c, 0xb2, 0x40, 0xea, + 0x01, 0x6d, 0x0c, 0xb2, 0x40, 0x9a, 0x40, 0xea, 0x00, 0x65, 0x00, 0x6a, + 0x40, 0xc0, 0x00, 0x6a, 0x05, 0x97, 0x04, 0x90, 0x00, 0xef, 0x03, 0x63, + 0x10, 0x23, 0x12, 0x80, 0xc8, 0x03, 0x12, 0x80, 0x90, 0xee, 0x01, 0x80, + 0xfd, 0xd0, 0x01, 0x80, 0x6d, 0xe6, 0x01, 0x80, 0xa9, 0xe6, 0x01, 0x80, + 0xd4, 0x04, 0x12, 0x80, 0xfc, 0x63, 0x07, 0x62, 0x06, 0xd0, 0x19, 0xb0, + 0x20, 0xf0, 0x4a, 0xa0, 0x40, 0x6b, 0x4c, 0xeb, 0x00, 0x6a, 0x26, 0x23, + 0x82, 0x67, 0x16, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x20, 0xf0, 0x68, 0xa0, + 0x02, 0x6a, 0x4b, 0xea, 0x6c, 0xea, 0x20, 0xf0, 0x6a, 0xa0, 0x20, 0xf0, + 0x48, 0xc0, 0x41, 0x6a, 0x4b, 0xea, 0x6c, 0xea, 0x20, 0xf0, 0x4a, 0xc0, + 0x0e, 0xb2, 0x80, 0xa2, 0x02, 0x6d, 0x0e, 0xb2, 0x40, 0xea, 0x04, 0x00, + 0x9f, 0xf4, 0x07, 0x6c, 0x0c, 0xb2, 0x40, 0xea, 0xb0, 0x67, 0x00, 0x6a, + 0x7d, 0x67, 0x53, 0xc3, 0x0e, 0x6c, 0xb0, 0x67, 0x09, 0xb2, 0x40, 0xea, + 0x04, 0x6e, 0x01, 0x6a, 0x07, 0x97, 0x06, 0x90, 0x00, 0xef, 0x04, 0x63, + 0x10, 0x23, 0x12, 0x80, 0x91, 0x40, 0x00, 0x80, 0x38, 0x05, 0x12, 0x80, + 0xa9, 0xe6, 0x01, 0x80, 0x95, 0x2b, 0x01, 0x80, 0x01, 0x4b, 0x00, 0x80, + 0xfd, 0x63, 0x05, 0x62, 0xff, 0x6a, 0x8c, 0xea, 0x05, 0x72, 0x21, 0x61, + 0x14, 0xb3, 0x74, 0xab, 0x80, 0xf3, 0x00, 0x6c, 0x8c, 0xeb, 0x03, 0x23, + 0x00, 0xf3, 0x00, 0x73, 0x09, 0x61, 0x11, 0xb4, 0xe0, 0xf1, 0x1f, 0x6b, + 0xa0, 0xac, 0xac, 0xeb, 0x00, 0xf6, 0x00, 0x6d, 0xad, 0xeb, 0x60, 0xcc, + 0x0b, 0xb3, 0x20, 0xf0, 0x8a, 0xa3, 0x40, 0x6b, 0x8c, 0xeb, 0x09, 0x23, + 0x0a, 0xb4, 0xff, 0xf7, 0x1f, 0x6d, 0x10, 0x6e, 0x60, 0xac, 0xac, 0xeb, + 0xcd, 0xeb, 0xac, 0xeb, 0x60, 0xcc, 0x82, 0x67, 0x06, 0xb2, 0x40, 0xea, + 0x00, 0x65, 0x05, 0x97, 0x00, 0xef, 0x03, 0x63, 0x10, 0x23, 0x12, 0x80, + 0x40, 0x10, 0x00, 0xb6, 0x8e, 0x12, 0x00, 0xb6, 0x71, 0xac, 0x01, 0x80, + 0xfc, 0x63, 0x07, 0x62, 0x06, 0xd1, 0x05, 0xd0, 0x14, 0xb2, 0x40, 0x9a, + 0x09, 0xd5, 0x40, 0xea, 0x24, 0x67, 0x40, 0xd9, 0x09, 0x92, 0x02, 0x2a, + 0x19, 0x10, 0x40, 0xd9, 0x10, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x02, 0x67, + 0x0d, 0xb2, 0x40, 0x9a, 0x40, 0xea, 0x00, 0x65, 0x60, 0x99, 0x4e, 0xeb, + 0xf4, 0x2b, 0x60, 0xf2, 0x11, 0x58, 0x05, 0x61, 0x9f, 0xf5, 0x10, 0x48, + 0xff, 0xf7, 0x1f, 0x6a, 0x4c, 0xe8, 0x60, 0xf2, 0x10, 0x6a, 0x03, 0xe2, + 0x09, 0x92, 0x00, 0xda, 0x07, 0x97, 0x06, 0x91, 0x05, 0x90, 0x00, 0xef, + 0x04, 0x63, 0x00, 0x65, 0x14, 0x00, 0x12, 0x80, 0xa9, 0x38, 0x00, 0x80, + 0xf9, 0x63, 0x0d, 0x62, 0x0c, 0xd1, 0x0b, 0xd0, 0xff, 0x6a, 0xac, 0xea, + 0x06, 0xd2, 0x00, 0x6a, 0x40, 0xdc, 0x4e, 0xa4, 0x04, 0x67, 0x0f, 0x72, + 0x5e, 0x60, 0x1d, 0x4a, 0x32, 0xb3, 0x50, 0x32, 0x49, 0xe3, 0x21, 0x9a, + 0x04, 0x04, 0x31, 0xb2, 0x40, 0xea, 0x00, 0x6d, 0x04, 0x92, 0x30, 0xb4, + 0xb1, 0x67, 0x0a, 0x6e, 0x4c, 0xec, 0x86, 0x34, 0x2e, 0xb2, 0x40, 0xea, + 0x04, 0xd4, 0x22, 0x67, 0x04, 0x92, 0x40, 0xd8, 0x4f, 0xa0, 0x02, 0x72, + 0x03, 0x60, 0x2b, 0xb2, 0x2e, 0xea, 0x01, 0x2a, 0x00, 0x69, 0x25, 0xb3, + 0xc0, 0xf1, 0xa2, 0xa3, 0x0c, 0x75, 0x10, 0x61, 0x08, 0xd3, 0x07, 0xd5, + 0x26, 0xb2, 0x40, 0xea, 0x0c, 0x6c, 0x43, 0xe9, 0x08, 0x93, 0x07, 0x95, + 0x07, 0x60, 0x4e, 0xa0, 0x0c, 0x72, 0x31, 0x61, 0x01, 0x6a, 0xc0, 0xf1, + 0x43, 0xc3, 0x27, 0x10, 0x8e, 0xa0, 0x8e, 0xed, 0x11, 0x2d, 0x1e, 0xb2, + 0x40, 0xea, 0x00, 0x65, 0x23, 0xea, 0x25, 0x61, 0x06, 0x94, 0x16, 0xb2, + 0x90, 0x33, 0x6d, 0xe2, 0xc0, 0xf1, 0x46, 0x8a, 0xc0, 0xf1, 0x6c, 0x8b, + 0x01, 0x4a, 0x62, 0xea, 0x10, 0x60, 0x19, 0x10, 0x06, 0x95, 0x10, 0xb2, + 0x90, 0x34, 0xb0, 0x33, 0x6d, 0xe2, 0x91, 0xe2, 0xc0, 0xf1, 0xae, 0x8b, + 0xc0, 0xf1, 0x6e, 0x8c, 0xa2, 0xeb, 0x0d, 0x61, 0x0f, 0x6b, 0xc0, 0xf1, + 0x62, 0xc2, 0x01, 0x6b, 0x08, 0xb2, 0xc0, 0xf1, 0x63, 0xc2, 0x0d, 0xb2, + 0x0f, 0x6c, 0x40, 0xea, 0x01, 0x6d, 0x01, 0x6a, 0x01, 0x10, 0x00, 0x6a, + 0x0d, 0x97, 0x0c, 0x91, 0x0b, 0x90, 0x00, 0xef, 0x07, 0x63, 0x00, 0x65, + 0x10, 0x23, 0x12, 0x80, 0x65, 0x2e, 0x10, 0x80, 0xff, 0xff, 0x07, 0x00, + 0x55, 0x65, 0x00, 0x80, 0xff, 0xff, 0x03, 0x00, 0x91, 0x22, 0x10, 0x80, + 0x6d, 0xa2, 0x01, 0x80, 0xfc, 0x63, 0x07, 0x62, 0x06, 0xd1, 0x05, 0xd0, + 0x00, 0x69, 0x04, 0x67, 0x01, 0x6c, 0x8b, 0xec, 0x51, 0x67, 0x18, 0x10, + 0x4d, 0xe0, 0x72, 0xa3, 0x70, 0x36, 0xd9, 0xe5, 0xc0, 0xf1, 0xf0, 0xa6, + 0x01, 0x4f, 0xc0, 0xf1, 0xf0, 0xc6, 0xe7, 0x43, 0x16, 0x4f, 0xf0, 0x37, + 0xf5, 0xe5, 0xe2, 0x98, 0xe2, 0xdd, 0xc0, 0xf1, 0xac, 0x8e, 0xa2, 0xec, + 0x02, 0x60, 0x85, 0x67, 0x23, 0x67, 0x01, 0x4a, 0xff, 0x6b, 0x6c, 0xea, + 0x20, 0xf0, 0x60, 0xa0, 0x21, 0xb5, 0x63, 0xea, 0xe3, 0x61, 0x30, 0x32, + 0x55, 0xe5, 0xc0, 0xf1, 0x4c, 0x8d, 0x00, 0xf4, 0x00, 0x52, 0x09, 0x60, + 0x90, 0x67, 0x1d, 0xb2, 0x40, 0xea, 0xb1, 0x67, 0x04, 0x22, 0x20, 0xf0, + 0x61, 0xa0, 0x08, 0x6a, 0x27, 0x10, 0x18, 0xb2, 0x30, 0x33, 0x6d, 0xe2, + 0xc0, 0xf1, 0x90, 0xa3, 0xc0, 0xf1, 0x84, 0xc2, 0xc0, 0xf1, 0x8c, 0xab, + 0xc0, 0xf1, 0x86, 0xca, 0x87, 0x41, 0x16, 0x4c, 0x90, 0x34, 0x91, 0xe2, + 0xa1, 0x9c, 0xc0, 0xf1, 0x22, 0xc2, 0xc0, 0xf1, 0xa8, 0xda, 0x02, 0x6d, + 0xc0, 0xf1, 0xa3, 0xc2, 0x00, 0x6a, 0xc0, 0xf1, 0x50, 0xc3, 0xc0, 0xf1, + 0x4e, 0xab, 0x02, 0x6d, 0xc0, 0xf1, 0x4c, 0xcb, 0x42, 0x98, 0x41, 0xdc, + 0x09, 0xb2, 0x40, 0xea, 0x91, 0x67, 0x20, 0xf0, 0x61, 0xa0, 0x10, 0x6a, + 0x6d, 0xea, 0x20, 0xf0, 0x41, 0xc0, 0x07, 0x97, 0x06, 0x91, 0x05, 0x90, + 0x00, 0xef, 0x04, 0x63, 0x10, 0x23, 0x12, 0x80, 0xc5, 0x2e, 0x10, 0x80, + 0x6d, 0xa2, 0x01, 0x80, 0xfd, 0x63, 0x05, 0x62, 0x04, 0xb2, 0x40, 0xea, + 0x00, 0x65, 0x05, 0x97, 0x01, 0x6a, 0x00, 0xef, 0x03, 0x63, 0x00, 0x65, + 0xc5, 0x2f, 0x10, 0x80, 0xfd, 0x63, 0x05, 0x62, 0x00, 0x6b, 0x15, 0xb2, + 0x60, 0xc2, 0x15, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x14, 0xb2, 0x40, 0xa2, + 0x03, 0x2a, 0x14, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x13, 0xb2, 0x14, 0xb3, + 0x80, 0xaa, 0xe0, 0xf3, 0x1f, 0x6a, 0x4c, 0xec, 0x80, 0xcb, 0x12, 0xb3, + 0x60, 0xab, 0x6c, 0xea, 0x11, 0xb3, 0x40, 0xcb, 0xa3, 0x6b, 0x11, 0xb2, + 0x60, 0xca, 0x11, 0xb2, 0x00, 0x6b, 0x60, 0xca, 0x00, 0x6a, 0x10, 0xb3, 0x4d, 0xe3, 0x01, 0x4a, 0x01, 0x6c, 0x09, 0x52, 0x80, 0xc3, 0xf9, 0x61, - 0x0b, 0x97, 0x0a, 0x90, 0x00, 0xef, 0x06, 0x63, 0x01, 0x3c, 0x12, 0x80, - 0x61, 0x35, 0x10, 0x80, 0x00, 0x3c, 0x12, 0x80, 0x11, 0x3a, 0x10, 0x80, + 0x05, 0x97, 0x00, 0xef, 0x03, 0x63, 0x00, 0x65, 0x01, 0x3c, 0x12, 0x80, + 0x05, 0x35, 0x10, 0x80, 0x00, 0x3c, 0x12, 0x80, 0xb5, 0x39, 0x10, 0x80, 0x10, 0x12, 0x00, 0xb6, 0x34, 0x3c, 0x12, 0x80, 0x12, 0x12, 0x00, 0xb6, 0x36, 0x3c, 0x12, 0x80, 0x38, 0x3c, 0x12, 0x80, 0x3a, 0x3c, 0x12, 0x80, - 0x40, 0x3d, 0x10, 0x80, 0xfd, 0x25, 0x10, 0x80, 0x27, 0x24, 0x12, 0x80, - 0x19, 0xc3, 0x00, 0x80, 0x10, 0x23, 0x12, 0x80, 0x44, 0x3c, 0x12, 0x80, - 0xfd, 0x63, 0x05, 0x62, 0x40, 0xac, 0x01, 0xf4, 0x03, 0x72, 0x03, 0x61, - 0x04, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x05, 0x97, 0x00, 0x6a, 0x00, 0xef, - 0x03, 0x63, 0x00, 0x65, 0xc9, 0x30, 0x10, 0x80, 0xfa, 0x63, 0x0b, 0x62, - 0x0a, 0xd1, 0x09, 0xd0, 0x01, 0x6b, 0x5d, 0x67, 0x70, 0xc2, 0x40, 0xac, - 0x04, 0x67, 0x26, 0x67, 0xbf, 0xf4, 0x0e, 0x72, 0x10, 0x60, 0xbf, 0xf4, - 0x0f, 0x6c, 0x83, 0xea, 0x04, 0x60, 0x9f, 0xf4, 0x07, 0x72, 0x20, 0x60, - 0x41, 0x10, 0x9f, 0xf5, 0x00, 0x6f, 0x4e, 0xef, 0x21, 0x27, 0x9f, 0xf5, - 0x12, 0x72, 0x2a, 0x60, 0x39, 0x10, 0x62, 0xa4, 0x43, 0xa4, 0x01, 0x73, - 0x3f, 0x61, 0x08, 0x5a, 0x3d, 0x60, 0x23, 0xb3, 0x40, 0xc3, 0x23, 0xb4, - 0x40, 0xf0, 0xa4, 0xac, 0x07, 0x6b, 0x4c, 0xeb, 0x80, 0xf3, 0x01, 0x6a, - 0x4b, 0xea, 0xac, 0xea, 0x7c, 0x33, 0x6d, 0xea, 0x40, 0xf0, 0x44, 0xcc, - 0x00, 0x6d, 0x2d, 0x10, 0x04, 0x05, 0x1c, 0xb2, 0x40, 0xea, 0x90, 0x67, - 0xa2, 0x67, 0x27, 0x10, 0xc3, 0xa0, 0x06, 0xd7, 0x9f, 0xf5, 0x00, 0x6c, - 0x12, 0x6d, 0x18, 0xb2, 0x40, 0xea, 0xc0, 0x36, 0x06, 0x97, 0x7d, 0x67, - 0xf0, 0xc3, 0x1a, 0x10, 0xa6, 0x67, 0x15, 0xb2, 0x06, 0xd3, 0x40, 0xea, - 0x90, 0x67, 0x06, 0x93, 0x5d, 0x67, 0xa0, 0xa1, 0x70, 0xc2, 0x11, 0x10, - 0x80, 0xa8, 0x0f, 0xb2, 0x40, 0xea, 0x00, 0x6e, 0x01, 0x6a, 0x05, 0x10, - 0x01, 0x6a, 0x40, 0xc5, 0x00, 0x6a, 0x40, 0xc1, 0x00, 0x6a, 0x0b, 0x97, - 0x0a, 0x91, 0x09, 0x90, 0x00, 0xef, 0x06, 0x63, 0x12, 0x6d, 0x7d, 0x67, - 0x50, 0xa3, 0x01, 0x72, 0x01, 0x6a, 0xf5, 0x61, 0xe9, 0x17, 0x00, 0x65, - 0x34, 0x03, 0x12, 0x80, 0x10, 0x23, 0x12, 0x80, 0xa1, 0x2c, 0x10, 0x80, - 0x85, 0xab, 0x00, 0x80, 0x59, 0x24, 0x10, 0x80, 0xfc, 0x63, 0x07, 0x62, - 0x06, 0xd1, 0x05, 0xd0, 0x44, 0xac, 0x04, 0x67, 0xe0, 0xf1, 0x16, 0x72, - 0x17, 0x60, 0x40, 0xf4, 0x12, 0x72, 0x17, 0x61, 0x40, 0x9c, 0x60, 0xa2, - 0x3e, 0x73, 0x13, 0x61, 0x42, 0xa2, 0x02, 0x72, 0x10, 0x61, 0x0d, 0xb1, - 0x0d, 0xb2, 0x40, 0xea, 0x81, 0x99, 0xff, 0x6b, 0x4c, 0xeb, 0x03, 0x5b, - 0x08, 0x60, 0x81, 0x99, 0x0a, 0xb2, 0x40, 0xea, 0xa0, 0x98, 0x07, 0x10, - 0x80, 0xa4, 0x09, 0xb2, 0x02, 0x10, 0x90, 0x67, 0x08, 0xb2, 0x40, 0xea, - 0x00, 0x65, 0x07, 0x97, 0x06, 0x91, 0x05, 0x90, 0x00, 0xef, 0x04, 0x63, - 0x1c, 0x0b, 0x12, 0x80, 0xd1, 0xdd, 0x00, 0x80, 0xe1, 0xdd, 0x00, 0x80, - 0xf9, 0x29, 0x10, 0x80, 0x21, 0x5b, 0x00, 0x80, 0xfc, 0x63, 0x07, 0x62, - 0x06, 0xd0, 0x04, 0x67, 0x80, 0xac, 0x21, 0xf4, 0x15, 0x74, 0x0a, 0x61, - 0x0f, 0xb2, 0x40, 0xea, 0x90, 0x67, 0xa2, 0x67, 0x01, 0x6a, 0x13, 0x25, - 0x80, 0xa8, 0x04, 0xd2, 0x00, 0x6e, 0x0b, 0x10, 0xeb, 0xf7, 0x40, 0x44, - 0xff, 0xf7, 0x1f, 0x6b, 0x6c, 0xea, 0xe0, 0x5a, 0x00, 0x6a, 0x07, 0x60, - 0x04, 0xd2, 0x01, 0x6d, 0xc2, 0x67, 0x06, 0xb2, 0x40, 0xea, 0xe6, 0x67, - 0x01, 0x6a, 0x07, 0x97, 0x06, 0x90, 0x00, 0xef, 0x04, 0x63, 0x00, 0x65, - 0x3d, 0x2b, 0x10, 0x80, 0xed, 0x4d, 0x00, 0x80, 0xfd, 0x63, 0x05, 0x62, - 0x03, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x05, 0x97, 0x00, 0xef, 0x03, 0x63, - 0x61, 0x94, 0x00, 0x80, 0xfb, 0x63, 0x09, 0x62, 0x08, 0xd1, 0x07, 0xd0, - 0x18, 0xb3, 0x19, 0xb2, 0x43, 0xeb, 0x26, 0x61, 0x18, 0xb2, 0x80, 0x9a, - 0x18, 0xb3, 0x8e, 0xeb, 0x21, 0x2b, 0x02, 0xaa, 0x17, 0xb5, 0x1d, 0x10, - 0x42, 0x45, 0x17, 0xb4, 0x43, 0xec, 0x1a, 0x61, 0xc0, 0xa2, 0xff, 0xf7, - 0x1f, 0x6f, 0x43, 0x46, 0x43, 0xe8, 0x14, 0x61, 0x45, 0xe5, 0x23, 0xec, - 0x11, 0x61, 0x81, 0xa5, 0x60, 0xa5, 0x80, 0x34, 0x6d, 0xec, 0xec, 0xec, - 0xe0, 0xf1, 0x04, 0x5c, 0x09, 0x60, 0x43, 0xe0, 0x0d, 0xb2, 0x91, 0xe2, - 0x03, 0x4d, 0x0d, 0xb2, 0x40, 0xea, 0xec, 0xe8, 0xb1, 0x67, 0xe2, 0x28, - 0x09, 0x97, 0x08, 0x91, 0x07, 0x90, 0x00, 0xef, 0x05, 0x63, 0x00, 0x65, - 0xf0, 0xbf, 0x10, 0x80, 0x30, 0x3e, 0x10, 0x80, 0x34, 0x3e, 0x10, 0x80, - 0x55, 0xab, 0x23, 0x87, 0x3a, 0x3e, 0x10, 0x80, 0xff, 0xbf, 0x10, 0x80, - 0x38, 0x01, 0x12, 0x80, 0x19, 0xc3, 0x00, 0x80, 0xfd, 0x63, 0x05, 0x62, - 0x0e, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x0e, 0xb3, 0xff, 0xf7, 0x1f, 0x6c, - 0x02, 0xf0, 0x00, 0x6d, 0x40, 0xab, 0xab, 0xed, 0x8c, 0xea, 0xad, 0xea, - 0x3f, 0x4d, 0xac, 0xea, 0x02, 0xf1, 0x01, 0x4d, 0xad, 0xea, 0x9f, 0xf6, - 0x00, 0x4d, 0xac, 0xea, 0x05, 0x6d, 0xad, 0xea, 0x8c, 0xea, 0x40, 0xcb, - 0x05, 0x97, 0x00, 0xef, 0x03, 0x63, 0x00, 0x65, 0x39, 0x72, 0x01, 0x80, - 0x28, 0x12, 0x00, 0xb6, 0xfd, 0x63, 0x05, 0x62, 0x15, 0xb2, 0x40, 0xea, - 0x00, 0x65, 0x15, 0xb2, 0x20, 0xf0, 0x8a, 0xa2, 0x01, 0x6b, 0x8d, 0xeb, - 0xa0, 0xf1, 0x95, 0xa2, 0x20, 0xf0, 0x6a, 0xc2, 0x07, 0x6b, 0x6b, 0xeb, - 0x8c, 0xeb, 0xa0, 0xf1, 0x75, 0xc2, 0x00, 0x6a, 0x50, 0x35, 0x0d, 0xb3, - 0xb5, 0xe3, 0x00, 0xf4, 0x00, 0x6c, 0xc0, 0xf1, 0x8e, 0xcd, 0x01, 0x4a, - 0xff, 0x6d, 0xac, 0xea, 0x0b, 0x5a, 0xf4, 0x61, 0x00, 0xf1, 0x00, 0x6a, - 0x60, 0xf2, 0x5e, 0xcb, 0x00, 0x6a, 0x80, 0xf2, 0x8e, 0xcb, 0x80, 0xf2, - 0x5e, 0xcb, 0x05, 0x97, 0x00, 0xef, 0x03, 0x63, 0xc9, 0x76, 0x01, 0x80, - 0x10, 0x23, 0x12, 0x80, 0xfd, 0x63, 0x05, 0x62, 0x0d, 0xb2, 0x0e, 0xb3, - 0x72, 0xda, 0x0e, 0xb3, 0x6c, 0xda, 0x0e, 0xb2, 0x40, 0xea, 0x00, 0x65, - 0x0d, 0xb2, 0xff, 0xf7, 0x1f, 0x6b, 0xff, 0x6c, 0xa0, 0xaa, 0x08, 0xf0, - 0x00, 0x6a, 0x7b, 0x4c, 0x6c, 0xed, 0x4d, 0xed, 0x09, 0xb2, 0x40, 0x9a, - 0x40, 0xea, 0x6c, 0xed, 0x05, 0x97, 0x00, 0x6a, 0x00, 0xef, 0x03, 0x63, - 0xa4, 0x19, 0x12, 0x80, 0x59, 0x33, 0x10, 0x80, 0x99, 0x32, 0x10, 0x80, - 0x29, 0x37, 0x10, 0x80, 0x7a, 0x01, 0x00, 0xb6, 0x10, 0x00, 0x12, 0x80, - 0x15, 0xb3, 0x16, 0xb2, 0x60, 0xda, 0x16, 0xb3, 0x16, 0xb2, 0x60, 0xda, - 0x16, 0xb2, 0xa0, 0xf0, 0x6f, 0xa2, 0xa0, 0xf0, 0x8e, 0xa2, 0x60, 0x33, - 0x8d, 0xeb, 0xa0, 0xf0, 0x90, 0xa2, 0x80, 0x34, 0x80, 0x34, 0x6d, 0xec, - 0xa0, 0xf0, 0x71, 0xa2, 0x00, 0xf6, 0x60, 0x33, 0x8d, 0xeb, 0x0f, 0xb4, - 0x8d, 0xeb, 0x62, 0x34, 0xa0, 0xf0, 0x6e, 0xc2, 0xa0, 0xf0, 0x8f, 0xc2, - 0x00, 0xf6, 0x62, 0x33, 0x82, 0x34, 0xa0, 0xf0, 0x71, 0xc2, 0xa0, 0xf0, - 0x90, 0xc2, 0x09, 0xb3, 0x09, 0xb2, 0x20, 0xe8, 0x60, 0xda, 0x00, 0x65, - 0x39, 0x39, 0x10, 0x80, 0x04, 0x07, 0x12, 0x80, 0x65, 0x36, 0x10, 0x80, - 0x00, 0x08, 0x12, 0x80, 0x38, 0x01, 0x12, 0x80, 0x00, 0x00, 0x00, 0x80, - 0xd1, 0x38, 0x10, 0x80, 0x00, 0x07, 0x12, 0x80, 0x20, 0xe8, 0x00, 0x65, - 0x08, 0xb2, 0x40, 0x9a, 0x61, 0x42, 0x09, 0x23, 0x03, 0x6b, 0x78, 0xea, - 0x06, 0xb3, 0x12, 0xea, 0x01, 0x4a, 0x4c, 0x32, 0x49, 0xe3, 0x05, 0xb3, - 0x61, 0xda, 0x20, 0xe8, 0x00, 0x65, 0x00, 0x65, 0xfc, 0x00, 0x12, 0x80, - 0x6c, 0x1a, 0x12, 0x80, 0x41, 0x38, 0x10, 0x80, 0x08, 0xb2, 0x20, 0xf1, - 0x6c, 0xa2, 0x61, 0xc4, 0x00, 0x6b, 0x60, 0xc4, 0x40, 0xf0, 0xa4, 0xa2, - 0x01, 0x6b, 0x6c, 0xed, 0xa2, 0xc4, 0xe0, 0xf0, 0x5c, 0xa2, 0x4c, 0xeb, - 0x20, 0xe8, 0x63, 0xc4, 0x10, 0x23, 0x12, 0x80, 0x11, 0xb2, 0xa1, 0xa4, - 0x20, 0xf0, 0x42, 0xa2, 0x00, 0x6b, 0xae, 0xea, 0x01, 0x22, 0x01, 0x6b, - 0x01, 0x6a, 0x6c, 0xea, 0x0d, 0xb3, 0xc2, 0xa4, 0x60, 0xa3, 0x00, 0x6d, - 0xce, 0xeb, 0x01, 0x23, 0x01, 0x6d, 0x01, 0x6b, 0xac, 0xeb, 0x74, 0x33, - 0x4d, 0xeb, 0x08, 0xb2, 0x83, 0xa4, 0x41, 0xa2, 0x00, 0x6d, 0x8e, 0xea, - 0x01, 0x22, 0x01, 0x6d, 0x01, 0x6a, 0xac, 0xea, 0x40, 0x32, 0x4c, 0x32, - 0x20, 0xe8, 0x6d, 0xea, 0x44, 0x0d, 0x12, 0x80, 0x3c, 0x3c, 0x12, 0x80, - 0x61, 0xa4, 0x05, 0xb2, 0x20, 0xf0, 0x62, 0xc2, 0x62, 0xa4, 0x04, 0xb2, - 0x60, 0xc2, 0x63, 0xa4, 0x20, 0xe8, 0x61, 0xc2, 0x44, 0x0d, 0x12, 0x80, - 0x3c, 0x3c, 0x12, 0x80, 0x20, 0xe8, 0x00, 0x6a, 0x20, 0xe8, 0x00, 0x6a, - 0x20, 0xe8, 0x00, 0x6a, 0x20, 0xe8, 0x7f, 0x6a, 0x09, 0xb2, 0x20, 0xf0, - 0x47, 0xa2, 0x03, 0x22, 0xe9, 0xf7, 0x1a, 0x6b, 0x01, 0x10, 0x60, 0xac, - 0x05, 0xb4, 0x4b, 0x9c, 0x02, 0x6e, 0xcb, 0xee, 0xcc, 0xea, 0x4b, 0xdc, - 0x60, 0xcd, 0x20, 0xe8, 0x00, 0x6a, 0x00, 0x65, 0x44, 0x0d, 0x12, 0x80, + 0x44, 0x3c, 0x12, 0x80, 0xfd, 0x63, 0x05, 0x62, 0x40, 0xac, 0x01, 0xf4, + 0x03, 0x72, 0x03, 0x61, 0x04, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x05, 0x97, + 0x00, 0x6a, 0x00, 0xef, 0x03, 0x63, 0x00, 0x65, 0xb5, 0x30, 0x10, 0x80, + 0xfa, 0x63, 0x0b, 0x62, 0x0a, 0xd1, 0x09, 0xd0, 0x01, 0x6b, 0x5d, 0x67, + 0x70, 0xc2, 0x40, 0xac, 0x04, 0x67, 0x26, 0x67, 0xbf, 0xf4, 0x0e, 0x72, + 0x10, 0x60, 0xbf, 0xf4, 0x0f, 0x6c, 0x83, 0xea, 0x04, 0x60, 0x9f, 0xf4, + 0x07, 0x72, 0x20, 0x60, 0x41, 0x10, 0x9f, 0xf5, 0x00, 0x6f, 0x4e, 0xef, + 0x21, 0x27, 0x9f, 0xf5, 0x12, 0x72, 0x2a, 0x60, 0x39, 0x10, 0x62, 0xa4, + 0x43, 0xa4, 0x01, 0x73, 0x3f, 0x61, 0x08, 0x5a, 0x3d, 0x60, 0x23, 0xb3, + 0x40, 0xc3, 0x23, 0xb4, 0x40, 0xf0, 0xa4, 0xac, 0x07, 0x6b, 0x4c, 0xeb, + 0x80, 0xf3, 0x01, 0x6a, 0x4b, 0xea, 0xac, 0xea, 0x7c, 0x33, 0x6d, 0xea, + 0x40, 0xf0, 0x44, 0xcc, 0x00, 0x6d, 0x2d, 0x10, 0x04, 0x05, 0x1c, 0xb2, + 0x40, 0xea, 0x90, 0x67, 0xa2, 0x67, 0x27, 0x10, 0xc3, 0xa0, 0x06, 0xd7, + 0x9f, 0xf5, 0x00, 0x6c, 0x12, 0x6d, 0x18, 0xb2, 0x40, 0xea, 0xc0, 0x36, + 0x06, 0x97, 0x7d, 0x67, 0xf0, 0xc3, 0x1a, 0x10, 0xa6, 0x67, 0x15, 0xb2, + 0x06, 0xd3, 0x40, 0xea, 0x90, 0x67, 0x06, 0x93, 0x5d, 0x67, 0xa0, 0xa1, + 0x70, 0xc2, 0x11, 0x10, 0x80, 0xa8, 0x0f, 0xb2, 0x40, 0xea, 0x00, 0x6e, + 0x01, 0x6a, 0x05, 0x10, 0x01, 0x6a, 0x40, 0xc5, 0x00, 0x6a, 0x40, 0xc1, + 0x00, 0x6a, 0x0b, 0x97, 0x0a, 0x91, 0x09, 0x90, 0x00, 0xef, 0x06, 0x63, + 0x12, 0x6d, 0x7d, 0x67, 0x50, 0xa3, 0x01, 0x72, 0x01, 0x6a, 0xf5, 0x61, + 0xe9, 0x17, 0x00, 0x65, 0x34, 0x03, 0x12, 0x80, 0x10, 0x23, 0x12, 0x80, + 0x8d, 0x2c, 0x10, 0x80, 0x85, 0xab, 0x00, 0x80, 0x69, 0x24, 0x10, 0x80, + 0xfc, 0x63, 0x07, 0x62, 0x06, 0xd1, 0x05, 0xd0, 0x44, 0xac, 0x04, 0x67, + 0xe0, 0xf1, 0x16, 0x72, 0x17, 0x60, 0x40, 0xf4, 0x12, 0x72, 0x17, 0x61, + 0x40, 0x9c, 0x60, 0xa2, 0x3e, 0x73, 0x13, 0x61, 0x42, 0xa2, 0x02, 0x72, + 0x10, 0x61, 0x0d, 0xb1, 0x0d, 0xb2, 0x40, 0xea, 0x81, 0x99, 0xff, 0x6b, + 0x4c, 0xeb, 0x03, 0x5b, 0x08, 0x60, 0x81, 0x99, 0x0a, 0xb2, 0x40, 0xea, + 0xa0, 0x98, 0x07, 0x10, 0x80, 0xa4, 0x09, 0xb2, 0x02, 0x10, 0x90, 0x67, + 0x08, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x07, 0x97, 0x06, 0x91, 0x05, 0x90, + 0x00, 0xef, 0x04, 0x63, 0x1c, 0x0b, 0x12, 0x80, 0xd1, 0xdd, 0x00, 0x80, + 0xe1, 0xdd, 0x00, 0x80, 0xe5, 0x29, 0x10, 0x80, 0x21, 0x5b, 0x00, 0x80, + 0xfc, 0x63, 0x07, 0x62, 0x06, 0xd0, 0x04, 0x67, 0x80, 0xac, 0x21, 0xf4, + 0x15, 0x74, 0x0a, 0x61, 0x0f, 0xb2, 0x40, 0xea, 0x90, 0x67, 0xa2, 0x67, + 0x01, 0x6a, 0x13, 0x25, 0x80, 0xa8, 0x04, 0xd2, 0x00, 0x6e, 0x0b, 0x10, + 0xeb, 0xf7, 0x40, 0x44, 0xff, 0xf7, 0x1f, 0x6b, 0x6c, 0xea, 0xe0, 0x5a, + 0x00, 0x6a, 0x07, 0x60, 0x04, 0xd2, 0x01, 0x6d, 0xc2, 0x67, 0x06, 0xb2, + 0x40, 0xea, 0xe6, 0x67, 0x01, 0x6a, 0x07, 0x97, 0x06, 0x90, 0x00, 0xef, + 0x04, 0x63, 0x00, 0x65, 0x29, 0x2b, 0x10, 0x80, 0xed, 0x4d, 0x00, 0x80, 0xfd, 0x63, 0x05, 0x62, 0x03, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x05, 0x97, - 0x00, 0xef, 0x03, 0x63, 0x59, 0x17, 0x01, 0x80, 0xfd, 0x63, 0x05, 0x62, - 0x60, 0x9c, 0x10, 0xf0, 0x00, 0x6a, 0x6c, 0xea, 0x0c, 0x22, 0x09, 0xb2, - 0x40, 0xea, 0x00, 0x65, 0x08, 0xb3, 0xff, 0x6c, 0x80, 0x6d, 0x40, 0xa3, - 0xab, 0xed, 0x8c, 0xea, 0xad, 0xea, 0x8c, 0xea, 0x40, 0xc3, 0x05, 0x97, - 0x01, 0x6a, 0x00, 0xef, 0x03, 0x63, 0x00, 0x65, 0xe5, 0xc0, 0x00, 0x80, - 0xbc, 0xa0, 0x00, 0xb0, 0xfa, 0x63, 0x0b, 0x62, 0x0a, 0xd1, 0x09, 0xd0, - 0x1b, 0xb2, 0x1c, 0xb1, 0x20, 0xf0, 0x67, 0xa1, 0xe0, 0xaa, 0x1b, 0xb4, - 0xff, 0xf7, 0x1f, 0x68, 0x0c, 0xef, 0x40, 0xa4, 0xc1, 0xa4, 0x1b, 0x23, - 0x05, 0xd2, 0x06, 0xd3, 0x04, 0xd6, 0x17, 0xb4, 0x40, 0xec, 0x07, 0xd7, - 0x16, 0xb4, 0xa0, 0xac, 0x01, 0x6c, 0x0c, 0xed, 0x8d, 0xed, 0x15, 0xb4, - 0x80, 0x9c, 0x0c, 0xed, 0x0c, 0x65, 0x08, 0x67, 0x00, 0xf2, 0x1a, 0x6c, - 0x40, 0xe8, 0x00, 0x65, 0x00, 0x6c, 0x20, 0xf0, 0x87, 0xc1, 0x07, 0x97, - 0x04, 0x96, 0x06, 0x93, 0x05, 0x92, 0x64, 0x33, 0x54, 0x32, 0x6d, 0xea, - 0xf6, 0x37, 0x01, 0x6b, 0xd8, 0x36, 0x6c, 0xef, 0xcd, 0xea, 0xec, 0x37, - 0xed, 0xea, 0x0b, 0x97, 0x0a, 0x91, 0x09, 0x90, 0x00, 0xef, 0x06, 0x63, - 0xa6, 0x01, 0x00, 0xb6, 0x44, 0x0d, 0x12, 0x80, 0x3c, 0x3c, 0x12, 0x80, + 0x00, 0xef, 0x03, 0x63, 0x61, 0x94, 0x00, 0x80, 0xfb, 0x63, 0x09, 0x62, + 0x08, 0xd1, 0x07, 0xd0, 0x18, 0xb3, 0x19, 0xb2, 0x43, 0xeb, 0x26, 0x61, + 0x18, 0xb2, 0x80, 0x9a, 0x18, 0xb3, 0x8e, 0xeb, 0x21, 0x2b, 0x02, 0xaa, + 0x17, 0xb5, 0x1d, 0x10, 0x42, 0x45, 0x17, 0xb4, 0x43, 0xec, 0x1a, 0x61, + 0xc0, 0xa2, 0xff, 0xf7, 0x1f, 0x6f, 0x43, 0x46, 0x43, 0xe8, 0x14, 0x61, + 0x45, 0xe5, 0x23, 0xec, 0x11, 0x61, 0x81, 0xa5, 0x60, 0xa5, 0x80, 0x34, + 0x6d, 0xec, 0xec, 0xec, 0xe0, 0xf1, 0x04, 0x5c, 0x09, 0x60, 0x43, 0xe0, + 0x0d, 0xb2, 0x91, 0xe2, 0x03, 0x4d, 0x0d, 0xb2, 0x40, 0xea, 0xec, 0xe8, + 0xb1, 0x67, 0xe2, 0x28, 0x09, 0x97, 0x08, 0x91, 0x07, 0x90, 0x00, 0xef, + 0x05, 0x63, 0x00, 0x65, 0xf0, 0xbf, 0x10, 0x80, 0xb8, 0x3d, 0x10, 0x80, + 0xbc, 0x3d, 0x10, 0x80, 0x55, 0xab, 0x23, 0x87, 0xc2, 0x3d, 0x10, 0x80, + 0xff, 0xbf, 0x10, 0x80, 0x38, 0x01, 0x12, 0x80, 0x19, 0xc3, 0x00, 0x80, + 0xfd, 0x63, 0x05, 0x62, 0x0e, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x0e, 0xb3, + 0xff, 0xf7, 0x1f, 0x6c, 0x02, 0xf0, 0x00, 0x6d, 0x40, 0xab, 0xab, 0xed, + 0x8c, 0xea, 0xad, 0xea, 0x3f, 0x4d, 0xac, 0xea, 0x02, 0xf1, 0x01, 0x4d, + 0xad, 0xea, 0x9f, 0xf6, 0x00, 0x4d, 0xac, 0xea, 0x05, 0x6d, 0xad, 0xea, + 0x8c, 0xea, 0x40, 0xcb, 0x05, 0x97, 0x00, 0xef, 0x03, 0x63, 0x00, 0x65, + 0x39, 0x72, 0x01, 0x80, 0x28, 0x12, 0x00, 0xb6, 0xfd, 0x63, 0x05, 0x62, + 0x15, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x15, 0xb2, 0x20, 0xf0, 0x8a, 0xa2, + 0x01, 0x6b, 0x8d, 0xeb, 0xa0, 0xf1, 0x95, 0xa2, 0x20, 0xf0, 0x6a, 0xc2, + 0x07, 0x6b, 0x6b, 0xeb, 0x8c, 0xeb, 0xa0, 0xf1, 0x75, 0xc2, 0x00, 0x6a, + 0x50, 0x35, 0x0d, 0xb3, 0xb5, 0xe3, 0x00, 0xf4, 0x00, 0x6c, 0xc0, 0xf1, + 0x8e, 0xcd, 0x01, 0x4a, 0xff, 0x6d, 0xac, 0xea, 0x0b, 0x5a, 0xf4, 0x61, + 0x00, 0xf1, 0x00, 0x6a, 0x60, 0xf2, 0x5e, 0xcb, 0x00, 0x6a, 0x80, 0xf2, + 0x8e, 0xcb, 0x80, 0xf2, 0x5e, 0xcb, 0x05, 0x97, 0x00, 0xef, 0x03, 0x63, + 0xc9, 0x76, 0x01, 0x80, 0x10, 0x23, 0x12, 0x80, 0xfd, 0x63, 0x05, 0x62, + 0x0d, 0xb2, 0x0e, 0xb3, 0x72, 0xda, 0x0e, 0xb3, 0x6c, 0xda, 0x0e, 0xb2, + 0x40, 0xea, 0x00, 0x65, 0x0d, 0xb2, 0xff, 0xf7, 0x1f, 0x6b, 0xff, 0x6c, + 0xa0, 0xaa, 0x08, 0xf0, 0x00, 0x6a, 0x7b, 0x4c, 0x6c, 0xed, 0x4d, 0xed, + 0x09, 0xb2, 0x40, 0x9a, 0x40, 0xea, 0x6c, 0xed, 0x05, 0x97, 0x00, 0x6a, + 0x00, 0xef, 0x03, 0x63, 0xa4, 0x19, 0x12, 0x80, 0xfd, 0x32, 0x10, 0x80, + 0x3d, 0x32, 0x10, 0x80, 0xcd, 0x36, 0x10, 0x80, 0x7a, 0x01, 0x00, 0xb6, + 0x10, 0x00, 0x12, 0x80, 0x15, 0xb3, 0x16, 0xb2, 0x60, 0xda, 0x16, 0xb3, + 0x16, 0xb2, 0x60, 0xda, 0x16, 0xb2, 0xa0, 0xf0, 0x6f, 0xa2, 0xa0, 0xf0, + 0x8e, 0xa2, 0x60, 0x33, 0x8d, 0xeb, 0xa0, 0xf0, 0x90, 0xa2, 0x80, 0x34, + 0x80, 0x34, 0x6d, 0xec, 0xa0, 0xf0, 0x71, 0xa2, 0x00, 0xf6, 0x60, 0x33, + 0x8d, 0xeb, 0x0f, 0xb4, 0x8d, 0xeb, 0x62, 0x34, 0xa0, 0xf0, 0x6e, 0xc2, + 0xa0, 0xf0, 0x8f, 0xc2, 0x00, 0xf6, 0x62, 0x33, 0x82, 0x34, 0xa0, 0xf0, + 0x71, 0xc2, 0xa0, 0xf0, 0x90, 0xc2, 0x09, 0xb3, 0x09, 0xb2, 0x20, 0xe8, + 0x60, 0xda, 0x00, 0x65, 0xdd, 0x38, 0x10, 0x80, 0x04, 0x07, 0x12, 0x80, + 0x09, 0x36, 0x10, 0x80, 0x00, 0x08, 0x12, 0x80, 0x38, 0x01, 0x12, 0x80, + 0x00, 0x00, 0x00, 0x80, 0x75, 0x38, 0x10, 0x80, 0x00, 0x07, 0x12, 0x80, + 0x20, 0xe8, 0x00, 0x65, 0x08, 0xb2, 0x40, 0x9a, 0x61, 0x42, 0x09, 0x23, + 0x03, 0x6b, 0x78, 0xea, 0x06, 0xb3, 0x12, 0xea, 0x01, 0x4a, 0x4c, 0x32, + 0x49, 0xe3, 0x05, 0xb3, 0x61, 0xda, 0x20, 0xe8, 0x00, 0x65, 0x00, 0x65, + 0xfc, 0x00, 0x12, 0x80, 0x6c, 0x1a, 0x12, 0x80, 0xe5, 0x37, 0x10, 0x80, + 0x08, 0xb2, 0x20, 0xf1, 0x6c, 0xa2, 0x61, 0xc4, 0x00, 0x6b, 0x60, 0xc4, + 0x40, 0xf0, 0xa4, 0xa2, 0x01, 0x6b, 0x6c, 0xed, 0xa2, 0xc4, 0xe0, 0xf0, + 0x5c, 0xa2, 0x4c, 0xeb, 0x20, 0xe8, 0x63, 0xc4, 0x10, 0x23, 0x12, 0x80, + 0x11, 0xb2, 0xa1, 0xa4, 0x20, 0xf0, 0x42, 0xa2, 0x00, 0x6b, 0xae, 0xea, + 0x01, 0x22, 0x01, 0x6b, 0x01, 0x6a, 0x6c, 0xea, 0x0d, 0xb3, 0xc2, 0xa4, + 0x60, 0xa3, 0x00, 0x6d, 0xce, 0xeb, 0x01, 0x23, 0x01, 0x6d, 0x01, 0x6b, + 0xac, 0xeb, 0x74, 0x33, 0x4d, 0xeb, 0x08, 0xb2, 0x83, 0xa4, 0x41, 0xa2, + 0x00, 0x6d, 0x8e, 0xea, 0x01, 0x22, 0x01, 0x6d, 0x01, 0x6a, 0xac, 0xea, + 0x40, 0x32, 0x4c, 0x32, 0x20, 0xe8, 0x6d, 0xea, 0x44, 0x0d, 0x12, 0x80, + 0x3c, 0x3c, 0x12, 0x80, 0x61, 0xa4, 0x05, 0xb2, 0x20, 0xf0, 0x62, 0xc2, + 0x62, 0xa4, 0x04, 0xb2, 0x60, 0xc2, 0x63, 0xa4, 0x20, 0xe8, 0x61, 0xc2, + 0x44, 0x0d, 0x12, 0x80, 0x3c, 0x3c, 0x12, 0x80, 0x20, 0xe8, 0x00, 0x6a, + 0x20, 0xe8, 0x00, 0x6a, 0x20, 0xe8, 0x00, 0x6a, 0x20, 0xe8, 0x7f, 0x6a, + 0x09, 0xb2, 0x20, 0xf0, 0x47, 0xa2, 0x03, 0x22, 0xe9, 0xf7, 0x1a, 0x6b, + 0x01, 0x10, 0x60, 0xac, 0x05, 0xb4, 0x4b, 0x9c, 0x02, 0x6e, 0xcb, 0xee, + 0xcc, 0xea, 0x4b, 0xdc, 0x60, 0xcd, 0x20, 0xe8, 0x00, 0x6a, 0x00, 0x65, + 0x44, 0x0d, 0x12, 0x80, 0xfd, 0x63, 0x05, 0x62, 0x03, 0xb2, 0x40, 0xea, + 0x00, 0x65, 0x05, 0x97, 0x00, 0xef, 0x03, 0x63, 0x59, 0x17, 0x01, 0x80, + 0xfd, 0x63, 0x05, 0x62, 0x60, 0x9c, 0x10, 0xf0, 0x00, 0x6a, 0x6c, 0xea, + 0x0c, 0x22, 0x09, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x08, 0xb3, 0xff, 0x6c, + 0x80, 0x6d, 0x40, 0xa3, 0xab, 0xed, 0x8c, 0xea, 0xad, 0xea, 0x8c, 0xea, + 0x40, 0xc3, 0x05, 0x97, 0x01, 0x6a, 0x00, 0xef, 0x03, 0x63, 0x00, 0x65, + 0xe5, 0xc0, 0x00, 0x80, 0xbc, 0xa0, 0x00, 0xb0, 0xfa, 0x63, 0x0b, 0x62, + 0x0a, 0xd1, 0x09, 0xd0, 0x1b, 0xb2, 0x1c, 0xb1, 0x20, 0xf0, 0x67, 0xa1, + 0xe0, 0xaa, 0x1b, 0xb4, 0xff, 0xf7, 0x1f, 0x68, 0x0c, 0xef, 0x40, 0xa4, + 0xc1, 0xa4, 0x1b, 0x23, 0x05, 0xd2, 0x06, 0xd3, 0x04, 0xd6, 0x17, 0xb4, + 0x40, 0xec, 0x07, 0xd7, 0x16, 0xb4, 0xa0, 0xac, 0x01, 0x6c, 0x0c, 0xed, + 0x8d, 0xed, 0x15, 0xb4, 0x80, 0x9c, 0x0c, 0xed, 0x0c, 0x65, 0x08, 0x67, + 0x00, 0xf2, 0x1a, 0x6c, 0x40, 0xe8, 0x00, 0x65, 0x00, 0x6c, 0x20, 0xf0, + 0x87, 0xc1, 0x07, 0x97, 0x04, 0x96, 0x06, 0x93, 0x05, 0x92, 0x64, 0x33, + 0x54, 0x32, 0x6d, 0xea, 0xf6, 0x37, 0x01, 0x6b, 0xd8, 0x36, 0x6c, 0xef, + 0xcd, 0xea, 0xec, 0x37, 0xed, 0xea, 0x0b, 0x97, 0x0a, 0x91, 0x09, 0x90, + 0x00, 0xef, 0x06, 0x63, 0xa6, 0x01, 0x00, 0xb6, 0x44, 0x0d, 0x12, 0x80, + 0x3c, 0x3c, 0x12, 0x80, 0xe5, 0xc0, 0x00, 0x80, 0x1a, 0x02, 0x00, 0xb6, + 0x10, 0x00, 0x12, 0x80, 0xfd, 0x63, 0x05, 0x62, 0x0b, 0xb3, 0x0c, 0xb2, + 0x7b, 0xda, 0x0c, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x0b, 0xb2, 0xff, 0xf7, + 0x1f, 0x6b, 0x00, 0xf2, 0x1a, 0x6c, 0xa0, 0xaa, 0x01, 0x6a, 0x6c, 0xed, + 0x4d, 0xed, 0x08, 0xb2, 0x40, 0x9a, 0x40, 0xea, 0x6c, 0xed, 0x05, 0x97, + 0x00, 0xef, 0x03, 0x63, 0xf5, 0x35, 0x10, 0x80, 0xa4, 0x19, 0x12, 0x80, 0xe5, 0xc0, 0x00, 0x80, 0x1a, 0x02, 0x00, 0xb6, 0x10, 0x00, 0x12, 0x80, - 0xfd, 0x63, 0x05, 0x62, 0x0b, 0xb3, 0x0c, 0xb2, 0x7b, 0xda, 0x0c, 0xb2, - 0x40, 0xea, 0x00, 0x65, 0x0b, 0xb2, 0xff, 0xf7, 0x1f, 0x6b, 0x00, 0xf2, - 0x1a, 0x6c, 0xa0, 0xaa, 0x01, 0x6a, 0x6c, 0xed, 0x4d, 0xed, 0x08, 0xb2, - 0x40, 0x9a, 0x40, 0xea, 0x6c, 0xed, 0x05, 0x97, 0x00, 0xef, 0x03, 0x63, - 0x51, 0x36, 0x10, 0x80, 0xa4, 0x19, 0x12, 0x80, 0xe5, 0xc0, 0x00, 0x80, - 0x1a, 0x02, 0x00, 0xb6, 0x10, 0x00, 0x12, 0x80, 0xfd, 0x63, 0x05, 0x62, - 0x04, 0xd0, 0x09, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x08, 0xb3, 0x20, 0xf0, - 0x02, 0xa3, 0x82, 0x67, 0x07, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x0b, 0xea, - 0x05, 0x97, 0x04, 0x90, 0xc0, 0xf7, 0x42, 0x32, 0x00, 0xef, 0x03, 0x63, - 0xe0, 0x2b, 0x00, 0x80, 0x44, 0x0d, 0x12, 0x80, 0xfc, 0x2b, 0x00, 0x80, - 0xf8, 0x63, 0x0f, 0x62, 0x0e, 0xd1, 0x0d, 0xd0, 0xff, 0x69, 0x8c, 0xe9, - 0x5d, 0x67, 0x9d, 0x67, 0x38, 0xc2, 0x06, 0x6a, 0x59, 0xc4, 0x00, 0x6a, - 0x5a, 0xc4, 0x5b, 0xc4, 0x5c, 0xc4, 0x5d, 0xc4, 0x5e, 0xc4, 0x5f, 0xc4, - 0x00, 0x68, 0x1c, 0xb3, 0x08, 0x32, 0x49, 0xe3, 0x40, 0x9a, 0x40, 0xea, - 0x00, 0x65, 0x9d, 0x67, 0x0d, 0xe4, 0x5a, 0xc3, 0x01, 0x48, 0xff, 0x6a, - 0x4c, 0xe8, 0x06, 0x58, 0xf2, 0x61, 0xba, 0xa4, 0x02, 0x6a, 0x54, 0xcc, - 0x5b, 0xa4, 0xa0, 0x35, 0xa0, 0x35, 0x00, 0xf6, 0x40, 0x32, 0x4d, 0xed, - 0x00, 0xf6, 0x00, 0x6a, 0x4d, 0xed, 0x2d, 0xed, 0x08, 0xd5, 0x5e, 0xa4, - 0xdd, 0xa4, 0x0a, 0x97, 0x40, 0x32, 0x40, 0x32, 0xc0, 0x36, 0x4d, 0xee, - 0x5c, 0xa4, 0x4d, 0xee, 0x5f, 0xa4, 0x00, 0xf6, 0x40, 0x32, 0x4d, 0xee, - 0x09, 0xd6, 0x08, 0xb2, 0x80, 0x9a, 0x0b, 0x92, 0x04, 0xd2, 0x07, 0xb2, - 0x40, 0xea, 0x00, 0x65, 0x0f, 0x97, 0x0e, 0x91, 0x0d, 0x90, 0x00, 0xef, - 0x08, 0x63, 0x00, 0x65, 0x4c, 0x3d, 0x10, 0x80, 0x38, 0x1d, 0x12, 0x80, - 0x2d, 0xdb, 0x00, 0x80, 0xfd, 0x63, 0x05, 0x62, 0x1e, 0xb2, 0x60, 0xaa, - 0x28, 0x73, 0x01, 0x4b, 0x01, 0x61, 0x01, 0x6b, 0x60, 0xca, 0x1c, 0xb2, - 0x40, 0xf0, 0xc4, 0xa2, 0xe0, 0xf0, 0x9c, 0xa2, 0x01, 0x6b, 0x6c, 0xee, - 0x6c, 0xec, 0x19, 0xb3, 0x20, 0xf1, 0xec, 0xa2, 0x20, 0xf0, 0x62, 0xa3, - 0x00, 0x6a, 0xee, 0xeb, 0x01, 0x23, 0x01, 0x6a, 0x01, 0x6b, 0x4c, 0xeb, - 0x14, 0xb2, 0x40, 0xa2, 0x00, 0x6d, 0xce, 0xea, 0x01, 0x22, 0x01, 0x6d, - 0x01, 0x6a, 0xac, 0xea, 0x10, 0xb5, 0xa1, 0xa5, 0x54, 0x32, 0x6d, 0xea, - 0x8e, 0xed, 0x00, 0x6b, 0x01, 0x25, 0x01, 0x6b, 0x01, 0x6d, 0x6c, 0xed, - 0xa0, 0x35, 0xac, 0x35, 0x4d, 0xed, 0x09, 0xb2, 0x20, 0xf0, 0xe2, 0xc2, - 0x08, 0xb2, 0xc0, 0xc2, 0x81, 0xc2, 0x03, 0x25, 0x07, 0xb2, 0x40, 0xea, - 0x27, 0x6c, 0x05, 0x97, 0x00, 0xef, 0x03, 0x63, 0x40, 0x3c, 0x12, 0x80, - 0x10, 0x23, 0x12, 0x80, 0x44, 0x0d, 0x12, 0x80, 0x3c, 0x3c, 0x12, 0x80, - 0xa1, 0x37, 0x10, 0x80, 0xfb, 0x63, 0x09, 0x62, 0x08, 0xd0, 0x16, 0xb0, - 0x40, 0x98, 0xa0, 0xf1, 0x06, 0x6c, 0x20, 0xf2, 0x00, 0x6d, 0x40, 0xea, - 0x00, 0x65, 0x40, 0x98, 0xa0, 0xf1, 0x12, 0x6c, 0x40, 0xea, 0xff, 0x6d, - 0x40, 0x98, 0xfa, 0x6c, 0x40, 0xea, 0x32, 0x6d, 0x40, 0x98, 0xf4, 0x6c, - 0x40, 0xea, 0x01, 0x6d, 0x40, 0x98, 0xa0, 0xf1, 0x0a, 0x6c, 0x40, 0xea, - 0x03, 0x6d, 0x00, 0x6a, 0x09, 0xb3, 0x04, 0xd2, 0x06, 0xd2, 0x05, 0xd3, - 0x05, 0x6c, 0x20, 0xf3, 0x1e, 0x6e, 0x81, 0xf1, 0x12, 0x6f, 0x06, 0xb2, - 0x40, 0xea, 0xfe, 0x6d, 0x09, 0x97, 0x08, 0x90, 0x00, 0xef, 0x05, 0x63, - 0x10, 0x00, 0x12, 0x80, 0x3c, 0x3d, 0x10, 0x80, 0xd1, 0x27, 0x01, 0x80, - 0xfb, 0x63, 0x09, 0x62, 0x08, 0xd0, 0x21, 0xb2, 0x40, 0xea, 0x00, 0x65, - 0x20, 0xb2, 0xa0, 0xf0, 0x83, 0xa2, 0xa0, 0xf0, 0x62, 0xa2, 0x80, 0x34, - 0x6d, 0xec, 0xa0, 0xf0, 0x64, 0xa2, 0xa0, 0xf0, 0x45, 0xa2, 0x60, 0x33, - 0x60, 0x33, 0x8d, 0xeb, 0x00, 0xf6, 0x40, 0x32, 0x6d, 0xea, 0x19, 0xb3, - 0x6c, 0xea, 0x26, 0x22, 0x18, 0xb4, 0x40, 0x9c, 0x01, 0x4a, 0x03, 0x22, - 0x17, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x00, 0x6a, 0xe2, 0x67, 0x16, 0xb6, - 0x04, 0xd2, 0x13, 0xb5, 0x15, 0xb2, 0x40, 0xea, 0x01, 0x6c, 0x11, 0xb0, - 0x14, 0xb2, 0xa4, 0x9a, 0x14, 0xb2, 0x40, 0xea, 0x80, 0x98, 0x01, 0x6a, - 0x04, 0xd2, 0x13, 0xb2, 0x05, 0xd2, 0x40, 0x98, 0x02, 0x6c, 0x06, 0xd2, - 0xe0, 0xf1, 0x0d, 0x6e, 0xe5, 0xf6, 0x05, 0x6f, 0x0f, 0xb2, 0x40, 0xea, - 0xfe, 0x6d, 0x0f, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x09, 0x97, 0x08, 0x90, - 0x00, 0xef, 0x05, 0x63, 0xe5, 0xc1, 0x00, 0x80, 0x38, 0x01, 0x12, 0x80, - 0x00, 0x00, 0x00, 0x40, 0xfc, 0x00, 0x12, 0x80, 0x1d, 0xdd, 0x00, 0x80, - 0x41, 0x38, 0x10, 0x80, 0x71, 0xdd, 0x00, 0x80, 0x44, 0x0d, 0x12, 0x80, - 0xc1, 0xdc, 0x00, 0x80, 0x3c, 0x3d, 0x10, 0x80, 0xd1, 0x27, 0x01, 0x80, - 0x71, 0xc1, 0x00, 0x80, 0x04, 0xb3, 0x05, 0xb2, 0x60, 0xda, 0x05, 0xb3, - 0x05, 0xb2, 0x20, 0xe8, 0x60, 0xda, 0x00, 0x65, 0x75, 0x3a, 0x10, 0x80, - 0x78, 0x00, 0x12, 0x80, 0x31, 0x3a, 0x10, 0x80, 0xc8, 0x00, 0x12, 0x80, - 0xfd, 0x63, 0x05, 0x62, 0x05, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x01, 0x6b, - 0x04, 0xb2, 0x60, 0xc2, 0x05, 0x97, 0x00, 0xef, 0x03, 0x63, 0x00, 0x65, - 0xad, 0x98, 0x00, 0x80, 0x00, 0x3c, 0x12, 0x80, 0xfd, 0x63, 0x05, 0x62, - 0x00, 0xf6, 0x80, 0x34, 0x00, 0xf6, 0x83, 0x34, 0x0a, 0xb2, 0x40, 0xea, - 0x00, 0x65, 0x0a, 0xb2, 0x67, 0xa2, 0x86, 0xa2, 0x60, 0x33, 0x8d, 0xeb, - 0x08, 0xb4, 0x60, 0xcc, 0x65, 0xa2, 0x44, 0xa2, 0x60, 0x33, 0x4d, 0xeb, - 0x06, 0xb2, 0x60, 0xca, 0x05, 0x97, 0x00, 0xef, 0x03, 0x63, 0x00, 0x65, - 0x9d, 0x9d, 0x00, 0x80, 0xac, 0x0c, 0x12, 0x80, 0xea, 0x10, 0x00, 0xb6, - 0xf0, 0x10, 0x00, 0xb6, 0xfd, 0x63, 0x05, 0x62, 0x08, 0xb2, 0x40, 0xea, - 0x00, 0x65, 0x08, 0xb2, 0x08, 0xb3, 0x66, 0xda, 0x18, 0x6b, 0x6e, 0xca, - 0x07, 0xb3, 0x60, 0xda, 0x4a, 0x6b, 0x62, 0xca, 0x05, 0x97, 0x00, 0xef, - 0x03, 0x63, 0x00, 0x65, 0x01, 0xa0, 0x00, 0x80, 0xc8, 0x0c, 0x12, 0x80, - 0x64, 0x3d, 0x10, 0x80, 0x94, 0x3d, 0x10, 0x80, 0xfd, 0x63, 0x05, 0x62, - 0xff, 0x6a, 0x8c, 0xea, 0x02, 0x5a, 0x10, 0x60, 0x0c, 0xb3, 0x60, 0xa3, - 0x01, 0x73, 0x04, 0x61, 0x0b, 0xb3, 0x20, 0xf1, 0x72, 0xa3, 0x02, 0x10, - 0x0a, 0xb3, 0x60, 0xa3, 0x09, 0x73, 0x04, 0x60, 0x09, 0xb4, 0x6d, 0xe4, - 0x01, 0x6c, 0x80, 0xc3, 0x82, 0x67, 0x08, 0xb2, 0x40, 0xea, 0x00, 0x65, - 0x05, 0x97, 0x00, 0xef, 0x03, 0x63, 0x00, 0x65, 0x20, 0x05, 0x12, 0x80, - 0x10, 0x23, 0x12, 0x80, 0x21, 0x05, 0x12, 0x80, 0x44, 0x3c, 0x12, 0x80, - 0x49, 0x0c, 0x00, 0x80, 0xf9, 0x63, 0x0d, 0x62, 0x0c, 0xd1, 0x0b, 0xd0, - 0xff, 0x6b, 0x8c, 0xeb, 0x55, 0xb2, 0x69, 0xe2, 0x40, 0xa2, 0xa0, 0xf0, - 0x00, 0x22, 0x47, 0x43, 0x4b, 0x4a, 0x53, 0xb1, 0x48, 0x32, 0x49, 0xe1, - 0x00, 0x9a, 0x52, 0xb2, 0x40, 0x9a, 0x40, 0xea, 0x08, 0xd3, 0x46, 0x32, - 0x08, 0x93, 0x05, 0xd2, 0x4f, 0xb2, 0x40, 0x9a, 0x40, 0xea, 0x83, 0x67, - 0x01, 0x6a, 0x00, 0x6c, 0x4b, 0xea, 0x40, 0xf1, 0x24, 0x99, 0xe4, 0x67, - 0x04, 0xd2, 0x08, 0x93, 0x39, 0x10, 0xa3, 0xa1, 0x05, 0x6a, 0xac, 0xea, - 0x01, 0x72, 0x32, 0x61, 0xb1, 0xa9, 0x51, 0xa8, 0xae, 0xea, 0x2e, 0x2a, - 0x45, 0xb2, 0x05, 0x94, 0x45, 0xb6, 0x4c, 0xec, 0x05, 0xd4, 0x40, 0xa1, - 0x44, 0xb4, 0xe9, 0x4a, 0x00, 0xf6, 0x40, 0x32, 0x00, 0xf6, 0x43, 0x32, - 0x44, 0x32, 0x91, 0xe2, 0xc9, 0xe2, 0xa0, 0xac, 0x40, 0xaa, 0xff, 0xf7, - 0x1f, 0x6c, 0x08, 0xd3, 0x4c, 0xec, 0x82, 0x34, 0x0f, 0x6a, 0x8a, 0x34, - 0x4c, 0xec, 0xe7, 0xf7, 0x10, 0x4a, 0xac, 0xea, 0x80, 0x34, 0x05, 0x95, - 0x98, 0x34, 0x4d, 0xec, 0x07, 0xd7, 0x38, 0xb2, 0x40, 0xea, 0x0a, 0x6e, - 0x04, 0x94, 0x08, 0x93, 0x07, 0x97, 0x83, 0xea, 0x01, 0x60, 0x04, 0xd2, - 0x43, 0xef, 0x01, 0x6c, 0x01, 0x60, 0xe2, 0x67, 0x00, 0xf1, 0x14, 0x49, - 0x31, 0xb2, 0xa0, 0x9a, 0x31, 0xb2, 0x40, 0x9a, 0x49, 0xe5, 0xff, 0x6d, - 0x15, 0x4d, 0xb8, 0xea, 0x26, 0xb5, 0x40, 0xf1, 0xa4, 0x9d, 0x12, 0xea, - 0x49, 0xe5, 0x43, 0xe9, 0xb8, 0x61, 0x04, 0x27, 0x51, 0xa8, 0x44, 0x32, - 0xeb, 0xe2, 0x06, 0xd2, 0x38, 0x24, 0x06, 0x92, 0x04, 0x94, 0x43, 0xec, - 0x01, 0x60, 0x44, 0x67, 0x04, 0x5a, 0x31, 0x60, 0x1b, 0xb2, 0x6d, 0xe2, - 0x00, 0x6a, 0x40, 0xc3, 0x51, 0xa8, 0x80, 0xf0, 0x4c, 0xc8, 0x80, 0xf0, - 0x4e, 0xc8, 0x80, 0xf0, 0x50, 0xc8, 0x53, 0xa8, 0x80, 0xf0, 0x52, 0xc8, - 0x55, 0xa8, 0x80, 0xf0, 0x54, 0xc8, 0x52, 0xa8, 0x80, 0xf0, 0x56, 0xc8, - 0x80, 0xf0, 0x58, 0xc8, 0x80, 0xf0, 0x5a, 0xc8, 0x51, 0xa8, 0x46, 0x33, - 0xff, 0x4a, 0x04, 0x4b, 0x09, 0x52, 0x80, 0xf0, 0x7e, 0xc8, 0x01, 0x61, - 0x08, 0x6a, 0xa0, 0xf0, 0x40, 0xc0, 0x5d, 0x98, 0x02, 0x2a, 0x5c, 0x98, - 0x07, 0x22, 0x80, 0xf0, 0x67, 0xa0, 0x01, 0x6a, 0x6d, 0xea, 0x80, 0xf0, - 0x47, 0xc0, 0x03, 0x10, 0x0e, 0xb2, 0x40, 0xea, 0x90, 0x67, 0x0d, 0x97, - 0x0c, 0x91, 0x0b, 0x90, 0x00, 0xef, 0x07, 0x63, 0x44, 0x3c, 0x12, 0x80, - 0x10, 0x23, 0x12, 0x80, 0x14, 0x00, 0x12, 0x80, 0xfc, 0x04, 0x12, 0x80, + 0xfd, 0x63, 0x05, 0x62, 0x04, 0xd0, 0x09, 0xb2, 0x40, 0xea, 0x00, 0x65, + 0x08, 0xb3, 0x20, 0xf0, 0x02, 0xa3, 0x82, 0x67, 0x07, 0xb2, 0x40, 0xea, + 0x00, 0x65, 0x0b, 0xea, 0x05, 0x97, 0x04, 0x90, 0xc0, 0xf7, 0x42, 0x32, + 0x00, 0xef, 0x03, 0x63, 0xe0, 0x2b, 0x00, 0x80, 0x44, 0x0d, 0x12, 0x80, + 0xfc, 0x2b, 0x00, 0x80, 0xf8, 0x63, 0x0f, 0x62, 0x0e, 0xd1, 0x0d, 0xd0, + 0xff, 0x69, 0x8c, 0xe9, 0x5d, 0x67, 0x9d, 0x67, 0x38, 0xc2, 0x06, 0x6a, + 0x59, 0xc4, 0x00, 0x6a, 0x5a, 0xc4, 0x5b, 0xc4, 0x5c, 0xc4, 0x5d, 0xc4, + 0x5e, 0xc4, 0x5f, 0xc4, 0x00, 0x68, 0x1c, 0xb3, 0x08, 0x32, 0x49, 0xe3, + 0x40, 0x9a, 0x40, 0xea, 0x00, 0x65, 0x9d, 0x67, 0x0d, 0xe4, 0x5a, 0xc3, + 0x01, 0x48, 0xff, 0x6a, 0x4c, 0xe8, 0x06, 0x58, 0xf2, 0x61, 0xba, 0xa4, + 0x02, 0x6a, 0x54, 0xcc, 0x5b, 0xa4, 0xa0, 0x35, 0xa0, 0x35, 0x00, 0xf6, + 0x40, 0x32, 0x4d, 0xed, 0x00, 0xf6, 0x00, 0x6a, 0x4d, 0xed, 0x2d, 0xed, + 0x08, 0xd5, 0x5e, 0xa4, 0xdd, 0xa4, 0x0a, 0x97, 0x40, 0x32, 0x40, 0x32, + 0xc0, 0x36, 0x4d, 0xee, 0x5c, 0xa4, 0x4d, 0xee, 0x5f, 0xa4, 0x00, 0xf6, + 0x40, 0x32, 0x4d, 0xee, 0x09, 0xd6, 0x08, 0xb2, 0x80, 0x9a, 0x0b, 0x92, + 0x04, 0xd2, 0x07, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x0f, 0x97, 0x0e, 0x91, + 0x0d, 0x90, 0x00, 0xef, 0x08, 0x63, 0x00, 0x65, 0xd4, 0x3c, 0x10, 0x80, + 0x38, 0x1d, 0x12, 0x80, 0x2d, 0xdb, 0x00, 0x80, 0xfd, 0x63, 0x05, 0x62, + 0x1e, 0xb2, 0x60, 0xaa, 0x28, 0x73, 0x01, 0x4b, 0x01, 0x61, 0x01, 0x6b, + 0x60, 0xca, 0x1c, 0xb2, 0x40, 0xf0, 0xc4, 0xa2, 0xe0, 0xf0, 0x9c, 0xa2, + 0x01, 0x6b, 0x6c, 0xee, 0x6c, 0xec, 0x19, 0xb3, 0x20, 0xf1, 0xec, 0xa2, + 0x20, 0xf0, 0x62, 0xa3, 0x00, 0x6a, 0xee, 0xeb, 0x01, 0x23, 0x01, 0x6a, + 0x01, 0x6b, 0x4c, 0xeb, 0x14, 0xb2, 0x40, 0xa2, 0x00, 0x6d, 0xce, 0xea, + 0x01, 0x22, 0x01, 0x6d, 0x01, 0x6a, 0xac, 0xea, 0x10, 0xb5, 0xa1, 0xa5, + 0x54, 0x32, 0x6d, 0xea, 0x8e, 0xed, 0x00, 0x6b, 0x01, 0x25, 0x01, 0x6b, + 0x01, 0x6d, 0x6c, 0xed, 0xa0, 0x35, 0xac, 0x35, 0x4d, 0xed, 0x09, 0xb2, + 0x20, 0xf0, 0xe2, 0xc2, 0x08, 0xb2, 0xc0, 0xc2, 0x81, 0xc2, 0x03, 0x25, + 0x07, 0xb2, 0x40, 0xea, 0x27, 0x6c, 0x05, 0x97, 0x00, 0xef, 0x03, 0x63, + 0x40, 0x3c, 0x12, 0x80, 0x10, 0x23, 0x12, 0x80, 0x44, 0x0d, 0x12, 0x80, + 0x3c, 0x3c, 0x12, 0x80, 0x45, 0x37, 0x10, 0x80, 0xfb, 0x63, 0x09, 0x62, + 0x08, 0xd0, 0x16, 0xb0, 0x40, 0x98, 0xa0, 0xf1, 0x06, 0x6c, 0x20, 0xf2, + 0x00, 0x6d, 0x40, 0xea, 0x00, 0x65, 0x40, 0x98, 0xa0, 0xf1, 0x12, 0x6c, + 0x40, 0xea, 0xff, 0x6d, 0x40, 0x98, 0xfa, 0x6c, 0x40, 0xea, 0x32, 0x6d, + 0x40, 0x98, 0xf4, 0x6c, 0x40, 0xea, 0x01, 0x6d, 0x40, 0x98, 0xa0, 0xf1, + 0x0a, 0x6c, 0x40, 0xea, 0x03, 0x6d, 0x00, 0x6a, 0x09, 0xb3, 0x04, 0xd2, + 0x06, 0xd2, 0x05, 0xd3, 0x05, 0x6c, 0x20, 0xf3, 0x1e, 0x6e, 0x81, 0xf1, + 0x12, 0x6f, 0x06, 0xb2, 0x40, 0xea, 0xfe, 0x6d, 0x09, 0x97, 0x08, 0x90, + 0x00, 0xef, 0x05, 0x63, 0x10, 0x00, 0x12, 0x80, 0xd0, 0x3c, 0x10, 0x80, + 0xd1, 0x27, 0x01, 0x80, 0xfb, 0x63, 0x09, 0x62, 0x08, 0xd0, 0x21, 0xb2, + 0x40, 0xea, 0x00, 0x65, 0x20, 0xb2, 0xa0, 0xf0, 0x83, 0xa2, 0xa0, 0xf0, + 0x62, 0xa2, 0x80, 0x34, 0x6d, 0xec, 0xa0, 0xf0, 0x64, 0xa2, 0xa0, 0xf0, + 0x45, 0xa2, 0x60, 0x33, 0x60, 0x33, 0x8d, 0xeb, 0x00, 0xf6, 0x40, 0x32, + 0x6d, 0xea, 0x19, 0xb3, 0x6c, 0xea, 0x26, 0x22, 0x18, 0xb4, 0x40, 0x9c, + 0x01, 0x4a, 0x03, 0x22, 0x17, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x00, 0x6a, + 0xe2, 0x67, 0x16, 0xb6, 0x04, 0xd2, 0x13, 0xb5, 0x15, 0xb2, 0x40, 0xea, + 0x01, 0x6c, 0x11, 0xb0, 0x14, 0xb2, 0xa4, 0x9a, 0x14, 0xb2, 0x40, 0xea, + 0x80, 0x98, 0x01, 0x6a, 0x04, 0xd2, 0x13, 0xb2, 0x05, 0xd2, 0x40, 0x98, + 0x02, 0x6c, 0x06, 0xd2, 0xe0, 0xf1, 0x0d, 0x6e, 0xe5, 0xf6, 0x05, 0x6f, + 0x0f, 0xb2, 0x40, 0xea, 0xfe, 0x6d, 0x0f, 0xb2, 0x40, 0xea, 0x00, 0x65, + 0x09, 0x97, 0x08, 0x90, 0x00, 0xef, 0x05, 0x63, 0xe5, 0xc1, 0x00, 0x80, + 0x38, 0x01, 0x12, 0x80, 0x00, 0x00, 0x00, 0x40, 0xfc, 0x00, 0x12, 0x80, + 0x1d, 0xdd, 0x00, 0x80, 0xe5, 0x37, 0x10, 0x80, 0x71, 0xdd, 0x00, 0x80, + 0x44, 0x0d, 0x12, 0x80, 0xc1, 0xdc, 0x00, 0x80, 0xd0, 0x3c, 0x10, 0x80, + 0xd1, 0x27, 0x01, 0x80, 0x71, 0xc1, 0x00, 0x80, 0x04, 0xb3, 0x05, 0xb2, + 0x60, 0xda, 0x05, 0xb3, 0x05, 0xb2, 0x20, 0xe8, 0x60, 0xda, 0x00, 0x65, + 0x19, 0x3a, 0x10, 0x80, 0x78, 0x00, 0x12, 0x80, 0xd5, 0x39, 0x10, 0x80, + 0xc8, 0x00, 0x12, 0x80, 0xfd, 0x63, 0x05, 0x62, 0x05, 0xb2, 0x40, 0xea, + 0x00, 0x65, 0x01, 0x6b, 0x04, 0xb2, 0x60, 0xc2, 0x05, 0x97, 0x00, 0xef, + 0x03, 0x63, 0x00, 0x65, 0xad, 0x98, 0x00, 0x80, 0x00, 0x3c, 0x12, 0x80, + 0xfd, 0x63, 0x05, 0x62, 0x00, 0xf6, 0x80, 0x34, 0x00, 0xf6, 0x83, 0x34, + 0x0a, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x0a, 0xb2, 0x67, 0xa2, 0x86, 0xa2, + 0x60, 0x33, 0x8d, 0xeb, 0x08, 0xb4, 0x60, 0xcc, 0x65, 0xa2, 0x44, 0xa2, + 0x60, 0x33, 0x4d, 0xeb, 0x06, 0xb2, 0x60, 0xca, 0x05, 0x97, 0x00, 0xef, + 0x03, 0x63, 0x00, 0x65, 0x9d, 0x9d, 0x00, 0x80, 0xac, 0x0c, 0x12, 0x80, + 0xea, 0x10, 0x00, 0xb6, 0xf0, 0x10, 0x00, 0xb6, 0xfd, 0x63, 0x05, 0x62, + 0x08, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x08, 0xb2, 0x08, 0xb3, 0x66, 0xda, + 0x18, 0x6b, 0x6e, 0xca, 0x07, 0xb3, 0x60, 0xda, 0x4a, 0x6b, 0x62, 0xca, + 0x05, 0x97, 0x00, 0xef, 0x03, 0x63, 0x00, 0x65, 0x01, 0xa0, 0x00, 0x80, + 0xc8, 0x0c, 0x12, 0x80, 0xec, 0x3c, 0x10, 0x80, 0x1c, 0x3d, 0x10, 0x80, + 0xfd, 0x63, 0x05, 0x62, 0xff, 0x6a, 0x8c, 0xea, 0x02, 0x5a, 0x10, 0x60, + 0x0c, 0xb3, 0x60, 0xa3, 0x01, 0x73, 0x04, 0x61, 0x0b, 0xb3, 0x20, 0xf1, + 0x72, 0xa3, 0x02, 0x10, 0x0a, 0xb3, 0x60, 0xa3, 0x09, 0x73, 0x04, 0x60, + 0x09, 0xb4, 0x6d, 0xe4, 0x01, 0x6c, 0x80, 0xc3, 0x82, 0x67, 0x08, 0xb2, + 0x40, 0xea, 0x00, 0x65, 0x05, 0x97, 0x00, 0xef, 0x03, 0x63, 0x00, 0x65, + 0x20, 0x05, 0x12, 0x80, 0x10, 0x23, 0x12, 0x80, 0x21, 0x05, 0x12, 0x80, + 0x44, 0x3c, 0x12, 0x80, 0x49, 0x0c, 0x00, 0x80, 0xfa, 0x63, 0x0b, 0x62, + 0x0a, 0xd1, 0x09, 0xd0, 0xff, 0x6f, 0x8c, 0xef, 0x52, 0xb2, 0xe9, 0xe2, + 0x40, 0xa2, 0x80, 0xf0, 0x1a, 0x22, 0x47, 0x47, 0x4b, 0x4a, 0x50, 0xb1, + 0x48, 0x32, 0x49, 0xe1, 0x00, 0x9a, 0x4f, 0xb2, 0x40, 0x9a, 0x40, 0xea, + 0x07, 0xd7, 0x46, 0x32, 0x00, 0x6c, 0x01, 0x6b, 0x05, 0xd2, 0x40, 0xf1, + 0x24, 0x99, 0x04, 0xd4, 0x6b, 0xeb, 0x07, 0x97, 0x39, 0x10, 0xa3, 0xa1, + 0x05, 0x6a, 0xac, 0xea, 0x01, 0x72, 0x32, 0x61, 0xb1, 0xa9, 0x51, 0xa8, + 0xae, 0xea, 0x2e, 0x2a, 0x44, 0xb2, 0x05, 0x94, 0x44, 0xb6, 0x4c, 0xec, + 0x05, 0xd4, 0x40, 0xa1, 0x43, 0xb4, 0xe9, 0x4a, 0x00, 0xf6, 0x40, 0x32, + 0x00, 0xf6, 0x43, 0x32, 0x44, 0x32, 0x91, 0xe2, 0xc9, 0xe2, 0xa0, 0xac, + 0x40, 0xaa, 0xff, 0xf7, 0x1f, 0x6c, 0x06, 0xd3, 0x4c, 0xec, 0x82, 0x34, + 0x0f, 0x6a, 0x8a, 0x34, 0x4c, 0xec, 0xe7, 0xf7, 0x10, 0x4a, 0xac, 0xea, + 0x80, 0x34, 0x05, 0x95, 0x98, 0x34, 0x4d, 0xec, 0x07, 0xd7, 0x37, 0xb2, + 0x40, 0xea, 0x0a, 0x6e, 0x06, 0x93, 0x07, 0x97, 0x63, 0xea, 0x01, 0x60, + 0x62, 0x67, 0x04, 0x95, 0x01, 0x6c, 0x43, 0xed, 0x01, 0x60, 0x04, 0xd2, + 0x00, 0xf1, 0x14, 0x49, 0x30, 0xb2, 0xa0, 0x9a, 0x30, 0xb2, 0x40, 0x9a, + 0x49, 0xe5, 0xff, 0x6d, 0x15, 0x4d, 0xb8, 0xea, 0x26, 0xb5, 0x40, 0xf1, + 0xa4, 0x9d, 0x12, 0xea, 0x49, 0xe5, 0x43, 0xe9, 0xb8, 0x61, 0x04, 0x92, + 0x07, 0x22, 0x51, 0xa8, 0x04, 0x95, 0x44, 0x32, 0xab, 0xe2, 0x63, 0xea, + 0x01, 0x60, 0x62, 0x67, 0x01, 0x6a, 0x8e, 0xea, 0x32, 0x2a, 0x04, 0x5b, + 0x30, 0x60, 0x1b, 0xb3, 0xfd, 0xe3, 0x40, 0xc7, 0x51, 0xa8, 0x80, 0xf0, + 0x4c, 0xc8, 0x80, 0xf0, 0x4e, 0xc8, 0x80, 0xf0, 0x50, 0xc8, 0x53, 0xa8, + 0x80, 0xf0, 0x52, 0xc8, 0x55, 0xa8, 0x80, 0xf0, 0x54, 0xc8, 0x52, 0xa8, + 0x80, 0xf0, 0x56, 0xc8, 0x80, 0xf0, 0x58, 0xc8, 0x80, 0xf0, 0x5a, 0xc8, + 0x51, 0xa8, 0x46, 0x33, 0xff, 0x4a, 0x04, 0x4b, 0x09, 0x52, 0x80, 0xf0, + 0x7e, 0xc8, 0x01, 0x61, 0x08, 0x6a, 0xa0, 0xf0, 0x40, 0xc0, 0x5d, 0x98, + 0x02, 0x2a, 0x5c, 0x98, 0x07, 0x22, 0x80, 0xf0, 0x67, 0xa0, 0x01, 0x6a, + 0x6d, 0xea, 0x80, 0xf0, 0x47, 0xc0, 0x03, 0x10, 0x0d, 0xb2, 0x40, 0xea, + 0x90, 0x67, 0x0b, 0x97, 0x0a, 0x91, 0x09, 0x90, 0x00, 0xef, 0x06, 0x63, + 0x44, 0x3c, 0x12, 0x80, 0x10, 0x23, 0x12, 0x80, 0x14, 0x00, 0x12, 0x80, 0xff, 0xff, 0x03, 0x00, 0x38, 0x12, 0x00, 0xb6, 0x32, 0x12, 0x00, 0xb6, 0x55, 0x65, 0x00, 0x80, 0xc8, 0x03, 0x12, 0x80, 0xc4, 0x03, 0x12, 0x80, 0xd1, 0x9f, 0x01, 0x80, 0xfd, 0x63, 0x05, 0x62, 0xff, 0x6a, 0x85, 0x67, 0x4c, 0xec, 0x67, 0x44, 0x4b, 0x4b, 0x09, 0xb5, 0x68, 0x33, 0x6d, 0xe5, 0x60, 0x9b, 0xa3, 0xa3, 0x04, 0x6b, 0xac, 0xeb, 0x4c, 0xeb, 0x03, 0x23, 0x05, 0xb2, 0x40, 0xea, 0x00, 0x65, 0x05, 0x97, 0x00, 0x6a, 0x00, 0xef, - 0x03, 0x63, 0x00, 0x65, 0x10, 0x23, 0x12, 0x80, 0xf9, 0x3a, 0x10, 0x80, + 0x03, 0x63, 0x00, 0x65, 0x10, 0x23, 0x12, 0x80, 0x9d, 0x3a, 0x10, 0x80, 0xfd, 0x63, 0x05, 0x62, 0xff, 0xf7, 0x1f, 0x6b, 0xac, 0xeb, 0x07, 0xb5, 0xbb, 0xe4, 0x07, 0xb2, 0x03, 0x2e, 0x85, 0x67, 0x20, 0x6d, 0x01, 0x10, 0xa3, 0x67, 0x40, 0xea, 0x00, 0x65, 0x05, 0x97, 0x00, 0xef, 0x03, 0x63, @@ -1322,9 +1313,8 @@ const unsigned char rtlbt_fw[] = { 0x07, 0xb2, 0x40, 0xea, 0x91, 0x67, 0x07, 0x97, 0x06, 0x91, 0x05, 0x90, 0x00, 0x6a, 0x00, 0xef, 0x04, 0x63, 0x00, 0x65, 0x10, 0x23, 0x12, 0x80, 0x50, 0x00, 0x12, 0x80, 0x75, 0xd4, 0x01, 0x80, 0x41, 0x00, 0x00, 0x00, - 0x07, 0x00, 0xf8, 0x03, 0x00, 0xe0, 0x07, 0x00, 0xc0, 0x7f, 0x00, 0x00, - 0x6d, 0x37, 0x10, 0x80, 0x19, 0x36, 0x10, 0x80, 0x1d, 0x36, 0x10, 0x80, - 0x9d, 0x36, 0x10, 0x80, 0x21, 0x36, 0x10, 0x80, 0x25, 0x36, 0x10, 0x80, + 0x11, 0x37, 0x10, 0x80, 0xbd, 0x35, 0x10, 0x80, 0xc1, 0x35, 0x10, 0x80, + 0x41, 0x36, 0x10, 0x80, 0xc5, 0x35, 0x10, 0x80, 0xc9, 0x35, 0x10, 0x80, 0x00, 0xf0, 0x20, 0x00, 0x00, 0x90, 0x4f, 0x03, 0x00, 0xf0, 0x20, 0x00, 0x00, 0x90, 0x6f, 0x03, 0x00, 0xf0, 0x08, 0x00, 0x02, 0x90, 0x17, 0xf8, 0x34, 0x00, 0x03, 0x10, 0x36, 0x00, 0x04, 0xe2, 0x38, 0x00, 0x01, 0x31, @@ -1341,8 +1331,8 @@ const unsigned char rtlbt_fw[] = { 0x64, 0x01, 0x44, 0x3b, 0x66, 0x01, 0xd2, 0x76, 0x08, 0x00, 0xb0, 0x00, 0x66, 0x00, 0x59, 0x40, 0x0a, 0x06, 0xdb, 0x50, 0x0c, 0x06, 0xe2, 0x7b, 0x0e, 0x06, 0x6a, 0xc0, 0x10, 0x06, 0x8c, 0x55, 0x12, 0x06, 0x0a, 0x28, - 0x14, 0x06, 0x27, 0x01, 0x02, 0x02, 0x6a, 0x7c, 0x4e, 0x61, 0xdf, 0x4e, - 0x4e, 0x61, 0xdf, 0x4e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x14, 0x06, 0x27, 0x01, 0x02, 0x02, 0x6a, 0x7c, 0xb1, 0xed, 0xf4, 0xe8, + 0xb1, 0xed, 0xf4, 0xe8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/component/common/bluetooth/realtek/sdk/board/amebaz2/src/hci/hci_board.c b/component/common/bluetooth/realtek/sdk/board/amebaz2/src/hci/hci_board.c index 9c72a736..464eab6e 100644 --- a/component/common/bluetooth/realtek/sdk/board/amebaz2/src/hci/hci_board.c +++ b/component/common/bluetooth/realtek/sdk/board/amebaz2/src/hci/hci_board.c @@ -365,7 +365,6 @@ uint8_t *hci_rtk_combine_config(void) uint8_t *p_len = full_config_buf+4; memcpy(full_config_buf,rtlbt_init_config, sizeof(rtlbt_init_config)); - memcpy(full_config_buf+sizeof(rtlbt_init_config),rtlbt_config+HCI_CONFIG_HEAD, rtlbt_config_len-HCI_CONFIG_HEAD); HCI_PRINT_WARN1("hci_rtk_combine_config: invalid len, calculated %u", config_length); @@ -395,9 +394,9 @@ bool hci_rtk_find_patch(uint8_t bt_hci_chip_id) extern unsigned char rtlbt_config[]; extern unsigned int rtlbt_config_len; - uint8_t *fw_buf; + uint8_t *fw_buf = NULL; uint8_t *config_buf; - uint16_t fw_len; + uint16_t fw_len = 0; uint32_t fw_offset; uint16_t config_len; uint32_t lmp_subversion;; @@ -408,7 +407,7 @@ bool hci_rtk_find_patch(uint8_t bt_hci_chip_id) flash_t flash; uint8_t i = 0; const uint8_t rtb_patch_smagic[8]= {0x52, 0x65, 0x61, 0x6C, 0x74, 0x65, 0x63, 0x68}; - uint8_t tmp_patch_head[8]; + uint8_t tmp_patch_head[8] = {0}; const uint8_t single_patch_sing[4]= {0xFD, 0x63, 0x05, 0x62}; #define MERGE_PATCH_SWITCH_SINGLE 0xAAAAAAAA @@ -1046,7 +1045,7 @@ void bt_write_lgc_efuse_value(void) int bt_get_mac_address(uint8_t *mac) { uint8_t addr_size = 6; - uint8_t read_ddr[6]; + uint8_t read_ddr[6] = {0}; //Check BT address device_mutex_lock(RT_DEV_LOCK_EFUSE); @@ -1062,7 +1061,7 @@ int bt_set_mac_address(uint8_t *mac) { uint8_t addr_size = 6; int ret = 0; - uint8_t read_ddr[6]; + uint8_t read_ddr[6] = {0}; device_mutex_lock(RT_DEV_LOCK_EFUSE); efuse_logical_write(BOARD_LOGIC_EFUSE_OFFSET, addr_size, mac); diff --git a/component/common/bluetooth/realtek/sdk/board/amebaz2/src/vendor_cmd/vendor_cmd.c b/component/common/bluetooth/realtek/sdk/board/amebaz2/src/vendor_cmd/vendor_cmd.c index 1e01f404..ae935bbc 100644 --- a/component/common/bluetooth/realtek/sdk/board/amebaz2/src/vendor_cmd/vendor_cmd.c +++ b/component/common/bluetooth/realtek/sdk/board/amebaz2/src/vendor_cmd/vendor_cmd.c @@ -14,6 +14,7 @@ P_FUN_GAP_APP_CB ext_app_cb = NULL; bool mailbox_to_bt(uint8_t *data, uint8_t len) { T_GAP_DEV_STATE new_state; + memset(&new_state, 0, sizeof(T_GAP_DEV_STATE)); le_get_gap_param(GAP_PARAM_DEV_STATE , &new_state ); if (new_state.gap_init_state != GAP_INIT_STATE_STACK_READY) { APP_PRINT_ERROR1("mailbox_to_bt: gap_init_state: 0x%x", new_state.gap_init_state); @@ -33,6 +34,7 @@ bool mailbox_to_bt(uint8_t *data, uint8_t len) bool mailbox_to_bt_set_profile_report(uint8_t *data, uint8_t len) { T_GAP_DEV_STATE new_state; + memset(&new_state, 0, sizeof(T_GAP_DEV_STATE)); le_get_gap_param(GAP_PARAM_DEV_STATE , &new_state ); if (new_state.gap_init_state != GAP_INIT_STATE_STACK_READY) { APP_PRINT_INFO1("mailbox_to_bt_set_profile_report: gap_init_state: 0x%x", new_state.gap_init_state); @@ -109,7 +111,7 @@ T_GAP_CAUSE le_adv_set_power_save_enable(uint8_t enable) #if BT_VENDOR_CMD_CONN_TX_POWER_SUPPORT T_GAP_CAUSE le_set_conn_tx_power(uint8_t conn_id, bool reset, uint8_t tx_power) { - uint16_t conn_handle; + uint16_t conn_handle = 0; if (le_get_conn_param(GAP_PARAM_CONN_HANDLE, &conn_handle, conn_id) == GAP_CAUSE_SUCCESS) { uint8_t param[5]; diff --git a/component/common/bluetooth/realtek/sdk/board/common/os/freertos/osif_freertos.c b/component/common/bluetooth/realtek/sdk/board/common/os/freertos/osif_freertos.c index f8820853..698e8e0a 100644 --- a/component/common/bluetooth/realtek/sdk/board/common/os/freertos/osif_freertos.c +++ b/component/common/bluetooth/realtek/sdk/board/common/os/freertos/osif_freertos.c @@ -31,6 +31,9 @@ #include "cmsis_iar.h" #endif #endif + +#define CONFIG_OSIF_DEBUG 0 + /****************************************************************************/ /* Check if in task context (true), or isr context (false) */ /****************************************************************************/ @@ -67,8 +70,13 @@ uint32_t osif_sys_time_get(void) /****************************************************************************/ bool osif_sched_start(void) { +#if CONFIG_OSIF_DEBUG + printf("%s enter\r\n", __FUNCTION__); +#endif vTaskStartScheduler(); - +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } @@ -77,8 +85,13 @@ bool osif_sched_start(void) /****************************************************************************/ bool osif_sched_stop(void) { +#if CONFIG_OSIF_DEBUG + printf("%s enter\r\n", __FUNCTION__); +#endif vTaskEndScheduler(); - +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } @@ -87,8 +100,13 @@ bool osif_sched_stop(void) /****************************************************************************/ bool osif_sched_suspend(void) { +#if CONFIG_OSIF_DEBUG + printf("%s enter\r\n", __FUNCTION__); +#endif vTaskSuspendAll(); - +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } @@ -97,8 +115,13 @@ bool osif_sched_suspend(void) /****************************************************************************/ bool osif_sched_resume(void) { +#if CONFIG_OSIF_DEBUG + printf("%s enter\r\n", __FUNCTION__); +#endif xTaskResumeAll(); - +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } @@ -108,10 +131,16 @@ bool osif_sched_resume(void) bool osif_task_create(void **pp_handle, const char *p_name, void (*p_routine)(void *), void *p_param, uint16_t stack_size, uint16_t priority) { +#if CONFIG_OSIF_DEBUG + printf("%s pp_handle 0x%x p_name %s p_routine 0x%x p_param 0x%x stack_size %d priority %d\r\n", __FUNCTION__, + pp_handle, p_name, p_routine, p_param, stack_size, priority); +#endif + BaseType_t ret; if (pp_handle == NULL) { + printf("%s fail!(p_handle == NULL)\r\n", __FUNCTION__); return false; } @@ -119,10 +148,14 @@ bool osif_task_create(void **pp_handle, const char *p_name, void (*p_routine)(vo p_param, priority, (TaskHandle_t *)pp_handle); if (ret == pdPASS) { +#if CONFIG_OSIF_DEBUG + printf("%s *pp_handle 0x%x\r\n", __FUNCTION__, *pp_handle); +#endif return true; } else { + printf("%s fail!\r\n", __FUNCTION__); return false; } } @@ -132,8 +165,13 @@ bool osif_task_create(void **pp_handle, const char *p_name, void (*p_routine)(vo /****************************************************************************/ bool osif_task_delete(void *p_handle) { +#if CONFIG_OSIF_DEBUG + printf("%s p_handle 0x%x\r\n", __FUNCTION__, p_handle); +#endif vTaskDelete((TaskHandle_t)p_handle); - +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } @@ -142,7 +180,13 @@ bool osif_task_delete(void *p_handle) /****************************************************************************/ bool osif_task_suspend(void *p_handle) { +#if CONFIG_OSIF_DEBUG + printf("%s p_handle 0x%x\r\n", __FUNCTION__, p_handle); +#endif vTaskSuspend((TaskHandle_t)p_handle); +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } @@ -151,8 +195,13 @@ bool osif_task_suspend(void *p_handle) /****************************************************************************/ bool osif_task_resume(void *p_handle) { +#if CONFIG_OSIF_DEBUG + printf("%s p_handle 0x%x\r\n", __FUNCTION__, p_handle); +#endif vTaskResume((TaskHandle_t)p_handle); - +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } @@ -161,8 +210,13 @@ bool osif_task_resume(void *p_handle) /****************************************************************************/ bool osif_task_yield(void) { +#if CONFIG_OSIF_DEBUG + printf("%s enter\r\n", __FUNCTION__); +#endif taskYIELD(); - +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } @@ -171,13 +225,19 @@ bool osif_task_yield(void) /****************************************************************************/ bool osif_task_handle_get(void **pp_handle) { +#if CONFIG_OSIF_DEBUG + printf("%s pp_handle 0x%x\r\n", __FUNCTION__, pp_handle); +#endif if (pp_handle == NULL) { + printf("%s fail!(*pp_handle == NULL)\r\n", __FUNCTION__); return false; } *pp_handle = (void *)xTaskGetCurrentTaskHandle(); - +#if CONFIG_OSIF_DEBUG + printf("%s *pp_handle 0x%x\r\n", __FUNCTION__, *pp_handle); +#endif return true; } @@ -186,13 +246,19 @@ bool osif_task_handle_get(void **pp_handle) /****************************************************************************/ bool osif_task_priority_get(void *p_handle, uint16_t *p_priority) { +#if CONFIG_OSIF_DEBUG + printf("%s p_handle 0x%x, p_priority 0x%x\r\n", __FUNCTION__, p_handle, p_priority); +#endif if (p_priority == NULL) { + printf("%s fail!(p_priority == NULL)\r\n", __FUNCTION__); return false; } *p_priority = uxTaskPriorityGet((TaskHandle_t)p_handle); - +#if CONFIG_OSIF_DEBUG + printf("%s *p_priority 0x%x\r\n", __FUNCTION__, *p_priority); +#endif return true; } @@ -201,8 +267,13 @@ bool osif_task_priority_get(void *p_handle, uint16_t *p_priority) /****************************************************************************/ bool osif_task_priority_set(void *p_handle, uint16_t priority) { +#if CONFIG_OSIF_DEBUG + printf("%s p_handle 0x%x priority %d\r\n", __FUNCTION__, p_handle, priority); +#endif vTaskPrioritySet((TaskHandle_t)p_handle, priority); - +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } @@ -212,21 +283,31 @@ bool osif_signal_init(void) sig_handle = (void *)xSemaphoreCreateCounting(1, 0); if (sig_handle != NULL) { +#if CONFIG_OSIF_DEBUG + printf("%s sig_handle 0x%x\r\n", __FUNCTION__, sig_handle); +#endif return true; } else { + printf("%s fail! sig_handle = NULL\r\n", __FUNCTION__); return false; } } void osif_signal_deinit(void) { +#if CONFIG_OSIF_DEBUG + printf("%s sig_handle 0x%x\r\n", __FUNCTION__, sig_handle); +#endif if (sig_handle != NULL) { vSemaphoreDelete(sig_handle); sig_handle = NULL; } +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif } /****************************************************************************/ @@ -234,7 +315,9 @@ void osif_signal_deinit(void) /****************************************************************************/ bool osif_task_signal_send(void *p_handle, uint32_t signal) { - +#if CONFIG_OSIF_DEBUG + printf("%s sig_handle 0x%x\r\n", __FUNCTION__, sig_handle); +#endif if (!sig_handle) { printf("osif_task_signal_send: sig_handle is null"); @@ -255,6 +338,9 @@ bool osif_task_signal_send(void *p_handle, uint32_t signal) portEND_SWITCHING_ISR(task_woken); } +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } @@ -264,7 +350,9 @@ bool osif_task_signal_send(void *p_handle, uint32_t signal) /****************************************************************************/ bool osif_task_signal_recv(uint32_t *p_handle, uint32_t wait_ms) { - +#if CONFIG_OSIF_DEBUG + printf("%s sig_handle 0x%x wait_ms 0x%x\r\n", __FUNCTION__, sig_handle, wait_ms); +#endif BaseType_t ret; TickType_t wait_ticks; @@ -298,10 +386,14 @@ bool osif_task_signal_recv(uint32_t *p_handle, uint32_t wait_ms) if (ret == pdTRUE) { +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } else { + printf("%s fail!\r\n", __FUNCTION__); return false; } } @@ -311,16 +403,23 @@ bool osif_task_signal_recv(uint32_t *p_handle, uint32_t wait_ms) /****************************************************************************/ bool osif_task_signal_clear(void *p_handle) { +#if CONFIG_OSIF_DEBUG + printf("%s p_handle 0x%x...\r\n", __FUNCTION__, p_handle); +#endif BaseType_t ret; extern BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask ); ret = xTaskNotifyStateClear((TaskHandle_t)p_handle); if (ret == pdTRUE) { +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } else { + printf("%s fail!\r\n", __FUNCTION__); return false; } } @@ -339,7 +438,7 @@ uint32_t osif_lock(void) } else { - hci_board_debug("warn: unexpected isr mode\r\n"); + printf("warn: unexpected isr mode\r\n"); //flags = taskENTER_CRITICAL_FROM_ISR(); } @@ -358,7 +457,7 @@ void osif_unlock(uint32_t flags) } else { - hci_board_debug("warn: unexpected isr mode\r\n"); + printf("warn: unexpected isr mode\r\n"); //taskEXIT_CRITICAL_FROM_ISR(flags); } @@ -369,18 +468,26 @@ void osif_unlock(uint32_t flags) /****************************************************************************/ bool osif_sem_create(void **pp_handle, uint32_t init_count, uint32_t max_count) { +#if CONFIG_OSIF_DEBUG + printf("%s pp_handle 0x%x init_count %d max_count %d\r\n", __FUNCTION__, pp_handle, init_count, max_count); +#endif if (pp_handle == NULL) { + printf("%s fail!(pp_handle == NULL)\r\n", __FUNCTION__); return false; } *pp_handle = (void *)xSemaphoreCreateCounting(max_count, init_count); if (*pp_handle != NULL) { +#if CONFIG_OSIF_DEBUG + printf("%s *pp_handle 0x%x\r\n", __FUNCTION__, *pp_handle); +#endif return true; } else { + printf("%s fail! *pp_handle = NULL\r\n", __FUNCTION__); return false; } } @@ -390,8 +497,13 @@ bool osif_sem_create(void **pp_handle, uint32_t init_count, uint32_t max_count) /****************************************************************************/ bool osif_sem_delete(void *p_handle) { +#if CONFIG_OSIF_DEBUG + printf("%s p_handle 0x%x\r\n", __FUNCTION__, p_handle); +#endif vSemaphoreDelete((QueueHandle_t)p_handle); - +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } @@ -400,6 +512,9 @@ bool osif_sem_delete(void *p_handle) /****************************************************************************/ bool osif_sem_take(void *p_handle, uint32_t wait_ms) { +#if CONFIG_OSIF_DEBUG + printf("%s p_handle 0x%x wait_ms 0x%x\r\n", __FUNCTION__, p_handle, wait_ms); +#endif BaseType_t ret; if (osif_task_context_check() == true) @@ -428,10 +543,14 @@ bool osif_sem_take(void *p_handle, uint32_t wait_ms) if (ret == pdTRUE) { +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } else { + printf("%s fail!\r\n", __FUNCTION__); return false; } } @@ -441,6 +560,9 @@ bool osif_sem_take(void *p_handle, uint32_t wait_ms) /****************************************************************************/ bool osif_sem_give(void *p_handle) { +#if CONFIG_OSIF_DEBUG + printf("%s p_handle 0x%x\r\n", __FUNCTION__, p_handle); +#endif BaseType_t ret; if (osif_task_context_check() == true) @@ -458,10 +580,14 @@ bool osif_sem_give(void *p_handle) if (ret == pdTRUE) { +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } else { + printf("%s fail!\r\n", __FUNCTION__); return false; } } @@ -471,18 +597,26 @@ bool osif_sem_give(void *p_handle) /****************************************************************************/ bool osif_mutex_create(void **pp_handle) { +#if CONFIG_OSIF_DEBUG + printf("%s pp_handle 0x%x\r\n", __FUNCTION__, pp_handle); +#endif if (pp_handle == NULL) { + printf("%s fail!(p_handle == NULL)\r\n", __FUNCTION__); return false; } *pp_handle = (void *)xSemaphoreCreateRecursiveMutex(); if (*pp_handle != NULL) { +#if CONFIG_OSIF_DEBUG + printf("%s *pp_handle 0x%x\r\n", __FUNCTION__, *pp_handle); +#endif return true; } else { + printf("%s fail! *pp_handle = NULL\r\n", __FUNCTION__); return false; } } @@ -492,14 +626,21 @@ bool osif_mutex_create(void **pp_handle) /****************************************************************************/ bool osif_mutex_delete(void *p_handle) { +#if CONFIG_OSIF_DEBUG + printf("%s p_handle 0x%x\r\n", __FUNCTION__, p_handle); +#endif if (xSemaphoreGetMutexHolder((QueueHandle_t)p_handle) == NULL) { vSemaphoreDelete((QueueHandle_t)p_handle); +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } else { /* Do not delete mutex if held by a task */ + printf("%s Do not delete mutex because it held by a task\r\n", __FUNCTION__); return false; } } @@ -509,6 +650,9 @@ bool osif_mutex_delete(void *p_handle) /****************************************************************************/ bool osif_mutex_take(void *p_handle, uint32_t wait_ms) { +#if CONFIG_OSIF_DEBUG + printf("%s p_handle 0x%x wait_ms 0x%x\r\n", __FUNCTION__, p_handle, wait_ms); +#endif TickType_t wait_ticks; BaseType_t ret; @@ -524,10 +668,14 @@ bool osif_mutex_take(void *p_handle, uint32_t wait_ms) ret = xSemaphoreTakeRecursive((QueueHandle_t)p_handle, wait_ticks); if (ret == pdTRUE) { +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } else { + printf("%s fail!\r\n", __FUNCTION__); return false; } } @@ -537,15 +685,22 @@ bool osif_mutex_take(void *p_handle, uint32_t wait_ms) /****************************************************************************/ bool osif_mutex_give(void *p_handle) { +#if CONFIG_OSIF_DEBUG + printf("%s p_handle 0x%x\r\n", __FUNCTION__, p_handle); +#endif BaseType_t ret; ret = xSemaphoreGiveRecursive((QueueHandle_t)p_handle); if (ret == pdTRUE) { +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } else { + printf("%s fail!\r\n", __FUNCTION__); return false; } } @@ -555,19 +710,27 @@ bool osif_mutex_give(void *p_handle) /****************************************************************************/ bool osif_msg_queue_create(void **pp_handle, uint32_t msg_num, uint32_t msg_size) { +#if CONFIG_OSIF_DEBUG + printf("%s pp_handle 0x%x msg_num %d msg_size %d\r\n", __FUNCTION__, pp_handle, msg_num, msg_size); +#endif if (pp_handle == NULL) { + printf("%s fail!(p_handle == NULL)\r\n", __FUNCTION__); return false; } *pp_handle = (void *)xQueueCreate(msg_num, msg_size); + if (*pp_handle != NULL) { +#if CONFIG_OSIF_DEBUG + printf("%s *pp_handle 0x%x\r\n", __FUNCTION__, *pp_handle); +#endif return true; } else { - + printf("%s fail! *pp_handle = NULL\r\n", __FUNCTION__); return false; } } @@ -577,12 +740,18 @@ bool osif_msg_queue_create(void **pp_handle, uint32_t msg_num, uint32_t msg_size /****************************************************************************/ bool osif_msg_queue_delete(void *p_handle) { +#if CONFIG_OSIF_DEBUG + printf("%s p_handle 0x%x\r\n", __FUNCTION__, p_handle); +#endif if (p_handle == NULL) { + printf("%s fail!(p_handle == NULL)\r\n", __FUNCTION__); return false; } vQueueDelete((QueueHandle_t)p_handle); - +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } @@ -591,8 +760,12 @@ bool osif_msg_queue_delete(void *p_handle) /****************************************************************************/ bool osif_msg_queue_peek(void *p_handle, uint32_t *p_msg_num) { - if (p_handle == NULL) +#if CONFIG_OSIF_DEBUG + printf("%s p_handle 0x%x p_msg_num 0x%x\r\n", __FUNCTION__, p_handle, p_msg_num); +#endif + if (p_handle == NULL || p_msg_num == NULL ) { + printf("%s fail!(p_handle == NULL || p_msg_num == NULL)\r\n", __FUNCTION__); return false; } if (osif_task_context_check() == true) @@ -603,7 +776,9 @@ bool osif_msg_queue_peek(void *p_handle, uint32_t *p_msg_num) { *p_msg_num = (uint32_t)uxQueueMessagesWaitingFromISR((QueueHandle_t)p_handle); } - +#if CONFIG_OSIF_DEBUG + printf("%s *p_msg_num 0x%x\r\n", __FUNCTION__, *p_msg_num); +#endif return true; } @@ -612,10 +787,14 @@ bool osif_msg_queue_peek(void *p_handle, uint32_t *p_msg_num) /****************************************************************************/ bool osif_msg_send(void *p_handle, void *p_msg, uint32_t wait_ms) { +#if CONFIG_OSIF_DEBUG + printf("%s p_handle 0x%x p_msg 0x%x wait_ms 0x%x\r\n", __FUNCTION__, p_handle, p_msg, wait_ms); +#endif BaseType_t ret; if (p_handle == NULL) { + printf("%s fail!(p_handle == NULL)\r\n", __FUNCTION__); return false; } @@ -644,10 +823,14 @@ bool osif_msg_send(void *p_handle, void *p_msg, uint32_t wait_ms) if (ret == pdTRUE) { +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } else { + printf("%s fail!\r\n", __FUNCTION__); return false; } } @@ -657,9 +840,13 @@ bool osif_msg_send(void *p_handle, void *p_msg, uint32_t wait_ms) /****************************************************************************/ bool osif_msg_recv(void *p_handle, void *p_msg, uint32_t wait_ms) { +#if CONFIG_OSIF_DEBUG + printf("%s p_handle 0x%x p_msg 0x%x wait_ms 0x%x\r\n", __FUNCTION__, p_handle, p_msg, wait_ms); +#endif BaseType_t ret; if (p_handle == NULL) { + printf("%s fail!(p_handle == NULL)\r\n", __FUNCTION__); return false; } if (osif_task_context_check() == true) @@ -688,6 +875,9 @@ bool osif_msg_recv(void *p_handle, void *p_msg, uint32_t wait_ms) if (ret == pdTRUE) { +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } else @@ -701,9 +891,13 @@ bool osif_msg_recv(void *p_handle, void *p_msg, uint32_t wait_ms) /****************************************************************************/ bool osif_msg_peek(void *p_handle, void *p_msg, uint32_t wait_ms) { +#if CONFIG_OSIF_DEBUG + printf("%s p_handle 0x%x p_msg 0x%x wait_ms 0x%x\r\n", __FUNCTION__, p_handle, p_msg, wait_ms); +#endif BaseType_t ret; if (p_handle == NULL) { + printf("%s fail!(p_handle == NULL)\r\n", __FUNCTION__); return false; } if (osif_task_context_check() == true) @@ -728,10 +922,14 @@ bool osif_msg_peek(void *p_handle, void *p_msg, uint32_t wait_ms) if (ret == pdTRUE) { +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } else { + printf("%s fail!\r\n", __FUNCTION__); return false; } } @@ -762,6 +960,7 @@ void *osif_mem_aligned_alloc(RAM_TYPE ram_type, size_t size, uint8_t alignment) p = pvPortMalloc(size + sizeof(void *) + alignment); if (p == NULL) { + printf("%s fail!(p == NULL)\r\n", __FUNCTION__); return p; } @@ -779,6 +978,7 @@ void osif_mem_free(void *p_block) { if (p_block == NULL) { + printf("%s fail!(p_block == NULL)\r\n", __FUNCTION__); return; } vPortFree(p_block); @@ -792,6 +992,7 @@ void osif_mem_aligned_free(void *p_block) void *p; if (p_block == NULL) { + printf("%s fail!(p_block == NULL)\r\n", __FUNCTION__); return; } memcpy(&p, (uint8_t *)p_block - sizeof(void *), sizeof(void *)); @@ -813,13 +1014,19 @@ size_t osif_mem_peek(RAM_TYPE ram_type) /****************************************************************************/ bool osif_timer_id_get(void **pp_handle, uint32_t *p_timer_id) { +#if CONFIG_OSIF_DEBUG + printf("%s pp_handle 0x%x p_timer_id 0x%x\r\n", __FUNCTION__, pp_handle, p_timer_id); +#endif if (pp_handle == NULL || *pp_handle == NULL) { + printf("%s fail!(pp_handle == NULL || *pp_handle == NULL)\r\n", __FUNCTION__); return false; } *p_timer_id = (uint32_t)pvTimerGetTimerID((TimerHandle_t) * pp_handle); - +#if CONFIG_OSIF_DEBUG + printf("%s *p_timer_id %d\r\n", __FUNCTION__, *p_timer_id); +#endif return true; } @@ -830,10 +1037,14 @@ bool osif_timer_id_get(void **pp_handle, uint32_t *p_timer_id) bool osif_timer_create(void **pp_handle, const char *p_timer_name, uint32_t timer_id, uint32_t interval_ms, bool reload, void (*p_timer_callback)(void *)) { +#if CONFIG_OSIF_DEBUG + printf("%s pp_handle 0x%x p_timer_name %s timer_id %d interval_ms %d reload %d p_timer_callback 0x%x\r\n", __FUNCTION__, pp_handle, p_timer_name, timer_id, interval_ms, reload, p_timer_callback); +#endif TickType_t timer_ticks; if (pp_handle == NULL || p_timer_callback == NULL) { + printf("%s fail!(pp_handle == NULL || p_timer_callback == NULL)\r\n", __FUNCTION__); return false; } @@ -843,16 +1054,23 @@ bool osif_timer_create(void **pp_handle, const char *p_timer_name, uint32_t time { *pp_handle = xTimerCreate(p_timer_name, timer_ticks, (BaseType_t)reload, (void *)timer_id, (TimerCallbackFunction_t)p_timer_callback); +#if CONFIG_OSIF_DEBUG + printf("%s *pp_handle 0x%x\r\n", __FUNCTION__, *pp_handle); +#endif if (*pp_handle == NULL) { + printf("%s fail!(p_handle == NULL)\r\n", __FUNCTION__); return false; } } else { + printf("%s fail!(p_handle != NULL)\r\n", __FUNCTION__); return false; } - +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } @@ -861,10 +1079,14 @@ bool osif_timer_create(void **pp_handle, const char *p_timer_name, uint32_t time /****************************************************************************/ bool osif_timer_start(void **pp_handle) { +#if CONFIG_OSIF_DEBUG + printf("%s pp_handle 0x%x *pp_handle 0x%x\r\n", __FUNCTION__, pp_handle, *pp_handle); +#endif BaseType_t ret; if (pp_handle == NULL || *pp_handle == NULL) { + printf("%s fail!(pp_handle == NULL || *pp_handle == NULL)\r\n", __FUNCTION__); return false; } @@ -883,10 +1105,14 @@ bool osif_timer_start(void **pp_handle) if (ret == pdTRUE) { +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } else { + printf("%s fail!\r\n", __FUNCTION__, ret); return false; } } @@ -896,11 +1122,15 @@ bool osif_timer_start(void **pp_handle) /****************************************************************************/ bool osif_timer_restart(void **pp_handle, uint32_t interval_ms) { +#if CONFIG_OSIF_DEBUG + printf("%s pp_handle 0x%x *pp_handle 0x%x interval_ms %d\r\n", __FUNCTION__, pp_handle, *pp_handle, interval_ms); +#endif TickType_t timer_ticks; BaseType_t ret; if (pp_handle == NULL || *pp_handle == NULL) { + printf("%s fail!(pp_handle == NULL || *pp_handle == NULL)\r\n", __FUNCTION__); return false; } @@ -921,10 +1151,14 @@ bool osif_timer_restart(void **pp_handle, uint32_t interval_ms) if (ret == pdTRUE) { +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } else { + printf("%s fail!\r\n", __FUNCTION__); return false; } } @@ -934,10 +1168,14 @@ bool osif_timer_restart(void **pp_handle, uint32_t interval_ms) /****************************************************************************/ bool osif_timer_stop(void **pp_handle) { +#if CONFIG_OSIF_DEBUG + printf("%s pp_handle 0x%x *pp_handle 0x%x\r\n", __FUNCTION__, pp_handle, *pp_handle); +#endif BaseType_t ret; if (pp_handle == NULL || *pp_handle == NULL) { + printf("%s fail!(pp_handle == NULL || *pp_handle == NULL)\r\n", __FUNCTION__); return false; } @@ -956,10 +1194,14 @@ bool osif_timer_stop(void **pp_handle) if (ret == pdTRUE) { +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } else { + printf("%s fail!\r\n", __FUNCTION__); return false; } } @@ -969,6 +1211,9 @@ bool osif_timer_stop(void **pp_handle) /****************************************************************************/ bool osif_timer_delete(void **pp_handle) { +#if CONFIG_OSIF_DEBUG + printf("%s pp_handle 0x%x *pp_handle 0x%x\r\n", __FUNCTION__, pp_handle, *pp_handle); +#endif if (pp_handle == NULL || *pp_handle == NULL) { return false; @@ -976,11 +1221,14 @@ bool osif_timer_delete(void **pp_handle) if (xTimerDelete((TimerHandle_t)*pp_handle, (TickType_t)0) == pdFAIL) { + printf("%s fail!\r\n", __FUNCTION__); return false; } *pp_handle = NULL; - +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } /****************************************************************************/ @@ -988,8 +1236,12 @@ bool osif_timer_delete(void **pp_handle) /****************************************************************************/ bool osif_timer_state_get(void **pp_handle, uint32_t *p_timer_state) { +#if CONFIG_OSIF_DEBUG + printf("%s pp_handle 0x%x p_timer_state 0x%x\r\n", __FUNCTION__, pp_handle, p_timer_state); +#endif if (pp_handle == NULL || *pp_handle == NULL) { + printf("%s fail!(pp_handle == NULL || *pp_handle == NULL)\r\n", __FUNCTION__); return false; } @@ -1001,6 +1253,9 @@ bool osif_timer_state_get(void **pp_handle, uint32_t *p_timer_state) { //*p_timer_state = (uint32_t)xTimerIsTimerActiveFromISR((TimerHandle_t) * pp_handle); } +#if CONFIG_OSIF_DEBUG + printf("%s exit\r\n", __FUNCTION__); +#endif return true; } /****************************************************************************/ @@ -1018,6 +1273,6 @@ extern void rtw_create_secure_context(u32 secure_stack_size); void osif_create_secure_context(uint32_t size) { #if defined(configENABLE_TRUSTZONE) && (configENABLE_TRUSTZONE == 1) - rtw_create_secure_context(size); + rtw_create_secure_context(size); #endif } diff --git a/component/common/bluetooth/realtek/sdk/board/common/src/cycle_queue.c b/component/common/bluetooth/realtek/sdk/board/common/src/cycle_queue.c index 59253791..a485d7e4 100644 --- a/component/common/bluetooth/realtek/sdk/board/common/src/cycle_queue.c +++ b/component/common/bluetooth/realtek/sdk/board/common/src/cycle_queue.c @@ -158,6 +158,7 @@ bool MallocCycQueue() cyc_buffer = osif_mem_alloc(RAM_TYPE_DATA_ON, MAX_BUFFER_SIZE); if (cyc_buffer == NULL) { printf("cyc_buffer is NULL, malloc fail\r\n"); + return false; } memset(cyc_buffer, 0, MAX_BUFFER_SIZE); pRead = 0; diff --git a/component/common/bluetooth/realtek/sdk/board/common/src/hci_process.c b/component/common/bluetooth/realtek/sdk/board/common/src/hci_process.c index c9952c0a..43ad32dc 100644 --- a/component/common/bluetooth/realtek/sdk/board/common/src/hci_process.c +++ b/component/common/bluetooth/realtek/sdk/board/common/src/hci_process.c @@ -263,7 +263,7 @@ uint8_t hci_tp_download_patch(void) uint8_t *p; uint8_t *p_frag; uint16_t sent_len; - uint8_t patch_frag_index; + uint8_t patch_frag_index = 0; T_HCI_PATCH *p_hci_rtk = &hci_patch_info; if (p_hci_rtk->patch_frag_idx < p_hci_rtk->patch_frag_cnt) diff --git a/component/common/bluetooth/realtek/sdk/example/ble_central/ble_central_app_task.c b/component/common/bluetooth/realtek/sdk/example/ble_central/ble_central_app_task.c index bdb332e9..1327d38a 100644 --- a/component/common/bluetooth/realtek/sdk/example/ble_central/ble_central_app_task.c +++ b/component/common/bluetooth/realtek/sdk/example/ble_central/ble_central_app_task.c @@ -27,9 +27,6 @@ #include #include #include -#include -#include -#include #include #include @@ -90,11 +87,6 @@ void ble_central_app_main_task(void *p_param) gap_start_bt_stack(ble_central_evt_queue_handle, ble_central_io_queue_handle, BLE_CENTRAL_MAX_NUMBER_OF_GAP_MESSAGE); - data_uart_init(ble_central_evt_queue_handle, ble_central_io_queue_handle); -#if defined (CONFIG_BT_USER_COMMAND) && (CONFIG_BT_USER_COMMAND) - user_cmd_init(&user_cmd_if, "central_client"); -#endif - while (true) { if (os_msg_recv(ble_central_evt_queue_handle, &event, 0xFFFFFFFF) == true) diff --git a/component/common/bluetooth/realtek/sdk/example/ble_central/ble_central_at_cmd.c b/component/common/bluetooth/realtek/sdk/example/ble_central/ble_central_at_cmd.c index 4c6d465b..0f7bb505 100644 --- a/component/common/bluetooth/realtek/sdk/example/ble_central/ble_central_at_cmd.c +++ b/component/common/bluetooth/realtek/sdk/example/ble_central/ble_central_at_cmd.c @@ -2,6 +2,9 @@ #if ((defined(CONFIG_BT_CENTRAL) && CONFIG_BT_CENTRAL) || \ (defined(CONFIG_BT_MESH_PROVISIONER_MULTIPLE_PROFILE) && CONFIG_BT_MESH_PROVISIONER_MULTIPLE_PROFILE) || \ (defined(CONFIG_BT_MESH_DEVICE_MULTIPLE_PROFILE) && CONFIG_BT_MESH_DEVICE_MULTIPLE_PROFILE)) +#include "platform_opts.h" +#include +#if SUPPORT_LOG_SERVICE #include #include #include @@ -14,7 +17,6 @@ #include "atcmd_bt.h" #include "ble_central_at_cmd.h" #include "os_msg.h" -#include #include "os_sched.h" #include "os_mem.h" @@ -208,7 +210,7 @@ void save_white_list_data(uint8_t white_list_data[ADDR_LEN*ADDR_NO]) { flash_t flash; if(erase_current_page == 1){ - //dbg_printf("[%s]erase_current_page: page %d.\n", __func__, page_id); + //printf("[%s]erase_current_page: page %d.\r\n", __func__, page_id); device_mutex_lock(RT_DEV_LOCK_FLASH); flash_erase_sector(&flash, BT_WHITELIST_BASE_1 + ((page_id == 1)? 0: 1)*BT_WHITELIST_PAGE_SIZE); device_mutex_unlock(RT_DEV_LOCK_FLASH); @@ -217,13 +219,13 @@ void save_white_list_data(uint8_t white_list_data[ADDR_LEN*ADDR_NO]) erase_current_page = 0; read_white_list_data(page_id, row_id); }else{ - //dbg_printf("[%s]write white list data to page %d, row %d.\n", __func__, page_id, row_id); + //printf("[%s]write white list data to page %d, row %d.\r\n", __func__, page_id, row_id); device_mutex_lock(RT_DEV_LOCK_FLASH); flash_stream_write(&flash, BT_WHITELIST_BASE_1 + (page_id - 1)*BT_WHITELIST_PAGE_SIZE + row_id*ADDR_LEN*ADDR_NO, ADDR_LEN*ADDR_NO, white_list_data); device_mutex_unlock(RT_DEV_LOCK_FLASH); if(row_id == 0){ - //dbg_printf("[%s]erase_last_page: page %d.\n", __func__, (page_id == 1)? 2: 1); + //printf("[%s]erase_last_page: page %d.\r\n", __func__, (page_id == 1)? 2: 1); device_mutex_lock(RT_DEV_LOCK_FLASH); flash_erase_sector(&flash, BT_WHITELIST_BASE_1 + ((page_id == 1)? 1: 0)*BT_WHITELIST_PAGE_SIZE); device_mutex_unlock(RT_DEV_LOCK_FLASH); @@ -233,11 +235,11 @@ void save_white_list_data(uint8_t white_list_data[ADDR_LEN*ADDR_NO]) if(row_id == MAX_N){ page_id = (page_id == 1)? 2: 1; row_id = 0; - //dbg_printf("[%s]row 15 has data, next write to the next page.\n", __func__); + //printf("[%s]row 15 has data, next write to the next page.\r\n", __func__); } } /* - dbg_printf("[%s]display real-time white_list_data.\n", __func__); + printf("[%s]display real-time white_list_data.\r\n", __func__); for(u8 i = 0; i < ADDR_NO; i++){ if(white_list_data[i*ADDR_LEN] == VALID_SIGN){ if(white_list_data[i*ADDR_LEN + 1] == BT_TYPE_PUBLIC){ @@ -245,13 +247,13 @@ void save_white_list_data(uint8_t white_list_data[ADDR_LEN*ADDR_NO]) for(u8 j = 0; j < BD_ADDR_LEN; j++){ printf("0x%x ", white_list_data[i*ADDR_LEN + 2 + j]); } - printf("\n"); + printf("\r\n"); }else if (white_list_data[i*ADDR_LEN + 1] == BT_TYPE_RANDOM){ printf("[Random] "); for(u8 j = 0; j < BD_ADDR_LEN; j++){ printf("0x%x ", white_list_data[i*ADDR_LEN + 2 + j]); } - printf("\n"); + printf("\r\n"); } } } @@ -264,7 +266,7 @@ void clear_white_list_data(void) erase_current_page = 1; save_white_list_data(read_data); }else{ - printf("White list haven't be initiated from flash, enter ATBn = 3 to load white list data from flash.\n"); + printf("White list haven't be initiated from flash, enter ATBn = 3 to load white list data from flash.\r\n"); } } @@ -296,20 +298,20 @@ void remove_white_list_data(T_GAP_REMOTE_ADDR_TYPE DestAddrType, u8 DestAddr[BD_ } if(count == 0){ - printf("All invalid, no address to remove.\n"); + printf("All invalid, no address to remove.\r\n"); }else if((count == 1) && (find_flag == 1)){ clear_white_list_data(); }else if(find_flag == 1){ - printf("Address match, ready to remove.\n"); + printf("Address match, ready to remove.\r\n"); for (u8 j = 0; j < ADDR_LEN; j++){ read_data[i*ADDR_LEN + j] = 0xff; } save_white_list_data(read_data); }else{ - printf("Address wrong.\n"); + printf("Address wrong.\r\n"); } }else{ - printf("White list haven't be initiated from flash, enter ATBn = 3 to load white list data from flash.\n"); + printf("White list haven't be initiated from flash, enter ATBn = 3 to load white list data from flash.\r\n"); } } @@ -372,7 +374,7 @@ void whitelist_flash_init(void) //find which block saved the latest white list data n1 = whitelist_find(BT_WHITELIST_BASE_1); n2 = whitelist_find(BT_WHITELIST_BASE_2); - //dbg_printf("[%s] find block %d in 4k(1), find block %d in 4k(2).\n", __func__, n1, n2); + //printf("[%s] find block %d in 4k(1), find block %d in 4k(2).\r\n", __func__, n1, n2); if((n1 == n2) && (n1 == INVALID_SIGN)){ page_id = 1; row_id = 0; @@ -422,8 +424,8 @@ void whitelist_flash_init(void) } //whitelist_flash_init complete whitelist_flash_init_flag = 1; - //dbg_printf("[%s] record next data in page %d block %d.\n", __func__, page_id, row_id); - printf("White list initiated from flash."); + //printf("[%s] record next data in page %d block %d.\r\n", __func__, page_id, row_id); + printf("White list initiated from flash.\r\n"); } void display_white_list_data(uint8_t white_list_data[ADDR_LEN*ADDR_NO]) @@ -436,18 +438,18 @@ void display_white_list_data(uint8_t white_list_data[ADDR_LEN*ADDR_NO]) for(u8 j = 0; j < BD_ADDR_LEN; j++){ printf("0x%x ", white_list_data[i*ADDR_LEN + 2 + j]); } - printf("\n"); + printf("\r\n"); }else if(white_list_data[i*ADDR_LEN + 1] == BT_TYPE_RANDOM){ printf("[Random] "); for(u8 j = 0; j < BD_ADDR_LEN; j++){ printf("0x%x ", white_list_data[i*ADDR_LEN + 2 + j]); } - printf("\n"); + printf("\r\n"); } } } }else{ - printf("White list haven't be initiated from flash, enter ATBn = 3 to load white list data from flash.\n"); + printf("White list haven't be initiated from flash, enter ATBn = 3 to load white list data from flash.\r\n"); } } @@ -465,7 +467,7 @@ void add_white_list_data(T_GAP_REMOTE_ADDR_TYPE DestAddrType, u8 DestAddr[BD_ADD && (read_data[i*ADDR_LEN+5] == DestAddr[2]) && (read_data[i*ADDR_LEN+6] == DestAddr[1]) && (read_data[i*ADDR_LEN+7] == DestAddr[0])){ - printf("BT address already saved.\n"); + printf("BT address already saved.\r\n"); return; } } @@ -484,13 +486,13 @@ void add_white_list_data(T_GAP_REMOTE_ADDR_TYPE DestAddrType, u8 DestAddr[BD_ADD if(save_flag){ save_white_list_data(read_data); - printf("Address saved.\n"); + printf("Address saved.\r\n"); save_flag = 0; }else{ - printf("Adress list full.\n"); + printf("Adress list full.\r\n"); } }else{ - printf("White list haven't be initiated from flash, enter ATBn = 3 to load white list data from flash.\n"); + printf("White list haven't be initiated from flash, enter ATBn = 3 to load white list data from flash.\r\n"); } } #endif @@ -507,18 +509,18 @@ void ble_central_at_cmd_send_msg(uint16_t sub_type) #if defined(CONFIG_BT_CENTRAL) && CONFIG_BT_CENTRAL if (ble_central_evt_queue_handle != NULL && ble_central_io_queue_handle != NULL) { if (os_msg_send(ble_central_io_queue_handle, &io_msg, 0) == false) { - BLE_PRINT("ble central at cmd send msg fail: subtype 0x%x", io_msg.subtype); + printf("ble central at cmd send msg fail: subtype 0x%x\r\n", io_msg.subtype); } else if (os_msg_send(ble_central_evt_queue_handle, &event, 0) == false) { - BLE_PRINT("ble central at cmd send event fail: subtype 0x%x", io_msg.subtype); + printf("ble central at cmd send event fail: subtype 0x%x\r\n", io_msg.subtype); } } #endif #if defined(CONFIG_BT_SCATTERNET) && CONFIG_BT_SCATTERNET if (ble_scatternet_evt_queue_handle != NULL && ble_scatternet_io_queue_handle != NULL) { if (os_msg_send(ble_scatternet_io_queue_handle, &io_msg, 0) == false) { - BLE_PRINT("ble central at cmd send msg fail: subtype 0x%x", io_msg.subtype); + printf("ble central at cmd send msg fail: subtype 0x%x\r\n", io_msg.subtype); } else if (os_msg_send(ble_scatternet_evt_queue_handle, &event, 0) == false) { - BLE_PRINT("ble central at cmd send event fail: subtype 0x%x", io_msg.subtype); + printf("ble central at cmd send event fail: subtype 0x%x\r\n", io_msg.subtype); } } #endif @@ -527,18 +529,18 @@ void ble_central_at_cmd_send_msg(uint16_t sub_type) #if defined(CONFIG_BT_MESH_PROVISIONER_MULTIPLE_PROFILE) && CONFIG_BT_MESH_PROVISIONER_MULTIPLE_PROFILE if (bt_mesh_provisioner_multiple_profile_evt_queue_handle != NULL && bt_mesh_provisioner_multiple_profile_io_queue_handle != NULL) { if (os_msg_send(bt_mesh_provisioner_multiple_profile_io_queue_handle, &io_msg, 0) == false) { - BLE_PRINT("ble central at cmd send msg fail: subtype 0x%x", io_msg.subtype); + printf("ble central at cmd send msg fail: subtype 0x%x\r\n", io_msg.subtype); } else if (os_msg_send(bt_mesh_provisioner_multiple_profile_evt_queue_handle, &event, 0) == false) { - BLE_PRINT("ble central at cmd send event fail: subtype 0x%x", io_msg.subtype); + printf("ble central at cmd send event fail: subtype 0x%x\r\n", io_msg.subtype); } } #endif #if defined(CONFIG_BT_MESH_DEVICE_MULTIPLE_PROFILE) && CONFIG_BT_MESH_DEVICE_MULTIPLE_PROFILE if (bt_mesh_device_multiple_profile_evt_queue_handle != NULL && bt_mesh_device_multiple_profile_io_queue_handle != NULL) { if (os_msg_send(bt_mesh_device_multiple_profile_io_queue_handle, &io_msg, 0) == false) { - BLE_PRINT("ble central at cmd send msg fail: subtype 0x%x", io_msg.subtype); + printf("ble central at cmd send msg fail: subtype 0x%x\r\n", io_msg.subtype); } else if (os_msg_send(bt_mesh_device_multiple_profile_evt_queue_handle, &event, 0) == false) { - BLE_PRINT("ble central at cmd send event fail: subtype 0x%x", io_msg.subtype); + printf("ble central at cmd send event fail: subtype 0x%x\r\n", io_msg.subtype); } } #endif //device multiple profile end @@ -547,9 +549,9 @@ void ble_central_at_cmd_send_msg(uint16_t sub_type) #if defined(CONFIG_BT_MESH_DEVICE_MULTIPLE_PROFILE) && CONFIG_BT_MESH_DEVICE_MULTIPLE_PROFILE if (bt_mesh_device_matter_evt_queue_handle != NULL && bt_mesh_device_matter_io_queue_handle != NULL) { if (os_msg_send(bt_mesh_device_matter_io_queue_handle, &io_msg, 0) == false) { - BLE_PRINT("ble central at cmd send msg fail: subtype 0x%x", io_msg.subtype); + printf("ble central at cmd send msg fail: subtype 0x%x\r\n", io_msg.subtype); } else if (os_msg_send(bt_mesh_device_matter_evt_queue_handle, &event, 0) == false) { - BLE_PRINT("ble central at cmd send event fail: subtype 0x%x", io_msg.subtype); + printf("ble central at cmd send event fail: subtype 0x%x\r\n", io_msg.subtype); } } #endif @@ -561,23 +563,25 @@ int ble_central_at_cmd_connect(int argc, char **argv) (void) argc; #if defined(CONFIG_BT_SCATTERNET) && CONFIG_BT_SCATTERNET if(ble_scatternet_central_app_max_links >= BLE_SCATTERNET_CENTRAL_APP_MAX_LINKS){ - BLE_PRINT("scatternet: exceed the max links number\r\n"); + printf("scatternet: exceed the max links number\r\n"); return 0; } #endif #if defined(CONFIG_BT_MESH_SCATTERNET) && CONFIG_BT_MESH_SCATTERNET if(bt_mesh_scatternet_central_app_max_links >= BLE_SCATTERNET_CENTRAL_APP_MAX_LINKS){ - BLE_PRINT("scatternet: exceed the max links number\r\n"); + printf("scatternet: exceed the max links number\r\n"); return 0; } #endif #if defined(CONFIG_BT_MESH_DEVICE_MATTER) && CONFIG_BT_MESH_DEVICE_MATTER if (bt_mesh_device_matter_central_app_max_links >= BT_MESH_DEVICE_MATTER_CENTRAL_APP_MAX_LINKS) { - BLE_PRINT("scatternet: exceed the max links number\r\n"); + printf("scatternet: exceed the max links number\r\n"); return 0; } #endif + return 0; + u8 DestAddr[6] = {0}; u8 DestAddrType = GAP_REMOTE_ADDR_LE_PUBLIC; #if (F_BT_LE_USE_RANDOM_ADDR==1) @@ -595,7 +599,7 @@ int ble_central_at_cmd_connect(int argc, char **argv) DestAddrType = GAP_REMOTE_ADDR_LE_RANDOM; if (strlen(argv[2]) != 2*BD_ADDR_LEN) { - BLE_PRINT("ERROR: mac address length error!\r\n"); + printf("ERROR: mac address length error!\r\n"); return -1; } @@ -611,7 +615,7 @@ int ble_central_at_cmd_connect(int argc, char **argv) conn_req_param.ce_len_max = 2 * (conn_req_param.conn_interval_max - 1); le_set_conn_param(GAP_CONN_PARAM_1M, &conn_req_param); - BLE_PRINT("cmd_con, DestAddr: 0x%02X:0x%02X:0x%02X:0x%02X:0x%02X:0x%02X\r\n", + printf("cmd_con, DestAddr: 0x%02X:0x%02X:0x%02X:0x%02X:0x%02X:0x%02X\r\n", DestAddr[5], DestAddr[4], DestAddr[3], DestAddr[2], DestAddr[1], DestAddr[0]); le_connect(0, DestAddr, (T_GAP_REMOTE_ADDR_TYPE)DestAddrType, local_addr_type, 1000); @@ -634,7 +638,7 @@ int ble_central_at_cmd_modify_whitelist(int argc, char **argv) #else if((type != 0) && (type != 1) && (type !=2)){ #endif - BLE_PRINT("unknow operation code, return\r\n"); + printf("unknow operation code, return\r\n"); return -1; } @@ -649,7 +653,7 @@ int ble_central_at_cmd_modify_whitelist(int argc, char **argv) #endif }else{ if (argc != 4){ - BLE_PRINT("ERROR:input parameter error!\r\n"); + printf("ERROR:input parameter error!\r\n"); return -1; } @@ -668,7 +672,7 @@ int ble_central_at_cmd_modify_whitelist(int argc, char **argv) hex_str_to_bd_addr(strlen(argv[3]), ( s8 *)argv[3], (u8*)DestAddr); - BLE_PRINT("cmd_modify, DestAddr: 0x%02X:0x%02X:0x%02X:0x%02X:0x%02X:0x%02X\r\n", + printf("cmd_modify, DestAddr: 0x%02X:0x%02X:0x%02X:0x%02X:0x%02X:0x%02X\r\n", DestAddr[5], DestAddr[4], DestAddr[3], DestAddr[2], DestAddr[1], DestAddr[0]); ret = le_modify_white_list(operation, DestAddr, DestAddrType); @@ -717,16 +721,16 @@ int ble_central_at_cmd_get_conn_info(int argc, char **argv) { if (le_get_conn_info(conn_id, &conn_info)) { - BLE_PRINT("ShowCon conn_id %d state 0x%x role %d\r\n", conn_id, + printf("ShowCon conn_id %d state 0x%x role %d\r\n", conn_id, conn_info.conn_state, conn_info.role); - BLE_PRINT("RemoteBd = [%02x:%02x:%02x:%02x:%02x:%02x] type = %d\r\n", + printf("RemoteBd = [%02x:%02x:%02x:%02x:%02x:%02x] type = %d\r\n", conn_info.remote_bd[5], conn_info.remote_bd[4], conn_info.remote_bd[3], conn_info.remote_bd[2], conn_info.remote_bd[1], conn_info.remote_bd[0], conn_info.remote_bd_type); } } - BLE_PRINT("active link num %d, idle link num %d\r\n", le_get_active_link_num(), le_get_idle_link_num()); + printf("active link num %d, idle link num %d\r\n", le_get_active_link_num(), le_get_idle_link_num()); return 0; } @@ -762,7 +766,7 @@ int ble_central_at_cmd_bond_information(int argc, char **argv) for (i = 0; i < bond_storage_num; i++) { p_entry = le_find_key_entry_by_idx(i); if (p_entry != NULL) { - BLE_PRINT("bond_dev[%d]: bd 0x%02x%02x%02x%02x%02x%02x, addr_type %d, flags 0x%x\r\n", + printf("bond_dev[%d]: bd 0x%02x%02x%02x%02x%02x%02x, addr_type %d, flags 0x%x\r\n", p_entry->idx, p_entry->remote_bd.addr[5], p_entry->remote_bd.addr[4], @@ -798,13 +802,13 @@ int ble_central_at_cmd_get(int argc, char **argv) gcs_all_primary_srv_discovery(conn_id); }else if(strcmp(argv[1], "SRV") == 0){ if(argc != 5){ - BLE_PRINT("ERROR:input parameter error!\n\r"); + printf("ERROR:input parameter error!\r\n"); return -1; } uuid_type = atoi(argv[3]); if(uuid_type == 0){ if (strlen(argv[4]) != 2 * UUID_16_LEN){ - BLE_PRINT("ERROR:uuid length error!\n\r"); + printf("ERROR:uuid length error!\r\n"); return -1; } hex_str_to_bd_addr(strlen(argv[4]), (s8 *)argv[4], (u8 *)uuid); @@ -812,18 +816,18 @@ int ble_central_at_cmd_get(int argc, char **argv) gcs_by_uuid_srv_discovery(conn_id, uuid16); }else if(uuid_type == 1){ if (strlen(argv[4]) != 2 * UUID_128_LEN){ - BLE_PRINT("ERROR:uuid length error!\n\r"); + printf("ERROR:uuid length error!\r\n"); return -1; } hex_str_to_bd_addr(strlen(argv[4]), (s8 *)argv[4], (u8 *)uuid); gcs_by_uuid128_srv_discovery(conn_id, uuid); }else{ - BLE_PRINT("ERROR:uuid type error!\n\r"); + printf("ERROR:uuid type error!\r\n"); return -1; } } else if(strcmp(argv[1], "CHARDIS") == 0){ if(argc != 5){ - BLE_PRINT("ERROR:input parameter error!\n\r"); + printf("ERROR:input parameter error!\r\n"); return -1; } start_handle = hex_str_to_int(strlen(argv[3]), (s8 *)argv[3]); @@ -831,7 +835,7 @@ int ble_central_at_cmd_get(int argc, char **argv) gcs_all_char_discovery(conn_id, start_handle, end_handle); }else if(strcmp(argv[1], "CHARUUID") == 0){ if(argc != 7){ - BLE_PRINT("ERROR:input parameter error!\n\r"); + printf("ERROR:input parameter error!\r\n"); return -1; } @@ -840,7 +844,7 @@ int ble_central_at_cmd_get(int argc, char **argv) uuid_type = atoi(argv[5]); if(uuid_type == 0){ if (strlen(argv[6]) != 2 * UUID_16_LEN){ - BLE_PRINT("ERROR:uuid length error!\n\r"); + printf("ERROR:uuid length error!\r\n"); return -1; } hex_str_to_bd_addr(strlen(argv[6]), (s8 *)argv[6], (u8 *)uuid); @@ -848,13 +852,13 @@ int ble_central_at_cmd_get(int argc, char **argv) gcs_by_uuid_char_discovery(conn_id, start_handle, end_handle, uuid16); }else if(uuid_type == 1){ if (strlen(argv[6]) != 2 * UUID_128_LEN){ - BLE_PRINT("ERROR:uuid length error!\n\r"); + printf("ERROR:uuid length error!\r\n"); return -1; } hex_str_to_bd_addr(strlen(argv[6]), (s8 *)argv[6], (u8 *)uuid); gcs_by_uuid128_char_discovery(conn_id, start_handle, end_handle, uuid); }else{ - BLE_PRINT("ERROR:uuid type error!\n\r"); + printf("ERROR:uuid type error!\r\n"); return -1; } @@ -900,10 +904,10 @@ int ble_central_at_cmd_scan(int argc, char **argv) { if (scan_enable) { if (scan_is_processing) { - BLE_PRINT("Scan is processing, please stop it first\n\r"); + printf("Scan is processing, please stop it first\r\n"); } else { scan_is_processing = 1; - BLE_PRINT("Start scan, scan_filter_policy = %d, scan_filter_duplicate = %d\n\r", scan_filter_policy, scan_filter_duplicate); + printf("Start scan, scan_filter_policy = %d, scan_filter_duplicate = %d\r\n", scan_filter_policy, scan_filter_duplicate); le_scan_set_param(GAP_PARAM_SCAN_FILTER_POLICY, sizeof(scan_filter_policy), &scan_filter_policy); le_scan_set_param(GAP_PARAM_SCAN_FILTER_DUPLICATES, sizeof(scan_filter_duplicate), &scan_filter_duplicate); ble_central_at_cmd_send_msg(3); @@ -911,16 +915,15 @@ int ble_central_at_cmd_scan(int argc, char **argv) } else { if (scan_is_processing) { ble_central_at_cmd_send_msg(2); - BLE_PRINT("Stop scan\n\r"); + printf("Stop scan\r\n"); scan_is_processing = 0; } else - BLE_PRINT("There is no scan\n\r"); + printf("There is no scan\r\n"); } } #endif -#if ((defined(CONFIG_BT_MESH_CENTRAL) && CONFIG_BT_MESH_CENTRAL) || \ - (defined(CONFIG_BT_MESH_SCATTERNET) && CONFIG_BT_MESH_SCATTERNET)) +#if ((defined(CONFIG_BT_MESH_CENTRAL) && CONFIG_BT_MESH_CENTRAL)) #if defined(CONFIG_BT_MESH_PROVISIONER_MULTIPLE_PROFILE) && CONFIG_BT_MESH_PROVISIONER_MULTIPLE_PROFILE new_state = bt_mesh_provisioner_multiple_profile_gap_dev_state; #elif defined(CONFIG_BT_MESH_DEVICE_MULTIPLE_PROFILE) && CONFIG_BT_MESH_DEVICE_MULTIPLE_PROFILE @@ -933,10 +936,10 @@ int ble_central_at_cmd_scan(int argc, char **argv) if (new_state.gap_init_state) { if (scan_enable) { if (scan_is_processing) { - BLE_PRINT("Scan is processing, please stop it first\n\r"); + printf("Scan is processing, please stop it first\r\n"); } else { scan_is_processing = 1; - BLE_PRINT("Start scan\n\r"); + printf("Start scan\r\n"); ble_central_at_cmd_send_msg(2); do { @@ -981,10 +984,10 @@ int ble_central_at_cmd_scan(int argc, char **argv) le_get_gap_param(GAP_PARAM_DEV_STATE , &new_state); } while (new_state.gap_scan_state != GAP_SCAN_STATE_SCANNING); - BLE_PRINT("Stop scan\n\r"); + printf("Stop scan\r\n"); scan_is_processing = 0; } else - BLE_PRINT("There is no scan\n\r"); + printf("There is no scan\r\n"); } } #endif @@ -1001,14 +1004,14 @@ int ble_central_at_cmd_auth(int argc, char **argv) if(strcmp(argv[1],"SEND") == 0) { if(argc != 3){ - BLE_PRINT("ERROR:input parameter error!\n\r"); + printf("ERROR:input parameter error!\r\n"); return -1; } conn_id = atoi(argv[2]); le_bond_pair(conn_id); }else if(strcmp(argv[1], "KEY") == 0){ if(argc !=4){ - BLE_PRINT("ERROR:input parameter error!\n\r"); + printf("ERROR:input parameter error!\r\n"); return -1; } conn_id = atoi(argv[2]); @@ -1020,7 +1023,7 @@ int ble_central_at_cmd_auth(int argc, char **argv) s8* str = (s8 *)argv[3]; for(unsigned int i = 0; i < strlen(argv[3]); i ++){ if((str[i ++] < '0') || (str[i ++] > '9')){ - BLE_PRINT("ERROR:input parameter error!\n\r"); + printf("ERROR:input parameter error!\r\n"); return -1; } } @@ -1028,7 +1031,7 @@ int ble_central_at_cmd_auth(int argc, char **argv) passcode = atoi(argv[3]); if (passcode > GAP_PASSCODE_MAX) { - BLE_PRINT("ERROR:passcode is out of range[0-999999] !\n\r"); + printf("ERROR:passcode is out of range[0-999999] !\r\n"); confirm = GAP_CFM_CAUSE_REJECT; } le_bond_passkey_input_confirm(conn_id, passcode, confirm); @@ -1069,11 +1072,11 @@ int ble_central_at_cmd_auth(int argc, char **argv) ret = gap_set_pairable_mode(); if(ret == GAP_CAUSE_SUCCESS) - BLE_PRINT("\n\rSet pairable mode success!\r\n"); + printf("Set pairable mode success!\r\n"); else - BLE_PRINT("\n\rSet pairable mode fail!\r\n"); + printf("Set pairable mode fail!\r\n"); }else{ - BLE_PRINT("ERROR:input parameter error!\n\r"); + printf("ERROR:input parameter error!\r\n"); return -1; } @@ -1121,26 +1124,26 @@ int ble_central_at_cmd_read(int argc, char **argv) start_handle = hex_str_to_int(strlen(argv[2]), (s8 *)argv[2]); end_handle = hex_str_to_int(strlen(argv[3]), (s8 *)argv[3]); uuid_type = atoi(argv[4]); - BLE_PRINT("conn_id = %d, start_handle = 0x%x, end_handle = 0x%x, uuid_type = %d\n\r", conn_id, start_handle, end_handle, uuid_type); + printf("conn_id = %d, start_handle = 0x%x, end_handle = 0x%x, uuid_type = %d\r\n", conn_id, start_handle, end_handle, uuid_type); if(uuid_type == 0){ if (strlen(argv[5]) != 2 * UUID_16_LEN){ - BLE_PRINT("ERROR:uuid length error!\n\r"); + printf("ERROR:uuid length error!\r\n"); return -1; } hex_str_to_bd_addr(strlen(argv[5]), (s8 *)argv[5], (u8 *)uuid); uuid16 = uuid[1]<<8 | uuid[0]; - BLE_PRINT("uuid16 = 0x%x\n\r", uuid16); + printf("uuid16 = 0x%x\r\n", uuid16); gcs_attr_read_using_uuid16(conn_id, start_handle, end_handle, uuid16); }else if(uuid_type == 1){ if (strlen(argv[5]) != 2 * UUID_128_LEN){ - BLE_PRINT("ERROR:uuid length error!\n\r"); + printf("ERROR:uuid length error!\r\n"); return -1; } hex_str_to_bd_addr(strlen(argv[5]), (s8 *)argv[5], (u8 *)uuid); gcs_attr_read_using_uuid128(conn_id, start_handle, end_handle, uuid); }else{ - BLE_PRINT("ERROR:uuid type error!\n\r"); + printf("ERROR:uuid type error!\r\n"); return -1; } @@ -1162,10 +1165,10 @@ int ble_central_at_cmd_write(int argc, char **argv) length = hex_str_to_int(strlen(argv[4]), (s8 *)argv[4]); if (length == -1) { - printf("\n\rError:value length should be hexadecimal and start with '0X' or '0x'\r\n"); + printf("Error:value length should be hexadecimal and start with '0X' or '0x'\r\n"); return -1; } else if (length == 0) { - printf("\n\rError:value length should larger than 0\r\n"); + printf("Error:value length should larger than 0\r\n"); return -1; } @@ -1269,9 +1272,11 @@ int ble_central_at_cmd_set_phy(int argc, char **argv) return cause; } #endif +#endif int ble_central_app_handle_at_cmd(uint16_t subtype, void *arg) { +#if SUPPORT_LOG_SERVICE int common_cmd_flag = 0; int argc = 0; char *argv[MAX_ARGC] = {0}; @@ -1334,5 +1339,8 @@ int ble_central_app_handle_at_cmd(uint16_t subtype, void *arg) } return common_cmd_flag; +#else + return 0; +#endif } #endif diff --git a/component/common/bluetooth/realtek/sdk/example/ble_central/ble_central_client_app.c b/component/common/bluetooth/realtek/sdk/example/ble_central/ble_central_client_app.c index acb52a03..4a2b0c9b 100644 --- a/component/common/bluetooth/realtek/sdk/example/ble_central/ble_central_client_app.c +++ b/component/common/bluetooth/realtek/sdk/example/ble_central/ble_central_client_app.c @@ -28,10 +28,7 @@ #include #include #include -#include -#include #include -#include "data_uart.h" #include "ble_central_at_cmd.h" /** @defgroup CENTRAL_CLIENT_APP Central Client Application @@ -74,14 +71,6 @@ void ble_central_app_handle_io_msg(T_IO_MSG io_msg) ble_central_app_handle_gap_msg(&io_msg); } break; -#if defined (CONFIG_BT_USER_COMMAND) && (CONFIG_BT_USER_COMMAND) - case IO_MSG_TYPE_UART: - uint8_t rx_char; - /* We handle user command informations from Data UART in this branch. */ - rx_char = (uint8_t)io_msg.subtype; - user_cmd_collect(&user_cmd_if, &rx_char, sizeof(rx_char), user_cmd_table); - break; -#endif case IO_MSG_TYPE_AT_CMD: { uint16_t subtype = io_msg.subtype; @@ -126,14 +115,14 @@ void ble_central_app_handle_dev_state_evt(T_GAP_DEV_STATE new_state, uint16_t ca T_GAP_RAND_ADDR_TYPE rand_addr_type = GAP_RAND_ADDR_RESOLVABLE; T_GAP_CAUSE result; result = le_gen_rand_addr(rand_addr_type, bt_addr); - BLE_PRINT("[%s]le_gen_rand_addr result = %x\n\r",__func__,result); + printf("[%s]le_gen_rand_addr result = %x\n\r",__func__,result); result = le_set_rand_addr(bt_addr); - BLE_PRINT("[%s]le_set_rand_addr result = %x\n\r",__func__,result); + printf("[%s]le_set_rand_addr result = %x\n\r",__func__,result); memset(bt_addr,0,sizeof(uint8_t)*6); #endif /*stack ready*/ gap_get_param(GAP_PARAM_BD_ADDR, bt_addr); - data_uart_print("local bd addr: 0x%2x:%2x:%2x:%2x:%2x:%2x\r\n", + printf("local bd addr: 0x%2x:%2x:%2x:%2x:%2x:%2x\r\n", bt_addr[5], bt_addr[4], bt_addr[3], @@ -148,12 +137,12 @@ void ble_central_app_handle_dev_state_evt(T_GAP_DEV_STATE new_state, uint16_t ca if (new_state.gap_scan_state == GAP_SCAN_STATE_IDLE) { APP_PRINT_INFO0("GAP scan stop"); - data_uart_print("GAP scan stop\r\n"); + printf("GAP scan stop\r\n"); } else if (new_state.gap_scan_state == GAP_SCAN_STATE_SCANNING) { APP_PRINT_INFO0("GAP scan start"); - data_uart_print("GAP scan start\r\n"); + printf("GAP scan start\r\n"); } } @@ -191,7 +180,7 @@ void ble_central_app_handle_conn_state_evt(uint8_t conn_id, T_GAP_CONN_STATE new disc_cause); } - data_uart_print("Disconnect conn_id %d, cause 0x%x\r\n", conn_id, disc_cause); + printf("Disconnect conn_id %d, cause 0x%x\r\n", conn_id, disc_cause); memset(&ble_central_app_link_table[conn_id], 0, sizeof(T_APP_LINK)); } break; @@ -200,7 +189,7 @@ void ble_central_app_handle_conn_state_evt(uint8_t conn_id, T_GAP_CONN_STATE new { le_get_conn_addr(conn_id, ble_central_app_link_table[conn_id].bd_addr, (void *)&ble_central_app_link_table[conn_id].bd_type); - data_uart_print("Connected success conn_id %d\r\n", conn_id); + printf("Connected success conn_id %d\r\n", conn_id); #if F_BT_LE_5_0_SET_PHY_SUPPORT { uint8_t tx_phy; @@ -208,7 +197,7 @@ void ble_central_app_handle_conn_state_evt(uint8_t conn_id, T_GAP_CONN_STATE new le_get_conn_param(GAP_PARAM_CONN_RX_PHY_TYPE, &rx_phy, conn_id); le_get_conn_param(GAP_PARAM_CONN_TX_PHY_TYPE, &tx_phy, conn_id); APP_PRINT_INFO2("GAP_CONN_STATE_CONNECTED: tx_phy %d, rx_phy %d", tx_phy, rx_phy); - data_uart_print("GAP_CONN_STATE_CONNECTED: tx_phy %d, rx_phy %d\r\n", tx_phy, rx_phy); + printf("GAP_CONN_STATE_CONNECTED: tx_phy %d, rx_phy %d\r\n", tx_phy, rx_phy); } #endif @@ -246,13 +235,13 @@ void ble_central_app_handle_authen_state_evt(uint8_t conn_id, uint8_t new_state, { if (cause == GAP_SUCCESS) { - data_uart_print("Pair success\r\n"); + printf("Pair success\r\n"); APP_PRINT_INFO0("ble_central_app_handle_authen_state_evt: GAP_AUTHEN_STATE_COMPLETE pair success"); } else { - data_uart_print("Pair failed: cause 0x%x\r\n", cause); + printf("Pair failed: cause 0x%x\r\n", cause); APP_PRINT_INFO0("ble_central_app_handle_authen_state_evt: GAP_AUTHEN_STATE_COMPLETE pair failed"); } } @@ -301,7 +290,7 @@ void ble_central_app_handle_conn_param_update_evt(uint8_t conn_id, uint8_t statu le_get_conn_param(GAP_PARAM_CONN_TIMEOUT, &conn_supervision_timeout, conn_id); APP_PRINT_INFO4("ble_central_app_handle_conn_param_update_evt update success:conn_id %d, conn_interval 0x%x, conn_slave_latency 0x%x, conn_supervision_timeout 0x%x", conn_id, conn_interval, conn_slave_latency, conn_supervision_timeout); - data_uart_print("\n\rble_central_app_handle_conn_param_update_evt update success:conn_id %d, conn_interval 0x%x, conn_slave_latency 0x%x, conn_supervision_timeout 0x%x \r\n", + printf("ble_central_app_handle_conn_param_update_evt update success:conn_id %d, conn_interval 0x%x, conn_slave_latency 0x%x, conn_supervision_timeout 0x%x \r\n", conn_id, conn_interval, conn_slave_latency, conn_supervision_timeout); } break; @@ -310,7 +299,7 @@ void ble_central_app_handle_conn_param_update_evt(uint8_t conn_id, uint8_t statu { APP_PRINT_ERROR2("ble_central_app_handle_conn_param_update_evt update failed: conn_id %d, cause 0x%x", conn_id, cause); - data_uart_print("\n\rble_central_app_handle_conn_param_update_evt update failed: conn_id %d, cause 0x%x\r\n", + printf("ble_central_app_handle_conn_param_update_evt update failed: conn_id %d, cause 0x%x\r\n", conn_id, cause); } @@ -319,7 +308,7 @@ void ble_central_app_handle_conn_param_update_evt(uint8_t conn_id, uint8_t statu case GAP_CONN_PARAM_UPDATE_STATUS_PENDING: { APP_PRINT_INFO1("ble_central_app_handle_conn_param_update_evt update pending: conn_id %d", conn_id); - data_uart_print("\n\rble_central_app_handle_conn_param_update_evt update pending: conn_id %d\r\n", conn_id); + printf("ble_central_app_handle_conn_param_update_evt update pending: conn_id %d\r\n", conn_id); } break; @@ -424,7 +413,7 @@ void ble_central_app_handle_gap_msg(T_IO_MSG *p_gap_msg) //uint32_t passkey = 888888; conn_id = gap_msg.msg_data.gap_bond_passkey_input.conn_id; APP_PRINT_INFO1("GAP_MSG_LE_BOND_PASSKEY_INPUT: conn_id %d", conn_id); - data_uart_print("GAP_MSG_LE_BOND_PASSKEY_INPUT: conn_id %d\r\n", conn_id); + printf("GAP_MSG_LE_BOND_PASSKEY_INPUT: conn_id %d\r\n", conn_id); //le_bond_passkey_input_confirm(conn_id, passkey, GAP_CFM_CAUSE_ACCEPT); } break; @@ -479,8 +468,8 @@ void ble_central_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) APP_PRINT_TRACE2("ble_central_app_parse_scan_info: AD Structure Info: AD type 0x%x, AD Data Length %d", type, length - 1); -// BLE_PRINT("ble_central_app_parse_scan_info: AD Structure Info: AD type 0x%x, AD Data Length %d\n\r", type, -// length - 1); +// printf("ble_central_app_parse_scan_info: AD Structure Info: AD type 0x%x, AD Data Length %d\r\n", type, +// length - 1); switch (type) @@ -494,7 +483,7 @@ void ble_central_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) /* (flags & 0x10) -- Simultaneous LE and BR/EDR to Same Device Capable (Host) */ uint8_t flags = scan_info->data[pos + 1]; APP_PRINT_INFO1("GAP_ADTYPE_FLAGS: 0x%x", flags); - BLE_PRINT("GAP_ADTYPE_FLAGS: 0x%x\n\r", flags); + printf("GAP_ADTYPE_FLAGS: 0x%x\r\n", flags); } break; @@ -509,8 +498,8 @@ void ble_central_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) while (i >= 2) { APP_PRINT_INFO1("GAP_ADTYPE_16BIT_XXX: 0x%x", *p_uuid); - BLE_PRINT("GAP_ADTYPE_16BIT_XXX: 0x%x\n\r", *p_uuid); - p_uuid ++; + printf("GAP_ADTYPE_16BIT_XXX: 0x%x\r\n", *p_uuid); + p_uuid ++; i -= 2; } } @@ -525,8 +514,8 @@ void ble_central_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) while (i >= 4) { APP_PRINT_INFO1("GAP_ADTYPE_32BIT_XXX: 0x%x", *p_uuid); - BLE_PRINT("GAP_ADTYPE_32BIT_XXX: 0x%x\n\r", (unsigned int)*p_uuid); - p_uuid ++; + printf("GAP_ADTYPE_32BIT_XXX: 0x%x\r\n", (unsigned int)*p_uuid); + p_uuid ++; i -= 4; } @@ -540,8 +529,8 @@ void ble_central_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) uint32_t *p_uuid = (uint32_t *)(buffer); APP_PRINT_INFO4("GAP_ADTYPE_128BIT_XXX: 0x%8.8x%8.8x%8.8x%8.8x", p_uuid[3], p_uuid[2], p_uuid[1], p_uuid[0]); - BLE_PRINT("GAP_ADTYPE_128BIT_XXX: 0x%8.8x%8.8x%8.8x%8.8x\n\r", - (unsigned int)p_uuid[3], (unsigned int)p_uuid[2], (unsigned int)p_uuid[1], (unsigned int)p_uuid[0]); + printf("GAP_ADTYPE_128BIT_XXX: 0x%8.8x%8.8x%8.8x%8.8x\r\n", + (unsigned int)p_uuid[3], (unsigned int)p_uuid[2], (unsigned int)p_uuid[1], (unsigned int)p_uuid[0]); } break; @@ -551,7 +540,7 @@ void ble_central_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) { buffer[length - 1] = '\0'; APP_PRINT_INFO1("GAP_ADTYPE_LOCAL_NAME_XXX: %s", TRACE_STRING(buffer)); - BLE_PRINT("GAP_ADTYPE_LOCAL_NAME_XXX: %s\n\r", buffer); + printf("GAP_ADTYPE_LOCAL_NAME_XXX: %s\r\n", buffer); } break; @@ -559,7 +548,7 @@ void ble_central_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) case GAP_ADTYPE_POWER_LEVEL: { APP_PRINT_INFO1("GAP_ADTYPE_POWER_LEVEL: 0x%x", scan_info->data[pos + 1]); - BLE_PRINT("GAP_ADTYPE_POWER_LEVEL: 0x%x\n\r", scan_info->data[pos + 1]); + printf("GAP_ADTYPE_POWER_LEVEL: 0x%x\r\n", scan_info->data[pos + 1]); } break; @@ -570,8 +559,8 @@ void ble_central_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) uint16_t *p_max = p_min + 1; APP_PRINT_INFO2("GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE: 0x%x - 0x%x", *p_min, *p_max); - BLE_PRINT("GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE: 0x%x - 0x%x\n\r", *p_min, - *p_max); + printf("GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE: 0x%x - 0x%x\r\n", *p_min, + *p_max); } break; @@ -583,8 +572,8 @@ void ble_central_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) APP_PRINT_INFO3("GAP_ADTYPE_SERVICE_DATA: UUID 0x%x, len %d, data %b", *p_uuid, data_len, TRACE_BINARY(data_len, &buffer[2])); - BLE_PRINT("GAP_ADTYPE_SERVICE_DATA: UUID 0x%x, len %d\n\r", *p_uuid, - data_len); + printf("GAP_ADTYPE_SERVICE_DATA: UUID 0x%x, len %d\r\n", *p_uuid, + data_len); } break; @@ -592,7 +581,7 @@ void ble_central_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) { uint16_t *p_appearance = (uint16_t *)(buffer); APP_PRINT_INFO1("GAP_ADTYPE_APPEARANCE: %d", *p_appearance); - BLE_PRINT("GAP_ADTYPE_APPEARANCE: %d\n\r", *p_appearance); + printf("GAP_ADTYPE_APPEARANCE: %d\r\n", *p_appearance); } break; @@ -603,8 +592,8 @@ void ble_central_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) uint16_t *p_company_id = (uint16_t *)(buffer); APP_PRINT_INFO3("GAP_ADTYPE_MANUFACTURER_SPECIFIC: company_id 0x%x, len %d, data %b", *p_company_id, data_len, TRACE_BINARY(data_len, &buffer[2])); - BLE_PRINT("GAP_ADTYPE_MANUFACTURER_SPECIFIC: company_id 0x%x, len %d\n\r", - *p_company_id, data_len); + printf("GAP_ADTYPE_MANUFACTURER_SPECIFIC: company_id 0x%x, len %d\r\n", + *p_company_id, data_len); } break; @@ -615,8 +604,8 @@ void ble_central_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) for (i = 0; i < (length - 1); i++) { - APP_PRINT_INFO1(" AD Data: Unhandled Data = 0x%x", scan_info->data[pos + i]); -// BLE_PRINT(" AD Data: Unhandled Data = 0x%x\n\r", scan_info->data[pos + i]); + APP_PRINT_INFO1(" AD Data: Unhandled Data = 0x%x", scan_info->data[pos + 1 + i]); +// printf(" AD Data: Unhandled Data = 0x%x\r\n", scan_info->data[pos + 1 + i]); } } @@ -624,7 +613,10 @@ void ble_central_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) } } - pos += length; + if (pos + length > 0xFF) //Avoid pos + length overflow uint8_t + pos = 0xFF; + else + pos += length; } } /** @@ -658,8 +650,8 @@ T_APP_RESULT ble_central_app_gap_callback(uint8_t cb_type, void *p_cb_data) sprintf(remote_addr_type,"%s",(p_data->p_le_scan_info->remote_addr_type == GAP_REMOTE_ADDR_LE_PUBLIC)? "public": (p_data->p_le_scan_info->remote_addr_type == GAP_REMOTE_ADDR_LE_RANDOM)? "random":"unknown"); - BLE_PRINT("ADVType\t\t\t| AddrType\t|%s\t\t\t|rssi\n\r","BT_Addr"); - BLE_PRINT("%s\t\t%s\t"BD_ADDR_FMT"\t%d\n\r",adv_type,remote_addr_type,BD_ADDR_ARG(p_data->p_le_scan_info->bd_addr), + printf("ADVType\t\t\t| AddrType\t|%s\t\t\t|rssi\r\n","BT_Addr"); + printf("%s\t\t%s\t"BD_ADDR_FMT"\t%d\r\n",adv_type,remote_addr_type,BD_ADDR_ARG(p_data->p_le_scan_info->bd_addr), p_data->p_le_scan_info->rssi); ble_central_app_parse_scan_info(p_data->p_le_scan_info); @@ -672,7 +664,7 @@ T_APP_RESULT ble_central_app_gap_callback(uint8_t cb_type, void *p_cb_data) p_data->p_le_conn_update_ind->conn_interval_min, p_data->p_le_conn_update_ind->conn_latency, p_data->p_le_conn_update_ind->supervision_timeout); - data_uart_print("GAP_MSG_LE_CONN_UPDATE_IND: conn_id %d, conn_interval_max 0x%x, conn_interval_min 0x%x, conn_latency 0x%x,supervision_timeout 0x%x", + printf("GAP_MSG_LE_CONN_UPDATE_IND: conn_id %d, conn_interval_max 0x%x, conn_interval_min 0x%x, conn_latency 0x%x,supervision_timeout 0x%x\r\n", p_data->p_le_conn_update_ind->conn_id, p_data->p_le_conn_update_ind->conn_interval_max, p_data->p_le_conn_update_ind->conn_interval_min, @@ -689,7 +681,7 @@ T_APP_RESULT ble_central_app_gap_callback(uint8_t cb_type, void *p_cb_data) p_data->p_le_phy_update_info->cause, p_data->p_le_phy_update_info->rx_phy, p_data->p_le_phy_update_info->tx_phy); - data_uart_print("GAP_MSG_LE_PHY_UPDATE_INFO:conn_id %d, cause 0x%x, rx_phy %d, tx_phy %d\r\n", + printf("GAP_MSG_LE_PHY_UPDATE_INFO:conn_id %d, cause 0x%x, rx_phy %d, tx_phy %d\r\n", p_data->p_le_phy_update_info->conn_id, p_data->p_le_phy_update_info->cause, p_data->p_le_phy_update_info->rx_phy, @@ -709,12 +701,12 @@ T_APP_RESULT ble_central_app_gap_callback(uint8_t cb_type, void *p_cb_data) if (remote_feats[LE_SUPPORT_FEATURES_MASK_ARRAY_INDEX1] & LE_SUPPORT_FEATURES_LE_2M_MASK_BIT) { APP_PRINT_INFO0("GAP_MSG_LE_REMOTE_FEATS_INFO: support 2M"); - data_uart_print("GAP_MSG_LE_REMOTE_FEATS_INFO: support 2M\r\n"); + printf("GAP_MSG_LE_REMOTE_FEATS_INFO: support 2M\r\n"); } if (remote_feats[LE_SUPPORT_FEATURES_MASK_ARRAY_INDEX1] & LE_SUPPORT_FEATURES_LE_CODED_PHY_MASK_BIT) { APP_PRINT_INFO0("GAP_MSG_LE_REMOTE_FEATS_INFO: support CODED"); - data_uart_print("GAP_MSG_LE_REMOTE_FEATS_INFO: support CODED\r\n"); + printf("GAP_MSG_LE_REMOTE_FEATS_INFO: support CODED\r\n"); } } } @@ -725,7 +717,7 @@ T_APP_RESULT ble_central_app_gap_callback(uint8_t cb_type, void *p_cb_data) APP_PRINT_INFO2("GAP_MSG_LE_MODIFY_WHITE_LIST: operation 0x%x, cause 0x%x", p_data->p_le_modify_white_list_rsp->operation, p_data->p_le_modify_white_list_rsp->cause); - data_uart_print("GAP_MSG_LE_MODIFY_WHITE_LIST: operation 0x%x, cause 0x%x\r\n", + printf("GAP_MSG_LE_MODIFY_WHITE_LIST: operation 0x%x, cause 0x%x\r\n", p_data->p_le_modify_white_list_rsp->operation, p_data->p_le_modify_white_list_rsp->cause); break; @@ -762,7 +754,7 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE i, p_result_table->result_data.srv_uuid16_disc_data.att_handle, p_result_table->result_data.srv_uuid16_disc_data.end_group_handle, p_result_table->result_data.srv_uuid16_disc_data.uuid16); - BLE_PRINT("ALL SRV UUID16[%d]: service range: 0x%x-0x%x, uuid16 0x%x\n\r", + printf("ALL SRV UUID16[%d]: service range: 0x%x-0x%x, uuid16 0x%x\r\n", i, p_result_table->result_data.srv_uuid16_disc_data.att_handle, p_result_table->result_data.srv_uuid16_disc_data.end_group_handle, p_result_table->result_data.srv_uuid16_disc_data.uuid16); @@ -772,7 +764,7 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE i, p_result_table->result_data.srv_uuid128_disc_data.att_handle, p_result_table->result_data.srv_uuid128_disc_data.end_group_handle, TRACE_BINARY(16, p_result_table->result_data.srv_uuid128_disc_data.uuid128)); - BLE_PRINT("ALL SRV UUID128[%d]: service range: 0x%x-0x%x, service="UUID_128_FORMAT"\n\r", + printf("ALL SRV UUID128[%d]: service range: 0x%x-0x%x, service="UUID_128_FORMAT"\r\n", i, p_result_table->result_data.srv_uuid128_disc_data.att_handle, p_result_table->result_data.srv_uuid128_disc_data.end_group_handle, UUID_128(p_result_table->result_data.srv_uuid128_disc_data.uuid128)); @@ -781,7 +773,7 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE default: APP_PRINT_ERROR0("Invalid Discovery Result Type!"); - BLE_PRINT("Invalid Discovery Result Type!\n\r"); + printf("Invalid Discovery Result Type!\r\n"); break; } } @@ -790,7 +782,7 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE case GCS_BY_UUID128_SRV_DISCOV: APP_PRINT_INFO2("conn_id %d, GCS_BY_UUID128_SRV_DISCOV, is_success %d", conn_id, discov_result.is_success); - BLE_PRINT("conn_id %d, GCS_BY_UUID128_SRV_DISCOV, is_success %d\n\r", + printf("conn_id %d, GCS_BY_UUID128_SRV_DISCOV, is_success %d\r\n", conn_id, discov_result.is_success); for (i = 0; i < discov_result.result_num; i++) @@ -802,7 +794,7 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE APP_PRINT_INFO3("SRV DATA[%d]: service range: 0x%x-0x%x", i, p_result_table->result_data.srv_disc_data.att_handle, p_result_table->result_data.srv_disc_data.end_group_handle); - BLE_PRINT("SRV DATA[%d]: service range: 0x%x-0x%x\n\r", + printf("SRV DATA[%d]: service range: 0x%x-0x%x\r\n", i, p_result_table->result_data.srv_disc_data.att_handle, p_result_table->result_data.srv_disc_data.end_group_handle); @@ -810,7 +802,7 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE default: APP_PRINT_ERROR0("Invalid Discovery Result Type!"); - BLE_PRINT("Invalid Discovery Result Type!\n\r"); + printf("Invalid Discovery Result Type!\r\n"); break; } } @@ -819,7 +811,7 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE case GCS_BY_UUID_SRV_DISCOV: APP_PRINT_INFO2("conn_id %d, GCS_BY_UUID_SRV_DISCOV, is_success %d", conn_id, discov_result.is_success); - BLE_PRINT("conn_id %d, GCS_BY_UUID_SRV_DISCOV, is_success %d\n\r", + printf("conn_id %d, GCS_BY_UUID_SRV_DISCOV, is_success %d\r\n", conn_id, discov_result.is_success); for (i = 0; i < discov_result.result_num; i++) @@ -831,7 +823,7 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE APP_PRINT_INFO3("SRV DATA[%d]: service range: 0x%x-0x%x", i, p_result_table->result_data.srv_disc_data.att_handle, p_result_table->result_data.srv_disc_data.end_group_handle); - BLE_PRINT("SRV DATA[%d]: service range: 0x%x-0x%x\n\r", + printf("SRV DATA[%d]: service range: 0x%x-0x%x\r\n", i, p_result_table->result_data.srv_disc_data.att_handle, p_result_table->result_data.srv_disc_data.end_group_handle); @@ -839,7 +831,7 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE default: APP_PRINT_ERROR0("Invalid Discovery Result Type!"); - BLE_PRINT("Invalid Discovery Result Type!\n\r"); + printf("Invalid Discovery Result Type!\r\n"); break; } } @@ -848,7 +840,7 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE case GCS_ALL_CHAR_DISCOV: APP_PRINT_INFO2("conn_id %d, GCS_ALL_CHAR_DISCOV, is_success %d", conn_id, discov_result.is_success); - BLE_PRINT("conn_id %d, GCS_ALL_CHAR_DISCOV, is_success %d\n\r", + printf("conn_id %d, GCS_ALL_CHAR_DISCOV, is_success %d\r\n", conn_id, discov_result.is_success); for (i = 0; i < discov_result.result_num; i++) @@ -869,12 +861,12 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE properties & GATT_CHAR_PROP_WRITE_NO_RSP, properties & GATT_CHAR_PROP_WRITE, properties & GATT_CHAR_PROP_NOTIFY); - BLE_PRINT("CHAR UUID16[%d]: decl_handle 0x%x, properties 0x%x, value_handle 0x%x, uuid16 0x%x\n\r", + printf("CHAR UUID16[%d]: decl_handle 0x%x, properties 0x%x, value_handle 0x%x, uuid16 0x%x\r\n", i, p_result_table->result_data.char_uuid16_disc_data.decl_handle, p_result_table->result_data.char_uuid16_disc_data.properties, p_result_table->result_data.char_uuid16_disc_data.value_handle, p_result_table->result_data.char_uuid16_disc_data.uuid16); - BLE_PRINT("properties:indicate %d, read %d, write cmd %d, write %d, notify %d\n\r", + printf("properties:indicate %d, read %d, write cmd %d, write %d, notify %d\r\n", properties & GATT_CHAR_PROP_INDICATE, properties & GATT_CHAR_PROP_READ, properties & GATT_CHAR_PROP_WRITE_NO_RSP, @@ -898,12 +890,12 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE properties & GATT_CHAR_PROP_WRITE, properties & GATT_CHAR_PROP_NOTIFY ); - BLE_PRINT("CHAR UUID128[%d]: decl hndl=0x%x, prop=0x%x, value hndl=0x%x, uuid128="UUID_128_FORMAT"\n\r", + printf("CHAR UUID128[%d]: decl hndl=0x%x, prop=0x%x, value hndl=0x%x, uuid128="UUID_128_FORMAT"\r\n", i, p_result_table->result_data.char_uuid128_disc_data.decl_handle, p_result_table->result_data.char_uuid128_disc_data.properties, p_result_table->result_data.char_uuid128_disc_data.value_handle, UUID_128(p_result_table->result_data.char_uuid128_disc_data.uuid128)); - BLE_PRINT("properties:indicate %d, read %d, write cmd %d, write %d, notify %d\n\r", + printf("properties:indicate %d, read %d, write cmd %d, write %d, notify %d\r\n", properties & GATT_CHAR_PROP_INDICATE, properties & GATT_CHAR_PROP_READ, properties & GATT_CHAR_PROP_WRITE_NO_RSP, @@ -914,7 +906,7 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE break; default: APP_PRINT_ERROR0("Invalid Discovery Result Type!"); - BLE_PRINT("Invalid Discovery Result Type!\n\r"); + printf("Invalid Discovery Result Type!\r\n"); break; } } @@ -923,7 +915,7 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE case GCS_BY_UUID_CHAR_DISCOV: APP_PRINT_INFO2("conn_id %d, GCS_BY_UUID_CHAR_DISCOV, is_success %d", conn_id, discov_result.is_success); - BLE_PRINT("conn_id %d, GCS_BY_UUID_CHAR_DISCOV, is_success %d\n\r", + printf("conn_id %d, GCS_BY_UUID_CHAR_DISCOV, is_success %d\r\n", conn_id, discov_result.is_success); for (i = 0; i < discov_result.result_num; i++) @@ -945,12 +937,12 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE properties & GATT_CHAR_PROP_WRITE, properties & GATT_CHAR_PROP_NOTIFY ); - BLE_PRINT("UUID16 CHAR[%d]: Characteristics by uuid16, decl hndl=0x%x, prop=0x%x, value hndl=0x%x, uuid16=<0x%x>\n\r", + printf("UUID16 CHAR[%d]: Characteristics by uuid16, decl hndl=0x%x, prop=0x%x, value hndl=0x%x, uuid16=<0x%x>\r\n", i, p_result_table->result_data.char_uuid16_disc_data.decl_handle, p_result_table->result_data.char_uuid16_disc_data.properties, p_result_table->result_data.char_uuid16_disc_data.value_handle, p_result_table->result_data.char_uuid16_disc_data.uuid16); - BLE_PRINT("properties:indicate %d, read %d, write cmd %d, write %d, notify %d\n\r", + printf("properties:indicate %d, read %d, write cmd %d, write %d, notify %d\r\n", properties & GATT_CHAR_PROP_INDICATE, properties & GATT_CHAR_PROP_READ, properties & GATT_CHAR_PROP_WRITE_NO_RSP, @@ -962,7 +954,7 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE default: APP_PRINT_ERROR0("Invalid Discovery Result Type!"); - BLE_PRINT("Invalid Discovery Result Type!"); + printf("Invalid Discovery Result Type!\r\n"); break; } } @@ -971,7 +963,7 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE case GCS_BY_UUID128_CHAR_DISCOV: APP_PRINT_INFO2("conn_id %d, GCS_BY_UUID128_CHAR_DISCOV, is_success %d", conn_id, discov_result.is_success); - BLE_PRINT("conn_id %d, GCS_BY_UUID128_CHAR_DISCOV, is_success %d\n\r", + printf("conn_id %d, GCS_BY_UUID128_CHAR_DISCOV, is_success %d\r\n", conn_id, discov_result.is_success); for (i = 0; i < discov_result.result_num; i++) @@ -993,12 +985,12 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE properties & GATT_CHAR_PROP_WRITE, properties & GATT_CHAR_PROP_NOTIFY ); - BLE_PRINT("UUID128 CHAR[%d]: Characteristics by uuid128, decl hndl=0x%x, prop=0x%x, value hndl=0x%x, uuid128="UUID_128_FORMAT"\n\r", + printf("UUID128 CHAR[%d]: Characteristics by uuid128, decl hndl=0x%x, prop=0x%x, value hndl=0x%x, uuid128="UUID_128_FORMAT"\r\n", i, p_result_table->result_data.char_uuid128_disc_data.decl_handle, p_result_table->result_data.char_uuid128_disc_data.properties, p_result_table->result_data.char_uuid128_disc_data.value_handle, UUID_128(p_result_table->result_data.char_uuid128_disc_data.uuid128)); - BLE_PRINT("properties:indicate %d, read %d, write cmd %d, write %d, notify %d\n\r", + printf("properties:indicate %d, read %d, write cmd %d, write %d, notify %d\r\n", properties & GATT_CHAR_PROP_INDICATE, properties & GATT_CHAR_PROP_READ, properties & GATT_CHAR_PROP_WRITE_NO_RSP, @@ -1010,7 +1002,7 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE default: APP_PRINT_ERROR0("Invalid Discovery Result Type!"); - BLE_PRINT("Invalid Discovery Result Type!\n\r"); + printf("Invalid Discovery Result Type!\r\n"); break; } } @@ -1019,7 +1011,7 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE case GCS_ALL_CHAR_DESC_DISCOV: APP_PRINT_INFO2("conn_id %d, GCS_ALL_CHAR_DESC_DISCOV, is_success %d\r\n", conn_id, discov_result.is_success); - BLE_PRINT("conn_id %d, GCS_ALL_CHAR_DESC_DISCOV, is_success %d\n\r", + printf("conn_id %d, GCS_ALL_CHAR_DESC_DISCOV, is_success %d\r\n", conn_id, discov_result.is_success); for (i = 0; i < discov_result.result_num; i++) { @@ -1030,7 +1022,7 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE APP_PRINT_INFO3("DESC UUID16[%d]: Descriptors handle=0x%x, uuid16=<0x%x>", i, p_result_table->result_data.char_desc_uuid16_disc_data.handle, p_result_table->result_data.char_desc_uuid16_disc_data.uuid16); - BLE_PRINT("DESC UUID16[%d]: Descriptors handle=0x%x, uuid16=<0x%x>\n\r", + printf("DESC UUID16[%d]: Descriptors handle=0x%x, uuid16=<0x%x>\r\n", i, p_result_table->result_data.char_desc_uuid16_disc_data.handle, p_result_table->result_data.char_desc_uuid16_disc_data.uuid16); @@ -1039,14 +1031,14 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE APP_PRINT_INFO3("DESC UUID128[%d]: Descriptors handle=0x%x, uuid128=<%b>", i, p_result_table->result_data.char_desc_uuid128_disc_data.handle, TRACE_BINARY(16, p_result_table->result_data.char_desc_uuid128_disc_data.uuid128)); - BLE_PRINT("DESC UUID128[%d]: Descriptors handle=0x%x, uuid128="UUID_128_FORMAT"\n\r", + printf("DESC UUID128[%d]: Descriptors handle=0x%x, uuid128="UUID_128_FORMAT"\r\n", i, p_result_table->result_data.char_desc_uuid128_disc_data.handle, UUID_128(p_result_table->result_data.char_desc_uuid128_disc_data.uuid128)); break; default: APP_PRINT_ERROR0("Invalid Discovery Result Type!"); - BLE_PRINT("Invalid Discovery Result Type!\n\r"); + printf("Invalid Discovery Result Type!\r\n"); break; } } @@ -1055,7 +1047,7 @@ void ble_central_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY_RE default: APP_PRINT_ERROR2("Invalid disc type: conn_id %d, discov_type %d", conn_id, discov_result.discov_type); - BLE_PRINT("Invalid disc type: conn_id %d, discov_type %d\n\r", + printf("Invalid disc type: conn_id %d, discov_type %d\r\n", conn_id, discov_result.discov_type); break; } @@ -1085,7 +1077,7 @@ T_APP_RESULT ble_central_gcs_client_callback(T_CLIENT_ID client_id, uint8_t conn p_gcs_cb_data->cb_content.read_result.cause, p_gcs_cb_data->cb_content.read_result.handle, p_gcs_cb_data->cb_content.read_result.value_size); - data_uart_print("READ RESULT: cause 0x%x, handle 0x%x, value_len %d\n\r", + printf("READ RESULT: cause 0x%x, handle 0x%x, value_len %d\r\n", p_gcs_cb_data->cb_content.read_result.cause, p_gcs_cb_data->cb_content.read_result.handle, p_gcs_cb_data->cb_content.read_result.value_size); @@ -1095,10 +1087,10 @@ T_APP_RESULT ble_central_gcs_client_callback(T_CLIENT_ID client_id, uint8_t conn APP_PRINT_INFO1("READ VALUE: %b", TRACE_BINARY(p_gcs_cb_data->cb_content.read_result.value_size, p_gcs_cb_data->cb_content.read_result.p_value)); - data_uart_print("READ VALUE: "); + printf("READ VALUE: "); for(int i=0; i< p_gcs_cb_data->cb_content.read_result.value_size; i++) - data_uart_print("0x%02x ", *(p_gcs_cb_data->cb_content.read_result.p_value + i)); - data_uart_print("\n\r"); + printf("0x%02x ", *(p_gcs_cb_data->cb_content.read_result.p_value + i)); + printf("\r\n"); } break; case GCS_CLIENT_CB_TYPE_WRITE_RESULT: @@ -1106,7 +1098,7 @@ T_APP_RESULT ble_central_gcs_client_callback(T_CLIENT_ID client_id, uint8_t conn p_gcs_cb_data->cb_content.write_result.cause, p_gcs_cb_data->cb_content.write_result.handle, p_gcs_cb_data->cb_content.write_result.type); - data_uart_print("WRITE RESULT: cause 0x%x, handle 0x%x, type %d\n\r", + printf("WRITE RESULT: cause 0x%x, handle 0x%x, type %d\r\n", p_gcs_cb_data->cb_content.write_result.cause, p_gcs_cb_data->cb_content.write_result.handle, p_gcs_cb_data->cb_content.write_result.type); @@ -1120,13 +1112,13 @@ T_APP_RESULT ble_central_gcs_client_callback(T_CLIENT_ID client_id, uint8_t conn APP_PRINT_INFO1("INDICATION: value %b", TRACE_BINARY(p_gcs_cb_data->cb_content.notif_ind.value_size, p_gcs_cb_data->cb_content.notif_ind.p_value)); - data_uart_print("INDICATION: handle 0x%x, value_size %d\r\n", + printf("INDICATION: handle 0x%x, value_size %d\r\n", p_gcs_cb_data->cb_content.notif_ind.handle, p_gcs_cb_data->cb_content.notif_ind.value_size); - data_uart_print("INDICATION: value "); + printf("INDICATION: value "); for(int i=0; i < p_gcs_cb_data->cb_content.notif_ind.value_size; i++) - data_uart_print("0x%02x ", *(p_gcs_cb_data->cb_content.notif_ind.p_value+ i)); - data_uart_print("\n\r"); + printf("0x%02x ", *(p_gcs_cb_data->cb_content.notif_ind.p_value+ i)); + printf("\r\nr"); } else { @@ -1136,13 +1128,13 @@ T_APP_RESULT ble_central_gcs_client_callback(T_CLIENT_ID client_id, uint8_t conn APP_PRINT_INFO1("NOTIFICATION: value %b", TRACE_BINARY(p_gcs_cb_data->cb_content.notif_ind.value_size, p_gcs_cb_data->cb_content.notif_ind.p_value)); - data_uart_print("NOTIFICATION: handle 0x%x, value_size %d\r\n", + printf("NOTIFICATION: handle 0x%x, value_size %d\r\n", p_gcs_cb_data->cb_content.notif_ind.handle, p_gcs_cb_data->cb_content.notif_ind.value_size); - data_uart_print("NOTIFICATION: value "); + printf("NOTIFICATION: value "); for(int j=0; j < p_gcs_cb_data->cb_content.notif_ind.value_size; j++) - data_uart_print("0x%02x ", *(p_gcs_cb_data->cb_content.notif_ind.p_value+ j)); - data_uart_print("\n\r"); + printf("0x%02x ", *(p_gcs_cb_data->cb_content.notif_ind.p_value+ j)); + printf("\r\n"); } break; default: diff --git a/component/common/bluetooth/realtek/sdk/example/ble_central/ble_central_client_app.h b/component/common/bluetooth/realtek/sdk/example/ble_central/ble_central_client_app.h index 439c9b8c..0248085d 100644 --- a/component/common/bluetooth/realtek/sdk/example/ble_central/ble_central_client_app.h +++ b/component/common/bluetooth/realtek/sdk/example/ble_central/ble_central_client_app.h @@ -26,7 +26,6 @@ extern "C" { #include -#define BLE_PRINT printf #define BD_ADDR_FMT "%02x:%02x:%02x:%02x:%02x:%02x" #define BD_ADDR_ARG(x) (x)[5],(x)[4],(x)[3],(x)[2],(x)[1],(x)[0] #define UUID_128_FORMAT "0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X" diff --git a/component/common/bluetooth/realtek/sdk/example/ble_peripheral/ble_app_main.c b/component/common/bluetooth/realtek/sdk/example/ble_peripheral/ble_app_main.c index d44274c5..2952dd95 100644 --- a/component/common/bluetooth/realtek/sdk/example/ble_peripheral/ble_app_main.c +++ b/component/common/bluetooth/realtek/sdk/example/ble_peripheral/ble_app_main.c @@ -214,7 +214,9 @@ void app_le_gap_init(void) #endif #elif (F_BT_LE_USE_RANDOM_ADDR==2) && F_BT_LE_LOCAL_IRK_SETTING_SUPPORT uint8_t irk_auto = true; + uint8_t local_bd_type = GAP_LOCAL_ADDR_LE_RANDOM; le_bond_set_param(GAP_PARAM_BOND_GEN_LOCAL_IRK_AUTO, sizeof(uint8_t), &irk_auto); + le_adv_set_param(GAP_PARAM_ADV_LOCAL_ADDR_TYPE, sizeof(local_bd_type), &local_bd_type); #endif #if F_BT_LE_5_0_SET_PHY_SUPPORT uint8_t phys_prefer = GAP_PHYS_PREFER_ALL; @@ -315,7 +317,7 @@ int ble_app_init(void) le_get_gap_param(GAP_PARAM_DEV_STATE , &new_state); if (new_state.gap_init_state == GAP_INIT_STATE_STACK_READY) { //bt_stack_already_on = 1; - printf("[BLE Peripheral]BT Stack already on\n\r"); + printf("[BLE Peripheral]BT Stack already on\r\n"); return 0; } else @@ -343,14 +345,14 @@ void ble_app_deinit(void) T_GAP_DEV_STATE state; le_get_gap_param(GAP_PARAM_DEV_STATE , &state); if (state.gap_init_state != GAP_INIT_STATE_STACK_READY) { - printf("[BLE Peripheral]BT Stack is not running\n\r"); + printf("[BLE Peripheral]BT Stack is not running\r\n"); } #if F_BT_DEINIT else { bte_deinit(); bt_trace_uninit(); memset(&gap_dev_state, 0, sizeof(T_GAP_DEV_STATE)); - printf("[BLE Peripheral]BT Stack deinitalized\n\r"); + printf("[BLE Peripheral]BT Stack deinitalized\r\n"); } #endif } diff --git a/component/common/bluetooth/realtek/sdk/example/ble_peripheral/ble_peripheral_at_cmd.c b/component/common/bluetooth/realtek/sdk/example/ble_peripheral/ble_peripheral_at_cmd.c index 3b0c14c9..5105f387 100644 --- a/component/common/bluetooth/realtek/sdk/example/ble_peripheral/ble_peripheral_at_cmd.c +++ b/component/common/bluetooth/realtek/sdk/example/ble_peripheral/ble_peripheral_at_cmd.c @@ -2,9 +2,11 @@ #if ((defined(CONFIG_BT_PERIPHERAL) && CONFIG_BT_PERIPHERAL) || \ (defined(CONFIG_BT_MESH_PROVISIONER_MULTIPLE_PROFILE) && CONFIG_BT_MESH_PROVISIONER_MULTIPLE_PROFILE) || \ (defined(CONFIG_BT_MESH_DEVICE_MULTIPLE_PROFILE) && CONFIG_BT_MESH_DEVICE_MULTIPLE_PROFILE)) +#include "platform_opts.h" +#include +#if SUPPORT_LOG_SERVICE #include "log_service.h" #include "atcmd_bt.h" -#include #include "gap.h" #include "gap_adv.h" #include "gap_bond_le.h" @@ -16,7 +18,6 @@ #include "os_mem.h" #include "profile_server.h" -#define BLE_PRINT printf #if defined(CONFIG_BT_PERIPHERAL) && CONFIG_BT_PERIPHERAL extern void *evt_queue_handle; @@ -87,18 +88,18 @@ void ble_peripheral_at_cmd_send_msg(uint16_t sub_type) #if defined(CONFIG_BT_PERIPHERAL) && CONFIG_BT_PERIPHERAL if (evt_queue_handle != NULL && io_queue_handle != NULL) { if (os_msg_send(io_queue_handle, &io_msg, 0) == false) { - BLE_PRINT("ble peripheral at cmd send msg fail: subtype 0x%x", io_msg.subtype); + printf("ble peripheral at cmd send msg fail: subtype 0x%x\r\n", io_msg.subtype); } else if (os_msg_send(evt_queue_handle, &event, 0) == false) { - BLE_PRINT("ble peripheral at cmd send event fail: subtype 0x%x", io_msg.subtype); + printf("ble peripheral at cmd send event fail: subtype 0x%x\r\n", io_msg.subtype); } } #endif #if defined(CONFIG_BT_SCATTERNET) && CONFIG_BT_SCATTERNET if (ble_scatternet_evt_queue_handle != NULL && ble_scatternet_io_queue_handle != NULL) { if (os_msg_send(ble_scatternet_io_queue_handle, &io_msg, 0) == false) { - BLE_PRINT("ble peripheral at cmd send msg fail: subtype 0x%x", io_msg.subtype); + printf("ble peripheral at cmd send msg fail: subtype 0x%x\r\n", io_msg.subtype); } else if (os_msg_send(ble_scatternet_evt_queue_handle, &event, 0) == false) { - BLE_PRINT("ble peripheral at cmd send event fail: subtype 0x%x", io_msg.subtype); + printf("ble peripheral at cmd send event fail: subtype 0x%x\r\n", io_msg.subtype); } } #endif @@ -163,14 +164,14 @@ int ble_peripheral_at_cmd_auth(int argc, char **argv) if(strcmp(argv[1],"SEND") == 0) { if(argc != 3){ - BLE_PRINT("ERROR:input parameter error!\n\r"); + printf("ERROR:input parameter error!\r\n"); return -1; } conn_id = atoi(argv[2]); le_bond_pair(conn_id); }else if(strcmp(argv[1], "KEY") == 0){ if(argc !=4){ - BLE_PRINT("ERROR:input parameter error!\n\r"); + printf("ERROR:input parameter error!\r\n"); return -1; } conn_id = atoi(argv[2]); @@ -182,7 +183,7 @@ int ble_peripheral_at_cmd_auth(int argc, char **argv) s8* str = (s8 *)argv[3]; for(unsigned int i = 0; i < strlen(argv[3]); i ++){ if((str[i ++] < '0') || (str[i ++] > '9')){ - BLE_PRINT("ERROR:input parameter error!\n\r"); + printf("ERROR:input parameter error!\r\n"); return -1; } } @@ -190,7 +191,7 @@ int ble_peripheral_at_cmd_auth(int argc, char **argv) passcode = atoi(argv[3]); if (passcode > GAP_PASSCODE_MAX) { - BLE_PRINT("ERROR:passcode is out of range[0-999999] !\n\r"); + printf("ERROR:passcode is out of range[0-999999] !\r\n"); confirm = GAP_CFM_CAUSE_REJECT; } le_bond_passkey_input_confirm(conn_id, passcode, confirm); @@ -231,11 +232,11 @@ int ble_peripheral_at_cmd_auth(int argc, char **argv) ret = gap_set_pairable_mode(); if(ret == GAP_CAUSE_SUCCESS) - BLE_PRINT("\n\rSet pairable mode success!\r\n"); + printf("Set pairable mode success!\r\n"); else - BLE_PRINT("\n\rSet pairable mode fail!\r\n"); + printf("Set pairable mode fail!\r\n"); }else{ - BLE_PRINT("ERROR:input parameter error!\n\r"); + printf("ERROR:input parameter error!\r\n"); return -1; } @@ -295,7 +296,7 @@ int ble_peripheral_at_cmd_bond_information(int argc, char **argv) for (i = 0; i < bond_storage_num; i++) { p_entry = le_find_key_entry_by_idx(i); if (p_entry != NULL) { - BLE_PRINT("bond_dev[%d]: bd 0x%02x%02x%02x%02x%02x%02x, addr_type %d, flags 0x%x\r\n", + printf("bond_dev[%d]: bd 0x%02x%02x%02x%02x%02x%02x, addr_type %d, flags 0x%x\r\n", p_entry->idx, p_entry->remote_bd.addr[5], p_entry->remote_bd.addr[4], @@ -326,10 +327,10 @@ int ble_peripheral_send_indi_notification(int argc, char **argv) int data_count; if (length == -1) { - printf("\n\rError:value length should be hexadecimal and start with '0X' or '0x'\r\n"); + printf("Error:value length should be hexadecimal and start with '0X' or '0x'\r\n"); return -1; } else if (length == 0) { - printf("\n\rError:value length should larger than 0\r\n"); + printf("Error:value length should larger than 0\r\n"); return -1; } @@ -350,9 +351,11 @@ int ble_peripheral_send_indi_notification(int argc, char **argv) return 0; } +#endif int ble_peripheral_app_handle_at_cmd(uint16_t subtype, void *arg) { +#if SUPPORT_LOG_SERVICE int argc = 0; char *argv[MAX_ARGC] = {0}; @@ -381,5 +384,8 @@ int ble_peripheral_app_handle_at_cmd(uint16_t subtype, void *arg) } return 0; +#else + return 0; +#endif } #endif diff --git a/component/common/bluetooth/realtek/sdk/example/ble_peripheral/peripheral_app.c b/component/common/bluetooth/realtek/sdk/example/ble_peripheral/peripheral_app.c index 89560c61..a7bf7719 100644 --- a/component/common/bluetooth/realtek/sdk/example/ble_peripheral/peripheral_app.c +++ b/component/common/bluetooth/realtek/sdk/example/ble_peripheral/peripheral_app.c @@ -94,7 +94,9 @@ typedef struct uint16_t adv_interval; uint8_t local_bd_type; uint8_t adv_data[31]; + uint8_t adv_data_size; uint8_t scan_rsp_data[31]; + uint8_t scan_rsp_data_size; } T_LEGACY_ADV_INFO; T_LEGACY_ADV_CONCURRENT lac_adapter; @@ -223,15 +225,15 @@ void app_handle_dev_state_evt(T_GAP_DEV_STATE new_state, uint16_t cause) if (new_state.gap_init_state == GAP_INIT_STATE_STACK_READY) { APP_PRINT_INFO0("GAP stack ready"); - printf("\n\r[BLE peripheral] GAP stack ready\n\r"); + printf("[BLE peripheral] GAP stack ready\r\n"); uint8_t bt_addr[6]={0}; #if (F_BT_LE_USE_RANDOM_ADDR==2) && F_BT_LE_LOCAL_IRK_SETTING_SUPPORT T_GAP_RAND_ADDR_TYPE rand_addr_type = GAP_RAND_ADDR_RESOLVABLE; T_GAP_CAUSE result; result = le_gen_rand_addr(rand_addr_type, bt_addr); - printf("[%s]le_gen_rand_addr result = %x\n\r",__func__,result); + printf("[%s]le_gen_rand_addr result = %x\r\n",__func__,result); result = le_set_rand_addr(bt_addr); - printf("[%s]le_set_rand_addr result = %x\n\r",__func__,result); + printf("[%s]le_set_rand_addr result = %x\r\n",__func__,result); memset(bt_addr,0,sizeof(uint8_t)*6); #endif /*stack ready*/ @@ -260,18 +262,18 @@ void app_handle_dev_state_evt(T_GAP_DEV_STATE new_state, uint16_t cause) if (new_state.gap_adv_sub_state == GAP_ADV_TO_IDLE_CAUSE_CONN) { APP_PRINT_INFO0("GAP adv stoped: because connection created"); - printf("\n\rGAP adv stoped: because connection created\n\r"); + printf("GAP adv stoped: because connection created\r\n"); } else { APP_PRINT_INFO0("GAP adv stoped"); - printf("\n\rGAP adv stopped\n\r"); + printf("GAP adv stopped\r\n"); } } else if (new_state.gap_adv_state == GAP_ADV_STATE_ADVERTISING) { APP_PRINT_INFO0("GAP adv start"); - printf("\n\rGAP adv start\n\r"); + printf("GAP adv start\r\n"); } } @@ -304,7 +306,7 @@ void app_handle_conn_state_evt(uint8_t conn_id, T_GAP_CONN_STATE new_state, uint { APP_PRINT_ERROR1("app_handle_conn_state_evt: connection lost cause 0x%x", disc_cause); } - printf("\n\r[BLE peripheral] BT Disconnected, cause 0x%x, start ADV\n\r", disc_cause); + printf("[BLE peripheral] BT Disconnected, cause 0x%x, start ADV\r\n", disc_cause); #if (LEGACY_ADV_CONCURRENT == 1) legacy_adv_concurrent_start(); #else @@ -328,7 +330,7 @@ void app_handle_conn_state_evt(uint8_t conn_id, T_GAP_CONN_STATE new_state, uint APP_PRINT_INFO5("GAP_CONN_STATE_CONNECTED:remote_bd %s, remote_addr_type %d, conn_interval 0x%x, conn_latency 0x%x, conn_supervision_timeout 0x%x", TRACE_BDADDR(remote_bd), remote_bd_type, conn_interval, conn_latency, conn_supervision_timeout); - printf("\n\r[BLE peripheral] BT Connected\n\r"); + printf("[BLE peripheral] BT Connected\r\n"); #if (LEGACY_ADV_CONCURRENT == 1) legacy_adv_concurrent_stop(); #else @@ -438,7 +440,7 @@ void app_handle_conn_param_update_evt(uint8_t conn_id, uint8_t status, uint16_t case GAP_CONN_PARAM_UPDATE_STATUS_PENDING: { APP_PRINT_INFO0("app_handle_conn_param_update_evt update pending."); - printf("\n\rble_central_app_handle_conn_param_update_evt update pending: conn_id %d\r\n", conn_id); + printf("ble_central_app_handle_conn_param_update_evt update pending: conn_id %d\r\n", conn_id); } break; @@ -648,7 +650,7 @@ T_APP_RESULT app_profile_callback(T_SERVER_ID service_id, void *p_data) p_param->event_data.send_data_result.service_id, p_param->event_data.send_data_result.attrib_idx, p_param->event_data.send_data_result.credits); - printf("\n\rPROFILE_EVT_SEND_DATA_COMPLETE: conn_id %d, cause 0x%x, service_id %d, attrib_idx 0x%x, credits %d\r\n", + printf("PROFILE_EVT_SEND_DATA_COMPLETE: conn_id %d, cause 0x%x, service_id %d, attrib_idx 0x%x, credits %d\r\n", p_param->event_data.send_data_result.conn_id, p_param->event_data.send_data_result.cause, p_param->event_data.send_data_result.service_id, @@ -682,26 +684,26 @@ T_APP_RESULT app_profile_callback(T_SERVER_ID service_id, void *p_data) case SIMP_NOTIFY_INDICATE_V3_ENABLE: { APP_PRINT_INFO0("SIMP_NOTIFY_INDICATE_V3_ENABLE"); - printf("\n\rSIMP_NOTIFY_INDICATE_V3_ENABLE\r\n"); + printf("SIMP_NOTIFY_INDICATE_V3_ENABLE\r\n"); } break; case SIMP_NOTIFY_INDICATE_V3_DISABLE: { APP_PRINT_INFO0("SIMP_NOTIFY_INDICATE_V3_DISABLE"); - printf("\n\rSIMP_NOTIFY_INDICATE_V3_DISABLE\r\n"); + printf("SIMP_NOTIFY_INDICATE_V3_DISABLE\r\n"); } break; case SIMP_NOTIFY_INDICATE_V4_ENABLE: { APP_PRINT_INFO0("SIMP_NOTIFY_INDICATE_V4_ENABLE"); - printf("\n\rSIMP_NOTIFY_INDICATE_V4_ENABLE\r\n"); + printf("SIMP_NOTIFY_INDICATE_V4_ENABLE\r\n"); } break; case SIMP_NOTIFY_INDICATE_V4_DISABLE: { APP_PRINT_INFO0("SIMP_NOTIFY_INDICATE_V4_DISABLE"); - printf("\n\rSIMP_NOTIFY_INDICATE_V4_DISABLE\r\n"); + printf("SIMP_NOTIFY_INDICATE_V4_DISABLE\r\n"); } break; default: @@ -735,7 +737,7 @@ T_APP_RESULT app_profile_callback(T_SERVER_ID service_id, void *p_data) for(int i = 0; i < p_simp_cb_data->msg_data.write.len; i ++){ printf("0x%02x ", *(p_simp_cb_data->msg_data.write.p_value + i)); } - printf("\n\r"); + printf("\r\n"); } break; default: @@ -760,14 +762,14 @@ T_APP_RESULT app_profile_callback(T_SERVER_ID service_id, void *p_data) case BAS_NOTIFY_BATTERY_LEVEL_ENABLE: { APP_PRINT_INFO0("BAS_NOTIFY_BATTERY_LEVEL_ENABLE"); - printf("\n\rBAS_NOTIFY_BATTERY_LEVEL_ENABLE\r\n"); + printf("BAS_NOTIFY_BATTERY_LEVEL_ENABLE\r\n"); } break; case BAS_NOTIFY_BATTERY_LEVEL_DISABLE: { APP_PRINT_INFO0("BAS_NOTIFY_BATTERY_LEVEL_DISABLE"); - printf("\n\rBAS_NOTIFY_BATTERY_LEVEL_DISABLE\r\n"); + printf("BAS_NOTIFY_BATTERY_LEVEL_DISABLE\r\n"); } break; default: @@ -939,8 +941,8 @@ void legacy_adv_concurrent_task(void *p_param) } le_adv_set_param(GAP_PARAM_ADV_LOCAL_ADDR_TYPE, sizeof(adv_info.local_bd_type), &adv_info.local_bd_type); #endif - le_adv_set_param(GAP_PARAM_ADV_DATA, sizeof(adv_info.adv_data), (void *)adv_info.adv_data); - le_adv_set_param(GAP_PARAM_SCAN_RSP_DATA, sizeof(adv_info.scan_rsp_data), (void *)adv_info.scan_rsp_data); + le_adv_set_param(GAP_PARAM_ADV_DATA, adv_info.adv_data_size, (void *)adv_info.adv_data); + le_adv_set_param(GAP_PARAM_SCAN_RSP_DATA, adv_info.scan_rsp_data_size, (void *)adv_info.scan_rsp_data); legacy_adv_concurrent_send_msg(); } } @@ -972,9 +974,12 @@ void legacy_adv_concurrent_init(uint32_t adv_interval_0, uint32_t adv_interval_1 } adv_info_0.adv_interval = adv_interval_0; + adv_info_0.local_bd_type = GAP_LOCAL_ADDR_LE_PUBLIC; - memcpy(&adv_info_0.adv_data, adv_data_0, 31); - memcpy(&adv_info_0.scan_rsp_data, scan_rsp_data_0, 31); + memcpy(adv_info_0.adv_data, adv_data_0, sizeof(adv_data_0)); + memcpy(adv_info_0.scan_rsp_data, scan_rsp_data_0, sizeof(scan_rsp_data_0)); + adv_info_0.adv_data_size = sizeof(adv_data_0); + adv_info_0.scan_rsp_data_size = sizeof(scan_rsp_data_0); adv_info_1.adv_interval = adv_interval_1; #if (F_BT_LE_USE_RANDOM_ADDR == 1) @@ -982,8 +987,10 @@ void legacy_adv_concurrent_init(uint32_t adv_interval_0, uint32_t adv_interval_1 #else if (F_BT_LE_USE_RANDOM_ADDR == 0) adv_info_1.local_bd_type = GAP_LOCAL_ADDR_LE_PUBLIC; #endif - memcpy(&adv_info_1.adv_data, adv_data_1, 31); - memcpy(&adv_info_1.scan_rsp_data, scan_rsp_data_1, 31); + memcpy(adv_info_1.adv_data, adv_data_1, sizeof(adv_data_1)); + memcpy(adv_info_1.scan_rsp_data, scan_rsp_data_1, sizeof(scan_rsp_data_1)); + adv_info_1.adv_data_size = sizeof(adv_data_1); + adv_info_1.scan_rsp_data_size = sizeof(scan_rsp_data_1); memset(&lac_adapter, 0, sizeof(lac_adapter)); lac_adapter.start_stop_flag = true; diff --git a/component/common/bluetooth/realtek/sdk/example/ble_scatternet/ble_scatternet_app.c b/component/common/bluetooth/realtek/sdk/example/ble_scatternet/ble_scatternet_app.c index 7c08f080..21500c2b 100644 --- a/component/common/bluetooth/realtek/sdk/example/ble_scatternet/ble_scatternet_app.c +++ b/component/common/bluetooth/realtek/sdk/example/ble_scatternet/ble_scatternet_app.c @@ -29,12 +29,9 @@ #include #include #include -#include -#include #include #include "platform_opts_bt.h" #include "gatt_builtin_services.h" -#include "data_uart.h" #include "ble_central_at_cmd.h" #include "ble_peripheral_at_cmd.h" @@ -80,14 +77,6 @@ void ble_scatternet_app_handle_io_msg(T_IO_MSG io_msg) ble_scatternet_app_handle_gap_msg(&io_msg); } break; -#if defined (CONFIG_BT_USER_COMMAND) && (CONFIG_BT_USER_COMMAND) - case IO_MSG_TYPE_UART: - uint8_t rx_char; - /* We handle user command informations from Data UART in this branch. */ - rx_char = (uint8_t)io_msg.subtype; - user_cmd_collect(&ble_scatternet_user_cmd_if, &rx_char, sizeof(rx_char), ble_scatternet_user_cmd_table); - break; -#endif case IO_MSG_TYPE_AT_CMD: { uint16_t subtype = io_msg.subtype; @@ -138,14 +127,14 @@ void ble_scatternet_app_handle_dev_state_evt(T_GAP_DEV_STATE new_state, uint16_t T_GAP_RAND_ADDR_TYPE rand_addr_type = GAP_RAND_ADDR_RESOLVABLE; T_GAP_CAUSE result; result = le_gen_rand_addr(rand_addr_type, bt_addr); - BLE_PRINT("[%s]le_gen_rand_addr result = %x\n\r",__func__,result); + printf("[%s]le_gen_rand_addr result = %x\r\n",__func__,result); result = le_set_rand_addr(bt_addr); - BLE_PRINT("[%s]le_set_rand_addr result = %x\n\r",__func__,result); + printf("[%s]le_set_rand_addr result = %x\r\n",__func__,result); memset(bt_addr,0,sizeof(uint8_t)*6); #endif /*stack ready*/ gap_get_param(GAP_PARAM_BD_ADDR, bt_addr); - data_uart_print("local bd addr: 0x%2x:%2x:%2x:%2x:%2x:%2x\r\n", + printf("local bd addr: 0x%2x:%2x:%2x:%2x:%2x:%2x\r\n", bt_addr[5], bt_addr[4], bt_addr[3], @@ -155,7 +144,7 @@ void ble_scatternet_app_handle_dev_state_evt(T_GAP_DEV_STATE new_state, uint16_t ret = le_adv_start(); if(ret == GAP_CAUSE_SUCCESS) - data_uart_print("\n\rSTART ADV!!\n"); + printf("START ADV!!\r\n"); } } @@ -164,12 +153,12 @@ void ble_scatternet_app_handle_dev_state_evt(T_GAP_DEV_STATE new_state, uint16_t if (new_state.gap_scan_state == GAP_SCAN_STATE_IDLE) { APP_PRINT_INFO0("GAP scan stop"); - data_uart_print("GAP scan stop\r\n"); + printf("GAP scan stop\r\n"); } else if (new_state.gap_scan_state == GAP_SCAN_STATE_SCANNING) { APP_PRINT_INFO0("GAP scan start"); - data_uart_print("GAP scan start\r\n"); + printf("GAP scan start\r\n"); } } @@ -180,18 +169,18 @@ void ble_scatternet_app_handle_dev_state_evt(T_GAP_DEV_STATE new_state, uint16_t if (new_state.gap_adv_sub_state == GAP_ADV_TO_IDLE_CAUSE_CONN) { APP_PRINT_INFO0("GAP adv stoped: because connection created"); - data_uart_print("GAP adv stoped: because connection created\r\n"); + printf("GAP adv stoped: because connection created\r\n"); } else { APP_PRINT_INFO0("GAP adv stoped"); - data_uart_print("GAP adv stopped\r\n"); + printf("GAP adv stopped\r\n"); } } else if (new_state.gap_adv_state == GAP_ADV_STATE_ADVERTISING) { APP_PRINT_INFO0("GAP adv start"); - data_uart_print("GAP adv start\r\n"); + printf("GAP adv start\r\n"); } } @@ -232,13 +221,13 @@ void ble_scatternet_app_handle_conn_state_evt(uint8_t conn_id, T_GAP_CONN_STATE disc_cause); } - data_uart_print("Disconnect conn_id %d, cause 0x%x\r\n", conn_id, disc_cause); + printf("Disconnect conn_id %d, cause 0x%x\r\n", conn_id, disc_cause); ///judge the type of disconnect is central or peripheral,if peripheral,start ADV if (ble_scatternet_app_link_table[conn_id].role == GAP_LINK_ROLE_SLAVE){ - data_uart_print("As peripheral,recieve disconncect,please start ADV\r\n"); + printf("As peripheral,recieve disconncect,please start ADV\r\n"); ret = le_adv_start(); if(ret == GAP_CAUSE_SUCCESS) - data_uart_print("\n\rSTART ADV!!\n"); + printf("\n\rSTART ADV!!\n"); } if (ble_scatternet_app_link_table[conn_id].role == GAP_LINK_ROLE_MASTER) @@ -262,7 +251,7 @@ void ble_scatternet_app_handle_conn_state_evt(uint8_t conn_id, T_GAP_CONN_STATE else if (ble_scatternet_app_link_table[conn_id].role == GAP_LINK_ROLE_SLAVE) ble_scatternet_peripheral_app_max_links ++; } - data_uart_print("Connected success conn_id %d\r\n", conn_id); + printf("Connected success conn_id %d\r\n", conn_id); ////print bt address type uint8_t local_bd_type; //uint8_t features[8]; @@ -271,7 +260,7 @@ void ble_scatternet_app_handle_conn_state_evt(uint8_t conn_id, T_GAP_CONN_STATE le_get_conn_param(GAP_PARAM_CONN_BD_ADDR_TYPE, &remote_bd_type, conn_id); APP_PRINT_INFO3("GAP_CONN_STATE_CONNECTED: conn_id %d, local_bd_type %d, remote_bd_type %d\n", conn_id, local_bd_type, remote_bd_type); - data_uart_print("GAP_CONN_STATE_CONNECTED: conn_id %d, local_bd_type %d, remote_bd_type %d\n", + printf("GAP_CONN_STATE_CONNECTED: conn_id %d, local_bd_type %d, remote_bd_type %d\r\n", conn_id, local_bd_type, remote_bd_type); #if F_BT_LE_5_0_SET_PHY_SUPPORT { @@ -280,7 +269,7 @@ void ble_scatternet_app_handle_conn_state_evt(uint8_t conn_id, T_GAP_CONN_STATE le_get_conn_param(GAP_PARAM_CONN_RX_PHY_TYPE, &rx_phy, conn_id); le_get_conn_param(GAP_PARAM_CONN_TX_PHY_TYPE, &tx_phy, conn_id); APP_PRINT_INFO2("GAP_CONN_STATE_CONNECTED: tx_phy %d, rx_phy %d\n", tx_phy, rx_phy); - data_uart_print("GAP_CONN_STATE_CONNECTED: tx_phy %d, rx_phy %d\n", tx_phy, rx_phy); + printf("GAP_CONN_STATE_CONNECTED: tx_phy %d, rx_phy %d\r\n", tx_phy, rx_phy); } #endif } @@ -316,12 +305,12 @@ void ble_scatternet_app_handle_authen_state_evt(uint8_t conn_id, uint8_t new_sta { if (cause == GAP_SUCCESS) { - data_uart_print("Pair success\r\n"); + printf("Pair success\r\n"); APP_PRINT_INFO0("ble_scatternet_app_handle_authen_state_evt: GAP_AUTHEN_STATE_COMPLETE pair success"); } else { - data_uart_print("Pair failed: cause 0x%x\r\n", cause); + printf("Pair failed: cause 0x%x\r\n", cause); APP_PRINT_INFO0("ble_scatternet_app_handle_authen_state_evt: GAP_AUTHEN_STATE_COMPLETE pair failed"); } } @@ -370,7 +359,7 @@ void ble_scatternet_app_handle_conn_param_update_evt(uint8_t conn_id, uint8_t st le_get_conn_param(GAP_PARAM_CONN_TIMEOUT, &conn_supervision_timeout, conn_id); APP_PRINT_INFO4("ble_scatternet_app_handle_conn_param_update_evt update success:conn_id %d, conn_interval 0x%x, conn_slave_latency 0x%x, conn_supervision_timeout 0x%x", conn_id, conn_interval, conn_slave_latency, conn_supervision_timeout); - data_uart_print("\n\rble_scatternet_app_handle_conn_param_update_evt update success:conn_id %d, conn_interval 0x%x, conn_slave_latency 0x%x, conn_supervision_timeout 0x%x \r\n", + printf("ble_scatternet_app_handle_conn_param_update_evt update success:conn_id %d, conn_interval 0x%x, conn_slave_latency 0x%x, conn_supervision_timeout 0x%x \r\n", conn_id, conn_interval, conn_slave_latency, conn_supervision_timeout); } break; @@ -379,7 +368,7 @@ void ble_scatternet_app_handle_conn_param_update_evt(uint8_t conn_id, uint8_t st { APP_PRINT_ERROR2("ble_scatternet_app_handle_conn_param_update_evt update failed: conn_id %d, cause 0x%x", conn_id, cause); - data_uart_print("\n\rble_scatternet_app_handle_conn_param_update_evt update failed: conn_id %d, cause 0x%x\r\n", + printf("ble_scatternet_app_handle_conn_param_update_evt update failed: conn_id %d, cause 0x%x\r\n", conn_id, cause); } @@ -388,7 +377,7 @@ void ble_scatternet_app_handle_conn_param_update_evt(uint8_t conn_id, uint8_t st case GAP_CONN_PARAM_UPDATE_STATUS_PENDING: { APP_PRINT_INFO1("ble_scatternet_app_handle_conn_param_update_evt update pending: conn_id %d", conn_id); - data_uart_print("\n\rble_scatternet_app_handle_conn_param_update_evt update pending: conn_id %d\r\n", conn_id); + printf("ble_scatternet_app_handle_conn_param_update_evt update pending: conn_id %d\r\n", conn_id); } break; @@ -469,8 +458,7 @@ void ble_scatternet_app_handle_gap_msg(T_IO_MSG *p_gap_msg) conn_id, display_value); le_bond_passkey_display_confirm(conn_id, GAP_CFM_CAUSE_ACCEPT); printf("GAP_MSG_LE_BOND_PASSKEY_DISPLAY: conn_id %d, passkey %06d\r\n", - conn_id, - display_value); + conn_id, display_value); } break; @@ -493,7 +481,7 @@ void ble_scatternet_app_handle_gap_msg(T_IO_MSG *p_gap_msg) //uint32_t passkey = 888888; conn_id = gap_msg.msg_data.gap_bond_passkey_input.conn_id; APP_PRINT_INFO1("GAP_MSG_LE_BOND_PASSKEY_INPUT: conn_id %d", conn_id); - data_uart_print("GAP_MSG_LE_BOND_PASSKEY_INPUT: conn_id %d\r\n", conn_id); + printf("GAP_MSG_LE_BOND_PASSKEY_INPUT: conn_id %d\r\n", conn_id); //le_bond_passkey_input_confirm(conn_id, passkey, GAP_CFM_CAUSE_ACCEPT); } break; @@ -544,7 +532,7 @@ void ble_scatternet_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) APP_PRINT_TRACE2("ble_scatternet_app_parse_scan_info: AD Structure Info: AD type 0x%x, AD Data Length %d", type, length - 1); -// BLE_PRINT("ble_scatternet_app_parse_scan_info: AD Structure Info: AD type 0x%x, AD Data Length %d\n\r", type, +// printf("ble_scatternet_app_parse_scan_info: AD Structure Info: AD type 0x%x, AD Data Length %d\r\n", type, // length - 1); @@ -559,7 +547,7 @@ void ble_scatternet_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) /* (flags & 0x10) -- Simultaneous LE and BR/EDR to Same Device Capable (Host) */ uint8_t flags = scan_info->data[pos + 1]; APP_PRINT_INFO1("GAP_ADTYPE_FLAGS: 0x%x", flags); - BLE_PRINT("GAP_ADTYPE_FLAGS: 0x%x\n\r", flags); + printf("GAP_ADTYPE_FLAGS: 0x%x\r\n", flags); } break; @@ -574,7 +562,7 @@ void ble_scatternet_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) while (i >= 2) { APP_PRINT_INFO1("GAP_ADTYPE_16BIT_XXX: 0x%x", *p_uuid); - BLE_PRINT("GAP_ADTYPE_16BIT_XXX: 0x%x\n\r", *p_uuid); + printf("GAP_ADTYPE_16BIT_XXX: 0x%x\r\n", *p_uuid); p_uuid ++; i -= 2; } @@ -590,7 +578,7 @@ void ble_scatternet_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) while (i >= 4) { APP_PRINT_INFO1("GAP_ADTYPE_32BIT_XXX: 0x%x", *p_uuid); - BLE_PRINT("GAP_ADTYPE_32BIT_XXX: 0x%x\n\r", (unsigned int)*p_uuid); + printf("GAP_ADTYPE_32BIT_XXX: 0x%x\r\n", (unsigned int)*p_uuid); p_uuid ++; i -= 4; @@ -605,7 +593,7 @@ void ble_scatternet_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) uint32_t *p_uuid = (uint32_t *)(buffer); APP_PRINT_INFO4("GAP_ADTYPE_128BIT_XXX: 0x%8.8x%8.8x%8.8x%8.8x", p_uuid[3], p_uuid[2], p_uuid[1], p_uuid[0]); - BLE_PRINT("GAP_ADTYPE_128BIT_XXX: 0x%8.8x%8.8x%8.8x%8.8x\n\r", + printf("GAP_ADTYPE_128BIT_XXX: 0x%8.8x%8.8x%8.8x%8.8x\r\n", (unsigned int)p_uuid[3], (unsigned int)p_uuid[2], (unsigned int)p_uuid[1], (unsigned int)p_uuid[0]); } @@ -616,7 +604,7 @@ void ble_scatternet_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) { buffer[length - 1] = '\0'; APP_PRINT_INFO1("GAP_ADTYPE_LOCAL_NAME_XXX: %s", TRACE_STRING(buffer)); - BLE_PRINT("GAP_ADTYPE_LOCAL_NAME_XXX: %s\n\r", buffer); + printf("GAP_ADTYPE_LOCAL_NAME_XXX: %s\r\n", buffer); } break; @@ -624,7 +612,7 @@ void ble_scatternet_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) case GAP_ADTYPE_POWER_LEVEL: { APP_PRINT_INFO1("GAP_ADTYPE_POWER_LEVEL: 0x%x", scan_info->data[pos + 1]); - BLE_PRINT("GAP_ADTYPE_POWER_LEVEL: 0x%x\n\r", scan_info->data[pos + 1]); + printf("GAP_ADTYPE_POWER_LEVEL: 0x%x\r\n", scan_info->data[pos + 1]); } break; @@ -635,7 +623,7 @@ void ble_scatternet_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) uint16_t *p_max = p_min + 1; APP_PRINT_INFO2("GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE: 0x%x - 0x%x", *p_min, *p_max); - BLE_PRINT("GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE: 0x%x - 0x%x\n\r", *p_min, + printf("GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE: 0x%x - 0x%x\r\n", *p_min, *p_max); } @@ -648,7 +636,7 @@ void ble_scatternet_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) APP_PRINT_INFO3("GAP_ADTYPE_SERVICE_DATA: UUID 0x%x, len %d, data %b", *p_uuid, data_len, TRACE_BINARY(data_len, &buffer[2])); - BLE_PRINT("GAP_ADTYPE_SERVICE_DATA: UUID 0x%x, len %d\n\r", *p_uuid, + printf("GAP_ADTYPE_SERVICE_DATA: UUID 0x%x, len %d\r\n", *p_uuid, data_len); } @@ -657,7 +645,7 @@ void ble_scatternet_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) { uint16_t *p_appearance = (uint16_t *)(buffer); APP_PRINT_INFO1("GAP_ADTYPE_APPEARANCE: %d", *p_appearance); - BLE_PRINT("GAP_ADTYPE_APPEARANCE: %d\n\r", *p_appearance); + printf("GAP_ADTYPE_APPEARANCE: %d\r\n", *p_appearance); } break; @@ -668,7 +656,7 @@ void ble_scatternet_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) uint16_t *p_company_id = (uint16_t *)(buffer); APP_PRINT_INFO3("GAP_ADTYPE_MANUFACTURER_SPECIFIC: company_id 0x%x, len %d, data %b", *p_company_id, data_len, TRACE_BINARY(data_len, &buffer[2])); - BLE_PRINT("GAP_ADTYPE_MANUFACTURER_SPECIFIC: company_id 0x%x, len %d\n\r", + printf("GAP_ADTYPE_MANUFACTURER_SPECIFIC: company_id 0x%x, len %d\r\n", *p_company_id, data_len); } @@ -680,8 +668,8 @@ void ble_scatternet_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) for (i = 0; i < (length - 1); i++) { - APP_PRINT_INFO1(" AD Data: Unhandled Data = 0x%x", scan_info->data[pos + i]); -// BLE_PRINT(" AD Data: Unhandled Data = 0x%x\n\r", scan_info->data[pos + i]); + APP_PRINT_INFO1(" AD Data: Unhandled Data = 0x%x", scan_info->data[pos + 1 + i]); +// printf(" AD Data: Unhandled Data = 0x%x\r\n", scan_info->data[pos + 1 + i]); } } @@ -689,7 +677,10 @@ void ble_scatternet_app_parse_scan_info(T_LE_SCAN_INFO *scan_info) } } - pos += length; + if (pos + length > 0xFF) //Avoid pos + length overflow uint8_t + pos = 0xFF; + else + pos += length; } } /** @@ -723,8 +714,8 @@ T_APP_RESULT ble_scatternet_app_gap_callback(uint8_t cb_type, void *p_cb_data) sprintf(remote_addr_type,"%s",(p_data->p_le_scan_info->remote_addr_type == GAP_REMOTE_ADDR_LE_PUBLIC)? "public": (p_data->p_le_scan_info->remote_addr_type == GAP_REMOTE_ADDR_LE_RANDOM)? "random":"unknown"); - BLE_PRINT("ADVType\t\t\t| AddrType\t|%s\t\t\t|rssi\n\r","BT_Addr"); - BLE_PRINT("%s\t\t%s\t"BD_ADDR_FMT"\t%d\n\r",adv_type,remote_addr_type,BD_ADDR_ARG(p_data->p_le_scan_info->bd_addr), + printf("ADVType\t\t\t| AddrType\t|%s\t\t\t|rssi\r\n","BT_Addr"); + printf("%s\t\t%s\t"BD_ADDR_FMT"\t%d\r\n",adv_type,remote_addr_type,BD_ADDR_ARG(p_data->p_le_scan_info->bd_addr), p_data->p_le_scan_info->rssi); ble_scatternet_app_parse_scan_info(p_data->p_le_scan_info); @@ -737,7 +728,7 @@ T_APP_RESULT ble_scatternet_app_gap_callback(uint8_t cb_type, void *p_cb_data) p_data->p_le_conn_update_ind->conn_interval_min, p_data->p_le_conn_update_ind->conn_latency, p_data->p_le_conn_update_ind->supervision_timeout); - data_uart_print("GAP_MSG_LE_CONN_UPDATE_IND: conn_id %d, conn_interval_max 0x%x, conn_interval_min 0x%x, conn_latency 0x%x,supervision_timeout 0x%x\n\r", + printf("GAP_MSG_LE_CONN_UPDATE_IND: conn_id %d, conn_interval_max 0x%x, conn_interval_min 0x%x, conn_latency 0x%x,supervision_timeout 0x%x\r\n", p_data->p_le_conn_update_ind->conn_id, p_data->p_le_conn_update_ind->conn_interval_max, p_data->p_le_conn_update_ind->conn_interval_min, @@ -753,7 +744,7 @@ T_APP_RESULT ble_scatternet_app_gap_callback(uint8_t cb_type, void *p_cb_data) p_data->p_le_phy_update_info->cause, p_data->p_le_phy_update_info->rx_phy, p_data->p_le_phy_update_info->tx_phy); - data_uart_print("GAP_MSG_LE_PHY_UPDATE_INFO:conn_id %d, cause 0x%x, rx_phy %d, tx_phy %d\n\r", + printf("GAP_MSG_LE_PHY_UPDATE_INFO:conn_id %d, cause 0x%x, rx_phy %d, tx_phy %d\r\n", p_data->p_le_phy_update_info->conn_id, p_data->p_le_phy_update_info->cause, p_data->p_le_phy_update_info->rx_phy, @@ -773,12 +764,12 @@ T_APP_RESULT ble_scatternet_app_gap_callback(uint8_t cb_type, void *p_cb_data) if (remote_feats[LE_SUPPORT_FEATURES_MASK_ARRAY_INDEX1] & LE_SUPPORT_FEATURES_LE_2M_MASK_BIT) { APP_PRINT_INFO0("GAP_MSG_LE_REMOTE_FEATS_INFO: support 2M"); - data_uart_print("GAP_MSG_LE_REMOTE_FEATS_INFO: support 2M\n\r"); + printf("GAP_MSG_LE_REMOTE_FEATS_INFO: support 2M\r\n"); } if (remote_feats[LE_SUPPORT_FEATURES_MASK_ARRAY_INDEX1] & LE_SUPPORT_FEATURES_LE_CODED_PHY_MASK_BIT) { APP_PRINT_INFO0("GAP_MSG_LE_REMOTE_FEATS_INFO: support CODED"); - data_uart_print("GAP_MSG_LE_REMOTE_FEATS_INFO: support CODED\n\r"); + printf("GAP_MSG_LE_REMOTE_FEATS_INFO: support CODED\r\n"); } } } @@ -789,7 +780,7 @@ T_APP_RESULT ble_scatternet_app_gap_callback(uint8_t cb_type, void *p_cb_data) APP_PRINT_INFO2("GAP_MSG_LE_MODIFY_WHITE_LIST: operation 0x%x, cause 0x%x", p_data->p_le_modify_white_list_rsp->operation, p_data->p_le_modify_white_list_rsp->cause); - data_uart_print("GAP_MSG_LE_MODIFY_WHITE_LIST: operation 0x%x, cause 0x%x\r\n", + printf("GAP_MSG_LE_MODIFY_WHITE_LIST: operation 0x%x, cause 0x%x\r\n", p_data->p_le_modify_white_list_rsp->operation, p_data->p_le_modify_white_list_rsp->cause); break; @@ -831,7 +822,7 @@ T_APP_RESULT ble_scatternet_gap_service_callback(T_SERVER_ID service_id, void *p T_LOCAL_NAME device_name; memcpy(device_name.local_name, p_gap_data->msg_data.p_value, p_gap_data->msg_data.len); device_name.local_name[p_gap_data->msg_data.len] = 0; - //data_uart_print("GAPS_WRITE_DEVICE_NAME:device_name = %s \n\r",device_name.local_name); + //printf("GAPS_WRITE_DEVICE_NAME:device_name = %s \r\n",device_name.local_name); flash_save_local_name(&device_name); } break; @@ -843,13 +834,13 @@ T_APP_RESULT ble_scatternet_gap_service_callback(T_SERVER_ID service_id, void *p LE_ARRAY_TO_UINT16(appearance_val, p_gap_data->msg_data.p_value); appearance.local_appearance = appearance_val; - //data_uart_print("GAPS_WRITE_APPEARANCE:appearance = %s \n\r",appearance.local_appearance); + //printf("GAPS_WRITE_APPEARANCE:appearance = %s \r\n",appearance.local_appearance); flash_save_local_appearance(&appearance); } break; default: APP_PRINT_ERROR1("ble_scatternet_gap_service_callback: unhandled msg_data.opcode 0x%x", p_gap_data->msg_data.opcode); - //data_uart_print("ble_scatternet_gap_service_callback: unhandled msg_data.opcode 0x%x", p_gap_data->msg_data.opcode); + //printf("ble_scatternet_gap_service_callback: unhandled msg_data.opcode 0x%x\r\n", p_gap_data->msg_data.opcode); break; } } @@ -883,7 +874,7 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY i, p_result_table->result_data.srv_uuid16_disc_data.att_handle, p_result_table->result_data.srv_uuid16_disc_data.end_group_handle, p_result_table->result_data.srv_uuid16_disc_data.uuid16); - data_uart_print("ALL SRV UUID16[%d]: service range: 0x%x-0x%x, uuid16 0x%x\n\r", + printf("ALL SRV UUID16[%d]: service range: 0x%x-0x%x, uuid16 0x%x\r\n", i, p_result_table->result_data.srv_uuid16_disc_data.att_handle, p_result_table->result_data.srv_uuid16_disc_data.end_group_handle, p_result_table->result_data.srv_uuid16_disc_data.uuid16); @@ -893,7 +884,7 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY i, p_result_table->result_data.srv_uuid128_disc_data.att_handle, p_result_table->result_data.srv_uuid128_disc_data.end_group_handle, TRACE_BINARY(16, p_result_table->result_data.srv_uuid128_disc_data.uuid128)); - data_uart_print("ALL SRV UUID128[%d]: service range: 0x%x-0x%x, service="UUID_128_FORMAT"\n\r", + printf("ALL SRV UUID128[%d]: service range: 0x%x-0x%x, service="UUID_128_FORMAT"\r\n", i, p_result_table->result_data.srv_uuid128_disc_data.att_handle, p_result_table->result_data.srv_uuid128_disc_data.end_group_handle, UUID_128(p_result_table->result_data.srv_uuid128_disc_data.uuid128)); @@ -902,7 +893,7 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY default: APP_PRINT_ERROR0("Invalid Discovery Result Type!"); - data_uart_print("Invalid Discovery Result Type!\n\r"); + printf("Invalid Discovery Result Type!\r\n"); break; } } @@ -911,7 +902,7 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY case GCS_BY_UUID128_SRV_DISCOV: APP_PRINT_INFO2("conn_id %d, GCS_BY_UUID128_SRV_DISCOV, is_success %d", conn_id, discov_result.is_success); - data_uart_print("conn_id %d, GCS_BY_UUID128_SRV_DISCOV, is_success %d\n\r", + printf("conn_id %d, GCS_BY_UUID128_SRV_DISCOV, is_success %d\r\n", conn_id, discov_result.is_success); for (i = 0; i < discov_result.result_num; i++) @@ -923,7 +914,7 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY APP_PRINT_INFO3("SRV DATA[%d]: service range: 0x%x-0x%x", i, p_result_table->result_data.srv_disc_data.att_handle, p_result_table->result_data.srv_disc_data.end_group_handle); - data_uart_print("SRV DATA[%d]: service range: 0x%x-0x%x\n\r", + printf("SRV DATA[%d]: service range: 0x%x-0x%x\r\n", i, p_result_table->result_data.srv_disc_data.att_handle, p_result_table->result_data.srv_disc_data.end_group_handle); @@ -931,7 +922,7 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY default: APP_PRINT_ERROR0("Invalid Discovery Result Type!"); - data_uart_print("Invalid Discovery Result Type!\n\r"); + printf("Invalid Discovery Result Type!\r\n"); break; } } @@ -940,7 +931,7 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY case GCS_BY_UUID_SRV_DISCOV: APP_PRINT_INFO2("conn_id %d, GCS_BY_UUID_SRV_DISCOV, is_success %d", conn_id, discov_result.is_success); - data_uart_print("conn_id %d, GCS_BY_UUID_SRV_DISCOV, is_success %d\n\r", + printf("conn_id %d, GCS_BY_UUID_SRV_DISCOV, is_success %d\r\n", conn_id, discov_result.is_success); for (i = 0; i < discov_result.result_num; i++) @@ -952,7 +943,7 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY APP_PRINT_INFO3("SRV DATA[%d]: service range: 0x%x-0x%x", i, p_result_table->result_data.srv_disc_data.att_handle, p_result_table->result_data.srv_disc_data.end_group_handle); - data_uart_print("SRV DATA[%d]: service range: 0x%x-0x%x\n\r", + printf("SRV DATA[%d]: service range: 0x%x-0x%x\r\n", i, p_result_table->result_data.srv_disc_data.att_handle, p_result_table->result_data.srv_disc_data.end_group_handle); @@ -960,7 +951,7 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY default: APP_PRINT_ERROR0("Invalid Discovery Result Type!"); - data_uart_print("Invalid Discovery Result Type!\n\r"); + printf("Invalid Discovery Result Type!\r\n"); break; } } @@ -969,7 +960,7 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY case GCS_ALL_CHAR_DISCOV: APP_PRINT_INFO2("conn_id %d, GCS_ALL_CHAR_DISCOV, is_success %d", conn_id, discov_result.is_success); - data_uart_print("conn_id %d, GCS_ALL_CHAR_DISCOV, is_success %d\n\r", + printf("conn_id %d, GCS_ALL_CHAR_DISCOV, is_success %d\r\n", conn_id, discov_result.is_success); for (i = 0; i < discov_result.result_num; i++) @@ -990,12 +981,12 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY properties & GATT_CHAR_PROP_WRITE_NO_RSP, properties & GATT_CHAR_PROP_WRITE, properties & GATT_CHAR_PROP_NOTIFY); - data_uart_print("CHAR UUID16[%d]: decl_handle 0x%x, properties 0x%x, value_handle 0x%x, uuid16 0x%x\n\r", + printf("CHAR UUID16[%d]: decl_handle 0x%x, properties 0x%x, value_handle 0x%x, uuid16 0x%x\r\n", i, p_result_table->result_data.char_uuid16_disc_data.decl_handle, p_result_table->result_data.char_uuid16_disc_data.properties, p_result_table->result_data.char_uuid16_disc_data.value_handle, p_result_table->result_data.char_uuid16_disc_data.uuid16); - data_uart_print("properties:indicate %d, read %d, write cmd %d, write %d, notify %d\n\r", + printf("properties:indicate %d, read %d, write cmd %d, write %d, notify %d\r\n", properties & GATT_CHAR_PROP_INDICATE, properties & GATT_CHAR_PROP_READ, properties & GATT_CHAR_PROP_WRITE_NO_RSP, @@ -1019,12 +1010,12 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY properties & GATT_CHAR_PROP_WRITE, properties & GATT_CHAR_PROP_NOTIFY ); - data_uart_print("CHAR UUID128[%d]: decl hndl=0x%x, prop=0x%x, value hndl=0x%x, uuid128="UUID_128_FORMAT"\n\r", + printf("CHAR UUID128[%d]: decl hndl=0x%x, prop=0x%x, value hndl=0x%x, uuid128="UUID_128_FORMAT"\r\n", i, p_result_table->result_data.char_uuid128_disc_data.decl_handle, p_result_table->result_data.char_uuid128_disc_data.properties, p_result_table->result_data.char_uuid128_disc_data.value_handle, UUID_128(p_result_table->result_data.char_uuid128_disc_data.uuid128)); - data_uart_print("properties:indicate %d, read %d, write cmd %d, write %d, notify %d\n\r", + printf("properties:indicate %d, read %d, write cmd %d, write %d, notify %d\r\n", properties & GATT_CHAR_PROP_INDICATE, properties & GATT_CHAR_PROP_READ, properties & GATT_CHAR_PROP_WRITE_NO_RSP, @@ -1035,7 +1026,7 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY break; default: APP_PRINT_ERROR0("Invalid Discovery Result Type!"); - data_uart_print("Invalid Discovery Result Type!\n\r"); + printf("Invalid Discovery Result Type!\r\n"); break; } } @@ -1044,7 +1035,7 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY case GCS_BY_UUID_CHAR_DISCOV: APP_PRINT_INFO2("conn_id %d, GCS_BY_UUID_CHAR_DISCOV, is_success %d", conn_id, discov_result.is_success); - data_uart_print("conn_id %d, GCS_BY_UUID_CHAR_DISCOV, is_success %d\n\r", + printf("conn_id %d, GCS_BY_UUID_CHAR_DISCOV, is_success %d\r\n", conn_id, discov_result.is_success); for (i = 0; i < discov_result.result_num; i++) @@ -1066,12 +1057,12 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY properties & GATT_CHAR_PROP_WRITE, properties & GATT_CHAR_PROP_NOTIFY ); - data_uart_print("UUID16 CHAR[%d]: Characteristics by uuid16, decl hndl=0x%x, prop=0x%x, value hndl=0x%x, uuid16=<0x%x>\n\r", + printf("UUID16 CHAR[%d]: Characteristics by uuid16, decl hndl=0x%x, prop=0x%x, value hndl=0x%x, uuid16=<0x%x>\r\n", i, p_result_table->result_data.char_uuid16_disc_data.decl_handle, p_result_table->result_data.char_uuid16_disc_data.properties, p_result_table->result_data.char_uuid16_disc_data.value_handle, p_result_table->result_data.char_uuid16_disc_data.uuid16); - data_uart_print("properties:indicate %d, read %d, write cmd %d, write %d, notify %d\n\r", + printf("properties:indicate %d, read %d, write cmd %d, write %d, notify %d\r\n", properties & GATT_CHAR_PROP_INDICATE, properties & GATT_CHAR_PROP_READ, properties & GATT_CHAR_PROP_WRITE_NO_RSP, @@ -1083,7 +1074,7 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY default: APP_PRINT_ERROR0("Invalid Discovery Result Type!"); - data_uart_print("Invalid Discovery Result Type!"); + printf("Invalid Discovery Result Type!\r\n"); break; } } @@ -1092,7 +1083,7 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY case GCS_BY_UUID128_CHAR_DISCOV: APP_PRINT_INFO2("conn_id %d, GCS_BY_UUID128_CHAR_DISCOV, is_success %d", conn_id, discov_result.is_success); - data_uart_print("conn_id %d, GCS_BY_UUID128_CHAR_DISCOV, is_success %d\n\r", + printf("conn_id %d, GCS_BY_UUID128_CHAR_DISCOV, is_success %d\r\n", conn_id, discov_result.is_success); for (i = 0; i < discov_result.result_num; i++) @@ -1114,12 +1105,12 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY properties & GATT_CHAR_PROP_WRITE, properties & GATT_CHAR_PROP_NOTIFY ); - data_uart_print("UUID128 CHAR[%d]: Characteristics by uuid128, decl hndl=0x%x, prop=0x%x, value hndl=0x%x, uuid128="UUID_128_FORMAT"\n\r", + printf("UUID128 CHAR[%d]: Characteristics by uuid128, decl hndl=0x%x, prop=0x%x, value hndl=0x%x, uuid128="UUID_128_FORMAT"\r\n", i, p_result_table->result_data.char_uuid128_disc_data.decl_handle, p_result_table->result_data.char_uuid128_disc_data.properties, p_result_table->result_data.char_uuid128_disc_data.value_handle, UUID_128(p_result_table->result_data.char_uuid128_disc_data.uuid128)); - data_uart_print("properties:indicate %d, read %d, write cmd %d, write %d, notify %d\n\r", + printf("properties:indicate %d, read %d, write cmd %d, write %d, notify %d\r\n", properties & GATT_CHAR_PROP_INDICATE, properties & GATT_CHAR_PROP_READ, properties & GATT_CHAR_PROP_WRITE_NO_RSP, @@ -1131,7 +1122,7 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY default: APP_PRINT_ERROR0("Invalid Discovery Result Type!"); - BLE_PRINT("Invalid Discovery Result Type!\n\r"); + printf("Invalid Discovery Result Type!\r\n"); break; } } @@ -1140,7 +1131,7 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY case GCS_ALL_CHAR_DESC_DISCOV: APP_PRINT_INFO2("conn_id %d, GCS_ALL_CHAR_DESC_DISCOV, is_success %d\r\n", conn_id, discov_result.is_success); - data_uart_print("conn_id %d, GCS_ALL_CHAR_DESC_DISCOV, is_success %d\n\r", + printf("conn_id %d, GCS_ALL_CHAR_DESC_DISCOV, is_success %d\r\n", conn_id, discov_result.is_success); for (i = 0; i < discov_result.result_num; i++) { @@ -1151,7 +1142,7 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY APP_PRINT_INFO3("DESC UUID16[%d]: Descriptors handle=0x%x, uuid16=<0x%x>", i, p_result_table->result_data.char_desc_uuid16_disc_data.handle, p_result_table->result_data.char_desc_uuid16_disc_data.uuid16); - data_uart_print("DESC UUID16[%d]: Descriptors handle=0x%x, uuid16=<0x%x>\n\r", + printf("DESC UUID16[%d]: Descriptors handle=0x%x, uuid16=<0x%x>\r\n", i, p_result_table->result_data.char_desc_uuid16_disc_data.handle, p_result_table->result_data.char_desc_uuid16_disc_data.uuid16); @@ -1160,14 +1151,14 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY APP_PRINT_INFO3("DESC UUID128[%d]: Descriptors handle=0x%x, uuid128=<%b>", i, p_result_table->result_data.char_desc_uuid128_disc_data.handle, TRACE_BINARY(16, p_result_table->result_data.char_desc_uuid128_disc_data.uuid128)); - data_uart_print("DESC UUID128[%d]: Descriptors handle=0x%x, uuid128="UUID_128_FORMAT"\n\r", + printf("DESC UUID128[%d]: Descriptors handle=0x%x, uuid128="UUID_128_FORMAT"\r\n", i, p_result_table->result_data.char_desc_uuid128_disc_data.handle, UUID_128(p_result_table->result_data.char_desc_uuid128_disc_data.uuid128)); break; default: APP_PRINT_ERROR0("Invalid Discovery Result Type!"); - data_uart_print("Invalid Discovery Result Type!\n\r"); + printf("Invalid Discovery Result Type!\r\n"); break; } } @@ -1176,7 +1167,7 @@ void ble_scatternet_gcs_handle_discovery_result(uint8_t conn_id, T_GCS_DISCOVERY default: APP_PRINT_ERROR2("Invalid disc type: conn_id %d, discov_type %d", conn_id, discov_result.discov_type); - data_uart_print("Invalid disc type: conn_id %d, discov_type %d\n\r", + printf("Invalid disc type: conn_id %d, discov_type %d\r\n", conn_id, discov_result.discov_type); break; } @@ -1206,7 +1197,7 @@ T_APP_RESULT ble_scatternet_gcs_client_callback(T_CLIENT_ID client_id, uint8_t c p_gcs_cb_data->cb_content.read_result.cause, p_gcs_cb_data->cb_content.read_result.handle, p_gcs_cb_data->cb_content.read_result.value_size); - data_uart_print("READ RESULT: cause 0x%x, handle 0x%x, value_len %d\n\r", + printf("READ RESULT: cause 0x%x, handle 0x%x, value_len %d\r\n", p_gcs_cb_data->cb_content.read_result.cause, p_gcs_cb_data->cb_content.read_result.handle, p_gcs_cb_data->cb_content.read_result.value_size); @@ -1216,10 +1207,10 @@ T_APP_RESULT ble_scatternet_gcs_client_callback(T_CLIENT_ID client_id, uint8_t c APP_PRINT_INFO1("READ VALUE: %b", TRACE_BINARY(p_gcs_cb_data->cb_content.read_result.value_size, p_gcs_cb_data->cb_content.read_result.p_value)); - data_uart_print("READ VALUE: "); + printf("READ VALUE: "); for(int i=0; i< p_gcs_cb_data->cb_content.read_result.value_size; i++) - data_uart_print("0x%02x ", *(p_gcs_cb_data->cb_content.read_result.p_value + i)); - data_uart_print("\n\r"); + printf("0x%02x ", *(p_gcs_cb_data->cb_content.read_result.p_value + i)); + printf("\r\n"); } break; case GCS_CLIENT_CB_TYPE_WRITE_RESULT: @@ -1227,7 +1218,7 @@ T_APP_RESULT ble_scatternet_gcs_client_callback(T_CLIENT_ID client_id, uint8_t c p_gcs_cb_data->cb_content.write_result.cause, p_gcs_cb_data->cb_content.write_result.handle, p_gcs_cb_data->cb_content.write_result.type); - data_uart_print("WRITE RESULT: cause 0x%x, handle 0x%x, type %d\n\r", + printf("WRITE RESULT: cause 0x%x, handle 0x%x, type %d\r\n", p_gcs_cb_data->cb_content.write_result.cause, p_gcs_cb_data->cb_content.write_result.handle, p_gcs_cb_data->cb_content.write_result.type); @@ -1241,14 +1232,14 @@ T_APP_RESULT ble_scatternet_gcs_client_callback(T_CLIENT_ID client_id, uint8_t c APP_PRINT_INFO1("INDICATION: value %b", TRACE_BINARY(p_gcs_cb_data->cb_content.notif_ind.value_size, p_gcs_cb_data->cb_content.notif_ind.p_value)); - data_uart_print("INDICATION: handle 0x%x, value_size %d\r\n", + printf("INDICATION: handle 0x%x, value_size %d\r\n", p_gcs_cb_data->cb_content.notif_ind.handle, p_gcs_cb_data->cb_content.notif_ind.value_size); - data_uart_print("INDICATION: value "); + printf("INDICATION: value "); for (int i = 0; i < p_gcs_cb_data->cb_content.notif_ind.value_size; i++) { - data_uart_print("0x%02x ", *(p_gcs_cb_data->cb_content.notif_ind.p_value+ i)); + printf("0x%02x ", *(p_gcs_cb_data->cb_content.notif_ind.p_value+ i)); } - data_uart_print("\n\r"); + printf("\r\n"); } else { @@ -1258,14 +1249,14 @@ T_APP_RESULT ble_scatternet_gcs_client_callback(T_CLIENT_ID client_id, uint8_t c APP_PRINT_INFO1("NOTIFICATION: value %b", TRACE_BINARY(p_gcs_cb_data->cb_content.notif_ind.value_size, p_gcs_cb_data->cb_content.notif_ind.p_value)); - data_uart_print("NOTIFICATION: handle 0x%x, value_size %d\r\n", + printf("NOTIFICATION: handle 0x%x, value_size %d\r\n", p_gcs_cb_data->cb_content.notif_ind.handle, p_gcs_cb_data->cb_content.notif_ind.value_size); - data_uart_print("NOTIFICATION: value "); + printf("NOTIFICATION: value "); for (int i = 0; i < p_gcs_cb_data->cb_content.notif_ind.value_size; i++) { - data_uart_print("0x%02x ", *(p_gcs_cb_data->cb_content.notif_ind.p_value+ i)); + printf("0x%02x ", *(p_gcs_cb_data->cb_content.notif_ind.p_value+ i)); } - data_uart_print("\n\r"); + printf("\r\n"); } break; default: diff --git a/component/common/bluetooth/realtek/sdk/example/ble_scatternet/ble_scatternet_app.h b/component/common/bluetooth/realtek/sdk/example/ble_scatternet/ble_scatternet_app.h index 37a394fe..51133544 100644 --- a/component/common/bluetooth/realtek/sdk/example/ble_scatternet/ble_scatternet_app.h +++ b/component/common/bluetooth/realtek/sdk/example/ble_scatternet/ble_scatternet_app.h @@ -28,7 +28,6 @@ extern "C" { #include -#define BLE_PRINT printf #define BD_ADDR_FMT "%02x:%02x:%02x:%02x:%02x:%02x" #define BD_ADDR_ARG(x) (x)[5],(x)[4],(x)[3],(x)[2],(x)[1],(x)[0] #define UUID_128_FORMAT "0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X:0x%2X" @@ -70,7 +69,7 @@ T_APP_RESULT ble_scatternet_app_gap_callback(uint8_t cb_type, void *p_cb_data); */ T_APP_RESULT ble_scatternet_gcs_client_callback(T_CLIENT_ID client_id, uint8_t conn_id, void *p_data); #if F_BT_GAPS_CHAR_WRITEABLE - T_APP_RESULT ble_scatternet_gap_service_callback(T_SERVER_ID service_id, void *p_para); +T_APP_RESULT ble_scatternet_gap_service_callback(T_SERVER_ID service_id, void *p_para); #endif #ifdef __cplusplus diff --git a/component/common/bluetooth/realtek/sdk/example/ble_scatternet/ble_scatternet_app_main.c b/component/common/bluetooth/realtek/sdk/example/ble_scatternet/ble_scatternet_app_main.c index 537554ae..fa1dd4ed 100644 --- a/component/common/bluetooth/realtek/sdk/example/ble_scatternet/ble_scatternet_app_main.c +++ b/component/common/bluetooth/realtek/sdk/example/ble_scatternet/ble_scatternet_app_main.c @@ -33,7 +33,6 @@ #include #include "trace_uart.h" #include - #include "wifi_constants.h" #include #include @@ -230,7 +229,9 @@ void ble_scatternet_app_le_gap_init(void) le_scan_set_param(GAP_PARAM_SCAN_LOCAL_ADDR_TYPE, sizeof(local_bd_type), &local_bd_type); #elif (F_BT_LE_USE_RANDOM_ADDR==2) && F_BT_LE_LOCAL_IRK_SETTING_SUPPORT uint8_t irk_auto = true; + uint8_t local_bd_type = GAP_LOCAL_ADDR_LE_RANDOM; le_bond_set_param(GAP_PARAM_BOND_GEN_LOCAL_IRK_AUTO, sizeof(uint8_t), &irk_auto); + le_adv_set_param(GAP_PARAM_ADV_LOCAL_ADDR_TYPE, sizeof(local_bd_type), &local_bd_type); #endif #if F_BT_GAPS_CHAR_WRITEABLE uint8_t appearance_prop = GAPS_PROPERTY_WRITE_ENABLE; @@ -319,7 +320,7 @@ int ble_scatternet_app_init(void) //judge BLE central is already on le_get_gap_param(GAP_PARAM_DEV_STATE , &new_state); if (new_state.gap_init_state == GAP_INIT_STATE_STACK_READY) { - printf("[BLE Scatternet]BT Stack already on\n\r"); + printf("[BLE Scatternet]BT Stack already on\r\n"); return 0; } else @@ -345,14 +346,14 @@ void ble_scatternet_app_deinit(void) T_GAP_DEV_STATE state; le_get_gap_param(GAP_PARAM_DEV_STATE , &state); if (state.gap_init_state != GAP_INIT_STATE_STACK_READY) { - printf("[BLE Scatternet]BT Stack is not running\n\r"); + printf("[BLE Scatternet]BT Stack is not running\r\n"); } #if F_BT_DEINIT else { gcs_delete_client(); bte_deinit(); bt_trace_uninit(); - printf("[BLE Scatternet]BT Stack deinitalized\n\r"); + printf("[BLE Scatternet]BT Stack deinitalized\r\n"); } #endif } diff --git a/component/common/bluetooth/realtek/sdk/example/ble_scatternet/ble_scatternet_app_task.c b/component/common/bluetooth/realtek/sdk/example/ble_scatternet/ble_scatternet_app_task.c index c5aa5118..977d02e8 100644 --- a/component/common/bluetooth/realtek/sdk/example/ble_scatternet/ble_scatternet_app_task.c +++ b/component/common/bluetooth/realtek/sdk/example/ble_scatternet/ble_scatternet_app_task.c @@ -27,9 +27,6 @@ #include #include #include -#include -#include -#include "ble_scatternet_user_cmd.h" #include #include @@ -74,9 +71,9 @@ void ble_scatternet_send_msg(uint16_t sub_type) if (ble_scatternet_evt_queue_handle != NULL && ble_scatternet_io_queue_handle != NULL) { if (os_msg_send(ble_scatternet_io_queue_handle, &io_msg, 0) == false) { - data_uart_print("ble scatternet send msg fail: subtype 0x%x", io_msg.subtype); + printf("ble scatternet send msg fail: subtype 0x%x\r\n", io_msg.subtype); } else if (os_msg_send(ble_scatternet_evt_queue_handle, &event, 0) == false) { - data_uart_print("ble scatternet send event fail: subtype 0x%x", io_msg.subtype); + printf("ble scatternet send event fail: subtype 0x%x\r\n", io_msg.subtype); } } } @@ -112,11 +109,6 @@ void ble_scatternet_app_main_task(void *p_param) gap_start_bt_stack(ble_scatternet_evt_queue_handle, ble_scatternet_io_queue_handle, BLE_SCATTERNET_MAX_NUMBER_OF_GAP_MESSAGE); - data_uart_init(ble_scatternet_evt_queue_handle, ble_scatternet_io_queue_handle); -#if defined (CONFIG_BT_USER_COMMAND) && (CONFIG_BT_USER_COMMAND) - user_cmd_init(&ble_scatternet_user_cmd_if, "ble_scatternet"); -#endif - while (true) { if (os_msg_recv(ble_scatternet_evt_queue_handle, &event, 0xFFFFFFFF) == true) diff --git a/component/common/bluetooth/realtek/sdk/example/bt_config/bt_config_app_task.c b/component/common/bluetooth/realtek/sdk/example/bt_config/bt_config_app_task.c index 12e5978c..190b96ef 100644 --- a/component/common/bluetooth/realtek/sdk/example/bt_config/bt_config_app_task.c +++ b/component/common/bluetooth/realtek/sdk/example/bt_config/bt_config_app_task.c @@ -64,9 +64,9 @@ void bt_config_send_msg(uint16_t sub_type) if (evt_queue_handle != NULL && io_queue_handle != NULL) { if (os_msg_send(io_queue_handle, &io_msg, 0) == false) { - BC_printf("bt config send msg fail: subtype 0x%x", io_msg.subtype); + BC_printf("bt config send msg fail: subtype 0x%x\r\n", io_msg.subtype); } else if (os_msg_send(evt_queue_handle, &event, 0) == false) { - BC_printf("bt config send event fail: subtype 0x%x", io_msg.subtype); + BC_printf("bt config send event fail: subtype 0x%x\r\n", io_msg.subtype); } } } @@ -102,12 +102,12 @@ void bt_config_app_main_task(void *p_param) void bt_config_app_task_init() { if (app_task_handle == NULL) { - BC_printf("bt_config_app_task_init\n\r"); + BC_printf("bt_config_app_task_init\r\n"); os_task_create(&app_task_handle, "bt_config_app", bt_config_app_main_task, 0, APP_TASK_STACK_SIZE, APP_TASK_PRIORITY); } else { - BC_printf("bt_config_app_main_task already on\n\r"); + BC_printf("bt_config_app_main_task already on\r\n"); } } diff --git a/component/common/bluetooth/realtek/sdk/example/bt_config/bt_config_peripheral_app.c b/component/common/bluetooth/realtek/sdk/example/bt_config/bt_config_peripheral_app.c index afefea88..5c84e8de 100644 --- a/component/common/bluetooth/realtek/sdk/example/bt_config/bt_config_peripheral_app.c +++ b/component/common/bluetooth/realtek/sdk/example/bt_config/bt_config_peripheral_app.c @@ -130,7 +130,7 @@ void bt_config_app_set_adv_data(void) sprintf((char *)device_name,"Ameba_%02X%02X%02X",bt_addr[2],bt_addr[1],bt_addr[0]); memcpy(adv_data+9,device_name,strlen((char const*)device_name)); - //printf("Device name: \"%s\" (BD Address %02X:%02X:%02X:%02X:%02X:%02X) \n\r", + //printf("Device name: \"%s\" (BD Address %02X:%02X:%02X:%02X:%02X:%02X) \r\n", // device_name,bt_addr[5],bt_addr[4],bt_addr[3],bt_addr[2],bt_addr[1],bt_addr[0]); le_set_gap_param(GAP_PARAM_DEVICE_NAME, GAP_DEVICE_NAME_LEN, device_name); @@ -160,7 +160,7 @@ void bt_config_app_handle_dev_state_evt(T_GAP_DEV_STATE new_state, uint16_t caus bt_config_app_set_adv_data(); le_adv_start(); set_bt_config_state(BC_DEV_IDLE); // BT Config Ready - BC_printf("BT Config Wifi ready\n\r"); + BC_printf("BT Config Wifi ready\r\n"); } } @@ -175,13 +175,13 @@ void bt_config_app_handle_dev_state_evt(T_GAP_DEV_STATE new_state, uint16_t caus else { APP_PRINT_INFO0("GAP adv stopped"); - BC_printf("ADV stopped\n\r"); + BC_printf("ADV stopped\r\n"); } } else if (new_state.gap_adv_state == GAP_ADV_STATE_ADVERTISING) { APP_PRINT_INFO0("GAP adv start"); - BC_printf("ADV started\n\r"); + BC_printf("ADV started\r\n"); } } @@ -211,7 +211,7 @@ void bt_config_app_handle_conn_state_evt(uint8_t conn_id, T_GAP_CONN_STATE new_s APP_PRINT_ERROR1("bt_config_app_handle_conn_state_evt: connection lost cause 0x%x", disc_cause); } bt_config_conn_id = 0; - BC_printf("Bluetooth Connection Disconnected\n\r"); + BC_printf("Bluetooth Connection Disconnected\r\n"); if (wifi_is_ready_to_transceive(RTW_STA_INTERFACE) != RTW_SUCCESS) { bt_config_app_set_adv_data(); le_adv_start(); @@ -251,14 +251,14 @@ void bt_config_app_handle_conn_state_evt(uint8_t conn_id, T_GAP_CONN_STATE new_s ce_length_max ); if (cause == GAP_CAUSE_NON_CONN) { - BC_printf("No Bluetooth Connection\n\r"); + BC_printf("No Bluetooth Connection\r\n"); break; } //update_connection_time APP_PRINT_INFO5("GAP_CONN_STATE_CONNECTED:remote_bd %s, remote_addr_type %d, conn_interval 0x%x, conn_latency 0x%x, conn_supervision_timeout 0x%x", TRACE_BDADDR(remote_bd), remote_bd_type, conn_interval, conn_latency, conn_supervision_timeout); - BC_printf("Bluetooth Connection Established\n\r"); + BC_printf("Bluetooth Connection Established\r\n"); bt_config_conn_id = conn_id; set_bt_config_state(BC_DEV_BT_CONNECTED); // BT Config Bluetooth Connected } @@ -379,7 +379,7 @@ void bt_config_app_handle_gap_msg(T_IO_MSG *p_gap_msg) T_LE_GAP_MSG gap_msg; uint8_t conn_id; memcpy(&gap_msg, &p_gap_msg->u.param, sizeof(p_gap_msg->u.param)); - //printf("bt_config_app_handle_gap_msg: subtype %d\n\r", p_gap_msg->subtype); + //printf("bt_config_app_handle_gap_msg: subtype %d\r\n", p_gap_msg->subtype); APP_PRINT_TRACE1("bt_config_app_handle_gap_msg: subtype %d", p_gap_msg->subtype); switch (p_gap_msg->subtype) @@ -485,7 +485,7 @@ T_APP_RESULT bt_config_app_gap_callback(uint8_t cb_type, void *p_cb_data) { #if defined(CONFIG_PLATFORM_8721D) case GAP_MSG_LE_DATA_LEN_CHANGE_INFO: - //printf("GAP_MSG_LE_DATA_LEN_CHANGE_INFO: conn_id %d, tx octets 0x%x, max_tx_time 0x%x", p_data->p_le_data_len_change_info->conn_id, p_data->p_le_data_len_change_info->max_tx_octets, p_data->p_le_data_len_change_info->max_tx_time); + //printf("GAP_MSG_LE_DATA_LEN_CHANGE_INFO: conn_id %d, tx octets 0x%x, max_tx_time 0x%x\r\n", p_data->p_le_data_len_change_info->conn_id, p_data->p_le_data_len_change_info->max_tx_octets, p_data->p_le_data_len_change_info->max_tx_time); APP_PRINT_INFO3("GAP_MSG_LE_DATA_LEN_CHANGE_INFO: conn_id %d, tx octets 0x%x, max_tx_time 0x%x", p_data->p_le_data_len_change_info->conn_id, p_data->p_le_data_len_change_info->max_tx_octets, diff --git a/component/common/bluetooth/realtek/sdk/example/bt_config/bt_config_wifi.c b/component/common/bluetooth/realtek/sdk/example/bt_config/bt_config_wifi.c index db8e01a8..bc9ffc2f 100644 --- a/component/common/bluetooth/realtek/sdk/example/bt_config/bt_config_wifi.c +++ b/component/common/bluetooth/realtek/sdk/example/bt_config/bt_config_wifi.c @@ -83,14 +83,14 @@ int BC_req_scan_hdl(BC_band_t band, struct BC_wifi_scan_result* BC_scan_result) pscan_config = (uint8_t*)os_mem_alloc(RAM_TYPE_DATA_ON, pscan_config_size); if(pscan_config == NULL) { - BC_printf("[%s] malloc pscan_config fail!\n\r",__FUNCTION__); + BC_printf("[%s] malloc pscan_config fail!\r\n",__FUNCTION__); goto exit; } memset(pscan_config, PSCAN_ENABLE, pscan_config_size); ret = wifi_set_pscan_chan(pscan_channel, pscan_config, pscan_config_size); if(ret < 0) { - BC_printf("[%s] wifi set partial scan channel fail\n\r",__FUNCTION__); + BC_printf("[%s] wifi set partial scan channel fail\r\n",__FUNCTION__); goto exit; } @@ -99,7 +99,7 @@ int BC_req_scan_hdl(BC_band_t band, struct BC_wifi_scan_result* BC_scan_result) BC_scan_result->ap_num = 0; ret = wifi_scan_networks(scan_result_handler,(void*) BC_scan_result); if(ret != RTW_SUCCESS) { - BC_printf("wifi scan failed (%d)\n",ret); + BC_printf("wifi scan failed (%d)\r\n",ret); ret = -1; } os_sem_take(wifi_scan_sema, 0xFFFFFFFF); @@ -146,7 +146,7 @@ int BC_req_connect_hdl(uint8_t *ssid, uint8_t *password, uint8_t *bssid, rtw_sec assoc_by_bssid = 1; } else if (wifi.ssid.len == 0) { - BC_printf("Error: SSID can't be empty\n\r"); + BC_printf("Error: SSID can't be empty\r\n"); return -1; } @@ -166,11 +166,11 @@ int BC_req_connect_hdl(uint8_t *ssid, uint8_t *password, uint8_t *bssid, rtw_sec } if(ret != RTW_SUCCESS){ - BC_printf("ERROR: Can't connect to AP\n\r"); + BC_printf("ERROR: Can't connect to AP\r\n"); return ret; } tick2 = rtw_get_current_time(); - BC_printf("Connected after %dms.\n\r", (tick2-tick1)); + BC_printf("Connected after %dms.\r\n", (tick2-tick1)); #if CONFIG_LWIP_LAYER /* Start DHCPClient */ @@ -180,7 +180,7 @@ int BC_req_connect_hdl(uint8_t *ssid, uint8_t *password, uint8_t *bssid, rtw_sec return -1; } tick3 = rtw_get_current_time(); - BC_printf("Got IP after %dms.\n\r", (tick3-tick1)); + BC_printf("Got IP after %dms.\r\n", (tick3-tick1)); #endif return 0; @@ -195,11 +195,11 @@ void BC_req_status_hdl(BC_status_t *status, uint8_t *SSID, uint8_t *BSSID, rtw_s //BC_printf("Status Request"); if (!rltk_wlan_running(WLAN0_IDX)) { *status = BC_STATE_DISABLED; - BC_printf("%s is disabled\n\r", WLAN0_NAME); + BC_printf("%s is disabled\r\n", WLAN0_NAME); } else if (last_conn_error == RTW_WRONG_PASSWORD) { *status = BC_STATE_WRONG_PASSWORD; - BC_printf("Wrong Password\n\r"); + BC_printf("Wrong Password\r\n"); } else if (wifi_is_ready_to_transceive(RTW_STA_INTERFACE)== RTW_SUCCESS) { if (wifi_get_setting(WLAN0_NAME,&setting) != -1) { @@ -215,12 +215,12 @@ void BC_req_status_hdl(BC_status_t *status, uint8_t *SSID, uint8_t *BSSID, rtw_s } else { *status= BC_STATE_IDLE; - BC_DBG("Wifi not Connected\n\r"); + BC_DBG("Wifi not Connected\r\n"); } } else { *status = BC_STATE_IDLE; - BC_DBG("Wifi not Connected\n\r"); + BC_DBG("Wifi not Connected\r\n"); } } @@ -248,9 +248,9 @@ void BC_status_monitor(void *p_param) if (gap_conn_state != GAP_CONN_STATE_CONNECTED) { // BT not connected if (airsync_specific) { - BC_printf("[%s] wifi connected, deinit BT Airsync Config\n\r", __FUNCTION__); + BC_printf("[%s] wifi connected, deinit BT Airsync Config\r\n", __FUNCTION__); } else { - BC_printf("[%s] wifi connected, deinit BT Config\n\r", __FUNCTION__); + BC_printf("[%s] wifi connected, deinit BT Config\r\n", __FUNCTION__); } break; } @@ -276,11 +276,11 @@ void bt_config_wifi_init(void) if (BC_status_monitor_task_hdl == NULL) { if(os_task_create(&BC_status_monitor_task_hdl, (char const *)"BC_status_monitor", BC_status_monitor, NULL, 512, 1) != true){ - BC_printf("[%s] Create BC_status_monitor failed", __FUNCTION__); + BC_printf("[%s] Create BC_status_monitor failed\r\n", __FUNCTION__); } } else { - BC_printf("BC_status_monitor already on\n\r"); + BC_printf("BC_status_monitor already on\r\n"); } } diff --git a/component/common/bluetooth/realtek/sdk/inc/bluetooth/gap/gap_bond_le.h b/component/common/bluetooth/realtek/sdk/inc/bluetooth/gap/gap_bond_le.h index f6b5fea0..fd350048 100644 --- a/component/common/bluetooth/realtek/sdk/inc/bluetooth/gap/gap_bond_le.h +++ b/component/common/bluetooth/realtek/sdk/inc/bluetooth/gap/gap_bond_le.h @@ -1,752 +1,752 @@ -/** -***************************************************************************************** -* Copyright(c) 2016, Realtek Semiconductor Corporation. All rights reserved. -***************************************************************************************** - * @file gap_bond_le.h - * @brief This file contains all the functions prototypes for the GAP bond and pairing - * related functions. - * @details - * @author ranhui - * @date 2016-02-18 - * @version v1.0 - * ************************************************************************************* - */ - -/*============================================================================* - * Define to prevent recursive inclusion - *============================================================================*/ -#ifndef GAP_BOND_LE_H -#define GAP_BOND_LE_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -/*============================================================================* - * Header Files - *============================================================================*/ -#include -#include - - -/** @defgroup GAP_LE_Bond_Manager GAP LE Bond Manager - * @brief GAP LE Bond Manager - * @{ - */ -/*============================================================================* - * Types - *============================================================================*/ -/** @defgroup GAP_LE_BOND_MANAGER_Exported_Types GAP LE Bond Manager Exported Types - * @{ - */ - -/** @brief LE bond parameter types */ -typedef enum -{ -#if F_BT_LE_SMP_OOB_SUPPORT - GAP_PARAM_BOND_OOB_DATA = 0x210,//!< OOB Data. Read/Write. size uint8_t[16]. Default is all 0's. -#endif - GAP_PARAM_BOND_FIXED_PASSKEY = 0x211,//!< The fix passcode for MITM protection. Read/Write. size is uint32_t. Range is 0 - 999,999. Default is 0. - GAP_PARAM_BOND_FIXED_PASSKEY_ENABLE = 0x212,//!< The fix passcode available for pairing. Read/Write. size is uint8_t. Default is 0(disabled). - GAP_PARAM_BOND_SEC_REQ_ENABLE = 0x213,//!< Send smp security request when connected. Read/Write. size is uint8_t. Default is 0(disabled). - GAP_PARAM_BOND_SEC_REQ_REQUIREMENT = 0x214,//!< Security request requirements. Read/Write. size is uint8_t. Default is GAP_AUTHEN_BIT_BONDING_FLAG (@ref BOND_MITM_DEFINES) - GAP_PARAM_BOND_MIN_KEY_SIZE = 0x215,//!< Minium LTK size required. Read/Write. size is uint8_t. -#if F_BT_LE_LOCAL_IRK_SETTING_SUPPORT - GAP_PARAM_BOND_GEN_LOCAL_IRK_AUTO = 0x216,//!< Auto generate local IRK. Write only. size is uint8_t. Default is 0(disabled). - GAP_PARAM_BOND_SET_LOCAL_IRK = 0x217,//!< Set local IRK. Write only. size is uint8_t. Default is all zero. -#endif - GAP_PARAM_BOND_KEY_MANAGER = 0x218,//!< Key manager. Write only. size is uint8_t. Default is 0(disabled). - GAP_PARAM_BOND_SIGN_KEY_FLAG = 0x219,//!< Sign key flag configure. Write only. size is uint8_t. Default is 0(disabled). -} T_LE_BOND_PARAM_TYPE; - -/** End of GAP_LE_BOND_MANAGER_Exported_Types -* @} -*/ - - -/*============================================================================* - * Functions - *============================================================================*/ -/** @defgroup GAP_LE_BONDMGR_Exported_Functions GAP LE Bond Manager Exported Functions - * @brief - * @{ - */ - -/** - * @brief Set a GAP Bond Manager Parameter. - * - * NOTE: You can call this function with a bond parameter type and it will set the - * bond parameter. Bond parameters are defined in @ref T_LE_BOND_PARAM_TYPE. - * if the "len" field sets to the size of a "uint16_t" ,the - * "p_value" field must point to a data with type of "uint16_t". - * - * @param[in] param Bond parameter type: @ref T_LE_BOND_PARAM_TYPE - * @param[in] len Length of data to write - * @param[in] p_value Pointer to data to write. This is dependent on - * the parameter type and will be cast to the appropriate - * data type (For example: if data type param is uint16, p_value will be cast to - * pointer of uint16_t). - * - * @return Set result - * @retval GAP_CAUSE_SUCCESS Operation success. - * @retval Others Operation failure. No connection. - * - * Example usage - * \code{.c} - void app_le_gap_init(void) - { - ... - uint8_t auth_use_fix_passkey = false; - uint32_t auth_fix_passkey = 0; - uint8_t auth_sec_req_enable = false; - uint16_t auth_sec_req_flags = GAP_AUTHEN_BIT_NONE; - - le_bond_set_param(GAP_PARAM_BOND_FIXED_PASSKEY, sizeof(auth_fix_passkey), &auth_fix_passkey); - le_bond_set_param(GAP_PARAM_BOND_FIXED_PASSKEY_ENABLE, sizeof(auth_use_fix_passkey), - &auth_use_fix_passkey); - le_bond_set_param(GAP_PARAM_BOND_SEC_REQ_ENABLE, sizeof(auth_sec_req_enable), &auth_sec_req_enable); - le_bond_set_param(GAP_PARAM_BOND_SEC_REQ_REQUIREMENT, sizeof(auth_sec_req_flags), - &auth_sec_req_flags); - .... - } - * \endcode - */ -T_GAP_CAUSE le_bond_set_param(T_LE_BOND_PARAM_TYPE param, uint8_t len, void *p_value); - -/** - * @brief Get a GAP Bond Manager Parameter. - * - * NOTE: You can call this function with a bond parameter type and it will get a - * bond parameter. Bond parameters are defined in @ref T_LE_BOND_PARAM_TYPE. Also, the - * "p_value" field must point to a "uint16". - * - * @param[in] param Profile parameter ID: @ref T_LE_BOND_PARAM_TYPE - * @param[in,out] p_value pointer to location to get the value. This is dependent on - * the parameter type and will be cast to the appropriate - * data type (For example: if data type param is uint16, p_value will be cast to - * pointer of uint16_t). - * - * @return Get result - * @retval GAP_CAUSE_SUCCESS Get parameter success. - * @retval other Get parameter failed. - * - * Example usage - * \code{.c} - void test(void) - { - uint8_t seq_req; - le_bond_get_param(GAP_PARAM_BOND_SEC_REQ_ENABLE, &seq_req); - } - * \endcode - */ -T_GAP_CAUSE le_bond_get_param(T_LE_BOND_PARAM_TYPE param, void *p_value); - -/** - * @brief Start authentication the link. - * - * NOTE: If the link has not been bonded, it will trigger pairing procedure, otherwise - * it will trigger the link encryption procedure. - * @param[in] conn_id Connection ID. - * @return Operation result. - * @retval GAP_CAUSE_SUCCESS Operation success. - * @retval GAP_CAUSE_NON_CONN Operation failure. No connection. - * - * Example usage - * \code{.c} - void test(void) - { - uint8_t conn_id = 0x01; - le_bond_pair(conn_id); - } - - void app_handle_authen_state_evt(uint8_t conn_id, uint8_t new_state, uint16_t cause) - { - APP_PRINT_INFO2("app_handle_authen_state_evt:conn_id %d, cause 0x%x", conn_id, cause); - - switch (new_state) - { - case GAP_AUTHEN_STATE_STARTED: - { - APP_PRINT_INFO0("app_handle_authen_state_evt: GAP_AUTHEN_STATE_STARTED"); - } - break; - - case GAP_AUTHEN_STATE_COMPLETE: - { - if (cause == GAP_SUCCESS) - { - APP_PRINT_INFO0("app_handle_authen_state_evt: GAP_AUTHEN_STATE_COMPLETE pair success"); - - } - else - { - APP_PRINT_INFO0("app_handle_authen_state_evt: GAP_AUTHEN_STATE_COMPLETE pair failed"); - } - } - break; - - default: - { - APP_PRINT_ERROR1("app_handle_authen_state_evt: unknown newstate %d", new_state); - } - break; - } - } - * \endcode - */ -T_GAP_CAUSE le_bond_pair(uint8_t conn_id); - -/** - * @brief Get the display key information - * - * @param[in] conn_id Connection ID. - * @param[in,out] p_key Passkey valueto be displayed as a 6 digit decimal number. - * @return Operation result. - * @retval GAP_CAUSE_SUCCESS Operation success. - * @retval GAP_CAUSE_NON_CONN Operation failure. No connection. - * - * Example usage - * \code{.c} - void app_handle_gap_msg(T_IO_MSG *p_io_msg) - { - T_LE_GAP_MSG bt_msg; - uint8_t conn_id; - - memcpy(&bt_msg, &p_io_msg->u.param, sizeof(p_io_msg->u.param)); - - switch (p_io_msg->subtype) - { - ... - case GAP_MSG_LE_BOND_PASSKEY_DISPLAY: - { - uint32_t display_value = 0; - conn_id = gap_msg.msg_data.gap_bond_passkey_display.conn_id; - le_bond_get_display_key(conn_id, &display_value); - APP_PRINT_INFO1("GAP_MSG_LE_BOND_PASSKEY_DISPLAY:passkey %d", display_value); - le_bond_passkey_display_confirm(conn_id, GAP_CFM_CAUSE_ACCEPT); - } - break; - ... - } - ... - } - * \endcode - */ -T_GAP_CAUSE le_bond_get_display_key(uint8_t conn_id, uint32_t *p_key); - -/** - * @brief Send passkey to gap bond manager when pairing with passkey entry, - * and local should input passkey. - * - * @param[in] conn_id Connection ID. - * @param[in] passcode Result of Keyboard input. - * @param[in] cause User confirm result. - * @return Operation result. - * @retval GAP_CAUSE_SUCCESS Operation success. - * @retval GAP_CAUSE_NON_CONN Operation failure. No connection. - * - * Example usage - * \code{.c} - void app_handle_gap_msg(T_IO_MSG *p_io_msg) - { - T_LE_GAP_MSG bt_msg; - uint8_t conn_id; - - memcpy(&bt_msg, &p_io_msg->u.param, sizeof(p_io_msg->u.param)); - - switch (p_io_msg->subtype) - { - ... - case GAP_MSG_LE_BOND_PASSKEY_INPUT: - { - conn_id = bt_msg.msg_data.gap_bond_passkey_input.conn_id; - APP_PRINT_INFO0("GAP_MSG_LE_BOND_PASSKEY_INPUT"); - uint32_t passKey = 888888; - le_bond_passkey_input_confirm(conn_id, passKey, GAP_CFM_CAUSE_ACCEPT); - } - break; - ... - } - ... - } - * \endcode - */ -T_GAP_CAUSE le_bond_passkey_input_confirm(uint8_t conn_id, uint32_t passcode, - T_GAP_CFM_CAUSE cause); - -/** - * @brief Send oob data to gap bond manager when pairing with out of bond, - * and local should input oob data. - * @param[in] conn_id connection ID. - * @param[in] cause User confirm result. - * @return Operation result. - * @retval GAP_CAUSE_SUCCESS Operation success. - * @retval GAP_CAUSE_NON_CONN Operation failure. No connection. - * - * Example usage - * \code{.c} - void app_handle_gap_msg(T_IO_MSG *p_io_msg) - { - T_LE_GAP_MSG bt_msg; - uint8_t conn_id; - - memcpy(&bt_msg, &p_io_msg->u.param, sizeof(p_io_msg->u.param)); - - switch (p_io_msg->subtype) - { - ... - case GAP_MSG_LE_BOND_OOB_INPUT: - { - conn_id = bt_msg.msg_data.gap_bond_oob_input.conn_id; - APP_PRINT_INFO0("GAP_MSG_LE_BOND_OOB_INPUT"); - uint8_t ooBData[GAP_OOB_LEN] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - le_bond_set_param(GAP_PARAM_BOND_OOB_DATA, GAP_OOB_LEN, ooBData); - le_bond_oob_input_confirm(conn_id, GAP_CFM_CAUSE_ACCEPT); - } - break; - ... - } - ... - } - * \endcode - */ -#if F_BT_LE_SMP_OOB_SUPPORT -T_GAP_CAUSE le_bond_oob_input_confirm(uint8_t conn_id, T_GAP_CFM_CAUSE cause); -#endif -/** - * @brief Send user confirmation request to confirm result to upper stack when - pairing with jsut work. - * @param[in] conn_id Connection ID. - * @param[in] cause User confirm result. - * @return Operation result. - * @retval GAP_CAUSE_SUCCESS Operation success. - * @retval GAP_CAUSE_NON_CONN Operation failure. No connection. - * - * Example usage - * \code{.c} - void app_handle_gap_msg(T_IO_MSG *p_io_msg) - { - T_LE_GAP_MSG bt_msg; - uint8_t conn_id; - - memcpy(&bt_msg, &p_io_msg->u.param, sizeof(p_io_msg->u.param)); - - switch (p_io_msg->subtype) - { - ... - case GAP_MSG_LE_BOND_JUST_WORK: - { - conn_id = gap_msg.msg_data.gap_bond_just_work_conf.conn_id; - le_bond_just_work_confirm(conn_id, GAP_CFM_CAUSE_ACCEPT); - APP_PRINT_INFO0("GAP_MSG_LE_BOND_JUST_WORK"); - } - break; - ... - } - ... - } - * \endcode - */ -T_GAP_CAUSE le_bond_just_work_confirm(uint8_t conn_id, T_GAP_CFM_CAUSE cause); - - -/** - * @brief Send user confirmation request to confirm result to upper stack when - pairing with passkey entry, and local shall display a passkey. - * @param[in] conn_id Connection ID. - * @param[in] cause User confirm result. - * @return Operation result. - * @retval GAP_CAUSE_SUCCESS Operation success. - * @retval GAP_CAUSE_NON_CONN Operation failure. No connection. - * - * Example usage - * \code{.c} - void app_handle_gap_msg(T_IO_MSG *p_io_msg) - { - T_LE_GAP_MSG bt_msg; - uint8_t conn_id; - - memcpy(&bt_msg, &p_io_msg->u.param, sizeof(p_io_msg->u.param)); - - switch (p_io_msg->subtype) - { - ... - case GAP_MSG_LE_BOND_PASSKEY_DISPLAY: - { - uint32_t display_value = 0; - conn_id = gap_msg.msg_data.gap_bond_passkey_display.conn_id; - le_bond_get_display_key(conn_id, &display_value); - APP_PRINT_INFO1("GAP_MSG_LE_BOND_PASSKEY_DISPLAY:passkey %d", display_value); - le_bond_passkey_display_confirm(conn_id, GAP_CFM_CAUSE_ACCEPT); - } - break; - ... - } - ... - } - * \endcode - */ -T_GAP_CAUSE le_bond_passkey_display_confirm(uint8_t conn_id, T_GAP_CFM_CAUSE cause); - -/** - * @brief Send user confirmation request to confirm result to upper stack - * @param[in] conn_id Connection ID. - * @param[in] cause User confirm result. - * @return Operation result. - * @retval GAP_CAUSE_SUCCESS Operation success. - * @retval GAP_CAUSE_NON_CONN Operation failure. No connection. - * - * Example usage - * \code{.c} - void app_handle_gap_msg(T_IO_MSG *p_io_msg) - { - T_LE_GAP_MSG bt_msg; - uint8_t conn_id; - - memcpy(&bt_msg, &p_io_msg->u.param, sizeof(p_io_msg->u.param)); - - switch (p_io_msg->subtype) - { - ... - case GAP_MSG_LE_BOND_USER_CONFIRMATION: - { - uint32_t display_value = 0; - conn_id = gap_msg.msg_data.gap_bond_user_conf.conn_id; - le_bond_get_display_key(conn_id, &display_value); - APP_PRINT_INFO1("GAP_MSG_LE_BOND_USER_CONFIRMATION: passkey %d", display_value); - le_bond_user_confirm(conn_id, GAP_CFM_CAUSE_ACCEPT); - } - break; - ... - } - ... - } - * \endcode - */ -#if F_BT_LE_4_2_SC_SUPPORT -T_GAP_CAUSE le_bond_user_confirm(uint8_t conn_id, T_GAP_CFM_CAUSE cause); -#endif - -/** - * @brief Set local key distribution field - * @param[in] init_dist Initiator key distribution. - * @param[in] rsp_dist Responder key distribution. - * @return Operation result. - * @retval GAP_CAUSE_SUCCESS Operation success. - * @retval Others Operation failure. No connection. - * - * Example usage - * \code{.c} - static T_USER_CMD_PARSE_RESULT cmd_setkeydis(T_USER_CMD_PARSED_VALUE *p_parse_value) - { - uint8_t init_dist = p_parse_value->dw_param[0]; - uint8_t rsp_dist = p_parse_value->dw_param[1]; - le_bond_cfg_local_key_distribute(init_dist, rsp_dist); - return (RESULT_SUCESS); - } - * \endcode - */ -T_GAP_CAUSE le_bond_cfg_local_key_distribute(uint8_t init_dist, uint8_t rsp_dist); - -/** - * @brief Erase all link keys of bonded devices - * @return void - * - * Example usage - * \code{.c} - T_APP_RESULT app_gap_callback(uint8_t cb_type, void *p_cb_data) - { - T_APP_RESULT result = APP_RESULT_SUCCESS; - T_LE_CB_DATA cb_data; - memcpy(&cb_data, p_cb_data, sizeof(T_LE_CB_DATA)); - APP_PRINT_TRACE1("app_gap_callback: cb_type = %d", cb_type); - switch (cb_type) - { - ... - case GAP_MSG_LE_BOND_MODIFY_INFO: - app_handle_bond_modify_msg(cb_data.p_le_bond_modify_info->type, - cb_data.p_le_bond_modify_info->p_entry); - break; - ... - } - } - - void app_handle_bond_modify_msg(T_LE_BOND_MODIFY_TYPE type, T_LE_KEY_ENTRY *p_entry) - { - APP_PRINT_INFO1("app_handle_bond_modify_msg GAP_MSG_LE_BOND_MODIFY_INFO:type=0x%x", - type); - if (type == LE_BOND_CLEAR) - { - privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_CLEAR, GAP_IDENT_ADDR_PUBLIC, - NULL); - privacy_handle_pending_resolving_list(); - } - else if (type == LE_BOND_ADD) - { - if (p_entry->flags & LE_KEY_STORE_REMOTE_IRK_BIT) - { - privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_ADD, - (T_GAP_IDENT_ADDR_TYPE)p_entry->resolved_remote_bd.remote_bd_type, - p_entry->resolved_remote_bd.addr); - } - else if (p_entry->flags & LE_KEY_STORE_LOCAL_IRK_BIT) - { - privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_ADD, - (T_GAP_IDENT_ADDR_TYPE)p_entry->remote_bd.remote_bd_type, - p_entry->remote_bd.addr); - } - else - { - } - privacy_handle_pending_resolving_list(); - } - else if (type == LE_BOND_DELETE) - { - if (p_entry->flags & LE_KEY_STORE_REMOTE_IRK_BIT) - { - privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_REMOVE, - (T_GAP_IDENT_ADDR_TYPE)p_entry->resolved_remote_bd.remote_bd_type, - p_entry->resolved_remote_bd.addr); - } - else if (p_entry->flags & LE_KEY_STORE_LOCAL_IRK_BIT) - { - privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_REMOVE, - (T_GAP_IDENT_ADDR_TYPE)p_entry->remote_bd.remote_bd_type, - p_entry->remote_bd.addr); - } - else - { - } - privacy_handle_pending_resolving_list(); - } - else - { - } - } - * \endcode - */ -void le_bond_clear_all_keys(void); - -/** - * @brief Delete bond information by index - * @param[in] idx Index of key entry. - * @return Operation result. - * @retval GAP_CAUSE_SUCCESS: Operation success. - * @retval GAP_CAUSE_NOT_FIND: Operation failure. Not found. - * - * Example usage - * \code{.c} - T_APP_RESULT app_gap_callback(uint8_t cb_type, void *p_cb_data) - { - T_APP_RESULT result = APP_RESULT_SUCCESS; - T_LE_CB_DATA cb_data; - memcpy(&cb_data, p_cb_data, sizeof(T_LE_CB_DATA)); - APP_PRINT_TRACE1("app_gap_callback: cb_type = %d", cb_type); - switch (cb_type) - { - ... - case GAP_MSG_LE_BOND_MODIFY_INFO: - app_handle_bond_modify_msg(cb_data.p_le_bond_modify_info->type, - cb_data.p_le_bond_modify_info->p_entry); - break; - ... - } - } - - void app_handle_bond_modify_msg(T_LE_BOND_MODIFY_TYPE type, T_LE_KEY_ENTRY *p_entry) - { - APP_PRINT_INFO1("app_handle_bond_modify_msg GAP_MSG_LE_BOND_MODIFY_INFO:type=0x%x", - type); - if (type == LE_BOND_CLEAR) - { - privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_CLEAR, GAP_IDENT_ADDR_PUBLIC, - NULL); - privacy_handle_pending_resolving_list(); - } - else if (type == LE_BOND_ADD) - { - if (p_entry->flags & LE_KEY_STORE_REMOTE_IRK_BIT) - { - privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_ADD, - (T_GAP_IDENT_ADDR_TYPE)p_entry->resolved_remote_bd.remote_bd_type, - p_entry->resolved_remote_bd.addr); - } - else if (p_entry->flags & LE_KEY_STORE_LOCAL_IRK_BIT) - { - privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_ADD, - (T_GAP_IDENT_ADDR_TYPE)p_entry->remote_bd.remote_bd_type, - p_entry->remote_bd.addr); - } - else - { - } - privacy_handle_pending_resolving_list(); - } - else if (type == LE_BOND_DELETE) - { - if (p_entry->flags & LE_KEY_STORE_REMOTE_IRK_BIT) - { - privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_REMOVE, - (T_GAP_IDENT_ADDR_TYPE)p_entry->resolved_remote_bd.remote_bd_type, - p_entry->resolved_remote_bd.addr); - } - else if (p_entry->flags & LE_KEY_STORE_LOCAL_IRK_BIT) - { - privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_REMOVE, - (T_GAP_IDENT_ADDR_TYPE)p_entry->remote_bd.remote_bd_type, - p_entry->remote_bd.addr); - } - else - { - } - privacy_handle_pending_resolving_list(); - } - else - { - } - } - * \endcode - */ -T_GAP_CAUSE le_bond_delete_by_idx(uint8_t idx); - -/** - * @brief Delete bond information by bluetooth device address and address type - * @param[in] bd_addr Bonded bluetooth device address. - * @param[in] bd_type Bonded bluetooth device address type. - * @return Operation result. - * @retval GAP_CAUSE_SUCCESS: Operation success. - * @retval GAP_CAUSE_NOT_FIND: Operation failure. Not found. - * - * Example usage - * \code{.c} - T_APP_RESULT app_gap_callback(uint8_t cb_type, void *p_cb_data) - { - T_APP_RESULT result = APP_RESULT_SUCCESS; - T_LE_CB_DATA cb_data; - memcpy(&cb_data, p_cb_data, sizeof(T_LE_CB_DATA)); - APP_PRINT_TRACE1("app_gap_callback: cb_type = %d", cb_type); - switch (cb_type) - { - ... - case GAP_MSG_LE_BOND_MODIFY_INFO: - app_handle_bond_modify_msg(cb_data.p_le_bond_modify_info->type, - cb_data.p_le_bond_modify_info->p_entry); - break; - ... - } - } - - void app_handle_bond_modify_msg(T_LE_BOND_MODIFY_TYPE type, T_LE_KEY_ENTRY *p_entry) - { - APP_PRINT_INFO1("app_handle_bond_modify_msg GAP_MSG_LE_BOND_MODIFY_INFO:type=0x%x", - type); - if (type == LE_BOND_CLEAR) - { - privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_CLEAR, GAP_IDENT_ADDR_PUBLIC, - NULL); - privacy_handle_pending_resolving_list(); - } - else if (type == LE_BOND_ADD) - { - if (p_entry->flags & LE_KEY_STORE_REMOTE_IRK_BIT) - { - privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_ADD, - (T_GAP_IDENT_ADDR_TYPE)p_entry->resolved_remote_bd.remote_bd_type, - p_entry->resolved_remote_bd.addr); - } - else if (p_entry->flags & LE_KEY_STORE_LOCAL_IRK_BIT) - { - privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_ADD, - (T_GAP_IDENT_ADDR_TYPE)p_entry->remote_bd.remote_bd_type, - p_entry->remote_bd.addr); - } - else - { - } - privacy_handle_pending_resolving_list(); - } - else if (type == LE_BOND_DELETE) - { - if (p_entry->flags & LE_KEY_STORE_REMOTE_IRK_BIT) - { - privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_REMOVE, - (T_GAP_IDENT_ADDR_TYPE)p_entry->resolved_remote_bd.remote_bd_type, - p_entry->resolved_remote_bd.addr); - } - else if (p_entry->flags & LE_KEY_STORE_LOCAL_IRK_BIT) - { - privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_REMOVE, - (T_GAP_IDENT_ADDR_TYPE)p_entry->remote_bd.remote_bd_type, - p_entry->remote_bd.addr); - } - else - { - } - privacy_handle_pending_resolving_list(); - } - else - { - } - } - * \endcode - */ -T_GAP_CAUSE le_bond_delete_by_bd(uint8_t *bd_addr, T_GAP_REMOTE_ADDR_TYPE bd_type); - -/** - * @brief Get the security level. - * @param[in] conn_id Connection ID. - * @param[out] p_type Pointer to location to get the security level. - * @return Operation result. - * @retval GAP_CAUSE_SUCCESS Operation success. - * @retval GAP_CAUSE_INVALID_PARAM Operation failure. No connection. - * - * Example usage - * \code{.c} - static T_USER_CMD_PARSE_RESULT cmd_seclevel(T_USER_CMD_PARSED_VALUE *p_parse_value) - { - T_GAP_CAUSE cause; - T_GAP_SEC_LEVEL sec_level; - uint8_t conn_id = p_parse_value->dw_param[0]; - - cause = le_bond_get_sec_level(conn_id, &sec_level); - if(sec_level == GAP_SEC_LEVEL_NO) - { - data_uart_print("GAP_SEC_LEVEL_NO\r\n"); - } - else if(sec_level == GAP_SEC_LEVEL_UNAUTHEN) - { - data_uart_print("GAP_SEC_LEVEL_UNAUTHEN\r\n"); - } - else if(sec_level == GAP_SEC_LEVEL_AUTHEN) - { - data_uart_print("GAP_SEC_LEVEL_AUTHEN\r\n"); - } - else if(sec_level == GAP_SEC_LEVEL_SC_UNAUTHEN) - { - data_uart_print("GAP_SEC_LEVEL_SC_UNAUTHEN\r\n"); - } - else if(sec_level == GAP_SEC_LEVEL_SC_AUTHEN) - { - data_uart_print("GAP_SEC_LEVEL_SC_AUTHEN\r\n"); - } - return (T_USER_CMD_PARSE_RESULT)cause; - } - * \endcode - */ -T_GAP_CAUSE le_bond_get_sec_level(uint8_t conn_id, T_GAP_SEC_LEVEL *p_type); - -/** End of GAP_LE_BONDMGR_Exported_Functions - * @} - */ - -/** End of GAP_LE_Bond_Manager - * @} - */ - - -#ifdef __cplusplus -} -#endif - -#endif /* GAP_BOND_LE_H */ +/** +***************************************************************************************** +* Copyright(c) 2016, Realtek Semiconductor Corporation. All rights reserved. +***************************************************************************************** + * @file gap_bond_le.h + * @brief This file contains all the functions prototypes for the GAP bond and pairing + * related functions. + * @details + * @author ranhui + * @date 2016-02-18 + * @version v1.0 + * ************************************************************************************* + */ + +/*============================================================================* + * Define to prevent recursive inclusion + *============================================================================*/ +#ifndef GAP_BOND_LE_H +#define GAP_BOND_LE_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +/*============================================================================* + * Header Files + *============================================================================*/ +#include +#include + + +/** @defgroup GAP_LE_Bond_Manager GAP LE Bond Manager + * @brief GAP LE Bond Manager + * @{ + */ +/*============================================================================* + * Types + *============================================================================*/ +/** @defgroup GAP_LE_BOND_MANAGER_Exported_Types GAP LE Bond Manager Exported Types + * @{ + */ + +/** @brief LE bond parameter types */ +typedef enum +{ +#if F_BT_LE_SMP_OOB_SUPPORT + GAP_PARAM_BOND_OOB_DATA = 0x210,//!< OOB Data. Read/Write. size uint8_t[16]. Default is all 0's. +#endif + GAP_PARAM_BOND_FIXED_PASSKEY = 0x211,//!< The fix passcode for MITM protection. Read/Write. size is uint32_t. Range is 0 - 999,999. Default is 0. + GAP_PARAM_BOND_FIXED_PASSKEY_ENABLE = 0x212,//!< The fix passcode available for pairing. Read/Write. size is uint8_t. Default is 0(disabled). + GAP_PARAM_BOND_SEC_REQ_ENABLE = 0x213,//!< Send smp security request when connected. Read/Write. size is uint8_t. Default is 0(disabled). + GAP_PARAM_BOND_SEC_REQ_REQUIREMENT = 0x214,//!< Security request requirements. Read/Write. size is uint8_t. Default is GAP_AUTHEN_BIT_BONDING_FLAG (@ref BOND_MITM_DEFINES) + GAP_PARAM_BOND_MIN_KEY_SIZE = 0x215,//!< Minium LTK size required. Read/Write. size is uint8_t. +#if F_BT_LE_LOCAL_IRK_SETTING_SUPPORT + GAP_PARAM_BOND_GEN_LOCAL_IRK_AUTO = 0x216,//!< Auto generate local IRK. Write only. size is uint8_t. Default is 0(disabled). + GAP_PARAM_BOND_SET_LOCAL_IRK = 0x217,//!< Set local IRK. Write only. size is uint8_t. Default is all zero. +#endif + GAP_PARAM_BOND_KEY_MANAGER = 0x218,//!< Key manager. Write only. size is uint8_t. Default is 0(disabled). + GAP_PARAM_BOND_SIGN_KEY_FLAG = 0x219,//!< Sign key flag configure. Write only. size is uint8_t. Default is 0(disabled). +} T_LE_BOND_PARAM_TYPE; + +/** End of GAP_LE_BOND_MANAGER_Exported_Types +* @} +*/ + + +/*============================================================================* + * Functions + *============================================================================*/ +/** @defgroup GAP_LE_BONDMGR_Exported_Functions GAP LE Bond Manager Exported Functions + * @brief + * @{ + */ + +/** + * @brief Set a GAP Bond Manager Parameter. + * + * NOTE: You can call this function with a bond parameter type and it will set the + * bond parameter. Bond parameters are defined in @ref T_LE_BOND_PARAM_TYPE. + * if the "len" field sets to the size of a "uint16_t" ,the + * "p_value" field must point to a data with type of "uint16_t". + * + * @param[in] param Bond parameter type: @ref T_LE_BOND_PARAM_TYPE + * @param[in] len Length of data to write + * @param[in] p_value Pointer to data to write. This is dependent on + * the parameter type and will be cast to the appropriate + * data type (For example: if data type param is uint16, p_value will be cast to + * pointer of uint16_t). + * + * @return Set result + * @retval GAP_CAUSE_SUCCESS Operation success. + * @retval Others Operation failure. No connection. + * + * Example usage + * \code{.c} + void app_le_gap_init(void) + { + ... + uint8_t auth_use_fix_passkey = false; + uint32_t auth_fix_passkey = 0; + uint8_t auth_sec_req_enable = false; + uint16_t auth_sec_req_flags = GAP_AUTHEN_BIT_NONE; + + le_bond_set_param(GAP_PARAM_BOND_FIXED_PASSKEY, sizeof(auth_fix_passkey), &auth_fix_passkey); + le_bond_set_param(GAP_PARAM_BOND_FIXED_PASSKEY_ENABLE, sizeof(auth_use_fix_passkey), + &auth_use_fix_passkey); + le_bond_set_param(GAP_PARAM_BOND_SEC_REQ_ENABLE, sizeof(auth_sec_req_enable), &auth_sec_req_enable); + le_bond_set_param(GAP_PARAM_BOND_SEC_REQ_REQUIREMENT, sizeof(auth_sec_req_flags), + &auth_sec_req_flags); + .... + } + * \endcode + */ +T_GAP_CAUSE le_bond_set_param(T_LE_BOND_PARAM_TYPE param, uint8_t len, void *p_value); + +/** + * @brief Get a GAP Bond Manager Parameter. + * + * NOTE: You can call this function with a bond parameter type and it will get a + * bond parameter. Bond parameters are defined in @ref T_LE_BOND_PARAM_TYPE. Also, the + * "p_value" field must point to a "uint16". + * + * @param[in] param Profile parameter ID: @ref T_LE_BOND_PARAM_TYPE + * @param[in,out] p_value pointer to location to get the value. This is dependent on + * the parameter type and will be cast to the appropriate + * data type (For example: if data type param is uint16, p_value will be cast to + * pointer of uint16_t). + * + * @return Get result + * @retval GAP_CAUSE_SUCCESS Get parameter success. + * @retval other Get parameter failed. + * + * Example usage + * \code{.c} + void test(void) + { + uint8_t seq_req; + le_bond_get_param(GAP_PARAM_BOND_SEC_REQ_ENABLE, &seq_req); + } + * \endcode + */ +T_GAP_CAUSE le_bond_get_param(T_LE_BOND_PARAM_TYPE param, void *p_value); + +/** + * @brief Start authentication the link. + * + * NOTE: If the link has not been bonded, it will trigger pairing procedure, otherwise + * it will trigger the link encryption procedure. + * @param[in] conn_id Connection ID. + * @return Operation result. + * @retval GAP_CAUSE_SUCCESS Operation success. + * @retval GAP_CAUSE_NON_CONN Operation failure. No connection. + * + * Example usage + * \code{.c} + void test(void) + { + uint8_t conn_id = 0x01; + le_bond_pair(conn_id); + } + + void app_handle_authen_state_evt(uint8_t conn_id, uint8_t new_state, uint16_t cause) + { + APP_PRINT_INFO2("app_handle_authen_state_evt:conn_id %d, cause 0x%x", conn_id, cause); + + switch (new_state) + { + case GAP_AUTHEN_STATE_STARTED: + { + APP_PRINT_INFO0("app_handle_authen_state_evt: GAP_AUTHEN_STATE_STARTED"); + } + break; + + case GAP_AUTHEN_STATE_COMPLETE: + { + if (cause == GAP_SUCCESS) + { + APP_PRINT_INFO0("app_handle_authen_state_evt: GAP_AUTHEN_STATE_COMPLETE pair success"); + + } + else + { + APP_PRINT_INFO0("app_handle_authen_state_evt: GAP_AUTHEN_STATE_COMPLETE pair failed"); + } + } + break; + + default: + { + APP_PRINT_ERROR1("app_handle_authen_state_evt: unknown newstate %d", new_state); + } + break; + } + } + * \endcode + */ +T_GAP_CAUSE le_bond_pair(uint8_t conn_id); + +/** + * @brief Get the display key information + * + * @param[in] conn_id Connection ID. + * @param[in,out] p_key Passkey valueto be displayed as a 6 digit decimal number. + * @return Operation result. + * @retval GAP_CAUSE_SUCCESS Operation success. + * @retval GAP_CAUSE_NON_CONN Operation failure. No connection. + * + * Example usage + * \code{.c} + void app_handle_gap_msg(T_IO_MSG *p_io_msg) + { + T_LE_GAP_MSG bt_msg; + uint8_t conn_id; + + memcpy(&bt_msg, &p_io_msg->u.param, sizeof(p_io_msg->u.param)); + + switch (p_io_msg->subtype) + { + ... + case GAP_MSG_LE_BOND_PASSKEY_DISPLAY: + { + uint32_t display_value = 0; + conn_id = gap_msg.msg_data.gap_bond_passkey_display.conn_id; + le_bond_get_display_key(conn_id, &display_value); + APP_PRINT_INFO1("GAP_MSG_LE_BOND_PASSKEY_DISPLAY:passkey %d", display_value); + le_bond_passkey_display_confirm(conn_id, GAP_CFM_CAUSE_ACCEPT); + } + break; + ... + } + ... + } + * \endcode + */ +T_GAP_CAUSE le_bond_get_display_key(uint8_t conn_id, uint32_t *p_key); + +/** + * @brief Send passkey to gap bond manager when pairing with passkey entry, + * and local should input passkey. + * + * @param[in] conn_id Connection ID. + * @param[in] passcode Result of Keyboard input. + * @param[in] cause User confirm result. + * @return Operation result. + * @retval GAP_CAUSE_SUCCESS Operation success. + * @retval GAP_CAUSE_NON_CONN Operation failure. No connection. + * + * Example usage + * \code{.c} + void app_handle_gap_msg(T_IO_MSG *p_io_msg) + { + T_LE_GAP_MSG bt_msg; + uint8_t conn_id; + + memcpy(&bt_msg, &p_io_msg->u.param, sizeof(p_io_msg->u.param)); + + switch (p_io_msg->subtype) + { + ... + case GAP_MSG_LE_BOND_PASSKEY_INPUT: + { + conn_id = bt_msg.msg_data.gap_bond_passkey_input.conn_id; + APP_PRINT_INFO0("GAP_MSG_LE_BOND_PASSKEY_INPUT"); + uint32_t passKey = 888888; + le_bond_passkey_input_confirm(conn_id, passKey, GAP_CFM_CAUSE_ACCEPT); + } + break; + ... + } + ... + } + * \endcode + */ +T_GAP_CAUSE le_bond_passkey_input_confirm(uint8_t conn_id, uint32_t passcode, + T_GAP_CFM_CAUSE cause); + +#if F_BT_LE_SMP_OOB_SUPPORT +/** + * @brief Send oob data to gap bond manager when pairing with out of bond, + * and local should input oob data. + * @param[in] conn_id connection ID. + * @param[in] cause User confirm result. + * @return Operation result. + * @retval GAP_CAUSE_SUCCESS Operation success. + * @retval GAP_CAUSE_NON_CONN Operation failure. No connection. + * + * Example usage + * \code{.c} + void app_handle_gap_msg(T_IO_MSG *p_io_msg) + { + T_LE_GAP_MSG bt_msg; + uint8_t conn_id; + + memcpy(&bt_msg, &p_io_msg->u.param, sizeof(p_io_msg->u.param)); + + switch (p_io_msg->subtype) + { + ... + case GAP_MSG_LE_BOND_OOB_INPUT: + { + conn_id = bt_msg.msg_data.gap_bond_oob_input.conn_id; + APP_PRINT_INFO0("GAP_MSG_LE_BOND_OOB_INPUT"); + uint8_t ooBData[GAP_OOB_LEN] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + le_bond_set_param(GAP_PARAM_BOND_OOB_DATA, GAP_OOB_LEN, ooBData); + le_bond_oob_input_confirm(conn_id, GAP_CFM_CAUSE_ACCEPT); + } + break; + ... + } + ... + } + * \endcode + */ +T_GAP_CAUSE le_bond_oob_input_confirm(uint8_t conn_id, T_GAP_CFM_CAUSE cause); +#endif +/** + * @brief Send user confirmation request to confirm result to upper stack when + pairing with jsut work. + * @param[in] conn_id Connection ID. + * @param[in] cause User confirm result. + * @return Operation result. + * @retval GAP_CAUSE_SUCCESS Operation success. + * @retval GAP_CAUSE_NON_CONN Operation failure. No connection. + * + * Example usage + * \code{.c} + void app_handle_gap_msg(T_IO_MSG *p_io_msg) + { + T_LE_GAP_MSG bt_msg; + uint8_t conn_id; + + memcpy(&bt_msg, &p_io_msg->u.param, sizeof(p_io_msg->u.param)); + + switch (p_io_msg->subtype) + { + ... + case GAP_MSG_LE_BOND_JUST_WORK: + { + conn_id = gap_msg.msg_data.gap_bond_just_work_conf.conn_id; + le_bond_just_work_confirm(conn_id, GAP_CFM_CAUSE_ACCEPT); + APP_PRINT_INFO0("GAP_MSG_LE_BOND_JUST_WORK"); + } + break; + ... + } + ... + } + * \endcode + */ +T_GAP_CAUSE le_bond_just_work_confirm(uint8_t conn_id, T_GAP_CFM_CAUSE cause); + + +/** + * @brief Send user confirmation request to confirm result to upper stack when + pairing with passkey entry, and local shall display a passkey. + * @param[in] conn_id Connection ID. + * @param[in] cause User confirm result. + * @return Operation result. + * @retval GAP_CAUSE_SUCCESS Operation success. + * @retval GAP_CAUSE_NON_CONN Operation failure. No connection. + * + * Example usage + * \code{.c} + void app_handle_gap_msg(T_IO_MSG *p_io_msg) + { + T_LE_GAP_MSG bt_msg; + uint8_t conn_id; + + memcpy(&bt_msg, &p_io_msg->u.param, sizeof(p_io_msg->u.param)); + + switch (p_io_msg->subtype) + { + ... + case GAP_MSG_LE_BOND_PASSKEY_DISPLAY: + { + uint32_t display_value = 0; + conn_id = gap_msg.msg_data.gap_bond_passkey_display.conn_id; + le_bond_get_display_key(conn_id, &display_value); + APP_PRINT_INFO1("GAP_MSG_LE_BOND_PASSKEY_DISPLAY:passkey %d", display_value); + le_bond_passkey_display_confirm(conn_id, GAP_CFM_CAUSE_ACCEPT); + } + break; + ... + } + ... + } + * \endcode + */ +T_GAP_CAUSE le_bond_passkey_display_confirm(uint8_t conn_id, T_GAP_CFM_CAUSE cause); + +#if F_BT_LE_4_2_SC_SUPPORT +/** + * @brief Send user confirmation request to confirm result to upper stack + * @param[in] conn_id Connection ID. + * @param[in] cause User confirm result. + * @return Operation result. + * @retval GAP_CAUSE_SUCCESS Operation success. + * @retval GAP_CAUSE_NON_CONN Operation failure. No connection. + * + * Example usage + * \code{.c} + void app_handle_gap_msg(T_IO_MSG *p_io_msg) + { + T_LE_GAP_MSG bt_msg; + uint8_t conn_id; + + memcpy(&bt_msg, &p_io_msg->u.param, sizeof(p_io_msg->u.param)); + + switch (p_io_msg->subtype) + { + ... + case GAP_MSG_LE_BOND_USER_CONFIRMATION: + { + uint32_t display_value = 0; + conn_id = gap_msg.msg_data.gap_bond_user_conf.conn_id; + le_bond_get_display_key(conn_id, &display_value); + APP_PRINT_INFO1("GAP_MSG_LE_BOND_USER_CONFIRMATION: passkey %d", display_value); + le_bond_user_confirm(conn_id, GAP_CFM_CAUSE_ACCEPT); + } + break; + ... + } + ... + } + * \endcode + */ +T_GAP_CAUSE le_bond_user_confirm(uint8_t conn_id, T_GAP_CFM_CAUSE cause); +#endif + +/** + * @brief Set local key distribution field + * @param[in] init_dist Initiator key distribution. + * @param[in] rsp_dist Responder key distribution. + * @return Operation result. + * @retval GAP_CAUSE_SUCCESS Operation success. + * @retval Others Operation failure. No connection. + * + * Example usage + * \code{.c} + static T_USER_CMD_PARSE_RESULT cmd_setkeydis(T_USER_CMD_PARSED_VALUE *p_parse_value) + { + uint8_t init_dist = p_parse_value->dw_param[0]; + uint8_t rsp_dist = p_parse_value->dw_param[1]; + le_bond_cfg_local_key_distribute(init_dist, rsp_dist); + return (RESULT_SUCESS); + } + * \endcode + */ +T_GAP_CAUSE le_bond_cfg_local_key_distribute(uint8_t init_dist, uint8_t rsp_dist); + +/** + * @brief Erase all link keys of bonded devices + * @return void + * + * Example usage + * \code{.c} + T_APP_RESULT app_gap_callback(uint8_t cb_type, void *p_cb_data) + { + T_APP_RESULT result = APP_RESULT_SUCCESS; + T_LE_CB_DATA cb_data; + memcpy(&cb_data, p_cb_data, sizeof(T_LE_CB_DATA)); + APP_PRINT_TRACE1("app_gap_callback: cb_type = %d", cb_type); + switch (cb_type) + { + ... + case GAP_MSG_LE_BOND_MODIFY_INFO: + app_handle_bond_modify_msg(cb_data.p_le_bond_modify_info->type, + cb_data.p_le_bond_modify_info->p_entry); + break; + ... + } + } + + void app_handle_bond_modify_msg(T_LE_BOND_MODIFY_TYPE type, T_LE_KEY_ENTRY *p_entry) + { + APP_PRINT_INFO1("app_handle_bond_modify_msg GAP_MSG_LE_BOND_MODIFY_INFO:type=0x%x", + type); + if (type == LE_BOND_CLEAR) + { + privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_CLEAR, GAP_IDENT_ADDR_PUBLIC, + NULL); + privacy_handle_pending_resolving_list(); + } + else if (type == LE_BOND_ADD) + { + if (p_entry->flags & LE_KEY_STORE_REMOTE_IRK_BIT) + { + privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_ADD, + (T_GAP_IDENT_ADDR_TYPE)p_entry->resolved_remote_bd.remote_bd_type, + p_entry->resolved_remote_bd.addr); + } + else if (p_entry->flags & LE_KEY_STORE_LOCAL_IRK_BIT) + { + privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_ADD, + (T_GAP_IDENT_ADDR_TYPE)p_entry->remote_bd.remote_bd_type, + p_entry->remote_bd.addr); + } + else + { + } + privacy_handle_pending_resolving_list(); + } + else if (type == LE_BOND_DELETE) + { + if (p_entry->flags & LE_KEY_STORE_REMOTE_IRK_BIT) + { + privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_REMOVE, + (T_GAP_IDENT_ADDR_TYPE)p_entry->resolved_remote_bd.remote_bd_type, + p_entry->resolved_remote_bd.addr); + } + else if (p_entry->flags & LE_KEY_STORE_LOCAL_IRK_BIT) + { + privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_REMOVE, + (T_GAP_IDENT_ADDR_TYPE)p_entry->remote_bd.remote_bd_type, + p_entry->remote_bd.addr); + } + else + { + } + privacy_handle_pending_resolving_list(); + } + else + { + } + } + * \endcode + */ +void le_bond_clear_all_keys(void); + +/** + * @brief Delete bond information by index + * @param[in] idx Index of key entry. + * @return Operation result. + * @retval GAP_CAUSE_SUCCESS: Operation success. + * @retval GAP_CAUSE_NOT_FIND: Operation failure. Not found. + * + * Example usage + * \code{.c} + T_APP_RESULT app_gap_callback(uint8_t cb_type, void *p_cb_data) + { + T_APP_RESULT result = APP_RESULT_SUCCESS; + T_LE_CB_DATA cb_data; + memcpy(&cb_data, p_cb_data, sizeof(T_LE_CB_DATA)); + APP_PRINT_TRACE1("app_gap_callback: cb_type = %d", cb_type); + switch (cb_type) + { + ... + case GAP_MSG_LE_BOND_MODIFY_INFO: + app_handle_bond_modify_msg(cb_data.p_le_bond_modify_info->type, + cb_data.p_le_bond_modify_info->p_entry); + break; + ... + } + } + + void app_handle_bond_modify_msg(T_LE_BOND_MODIFY_TYPE type, T_LE_KEY_ENTRY *p_entry) + { + APP_PRINT_INFO1("app_handle_bond_modify_msg GAP_MSG_LE_BOND_MODIFY_INFO:type=0x%x", + type); + if (type == LE_BOND_CLEAR) + { + privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_CLEAR, GAP_IDENT_ADDR_PUBLIC, + NULL); + privacy_handle_pending_resolving_list(); + } + else if (type == LE_BOND_ADD) + { + if (p_entry->flags & LE_KEY_STORE_REMOTE_IRK_BIT) + { + privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_ADD, + (T_GAP_IDENT_ADDR_TYPE)p_entry->resolved_remote_bd.remote_bd_type, + p_entry->resolved_remote_bd.addr); + } + else if (p_entry->flags & LE_KEY_STORE_LOCAL_IRK_BIT) + { + privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_ADD, + (T_GAP_IDENT_ADDR_TYPE)p_entry->remote_bd.remote_bd_type, + p_entry->remote_bd.addr); + } + else + { + } + privacy_handle_pending_resolving_list(); + } + else if (type == LE_BOND_DELETE) + { + if (p_entry->flags & LE_KEY_STORE_REMOTE_IRK_BIT) + { + privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_REMOVE, + (T_GAP_IDENT_ADDR_TYPE)p_entry->resolved_remote_bd.remote_bd_type, + p_entry->resolved_remote_bd.addr); + } + else if (p_entry->flags & LE_KEY_STORE_LOCAL_IRK_BIT) + { + privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_REMOVE, + (T_GAP_IDENT_ADDR_TYPE)p_entry->remote_bd.remote_bd_type, + p_entry->remote_bd.addr); + } + else + { + } + privacy_handle_pending_resolving_list(); + } + else + { + } + } + * \endcode + */ +T_GAP_CAUSE le_bond_delete_by_idx(uint8_t idx); + +/** + * @brief Delete bond information by bluetooth device address and address type + * @param[in] bd_addr Bonded bluetooth device address. + * @param[in] bd_type Bonded bluetooth device address type. + * @return Operation result. + * @retval GAP_CAUSE_SUCCESS: Operation success. + * @retval GAP_CAUSE_NOT_FIND: Operation failure. Not found. + * + * Example usage + * \code{.c} + T_APP_RESULT app_gap_callback(uint8_t cb_type, void *p_cb_data) + { + T_APP_RESULT result = APP_RESULT_SUCCESS; + T_LE_CB_DATA cb_data; + memcpy(&cb_data, p_cb_data, sizeof(T_LE_CB_DATA)); + APP_PRINT_TRACE1("app_gap_callback: cb_type = %d", cb_type); + switch (cb_type) + { + ... + case GAP_MSG_LE_BOND_MODIFY_INFO: + app_handle_bond_modify_msg(cb_data.p_le_bond_modify_info->type, + cb_data.p_le_bond_modify_info->p_entry); + break; + ... + } + } + + void app_handle_bond_modify_msg(T_LE_BOND_MODIFY_TYPE type, T_LE_KEY_ENTRY *p_entry) + { + APP_PRINT_INFO1("app_handle_bond_modify_msg GAP_MSG_LE_BOND_MODIFY_INFO:type=0x%x", + type); + if (type == LE_BOND_CLEAR) + { + privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_CLEAR, GAP_IDENT_ADDR_PUBLIC, + NULL); + privacy_handle_pending_resolving_list(); + } + else if (type == LE_BOND_ADD) + { + if (p_entry->flags & LE_KEY_STORE_REMOTE_IRK_BIT) + { + privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_ADD, + (T_GAP_IDENT_ADDR_TYPE)p_entry->resolved_remote_bd.remote_bd_type, + p_entry->resolved_remote_bd.addr); + } + else if (p_entry->flags & LE_KEY_STORE_LOCAL_IRK_BIT) + { + privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_ADD, + (T_GAP_IDENT_ADDR_TYPE)p_entry->remote_bd.remote_bd_type, + p_entry->remote_bd.addr); + } + else + { + } + privacy_handle_pending_resolving_list(); + } + else if (type == LE_BOND_DELETE) + { + if (p_entry->flags & LE_KEY_STORE_REMOTE_IRK_BIT) + { + privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_REMOVE, + (T_GAP_IDENT_ADDR_TYPE)p_entry->resolved_remote_bd.remote_bd_type, + p_entry->resolved_remote_bd.addr); + } + else if (p_entry->flags & LE_KEY_STORE_LOCAL_IRK_BIT) + { + privacy_add_pending_resolving_list(GAP_RESOLV_LIST_OP_REMOVE, + (T_GAP_IDENT_ADDR_TYPE)p_entry->remote_bd.remote_bd_type, + p_entry->remote_bd.addr); + } + else + { + } + privacy_handle_pending_resolving_list(); + } + else + { + } + } + * \endcode + */ +T_GAP_CAUSE le_bond_delete_by_bd(uint8_t *bd_addr, T_GAP_REMOTE_ADDR_TYPE bd_type); + +/** + * @brief Get the security level. + * @param[in] conn_id Connection ID. + * @param[out] p_type Pointer to location to get the security level. + * @return Operation result. + * @retval GAP_CAUSE_SUCCESS Operation success. + * @retval GAP_CAUSE_INVALID_PARAM Operation failure. No connection. + * + * Example usage + * \code{.c} + static T_USER_CMD_PARSE_RESULT cmd_seclevel(T_USER_CMD_PARSED_VALUE *p_parse_value) + { + T_GAP_CAUSE cause; + T_GAP_SEC_LEVEL sec_level; + uint8_t conn_id = p_parse_value->dw_param[0]; + + cause = le_bond_get_sec_level(conn_id, &sec_level); + if(sec_level == GAP_SEC_LEVEL_NO) + { + data_uart_print("GAP_SEC_LEVEL_NO\r\n"); + } + else if(sec_level == GAP_SEC_LEVEL_UNAUTHEN) + { + data_uart_print("GAP_SEC_LEVEL_UNAUTHEN\r\n"); + } + else if(sec_level == GAP_SEC_LEVEL_AUTHEN) + { + data_uart_print("GAP_SEC_LEVEL_AUTHEN\r\n"); + } + else if(sec_level == GAP_SEC_LEVEL_SC_UNAUTHEN) + { + data_uart_print("GAP_SEC_LEVEL_SC_UNAUTHEN\r\n"); + } + else if(sec_level == GAP_SEC_LEVEL_SC_AUTHEN) + { + data_uart_print("GAP_SEC_LEVEL_SC_AUTHEN\r\n"); + } + return (T_USER_CMD_PARSE_RESULT)cause; + } + * \endcode + */ +T_GAP_CAUSE le_bond_get_sec_level(uint8_t conn_id, T_GAP_SEC_LEVEL *p_type); + +/** End of GAP_LE_BONDMGR_Exported_Functions + * @} + */ + +/** End of GAP_LE_Bond_Manager + * @} + */ + + +#ifdef __cplusplus +} +#endif + +#endif /* GAP_BOND_LE_H */ diff --git a/component/common/bluetooth/realtek/sdk/inc/bluetooth/gap/gap_customer.h b/component/common/bluetooth/realtek/sdk/inc/bluetooth/gap/gap_customer.h new file mode 100644 index 00000000..1ef4ea29 --- /dev/null +++ b/component/common/bluetooth/realtek/sdk/inc/bluetooth/gap/gap_customer.h @@ -0,0 +1,19 @@ +#ifndef GAP_CUSTOMER_H +#define GAP_CUSTOMER_H + +#include "bt_flags.h" + +typedef struct +{ + //FW version + uint16_t hci_revision; + uint16_t lmp_subversion; + //Upperstack version + uint16_t btgap_revision; + uint16_t btgap_buildnum; +} T_BT_VERSION_INFO; + +bool gap_get_bt_version_info(T_BT_VERSION_INFO *p_info); + + +#endif /* GAP_DTM_H */ diff --git a/component/common/bluetooth/realtek/sdk/inc/bluetooth/gap/gap_le.h b/component/common/bluetooth/realtek/sdk/inc/bluetooth/gap/gap_le.h index 98196ca2..06b4612c 100644 --- a/component/common/bluetooth/realtek/sdk/inc/bluetooth/gap/gap_le.h +++ b/component/common/bluetooth/realtek/sdk/inc/bluetooth/gap/gap_le.h @@ -1,475 +1,475 @@ -/** -***************************************************************************************** -* Copyright(c) 2016, Realtek Semiconductor Corporation. All rights reserved. -***************************************************************************************** - * @file gap_le.h - * @brief This file contains all the constants and functions prototypes for GAP protocol. - * @details - * @author jane - * @date 2016-02-18 - * @version v1.0 - * ************************************************************************************* - */ - -/*============================================================================* - * Define to prevent recursive inclusion - *============================================================================*/ -#ifndef GAP_LE_H -#define GAP_LE_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -/*============================================================================* - * Header Files - *============================================================================*/ -#include -#include -#include - - -/** @addtogroup GAP_LE_COMMON GAP LE Common Module - * @brief GAP LE common module - * @{ - */ - -/*============================================================================* - * Types - *============================================================================*/ -/** @defgroup GAP_LE_Exported_Types GAP LE Exported Types - * @brief - * @{ - */ -/** @brief GAP LE Parameter Types List.*/ -typedef enum -{ - GAP_PARAM_DEV_STATE = 0x220, //!< Device's current GAP device state. Read/Write. Size is sizeof(TGapDevState). - GAP_PARAM_APPEARANCE = 0x221, //!< Local Device's Appearance. Read/Write. size is uint16. Appearance value please refer to GAP Appearance Values.(@ref GAP_LE_APPEARANCE_VALUES) - GAP_PARAM_DEVICE_NAME = 0x222, //!< Local Device's Name. Write Only. Name string length is GAP_DEVICE_NAME_LEN. -#if F_BT_LE_GAP_PERIPHERAL_SUPPORT - GAP_PARAM_SLAVE_INIT_GATT_MTU_REQ = 0x223, //!< Slave initiate the GATT exchange MTU procedure. Write Only. -#endif - GAP_PARAM_RANDOM_ADDR = 0x224, //!< Random address. Write Only. - GAP_PARAM_LATEST_CONN_BD_ADDR = 0x226, //!< Latest connected bluetooth devive address. Read Only. - GAP_PARAM_LATEST_CONN_BD_ADDR_TYPE = 0x227, //!< Latest connected bluetooth devive address type. Read Only. - GAP_PARAM_HANDLE_CREATE_CONN_IND = 0x228, //!< App handle the create connection indication message. -#if F_BT_LE_5_0_SET_PHYS_SUPPORT - GAP_PARAM_DEFAULT_PHYS_PREFER = 0x229, //!< Preferred values for the transmitter PHY and receiver PHY to be used for all subsequent connections over the LE transport. - GAP_PARAM_DEFAULT_TX_PHYS_PREFER = 0x22a, //!< The transmitter PHYs that the Host prefers the Controller to use. - GAP_PARAM_DEFAULT_RX_PHYS_PREFER = 0x22b, //!< The receiver PHYs that the Host prefers the Controller to use. -#endif -#if F_BT_LE_4_2_DATA_LEN_EXT_SUPPORT - GAP_PARAM_DEFAULT_DATA_LEN_MAX_TX_OCTETS = 0x22e, - GAP_PARAM_DEFAULT_DATA_LEN_MAX_TX_TIME = 0x22f, -#endif - GAP_PARAM_LOCAL_FEATURES = 0x230, //!< Local supported features. - GAP_PARAM_DS_POOL_ID = 0x231, //!< Downstream PoolID. Read only. size is uint16. - GAP_PARAM_DS_DATA_OFFSET = 0x232, //!< Downstream pool buffer data offset. Read only. size is uint16. - GAP_PARAM_LE_REMAIN_CREDITS = 0x233, //!< Remain credits avaiable for TX. Read only. size is uint16. - GAP_PARAM_MAX_WL_SIZE = 0x234, //!< Max white list size. Read only. size is uint16. -} T_GAP_LE_PARAM_TYPE; - -/** - * @brief Callback for gap le to notify app - * @param[in] cb_type callback msy type @ref GAP_LE_MSG_Types. - * @param[in] p_cb_data point to callback data @ref T_LE_CB_DATA. - * @retval result @ref T_APP_RESULT - */ -typedef T_APP_RESULT(*P_FUN_LE_APP_CB)(uint8_t cb_type, void *p_cb_data); -/** End of GAP_LE_Exported_Types - * @} - */ - - -/*============================================================================* - * Functions - *============================================================================*/ -/** - * @defgroup GAP_LE_COMMON_Exported_Functions GAP LE Common Exported Functions - * - * @{ - */ - -/** - * @brief Initialize parameters of GAP. - * @param[in] link_num Initialize link number. - * @retval true Success. - * @retval false Failed because of invalid parameter. - * - * Example usage - * \code{.c} - int main(void) - { - board_init(); - driver_init(); - le_gap_init(1); - app_le_gap_init(); - app_le_profile_init(); - pwr_mgr_init(); - task_init(); - os_sched_start(); - - return 0; - } - * \endcode - */ -bool le_gap_init(uint8_t link_num); - -/** - * @brief Set gap message inform way. - * - * Default value is true. - * 1. When use_msg is true, gap will send the gap message to io_queue registered by gap_start_bt_stack. - * Message type is @ref GAP_MSG_TYPE. - * 2. When use_msg is false, gap will send the gap message using callback function registered by le_register_app_cb. - * Message type is @ref GAP_MSG_LE_GAP_STATE_MSG. - * - * @param[in] use_msg Whether to use message. - * @retval void - * - * Example usage - * \code{.c} - int test(void) - { - le_gap_msg_info_way(false); - } - T_APP_RESULT app_gap_callback(uint8_t cb_type, void *p_cb_data) - { - T_APP_RESULT result = APP_RESULT_SUCCESS; - T_LE_CB_DATA cb_data; - memcpy(&cb_data, p_cb_data, sizeof(T_LE_CB_DATA)); - APP_PRINT_TRACE1("app_gap_callback: msgType = %d", cb_type); - switch (cb_type) - { - ... - case GAP_MSG_LE_GAP_STATE_MSG: - APP_PRINT_INFO0("GAP_MSG_LE_GAP_STATE_MSG"); - app_handle_gap_msg((T_IO_MSG *)cb_data->p_gap_state_msg); - break; - ... - } - } - - * \endcode - */ -void le_gap_msg_info_way(bool use_msg); - -/** - * @brief Get max supported le link count. - * @retval max_link_num Max supported le link count. - * - * Example usage - * \code{.c} - void test(void) - { - link_num = le_get_max_link_num(); - le_gap_init(link_num); - } - * \endcode - */ -uint8_t le_get_max_link_num(void); - -/** - * @brief Register app callback from gap le. - * @param[in] app_callback callback - * @return void - * - * Example usage - * \code{.c} - void app_le_profile_init(void) - { - le_register_app_cb(app_gap_callback); - client_init(1); - simple_ble_client_id = simp_ble_add_client(app_client_callback); - client_register_general_client_cb(app_client_callback); - } - * \endcode - */ -void le_register_app_cb(P_FUN_LE_APP_CB app_callback); - -/** - * @brief Set a GAP Common parameter. - * - * NOTE: You can call this function with a GAP Common Parameter ID and it will set the - * GAP Parameter. GAP Peripheral Parameters are defined in (gap.h). - * If the "len" field sets to the size of a "uint16_t" ,the - * "p_value" field must point to a data with type of "uint16_t". - * - * @param[in] param Profile parameter ID: @ref T_GAP_LE_PARAM_TYPE - * @param[in] len Length of data to write - * @param[in] p_value Pointer to data to write. This is dependent on - * the parameter ID and WILL be cast to the appropriate - * data type (For example: if data type param is uint16, p_value will be cast to - * pointer of uint16_t). - * @return Set result - * @retval GAP_CAUSE_SUCCESS Set parameter success. - * @retval other Set parameter failed. - * - * Example usage - * \code{.c} - void app_le_gap_init(void) - { - ... - //device name and device appearance - uint8_t device_name[GAP_DEVICE_NAME_LEN] = "BLE_PERIP"; - uint16_t appearance = GAP_GATT_APPEARANCE_UNKNOWN; - - //Set device name and device appearance - le_set_gap_param(GAP_PARAM_DEVICE_NAME, GAP_DEVICE_NAME_LEN, device_name); - le_set_gap_param(GAP_PARAM_APPEARANCE, sizeof(appearance), &appearance); - ... - } - * \endcode - */ -T_GAP_CAUSE le_set_gap_param(T_GAP_LE_PARAM_TYPE param, uint8_t len, void *p_value); - -/** - * @brief Get a GAP Common parameter. - * - * NOTE: You can call this function with a GAP Common Parameter ID and it will get a - * GAP Common Parameter. GAP Common Parameters are defined in (gap.h). Also, the - * "p_value" field must point to a "uint16". - * - * @param[in] param Profile parameter ID: @ref T_GAP_LE_PARAM_TYPE - * @param[in,out] p_value Pointer to location to get the parameter value. This is dependent on - * the parameter ID and will be cast to the appropriate - * data type (For example: if data type of param is uint16_t, p_value will be cast to - * pointer of uint16_t). - * - * @return Get result - * @retval GAP_CAUSE_SUCCESS Get parameter success. - * @retval other Get parameter failed. - * - * Example usage - * \code{.c} - void test(void) - { - uint8_t addr_type = GAP_REMOTE_ADDR_LE_PUBLIC; - uint8_t addr[GAP_BD_ADDR_LEN] = {0}; - - //get connected device address and address type - le_get_gap_param(GAP_PARAM_LATEST_CONN_BD_ADDR_TYPE, &addr_type); - le_get_gap_param(GAP_PARAM_LATEST_CONN_BD_ADDR, &addr); - } - * \endcode - */ -T_GAP_CAUSE le_get_gap_param(T_GAP_LE_PARAM_TYPE param, void *p_value); - -/** - * @brief Modify local white list. - * NOTE: You can call this function to add, remove or clear whist list. - * This function can be called after @ref gap_start_bt_stack is invoked. - * - * @param[in] operation Bluetooth Device Random Address type, @ref T_GAP_RAND_ADDR_TYPE. - * @param[in] bd_addr Bluetooth Device Address. - * @param[in] bd_type Bluetooth Device Address type. - * @retval GAP_CAUSE_SUCCESS Operation success. - * @retval GAP_CAUSE_SEND_REQ_FAILED Operation failure. - * - * Example usage - * \code{.c} - void test() - { - T_GAP_WHITE_LIST_OP operation = GAP_WHITE_LIST_OP_ADD; - uint8_t *bd_addr = {0}; - T_GAP_REMOTE_ADDR_TYPE bd_type = GAP_REMOTE_ADDR_LE_PUBLIC; - le_modify_white_list(operation, bd_addr, bd_type); - } - T_APP_RESULT app_gap_callback(uint8_t cb_type, void *p_cb_data) - { - T_APP_RESULT result = APP_RESULT_SUCCESS; - T_LE_CB_DATA cb_data; - memcpy(&cb_data, p_cb_data, sizeof(T_LE_CB_DATA)); - APP_PRINT_TRACE1("app_gap_callback: cb_type = %d", cb_type); - switch (cb_type) - { - ... - case GAP_MSG_LE_MODIFY_WHITE_LIST: - APP_PRINT_INFO2("GAP_MSG_LE_MODIFY_WHITE_LIST: operation 0x%x, cause 0x%x", - cb_data.p_le_modify_white_list_rsp->operation, - cb_data.p_le_modify_white_list_rsp->cause); - break; - } - ... - } - * \endcode - */ -T_GAP_CAUSE le_modify_white_list(T_GAP_WHITE_LIST_OP operation, uint8_t *bd_addr, - T_GAP_REMOTE_ADDR_TYPE bd_type); - -/** - * @brief Generate local random address. - * @param[in] rand_addr_type Bluetooth Device Random Address type, @ref T_GAP_RAND_ADDR_TYPE. - * @param[in,out] random_bd pointer to Bluetooth Device Address. - * @retval GAP_CAUSE_SUCCESS Operation success. - * @retval GAP_CAUSE_SEND_REQ_FAILED Operation failure. - * - * Example usage - * \code{.c} - void test() - { - T_GAP_RAND_ADDR_TYPE rand_addr_type = GAP_RAND_ADDR_RESOLVABLE; - uint8_t random_bd[BD_ADDR_SIZE] = {0}; - le_gen_rand_addr(rand_addr_type, random_bd); - } - * - * \endcode - */ -T_GAP_CAUSE le_gen_rand_addr(T_GAP_RAND_ADDR_TYPE rand_addr_type, uint8_t *random_bd); - -/** - * @brief Set local random address. - * - * NOTE: This function can be called after @ref gap_start_bt_stack is invoked. - * - * @param[in] random_bd Bluetooth Device Address. - * @retval GAP_CAUSE_SUCCESS Operation success. - * @retval GAP_CAUSE_SEND_REQ_FAILED Operation failure. - * - * Example usage - * \code{.c} - void test() - { - uint8_t random_bd[BD_ADDR_SIZE] = {0}; - le_set_rand_addr(random_bd); - } - T_APP_RESULT app_gap_callback(uint8_t cb_type, void *p_cb_data) - { - T_APP_RESULT result = APP_RESULT_SUCCESS; - T_LE_CB_DATA cb_data; - memcpy(&cb_data, p_cb_data, sizeof(T_LE_CB_DATA)); - APP_PRINT_TRACE1("app_gap_callback: cb_type = %d", cb_type); - switch (cb_type) - { - ... - case GAP_MSG_LE_SET_RAND_ADDR: - APP_PRINT_INFO1("GAP_MSG_LE_SET_RAND_ADDR: cause 0x%x", - cb_data.p_le_set_rand_addr_rsp->cause); - break; - } - ... - } - * \endcode - */ -T_GAP_CAUSE le_set_rand_addr(uint8_t *random_bd); - -/** - * @brief Configure local identity address. - * - * NOTE: This function can be called before @ref gap_start_bt_stack is invoked. - * - * @param[in] addr Bluetooth Device Address. - * @param[in] type Bluetooth Device Address type. - * @retval GAP_CAUSE_SUCCESS Operation success. - * @retval GAP_CAUSE_SEND_REQ_FAILED Operation failure. - * - * Example usage - * \code{.c} - void test() - { - T_GAP_IDENT_ADDR_TYPE type = GAP_IDENT_ADDR_PUBLIC; - uint8_t addr[BD_ADDR_SIZE] = {0}; - le_cfg_local_identity_address(addr, type); - } - * \endcode - */ -T_GAP_CAUSE le_cfg_local_identity_address(uint8_t *addr, T_GAP_IDENT_ADDR_TYPE type); - -#if F_BT_LE_GAP_CENTRAL_SUPPORT -/** -* @brief Set the Host Channel Classification for master role. -* -* NOTE: This function can be called after @ref gap_start_bt_stack is invoked. -* -* @param[in] p_channel_map Channel bit map, the most 3 significant bits are reserved. -* -* @retval GAP_CAUSE_SUCCESS: Operation success. -* @retval GAP_CAUSE_SEND_REQ_FAILED: Operation fail. - * - * Example usage - * \code{.c} - void test() - { - uint8_t channel_map = 0; - le_set_host_chann_classif(channel_map); - } - T_APP_RESULT app_gap_callback(uint8_t cb_type, void *p_cb_data) - { - T_APP_RESULT result = APP_RESULT_SUCCESS; - T_LE_CB_DATA cb_data; - memcpy(&cb_data, p_cb_data, sizeof(T_LE_CB_DATA)); - APP_PRINT_TRACE1("app_gap_callback: cb_type = %d", cb_type); - switch (cb_type) - { - ... - case GAP_MSG_LE_SET_HOST_CHANN_CLASSIF: - APP_PRINT_INFO1("GAP_MSG_LE_SET_HOST_CHANN_CLASSIF: cause 0x%x", - cb_data.p_le_set_host_chann_classif_rsp->cause); - break; - } - ... - } - * \endcode - */ -T_GAP_CAUSE le_set_host_chann_classif(uint8_t *p_channel_map); -#endif - -#if F_BT_LE_4_2_DATA_LEN_EXT_SUPPORT -/** -* @brief Specify suggested values for maximum transmission number of payload - octets and maximum packet transmission time for new connections. -* -* NOTE: This function can be called after @ref gap_start_bt_stack is invoked. -* -* @param[in] tx_octets maximum transmission number of payload octets, range: 0x001B-0x00FB -* @param[in] tx_time maximum packet transmission time, range: 0x0148-0x4290 -* -* @retval GAP_CAUSE_SUCCESS: Operation success. -* @retval GAP_CAUSE_SEND_REQ_FAILED: Operation fail. - * - * Example usage - * \code{.c} - void test() - { - uint16_t tx_octets = 0x00FB; - uint16_t tx_time = 0x0848; - le_write_default_data_len(tx_octets, tx_time); - } - T_APP_RESULT app_gap_callback(uint8_t cb_type, void *p_cb_data) - { - T_APP_RESULT result = APP_RESULT_SUCCESS; - T_LE_CB_DATA cb_data; - memcpy(&cb_data, p_cb_data, sizeof(T_LE_CB_DATA)); - APP_PRINT_TRACE1("app_gap_callback: cb_type = %d", cb_type); - switch (cb_type) - { - ... - case GAP_MSG_LE_WRITE_DEFAULT_DATA_LEN: - APP_PRINT_INFO1("GAP_MSG_LE_WRITE_DEFAULT_DATA_LEN: cause 0x%x", - cb_data->le_cause.cause); - break; - } - ... - } - * \endcode - */ -T_GAP_CAUSE le_write_default_data_len(uint16_t tx_octets, uint16_t tx_time); -#endif -/** @} */ /* End of group GAP_LE_COMMON_Exported_Functions */ -/** @} */ /* End of group GAP_LE_COMMON */ - - -/*------------------------------------------------------------------- --------------------------------------------------------------------*/ - -#ifdef __cplusplus -} -#endif - -#endif /* GAP_LE_H */ - - - - +/** +***************************************************************************************** +* Copyright(c) 2016, Realtek Semiconductor Corporation. All rights reserved. +***************************************************************************************** + * @file gap_le.h + * @brief This file contains all the constants and functions prototypes for GAP protocol. + * @details + * @author jane + * @date 2016-02-18 + * @version v1.0 + * ************************************************************************************* + */ + +/*============================================================================* + * Define to prevent recursive inclusion + *============================================================================*/ +#ifndef GAP_LE_H +#define GAP_LE_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +/*============================================================================* + * Header Files + *============================================================================*/ +#include +#include +#include + + +/** @addtogroup GAP_LE_COMMON GAP LE Common Module + * @brief GAP LE common module + * @{ + */ + +/*============================================================================* + * Types + *============================================================================*/ +/** @defgroup GAP_LE_Exported_Types GAP LE Exported Types + * @brief + * @{ + */ +/** @brief GAP LE Parameter Types List.*/ +typedef enum +{ + GAP_PARAM_DEV_STATE = 0x220, //!< Device's current GAP device state. Read/Write. Size is sizeof(TGapDevState). + GAP_PARAM_APPEARANCE = 0x221, //!< Local Device's Appearance. Read/Write. size is uint16. Appearance value please refer to GAP Appearance Values.(@ref GAP_LE_APPEARANCE_VALUES) + GAP_PARAM_DEVICE_NAME = 0x222, //!< Local Device's Name. Write Only. Name string length is GAP_DEVICE_NAME_LEN. +#if F_BT_LE_GAP_PERIPHERAL_SUPPORT + GAP_PARAM_SLAVE_INIT_GATT_MTU_REQ = 0x223, //!< Slave initiate the GATT exchange MTU procedure. Write Only. +#endif + GAP_PARAM_RANDOM_ADDR = 0x224, //!< Random address. Write Only. + GAP_PARAM_LATEST_CONN_BD_ADDR = 0x226, //!< Latest connected bluetooth devive address. Read Only. + GAP_PARAM_LATEST_CONN_BD_ADDR_TYPE = 0x227, //!< Latest connected bluetooth devive address type. Read Only. + GAP_PARAM_HANDLE_CREATE_CONN_IND = 0x228, //!< App handle the create connection indication message. +#if F_BT_LE_5_0_SET_PHYS_SUPPORT + GAP_PARAM_DEFAULT_PHYS_PREFER = 0x229, //!< Preferred values for the transmitter PHY and receiver PHY to be used for all subsequent connections over the LE transport. + GAP_PARAM_DEFAULT_TX_PHYS_PREFER = 0x22a, //!< The transmitter PHYs that the Host prefers the Controller to use. + GAP_PARAM_DEFAULT_RX_PHYS_PREFER = 0x22b, //!< The receiver PHYs that the Host prefers the Controller to use. +#endif +#if F_BT_LE_4_2_DATA_LEN_EXT_SUPPORT + GAP_PARAM_DEFAULT_DATA_LEN_MAX_TX_OCTETS = 0x22e, + GAP_PARAM_DEFAULT_DATA_LEN_MAX_TX_TIME = 0x22f, +#endif + GAP_PARAM_LOCAL_FEATURES = 0x230, //!< Local supported features. + GAP_PARAM_DS_POOL_ID = 0x231, //!< Downstream PoolID. Read only. size is uint16. + GAP_PARAM_DS_DATA_OFFSET = 0x232, //!< Downstream pool buffer data offset. Read only. size is uint16. + GAP_PARAM_LE_REMAIN_CREDITS = 0x233, //!< Remain credits avaiable for TX. Read only. size is uint16. + GAP_PARAM_MAX_WL_SIZE = 0x234, //!< Max white list size. Read only. size is uint16. +} T_GAP_LE_PARAM_TYPE; + +/** + * @brief Callback for gap le to notify app + * @param[in] cb_type callback msy type @ref GAP_LE_MSG_Types. + * @param[in] p_cb_data point to callback data @ref T_LE_CB_DATA. + * @retval result @ref T_APP_RESULT + */ +typedef T_APP_RESULT(*P_FUN_LE_APP_CB)(uint8_t cb_type, void *p_cb_data); +/** End of GAP_LE_Exported_Types + * @} + */ + + +/*============================================================================* + * Functions + *============================================================================*/ +/** + * @defgroup GAP_LE_COMMON_Exported_Functions GAP LE Common Exported Functions + * + * @{ + */ + +/** + * @brief Initialize parameters of GAP. + * @param[in] link_num Initialize link number. + * @retval true Success. + * @retval false Failed because of invalid parameter. + * + * Example usage + * \code{.c} + int main(void) + { + board_init(); + driver_init(); + le_gap_init(1); + app_le_gap_init(); + app_le_profile_init(); + pwr_mgr_init(); + task_init(); + os_sched_start(); + + return 0; + } + * \endcode + */ +bool le_gap_init(uint8_t link_num); + +/** + * @brief Set gap message inform way. + * + * Default value is true. + * 1. When use_msg is true, gap will send the gap message to io_queue registered by gap_start_bt_stack. + * Message type is @ref GAP_MSG_TYPE. + * 2. When use_msg is false, gap will send the gap message using callback function registered by le_register_app_cb. + * Message type is @ref GAP_MSG_LE_GAP_STATE_MSG. + * + * @param[in] use_msg Whether to use message. + * @retval void + * + * Example usage + * \code{.c} + int test(void) + { + le_gap_msg_info_way(false); + } + T_APP_RESULT app_gap_callback(uint8_t cb_type, void *p_cb_data) + { + T_APP_RESULT result = APP_RESULT_SUCCESS; + T_LE_CB_DATA cb_data; + memcpy(&cb_data, p_cb_data, sizeof(T_LE_CB_DATA)); + APP_PRINT_TRACE1("app_gap_callback: msgType = %d", cb_type); + switch (cb_type) + { + ... + case GAP_MSG_LE_GAP_STATE_MSG: + APP_PRINT_INFO0("GAP_MSG_LE_GAP_STATE_MSG"); + app_handle_gap_msg((T_IO_MSG *)cb_data->p_gap_state_msg); + break; + ... + } + } + + * \endcode + */ +void le_gap_msg_info_way(bool use_msg); + +/** + * @brief Get max supported le link count. + * @retval max_link_num Max supported le link count. + * + * Example usage + * \code{.c} + void test(void) + { + link_num = le_get_max_link_num(); + le_gap_init(link_num); + } + * \endcode + */ +uint8_t le_get_max_link_num(void); + +/** + * @brief Register app callback from gap le. + * @param[in] app_callback callback + * @return void + * + * Example usage + * \code{.c} + void app_le_profile_init(void) + { + le_register_app_cb(app_gap_callback); + client_init(1); + simple_ble_client_id = simp_ble_add_client(app_client_callback); + client_register_general_client_cb(app_client_callback); + } + * \endcode + */ +void le_register_app_cb(P_FUN_LE_APP_CB app_callback); + +/** + * @brief Set a GAP Common parameter. + * + * NOTE: You can call this function with a GAP Common Parameter ID and it will set the + * GAP Parameter. GAP Peripheral Parameters are defined in (gap.h). + * If the "len" field sets to the size of a "uint16_t" ,the + * "p_value" field must point to a data with type of "uint16_t". + * + * @param[in] param Profile parameter ID: @ref T_GAP_LE_PARAM_TYPE + * @param[in] len Length of data to write + * @param[in] p_value Pointer to data to write. This is dependent on + * the parameter ID and WILL be cast to the appropriate + * data type (For example: if data type param is uint16, p_value will be cast to + * pointer of uint16_t). + * @return Set result + * @retval GAP_CAUSE_SUCCESS Set parameter success. + * @retval other Set parameter failed. + * + * Example usage + * \code{.c} + void app_le_gap_init(void) + { + ... + //device name and device appearance + uint8_t device_name[GAP_DEVICE_NAME_LEN] = "BLE_PERIP"; + uint16_t appearance = GAP_GATT_APPEARANCE_UNKNOWN; + + //Set device name and device appearance + le_set_gap_param(GAP_PARAM_DEVICE_NAME, GAP_DEVICE_NAME_LEN, device_name); + le_set_gap_param(GAP_PARAM_APPEARANCE, sizeof(appearance), &appearance); + ... + } + * \endcode + */ +T_GAP_CAUSE le_set_gap_param(T_GAP_LE_PARAM_TYPE param, uint8_t len, void *p_value); + +/** + * @brief Get a GAP Common parameter. + * + * NOTE: You can call this function with a GAP Common Parameter ID and it will get a + * GAP Common Parameter. GAP Common Parameters are defined in (gap.h). Also, the + * "p_value" field must point to a "uint16". + * + * @param[in] param Profile parameter ID: @ref T_GAP_LE_PARAM_TYPE + * @param[in,out] p_value Pointer to location to get the parameter value. This is dependent on + * the parameter ID and will be cast to the appropriate + * data type (For example: if data type of param is uint16_t, p_value will be cast to + * pointer of uint16_t). + * + * @return Get result + * @retval GAP_CAUSE_SUCCESS Get parameter success. + * @retval other Get parameter failed. + * + * Example usage + * \code{.c} + void test(void) + { + uint8_t addr_type = GAP_REMOTE_ADDR_LE_PUBLIC; + uint8_t addr[GAP_BD_ADDR_LEN] = {0}; + + //get connected device address and address type + le_get_gap_param(GAP_PARAM_LATEST_CONN_BD_ADDR_TYPE, &addr_type); + le_get_gap_param(GAP_PARAM_LATEST_CONN_BD_ADDR, &addr); + } + * \endcode + */ +T_GAP_CAUSE le_get_gap_param(T_GAP_LE_PARAM_TYPE param, void *p_value); + +/** + * @brief Modify local white list. + * NOTE: You can call this function to add, remove or clear whist list. + * This function can be called after @ref gap_start_bt_stack is invoked. + * + * @param[in] operation Bluetooth Device Random Address type, @ref T_GAP_RAND_ADDR_TYPE. + * @param[in] bd_addr Bluetooth Device Address. + * @param[in] bd_type Bluetooth Device Address type. + * @retval GAP_CAUSE_SUCCESS Operation success. + * @retval GAP_CAUSE_SEND_REQ_FAILED Operation failure. + * + * Example usage + * \code{.c} + void test() + { + T_GAP_WHITE_LIST_OP operation = GAP_WHITE_LIST_OP_ADD; + uint8_t *bd_addr = {0}; + T_GAP_REMOTE_ADDR_TYPE bd_type = GAP_REMOTE_ADDR_LE_PUBLIC; + le_modify_white_list(operation, bd_addr, bd_type); + } + T_APP_RESULT app_gap_callback(uint8_t cb_type, void *p_cb_data) + { + T_APP_RESULT result = APP_RESULT_SUCCESS; + T_LE_CB_DATA cb_data; + memcpy(&cb_data, p_cb_data, sizeof(T_LE_CB_DATA)); + APP_PRINT_TRACE1("app_gap_callback: cb_type = %d", cb_type); + switch (cb_type) + { + ... + case GAP_MSG_LE_MODIFY_WHITE_LIST: + APP_PRINT_INFO2("GAP_MSG_LE_MODIFY_WHITE_LIST: operation 0x%x, cause 0x%x", + cb_data.p_le_modify_white_list_rsp->operation, + cb_data.p_le_modify_white_list_rsp->cause); + break; + } + ... + } + * \endcode + */ +T_GAP_CAUSE le_modify_white_list(T_GAP_WHITE_LIST_OP operation, uint8_t *bd_addr, + T_GAP_REMOTE_ADDR_TYPE bd_type); + +/** + * @brief Generate local random address. + * @param[in] rand_addr_type Bluetooth Device Random Address type, @ref T_GAP_RAND_ADDR_TYPE. + * @param[in,out] random_bd pointer to Bluetooth Device Address. + * @retval GAP_CAUSE_SUCCESS Operation success. + * @retval GAP_CAUSE_SEND_REQ_FAILED Operation failure. + * + * Example usage + * \code{.c} + void test() + { + T_GAP_RAND_ADDR_TYPE rand_addr_type = GAP_RAND_ADDR_RESOLVABLE; + uint8_t random_bd[BD_ADDR_SIZE] = {0}; + le_gen_rand_addr(rand_addr_type, random_bd); + } + * + * \endcode + */ +T_GAP_CAUSE le_gen_rand_addr(T_GAP_RAND_ADDR_TYPE rand_addr_type, uint8_t *random_bd); + +/** + * @brief Set local random address. + * + * NOTE: This function can be called after @ref gap_start_bt_stack is invoked. + * + * @param[in] random_bd Bluetooth Device Address. + * @retval GAP_CAUSE_SUCCESS Operation success. + * @retval GAP_CAUSE_SEND_REQ_FAILED Operation failure. + * + * Example usage + * \code{.c} + void test() + { + uint8_t random_bd[BD_ADDR_SIZE] = {0}; + le_set_rand_addr(random_bd); + } + T_APP_RESULT app_gap_callback(uint8_t cb_type, void *p_cb_data) + { + T_APP_RESULT result = APP_RESULT_SUCCESS; + T_LE_CB_DATA cb_data; + memcpy(&cb_data, p_cb_data, sizeof(T_LE_CB_DATA)); + APP_PRINT_TRACE1("app_gap_callback: cb_type = %d", cb_type); + switch (cb_type) + { + ... + case GAP_MSG_LE_SET_RAND_ADDR: + APP_PRINT_INFO1("GAP_MSG_LE_SET_RAND_ADDR: cause 0x%x", + cb_data.p_le_set_rand_addr_rsp->cause); + break; + } + ... + } + * \endcode + */ +T_GAP_CAUSE le_set_rand_addr(uint8_t *random_bd); + +/** + * @brief Configure local identity address. + * + * NOTE: This function can be called before @ref gap_start_bt_stack is invoked. + * + * @param[in] addr Bluetooth Device Address. + * @param[in] type Bluetooth Device Address type. + * @retval GAP_CAUSE_SUCCESS Operation success. + * @retval GAP_CAUSE_SEND_REQ_FAILED Operation failure. + * + * Example usage + * \code{.c} + void test() + { + T_GAP_IDENT_ADDR_TYPE type = GAP_IDENT_ADDR_PUBLIC; + uint8_t addr[BD_ADDR_SIZE] = {0}; + le_cfg_local_identity_address(addr, type); + } + * \endcode + */ +T_GAP_CAUSE le_cfg_local_identity_address(uint8_t *addr, T_GAP_IDENT_ADDR_TYPE type); + +#if F_BT_LE_GAP_CENTRAL_SUPPORT +/** +* @brief Set the Host Channel Classification for master role. +* +* NOTE: This function can be called after @ref gap_start_bt_stack is invoked. +* +* @param[in] p_channel_map Channel bit map, the most 3 significant bits are reserved. +* +* @retval GAP_CAUSE_SUCCESS: Operation success. +* @retval GAP_CAUSE_SEND_REQ_FAILED: Operation fail. + * + * Example usage + * \code{.c} + void test() + { + uint8_t channel_map = 0; + le_set_host_chann_classif(channel_map); + } + T_APP_RESULT app_gap_callback(uint8_t cb_type, void *p_cb_data) + { + T_APP_RESULT result = APP_RESULT_SUCCESS; + T_LE_CB_DATA cb_data; + memcpy(&cb_data, p_cb_data, sizeof(T_LE_CB_DATA)); + APP_PRINT_TRACE1("app_gap_callback: cb_type = %d", cb_type); + switch (cb_type) + { + ... + case GAP_MSG_LE_SET_HOST_CHANN_CLASSIF: + APP_PRINT_INFO1("GAP_MSG_LE_SET_HOST_CHANN_CLASSIF: cause 0x%x", + cb_data.p_le_set_host_chann_classif_rsp->cause); + break; + } + ... + } + * \endcode + */ +T_GAP_CAUSE le_set_host_chann_classif(uint8_t *p_channel_map); +#endif + +#if F_BT_LE_4_2_DATA_LEN_EXT_SUPPORT +/** +* @brief Specify suggested values for maximum transmission number of payload + octets and maximum packet transmission time for new connections. +* +* NOTE: This function can be called after @ref gap_start_bt_stack is invoked. +* +* @param[in] tx_octets maximum transmission number of payload octets, range: 0x001B-0x00FB +* @param[in] tx_time maximum packet transmission time, range: 0x0148-0x4290 +* +* @retval GAP_CAUSE_SUCCESS: Operation success. +* @retval GAP_CAUSE_SEND_REQ_FAILED: Operation fail. + * + * Example usage + * \code{.c} + void test() + { + uint16_t tx_octets = 0x00FB; + uint16_t tx_time = 0x0848; + le_write_default_data_len(tx_octets, tx_time); + } + T_APP_RESULT app_gap_callback(uint8_t cb_type, void *p_cb_data) + { + T_APP_RESULT result = APP_RESULT_SUCCESS; + T_LE_CB_DATA cb_data; + memcpy(&cb_data, p_cb_data, sizeof(T_LE_CB_DATA)); + APP_PRINT_TRACE1("app_gap_callback: cb_type = %d", cb_type); + switch (cb_type) + { + ... + case GAP_MSG_LE_WRITE_DEFAULT_DATA_LEN: + APP_PRINT_INFO1("GAP_MSG_LE_WRITE_DEFAULT_DATA_LEN: cause 0x%x", + cb_data->le_cause.cause); + break; + } + ... + } + * \endcode + */ +T_GAP_CAUSE le_write_default_data_len(uint16_t tx_octets, uint16_t tx_time); +#endif +/** @} */ /* End of group GAP_LE_COMMON_Exported_Functions */ +/** @} */ /* End of group GAP_LE_COMMON */ + + +/*------------------------------------------------------------------- +-------------------------------------------------------------------*/ + +#ifdef __cplusplus +} +#endif + +#endif /* GAP_LE_H */ + + + + diff --git a/component/common/bluetooth/realtek/sdk/inc/bluetooth/profile/profile_client.h b/component/common/bluetooth/realtek/sdk/inc/bluetooth/profile/profile_client.h index bc7f7d3a..a965246f 100644 --- a/component/common/bluetooth/realtek/sdk/inc/bluetooth/profile/profile_client.h +++ b/component/common/bluetooth/realtek/sdk/inc/bluetooth/profile/profile_client.h @@ -533,6 +533,31 @@ T_GAP_CAUSE client_attr_write(uint8_t conn_id, T_CLIENT_ID client_id, */ T_GAP_CAUSE client_attr_ind_confirm(uint8_t conn_id); +/** + * @brief Send the exchange MTU request. + * This function is used to send the exchange MTU request. + * + * @param[in] conn_id Connection id indicate which link is. + * @retval GAP_CAUSE_SUCCESS: Write request success. + * @retval other: Write request failed. + * + * Example usage + * \code{.c} + uint8_t *p_data_buf; + uint16_t data_offset; + static T_USER_CMD_PARSE_RESULT cmd_send_mtu_req(T_USER_CMD_PARSED_VALUE *p_parse_value) + { + T_GAP_CAUSE cause; + uint8_t conn_id = p_parse_value->dw_param[0]; + + cause = client_send_exchange_mtu_req(conn_id); + return (T_USER_CMD_PARSE_RESULT)cause; + } + * \endcode + */ +T_GAP_CAUSE client_send_exchange_mtu_req(uint8_t conn_id); + + /** End of GATT_Client_Exported_Functions * @} */ diff --git a/component/common/bluetooth/realtek/sdk/src/ble/profile/server/bas.c b/component/common/bluetooth/realtek/sdk/src/ble/profile/server/bas.c index efd5e1be..dfaab832 100644 --- a/component/common/bluetooth/realtek/sdk/src/ble/profile/server/bas.c +++ b/component/common/bluetooth/realtek/sdk/src/ble/profile/server/bas.c @@ -347,7 +347,7 @@ const T_FUN_GATT_SERVICE_CBS bas_cbs = */ T_SERVER_ID bas_add_service(void *p_func) { - T_SERVER_ID service_id; + T_SERVER_ID service_id = 0; if (false == server_add_service(&service_id, (uint8_t *)bas_attr_tbl, bas_attr_tbl_size, diff --git a/component/common/bluetooth/realtek/sdk/src/ble/profile/server/dis.c b/component/common/bluetooth/realtek/sdk/src/ble/profile/server/dis.c index 2d79f706..56fe74ad 100644 --- a/component/common/bluetooth/realtek/sdk/src/ble/profile/server/dis.c +++ b/component/common/bluetooth/realtek/sdk/src/ble/profile/server/dis.c @@ -678,7 +678,7 @@ const T_FUN_GATT_SERVICE_CBS dis_cbs = */ T_SERVER_ID dis_add_service(void *p_func) { - T_SERVER_ID service_id; + T_SERVER_ID service_id = 0; if (false == server_add_service(&service_id, (uint8_t *)dis_attr_tbl, dis_attr_tbl_size, diff --git a/component/common/bluetooth/realtek/sdk/src/ble/profile/server/gls.c b/component/common/bluetooth/realtek/sdk/src/ble/profile/server/gls.c index 736a366e..53ffd86a 100644 --- a/component/common/bluetooth/realtek/sdk/src/ble/profile/server/gls.c +++ b/component/common/bluetooth/realtek/sdk/src/ble/profile/server/gls.c @@ -10,12 +10,11 @@ * @version v1.0 * ************************************************************************************* */ - +#include #include "trace.h" #include #include "gatt.h" #include "gls.h" -#include "data_uart.h" /** @brief service related UUIDs. */ @@ -1734,7 +1733,7 @@ static void gls_ctl_pnt_write_ind_post_proc(uint8_t conn_id, T_SERVER_ID service PROFILE_PRINT_INFO4("gls_ctl_pnt_write_ind_post_proc Write GLS Control Point: OpCode = %d, operator = %d, length = %d, filter type = %d", p_value[0], p_value[1], write_length, p_value[2]); - data_uart_print("\n\rgls_ctl_pnt_write_ind_post_proc Write GLS Control Point: OpCode = %d, operator = %d, length = %d, filter type = %d \r\n",p_value[0], p_value[1], write_length, p_value[2]); + printf("gls_ctl_pnt_write_ind_post_proc Write GLS Control Point: OpCode = %d, operator = %d, length = %d, filter type = %d \r\n",p_value[0], p_value[1], write_length, p_value[2]); /* Notify Application. */ if (pfn_gls_cb) @@ -1744,7 +1743,7 @@ static void gls_ctl_pnt_write_ind_post_proc(uint8_t conn_id, T_SERVER_ID service memcpy(&GLS_upsteam_msg.msg_data.write, p_value, write_length); pfn_gls_cb(service_id, (void *)&GLS_upsteam_msg); } - data_uart_print("\n\rgls_ctl_pnt_write_ind_post_proc:glc_racp.ctrl_point.op_code = 0x%x ,gls_send_data_flag = %d\r\n",glc_racp.ctrl_point.op_code,gls_send_data_flag); + printf("gls_ctl_pnt_write_ind_post_proc:glc_racp.ctrl_point.op_code = 0x%x ,gls_send_data_flag = %d\r\n",glc_racp.ctrl_point.op_code,gls_send_data_flag); if (p_value[0] != GLC_RACP_OPCODE_ABORT_OPERATION) { memset(&glc_racp.ctrl_point, 0, sizeof(T_GLC_CONTROL_POINT)); @@ -1822,12 +1821,12 @@ T_APP_RESULT gls_attr_write_cb(uint8_t conn_id, T_SERVER_ID service_id, uint16_t { T_APP_RESULT cause = APP_RESULT_SUCCESS; PROFILE_PRINT_INFO2("gls_attr_write_cb attrib_index = %d, length = %x", attrib_index, length); - data_uart_print("\n\rgls_attr_write_cb attrib_index = %d, length = %x \r\n",attrib_index, length); + printf("gls_attr_write_cb attrib_index = %d, length = %x \r\n",attrib_index, length); switch (attrib_index) { case GLS_CHAR_GLC_RACP_INDEX: { - data_uart_print("\n\rglc_racp.ctrl_point.op_code = 0x%x \r\n",glc_racp.ctrl_point.op_code); + printf("glc_racp.ctrl_point.op_code = 0x%x \r\n",glc_racp.ctrl_point.op_code); /* Attribute value has variable size, make sure written value size is valid. */ if ((length > sizeof(T_GLC_CONTROL_POINT)) || (p_value == NULL)) { @@ -1837,7 +1836,7 @@ T_APP_RESULT gls_attr_write_cb(uint8_t conn_id, T_SERVER_ID service_id, uint16_t else if (GLC_RACP_OPERATION_ACTIVE(glc_racp.ctrl_point.op_code) && (p_value[0] != GLC_RACP_OPCODE_ABORT_OPERATION)) { - data_uart_print("\n\rGLC_ERR_PROC_ALREADY_IN_PROGRESS \r\n"); + printf("GLC_ERR_PROC_ALREADY_IN_PROGRESS \r\n"); cause = (T_APP_RESULT)(ATT_ERR | GLC_ERR_PROC_ALREADY_IN_PROGRESS); } /* Make sure Control Point is configured indication enable. */ @@ -1851,7 +1850,7 @@ T_APP_RESULT gls_attr_write_cb(uint8_t conn_id, T_SERVER_ID service_id, uint16_t /** handle RACP request after sending write response */ PROFILE_PRINT_INFO2("gls_attr_write_cb opcode: old = %d, new = %d\n", glc_racp.ctrl_point.op_code, p_value[0]); - data_uart_print("\n\rgls_attr_write_cb opcode: old = %d, new = %d\r\n",glc_racp.ctrl_point.op_code,p_value[0]); + printf("gls_attr_write_cb opcode: old = %d, new = %d\r\n",glc_racp.ctrl_point.op_code,p_value[0]); *p_write_ind_post_proc = gls_ctl_pnt_write_ind_post_proc; } diff --git a/component/common/bluetooth/realtek/sdk/src/ble/profile/server/hids.c b/component/common/bluetooth/realtek/sdk/src/ble/profile/server/hids.c index b63fd5fd..4cca0f17 100644 --- a/component/common/bluetooth/realtek/sdk/src/ble/profile/server/hids.c +++ b/component/common/bluetooth/realtek/sdk/src/ble/profile/server/hids.c @@ -760,7 +760,7 @@ const T_FUN_GATT_SERVICE_CBS hids_cbs = */ T_SERVER_ID hids_add_service(void *p_func) { - T_SERVER_ID service_id; + T_SERVER_ID service_id = 0; if (false == server_add_service(&service_id, (uint8_t *)hids_attr_tbl, hids_attr_tbl_len, hids_cbs)) { APP_PRINT_ERROR1("hids_add_service: ServiceId %d", service_id); diff --git a/component/common/drivers/wlan/realtek/include/autoconf.h b/component/common/drivers/wlan/realtek/include/autoconf.h index 11cf618a..8b46f011 100644 --- a/component/common/drivers/wlan/realtek/include/autoconf.h +++ b/component/common/drivers/wlan/realtek/include/autoconf.h @@ -231,7 +231,9 @@ #endif #define CONFIG_PMKSA_CACHING - +#ifdef CONFIG_PMKSA_CACHING +//#define CONFIG_PMKSA_CACHING_RECONNECT +#endif /* For WPA3 */ #define CONFIG_IEEE80211W #define CONFIG_SAE_SUPPORT diff --git a/component/common/drivers/wlan/realtek/include/wifi_structures.h b/component/common/drivers/wlan/realtek/include/wifi_structures.h index cbe836b2..abd75e4c 100644 --- a/component/common/drivers/wlan/realtek/include/wifi_structures.h +++ b/component/common/drivers/wlan/realtek/include/wifi_structures.h @@ -272,6 +272,24 @@ typedef struct wowlan_pattern { unsigned char mask[5]; } wowlan_pattern_t; +#ifdef CONFIG_MCC_STA_AP_MODE +typedef struct rtw_fw_txrpt_stats { + unsigned long tx_pass_cnt; // tx pass packet count + unsigned long tx_drop_cnt; // tx drop packet count + unsigned long tx_rty_cnt; // tx retry count (due to HW limit, the retry times >=4 is calculated as 4) + int txrpt_drop_cnt_ready; // used to sync txrpt pass & drop count ready + int txrpt_rty_cnt_ready; // used to sync txrpt retry count ready +}rtw_fw_txrpt_stats_t; + +typedef struct rtw_fw_txrpt_retry { + unsigned long tx_pass_cnt; // tx pass packet count + unsigned long tx_pass_rty_cnt; // tx pass packet retry count + unsigned long tx_drop_cnt; // tx drop packet count + unsigned long tx_drop_rty_cnt; // tx drop packet retry count + int enable_spe_txrpt; // enable specific tx report + int spe_txrpt_ifid; // the interface to enable specific tx report +}rtw_fw_txrpt_retry_t; +#endif #ifdef __cplusplus } diff --git a/component/common/example/coap/example_coap.c b/component/common/example/coap/example_coap.c index 9c2d6a73..22e66ff6 100644 --- a/component/common/example/coap/example_coap.c +++ b/component/common/example/coap/example_coap.c @@ -10,10 +10,10 @@ #include "sn_coap_protocol.h" #include "sn_coap_ameba_port.h" -//#define SERVER_HOST "coap.me" -//#define URI_PATH "/hello" -#define SERVER_HOST "californium.eclipse.org" -#define URI_PATH "obs" +#define SERVER_HOST "coap.me" +#define URI_PATH "/separate" +//#define SERVER_HOST "californium.eclipseprojects.io" +//#define URI_PATH "obs" #define SERVER_PORT 5683 #define BUF_LEN 1280 // Suggested is to keep packet size under 1280 bytes #define MAX_AGE 60 @@ -109,6 +109,7 @@ coap_res_ptr->msg_id = randLIB_get_16bit(); //receive CoAP message struct sockaddr_in from_address; + memset(&from_address, 0, sizeof(struct sockaddr_in)); uint8_t* recv_buffer = (uint8_t*)coap_calloc(BUF_LEN); int ret; diff --git a/component/common/example/httpc/example_httpc.c b/component/common/example/httpc/example_httpc.c index 61b332a2..53df10e3 100644 --- a/component/common/example/httpc/example_httpc.c +++ b/component/common/example/httpc/example_httpc.c @@ -3,6 +3,7 @@ #include #include +#define STACKSIZE 2048 #define USE_HTTPS 0 #define SERVER_HOST "httpbin.org" diff --git a/component/common/example/mqtt/example_mqtt.c b/component/common/example/mqtt/example_mqtt.c index 668167d1..8a484c6a 100644 --- a/component/common/example/mqtt/example_mqtt.c +++ b/component/common/example/mqtt/example_mqtt.c @@ -11,13 +11,18 @@ #include "MQTTClient.h" #include "wifi_conf.h" +#if defined(MQTTV5) +#include "MQTTProperties.h" +#include "MQTTV5Packet.h" +#include "MQTTV5Connect.h" +#endif + #if defined(configENABLE_TRUSTZONE) && (configENABLE_TRUSTZONE == 1) && defined(CONFIG_SSL_CLIENT_PRIVATE_IN_TZ) && (CONFIG_SSL_CLIENT_PRIVATE_IN_TZ == 1) #include "device_lock.h" +#define STACKSIZE 2048 #endif -#define STACKSIZE 2048 #define MQTT_SELECT_TIMEOUT 1 - static void messageArrived(MessageData* data) { mqtt_printf(MQTT_INFO, "Message arrived on topic %s: %s\n", data->topicName->lenstring.data, (char *)data->message->payload); @@ -35,9 +40,68 @@ void prvMQTTEchoTask(void *pvParameters) unsigned char sendbuf[512], readbuf[80]; int rc = 0, count = 0; MQTTPacket_connectData connectData = MQTTPacket_connectData_initializer; - char* address = "gpssensor.ddns.net"; - char* sub_topic = "LASS/Test/Pm25Ameba/#"; - char* pub_topic = "LASS/Test/Pm25Ameba/FT1_018"; + +#if defined(MQTTV5) + + //init connect properties and will properties + MQTTProperties connectProperties = MQTTProperties_initializer, + willProperties = MQTTProperties_initializer, + subProperties = MQTTProperties_initializer, + pubProperties = MQTTProperties_initializer; + MQTTProperty connect_props[10], will_props[10], sub_props[10], pub_props[20]; + + connectProperties.max_count = 6; + connectProperties.array = connect_props; + + willProperties.max_count = 10; + willProperties.array = will_props; + + subProperties.max_count = 10; + subProperties.array = sub_props; + + pubProperties.max_count = 10; + pubProperties.array = pub_props; + + MQTTProperty pub_format; + pub_format.identifier = PAYLOAD_FORMAT_INDICATOR; + pub_format.value.byte = 1; + rc = MQTTProperties_add(&pubProperties, &pub_format); + + MQTTProperty connect; + connect.identifier = SESSION_EXPIRY_INTERVAL; + connect.value.integer4 = 10; + rc = MQTTProperties_add(&connectProperties, &connect); + + MQTTProperty will; + will.identifier = WILL_DELAY_INTERVAL; + will.value.integer4 = 1; + rc = MQTTProperties_add(&willProperties, &will); + + MQTTProperty will_format; + will_format.identifier = PAYLOAD_FORMAT_INDICATOR; + will_format.value.byte = 1; + rc = MQTTProperties_add(&willProperties, &will_format); + + MQTTProperty will_topic; + will_topic.identifier = RESPONSE_TOPIC; + will_topic.value.value.data= "MQTTV5/test"; + will_topic.value.value.len=11; + rc = MQTTProperties_add(&willProperties, &will_topic); + + MQTTProperty sub; + sub.identifier = USER_PROPERTY; + sub.value.value.data= "FFFF"; + sub.value.value.len=strlen(sub.value.value.data); + sub.value.data.data= "AAAA"; + sub.value.data.len=strlen(sub.value.data.data);; + rc = MQTTProperties_add(&subProperties, &sub); + +#endif + char* address = "broker.emqx.io"; + char* sub_topic = "MQTTV5/test"; + char* pub_topic = "MQTTV5/test"; + + int port = 1883; #if defined(configENABLE_TRUSTZONE) && (configENABLE_TRUSTZONE == 1) && defined(CONFIG_SSL_CLIENT_PRIVATE_IN_TZ) && (CONFIG_SSL_CLIENT_PRIVATE_IN_TZ == 1) rtw_create_secure_context(STACKSIZE*2); @@ -46,7 +110,7 @@ void prvMQTTEchoTask(void *pvParameters) extern void NS_ENTRY secure_set_ns_device_lock(void (*device_mutex_lock_func)(uint32_t), void (*device_mutex_unlock_func)(uint32_t)); secure_set_ns_device_lock(device_mutex_lock, device_mutex_unlock); #endif - + memset(readbuf, 0x00, sizeof(readbuf)); NetworkInit(&network); @@ -59,53 +123,88 @@ void prvMQTTEchoTask(void *pvParameters) mqtt_printf(MQTT_INFO, "Wi-Fi connected."); mqtt_printf(MQTT_INFO, "Connect Network \"%s\"", address); - while ((rc = NetworkConnect(&network, address, 1883)) != 0){ + while ((rc = NetworkConnect(&network, address, port)) != 0){ mqtt_printf(MQTT_INFO, "Return code from network connect is %d\n", rc); vTaskDelay(1000 / portTICK_PERIOD_MS); } mqtt_printf(MQTT_INFO, "\"%s\" Connected", address); - + connectData.clientID.cstring = "AmebaMQTT"; +#if defined(MQTTV5) + connectData.MQTTVersion = 5; + connectData.keepAliveInterval = 500; + connectData.cleansession = 1 ; + connectData.willFlag = 1; + connectData.will.message.cstring = "will_message"; + connectData.will.qos = 1; + connectData.will.retained = 1; + connectData.will.topicName.cstring = "MQTTV5/test"; + + struct subscribeOptions opts = {0, 0, 0, 0}; + opts.MaxQOS = 2; + opts.noLocal = 0; + opts.retainAsPublished = 1; + opts.retainHandling = 2; + +#else connectData.MQTTVersion = 3; - connectData.clientID.cstring = "FT1_018"; - +#endif mqtt_printf(MQTT_INFO, "Start MQTT connection"); +#if defined(MQTTV5) + while ((rc = MQTTV5Connect(&client, &connectData, &connectProperties, &willProperties)) != 0){ +#else while ((rc = MQTTConnect(&client, &connectData)) != 0){ +#endif mqtt_printf(MQTT_INFO, "Return code from MQTT connect is %d\n", rc); vTaskDelay(1000 / portTICK_PERIOD_MS); } + mqtt_printf(MQTT_INFO, "MQTT Connected"); - + mqtt_printf(MQTT_INFO, "Subscribe to Topic: %s", sub_topic); +#if defined(MQTTV5) + if ((rc = MQTTV5Subscribe(&client, sub_topic, &opts, messageArrived, &subProperties)) != 0) +#else if ((rc = MQTTSubscribe(&client, sub_topic, QOS2, messageArrived)) != 0) - mqtt_printf(MQTT_INFO, "Return code from MQTT subscribe is %d\n", rc); +#endif + mqtt_printf(MQTT_INFO, "Return code from MQTT subscribe is %d\n", rc); mqtt_printf(MQTT_INFO, "Publish Topics: %s", pub_topic); + while (1) { MQTTMessage message; char payload[300]; if (++count == 0) - count = 1; + count = 1; - message.qos = QOS1; + message.qos = QOS2; message.retained = 0; message.payload = payload; sprintf(payload, "hello from AMEBA %d", count); message.payloadlen = strlen(payload); - +#if defined(MQTTV5) + if ((rc = MQTTV5PublishHandle(&client, pub_topic, &message, &pubProperties)) != 0) +#else if ((rc = MQTTPublish(&client, pub_topic, &message)) != 0) +#endif mqtt_printf(MQTT_INFO,"Return code from MQTT publish is %d\n", rc); + if ((rc = MQTTYield(&client, 1000)) != 0) mqtt_printf(MQTT_INFO,"Return code from yield is %d\n", rc); vTaskDelay(5000); } /* do not return */ + vTaskDelete( NULL ); } #if defined(MQTT_TASK) +#if defined(MQTTV5) +void MQTTPublishMessage(MQTTClient* c, char *topic , MQTTProperties* properties) +#else void MQTTPublishMessage(MQTTClient* c, char *topic) -{ +#endif +{ int rc = 0; static int count = 0; MQTTMessage message; @@ -114,12 +213,18 @@ void MQTTPublishMessage(MQTTClient* c, char *topic) message.retained = 0; message.payload = payload; - if(c->mqttstatus == MQTT_RUNNING){ + if(c->mqttstatus == MQTT_RUNNING) + { count++; sprintf(payload, "hello from AMEBA %d", count); message.payloadlen = strlen(payload); mqtt_printf(MQTT_INFO, "Publish Topic %s : %d", topic, count); - if ((rc = MQTTPublish(c, topic, &message)) != 0){ +#if defined(MQTTV5) + if ((rc = MQTTV5PublishHandle(c, topic, &message, properties)) != 0) +#else + if ((rc = MQTTPublish(c, topic, &message)) != 0) +#endif + { mqtt_printf(MQTT_INFO, "Return code from MQTT publish is %d\n", rc); MQTTSetStatus(c, MQTT_START); c->ipstack->disconnect(c->ipstack); @@ -132,18 +237,47 @@ static void prvMQTTTask(void *pvParameters) { /* To avoid gcc warnings */ ( void ) pvParameters; - MQTTClient client; Network network; static unsigned char sendbuf[MQTT_SENDBUF_LEN], readbuf[MQTT_READBUF_LEN]; int rc = 0, mqtt_pub_count = 0; MQTTPacket_connectData connectData = MQTTPacket_connectData_initializer; +#if defined(MQTTV5) + MQTTProperty connect_props[10], will_props[10], pub_props[10]; + MQTTProperties connectProperties = MQTTProperties_initializer; + connectProperties.max_count = 6; + connectProperties.array = connect_props; + MQTTProperty connect; + connect.identifier = SESSION_EXPIRY_INTERVAL; + connect.value.integer4 = 10; + + MQTTProperties willProperties = MQTTProperties_initializer; + willProperties.max_count = 10; + willProperties.array = will_props; + MQTTProperty will; + will.identifier = WILL_DELAY_INTERVAL; + will.value.integer4 = 1; + rc = MQTTProperties_add(&willProperties, &will); + rc = MQTTProperties_add(&connectProperties, &connect); + + MQTTProperties pubProperties = MQTTProperties_initializer; + pubProperties.max_count = 10; + pubProperties.array = pub_props; + + MQTTProperty pub_format; + pub_format.identifier = PAYLOAD_FORMAT_INDICATOR; + pub_format.value.byte = 1; + rc = MQTTProperties_add(&pubProperties, &pub_format); + + connectData.MQTTVersion = 5; +#else connectData.MQTTVersion = 3; +#endif connectData.clientID.cstring = "FT1_018"; - char* address = "gpssensor.ddns.net"; + char* address = "broker.emqx.io"; char* sub_topic = "LASS/Test/Pm25Ameba/#"; char* pub_topic = "LASS/Test/Pm25Ameba/FT1_018"; - + #if defined(configENABLE_TRUSTZONE) && (configENABLE_TRUSTZONE == 1) && defined(CONFIG_SSL_CLIENT_PRIVATE_IN_TZ) && (CONFIG_SSL_CLIENT_PRIVATE_IN_TZ == 1) rtw_create_secure_context(STACKSIZE*2); extern int NS_ENTRY secure_mbedtls_platform_set_calloc_free(void); @@ -151,12 +285,11 @@ static void prvMQTTTask(void *pvParameters) extern void NS_ENTRY secure_set_ns_device_lock(void (*device_mutex_lock_func)(uint32_t), void (*device_mutex_unlock_func)(uint32_t)); secure_set_ns_device_lock(device_mutex_lock, device_mutex_unlock); #endif - + NetworkInit(&network); MQTTClientInit(&client, &network, 30000, sendbuf, sizeof(sendbuf), readbuf, sizeof(readbuf)); - while (1) - { + { while(wifi_is_ready_to_transceive(RTW_STA_INTERFACE) != RTW_SUCCESS) { mqtt_printf(MQTT_INFO, "Wait Wi-Fi to be connected."); vTaskDelay(5000 / portTICK_PERIOD_MS); @@ -170,12 +303,11 @@ static void prvMQTTTask(void *pvParameters) FD_ZERO(&except_fds); timeout.tv_sec = MQTT_SELECT_TIMEOUT; timeout.tv_usec = 0; - - if(network.my_socket >= 0){ + if(network.my_socket >= 0) + { FD_SET(network.my_socket, &read_fds); FD_SET(network.my_socket, &except_fds); rc = FreeRTOS_Select(network.my_socket + 1, &read_fds, NULL, &except_fds, &timeout); - if(FD_ISSET(network.my_socket, &except_fds)) { mqtt_printf(MQTT_INFO, "except_fds is set"); @@ -185,12 +317,22 @@ static void prvMQTTTask(void *pvParameters) { if(++mqtt_pub_count == 5) //Send MQTT publish message every 5 seconds { +#if defined(MQTTV5) + MQTTPublishMessage(&client, pub_topic, &pubProperties); +#else MQTTPublishMessage(&client, pub_topic); +#endif + mqtt_pub_count = 0; } } } +#if defined(MQTTV5) + MQTTDataHandle(&client, &read_fds, &connectData, messageArrived, address, sub_topic, &connectProperties, &willProperties); +#else MQTTDataHandle(&client, &read_fds, &connectData, messageArrived, address, sub_topic); +#endif + } } #endif @@ -201,24 +343,24 @@ void vStartMQTTTasks(uint16_t usTaskStackSize, UBaseType_t uxTaskPriority) #if defined(MQTT_TASK) xTaskCreate(prvMQTTTask, /* The function that implements the task. */ - "MQTTTask", /* Just a text name for the task to aid debugging. */ - usTaskStackSize, /* The stack size is defined in FreeRTOSIPConfig.h. */ - (void *)x, /* The task parameter, not used in this case. */ - uxTaskPriority, /* The priority assigned to the task is defined in FreeRTOSConfig.h. */ - NULL); /* The task handle is not used. */ + "MQTTTask", /* Just a text name for the task to aid debugging. */ + usTaskStackSize, /* The stack size is defined in FreeRTOSIPConfig.h. */ + (void *)x, /* The task parameter, not used in this case. */ + uxTaskPriority, /* The priority assigned to the task is defined in FreeRTOSConfig.h. */ + NULL); /* The task handle is not used. */ #else xTaskCreate(prvMQTTEchoTask, /* The function that implements the task. */ - "MQTTEcho0", /* Just a text name for the task to aid debugging. */ - usTaskStackSize + 128, /* The stack size is defined in FreeRTOSIPConfig.h. */ - (void *)x, /* The task parameter, not used in this case. */ - uxTaskPriority, /* The priority assigned to the task is defined in FreeRTOSConfig.h. */ - NULL); /* The task handle is not used. */ + "MQTTEcho0", /* Just a text name for the task to aid debugging. */ + usTaskStackSize + 128, /* The stack size is defined in FreeRTOSIPConfig.h. */ + (void *)x, /* The task parameter, not used in this case. */ + uxTaskPriority, /* The priority assigned to the task is defined in FreeRTOSConfig.h. */ + NULL); /* The task handle is not used. */ #endif } void example_mqtt(void) -{ +{ vStartMQTTTasks(4096, tskIDLE_PRIORITY + 4); } /*-----------------------------------------------------------*/ diff --git a/component/common/example/nonblock_connect/example_nonblock_connect.c b/component/common/example/nonblock_connect/example_nonblock_connect.c index 1f6dd853..85dad6fa 100644 --- a/component/common/example/nonblock_connect/example_nonblock_connect.c +++ b/component/common/example/nonblock_connect/example_nonblock_connect.c @@ -21,34 +21,40 @@ static void example_nonblock_connect_thread(void *param) vTaskDelay(10000); printf("\nExample: Non-blocking socket connect\n"); - server_fd = socket(AF_INET, SOCK_STREAM, 0); - fcntl(server_fd, F_SETFL, fcntl(server_fd, F_GETFL, 0) | O_NONBLOCK); - - server_addr.sin_family = AF_INET; - server_addr.sin_addr.s_addr = inet_addr(SERVER_IP); - server_addr.sin_port = htons(SERVER_PORT); - connect(server_fd, (struct sockaddr *) &server_addr, sizeof(server_addr)); - - if(errno == EINPROGRESS) { - fd_set wfds; - struct timeval time_out; - - time_out.tv_sec = 3; // Set select timeout of 3 seconds - time_out.tv_usec = 0; - FD_ZERO(&wfds) ; - FD_SET(server_fd, &wfds); // Only set server fd - - // Use select to wait for non-blocking connect - if(select(server_fd + 1, NULL, &wfds, NULL, &time_out) == 1) - printf("Server connection successful\n"); - else - printf("Server connection failed\n"); - } - else { - printf("ERROR: connect\n"); - } + if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) >= 0) { + fcntl(server_fd, F_SETFL, fcntl(server_fd, F_GETFL, 0) | O_NONBLOCK); + + server_addr.sin_family = AF_INET; + server_addr.sin_addr.s_addr = inet_addr(SERVER_IP); + server_addr.sin_port = htons(SERVER_PORT); + connect(server_fd, (struct sockaddr *) &server_addr, sizeof(server_addr)); + + if(errno == EINPROGRESS) { + fd_set wfds; + struct timeval time_out; - close(server_fd); + time_out.tv_sec = 3; // Set select timeout of 3 seconds + time_out.tv_usec = 0; + FD_ZERO(&wfds) ; + FD_SET(server_fd, &wfds); // Only set server fd + + // Use select to wait for non-blocking connect + if(select(server_fd + 1, NULL, &wfds, NULL, &time_out) == 1) + printf("Server connection successful\n"); + else + printf("Server connection failed\n"); + } + else { + printf("ERROR: connect\n"); + } + + } else { + printf("socket error\n"); + goto exit; + } +exit: + if(server_fd >= 0) + close(server_fd); vTaskDelete(NULL); } diff --git a/component/common/example/socket_select/example_socket_select.c b/component/common/example/socket_select/example_socket_select.c index d3224b99..a1902986 100644 --- a/component/common/example/socket_select/example_socket_select.c +++ b/component/common/example/socket_select/example_socket_select.c @@ -2,6 +2,7 @@ #include "task.h" #include #include +#include "wifi_conf.h" #define CONNECT_REMOTE 0 @@ -29,7 +30,10 @@ static void example_socket_select_thread(void *param) int socket_used[MAX_SOCKETS]; // Delay to wait for IP by DHCP - vTaskDelay(10000); + while(wifi_is_ready_to_transceive(RTW_STA_INTERFACE) != RTW_SUCCESS){ + printf("\n\rWait for WIFI connection ...\r\n"); + vTaskDelay(12000); + } printf("\nExample: socket select\n"); memset(socket_used, 0, sizeof(socket_used)); diff --git a/component/common/example/wifi_roaming/example_wifi_roaming.c b/component/common/example/wifi_roaming/example_wifi_roaming.c index 118a75a6..24e6ed4d 100644 --- a/component/common/example/wifi_roaming/example_wifi_roaming.c +++ b/component/common/example/wifi_roaming/example_wifi_roaming.c @@ -53,7 +53,7 @@ u32 wifi_roaming_find_ap_from_scan_buf(char*buf, int buflen, char *target_ssid, while(plen < buflen) { - u32 len, ssid_len, security_mode, security_type, channel; + u32 len, ssid_len, security_mode, security_type = 0, channel; s32 rssi; u8 *mac, *ssid; // len @@ -131,7 +131,7 @@ void wifi_roaming_thread(void *param) { rtw_wifi_setting_t setting; wifi_roaming_ap_t roaming_ap; - int ap_rssi; + int ap_rssi = 0; u32 i = 0, polling_count =0; u8 *pscan_config = NULL; u8 pscan_connect = PSCAN_ENABLE; diff --git a/component/common/example/wlan_fast_connect/example_wlan_fast_connect.c b/component/common/example/wlan_fast_connect/example_wlan_fast_connect.c index 2b20883d..8401c162 100644 --- a/component/common/example/wlan_fast_connect/example_wlan_fast_connect.c +++ b/component/common/example/wlan_fast_connect/example_wlan_fast_connect.c @@ -22,6 +22,7 @@ #include extern struct netif xnetif[NET_IF_NUM]; +extern u32 g_reconnect_delay; write_reconnect_ptr p_write_reconnect_ptr; @@ -154,6 +155,10 @@ int wifi_init_done_prior(void) if(ret != RTW_SUCCESS){ wifi_retry_connect--; if(wifi_retry_connect > 0){ + if (g_reconnect_delay > 0) { + vTaskDelay(g_reconnect_delay); + g_reconnect_delay = 0; + } printf("wifi retry\r\n"); goto WIFI_RETRY_LOOP; } @@ -168,8 +173,10 @@ int wifi_init_done_prior(void) } free(data); + return 0; } - + printf("malloc fail\r\n"); + return -1; } /* * Usage: @@ -308,6 +315,10 @@ int wlan_init_done_callback(void) wifi_retry_connect--; if(wifi_retry_connect > 0){ printf("wifi retry\r\n"); + if (g_reconnect_delay > 0) { + vTaskDelay(g_reconnect_delay); + g_reconnect_delay = 0; + } goto WIFI_RETRY_LOOP; } } diff --git a/component/common/mbed/targets/hal/rtl8710c/crypto_api.c b/component/common/mbed/targets/hal/rtl8710c/crypto_api.c index daab5409..f3bef3a2 100644 --- a/component/common/mbed/targets/hal/rtl8710c/crypto_api.c +++ b/component/common/mbed/targets/hal/rtl8710c/crypto_api.c @@ -61,7 +61,7 @@ int crypto_deinit(void) #if defined(CONFIG_FLASH_XIP_EN) && (CONFIG_FLASH_XIP_EN == 1) int xip_flash_remap_check(const uint8_t *ori_addr, u32 *remap_addr, const uint32_t buf_len) { u32 xip_phy_addr; - u8 pis_enc; + u32 pis_enc; int ret = SUCCESS; if (((u32)ori_addr >= XIP_REMAPPED_START_ADDR) && ((u32)ori_addr < XIP_REMAPPED_END_ADDR)) { @@ -1298,7 +1298,8 @@ int crypto_random_seed (uint8_t *seed_buf, uint32_t seed_size) hal_timer_adapter_t *phs_tmr; uint32_t loop_cnt; uint32_t i; - + + memset(&ls_timer, 0, sizeof(hal_timer_adapter_t)); if ((seed_size == 0) || (seed_buf == NULL)) { return _ERRNO_CRYPTO_RNG_RANDOM_SEED_FAIL; } diff --git a/component/common/mbed/targets/hal/rtl8710c/efuse_api.c b/component/common/mbed/targets/hal/rtl8710c/efuse_api.c index 285e0fbf..afd3bc4f 100644 --- a/component/common/mbed/targets/hal/rtl8710c/efuse_api.c +++ b/component/common/mbed/targets/hal/rtl8710c/efuse_api.c @@ -110,7 +110,7 @@ int efuse_disable_nonsec_jtag(void) int efuse_lock_susec_key(void) { uint32_t ret = _FALSE; - uint8_t ss_lock; + uint8_t ss_lock = 0; ret = hal_efuse_read (EFUSE_SSLOCK_OFFSET, &ss_lock, LDO_OUT_DEFAULT_VOLT); if (ret == _TRUE) { @@ -128,4 +128,11 @@ int efuse_lock_susec_key(void) } } +void efuse_rotpk_enable(void) +{ + uint8_t rotpk_en = 0; + hal_efuse_read(EFUSE_SSLOCK_OFFSET, &rotpk_en, LDO_OUT_DEFAULT_VOLT); + rotpk_en &= ~(BIT(1)); + hal_efuse_write(EFUSE_SSLOCK_OFFSET, rotpk_en, LDO_OUT_DEFAULT_VOLT); +} #endif diff --git a/component/common/mbed/targets/hal/rtl8710c/pwmout_api.c b/component/common/mbed/targets/hal/rtl8710c/pwmout_api.c index 2a0dec31..5f3ab3c5 100644 --- a/component/common/mbed/targets/hal/rtl8710c/pwmout_api.c +++ b/component/common/mbed/targets/hal/rtl8710c/pwmout_api.c @@ -107,8 +107,8 @@ void pwmout_init(pwmout_t *obj, PinName pin) return; } obj->is_init = 1; // Initialize Success - pwmout_period_us(obj, 20000); // 20 ms per default - hal_pwm_enable ((&obj->pwm_hal_adp)); + //pwmout_period_us(obj, 20000); // 20 ms per default + //hal_pwm_enable ((&obj->pwm_hal_adp)); } void pwmout_free(pwmout_t *obj) diff --git a/component/common/network/coap/sn_coap_ameba_port.c b/component/common/network/coap/sn_coap_ameba_port.c index 409ed01d..3d998da7 100644 --- a/component/common/network/coap/sn_coap_ameba_port.c +++ b/component/common/network/coap/sn_coap_ameba_port.c @@ -4,7 +4,7 @@ ///////////////////////////////////////////ramdom function/////////////////////////////////////////// uint16_t randLIB_get_16bit(){ - unsigned char rnd[2]; + unsigned char rnd[2] = {0}; rtw_get_random_bytes(rnd,2); return ( ((uint16_t)rnd[0] << 8) | ((uint16_t)rnd[1]) ); @@ -98,7 +98,7 @@ int coap_send(char *to_address, uint16_t port, int socket, sn_coap_hdr_s *coap_m coap_free(message_ptr); return -1; } - memcpy((void *) &internet_address.sin_addr, (void *) host_entry->h_addr, host_entry->h_length); + memcpy((void *) &internet_address.sin_addr, (void *) host_entry->h_addr, sizeof(internet_address.sin_addr)); int n = sendto(socket, message_ptr, message_len, 0, (struct sockaddr *)&internet_address, sizeof(internet_address)); diff --git a/component/common/network/sntp/sntp.c b/component/common/network/sntp/sntp.c index f648850d..631f0bb9 100644 --- a/component/common/network/sntp/sntp.c +++ b/component/common/network/sntp/sntp.c @@ -741,7 +741,7 @@ sntp_stop(void) int atcmd_sntp(char* hostname){ ip_addr_t sntp_server_address; - err_t err; + err_t err = ERR_OK; if (sntp_pcb == NULL) { sntp_pcb = udp_new(); diff --git a/component/common/utilities/xml.c b/component/common/utilities/xml.c index f82eadfb..553ba91f 100644 --- a/component/common/utilities/xml.c +++ b/component/common/utilities/xml.c @@ -497,7 +497,7 @@ struct xml_node *xml_parse_doc(char *doc_buf, int doc_len, char *doc_prefix, cha struct xml_node *xml_parse(char *doc_buf, int doc_len) { - char *proc_inst, *comment, *pos, *prolog_end; + char *proc_inst = NULL, *comment = NULL, *pos, *prolog_end; /* Remove XML Prolog */ pos = doc_buf; diff --git a/component/os/freertos/cmsis_os.c b/component/os/freertos/cmsis_os.c index 156e0f69..29d189cc 100644 --- a/component/os/freertos/cmsis_os.c +++ b/component/os/freertos/cmsis_os.c @@ -654,6 +654,7 @@ osEvent osSignalWait (int32_t signals, uint32_t millisec) osEvent ret; uint32_t wait_ticks; + memset(&ret, 0, sizeof(osEvent)); if (signals & (0xFFFFFFFF << osFeature_Signals)) { ret.status = osErrorValue; ret.value.signals = 0; @@ -1146,6 +1147,7 @@ osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec) portTickType ticks; osEvent retEvent; + memset(&retEvent, 0, sizeof(osEvent)); retEvent.def.message_id = queue_id; if (inHandlerMode()) { if (xQueueReceiveFromISR(queue_id, (void *)retEvent.value.p, &taskWoken) != pdTRUE) { @@ -1327,6 +1329,7 @@ osEvent osMailGet (osMailQId queue_id, uint32_t millisec) portTickType ticks; osEvent event; + memset(&event, 0, sizeof(osEvent)); event.def.mail_id = queue_id; if (queue_id == NULL) { diff --git a/component/soc/realtek/8710c/cmsis/rtl8710c/source/ram_s/app_start.c b/component/soc/realtek/8710c/cmsis/rtl8710c/source/ram_s/app_start.c index 57c67353..678992bd 100644 --- a/component/soc/realtek/8710c/cmsis/rtl8710c/source/ram_s/app_start.c +++ b/component/soc/realtek/8710c/cmsis/rtl8710c/source/ram_s/app_start.c @@ -54,21 +54,21 @@ __weak int main (void) __weak void __iar_data_init3(void) { - + } __weak void __iar_zero_init3(void) { - + } #if (defined(CONFIG_MIIO)&&(CONFIG_MIIO)) void HalHardFaultHandler_Patch_c(u32 HardDefaultArg, u32 lr) { - uint32_t crash_flag = 0xE32C04EDUL; - extern int arch_psm_set_value(const char*, const char*, const void*, uint32_t); - arch_psm_set_value("arch", "crash_flag", &crash_flag, sizeof(uint32_t)); - ((int_vector_t)(0xab5))(); + uint32_t crash_flag = 0xE32C04EDUL; + extern int arch_psm_set_value(const char*, const char*, const void*, uint32_t); + arch_psm_set_value("arch", "crash_flag", &crash_flag, sizeof(uint32_t)); + ((int_vector_t)(0xab5))(); } void HalHardFaultHandler_Patch_asm(void) @@ -94,54 +94,54 @@ void HalHardFaultHandler_Patch_asm(void) void sau_setup(ns_region_t *ns_region) { #if SAU_INIT_REGION0 - //dbg_printf ("SAU 0: 0x%08x ~ 0x%08x as %s\r\n", SAU_INIT_START0, SAU_INIT_END0, SAU_INIT_NSC0?"Secure(NSC)":"Non-Secure"); - if (SAU_INIT_NSC0 == 0) { - // Set Bus IDAU to match the SAU setting, use IDAU2 - bus_idau_setup(0, SAU_INIT_START0, SAU_INIT_END0); - } - ns_region[0].start_addr = SAU_INIT_START0; - ns_region[0].end_addr = SAU_INIT_END0; - ns_region[0].is_valid = 1; + //dbg_printf ("SAU 0: 0x%08x ~ 0x%08x as %s\r\n", SAU_INIT_START0, SAU_INIT_END0, SAU_INIT_NSC0?"Secure(NSC)":"Non-Secure"); + if (SAU_INIT_NSC0 == 0) { + // Set Bus IDAU to match the SAU setting, use IDAU2 + bus_idau_setup(0, SAU_INIT_START0, SAU_INIT_END0); + } + ns_region[0].start_addr = SAU_INIT_START0; + ns_region[0].end_addr = SAU_INIT_END0; + ns_region[0].is_valid = 1; #endif #if SAU_INIT_REGION1 - //dbg_printf ("SAU 1: 0x%08x ~ 0x%08x as %s\r\n", SAU_INIT_START1, SAU_INIT_END1, SAU_INIT_NSC1?"Secure(NSC)":"Non-Secure"); - if (SAU_INIT_NSC1 == 0) { - // Set Bus IDAU to match the SAU setting, use IDAU3 - bus_idau_setup(1, SAU_INIT_START1, SAU_INIT_END1); - } - ns_region[1].start_addr = SAU_INIT_START1; - ns_region[1].end_addr = SAU_INIT_END1; - ns_region[1].is_valid = 1; + //dbg_printf ("SAU 1: 0x%08x ~ 0x%08x as %s\r\n", SAU_INIT_START1, SAU_INIT_END1, SAU_INIT_NSC1?"Secure(NSC)":"Non-Secure"); + if (SAU_INIT_NSC1 == 0) { + // Set Bus IDAU to match the SAU setting, use IDAU3 + bus_idau_setup(1, SAU_INIT_START1, SAU_INIT_END1); + } + ns_region[1].start_addr = SAU_INIT_START1; + ns_region[1].end_addr = SAU_INIT_END1; + ns_region[1].is_valid = 1; #endif - + #if SAU_INIT_REGION2 - //dbg_printf ("SAU 2: 0x%08x ~ 0x%08x as %s\r\n", SAU_INIT_START2, SAU_INIT_END2, SAU_INIT_NSC2?"Secure(NSC)":"Non-Secure"); - if (SAU_INIT_NSC2 == 0) { - // Set Bus IDAU to match the SAU setting, use IDAU0 - bus_idau_setup(2, SAU_INIT_START2, SAU_INIT_END2); - } - ns_region[2].start_addr = SAU_INIT_START2; - ns_region[2].end_addr = SAU_INIT_END2; - ns_region[2].is_valid = 1; + //dbg_printf ("SAU 2: 0x%08x ~ 0x%08x as %s\r\n", SAU_INIT_START2, SAU_INIT_END2, SAU_INIT_NSC2?"Secure(NSC)":"Non-Secure"); + if (SAU_INIT_NSC2 == 0) { + // Set Bus IDAU to match the SAU setting, use IDAU0 + bus_idau_setup(2, SAU_INIT_START2, SAU_INIT_END2); + } + ns_region[2].start_addr = SAU_INIT_START2; + ns_region[2].end_addr = SAU_INIT_END2; + ns_region[2].is_valid = 1; #endif #if SAU_INIT_REGION3 - //dbg_printf ("SAU 3: 0x%08x ~ 0x%08x as %s\r\n", SAU_INIT_START3, SAU_INIT_END3, SAU_INIT_NSC3?"Secure(NSC)":"Non-Secure"); - if (SAU_INIT_NSC3 == 0) { - // Set Bus IDAU to match the SAU setting, use IDAU0 - bus_idau_setup(3, SAU_INIT_START3, SAU_INIT_END3); - - ns_region[3].start_addr = SAU_INIT_START3; - ns_region[3].end_addr = SAU_INIT_END3; - ns_region[3].is_valid = 1; - } + //dbg_printf ("SAU 3: 0x%08x ~ 0x%08x as %s\r\n", SAU_INIT_START3, SAU_INIT_END3, SAU_INIT_NSC3?"Secure(NSC)":"Non-Secure"); + if (SAU_INIT_NSC3 == 0) { + // Set Bus IDAU to match the SAU setting, use IDAU0 + bus_idau_setup(3, SAU_INIT_START3, SAU_INIT_END3); + + ns_region[3].start_addr = SAU_INIT_START3; + ns_region[3].end_addr = SAU_INIT_END3; + ns_region[3].is_valid = 1; + } #endif - TZ_SAU_Setup(); + TZ_SAU_Setup(); } #endif void app_start (void) -{ - dbg_printf ("Build @ %s, %s\r\n", __TIME__, __DATE__); +{ + dbg_printf ("Build @ %s, %s\r\n", __TIME__, __DATE__); #if (defined(CONFIG_MIIO)&&(CONFIG_MIIO)) extern int_vector_t ram_vector_table[]; @@ -156,11 +156,11 @@ void app_start (void) // __iar_data_init3 replaced by __iar_cstart_call_ctors, just do c++ constructor //__iar_cstart_call_ctors(NULL); #endif - - shell_cmd_init (); - main(); + + shell_cmd_init (); + main(); #if defined ( __ICCARM__ ) - // for compile issue, If user never call this function, Liking fail + // for compile issue, If user never call this function, Liking fail __iar_data_init3(); #endif } diff --git a/component/soc/realtek/8710c/fwlib/source/ram_ns/hal_flash.c b/component/soc/realtek/8710c/fwlib/source/ram_ns/hal_flash.c index 328897b8..43f0ea9d 100644 --- a/component/soc/realtek/8710c/fwlib/source/ram_ns/hal_flash.c +++ b/component/soc/realtek/8710c/fwlib/source/ram_ns/hal_flash.c @@ -586,7 +586,7 @@ void hal_flash_return_spi (phal_spic_adaptor_t phal_spic_adaptor) { pflash_cmd_t cmd = phal_spic_adaptor->cmd; spic_valid_cmd_t valid_cmd; - spic_init_para_t spic_init_data; + spic_init_para_t spic_init_data = {0}; pspic_init_para_t pspic_init_data = &spic_init_data; SPIC_Type *spic_dev = phal_spic_adaptor->spic_dev; u8 spic_send_cmd_mode = phal_spic_adaptor->spic_send_cmd_mode; @@ -743,6 +743,9 @@ void hal_flash_burst_write (phal_spic_adaptor_t phal_spic_adaptor, u32 length, u } if (((u32)data >> 24) == 0x98) { + DBG_SPIF_ERR("Source data should be stored in ram!\r\n"); + return; +#if 0 data = (u8*)((u32)data & 0xFFFFFF); page_size = 256; existed_data_size = addr & 0xFF; @@ -775,6 +778,7 @@ void hal_flash_burst_write (phal_spic_adaptor_t phal_spic_adaptor, u32 length, u } } } +#endif } else { hal_flash_stubs.hal_flash_burst_write(phal_spic_adaptor, length, addr, data); } @@ -799,6 +803,7 @@ void hal_flash_page_program (phal_spic_adaptor_t phal_spic_adaptor, u32 length, hal_flash_stubs.hal_flash_page_program(phal_spic_adaptor, length, addr, data); } +#if 0 /** \brief Description of hal_flash_read_write_flash * * hal_flash_read_write_flash is used to program sequential data with user mode. @@ -824,7 +829,7 @@ void hal_flash_read_write_flash (phal_spic_adaptor_t phal_spic_adaptor, u32 leng u8 index; u8 spic_send_cmd_mode; u8 addr_byte_num; - u8 buffer[256]; + u8 buffer[256] = {0}; u8* ptr = &buffer[0]; hal_flash_stream_read(phal_spic_adaptor, length, (u32)data, buffer); @@ -946,7 +951,7 @@ void hal_flash_read_write_flash (phal_spic_adaptor_t phal_spic_adaptor, u32 leng spic_dev->valid_cmd_b.prm_en = ENABLE; } - +#endif /** \brief Description of hal_flash_reset_to_spi * @@ -1037,7 +1042,7 @@ void hal_flash_support_new_type (phal_spic_adaptor_t phal_spic_adaptor) */ u8 hal_flash_get_size (phal_spic_adaptor_t phal_spic_adaptor) { - u8 efuse_value; + u8 efuse_value = 0; u8 size_id = phal_spic_adaptor->flash_id[2]; u32 size = 0; diff --git a/component/soc/realtek/8710c/fwlib/source/ram_ns/hal_i2c.c b/component/soc/realtek/8710c/fwlib/source/ram_ns/hal_i2c.c index 57e19c2c..17d6bd00 100644 --- a/component/soc/realtek/8710c/fwlib/source/ram_ns/hal_i2c.c +++ b/component/soc/realtek/8710c/fwlib/source/ram_ns/hal_i2c.c @@ -51,7 +51,7 @@ extern hal_i2c_func_stubs_t __rom_stubs_hal_i2c; // symbol from linker scrip */ hal_status_t hal_i2c_pin_register(hal_i2c_adapter_t *phal_i2c_adapter) { - hal_status_t ret; + hal_status_t ret = HAL_OK; if ((uint8_t)(phal_i2c_adapter->pltf_dat.scl_pin) != (uint8_t)0) { ret = hal_pinmux_register(phal_i2c_adapter->pltf_dat.scl_pin, PID_I2C0); } @@ -72,7 +72,7 @@ hal_status_t hal_i2c_pin_register(hal_i2c_adapter_t *phal_i2c_adapter) */ hal_status_t hal_i2c_pin_unregister(hal_i2c_adapter_t *phal_i2c_adapter) { - hal_status_t ret; + hal_status_t ret = HAL_OK; if ((uint8_t)(phal_i2c_adapter->pltf_dat.scl_pin) != (uint8_t)0) { ret = hal_pinmux_unregister(phal_i2c_adapter->pltf_dat.scl_pin, PID_I2C0); } diff --git a/component/soc/realtek/8710c/fwlib/source/ram_ns/hal_sdio_dev.c b/component/soc/realtek/8710c/fwlib/source/ram_ns/hal_sdio_dev.c index 87c093f2..39b17b46 100644 --- a/component/soc/realtek/8710c/fwlib/source/ram_ns/hal_sdio_dev.c +++ b/component/soc/realtek/8710c/fwlib/source/ram_ns/hal_sdio_dev.c @@ -714,9 +714,9 @@ uint8_t hal_sdio_dev_process_rpwm2 (hal_sdio_dev_adapter_t *psdio_adp) */ hal_status_t hal_sdio_dev_init (void) { - hal_status_t ret; - uint16_t tx_bd_num; - uint16_t rx_bd_num; + hal_status_t ret = HAL_OK; + uint16_t tx_bd_num = 0; + uint16_t rx_bd_num = 0; uint32_t i; sdiod_rx_packet_t *prx_pkt; diff --git a/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_eap.a b/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_eap.a index 7aa41c42..2ef31a9a 100644 Binary files a/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_eap.a and b/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_eap.a differ diff --git a/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_wlan.a b/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_wlan.a index 13250a04..0259948d 100644 Binary files a/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_wlan.a and b/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_wlan.a differ diff --git a/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_wlan_mp.a b/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_wlan_mp.a index 96fd996b..9834ecc6 100644 Binary files a/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_wlan_mp.a and b/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_wlan_mp.a differ diff --git a/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_wlan_mp_ns.a b/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_wlan_mp_ns.a index a8a8e843..d858cd28 100644 Binary files a/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_wlan_mp_ns.a and b/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_wlan_mp_ns.a differ diff --git a/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_wlan_ns.a b/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_wlan_ns.a index 9e500931..4c95ca55 100644 Binary files a/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_wlan_ns.a and b/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/lib_wlan_ns.a differ diff --git a/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_eap.a b/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_eap.a index 274afdc7..d1f3d979 100644 Binary files a/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_eap.a and b/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_eap.a differ diff --git a/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_wlan.a b/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_wlan.a index bdf59db4..7f85f837 100644 Binary files a/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_wlan.a and b/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_wlan.a differ diff --git a/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_wlan_mp.a b/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_wlan_mp.a index bb941678..8c9cbe00 100644 Binary files a/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_wlan_mp.a and b/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_wlan_mp.a differ diff --git a/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_wlan_mp_ns.a b/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_wlan_mp_ns.a index 019fcc0a..69534a48 100644 Binary files a/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_wlan_mp_ns.a and b/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_wlan_mp_ns.a differ diff --git a/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_wlan_ns.a b/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_wlan_ns.a index 974272ed..080e1edf 100644 Binary files a/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_wlan_ns.a and b/component/soc/realtek/8710c/misc/bsp/lib/common/IAR/lib_wlan_ns.a differ diff --git a/component/soc/realtek/8710c/misc/driver/flash_api_ext.c b/component/soc/realtek/8710c/misc/driver/flash_api_ext.c index a8a6082b..114625b5 100644 --- a/component/soc/realtek/8710c/misc/driver/flash_api_ext.c +++ b/component/soc/realtek/8710c/misc/driver/flash_api_ext.c @@ -45,7 +45,7 @@ void flash_erase_dword(u32 address, u32 dword_num) flash_t flash; u32 data_4=0; - u8 data_8[8]; + u8 data_8[8] = {0}; /* erase backup sector 4k bytes*/ flash_erase_sector(&flash, FLASH_RESERVED_DATA_BASE); diff --git a/component/soc/realtek/8710c/misc/platform/ota_8710c.c b/component/soc/realtek/8710c/misc/platform/ota_8710c.c index b952e16a..c029e241 100644 --- a/component/soc/realtek/8710c/misc/platform/ota_8710c.c +++ b/component/soc/realtek/8710c/misc/platform/ota_8710c.c @@ -82,7 +82,7 @@ int update_ota_erase_upg_region(uint32_t img_len, uint32_t NewFWLen, uint32_t Ne int update_ota_signature(unsigned char* sig_backup, uint32_t NewFWAddr){ int ret = 0; - unsigned char sig_readback[32]; + unsigned char sig_readback[32] = {0}; printf("\n\r[%s] Append OTA signature", __FUNCTION__); device_mutex_lock(RT_DEV_LOCK_FLASH); if(flash_burst_write(&flash_ota, NewFWAddr + 16, 16, sig_backup + 16) < 0){ @@ -108,7 +108,7 @@ int update_ota_signature(unsigned char* sig_backup, uint32_t NewFWAddr){ static void update_ota_local_task(void *param) { - int server_socket; + int server_socket = 0; unsigned char *buf; unsigned char sig_backup[32]; int read_bytes = 0, idx = 0; @@ -536,7 +536,8 @@ int parse_http_response(uint8_t *response, uint32_t response_len, http_response_ while ( j1 < q && (*(response+j1) == ':' || *(response+j1) == ' ') ) ++j1; while ( j2 > j1 && *(response+j2) == ' ') --j2; uint8_t len_buf[12] = {0}; - memcpy(len_buf, response+j1, j2-j1+1); + if ((j2-j1+1)<=sizeof(len_buf)) + memcpy(len_buf, response+j1, j2-j1+1); result->body_len = atoi((char const *)len_buf); result->parse_status = 2; } diff --git a/component/soc/realtek/8710c/misc/utilities/source/ram/libc_wrap.c b/component/soc/realtek/8710c/misc/utilities/source/ram/libc_wrap.c index 836e4c12..89978a77 100644 --- a/component/soc/realtek/8710c/misc/utilities/source/ram/libc_wrap.c +++ b/component/soc/realtek/8710c/misc/utilities/source/ram/libc_wrap.c @@ -104,7 +104,9 @@ int check_format(const char * fmt,...){ if(*fmt1 == '"') { do { fmt1 ++; - } while(*fmt1 != '"'); + } while(*fmt1 != '"' && *fmt1 !='\0'); + if(*fmt1 == '\0') + return 1; fmt1 ++; } @@ -848,7 +850,8 @@ validate_structure (struct tm *tim_p) ((_DAYS_IN_YEAR (tim_p->tm_year) == 366) ? 29 : 28); } - tim_p->tm_mday += _DAYS_IN_MONTH (tim_p->tm_mon); + if (tim_p->tm_mon != -1) // to pass coverity test + tim_p->tm_mday += _DAYS_IN_MONTH (tim_p->tm_mon); } } else diff --git a/project/realtek_amebaz2_v0_example/EWARM-RELEASE/application_is.ewp b/project/realtek_amebaz2_v0_example/EWARM-RELEASE/application_is.ewp index cd736eef..3a262576 100644 --- a/project/realtek_amebaz2_v0_example/EWARM-RELEASE/application_is.ewp +++ b/project/realtek_amebaz2_v0_example/EWARM-RELEASE/application_is.ewp @@ -458,6 +458,8 @@ $PROJ_DIR$\..\..\..\component\common\bluetooth\realtek\sdk\example\bt_ota_central_client $PROJ_DIR$\..\..\..\component\common\bluetooth\realtek\sdk\example\bt_harmony_adapter $PROJ_DIR$\..\..\..\component\common\bluetooth\realtek\sdk\example\bt_datatrans + $PROJ_DIR$\..\..\..\component\common\application\mqtt\MQTTPacket\V5 + $PROJ_DIR$\..\..\..\component\common\application\mqtt\MQTTPacket