core: Make adapter_ops->set_discoverable to take discoverable timeout
Luiz Augusto von Dentz
maintainerPATCH v2 1/2 core: Make adapter_ops->set_discoverable to take discoverable timeout
From: Luiz Augusto von Dentz <[email protected]>
This enables the driver to implements its own handling of the timeout
---
v2: Merge changes on hciops and mgmtops
plugins/hciops.c | 92 +++++++++++++++++++++++++++++++++++++++++-------- plugins/mgmtops.c | 13 ++++--- src/adapter.c | 98 ++++++----------------------------------------------- src/adapter.h | 7 +++- 4 files changed, 101 insertions(+), 109 deletions(-)
plugins/hciops.c +77 -15
@@ -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 ; }
@@ -654,6 +660,7 @@ static gboolean init_adapter(int index)gboolean existing_adapter = dev->registered;uint8_t mode, on_mode;gboolean pairable, discoverable; +uint16_t discoverable_timeout;if (!dev->registered) { adapter =btd_manager_register_adapter (index, TRUE);
@@ -668,7 +675,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;
@@ -683,7 +692,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)
@@ -1650,20 +1659,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; }static int write_class (int index,uint32_t class)
@@ -1721,6 +1723,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];
@@ -2799,6 +2860,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;
@@ -3815,8 +3877,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,
plugins/mgmtops.c +8 -5
@@ -215,7 +215,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;
@@ -229,6 +230,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;
@@ -305,16 +307,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))
@@ -1021,7 +1024,7 @@ static void read_info_complete(int sk, uint16_t index, void *buf, size_t len)adapter_name_changed (adapter, (char *) rp->name); -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 ;
src/adapter.c +11 -87
161 lines not on this page · raw message
src/adapter.h +5 -2
@@ -87,7 +87,9 @@ void btd_adapter_start(struct btd_adapter *adapter);int btd_adapter_stop (struct btd_adapter *adapter);void btd_adapter_get_mode (struct btd_adapter *adapter,uint8_t *mode, -uint8_t *on_mode,gboolean *pairable); +uint8_t *on_mode, +uint16_t *discoverable_timeout, +gboolean *pairable);struct btd_device *adapter_get_device (DBusConnection *conn,struct btd_adapter *adapter,const char *address);
@@ -181,7 +183,8 @@ struct btd_adapter_ops {int (*setup) (void );void (*cleanup) (void );int (*set_powered) (int index,gboolean powered); -int (*set_discoverable) (int index,gboolean discoverable); +int (*set_discoverable) (int index,gboolean discoverable, +uint16_t timeout);int (*set_pairable) (int index,gboolean pairable);int (*set_limited_discoverable) (int index,gboolean limited);int (*start_discovery) (int index);
Signature · 1 line
1.7.7.6
Luiz Augusto von Dentz
maintainerPATCH v2 2/2 core: remove set_limited_discoverable from adapter_ops driver
From: Luiz Augusto von Dentz <[email protected]>
Core should not longer need to take care of details of discoverable bits
---
v2: Merge changes in hciops and mgmtops
plugins/hciops.c | 1 - plugins/mgmtops.c | 7 ------- src/adapter.c | 8 -------- src/adapter.h | 1 - 4 files changed, 0 insertions(+), 17 deletions(-)
plugins/hciops.c +0 -1
@@ -3877,7 +3877,6 @@ static struct btd_adapter_ops hci_ops = { .cleanup = hciops_cleanup, .set_powered = hciops_set_powered, .set_discoverable = hciops_set_discoverable, - .set_limited_discoverable = hciops_set_limited_discoverable, .set_pairable = hciops_set_pairable, .start_discovery = hciops_start_discovery, .stop_discovery = hciops_stop_discovery,
plugins/mgmtops.c +0 -7
@@ -1841,12 +1841,6 @@ static void mgmt_cleanup(void) } } -static int mgmt_set_limited_discoverable (int index,gboolean limited) -{ -DBG ("index %d limited %d" , index, limited); -return -ENOSYS ; -} -static int mgmt_start_discovery (int index) {char buf[MGMT_HDR_SIZE +sizeof (struct mgmt_cp_start_discovery )];
@@ -2392,7 +2386,6 @@ static struct btd_adapter_ops mgmt_ops = { .set_powered = mgmt_set_powered, .set_discoverable = mgmt_set_discoverable, .set_pairable = mgmt_set_pairable, - .set_limited_discoverable = mgmt_set_limited_discoverable, .start_discovery = mgmt_start_discovery, .stop_discovery = mgmt_stop_discovery, .set_name = mgmt_set_name,
src/adapter.c +0 -8
@@ -206,14 +206,6 @@ static uint8_t get_mode(const bdaddr_t *bdaddr, const char *mode)return MODE_UNKNOWN ; } -static void adapter_set_limited_discoverable (struct btd_adapter *adapter, -gboolean limited) -{ -DBG ("%s" , limited ?"TRUE" :"FALSE" ); - - adapter_ops->set_limited_discoverable (adapter->dev_id, limited); -} -static struct session_req *session_ref (struct session_req *req) { req->refcount++;
src/adapter.h +0 -1
@@ -186,7 +186,6 @@ struct btd_adapter_ops {int (*set_discoverable) (int index,gboolean discoverable,uint16_t timeout);int (*set_pairable) (int index,gboolean pairable); -int (*set_limited_discoverable) (int index,gboolean limited);int (*start_discovery) (int index);int (*stop_discovery) (int index);
Signature · 1 line
1.7.7.6
Hi Luiz,
Quoted 11 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This enables the driver to implements its own handling of the timeout
---
v2: Merge changes on hciops and mgmtopsplugins/hciops.c | 92 +++++++++++++++++++++++++++++++++++++++++-------- plugins/mgmtops.c | 13 ++++--- src/adapter.c | 98 ++++++----------------------------------------------- src/adapter.h | 7 +++- 4 files changed, 101 insertions(+), 109 deletions(-)
Both patches have been applied. Thanks.
Johan