linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC BlueZ 1/4] Add Bluetooth address type in sockaddr_l2
@ 2012-04-04 20:16 Claudio Takahasi
  2012-04-04 20:16 ` [RFC BlueZ 2/4] btio: Add address type in bt_io_connect Claudio Takahasi
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Claudio Takahasi @ 2012-04-04 20:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

This patch adds the address type information to sockaddr_l2 structure,
allowing the userspace to inform the remote address type required for
LE Create Connection command.
---
 lib/l2cap.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/lib/l2cap.h b/lib/l2cap.h
index 5806aaa..5ce94c4 100644
--- a/lib/l2cap.h
+++ b/lib/l2cap.h
@@ -43,6 +43,7 @@ struct sockaddr_l2 {
 	unsigned short	l2_psm;
 	bdaddr_t	l2_bdaddr;
 	unsigned short	l2_cid;
+	uint8_t		l2_bdaddr_type;
 };
 
 /* L2CAP socket options */
-- 
1.7.8.5


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

* [RFC BlueZ 2/4] btio: Add address type in bt_io_connect
  2012-04-04 20:16 [RFC BlueZ 1/4] Add Bluetooth address type in sockaddr_l2 Claudio Takahasi
@ 2012-04-04 20:16 ` Claudio Takahasi
  2012-04-05 10:28   ` Johan Hedberg
  2012-04-04 20:16 ` [RFC BlueZ 3/4] Add address type for BLE bt_io_connect calls Claudio Takahasi
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: Claudio Takahasi @ 2012-04-04 20:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

