SDK-3.7.0: Set scan_mode = BTM_BLE_SCAN_MODE_PASSIVE has no effect

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
AxLi_1746341
Level 7
Level 7
10 comments on KBA 5 comments on KBA First comment on KBA

Hi,

To test BTM_BLE_SCAN_MODE_PASSIVE and BTM_BLE_SCAN_MODE_ACTIVE:

I set

.scan_mode = BTM_BLE_SCAN_MODE_PASSIVE;

I expect .scan_mode = BTM_BLE_SCAN_MODE_PASSIVE should not receive BTM_BLE_EVT_SCAN_RSP data.

But still receive data with BTM_BLE_EVT_SCAN_RSP (p_scan_result->ble_evt_type == BTM_BLE_EVT_SCAN_RSP).

Note, I remember it was working in SDK-3.5.x.

kausik

SDK-3.7.0-7 is not yet release, so I cannot test it. Maybe your team should test this issue.

[The test_active_passive_switch() call implement is wrong in my previous post, so I just remove it and re-post.]

0 Likes
36 Replies
AxLi_1746341
Level 7
Level 7
10 comments on KBA 5 comments on KBA First comment on KBA

What is the correct steps to switch ACTIVE/PASSIVE scan mode at run time?

Should I stop scanning before changing scan_mode setting?

wiced_bt_dev_status_t wiced_bt_ble_observe (wiced_bool_t start, uint8_t duration, wiced_bt_ble_scan_result_cback_t *p_scan_result_cback);

I'm wondering if set WICED_FALSE as first parameter of wiced_bt_ble_observe() means stop.

For wiced_bt_ble_scan() I seem don't find the API to stop it.

AxLi_1746341
Level 7
Level 7
10 comments on KBA 5 comments on KBA First comment on KBA

axel.lin wrote:

kausik

SDK-3.7.0-7 is not yet release, so I cannot test it. Maybe your team should test this issue.

[The test_active_passive_switch() call implement is wrong in my previous post, so I just remove it and re-post.]

kausik

Now I can confirm that SDK-3.7.0-7 has the same issue.

Even I set .scan_mode = BTM_BLE_SCAN_MODE_PASSIVE I still got BTM_BLE_EVT_SCAN_RSP type data.

0 Likes

axel.lin wrote:

axel.lin wrote:

kausik

SDK-3.7.0-7 is not yet release, so I cannot test it. Maybe your team should test this issue.

[The test_active_passive_switch() call implement is wrong in my previous post, so I just remove it and re-post.]

kausik

Now I can confirm that SDK-3.7.0-7 has the same issue.

Even I set .scan_mode = BTM_BLE_SCAN_MODE_PASSIVE I still got BTM_BLE_EVT_SCAN_RSP type data.

kausikjaeyoungjakewtorres

Just for your reference:

I found this issue only happens when using wiced_bt_ble_observe() but does not happen if using wiced_bt_ble_scan().

Hope this is helpful for debugging and fixing the issue.

0 Likes

Hello Axel,

This was discussed internally a while back - I will dig up the thread and respond tomorrow.

regards

/kausik

kausik wrote:

Hello Axel,

This was discussed internally a while back - I will dig up the thread and respond tomorrow.

Hi kausik,

Thanks.

Please also let me know what is the correct steps to switch scan_mode.

I have read the BT/BLE related APIs in the header files.

However, all the example code includes in the sdk seems assume the scan_mode is set before init BT stack.

It's not clear to me if it's ok to run-time switching scan_mode.

i.e.

Is it necessary to stop/restart scan after switching scan_mode?

Is it fine to set scan_mode and/or calling wiced_bt_ble_observe/wiced_bt_ble_scan at application thread

even the device is scanning?

A similar question is for run-time setting BLE broadcast payload.

I known the wiced_bt_start_advertisements() API, but I don't know if it's fine to call it at run-time

at my application thread especially when my device is doing scan. 

0 Likes

Hi Alex

Below are your answers

