From: Jose Antonio Santos Cadenas <santoscadenas@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Jose Antonio Santos Cadenas <santoscadenas@gmail.com>
Subject: [PATCH 08/16] Process MCAP response mcap_md_create_mdl_rsp
Date: Wed, 28 Jul 2010 10:03:48 +0200 [thread overview]
Message-ID: <1280304232-2939-2-git-send-email-santoscadenas@gmail.com> (raw)
In-Reply-To: <1280304232-2939-1-git-send-email-santoscadenas@gmail.com>
---
health/mcap.c | 195 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
health/mcap.h | 6 ++
2 files changed, 200 insertions(+), 1 deletions(-)
diff --git a/health/mcap.c b/health/mcap.c
index 9bb81cf..734c6be 100644
--- a/health/mcap.c
+++ b/health/mcap.c
@@ -126,6 +126,38 @@ static void set_default_cb(struct mcap_mcl *mcl)
mcl->cb->mdl_reconn_req = default_mdl_reconn_req_cb;
}
+static char *error2str(uint8_t rc)
+{
+ switch (rc) {
+ case MCAP_SUCCESS:
+ return "Success";
+ case MCAP_INVALID_OP_CODE:
+ return "Invalid Op Code";
+ case MCAP_INVALID_PARAM_VALUE:
+ return "Invalid Parameter Value";
+ case MCAP_INVALID_MDEP:
+ return "Invalid MDEP";
+ case MCAP_MDEP_BUSY:
+ return "MDEP Busy";
+ case MCAP_INVALID_MDL:
+ return "Invalid MDL";
+ case MCAP_MDL_BUSY:
+ return "MDL Busy";
+ case MCAP_INVALID_OPERATION:
+ return "Invalid Operation";
+ case MCAP_RESOURCE_UNAVAILABLE:
+ return "Resource Unavailable";
+ case MCAP_UNSPECIFIED_ERROR:
+ return "Unspecified Error";
+ case MCAP_REQUEST_NOT_SUPPORTED:
+ return "Request Not Supported";
+ case MCAP_CONFIGURATION_REJECTED:
+ return "Configuration Rejected";
+ default:
+ return "Unknown Response Code";
+ }
+}
+
static void mcap_send_std_opcode(struct mcap_mcl *mcl, void *cmd,
uint32_t size, GError **err)
{
@@ -854,9 +886,170 @@ static void proc_req_active(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
}
}
+/* Function used to process replies */
+static gboolean check_err_rsp(struct mcap_mcl *mcl, uint8_t *cmd,
+ uint32_t rlen, uint32_t len, GError **gerr)
+{
+ mcap_md_req *cmdlast = (mcap_md_req *) mcl->lcmd;
+ gint err = MCAP_ERROR_FAILED;
+ gboolean close = FALSE;
+ uint16_t rmdl, smdl;
+ mcap_rsp *rsp;
+ char *msg;
+
+ if (cmd[0] == MCAP_ERROR_RSP) {
+ msg = "MCAP_ERROR_RSP received";
+ close = TRUE;
+ goto fail;
+ }
+
+ /* Check if the response matches with the last request */
+ if (rlen < sizeof(mcap_rsp) || (mcl->lcmd[0] + 1) != cmd[0]) {
+ msg = "Protocol error";
+ close = TRUE;
+ goto fail;
+ }
+
+ if (rlen < len) {
+ msg = "Protocol error";
+ close = TRUE;
+ goto fail;
+ }
+
+ rsp = (mcap_rsp *)cmd;
+ smdl = ntohs(cmdlast->mdl);
+ rmdl = ntohs(rsp->mdl);
+ if (rmdl != smdl) {
+ msg = "MDLID received doesn't match with MDLID sent";
+ close = TRUE;
+ goto fail;
+ }
+
+ if (rsp->rc == MCAP_REQUEST_NOT_SUPPORTED) {
+ msg = "Remote does not support opcodes";
+ mcl->ctrl &= ~MCAP_CTRL_STD_OP;
+ goto fail;
+ }
+
+ if (rsp->rc == MCAP_UNSPECIFIED_ERROR) {
+ msg = "Unspecified error";
+ close = TRUE;
+ goto fail;
+ }
+
+ if (rsp->rc != MCAP_SUCCESS) {
+ msg = error2str(rsp->rc);
+ err = rsp->rc;
+ goto fail;
+ }
+
+ return FALSE;
+
+fail:
+ g_set_error(gerr, MCAP_ERROR, err, "%s", msg);
+ return close;
+}
+
+static gboolean process_md_create_mdl_rsp(struct mcap_mcl *mcl,
+ uint8_t *cmd, uint32_t len)
+{
+ mcap_md_create_mdl_req *cmdlast = (mcap_md_create_mdl_req *)mcl->lcmd;
+ struct mcap_mdl_op_cb *conn = mcl->priv_data;
+ mcap_mdl_operation_conf_cb connect_cb = conn->cb.op_conf;
+ gpointer user_data = conn->user_data;
+ struct mcap_mdl *mdl = conn->mdl;
+ uint8_t conf = cmdlast->conf;
+ gboolean close = FALSE;
+ GError *gerr = NULL;
+ uint8_t *param;
+
+ g_free(mcl->priv_data);
+ mcl->priv_data = NULL;
+
+ close = check_err_rsp(mcl, cmd, len, sizeof(mcap_rsp) + 1, &gerr);
+ g_free(mcl->lcmd);
+ mcl->lcmd = NULL;
+ mcl->req = MCL_AVAILABLE;
+
+ if (gerr)
+ goto fail;
+
+ if (len < sizeof(mcap_rsp)) {
+ g_set_error(&gerr, MCAP_ERROR, MCAP_ERROR_FAILED,
+ "Protocol error");
+ close = TRUE;
+ goto fail;
+ }
+
+ param = cmd + sizeof(mcap_rsp);
+ /* Check if preferences changed */
+ if (conf != 0x00 && *param != conf) {
+ g_set_error(&gerr, MCAP_ERROR, MCAP_ERROR_FAILED,
+ "Configuration changed");
+ close = TRUE;
+ goto fail;
+ }
+
+ connect_cb(mdl, *param, gerr, user_data);
+ return close;
+fail:
+ connect_cb(NULL, 0, gerr, user_data);
+ mcl->mdls = g_slist_remove(mcl->mdls, mdl);
+ g_free(mdl);
+ g_error_free(gerr);
+ update_mcl_state(mcl);
+ return close;
+}
+
+static gboolean process_md_reconnect_mdl_rsp(struct mcap_mcl *mcl,
+ uint8_t *cmd, uint32_t len)
+{
+ /* TODO: Implement process_md_reconnect_mdl_rsp */
+ return TRUE;
+}
+
+static gboolean process_md_abort_mdl_rsp(struct mcap_mcl *mcl,
+ uint8_t *cmd, uint32_t len)
+{
+ /* TODO: Implement process_md_abort_mdl_rsp */
+ return TRUE;
+}
+
+static gboolean process_md_delete_mdl_rsp(struct mcap_mcl *mcl, uint8_t *cmd,
+ uint32_t len)
+{
+ /* TODO: Implement process_md_delete_mdl_rsp */
+ return TRUE;
+}
+
static void proc_response(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
{
- /* TODO: Implement proc_response */
+ gboolean close;
+ RELEASE_TIMER(mcl);
+
+ switch (mcl->lcmd[0] + 1) {
+ case MCAP_MD_CREATE_MDL_RSP:
+ close = process_md_create_mdl_rsp(mcl, cmd, len);
+ break;
+ case MCAP_MD_RECONNECT_MDL_RSP:
+ close = process_md_reconnect_mdl_rsp(mcl, cmd, len);
+ break;
+ case MCAP_MD_ABORT_MDL_RSP:
+ close = process_md_abort_mdl_rsp(mcl, cmd, len);
+ break;
+ case MCAP_MD_DELETE_MDL_RSP:
+ close = process_md_delete_mdl_rsp(mcl, cmd, len);
+ break;
+ default:
+ DBG("Unknown cmd response received (op code = %d)",cmd[0]);
+ close = TRUE;
+ break;
+ }
+
+ if (close) {
+ mcl->ms->mcl_disconnected_cb(mcl, mcl->ms->user_data);
+ mcap_cache_mcl(mcl);
+ }
}
static void proc_cmd(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
diff --git a/health/mcap.h b/health/mcap.h
index d0d552a..1c72080 100644
--- a/health/mcap.h
+++ b/health/mcap.h
@@ -90,6 +90,12 @@ typedef struct {
uint8_t conf;
} __attribute__ ((packed)) mcap_md_create_mdl_req;
+typedef struct {
+ uint8_t op;
+ uint16_t mdl;
+} __attribute__ ((packed)) mcap_md_req;
+
+
/*
* MCAP Response Packet Format
*/
--
1.7.0.4
next prev parent reply other threads:[~2010-07-28 8:03 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-28 8:00 MCAP patches Santiago Carot-Nemesio
2010-07-28 8:00 ` [PATCH 01/16] Initial support for MCAP Santiago Carot-Nemesio
2010-07-28 8:00 ` [PATCH 02/16] Add MCAP instance management Santiago Carot-Nemesio
2010-07-28 8:00 ` [PATCH 03/16] Receive MCAP mcl connections from remote devices Santiago Carot-Nemesio
2010-07-28 8:00 ` [PATCH 04/16] Added function for MCAP control channel (MCL) management Santiago Carot-Nemesio
2010-07-28 8:00 ` [PATCH 05/16] Prepare FSM functions for processing comands Santiago Carot-Nemesio
2010-07-28 8:00 ` [PATCH 06/16] Send MCAP request mcap_md_create_mdl_req Santiago Carot-Nemesio
2010-07-28 8:03 ` [PATCH 07/16] Process " Jose Antonio Santos Cadenas
2010-07-28 8:03 ` Jose Antonio Santos Cadenas [this message]
2010-07-28 8:03 ` [PATCH 09/16] Implement connection of MCAP data links (MDL's) Jose Antonio Santos Cadenas
2010-07-28 8:03 ` [PATCH 10/16] Process MCAP process_md_abort_mdl request and response commands Jose Antonio Santos Cadenas
2010-07-28 8:03 ` [PATCH 11/16] Process MCAP process_md_reconnect_mdl " Jose Antonio Santos Cadenas
2010-07-28 8:03 ` [PATCH 12/16] Process MCAP process_md_delete_mdl " Jose Antonio Santos Cadenas
2010-07-28 8:07 ` [PATCH 13/16] Add functions for getting mdl properties Santiago Carot-Nemesio
2010-07-28 8:07 ` [PATCH 14/16] Response with invalid operation when an invalid request is received Santiago Carot-Nemesio
2010-07-28 8:07 ` [PATCH 15/16] Add version and supported procedures values Santiago Carot-Nemesio
2010-07-28 8:07 ` [PATCH 16/16] Add initial support for synchronization protocol Santiago Carot-Nemesio
2010-08-04 9:02 ` MCAP patches José Antonio Santos Cadenas
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=1280304232-2939-2-git-send-email-santoscadenas@gmail.com \
--to=santoscadenas@gmail.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;
as well as URLs for NNTP newsgroup(s).