From 51185f0fa5f13d8f2773caaedf13e01c68c6b2b1 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Tue, 10 Dec 2013 16:06:21 +0100 Subject: [PATCH] android/bluetooth: Add send_device_property helper function Remote device property notification will be send from multiple places so it make sense to have helper for that. This will be especially usefull for 'simple' properties. --- android/bluetooth.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/android/bluetooth.c b/android/bluetooth.c index 483396cec..b1d2c7191 100644 --- a/android/bluetooth.c +++ b/android/bluetooth.c @@ -574,26 +574,27 @@ static void new_link_key_callback(uint16_t index, uint16_t length, browse_remote_sdp(&addr->bdaddr); } - -static uint8_t get_device_name(struct device *dev) +static void send_device_property(const bdaddr_t *bdaddr, uint8_t type, + uint16_t len, const void *val) { - struct hal_ev_remote_device_props *ev; - size_t ev_len; - - ev_len = BASELEN_REMOTE_DEV_PROP + strlen(dev->name); - ev = g_malloc0(ev_len); + uint8_t buf[BASELEN_REMOTE_DEV_PROP + len]; + struct hal_ev_remote_device_props *ev = (void *) buf; ev->status = HAL_STATUS_SUCCESS; - bdaddr2android(&dev->bdaddr, ev->bdaddr); + bdaddr2android(bdaddr, ev->bdaddr); ev->num_props = 1; - ev->props[0].type = HAL_PROP_DEVICE_NAME; - ev->props[0].len = strlen(dev->name); - memcpy(&ev->props[0].val, dev->name, strlen(dev->name)); + ev->props[0].type = type; + ev->props[0].len = len; + memcpy(ev->props[0].val, val, len); ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_REMOTE_DEVICE_PROPS, - ev_len, ev); + sizeof(buf), buf); +} - g_free(ev); +static uint8_t get_device_name(struct device *dev) +{ + send_device_property(&dev->bdaddr, HAL_PROP_DEVICE_NAME, + strlen(dev->name), dev->name); return HAL_STATUS_SUCCESS; } -- 2.47.3