aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2012-03-01 11:15:03 +0200
committerJohan Hedberg <johan.hedberg@intel.com>2012-03-02 16:09:39 -0800
commit92f9d578033bad9067ea448d4fa2ca3773ec5f50 (patch)
tree1a19b268e93e5b6a1c329779ad1ef4e3ca04a39b /plugins
parent49e3fa4157304dd8291277eaa56229d260aefa9d (diff)
downloadbluez-92f9d578033bad9067ea448d4fa2ca3773ec5f50.tar.gz
bluez-92f9d578033bad9067ea448d4fa2ca3773ec5f50.tar.xz
bluez-92f9d578033bad9067ea448d4fa2ca3773ec5f50.zip
core: Make adapter_ops->set_discoverable to take discoverable timeout
This enables the driver to implements its own handling of the timeout
Diffstat (limited to 'plugins')
-rw-r--r--plugins/hciops.c92
-rw-r--r--plugins/mgmtops.c13
2 files changed, 85 insertions, 20 deletions
diff --git a/plugins/hciops.c b/plugins/hciops.c
index 3d68796f..fdc12710 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -171,6 +171,9 @@ static struct dev_info {
GSList *need_name;
guint stop_scan_id;
+
+ uint16_t discoverable_timeout;
+ guint discoverable_id;
} *devs = NULL;
static int found_dev_rssi_cmp(gconstpointer a, gconstpointer b)
@@ -495,7 +498,8 @@ static int init_ssp_mode(int index)
return 0;
}
-static int hciops_set_discoverable(int index, gboolean discoverable)
+static int hciops_set_discoverable(int index, gboolean discoverable,
+ uint16_t timeout)
{
struct dev_info *dev = &devs[index];
uint8_t mode;
@@ -511,6 +515,8 @@ static int hciops_set_discoverable(int index, gboolean discoverable)
1, &mode) < 0)
return -errno;
+ dev->discoverable_timeout = timeout;
+
return 0;
}
@@ -752,6 +758,7 @@ static gboolean init_adapter(int index)
uint8_t mode, on_mode, major, minor;
gboolean pairable, discoverable;
const char *name;
+ uint16_t discoverable_timeout;
if (!dev->registered) {
adapter = btd_manager_register_adapter(index, TRUE);
@@ -766,7 +773,9 @@ static gboolean init_adapter(int index)
if (adapter == NULL)
return FALSE;
- btd_adapter_get_mode(adapter, &mode, &on_mode, &pairable);
+ btd_adapter_get_mode(adapter, &mode, &on_mode,
+ &discoverable_timeout,
+ &pairable);
if (existing_adapter)
mode = on_mode;
@@ -789,7 +798,7 @@ static gboolean init_adapter(int index)
discoverable = (mode == MODE_DISCOVERABLE);
- hciops_set_discoverable(index, discoverable);
+ hciops_set_discoverable(index, discoverable, discoverable_timeout);
hciops_set_pairable(index, pairable);
if (dev->already_up)
@@ -1723,20 +1732,13 @@ static inline void cmd_status(int index, void *ptr)
cs_inquiry_evt(index, evt->status);
}
-static void read_scan_complete(int index, uint8_t status, void *ptr)
+static gboolean discoverable_timeout_handler(gpointer user_data)
{
- struct btd_adapter *adapter;
- read_scan_enable_rp *rp = ptr;
+ struct dev_info *dev = user_data;
- DBG("hci%d status %u", index, status);
+ hciops_set_discoverable(dev->id, FALSE, 0);
- adapter = manager_find_adapter_by_id(index);
- if (!adapter) {
- error("Unable to find matching adapter");
- return;
- }
-
- adapter_mode_changed(adapter, rp->enable);
+ return FALSE;
}
/* Limited Discoverable bit mask in CoD */
@@ -1776,6 +1778,65 @@ static int hciops_set_limited_discoverable(int index, gboolean limited)
return write_class(index, dev->wanted_cod);
}
+static void reset_discoverable_timeout(int index)
+{
+ struct dev_info *dev = &devs[index];
+
+ if (dev->discoverable_id > 0) {
+ g_source_remove(dev->discoverable_id);
+ dev->discoverable_id = 0;
+ }
+}
+
+static void set_discoverable_timeout(int index)
+{
+ struct dev_info *dev = &devs[index];
+
+ reset_discoverable_timeout(index);
+
+ if (dev->discoverable_timeout == 0) {
+ hciops_set_limited_discoverable(index, FALSE);
+ return;
+ }
+
+ /* Set limited discoverable if pairable and interval between 0 to 60
+ sec */
+ if (dev->pairable && dev->discoverable_timeout <= 60)
+ hciops_set_limited_discoverable(index, TRUE);
+ else
+ hciops_set_limited_discoverable(index, FALSE);
+
+ dev->discoverable_id = g_timeout_add_seconds(dev->discoverable_timeout,
+ discoverable_timeout_handler,
+ dev);
+}
+
+static void read_scan_complete(int index, uint8_t status, void *ptr)
+{
+ struct btd_adapter *adapter;
+ read_scan_enable_rp *rp = ptr;
+
+ DBG("hci%d status %u", index, status);
+
+ switch (rp->enable) {
+ case (SCAN_PAGE | SCAN_INQUIRY):
+ case SCAN_INQUIRY:
+ set_discoverable_timeout(index);
+ break;
+ default:
+ reset_discoverable_timeout(index);
+ hciops_set_limited_discoverable(index, FALSE);
+ }
+
+ adapter = manager_find_adapter_by_id(index);
+ if (!adapter) {
+ error("Unable to find matching adapter");
+ return;
+ }
+
+ adapter_mode_changed(adapter, rp->enable);
+}
+
static void write_class_complete(int index, uint8_t status)
{
struct dev_info *dev = &devs[index];
@@ -2854,6 +2915,7 @@ static void device_event(int event, int index)
devs[index].pending_cod = 0;
devs[index].cache_enable = TRUE;
devs[index].discov_state = DISCOV_HALTED;
+ reset_discoverable_timeout(index);
if (!devs[index].pending) {
struct btd_adapter *adapter;
@@ -3824,8 +3886,8 @@ static struct btd_adapter_ops hci_ops = {
.cleanup = hciops_cleanup,
.set_powered = hciops_set_powered,
.set_discoverable = hciops_set_discoverable,
- .set_pairable = hciops_set_pairable,
.set_limited_discoverable = hciops_set_limited_discoverable,
+ .set_pairable = hciops_set_pairable,
.start_discovery = hciops_start_discovery,
.stop_discovery = hciops_stop_discovery,
.set_name = hciops_set_name,
diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c
index dd5f7a38..51279ef4 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -216,7 +216,8 @@ static int mgmt_set_connectable(int index, gboolean connectable)
return mgmt_set_mode(index, MGMT_OP_SET_CONNECTABLE, connectable);
}
-static int mgmt_set_discoverable(int index, gboolean discoverable)
+static int mgmt_set_discoverable(int index, gboolean discoverable,
+ uint16_t timeout)
{
char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_set_discoverable)];
struct mgmt_hdr *hdr = (void *) buf;
@@ -230,6 +231,7 @@ static int mgmt_set_discoverable(int index, gboolean discoverable)
hdr->len = htobs(sizeof(*cp));
cp->val = discoverable;
+ cp->timeout = timeout;
if (write(mgmt_sock, buf, sizeof(buf)) < 0)
return -errno;
@@ -306,16 +308,17 @@ static void update_settings(struct btd_adapter *adapter, uint32_t settings)
struct controller_info *info;
gboolean pairable;
uint8_t on_mode;
- uint16_t index;
+ uint16_t index, discoverable_timeout;
- btd_adapter_get_mode(adapter, NULL, &on_mode, &pairable);
+ btd_adapter_get_mode(adapter, NULL, &on_mode, &discoverable_timeout,
+ &pairable);
index = adapter_get_dev_id(adapter);
info = &controllers[index];
if (on_mode == MODE_DISCOVERABLE && !mgmt_discoverable(settings))
- mgmt_set_discoverable(index, TRUE);
+ mgmt_set_discoverable(index, TRUE, discoverable_timeout);
else if (on_mode == MODE_CONNECTABLE && !mgmt_connectable(settings))
mgmt_set_connectable(index, TRUE);
else if (mgmt_powered(settings))
@@ -1085,7 +1088,7 @@ static void read_info_complete(int sk, uint16_t index, void *buf, size_t len)
btd_adapter_get_class(adapter, &major, &minor);
mgmt_set_dev_class(index, major, minor);
- btd_adapter_get_mode(adapter, &mode, NULL, NULL);
+ btd_adapter_get_mode(adapter, &mode, NULL, NULL, NULL);
if (mode == MODE_OFF && mgmt_powered(info->current_settings)) {
mgmt_set_powered(index, FALSE);
return;