linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] Bluetooth: Add basic discovery commands to the management interface
@ 2011-04-19 21:35 anderson.briglia
  2011-04-19 21:58 ` Johan Hedberg
  0 siblings, 1 reply; 5+ messages in thread
From: anderson.briglia @ 2011-04-19 21:35 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Johan Hedberg, Anderson Briglia

From: Johan Hedberg <johan.hedberg@nokia.com>

This patch adds start_discovery and stop_discovery commands to the
management interface. Right now their implementation is fairly
simplistic and the parameters are fixed to what user space has
defaulted to so far.
This is the very initial phase for discovery implementation into
the kernel. Next steps include name resolution, LE scanning and
bdaddr type handling.

Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
Signed-off-by: Anderson Briglia <anderson.briglia@openbossa.org>
---
 include/net/bluetooth/mgmt.h |    4 ++
 net/bluetooth/mgmt.c         |   77 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 80 insertions(+), 1 deletions(-)

diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 6b6ff92..be93dd0 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -195,6 +195,10 @@ struct mgmt_cp_remove_remote_oob_data {
 	bdaddr_t bdaddr;
 } __packed;
 
+#define MGMT_OP_START_DISCOVERY		0x001B
+
+#define MGMT_OP_STOP_DISCOVERY		0x001C
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	__le16 opcode;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index c304688..958544a 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1569,6 +1569,75 @@ static int remove_remote_oob_data(struct sock *sk, u16 index,
 	return err;
 }
 
+static int start_discovery(struct sock *sk, u16 index)
+{
+	u8 lap[3] = { 0x33, 0x8b, 0x9e };
+	struct hci_cp_inquiry cp;
+	struct pending_cmd *cmd;
+	struct hci_dev *hdev;
+	int err;
+
+	BT_DBG("hci%u ", index);
+
+	hdev = hci_dev_get(index);
+	if (!hdev)
+		return cmd_status(sk, index, MGMT_OP_START_DISCOVERY, ENODEV);
+
+	hci_dev_lock_bh(hdev);
+
+	cmd = mgmt_pending_add(sk, MGMT_OP_START_DISCOVERY, index, NULL, 0);
+	if (!cmd) {
+		err = -ENOMEM;
+		goto failed;
+	}
+
+	memset(&cp, 0, sizeof(cp));
+	memcpy(&cp.lap, lap, 3);
+	cp.length  = 0x08;
+	cp.num_rsp = 0x00;
+
+	err = hci_send_cmd(hdev, HCI_OP_INQUIRY, sizeof(cp), &cp);
+	if (err < 0)
+		mgmt_pending_remove(cmd);
+
+failed:
+	hci_dev_unlock_bh(hdev);
+	hci_dev_put(hdev);
+
+	return err;
+}
+
+static int stop_discovery(struct sock *sk, u16 index)
+{
+	struct hci_dev *hdev;
+	struct pending_cmd *cmd;
+	int err;
+
+	BT_DBG("hci%u ", index);
+
+	hdev = hci_dev_get(index);
+	if (!hdev)
+		return cmd_status(sk, index, MGMT_OP_STOP_DISCOVERY, ENODEV);
+
+	hci_dev_lock_bh(hdev);
+
+	cmd = mgmt_pending_add(sk, MGMT_OP_STOP_DISCOVERY, index, NULL, 0);
+	if (!cmd) {
+		err = -ENOMEM;
+		goto failed;
+	}
+
+	err = hci_send_cmd(hdev, HCI_OP_INQUIRY_CANCEL, 0, NULL);
+	if (err < 0)
+		mgmt_pending_remove(cmd);
+
+failed:
+	hci_dev_unlock_bh(hdev);
+	hci_dev_put(hdev);
+
+	return err;
+}
+
 int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
 {
 	unsigned char *buf;
@@ -1677,7 +1746,12 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
 		err = remove_remote_oob_data(sk, index, buf + sizeof(*hdr),
 									len);
 		break;
-
+	case MGMT_OP_START_DISCOVERY:
+		err = start_discovery(sk, index);
+		break;
+	case MGMT_OP_STOP_DISCOVERY:
+		err = stop_discovery(sk, index);
+		break;
 	default:
 		BT_DBG("Unknown op %u", opcode);
 		err = cmd_status(sk, index, opcode, 0x01);
@@ -2075,3 +2149,4 @@ int mgmt_remote_name(u16 index, bdaddr_t *bdaddr, u8 *name)
 
 	return mgmt_event(MGMT_EV_REMOTE_NAME, index, &ev, sizeof(ev), NULL);
 }
+
-- 
1.7.1


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

* Re: [PATCH 1/2] Bluetooth: Add basic discovery commands to the management interface
  2011-04-19 21:35 [PATCH 1/2] Bluetooth: Add basic discovery commands to the management interface anderson.briglia
@ 2011-04-19 21:58 ` Johan Hedberg
  2011-04-20 12:33   ` Anderson Briglia
  0 siblings, 1 reply; 5+ messages in thread
From: Johan Hedberg @ 2011-04-19 21:58 UTC (permalink / raw)
  To: anderson.briglia; +Cc: linux-bluetooth

Hi Briglia,

On Tue, Apr 19, 2011, anderson.briglia@openbossa.org wrote:
> From: Johan Hedberg <johan.hedberg@nokia.com>
> 
> This patch adds start_discovery and stop_discovery commands to the
> management interface. Right now their implementation is fairly
> simplistic and the parameters are fixed to what user space has
> defaulted to so far.
> This is the very initial phase for discovery implementation into
> the kernel. Next steps include name resolution, LE scanning and
> bdaddr type handling.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
> Signed-off-by: Anderson Briglia <anderson.briglia@openbossa.org>
> ---
>  include/net/bluetooth/mgmt.h |    4 ++
>  net/bluetooth/mgmt.c         |   77 +++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 80 insertions(+), 1 deletions(-)

I'd appreciate it if you'd check with me first before going about
sending patches in my name that I haven't 100% authored. There are e.g.
some coding style things I'd have cleaned up before making this public.
Depending on the amount of code changed (maybe not enough for this case
though) you could have even put yourself as author and simply mentioned
"Based on original code by Johan..." somewhere in the commit message.

Johan

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

* Re: [PATCH 1/2] Bluetooth: Add basic discovery commands to the management interface
  2011-04-19 21:58 ` Johan Hedberg
