From ad798d2aca153c0315d1808fdcea8bb6a0127af6 Mon Sep 17 00:00:00 2001 From: Tzafrir Cohen Date: Wed, 13 May 2009 20:18:20 +0000 Subject: astribank_tool: Support 'reset' of pre-MPP protocol as fallback As of USB firmware rev. 6926, the Astribank control connection protocol has changed in an incompatible manner. If astribank_tool fails to open a device when running a reset command, try to reset the device with the command from the old (pre-MPP) protocol (A single 0x20 byte). No support whatsoever for any other feature of the old protocol. From xpp rev. 7067. (previous commit was xpp rev. 7066). git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/trunk@6617 a0bf4364-ded3-4de4-8d8a-66a801d63aff --- xpp/astribank_tool.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ xpp/mpp_funcs.c | 9 +++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/xpp/astribank_tool.c b/xpp/astribank_tool.c index d5ba667..b9bcaaa 100644 --- a/xpp/astribank_tool.c +++ b/xpp/astribank_tool.c @@ -31,6 +31,11 @@ #include "debug.h" #define DBG_MASK 0x80 +/* if enabled, adds support for resetting pre-MPP USB firmware - if we + * failed opening a device and we were asked to reset it, try also the + * old protocol. + */ +#define SUPPORT_OLD_RESET static char *progname; @@ -106,6 +111,36 @@ static int show_hardware(struct astribank_device *astribank) return 0; } +#ifdef SUPPORT_OLD_RESET +/* Try to reset a device using USB_FW.hex, up to Xorcom rev. 6885 */ +int old_reset(const char* devpath) +{ + struct astribank_device *astribank; + int ret; + struct { + uint8_t op; + } PACKED header = {0x20}; /* PT_RESET */ + char *buf = (char*) &header; + + /* Note that the function re-opens the connection to the Astribank + * as any reference to the previous connection was lost when mpp_open + * returned NULL as the astribank reference. */ + astribank = astribank_open(devpath, 1); + if (!astribank) { + DBG("Failed re-opening astribank device for old_reset\n"); + return -ENODEV; + } + ret = send_usb(astribank, buf, 1, 5000); + + /* If we just had a reenumeration, we may get -ENODEV */ + if(ret < 0 && ret != -ENODEV) + return ret; + /* We don't astribank_close(), as it has likely been + * reenumerated by now. */ + return 0; +} +#endif /* SUPPORT_OLD_RESET */ + int main(int argc, char *argv[]) { char *devpath = NULL; @@ -164,6 +199,16 @@ int main(int argc, char *argv[]) DBG("Startup %s\n", devpath); if((astribank = mpp_init(devpath)) == NULL) { ERR("Failed initializing MPP\n"); +#ifdef SUPPORT_OLD_RESET + INFO("opt_reset = %s\n", opt_reset); + if (opt_reset) { + INFO("Trying old reset method\n"); + if ((ret = old_reset(devpath)) != 0) { + ERR("Old reset method failed as well: %d\n", ret); + } + } +#endif /* SUPPORT_OLD_RESET */ + return 1; } show_hardware(astribank); diff --git a/xpp/mpp_funcs.c b/xpp/mpp_funcs.c index 61868db..c52397f 100644 --- a/xpp/mpp_funcs.c +++ b/xpp/mpp_funcs.c @@ -928,14 +928,19 @@ struct astribank_device *mpp_init(const char devpath[]) ret = mpp_proto_query(astribank); if(ret < 0) { ERR("Protocol handshake failed: %d\n", ret); - return NULL; + goto err; } ret = mpp_status_query(astribank); if(ret < 0) { ERR("Status query failed: %d\n", ret); - return NULL; + goto err; } return astribank; + +err: + if (astribank) + astribank_close(astribank, 0); + return NULL; } void mpp_exit(struct astribank_device *astribank) -- cgit v1.2.3