Skip to content

Commit

Permalink
Add an API to set the link timeout.
Browse files Browse the repository at this point in the history
Change-Id: I5abd8fc37e20a7916e84e624f883c7a1987b0587
  • Loading branch information
Jaikumar Ganesh committed May 25, 2011
1 parent 77cb906 commit a04c1f0
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 1 deletion.
27 changes: 27 additions & 0 deletions plugins/hciops.c
Expand Up @@ -3663,6 +3663,32 @@ static int hciops_remove_remote_oob_data(int index, bdaddr_t *bdaddr)
return 0;
}

static int hciops_set_link_timeout(int index, bdaddr_t *bdaddr, uint32_t num_slots)
{
int dd, err;
uint16_t handle;
char addr[18];

ba2str(bdaddr, addr);
DBG("hci%d, addr %s, num_slots %d", index, bdaddr, num_slots);

dd = hci_open_dev(index);

if (dd < 0)
return EIO;

handle = get_handle(index, bdaddr, &handle);
err = hci_write_link_supervision_timeout(dd, htobs(handle),
htobs(num_slots), 1000);
if (err < 0)
err = -errno;

hci_close_dev(dd);

return err;
}


static struct btd_adapter_ops hci_ops = {
.setup = hciops_setup,
.cleanup = hciops_cleanup,
Expand Down Expand Up @@ -3702,6 +3728,7 @@ static struct btd_adapter_ops hci_ops = {
.read_local_oob_data = hciops_read_local_oob_data,
.add_remote_oob_data = hciops_add_remote_oob_data,
.remove_remote_oob_data = hciops_remove_remote_oob_data,
.set_link_timeout = hciops_set_link_timeout,
};

static int hciops_init(void)
Expand Down
35 changes: 34 additions & 1 deletion src/adapter.c
Expand Up @@ -1981,7 +1981,6 @@ static DBusMessage *add_rfcomm_service_record(DBusConnection *conn,
ERROR_INTERFACE ".Failed",
"Failed to register sdp record");

printf("npelly new handle %X\n", record->handle);
reply = dbus_message_new_method_return(msg);
dbus_message_append_args(reply,
DBUS_TYPE_UINT32, &record->handle,
Expand Down Expand Up @@ -2009,6 +2008,39 @@ static DBusMessage *remove_service_record(DBusConnection *conn,
return dbus_message_new_method_return(msg);
}

static DBusMessage *set_link_timeout(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct btd_adapter *adapter = data;
struct btd_device *device;
const char *path;
GSList *l;
uint32_t num_slots;
int dd, err;
bdaddr_t bdaddr;

if (!dbus_message_get_args(msg, NULL,
DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_UINT32, &num_slots,
DBUS_TYPE_INVALID))
return btd_error_invalid_args(msg);

l = g_slist_find_custom(adapter->devices,
path, (GCompareFunc) device_path_cmp);
if (!l)
return g_dbus_create_error(msg,
ERROR_INTERFACE ".DoesNotExist",
"Device does not exist");
device_get_address(l->data, &bdaddr);

err = adapter_ops->set_link_timeout(adapter->dev_id, &bdaddr,
num_slots);
if (err < 0)
return btd_error_failed(msg, strerror(-err));

return dbus_message_new_method_return(msg);
}

static GDBusMethodTable adapter_methods[] = {
{ "GetProperties", "", "a{sv}",get_properties },
{ "SetProperty", "sv", "", set_property,
Expand All @@ -2034,6 +2066,7 @@ static GDBusMethodTable adapter_methods[] = {
{ "UnregisterAgent", "o", "", unregister_agent },
{ "AddRfcommServiceRecord", "sttq", "u", add_rfcomm_service_record },
{ "RemoveServiceRecord", "u", "", remove_service_record },
{ "SetLinkTimeout", "ou", "", set_link_timeout },
{ }
};

Expand Down
1 change: 1 addition & 0 deletions src/adapter.h
Expand Up @@ -210,6 +210,7 @@ struct btd_adapter_ops {
int (*add_remote_oob_data) (int index, bdaddr_t *bdaddr, uint8_t *hash,
uint8_t *randomizer);
int (*remove_remote_oob_data) (int index, bdaddr_t *bdaddr);
int (*set_link_timeout) (int index, bdaddr_t *bdaddr, uint32_t num_slots);
};

int btd_register_adapter_ops(struct btd_adapter_ops *ops, gboolean priority);
Expand Down
5 changes: 5 additions & 0 deletions src/device.c
Expand Up @@ -901,6 +901,11 @@ void device_remove_connection(struct btd_device *device, DBusConnection *conn)
DBUS_TYPE_BOOLEAN, &device->connected);
}

uint16_t device_get_handle(struct btd_device *device)
{
return device->handle;
}

guint device_add_disconnect_watch(struct btd_device *device,
disconnect_watch watch, void *user_data,
GDestroyNotify destroy)
Expand Down
1 change: 1 addition & 0 deletions src/device.h
Expand Up @@ -92,6 +92,7 @@ gboolean device_is_authorizing(struct btd_device *device);
void device_set_authorizing(struct btd_device *device, gboolean auth);
void device_add_connection(struct btd_device *device, DBusConnection *conn);
void device_remove_connection(struct btd_device *device, DBusConnection *conn);
uint16_t device_get_handle(struct btd_device *device);
void device_request_disconnect(struct btd_device *device, DBusMessage *msg);

typedef void (*disconnect_watch) (struct btd_device *device, gboolean removal,
Expand Down
9 changes: 9 additions & 0 deletions src/main.c
Expand Up @@ -229,6 +229,15 @@ static void parse_config(GKeyFile *config)

main_opts.link_policy = HCI_LP_RSWITCH | HCI_LP_SNIFF |
HCI_LP_HOLD | HCI_LP_PARK;

str = g_key_file_get_string(config, "General",
"DefaultLinkPolicy", &err);
if (err)
g_clear_error(&err);
else {
DBG("default_link_policy=%s", str);
main_opts.link_policy &= strtol(str, NULL, 16);
}
}

static void init_defaults(void)
Expand Down

0 comments on commit a04c1f0

Please sign in to comment.