linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] tools/btpclient: Use address convertion function from libbluetooth
@ 2018-01-16 14:03 Szymon Janc
  2018-01-16 14:03 ` [PATCH 2/2] shared/btp: Use bdaddr_t for storing address Szymon Janc
  2018-01-17 10:30 ` [PATCH 1/2] tools/btpclient: Use address convertion function from libbluetooth Szymon Janc
  0 siblings, 2 replies; 3+ messages in thread
From: Szymon Janc @ 2018-01-16 14:03 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

There is no need for internal helper.
---
 Makefile.tools    |  2 +-
 tools/btpclient.c | 12 ++++--------
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/Makefile.tools b/Makefile.tools
index 651ff00ca..71d083e71 100644
--- a/Makefile.tools
+++ b/Makefile.tools
@@ -450,5 +450,5 @@ noinst_PROGRAMS += tools/btpclient
 
 tools_btpclient_SOURCES = tools/btpclient.c src/shared/btp.c src/shared/btp.h
 tools_btpclient_CFLAGS = $(AM_CFLAGS) @ELL_CFLAGS@
-tools_btpclient_LDADD = @ELL_LIBS@
+tools_btpclient_LDADD = @ELL_LIBS@ lib/libbluetooth-internal.la
 endif
diff --git a/tools/btpclient.c b/tools/btpclient.c
index 806403f6a..4d4475a07 100644
--- a/tools/btpclient.c
+++ b/tools/btpclient.c
@@ -32,6 +32,7 @@
 
 #include <ell/ell.h>
 
