android/daemon: Implement get adapter name
PATCH v2 1/2 android/daemon: Implement get adapter name
From: Andrei Emeltchenko <[email protected]>
--- android/adapter.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
android/adapter.c +6 -5
@@ -1017,13 +1017,14 @@ static void send_adapter_address(void)g_free (ev); } -static bool get_name (void ) +static bool send_adapter_name (void ) { -DBG ("Not implemented" ); +if (!adapter->name) +return false; -/* TODO: Add implementation */ +adapter_name_changed ((uint8_t *) adapter->name); -return false; +return true; }static bool get_uuids (void )
@@ -1098,7 +1099,7 @@ static bool get_property(void *buf, uint16_t len)send_adapter_address ();return true;case HAL_PROP_ADAPTER_NAME : -return get_name (); +return send_adapter_name ();case HAL_PROP_ADAPTER_UUIDS :return get_uuids ();case HAL_PROP_ADAPTER_CLASS :
Signature · 1 line
1.7.10.4
PATCH v2 2/2 android/daemon: Fix setting adapter name
From: Andrei Emeltchenko <[email protected]>
Android use the full string returned even if we terminate it with '\0'.
--- android/adapter.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
android/adapter.c +6 -5
@@ -145,8 +145,8 @@ static void scan_mode_changed(void)static void adapter_name_changed (const uint8_t *name) {struct hal_ev_adapter_props_changed *ev; -uint8_t buf[sizeof (*ev) +sizeof (struct hal_property ) + -HAL_MAX_NAME_LENGTH ]; +size_t len =strlen ((const char *) name); +uint8_t buf[sizeof (*ev) +sizeof (struct hal_property ) + len];memset (buf,0 ,sizeof (buf)); ev = (void *) buf;
@@ -154,10 +154,11 @@ static void adapter_name_changed(const uint8_t *name) ev->num_props =1 ; ev->status =HAL_STATUS_SUCCESS ; ev->props[0 ].type =HAL_PROP_ADAPTER_NAME ; - ev->props[0 ].len =HAL_MAX_NAME_LENGTH ; -memcpy (ev->props->val, name,HAL_MAX_NAME_LENGTH ); +/* Android expects value without NULL terminator */ + ev->props[0 ].len = len; +memcpy (ev->props->val, name, len); -DBG ("Adapter name changed to: %s" , ev->props->val); +DBG ("Adapter name changed to: %s" , name);ipc_send (notification_io,HAL_SERVICE_ID_BLUETOOTH ,HAL_EV_ADAPTER_PROPS_CHANGED ,sizeof (buf), ev,-1 );
Signature · 1 line
1.7.10.4
Luiz Augusto von Dentz
maintainerHi Andrei,
Quoted 30 lines · Andrei Emeltchenko
From: Andrei Emeltchenko <[email protected]>
--- android/adapter.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)android/adapter.c +5
-4@@ -1017,13 +1017,14 @@ static void send_adapter_address(void)g_free (ev); } -static bool get_name (void ) +static bool send_adapter_name (void ) { -DBG ("Not implemented" ); +if (!adapter->name) +return false; -/* TODO: Add implementation */ +adapter_name_changed ((uint8_t *) adapter->name); -return false; +return true; }static bool get_uuids (void )
android/adapter.c static bool get_property(void *buf, uint16_t len) · line 1102
Quoted 5 lines
android/adapter.c +1
-1@@ -1098,7 +1099,7 @@ static bool get_property(void *buf, uint16_t len)send_adapter_address ();return true;case HAL_PROP_ADAPTER_NAME : -return get_name (); +return send_adapter_name ();
Not sure why you are changing the name here, all the other properties is using the same format as get_<name of property>.
Signature · 1 line
Luiz Augusto von Dentz
Hi Luiz,
Quoted 32 lines · Luiz Augusto von Dentz
Hi Andrei,
Quoted 28 lines · Andrei Emeltchenko
From: Andrei Emeltchenko <[email protected]>
--- android/adapter.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)android/adapter.c +5
-4@@ -1017,13 +1017,14 @@ static void send_adapter_address(void)g_free (ev); } -static bool get_name (void ) +static bool send_adapter_name (void ) { -DBG ("Not implemented" ); +if (!adapter->name) +return false; -/* TODO: Add implementation */ +adapter_name_changed ((uint8_t *) adapter->name); -return false; +return true; }
Quoted 10 lines
android/adapter.c static bool get_property(void *buf, uint16_t len) · line 1102
Quoted 7 lines
android/adapter.c +1
-1static bool get_uuids (void )@@ -1098,7 +1099,7 @@ static bool get_property(void *buf, uint16_t len)send_adapter_address ();return true;case HAL_PROP_ADAPTER_NAME : -return get_name (); +return send_adapter_name ();Not sure why you are changing the name here, all the other properties is using the same format as get_<name of property>.
I am following style, look at previous function: send_adapter_address. So shall I change that one also in a separate patch?
Best regards
Andrei Emeltchenko
PATCH v3 1/4 android/daemon: Implement get adapter name
In reply to Luiz Augusto von DentzFrom: Andrei Emeltchenko <[email protected]>
Use adapter_name_changed for get_property call.
--- android/adapter.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
android/adapter.c +4 -3
@@ -1019,11 +1019,12 @@ static void send_adapter_address(void)static bool get_name (void ) { -DBG ("Not implemented" ); +if (!adapter->name) +return false; -/* TODO: Add implementation */ +adapter_name_changed ((uint8_t *) adapter->name); -return false; +return true; }static bool get_uuids (void )
Signature · 1 line
1.7.10.4
PATCH v3 2/4 android/daemon: Clean up get_address name
From: Andrei Emeltchenko <[email protected]>
Make function name consistent with the rest of the code.
--- android/adapter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
android/adapter.c +2 -2
@@ -995,7 +995,7 @@ static bool set_discoverable(uint8_t mode, uint16_t timeout)return false; } -static void send_adapter_address (void ) +static void get_address (void ) {struct hal_ev_adapter_props_changed *ev;int len;
@@ -1096,7 +1096,7 @@ static bool get_property(void *buf, uint16_t len)switch (cmd->type) {case HAL_PROP_ADAPTER_ADDR : -send_adapter_address (); +get_address ();return true;case HAL_PROP_ADAPTER_NAME :return get_name ();
Signature · 1 line
1.7.10.4
PATCH v3 3/4 android/daemon: Fix setting adapter name
In reply to Andrei EmeltchenkoFrom: Andrei Emeltchenko <[email protected]>
Android use the full string returned even if we terminate it with '\0'.
--- android/adapter.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
android/adapter.c +6 -5
@@ -145,8 +145,8 @@ static void scan_mode_changed(void)static void adapter_name_changed (const uint8_t *name) {struct hal_ev_adapter_props_changed *ev; -uint8_t buf[sizeof (*ev) +sizeof (struct hal_property ) + -HAL_MAX_NAME_LENGTH ]; +size_t len =strlen ((const char *) name); +uint8_t buf[sizeof (*ev) +sizeof (struct hal_property ) + len];memset (buf,0 ,sizeof (buf)); ev = (void *) buf;
@@ -154,10 +154,11 @@ static void adapter_name_changed(const uint8_t *name) ev->num_props =1 ; ev->status =HAL_STATUS_SUCCESS ; ev->props[0 ].type =HAL_PROP_ADAPTER_NAME ; - ev->props[0 ].len =HAL_MAX_NAME_LENGTH ; -memcpy (ev->props->val, name,HAL_MAX_NAME_LENGTH ); +/* Android expects value without NULL terminator */ + ev->props[0 ].len = len; +memcpy (ev->props->val, name, len); -DBG ("Adapter name changed to: %s" , ev->props->val); +DBG ("Adapter name changed to: %s" , name);ipc_send (notification_io,HAL_SERVICE_ID_BLUETOOTH ,HAL_EV_ADAPTER_PROPS_CHANGED ,sizeof (buf), ev,-1 );
Signature · 1 line
1.7.10.4
PATCH v3 4/4 android: Fix printing not NULL terminated strings
In reply to Andrei EmeltchenkoFrom: Andrei Emeltchenko <[email protected]>
Android passes not NULL terminated strings.
--- android/client/textconv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
android/client/textconv.c +2 -1
@@ -258,7 +258,8 @@ char *btproperty2str(const bt_property_t *property)switch (property->type) {case BT_PROPERTY_BDNAME :case BT_PROPERTY_REMOTE_FRIENDLY_NAME : -sprintf (p,"%s" , ((bt_bdname_t *) property->val)->name); +snprintf (p, property->len +1 ,"%s" , + ((bt_bdname_t *) property->val)->name);break ;case BT_PROPERTY_BDADDR :
Signature · 1 line
1.7.10.4
Hi Andrei,
Quoted 4 lines · Andrei Emeltchenko
Use
adapter_name_changedforget_propertycall.--- android/adapter.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
All four patches have been applied. Thanks.
Johan