1> To stop scan you should pass BTM_BLE_SCAN_TYPE_NONE as the first paramter for the api wiced_bt_ble_scan , i think we will document the usage in wiced_bt_ble.h

2> At run time to switch between Active/passive scan , you need to first stop the scan , change the settings of the scan mode and then call the scan

below is the test snippet

extern wiced_bt_cfg_settings_t wiced_bt_cfg_settings;

wiced_result_t restful_smart_passive_scan()

{

wiced_bt_cfg_settings.ble_scan_cfg.scan_mode = BTM_BLE_SCAN_MODE_PASSIVE;

    wiced_bt_ble_scan( BTM_BLE_SCAN_TYPE_HIGH_DUTY, WICED_TRUE, scan_result_callback );

    return WICED_SUCCESS;

}

wiced_result_t restful_smart_active_scan( wiced_http_response_stream_t* stream )

{

wiced_bt_cfg_settings.ble_scan_cfg.scan_mode = BTM_BLE_SCAN_MODE_ACTIVE;

    wiced_bt_ble_scan( BTM_BLE_SCAN_TYPE_HIGH_DUTY, WICED_TRUE, scan_result_callback );

                                                                                                                        

    return WICED_SUCCESS;

}

3> when you use the above implementation you can see that only active scan will respond with scan result and not the passive scan

static void scan_result_callback( wiced_bt_ble_scan_results_t *result, uint8_t *data )

{

  printf("\n recvd result type is = %d\n" , result->ble_evt_type);

..

.

}

4> wiced_bt_ble_observe : is an api that is used to scan beacons adv and scan mode switch may not have any effect, I shall test it and let you know

5> You can run Scan and ADV at the same time , kindly go through the below post which i had replied earlier may be this could be helpful

3.7.0 BLE: Simultaneous Central / Peripheral?

Sequence for simultaneous BLE Central/Peripheral

  1. 1> Init the BT stack with a management callback

    /* Register call back and configuration with stack */wiced_bt_stack_init( hello_sensor_management_callback ,&wiced_bt_cfg_settings, wiced_bt_cfg_buf_pools );

  1. 2> In the management callback on receiving BTM_ENABLED, I register for GATT  and then start adv , and then start scan

static wiced_result_t hello_sensor_management_callback( wiced_bt_management_evt_t event,wiced_bt_management_evt_data_t *p_event_data )

