* Re: [RFC 02/15] Bluetooth: Mgmt command for adding connection parameters
From: Andre Guedes @ 2013-10-18 14:07 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <BA029FAA-265C-47A8-953F-95E6B504941B@holtmann.org>
Hi Marcel,
On Oct 17, 2013, at 6:22 AM, Marcel Holtmann wrote:
> Hi Andre,
>=20
>> This patch introduces a new Mgmt command (MGMT_OP_ADD_CONN_PARAM) =
which
>> adds the connection parameters to controller's connection parameters
>> list. These parameters will be used by the kernel when it establishes =
a
>> connection with the given device.
>>=20
>> This patch also moves the 'auto_connect' enum from hci_core.h to
>> bluetooth.h since the will accessed used by userspace in order to
>> send the MGMT_OP_ADD_CONN_PARAM command.
>=20
> the comment about userspace makes no sense. And is not an argument to =
move the enum anywhere. Also if these are mgmt "modes" or "types" then =
they should be somewhere else and not in bluetooth.h.
Ok, so for now I'll leave these macros in hci_core.h.
>=20
>>=20
>> Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
>> ---
>> include/net/bluetooth/bluetooth.h | 6 ++++++
>> include/net/bluetooth/hci_core.h | 6 +-----
>> include/net/bluetooth/mgmt.h | 9 +++++++++
>> net/bluetooth/mgmt.c | 35 =
+++++++++++++++++++++++++++++++++++
>> 4 files changed, 51 insertions(+), 5 deletions(-)
>>=20
>> diff --git a/include/net/bluetooth/bluetooth.h =
b/include/net/bluetooth/bluetooth.h
>> index bf2ddff..8509520 100644
>> --- a/include/net/bluetooth/bluetooth.h
>> +++ b/include/net/bluetooth/bluetooth.h
>> @@ -354,4 +354,10 @@ void sco_exit(void);
>>=20
>> void bt_sock_reclassify_lock(struct sock *sk, int proto);
>>=20
>> +enum {
>> + BT_AUTO_CONN_DISABLED,
>> + BT_AUTO_CONN_ALWAYS,
>> + BT_AUTO_CONN_LINK_LOSS,
>> +};
>> +
>> #endif /* __BLUETOOTH_H */
>> diff --git a/include/net/bluetooth/hci_core.h =
b/include/net/bluetooth/hci_core.h
>> index 5052bf0..98be273 100644
>> --- a/include/net/bluetooth/hci_core.h
>> +++ b/include/net/bluetooth/hci_core.h
>> @@ -376,11 +376,7 @@ struct hci_conn_param {
>> bdaddr_t addr;
>> u8 addr_type;
>>=20
>> - enum {
>> - HCI_AUTO_CONN_DISABLED,
>> - HCI_AUTO_CONN_ALWAYS,
>> - HCI_AUTO_CONN_LINK_LOSS,
>> - } auto_connect;
>> + u8 auto_connect;
>>=20
>> u16 min_conn_interval;
>> u16 max_conn_interval;
>> diff --git a/include/net/bluetooth/mgmt.h =
b/include/net/bluetooth/mgmt.h
>> index 518c5c8..ed689b5 100644
>> --- a/include/net/bluetooth/mgmt.h
>> +++ b/include/net/bluetooth/mgmt.h
>> @@ -369,6 +369,15 @@ struct mgmt_cp_set_scan_params {
>> } __packed;
>> #define MGMT_SET_SCAN_PARAMS_SIZE 4
>>=20
>> +#define MGMT_OP_ADD_CONN_PARAM 0x002D
>> +struct mgmt_cp_add_conn_param {
>> + struct mgmt_addr_info addr;
>> + __u8 auto_connect;
>> + __le16 min_conn_interval;
>> + __le16 max_conn_interval;
>> +} __packed;
>> +#define MGMT_ADD_CONN_PARAM_SIZE (MGMT_ADDR_INFO_SIZE + 5)
>> +
>> #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 a727b47..5d1a2e8 100644
>> --- a/net/bluetooth/mgmt.c
>> +++ b/net/bluetooth/mgmt.c
>> @@ -79,6 +79,7 @@ static const u16 mgmt_commands[] =3D {
>> MGMT_OP_SET_BREDR,
>> MGMT_OP_SET_STATIC_ADDRESS,
>> MGMT_OP_SET_SCAN_PARAMS,
>> + MGMT_OP_ADD_CONN_PARAM,
>> };
>=20
> So my 2nd patch wouldn't have been the mgmt command. I would have put =
all the cleanup and infrastructure changes in first. And I would have =
turned the connect() into the first user with a mode of "connect once" =
and default connection parameters.
>=20
> This clearly shows later on where all this magic handling comes into =
place. But in the end, the connect() call is just a connect once type of =
passive scanning. And maybe with learned connection slave interval =
values from advertising data during the scanning.
In v2, I'll put this patch after the infrastructure changes.
I didn't know we want to change connect() behavior. What is the issue we =
are trying address with this changing?
>=20
> The other problem that I have is that we can never update the =
parameters for a device. We need to remove them and re-add them. That is =
just not a good idea since we will almost certainly learn about updated =
values here. And maybe even change the mode of a device.
These connection parameters and auto connection policy is pretty much =
static values. We know ahead configuring the kernel what profiles the =
device supports. And the profiles the device supports don't dynamically =
change.
>=20
> In general just having one Update Connection Parameters call might be =
better. The kernel can happily just expire values from connection once =
or disabled by itself. So this needs a bit more discussion. Doing the =
mgmt interface last would allow to get all the other patches merged. =
Otherwise you are stuck on the mgmt part until we figure that out.
Sure we need more discussion on this. As I said, I'll move this mgmt =
command patches to the end of this patch set.
>=20
>> static const u16 mgmt_events[] =3D {
>> @@ -4025,6 +4026,39 @@ static int load_long_term_keys(struct sock =
*sk, struct hci_dev *hdev,
>> return err;
>> }
>>=20
>> +static int add_conn_param(struct sock *sk, struct hci_dev *hdev, =
void *cp_data,
>> + u16 len)
>> +{
>> + struct mgmt_cp_add_conn_param *cp =3D cp_data;
>> + u8 status;
>> + u8 addr_type;
>> +
>> + if (cp->addr.type =3D=3D BDADDR_BREDR)
>> + return cmd_complete(sk, hdev->id, =
MGMT_OP_ADD_CONN_PARAM,
>> + MGMT_STATUS_NOT_SUPPORTED, NULL, 0);
>=20
> Instead of checking for BDADDR_BREDR it would be better to check for =
!bdaddr_type_is_le().
>=20
> I really want everybody to get into the habit to do proper input =
validation. Not the half backed thing. That is why mgmt-tester can catch =
these kind of things easily and repeatedly.
I'll replace this with !bdaddr_type_is_le().
>=20
>> +
>> + status =3D mgmt_le_support(hdev);
>> + if (status)
>> + return cmd_complete(sk, hdev->id, =
MGMT_OP_ADD_CONN_PARAM,
>> + status, NULL, 0);
>> +
>> + if (cp->addr.type =3D=3D BDADDR_LE_PUBLIC)
>> + addr_type =3D ADDR_LE_DEV_PUBLIC;
>> + else
>> + addr_type =3D ADDR_LE_DEV_RANDOM;
>> +
>> + if (hci_add_conn_param(hdev, &cp->addr.bdaddr, addr_type,
>> + cp->auto_connect,
>> + __le16_to_cpu(cp->min_conn_interval),
>> + __le16_to_cpu(cp->max_conn_interval)))
>> + status =3D MGMT_STATUS_FAILED;
>> + else
>> + status =3D MGMT_STATUS_SUCCESS;
>> +
>> + return cmd_complete(sk, hdev->id, MGMT_OP_ADD_CONN_PARAM, =
status,
>> + NULL, 0);
>> +}
>> +
>> static const struct mgmt_handler {
>> int (*func) (struct sock *sk, struct hci_dev *hdev, void *data,
>> u16 data_len);
>> @@ -4076,6 +4110,7 @@ static const struct mgmt_handler {
>> { set_bredr, false, MGMT_SETTING_SIZE },
>> { set_static_address, false, MGMT_SET_STATIC_ADDRESS_SIZE },
>> { set_scan_params, false, MGMT_SET_SCAN_PARAMS_SIZE },
>> + { add_conn_param, false, MGMT_ADD_CONN_PARAM_SIZE },
>> };
>>=20
>=20
> And btw. it is always plural "params". It is not single parameter.
I'll fix it.
Regards,
Andre
^ permalink raw reply
* Re: [PATCH 0/3] Tab completion for haltest tool
From: Johan Hedberg @ 2013-10-18 13:51 UTC (permalink / raw)
To: Jerzy Kasenberg; +Cc: linux-bluetooth
In-Reply-To: <1382102160-21532-1-git-send-email-jerzy.kasenberg@tieto.com>
Hi Jerzy,
On Fri, Oct 18, 2013, Jerzy Kasenberg wrote:
> This patchset add tab completion to haltest so using this tool
> will be much easier.
>
> It allows to build for andriod 4.3 and for host with autotools.
>
> Jerzy Kasenberg (3):
> android: Add tab completion to haltest
> android: Fix error in draw line in haltest tool
> android: Add completion for adapter to haltest
>
> Makefile.android | 2 +
> android/Android.mk | 1 +
> android/client/haltest.c | 11 +-
> android/client/if-bt.c | 331 ++++++++++++++++++++++++++++++++++------
> android/client/if-main.h | 44 +++++-
> android/client/tabcompletion.c | 313 +++++++++++++++++++++++++++++++++++++
> android/client/terminal.c | 4 +-
> android/client/textconv.c | 21 +++
> android/client/textconv.h | 4 +
> 9 files changed, 673 insertions(+), 58 deletions(-)
> create mode 100644 android/client/tabcompletion.c
All three patches have been applied. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH] android: Add missing signal handler functionality
From: Johan Hedberg @ 2013-10-18 13:19 UTC (permalink / raw)
To: Ravi kumar Veeramally; +Cc: linux-bluetooth
In-Reply-To: <1382101802-23965-1-git-send-email-ravikumar.veeramally@linux.intel.com>
Hi Ravi,
On Fri, Oct 18, 2013, Ravi kumar Veeramally wrote:
> Added singal handling based on singalfd and removed sigaction
> based code.
> ---
> android/main.c | 80 +++++++++++++++++++++++++++++++++++++++++++++-----------
> 1 file changed, 65 insertions(+), 15 deletions(-)
Applied (after a minor fix to exit the daemon if the setup function
fails). Thanks.
Johan
^ permalink raw reply
* [PATCH 3/3] android: Add completion for adapter to haltest
From: Jerzy Kasenberg @ 2013-10-18 13:16 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Jerzy Kasenberg
In-Reply-To: <1382102160-21532-1-git-send-email-jerzy.kasenberg@tieto.com>
This patch adds all completion functions for adapter methods.
It also adds short help lines for all methods that require arguments.
---
android/client/haltest.c | 11 +-
android/client/if-bt.c | 331 ++++++++++++++++++++++++++++++++++++++-------
android/client/if-main.h | 16 +++
android/client/textconv.c | 21 +++
android/client/textconv.h | 4 +
5 files changed, 330 insertions(+), 53 deletions(-)
diff --git a/android/client/haltest.c b/android/client/haltest.c
index 6dcabbc..6b37f33 100644
--- a/android/client/haltest.c
+++ b/android/client/haltest.c
@@ -103,11 +103,12 @@ static void process_line(char *line_buffer)
continue;
}
if (argc < 2 || strcmp(argv[1], "?") == 0) {
- j = 0;
- while (strcmp(interfaces[i]->methods[j].name, "")) {
- haltest_info("%s %s\n", argv[0],
- interfaces[i]->methods[j].name);
- ++j;
+ struct method *m = &interfaces[i]->methods[0];
+ while (strcmp(m->name, "")) {
+ haltest_info("%s %s %s\n", argv[0],
+ m->name,
+ (m->help ? m->help : ""));
+ m++;
}
return;
}
diff --git a/android/client/if-bt.c b/android/client/if-bt.c
index 90ef732..30b41cd 100644
--- a/android/client/if-bt.c
+++ b/android/client/if-bt.c
@@ -19,6 +19,16 @@
const bt_interface_t *if_bluetooth;
+#define VERIFY_PROP_TYPE_ARG(n, typ) \
+ do { \
+ if (n < argc) \
+ typ = str2btpropertytype(argv[n]); \
+ else { \
+ haltest_error("No property type specified\n"); \
+ return;\
+ } \
+ } while (0)
+
static char *bdaddr2str(const bt_bdaddr_t *bd_addr)
{
static char buf[18];
@@ -177,6 +187,84 @@ static void dump_properties(int num_properties, bt_property_t *properties)
}
}
+/*
+ * Cache for remote devices, stored in sorted array
+ */
+static bt_bdaddr_t *remote_devices = NULL;
+static int remote_devices_cnt = 0;
+static int remote_devices_capacity = 0;
+
+/* Adds address to remote device set so it can be used in tab completion */
+void add_remote_device(const bt_bdaddr_t *addr)
+{
+ int i;
+
+ if (remote_devices == NULL) {
+ remote_devices = malloc(4 * sizeof(bt_bdaddr_t));
+ remote_devices_cnt = 0;
+ if (remote_devices == NULL) {
+ remote_devices_capacity = 0;
+ return;
+ }
+ remote_devices_capacity = 4;
+ }
+
+ /* Array is sorted, search for right place */
+ for (i = 0; i < remote_devices_cnt; ++i) {
+ int res = memcmp(&remote_devices[i], addr, sizeof(*addr));
+ if (res == 0)
+ return; /* Already added */
+ else if (res > 0)
+ break;
+ }
+
+ /* Realloc space if needed */
+ if (remote_devices_cnt >= remote_devices_capacity) {
+ remote_devices_capacity *= 2;
+ remote_devices = realloc(remote_devices, sizeof(bt_bdaddr_t) *
+ remote_devices_capacity);
+ if (remote_devices == NULL) {
+ remote_devices_capacity = 0;
+ remote_devices_cnt = 0;
+ return;
+ }
+ }
+
+ if (i < remote_devices_cnt)
+ memmove(remote_devices + i + 1, remote_devices + i,
+ (remote_devices_cnt - i) * sizeof(bt_bdaddr_t));
+ remote_devices[i] = *addr;
+ remote_devices_cnt++;
+}
+
+const char *enum_devices(void *v, int i)
+{
+ static char buf[19];
+
+ if (i >= remote_devices_cnt)
+ return NULL;
+
+ bt_bdaddr_t2str(&remote_devices[i], buf);
+ return buf;
+}
+
+static void add_remote_device_from_props(int num_properties,
+ const bt_property_t *properties)
+{
+ int i;
+
+ for (i = 0; i < num_properties; i++) {
+ /*
+ * properities sometimes come unaligned hence memcp to
+ * aligned buffer
+ */
+ bt_property_t property;
+ memcpy(&property, properties + i, sizeof(property));
+ if (property.type == BT_PROPERTY_BDADDR)
+ add_remote_device((bt_bdaddr_t *) property.val);
+ }
+}
+
static void adapter_state_changed_cb(bt_state_t state)
{
haltest_info("%s: state=%s\n", __func__, bt_state_t2str(state));
@@ -198,6 +286,8 @@ static void remote_device_properties_cb(bt_status_t status,
__func__, bt_status_t2str(status), bdaddr2str(bd_addr),
num_properties);
+ add_remote_device(bd_addr);
+
dump_properties(num_properties, properties);
}
@@ -205,6 +295,8 @@ static void device_found_cb(int num_properties, bt_property_t *properties)
{
haltest_info("%s: num_properties=%d\n", __func__, num_properties);
+ add_remote_device_from_props(num_properties, properties);
+
dump_properties(num_properties, properties);
}
@@ -214,19 +306,33 @@ static void discovery_state_changed_cb(bt_discovery_state_t state)
bt_discovery_state_t2str(state));
}
+/*
+ * Buffer for remote addres that came from one of bind request.
+ * It's stored for command completion.
+ */
+static char last_remote_addr[18];
+static bt_ssp_variant_t last_ssp_variant = (bt_ssp_variant_t)-1;
+
static void pin_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name,
uint32_t cod)
{
+ /* Store for command completion */
+ bt_bdaddr_t2str(remote_bd_addr, last_remote_addr);
+
haltest_info("%s: remote_bd_addr=%s bd_name=%s cod=%06x\n", __func__,
- bdaddr2str(remote_bd_addr), bd_name->name, cod);
+ last_remote_addr, bd_name->name, cod);
}
static void ssp_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name,
uint32_t cod, bt_ssp_variant_t pairing_variant,
uint32_t pass_key)
{
+ /* Store for command completion */
+ bt_bdaddr_t2str(remote_bd_addr, last_remote_addr);
+ last_ssp_variant = pairing_variant;
+
haltest_info("%s: remote_bd_addr=%s bd_name=%s cod=%06x pairing_variant=%s pass_key=%d\n",
- __func__, bdaddr2str(remote_bd_addr), bd_name->name, cod,
+ __func__, last_remote_addr, bd_name->name, cod,
bt_ssp_variant_t2str(pairing_variant), pass_key);
}
@@ -338,15 +444,45 @@ static void get_adapter_properties_p(int argc, const char **argv)
EXEC(if_bluetooth->get_adapter_properties);
}
+static void get_adapter_property_c(int argc, const char **argv,
+ enum_func *penum_func, void **puser)
+{
+ if (argc == 3) {
+ *puser = TYPE_ENUM(bt_property_type_t);
+ *penum_func = enum_defines;
+ }
+}
+
static void get_adapter_property_p(int argc, const char **argv)
{
- int type = str2btpropertytype(argv[2]);
+ int type;
RETURN_IF_NULL(if_bluetooth);
+ VERIFY_PROP_TYPE_ARG(2, type);
EXEC(if_bluetooth->get_adapter_property, type);
}
+static const char * const names[] = {
+ "BT_PROPERTY_BDNAME",
+ "BT_PROPERTY_ADAPTER_SCAN_MODE",
+ "BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT", NULL
+};
+
+static void set_adapter_property_c(int argc, const char **argv,
+ enum_func *penum_func, void **puser)
+{
+ if (argc == 3) {
+ *puser = (void *) names;
+ *penum_func = enum_strings;
+ } else if (argc == 4) {
+ if (0 == strcmp(argv[2], "BT_PROPERTY_ADAPTER_SCAN_MODE")) {
+ *puser = TYPE_ENUM(bt_scan_mode_t);
+ *penum_func = enum_defines;
+ }
+ }
+}
+
static void set_adapter_property_p(int argc, const char **argv)
{
bt_property_t property;
@@ -354,9 +490,12 @@ static void set_adapter_property_p(int argc, const char **argv)
int timeout;
RETURN_IF_NULL(if_bluetooth);
+ VERIFY_PROP_TYPE_ARG(2, property.type);
- property.type = str2btpropertytype(argv[2]);
-
+ if (argc <= 3) {
+ haltest_error("No property value specified\n");
+ return;
+ }
switch (property.type) {
case BT_PROPERTY_BDNAME:
property.len = strlen(argv[3]) + 1;
@@ -383,39 +522,70 @@ static void set_adapter_property_p(int argc, const char **argv)
EXEC(if_bluetooth->set_adapter_property, &property);
}
+/*
+ * This function is to be used for completion methods that need only address
+ */
+static void complete_addr_c(int argc, const char **argv,
+ enum_func *penum_func, void **puser)
+{
+ if (argc == 3) {
+ *puser = NULL;
+ *penum_func = enum_devices;
+ }
+}
+
+/* Just addres to complete, use complete_addr_c */
+#define get_remote_device_properties_c complete_addr_c
+
static void get_remote_device_properties_p(int argc, const char **argv)
{
bt_bdaddr_t addr;
RETURN_IF_NULL(if_bluetooth);
-
- str2bt_bdaddr_t(argv[2], &addr);
+ VERIFY_ADDR_ARG(2, &addr);
EXEC(if_bluetooth->get_remote_device_properties, &addr);
}
+static void get_remote_device_property_c(int argc, const char **argv,
+ enum_func *penum_func,
+ void **puser)
+{
+ if (argc == 3) {
+ *puser = NULL;
+ *penum_func = enum_devices;
+ } else if (argc == 4) {
+ *puser = TYPE_ENUM(bt_property_type_t);
+ *penum_func = enum_defines;
+ }
+}
+
static void get_remote_device_property_p(int argc, const char **argv)
{
bt_property_type_t type;
bt_bdaddr_t addr;
RETURN_IF_NULL(if_bluetooth);
-
- str2bt_bdaddr_t(argv[2], &addr);
- type = str2btpropertytype(argv[3]);
+ VERIFY_ADDR_ARG(2, &addr);
+ VERIFY_PROP_TYPE_ARG(3, type);
EXEC(if_bluetooth->get_remote_device_property, &addr, type);
}
+/*
+ * Same completion as for get_remote_device_property_c can be used for
+ * set_remote_device_property_c. No need to create separate function.
+ */
+#define set_remote_device_property_c get_remote_device_property_c
+
static void set_remote_device_property_p(int argc, const char **argv)
{
bt_property_t property;
bt_bdaddr_t addr;
RETURN_IF_NULL(if_bluetooth);
-
- str2bt_bdaddr_t(argv[2], &addr);
- property.type = str2btpropertytype(argv[3]);
+ VERIFY_ADDR_ARG(2, &addr);
+ VERIFY_PROP_TYPE_ARG(3, property.type);
switch (property.type) {
case BT_PROPERTY_REMOTE_FRIENDLY_NAME:
@@ -430,26 +600,37 @@ static void set_remote_device_property_p(int argc, const char **argv)
EXEC(if_bluetooth->set_remote_device_property, &addr, &property);
}
+/*
+ * For now uuid is not autocompleted. Use routine for complete_addr_c
+ */
+#define get_remote_service_record_c complete_addr_c
+
static void get_remote_service_record_p(int argc, const char **argv)
{
bt_bdaddr_t addr;
bt_uuid_t uuid;
RETURN_IF_NULL(if_bluetooth);
+ VERIFY_ADDR_ARG(2, &addr);
- str2bt_bdaddr_t(argv[2], &addr);
+ if (argc <= 3) {
+ haltest_error("No uuid specified\n");
+ return;
+ }
str2bt_uuid_t(argv[3], &uuid);
EXEC(if_bluetooth->get_remote_service_record, &addr, &uuid);
}
+/* Just addres to complete, use complete_addr_c */
+#define get_remote_services_c complete_addr_c
+
static void get_remote_services_p(int argc, const char **argv)
{
bt_bdaddr_t addr;
RETURN_IF_NULL(if_bluetooth);
-
- str2bt_bdaddr_t(argv[2], &addr);
+ VERIFY_ADDR_ARG(2, &addr);
EXEC(if_bluetooth->get_remote_services, &addr);
}
@@ -468,39 +649,55 @@ static void cancel_discovery_p(int argc, const char **argv)
EXEC(if_bluetooth->cancel_discovery);
}
+/* Just addres to complete, use complete_addr_c */
+#define create_bond_c complete_addr_c
+
static void create_bond_p(int argc, const char **argv)
{
bt_bdaddr_t addr;
RETURN_IF_NULL(if_bluetooth);
-
- str2bt_bdaddr_t(argv[2], &addr);
+ VERIFY_ADDR_ARG(2, &addr);
EXEC(if_bluetooth->create_bond, &addr);
}
+/* Just addres to complete, use complete_addr_c */
+#define remove_bond_c complete_addr_c
+
static void remove_bond_p(int argc, const char **argv)
{
bt_bdaddr_t addr;
RETURN_IF_NULL(if_bluetooth);
-
- str2bt_bdaddr_t(argv[2], &addr);
+ VERIFY_ADDR_ARG(2, &addr);
EXEC(if_bluetooth->remove_bond, &addr);
}
+/* Just addres to complete, use complete_addr_c */
+#define cancel_bond_c complete_addr_c
+
static void cancel_bond_p(int argc, const char **argv)
{
bt_bdaddr_t addr;
RETURN_IF_NULL(if_bluetooth);
-
- str2bt_bdaddr_t(argv[2], &addr);
+ VERIFY_ADDR_ARG(2, &addr);
EXEC(if_bluetooth->cancel_bond, &addr);
}
+static void pin_reply_c(int argc, const char **argv,
+ enum_func *penum_func, void **puser)
+{
+ static const char *const completions[] = { last_remote_addr, NULL };
+ if (argc == 3) {
+ *puser = (void *) completions;
+ *penum_func = enum_strings;
+ }
+}
+
static void pin_reply_p(int argc, const char **argv)
{
bt_bdaddr_t addr;
@@ -509,14 +706,9 @@ static void pin_reply_p(int argc, const char **argv)
int accept;
RETURN_IF_NULL(if_bluetooth);
+ VERIFY_ADDR_ARG(2, &addr);
- if (argc < 3) {
- haltest_error("No address specified\n");
- return;
- }
- str2bt_bdaddr_t(argv[2], &addr);
-
- if (argc >= 4) {
+ if (argc > 3) {
accept = 1;
pin_len = strlen(argv[3]);
memcpy(pin.pin, argv[3], pin_len);
@@ -525,6 +717,26 @@ static void pin_reply_p(int argc, const char **argv)
EXEC(if_bluetooth->pin_reply, &addr, accept, pin_len, &pin);
}
+static void ssp_reply_c(int argc, const char **argv,
+ enum_func *penum_func, void **puser)
+{
+ if (argc == 3) {
+ *puser = last_remote_addr;
+ *penum_func = enum_one_string;
+ } else if (argc == 5) {
+ *puser = "1";
+ *penum_func = enum_one_string;
+ } else if (argc == 4) {
+ if (-1 != (int) last_ssp_variant) {
+ *puser = (void *) bt_ssp_variant_t2str(last_ssp_variant);
+ *penum_func = enum_one_string;
+ } else {
+ *puser = TYPE_ENUM(bt_ssp_variant_t);
+ *penum_func = enum_defines;
+ }
+ }
+}
+
static void ssp_reply_p(int argc, const char **argv)
{
bt_bdaddr_t addr;
@@ -533,12 +745,8 @@ static void ssp_reply_p(int argc, const char **argv)
int passkey;
RETURN_IF_NULL(if_bluetooth);
+ VERIFY_ADDR_ARG(2, &addr);
- if (argc < 3) {
- haltest_error("No address specified\n");
- return;
- }
- str2bt_bdaddr_t(argv[2], &addr);
if (argc < 4) {
haltest_error("No ssp variant specified\n");
return;
@@ -557,6 +765,29 @@ static void ssp_reply_p(int argc, const char **argv)
EXEC(if_bluetooth->ssp_reply, &addr, var, accept, passkey);
}
+static void get_profile_interface_c(int argc, const char **argv,
+ enum_func *penum_func, void **puser)
+{
+ static const char *const profile_ids[] = {
+ BT_PROFILE_HANDSFREE_ID,
+ BT_PROFILE_ADVANCED_AUDIO_ID,
+ BT_PROFILE_HEALTH_ID,
+ BT_PROFILE_SOCKETS_ID,
+ BT_PROFILE_HIDHOST_ID,
+ BT_PROFILE_PAN_ID,
+#if PLATFORM_SDK_VERSION >= 18
+ BT_PROFILE_GATT_ID,
+#endif
+ BT_PROFILE_AV_RC_ID,
+ NULL
+ };
+
+ if (argc == 3) {
+ *puser = (void *) profile_ids;
+ *penum_func = enum_strings;
+ }
+}
+
static void get_profile_interface_p(int argc, const char **argv)
{
const char *id = argv[2];
@@ -595,6 +826,10 @@ static void dut_mode_configure_p(int argc, const char **argv)
RETURN_IF_NULL(if_bluetooth);
+ if (argc <= 2) {
+ haltest_error("No dut mode specified\n");
+ return;
+ }
mode = strtol(argv[2], NULL, 0);
EXEC(if_bluetooth->dut_mode_configure, mode);
@@ -606,22 +841,22 @@ static struct method methods[] = {
STD_METHOD(enable),
STD_METHOD(disable),
STD_METHOD(get_adapter_properties),
- STD_METHOD(get_adapter_property),
- STD_METHOD(set_adapter_property),
- STD_METHOD(get_remote_device_properties),
- STD_METHOD(get_remote_device_property),
- STD_METHOD(set_remote_device_property),
- STD_METHOD(get_remote_service_record),
- STD_METHOD(get_remote_services),
+ STD_METHODCH(get_adapter_property, "<prop_type>"),
+ STD_METHODCH(set_adapter_property, "<prop_type> <prop_value>"),
+ STD_METHODCH(get_remote_device_properties, "<addr>"),
+ STD_METHODCH(get_remote_device_property, "<addr> <property_type>"),
+ STD_METHODCH(set_remote_device_property, "<addr> <property_type> <value>"),
+ STD_METHODCH(get_remote_service_record, "<addr> <uuid>"),
+ STD_METHODCH(get_remote_services, "<addr>"),
STD_METHOD(start_discovery),
STD_METHOD(cancel_discovery),
- STD_METHOD(create_bond),
- STD_METHOD(remove_bond),
- STD_METHOD(cancel_bond),
- STD_METHOD(pin_reply),
- STD_METHOD(ssp_reply),
- STD_METHOD(get_profile_interface),
- STD_METHOD(dut_mode_configure),
+ STD_METHODCH(create_bond, "<addr>"),
+ STD_METHODCH(remove_bond, "<addr>"),
+ STD_METHODCH(cancel_bond, "<addr>"),
+ STD_METHODCH(pin_reply, "<address> [<pin>]"),
+ STD_METHODCH(ssp_reply, "<address> <ssp_veriant> 1|0 [<passkey>]"),
+ STD_METHODCH(get_profile_interface, "<profile id>"),
+ STD_METHODH(dut_mode_configure, "<dut mode>"),
END_METHOD
};
diff --git a/android/client/if-main.h b/android/client/if-main.h
index 3fb3007..b6bbf05 100644
--- a/android/client/if-main.h
+++ b/android/client/if-main.h
@@ -103,6 +103,12 @@ int haltest_error(const char *format, ...);
int haltest_info(const char *format, ...);
int haltest_warn(const char *format, ...);
+/*
+ * Enumerator for discovered devices, to be used as tab completion enum_func
+ */
+const char *enum_devices(void *v, int i);
+void add_remote_device(const bt_bdaddr_t *addr);
+
/* Helper macro for executing function on interface and printing BT_STATUS */
#define EXEC(f, ...) \
{ \
@@ -119,3 +125,13 @@ int haltest_warn(const char *format, ...);
#define RETURN_IF_NULL(x) \
do { if (!x) { haltest_error("%s is NULL\n", #x); return; } } while (0)
+
+#define VERIFY_ADDR_ARG(n, adr) \
+ do { \
+ if (n < argc) \
+ str2bt_bdaddr_t(argv[n], adr); \
+ else { \
+ haltest_error("No address specified\n");\
+ return;\
+ } \
+ } while (0)
diff --git a/android/client/textconv.c b/android/client/textconv.c
index eebad70..3493b1c 100644
--- a/android/client/textconv.c
+++ b/android/client/textconv.c
@@ -203,3 +203,24 @@ void str2bt_uuid_t(const char *str, bt_uuid_t *uuid)
str += 2;
}
}
+
+const char *enum_defines(void *v, int i)
+{
+ const struct int2str *m = v;
+
+ return m[i].str != NULL ? m[i].str : NULL;
+}
+
+const char *enum_strings(void *v, int i)
+{
+ const char **m = v;
+
+ return m[i] != NULL ? m[i] : NULL;
+}
+
+const char *enum_one_string(void *v, int i)
+{
+ const char *m = v;
+
+ return (i == 0) && (m[0] != 0) ? m : NULL;
+}
diff --git a/android/client/textconv.h b/android/client/textconv.h
index 8fe976c..88da641 100644
--- a/android/client/textconv.h
+++ b/android/client/textconv.h
@@ -54,7 +54,11 @@ struct int2str {
int int2str_findint(int v, const struct int2str m[]);
int int2str_findstr(const char *str, const struct int2str m[]);
+const char *enum_defines(void *v, int i);
+const char *enum_strings(void *v, int i);
+const char *enum_one_string(void *v, int i);
+#define TYPE_ENUM(type) ((void *)&__##type##2str[0])
#define DECINTMAP(type) \
extern struct int2str __##type##2str[]; \
const char *type##2##str(type v); \
--
1.7.9.5
^ permalink raw reply related
* [PATCH 2/3] android: Fix error in draw line in haltest tool
From: Jerzy Kasenberg @ 2013-10-18 13:15 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Jerzy Kasenberg
In-Reply-To: <1382102160-21532-1-git-send-email-jerzy.kasenberg@tieto.com>
This fixes small error that showed up when tab completion inserted
characters before end of line.
Cursor in line was not moved correctly.
---
android/client/terminal.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/android/client/terminal.c b/android/client/terminal.c
index 0421633..8dd3a25 100644
--- a/android/client/terminal.c
+++ b/android/client/terminal.c
@@ -140,7 +140,7 @@ void terminal_draw_command_line(void)
putchar('>');
/* move cursor to it's place */
- terminal_move_cursor(line_len - line_buf_ix);
+ terminal_move_cursor(line_buf_ix - line_len);
}
/* inserts string into command line at cursor position */
--
1.7.9.5
^ permalink raw reply related
* [PATCH 1/3] android: Add tab completion to haltest
From: Jerzy Kasenberg @ 2013-10-18 13:15 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Jerzy Kasenberg
In-Reply-To: <1382102160-21532-1-git-send-email-jerzy.kasenberg@tieto.com>
This patch adds tab completion to interfaces, methods and parameters
in haltest.
---
Makefile.android | 2 +
android/Android.mk | 1 +
android/client/if-main.h | 28 +++-
android/client/tabcompletion.c | 313 ++++++++++++++++++++++++++++++++++++++++
android/client/terminal.c | 2 +-
5 files changed, 342 insertions(+), 4 deletions(-)
create mode 100644 android/client/tabcompletion.c
diff --git a/Makefile.android b/Makefile.android
index 56caf78..dcaca3c 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -42,6 +42,7 @@ android_haltest_SOURCES = android/client/haltest.c \
android/client/terminal.c \
android/client/history.c \
android/client/textconv.c \
+ android/client/tabcompletion.c \
android/client/if-bt.c \
android/client/hwmodule.c
@@ -67,6 +68,7 @@ EXTRA_DIST += android/client/terminal.c \
android/client/history.c \
android/client/if-bt.c \
android/client/textconv.c \
+ android/client/tabcompletion.c \
android/client/textconv.h \
android/client/if-main.h \
android/client/pollhandler.h \
diff --git a/android/Android.mk b/android/Android.mk
index 5858c3d..30b2169 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -78,6 +78,7 @@ LOCAL_SRC_FILES := \
client/terminal.c \
client/history.c \
client/textconv.c \
+ client/tabcompletion.c \
client/if-bt.c \
LOCAL_SHARED_LIBRARIES := libhardware
diff --git a/android/client/if-main.h b/android/client/if-main.h
index 9cac7ef..3fb3007 100644
--- a/android/client/if-main.h
+++ b/android/client/if-main.h
@@ -56,9 +56,12 @@ extern const struct interface bluetooth_if;
/* Interfaces that will show up in tool (first part of command line) */
extern const struct interface *interfaces[];
-#define METHOD(name, func) {name, func}
-#define STD_METHOD(m) {#m, m##_p}
-#define END_METHOD {"", NULL}
+#define METHOD(name, func, comp, help) {name, func, comp, help}
+#define STD_METHOD(m) {#m, m##_p, NULL, NULL}
+#define STD_METHODC(m) {#m, m##_p, m##_c, NULL}
+#define STD_METHODH(m, h) {#m, m##_p, NULL, h}
+#define STD_METHODCH(m, h) {#m, m##_p, m##_c, h}
+#define END_METHOD {"", NULL, NULL, NULL}
/*
* Function to parse argument for function, argv[0] and argv[1] are already
@@ -69,12 +72,31 @@ extern const struct interface *interfaces[];
typedef void (*parse_and_call)(int argc, const char **argv);
/*
+ * This is prototype of function that will return string for given number.
+ * Purpose is to enumerate string for auto completion.
+ * Function of this type will always be called in loop.
+ * First time function is called i = 0, then if function returns non-NULL
+ * it will be called again till for some value of i it will return NULL
+ */
+typedef const char *(*enum_func)(void *user, int i);
+
+/*
+ * This is prototype of function that when given argc, argv will
+ * fill penum_func with pointer to function that will enumerate
+ * parameters for argc argument, puser will be passed to penum_func.
+ */
+typedef void (*tab_complete)(int argc, const char **argv,
+ enum_func *penum_func, void **puser);
+
+/*
* For each method there is name and two functions to parse command line
* and call proper hal function on.
*/
struct method {
const char *name;
parse_and_call func;
+ tab_complete complete;
+ const char *help;
};
int haltest_error(const char *format, ...);
diff --git a/android/client/tabcompletion.c b/android/client/tabcompletion.c
new file mode 100644
index 0000000..e9c9921
--- /dev/null
+++ b/android/client/tabcompletion.c
@@ -0,0 +1,313 @@
+/*
+ * Copyright (C) 2013 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <ctype.h>
+#include "if-main.h"
+#include "terminal.h"
+
+/* how many times tab was hit */
+static int tab_hit_count;
+
+typedef struct split_arg {
+ struct split_arg *next; /* next argument in buffer */
+ const char *origin; /* pointer to original argument */
+ char ntcopy[1]; /* null terminated copy of argument */
+} split_arg_t;
+
+/* function returns interface of given name or NULL if not found */
+static const struct interface *get_interface(const char *name)
+{
+ int i;
+
+ for (i = 0; interfaces[i] != NULL; ++i) {
+ if (strcmp(interfaces[i]->name, name) == 0)
+ break;
+ }
+
+ return interfaces[i];
+}
+
+/* function returns method of given name or NULL if not found */
+static const struct method *get_method(const char *iname, const char *mname)
+{
+ int i;
+ const struct interface *iface = get_interface(iname);
+
+ if (iface == NULL)
+ return NULL;
+
+ for (i = 0; iface->methods[i].name[0]; ++i) {
+ if (0 == strcmp(iface->methods[i].name, mname))
+ return &iface->methods[i];
+ }
+ return NULL;
+}
+
+/* prints matching elements */
+static void print_matches(enum_func f, void *user, const char *prefix, int len)
+{
+ int i;
+ const char *enum_name;
+
+ putchar('\n');
+ for (i = 0; NULL != (enum_name = f(user, i)); ++i) {
+ if (strncmp(enum_name, prefix, len) == 0)
+ printf("%s\t", enum_name);
+ }
+ putchar('\n');
+ terminal_draw_command_line();
+}
+
+/*
+ * This function splits command line into linked list of arguments.
+ * line_buffer - pointer to input comman line
+ * size - size of command line to parse
+ * buf - output buffer to keep splited arguments list
+ * buf_size_in_bytes - size of buf
+ */
+static int split_command(const char *line_buffer, int size,
+ split_arg_t *buf, int buf_size_in_bytes)
+{
+ split_arg_t *prev = NULL;
+ split_arg_t *arg = buf;
+ int argc = 0;
+ const char *p = line_buffer;
+ const char *e = p + (size > 0 ? size : (int) strlen(p));
+ int len;
+
+ do {
+ while (p < e && isspace(*p))
+ p++;
+ arg->origin = p;
+ arg->next = NULL;
+ while (p < e && !isspace(*p))
+ p++;
+ len = p - arg->origin;
+ if (&arg->ntcopy[0] + len + 1 >
+ (const char *) buf + buf_size_in_bytes)
+ break;
+ strncpy(arg->ntcopy, arg->origin, len);
+ arg->ntcopy[len] = 0;
+ if (prev != NULL)
+ prev->next = arg;
+ prev = arg;
+ arg += (2 * sizeof(*arg) + len) / sizeof(*arg);
+ argc++;
+ } while (p < e);
+
+ return argc;
+}
+
+/* Function to enumerate interface names */
+static const char *interface_name(void *v, int i)
+{
+ return interfaces[i] ? interfaces[i]->name : NULL;
+}
+
+/* Function to enumerate method names */
+static const char *methods_name(void *v, int i)
+{
+ const struct interface *iface = v;
+
+ return iface->methods[i].name[0] ? iface->methods[i].name : NULL;
+}
+
+struct command_completion_args;
+typedef void (*short_help)(struct command_completion_args *args);
+
+struct command_completion_args {
+ const split_arg_t *arg; /* list of arguments */
+ const char *typed; /* last typed element */
+ enum_func func; /* enumerating function */
+ void *user; /* argument to enumerating function */
+ short_help help; /* help function */
+ void *user_help; /* additional data (used by short_help) */
+};
+
+/*
+ * complete command line
+ */
+static void command_completion(struct command_completion_args *args)
+{
+ const char *name = args->typed;
+ const int len = strlen(name);
+ int i;
+ int j;
+ char prefix[128] = {0};
+ int prefix_len = 0;
+ int count = 0;
+ const char *enum_name;
+
+ for (i = 0; NULL != (enum_name = args->func(args->user, i)); ++i) {
+ /* prefix does not match */
+ if (strncmp(enum_name, name, len) != 0)
+ continue;
+ /* prefix matches first time */
+ if (count++ == 0) {
+ strcpy(prefix, enum_name);
+ prefix_len = strlen(prefix);
+ continue;
+ }
+ /*
+ * Prefix matches next time
+ * reduce prefix to common part
+ */
+ for (j = 0; prefix[j] != 0
+ && prefix[j] == enum_name[j];)
+ ++j;
+ prefix_len = j;
+ prefix[j] = 0;
+ }
+
+ if (count == 0) {
+ /* no matches */
+ if (args->help != NULL)
+ args->help(args);
+ tab_hit_count = 0;
+ return;
+ }
+ /* len == prefix_len => nothing new was added */
+ if (len == prefix_len) {
+ if (count != 1) {
+ if (tab_hit_count == 1)
+ putchar('\a');
+ else if (tab_hit_count == 2 ||
+ args->help == NULL) {
+ print_matches(args->func,
+ args->user, name, len);
+ } else {
+ args->help(args);
+ tab_hit_count = 1;
+ }
+ } else if (count == 1) {
+ /* nothing to add, exact match add space */
+ terminal_insert_into_command_line(" ");
+ }
+ } else {
+ /* new chars can be added from some interface name(s) */
+ if (count == 1) {
+ /* exact match, add space */
+ prefix[prefix_len++] = ' ';
+ prefix[prefix_len] = '\0';
+ }
+ terminal_insert_into_command_line(prefix + len);
+ tab_hit_count = 0;
+ }
+}
+
+/* interface completion */
+static void interface_completion(split_arg_t *arg)
+{
+ struct command_completion_args args = {
+ .arg = arg,
+ .typed = arg->ntcopy,
+ .func = interface_name
+ };
+
+ command_completion(&args);
+}
+
+/* method completion */
+static void method_completion(const struct interface *iface, split_arg_t *arg)
+{
+ struct command_completion_args args = {
+ .arg = arg,
+ .typed = arg->next->ntcopy,
+ .func = methods_name,
+ .user = (void *) iface
+ };
+
+ if (iface == NULL)
+ return;
+
+ command_completion(&args);
+}
+
+/* prints short help on method for interface */
+static void method_help(struct command_completion_args *args)
+{
+ if (args->user_help == NULL)
+ return;
+
+ haltest_info("%s %s %s\n", args->arg->ntcopy,
+ args->arg->next->ntcopy, args->user_help);
+}
+
+/* So we have empty enumeration */
+static const char *return_null(void *user, int i)
+{
+ return NULL;
+}
+
+/* parameter completion function */
+static void param_completion(int argc, const split_arg_t *arg)
+{
+ const struct method *method;
+ int i;
+ const char *argv[argc];
+ const split_arg_t *tmp = arg;
+ struct command_completion_args args = {
+ .arg = arg,
+ .func = return_null
+ };
+
+ /* prepare standard argv from arg */
+ for (i = 0; i < argc; ++i) {
+ argv[i] = tmp->ntcopy;
+ tmp = tmp->next;
+ }
+
+ /* Find method for <interface, name> pair */
+ method = get_method(argv[0], argv[1]);
+
+ if (method != NULL && method->complete != NULL) {
+ /* ask method for completion function */
+ method->complete(argc, argv, &args.func, &args.user);
+ }
+
+ /* If method provided enumeration function call try to complete */
+ if (args.func != NULL) {
+ args.typed = argv[argc - 1];
+ args.help = method_help;
+ args.user_help = (void *) method->help;
+
+ command_completion(&args);
+ }
+}
+
+/*
+ * This methd gets called when user tapped tab key.
+ * line - points to comman line
+ * len - size of line that should be used for comletions. This should be
+ * cursor position during tab hit.
+ */
+void process_tab(const char *line, int len)
+{
+ int argc;
+ static split_arg_t buf[(LINE_BUF_MAX * 2) / sizeof(split_arg_t)];
+
+ argc = split_command(line, len, buf, sizeof(buf));
+ tab_hit_count++;
+
+ if (argc == 1)
+ interface_completion(buf);
+ else if (argc == 2)
+ method_completion(get_interface(buf[0].ntcopy), buf);
+ else if (argc > 2)
+ param_completion(argc, buf);
+}
diff --git a/android/client/terminal.c b/android/client/terminal.c
index b484ef6..0421633 100644
--- a/android/client/terminal.c
+++ b/android/client/terminal.c
@@ -453,7 +453,7 @@ void terminal_process_char(int c, void (*process_line)(char *line))
break;
case '\t':
/* tab processing */
- /* TODO Add completion here */
+ process_tab(line_buf, line_buf_ix);
break;
case KEY_BACKSPACE:
if (line_buf_ix <= 0)
--
1.7.9.5
^ permalink raw reply related
* [PATCH 0/3] Tab completion for haltest tool
From: Jerzy Kasenberg @ 2013-10-18 13:15 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Jerzy Kasenberg
This patchset add tab completion to haltest so using this tool
will be much easier.
It allows to build for andriod 4.3 and for host with autotools.
Jerzy Kasenberg (3):
android: Add tab completion to haltest
android: Fix error in draw line in haltest tool
android: Add completion for adapter to haltest
Makefile.android | 2 +
android/Android.mk | 1 +
android/client/haltest.c | 11 +-
android/client/if-bt.c | 331 ++++++++++++++++++++++++++++++++++------
android/client/if-main.h | 44 +++++-
android/client/tabcompletion.c | 313 +++++++++++++++++++++++++++++++++++++
android/client/terminal.c | 4 +-
android/client/textconv.c | 21 +++
android/client/textconv.h | 4 +
9 files changed, 673 insertions(+), 58 deletions(-)
create mode 100644 android/client/tabcompletion.c
--
1.7.9.5
^ permalink raw reply
* [PATCH] android: Add missing signal handler functionality
From: Ravi kumar Veeramally @ 2013-10-18 13:10 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
Added singal handling based on singalfd and removed sigaction
based code.
---
android/main.c | 80 +++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 65 insertions(+), 15 deletions(-)
diff --git a/android/main.c b/android/main.c
index 256b83b..4ae654c 100644
--- a/android/main.c
+++ b/android/main.c
@@ -32,6 +32,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
+#include <sys/signalfd.h>
#include <glib.h>
@@ -54,23 +55,74 @@ static uint8_t mgmt_revision = 0;
static uint16_t adapter_index = MGMT_INDEX_NONE;
-static gboolean quit_eventloop(gpointer user_data)
+static volatile sig_atomic_t __terminated = 0;
+
+static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
+ gpointer user_data)
{
- g_main_loop_quit(event_loop);
+ struct signalfd_siginfo si;
+ ssize_t result;
+ int fd;
+
+ if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
+ return FALSE;
+
+ fd = g_io_channel_unix_get_fd(channel);
+
+ result = read(fd, &si, sizeof(si));
+ if (result != sizeof(si))
+ return FALSE;
+
+ switch (si.ssi_signo) {
+ case SIGINT:
+ case SIGTERM:
+ if (__terminated == 0) {
+ info("Terminating");
+ g_main_loop_quit(event_loop);
+ }
+
+ __terminated = 1;
+ break;
+ }
- return FALSE;
+ return TRUE;
}
-static void sig_term(int sig)
+static guint setup_signalfd(void)
{
- static bool __terminated = false;
+ GIOChannel *channel;
+ guint source;
+ sigset_t mask;
+ int fd;
+
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGINT);
+ sigaddset(&mask, SIGTERM);
+
+ if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) {
+ perror("Failed to set signal mask");
+ return 0;
+ }
- if (!__terminated) {
- g_timeout_add_seconds(SHUTDOWN_GRACE_SECONDS,
- quit_eventloop, NULL);
+ fd = signalfd(-1, &mask, 0);
+ if (fd < 0) {
+ perror("Failed to create signal descriptor");
+ return 0;
}
- __terminated = true;
+ channel = g_io_channel_unix_new(fd);
+
+ g_io_channel_set_close_on_unref(channel, TRUE);
+ g_io_channel_set_encoding(channel, NULL, NULL);
+ g_io_channel_set_buffered(channel, FALSE);
+
+ source = g_io_add_watch(channel,
+ G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+ signal_handler, NULL);
+
+ g_io_channel_unref(channel);
+
+ return source;
}
static gboolean option_version = FALSE;
@@ -244,7 +296,7 @@ int main(int argc, char *argv[])
{
GOptionContext *context;
GError *err = NULL;
- struct sigaction sa;
+ guint signal;
context = g_option_context_new(NULL);
g_option_context_add_main_entries(context, options, NULL);
@@ -267,14 +319,10 @@ int main(int argc, char *argv[])
}
event_loop = g_main_loop_new(NULL, FALSE);
+ signal = setup_signalfd();
__btd_log_init("*", 0);
- memset(&sa, 0, sizeof(sa));
- sa.sa_handler = sig_term;
- sigaction(SIGINT, &sa, NULL);
- sigaction(SIGTERM, &sa, NULL);
-
if (!init_mgmt_interface())
return EXIT_FAILURE;
@@ -285,6 +333,8 @@ int main(int argc, char *argv[])
g_main_loop_run(event_loop);
+ g_source_remove(signal);
+
stop_sdp_server();
cleanup_mgmt_interface();
g_main_loop_unref(event_loop);
--
1.7.9.5
^ permalink raw reply related
* Re: [PATCH BlueZ] core: Fix typo in adapter.c comments
From: Johan Hedberg @ 2013-10-18 12:47 UTC (permalink / raw)
To: Claudio Takahasi; +Cc: linux-bluetooth
In-Reply-To: <1382099552-5562-3-git-send-email-claudio.takahasi@openbossa.org>
Hi Claudio,
On Fri, Oct 18, 2013, Claudio Takahasi wrote:
> ---
> src/adapter.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
Applied. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH BlueZ] core: Remove unneeded includes in device.c
From: Johan Hedberg @ 2013-10-18 12:47 UTC (permalink / raw)
To: Claudio Takahasi; +Cc: linux-bluetooth
In-Reply-To: <1382099552-5562-2-git-send-email-claudio.takahasi@openbossa.org>
Hi Claudio,
On Fri, Oct 18, 2013, Claudio Takahasi wrote:
> ---
> src/device.c | 3 ---
> 1 file changed, 3 deletions(-)
Applied. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH BlueZ] core: Remove leftover adapter_get_default()
From: Johan Hedberg @ 2013-10-18 12:47 UTC (permalink / raw)
To: Claudio Takahasi; +Cc: linux-bluetooth
In-Reply-To: <1382099552-5562-1-git-send-email-claudio.takahasi@openbossa.org>
Hi Claudio,
On Fri, Oct 18, 2013, Claudio Takahasi wrote:
> ---
> src/adapter.h | 1 -
> 1 file changed, 1 deletion(-)
Applied. Thanks.
Johan
^ permalink raw reply
* [PATCH BlueZ] core: Fix typo in adapter.c comments
From: Claudio Takahasi @ 2013-10-18 12:32 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1382099552-5562-1-git-send-email-claudio.takahasi@openbossa.org>
---
src/adapter.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 40a9c4e..30bcc4d 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -285,7 +285,7 @@ static void set_dev_class_complete(uint8_t status, uint16_t length,
}
/*
- * The parameters are idential and also the task that is
+ * The parameters are identical and also the task that is
* required in both cases. So it is safe to just call the
* event handling functions here.
*/
@@ -487,7 +487,7 @@ static void set_mode_complete(uint8_t status, uint16_t length,
}
/*
- * The parameters are idential and also the task that is
+ * The parameters are identical and also the task that is
* required in both cases. So it is safe to just call the
* event handling functions here.
*/
@@ -631,7 +631,7 @@ static void set_local_name_complete(uint8_t status, uint16_t length,
}
/*
- * The parameters are idential and also the task that is
+ * The parameters are identical and also the task that is
* required in both cases. So it is safe to just call the
* event handling functions here.
*/
@@ -753,7 +753,7 @@ static void add_uuid_complete(uint8_t status, uint16_t length,
}
/*
- * The parameters are idential and also the task that is
+ * The parameters are identical and also the task that is
* required in both cases. So it is safe to just call the
* event handling functions here.
*/
@@ -805,7 +805,7 @@ static void remove_uuid_complete(uint8_t status, uint16_t length,
}
/*
- * The parameters are idential and also the task that is
+ * The parameters are identical and also the task that is
* required in both cases. So it is safe to just call the
* event handling functions here.
*/
@@ -856,7 +856,7 @@ static void clear_uuids_complete(uint8_t status, uint16_t length,
}
/*
- * The parameters are idential and also the task that is
+ * The parameters are identical and also the task that is
* required in both cases. So it is safe to just call the
* event handling functions here.
*/
@@ -1868,7 +1868,7 @@ static void property_set_mode_complete(uint8_t status, uint16_t length,
g_dbus_pending_property_success(data->id);
/*
- * The parameters are idential and also the task that is
+ * The parameters are identical and also the task that is
* required in both cases. So it is safe to just call the
* event handling functions here.
*/
--
1.8.3.1
^ permalink raw reply related
* [PATCH BlueZ] core: Remove unneeded includes in device.c
From: Claudio Takahasi @ 2013-10-18 12:32 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1382099552-5562-1-git-send-email-claudio.takahasi@openbossa.org>
---
src/device.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/device.c b/src/device.c
index 3dd3584..77f2322 100644
--- a/src/device.c
+++ b/src/device.c
@@ -31,8 +31,6 @@
#include <unistd.h>
#include <fcntl.h>
#include <stdbool.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
#include <errno.h>
#include <dirent.h>
#include <time.h>
@@ -64,7 +62,6 @@
#include "sdp-client.h"
#include "attrib/gatt.h"
#include "agent.h"
-#include "sdp-xml.h"
#include "storage.h"
#include "attrib-server.h"
--
1.8.3.1
^ permalink raw reply related
* [PATCH BlueZ] core: Remove leftover adapter_get_default()
From: Claudio Takahasi @ 2013-10-18 12:32 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
---
src/adapter.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/adapter.h b/src/adapter.h
index 5d124e7..80c5f77 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -82,7 +82,6 @@ void adapter_shutdown(void);
struct btd_adapter *adapter_find(const bdaddr_t *sba);
struct btd_adapter *adapter_find_by_id(int id);
-struct btd_adapter *adapter_get_default(void);
void adapter_foreach(adapter_cb func, gpointer user_data);
bool btd_adapter_get_pairable(struct btd_adapter *adapter);
--
1.8.3.1
^ permalink raw reply related
* Re: [PATCH 1/2] Bluetooth: Use hcon directly instead of conn->hcon where possible
From: Johan Hedberg @ 2013-10-18 11:44 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1382092981-48006-1-git-send-email-marcel@holtmann.org>
Hi Marcel,
On Fri, Oct 18, 2013, Marcel Holtmann wrote:
> When the HCI connection hcon is already dereferenced, then use hcon
> directly instead of conn->hcon.
>
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
> net/bluetooth/l2cap_core.c | 7 +++----
> net/bluetooth/smp.c | 2 +-
> 2 files changed, 4 insertions(+), 5 deletions(-)
Both patches have been applied to bluetooth-next. Thanks.
Johan
^ permalink raw reply
* Re: [PATCHv5 0/7] Android BlueZ patches, second chunk
From: Johan Hedberg @ 2013-10-18 11:36 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1381998406-16662-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
On Thu, Oct 17, 2013, Andrei Emeltchenko wrote:
> This is second chunk from my initial big patch set. Fixed style issues
> commented by Marcel.
>
> Changes:
> * v5: Rebased against upstream, hid and pan now uses explicit struct initialization,
> adapter-related functionality moved to adapter.c, fixed issues reported by Johan.
> * v4: Fixes several typos and missing style issues commented by Marcel earlier.
> * v3: Following upstream comments file names are changed from "_" to "-", added kernel style
> struct initialization, fixed bug checking status for mgmt commands, added 2 HALs skeletons.
> * v2: Corrected android_daemon -> enable_android autoconf stuff, better name for acquiring caps,
> renamed hal_msg.h to hal-msg.h due to Johan's comment. Added small test-sdp fix.
>
> Note that due to Marcel comment this cannot be built unless you include my patch
> for Android bionic library:
> http://code.google.com/p/android-bluez/source/detail?r=77a07e7703b63e280d9880baad30b3375e7df079&repo=bionic#
>
> Andrei Emeltchenko (7):
> android: Add capabilities and set userid
> android: Implement read_info_complete callback
> android: Use kernel style to initialize struct fields
> android: Rename hal_bluetooth.c to hal-bluetooth.c
> android: Rename hal_bt_sock.c to hal-bt-sock.c
> android: Add HID Host skeleton
> android: Add PAN skeleton
>
> Makefile.android | 3 +-
> android/Android.mk | 7 +-
> android/adapter.c | 108 +++++++++++--
> android/hal-bluetooth.c | 392 +++++++++++++++++++++++++++++++++++++++++++++++
> android/hal-bt-sock.c | 85 ++++++++++
> android/hal-hidhost.c | 204 ++++++++++++++++++++++++
> android/hal-pan.c | 120 +++++++++++++++
> android/hal.h | 2 +
> android/hal_bluetooth.c | 384 ----------------------------------------------
> android/hal_bt_sock.c | 85 ----------
> android/main.c | 77 ++++++++--
> configure.ac | 4 +
> 12 files changed, 980 insertions(+), 491 deletions(-)
> create mode 100644 android/hal-bluetooth.c
> create mode 100644 android/hal-bt-sock.c
> create mode 100644 android/hal-hidhost.c
> create mode 100644 android/hal-pan.c
> delete mode 100644 android/hal_bluetooth.c
> delete mode 100644 android/hal_bt_sock.c
After quite heavy fixing and additional patches of my own, these are now
upstream.
Johan
^ permalink raw reply
* [PATCH 2/2] Bluetooth: Block ATT connection on LE when device is blocked
From: Marcel Holtmann @ 2013-10-18 10:43 UTC (permalink / raw)
To: linux-bluetooth
When the remote LE device is blocked, then do not create a L2CAP
channel for it. Without a channel, all packets for that connection
will be dropped.
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
net/bluetooth/l2cap_core.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 9757297..bf1f34e 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1382,14 +1382,16 @@ static struct l2cap_chan *l2cap_global_chan_by_scid(int state, u16 cid,
static void l2cap_le_conn_ready(struct l2cap_conn *conn)
{
+ struct hci_conn *hcon = conn->hcon;
struct sock *parent;
struct l2cap_chan *chan, *pchan;
+ __u8 dst_type;
BT_DBG("");
/* Check if we have socket listening on cid */
pchan = l2cap_global_chan_by_scid(BT_LISTEN, L2CAP_CID_ATT,
- &conn->hcon->src, &conn->hcon->dst);
+ &hcon->src, &hcon->dst);
if (!pchan)
return;
@@ -1397,6 +1399,12 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
if (__l2cap_get_chan_by_dcid(conn, L2CAP_CID_ATT))
return;
+ dst_type = bdaddr_type(hcon, hcon->dst_type);
+
+ /* If device is blocked, do not create a channel for it */
+ if (hci_blacklist_lookup(hcon->hdev, &hcon->dst, dst_type))
+ return;
+
parent = pchan->sk;
lock_sock(parent);
@@ -1407,10 +1415,10 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
chan->dcid = L2CAP_CID_ATT;
- bacpy(&chan->src, &conn->hcon->src);
- bacpy(&chan->dst, &conn->hcon->dst);
- chan->src_type = bdaddr_type(conn->hcon, conn->hcon->src_type);
- chan->dst_type = bdaddr_type(conn->hcon, conn->hcon->dst_type);
+ bacpy(&chan->src, &hcon->src);
+ bacpy(&chan->dst, &hcon->dst);
+ chan->src_type = bdaddr_type(hcon, hcon->src_type);
+ chan->dst_type = dst_type;
__l2cap_chan_add(conn, chan);
@@ -6438,6 +6446,9 @@ static void l2cap_att_channel(struct l2cap_conn *conn,
BT_DBG("chan %p, len %d", chan, skb->len);
+ if (hci_blacklist_lookup(hcon->hdev, &hcon->dst, hcon->dst_type))
+ goto drop;
+
if (chan->imtu < skb->len)
goto drop;
--
1.8.3.1
^ permalink raw reply related
* [PATCH 1/2] Bluetooth: Use hcon directly instead of conn->hcon where possible
From: Marcel Holtmann @ 2013-10-18 10:43 UTC (permalink / raw)
To: linux-bluetooth
When the HCI connection hcon is already dereferenced, then use hcon
directly instead of conn->hcon.
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
net/bluetooth/l2cap_core.c | 7 +++----
net/bluetooth/smp.c | 2 +-
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 763b741..9757297 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -6399,8 +6399,7 @@ static void l2cap_conless_channel(struct l2cap_conn *conn, __le16 psm,
if (hcon->type != ACL_LINK)
goto drop;
- chan = l2cap_global_chan_by_psm(0, psm, &conn->hcon->src,
- &conn->hcon->dst);
+ chan = l2cap_global_chan_by_psm(0, psm, &hcon->src, &hcon->dst);
if (!chan)
goto drop;
@@ -6413,7 +6412,7 @@ static void l2cap_conless_channel(struct l2cap_conn *conn, __le16 psm,
goto drop;
/* Store remote BD_ADDR and PSM for msg_name */
- bacpy(&bt_cb(skb)->bdaddr, &conn->hcon->dst);
+ bacpy(&bt_cb(skb)->bdaddr, &hcon->dst);
bt_cb(skb)->psm = psm;
if (!chan->ops->recv(chan, skb))
@@ -6433,7 +6432,7 @@ static void l2cap_att_channel(struct l2cap_conn *conn,
goto drop;
chan = l2cap_global_chan_by_scid(BT_CONNECTED, L2CAP_CID_ATT,
- &conn->hcon->src, &conn->hcon->dst);
+ &hcon->src, &hcon->dst);
if (!chan)
goto drop;
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index fc200e0..85a2796c 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -864,7 +864,7 @@ int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb)
return -EILSEQ;
}
- if (!test_bit(HCI_LE_ENABLED, &conn->hcon->hdev->dev_flags)) {
+ if (!test_bit(HCI_LE_ENABLED, &hcon->hdev->dev_flags)) {
err = -ENOTSUPP;
reason = SMP_PAIRING_NOTSUPP;
goto done;
--
1.8.3.1
^ permalink raw reply related
* Re: [PATCH] Bluetooth: Add hci_h4p driver
From: Pali Rohár @ 2013-10-18 10:30 UTC (permalink / raw)
To: Marcel Holtmann
Cc: Gustavo Padovan, Johan Hedberg, Pavel Machek, linux-kernel,
linux-bluetooth,
Ивайло Димитров,
Joni Lapilainen, Sebastian Reichel, Aaro Koskinen
In-Reply-To: <3B0F039C-4680-46FF-A654-48D6A28B9B5E@holtmann.org>
[-- Attachment #1: Type: Text/Plain, Size: 62533 bytes --]
On Friday 18 October 2013 00:11:44 Marcel Holtmann wrote:
> Hi Pali,
>
> >> This driver adding support for Nokia N900 bluetooth
> >> hardware
> >>
> >> Signed-off-by: Ville Tervo <ville.tervo@nokia.com>
> >> Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
> >> ---
> >> drivers/bluetooth/Kconfig | 10 +
> >> drivers/bluetooth/Makefile | 2 +
> >> drivers/bluetooth/hci_h4p/Makefile | 7 +
> >> drivers/bluetooth/hci_h4p/core.c | 1085
> >> +++++++++++++++++++++++++++++++++
> >> drivers/bluetooth/hci_h4p/fw-bcm.c | 149 +++++
> >> drivers/bluetooth/hci_h4p/fw-csr.c | 152 +++++
> >> drivers/bluetooth/hci_h4p/fw-ti1273.c | 113 ++++
> >> drivers/bluetooth/hci_h4p/fw.c | 166 +++++
> >> drivers/bluetooth/hci_h4p/hci_h4p.h | 238 ++++++++
> >> drivers/bluetooth/hci_h4p/uart.c | 203 ++++++
> >> include/linux/bluetooth/hci_h4p.h | 41 ++
> >> 11 files changed, 2166 insertions(+)
> >> create mode 100644 drivers/bluetooth/hci_h4p/Makefile
> >> create mode 100644 drivers/bluetooth/hci_h4p/core.c
> >> create mode 100644 drivers/bluetooth/hci_h4p/fw-bcm.c
> >> create mode 100644 drivers/bluetooth/hci_h4p/fw-csr.c
> >> create mode 100644 drivers/bluetooth/hci_h4p/fw-ti1273.c
> >> create mode 100644 drivers/bluetooth/hci_h4p/fw.c
> >> create mode 100644 drivers/bluetooth/hci_h4p/hci_h4p.h
> >> create mode 100644 drivers/bluetooth/hci_h4p/uart.c
> >> create mode 100644 include/linux/bluetooth/hci_h4p.h
> >
> > Can somebody look & comment this patch? What is needed to be
> > part of upstream kernel?
>
> you need to rebase against bluetooth-next at least.
>
> Regards
>
> Marcel
I rebased patch on top of https://git.kernel.org/cgit/linux/kernel/git/bluetooth/bluetooth-next.git branch master
diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
index 11a6104..95155c3 100644
--- a/drivers/bluetooth/Kconfig
+++ b/drivers/bluetooth/Kconfig
@@ -242,4 +242,14 @@ config BT_WILINK
Say Y here to compile support for Texas Instrument's WiLink7 driver
into the kernel or say M to compile it as module.
+
+config BT_HCIH4P
+ tristate "HCI driver with H4 Nokia extensions"
+ depends on BT && ARCH_OMAP
+ help
+ Bluetooth HCI driver with H4 extensions. This driver provides
+ support for H4+ Bluetooth chip with vendor-specific H4 extensions.
+
+ Say Y here to compile support for h4 extended devices into the kernel
+ or say M to compile it as module (hci_h4p).
endmenu
diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile
index 9fe8a87..46759f1 100644
--- a/drivers/bluetooth/Makefile
+++ b/drivers/bluetooth/Makefile
@@ -20,6 +20,8 @@ obj-$(CONFIG_BT_MRVL) += btmrvl.o
obj-$(CONFIG_BT_MRVL_SDIO) += btmrvl_sdio.o
obj-$(CONFIG_BT_WILINK) += btwilink.o
+obj-y += hci_h4p/
+
btmrvl-y := btmrvl_main.o
btmrvl-$(CONFIG_DEBUG_FS) += btmrvl_debugfs.o
diff --git a/drivers/bluetooth/hci_h4p/Makefile b/drivers/bluetooth/hci_h4p/Makefile
new file mode 100644
index 0000000..f20bd9a
--- /dev/null
+++ b/drivers/bluetooth/hci_h4p/Makefile
@@ -0,0 +1,7 @@
+#
+# Makefile for the Linux Bluetooth HCI device drivers.
+#
+
+obj-$(CONFIG_BT_HCIH4P) += hci_h4p.o
+
+hci_h4p-objs := core.o fw.o uart.o fw-csr.o fw-bcm.o fw-ti1273.o
diff --git a/drivers/bluetooth/hci_h4p/core.c b/drivers/bluetooth/hci_h4p/core.c
new file mode 100644
index 0000000..13a1243
--- /dev/null
+++ b/drivers/bluetooth/hci_h4p/core.c
@@ -0,0 +1,1076 @@
+/*
+ * This file is part of hci_h4p bluetooth driver
+ *
+ * Copyright (C) 2005-2010 Nokia Corporation.
+ *
+ * Contact: Ville Tervo <ville.tervo@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/errno.h>
+#include <linux/delay.h>
+#include <linux/spinlock.h>
+#include <linux/serial_reg.h>
+#include <linux/skbuff.h>
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/interrupt.h>
+#include <linux/gpio.h>
+#include <linux/timer.h>
+#include <linux/bluetooth/hci_h4p.h>
+
+#include <net/bluetooth/bluetooth.h>
+#include <net/bluetooth/hci_core.h>
+#include <net/bluetooth/hci.h>
+
+#include "hci_h4p.h"
+
+static void hci_h4p_set_clk(struct hci_h4p_info *info, int *clock, int enable)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&info->clocks_lock, flags);
+ if (enable && !*clock) {
+ NBT_DBG_POWER("Enabling %p\n", clock);
+ clk_prepare_enable(info->uart_fclk);
+ clk_prepare_enable(info->uart_iclk);
+ if (atomic_read(&info->clk_users) == 0)
+ hci_h4p_restore_regs(info);
+ atomic_inc(&info->clk_users);
+ }
+
+ if (!enable && *clock) {
+ NBT_DBG_POWER("Disabling %p\n", clock);
+ if (atomic_dec_and_test(&info->clk_users))
+ hci_h4p_store_regs(info);
+ clk_disable_unprepare(info->uart_fclk);
+ clk_disable_unprepare(info->uart_iclk);
+ }
+
+ *clock = enable;
+ spin_unlock_irqrestore(&info->clocks_lock, flags);
+}
+
+/* Power management functions */
+void hci_h4p_smart_idle(struct hci_h4p_info *info, bool enable)
+{
+ u8 v;
+
+ return;
+
+ v = hci_h4p_inb(info, UART_OMAP_SYSC);
+ v &= ~(UART_OMAP_SYSC_IDLEMASK);
+
+ if (enable)
+ v |= UART_OMAP_SYSC_SMART_IDLE;
+ else
+ v |= UART_OMAP_SYSC_NO_IDLE;
+
+ hci_h4p_outb(info, UART_OMAP_SYSC, v);
+}
+
+static void hci_h4p_disable_tx(struct hci_h4p_info *info)
+{
+ NBT_DBG_POWER("\n");
+
+ if (!info->pm_enabled)
+ return;
+
+ hci_h4p_smart_idle(info, 1);
+
+ info->bt_wakeup(0);
+ hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
+ info->tx_enabled = 0;
+}
+
+void hci_h4p_enable_tx(struct hci_h4p_info *info)
+{
+ NBT_DBG_POWER("\n");
+
+ if (!info->pm_enabled)
+ return;
+
+ hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
+ info->tx_enabled = 1;
+ hci_h4p_smart_idle(info, 0);
+ info->bt_wakeup(1);
+ hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) |
+ UART_IER_THRI);
+}
+
+static void hci_h4p_disable_rx(struct hci_h4p_info *info)
+{
+ if (!info->pm_enabled)
+ return;
+
+ info->rx_enabled = 0;
+
+ if (hci_h4p_inb(info, UART_LSR) & UART_LSR_DR) {
+ NBT_DBG("data ready postpone autorts");
+ return;
+ }
+
+ if (!(hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT)) {
+ NBT_DBG("trasmitter not empty postpone autorts");
+ return;
+ }
+
+ hci_h4p_set_rts(info, info->rx_enabled);
+ __hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_RTS);
+ info->autorts = 0;
+ hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
+}
+
+static void hci_h4p_enable_rx(struct hci_h4p_info *info)
+{
+ if (!info->pm_enabled)
+ return;
+
+ hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
+ info->rx_enabled = 1;
+
+ hci_h4p_set_rts(info, 1);
+
+ if (!(hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT)) {
+ NBT_DBG("trasmitter not empty postpone autorts");
+ return;
+ }
+
+ if (hci_h4p_inb(info, UART_LSR) & UART_LSR_DR) {
+ NBT_DBG("data ready postpone autorts");
+ return;
+ }
+
+ __hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_RTS);
+ info->autorts = 1;
+}
+
+/* Negotiation functions */
+int hci_h4p_send_alive_packet(struct hci_h4p_info *info)
+{
+ struct hci_h4p_alive_hdr *alive_hdr;
+ struct hci_h4p_alive_msg *alive_cmd;
+ struct sk_buff *skb;
+ unsigned long flags;
+
+ NBT_DBG("Sending alive packet\n");
+
+ skb = bt_skb_alloc(HCI_H4P_ALIVE_HDR_SIZE + HCI_H4P_ALIVE_MSG_SIZE, GFP_ATOMIC);
+ if (!skb)
+ return -ENOMEM;
+
+ alive_hdr = (void *) skb_put(skb, HCI_H4P_ALIVE_HDR_SIZE);
+ alive_hdr->dlen = HCI_H4P_ALIVE_MSG_SIZE;
+ alive_cmd = (void *) skb_put(skb, HCI_H4P_ALIVE_MSG_SIZE);
+ alive_cmd->message_id = HCI_H4P_ALIVE_IND_REQ;
+ alive_cmd->unused = 0x00;
+ *skb_push(skb, 1) = H4_ALIVE_PKT;
+
+ skb_queue_tail(&info->txq, skb);
+ spin_lock_irqsave(&info->lock, flags);
+ hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) |
+ UART_IER_THRI);
+ spin_unlock_irqrestore(&info->lock, flags);
+
+ NBT_DBG("Alive packet sent\n");
+
+ return 0;
+}
+
+static void hci_h4p_alive_packet(struct hci_h4p_info *info, struct sk_buff *skb)
+{
+ struct hci_h4p_alive_hdr *alive_hdr = (void *) skb->data;
+ struct hci_h4p_alive_msg *alive_evt;
+
+ if (alive_hdr->dlen > skb->len) {
+ info->init_error = -EPROTO;
+ complete(&info->init_completion);
+ return;
+ }
+
+ alive_evt = (void *) skb_pull(skb, HCI_H4P_ALIVE_HDR_SIZE);
+
+ NBT_DBG("Received alive packet\n");
+ if (alive_evt->message_id != HCI_H4P_ALIVE_IND_RESP) {
+ dev_err(info->dev, "Could not negotiate hci_h4p settings\n");
+ info->init_error = -EINVAL;
+ }
+
+ complete(&info->init_completion);
+ kfree_skb(skb);
+}
+
+static int hci_h4p_send_negotiation(struct hci_h4p_info *info)
+{
+ struct hci_h4p_init_cmd *init_cmd;
+ struct hci_h4p_init_hdr *init_hdr;
+ struct sk_buff *skb;
+ unsigned long flags;
+ int err;
+
+ NBT_DBG("Sending negotiation..\n");
+
+ skb = bt_skb_alloc(HCI_H4P_INIT_HDR_SIZE + HCI_H4P_INIT_CMD_SIZE, GFP_KERNEL);
+ if (!skb)
+ return -ENOMEM;
+
+ init_hdr = (void *)skb_put(skb, HCI_H4P_INIT_HDR_SIZE);
+ init_hdr->dlen = HCI_H4P_INIT_CMD_SIZE;
+ init_cmd = (void *)skb_put(skb, HCI_H4P_INIT_CMD_SIZE);
+ init_cmd->ack = 0x00;
+ init_cmd->baudrate = cpu_to_le16(0x01a1);
+ init_cmd->unused = cpu_to_le16(0x0000);
+ init_cmd->mode = HCI_H4P_MODE;
+ init_cmd->sys_clk = cpu_to_le16(0x9600);
+ init_cmd->unused2 = cpu_to_le16(0x0000);
+ *skb_push(skb, 1) = H4_NEG_PKT;
+
+ hci_h4p_change_speed(info, INIT_SPEED);
+
+ hci_h4p_set_rts(info, 1);
+ info->init_error = 0;
+ init_completion(&info->init_completion);
+ skb_queue_tail(&info->txq, skb);
+ spin_lock_irqsave(&info->lock, flags);
+ hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) |
+ UART_IER_THRI);
+ spin_unlock_irqrestore(&info->lock, flags);
+
+ if (!wait_for_completion_interruptible_timeout(&info->init_completion,
+ msecs_to_jiffies(1000)))
+ return -ETIMEDOUT;
+
+ if (info->init_error < 0)
+ return info->init_error;
+
+ /* Change to operational settings */
+ hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_RTS);
+ hci_h4p_set_rts(info, 0);
+ hci_h4p_change_speed(info, MAX_BAUD_RATE);
+
+ err = hci_h4p_wait_for_cts(info, 1, 100);
+ if (err < 0)
+ return err;
+
+ hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_RTS);
+ init_completion(&info->init_completion);
+ err = hci_h4p_send_alive_packet(info);
+
+ if (err < 0)
+ return err;
+
+ if (!wait_for_completion_interruptible_timeout(&info->init_completion,
+ msecs_to_jiffies(1000)))
+ return -ETIMEDOUT;
+
+ if (info->init_error < 0)
+ return info->init_error;
+
+ NBT_DBG("Negotiation succesful\n");
+ return 0;
+}
+
+static void hci_h4p_negotiation_packet(struct hci_h4p_info *info,
+ struct sk_buff *skb)
+{
+ struct hci_h4p_init_hdr *init_hdr = (void *) skb->data;
+ struct hci_h4p_init_evt *init_evt;
+
+ if (init_hdr->dlen > skb->len) {
+ kfree_skb(skb);
+ info->init_error = -EPROTO;
+ complete(&info->init_completion);
+ return;
+ }
+
+ init_evt = (void *)skb_pull(skb, HCI_H4P_INIT_HDR_SIZE);
+
+ if (init_evt->ack != HCI_H4P_ACK) {
+ dev_err(info->dev, "Could not negotiate hci_h4p settings\n");
+ info->init_error = -EINVAL;
+ }
+
+ info->man_id = init_evt->man_id;
+ info->ver_id = init_evt->ver_id;
+
+ complete(&info->init_completion);
+ kfree_skb(skb);
+}
+
+/* H4 packet handling functions */
+static int hci_h4p_get_hdr_len(struct hci_h4p_info *info, u8 pkt_type)
+{
+ long retval;
+
+ switch (pkt_type) {
+ case H4_EVT_PKT:
+ retval = HCI_EVENT_HDR_SIZE;
+ break;
+ case H4_ACL_PKT:
+ retval = HCI_ACL_HDR_SIZE;
+ break;
+ case H4_SCO_PKT:
+ retval = HCI_SCO_HDR_SIZE;
+ break;
+ case H4_NEG_PKT:
+ retval = HCI_H4P_INIT_HDR_SIZE;
+ break;
+ case H4_ALIVE_PKT:
+ retval = HCI_H4P_ALIVE_HDR_SIZE;
+ break;
+ case H4_RADIO_PKT:
+ retval = H4_RADIO_HDR_SIZE;
+ break;
+ default:
+ dev_err(info->dev, "Unknown H4 packet type 0x%.2x\n", pkt_type);
+ retval = -1;
+ break;
+ }
+
+ return retval;
+}
+
+static unsigned int hci_h4p_get_data_len(struct hci_h4p_info *info,
+ struct sk_buff *skb)
+{
+ long retval = -1;
+ struct hci_event_hdr *evt_hdr;
+ struct hci_acl_hdr *acl_hdr;
+ struct hci_sco_hdr *sco_hdr;
+ struct hci_h4p_radio_hdr *radio_hdr;
+ struct hci_h4p_init_hdr *init_hdr;
+ struct hci_h4p_alive_hdr *alive_hdr;
+
+ switch (bt_cb(skb)->pkt_type) {
+ case H4_EVT_PKT:
+ evt_hdr = (struct hci_event_hdr *)skb->data;
+ retval = evt_hdr->plen;
+ break;
+ case H4_ACL_PKT:
+ acl_hdr = (struct hci_acl_hdr *)skb->data;
+ retval = le16_to_cpu(acl_hdr->dlen);
+ break;
+ case H4_SCO_PKT:
+ sco_hdr = (struct hci_sco_hdr *)skb->data;
+ retval = sco_hdr->dlen;
+ break;
+ case H4_RADIO_PKT:
+ radio_hdr = (struct hci_h4p_radio_hdr *)skb->data;
+ retval = radio_hdr->dlen;
+ break;
+ case H4_NEG_PKT:
+ init_hdr = (struct hci_h4p_init_hdr *)skb->data;
+ retval = init_hdr->dlen;
+ break;
+ case H4_ALIVE_PKT:
+ alive_hdr = (struct hci_h4p_alive_hdr *)skb->data;
+ retval = alive_hdr->dlen;
+ break;
+ }
+
+ return retval;
+}
+
+static inline void hci_h4p_recv_frame(struct hci_h4p_info *info,
+ struct sk_buff *skb)
+{
+
+ if (unlikely(!test_bit(HCI_RUNNING, &info->hdev->flags))) {
+ NBT_DBG("fw_event\n");
+ if (bt_cb(info->rx_skb)->pkt_type == H4_NEG_PKT) {
+ hci_h4p_negotiation_packet(info, info->rx_skb);
+ return;
+ }
+ if (bt_cb(info->rx_skb)->pkt_type == H4_ALIVE_PKT) {
+ hci_h4p_alive_packet(info, info->rx_skb);
+ return;
+ }
+ hci_h4p_parse_fw_event(info, skb);
+ } else {
+ hci_recv_frame(info->hdev, skb);
+ NBT_DBG("Frame sent to upper layer\n");
+ }
+}
+
+static inline void hci_h4p_handle_byte(struct hci_h4p_info *info, u8 byte)
+{
+ switch (info->rx_state) {
+ case WAIT_FOR_PKT_TYPE:
+ bt_cb(info->rx_skb)->pkt_type = byte;
+ info->rx_count = hci_h4p_get_hdr_len(info, byte);
+ if (info->rx_count < 0) {
+ info->hdev->stat.err_rx++;
+ kfree_skb(info->rx_skb);
+ info->rx_skb = NULL;
+ } else {
+ info->rx_state = WAIT_FOR_HEADER;
+ }
+ break;
+ case WAIT_FOR_HEADER:
+ info->rx_count--;
+ *skb_put(info->rx_skb, 1) = byte;
+ if (info->rx_count != 0)
+ break;
+
+ info->rx_count = hci_h4p_get_data_len(info,
+ info->rx_skb);
+ if (info->rx_count > skb_tailroom(info->rx_skb)) {
+ dev_err(info->dev, "Too long frame.\n");
+ info->garbage_bytes = info->rx_count -
+ skb_tailroom(info->rx_skb);
+ kfree_skb(info->rx_skb);
+ info->rx_skb = NULL;
+ break;
+ }
+ info->rx_state = WAIT_FOR_DATA;
+ break;
+ case WAIT_FOR_DATA:
+ info->rx_count--;
+ *skb_put(info->rx_skb, 1) = byte;
+ break;
+ default:
+ WARN_ON(1);
+ break;
+ }
+
+ if (info->rx_count == 0) {
+ /* H4+ devices should allways send word aligned
+ * packets */
+ if (!(info->rx_skb->len % 2))
+ info->garbage_bytes++;
+ hci_h4p_recv_frame(info, info->rx_skb);
+ info->rx_skb = NULL;
+ }
+}
+
+static void hci_h4p_rx(unsigned long data)
+{
+ u8 byte;
+ struct hci_h4p_info *info = (struct hci_h4p_info *)data;
+
+ NBT_DBG("rx woke up\n");
+
+ while (hci_h4p_inb(info, UART_LSR) & UART_LSR_DR) {
+ byte = hci_h4p_inb(info, UART_RX);
+ if (info->garbage_bytes) {
+ info->garbage_bytes--;
+ continue;
+ }
+ if (info->rx_skb == NULL) {
+ info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE,
+ GFP_ATOMIC);
+ if (!info->rx_skb) {
+ dev_err(info->dev,
+ "No memory for new packet\n");
+ return;
+ }
+ info->rx_state = WAIT_FOR_PKT_TYPE;
+ }
+ info->hdev->stat.byte_rx++;
+ NBT_DBG_TRANSFER_NF("0x%.2x ", byte);
+ hci_h4p_handle_byte(info, byte);
+ }
+
+ if (info->rx_enabled == info->autorts)
+ return;
+
+ if (!(hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT))
+ return;
+
+ if (hci_h4p_inb(info, UART_LSR) & UART_LSR_DR)
+ return;
+
+ hci_h4p_set_rts(info, info->rx_enabled);
+ __hci_h4p_set_auto_ctsrts(info, info->rx_enabled, UART_EFR_RTS);
+ info->autorts = info->rx_enabled;
+
+ /* Flush posted write to avoid spurious interrupts */
+ hci_h4p_inb(info, UART_OMAP_SCR);
+ hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
+}
+
+static void hci_h4p_tx(unsigned long data)
+{
+ unsigned int sent = 0;
+ struct sk_buff *skb;
+ struct hci_h4p_info *info = (struct hci_h4p_info *)data;
+
+ NBT_DBG("tx woke up\n");
+ NBT_DBG_TRANSFER("data ");
+
+ if (info->autorts != info->rx_enabled) {
+ NBT_DBG("rts unbalanced.. autorts %d rx_enabled %d", info->autorts, info->rx_enabled);
+ if (hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT &&
+ !(hci_h4p_inb(info, UART_LSR) & UART_LSR_DR)) {
+ __hci_h4p_set_auto_ctsrts(info, info->rx_enabled,
+ UART_EFR_RTS);
+ info->autorts = info->rx_enabled;
+ hci_h4p_set_rts(info, info->rx_enabled);
+ hci_h4p_set_clk(info, &info->rx_clocks_en,
+ info->rx_enabled);
+ NBT_DBG("transmitter empty. setinng into balance\n");
+ } else {
+ hci_h4p_outb(info, UART_OMAP_SCR,
+ hci_h4p_inb(info, UART_OMAP_SCR) |
+ UART_OMAP_SCR_EMPTY_THR);
+ NBT_DBG("transmitter/receiver was not empty waiting for next irq\n");
+ hci_h4p_set_rts(info, 1);
+ goto finish_tx;
+ }
+ }
+
+ skb = skb_dequeue(&info->txq);
+ if (!skb) {
+ /* No data in buffer */
+ NBT_DBG("skb ready\n");
+ if (hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT) {
+ hci_h4p_outb(info, UART_IER,
+ hci_h4p_inb(info, UART_IER) &
+ ~UART_IER_THRI);
+ hci_h4p_inb(info, UART_OMAP_SCR);
+ hci_h4p_disable_tx(info);
+ NBT_DBG("transmitter was empty. cleaning up\n");
+ return;
+ }
+ hci_h4p_outb(info, UART_OMAP_SCR,
+ hci_h4p_inb(info, UART_OMAP_SCR) |
+ UART_OMAP_SCR_EMPTY_THR);
+ NBT_DBG("transmitter was not empty waiting for next irq\n");
+ goto finish_tx;
+ }
+
+ /* Copy data to tx fifo */
+ while (!(hci_h4p_inb(info, UART_OMAP_SSR) & UART_OMAP_SSR_TXFULL) &&
+ (sent < skb->len)) {
+ NBT_DBG_TRANSFER_NF("0x%.2x ", skb->data[sent]);
+ hci_h4p_outb(info, UART_TX, skb->data[sent]);
+ sent++;
+ }
+
+ info->hdev->stat.byte_tx += sent;
+ if (skb->len == sent) {
+ kfree_skb(skb);
+ } else {
+ skb_pull(skb, sent);
+ skb_queue_head(&info->txq, skb);
+ }
+
+ hci_h4p_outb(info, UART_OMAP_SCR, hci_h4p_inb(info, UART_OMAP_SCR) &
+ ~UART_OMAP_SCR_EMPTY_THR);
+ hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) |
+ UART_IER_THRI);
+
+finish_tx:
+ /* Flush posted write to avoid spurious interrupts */
+ hci_h4p_inb(info, UART_OMAP_SCR);
+
+}
+
+static irqreturn_t hci_h4p_interrupt(int irq, void *data)
+{
+ struct hci_h4p_info *info = (struct hci_h4p_info *)data;
+ u8 iir, msr;
+ int ret;
+
+ ret = IRQ_NONE;
+
+ iir = hci_h4p_inb(info, UART_IIR);
+ if (iir & UART_IIR_NO_INT)
+ return IRQ_HANDLED;
+
+ NBT_DBG("In interrupt handler iir 0x%.2x\n", iir);
+
+ iir &= UART_IIR_ID;
+
+ if (iir == UART_IIR_MSI) {
+ msr = hci_h4p_inb(info, UART_MSR);
+ ret = IRQ_HANDLED;
+ }
+ if (iir == UART_IIR_RLSI) {
+ hci_h4p_inb(info, UART_RX);
+ hci_h4p_inb(info, UART_LSR);
+ ret = IRQ_HANDLED;
+ }
+
+ if (iir == UART_IIR_RDI) {
+ hci_h4p_rx((unsigned long)data);
+ ret = IRQ_HANDLED;
+ }
+
+ if (iir == UART_IIR_THRI) {
+ hci_h4p_tx((unsigned long)data);
+ ret = IRQ_HANDLED;
+ }
+
+ return ret;
+}
+
+static irqreturn_t hci_h4p_wakeup_interrupt(int irq, void *dev_inst)
+{
+ struct hci_h4p_info *info = dev_inst;
+ int should_wakeup;
+ struct hci_dev *hdev;
+
+ if (!info->hdev)
+ return IRQ_HANDLED;
+
+ hdev = info->hdev;
+
+ if (!test_bit(HCI_RUNNING, &hdev->flags))
+ return IRQ_HANDLED;
+
+ should_wakeup = info->host_wakeup();
+ NBT_DBG_POWER("gpio interrupt %d\n", should_wakeup);
+
+ /* Check if wee have missed some interrupts */
+ if (info->rx_enabled == should_wakeup)
+ return IRQ_HANDLED;
+
+ if (should_wakeup)
+ hci_h4p_enable_rx(info);
+ else
+ hci_h4p_disable_rx(info);
+
+ return IRQ_HANDLED;
+}
+
+static int hci_h4p_reset(struct hci_h4p_info *info)
+{
+ int err;
+
+ err = hci_h4p_reset_uart(info);
+ if (err < 0) {
+ dev_err(info->dev, "Uart reset failed\n");
+ return err;
+ }
+ hci_h4p_init_uart(info);
+ hci_h4p_set_rts(info, 0);
+
+ info->reset(0);
+ info->bt_wakeup(1);
+ msleep(10);
+ info->reset(1);
+
+ err = hci_h4p_wait_for_cts(info, 1, 100);
+ if (err < 0) {
+ dev_err(info->dev, "No cts from bt chip\n");
+ return err;
+ }
+
+ hci_h4p_set_rts(info, 1);
+
+ return 0;
+}
+
+/* hci callback functions */
+static int hci_h4p_hci_flush(struct hci_dev *hdev)
+{
+ struct hci_h4p_info *info;
+ info = hci_get_drvdata(hdev);
+
+ skb_queue_purge(&info->txq);
+
+ return 0;
+}
+
+static int hci_h4p_hci_open(struct hci_dev *hdev)
+{
+ struct hci_h4p_info *info;
+ int err;
+ struct sk_buff_head fw_queue;
+ unsigned long flags;
+
+ info = hci_get_drvdata(hdev);
+
+ if (test_bit(HCI_RUNNING, &hdev->flags))
+ return 0;
+
+ info->rx_enabled = 1;
+ info->rx_state = WAIT_FOR_PKT_TYPE;
+ info->rx_count = 0;
+ info->garbage_bytes = 0;
+ info->rx_skb = NULL;
+ info->pm_enabled = 0;
+ init_completion(&info->fw_completion);
+ hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
+ hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
+ skb_queue_head_init(&fw_queue);
+
+ err = hci_h4p_reset(info);
+ if (err < 0)
+ goto err_clean;
+
+ hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_CTS | UART_EFR_RTS);
+ info->autorts = 1;
+ err = hci_h4p_send_negotiation(info);
+ if (err < 0)
+ goto err_clean;
+
+ skb_queue_head_init(&fw_queue);
+ err = hci_h4p_read_fw(info, &fw_queue);
+ if (err < 0) {
+ dev_err(info->dev, "Cannot read firmware\n");
+ return err;
+ }
+
+ /* FW image contains also unneeded negoation and alive msgs */
+ skb_dequeue(&fw_queue);
+ skb_dequeue(&fw_queue);
+
+ err = hci_h4p_send_fw(info, &fw_queue);
+ if (err < 0) {
+ dev_err(info->dev, "Sending firmware failed.\n");
+ goto err_clean;
+ }
+
+ info->pm_enabled = 1;
+
+ spin_lock_irqsave(&info->lock, flags);
+ info->rx_enabled = info->host_wakeup();
+ hci_h4p_set_clk(info, &info->rx_clocks_en, info->rx_enabled);
+ spin_unlock_irqrestore(&info->lock, flags);
+
+ hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
+
+ set_bit(HCI_RUNNING, &hdev->flags);
+
+ NBT_DBG("hci up and running\n");
+ return 0;
+
+err_clean:
+ hci_h4p_hci_flush(hdev);
+ hci_h4p_reset_uart(info);
+ hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
+ hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
+ info->reset(0);
+ info->bt_wakeup(0);
+ skb_queue_purge(&fw_queue);
+ kfree_skb(info->rx_skb);
+
+ return err;
+}
+
+static int hci_h4p_hci_close(struct hci_dev *hdev)
+{
+ struct hci_h4p_info *info = hci_get_drvdata(hdev);
+
+ if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
+ return 0;
+
+ hci_h4p_hci_flush(hdev);
+ hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
+ hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
+ hci_h4p_reset_uart(info);
+ hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
+ hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
+ info->reset(0);
+ info->bt_wakeup(0);
+ kfree_skb(info->rx_skb);
+
+ return 0;
+}
+
+static int hci_h4p_hci_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
+{
+ struct hci_h4p_info *info;
+ int err = 0;
+ unsigned long flags;
+
+ if (!hdev) {
+ printk(KERN_WARNING "hci_h4p: Frame for unknown device\n");
+ return -ENODEV;
+ }
+
+ NBT_DBG("dev %p, skb %p\n", hdev, skb);
+
+ info = hci_get_drvdata(hdev);
+
+ if (!test_bit(HCI_RUNNING, &hdev->flags)) {
+ dev_warn(info->dev, "Frame for non-running device\n");
+ return -EIO;
+ }
+
+ switch (bt_cb(skb)->pkt_type) {
+ case HCI_COMMAND_PKT:
+ hdev->stat.cmd_tx++;
+ break;
+ case HCI_ACLDATA_PKT:
+ hdev->stat.acl_tx++;
+ break;
+ case HCI_SCODATA_PKT:
+ hdev->stat.sco_tx++;
+ break;
+ }
+
+ /* Push frame type to skb */
+ *skb_push(skb, 1) = (bt_cb(skb)->pkt_type);
+ /* We should allways send word aligned data to h4+ devices */
+ if (skb->len % 2) {
+ err = skb_pad(skb, 1);
+ if (!err)
+ *skb_put(skb, 1) = 0x00;
+ }
+ if (err)
+ return err;
+
+ spin_lock_irqsave(&info->lock, flags);
+ skb_queue_tail(&info->txq, skb);
+ hci_h4p_enable_tx(info);
+ spin_unlock_irqrestore(&info->lock, flags);
+
+ return 0;
+}
+
+static int hci_h4p_register_hdev(struct hci_h4p_info *info)
+{
+ struct hci_dev *hdev;
+
+ /* Initialize and register HCI device */
+
+ hdev = hci_alloc_dev();
+ if (!hdev) {
+ dev_err(info->dev, "Can't allocate memory for device\n");
+ return -ENOMEM;
+ }
+ info->hdev = hdev;
+
+ hdev->bus = HCI_UART;
+ hci_set_drvdata(hdev, info);
+
+ hdev->open = hci_h4p_hci_open;
+ hdev->close = hci_h4p_hci_close;
+ hdev->flush = hci_h4p_hci_flush;
+ hdev->send = hci_h4p_hci_send_frame;
+ set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
+
+ SET_HCIDEV_DEV(hdev, info->dev);
+
+ if (hci_register_dev(hdev) < 0) {
+ dev_err(info->dev, "hci_register failed %s.\n", hdev->name);
+ return -ENODEV;
+ }
+
+ return 0;
+}
+
+static ssize_t hci_h4p_store_bdaddr(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct hci_h4p_info *info = dev_get_drvdata(dev);
+ unsigned int bdaddr[6];
+ int ret, i;
+
+ ret = sscanf(buf, "%2x:%2x:%2x:%2x:%2x:%2x\n",
+ &bdaddr[0], &bdaddr[1], &bdaddr[2],
+ &bdaddr[3], &bdaddr[4], &bdaddr[5]);
+
+ if (ret != 6)
+ return -EINVAL;
+
+ for (i = 0; i < 6; i++)
+ info->bd_addr[i] = bdaddr[i] & 0xff;
+
+ return count;
+}
+
+static ssize_t hci_h4p_show_bdaddr(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct hci_h4p_info *info = dev_get_drvdata(dev);
+
+ return sprintf(buf, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
+ info->bd_addr[0], info->bd_addr[1], info->bd_addr[2],
+ info->bd_addr[3], info->bd_addr[4], info->bd_addr[5]);
+}
+
+static DEVICE_ATTR(bdaddr, S_IRUGO | S_IWUSR, hci_h4p_show_bdaddr,
+ hci_h4p_store_bdaddr);
+
+static int hci_h4p_sysfs_create_files(struct device *dev)
+{
+ return device_create_file(dev, &dev_attr_bdaddr);
+}
+
+static void hci_h4p_sysfs_remove_files(struct device *dev)
+{
+ device_remove_file(dev, &dev_attr_bdaddr);
+}
+
+static int hci_h4p_probe(struct platform_device *pdev)
+{
+ struct hci_h4p_platform_data *bt_plat_data;
+ struct hci_h4p_info *info;
+ int err;
+
+ dev_info(&pdev->dev, "Registering HCI H4P device\n");
+ info = kzalloc(sizeof(struct hci_h4p_info), GFP_KERNEL);
+ if (!info)
+ return -ENOMEM;
+
+ info->dev = &pdev->dev;
+ info->pm_enabled = 0;
+ info->tx_enabled = 1;
+ info->rx_enabled = 1;
+ info->garbage_bytes = 0;
+ info->tx_clocks_en = 0;
+ info->rx_clocks_en = 0;
+ spin_lock_init(&info->lock);
+ spin_lock_init(&info->clocks_lock);
+ skb_queue_head_init(&info->txq);
+
+ if (pdev->dev.platform_data == NULL) {
+ dev_err(&pdev->dev, "Could not get Bluetooth config data\n");
+ kfree(info);
+ return -ENODATA;
+ }
+
+ bt_plat_data = pdev->dev.platform_data;
+ info->chip_type = 3;
+ info->bt_wakeup = bt_plat_data->bt_wu;
+ info->host_wakeup = bt_plat_data->host_wu;
+ info->reset = bt_plat_data->reset;
+ info->uart_base = bt_plat_data->uart_base;
+ info->host_wakeup_gpio = bt_plat_data->host_wu_gpio;
+
+ NBT_DBG("RESET gpio: %p\n", info->reset);
+ NBT_DBG("BTWU gpio: %p\n", info->bt_wakeup);
+ NBT_DBG("HOSTWU gpio: %p\n", info->host_wakeup);
+
+ info->irq = bt_plat_data->uart_irq;
+ err = request_irq(info->irq, hci_h4p_interrupt, IRQF_DISABLED | IRQF_SHARED,
+ "hci_h4p", info);
+ if (err < 0) {
+ dev_err(info->dev, "hci_h4p: unable to get IRQ %d\n", info->irq);
+ goto cleanup;
+ }
+
+ err = request_irq(gpio_to_irq(info->host_wakeup_gpio),
+ hci_h4p_wakeup_interrupt, IRQF_TRIGGER_FALLING |
+ IRQF_TRIGGER_RISING | IRQF_DISABLED,
+ "hci_h4p_wkup", info);
+ if (err < 0) {
+ dev_err(info->dev, "hci_h4p: unable to get wakeup IRQ %d\n",
+ gpio_to_irq(info->host_wakeup_gpio));
+ free_irq(info->irq, info);
+ goto cleanup;
+ }
+
+ err = irq_set_irq_wake(gpio_to_irq(info->host_wakeup_gpio), 1);
+ if (err < 0) {
+ dev_err(info->dev, "hci_h4p: unable to set wakeup for IRQ %d\n",
+ gpio_to_irq(info->host_wakeup_gpio));
+ free_irq(info->irq, info);
+ free_irq(gpio_to_irq(info->host_wakeup_gpio), info);
+ goto cleanup;
+ }
+
+ hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
+ err = hci_h4p_reset_uart(info);
+ if (err < 0)
+ goto cleanup_irq;
+ hci_h4p_init_uart(info);
+ hci_h4p_set_rts(info, 0);
+ err = hci_h4p_reset(info);
+ hci_h4p_reset_uart(info);
+ if (err < 0)
+ goto cleanup_irq;
+ info->reset(0);
+ hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
+
+ platform_set_drvdata(pdev, info);
+
+ if (hci_h4p_sysfs_create_files(info->dev) < 0) {
+ dev_err(info->dev, "failed to create sysfs files\n");
+ goto cleanup_irq;
+ }
+
+ if (hci_h4p_register_hdev(info) < 0) {
+ dev_err(info->dev, "failed to register hci_h4p hci device\n");
+ goto cleanup_sysfs;
+ }
+
+ return 0;
+
+cleanup_sysfs:
+ hci_h4p_sysfs_remove_files(info->dev);
+cleanup_irq:
+ free_irq(info->irq, (void *)info);
+ free_irq(gpio_to_irq(info->host_wakeup_gpio), info);
+cleanup:
+ info->reset(0);
+ kfree(info);
+ return err;
+
+}
+
+static int hci_h4p_remove(struct platform_device *pdev)
+{
+ struct hci_h4p_info *info;
+
+ info = platform_get_drvdata(pdev);
+
+ hci_h4p_sysfs_remove_files(info->dev);
+ hci_h4p_hci_close(info->hdev);
+ free_irq(gpio_to_irq(info->host_wakeup_gpio), info);
+ hci_unregister_dev(info->hdev);
+ hci_free_dev(info->hdev);
+ free_irq(info->irq, (void *) info);
+ kfree(info);
+
+ return 0;
+}
+
+static struct platform_driver hci_h4p_driver = {
+ .probe = hci_h4p_probe,
+ .remove = hci_h4p_remove,
+ .driver = {
+ .name = "hci_h4p",
+ },
+};
+
+static int __init hci_h4p_init(void)
+{
+ int err = 0;
+
+ /* Register the driver with LDM */
+ err = platform_driver_register(&hci_h4p_driver);
+ if (err < 0)
+ printk(KERN_WARNING "failed to register hci_h4p driver\n");
+
+ return err;
+}
+
+static void __exit hci_h4p_exit(void)
+{
+ platform_driver_unregister(&hci_h4p_driver);
+}
+
+module_init(hci_h4p_init);
+module_exit(hci_h4p_exit);
+
+MODULE_ALIAS("platform:hci_h4p");
+MODULE_DESCRIPTION("Bluetooth h4 driver with nokia extensions");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Ville Tervo");
+MODULE_FIRMWARE(FW_NAME_CSR);
+MODULE_FIRMWARE(FW_NAME_TI);
+MODULE_FIRMWARE(FW_NAME_BCM);
diff --git a/drivers/bluetooth/hci_h4p/fw-bcm.c b/drivers/bluetooth/hci_h4p/fw-bcm.c
new file mode 100644
index 0000000..56684f8
--- /dev/null
+++ b/drivers/bluetooth/hci_h4p/fw-bcm.c
@@ -0,0 +1,149 @@
+/*
+ * This file is part of hci_h4p bluetooth driver
+ *
+ * Copyright (C) 2005-2008 Nokia Corporation.
+ *
+ * Contact: Ville Tervo <ville.tervo@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/skbuff.h>
+#include <linux/delay.h>
+#include <linux/serial_reg.h>
+
+#include "hci_h4p.h"
+
+static int hci_h4p_bcm_set_bdaddr(struct hci_h4p_info *info, struct sk_buff *skb)
+{
+ static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
+ int not_valid;
+ int i;
+
+ not_valid = 1;
+ for (i = 0; i < 6; i++) {
+ if (info->bd_addr[i] != 0x00) {
+ not_valid = 0;
+ break;
+ }
+ }
+
+ if (not_valid) {
+ dev_info(info->dev, "Valid bluetooth address not found, setting some random\n");
+ /* When address is not valid, use some random but Nokia MAC */
+ memcpy(info->bd_addr, nokia_oui, 3);
+ get_random_bytes(info->bd_addr + 3, 3);
+ }
+
+ for (i = 0; i < 6; i++)
+ skb->data[9 - i] = info->bd_addr[i];
+
+ return 0;
+}
+
+void hci_h4p_bcm_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
+{
+ struct sk_buff *fw_skb;
+ int err;
+ unsigned long flags;
+
+ if (skb->data[5] != 0x00) {
+ dev_err(info->dev, "Firmware sending command failed 0x%.2x\n",
+ skb->data[5]);
+ info->fw_error = -EPROTO;
+ }
+
+ kfree_skb(skb);
+
+ fw_skb = skb_dequeue(info->fw_q);
+ if (fw_skb == NULL || info->fw_error) {
+ complete(&info->fw_completion);
+ return;
+ }
+
+ if (fw_skb->data[1] == 0x01 && fw_skb->data[2] == 0xfc && fw_skb->len >= 10) {
+ NBT_DBG_FW("Setting bluetooth address\n");
+ err = hci_h4p_bcm_set_bdaddr(info, fw_skb);
+ if (err < 0) {
+ kfree_skb(fw_skb);
+ info->fw_error = err;
+ complete(&info->fw_completion);
+ return;
+ }
+ }
+
+ skb_queue_tail(&info->txq, fw_skb);
+ spin_lock_irqsave(&info->lock, flags);
+ hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) |
+ UART_IER_THRI);
+ spin_unlock_irqrestore(&info->lock, flags);
+}
+
+
+int hci_h4p_bcm_send_fw(struct hci_h4p_info *info,
+ struct sk_buff_head *fw_queue)
+{
+ struct sk_buff *skb;
+ unsigned long flags, time;
+
+ info->fw_error = 0;
+
+ NBT_DBG_FW("Sending firmware\n");
+
+ time = jiffies;
+
+ info->fw_q = fw_queue;
+ skb = skb_dequeue(fw_queue);
+ if (!skb)
+ return -ENODATA;
+
+ NBT_DBG_FW("Sending commands\n");
+
+ /*
+ * Disable smart-idle as UART TX interrupts
+ * are not wake-up capable
+ */
+ hci_h4p_smart_idle(info, 0);
+
+ /* Check if this is bd_address packet */
+ init_completion(&info->fw_completion);
+ skb_queue_tail(&info->txq, skb);
+ spin_lock_irqsave(&info->lock, flags);
+ hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) |
+ UART_IER_THRI);
+ spin_unlock_irqrestore(&info->lock, flags);
+
+ if (!wait_for_completion_timeout(&info->fw_completion,
+ msecs_to_jiffies(2000))) {
+ dev_err(info->dev, "No reply to fw command\n");
+ return -ETIMEDOUT;
+ }
+
+ if (info->fw_error) {
+ dev_err(info->dev, "FW error\n");
+ return -EPROTO;
+ }
+
+ NBT_DBG_FW("Firmware sent in %d msecs\n",
+ jiffies_to_msecs(jiffies-time));
+
+ hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_RTS);
+ hci_h4p_set_rts(info, 0);
+ hci_h4p_change_speed(info, BC4_MAX_BAUD_RATE);
+ hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_RTS);
+
+ return 0;
+}
diff --git a/drivers/bluetooth/hci_h4p/fw-csr.c b/drivers/bluetooth/hci_h4p/fw-csr.c
new file mode 100644
index 0000000..020fa52
--- /dev/null
+++ b/drivers/bluetooth/hci_h4p/fw-csr.c
@@ -0,0 +1,152 @@
+/*
+ * This file is part of hci_h4p bluetooth driver
+ *
+ * Copyright (C) 2005-2008 Nokia Corporation.
+ *
+ * Contact: Ville Tervo <ville.tervo@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/skbuff.h>
+#include <linux/delay.h>
+#include <linux/serial_reg.h>
+
+#include "hci_h4p.h"
+
+void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
+{
+ /* Check if this is fw packet */
+ if (skb->data[0] != 0xff) {
+ hci_recv_frame(info->hdev, skb);
+ return;
+ }
+
+ if (skb->data[11] || skb->data[12]) {
+ dev_err(info->dev, "Firmware sending command failed\n");
+ info->fw_error = -EPROTO;
+ }
+
+ kfree_skb(skb);
+ complete(&info->fw_completion);
+}
+
+int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
+ struct sk_buff_head *fw_queue)
+{
+ static const u8 nokia_oui[3] = {0x00, 0x19, 0x4F};
+ struct sk_buff *skb;
+ unsigned int offset;
+ int retries, count, i, not_valid;
+ unsigned long flags;
+
+ info->fw_error = 0;
+
+ NBT_DBG_FW("Sending firmware\n");
+ skb = skb_dequeue(fw_queue);
+
+ if (!skb)
+ return -ENOMSG;
+
+ /* Check if this is bd_address packet */
+ if (skb->data[15] == 0x01 && skb->data[16] == 0x00) {
+ offset = 21;
+ skb->data[offset + 1] = 0x00;
+ skb->data[offset + 5] = 0x00;
+
+ not_valid = 1;
+ for (i = 0; i < 6; i++) {
+ if (info->bd_addr[i] != 0x00) {
+ not_valid = 0;
+ break;
+ }
+ }
+
+ if (not_valid) {
+ dev_info(info->dev, "Valid bluetooth address not found,"
+ " setting some random\n");
+ /* When address is not valid, use some random */
+ memcpy(info->bd_addr, nokia_oui, 3);
+ get_random_bytes(info->bd_addr + 3, 3);
+ }
+
+ skb->data[offset + 7] = info->bd_addr[0];
+ skb->data[offset + 6] = info->bd_addr[1];
+ skb->data[offset + 4] = info->bd_addr[2];
+ skb->data[offset + 0] = info->bd_addr[3];
+ skb->data[offset + 3] = info->bd_addr[4];
+ skb->data[offset + 2] = info->bd_addr[5];
+ }
+
+ for (count = 1; ; count++) {
+ NBT_DBG_FW("Sending firmware command %d\n", count);
+ init_completion(&info->fw_completion);
+ skb_queue_tail(&info->txq, skb);
+ spin_lock_irqsave(&info->lock, flags);
+ hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) |
+ UART_IER_THRI);
+ spin_unlock_irqrestore(&info->lock, flags);
+
+ skb = skb_dequeue(fw_queue);
+ if (!skb)
+ break;
+
+ if (!wait_for_completion_timeout(&info->fw_completion,
+ msecs_to_jiffies(1000))) {
+ dev_err(info->dev, "No reply to fw command\n");
+ return -ETIMEDOUT;
+ }
+
+ if (info->fw_error) {
+ dev_err(info->dev, "FW error\n");
+ return -EPROTO;
+ }
+ };
+
+ /* Wait for chip warm reset */
+ retries = 100;
+ while ((!skb_queue_empty(&info->txq) ||
+ !(hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT)) &&
+ retries--) {
+ msleep(10);
+ }
+ if (!retries) {
+ dev_err(info->dev, "Transmitter not empty\n");
+ return -ETIMEDOUT;
+ }
+
+ hci_h4p_change_speed(info, BC4_MAX_BAUD_RATE);
+
+ if (hci_h4p_wait_for_cts(info, 1, 100)) {
+ dev_err(info->dev, "cts didn't deassert after final speed\n");
+ return -ETIMEDOUT;
+ }
+
+ retries = 100;
+ do {
+ init_completion(&info->init_completion);
+ hci_h4p_send_alive_packet(info);
+ retries--;
+ } while (!wait_for_completion_timeout(&info->init_completion, 100) &&
+ retries > 0);
+
+ if (!retries) {
+ dev_err(info->dev, "No alive reply after speed change\n");
+ return -ETIMEDOUT;
+ }
+
+ return 0;
+}
diff --git a/drivers/bluetooth/hci_h4p/fw-ti1273.c b/drivers/bluetooth/hci_h4p/fw-ti1273.c
new file mode 100644
index 0000000..d46c3a0
--- /dev/null
+++ b/drivers/bluetooth/hci_h4p/fw-ti1273.c
@@ -0,0 +1,113 @@
+/*
+ * This file is part of hci_h4p bluetooth driver
+ *
+ * Copyright (C) 2009 Nokia Corporation.
+ *
+ * Contact: Ville Tervo <ville.tervo@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/skbuff.h>
+#include <linux/delay.h>
+#include <linux/serial_reg.h>
+
+#include "hci_h4p.h"
+
+static struct sk_buff_head *fw_q;
+
+void hci_h4p_ti1273_parse_fw_event(struct hci_h4p_info *info,
+ struct sk_buff *skb)
+{
+ struct sk_buff *fw_skb;
+ unsigned long flags;
+
+ if (skb->data[5] != 0x00) {
+ dev_err(info->dev, "Firmware sending command failed 0x%.2x\n",
+ skb->data[5]);
+ info->fw_error = -EPROTO;
+ }
+
+ kfree_skb(skb);
+
+ fw_skb = skb_dequeue(fw_q);
+ if (fw_skb == NULL || info->fw_error) {
+ complete(&info->fw_completion);
+ return;
+ }
+
+ hci_h4p_enable_tx(info);
+ skb_queue_tail(&info->txq, fw_skb);
+ spin_lock_irqsave(&info->lock, flags);
+ hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) |
+ UART_IER_THRI);
+ spin_unlock_irqrestore(&info->lock, flags);
+}
+
+
+int hci_h4p_ti1273_send_fw(struct hci_h4p_info *info,
+ struct sk_buff_head *fw_queue)
+{
+ struct sk_buff *skb;
+ unsigned long flags, time;
+
+ info->fw_error = 0;
+
+ NBT_DBG_FW("Sending firmware\n");
+
+ time = jiffies;
+
+ fw_q = fw_queue;
+ skb = skb_dequeue(fw_queue);
+ if (!skb)
+ return -ENODATA;
+
+ NBT_DBG_FW("Sending commands\n");
+ /* Check if this is bd_address packet */
+ init_completion(&info->fw_completion);
+ hci_h4p_enable_tx(info);
+ skb_queue_tail(&info->txq, skb);
+ spin_lock_irqsave(&info->lock, flags);
+ hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) |
+ UART_IER_THRI);
+ spin_unlock_irqrestore(&info->lock, flags);
+
+ if (!wait_for_completion_timeout(&info->fw_completion,
+ msecs_to_jiffies(40000))) {
+ dev_err(info->dev, "No reply to fw command\n");
+ return -ETIMEDOUT;
+ }
+
+ if (info->fw_error) {
+ dev_err(info->dev, "FW error\n");
+ return -EPROTO;
+ }
+
+ NBT_DBG_FW("Firmware sent in %d msecs\n",
+ jiffies_to_msecs(jiffies-time));
+
+ hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_RTS);
+ hci_h4p_set_rts(info, 0);
+ hci_h4p_change_speed(info, BC4_MAX_BAUD_RATE);
+ if (hci_h4p_wait_for_cts(info, 1, 100)) {
+ dev_err(info->dev,
+ "cts didn't go down after final speed change\n");
+ return -ETIMEDOUT;
+ }
+ hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_RTS);
+
+ return 0;
+}
diff --git a/drivers/bluetooth/hci_h4p/fw.c b/drivers/bluetooth/hci_h4p/fw.c
new file mode 100644
index 0000000..b767a12
--- /dev/null
+++ b/drivers/bluetooth/hci_h4p/fw.c
@@ -0,0 +1,166 @@
+/*
+ * This file is part of hci_h4p bluetooth driver
+ *
+ * Copyright (C) 2005, 2006 Nokia Corporation.
+ *
+ * Contact: Ville Tervo <ville.tervo@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/skbuff.h>
+#include <linux/firmware.h>
+#include <linux/clk.h>
+
+#include <net/bluetooth/bluetooth.h>
+
+#include "hci_h4p.h"
+
+static int fw_pos;
+
+/* Firmware handling */
+static int hci_h4p_open_firmware(struct hci_h4p_info *info,
+ const struct firmware **fw_entry)
+{
+ int err;
+
+ fw_pos = 0;
+ NBT_DBG_FW("Opening %d/%d firmware\n", info->man_id, info->ver_id);
+ switch (info->man_id) {
+ case BT_CHIP_TI:
+ err = request_firmware(fw_entry, FW_NAME_TI, info->dev);
+ break;
+ case BT_CHIP_CSR:
+ err = request_firmware(fw_entry, FW_NAME_CSR, info->dev);
+ break;
+ case BT_CHIP_BCM:
+ err = request_firmware(fw_entry, FW_NAME_BCM, info->dev);
+ break;
+ default:
+ dev_err(info->dev, "Invalid chip type %d\n", info->man_id);
+ *fw_entry = NULL;
+ err = -EINVAL;
+ }
+
+ return err;
+}
+
+static void hci_h4p_close_firmware(const struct firmware *fw_entry)
+{
+ release_firmware(fw_entry);
+}
+
+/* Read fw. Return length of the command. If no more commands in
+ * fw 0 is returned. In error case return value is negative.
+ */
+static int hci_h4p_read_fw_cmd(struct hci_h4p_info *info, struct sk_buff **skb,
+ const struct firmware *fw_entry, gfp_t how)
+{
+ unsigned int cmd_len;
+
+ if (fw_pos >= fw_entry->size)
+ return 0;
+
+ if (fw_pos + 2 > fw_entry->size) {
+ dev_err(info->dev, "Corrupted firmware image 1\n");
+ return -EMSGSIZE;
+ }
+
+ cmd_len = fw_entry->data[fw_pos++];
+ cmd_len += fw_entry->data[fw_pos++] << 8;
+ if (cmd_len == 0)
+ return 0;
+
+ if (fw_pos + cmd_len > fw_entry->size) {
+ dev_err(info->dev, "Corrupted firmware image 2\n");
+ return -EMSGSIZE;
+ }
+
+ *skb = bt_skb_alloc(cmd_len, how);
+ if (!*skb) {
+ dev_err(info->dev, "Cannot reserve memory for buffer\n");
+ return -ENOMEM;
+ }
+ memcpy(skb_put(*skb, cmd_len), &fw_entry->data[fw_pos], cmd_len);
+
+ fw_pos += cmd_len;
+
+ return (*skb)->len;
+}
+
+int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
+{
+ const struct firmware *fw_entry = NULL;
+ struct sk_buff *skb = NULL;
+ int err;
+
+ err = hci_h4p_open_firmware(info, &fw_entry);
+ if (err < 0 || !fw_entry)
+ goto err_clean;
+
+ while ((err = hci_h4p_read_fw_cmd(info, &skb, fw_entry, GFP_KERNEL))) {
+ if (err < 0 || !skb)
+ goto err_clean;
+
+ skb_queue_tail(fw_queue, skb);
+ }
+
+err_clean:
+ hci_h4p_close_firmware(fw_entry);
+ return err;
+}
+
+int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
+{
+ int err;
+
+ switch (info->man_id) {
+ case BT_CHIP_CSR:
+ err = hci_h4p_bc4_send_fw(info, fw_queue);
+ break;
+ case BT_CHIP_TI:
+ err = hci_h4p_ti1273_send_fw(info, fw_queue);
+ break;
+ case BT_CHIP_BCM:
+ err = hci_h4p_bcm_send_fw(info, fw_queue);
+ break;
+ default:
+ dev_err(info->dev, "Don't know how to send firmware\n");
+ err = -EINVAL;
+ }
+
+ return err;
+}
+
+void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
+{
+ switch (info->man_id) {
+ case BT_CHIP_CSR:
+ hci_h4p_bc4_parse_fw_event(info, skb);
+ break;
+ case BT_CHIP_TI:
+ hci_h4p_ti1273_parse_fw_event(info, skb);
+ break;
+ case BT_CHIP_BCM:
+ hci_h4p_bcm_parse_fw_event(info, skb);
+ break;
+ default:
+ dev_err(info->dev, "Don't know how to parse fw event\n");
+ info->fw_error = -EINVAL;
+ }
+
+ return;
+}
diff --git a/drivers/bluetooth/hci_h4p/hci_h4p.h b/drivers/bluetooth/hci_h4p/hci_h4p.h
new file mode 100644
index 0000000..ebafd37
--- /dev/null
+++ b/drivers/bluetooth/hci_h4p/hci_h4p.h
@@ -0,0 +1,238 @@
+/*
+ * This file is part of hci_h4p bluetooth driver
+ *
+ * Copyright (C) 2005-2010 Nokia Corporation.
+ *
+ * Contact: Ville Tervo <ville.tervo@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <net/bluetooth/bluetooth.h>
+#include <net/bluetooth/hci_core.h>
+#include <net/bluetooth/hci.h>
+
+#ifndef __DRIVERS_BLUETOOTH_HCI_H4P_H
+#define __DRIVERS_BLUETOOTH_HCI_H4P_H
+
+#define BT_CHIP_CSR 0x02
+#define BT_CHIP_TI 0x30
+#define BT_CHIP_BCM 0x04
+
+#define FW_NAME_CSR "bc4fw.bin"
+#define FW_NAME_TI "ti1273.bin"
+#define FW_NAME_BCM "bcmfw.bin"
+
+#define UART_SYSC_OMAP_RESET 0x03
+#define UART_SYSS_RESETDONE 0x01
+#define UART_OMAP_SCR_EMPTY_THR 0x08
+#define UART_OMAP_SCR_WAKEUP 0x10
+#define UART_OMAP_SSR_WAKEUP 0x02
+#define UART_OMAP_SSR_TXFULL 0x01
+
+#define UART_OMAP_SYSC_IDLEMODE 0x03
+#define UART_OMAP_SYSC_IDLEMASK (3 << UART_OMAP_SYSC_IDLEMODE)
+
+#define UART_OMAP_SYSC_FORCE_IDLE (0 << UART_OMAP_SYSC_IDLEMODE)
+#define UART_OMAP_SYSC_NO_IDLE (1 << UART_OMAP_SYSC_IDLEMODE)
+#define UART_OMAP_SYSC_SMART_IDLE (2 << UART_OMAP_SYSC_IDLEMODE)
+
+#define NBT_DBG(fmt, arg...) \
+ pr_debug("%s: " fmt "" , __func__ , ## arg)
+
+#define NBT_DBG_FW(fmt, arg...) \
+ pr_debug("%s: " fmt "" , __func__ , ## arg)
+
+#define NBT_DBG_POWER(fmt, arg...) \
+ pr_debug("%s: " fmt "" , __func__ , ## arg)
+
+#define NBT_DBG_TRANSFER(fmt, arg...) \
+ pr_debug("%s: " fmt "" , __func__ , ## arg)
+
+#define NBT_DBG_TRANSFER_NF(fmt, arg...) \
+ pr_debug(fmt "" , ## arg)
+
+#define NBT_DBG_DMA(fmt, arg...) \
+ pr_debug("%s: " fmt "" , __func__ , ## arg)
+
+struct hci_h4p_info {
+ struct hci_dev *hdev;
+ spinlock_t lock;
+
+ void __iomem *uart_base;
+ unsigned long uart_phys_base;
+ int irq;
+ struct device *dev;
+ u8 chip_type;
+ void (*bt_wakeup)(bool enable);
+ bool (*host_wakeup)(void);
+ void (*reset)(bool enable);
+ int host_wakeup_gpio;
+ int man_id;
+ int ver_id;
+
+ struct sk_buff_head fw_queue;
+ struct completion init_completion;
+ struct completion fw_completion;
+ int fw_error;
+ int init_error;
+
+ struct sk_buff_head txq;
+
+ struct sk_buff *rx_skb;
+ long rx_count;
+ unsigned long rx_state;
+ unsigned long garbage_bytes;
+
+ u8 bd_addr[6];
+ struct sk_buff_head *fw_q;
+
+ int pm_enabled;
+ int tx_enabled;
+ int autorts;
+ int rx_enabled;
+
+ int tx_clocks_en;
+ int rx_clocks_en;
+ spinlock_t clocks_lock;
+ struct clk *uart_iclk;
+ struct clk *uart_fclk;
+ atomic_t clk_users;
+ u16 dll;
+ u16 dlh;
+ u16 ier;
+ u16 mdr1;
+ u16 efr;
+};
+
+struct hci_h4p_radio_hdr {
+ __u8 evt;
+ __u8 dlen;
+} __attribute__ ((packed));
+
+
+struct hci_h4p_init_hdr {
+ __u8 dlen;
+} __attribute__ ((packed));
+#define HCI_H4P_INIT_HDR_SIZE 1
+
+struct hci_h4p_init_cmd {
+ __u8 ack;
+ __u16 baudrate;
+ __u16 unused;
+ __u8 mode;
+ __u16 sys_clk;
+ __u16 unused2;
+} __attribute__ ((packed));
+#define HCI_H4P_INIT_CMD_SIZE 10
+
+struct hci_h4p_init_evt {
+ __u8 ack;
+ __u16 baudrate;
+ __u16 unused;
+ __u8 mode;
+ __u16 sys_clk;
+ __u16 unused2;
+ __u8 man_id;
+ __u8 ver_id;
+} __attribute__ ((packed));
+#define HCI_H4P_INIT_EVT_SIZE 12
+
+struct hci_h4p_alive_hdr {
+ __u8 dlen;
+} __attribute__ ((packed));
+#define HCI_H4P_ALIVE_HDR_SIZE 1
+
+struct hci_h4p_alive_msg {
+ __u8 message_id;
+ __u8 unused;
+} __attribute__ ((packed));
+#define HCI_H4P_ALIVE_MSG_SIZE 2
+
+#define MAX_BAUD_RATE 921600
+#define BC4_MAX_BAUD_RATE 3692300
+#define UART_CLOCK 48000000
+#define BT_INIT_DIVIDER 320
+#define BT_BAUDRATE_DIVIDER 384000000
+#define BT_SYSCLK_DIV 1000
+#define INIT_SPEED 120000
+
+#define HCI_H4P_MODE 0x4c
+
+#define HCI_H4P_ACK 0x20
+#define HCI_H4P_NACK 0x40
+#define HCI_H4P_ALIVE_IND_REQ 0x55
+#define HCI_H4P_ALIVE_IND_RESP 0xCC
+
+#define H4_TYPE_SIZE 1
+#define H4_RADIO_HDR_SIZE 2
+
+/* H4+ packet types */
+#define H4_CMD_PKT 0x01
+#define H4_ACL_PKT 0x02
+#define H4_SCO_PKT 0x03
+#define H4_EVT_PKT 0x04
+#define H4_NEG_PKT 0x06
+#define H4_ALIVE_PKT 0x07
+#define H4_RADIO_PKT 0x08
+
+/* TX states */
+#define WAIT_FOR_PKT_TYPE 1
+#define WAIT_FOR_HEADER 2
+#define WAIT_FOR_DATA 3
+
+struct hci_fw_event {
+ struct hci_event_hdr hev;
+ struct hci_ev_cmd_complete cmd;
+ u8 status;
+} __attribute__ ((packed));
+
+int hci_h4p_send_alive_packet(struct hci_h4p_info *info);
+
+void hci_h4p_bcm_parse_fw_event(struct hci_h4p_info *info,
+ struct sk_buff *skb);
+int hci_h4p_bcm_send_fw(struct hci_h4p_info *info,
+ struct sk_buff_head *fw_queue);
+
+void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info,
+ struct sk_buff *skb);
+int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
+ struct sk_buff_head *fw_queue);
+
+void hci_h4p_ti1273_parse_fw_event(struct hci_h4p_info *info,
+ struct sk_buff *skb);
+int hci_h4p_ti1273_send_fw(struct hci_h4p_info *info,
+ struct sk_buff_head *fw_queue);
+
+int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
+int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
+void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb);
+
+void hci_h4p_outb(struct hci_h4p_info *info, unsigned int offset, u8 val);
+u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset);
+void hci_h4p_set_rts(struct hci_h4p_info *info, int active);
+int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active, int timeout_ms);
+void __hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
+void hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
+void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed);
+int hci_h4p_reset_uart(struct hci_h4p_info *info);
+void hci_h4p_init_uart(struct hci_h4p_info *info);
+void hci_h4p_enable_tx(struct hci_h4p_info *info);
+void hci_h4p_store_regs(struct hci_h4p_info *info);
+void hci_h4p_restore_regs(struct hci_h4p_info *info);
+void hci_h4p_smart_idle(struct hci_h4p_info *info, bool enable);
+
+#endif /* __DRIVERS_BLUETOOTH_HCI_H4P_H */
diff --git a/drivers/bluetooth/hci_h4p/uart.c b/drivers/bluetooth/hci_h4p/uart.c
new file mode 100644
index 0000000..033825f
--- /dev/null
+++ b/drivers/bluetooth/hci_h4p/uart.c
@@ -0,0 +1,203 @@
+/*
+ * This file is part of hci_h4p bluetooth driver
+ *
+ * Copyright (C) 2005, 2006 Nokia Corporation.
+ *
+ * Contact: Ville Tervo <ville.tervo@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/serial_reg.h>
+#include <linux/delay.h>
+#include <linux/clk.h>
+
+#include <linux/io.h>
+
+#include "hci_h4p.h"
+
+inline void hci_h4p_outb(struct hci_h4p_info *info, unsigned int offset, u8 val)
+{
+ __raw_writeb(val, info->uart_base + (offset << 2));
+}
+
+inline u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset)
+{
+ return __raw_readb(info->uart_base + (offset << 2));
+}
+
+void hci_h4p_set_rts(struct hci_h4p_info *info, int active)
+{
+ u8 b;
+
+ b = hci_h4p_inb(info, UART_MCR);
+ if (active)
+ b |= UART_MCR_RTS;
+ else
+ b &= ~UART_MCR_RTS;
+ hci_h4p_outb(info, UART_MCR, b);
+}
+
+int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active,
+ int timeout_ms)
+{
+ unsigned long timeout;
+ int state;
+
+ timeout = jiffies + msecs_to_jiffies(timeout_ms);
+ for (;;) {
+ state = hci_h4p_inb(info, UART_MSR) & UART_MSR_CTS;
+ if (active) {
+ if (state)
+ return 0;
+ } else {
+ if (!state)
+ return 0;
+ }
+ if (time_after(jiffies, timeout))
+ return -ETIMEDOUT;
+ msleep(1);
+ }
+}
+
+void __hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which)
+{
+ u8 lcr, b;
+
+ lcr = hci_h4p_inb(info, UART_LCR);
+ hci_h4p_outb(info, UART_LCR, 0xbf);
+ b = hci_h4p_inb(info, UART_EFR);
+ if (on)
+ b |= which;
+ else
+ b &= ~which;
+ hci_h4p_outb(info, UART_EFR, b);
+ hci_h4p_outb(info, UART_LCR, lcr);
+}
+
+void hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&info->lock, flags);
+ __hci_h4p_set_auto_ctsrts(info, on, which);
+ spin_unlock_irqrestore(&info->lock, flags);
+}
+
+void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed)
+{
+ unsigned int divisor;
+ u8 lcr, mdr1;
+
+ NBT_DBG("Setting speed %lu\n", speed);
+
+ if (speed >= 460800) {
+ divisor = UART_CLOCK / 13 / speed;
+ mdr1 = 3;
+ } else {
+ divisor = UART_CLOCK / 16 / speed;
+ mdr1 = 0;
+ }
+
+ /* Make sure UART mode is disabled */
+ hci_h4p_outb(info, UART_OMAP_MDR1, 7);
+
+ lcr = hci_h4p_inb(info, UART_LCR);
+ hci_h4p_outb(info, UART_LCR, UART_LCR_DLAB); /* Set DLAB */
+ hci_h4p_outb(info, UART_DLL, divisor & 0xff); /* Set speed */
+ hci_h4p_outb(info, UART_DLM, divisor >> 8);
+ hci_h4p_outb(info, UART_LCR, lcr);
+
+ /* Make sure UART mode is enabled */
+ hci_h4p_outb(info, UART_OMAP_MDR1, mdr1);
+}
+
+int hci_h4p_reset_uart(struct hci_h4p_info *info)
+{
+ int count = 0;
+
+ /* Reset the UART */
+ hci_h4p_outb(info, UART_OMAP_SYSC, UART_SYSC_OMAP_RESET);
+ while (!(hci_h4p_inb(info, UART_OMAP_SYSS) & UART_SYSS_RESETDONE)) {
+ if (count++ > 100) {
+ dev_err(info->dev, "hci_h4p: UART reset timeout\n");
+ return -ENODEV;
+ }
+ udelay(1);
+ }
+
+ return 0;
+}
+
+
+void hci_h4p_store_regs(struct hci_h4p_info *info)
+{
+ u16 lcr = 0;
+
+ lcr = hci_h4p_inb(info, UART_LCR);
+ hci_h4p_outb(info, UART_LCR, 0xBF);
+ info->dll = hci_h4p_inb(info, UART_DLL);
+ info->dlh = hci_h4p_inb(info, UART_DLM);
+ info->efr = hci_h4p_inb(info, UART_EFR);
+ hci_h4p_outb(info, UART_LCR, lcr);
+ info->mdr1 = hci_h4p_inb(info, UART_OMAP_MDR1);
+ info->ier = hci_h4p_inb(info, UART_IER);
+}
+
+void hci_h4p_restore_regs(struct hci_h4p_info *info)
+{
+ u16 lcr = 0;
+
+ hci_h4p_init_uart(info);
+
+ hci_h4p_outb(info, UART_OMAP_MDR1, 7);
+ lcr = hci_h4p_inb(info, UART_LCR);
+ hci_h4p_outb(info, UART_LCR, 0xBF);
+ hci_h4p_outb(info, UART_DLL, info->dll); /* Set speed */
+ hci_h4p_outb(info, UART_DLM, info->dlh);
+ hci_h4p_outb(info, UART_EFR, info->efr);
+ hci_h4p_outb(info, UART_LCR, lcr);
+ hci_h4p_outb(info, UART_OMAP_MDR1, info->mdr1);
+ hci_h4p_outb(info, UART_IER, info->ier);
+}
+
+void hci_h4p_init_uart(struct hci_h4p_info *info)
+{
+ u8 mcr, efr;
+
+ /* Enable and setup FIFO */
+ hci_h4p_outb(info, UART_OMAP_MDR1, 0x00);
+
+ hci_h4p_outb(info, UART_LCR, 0xbf);
+ efr = hci_h4p_inb(info, UART_EFR);
+ hci_h4p_outb(info, UART_EFR, UART_EFR_ECB);
+ hci_h4p_outb(info, UART_LCR, UART_LCR_DLAB);
+ mcr = hci_h4p_inb(info, UART_MCR);
+ hci_h4p_outb(info, UART_MCR, UART_MCR_TCRTLR);
+ hci_h4p_outb(info, UART_FCR, UART_FCR_ENABLE_FIFO |
+ UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT |
+ (3 << 6) | (0 << 4));
+ hci_h4p_outb(info, UART_LCR, 0xbf);
+ hci_h4p_outb(info, UART_TI752_TLR, 0xed);
+ hci_h4p_outb(info, UART_TI752_TCR, 0xef);
+ hci_h4p_outb(info, UART_EFR, efr);
+ hci_h4p_outb(info, UART_LCR, UART_LCR_DLAB);
+ hci_h4p_outb(info, UART_MCR, 0x00);
+ hci_h4p_outb(info, UART_LCR, UART_LCR_WLEN8);
+ hci_h4p_outb(info, UART_IER, UART_IER_RDI | UART_IER_RLSI);
+ hci_h4p_outb(info, UART_OMAP_WER, 0xff);
+ hci_h4p_outb(info, UART_OMAP_SYSC, (0 << 0) | (1 << 2) | (1 << 3));
+}
diff --git a/include/linux/bluetooth/hci_h4p.h b/include/linux/bluetooth/hci_h4p.h
new file mode 100644
index 0000000..ba1d764
--- /dev/null
+++ b/include/linux/bluetooth/hci_h4p.h
@@ -0,0 +1,41 @@
+/*
+ * This file is part of hci_h4p bluetooth driver
+ *
+ * Copyright (C) 2010 Nokia Corporation.
+ *
+ * Contact: Roger Quadros <roger.quadros@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+
+/**
+ * struct hci_h4p_platform data - hci_h4p Platform data structure
+ * @uart_base: UART base address
+ * @uart_irq: UART Interrupt number
+ * @host_wu: Function hook determine if Host should wakeup or not.
+ * @bt_wu: Function hook to enable/disable Bluetooth transmission
+ * @reset: Function hook to set/clear reset conditiona
+ * @host_wu_gpio: Gpio used to wakeup host
+ */
+struct hci_h4p_platform_data {
+ void *uart_base;
+ unsigned int uart_irq;
+ bool (*host_wu)(void);
+ void (*bt_wu)(bool);
+ void (*reset)(bool);
+ unsigned int host_wu_gpio;
+};
--
Pali Rohár
pali.rohar@gmail.com
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply related
* [PATCH BlueZ 2/2] build: Libify btio
From: Luiz Augusto von Dentz @ 2013-10-18 10:16 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1382091380-31518-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This enables tools/binaries to link directly with libbtio-internal.la
so btio only need to be compiled once.
---
Makefile.am | 13 ++++++++-----
Makefile.obexd | 3 ++-
Makefile.tools | 24 ++++++++++++++----------
3 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 816c071..f73176c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -100,7 +100,9 @@ attrib_sources = attrib/att.h attrib/att-database.h attrib/att.c \
attrib/gattrib.h attrib/gattrib.c \
attrib/gatt-service.h attrib/gatt-service.c
-btio_sources = btio/btio.h btio/btio.c
+noinst_LTLIBRARIES += btio/libbtio-internal.la
+
+btio_libbtio_internal_la_SOURCES = btio/btio.h btio/btio.c
noinst_LTLIBRARIES += gobex/libgobex-internal.la
@@ -127,8 +129,7 @@ endif
libexec_PROGRAMS += src/bluetoothd
-src_bluetoothd_SOURCES = $(builtin_sources) \
- $(attrib_sources) $(btio_sources) \
+src_bluetoothd_SOURCES = $(builtin_sources) $(attrib_sources) \
src/bluetooth.ver \
src/main.c src/log.h src/log.c \
src/systemd.h src/systemd.c \
@@ -154,12 +155,14 @@ src_bluetoothd_SOURCES = $(builtin_sources) \
src/shared/util.h src/shared/util.c \
src/shared/mgmt.h src/shared/mgmt.c
src_bluetoothd_LDADD = lib/libbluetooth-internal.la gdbus/libgdbus-internal.la \
- @GLIB_LIBS@ @DBUS_LIBS@ -ldl -lrt
+ btio/libbtio-internal.la @GLIB_LIBS@ @DBUS_LIBS@ -ldl \
+ -lrt
src_bluetoothd_LDFLAGS = $(AM_LDFLAGS) -Wl,--export-dynamic \
-Wl,--version-script=$(srcdir)/src/bluetooth.ver
src_bluetoothd_DEPENDENCIES = lib/libbluetooth-internal.la \
- gdbus/libgdbus-internal.la src/bluetooth.service
+ gdbus/libgdbus-internal.la \
+ btio/libbtio-internal.la src/bluetooth.service
src_bluetoothd_CFLAGS = $(AM_CFLAGS) -DBLUETOOTH_PLUGIN_BUILTIN \
-DPLUGINDIR=\""$(build_plugindir)"\"
diff --git a/Makefile.obexd b/Makefile.obexd
index 1aad9ce..922b1b4 100644
--- a/Makefile.obexd
+++ b/Makefile.obexd
@@ -54,7 +54,7 @@ obexd_builtin_sources += obexd/client/mns.c obexd/src/map_ap.h \
libexec_PROGRAMS += obexd/src/obexd
-obexd_src_obexd_SOURCES = $(btio_sources) $(obexd_builtin_sources) \
+obexd_src_obexd_SOURCES = $(obexd_builtin_sources) \
obexd/src/main.c obexd/src/obexd.h \
obexd/src/plugin.h obexd/src/plugin.c \
obexd/src/log.h obexd/src/log.c \
@@ -81,6 +81,7 @@ obexd_src_obexd_SOURCES = $(btio_sources) $(obexd_builtin_sources) \
obexd_src_obexd_LDADD = lib/libbluetooth-internal.la \
gdbus/libgdbus-internal.la \
gobex/libgobex-internal.la \
+ btio/libbtio-internal.la \
@ICAL_LIBS@ @DBUS_LIBS@ @GLIB_LIBS@ -ldl
obexd_src_obexd_LDFLAGS = -Wl,--export-dynamic
diff --git a/Makefile.tools b/Makefile.tools
index 43bcf2e..c30b831 100644
--- a/Makefile.tools
+++ b/Makefile.tools
@@ -203,8 +203,9 @@ tools_btsnoop_SOURCES = tools/btsnoop.c \
src/shared/pcap.h src/shared/pcap.c \
src/shared/btsnoop.h src/shared/btsnoop.c
-tools_btiotest_SOURCES = tools/btiotest.c btio/btio.h btio/btio.c
-tools_btiotest_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
+tools_btiotest_SOURCES = tools/btiotest.c
+tools_btiotest_LDADD = btio/libbtio-internal.la lib/libbluetooth-internal.la \
+ @GLIB_LIBS@
tools_mpris_player_SOURCES = tools/mpris-player.c
tools_mpris_player_LDADD = gdbus/libgdbus-internal.la @GLIB_LIBS@ @DBUS_LIBS@
@@ -221,19 +222,22 @@ noinst_PROGRAMS += attrib/gatttool \
tools/bluetooth-player tools/obexctl
attrib_gatttool_SOURCES = attrib/gatttool.c attrib/att.c attrib/gatt.c \
- attrib/gattrib.c btio/btio.c \
- attrib/gatttool.h attrib/interactive.c \
- attrib/utils.c src/log.c client/display.c \
+ attrib/gattrib.c attrib/gatttool.h \
+ attrib/interactive.c attrib/utils.c \
+ src/log.c client/display.c \
client/display.h
-attrib_gatttool_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@ -lreadline
+attrib_gatttool_LDADD = lib/libbluetooth-internal.la btio/libbtio-internal.la \
+ @GLIB_LIBS@ -lreadline
-tools_obex_client_tool_SOURCES = $(btio_sources) tools/obex-client-tool.c
-tools_obex_client_tool_LDADD = lib/libbluetooth-internal.la \
+tools_obex_client_tool_SOURCES = tools/obex-client-tool.c
+tools_obex_client_tool_LDADD = btio/libbtio-internal.la \
+ lib/libbluetooth-internal.la \
gobex/libgobex-internal.la \
@GLIB_LIBS@ -lreadline
-tools_obex_server_tool_SOURCES = $(btio_sources) tools/obex-server-tool.c
-tools_obex_server_tool_LDADD = lib/libbluetooth-internal.la \
+tools_obex_server_tool_SOURCES = tools/obex-server-tool.c
+tools_obex_server_tool_LDADD = btio/libbtio-internal.la \
+ lib/libbluetooth-internal.la \
gobex/libgobex-internal.la \
@GLIB_LIBS@
--
1.8.3.1
^ permalink raw reply related
* [PATCH BlueZ 1/2] build: Libify gobex
From: Luiz Augusto von Dentz @ 2013-10-18 10:16 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This enables tools/binaries to link directly with libgobex-internal.la
so gobex only need to be compiled once.
---
Makefile.am | 35 ++++++++++++++++++-----------------
Makefile.obexd | 4 ++--
Makefile.tools | 13 +++++++------
3 files changed, 27 insertions(+), 25 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 8aed6f7..816c071 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -102,12 +102,14 @@ attrib_sources = attrib/att.h attrib/att-database.h attrib/att.c \
btio_sources = btio/btio.h btio/btio.c
-gobex_sources = gobex/gobex.h gobex/gobex.c \
- gobex/gobex-defs.h gobex/gobex-defs.c \
- gobex/gobex-packet.c gobex/gobex-packet.h \
- gobex/gobex-header.c gobex/gobex-header.h \
- gobex/gobex-transfer.c gobex/gobex-debug.h \
- gobex/gobex-apparam.c gobex/gobex-apparam.h
+noinst_LTLIBRARIES += gobex/libgobex-internal.la
+
+gobex_libgobex_internal_la_SOURCES = gobex/gobex.h gobex/gobex.c \
+ gobex/gobex-defs.h gobex/gobex-defs.c \
+ gobex/gobex-packet.c gobex/gobex-packet.h \
+ gobex/gobex-header.c gobex/gobex-header.h \
+ gobex/gobex-transfer.c gobex/gobex-debug.h \
+ gobex/gobex-apparam.c gobex/gobex-apparam.h
builtin_modules =
builtin_sources =
@@ -258,25 +260,24 @@ unit_test_gdbus_client_LDADD = gdbus/libgdbus-internal.la \
unit_tests += unit/test-gobex-header unit/test-gobex-packet unit/test-gobex \
unit/test-gobex-transfer unit/test-gobex-apparam
-unit_test_gobex_SOURCES = $(gobex_sources) unit/util.c unit/util.h \
- unit/test-gobex.c
-unit_test_gobex_LDADD = @GLIB_LIBS@
+unit_test_gobex_SOURCES = unit/util.c unit/util.h unit/test-gobex.c
+unit_test_gobex_LDADD = gobex/libgobex-internal.la @GLIB_LIBS@
-unit_test_gobex_packet_SOURCES = $(gobex_sources) unit/util.c unit/util.h \
+unit_test_gobex_packet_SOURCES = unit/util.c unit/util.h \
unit/test-gobex-packet.c
-unit_test_gobex_packet_LDADD = @GLIB_LIBS@
+unit_test_gobex_packet_LDADD = gobex/libgobex-internal.la @GLIB_LIBS@
-unit_test_gobex_header_SOURCES = $(gobex_sources) unit/util.c unit/util.h \
+unit_test_gobex_header_SOURCES = unit/util.c unit/util.h \
unit/test-gobex-header.c
-unit_test_gobex_header_LDADD = @GLIB_LIBS@
+unit_test_gobex_header_LDADD = gobex/libgobex-internal.la @GLIB_LIBS@
-unit_test_gobex_transfer_SOURCES = $(gobex_sources) unit/util.c unit/util.h \
+unit_test_gobex_transfer_SOURCES = unit/util.c unit/util.h \
unit/test-gobex-transfer.c
-unit_test_gobex_transfer_LDADD = @GLIB_LIBS@
+unit_test_gobex_transfer_LDADD = gobex/libgobex-internal.la @GLIB_LIBS@
-unit_test_gobex_apparam_SOURCES = $(gobex_sources) unit/util.c unit/util.h \
+unit_test_gobex_apparam_SOURCES = unit/util.c unit/util.h \
unit/test-gobex-apparam.c
-unit_test_gobex_apparam_LDADD = @GLIB_LIBS@
+unit_test_gobex_apparam_LDADD = gobex/libgobex-internal.la @GLIB_LIBS@
unit_tests += unit/test-lib
diff --git a/Makefile.obexd b/Makefile.obexd
index 3760867..1aad9ce 100644
--- a/Makefile.obexd
+++ b/Makefile.obexd
@@ -54,8 +54,7 @@ obexd_builtin_sources += obexd/client/mns.c obexd/src/map_ap.h \
libexec_PROGRAMS += obexd/src/obexd
-obexd_src_obexd_SOURCES = $(btio_sources) $(gobex_sources) \
- $(obexd_builtin_sources) \
+obexd_src_obexd_SOURCES = $(btio_sources) $(obexd_builtin_sources) \
obexd/src/main.c obexd/src/obexd.h \
obexd/src/plugin.h obexd/src/plugin.c \
obexd/src/log.h obexd/src/log.c \
@@ -81,6 +80,7 @@ obexd_src_obexd_SOURCES = $(btio_sources) $(gobex_sources) \
obexd/src/map_ap.h
obexd_src_obexd_LDADD = lib/libbluetooth-internal.la \
gdbus/libgdbus-internal.la \
+ gobex/libgobex-internal.la \
@ICAL_LIBS@ @DBUS_LIBS@ @GLIB_LIBS@ -ldl
obexd_src_obexd_LDFLAGS = -Wl,--export-dynamic
diff --git a/Makefile.tools b/Makefile.tools
index 840b95c..43bcf2e 100644
--- a/Makefile.tools
+++ b/Makefile.tools
@@ -227,14 +227,15 @@ attrib_gatttool_SOURCES = attrib/gatttool.c attrib/att.c attrib/gatt.c \
client/display.h
attrib_gatttool_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@ -lreadline
-tools_obex_client_tool_SOURCES = $(gobex_sources) $(btio_sources) \
- tools/obex-client-tool.c
+tools_obex_client_tool_SOURCES = $(btio_sources) tools/obex-client-tool.c
tools_obex_client_tool_LDADD = lib/libbluetooth-internal.la \
- @GLIB_LIBS@ -lreadline
+ gobex/libgobex-internal.la \
+ @GLIB_LIBS@ -lreadline
-tools_obex_server_tool_SOURCES = $(gobex_sources) $(btio_sources) \
- tools/obex-server-tool.c
-tools_obex_server_tool_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
+tools_obex_server_tool_SOURCES = $(btio_sources) tools/obex-server-tool.c
+tools_obex_server_tool_LDADD = lib/libbluetooth-internal.la \
+ gobex/libgobex-internal.la \
+ @GLIB_LIBS@
tools_bluetooth_player_SOURCES = tools/bluetooth-player.c \
client/display.h client/display.c
--
1.8.3.1
^ permalink raw reply related
* Re: [PATCH] Bluetooth: Use BDADDR_BREDR type for old blacklist ioctl interface
From: Johan Hedberg @ 2013-10-18 9:27 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1382083828-23001-1-git-send-email-marcel@holtmann.org>
Hi Marcel,
On Fri, Oct 18, 2013, Marcel Holtmann wrote:
> The old blacklist ioctl interface was only able to operate on BR/EDR
> addresses. So use the BDADDR_BREDR address type definition instead
> of an open coded magic 0 value.
>
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
> net/bluetooth/hci_sock.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Applied to bluetooth-next. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH] Bluetooth: Add hci_h4p driver
From: Marcel Holtmann @ 2013-10-18 8:56 UTC (permalink / raw)
To: Pali Rohár; +Cc: linux-bluetooth@vger.kernel.org development
In-Reply-To: <201310180739.47841@pali>
Hi Pali,
>>>> This driver adding support for Nokia N900 bluetooth
>>>> hardware
>>>>
>>>> Signed-off-by: Ville Tervo <ville.tervo@nokia.com>
>>>> Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
>>>> ---
>>>> drivers/bluetooth/Kconfig | 10 +
>>>> drivers/bluetooth/Makefile | 2 +
>>>> drivers/bluetooth/hci_h4p/Makefile | 7 +
>>>> drivers/bluetooth/hci_h4p/core.c | 1085
>>>> +++++++++++++++++++++++++++++++++
>>>> drivers/bluetooth/hci_h4p/fw-bcm.c | 149 +++++
>>>> drivers/bluetooth/hci_h4p/fw-csr.c | 152 +++++
>>>> drivers/bluetooth/hci_h4p/fw-ti1273.c | 113 ++++
>>>> drivers/bluetooth/hci_h4p/fw.c | 166 +++++
>>>> drivers/bluetooth/hci_h4p/hci_h4p.h | 238 ++++++++
>>>> drivers/bluetooth/hci_h4p/uart.c | 203 ++++++
>>>> include/linux/bluetooth/hci_h4p.h | 41 ++
>>>> 11 files changed, 2166 insertions(+)
>>>> create mode 100644 drivers/bluetooth/hci_h4p/Makefile
>>>> create mode 100644 drivers/bluetooth/hci_h4p/core.c
>>>> create mode 100644 drivers/bluetooth/hci_h4p/fw-bcm.c
>>>> create mode 100644 drivers/bluetooth/hci_h4p/fw-csr.c
>>>> create mode 100644 drivers/bluetooth/hci_h4p/fw-ti1273.c
>>>> create mode 100644 drivers/bluetooth/hci_h4p/fw.c
>>>> create mode 100644 drivers/bluetooth/hci_h4p/hci_h4p.h
>>>> create mode 100644 drivers/bluetooth/hci_h4p/uart.c
>>>> create mode 100644 include/linux/bluetooth/hci_h4p.h
>>>
>>> Can somebody look & comment this patch? What is needed to be
>>> part of upstream kernel?
>>
>> you need to rebase against bluetooth-next at least.
>
> Can you specify full url to that repo?
you can find that tree on git.kernel.org.
Regards
Marcel
^ permalink raw reply
* Re: [PATCH v2] Bluetooth: Fix ATT socket backwards compatibility with user space
From: Marcel Holtmann @ 2013-10-18 8:54 UTC (permalink / raw)
To: johan.hedberg; +Cc: linux-bluetooth
In-Reply-To: <1382086165-24818-1-git-send-email-johan.hedberg@gmail.com>
Hi Johan,
> Old user space versions bind the Attribute Protocol socket to
> BDADDR_BREDR when they should be using BDADDR_LE_PUBLIC or
> BDADDR_LE_RANDOM. The kernel recently introduced stricter checks on the
> socket parameters but we need to punch this hole for old user space
> versions to keep them working.
>
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/l2cap_sock.c | 27 +++++++++++++++++++++++++--
> 1 file changed, 25 insertions(+), 2 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel
^ permalink raw reply
* [PATCH v2] Bluetooth: Fix ATT socket backwards compatibility with user space
From: johan.hedberg @ 2013-10-18 8:49 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@intel.com>
Old user space versions bind the Attribute Protocol socket to
BDADDR_BREDR when they should be using BDADDR_LE_PUBLIC or
BDADDR_LE_RANDOM. The kernel recently introduced stricter checks on the
socket parameters but we need to punch this hole for old user space
versions to keep them working.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/l2cap_sock.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 34e5a58..1f326d9 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -159,8 +159,31 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr,
if (!bdaddr_type_is_valid(la.l2_bdaddr_type))
return -EINVAL;
- if (chan->src_type == BDADDR_BREDR && la.l2_bdaddr_type != BDADDR_BREDR)
- return -EINVAL;
+ /* Check that the socket wasn't bound to something that
+ * conflicts with the address given to connect(). If chan->src
+ * is BDADDR_ANY it means bind() was never used, in which case
+ * chan->src_type and la.l2_bdaddr_type do not need to match.
+ */
+ if (chan->src_type == BDADDR_BREDR && bacmp(&chan->src, BDADDR_ANY) &&
+ bdaddr_type_is_le(la.l2_bdaddr_type)) {
+ /* Old user space versions will try to incorrectly bind
+ * the ATT socket using BDADDR_BREDR. We need to accept
+ * this and fix up the source address type only when
+ * both the source CID and destination CID indicate
+ * ATT. Anything else is an invalid combination.
+ */
+ if (chan->scid != L2CAP_CID_ATT ||
+ la.l2_cid != __constant_cpu_to_le16(L2CAP_CID_ATT))
+ return -EINVAL;
+
+ /* We don't have the hdev available here to make a
+ * better decision on random vs public, but since all
+ * user space versions that exhibit this issue anyway do
+ * not support random local addresses assuming public
+ * here is good enough.
+ */
+ chan->src_type = BDADDR_LE_PUBLIC;
+ }
if (chan->src_type != BDADDR_BREDR && la.l2_bdaddr_type == BDADDR_BREDR)
return -EINVAL;
--
1.8.3.1
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox