Linux bluetooth development
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@tieto.com>
To: <linux-bluetooth@vger.kernel.org>
Cc: Szymon Janc <szymon.janc@tieto.com>
Subject: [RFC 03/14] android: Add HAL IPC message response sanity checks
Date: Wed, 6 Nov 2013 15:09:19 +0100	[thread overview]
Message-ID: <1383746970-25906-4-git-send-email-szymon.janc@tieto.com> (raw)
In-Reply-To: <1383746970-25906-1-git-send-email-szymon.janc@tieto.com>

This implements core, bluetooth, sock and hidhost services checks.
---
 android/hal-msg-check.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++
 android/hal-msg.h       |   2 +
 2 files changed, 103 insertions(+)

diff --git a/android/hal-msg-check.c b/android/hal-msg-check.c
index 208d8a5..0c719ac 100644
--- a/android/hal-msg-check.c
+++ b/android/hal-msg-check.c
@@ -161,3 +161,104 @@ bool hal_cmd_check(const struct hal_hdr *msg, const void *payload, ssize_t len)
 		return false;
 	}
 }
+
+static bool check_rsp_core(uint8_t opcode, const void *payload, uint16_t len)
+{
+	switch (opcode) {
+	check_fix_p(HAL_OP_STATUS, hal_status);
+	check_no_p(HAL_OP_REGISTER_MODULE);
+	check_no_p(HAL_OP_UNREGISTER_MODULE);
+	default:
+		return false;
+	}
+}
+
+static bool check_rsp_bluetooth(uint8_t opcode, const void *payload,
+								uint16_t len)
+{
+	switch (opcode) {
+	check_fix_p(HAL_OP_STATUS, hal_status);
+	check_no_p(HAL_OP_ENABLE);
+	check_no_p(HAL_OP_DISABLE);
+	check_no_p(HAL_OP_GET_ADAPTER_PROPS);
+	check_no_p(HAL_OP_GET_ADAPTER_PROP);
+	check_no_p(HAL_OP_SET_ADAPTER_PROP);
+	check_no_p(HAL_OP_GET_REMOTE_DEVICE_PROPS);
+	check_no_p(HAL_OP_GET_REMOTE_DEVICE_PROP);
+	check_no_p(HAL_OP_SET_REMOTE_DEVICE_PROP);
+	check_no_p(HAL_OP_GET_REMOTE_SERVICE_REC);
+	check_no_p(HAL_OP_GET_REMOTE_SERVICES);
+	check_no_p(HAL_OP_START_DISCOVERY);
+	check_no_p(HAL_OP_CANCEL_DISCOVERY);
+	check_no_p(HAL_OP_CREATE_BOND);
+	check_no_p(HAL_OP_REMOVE_BOND);
+	check_no_p(HAL_OP_CANCEL_BOND)
+	check_no_p(HAL_OP_PIN_REPLY);
+	check_no_p(HAL_OP_SSP_REPLY)
+	check_no_p(HAL_OP_DUT_MODE_CONF);
+	check_no_p(HAL_OP_DUT_MODE_SEND);
+	check_no_p(HAL_OP_LE_TEST_MODE);
+	default:
+		return false;
+	}
+}
+
+static bool check_rsp_sock(uint8_t opcode, const void *payload, uint16_t len)
+{
+	switch (opcode) {
+	check_fix_p(HAL_OP_STATUS, hal_status);
+	check_no_p(HAL_OP_SOCK_LISTEN);
+	check_no_p(HAL_OP_SOCK_CONNECT);
+	default:
+		return false;
+	}
+}
+
+static bool check_rsp_hidhost(uint8_t opcode, const void *payload,
+								uint16_t len)
+{
+	switch (opcode) {
+	check_fix_p(HAL_OP_STATUS, hal_status);
+	check_no_p(HAL_OP_HID_CONNECT);
+	check_no_p(HAL_OP_HID_DISCONNECT);
+	check_no_p(HAL_OP_HID_VP);
+	check_no_p(HAL_OP_HID_SET_INFO);
+	check_no_p(HAL_OP_HID_GET_PROTOCOL);
+	check_no_p(HAL_OP_HID_SET_PROTOCOL);
+	check_no_p(HAL_OP_HID_GET_REPORT);
+	check_no_p(HAL_OP_HID_SET_REPORT);
+	check_no_p(HAL_OP_HID_SEND_DATA);
+	default:
+		return false;
+	}
+}
+
+bool hal_rsp_check(const struct hal_hdr *msg, const void *payload,
+								ssize_t len)
+{
+	if (len < (ssize_t) sizeof(*msg))
+		return false;
+
+	if (len != (ssize_t) (sizeof(*msg) + msg->len))
+		return false;
+
+	switch (msg->service_id) {
+	case HAL_SERVICE_ID_CORE:
+		return check_rsp_core(msg->opcode, payload, msg->len);
+	case HAL_SERVICE_ID_BLUETOOTH:
+		return check_rsp_bluetooth(msg->opcode, payload, msg->len);
+	case HAL_SERVICE_ID_SOCK:
+		return check_rsp_sock(msg->opcode, payload, msg->len);
+	case HAL_SERVICE_ID_HIDHOST:
+		return check_rsp_hidhost(msg->opcode, payload, msg->len);
+	case HAL_SERVICE_ID_PAN:
+	case HAL_SERVICE_ID_HANDSFREE:
+	case HAL_SERVICE_ID_A2DP:
+	case HAL_SERVICE_ID_HEALTH:
+	case HAL_SERVICE_ID_AVRCP:
+	case HAL_SERVICE_ID_GATT:
+		return true;
+	default:
+		return false;
+	}
+}
diff --git a/android/hal-msg.h b/android/hal-msg.h
index e7587bf..2d67ccf 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -489,3 +489,5 @@ struct hal_ev_av_audio_state {
 
 bool hal_cmd_check(const struct hal_hdr *msg, const void *payload,
 								ssize_t len);
+bool hal_rsp_check(const struct hal_hdr *msg, const void *payload,
+								ssize_t len);
-- 
1.8.4.2


  parent reply	other threads:[~2013-11-06 14:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-06 14:09 [RFC 00/14] IPC sanity checks Szymon Janc
2013-11-06 14:09 ` [RFC 01/14] android: Add HAL IPC commands sanity check Szymon Janc
2013-11-07  8:44   ` Johan Hedberg
2013-11-06 14:09 ` [RFC 02/14] android: Use IPC command sanity checks Szymon Janc
2013-11-06 14:09 ` Szymon Janc [this message]
2013-11-06 14:09 ` [RFC 04/14] android/hal: Use IPC command responses " Szymon Janc
2013-11-06 14:09 ` [RFC 05/14] android: Add HAL IPC events sanity check Szymon Janc
2013-11-06 14:09 ` [RFC 06/14] android/hal: Use IPC notifications sanity checks Szymon Janc
2013-11-06 14:09 ` [RFC 07/14] android: Remove not needed HAL_MINIMUM_EVENT define Szymon Janc
2013-11-06 14:09 ` [RFC 08/14] android: Remove not needed buf len from Core service functions Szymon Janc
2013-11-06 14:09 ` [RFC 09/14] android: Remove not needed buf len from Bluetooth " Szymon Janc
2013-11-06 14:09 ` [RFC 10/14] android: Remove not needed buf len from Hidhost " Szymon Janc
2013-11-06 14:09 ` [RFC 11/14] android: Remove not needed buf len from Socket " Szymon Janc
2013-11-06 14:09 ` [RFC 12/14] android/hal: Remove not neede buf len from bluetooth HAL Szymon Janc
2013-11-06 14:09 ` [RFC 13/14] android/hal: Remove not neede buf len from hidhost HAL Szymon Janc
2013-11-06 14:09 ` [RFC 14/14] android/hal: Remove not neede buf len from av HAL Szymon Janc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1383746970-25906-4-git-send-email-szymon.janc@tieto.com \
    --to=szymon.janc@tieto.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox