Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions tools/auracast_sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/

#include "bt_le_scan.h"
#include "bt_pa_sync.h"
#include "bt_tools.h"

typedef struct {
Expand All @@ -36,18 +39,88 @@ static void usage(void)
}
}

static void on_scan_result(bt_scanner_t* scanner, ble_scan_result_t* result)
{
bt_status_t status;
bt_pa_sync_info_t* info;

if (g_auracast_sink->scanner != scanner)
return;

info = malloc(sizeof(bt_pa_sync_info_t));
if (info == NULL)
return;

status = bt_pa_sync_parse_adv_data(info, result);
if (status != BT_STATUS_SUCCESS)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Free the info when return error?

return;
}

static void on_scan_status(bt_scanner_t* scanner, uint8_t status)
{
PRINT("%s, status = %d", __func__, status);
if (g_auracast_sink->scanner != scanner)
return;

if (status != BT_STATUS_SUCCESS)
g_auracast_sink->scanner = NULL;
}

static void on_scan_stopped(bt_scanner_t* scanner)
{
PRINT("%s", __func__);
if (g_auracast_sink->scanner != scanner)
return;

g_auracast_sink->scanner = NULL;
}

static const scanner_callbacks_t scanner_cbs = {
.size = sizeof(scanner_cbs),
.on_scan_result = on_scan_result,
.on_scan_start_status = on_scan_status,
.on_scan_stopped = on_scan_stopped,
};

static const ble_scan_settings_t default_scan_settings = {
.scan_mode = BT_SCAN_MODE_LOW_LATENCY,
.legacy = false,
.scan_type = BT_LE_SCAN_TYPE_PASSIVE,
.scan_phy = BT_LE_1M_PHY,
.policy.policy = 0, /**< Unfiltered */
};

int scan_cmd(void* handle, int argc, char* argv[])
{
ble_scan_settings_t settings;

if (g_auracast_sink->scanner) {
PRINT("Already scanning");
return CMD_USAGE_FAULT;
}

memcpy(&settings, &default_scan_settings, sizeof(settings));

g_auracast_sink->scanner = bt_le_start_scan_settings(handle, &settings, &scanner_cbs);
if (g_auracast_sink->scanner == NULL)
return CMD_ERROR;

return CMD_OK;
}

int auracast_sink_command_init(void* handle)
{
g_auracast_sink = zalloc(sizeof(bttool_auracast_sink_t));
if (!g_auracast_sink)
return CMD_ERROR;

return CMD_OK;
}

void auracast_sink_command_uninit(void* handle)
{
free(g_auracast_sink);
g_auracast_sink = NULL;
}

int auracast_sink_command_exec(void* handle, int argc, char* argv[])
Expand Down