{

WPRINT_BT_APP_INFO(("hello_sensor_management_callback: %x\n", event ));

    switch( event )

    {

/* Bluetooth  stack enabled */

  case BTM_ENABLED_EVT:

  // Register for GATT callback

  // Start ADV

  // Start Scan

prejith wrote:

5> You can run Scan and ADV at the same time , kindly go through the below post which i had replied earlier may be this could be helpful

3.7.0 BLE: Simultaneous Central / Peripheral?

Sequence for simultaneous BLE Central/Peripheral

 

  1. 1> Init the BT stack with a management callback

    /* Register call back and configuration with stack */wiced_bt_stack_init( hello_sensor_management_callback ,&wiced_bt_cfg_settings, wiced_bt_cfg_buf_pools );

  1. 2> In the management callback on receiving BTM_ENABLED, I register for GATT  and then start adv , and then start scan

static wiced_result_t hello_sensor_management_callback( wiced_bt_management_evt_t event,wiced_bt_management_evt_data_t *p_event_data )

{

WPRINT_BT_APP_INFO(("hello_sensor_management_callback: %x\n", event ));

    switch( event )

    {

/* Bluetooth  stack enabled */

  case BTM_ENABLED_EVT:

  // Register for GATT callback

  // Start ADV

  // Start Scan

Can I call start ADV / Start Scan at run-time in application thread rather than int the callback(e.g. hello_sensor_management_callback). My point is to run-time start/stop ADV/Scan, I'm not able to put the code in the callback you mentioned, it's in application's logic.

0 Likes

Hi Alex

you should be able to put it any where , only pre-requisite is start scan  or ADV only after you have received BTM_ENABLED_EVT , infact the callback is implemented in application

Regarding your issue on using observe ? : Can you let me know to swich between Active/Passive if you can use wiced_bt_ble_scan instead of observe ?

Regards

Prejith

0 Likes

prejith wrote:

Hi Alex

you should be able to put it any where , only pre-requisite is start scan  or ADV only after you have received BTM_ENABLED_EVT , infact the callback is implemented in application

Regarding your issue on using observe ? : Can you let me know to swich between Active/Passive if you can use wiced_bt_ble_scan instead of observe ?

Regards

Prejith

The problem of wiced_bt_ble_scan() is it cannot scan non-connectable devices. e.g. beacons/tags.

So we need to use observe API.

(honestly, other BLE stacks have no problem to support scanning non-connectable devices and also support active/passive scan switch. I think it should be supported by WICED sdk.)

Hi Axel


I would like to look at your logs on 3.7.07 with the below simple changes 
(since the test
which you are trying is independent on platform you can run restful_smart_server app on BCM4343W instead of 43438 )


Below are the changes you should make ,

1> Change the wrapper of restful_smart_passive_scan

2> put a print on the restful_smart_scan_result_callback to print the ble_evt_type

3> build the app and execute the the curl command  curl -v -X GET http://192.168.0.184/gap/nodes?passive=1

wiced_result_t restful_smart_passive_scan( wiced_http_response_stream_t* stream )

{

    current_stream    = stream;

    scan_result_count = 0;

     wiced_bt_cfg_settings.ble_scan_cfg.scan_mode = BTM_BLE_SCAN_MODE_PASSIVE;

    rest_smart_response_write_status_code( current_stream, REST_SMART_STATUS_200 );

    rest_smart_response_write_node_array_start( current_stream );

     wiced_bt_ble_observe(WICED_TRUE,60,restful_smart_scan_result_callback)

     return WICED_SUCCESS;

}

static void restful_smart_scan_result_callback( wiced_bt_ble_scan_results_t *result, uint8_t *data )

{

   printf("\n recvd result type is = %d\n" , result->ble_evt_type);

XX

XX

}



Regards

Prejith

0 Likes
Anonymous
Not applicable

Hello Axel Lin,

As pert of testing we have seen in observe mode "Type:4" events which is related to SCAN. We have reproduced the issue and discussing internally for a FIX. Following is the UART debug log

[BtReader] 404040406666,-92,RAW(16) 0201060909496F542042756C62020A00

#type=4

[BtReader] 404040406666,-91,RAW(16) 0201060909496F542042756C62020A00

#type=0

[BtReader] 404040406666,-91,RAW(16) 0201060909496F542042756C62020A00

#type=4

[BtReader] 404040406666,-92,RAW(16) 0201060909496F542042756C62020A00

#type=0

[BtReader] 404040406666,-91,RAW(16) 0201060909496F542042756C62020A00

#type=0

[BtReader] 404040406666,-96,RAW(16) 0201060909496F542042756C62020A00

#type=4

I will let you know once we got the fix.

-Ramesh Mylavarapu

rash wrote:

Hello Axel Lin,

As pert of testing we have seen in observe mode "Type:4" events which is related to SCAN. We have reproduced the issue and discussing internally for a FIX. Following is the UART debug log

I will let you know once we got the fix.

-Ramesh Mylavarapu

prejithrash

Okay, and thank you.

0 Likes
Anonymous
Not applicable

Hello axel.lin_1746341,

As a reply to my previous response, we have checked this issue and found the bug. We have fixed it and we will consolidate it in the next SDK release.

-Ramesh Mylavarapu

0 Likes

rash wrote:

Hello Axel Lin,

As a reply to my previous response, we have checked this issue and found the bug. We have fixed it and we will consolidate it in the next SDK release.

-Ramesh Mylavarapu

Great!

I'm waiting for next SDK release (for3.7.x serial).

Do you know when will the SDK available?

Axel

0 Likes
Anonymous
Not applicable

It will be as early as possible. We couldn't give any time line Axel Lin.

0 Likes

Hi mifo​,

Do you have plan to release sdk update in the near future?

If yes, I can wait if it don't take too long.

If not, is there any way to deliver the BLE library fix?

It does not make sense to keep people waiting as you already fixed the issue.

0 Likes

axel.lin_1746341 wrote:

Hi mifo,

Do you have plan to release sdk update in the near future?

If yes, I can wait if it don't take too long.

If not, is there any way to deliver the BLE library fix?

It does not make sense to keep people waiting as you already fixed the issue.

mifo​,

I wait a week but don't get your response.

The issue is fixed 3 weeks ago, but I have no way to get the fix?

Any one can help?

0 Likes

axel.lin_1746341

I spoke with one of the SW managers and he said that he will work with rash​ and try to get the fix out to you sometime next week.

Thanks for your patience.

0 Likes

mifo wrote:

axel.lin_1746341

I spoke with one of the SW managers and he said that he will work with rash and try to get the fix out to you sometime next week.

Thanks for your patience.

Thanks for your support.

Axel

0 Likes

mifo wrote:

axel.lin_1746341

I spoke with one of the SW managers and he said that he will work with rash and try to get the fix out to you sometime next week.

Thanks for your patience.

Hi rash​,

Any update?

I'm going to release a firmware update to my customers this week.

I'd like to include this bug fix if possible.

0 Likes

He's in the process of testing the patch provided and will post once tested.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello axel.lin_1746341

As per the request we have fixed the issue. I am attaching the libraries which you need to import into your SDK and use. For your reference you can check the following logs

pastedImage_1.png

If you need more info please let me know.

Best Regards,

Ramesh Mylavarapu

Hi rash​,

I just test the updated BTE library.

I got below messages immediately once I switching BTM_BLE_SCAN_MODE_PASSIVE/BTM_BLE_SCAN_MODE_ACTIVE at run-time:

[13:32:02:652] 00:00:50.051248 GKI_exception(): Task State Table␍␍␊

[13:32:02:652] 00:00:50.056248 GKI_exception 65524 getbuf: out of buffers␍␍␊

below call stuck:

result = wiced_bt_ble_observe(WICED_FALSE, 30, my_scan_results_cb);

What I does is:

1. stop scan (wiced_bt_ble_observe(WICED_FALSE,...)  << hangup here

2. modify setting

3. start scan wiced_bt_ble_observe(WICED_TRUE,...)

0 Likes

axel.lin_1746341 wrote:

Hi rash,

I just test the updated BTE library.

I got below messages immediately once I switching BTM_BLE_SCAN_MODE_PASSIVE/BTM_BLE_SCAN_MODE_ACTIVE at run-time:

[13:32:02:652] 00:00:50.051248 GKI_exception(): Task State Table␍␍␊

[13:32:02:652] 00:00:50.056248 GKI_exception 65524 getbuf: out of buffers␍␍␊

below call stuck:

result = wiced_bt_ble_observe(WICED_FALSE, 30, my_scan_results_cb);

What I does is:

1. stop scan (wiced_bt_ble_observe(WICED_FALSE,...)  << hangup here

2. modify setting

3. start scan wiced_bt_ble_observe(WICED_TRUE,...)

rash

Can you let me know if you can reproduce this or is there any other information I need to provide.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello axel.lin_1746341

As part of the testing I couldn't able to reproduce the issue. Please check the attached code which I used to reproduce the issue. I couldn't find any hang up issue which you have mentioned. Please let me know if I need to change anything in the firmware.

Your testing code does not run-time switching scan mode at all.

e.g.

1) start scan using ACTIVE mode

    wiced_bt_cfg_settings.ble_scan_cfg.scan_mode = BTM_BLE_SCAN_MODE_ACTIVE;

    wiced_bt_ble_observe( WICED_TRUE, 30, ble_scan_results_cb );

2) stop scan

    wiced_bt_ble_observe( WICED_FALSE, 30, ble_scan_results_cb );

3) re-start scan using PASSIVE mode

    wiced_bt_cfg_settings.ble_scan_cfg.scan_mode = BTM_BLE_SCAN_MODE_PASSIVE;

    wiced_bt_ble_observe( WICED_TRUE, 30, ble_scan_results_cb );

run-time executing 1) 2) 3) to switch ACTIVE/PASSIVE modes.

