lea-manager: rename blefastpair to lea_manager [1/2]
PD#SWPL-196827
Problem:
The ble fast pair is confused with google fast pair
Solution:
Rename blefastpair to lea_manager.
Verify:
AD401
Change-Id: I2686a5c9e1666b263f759b77060f239e0633c80b
Signed-off-by: ye.he <ye.he@amlogic.com>
diff --git a/ble-fast-pair/ble_audio_bis_sink_with_assistant.c b/ble-fast-pair/ble_audio_bis_sink_with_assistant.c
deleted file mode 100644
index b312750..0000000
--- a/ble-fast-pair/ble_audio_bis_sink_with_assistant.c
+++ /dev/null
@@ -1,232 +0,0 @@
-// SPDX-License-Identifier: (GPL-2.0-only OR MIT)
-/*
- * Copyright (C) 2024 Amlogic, Inc. All rights reserved
- */
-
-#include <glib.h>
-#include <stdio.h>
-#include <signal.h>
-#include "adapter.h"
-#include "device.h"
-#include "logger.h"
-#include "agent.h"
-#include "application.h"
-#include "advertisement.h"
-#include "utility.h"
-#include "parser.h"
-
-#include "ble_fast_pair.h"
-
-#define TAG "BIS-SINK-BA"
-#define ADV_NAME_PREFIX "BIS-SINK-BA-"
-#define AUDIO_STREAM_CONTROL_SERVICE_UUID "0000184e-0000-1000-8000-00805f9b34fb"
-#define BCAST_AUDIO_SCAN_SERVICE_UUID "0000184f-0000-1000-8000-00805f9b34fb"
-#define PUBLISHED_AUDIO_CAP_SERVICE_UUID "00001850-0000-1000-8000-00805f9b34fb"
-
-static GMainLoop *loop = NULL;
-static Adapter *default_adapter = NULL;
-static Advertisement *advertisement = NULL;
-static Agent *agent = NULL;
-static Application *app = NULL;
-static gchar *adv_name;
-
-static void on_powered_state_changed(Adapter *adapter, gboolean state) {
- log_debug(TAG, "powered '%s' (%s)", state ? "on" : "off", binc_adapter_get_path(adapter));
-}
-
-static void on_central_state_changed(Adapter *adapter, Device *device) {
- char *deviceToString = binc_device_to_string(device);
- log_debug(TAG, deviceToString);
- g_free(deviceToString);
-
- log_debug(TAG, "remote BIS assistant %s is %s", binc_device_get_address(device), binc_device_get_connection_state_name(device));
- ConnectionState state = binc_device_get_connection_state(device);
- if (state == BINC_CONNECTED) {
- binc_adapter_stop_advertising(adapter, advertisement);
- } else if (state == BINC_DISCONNECTED){
- binc_adapter_start_advertising(adapter, advertisement);
- }
-}
-
-static const char *on_local_char_read(const Application *application, const char *address, const char *service_uuid,
- const char *char_uuid) {
- return BLUEZ_ERROR_REJECTED;
-}
-
-static const char *on_local_char_write(const Application *application, const char *address, const char *service_uuid,
- const char *char_uuid, GByteArray *byteArray) {
- return NULL;
-}
-
-static void on_local_char_start_notify(const Application *application, const char *service_uuid, const char *char_uuid) {
- log_debug(TAG, "on start notify");
-}
-
-static void on_local_char_stop_notify(const Application *application, const char *service_uuid, const char *char_uuid) {
- log_debug(TAG, "on stop notify");
-}
-
-static gboolean callback(gpointer data) {
-
- media_destroy();
-
- if (app != NULL) {
- binc_adapter_unregister_application(default_adapter, app);
- binc_application_free(app);
- app = NULL;
- }
-
- if (advertisement != NULL) {
- binc_adapter_stop_advertising(default_adapter, advertisement);
- binc_advertisement_free(advertisement);
- }
-
- if (default_adapter != NULL) {
- binc_adapter_free(default_adapter);
- default_adapter = NULL;
- }
-
- if (adv_name) {
- g_free(adv_name);
- adv_name = NULL;
- }
- g_main_loop_quit((GMainLoop *) data);
- return FALSE;
-}
-
-static void cleanup_handler(int signo) {
- if (signo == SIGINT) {
- log_error(TAG, "received SIGINT");
- callback(loop);
- }
-}
-
-static gboolean on_request_authorization(Device *device) {
- log_debug(TAG, "requesting authorization for '%s", binc_device_get_name(device));
- return TRUE;
-}
-
-static guint32 on_request_passkey(Device *device) {
- guint32 pass = 000000;
- log_debug(TAG, "requesting passkey for '%s", binc_device_get_name(device));
- log_debug(TAG, "Enter 6 digit pin code: ");
- int result = fscanf(stdin, "%d", &pass);
- if (result != 1) {
- log_error(TAG, "didn't read a pin code");
- } else {
- log_debug(TAG, "pass key:%d", pass);
- }
- return pass;
-}
-
-static void bcast_sync_state_change_cb(gboolean sync)
-{
- log_debug(TAG, "%s sync:%d", __func__, sync);
-}
-
-int ble_audio_bis_sink_with_assistant_go(void) {
- const gchar *local_address;
-
- log_enabled(TRUE);
- log_set_level(LOG_DEBUG);
- // log_set_filename("./ble_fast_pair_sink.txt", 1024 * 64, 5);
- // Get a DBus connection
- GDBusConnection *dbusConnection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
-
- // Setup handler for CTRL+C
- if (signal(SIGINT, cleanup_handler) == SIG_ERR)
- log_error(TAG, "can't catch SIGINT");
-
- // Setup mainloop
- loop = g_main_loop_new(NULL, FALSE);
-
- // Get the default default_adapter
- default_adapter = binc_adapter_get_default(dbusConnection);
-
- if (default_adapter != NULL) {
- local_address = binc_adapter_get_address(default_adapter);
-
- log_debug(TAG, "using default_adapter '%s', local_address: %s",
- binc_adapter_get_path(default_adapter), local_address);
-
- // Register an agent and set callbacks
- agent = binc_agent_create(default_adapter, "/org/bluez/BincAgent", DISPLAY_YES_NO);
- binc_agent_set_request_authorization_cb(agent, &on_request_authorization);
- binc_agent_set_request_passkey_cb(agent, &on_request_passkey);
-
- // Make sure the adapter is on
- binc_adapter_set_powered_state_cb(default_adapter, &on_powered_state_changed);
- if (!binc_adapter_get_powered_state(default_adapter)) {
- binc_adapter_power_on(default_adapter);
- }
-
- if (!media_setup(dbusConnection)) {
- log_debug(TAG, "media setup success");
- media_set_bcast_sync_state_cb(bcast_sync_state_change_cb);
- }
-
- GList *device_list = NULL;
- GList *iterator = NULL;
- Device *device = NULL;
-
- device_list = binc_adapter_get_devices(default_adapter);
- for (iterator = device_list; iterator != NULL; iterator = iterator->next) {
- device = (Device *)iterator->data;
- log_debug(TAG, "Device Name: %s\n", binc_device_get_name(device));
- log_debug(TAG, "Device Address: %s\n", binc_device_get_address(device));
- if (device) {
- binc_adapter_remove_device(default_adapter, device);
- }
- }
-
- // Setup remote central connection state callback
- binc_adapter_set_remote_central_cb(default_adapter, &on_central_state_changed);
-
- // Setup advertisement
- advertisement = binc_advertisement_create();
-
- GPtrArray *adv_service_uuids = g_ptr_array_new();
- g_ptr_array_add(adv_service_uuids, (gpointer)BCAST_AUDIO_SCAN_SERVICE_UUID);
- g_ptr_array_add(adv_service_uuids, (gpointer)PUBLISHED_AUDIO_CAP_SERVICE_UUID);
- const char *last_colon = strrchr(local_address, ':');
- const char *last_byte = last_colon + 1;
- char *second_last_colon = strrchr(local_address, ':');
- *second_last_colon = '\0';
- const char *second_last_byte = strrchr(local_address, ':') + 1;
- adv_name = g_strdup_printf("%s%s:%s", ADV_NAME_PREFIX, second_last_byte, last_byte);
- log_debug(TAG, "adv name: %s", adv_name);
-
- binc_advertisement_set_local_name(advertisement, adv_name);
- binc_advertisement_set_services(advertisement, adv_service_uuids);
- g_ptr_array_free(adv_service_uuids, TRUE);
-
-#if 1
- GByteArray *ascs_data_array = g_byte_array_new();
- // 0x00:Announcement Type
- // 0xFF,0x0F:Available sink contexts
- // 0x43,0x02:Available source context
- guint8 ascs_data[] = {0x00, 0xFF, 0x0F, 0x43, 0x02, 0x00};
- g_byte_array_append(ascs_data_array, ascs_data, sizeof(ascs_data));
- binc_advertisement_set_service_data(advertisement,
- AUDIO_STREAM_CONTROL_SERVICE_UUID, ascs_data_array);
- g_byte_array_free(ascs_data_array, TRUE);
-#endif
- binc_adapter_start_advertising(default_adapter, advertisement);
- } else {
- log_error(TAG, "No default_adapter found");
- }
-
- // Bail out after some time
- g_timeout_add_seconds(RUN_LOOP_TIMEOUT_SECONDS, callback, loop);
-
- // Start the mainloop
- g_main_loop_run(loop);
-
- // Disconnect from DBus
- g_dbus_connection_close_sync(dbusConnection, NULL, NULL);
- g_object_unref(dbusConnection);
-
- // Clean up mainloop
- g_main_loop_unref(loop);
- return 0;
-}
diff --git a/ble-fast-pair/ble_audio_cis_sink.c b/ble-fast-pair/ble_audio_cis_sink.c
deleted file mode 100644
index 01d5f25..0000000
--- a/ble-fast-pair/ble_audio_cis_sink.c
+++ /dev/null
@@ -1,250 +0,0 @@
-// SPDX-License-Identifier: (GPL-2.0-only OR MIT)
-/*
- * Copyright (C) 2024 Amlogic, Inc. All rights reserved
- */
-
-#include <glib.h>
-#include <stdio.h>
-#include <signal.h>
-#include "adapter.h"
-#include "device.h"
-#include "logger.h"
-#include "agent.h"
-#include "application.h"
-#include "advertisement.h"
-#include "utility.h"
-#include "parser.h"
-#include "ble_fast_pair.h"
-
-#define TAG "CIS-SINK"
-#define ADV_NAME_PREFIX "CIS-SINK-"
-
-#define AUDIO_STREAM_CONTROL_SERVICE_UUID "0000184e-0000-1000-8000-00805f9b34fb"
-#define COMMON_AUDIO_SERVICE_UUID "00001853-0000-1000-8000-00805f9b34fb"
-#define COORDINATED_SET_ID_SERVICE_UUID "00001846-0000-1000-8000-00805f9b34fb"
-// characteristic of CSIS
-#define SET_ID_RESOLVING_KEY_CHAR_UUID "00002b84-0000-1000-8000-00805f9b34fb"
-#define COORDINATED_SET_SIZE_CHAR_UUID "00002b85-0000-1000-8000-00805f9b34fb"
-#define SET_MEMBER_LOCK_CHAR_UUID "00002b86-0000-1000-8000-00805f9b34fb"
-#define SET_MEMBER_RANK_CHAR_UUID "00002b87-0000-1000-8000-00805f9b34fb"
-
-static GMainLoop *loop = NULL;
-static Adapter *default_adapter = NULL;
-static Advertisement *advertisement = NULL;
-static Agent *agent = NULL;
-static Application *app = NULL;
-static gchar *adv_name;
-
-static void on_powered_state_changed(Adapter *adapter, gboolean state) {
- log_debug(TAG, "powered '%s' (%s)", state ? "on" : "off", binc_adapter_get_path(adapter));
-}
-
-static void on_central_state_changed(Adapter *adapter, Device *device) {
- char *deviceToString = binc_device_to_string(device);
- log_debug(TAG, deviceToString);
- g_free(deviceToString);
-
- log_debug(TAG, "remote central %s is %s", binc_device_get_address(device), binc_device_get_connection_state_name(device));
- ConnectionState state = binc_device_get_connection_state(device);
- if (state == BINC_CONNECTED) {
- binc_adapter_stop_advertising(adapter, advertisement);
- } else if (state == BINC_DISCONNECTED){
- binc_adapter_start_advertising(adapter, advertisement);
- }
-}
-
-static const char *on_local_char_read(const Application *application, const char *address, const char *service_uuid,
- const char *char_uuid) {
- if (g_str_equal(service_uuid, COORDINATED_SET_ID_SERVICE_UUID) && g_str_equal(char_uuid, SET_ID_RESOLVING_KEY_CHAR_UUID)) {
- const guint8 bytes[17] = {0};
- GByteArray *byteArray = g_byte_array_sized_new(sizeof(bytes));
- g_byte_array_append(byteArray, bytes, sizeof(bytes));
- binc_application_set_char_value(app, service_uuid, char_uuid, byteArray);
- return NULL;
- }
-
- return BLUEZ_ERROR_REJECTED;
-}
-
-static const char *on_local_char_write(const Application *application, const char *address, const char *service_uuid,
- const char *char_uuid, GByteArray *byteArray) {
- return NULL;
-}
-
-static void on_local_char_start_notify(const Application *application, const char *service_uuid, const char *char_uuid) {
- log_debug(TAG, "on start notify");
-}
-
-static void on_local_char_stop_notify(const Application *application, const char *service_uuid, const char *char_uuid) {
- log_debug(TAG, "on stop notify");
-}
-
-static gboolean callback(gpointer data) {
- if (app != NULL) {
- binc_adapter_unregister_application(default_adapter, app);
- binc_application_free(app);
- app = NULL;
- }
-
- if (advertisement != NULL) {
- binc_adapter_stop_advertising(default_adapter, advertisement);
- binc_advertisement_free(advertisement);
- }
-
- if (default_adapter != NULL) {
- binc_adapter_free(default_adapter);
- default_adapter = NULL;
- }
-
- if (adv_name) {
- g_free(adv_name);
- adv_name = NULL;
- }
- g_main_loop_quit((GMainLoop *) data);
- return FALSE;
-}
-
-static void cleanup_handler(int signo) {
- if (signo == SIGINT) {
- log_error(TAG, "received SIGINT");
- callback(loop);
- }
-}
-
-static gboolean on_request_authorization(Device *device) {
- log_debug(TAG, "requesting authorization for '%s", binc_device_get_name(device));
- return TRUE;
-}
-
-static guint32 on_request_passkey(Device *device) {
- guint32 pass = 000000;
- log_debug(TAG, "requesting passkey for '%s", binc_device_get_name(device));
- log_debug(TAG, "Enter 6 digit pin code: ");
- int result = fscanf(stdin, "%d", &pass);
- if (result != 1) {
- log_error(TAG, "didn't read a pin code");
- } else {
- log_debug(TAG, "pass key:%d", pass);
- }
- return pass;
-}
-
-int ble_audio_cis_sink_go(void) {
- const gchar *local_address;
-
- log_enabled(TRUE);
- log_set_level(LOG_DEBUG);
- // log_set_filename("./ble_fast_pair_sink.txt", 1024 * 64, 5);
- // Get a DBus connection
- GDBusConnection *dbusConnection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
-
- // Setup handler for CTRL+C
- if (signal(SIGINT, cleanup_handler) == SIG_ERR)
- log_error(TAG, "can't catch SIGINT");
-
- // Setup mainloop
- loop = g_main_loop_new(NULL, FALSE);
-
- // Get the default default_adapter
- default_adapter = binc_adapter_get_default(dbusConnection);
-
- if (default_adapter != NULL) {
- local_address = binc_adapter_get_address(default_adapter);
-
- log_debug(TAG, "using default_adapter '%s', local_address: %s",
- binc_adapter_get_path(default_adapter), local_address);
-#if 0
- // Register an agent and set callbacks
- agent = binc_agent_create(default_adapter, "/org/bluez/BincAgent", DISPLAY_YES_NO);
- binc_agent_set_request_authorization_cb(agent, &on_request_authorization);
- binc_agent_set_request_passkey_cb(agent, &on_request_passkey);
-#endif
- // Make sure the adapter is on
- binc_adapter_set_powered_state_cb(default_adapter, &on_powered_state_changed);
- if (!binc_adapter_get_powered_state(default_adapter)) {
- binc_adapter_power_on(default_adapter);
- }
-
- GList *device_list = NULL;
- GList *iterator = NULL;
- Device *device = NULL;
-
- device_list = binc_adapter_get_devices(default_adapter);
- for (iterator = device_list; iterator != NULL; iterator = iterator->next) {
- device = (Device *)iterator->data;
- log_debug(TAG, "Device Name: %s\n", binc_device_get_name(device));
- log_debug(TAG, "Device Address: %s\n", binc_device_get_address(device));
- if (device) {
- binc_adapter_remove_device(default_adapter, device);
- }
- }
-
- // Setup remote central connection state callback
- binc_adapter_set_remote_central_cb(default_adapter, &on_central_state_changed);
-
-#if 1
- // Create an app with a service start
- app = binc_create_application(default_adapter);
- // add CAS as primary service without characteristics
- binc_application_add_service(app, COMMON_AUDIO_SERVICE_UUID);
- // add CSIS as primary service
- binc_application_add_service(app, COORDINATED_SET_ID_SERVICE_UUID);
- binc_application_add_characteristic(
- app,
- COORDINATED_SET_ID_SERVICE_UUID,
- SET_ID_RESOLVING_KEY_CHAR_UUID,
- GATT_CHR_PROP_READ | GATT_CHR_PROP_NOTIFY);
-
- // Set the callbacks for read/write
- binc_application_set_char_read_cb(app, &on_local_char_read);
- binc_application_set_char_write_cb(app, &on_local_char_write);
-
- // Register your app
- binc_adapter_register_application(default_adapter, app);
- // Create an app with a service end
-#endif
-
- // Setup advertisement
- advertisement = binc_advertisement_create();
-
- GPtrArray *adv_service_uuids = g_ptr_array_new();
- g_ptr_array_add(adv_service_uuids, (gpointer)AML_VENDOR_SERVICE_UUID);
- const char *last_colon = strrchr(local_address, ':');
- const char *last_byte = last_colon + 1;
- char *second_last_colon = strrchr(local_address, ':');
- *second_last_colon = '\0';
- const char *second_last_byte = strrchr(local_address, ':') + 1;
- adv_name = g_strdup_printf("%s%s:%s", ADV_NAME_PREFIX, second_last_byte, last_byte);
- log_debug(TAG, "adv name: %s", adv_name);
-
- binc_advertisement_set_local_name(advertisement, adv_name);
- binc_advertisement_set_services(advertisement, adv_service_uuids);
- g_ptr_array_free(adv_service_uuids, TRUE);
-
-#if 1
- GByteArray *ascs_data_array = g_byte_array_new();
- guint8 ascs_data[] = {0x00, 0xFF, 0x0F, 0x43, 0x02, 0x00};
- g_byte_array_append(ascs_data_array, ascs_data, sizeof(ascs_data));
- binc_advertisement_set_service_data(advertisement,
- AUDIO_STREAM_CONTROL_SERVICE_UUID, ascs_data_array);
- g_byte_array_free(ascs_data_array, TRUE);
-#endif
- binc_adapter_start_advertising(default_adapter, advertisement);
- } else {
- log_error(TAG, "No default_adapter found");
- }
-
- // Bail out after some time
- g_timeout_add_seconds(RUN_LOOP_TIMEOUT_SECONDS, callback, loop);
-
- // Start the mainloop
- g_main_loop_run(loop);
-
- // Disconnect from DBus
- g_dbus_connection_close_sync(dbusConnection, NULL, NULL);
- g_object_unref(dbusConnection);
-
- // Clean up mainloop
- g_main_loop_unref(loop);
- return 0;
-}
diff --git a/ble-fast-pair/ble_fast_pair.h b/ble-fast-pair/ble_fast_pair.h
deleted file mode 100644
index 608af82..0000000
--- a/ble-fast-pair/ble_fast_pair.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// SPDX-License-Identifier: (GPL-2.0-only OR MIT)
-/*
- * Copyright (C) 2024 Amlogic, Inc. All rights reserved
- */
-
-#ifndef BLE_FAST_PAIR_H
-#define BLE_FAST_PAIR_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <glib.h>
-#include <gio/gio.h>
-
-#define AML_VENDOR_SERVICE_UUID "0000fba0-0000-1000-8000-00805f9b34fb"
-
-#define RUN_LOOP_TIMEOUT_SECONDS (60 * 60 * 24) //24 Hours
-
-typedef void (*bcast_sync_state_cb_t)(gboolean);
-
-int ble_audio_bis_source_go(void);
-
-int ble_audio_bis_sink_go(void);
-
-int ble_audio_advertiser_go(void);
-
-int ble_audio_bis_sink_with_assistant_go(void);
-
-int ble_audio_cis_source_go(void);
-
-int ble_audio_cis_sink_go(void);
-
-int dbus_test_go(void);
-
-int media_setup(GDBusConnection *dbus_con);
-
-int media_destroy(void);
-
-int media_register_baa_endpoint(void);
-
-int media_register_bcaa_endpoint(void);
-
-void media_set_bcast_sync_state_cb(bcast_sync_state_cb_t cb);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //BLE_FAST_PAIR_H
diff --git a/ble-fast-pair/Makefile b/lea_manager/Makefile
similarity index 72%
rename from ble-fast-pair/Makefile
rename to lea_manager/Makefile
index b1cee57..145c3fc 100644
--- a/ble-fast-pair/Makefile
+++ b/lea_manager/Makefile
@@ -1,15 +1,15 @@
#
-# Makefile for aml ble fast pair
+# Makefile for le audio manager
#
#
# Define the source files
SOURCES = \
- ble_audio_advertiser.c \
- ble_audio_bis_sink.c \
- ble_fast_pair.c \
- dbus_test.c \
- bluez_media.c
+ lea_mgr_advertiser.c \
+ lea_mgr_scanner.c \
+ lea_manager.c \
+ lea_mgr_dbus_test.c \
+ lea_mgr_bluez_media.c
# Convert source files to object files
OBJ = $(SOURCES:.c=.o)
@@ -24,7 +24,7 @@
-I$(STAGING_DIR)/usr/include/libxml2
# Libraries to link against
-LIBS = -lbluetooth -lBinc -lgio-2.0 -ldbus-1 -lgobject-2.0 -lglib-2.0 -lm -lxml2
+LIBS = -lBinc -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lm -lxml2
# Compilation flags
CFLAGS = -Wall -Wextra $(INCLUDES) -fpermissive
@@ -32,7 +32,7 @@
# Linker flags
LDFLAGS = $(LIBS)
-TARGET = blefastpair
+TARGET = lea_manager
# Rules
all: $(TARGET)
@@ -48,6 +48,6 @@
clean:
rm -f $(OBJ) $(TARGET)
-install:
- cp blefastpair $(DESTDIR)/bin/blefastpair
+# install:
+# cp $(TARGET) $(DESTDIR)/bin/
diff --git a/ble-fast-pair/ble_fast_pair.c b/lea_manager/lea_manager.c
similarity index 60%
rename from ble-fast-pair/ble_fast_pair.c
rename to lea_manager/lea_manager.c
index d3f9bc2..86f74ad 100644
--- a/ble-fast-pair/ble_fast_pair.c
+++ b/lea_manager/lea_manager.c
@@ -6,21 +6,23 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include "ble_fast_pair.h"
+#include "lea_manager.h"
int main(int argc, char *argv[]) {
if (argc < 2) {
- fprintf(stderr, "Usage: %s <adver|scanner>\n", argv[0]);
+ fprintf(stderr, "Usage: %s <adver|scanner|test>\n", argv[0]);
return -1;
}
if (0 == strcmp(argv[1], "adver")) {
- ble_audio_advertiser_go();
+ lea_mgr_advertiser();
} else if (0 == strcmp(argv[1], "scanner")) {
- ble_audio_bis_sink_go();
+ lea_mgr_scanner();
+ } else if (0 == strcmp(argv[1], "test")) {
+ lea_mgr_dbus_test();
} else {
fprintf(stderr, "Unknown command: %s\n", argv[1]);
- fprintf(stderr, "Usage: %s <adver|scanner>\n", argv[0]);
+ fprintf(stderr, "Usage: %s <adver|scanner|test>\n", argv[0]);
return -1;
}
diff --git a/lea_manager/lea_manager.h b/lea_manager/lea_manager.h
new file mode 100644
index 0000000..995ffdc
--- /dev/null
+++ b/lea_manager/lea_manager.h
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: (GPL-2.0-only OR MIT)
+/*
+ * Copyright (C) 2024 Amlogic, Inc. All rights reserved
+ */
+
+#ifndef LEA_MANAGER_H
+#define LEA_MANAGER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#define AML_VENDOR_SERVICE_UUID "0000fba0-0000-1000-8000-00805f9b34fb"
+
+#define RUN_LOOP_TIMEOUT_SECONDS (60 * 60 * 24) //24 Hours
+
+typedef void (*bcast_sync_state_cb_t)(gboolean);
+
+int lea_mgr_bis_source(void);
+
+int lea_mgr_cis_source(void);
+
+int lea_mgr_advertiser(void);
+
+int lea_mgr_scanner(void);
+
+int lea_mgr_dbus_test(void);
+
+int lea_mgr_media_setup(GDBusConnection *dbus_con);
+
+int lea_mgr_media_destroy(void);
+
+int lea_mgr_media_register_baa_endpoint(void);
+
+int lea_mgr_media_register_bcaa_endpoint(void);
+
+void lea_mgr_media_set_bcast_sync_state_cb(bcast_sync_state_cb_t cb);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //LEA_MANAGER_H
diff --git a/ble-fast-pair/ble_audio_advertiser.c b/lea_manager/lea_mgr_advertiser.c
similarity index 88%
rename from ble-fast-pair/ble_audio_advertiser.c
rename to lea_manager/lea_mgr_advertiser.c
index 5d96fa3..523c87b 100644
--- a/ble-fast-pair/ble_audio_advertiser.c
+++ b/lea_manager/lea_mgr_advertiser.c
@@ -15,7 +15,7 @@
#include "utility.h"
#include "parser.h"
-#include "ble_fast_pair.h"
+#include "lea_manager.h"
#define TAG "ADVERTISER"
#define ADV_NAME_PREFIX "AML-LEA-"
@@ -57,16 +57,8 @@
static const char *on_local_char_read(__attribute__((unused)) const Application *application,
__attribute__((unused)) const char *address,
- const char *service_uuid,
- const char *char_uuid) {
- if (g_str_equal(service_uuid, COORDINATED_SET_ID_SERVICE_UUID) && g_str_equal(char_uuid, SET_ID_RESOLVING_KEY_CHAR_UUID)) {
- const guint8 bytes[17] = {0};
- GByteArray *byteArray = g_byte_array_sized_new(sizeof(bytes));
- g_byte_array_append(byteArray, bytes, sizeof(bytes));
- binc_application_set_char_value(app, service_uuid, char_uuid, byteArray);
- return NULL;
- }
-
+ __attribute__((unused)) const char *service_uuid,
+ __attribute__((unused)) const char *char_uuid) {
return BLUEZ_ERROR_REJECTED;
}
@@ -80,7 +72,7 @@
static gboolean callback(gpointer data) {
- media_destroy();
+ lea_mgr_media_destroy();
if (app != NULL) {
binc_adapter_unregister_application(default_adapter, app);
@@ -132,7 +124,7 @@
log_debug(TAG, "%s sync:%d", __func__, sync);
}
-int ble_audio_advertiser_go(void) {
+int lea_mgr_advertiser(void) {
const gchar *local_address;
log_enabled(TRUE);
@@ -147,7 +139,6 @@
else if (signal(SIGTERM, cleanup_handler) == SIG_ERR)
log_error(TAG, "can't catch SIGTERM");
-
// Setup mainloop
loop = g_main_loop_new(NULL, FALSE);
@@ -166,9 +157,9 @@
binc_adapter_power_on(default_adapter);
}
- if (!media_setup(dbusConnection)) {
+ if (!lea_mgr_media_setup(dbusConnection)) {
log_debug(TAG, "media setup success");
- media_set_bcast_sync_state_cb(bcast_sync_state_change_cb);
+ lea_mgr_media_set_bcast_sync_state_cb(bcast_sync_state_change_cb);
}
GList *device_list = NULL;
@@ -193,13 +184,6 @@
// add CAS as primary service without characteristics
binc_application_add_service(app, COMMON_AUDIO_SERVICE_UUID);
- // add CSIS as primary service
- binc_application_add_service(app, COORDINATED_SET_ID_SERVICE_UUID);
- binc_application_add_characteristic(
- app,
- COORDINATED_SET_ID_SERVICE_UUID,
- SET_ID_RESOLVING_KEY_CHAR_UUID,
- GATT_CHR_PROP_READ | GATT_CHR_PROP_NOTIFY);
// Set the callbacks for read/write
binc_application_set_char_read_cb(app, &on_local_char_read);
diff --git a/ble-fast-pair/ble_audio_bis_source.c b/lea_manager/lea_mgr_bis_source.c
similarity index 97%
rename from ble-fast-pair/ble_audio_bis_source.c
rename to lea_manager/lea_mgr_bis_source.c
index e7e4d0d..7c4fdd3 100644
--- a/ble-fast-pair/ble_audio_bis_source.c
+++ b/lea_manager/lea_mgr_bis_source.c
@@ -14,7 +14,7 @@
#include "advertisement.h"
#include "utility.h"
#include "parser.h"
-#include "ble_fast_pair.h"
+#include "lea_manager.h"
#define TAG "BIS-SOUR"
#define ADV_NAME_PREFIX "BIS-SOUR-"
@@ -54,7 +54,7 @@
}
}
-int ble_audio_bis_source_go(void) {
+int lea_mgr_bis_source(void) {
const gchar *local_address;
log_enabled(TRUE);
diff --git a/ble-fast-pair/bluez_media.c b/lea_manager/lea_mgr_bluez_media.c
similarity index 82%
rename from ble-fast-pair/bluez_media.c
rename to lea_manager/lea_mgr_bluez_media.c
index 4157711..25c241e 100644
--- a/ble-fast-pair/bluez_media.c
+++ b/lea_manager/lea_mgr_bluez_media.c
@@ -12,6 +12,7 @@
#include "logger.h"
#include "agent.h"
#include "parser.h"
+#include "lea_manager.h"
#define BLUEZ_BUS_NAME "org.bluez"
@@ -62,6 +63,7 @@
#define INTERFACE_DBUS_PROPERTIES "org.freedesktop.DBus.Properties"
#define SIGNAL_OBJECT_PROPERTIES_PROPERTIES_CHANGED "PropertiesChanged"
+#define DBUS_PROPERTY_METHOD_SET "Set"
#define DBUS_PROPERTY_METHOD_GET "Get"
#define DBUS_PROPERTY_METHOD_GET_ALL "GetAll"
#define DBUS_SIGNAL_PROPERTIES_CHANGED "PropertiesChanged"
@@ -77,6 +79,9 @@
#define MEDIA_TRANSPORT_SELECT_CALL_DELAY (100) /*unit: milliseconds*/
+#define CFG_FILE_NAME "/etc/lea_manager.conf"
+#define CFG_KEY_BCAST_AUDIO_CHL "bcast_audio_channel"
+
#define TAG "MEDIA"
typedef enum {
@@ -85,7 +90,16 @@
} BroadcastRole;
typedef enum {
+ BCAST_AUDIO_MONO_LEFT = 0,
+ BCAST_AUDIO_MONO_RIGHT,
+ BCAST_AUDIO_STEREO,
+} BroadcastAudioChannel;
+
+#define BROADCAST_BIS_MAX_NUM BCAST_AUDIO_STEREO
+
+typedef enum {
BCAST_TRANSPORT_STATE_IDLE = 0,
+ BCAST_TRANSPORT_STATE_PENDING,
BCAST_TRANSPORT_STATE_BROADCASTING,
BCAST_TRANSPORT_STATE_ACTIVE,
BCAST_TRANSPORT_STATE_MAX
@@ -193,28 +207,106 @@
guint iface_added;
guint iface_removed;
GPtrArray *supported_uuids;
+ GList *local_endpoints;
+ guint local_media_ep_if_reg_id;
MediaEndpointInterface *media_endpoint_interface;
- MediaTransportInterface *media_transport_interface;
- void (*sync_state_cb)(gboolean);
+ MediaTransportInterface *media_transport_interface[BROADCAST_BIS_MAX_NUM];
+ guint media_transport_num;
+ guint media_transport_source_id;
+ bcast_sync_state_cb_t sync_state_cb;
} MediaInterface;
static GDBusConnection *g_dbus_conn;
static MediaInterface *g_media_if;
-static GList *local_endpoints;
static BroadcastRole bcast_role;
-static guint local_media_ep_if_reg_id;
static guint8 bcast_source_codec_cap[] = {
0x03, 0x01, 0xff, 0x00, 0x02, 0x02, 0x03, 0x05, 0x04, 0x1a, 0x00, 0xf0, 0x00};
static guint8 bcast_sink_codec_cap[] = {
0x03, 0x01, 0xff, 0x00, 0x02, 0x02, 0x03, 0x05, 0x04, 0x1a, 0x00, 0xf0, 0x00};
+/*
+"idle": not streaming
+"pending": streaming but not acquired
+"broadcasting": streaming but not acquired, applicable only for transports created by a broadcast sink
+"active": streaming and acquired
+*/
const gchar *bcast_transport_state_str[BCAST_TRANSPORT_STATE_MAX] = {
"idle",
+ "pending",
"broadcasting",
"active"
};
+const gchar *bcast_audio_chl_str[] = {
+ "mono_left",
+ "mono_right",
+ "stereo"
+};
+
+static char *media_get_config_value(const char *file_path, const char *config_key) {
+ GError *error = NULL;
+ gchar *content = NULL;
+ gchar **lines = NULL;
+ gchar **tokens = NULL;
+ gchar *value = NULL;
+
+ if (!file_path || !config_key) {
+ log_error(TAG, "invalid param");
+ return NULL;
+ }
+
+ log_debug(TAG, "file_path:%s, key:%s", file_path, config_key);
+
+ if (!g_file_get_contents(file_path, &content, NULL, &error)) {
+ log_warn(TAG, "Failed to read file: %s", error->message);
+ g_clear_error(&error);
+ return NULL;
+ }
+
+ // Parse the content line by line
+ lines = g_strsplit(content, "\n", -1);
+
+ for (gchar **line = lines; *line != NULL; line++) {
+ if (g_str_has_prefix(*line, config_key)) {
+ tokens = g_strsplit(*line, "=", 2);
+ if (tokens[1] != NULL)
+ value = g_strdup(g_strstrip(tokens[1]));
+ g_strfreev(tokens);
+ break;
+ }
+ }
+
+ g_strfreev(lines);
+ g_free(content);
+
+ return value;
+}
+
+static BroadcastAudioChannel media_get_bcast_audio_channel(void) {
+ guint i;
+ char *value = NULL;
+ BroadcastAudioChannel channel = BCAST_AUDIO_STEREO;
+
+ value = media_get_config_value(CFG_FILE_NAME, CFG_KEY_BCAST_AUDIO_CHL);
+ if (!value) {
+ log_warn(TAG, "get key('%s') fail, use default config.", CFG_KEY_BCAST_AUDIO_CHL);
+ return BCAST_AUDIO_STEREO;
+ }
+
+ log_debug(TAG, "get key('%s') success, value:'%s'", CFG_KEY_BCAST_AUDIO_CHL, value);
+
+ for (i = 0;i < sizeof(bcast_audio_chl_str) / sizeof(bcast_audio_chl_str[0]);i++) {
+ if (g_str_equal(value, bcast_audio_chl_str[i])) {
+ channel = i;
+ break;
+ }
+ }
+
+ g_free(value);
+ return channel;
+}
+
static void media_endpoint_set_configuration(GDBusConnection *connection,
MediaEndpointInterface *media_ep_if)
{
@@ -364,19 +456,82 @@
return 0;
}
-static gboolean media_transport_select_cb (gpointer user_data)
-{
- MediaTransportInterface *media_transport_if = (MediaTransportInterface *)user_data;
+static void media_transport_set_links_property(
+ MediaTransportInterface *media_transport_if, const char *linked_path) {
+ GVariantBuilder *array_builder = g_variant_builder_new(G_VARIANT_TYPE("ao"));
+ g_variant_builder_add(array_builder, "o", linked_path);
- log_debug(TAG, "%s transport-state:'%s'", __func__, media_transport_if->state);
+ GError *error = NULL;
+ GVariant *result = g_dbus_connection_call_sync(
+ g_dbus_conn,
+ BLUEZ_BUS_NAME,
+ media_transport_if->path,
+ INTERFACE_DBUS_PROPERTIES,
+ DBUS_PROPERTY_METHOD_SET,
+ g_variant_new("(ssv)",
+ INTERFACE_MEDIA_TRANSPORT,
+ MEDIA_TRANSPORT_PROPERTY_LINKS,
+ g_variant_new("ao", array_builder)),
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
- if (g_str_equal(g_media_if->media_transport_interface->state,
- bcast_transport_state_str[BCAST_TRANSPORT_STATE_IDLE])) {
- media_transport_select(media_transport_if);
- return FALSE;
+ if (error) {
+ log_error(TAG, "Failed to set Links property: %s", error->message);
+ g_error_free(error);
+ } else {
+ log_debug(TAG, "Links property set successfully.");
}
- return TRUE; /* FALSE:stop period timer; TRUE:keep period timer. */
+ g_variant_builder_unref(array_builder);
+ if (result) g_variant_unref(result);
+}
+
+static gboolean media_transport_select_cb(gpointer user_data)
+{
+ BroadcastAudioChannel audio_channel;
+ MediaInterface *media_interface = (MediaInterface *)user_data;
+
+ audio_channel = media_get_bcast_audio_channel();
+
+ log_debug(TAG, "%s audio_channel:'%s', transport_num:%d",
+ __func__, bcast_audio_chl_str[audio_channel], media_interface->media_transport_num);
+
+ switch (audio_channel) {
+ case BCAST_AUDIO_MONO_LEFT:
+ case BCAST_AUDIO_MONO_RIGHT:
+ if (media_interface->media_transport_interface[audio_channel]) {
+ if (g_str_equal(media_interface->media_transport_interface[audio_channel]->state,
+ bcast_transport_state_str[BCAST_TRANSPORT_STATE_IDLE])) {
+ media_transport_select(media_interface->media_transport_interface[audio_channel]);
+ }
+ }
+ break;
+ case BCAST_AUDIO_STEREO:
+ default:
+ if (media_interface->media_transport_num == BROADCAST_BIS_MAX_NUM) {
+ media_transport_set_links_property(media_interface->media_transport_interface[0],
+ media_interface->media_transport_interface[1]->path);
+ }
+
+ for (guint i = 0;i < BROADCAST_BIS_MAX_NUM;i++) {
+ if (media_interface->media_transport_interface[i]) {
+ log_debug(TAG, "transport[%d]:'%s', state:'%s'",
+ i,
+ media_interface->media_transport_interface[i]->path,
+ media_interface->media_transport_interface[i]->state);
+ if (g_str_equal(media_interface->media_transport_interface[i]->state,
+ bcast_transport_state_str[BCAST_TRANSPORT_STATE_IDLE])) {
+ media_transport_select(media_interface->media_transport_interface[i]);
+ }
+ }
+ }
+ break;
+ }
+
+ return FALSE; /* FALSE:stop period timer; TRUE:keep period timer. */
}
static void media_endpoint_update_property(MediaEndpointInterface *media_ep_if,
@@ -505,12 +660,12 @@
g_free((gpointer)media_tran_if->device);
media_tran_if->device = g_strdup(g_variant_get_string(property_value, NULL));
g_assert(g_variant_is_object_path(media_tran_if->device));
- log_debug(TAG, "device:''%s''", media_tran_if->device);
+ log_debug(TAG, "device:'%s'", media_tran_if->device);
} else if (g_str_equal(property_name, MEDIA_TRANSPORT_PROPERTY_UUID)) {
if (media_tran_if->uuid)
g_free((gpointer)media_tran_if->uuid);
media_tran_if->uuid = g_strdup(g_variant_get_string(property_value, NULL));
- log_debug(TAG, "uuid:''%s''", media_tran_if->uuid);
+ log_debug(TAG, "uuid:'%s'", media_tran_if->uuid);
} else if (g_str_equal(property_name, MEDIA_TRANSPORT_PROPERTY_CODEC)) {
media_tran_if->codec = g_variant_get_byte(property_value);
log_debug(TAG, "codec:0x%x", media_tran_if->codec);
@@ -551,6 +706,8 @@
// log_debug(TAG, "meta[%d]:0x%x", i, media_tran_if->meta[i]);
//}
} else if (g_str_equal(property_name, MEDIA_TRANSPORT_PROPERTY_LINKS)) {
+ if (media_tran_if->links)
+ g_free((gpointer)media_tran_if->links);
media_tran_if->links = g_variant_get_objv(property_value, NULL);
} else if (g_str_equal(property_name, MEDIA_TRANSPORT_PROPERTY_QOS)) {
GVariantIter qos_iter;
@@ -632,6 +789,8 @@
g_free((gpointer)media_tran_if->config);
if (media_tran_if->endpoint)
g_free((gpointer)media_tran_if->endpoint);
+ if (media_tran_if->links)
+ g_free((gpointer)media_tran_if->links);
g_free((gpointer)media_tran_if);
}
}
@@ -704,7 +863,14 @@
MediaInterface *media_interface = (MediaInterface *) user_data;
g_assert(media_interface != NULL);
- media_tran_if = media_interface->media_transport_interface;
+
+ for (guint i = 0;i < BROADCAST_BIS_MAX_NUM;i++) {
+ if (media_interface->media_transport_interface[i] &&
+ g_str_equal(media_interface->media_transport_interface[i]->path, path)) {
+ media_tran_if = media_interface->media_transport_interface[i];
+ break;
+ }
+ }
if (!media_tran_if) {
log_warn(TAG, "media transport interface is not ready!");
@@ -760,22 +926,28 @@
log_debug(TAG, "interface added, obj_path:%s, interface_name:%s", object, interface_name);
MediaEndpointInterface *media_ep_if = g_new0(MediaEndpointInterface, 1);
media_ep_if->path = g_strdup(object);
- media_interface->media_endpoint_interface = media_ep_if;
g_variant_iter_init(&iter, properties);
while (g_variant_iter_loop(&iter, "{&sv}", &property_name, &property_value)) {
media_endpoint_update_property(media_ep_if, property_name, property_value);
}
+ if (media_ep_if->uuid &&
+ !g_str_equal(media_ep_if->uuid, LEA_BCAA_SERVICE_UUID)) {
+ log_warn(TAG, "ignore unknown media endpoint, uuid:%s", media_ep_if->uuid);
+ g_free((gpointer)media_ep_if);
+ goto EXIT;
+ }
+ media_interface->media_endpoint_interface = media_ep_if;
media_endpoint_set_configuration(g_dbus_conn, media_ep_if);
- }else if (g_str_equal(interface_name, INTERFACE_MEDIA_TRANSPORT)) {
+ } else if (g_str_equal(interface_name, INTERFACE_MEDIA_TRANSPORT)) {
log_debug(TAG, "interface added obj_path:%s, interface_name:%s", object, interface_name);
- if (media_interface->media_transport_interface) {
- log_warn(TAG, "multiple media transport interface un-supported!");
- return;
+
+ if (media_interface->media_transport_num >= BROADCAST_BIS_MAX_NUM) {
+ log_warn(TAG, "media transport max number:%d reached!", BROADCAST_BIS_MAX_NUM);
+ goto EXIT;
}
MediaTransportInterface *media_tran_if = g_new0(MediaTransportInterface, 1);
media_tran_if->path = g_strdup(object);
- media_interface->media_transport_interface = media_tran_if;
g_variant_iter_init(&iter, properties);
while (g_variant_iter_loop(&iter, "{&sv}", &property_name, &property_value)) {
@@ -783,23 +955,28 @@
}
if (media_tran_if->uuid &&
!g_str_equal(media_tran_if->uuid, LEA_BAA_SERVICE_UUID)) {
- log_warn(TAG, "ignore unknown uuid:%s", media_tran_if->uuid);
+ log_warn(TAG, "ignore unknown media transport, uuid:%s", media_tran_if->uuid);
g_free((gpointer)media_tran_if);
- media_interface->media_transport_interface = NULL;
- if (interfaces != NULL)
- g_variant_iter_free(interfaces);
- return;
+ goto EXIT;
}
- if (g_media_if->sync_state_cb) {
- g_media_if->sync_state_cb(TRUE);
+
+ media_interface->media_transport_interface[media_interface->media_transport_num] =
+ media_tran_if;
+ media_interface->media_transport_num++;
+ if (!media_interface->media_transport_source_id) {
+ if (g_media_if->sync_state_cb)
+ g_media_if->sync_state_cb(TRUE);
+
+ /* delay to wait transport setup done */
+ media_interface->media_transport_source_id =
+ g_timeout_add(MEDIA_TRANSPORT_SELECT_CALL_DELAY,
+ media_transport_select_cb,
+ media_interface);
}
- /* delay to wait transport setup done */
- g_timeout_add(MEDIA_TRANSPORT_SELECT_CALL_DELAY,
- media_transport_select_cb,
- media_tran_if);
}
}
+EXIT:
if (interfaces != NULL)
g_variant_iter_free(interfaces);
}
@@ -817,8 +994,9 @@
GVariantIter *interfaces = NULL;
const char *object = NULL;
const char *interface_name = NULL;
- MediaEndpointInterface *media_endpoint_if;
- MediaTransportInterface *media_transport_if;
+ MediaEndpointInterface *media_endpoint_if = NULL;
+ MediaTransportInterface *media_transport_if = NULL;
+ guint i;
MediaInterface *media_interface = (MediaInterface *) user_data;
g_assert(media_interface != NULL);
@@ -832,7 +1010,7 @@
while (g_variant_iter_loop(interfaces, "s", &interface_name)) {
//log_debug(TAG, "%s interface_name:%s", __func__, interface_name);
if (g_str_equal(interface_name, INTERFACE_MEDIA_ENDPOINT)) {
- log_debug(TAG, "interface_name:%s", interface_name);
+ log_debug(TAG, "interface removed, interface_name:%s", interface_name);
media_endpoint_if = media_interface->media_endpoint_interface;
if (media_endpoint_if) {
@@ -840,15 +1018,34 @@
media_interface->media_endpoint_interface = NULL;
}
} else if (g_str_equal(interface_name, INTERFACE_MEDIA_TRANSPORT)) {
- log_debug(TAG, "interface_name:%s", interface_name);
+ log_debug(TAG, "interface removed, interface_name:%s", interface_name);
- media_transport_if = media_interface->media_transport_interface;
- if (media_transport_if) {
+ log_debug(TAG, "%s transport_num:%d",
+ __func__, media_interface->media_transport_num);
+
+ for (i = 0;i < media_interface->media_transport_num;i++) {
+ if (media_interface->media_transport_interface[i] &&
+ g_str_equal(media_interface->media_transport_interface[i]->path, object_path)) {
+ media_transport_if = media_interface->media_transport_interface[i];
+ break;
+ }
+ }
+
+ if (!media_transport_if) {
+ log_warn(TAG, "media transport interface is not ready!");
+ goto EXIT;
+ } else {
media_transport_destroy(media_transport_if);
- media_interface->media_transport_interface = NULL;
+ media_interface->media_transport_interface[i] = NULL;
+ media_interface->media_transport_num--;
+ }
+ if (!media_interface->media_transport_num) {
+ media_interface->media_transport_source_id = 0;
}
}
}
+
+EXIT:
if (interfaces != NULL)
g_variant_iter_free(interfaces);
}
@@ -880,8 +1077,8 @@
ep->locations = locations;
ep->supported_context = supported_context;
ep->path = g_strdup_printf("%s/ep%u", MEDIA_ENDPOINT_OBJ_PATH,
- g_list_length(local_endpoints));
- local_endpoints = g_list_append(local_endpoints, ep);
+ g_list_length(g_media_if->local_endpoints));
+ g_media_if->local_endpoints = g_list_append(g_media_if->local_endpoints, ep);
return ep;
}
@@ -1034,7 +1231,7 @@
return 0;
}
-GVariant *media_endpoint_get_property(__attribute__((unused)) GDBusConnection *connection,
+static GVariant *media_endpoint_get_property(__attribute__((unused)) GDBusConnection *connection,
__attribute__((unused)) const gchar *sender,
__attribute__((unused)) const gchar *object_path,
__attribute__((unused)) const gchar *interface_name,
@@ -1211,7 +1408,7 @@
return EINVAL;
}
- local_media_ep_if_reg_id = g_dbus_connection_register_object(connection,
+ g_media_if->local_media_ep_if_reg_id = g_dbus_connection_register_object(connection,
endpoint->path,
info->interfaces[0],
&media_endpoint_method_table,
@@ -1220,7 +1417,7 @@
return 0;
}
-int media_setup(GDBusConnection *dbus_con)
+int lea_mgr_media_setup(GDBusConnection *dbus_con)
{
gchar *uuid;
@@ -1340,9 +1537,23 @@
media_endpoint_destroy(g_media_if->media_endpoint_interface);
g_media_if->media_endpoint_interface = NULL;
}
- if (g_media_if->media_transport_interface) {
- media_transport_destroy(g_media_if->media_transport_interface);
- g_media_if->media_transport_interface = NULL;
+ if (g_media_if->media_transport_num) {
+ log_debug(TAG, "%s transport_num:%d", __func__, g_media_if->media_transport_num);
+ for (guint i = 0;i < g_media_if->media_transport_num;i++) {
+ if (g_media_if->media_transport_interface[i]) {
+ log_debug(TAG, "transport[%d]:'%s', state:'%s'",
+ i,
+ g_media_if->media_transport_interface[i]->path,
+ g_media_if->media_transport_interface[i]->state);
+ if (g_str_equal(g_media_if->media_transport_interface[i]->state,
+ bcast_transport_state_str[BCAST_TRANSPORT_STATE_ACTIVE])) {
+ media_transport_unselect(g_media_if->media_transport_interface[i]);
+ }
+ media_transport_destroy(g_media_if->media_transport_interface[i]);
+ g_media_if->media_transport_interface[i] = NULL;
+ }
+ }
+ g_media_if->media_transport_num = 0;
}
g_free((gpointer)g_media_if);
@@ -1355,19 +1566,29 @@
return -1;
}
-int media_destroy(void)
+int lea_mgr_media_destroy(void)
{
log_debug(TAG, "%s", __func__);
if (g_media_if) {
- if (g_media_if->media_transport_interface) {
- log_debug(TAG, "transport-state:'%s'", g_media_if->media_transport_interface->state);
- if (g_str_equal(g_media_if->media_transport_interface->state,
- bcast_transport_state_str[BCAST_TRANSPORT_STATE_BROADCASTING]) ||
- g_str_equal(g_media_if->media_transport_interface->state,
- bcast_transport_state_str[BCAST_TRANSPORT_STATE_ACTIVE])) {
- media_transport_unselect(g_media_if->media_transport_interface);
+
+ if (g_media_if->media_transport_num) {
+ log_debug(TAG, "%s transport_num:%d", __func__, g_media_if->media_transport_num);
+ for (guint i = 0;i < g_media_if->media_transport_num;i++) {
+ if (g_media_if->media_transport_interface[i]) {
+ log_debug(TAG, "transport[%d]:'%s', state:'%s'",
+ i,
+ g_media_if->media_transport_interface[i]->path,
+ g_media_if->media_transport_interface[i]->state);
+ if (g_str_equal(g_media_if->media_transport_interface[i]->state,
+ bcast_transport_state_str[BCAST_TRANSPORT_STATE_ACTIVE])) {
+ media_transport_unselect(g_media_if->media_transport_interface[i]);
+ }
+ media_transport_destroy(g_media_if->media_transport_interface[i]);
+ g_media_if->media_transport_interface[i] = NULL;
+ }
}
+ g_media_if->media_transport_num = 0;
}
if (g_media_if->supported_uuids) {
@@ -1401,27 +1622,25 @@
media_endpoint_destroy(g_media_if->media_endpoint_interface);
g_media_if->media_endpoint_interface = NULL;
}
- if (g_media_if->media_transport_interface) {
- media_transport_destroy(g_media_if->media_transport_interface);
- g_media_if->media_transport_interface = NULL;
+
+ if (g_media_if->local_endpoints) {
+ destroy_local_endpoints(&g_media_if->local_endpoints);
+ g_media_if->local_endpoints = NULL;
+ }
+
+ if (g_media_if->local_media_ep_if_reg_id) {
+ gboolean result = g_dbus_connection_unregister_object(g_dbus_conn,
+ g_media_if->local_media_ep_if_reg_id);
+ if (!result) {
+ log_error(TAG, "failed to unregister local media endpoint interface");
+ }
+ g_media_if->local_media_ep_if_reg_id = 0;
}
g_free((gpointer)g_media_if);
g_media_if = NULL;
}
- if (local_endpoints) {
- destroy_local_endpoints(&local_endpoints);
- local_endpoints = NULL;
- }
-
- if (local_media_ep_if_reg_id) {
- gboolean result = g_dbus_connection_unregister_object(g_dbus_conn,
- local_media_ep_if_reg_id);
- if (!result) {
- log_error(TAG, "failed to unregister local media endpoint interface");
- }
- }
if (g_dbus_conn) {
g_dbus_conn = NULL;
@@ -1430,7 +1649,7 @@
return 0;
}
-int media_register_baa_endpoint(void)
+int lea_mgr_media_register_baa_endpoint(void)
{
gchar *uuid;
Endpoint *endpoint;
@@ -1460,7 +1679,7 @@
return -1;
}
-int media_register_bcaa_endpoint(void)
+int lea_mgr_media_register_bcaa_endpoint(void)
{
gchar *uuid;
Endpoint *endpoint;
@@ -1491,7 +1710,7 @@
return -1;
}
-void media_set_bcast_sync_state_cb(void (*cb)(gboolean))
+void lea_mgr_media_set_bcast_sync_state_cb(bcast_sync_state_cb_t cb)
{
if (g_media_if) {
g_media_if->sync_state_cb = cb;
diff --git a/ble-fast-pair/ble_audio_cis_source.c b/lea_manager/lea_mgr_cis_source.c
similarity index 98%
rename from ble-fast-pair/ble_audio_cis_source.c
rename to lea_manager/lea_mgr_cis_source.c
index 9f37469..f65f1be 100644
--- a/ble-fast-pair/ble_audio_cis_source.c
+++ b/lea_manager/lea_mgr_cis_source.c
@@ -11,7 +11,7 @@
#include "logger.h"
#include "agent.h"
#include "parser.h"
-#include "ble_fast_pair.h"
+#include "lea_manager.h"
#define TAG "CIS-SOUR"
@@ -172,7 +172,7 @@
}
}
-int ble_audio_cis_source_go(void) {
+int lea_mgr_cis_source(void) {
log_enabled(TRUE);
log_set_level(LOG_DEBUG);
// log_set_filename("./ble_fast_pair_source.txt", 1024 * 64, 5);
diff --git a/ble-fast-pair/dbus_test.c b/lea_manager/lea_mgr_dbus_test.c
similarity index 98%
rename from ble-fast-pair/dbus_test.c
rename to lea_manager/lea_mgr_dbus_test.c
index b8918cf..d19ce20 100644
--- a/ble-fast-pair/dbus_test.c
+++ b/lea_manager/lea_mgr_dbus_test.c
@@ -83,10 +83,7 @@
GVariantBuilder builder;
GVariant *dict;
gchar *str;
- GVariantIter iter;
GVariantIter dict_iter;
- GVariant *child_key;
- GVariant *child_value;
gint32 key;
const gchar *value;
@@ -128,7 +125,6 @@
GVariant *dict;
gchar *str;
GVariantIter iter;
- GVariant *child;
const gchar *key;
GVariant *value;
gint32 int_value;
@@ -258,7 +254,7 @@
}
}
-static int bluez_dbus_set_power_state_test(void)
+__attribute__((unused)) static int bluez_dbus_set_power_state_test(void)
{
GDBusConnection *connection;
GError *error = NULL;
@@ -420,7 +416,7 @@
g_variant_unref(result);
}
-static int bluez_dbus_properties_changed_test(const gchar *alias)
+__attribute__((unused)) static int bluez_dbus_properties_changed_test(const gchar *alias)
{
GDBusConnection *connection;
GError *error = NULL;
@@ -510,7 +506,7 @@
return 0;
}
-static int bluez_dbus_introspect_test(void)
+__attribute__((unused)) static int bluez_dbus_introspect_test(void)
{
GDBusConnection *connection;
GError *error = NULL;
@@ -716,7 +712,7 @@
return 0;
}
-int dbus_test_go(void)
+int lea_mgr_dbus_test(void)
{
dbus_array_test();
dbus_dictionary_test();
diff --git a/ble-fast-pair/ble_audio_bis_sink.c b/lea_manager/lea_mgr_scanner.c
similarity index 94%
rename from ble-fast-pair/ble_audio_bis_sink.c
rename to lea_manager/lea_mgr_scanner.c
index f332b70..354c65f 100644
--- a/ble-fast-pair/ble_audio_bis_sink.c
+++ b/lea_manager/lea_mgr_scanner.c
@@ -11,7 +11,7 @@
#include "logger.h"
#include "agent.h"
#include "parser.h"
-#include "ble_fast_pair.h"
+#include "lea_manager.h"
#define TAG "SCANNER"
@@ -45,7 +45,7 @@
static gboolean callback(gpointer data) {
- media_destroy();
+ lea_mgr_media_destroy();
if (default_adapter != NULL) {
GList *device_list = NULL;
@@ -85,7 +85,7 @@
binc_adapter_start_discovery(default_adapter);
}
-int ble_audio_bis_sink_go(void) {
+int lea_mgr_scanner(void) {
log_enabled(TRUE);
log_set_level(LOG_DEBUG);
// log_set_filename("./ble_fast_pair_source.txt", 1024 * 64, 5);
@@ -128,10 +128,10 @@
}
}
- if (!media_setup(dbusConnection)) {
+ if (!lea_mgr_media_setup(dbusConnection)) {
log_debug(TAG, "media setup success");
- media_set_bcast_sync_state_cb(bcast_sync_state_change_cb);
- media_register_baa_endpoint();
+ lea_mgr_media_set_bcast_sync_state_cb(bcast_sync_state_change_cb);
+ lea_mgr_media_register_baa_endpoint();
}
binc_adapter_set_discovery_cb(default_adapter, &on_scan_result);