fix(bluez): 同步主线bluez代码

Description: none

Log: none
This commit is contained in:
dengtuo 2023-08-14 11:16:48 +08:00
parent ff29f075af
commit 7648e382b4
17 changed files with 417 additions and 26 deletions

View File

@ -317,11 +317,12 @@ src_bluetoothd_SOURCES = $(builtin_sources) \
src/dbus-common.c src/dbus-common.h \
src/eir.h src/eir.c \
src/adv_monitor.h src/adv_monitor.c \
src/battery.h src/battery.c
src/battery.h src/battery.c \
src/kylin_bluetooth.h src/kylin_bluetooth.c
src_bluetoothd_LDADD = lib/libbluetooth-internal.la \
gdbus/libgdbus-internal.la \
src/libshared-glib.la \
$(BACKTRACE_LIBS) $(GLIB_LIBS) $(DBUS_LIBS) -ldl -lrt \
$(BACKTRACE_LIBS) $(GLIB_LIBS) $(DBUS_LIBS) -lgobject-2.0 -lgio-2.0 -ldl -lrt \
$(builtin_ldadd)
src_bluetoothd_LDFLAGS = $(AM_LDFLAGS) -Wl,--export-dynamic \
-Wl,--version-script=$(srcdir)/src/bluetooth.ver

View File