@ 2011-04-20 12:33   ` Anderson Briglia
  2011-04-20 13:09     ` Johan Hedberg
  0 siblings, 1 reply; 5+ messages in thread
From: Anderson Briglia @ 2011-04-20 12:33 UTC (permalink / raw)
  To: anderson.briglia, linux-bluetooth

Hi Johan,

On Tue, Apr 19, 2011 at 5:58 PM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> Hi Briglia,
>
> On Tue, Apr 19, 2011, anderson.briglia@openbossa.org wrote:
>> From: Johan Hedberg <johan.hedberg@nokia.com>
>>
>> This patch adds start_discovery and stop_discovery commands to the
>> management interface. Right now their implementation is fairly
>> simplistic and the parameters are fixed to what user space has
>> defaulted to so far.
>> This is the very initial phase for discovery implementation into
>> the kernel. Next steps include name resolution, LE scanning and
>> bdaddr type handling.
>>
>> Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
>> Signed-off-by: Anderson Briglia <anderson.briglia@openbossa.org>
>> ---
>>  include/net/bluetooth/mgmt.h |    4 ++
>>  net/bluetooth/mgmt.c         |   77 +++++++++++++++++++++++++++++++++++++++++-
>>  2 files changed, 80 insertions(+), 1 deletions(-)
>
> I'd appreciate it if you'd check with me first before going about
> sending patches in my name that I haven't 100% authored. There are e.g.
> some coding style things I'd have cleaned up before making this public.
> Depending on the amount of code changed (maybe not enough for this case
> though) you could have even put yourself as author and simply mentioned
> "Based on original code by Johan..." somewhere in the commit message.

Yes, you're right. Actually I thought just the "Signed-off-by" adding
myself would be enough since the code is pretty much the same and you
had already sent this few weeks ago. Anyway I should contact you first
before send to the mailing list, sorry.
What do you prefer? I modify the commit message and the patch
authoring (and send it again)? Which coding style issues did you
notice?

Regards,

Anderson Briglia

>
> Johan
>



-- 
INdT - Instituto Nokia de tecnologia
+55 2126 1122
http://techblog.briglia.net

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

* Re: [PATCH 1/2] Bluetooth: Add basic discovery commands to the management interface
  2011-04-20 12:33   ` Anderson Briglia
@ 2011-04-20 13:09     ` Johan Hedberg
  0 siblings, 0 replies; 5+ messages in thread
From: Johan Hedberg @ 2011-04-20 13:09 UTC (permalink / raw)
  To: Anderson Briglia; +Cc: linux-bluetooth

Hi,

On Wed, Apr 20, 2011, Anderson Briglia wrote:
> you had already sent this few weeks ago.

Could you point me to that thread? I'm not aware of sending these
patches before. AFAIK they were only available in my kernel.org tree
(which I use for experimental stuff not yet ready for upstream).

> What do you prefer? I modify the commit message and the patch
> authoring (and send it again)?

As I said, the changes are probably too minor to justify an author
change. My main point was that don't send stuff in other peoples name
without talking to them first.

> Which coding style issues did you notice?

