Browse Source

Added run command functionality to UTP.

Signed-off-by: Trace Russell <b45800@freescale.com>
Trace Russell 12 years ago
parent
commit
f24abd893b
1 changed files with 47 additions and 0 deletions
  1. 47 0
      drivers/usb/gadget/fsl_updater.c

+ 47 - 0
drivers/usb/gadget/fsl_updater.c

@@ -13,6 +13,12 @@
  * http://www.opensource.org/licenses/gpl-license.html
  * http://www.gnu.org/copyleft/gpl.html
  */
+#include <common.h>
+
+#define UTP_FLAG_COMMAND	0x00000001
+#define UTP_FLAG_DATA		0x00000002
+#define UTP_FLAG_STATUS		0x00000004
+#define UTP_FLAG_REPORT_BUSY	0x10000000
 
 static u64 get_be64(u8 *buf)
 {
@@ -455,3 +461,44 @@ static int utp_handle_message(struct fsg_common *common,
 	return -1;
 }
 
+u32 utp_run(char *cmd)
+{
+	return run_command(cmd, 0);
+}
+
+struct utp_user_data *utp_handle_command(char *cmd, u64 payload)
+{
+	u32			flags, status;
+	size_t			size;
+	struct utp_user_data	*answer;
+
+	/* defaults */
+	status = 0;
+	flags = 0;
+	size = 0;
+
+	if (cmd[0] == '$') {
+		status = utp_run(cmd + 2);
+		if (status)
+			flags = UTP_FLAG_STATUS;
+	}
+
+	answer = utp_user_data_alloc(size);
+	if (flags & UTP_FLAG_STATUS)
+		answer->status = status;
+	return answer;
+}
+
+struct utp_user_data *utp_interpret_message(struct utp_user_data *uud2r)
+{
+	struct utp_user_data *answer;
+
+	if (uud2r->flags & UTP_FLAG_COMMAND) {
+		answer = utp_handle_command(uud2r->command, uud2r->payload);
+		if (answer)
+			return answer;
+	} else if (uud2r->flags & UTP_FLAG_DATA) {
+		/* TODO */
+	}
+	return NULL;
+}