This patch adds a new BtIO option to allow setting the remote Bluetooth
address type for BLE connections.
---
 btio/btio.c |   20 ++++++++++++++++----
 btio/btio.h |    1 +
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/btio/btio.c b/btio/btio.c
index 9781ec4..d553da8 100644
--- a/btio/btio.c
+++ b/btio/btio.c
@@ -51,6 +51,7 @@
 struct set_opts {
 	bdaddr_t src;
 	bdaddr_t dst;
+	uint8_t dst_type;
 	int defer;
 	int sec_level;
 	uint8_t channel;
@@ -280,8 +281,8 @@ static int l2cap_bind(int sock, const bdaddr_t *src, uint16_t psm,
 	return 0;
 }
 
-static int l2cap_connect(int sock, const bdaddr_t *dst,
-					uint16_t psm, uint16_t cid)
+static int l2cap_connect(int sock, const bdaddr_t *dst, uint8_t dst_type,
+						uint16_t psm, uint16_t cid)
 {
 	int err;
 	struct sockaddr_l2 addr;
@@ -294,6 +295,8 @@ static int l2cap_connect(int sock, const bdaddr_t *dst,
 	else
 		addr.l2_psm = htobs(psm);
 
+	addr.l2_bdaddr_type = dst_type;
+
 	err = connect(sock, (struct sockaddr *) &addr, sizeof(addr));
 	if (err < 0 && !(errno == EAGAIN || errno == EINPROGRESS))
 		return -errno;
@@ -714,6 +717,9 @@ static gboolean parse_set_opts(struct set_opts *opts, GError **err,
 		case BT_IO_OPT_DEST_BDADDR:
 			bacpy(&opts->dst, va_arg(args, const bdaddr_t *));
 			break;
+		case BT_IO_OPT_DEST_TYPE:
+			opts->dst_type = va_arg(args, int);
+			break;
 		case BT_IO_OPT_DEFER_TIMEOUT:
 			opts->defer = va_arg(args, int);
 			break;
@@ -875,6 +881,10 @@ static gboolean l2cap_get(int sock, GError **err, BtIOOption opt1,
 		case BT_IO_OPT_DEST_BDADDR:
 			bacpy(va_arg(args, bdaddr_t *), &dst.l2_bdaddr);
 			break;
+		case BT_IO_OPT_DEST_TYPE:
+			g_set_error(err, BT_IO_ERROR, BT_IO_ERROR_INVALID_ARGS,
+							"Not implemented");
+			return FALSE;
 		case BT_IO_OPT_DEFER_TIMEOUT:
 			len = sizeof(int);
 			if (getsockopt(sock, SOL_BLUETOOTH, BT_DEFER_SETUP,
@@ -1366,11 +1376,13 @@ GIOChannel *bt_io_connect(BtIOType type, BtIOConnect connect,
 
 	switch (type) {
 	case BT_IO_L2RAW:
-		err = l2cap_connect(sock, &opts.dst, 0, opts.cid);
+		err = l2cap_connect(sock, &opts.dst, opts.dst_type, 0,
+								opts.cid);
 		break;
 	case BT_IO_L2CAP:
 	case BT_IO_L2ERTM:
-		err = l2cap_connect(sock, &opts.dst, opts.psm, opts.cid);
+		err = l2cap_connect(sock, &opts.dst, opts.dst_type,
+							opts.psm, opts.cid);
 		break;
 	case BT_IO_RFCOMM:
 		err = rfcomm_connect(sock, &opts.dst, opts.channel);
diff --git a/btio/btio.h b/btio/btio.h
index 429e8c0..cf0e070 100644
--- a/btio/btio.h
+++ b/btio/btio.h
@@ -51,6 +51,7 @@ typedef enum {
 	BT_IO_OPT_SOURCE_BDADDR,
 	BT_IO_OPT_DEST,
 	BT_IO_OPT_DEST_BDADDR,
+	BT_IO_OPT_DEST_TYPE,
 	BT_IO_OPT_DEFER_TIMEOUT,
 	BT_IO_OPT_SEC_LEVEL,
 	BT_IO_OPT_KEY_SIZE,
-- 
1.7.8.5


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

* [RFC BlueZ 3/4] Add address type for BLE bt_io_connect calls
  2012-04-04 20:16 [RFC BlueZ 1/4] Add Bluetooth address type in sockaddr_l2 Claudio Takahasi
  2012-04-04 20:16 ` [RFC BlueZ 2/4] btio: Add address type in bt_io_connect Claudio Takahasi
@ 2012-04-04 20:16 ` Claudio Takahasi
  2012-04-05 22:38   ` [RFC BlueZ v1 3/7] " Claudio Takahasi
  2012-04-04 20:16 ` [RFC BlueZ 4/4] l2test: Add option to inform the address type Claudio Takahasi
  2012-04-05 10:30 ` [RFC BlueZ 1/4] Add Bluetooth address type in sockaddr_l2 Johan Hedberg
  3 siblings, 1 reply; 12+ messages in thread
From: Claudio Takahasi @ 2012-04-04 20:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

This patch adds the address type option in bt_io_connect calls for BLE
devices. BR/EDR is the default value, and it is not mandatory to inform
it. For BLE devices, it is necessary to inform if the type is public or
random.
---
 src/device.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/src/device.c b/src/device.c
index df3fbac..f9b2fea 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1999,6 +1999,7 @@ static gboolean att_connect(gpointer user_data)
 					attcb, NULL, &gerr,
 					BT_IO_OPT_SOURCE_BDADDR, &sba,
 					BT_IO_OPT_DEST_BDADDR, &device->bdaddr,
+					BT_IO_OPT_DEST_TYPE, device->type,
 					BT_IO_OPT_CID, ATT_CID,
 					BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
 					BT_IO_OPT_INVALID);
@@ -2084,6 +2085,7 @@ int device_browse_primary(struct btd_device *device, DBusConnection *conn,
 				attcb, NULL, NULL,
 				BT_IO_OPT_SOURCE_BDADDR, &src,
 				BT_IO_OPT_DEST_BDADDR, &device->bdaddr,
+				BT_IO_OPT_DEST_TYPE, device->type,
 				BT_IO_OPT_CID, ATT_CID,
 				BT_IO_OPT_SEC_LEVEL, sec_level,
 				BT_IO_OPT_INVALID);
@@ -2486,7 +2488,8 @@ DBusMessage *device_create_bonding(struct btd_device *device,
 		device->att_io = bt_io_connect(BT_IO_L2CAP, att_connect_cb,
 					attcb, NULL, &gerr,
 					BT_IO_OPT_SOURCE_BDADDR, &sba,
-					BT_IO_OPT_DEST_BDADDR,&device->bdaddr,
+					BT_IO_OPT_DEST_BDADDR, &device->bdaddr,
+					BT_IO_OPT_DEST_TYPE, device->type,
 					BT_IO_OPT_CID, ATT_CID,
 					BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
 					BT_IO_OPT_INVALID);
-- 
1.7.8.5


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

* [RFC BlueZ 4/4] l2test: Add option to inform the address type
  2012-04-04 20:16 [RFC BlueZ 1/4] Add Bluetooth address type in sockaddr_l2 Claudio Takahasi
  2012-04-04 20:16 ` [RFC BlueZ 2/4] btio: Add address type in bt_io_connect Claudio Takahasi
  2012-04-04 20:16 ` [RFC BlueZ 3/4] Add address type for BLE bt_io_connect calls Claudio Takahasi
@ 2012-04-04 20:16 ` Claudio Takahasi
  2012-04-05  6:35   ` Andrei Emeltchenko
  2012-04-05 10:30 ` [RFC BlueZ 1/4] Add Bluetooth address type in sockaddr_l2 Johan Hedberg
  3 siblings, 1 reply; 12+ messages in thread
From: Claudio Takahasi @ 2012-04-04 20:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andre Guedes

From: Andre Guedes <andre.guedes@openbossa.org>

This patch adds 'V' option to inform the address type. Possible values
are: 0 (BR/EDR), 1 (LE Public), and 2 (LE Random).
---
 test/l2test.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/test/l2test.c b/test/l2test.c
index ae81aec..9085d3e 100644
--- a/test/l2test.c
+++ b/test/l2test.c
@@ -87,6 +87,7 @@ static long buffer_size = 2048;
 
 /* Default addr and psm and cid */
 static bdaddr_t bdaddr;
+static unsigned char bdaddr_type;
 static unsigned short psm = 0x1011;
 static unsigned short cid = 0;
 
@@ -362,6 +363,7 @@ static int do_connect(char *svr)
 	memset(&addr, 0, sizeof(addr));
 	addr.l2_family = AF_BLUETOOTH;
 	str2ba(svr, &addr.l2_bdaddr);
+	addr.l2_bdaddr_type = bdaddr_type;
 	if (cid)
 		addr.l2_cid = htobs(cid);
 	else if (psm)
@@ -1020,6 +1022,7 @@ static void info_request(char *svr)
 	memset(&addr, 0, sizeof(addr));
 	addr.l2_family = AF_BLUETOOTH;
 	str2ba(svr, &addr.l2_bdaddr);
+	addr.l2_bdaddr_type = bdaddr_type;
 
 	if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0 ) {
 		perror("Can't connect socket");
@@ -1167,6 +1170,7 @@ static void do_pairing(char *svr)
 	memset(&addr, 0, sizeof(addr));
 	addr.l2_family = AF_BLUETOOTH;
 	str2ba(svr, &addr.l2_bdaddr);
+	addr.l2_bdaddr_type = bdaddr_type;
 
 	if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0 ) {
 		perror("Can't connect socket");
@@ -1224,7 +1228,8 @@ static void usage(void)
 		"\t[-E] request encryption\n"
 		"\t[-S] secure connection\n"
 		"\t[-M] become master\n"
-		"\t[-T] enable timestamps\n");
+		"\t[-T] enable timestamps\n"
+		"\t[-V] Set address type: 0 (BR/EDR), 1 (LE Public), 2 (LE Random)\n");
 }
 
 int main(int argc, char *argv[])
@@ -1235,7 +1240,7 @@ int main(int argc, char *argv[])
 	bacpy(&bdaddr, BDADDR_ANY);
 
 	while ((opt = getopt(argc, argv, "rdscuwmntqxyzpb:a:"
-		"i:P:I:O:J:B:N:L:W:C:D:X:F:Q:Z:Y:H:K:RUGAESMT")) != EOF) {
+		"i:P:I:O:J:B:N:L:W:C:D:X:F:Q:Z:Y:H:K:V:RUGAESMT")) != EOF) {
 		switch (opt) {
 		case 'r':
 			mode = RECV;
@@ -1430,6 +1435,10 @@ int main(int argc, char *argv[])
 			rcvbuf = atoi(optarg);
 			break;
 
+		case 'V':
+			bdaddr_type = atoi(optarg);
+			break;
+
 		default:
 			usage();
 			exit(1);
-- 
1.7.8.5


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

* Re: [RFC BlueZ 4/4] l2test: Add option to inform the address type
  2012-04-04 20:16 ` [RFC BlueZ 4/4] l2test: Add option to inform the address type Claudio Takahasi
@ 2012-04-05  6:35   ` Andrei Emeltchenko
  2012-04-05 22:38     ` [RFC BlueZ v1 7/7] " Claudio Takahasi
  2012-04-05 23:17     ` [RFC BlueZ 4/4] " Andre Guedes
  0 siblings, 2 replies; 12+ messages in thread
From: Andrei Emeltchenko @ 2012-04-05  6:35 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth, Andre Guedes

Hi Claudio,

On Wed, Apr 04, 2012 at 05:16:11PM -0300, Claudio Takahasi wrote:
...

> +	addr.l2_bdaddr_type = bdaddr_type;
>  	if (cid)

...

> @@ -1020,6 +1022,7 @@ static void info_request(char *svr)
> +	addr.l2_bdaddr_type = bdaddr_type;

...

> @@ -1167,6 +1170,7 @@ static void do_pairing(char *svr)
> +	addr.l2_bdaddr_type = bdaddr_type;

...

> +		case 'V':
> +			bdaddr_type = atoi(optarg);

Apparently there is no check that value is correct. I think that you can
use here lookup_table (see l2cap_modes and chan_policies).

Best regards 
Andrei Emeltchenko 


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

* Re: [RFC BlueZ 2/4] btio: Add address type in bt_io_connect
  2012-04-04 20:16 ` [RFC BlueZ 2/4] btio: Add address type in bt_io_connect Claudio Takahasi
@ 2012-04-05 10:28   ` Johan Hedberg
  2012-04-05 22:38     ` [RFC BlueZ v1 2/7] " Claudio Takahasi
  0 siblings, 1 reply; 12+ messages in thread
From: Johan Hedberg @ 2012-04-05 10:28 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth

Hi Claudio,

On Wed, Apr 04, 2012, Claudio Takahasi wrote:
> @@ -714,6 +717,9 @@ static gboolean parse_set_opts(struct set_opts *opts, GError **err,
>  		case BT_IO_OPT_DEST_BDADDR:
>  			bacpy(&opts->dst, va_arg(args, const bdaddr_t *));
>  			break;
> +		case BT_IO_OPT_DEST_TYPE:
> +			opts->dst_type = va_arg(args, int);
> +			break;
>  		case BT_IO_OPT_DEFER_TIMEOUT:
>  			opts->defer = va_arg(args, int);
>  			break;

I'd prefer that you also add a line to the "Set defaults" section of
this function to initialize opts->dst_type (I know the default is
implicitly 0 but it's good to have it there for clarity). Also, are you
planning to add BT_IO_* defines/enum for the types or what value is the
new BtIO API expecting to receive (this should probably be documented
and you do need to know the answer to the question before adding the
initialization line I requested).

Johan

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

* Re: [RFC BlueZ 1/4] Add Bluetooth address type in sockaddr_l2
  2012-04-04 20:16 [RFC BlueZ 1/4] Add Bluetooth address type in sockaddr_l2 Claudio Takahasi
                   ` (2 preceding siblings ...)
  2012-04-04 20:16 ` [RFC BlueZ 4/4] l2test: Add option to inform the address type Claudio Takahasi
@ 2012-04-05 10:30 ` Johan Hedberg
  2012-04-05 22:38   ` [RFC BlueZ v1 1/7] " Claudio Takahasi
  3 siblings, 1 reply; 12+ messages in thread
From: Johan Hedberg @ 2012-04-05 10:30 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth

Hi Claudio,

On Wed, Apr 04, 2012, Claudio Takahasi wrote:
> This patch adds the address type information to sockaddr_l2 structure,
> allowing the userspace to inform the remote address type required for
> LE Create Connection command.
> ---
>  lib/l2cap.h |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/lib/l2cap.h b/lib/l2cap.h
> index 5806aaa..5ce94c4 100644
> --- a/lib/l2cap.h
> +++ b/lib/l2cap.h
> @@ -43,6 +43,7 @@ struct sockaddr_l2 {
>  	unsigned short	l2_psm;
>  	bdaddr_t	l2_bdaddr;
>  	unsigned short	l2_cid;
> +	uint8_t		l2_bdaddr_type;
>  };
>  
>  /* L2CAP socket options */

To answer my question about what defines/enum values are passed to the
BtIO API, this patch should probably be adding the same BDADDR_* defines
that Andre's patch 2/5 is adding on the kernel side, and then your BtIO
patch should use BDADDR_BREDR to initialize opts->dst_type.

Johan

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

* [RFC BlueZ v1 1/7] Add Bluetooth address type in sockaddr_l2
  2012-04-05 10:30 ` [RFC BlueZ 1/4] Add Bluetooth address type in sockaddr_l2 Johan Hedberg
@ 2012-04-05 22:38   ` Claudio Takahasi
  0 siblings, 0 replies; 12+ messages in thread
From: Claudio Takahasi @ 2012-04-05 22:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

This patch adds the address type information to sockaddr_l2 structure,
allowing the userspace to inform the remote address type required for
LE Create Connection command.
---
 lib/bluetooth.h |    5 +++++
 lib/l2cap.h     |    1 +
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index 0541842..0fc4508 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -222,6 +222,11 @@ typedef struct {
 	uint8_t b[6];
 } __attribute__((packed)) bdaddr_t;
 
+/* BD Address type */
+#define BDADDR_BREDR           0x00
+#define BDADDR_LE_PUBLIC       0x01
+#define BDADDR_LE_RANDOM       0x02
+
 #define BDADDR_ANY   (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
 #define BDADDR_ALL   (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})
 #define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})
diff --git a/lib/l2cap.h b/lib/l2cap.h
index 5806aaa..5ce94c4 100644
--- a/lib/l2cap.h
+++ b/lib/l2cap.h
@@ -43,6 +43,7 @@ struct sockaddr_l2 {
 	unsigned short	l2_psm;
 	bdaddr_t	l2_bdaddr;
 	unsigned short	l2_cid;
+	uint8_t		l2_bdaddr_type;
 };
 
 /* L2CAP socket options */
-- 
1.7.8.5


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

* [RFC BlueZ v1 2/7] btio: Add address type in bt_io_connect
  2012-04-05 10:28   ` Johan Hedberg
@ 2012-04-05 22:38     ` Claudio Takahasi
  0 siblings, 0 replies; 12+ messages in thread
From: Claudio Takahasi @ 2012-04-05 22:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

This patch adds a new BtIO option to allow setting the remote Bluetooth
address type for BLE connections. Allowed values for BT_IO_OPT_DEST_TYPE
option are: BDADDR_BREDR, BDADDR_LE_PUBLIC, and BDADDR_LE_RANDOM.
---
 btio/btio.c |   21 +++++++++++++++++----
 btio/btio.h |    1 +
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/btio/btio.c b/btio/btio.c
index 9781ec4..e81fb75 100644
--- a/btio/btio.c
+++ b/btio/btio.c
@@ -51,6 +51,7 @@
 struct set_opts {
 	bdaddr_t src;
 	bdaddr_t dst;
+	uint8_t dst_type;
 	int defer;
 	int sec_level;
 	uint8_t channel;
@@ -280,8 +281,8 @@ static int l2cap_bind(int sock, const bdaddr_t *src, uint16_t psm,
 	return 0;
 }
 
-static int l2cap_connect(int sock, const bdaddr_t *dst,
-					uint16_t psm, uint16_t cid)
+static int l2cap_connect(int sock, const bdaddr_t *dst, uint8_t dst_type,
+						uint16_t psm, uint16_t cid)
 {
 	int err;
 	struct sockaddr_l2 addr;
@@ -294,6 +295,8 @@ static int l2cap_connect(int sock, const bdaddr_t *dst,
 	else
 		addr.l2_psm = htobs(psm);
 
+	addr.l2_bdaddr_type = dst_type;
+
 	err = connect(sock, (struct sockaddr *) &addr, sizeof(addr));
 	if (err < 0 && !(errno == EAGAIN || errno == EINPROGRESS))
 		return -errno;
@@ -698,6 +701,7 @@ static gboolean parse_set_opts(struct set_opts *opts, GError **err,
 	opts->mode = L2CAP_MODE_BASIC;
 	opts->flushable = -1;
 	opts->priority = 0;
+	opts->dst_type = BDADDR_BREDR;
 
 	while (opt != BT_IO_OPT_INVALID) {
 		switch (opt) {
@@ -714,6 +718,9 @@ static gboolean parse_set_opts(struct set_opts *opts, GError **err,
 		case BT_IO_OPT_DEST_BDADDR:
 			bacpy(&opts->dst, va_arg(args, const bdaddr_t *));
 			break;
+		case BT_IO_OPT_DEST_TYPE:
+			opts->dst_type = va_arg(args, int);
+			break;
 		case BT_IO_OPT_DEFER_TIMEOUT:
 			opts->defer = va_arg(args, int);
 			break;
@@ -875,6 +882,10 @@ static gboolean l2cap_get(int sock, GError **err, BtIOOption opt1,
 		case BT_IO_OPT_DEST_BDADDR:
 			bacpy(va_arg(args, bdaddr_t *), &dst.l2_bdaddr);
 			break;
+		case BT_IO_OPT_DEST_TYPE:
+			g_set_error(err, BT_IO_ERROR, BT_IO_ERROR_INVALID_ARGS,
+							"Not implemented");
+			return FALSE;
 		case BT_IO_OPT_DEFER_TIMEOUT:
 			len = sizeof(int);
 			if (getsockopt(sock, SOL_BLUETOOTH, BT_DEFER_SETUP,
@@ -1366,11 +1377,13 @@ GIOChannel *bt_io_connect(BtIOType type, BtIOConnect connect,
 
 	switch (type) {
 	case BT_IO_L2RAW:
-		err = l2cap_connect(sock, &opts.dst, 0, opts.cid);
+		err = l2cap_connect(sock, &opts.dst, opts.dst_type, 0,
+								opts.cid);
 		break;
 	case BT_IO_L2CAP:
 	case BT_IO_L2ERTM:
-		err = l2cap_connect(sock, &opts.dst, opts.psm, opts.cid);
+		err = l2cap_connect(sock, &opts.dst, opts.dst_type,
+							opts.psm, opts.cid);
 		break;
 	case BT_IO_RFCOMM:
 		err = rfcomm_connect(sock, &opts.dst, opts.channel);
diff --git a/btio/btio.h b/btio/btio.h
index 429e8c0..cf0e070 100644
--- a/btio/btio.h
+++ b/btio/btio.h
@@ -51,6 +51,7 @@ typedef enum {
 	BT_IO_OPT_SOURCE_BDADDR,
 	BT_IO_OPT_DEST,
 	BT_IO_OPT_DEST_BDADDR,
+	BT_IO_OPT_DEST_TYPE,
 	BT_IO_OPT_DEFER_TIMEOUT,
 	BT_IO_OPT_SEC_LEVEL,
 	BT_IO_OPT_KEY_SIZE,
-- 
1.7.8.5


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

* [RFC BlueZ v1 3/7] Add address type for BLE bt_io_connect calls
  2012-04-04 20:16 ` [RFC BlueZ 3/4] Add address type for BLE bt_io_connect calls Claudio Takahasi
@ 2012-04-05 22:38   ` Claudio Takahasi
  0 siblings, 0 replies; 12+ messages in thread
From: Claudio Takahasi @ 2012-04-05 22:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

This patch adds the address type option in bt_io_connect calls for BLE
devices. BR/EDR is the default value, and it is not mandatory to inform
it. For BLE devices, it is necessary to inform if the type is public or
random.
---
 src/device.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/src/device.c b/src/device.c
index df3fbac..f9b2fea 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1999,6 +1999,7 @@ static gboolean att_connect(gpointer user_data)
 					attcb, NULL, &gerr,
 					BT_IO_OPT_SOURCE_BDADDR, &sba,
 					BT_IO_OPT_DEST_BDADDR, &device->bdaddr,
+					BT_IO_OPT_DEST_TYPE, device->type,
 					BT_IO_OPT_CID, ATT_CID,
 					BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
 					BT_IO_OPT_INVALID);
@@ -2084,6 +2085,7 @@ int device_browse_primary(struct btd_device *device, DBusConnection *conn,
 				attcb, NULL, NULL,
 				BT_IO_OPT_SOURCE_BDADDR, &src,
 				BT_IO_OPT_DEST_BDADDR, &device->bdaddr,
+				BT_IO_OPT_DEST_TYPE, device->type,
 				BT_IO_OPT_CID, ATT_CID,
 				BT_IO_OPT_SEC_LEVEL, sec_level,
 				BT_IO_OPT_INVALID);
@@ -2486,7 +2488,8 @@ DBusMessage *device_create_bonding(struct btd_device *device,
 		device->att_io = bt_io_connect(BT_IO_L2CAP, att_connect_cb,
 					attcb, NULL, &gerr,
 					BT_IO_OPT_SOURCE_BDADDR, &sba,
-					BT_IO_OPT_DEST_BDADDR,&device->bdaddr,
+					BT_IO_OPT_DEST_BDADDR, &device->bdaddr,
+					BT_IO_OPT_DEST_TYPE, device->type,
 					BT_IO_OPT_CID, ATT_CID,
 					BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
 					BT_IO_OPT_INVALID);
-- 
1.7.8.5


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

* [RFC BlueZ v1 7/7] l2test: Add option to inform the address type
  2012-04-05  6:35   ` Andrei Emeltchenko
@ 2012-04-05 22:38     ` Claudio Takahasi
  2012-04-05 23:17     ` [RFC BlueZ 4/4] " Andre Guedes
  1 sibling, 0 replies; 12+ messages in thread
From: Claudio Takahasi @ 2012-04-05 22:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andre Guedes

From: Andre Guedes <andre.guedes@openbossa.org>

This patch adds 'V' option to inform the address type. Possible values
are: "bredr", "le_public", and "le_random".
---
 test/l2test.c |   27 +++++++++++++++++++++++++--
 1 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/test/l2test.c b/test/l2test.c
index ae81aec..f66486d 100644
--- a/test/l2test.c
+++ b/test/l2test.c
@@ -117,6 +117,7 @@ static int defer_setup = 0;
 static int priority = -1;
 static int rcvbuf = 0;
 static int chan_policy = -1;
+static int bdaddr_type = 0;
 
 struct lookup_table {
 	char	*name;
@@ -141,6 +142,13 @@ static struct lookup_table chan_policies[] = {
 	{ NULL,		0					},
 };
 
+static struct lookup_table bdaddr_types[] = {
+	{ "bredr",	BDADDR_BREDR		},
+	{ "le_public",	BDADDR_LE_PUBLIC	},
+	{ "le_random",	BDADDR_LE_RANDOM	},
+	{ NULL,		0			},
+};
+
 static int get_lookup_flag(struct lookup_table *table, char *name)
 {
 	int i;
@@ -362,6 +370,7 @@ static int do_connect(char *svr)
 	memset(&addr, 0, sizeof(addr));
 	addr.l2_family = AF_BLUETOOTH;
 	str2ba(svr, &addr.l2_bdaddr);
+	addr.l2_bdaddr_type = bdaddr_type;
 	if (cid)
 		addr.l2_cid = htobs(cid);
 	else if (psm)
@@ -1020,6 +1029,7 @@ static void info_request(char *svr)
 	memset(&addr, 0, sizeof(addr));
 	addr.l2_family = AF_BLUETOOTH;
 	str2ba(svr, &addr.l2_bdaddr);
+	addr.l2_bdaddr_type = bdaddr_type;
 
 	if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0 ) {
 		perror("Can't connect socket");
@@ -1167,6 +1177,7 @@ static void do_pairing(char *svr)
 	memset(&addr, 0, sizeof(addr));
 	addr.l2_family = AF_BLUETOOTH;
 	str2ba(svr, &addr.l2_bdaddr);
+	addr.l2_bdaddr_type = bdaddr_type;
 
 	if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0 ) {
 		perror("Can't connect socket");
@@ -1224,7 +1235,8 @@ static void usage(void)
 		"\t[-E] request encryption\n"
 		"\t[-S] secure connection\n"
 		"\t[-M] become master\n"
-		"\t[-T] enable timestamps\n");
+		"\t[-T] enable timestamps\n"
+		"\t[-V type] address type (help for list, default = bredr)\n");
 }
 
 int main(int argc, char *argv[])
@@ -1235,7 +1247,7 @@ int main(int argc, char *argv[])
 	bacpy(&bdaddr, BDADDR_ANY);
 
 	while ((opt = getopt(argc, argv, "rdscuwmntqxyzpb:a:"
-		"i:P:I:O:J:B:N:L:W:C:D:X:F:Q:Z:Y:H:K:RUGAESMT")) != EOF) {
+		"i:P:I:O:J:B:N:L:W:C:D:X:F:Q:Z:Y:H:K:V:RUGAESMT")) != EOF) {
 		switch (opt) {
 		case 'r':
 			mode = RECV;
@@ -1430,6 +1442,17 @@ int main(int argc, char *argv[])
 			rcvbuf = atoi(optarg);
 			break;
 
+		case 'V':
+			bdaddr_type = get_lookup_flag(bdaddr_types, optarg);
+
+			if (bdaddr_type == -1) {
+				print_lookup_values(bdaddr_types,
+						"List Address types:");
+				exit(1);
+			}
+
+			break;
+
 		default:
 			usage();
 			exit(1);
-- 
1.7.8.5


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

* Re: [RFC BlueZ 4/4] l2test: Add option to inform the address type
  2012-04-05  6:35   ` Andrei Emeltchenko
  2012-04-05 22:38     ` [RFC BlueZ v1 7/7] " Claudio Takahasi
@ 2012-04-05 23:17     ` Andre Guedes
  1 sibling, 0 replies; 12+ messages in thread
From: Andre Guedes @ 2012-04-05 23:17 UTC (permalink / raw)
  To: Andrei Emeltchenko, linux-bluetooth

Hi Andrei,

On Thu, Apr 5, 2012 at 3:35 AM, Andrei Emeltchenko
<andrei.emeltchenko.news@gmail.com> wrote:
> Hi Claudio,
>
> On Wed, Apr 04, 2012 at 05:16:11PM -0300, Claudio Takahasi wrote:
> ...
>
>> +     addr.l2_bdaddr_type = bdaddr_type;
>>       if (cid)
>
> ...
>
>> @@ -1020,6 +1022,7 @@ static void info_request(char *svr)
>> +     addr.l2_bdaddr_type = bdaddr_type;
>
> ...
>
>> @@ -1167,6 +1170,7 @@ static void do_pairing(char *svr)
>> +     addr.l2_bdaddr_type = bdaddr_type;
>
> ...
>
>> +             case 'V':
>> +                     bdaddr_type = atoi(optarg);
>
> Apparently there is no check that value is correct. I think that you can
> use here lookup_table (see l2cap_modes and chan_policies).

Sure, I'll do it.

Thanks,

Andre

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

end of thread, other threads:[~2012-04-05 23:17 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-04 20:16 [RFC BlueZ 1/4] Add Bluetooth address type in sockaddr_l2 Claudio Takahasi
2012-04-04 20:16 ` [RFC BlueZ 2/4] btio: Add address type in bt_io_connect Claudio Takahasi
2012-04-05 10:28   ` Johan Hedberg
2012-04-05 22:38     ` [RFC BlueZ v1 2/7] " Claudio Takahasi
2012-04-04 20:16 ` [RFC BlueZ 3/4] Add address type for BLE bt_io_connect calls Claudio Takahasi
2012-04-05 22:38   ` [RFC BlueZ v1 3/7] " Claudio Takahasi
2012-04-04 20:16 ` [RFC BlueZ 4/4] l2test: Add option to inform the address type Claudio Takahasi
2012-04-05  6:35   ` Andrei Emeltchenko
2012-04-05 22:38     ` [RFC BlueZ v1 7/7] " Claudio Takahasi
2012-04-05 23:17     ` [RFC BlueZ 4/4] " Andre Guedes
2012-04-05 10:30 ` [RFC BlueZ 1/4] Add Bluetooth address type in sockaddr_l2 Johan Hedberg
2012-04-05 22:38   ` [RFC BlueZ v1 1/7] " Claudio Takahasi

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).