@@ -328,6 +328,11 @@ static void bt_cm_conn_dealloc(bt_cm_device_manager_t *env, bt_cm_dev_acl_info_t
328328 {
329329 if (& env -> bt_devices [i ] == conn )
330330 {
331+ if (conn -> profile_timer_hdl )
332+ {
333+ rt_timer_delete (conn -> profile_timer_hdl );
334+ conn -> profile_timer_hdl = NULL ;
335+ }
331336 memset (conn , 0 , sizeof (bt_cm_dev_acl_info_t ));
332337 return ;
333338 }
@@ -473,6 +478,44 @@ int bt_open_bt_request_scan(uint8_t scan)
473478}
474479
475480#ifdef BT_AUTO_CONNECT_LAST_DEVICE
481+
482+ static void bt_cm_reconnect_timeout_hdl (void * parameter )
483+ {
484+ uint32_t time_state = 0 ;
485+ if (parameter != NULL )
486+ {
487+ bt_cm_dev_acl_info_t * conn = (bt_cm_dev_acl_info_t * )parameter ;
488+ if (conn -> profile_timer_hdl )
489+ {
490+ rt_timer_delete (conn -> profile_timer_hdl );
491+ conn -> profile_timer_hdl = NULL ;
492+ }
493+
494+ uint32_t profile_bit = bt_cm_conn_get_next_profile (conn , conn -> info .link_type );
495+
496+ if (profile_bit )
497+ {
498+ bt_cm_err_t ret = bt_cm_profile_connect (profile_bit , & conn -> info .bd_addr , conn -> info .link_type );
499+ LOG_I ("bt_cm_reconnect_timeout_hdl profile_bit %d link_type 0x%2x" , profile_bit , conn -> info .link_type );
500+
501+ if (ret != BT_CM_ERR_NO_ERR )
502+ {
503+ bt_cm_conn_dealloc (bt_cm_get_env (), conn );
504+ gap_wr_scan_enb_req (bts2_task_get_app_task_id (), 1 , 1 );
505+ return ;
506+ }
507+
508+ // Avoid scan and page
509+ gap_wr_scan_enb_req (bts2_task_get_app_task_id (), 0 , 0 );
510+ }
511+ else
512+ {
513+ bt_cm_conn_dealloc (bt_cm_get_env (), conn );
514+ gap_wr_scan_enb_req (bts2_task_get_app_task_id (), 1 , 1 );
515+ }
516+ }
517+ }
518+
476519static int bt_cm_update_profile_bit_mask (bt_cm_dev_acl_info_t * conn , uint32_t profile_bit )
477520{
478521 if (conn )
@@ -968,6 +1011,7 @@ static void bt_cm_hci_acl_connect_complete_event_hdl(BTS2S_DM_EN_ACL_OPENED_IND
9681011 conn -> info .dev_cls = ind -> dev_cls ;
9691012 conn -> link_dir = ind -> incoming ;
9701013 conn -> state = BT_CM_ACL_STATE_CONNECTED ;
1014+ conn -> info .is_reconn = bt_cm_get_reconnect_flag_by_role (conn -> info .link_type );
9711015 hcia_wr_lp_settings_keep_sniff_interval (& ind -> bd , HCI_LINK_POLICY_NO_CHANGE , BT_CM_SNIFF_ENTER_TIME ,
9721016 BT_CM_SNIFF_INV , BT_CM_SNIFF_INV , BT_CM_SNIFF_ATTEMPT , BT_CM_SNIFF_TIMEOUT , NULL );
9731017 }
@@ -1033,9 +1077,23 @@ static void bt_cm_hci_acl_disconnect_complete_event_hdl(BTS2S_DM_ACL_DISC_IND *i
10331077
10341078 if (conn != NULL )
10351079 {
1036- bt_cm_link_role_t role = conn -> info .role ;
1080+ bt_cm_link_type_t link_type = conn -> info .link_type ;
10371081 uint8_t is_reconn = conn -> info .is_reconn ;
10381082 bt_cm_conn_dealloc (env , conn );
1083+ #ifdef BT_AUTO_CONNECT_LAST_DEVICE
1084+ if (is_reconn && ind -> reason == HCI_ERR_CONN_TIMEOUT )
1085+ {
1086+
1087+ // Try re-connect
1088+ conn = bt_cm_conn_alloc (env , & ind -> cur_bd , link_type );
1089+ conn -> profile_timer_hdl = rt_timer_create ("btcm_con" , bt_cm_reconnect_timeout_hdl , conn ,
1090+ rt_tick_from_millisecond (BT_CM_MAX_TIMEOUT ), RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_SOFT_TIMER );
1091+
1092+ if (conn -> profile_timer_hdl )
1093+ rt_timer_start (conn -> profile_timer_hdl );
1094+ }
1095+ #endif
1096+
10391097 }
10401098}
10411099
@@ -1423,11 +1481,6 @@ bt_err_t bt_interface_acpt_connect_req(unsigned char *mac, uint8_t link_role, ui
14231481 return BT_EOK ;
14241482}
14251483
1426- static void bt_cm_conn_timeout (void * parameter )
1427- {
1428- uint32_t time_state = 0 ;
1429- }
1430-
14311484bt_cm_err_t bt_cm_profile_connect (uint32_t profile_bit , BTS2S_BD_ADDR * bd_addr , bt_cm_link_type_t link_type )
14321485{
14331486 bt_cm_err_t err = BT_CM_ERR_NO_ERR ;
0 commit comments