@ -1159,7 +1159,8 @@ am__src_bluetoothd_SOURCES_DIST = plugins/hostname.c plugins/wiimote.c \
src/profile.c src/service.h src/service.c src/gatt-client.h \
src/gatt-client.c src/device.h src/device.c src/dbus-common.c \
src/dbus-common.h src/eir.h src/eir.c src/adv_monitor.h \
src/adv_monitor.c src/battery.h src/battery.c
src/adv_monitor.c src/battery.h src/battery.c \
src/kylin_bluetooth.h src/kylin_bluetooth.c
@ADMIN_TRUE@am__objects_13 = plugins/bluetoothd-admin.$(OBJEXT)
@NFC_TRUE@am__objects_14 = plugins/bluetoothd-neard.$(OBJEXT)
@SAP_TRUE@am__objects_15 = profiles/sap/bluetoothd-main.$(OBJEXT) \
@ -1245,7 +1246,8 @@ am_src_bluetoothd_OBJECTS = $(am__objects_23) $(am__objects_24) \
src/bluetoothd-dbus-common.$(OBJEXT) \
src/bluetoothd-eir.$(OBJEXT) \
src/bluetoothd-adv_monitor.$(OBJEXT) \
src/bluetoothd-battery.$(OBJEXT)
src/bluetoothd-battery.$(OBJEXT) \
src/bluetoothd-kylin_bluetooth.$(OBJEXT)
nodist_src_bluetoothd_OBJECTS = $(am__objects_12)
src_bluetoothd_OBJECTS = $(am_src_bluetoothd_OBJECTS) \
$(nodist_src_bluetoothd_OBJECTS)
@ -2240,6 +2242,7 @@ am__depfiles_remade = android/$(DEPDIR)/a2dp-sink.Po \
src/$(DEPDIR)/bluetoothd-storage.Po \
src/$(DEPDIR)/bluetoothd-textfile.Po \
src/$(DEPDIR)/bluetoothd-uuid-helper.Po src/$(DEPDIR)/eir.Po \
src/$(DEPDIR)/bluetoothd-kylin_bluetooth.Po \
src/$(DEPDIR)/log.Po src/$(DEPDIR)/oui.Po \
src/$(DEPDIR)/sdp-client.Po src/$(DEPDIR)/sdp-xml.Po \
src/$(DEPDIR)/sdpd-database.Po src/$(DEPDIR)/sdpd-request.Po \
@ -3288,7 +3291,8 @@ src_bluetoothd_SOURCES = $(builtin_sources) \
src/dbus-common.c src/dbus-common.h \
src/eir.h src/eir.c \
src/adv_monitor.h src/adv_monitor.c \
src/battery.h src/battery.c
src/battery.h src/battery.c \
src/kylin_bluetooth.h src/kylin_bluetooth.c
src_bluetoothd_LDADD = lib/libbluetooth-internal.la \
gdbus/libgdbus-internal.la \
@ -5609,6 +5613,8 @@ src/bluetoothd-adv_monitor.$(OBJEXT): src/$(am__dirstamp) \
src/$(DEPDIR)/$(am__dirstamp)
src/bluetoothd-battery.$(OBJEXT): src/$(am__dirstamp) \
src/$(DEPDIR)/$(am__dirstamp)
src/bluetoothd-kylin_bluetooth.$(OBJEXT): src/$(am__dirstamp) \
src/$(DEPDIR)/$(am__dirstamp)
src/bluetoothd$(EXEEXT): $(src_bluetoothd_OBJECTS) $(src_bluetoothd_DEPENDENCIES) $(EXTRA_src_bluetoothd_DEPENDENCIES) src/$(am__dirstamp)
@rm -f src/bluetoothd$(EXEEXT)
@ -6766,6 +6772,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/bluetoothd-storage.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/bluetoothd-textfile.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/bluetoothd-uuid-helper.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/bluetoothd-kylin_bluetooth.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/eir.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/log.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/oui.Po@am__quote@ # am--include-marker
@ -9477,6 +9484,21 @@ src/bluetoothd-battery.obj: src/battery.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_bluetoothd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/bluetoothd-battery.obj `if test -f 'src/battery.c'; then $(CYGPATH_W) 'src/battery.c'; else $(CYGPATH_W) '$(srcdir)/src/battery.c'; fi`
src/bluetoothd-kylin_bluetooth.o: src/kylin_bluetooth.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_bluetoothd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/bluetoothd-kylin_bluetooth.o -MD -MP -MF src/$(DEPDIR)/bluetoothd-kylin_bluetooth.Tpo -c -o src/bluetoothd-kylin_bluetooth.o `test -f 'src/kylin_bluetooth.c' || echo '$(srcdir)/'`src/kylin_bluetooth.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/bluetoothd-kylin_bluetooth.Tpo src/$(DEPDIR)/bluetoothd-kylin_bluetooth.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/kylin_bluetooth.c' object='src/bluetoothd-kylin_bluetooth.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_bluetoothd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/bluetoothd-kylin_bluetooth.o `test -f 'src/kylin_bluetooth.c' || echo '$(srcdir)/'`src/kylin_bluetooth.c
src/bluetoothd-kylin_bluetooth.obj: src/kylin_bluetooth.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_bluetoothd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/bluetoothd-kylin_bluetooth.obj -MD -MP -MF src/$(DEPDIR)/bluetoothd-kylin_bluetooth.Tpo -c -o src/bluetoothd-kylin_bluetooth.obj `if test -f 'src/kylin_bluetooth.c'; then $(CYGPATH_W) 'src/kylin_bluetooth.c'; else $(CYGPATH_W) '$(srcdir)/src/kylin_bluetooth.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/bluetoothd-kylin_bluetooth.Tpo src/$(DEPDIR)/bluetoothd-kylin_bluetooth.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/kylin_bluetooth.c' object='src/bluetoothd-kylin_bluetooth.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_bluetoothd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/bluetoothd-kylin_bluetooth.obj `if test -f 'src/kylin_bluetooth.c'; then $(CYGPATH_W) 'src/kylin_bluetooth.c'; else $(CYGPATH_W) '$(srcdir)/src/kylin_bluetooth.c'; fi`
unit/test_mesh_crypto-test-mesh-crypto.o: unit/test-mesh-crypto.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(unit_test_mesh_crypto_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT unit/test_mesh_crypto-test-mesh-crypto.o -MD -MP -MF unit/$(DEPDIR)/test_mesh_crypto-test-mesh-crypto.Tpo -c -o unit/test_mesh_crypto-test-mesh-crypto.o `test -f 'unit/test-mesh-crypto.c' || echo '$(srcdir)/'`unit/test-mesh-crypto.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) unit/$(DEPDIR)/test_mesh_crypto-test-mesh-crypto.Tpo unit/$(DEPDIR)/test_mesh_crypto-test-mesh-crypto.Po
@ -10917,6 +10939,7 @@ distclean: distclean-am
-rm -f src/$(DEPDIR)/bluetoothd-attrib-server.Po
-rm -f src/$(DEPDIR)/bluetoothd-backtrace.Po
-rm -f src/$(DEPDIR)/bluetoothd-battery.Po
-rm -f src/$(DEPDIR)/bluetoothd-kylin_bluetooth.Po
-rm -f src/$(DEPDIR)/bluetoothd-dbus-common.Po
-rm -f src/$(DEPDIR)/bluetoothd-device.Po
-rm -f src/$(DEPDIR)/bluetoothd-eir.Po
@ -11514,6 +11537,7 @@ maintainer-clean: maintainer-clean-am
-rm -f src/$(DEPDIR)/bluetoothd-attrib-server.Po
-rm -f src/$(DEPDIR)/bluetoothd-backtrace.Po
-rm -f src/$(DEPDIR)/bluetoothd-battery.Po
-rm -f src/$(DEPDIR)/bluetoothd-kylin_bluetooth.Po
-rm -f src/$(DEPDIR)/bluetoothd-dbus-common.Po
-rm -f src/$(DEPDIR)/bluetoothd-device.Po
-rm -f src/$(DEPDIR)/bluetoothd-eir.Po

1
configure vendored
View File

@ -13862,6 +13862,7 @@ fi
GLIB_LIBS="$GLIB_LIBS $GTHREAD_LIBS"
fi
GLIB_LIBS="$GLIB_LIBS $GTHREAD_LIBS -lgobject-2.0 -lgio-2.0"
pkg_failed=no
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for dbus-1 >= 1.6" >&5

View File

@ -94,6 +94,7 @@ gssize g_obex_header_encode(GObexHeader *header, void *buf, gsize buf_len)
utf16_len = utf8_to_utf16(&utf16, header->v.string);
if (utf16_len < 0 || (guint16) utf16_len > buf_len)
return -1;
header->hlen = utf16_len + 3;
g_assert_cmpuint(utf16_len + 3, ==, header->hlen);
u16 = g_htons(utf16_len + 3);
ptr = put_bytes(ptr, &u16, sizeof(u16));

View File

@ -27,6 +27,7 @@
#include <netinet/in.h>
#include <glib.h>
#include <gio/gio.h>
#include "lib/bluetooth.h"
#include "lib/sdp.h"
@ -366,6 +367,49 @@ static void handle_release(struct avctp *session, uint16_t op)
send_key(session->uinput, op, 0);
}
static void avctp_send_bluetooth_key(uint32_t uinput,bool opet)
{
DBG("Sending signal with value %d\n", uinput);
GError *gerror = NULL;
GDBusProxy * avctp_proxy = NULL ;
avctp_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
G_DBUS_PROPERTY_INFO_FLAGS_NONE,
NULL,
"com.ukui.bluetooth",
"/com/ukui/bluetooth",
"com.ukui.bluetooth",
NULL,
NULL);
if(!avctp_proxy)
{
DBG("avctp proxy is null!");
g_object_unref(avctp_proxy);
return;
}
GVariant *prms = g_variant_new_uint16(uinput);
if (!prms)
{
DBG("prms is null!");
g_variant_unref(prms);
return;
}
//获取设置列表
GVariant * dev_list = NULL;
dev_list = g_dbus_proxy_call_sync(avctp_proxy,
"bluetoothKeyValue",//"getKeyFilePath",
g_variant_new("(us)",uinput,opet?"pressed":"released"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
NULL);
g_object_unref(avctp_proxy);
}
static size_t handle_panel_passthrough(struct avctp *session,
uint8_t transaction, uint8_t *code,
uint8_t *subunit, uint8_t *operands,
@ -403,7 +447,9 @@ static size_t handle_panel_passthrough(struct avctp *session,
if ((operands[0] & 0x7F) != key_map[i].avc)
continue;
DBG("AV/C: %s %s", key_map[i].name, status);
DBG("AV/C: %s %d %s", key_map[i].name, key_map[i].uinput,status);
//test
avctp_send_bluetooth_key(key_map[i].uinput,pressed);
key_quirks = session->key_quirks[key_map[i].avc];
@ -2015,6 +2061,7 @@ unsigned int avctp_register_pdu_handler(struct avctp *session, uint8_t opcode,
avctp_control_pdu_cb cb,
void *user_data)
{
DBG("");
struct avctp_channel *control = session->control;
struct avctp_pdu_handler *handler;
static unsigned int id = 0;

View File

@ -428,7 +428,7 @@ static int process_queue(struct avdtp *session);
static void avdtp_sep_set_state(struct avdtp *session,
struct avdtp_local_sep *sep,
avdtp_state_t state);
int avdtp_stream_state_change(struct avdtp *session, struct avdtp_stream *stream);
static const char *avdtp_statestr(avdtp_state_t state)
{
switch (state) {
@ -998,6 +998,7 @@ static void avdtp_sep_set_state(struct avdtp *session,
break;
case AVDTP_STATE_OPEN:
stream->starting = FALSE;
avdtp_stream_state_change(session, stream);
break;
case AVDTP_STATE_STREAMING:
if (stream->start_timer) {
@ -1834,7 +1835,7 @@ static gboolean avdtp_start_cmd(struct avdtp *session, uint8_t transaction,
goto failed;
}
stream->starting = TRUE;
avdtp_stream_state_change(session, stream);
if (sep->ind && sep->ind->start) {
if (!sep->ind->start(session, sep, stream, &err,
sep->user_data))
@ -2588,8 +2589,10 @@ static int cancel_request(struct avdtp *session, int err)
if (lsep && lsep->cfm && lsep->cfm->start) {
lsep->cfm->start(session, lsep, stream, &averr,
lsep->user_data);
if (stream)
if (stream) {
stream->starting = FALSE;
avdtp_stream_state_change(session, stream);
}
}
break;
case AVDTP_SUSPEND:
@ -3126,6 +3129,7 @@ static gboolean avdtp_parse_rej(struct avdtp *session,
sep->cfm->start(session, sep, stream, &err,
sep->user_data);
stream->starting = FALSE;
avdtp_stream_state_change(session, stream);
}
return TRUE;
case AVDTP_SUSPEND:
@ -3677,8 +3681,10 @@ int avdtp_start(struct avdtp *session, struct avdtp_stream *stream)
ret = send_request(session, FALSE, stream, AVDTP_START,
&req, sizeof(req));
if (ret == 0)
if (ret == 0) {
stream->starting = TRUE;
avdtp_stream_state_change(session, stream);
}
return ret;
}
@ -3963,3 +3969,23 @@ gboolean avdtp_remove_state_cb(unsigned int id)
return FALSE;
}
int avdtp_stream_state_change(struct avdtp *session, struct avdtp_stream *stream)
{
if (stream->starting == TRUE) {
set_a2dp_state_hisi(TRUE,device_get_adapter(session->device),
device_get_address(session->device),
btd_device_get_bdaddr_type(session->device));
info("avdtp_stream_state_change ture ");
}
if (stream->starting == FALSE) {
set_a2dp_state_hisi(FALSE,device_get_adapter(session->device),
device_get_address(session->device),
btd_device_get_bdaddr_type(session->device));
info("avdtp_stream_state_change false");
}
return 0;
}

View File

@ -276,6 +276,8 @@ struct avrcp {
uint8_t transaction;
uint8_t transaction_events[AVRCP_EVENT_LAST + 1];
struct pending_pdu *pending_pdu;
int volume;
};
struct passthrough_handler {
@ -406,7 +408,7 @@ static sdp_record_t *avrcp_ct_record(bool browsing)
sdp_record_t *record;
sdp_data_t *psm[2], *version, *features;
uint16_t lp = AVCTP_CONTROL_PSM;
uint16_t avctp_ver = 0x0103;
uint16_t avctp_ver = 0x0104;
uint16_t feat = ( AVRCP_FEATURE_CATEGORY_1 |
AVRCP_FEATURE_CATEGORY_2 |
AVRCP_FEATURE_CATEGORY_3 |
@ -450,6 +452,7 @@ static sdp_record_t *avrcp_ct_record(bool browsing)
}
/* Bluetooth Profile Descriptor List */
#if 0
sdp_uuid16_create(&profile[0].uuid, AV_REMOTE_PROFILE_ID);
profile[0].version = AVRCP_CT_VERSION;
pfseq = sdp_list_append(NULL, &profile[0]);
@ -459,6 +462,7 @@ static sdp_record_t *avrcp_ct_record(bool browsing)
sdp_attr_add(record, SDP_ATTR_SUPPORTED_FEATURES, features);
sdp_set_info_attr(record, "AVRCP CT", NULL, NULL);
#endif
free(psm[0]);
free(version);
@ -482,7 +486,7 @@ static sdp_record_t *avrcp_tg_record(bool browsing)
sdp_record_t *record;
sdp_data_t *psm_control, *version, *features;
uint16_t lp = AVCTP_CONTROL_PSM;
uint16_t avctp_ver = 0x0103;
uint16_t avctp_ver = 0x0104;
uint16_t feat = ( AVRCP_FEATURE_CATEGORY_1 |
AVRCP_FEATURE_CATEGORY_2 |
AVRCP_FEATURE_CATEGORY_3 |
@ -1607,6 +1611,7 @@ static uint8_t avrcp_handle_register_notification(struct avrcp *session,
struct avrcp_header *pdu,
uint8_t transaction)
{
DBG("");
struct avrcp_player *player = target_get_player(session);
struct btd_device *dev = session->dev;
uint16_t len = ntohs(pdu->params_len);
@ -1750,6 +1755,8 @@ static uint8_t avrcp_handle_set_absolute_volume(struct avrcp *session,
struct avrcp_header *pdu,
uint8_t transaction)
{
DBG("");
uint16_t len = ntohs(pdu->params_len);
int8_t volume;
@ -1757,7 +1764,7 @@ static uint8_t avrcp_handle_set_absolute_volume(struct avrcp *session,
goto err;
volume = pdu->params[0] & 0x7F;
session->volume = volume;
media_transport_update_device_volume(session->dev, volume);
return AVC_CTYPE_ACCEPTED;
@ -3724,14 +3731,17 @@ static void avrcp_get_media_player_list(struct avrcp *session)
static void avrcp_volume_changed(struct avrcp *session,
struct avrcp_header *pdu)
{
DBG("");
struct avrcp_player *player = target_get_player(session);
int8_t volume;
volume = pdu->params[1] & 0x7F;
/* Always attempt to update the transport volume */
session->volume = volume;
media_transport_update_device_volume(session->dev, volume);
if (player)
player->cb->set_volume(volume, session->dev, player->user_data);
}
@ -3846,6 +3856,7 @@ static gboolean avrcp_handle_event(struct avctp *conn, uint8_t code,
uint8_t *operands, size_t operand_count,
void *user_data)
{
DBG("");
struct avrcp *session = user_data;
struct avrcp_header *pdu = (void *) operands;
uint8_t event;
@ -4144,6 +4155,7 @@ static void target_init(struct avrcp *session)
player->sessions = g_slist_prepend(player->sessions, session);
init_volume = media_player_get_device_volume(session->dev);
session->volume = init_volume;
media_transport_update_device_volume(session->dev, init_volume);
}
@ -4308,6 +4320,7 @@ static struct avrcp *session_create(struct avrcp_server *server,
session->server = server;
session->conn = avctp_connect(device);
session->dev = device;
session->volume = -1;
server->sessions = g_slist_append(server->sessions, session);
@ -4318,6 +4331,7 @@ static void state_changed(struct btd_device *device, avctp_state_t old_state,
avctp_state_t new_state, int err,
void *user_data)
{
DBG("");
struct avrcp_server *server;
struct avrcp *session;
@ -4327,6 +4341,8 @@ static void state_changed(struct btd_device *device, avctp_state_t old_state,
session = find_session(server->sessions, device);
DBG("new_state:%d",new_state);
switch (new_state) {
case AVCTP_STATE_DISCONNECTED:
if (session == NULL)
@ -4484,6 +4500,7 @@ static gboolean avrcp_handle_set_volume(struct avctp *conn, uint8_t code,
uint8_t *operands, size_t operand_count,
void *user_data)
{
DBG("");
struct avrcp *session = user_data;
struct avrcp_player *player = target_get_player(session);
struct avrcp_header *pdu = (void *) operands;
@ -4496,6 +4513,7 @@ static gboolean avrcp_handle_set_volume(struct avctp *conn, uint8_t code,
volume = pdu->params[0] & 0x7F;
/* Always attempt to update the transport volume */
session->volume = volume;
media_transport_update_device_volume(session->dev, volume);
if (player != NULL)
@ -4557,6 +4575,7 @@ static bool avrcp_event_registered(struct avrcp *session, uint8_t event)
int avrcp_set_volume(struct btd_device *dev, int8_t volume, bool notify)
{
DBG("");
struct avrcp_server *server;
struct avrcp *session;
uint8_t buf[AVRCP_HEADER_LENGTH + 1];
@ -4598,6 +4617,22 @@ int avrcp_set_volume(struct btd_device *dev, int8_t volume, bool notify)
avrcp_handle_set_volume, session);
}
int avrcp_get_volume(struct btd_device *dev)
{
struct avrcp_server *server;
struct avrcp *session;
server = find_server(servers, device_get_adapter(dev));
if (server == NULL)
return -1;
session = find_session(server->sessions, dev);
if (session == NULL)
return -1;
return session->volume;
}
struct avrcp_player *avrcp_get_target_player_by_device(struct btd_device *dev)
{
struct avrcp_server *server;

View File

@ -92,6 +92,8 @@ struct avrcp_player_cb {
int avrcp_set_volume(struct btd_device *dev, int8_t volume, bool notify);
int avrcp_get_volume(struct btd_device *dev);
struct avrcp_player *avrcp_register_player(struct btd_adapter *adapter,
struct avrcp_player_cb *cb,
void *user_data,

View File

@ -440,6 +440,7 @@ static void media_owner_add(struct media_owner *owner,
static DBusMessage *acquire(DBusConnection *conn, DBusMessage *msg,
void *data)
{
DBG("");
struct media_transport *transport = data;
struct media_owner *owner;
struct media_request *req;
@ -468,6 +469,7 @@ static DBusMessage *acquire(DBusConnection *conn, DBusMessage *msg,
static DBusMessage *try_acquire(DBusConnection *conn, DBusMessage *msg,
void *data)
{
DBG("");
struct media_transport *transport = data;
struct media_owner *owner;
struct media_request *req;
@ -499,6 +501,7 @@ static DBusMessage *try_acquire(DBusConnection *conn, DBusMessage *msg,
static DBusMessage *release(DBusConnection *conn, DBusMessage *msg,
void *data)
{
DBG("");
struct media_transport *transport = data;
struct media_owner *owner = transport->owner;
const char *sender;
@ -640,6 +643,7 @@ static void set_volume(const GDBusPropertyTable *property,
DBusMessageIter *iter, GDBusPendingPropertySet id,
void *data)
{
DBG("");
struct media_transport *transport = data;
struct a2dp_transport *a2dp = transport->data;
uint16_t arg;
@ -672,6 +676,7 @@ static void set_volume(const GDBusPropertyTable *property,
return;
error:
DBG("");
g_dbus_pending_property_error(id, ERROR_INTERFACE ".InvalidArguments",
"Invalid arguments in method call");
}
@ -810,7 +815,8 @@ static int media_transport_init_source(struct media_transport *transport)
transport->data = a2dp;
transport->destroy = destroy_a2dp;
a2dp->volume = -1;
a2dp->volume = avrcp_get_volume(transport->device);
DBG("init a2dp volume : %d", a2dp->volume);
transport->sink_watch = sink_add_state_cb(service, sink_state_changed,
transport);
@ -926,6 +932,7 @@ int8_t media_transport_get_volume(struct media_transport *transport)
void media_transport_update_volume(struct media_transport *transport,
int8_t volume)
{
DBG("");
struct a2dp_transport *a2dp = transport->data;
if (volume < 0)
@ -965,6 +972,7 @@ int8_t media_transport_get_device_volume(struct btd_device *dev)
void media_transport_update_device_volume(struct btd_device *dev,
int8_t volume)
{
DBG("update volume :%d",volume);
GSList *l;
if (dev == NULL || volume < 0)

View File

@ -9,8 +9,6 @@
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@ -89,6 +87,7 @@
#define DISTANCE_VAL_INVALID 0x7FFF
#define PATHLOSS_MAX 137
extern bool is_huawei;
/*
* These are known security keys that have been compromised.
* If this grows or there are needs to be platform specific, it is
@ -818,9 +817,37 @@ static void local_name_changed_callback(uint16_t index, uint16_t length,
}
DBG("Current alias: %s", adapter->current_alias);
DBG("Stored alias: %s", adapter->stored_alias);
if (!adapter->current_alias)
return;
else
{
char * version_name = g_strdup_printf("BlueZ %s", VERSION);
if ((0 != g_strcmp0(adapter->current_alias,version_name)) && (0 != g_strcmp0(adapter->current_alias,"oem_PC")))
{
if (0 != g_strcmp0(adapter->stored_alias,adapter->current_alias))
{
adapter->stored_alias = g_strdup(adapter->current_alias);
store_adapter_info(adapter);
}
}
else
{
if (NULL != adapter->stored_alias)
{
adapter->current_alias = g_strdup(adapter->stored_alias);
}
}
g_free(version_name);
}
DBG("name: %s", adapter->name);
DBG("short name: %s", adapter->short_name);
DBG("system name: %s", adapter->system_name);
DBG("current alias: %s", adapter->current_alias);
DBG("stored alias: %s", adapter->stored_alias);
g_dbus_emit_property_changed(dbus_conn, adapter->path,
ADAPTER_INTERFACE, "Alias");
@ -894,6 +921,11 @@ int adapter_set_name(struct btd_adapter *adapter, const char *name)
ADAPTER_INTERFACE, "Name");
/* alias is preferred over system name */
DBG("adapter->name: %s", adapter->name);
DBG("adapter->system_name: %s", adapter->system_name);
DBG("adapter->current_alias: %s", adapter->current_alias);
DBG("adapter->stored_alias: %s", adapter->stored_alias);
if (adapter->stored_alias)
return 0;
@ -902,6 +934,17 @@ int adapter_set_name(struct btd_adapter *adapter, const char *name)
g_dbus_emit_property_changed(dbus_conn, adapter->path,
ADAPTER_INTERFACE, "Alias");
char * version_name = g_strdup_printf("BlueZ %s", VERSION);
DBG("version_name: %s", version_name);
if (NULL == adapter->stored_alias && (0 != g_strcmp0(name,version_name)) && (0 != g_strcmp0(name,"oem_PC")))
{
adapter->stored_alias = g_strdup(name);
adapter->current_alias = g_strdup(name);
store_adapter_info(adapter);
}
g_free(version_name);
return set_name(adapter, name);
}
@ -934,7 +977,20 @@ struct btd_device *btd_adapter_find_device(struct btd_adapter *adapter,
if (bdaddr_type == BDADDR_BREDR)
device_set_bredr_support(device);
else
{
//蓝牙耳机音箱 不支持 le , 防止出现 连接异常情况
const char * icon = btd_device_get_icon(device);
if(icon && (strcmp(icon, "audio-headset") || strcmp(icon, "audio-headphones")))
{
DBG("device is audio, not set le, icon : %s", icon);
}
else
{
device_set_le_support(device, bdaddr_type);
DBG("device->le set true");
}
}
return device;
}
@ -10336,6 +10392,32 @@ int adapter_init(void)
return -EIO;
}
int set_a2dp_state_hisi(bool status, struct btd_adapter *adapter, const bdaddr_t *bdaddr,
uint8_t addr_type)
{
info("is_huawei:%d",is_huawei);
if (!is_huawei)
return 0;
struct mgmt_cp_pair_device cp;
memset(&cp, 0, sizeof(cp));
bacpy(&cp.addr.bdaddr, bdaddr);
cp.addr.type = addr_type;
info("set_a2dp_state_hisi begin status==%d",status);
if(status == true)
cp.io_cap = A2DP_STATE_START;
if(status == false)
cp.io_cap = A2DP_STATE_STOP;
int ret = mgmt_send(adapter->mgmt, MGMT_OP_PAIR_DEVICE_A2DP_STATE,
adapter->dev_id, sizeof(cp), &cp,
NULL, NULL, NULL);
info("set_a2dp_state_hisi device end ret =%d", ret);
return 0;
}
void adapter_cleanup(void)
{
@ -10417,3 +10499,8 @@ bool btd_has_kernel_features(uint32_t features)
{
return (kernel_features & features) ? true : false;
}
bool adapter_get_is_huawei()
{
return is_huawei;
}

View File

@ -23,6 +23,10 @@
/* Invalid SSP passkey value used to indicate negative replies */
#define INVALID_PASSKEY 0xffffffff
#define MGMT_OP_PAIR_DEVICE_A2DP_STATE 0x0019
#define A2DP_STATE_START 0x06
#define A2DP_STATE_STOP 0x07
struct btd_adapter;
struct btd_device;
struct queue;
@ -121,6 +125,7 @@ struct btd_adapter_driver {
void device_resolved_drivers(struct btd_adapter *adapter,
struct btd_device *device);
int set_a2dp_state_hisi(bool status, struct btd_adapter *adapter, const bdaddr_t *bdaddr, uint8_t addr_type);
typedef void (*service_auth_cb) (DBusError *derr, void *user_data);
void adapter_add_profile(struct btd_adapter *adapter, gpointer p);
@ -257,3 +262,5 @@ bool btd_adapter_set_allowed_uuids(struct btd_adapter *adapter,
bool btd_adapter_is_uuid_allowed(struct btd_adapter *adapter,
const char *uuid_str);
bool one_audio_device_connection(struct btd_device *dev,struct btd_adapter *pter,uint8_t bdaddr_type);
bool adapter_get_is_huawei();

View File

@ -1741,7 +1741,7 @@ static int connect_next(struct btd_device *dev)
err = btd_service_connect(service);
if (!err)
{
DBG("seivice %s, error %d", btd_service_get_profile(service)->name, err);
DBG("service %s, error %d", btd_service_get_profile(service)->name, err);
return 0;
}
@ -2007,7 +2007,7 @@ static GSList *create_pending_list(struct btd_device *dev, const char *uuid)
if (uuid) {
service = find_connectable_service(dev, uuid);
info("null service, uuid %s", uuid);
if (!service)
return dev->pending;
@ -2033,11 +2033,19 @@ static GSList *create_pending_list(struct btd_device *dev, const char *uuid)
}
if (g_slist_find(dev->pending, service))
{
DBG("");
continue;
}
if (btd_service_get_state(service) !=
BTD_SERVICE_STATE_DISCONNECTED)
{
DBG("");
continue;
}
DBG("insert service: %s", p->name);
dev->pending = g_slist_insert_sorted(dev->pending, service,
@ -3410,7 +3418,19 @@ static void load_info(struct btd_device *device, const char *local,
if (g_str_equal(*t, "BR/EDR"))
device->bredr = true;
else if (g_str_equal(*t, "LE"))
{
//蓝牙耳机音箱 不支持 le , 防止出现 连接异常情况
const char * icon = class_to_icon(device->class);
if(icon && (strcmp(icon, "audio-headset") || strcmp(icon, "audio-headphones")))
{
DBG("device is audio, not set le, icon : %s", icon);
}
else
{
device->le = true;
DBG("device->le set true");
}
}
else
error("Unknown device technology");
}
@ -4268,7 +4288,11 @@ struct btd_device *device_create(struct btd_adapter *adapter,
if (bdaddr_type == BDADDR_BREDR)
device->bredr = true;
else
{
device->le = true;
DBG("device->le set true");
}
str = load_cached_name(device, btd_adapter_get_storage_dir(adapter),
dst);
@ -4373,6 +4397,7 @@ void device_update_addr(struct btd_device *device, const bdaddr_t *bdaddr,
* Resolving purposes we can now assume LE is supported.
*/
device->le = true;
DBG("device->le set true");
bacpy(&device->bdaddr, bdaddr);
device->bdaddr_type = bdaddr_type;
@ -4398,7 +4423,7 @@ void device_set_le_support(struct btd_device *device, uint8_t bdaddr_type)
{
if (device->le)
return;
DBG("device->le set true");
device->le = true;
device->bdaddr_type = bdaddr_type;

45
src/kylin_bluetooth.c Normal file
View File

@ -0,0 +1,45 @@
/*
*
* kylin - Bluetooth configure for Linux
*
* Copyright (C) 2023- Kylin Corporation
* Copyright (C) 2023- Dengtuo Kylin <dengtuo@kylinos.cn>
*
*
*/
#include "kylin_bluetooth.h"
bool is_huawei = false;
bool systemEnvironmentinfo(void)
{
FILE *fp;
int nread=0;
ssize_t len = 0;
char *buf=NULL;
char *buffer=NULL;
char *file = FILE_CPUINFO;
fp = fopen(file, "rb");
if (fp == NULL)
{
printf("error to open: %s\n", file);
fclose(fp);
return false;
}
while((nread = getline(&buffer, &len, fp)) != -1)
{
if((buf=strstr(buffer, "Hardware"))!=NULL &&
((buf=strstr(buffer, "HUAWEI"))!=NULL ||
(buf=strstr(buffer, "Kirin" ))!=NULL )) /* 简单实现grep的功能 */
{
fclose(fp);
return true;
}
}
fclose(fp);
return false;
}

35
src/kylin_bluetooth.h Normal file
View File

@ -0,0 +1,35 @@
/*
*
* kylin - Bluetooth configure for Linux
*
* Copyright (C) 2023- Kylin Corporation
* Copyright (C) 2023- Dengtuo Kylin <dengtuo@kylinos.cn>
*
*
*/
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <glib.h>
#include <fcntl.h>
#include <string.h>
#include <dbus/dbus.h>
#include "gdbus/gdbus.h"
#include "dbus-common.h"
#define FILE_CPUINFO "/proc/cpuinfo"
#define KYLINCONFIGDIR "/etc/bluetooth"
//运行环境配置
extern bool is_huawei;
bool systemEnvironmentinfo(void);

View File

@ -53,6 +53,8 @@
#include "agent.h"
#include "profile.h"
#include "kylin_bluetooth.h"
#define BLUEZ_NAME "org.bluez"
#define DEFAULT_PAIRABLE_TIMEOUT 0 /* disabled */
@ -61,6 +63,8 @@
#define SHUTDOWN_GRACE_SECONDS 10
#define CLASS_PC 0x00010C
struct btd_opts btd_opts;
static GKeyFile *main_conf;
static char *main_conf_file_path;
@ -903,7 +907,8 @@ static void init_defaults(void)
/* Default HCId settings */
memset(&btd_opts, 0, sizeof(btd_opts));
btd_opts.name = g_strdup_printf("BlueZ %s", VERSION);
btd_opts.class = 0x000000;
//btd_opts.class = 0x000000;
btd_opts.class = CLASS_PC;
btd_opts.pairto = DEFAULT_PAIRABLE_TIMEOUT;
btd_opts.discovto = DEFAULT_DISCOVERABLE_TIMEOUT;
btd_opts.tmpto = DEFAULT_TEMPORARY_TIMEOUT;
@ -1161,6 +1166,9 @@ int main(int argc, char *argv[])
exit(1);
}
is_huawei = systemEnvironmentinfo();
DBG("[kylin log]is_huawei : %d", is_huawei);
if (btd_opts.experimental)
gdbus_flags = G_DBUS_FLAG_ENABLE_EXPERIMENTAL;

View File

@ -1096,7 +1096,9 @@ struct uart_t uart[] = {
/* AMP controller UART */
{ "amp", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200,
AMP_DEV, DISABLE_PM, NULL, NULL, NULL },
/*Hisi Bluetooth Module */
{ "hisi", 0x0000, 0x0000, HCI_UART_H4, 115200, 4000000,
FLOW_CTL, DISABLE_PM, NULL, NULL, NULL },
{ NULL, 0 }
};
@ -1205,6 +1207,30 @@ static int init_uart(char *dev, struct uart_t *u, int send_break, int raw)
return fd;
fail:
close(fd);
return -1;
}
/* Initialize UART driver */
static int hisi_init(char *dev, struct uart_t *u)
{
printf("hisi_init\n");
int fd;
fd = open(dev, O_RDWR);
printf("dev open, fd = %d\n",fd);
if (fd < 0) {
perror("Can't open device hisi");
goto fail;
}
if (ioctl(fd, BT_IOCTL_HCISETPROTO, u->proto) < 0) {
perror("Can't set device hisi");
goto fail;
}
return fd;
fail:
close(fd);
return -1;
@ -1345,6 +1371,17 @@ int main(int argc, char *argv[])
fprintf(stderr, "Unknown device type or id\n");
exit(1);
}
/*hisi init*/
if(u->type == "hisi"){
n = hisi_init(dev,u);
if (n < 0) {
perror("Can't initialize device");
exit(1);
}
return 0;
}
/* If user specified a initial speed, use that instead of
the hardware's default */

View File

@ -14,6 +14,8 @@
#define N_HCI 15
#endif
#define BT_IOCTL_HCISETPROTO 101
#define HCIUARTSETPROTO _IOW('U', 200, int)
#define HCIUARTGETPROTO _IOR('U', 201, int)
#define HCIUARTGETDEVICE _IOR('U', 202, int)