@@ -561,10 +561,6 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
561561 bool high_duty_directed = directed_to != NULL && interval <= 3.5 && timeout <= 1 ; // Really 1.3, but it's an int
562562
563563 uint32_t timeout_ms = timeout * 1000 ;
564- if (timeout_ms == 0 ) {
565- timeout_ms = BLE_HS_FOREVER ;
566- }
567-
568564
569565 #if MYNEWT_VAL (BLE_EXT_ADV )
570566 bool extended = advertising_data_len > BLE_ADV_LEGACY_DATA_MAX_LEN ||
@@ -626,8 +622,12 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
626622 }
627623 }
628624
625+ // If timeout_ms is zero, it means advertise forever. This is different than ble_gap_adv_start().
629626 rc = ble_gap_ext_adv_start (0 , timeout_ms , 0 );
627+
630628 #else
629+ // Extended advertising not enabled.
630+
631631 uint8_t conn_mode = connectable ? BLE_GAP_CONN_MODE_UND : BLE_GAP_CONN_MODE_NON ;
632632 if (directed_to != NULL ) {
633633 conn_mode = BLE_GAP_CONN_MODE_DIR ;
@@ -654,8 +654,10 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
654654 return rc ;
655655 }
656656 }
657- rc = ble_gap_adv_start (own_addr_type , directed_to != NULL ? & peer : NULL ,
658- timeout_ms ,
657+ // If timeout_ms is BLE_HS_FOREVER, it means advertise forever. This is different than ble_gap_ext_adv_start().
658+ rc = ble_gap_adv_start (own_addr_type ,
659+ directed_to != NULL ? & peer : NULL ,
660+ timeout_ms == 0 ? BLE_HS_FOREVER : timeout_ms ,
659661 & adv_params ,
660662 _advertising_event , self );
661663 #endif
@@ -739,7 +741,7 @@ bool common_hal_bleio_adapter_get_advertising(bleio_adapter_obj_t *self) {
739741bool common_hal_bleio_adapter_get_connected (bleio_adapter_obj_t * self ) {
740742 for (size_t i = 0 ; i < BLEIO_TOTAL_CONNECTION_COUNT ; i ++ ) {
741743 bleio_connection_internal_t * connection = & bleio_connections [i ];
742- if (connection -> conn_handle != BLEIO_HANDLE_INVALID && connection -> mtu != 0 ) {
744+ if (connection -> conn_handle != BLEIO_HANDLE_INVALID ) {
743745 return true;
744746 }
745747 }
@@ -754,7 +756,7 @@ mp_obj_t common_hal_bleio_adapter_get_connections(bleio_adapter_obj_t *self) {
754756 mp_obj_t items [BLEIO_TOTAL_CONNECTION_COUNT ];
755757 for (size_t i = 0 ; i < BLEIO_TOTAL_CONNECTION_COUNT ; i ++ ) {
756758 bleio_connection_internal_t * connection = & bleio_connections [i ];
757- if (connection -> conn_handle != BLEIO_HANDLE_INVALID && connection -> mtu != 0 ) {
759+ if (connection -> conn_handle != BLEIO_HANDLE_INVALID ) {
758760 if (connection -> connection_obj == mp_const_none ) {
759761 connection -> connection_obj = bleio_connection_new_from_internal (connection );
760762 }
@@ -818,9 +820,7 @@ void bleio_adapter_gc_collect(bleio_adapter_obj_t *adapter) {
818820
819821void bleio_adapter_reset (bleio_adapter_obj_t * adapter ) {
820822 common_hal_bleio_adapter_stop_scan (adapter );
821- if (common_hal_bleio_adapter_get_advertising (adapter )) {
822- common_hal_bleio_adapter_stop_advertising (adapter );
823- }
823+ common_hal_bleio_adapter_stop_advertising (adapter );
824824
825825 adapter -> connection_objs = NULL ;
826826 for (size_t i = 0 ; i < BLEIO_TOTAL_CONNECTION_COUNT ; i ++ ) {
0 commit comments