I think you can change start_ble_scan() function to take a mode parameter.

Then in your main application thread, after wiced_bt_stack_init() is done:

// below code will do testing switching mode multiple times.

for (i = 0; i < 10; i ++) {

        wiced_rtos_delay_milliseconds(5000);

        start_ble_scan(BTM_BLE_SCAN_MODE_ACTIVE);

        wiced_rtos_delay_milliseconds(5000);

        start_ble_scan(BTM_BLE_SCAN_MODE_PASSIVE);

}

0 Likes

Hi rash

I had sent you the modified code to show the issue.

In FreeRTOS build, it just hang at the second time calling wiced_bt_ble_observe(WICED_FALSE,...)

In ThreadX build, the second time calling wiced_bt_ble_observe(WICED_FALSE,...) return error code 8036.

You should be able to reproduce such issue with the code I sent you yesterday.

Let me know if any progress or any other things I need to provide.

Thanks,

Axel

0 Likes
Anonymous
Not applicable

I will test and get back to you Axel Lin.

0 Likes

Any update? Can you reproduce this issue?

0 Likes
Anonymous
Not applicable

I have a related problem.  I use wiced_bt_ble_observe and WICED causes the radio to transmit SCAN_REQ when certain beacons are detected in the environment.  The beacons then send SCAN_RSP.  It seems like observe should be completely passive.