+#include "lib/bluetooth.h"
 #include "src/shared/btp.h"
 
 struct btp_adapter {
@@ -53,12 +54,6 @@ static struct btp *btp;
 
 static bool gap_service_registered;
 
-static bool str2addr(const char *str, uint8_t *addr)
-{
-	return sscanf(str, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &addr[5], &addr[4],
-				&addr[3], &addr[2], &addr[1], &addr[0]) == 6;
-}
-
 static struct btp_adapter *find_adapter_by_proxy(struct l_dbus_proxy *proxy)
 {
 	const struct l_queue_entry *entry;
@@ -181,7 +176,8 @@ static void btp_gap_read_info(uint8_t index, const void *param, uint16_t length,
 	if (!l_dbus_proxy_get_property(adapter->proxy, "Address", "s", &str))
 		goto failed;
 
-	if (!str2addr(str, rp.address))
+
+	if (str2ba(str, (bdaddr_t *)rp.address) < 0)
 		goto failed;
 
 	if (!l_dbus_proxy_get_property(adapter->proxy, "Name", "s", &str)) {
@@ -674,7 +670,7 @@ static void btp_gap_device_found_ev(struct l_dbus_proxy *proxy)
 	int16_t rssi;
 
 	if (!l_dbus_proxy_get_property(proxy, "Address", "s", &str) ||
-						!str2addr(str, ev.address))
+						str2ba(str, (bdaddr_t *)ev.address) < 0)
 		return;
 
 	if (!l_dbus_proxy_get_property(proxy, "AddressType", "s", &str))
-- 
2.14.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] shared/btp: Use bdaddr_t for storing address
  2018-01-16 14:03 [PATCH 1/2] tools/btpclient: Use address convertion function from libbluetooth Szymon Janc
@ 2018-01-16 14:03 ` Szymon Janc
  2018-01-17 10:30 ` [PATCH 1/2] tools/btpclient: Use address convertion function from libbluetooth Szymon Janc
  1 sibling, 0 replies; 3+ messages in thread
From: Szymon Janc @ 2018-01-16 14:03 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This is more convenient as it allows to use common helpers for address
comparison and convertion.
---
 src/shared/btp.c  |  1 +
 src/shared/btp.h  | 30 +++++++++++++++---------------
 tools/btpclient.c |  4 ++--
 3 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/src/shared/btp.c b/src/shared/btp.c
index d981621a8..77622671c 100644
--- a/src/shared/btp.c
+++ b/src/shared/btp.c
@@ -28,6 +28,7 @@
 
 #include <ell/ell.h>
 
+#include "lib/bluetooth.h"
 #include "src/shared/btp.h"
 
 #define BTP_MTU 512
diff --git a/src/shared/btp.h b/src/shared/btp.h
index 7b1f48817..0b605be18 100644
--- a/src/shared/btp.h
+++ b/src/shared/btp.h
@@ -97,7 +97,7 @@ struct btp_gap_read_index_rp {
 
 #define BTP_OP_GAP_READ_COTROLLER_INFO		0x03
 struct btp_gap_read_info_rp {
-	uint8_t address[6];
+	bdaddr_t address;
 	uint32_t supported_settings;
 	uint32_t current_settings;
 	uint8_t cod[3];
@@ -190,13 +190,13 @@ struct btp_gap_start_discovery_cp {
 #define BTP_OP_GAP_CONNECT			0x0e
 struct btp_gap_connect_cp {
 	uint8_t address_type;
-	uint8_t address[6];
+	bdaddr_t address;
 } __packed;
 
 #define BTP_OP_GAP_DISCONNECT			0x0f
 struct btp_gap_disconnect_cp {
 	uint8_t address_type;
-	uint8_t address[6];
+	bdaddr_t address;
 } __packed;
 
 #define BTP_GAP_IOCAPA_DISPLAY_ONLY		0x00
@@ -213,26 +213,26 @@ struct btp_gap_set_io_capa_cp {
 #define BTP_OP_GAP_PAIR				0x11
 struct btp_gap_pair_cp {
 	uint8_t address_type;
-	uint8_t address[6];
+	bdaddr_t address;
 } __packed;
 
 #define BTP_OP_GAP_UNPAIR			0x12
 struct btp_gap_unpair_cp {
 	uint8_t address_type;
-	uint8_t address[6];
+	bdaddr_t address;
 } __packed;
 
 #define BTP_OP_GAP_PASSKEY_ENTRY_RSP		0x13
 struct btp_gap_passkey_entry_rsp_cp {
 	uint8_t address_type;
-	uint8_t address[6];
+	bdaddr_t address;
 	uint32_t passkey;
 } __packed;
 
 #define BTP_OP_GAP_PASSKEY_CONFIRM_RSP		0x14
 struct btp_gap_passkey_confirm_rsp_cp {
 	uint8_t address_type;
-	uint8_t address[6];
+	bdaddr_t address;
 	uint8_t match;
 } __packed;
 
@@ -247,7 +247,7 @@ struct btp_new_settings_ev {
 
 #define BTP_EV_GAP_DEVICE_FOUND			0x81
 struct btp_device_found_ev {
-	uint8_t address[6];
+	bdaddr_t address;
 	uint8_t address_type;
 	int8_t rssi;
 	uint8_t flags;
@@ -258,41 +258,41 @@ struct btp_device_found_ev {
 #define BTP_EV_GAP_DEVICE_CONNECTED		0x82
 struct btp_gap_device_connected_ev {
 	uint8_t address_type;
-	uint8_t address[6];
+	bdaddr_t address;
 } __packed;
 
 #define BTP_EV_GAP_DEVICE_DISCONNECTED		0x83
 struct btp_gap_device_disconnected_ev {
 	uint8_t address_type;
-	uint8_t address[6];
+	bdaddr_t address;
 } __packed;
 
 #define BTP_EV_GAP_PASSKEY_DISPLAY		0x84
 struct btp_gap_passkey_display_ev {
 	uint8_t address_type;
-	uint8_t address[6];
+	bdaddr_t address;
 	uint32_t passkey;
 } __packed;
 
 #define BTP_EV_GAP_PASSKEY_REQUEST		0x85
 struct btp_gap_passkey_req_ev {
 	uint8_t address_type;
-	uint8_t address[6];
+	bdaddr_t address;
 } __packed;
 
 #define BTP_EV_GAP_PASSKEY_CONFIRM		0x86
 struct btp_gap_passkey_confirm_ev {
 	uint8_t address_type;
-	uint8_t address[6];
+	bdaddr_t address;
 	uint32_t passkey;
 } __packed;
 
 #define BTP_EV_GAP_IDENTITY_RESOLVED		0x87
 struct btp_gap_identity_resolved_ev {
 	uint8_t address_type;
-	uint8_t address[6];
+	bdaddr_t address;
 	uint8_t identity_address_type;
-	uint8_t identity_address[6];
+	bdaddr_t identity_address;
 } __packed;
 
 struct btp;
diff --git a/tools/btpclient.c b/tools/btpclient.c
index 4d4475a07..8d5545015 100644
--- a/tools/btpclient.c
+++ b/tools/btpclient.c
@@ -177,7 +177,7 @@ static void btp_gap_read_info(uint8_t index, const void *param, uint16_t length,
 		goto failed;
 
 
-	if (str2ba(str, (bdaddr_t *)rp.address) < 0)
+	if (str2ba(str, &rp.address) < 0)
 		goto failed;
 
 	if (!l_dbus_proxy_get_property(adapter->proxy, "Name", "s", &str)) {
@@ -670,7 +670,7 @@ static void btp_gap_device_found_ev(struct l_dbus_proxy *proxy)
 	int16_t rssi;
 
 	if (!l_dbus_proxy_get_property(proxy, "Address", "s", &str) ||
-						str2ba(str, (bdaddr_t *)ev.address) < 0)
+						str2ba(str, &ev.address) < 0)
 		return;
 
 	if (!l_dbus_proxy_get_property(proxy, "AddressType", "s", &str))
-- 
2.14.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] tools/btpclient: Use address convertion function from libbluetooth
  2018-01-16 14:03 [PATCH 1/2] tools/btpclient: Use address convertion function from libbluetooth Szymon Janc
  2018-01-16 14:03 ` [PATCH 2/2] shared/btp: Use bdaddr_t for storing address Szymon Janc
@ 2018-01-17 10:30 ` Szymon Janc
  1 sibling, 0 replies; 3+ messages in thread
From: Szymon Janc @ 2018-01-17 10:30 UTC (permalink / raw)
  To: linux-bluetooth

On Tuesday, 16 January 2018 15:03:32 CET Szymon Janc wrote:
> There is no need for internal helper.
> ---
>  Makefile.tools    |  2 +-
>  tools/btpclient.c | 12 ++++--------
>  2 files changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/Makefile.tools b/Makefile.tools
> index 651ff00ca..71d083e71 100644
> --- a/Makefile.tools
> +++ b/Makefile.tools
> @@ -450,5 +450,5 @@ noinst_PROGRAMS += tools/btpclient
> 
>  tools_btpclient_SOURCES = tools/btpclient.c src/shared/btp.c
> src/shared/btp.h tools_btpclient_CFLAGS = $(AM_CFLAGS) @ELL_CFLAGS@
> -tools_btpclient_LDADD = @ELL_LIBS@
> +tools_btpclient_LDADD = @ELL_LIBS@ lib/libbluetooth-internal.la
>  endif
> diff --git a/tools/btpclient.c b/tools/btpclient.c
> index 806403f6a..4d4475a07 100644
> --- a/tools/btpclient.c
> +++ b/tools/btpclient.c
> @@ -32,6 +32,7 @@
> 
>  #include <ell/ell.h>
> 
> +#include "lib/bluetooth.h"
>  #include "src/shared/btp.h"
> 
>  struct btp_adapter {
> @@ -53,12 +54,6 @@ static struct btp *btp;
> 
>  static bool gap_service_registered;
> 
> -static bool str2addr(const char *str, uint8_t *addr)
> -{
> -	return sscanf(str, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &addr[5], &addr[4],
> -				&addr[3], &addr[2], &addr[1], &addr[0]) == 6;
> -}
> -
>  static struct btp_adapter *find_adapter_by_proxy(struct l_dbus_proxy
> *proxy) {
>  	const struct l_queue_entry *entry;
> @@ -181,7 +176,8 @@ static void btp_gap_read_info(uint8_t index, const void
> *param, uint16_t length, if (!l_dbus_proxy_get_property(adapter->proxy,
> "Address", "s", &str)) goto failed;
> 
> -	if (!str2addr(str, rp.address))
> +
> +	if (str2ba(str, (bdaddr_t *)rp.address) < 0)
>  		goto failed;
> 
>  	if (!l_dbus_proxy_get_property(adapter->proxy, "Name", "s", &str)) {
> @@ -674,7 +670,7 @@ static void btp_gap_device_found_ev(struct l_dbus_proxy
> *proxy) int16_t rssi;
> 
>  	if (!l_dbus_proxy_get_property(proxy, "Address", "s", &str) ||
> -						!str2addr(str, ev.address))
> +						str2ba(str, (bdaddr_t *)ev.address) < 0)
>  		return;
> 
>  	if (!l_dbus_proxy_get_property(proxy, "AddressType", "s", &str))

Applied.

-- 
pozdrawiam
Szymon Janc



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-01-17 10:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-16 14:03 [PATCH 1/2] tools/btpclient: Use address convertion function from libbluetooth Szymon Janc
2018-01-16 14:03 ` [PATCH 2/2] shared/btp: Use bdaddr_t for storing address Szymon Janc
2018-01-17 10:30 ` [PATCH 1/2] tools/btpclient: Use address convertion function from libbluetooth Szymon Janc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).