Skip to contentSkip to conversation

android/hidhost: Move get_protocol parameter check to daemon

PATCH In review Szymon Janc 2 participants 5 messages Dec 30, 2013 – Dec 31, 2013 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 android/hidhost: Move get_protocol parameter check to daemon

HAL library is to be as simple as possible and parameters values should be verified by daemon for robustness anyway. Move this check to daemon.

---
 android/hal-hidhost.c | 12 ++----------
 android/hidhost.c     |  9 +++++++++
 2 files changed, 11 insertions(+), 10 deletions(-)
android/hal-hidhost.c +2 -10
index 6a6b682..5d05f9b 100644
@@ -218,16 +218,8 @@ static bt_status_t get_protocol(bt_bdaddr_t *bd_addr,
 
 	memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
 
-	switch (protocol_mode) {
-	case BTHH_REPORT_MODE:
-		cmd.mode = HAL_HIDHOST_REPORT_PROTOCOL;
-		break;
-	case BTHH_BOOT_MODE:
-		cmd.mode = HAL_HIDHOST_BOOT_PROTOCOL;
-		break;
-	default:
-		return BT_STATUS_PARM_INVALID;
-	}
+	/* type match IPC type */
+	cmd.mode = protocol_mode;
 
 	return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST,
 				HAL_OP_HIDHOST_GET_PROTOCOL,
android/hidhost.c +9 -0
index 0e0391a..4635e53 100644
@@ -880,6 +880,15 @@ static void bt_hid_get_protocol(const void *buf, uint16_t len)
 
 	DBG("");
 
+	switch (cmd->mode) {
+	case HAL_HIDHOST_REPORT_PROTOCOL:
+	case HAL_HIDHOST_BOOT_PROTOCOL:
+		break;
+	default:
+		status = HAL_STATUS_INVALID;
+		goto failed;
+	}
+
 	android2bdaddr(&cmd->bdaddr, &dst);
 
 	l = g_slist_find_custom(devices, &dst, device_cmp);
Signature · 1 line
1.8.5.2
#1 lore raw

PATCH 2/4 android/hidhost: Move set_protocol parameter check to daemon

HAL library is to be as simple as possible and parameters values should be verified by daemon for robustness anyway. Move this check to daemon.

---
 android/hal-hidhost.c | 12 ++----------
 android/hidhost.c     |  9 +++++++++
 2 files changed, 11 insertions(+), 10 deletions(-)
android/hal-hidhost.c +2 -10
index 5d05f9b..b331145 100644
@@ -241,16 +241,8 @@ static bt_status_t set_protocol(bt_bdaddr_t *bd_addr,
 
 	memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
 
-	switch (protocol_mode) {
-	case BTHH_REPORT_MODE:
-		cmd.mode = HAL_HIDHOST_REPORT_PROTOCOL;
-		break;
-	case BTHH_BOOT_MODE:
-		cmd.mode = HAL_HIDHOST_BOOT_PROTOCOL;
-		break;
-	default:
-		return BT_STATUS_PARM_INVALID;
-	}
+	/* type match IPC type */
+	cmd.mode = protocol_mode;
 
 	return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST,
 				HAL_OP_HIDHOST_SET_PROTOCOL,
android/hidhost.c +9 -0
index 4635e53..76e65b8 100644
@@ -935,6 +935,15 @@ static void bt_hid_set_protocol(const void *buf, uint16_t len)
 
 	DBG("");
 
+	switch (cmd->mode) {
+	case HAL_HIDHOST_REPORT_PROTOCOL:
+	case HAL_HIDHOST_BOOT_PROTOCOL:
+		break;
+	default:
+		status = HAL_STATUS_INVALID;
+		goto failed;
+	}
+
 	android2bdaddr(&cmd->bdaddr, &dst);
 
 	l = g_slist_find_custom(devices, &dst, device_cmp);
Signature · 1 line
1.8.5.2
#2 lore raw

PATCH 3/4 android/hidhost: Move get_report parameter check to daemon

In reply to Szymon Janc

HAL library is to be as simple as possible and parameters values should be verified by daemon for robustness anyway. Move this check to daemon.

---
 android/hal-hidhost.c | 15 ++-------------
 android/hidhost.c     | 10 ++++++++++
 2 files changed, 12 insertions(+), 13 deletions(-)
android/hal-hidhost.c +2 -13
index b331145..371250a 100644
@@ -268,19 +268,8 @@ static bt_status_t get_report(bt_bdaddr_t *bd_addr,
 	cmd.id = report_id;
 	cmd.buf_size = buffer_size;
 
-	switch (report_type) {
-	case BTHH_INPUT_REPORT:
-		cmd.type = HAL_HIDHOST_INPUT_REPORT;
-		break;
-	case BTHH_OUTPUT_REPORT:
-		cmd.type = HAL_HIDHOST_OUTPUT_REPORT;
-		break;
-	case BTHH_FEATURE_REPORT:
-		cmd.type = HAL_HIDHOST_FEATURE_REPORT;
-		break;
-	default:
-		return BT_STATUS_PARM_INVALID;
-	}
+	/* type match IPC type */
+	cmd.type = report_type;
 
 	return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_GET_REPORT,
 			sizeof(cmd), &cmd, 0, NULL, NULL);
android/hidhost.c +10 -0
index 76e65b8..1cf85b1 100644
@@ -991,6 +991,16 @@ static void bt_hid_get_report(const void *buf, uint16_t len)
 
 	DBG("");
 
+	switch (cmd->type) {
+	case HAL_HIDHOST_INPUT_REPORT:
+	case HAL_HIDHOST_OUTPUT_REPORT:
+	case HAL_HIDHOST_FEATURE_REPORT:
+		break;
+	default:
+		status = HAL_STATUS_INVALID;
+		goto failed;
+	}
+
 	android2bdaddr(&cmd->bdaddr, &dst);
 
 	l = g_slist_find_custom(devices, &dst, device_cmp);
Signature · 1 line
1.8.5.2
#3 lore raw

PATCH 4/4 android/hidhost: Move set_report parameter check to daemon

In reply to Szymon Janc

HAL library is to be as simple as possible and parameters values should be verified by daemon for robustness anyway. Move this check to daemon.

---
 android/hal-hidhost.c | 15 ++-------------
 android/hidhost.c     | 10 ++++++++++
 2 files changed, 12 insertions(+), 13 deletions(-)
android/hal-hidhost.c +2 -13
index 371250a..fd3ad2d 100644
@@ -294,19 +294,8 @@ static bt_status_t set_report(bt_bdaddr_t *bd_addr,
 	cmd->len = strlen(report);
 	memcpy(cmd->data, report, cmd->len);
 
-	switch (report_type) {
-	case BTHH_INPUT_REPORT:
-		cmd->type = HAL_HIDHOST_INPUT_REPORT;
-		break;
-	case BTHH_OUTPUT_REPORT:
-		cmd->type = HAL_HIDHOST_OUTPUT_REPORT;
-		break;
-	case BTHH_FEATURE_REPORT:
-		cmd->type = HAL_HIDHOST_FEATURE_REPORT;
-		break;
-	default:
-		return BT_STATUS_PARM_INVALID;
-	}
+	/* type match IPC type */
+	cmd->type = report_type;
 
 	return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SET_REPORT,
 				sizeof(*cmd) + cmd->len, buf, 0, NULL, NULL);
android/hidhost.c +10 -0
index 1cf85b1..aed9899 100644
@@ -1064,6 +1064,16 @@ static void bt_hid_set_report(const void *buf, uint16_t len)
 		return;
 	}
 
+	switch (cmd->type) {
+	case HAL_HIDHOST_INPUT_REPORT:
+	case HAL_HIDHOST_OUTPUT_REPORT:
+	case HAL_HIDHOST_FEATURE_REPORT:
+		break;
+	default:
+		status = HAL_STATUS_INVALID;
+		goto failed;
+	}
+
 	android2bdaddr(&cmd->bdaddr, &dst);
 
 	l = g_slist_find_custom(devices, &dst, device_cmp);
Signature · 1 line
1.8.5.2
#4 lore raw
In reply to Szymon Janc

Hi Szymon,

Quoted 6 lines · Szymon Janc

HAL library is to be as simple as possible and parameters values should be verified by daemon for robustness anyway. Move this check to daemon.

---
 android/hal-hidhost.c | 12 ++----------
 android/hidhost.c     |  9 +++++++++
 2 files changed, 11 insertions(+), 10 deletions(-)

All patches in this set have been applied. Thanks.

Johan