From 43cc32a2ab9ba004fa2fec1893ca5bd3e13f64d2 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Sun, 7 Sep 2014 13:51:12 -0700 Subject: [PATCH] greybus: first cut at parsing svc messages sent to the AP --- drivers/staging/greybus/ap.c | 6 ++ drivers/staging/greybus/es1-ap-usb.c | 147 ++++++++++++++++++++++++++- 2 files changed, 151 insertions(+), 2 deletions(-) diff --git a/drivers/staging/greybus/ap.c b/drivers/staging/greybus/ap.c index 2fb2cc1416a7..a70404d7c1f1 100644 --- a/drivers/staging/greybus/ap.c +++ b/drivers/staging/greybus/ap.c @@ -42,6 +42,12 @@ static struct svc_msg *convert_ap_message(struct ap_msg *ap_msg) // for now, just cast the pointer and run away... svc_msg = (struct svc_msg *)ap_msg->data; + + // FIXME - put in correct version numbers + if ((svc_msg->header.version_major != 0x00) && + (svc_msg->header.version_minor != 0x00)) + return NULL; + return svc_msg; } diff --git a/drivers/staging/greybus/es1-ap-usb.c b/drivers/staging/greybus/es1-ap-usb.c index 8589273f35a5..12a5d0cf76ba 100644 --- a/drivers/staging/greybus/es1-ap-usb.c +++ b/drivers/staging/greybus/es1-ap-usb.c @@ -11,6 +11,7 @@ #include #include #include "greybus.h" +#include "svc_msg.h" static const struct usb_device_id id_table[] = { { USB_DEVICE(0xffff, 0x0001) }, // FIXME @@ -81,6 +82,124 @@ static void free_gbuf(struct gbuf *gbuf) kfree(buffer); } +static struct svc_msg *svc_msg_alloc(enum svc_function_type type) +{ + struct svc_msg *svc_msg; + + svc_msg = kzalloc((sizeof *svc_msg), GFP_KERNEL); + if (!svc_msg) + return NULL; + + // FIXME - verify we are only sending message types we should be + svc_msg->header.type = type; + return svc_msg; +} + +static void svc_msg_free(struct svc_msg *svc_msg) +{ + kfree(svc_msg); +} + +static int svc_msg_send(struct svc_msg *svc_msg) +{ + // FIXME - Do something with this message! + + + svc_msg_free(svc_msg); + return 0; +} + + +static void svc_handshake(struct svc_function_handshake *handshake, + struct es1_ap_dev *es1) +{ + struct svc_msg *svc_msg; + + /* A new SVC communication channel, let's verify it was for us */ + if (handshake->handshake_type != SVC_HANDSHAKE_SVC_HELLO) { + /* we don't know what to do with this, log it and return */ + dev_dbg(&es1->usb_intf->dev, + "received invalid handshake type %d\n", + handshake->handshake_type); + return; + } + + /* Send back a AP_HELLO message */ + svc_msg = svc_msg_alloc(SVC_FUNCTION_HANDSHAKE); + if (!svc_msg) + return; + + svc_msg->handshake.handshake_type = SVC_HANDSHAKE_AP_HELLO; + svc_msg_send(svc_msg); +} + +static void svc_management(struct svc_function_unipro_management *management, + struct es1_ap_dev *es1) +{ + /* What? An AP should not get this message */ + dev_err(&es1->usb_intf->dev, "Got an svc management message???\n"); +} + +static void svc_hotplug(struct svc_function_hotplug *hotplug, + struct es1_ap_dev *es1) +{ + u8 module_id = hotplug->module_id; + + switch (hotplug->hotplug_event) { + case SVC_HOTPLUG_EVENT: + dev_dbg(&es1->usb_intf->dev, "module id %d added\n", + module_id); + // FIXME - add the module to the system + break; + + case SVC_HOTUNPLUG_EVENT: + dev_dbg(&es1->usb_intf->dev, "module id %d removed\n", + module_id); + // FIXME - remove the module from the system + break; + + default: + dev_err(&es1->usb_intf->dev, "received invalid hotplug message type %d\n", + hotplug->hotplug_event); + break; + } +} + +static void svc_ddb(struct svc_function_ddb *ddb, struct es1_ap_dev *es1) +{ + /* What? An AP should not get this message */ + dev_err(&es1->usb_intf->dev, "Got an svc DDB message???\n"); +} + +static void svc_power(struct svc_function_power *power, struct es1_ap_dev *es1) +{ + u8 module_id = power->module_id; + + if (power->power_type != SVC_POWER_BATTERY_STATUS) { + dev_err(&es1->usb_intf->dev, "received invalid power type %d\n", + power->power_type); + return; + } + + dev_dbg(&es1->usb_intf->dev, "power status for module id %d is %d\n", + module_id, power->status.status); + + // FIXME - do something with the power information, like update our + // battery information... +} + +static void svc_epm(struct svc_function_epm *epm, struct es1_ap_dev *es1) +{ + /* What? An AP should not get this message */ + dev_err(&es1->usb_intf->dev, "Got an EPM message???\n"); +} + +static void svc_suspend(struct svc_function_suspend *suspend, + struct es1_ap_dev *es1) +{ + /* What? An AP should not get this message */ + dev_err(&es1->usb_intf->dev, "Got an suspend message???\n"); +} /* Main message loop for ap messages */ /* Odds are, most of this logic can move to core.c someday, but as we only have @@ -90,8 +209,32 @@ static void ap_msg(struct svc_msg *svc_msg, struct greybus_host_device *hd) struct es1_ap_dev *es1 = hd_to_es1(hd); /* Look at the message to figure out what to do with it */ - - + switch (svc_msg->header.type) { + case SVC_FUNCTION_HANDSHAKE: + svc_handshake(&svc_msg->handshake, es1); + break; + case SVC_FUNCTION_UNIPRO_NETWORK_MANAGEMENT: + svc_management(&svc_msg->management, es1); + break; + case SVC_FUNCTION_HOTPLUG: + svc_hotplug(&svc_msg->hotplug, es1); + break; + case SVC_FUNCTION_DDB: + svc_ddb(&svc_msg->ddb, es1); + break; + case SVC_FUNCTION_POWER: + svc_power(&svc_msg->power, es1); + break; + case SVC_FUNCTION_EPM: + svc_epm(&svc_msg->epm, es1); + break; + case SVC_FUNCTION_SUSPEND: + svc_suspend(&svc_msg->suspend, es1); + break; + default: + dev_err(&es1->usb_intf->dev, "received invalid SVC message type %d\n", + svc_msg->header.type); + } } -- 2.39.5