0 Likes
Anonymous
Not applicable

Hello stevef

Please use the patch which we have provided in the previous interactions. When coming to observe, it will work as by default as Passive scan and if scan settings is changed to Active then it will send scan responses.

rash wrote:

I will test and get back to you Axel Lin.

Any progress?

0 Likes

rash wrote:

I will test and get back to you Axel Lin.

rash

How is your testing result?

0 Likes

rash wrote:

I will test and get back to you Axel Lin.

You never come back so the issue is still there.

In case you might already forgot what is the issue:

I just test the updated BTE library.

I got below messages immediately once I switching BTM_BLE_SCAN_MODE_PASSIVE/BTM_BLE_SCAN_MODE_ACTIVE at run-time:

[13:32:02:652] 00:00:50.051248 GKI_exception(): Task State Table␍␍␊

[13:32:02:652] 00:00:50.056248 GKI_exception 65524 getbuf: out of buffers␍␍␊

below call stuck:

result = wiced_bt_ble_observe(WICED_FALSE, 30, my_scan_results_cb);

What I does is:

1. stop scan (wiced_bt_ble_observe(WICED_FALSE,...)  << hangup here

2. modify setting

3. start scan wiced_bt_ble_observe(WICED_TRUE,...)

0 Likes

rash wrote:

Hello Axel Lin,

As a reply to my previous response, we have checked this issue and found the bug. We have fixed it and we will consolidate it in the next SDK release.

-Ramesh Mylavarapu

The same issue comes back to the latest sdk.

Maybe below change missed merging your fix.

* [all BT/WiFi combo] Upgraded Bluetooth host BTEWICED stack running on combo chips

Can you apply the fix to latest sdk?

Thanks.

0 Likes
Anonymous
Not applicable

For my configuration, bluetooth_low_energy.ThreadX.NetX_Duo.ARM_CM4.release.a was being linked into the build.  I copied and renamed BTE_low_energy.ThreadX.NetX_Duo.ARM_CM4.release.a from the patch (BTE_ changed to bluetooth_).  I recompiled and tested.

It appears the patch has resolved the problem with wiced_bt_ble_observe unexpectedly sending SCAN_REQ packets.

I am still testing.  Prior to the patch, I noticed that when scannable beacons were in the environment (and SCAN_REQ/SCAN_RSP activity), the CPU would have a hard fault exception one or two times per day.  I need to let it run for a few days to be sure it is stable.  At the moment it looks good!

0 Likes