functionfs: fix cport helper debug message printf conversions

%ld is used where %zu should have been used for the cport
read/write helpers debug output that handles size_t value.
Fix that.

Signed-off-by: Matt Porter <mporter@linaro.org>
functionfs: give up and free memory if cport_read() fails

Currently we try repeatedly if a read of the cport fifo fails. Adjust
this behavior to simply free buffer memory and kill the thread.

Signed-off-by: Matt Porter <mporter@linaro.org>
main: cleanup: fix ordering by tearing down the gadget, then functionfs

When we exit gbsim, we currently tear down the functionfs pipes before
disabling the gadget. This is very bad as the gadget is still enabled
with no backing i/o. Correct this by tearing down the gadget first so
it disables and cause a disconnect on the host side.

Signed-off-by: Matt Porter <mporter@linaro.org>
gadget: fix gadget teardown order

Currently we are tearing down the functionfs backend before
we disable the gadget device itself. Fix this by disabling
the gadget, then tearing down the backing I/O.

Signed-off-by: Matt Porter <mporter@linaro.org>
gadget: clean up status message

Message was a bit redundant, fix that.

Signed-off-by: Matt Porter <mporter@linaro.org>
cport: refactor cport handling and add initial i2c support

Refactor the stubbed out cport handling to allows for multiple
protocol handlers. For now, the i2c_handler is called because we
don't yet track which cport is registered to handle a protocol.
Implement the i2c handler such that writes are consumed with
a success response and displayed and reads return an incrementing
byte stream to assist in verification.

Signed-off-by: Matt Porter <mporter@linaro.org>
Merge branch 'master' of ssh://github.com/ohporter/gbsim

Conflicts:
	functionfs.c

Signed-off-by: Matt Porter <mporter@linaro.org>
i2c op: refactor protocol version structure to be protocol independent

We will reuse the protocol version response struct everywhere so
remove i2c from the name.

Signed-off-by: Matt Porter <mporter@linaro.org>
cport: fix receive buffer leak

Forgot to free this receive buffer, fix that.

Signed-off-by: Matt Porter <mporter@linaro.org>
i2c: add beaglebone black backend support and cmdline options

Adds support to access an i2c adapter on the beaglebone black. It's
actually reasonably generic as it uses i2c-dev and a cmdline arg
allows selection of the i2c adapter that is accessed by gbsim.

Also add some cmdline arguments to control activation of the beaglebone
backend, i2c adapter to be used, hotplug base directory, and verbosity.

Signed-off-by: Matt Porter <mporter@linaro.org>
README: update docs to reflect latest dependencies and cmdline flags

With the introduction of the BeagleBone Black hardware backend we now
needed some cmdline flags and have an additional dependency on the
userpace i2c-dev interface. Document these.

Signed-off-by: Matt Porter <mporter@linaro.org>
functionfs: after handshake send the AP its assigned Device ID

The AP must know the Device ID that we assigned to it during
enumeration. After establishing the handshake, send the Device ID which
we hardcode to the loneliest number.

Signed-off-by: Matt Porter <mporter@linaro.org>
svc: add support for generating network link up events

Add basic support for generating a link up event after the
hotplug event has been sent. For now, we hardcoded the
interface and device ID. This needs reworked to parse
the manifest and assign a device ID per interface ID and
subject to the rules of address translation where we will
allocate additional device IDs for each range of 32 cports
above the first 32 cports handled by the first device ID.

Signed-off-by: Matt Porter <mporter@linaro.org>
svc: handle unipro network management set route message

Basic handling of set route messages. Simply check that we got the message and report the
Device ID to be routed.

This will soon change to actual management of a simulated switch route table. We'll use
this table to allow/disallow Cport connections to inserted modules.

Signed-off-by: Matt Porter <mporter@linaro.org>