Minor things like adding an extra empty line at the end of both patches
(shouldn't checkpatch.pl complain about that?) and an extra space in the
format string of a BT_DBG("hci%u ", index) debug print in the first patch.

Johan

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

* [PATCH 1/2] Bluetooth: Add basic discovery commands to the management interface
@ 2011-04-22  0:00 anderson.briglia
  0 siblings, 0 replies; 5+ messages in thread
From: anderson.briglia @ 2011-04-22  0:00 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Johan Hedberg, Anderson Briglia

From: Johan Hedberg <johan.hedberg@nokia.com>

This patch adds start_discovery and stop_discovery commands to the
management interface. Right now their implementation is fairly
simplistic and the parameters are fixed to what user space has
defaulted to so far.
This is the very initial phase for discovery implementation into
the kernel. Next steps include name resolution, LE scanning and
bdaddr type handling.

Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
Signed-off-by: Anderson Briglia <anderson.briglia@openbossa.org>
---
 include/net/bluetooth/mgmt.h |    4 ++
 net/bluetooth/mgmt.c         |   76 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 79 insertions(+), 1 deletions(-)

diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 6b6ff92..be93dd0 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -195,6 +195,10 @@ struct mgmt_cp_remove_remote_oob_data {
 	bdaddr_t bdaddr;
 } __packed;
 
+#define MGMT_OP_START_DISCOVERY		0x001B
+
+#define MGMT_OP_STOP_DISCOVERY		0x001C
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	__le16 opcode;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index c304688..dbc248f 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1569,6 +1569,75 @@ static int remove_remote_oob_data(struct sock *sk, u16 index,
 	return err;
 }
 
+static int start_discovery(struct sock *sk, u16 index)
+{
+	u8 lap[3] = { 0x33, 0x8b, 0x9e };
+	struct hci_cp_inquiry cp;
+	struct pending_cmd *cmd;
+	struct hci_dev *hdev;
+	int err;
+
+	BT_DBG("hci%u", index);
+
+	hdev = hci_dev_get(index);
+	if (!hdev)
+		return cmd_status(sk, index, MGMT_OP_START_DISCOVERY, ENODEV);
+
+	hci_dev_lock_bh(hdev);
+
+	cmd = mgmt_pending_add(sk, MGMT_OP_START_DISCOVERY, index, NULL, 0);
+	if (!cmd) {
+		err = -ENOMEM;
+		goto failed;
+	}
+
+	memset(&cp, 0, sizeof(cp));
+	memcpy(&cp.lap, lap, 3);
+	cp.length  = 0x08;
+	cp.num_rsp = 0x00;
+
+	err = hci_send_cmd(hdev, HCI_OP_INQUIRY, sizeof(cp), &cp);
+	if (err < 0)
+		mgmt_pending_remove(cmd);
+
+failed:
+	hci_dev_unlock_bh(hdev);
+	hci_dev_put(hdev);
+
+	return err;
+}
+
+static int stop_discovery(struct sock *sk, u16 index)
+{
+	struct hci_dev *hdev;
+	struct pending_cmd *cmd;
+	int err;
+
+	BT_DBG("hci%u", index);
+
+	hdev = hci_dev_get(index);
+	if (!hdev)
+		return cmd_status(sk, index, MGMT_OP_STOP_DISCOVERY, ENODEV);
+
+	hci_dev_lock_bh(hdev);
+
+	cmd = mgmt_pending_add(sk, MGMT_OP_STOP_DISCOVERY, index, NULL, 0);
+	if (!cmd) {
+		err = -ENOMEM;
+		goto failed;
+	}
+
+	err = hci_send_cmd(hdev, HCI_OP_INQUIRY_CANCEL, 0, NULL);
+	if (err < 0)
+		mgmt_pending_remove(cmd);
+
+failed:
+	hci_dev_unlock_bh(hdev);
+	hci_dev_put(hdev);
+
+	return err;
+}
+
 int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
 {
 	unsigned char *buf;
@@ -1677,7 +1746,12 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
 		err = remove_remote_oob_data(sk, index, buf + sizeof(*hdr),
 									len);
 		break;
-
+	case MGMT_OP_START_DISCOVERY:
+		err = start_discovery(sk, index);
+		break;
+	case MGMT_OP_STOP_DISCOVERY:
+		err = stop_discovery(sk, index);
+		break;
 	default:
 		BT_DBG("Unknown op %u", opcode);
 		err = cmd_status(sk, index, opcode, 0x01);
-- 
1.7.1


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

end of thread, other threads:[~2011-04-22  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-19 21:35 [PATCH 1/2] Bluetooth: Add basic discovery commands to the management interface anderson.briglia
2011-04-19 21:58 ` Johan Hedberg
2011-04-20 12:33   ` Anderson Briglia
2011-04-20 13:09     ` Johan Hedberg
  -- strict thread matches above, loose matches on Subject: below --
2011-04-22  0:00 anderson.briglia

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