Skip to contentSkip to conversation

Adding start_inquiry to hciops plugin.

PATCH New alok barsode 1 participant 1 message May 18, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Adding start_inquiry to hciops plugin.

Hi Marcel,

Attaching a patch which adds start_inquiry functionality to the hciops plugin. I have made the following changes :

* use hci_send_cmd instead of hci_send_req.
* move the cmd_status callback from dbus-hci.c to adapter.c and call it adapter_start_inquiry_cb().
* hardcode the callback instead of passing a function pointer.

If you are OK with this framework, i can start working on the periodic inquiry functionality.

Let me know what you think.

Cheers,
Alok.

From 6276d589b01b24e8577b779fa124804e0d10b6d5 Mon Sep 17 00:00:00 2001
From: Alok Barsode <[email protected]>
Date: Mon, 18 May 2009 19:59:40 +0530
Subject: [PATCH] Adding start_inquiry functionality to hciops plugin.

---
 lib/hci.c        |    2 +-
 plugins/hciops.c |   24 +++++++++++++++
 src/adapter.c    |   85 ++++++++++++++++++++++++++++--------------------------
 src/adapter.h    |    3 +-
 src/dbus-hci.c   |   29 ------------------
 src/dbus-hci.h   |    1 -
 src/security.c   |    2 +-
 7 files changed, 72 insertions(+), 74 deletions(-)
lib/hci.c +1 -1
index 6d25a8b..29ba319 100644
@@ -981,7 +981,7 @@ int hci_send_cmd(int dd, uint16_t ogf, uint16_t ocf, uint8_t plen, void *param)
 	while (writev(dd, iv, ivn) < 0) {
 		if (errno == EAGAIN || errno == EINTR)
 			continue;
-		return -1;
+		return -errno;
 	}
 	return 0;
 }
plugins/hciops.c +24 -0
index 8f9ee06..239596b 100644
@@ -561,6 +561,29 @@ done:
 	return err;
 }
 
+static int hciops_start_inquiry(int index)
+{
+	inquiry_cp cp;
+	uint8_t lap[3] = { 0x33, 0x8b, 0x9e };
+	int dd, err = 0;
+
+	dd = hci_open_dev(index);
+	if (dd < 0)
+		return dd;
+
+	memset(&cp, 0, sizeof(cp));
+	memcpy(&cp.lap, lap, 3);
+	cp.length = 0x08;
+	cp.num_rsp = 0x00;
+
+	err = hci_send_cmd(dd, OGF_LINK_CTL, OCF_INQUIRY,
+					INQUIRY_CP_SIZE, &cp);
+
+	hci_close_dev(dd);
+
+	return err;
+}
+
 static struct btd_adapter_ops hci_ops = {
 	.setup = hciops_setup,
 	.cleanup = hciops_cleanup,
@@ -570,6 +593,7 @@ static struct btd_adapter_ops hci_ops = {
 	.set_connectable = hciops_connectable,
 	.set_discoverable = hciops_discoverable,
 	.set_limited_discoverable = hciops_set_limited_discoverable,
+	.start_inquiry = hciops_start_inquiry,
 };
 
 static int hciops_init(void)
src/adapter.c +44 -41

113 lines not on this page · raw message

src/adapter.h +2 -1
index a94edc6..d3ae00f 100644
@@ -145,7 +145,7 @@ const char *btd_adapter_any_request_path(void);
 void btd_adapter_any_release_path(void);
 gboolean adapter_is_pairable(struct btd_adapter *adapter);
 gboolean adapter_powering_down(struct btd_adapter *adapter);
-
+void adapter_start_inquiry_cb(bdaddr_t *local, uint8_t status);
 
 struct btd_adapter_ops {
 	int (*setup) (void);
@@ -157,6 +157,7 @@ struct btd_adapter_ops {
 	int (*set_discoverable) (int index);
 	int (*set_limited_discoverable) (int index, const uint8_t *cls,
 						gboolean limited);
+	int (*start_inquiry) (int index);
 };
 
 int btd_register_adapter_ops(struct btd_adapter_ops *btd_adapter_ops);
src/dbus-hci.c +0 -29
index 65ac12b..70fbbc6 100644
@@ -434,35 +434,6 @@ void hcid_dbus_simple_pairing_complete(bdaddr_t *local, bdaddr_t *peer,
 	device_simple_pairing_complete(device, status);
 }
 
-void hcid_dbus_inquiry_start(bdaddr_t *local)
-{
-	struct btd_adapter *adapter;
-	int state;
-
-	adapter = manager_find_adapter(local);
-	if (!adapter) {
-		error("Unable to find matching adapter");
-		return;
-	}
-
-	state = adapter_get_state(adapter);
-	state |= STD_INQUIRY;
-	adapter_set_state(adapter, state);
-	/*
-	 * Cancel pending remote name request and clean the device list
-	 * when inquiry is supported in periodic inquiry idle state.
-	 */
-	if (adapter_get_state(adapter) & PERIODIC_INQUIRY)
-		pending_remote_name_cancel(adapter);
-
-	/* Disable name resolution for non D-Bus clients */
-	if (!adapter_has_discov_sessions(adapter)) {
-		state = adapter_get_state(adapter);
-		state &= ~RESOLVE_NAME;
-		adapter_set_state(adapter, state);
-	}
-}
-
 static int found_device_req_name(struct btd_adapter *adapter)
 {
 	struct hci_request rq;
src/dbus-hci.h +0 -1
index 1cb10f3..6dd9ab1 100644
@@ -24,7 +24,6 @@
 
 int hcid_dbus_request_pin(int dev, bdaddr_t *sba, struct hci_conn_info *ci);
 
-void hcid_dbus_inquiry_start(bdaddr_t *local);
 void hcid_dbus_inquiry_complete(bdaddr_t *local);
 void hcid_dbus_periodic_inquiry_start(bdaddr_t *local, uint8_t status);
 void hcid_dbus_periodic_inquiry_exit(bdaddr_t *local, uint8_t status);
src/security.c +1 -1
index a61d75f..792a94c 100644
@@ -550,7 +550,7 @@ static inline void cmd_status(int dev, bdaddr_t *sba, void *ptr)
 		return;
 
 	if (opcode == cmd_opcode_pack(OGF_LINK_CTL, OCF_INQUIRY))
-		hcid_dbus_inquiry_start(sba);
+		adapter_start_inquiry_cb(sba, evt->status);
 }
 
 static inline void cmd_complete(int dev, bdaddr_t *sba, void *ptr)
Signature · 1 line
1.5.6.3