[svn-commits] tzafrir: tools/trunk r10713 - /tools/trunk/xpp/xtalk/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Sep 20 08:43:44 CDT 2012


Author: tzafrir
Date: Thu Sep 20 08:43:41 2012
New Revision: 10713

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=10713
Log:
xtalk: checkpatch clean (almost)

Signed-off-by: Oron Peled <oron.peled at xorcom.com>
Acked-by: Tzafrir Cohen <tzafrir.cohen at xorcom.com>

Origin: Xorcom xtalk (r10638)

Modified:
    tools/trunk/xpp/xtalk/debug.c
    tools/trunk/xpp/xtalk/debug.h
    tools/trunk/xpp/xtalk/xlist.c
    tools/trunk/xpp/xtalk/xtalk.c
    tools/trunk/xpp/xtalk/xtalk.h
    tools/trunk/xpp/xtalk/xtalk_defs.h
    tools/trunk/xpp/xtalk/xusb.c
    tools/trunk/xpp/xtalk/xusb.h

Modified: tools/trunk/xpp/xtalk/debug.c
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/xtalk/debug.c?view=diff&rev=10713&r1=10712&r2=10713
==============================================================================
--- tools/trunk/xpp/xtalk/debug.c (original)
+++ tools/trunk/xpp/xtalk/debug.c Thu Sep 20 08:43:41 2012
@@ -30,43 +30,44 @@
 #include <debug.h>
 
 int	verbose = LOG_INFO;
-int	debug_mask = 0;
+int	debug_mask;
 
 void log_function(int level, int mask, const char *msg, ...)
 {
 	va_list ap;
 
 	va_start(ap, msg);
-	if(verbose >= level) {
-		if(level < LOG_DEBUG || (mask & debug_mask))
+	if (verbose >= level) {
+		if (level < LOG_DEBUG || (mask & debug_mask))
 			vfprintf(stderr, msg, ap);
 	}
 	va_end(ap);
 }
 
-void dump_packet(int loglevel, int mask, const char *msg, const char *buf, int len)
+void dump_packet(int loglevel, int mask, const char *msg,
+		const char *buf, int len)
 {
 	int	i;
 
-	if(!mask || (mask & debug_mask)) {
+	if (!mask || (mask & debug_mask)) {
 		log_function(loglevel, ~0, "%-15s:", msg);
-		for(i = 0; i < len; i++)
+		for (i = 0; i < len; i++)
 			log_function(loglevel, ~0, " %02X", (uint8_t)buf[i]);
 		log_function(loglevel, ~0, "\n");
 	}
 }
 
 /* from glibc info(1) */
-void print_backtrace (FILE *fp)
+void print_backtrace(FILE *fp)
 {
 	void	*array[10];
 	size_t	size;
 	char	**strings;
 	size_t	i;
 
-	size = backtrace (array, 10);
-	strings = backtrace_symbols (array, size);
+	size = backtrace(array, 10);
+	strings = backtrace_symbols(array, size);
 	for (i = 0; i < size; i++)
-		fprintf (fp, "%s\n", strings[i]);
-	free (strings);
+		fprintf(fp, "%s\n", strings[i]);
+	free(strings);
 }

Modified: tools/trunk/xpp/xtalk/debug.h
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/xtalk/debug.h?view=diff&rev=10713&r1=10712&r2=10713
==============================================================================
--- tools/trunk/xpp/xtalk/debug.h (original)
+++ tools/trunk/xpp/xtalk/debug.h Thu Sep 20 08:43:41 2012
@@ -35,15 +35,18 @@
 /*
  * Logging
  */
-void log_function(int level, int mask, const char *msg, ...) __attribute__(( format(printf, 3, 4) ));
+void log_function(int level, int mask, const char *msg, ...)
+		__attribute__((format(printf, 3, 4)));
 
-#define	ERR(fmt, arg...) log_function(LOG_ERR, 0, "%s:%d: ERROR(%s): " fmt, __FILE__, __LINE__, __FUNCTION__, ## arg)
+#define	ERR(fmt, arg...) log_function(LOG_ERR, 0, "%s:%d: ERROR(%s): " fmt, \
+		__FILE__, __LINE__, __func__, ## arg)
 #define	WARN(fmt, arg...) log_function(LOG_WARNING, 0, "WARNING: " fmt, ## arg)
 #define	INFO(fmt, arg...) log_function(LOG_INFO, 0, "INFO: " fmt, ## arg)
 #define	DBG(fmt, arg...) log_function(LOG_DEBUG, DBG_MASK,	\
-		"%s:%d: DBG(%s): " fmt, __FILE__, __LINE__, __FUNCTION__, ## arg)
+		"%s:%d: DBG(%s): " fmt, __FILE__, __LINE__, __func__, ## arg)
 
-void dump_packet(int loglevel, int mask, const char *msg, const char *buf, int len);
-void print_backtrace (FILE *fp);
+void dump_packet(int loglevel, int mask, const char *msg,
+		const char *buf, int len);
+void print_backtrace(FILE *fp);
 
 #endif	/* DEBUG_H */

Modified: tools/trunk/xpp/xtalk/xlist.c
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/xtalk/xlist.c?view=diff&rev=10713&r1=10712&r2=10713
==============================================================================
--- tools/trunk/xpp/xtalk/xlist.c (original)
+++ tools/trunk/xpp/xtalk/xlist.c Thu Sep 20 08:43:41 2012
@@ -7,7 +7,8 @@
 {
 	struct xlist_node	*list;
 
-	if((list = malloc(sizeof(*list))) == NULL)
+	list = malloc(sizeof(*list));
+	if (!list)
 		return NULL;
 	list->next = list;
 	list->prev = list;
@@ -20,12 +21,12 @@
 	struct xlist_node	*curr;
 	struct xlist_node	*next;
 
-	if (! list)
+	if (!list)
 		return;
 	curr = list->next;
-	while(curr != list) {
+	while (curr != list) {
 		next = curr->next;
-		if(destructor)
+		if (destructor)
 			destructor(curr->data);
 		memset(curr, 0, sizeof(*curr));
 		free(curr);
@@ -67,9 +68,9 @@
 {
 	struct xlist_node	*item;
 
-	if(!list)
+	if (!list)
 		return NULL;
-	if(xlist_empty(list))
+	if (xlist_empty(list))
 		return NULL;
 	item = list->next;
 	xlist_remove_item(item);
@@ -87,7 +88,7 @@
 	struct xlist_node	*curr;
 	size_t			count = 0;
 
-	for(curr = list->next; curr != list; curr = curr->next)
+	for (curr = list->next; curr != list; curr = curr->next)
 		count++;
 	return count;
 }

Modified: tools/trunk/xpp/xtalk/xtalk.c
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/xtalk/xtalk.c?view=diff&rev=10713&r1=10712&r2=10713
==============================================================================
--- tools/trunk/xpp/xtalk/xtalk.c (original)
+++ tools/trunk/xpp/xtalk/xtalk.c Thu Sep 20 08:43:41 2012
@@ -28,8 +28,6 @@
 #include <arpa/inet.h>
 #include <xtalk.h>
 #include <debug.h>
-
-static const char rcsid[] = "$Id$";
 
 #define	DBG_MASK	0x02
 
@@ -97,20 +95,21 @@
 
 void free_command(struct xtalk_command *cmd)
 {
-	if(!cmd)
+	if (!cmd)
 		return;
 	memset(cmd, 0, cmd->header.len);
 	free(cmd);
 }
 
-static const struct xtalk_command_desc *get_command_desc(const struct xtalk_protocol *xproto, uint8_t op)
+static const struct xtalk_command_desc *get_command_desc(
+		const struct xtalk_protocol *xproto, uint8_t op)
 {
 	const struct xtalk_command_desc	*desc;
 
-	if(!xproto)
+	if (!xproto)
 		return NULL;
 	desc = &xproto->commands[op];
-	if(!desc->name)
+	if (!desc->name)
 		return NULL;
 #if 0
 	DBG("%s version=%d, op=0x%X (%s)\n",
@@ -120,67 +119,74 @@
 	return desc;
 }
 
-static const char *ack_status_msg(const struct xtalk_protocol *xproto, uint8_t status)
+static const char *ack_status_msg(const struct xtalk_protocol *xproto,
+		uint8_t status)
 {
 	const char	*ack_status;
 
-	if(!xproto)
+	if (!xproto)
 		return NULL;
 	ack_status = xproto->ack_statuses[status];
 	DBG("%s status=0x%X (%s)\n", xproto->name, status, ack_status);
 	return ack_status;
 }
 
-int xtalk_set_protocol(struct xtalk_device *xtalk_dev, const struct xtalk_protocol *xproto)
+int xtalk_set_protocol(struct xtalk_device *xtalk_dev,
+		const struct xtalk_protocol *xproto)
 {
 	const char	*protoname = (xproto) ? xproto->name : "GLOBAL";
 	int		i;
 
 	DBG("%s\n", protoname);
 	memset(&xtalk_dev->xproto, 0, sizeof(xtalk_dev->xproto));
-	for(i = 0; i < MAX_OPS; i++) {
+	for (i = 0; i < MAX_OPS; i++) {
 		const struct xtalk_command_desc	*desc;
 
 		desc = get_command_desc(xproto, i);
-		if(desc) {
-			if(!IS_PRIVATE_OP(i)) {
-				ERR("Bad op=0x%X (should be in the range [0x%X-0x%X]\n",
+		if (desc) {
+			if (!IS_PRIVATE_OP(i)) {
+				ERR("Bad op=0x%X "
+					"(should be in the range [0x%X-0x%X]\n",
 					i, PRIVATE_OP_FIRST, PRIVATE_OP_LAST);
 				return -EINVAL;
 			}
 			xtalk_dev->xproto.commands[i] = *desc;
 			DBG("private: op=0x%X (%s)\n", i, desc->name);
 		} else {
-			if(!IS_PRIVATE_OP(i)) {
+			if (!IS_PRIVATE_OP(i)) {
 				const char	*name;
 
-				xtalk_dev->xproto.commands[i] = xtalk_base.commands[i];
+				xtalk_dev->xproto.commands[i] =
+					xtalk_base.commands[i];
 				name = xtalk_dev->xproto.commands[i].name;
-				if(name)
+				if (name)
 					DBG("global: op=0x%X (%s)\n", i, name);
 			}
 		}
 	}
-	for(i = 0; i < MAX_STATUS; i++) {
+	for (i = 0; i < MAX_STATUS; i++) {
 		const char	*stat_msg;
 
 		stat_msg = (xproto) ? xproto->ack_statuses[i] : NULL;
-		if(stat_msg) {
-			if(!IS_PRIVATE_OP(i)) {
-				ERR("Bad status=0x%X (should be in the range [0x%X-0x%X]\n",
+		if (stat_msg) {
+			if (!IS_PRIVATE_OP(i)) {
+				ERR("Bad status=0x%X "
+					"(should be in the range [0x%X-0x%X]\n",
 					i, PRIVATE_OP_FIRST, PRIVATE_OP_LAST);
 				return -EINVAL;
 			}
 			xtalk_dev->xproto.ack_statuses[i] = stat_msg;
 			DBG("private: status=0x%X (%s)\n", i, stat_msg);
 		} else {
-			if(!IS_PRIVATE_OP(i)) {
+			if (!IS_PRIVATE_OP(i)) {
 				const char	*stat_msg;
 
-				xtalk_dev->xproto.ack_statuses[i] = xtalk_base.ack_statuses[i];
+				xtalk_dev->xproto.ack_statuses[i] =
+					xtalk_base.ack_statuses[i];
 				stat_msg = xtalk_dev->xproto.ack_statuses[i];
-				if(stat_msg)
-					DBG("global: status=0x%X (%s)\n", i, stat_msg);
+				if (stat_msg)
+					DBG("global: status=0x%X (%s)\n",
+						i, stat_msg);
 			}
 		}
 	}
@@ -200,17 +206,18 @@
 
 	xproto = &xtalk_dev->xproto;
 	desc = get_command_desc(xproto, op);
-	if(!desc) {
+	if (!desc) {
 		ERR("Unknown op=0x%X.\n", op);
 		return NULL;
 	}
 	DBG("OP=0x%X [%s] (extra_data %d)\n", op, desc->name, extra_data);
 	len = desc->len + extra_data;
-	if((cmd = malloc(len)) == NULL) {
+	cmd = malloc(len);
+	if (!cmd) {
 		ERR("Out of memory\n");
 		return NULL;
 	}
-	if(extra_data) {
+	if (extra_data) {
 		uint8_t	*ptr = (uint8_t *)cmd;
 
 		DBG("clear extra_data (%d bytes)\n", extra_data);
@@ -228,18 +235,18 @@
 	int		i;
 
 	len = cmd->header.len;
-	if(len < sizeof(struct xtalk_header)) {
+	if (len < sizeof(struct xtalk_header)) {
 		ERR("Command too short (%d)\n", len);
 		return;
 	}
 	INFO("DUMP: OP=0x%X len=%d seq=%d\n",
 		cmd->header.op, cmd->header.len, cmd->header.seq);
-	for(i = 0; i < len - sizeof(struct xtalk_header); i++) {
+	for (i = 0; i < len - sizeof(struct xtalk_header); i++)
 		INFO("  %2d. 0x%X\n", i, cmd->alt.raw_data[i]);
-	}
-}
-
-static int send_command(struct xtalk_device *xtalk_dev, struct xtalk_command *cmd, int timeout)
+}
+
+static int send_command(struct xtalk_device *xtalk_dev,
+		struct xtalk_command *cmd, int timeout)
 {
 	int		ret;
 	int		len;
@@ -248,58 +255,46 @@
 	len = cmd->header.len;
 	cmd->header.seq = xtalk_dev->tx_sequenceno;
 
-	//printf("%s: len=%d\n", __FUNCTION__, len);
-#if 0
-	extern	FILE	*fp;
-	char		*buf;
-
-	buf = (char *)cmd;
-	if(fp) {
-		int	i;
-
-		fprintf(fp, "%05d:", cmd->header.seq);
-		for(i = 0; i < len; i++)
-			fprintf(fp, " %02X", (uint8_t)buf[i]);
-		fprintf(fp, "\n");
-	}
-#endif
 	ret = xtalk_dev->ops.send_func(priv, (char *)cmd, len, timeout);
-	if(ret < 0) {
+	if (ret < 0)
 		DBG("send_func failed ret=%d\n", ret);
-	}
 	xtalk_dev->tx_sequenceno++;
 	return ret;
 }
 
-static struct xtalk_command *recv_command(struct xtalk_device *xtalk_dev, int timeout)
+static struct xtalk_command *recv_command(struct xtalk_device *xtalk_dev,
+		int timeout)
 {
 	struct xtalk_command	*reply;
 	void			*priv = xtalk_dev->transport_priv;
+	size_t			psize = xtalk_dev->packet_size;
 	int			ret;
 
-	if((reply = malloc(xtalk_dev->packet_size)) == NULL) {
+	reply = malloc(psize);
+	if (!reply) {
 		ERR("Out of memory\n");
 		goto err;
 	}
 	reply->header.len = 0;
-	ret = xtalk_dev->ops.recv_func(priv, (char *)reply, xtalk_dev->packet_size, timeout);
-	if(ret < 0) {
+	ret = xtalk_dev->ops.recv_func(priv, (char *)reply, psize, timeout);
+	if (ret < 0) {
 		ERR("Receive from usb failed.\n");
 		goto err;
-	} else if(ret == 0) {
+	} else if (ret == 0) {
 		goto err;	/* No reply */
 	}
-	if(ret != reply->header.len) {
-		ERR("Wrong length received: got %d bytes, but length field says %d bytes%s\n",
-				ret, reply->header.len,
-				(ret == 1)? ". Old USB firmware?": "");
+	if (ret != reply->header.len) {
+		ERR("Wrong length received: got %d bytes, "
+			"but length field says %d bytes%s\n",
+			ret, reply->header.len,
+			(ret == 1) ? ". Old USB firmware?" : "");
 		goto err;
 	}
-	//dump_packet(LOG_DEBUG, DBG_MASK, __FUNCTION__, (char *)reply, ret);
+	/* dump_packet(LOG_DEBUG, DBG_MASK, __func__, (char *)reply, ret); */
 	return reply;
 err:
-	if(reply) {
-		memset(reply, 0, xtalk_dev->packet_size);
+	if (reply) {
+		memset(reply, 0, psize);
 		free_command(reply);
 	}
 	return NULL;
@@ -323,78 +318,76 @@
 
 	xproto = &xtalk_dev->xproto;
 	protoname = (xproto) ? xproto->name : "GLOBAL";
-	if(reply_ref)
-		*reply_ref = NULL;	/* So the caller knows if a reply was received */
+	/* So the caller knows if a reply was received */
+	if (reply_ref)
+		*reply_ref = NULL;
 	reply_op = cmd->header.op | XTALK_REPLY_MASK;
 	cmd_desc = get_command_desc(xproto, cmd->header.op);
 	expected = get_command_desc(xproto, reply_op);
-	//printf("%s: len=%d\n", __FUNCTION__, cmd->header.len);
 	ret = send_command(xtalk_dev, cmd, TIMEOUT);
-	if(!reply_ref) {
+	if (!reply_ref) {
 		DBG("No reply requested\n");
 		goto out;
 	}
-	if(ret < 0) {
+	if (ret < 0) {
 		ERR("send_command failed: %d\n", ret);
 		goto out;
 	}
 	reply = recv_command(xtalk_dev, TIMEOUT);
-	if(!reply) {
+	if (!reply) {
 		ERR("recv_command failed\n");
 		ret = -EPROTO;
 		goto out;
 	}
 	*reply_ref = reply;
-	if((reply->header.op & 0x80) != 0x80) {
-		ERR("Unexpected reply op=0x%02X, should have MSB set.\n", reply->header.op);
+	if ((reply->header.op & 0x80) != 0x80) {
+		ERR("Unexpected reply op=0x%02X, should have MSB set.\n",
+			reply->header.op);
 		ret = -EPROTO;
 		goto out;
 	}
 	DBG("REPLY OP: 0x%X\n", reply->header.op);
 	reply_desc = get_command_desc(xproto, reply->header.op);
-	if(!reply_desc) {
-		ERR("Unknown reply (proto=%s) op=0x%02X\n", protoname, reply->header.op);
+	if (!reply_desc) {
+		ERR("Unknown reply (proto=%s) op=0x%02X\n",
+			protoname, reply->header.op);
 		ret = -EPROTO;
 		goto out;
 	}
 	DBG("REPLY NAME: %s\n", reply_desc->name);
-	if(reply->header.op == XTALK_ACK) {
+	if (reply->header.op == XTALK_ACK) {
 		int	status = CMD_FIELD(reply, XTALK, ACK, stat);
 
-		if(expected) {
+		if (expected) {
 			ERR("Expected OP=0x%02X: Got ACK(%d): %s\n",
-				reply_op, status, ack_status_msg(xproto, status));
+				reply_op,
+				status,
+				ack_status_msg(xproto, status));
 			ret = -EPROTO;
 			goto out;
-		} else if(status != STAT_OK) {
+		} else if (status != STAT_OK) {
 
 			ERR("Got ACK (for OP=0x%X [%s]): %d %s\n",
 				cmd->header.op,
 				cmd_desc->name,
 				status, ack_status_msg(xproto, status));
-#if 0
-			extern	FILE	*fp;
-			if(fp) {
-				fprintf(fp, "Got ACK(%d)\n", status);
-			}
-#endif
 			ret = -EPROTO;
 			goto out;
 		}
 		/* Good expected ACK ... */
-	} else if(reply->header.op != reply_op) {
+	} else if (reply->header.op != reply_op) {
 			ERR("Expected OP=0x%02X: Got OP=0x%02X\n",
 				reply_op, reply->header.op);
 			ret = -EPROTO;
 			goto out;
 	}
-	if(expected && expected->len > reply->header.len) {
+	if (expected && expected->len > reply->header.len) {
 			ERR("Expected len=%d: Got len=%d\n",
 				expected->len, reply->header.len);
 			ret = -EPROTO;
 			goto out;
 	}
-	if(cmd->header.seq != reply->header.seq) {
+	if (cmd->header.seq != reply->header.seq) {
 			ERR("Expected seq=%d: Got seq=%d\n",
 				cmd->header.seq, reply->header.seq);
 			ret = -EPROTO;
@@ -404,7 +397,7 @@
 	DBG("returning reply op 0x%X (%d bytes)\n", reply->header.op, ret);
 out:
 	free_command(cmd);
-	if(!reply_ref && reply)
+	if (!reply_ref && reply)
 		free_command(reply);
 	return ret;
 }
@@ -423,18 +416,21 @@
 	DBG("\n");
 	assert(xtalk_dev != NULL);
 	proto_version = xtalk_dev->xproto.proto_version;
-	if((cmd = new_command(xtalk_dev, XTALK_PROTO_GET, 0)) == NULL) {
+	cmd = new_command(xtalk_dev, XTALK_PROTO_GET, 0);
+	if (!cmd) {
 		ERR("new_command failed\n");
 		return -ENOMEM;
 	}
-	CMD_FIELD(cmd, XTALK, PROTO_GET, proto_version) = proto_version;	/* Protocol Version */
+	/* Protocol Version */
+	CMD_FIELD(cmd, XTALK, PROTO_GET, proto_version) = proto_version;
 	ret = process_command(xtalk_dev, cmd, &reply);
-	if(ret < 0) {
+	if (ret < 0) {
 		ERR("process_command failed: %d\n", ret);
 		goto out;
 	}
-	xtalk_dev->xtalk_proto_version = CMD_FIELD(reply, XTALK, PROTO_GET_REPLY, proto_version);
-	if(xtalk_dev->xtalk_proto_version != proto_version) {
+	xtalk_dev->xtalk_proto_version =
+		CMD_FIELD(reply, XTALK, PROTO_GET_REPLY, proto_version);
+	if (xtalk_dev->xtalk_proto_version != proto_version) {
 		DBG("Got %s protocol version: 0x%02x (expected 0x%02x)\n",
 			xtalk_dev->xproto.name,
 			xtalk_dev->xtalk_proto_version,
@@ -453,24 +449,27 @@
  * Wrappers
  */
 
-struct xtalk_device *xtalk_new(const struct xtalk_ops *ops, size_t packet_size, void *priv)
+struct xtalk_device *xtalk_new(const struct xtalk_ops *ops,
+	size_t packet_size, void *priv)
 {
 	struct xtalk_device	*xtalk_dev;
 	int			ret;
 
 	DBG("\n");
 	assert(ops != NULL);
-	if((xtalk_dev = malloc(sizeof(*xtalk_dev))) == NULL) {
+	xtalk_dev = malloc(sizeof(*xtalk_dev));
+	if (!xtalk_dev) {
 		ERR("Allocating XTALK device memory failed\n");
 		return NULL;
 	}
 	memset(xtalk_dev, 0, sizeof(*xtalk_dev));
-	memcpy((void *)&xtalk_dev->ops, (const void *)ops, sizeof(xtalk_dev->ops));
+	memcpy((void *)&xtalk_dev->ops, (const void *)ops,
+		sizeof(xtalk_dev->ops));
 	xtalk_dev->transport_priv = priv;
 	xtalk_dev->packet_size = packet_size;
 	xtalk_dev->tx_sequenceno = 1;
 	ret = xtalk_set_protocol(xtalk_dev, NULL);
-	if(ret < 0) {
+	if (ret < 0) {
 		ERR("GLOBAL Protocol registration failed: %d\n", ret);
 		goto err;
 	}
@@ -486,7 +485,7 @@
 {
 	void	*priv;
 
-	if(!xtalk_dev)
+	if (!xtalk_dev)
 		return;
 	DBG("\n");
 	priv = xtalk_dev->transport_priv;

Modified: tools/trunk/xpp/xtalk/xtalk.h
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/xtalk/xtalk.h?view=diff&rev=10713&r1=10712&r2=10713
==============================================================================
--- tools/trunk/xpp/xtalk/xtalk.h (original)
+++ tools/trunk/xpp/xtalk/xtalk.h Thu Sep 20 08:43:41 2012
@@ -93,9 +93,11 @@
  *   cmd	- A pointer to struct xtalk_command
  *   field	- field name (e.g: raw_data)
  */
-#define XTALK_STRUCT(p,o)	p ## _struct_ ## o
+#define XTALK_STRUCT(p, o)	p ## _struct_ ## o
 #define XTALK_PDATA(o)		xtalk_privdata_ ## o
-#define	CMD_FIELD(cmd, p, o, field)	(((union XTALK_PDATA(p) *)&((cmd)->alt))->XTALK_STRUCT(p, o).field)
+#define	XTALK_CMD_PTR(cmd, p)	((union XTALK_PDATA(p)*)&((cmd)->alt))
+#define	CMD_FIELD(cmd, p, o, field) \
+		(XTALK_CMD_PTR(cmd, p)->XTALK_STRUCT(p, o).field)
 #define CMD_DEF(p, o, ...)	struct XTALK_STRUCT(p, o) {	\
 					__VA_ARGS__		\
 				} PACKED XTALK_STRUCT(p, o)
@@ -103,8 +105,10 @@
 
 /* Wrappers for transport (xusb) functions */
 struct xtalk_ops {
-	int	(*send_func)(void *transport_priv, void *data, size_t len, int timeout);
-	int	(*recv_func)(void *transport_priv, void *data, size_t maxlen, int timeout);
+	int	(*send_func)(void *transport_priv, void *data, size_t len,
+			int timeout);
+	int	(*recv_func)(void *transport_priv, void *data, size_t maxlen,
+			int timeout);
 	int	(*close_func)(void *transport_priv);
 };
 
@@ -116,9 +120,11 @@
 struct xtalk_device;
 
 /* high-level */
-struct xtalk_device *xtalk_new(const struct xtalk_ops *ops, size_t packet_size, void *transport_priv);
+struct xtalk_device *xtalk_new(const struct xtalk_ops *ops,
+		size_t packet_size, void *transport_priv);
 void xtalk_delete(struct xtalk_device *dev);
-int xtalk_set_protocol(struct xtalk_device *xtalk_dev, const struct xtalk_protocol *xproto);
+int xtalk_set_protocol(struct xtalk_device *xtalk_dev,
+		const struct xtalk_protocol *xproto);
 int xtalk_proto_query(struct xtalk_device *dev);
 void xtalk_dump_command(struct xtalk_command *cmd);
 
@@ -138,24 +144,24 @@
  *   o		- signify command op (e.g: ACK)
  *   cb		- A callback function (type xtalk_cmd_callback_t)
  */
-#define	CMD_RECV(p,o,cb)	\
-	[p ## _ ## o | XTALK_REPLY_MASK] {		\
-		.op = p ## _ ## o | XTALK_REPLY_MASK,	\
-		.name = #o "_reply",			\
-		.callback = (cb), 			\
+#define	CMD_RECV(p, o, cb)	\
+	[p ## _ ## o | XTALK_REPLY_MASK] = {		\
+		.op = (p ## _ ## o) | XTALK_REPLY_MASK,	\
+		.name = (#o "_reply"),			\
+		.callback = (cb),			\
 		.len =					\
 			sizeof(struct xtalk_header) +	\
-			sizeof(struct XTALK_STRUCT(p,o)),	\
+			sizeof(struct XTALK_STRUCT(p, o)),	\
 	}
 
-#define	CMD_SEND(p,o)	\
-	[p ## _ ## o] {		\
-		.op = p ## _ ## o,	\
-		.name = #o,		\
-		.callback = NULL, 	\
+#define	CMD_SEND(p, o)	\
+	[p ## _ ## o] = {		\
+		.op = (p ## _ ## o),	\
+		.name = (#o),		\
+		.callback = NULL,	\
 		.len =					\
 			sizeof(struct xtalk_header) +	\
-			sizeof(struct XTALK_STRUCT(p,o)),	\
+			sizeof(struct XTALK_STRUCT(p, o)),	\
 	}
 
 /*
@@ -163,7 +169,7 @@
  *   x		- status code (e.g: OK)
  *   m		- status message (const char *)
  */
-#define	ACK_STAT(x,m)	[ STAT_ ## x ] = (m)
+#define	ACK_STAT(x, m)	[STAT_ ## x] = (m)
 
 #ifdef __cplusplus
 }

Modified: tools/trunk/xpp/xtalk/xtalk_defs.h
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/xtalk/xtalk_defs.h?view=diff&rev=10713&r1=10712&r2=10713
==============================================================================
--- tools/trunk/xpp/xtalk/xtalk_defs.h (original)
+++ tools/trunk/xpp/xtalk/xtalk_defs.h Thu Sep 20 08:43:41 2012
@@ -8,17 +8,18 @@
 
 #define	PRIVATE_OP_FIRST	0x05
 #define	PRIVATE_OP_LAST		0x7F
-#define	IS_PRIVATE_OP(x)	(	\
-					(((x) & ~(XTALK_REPLY_MASK)) >= PRIVATE_OP_FIRST) &&	\
-					(((x) & ~(XTALK_REPLY_MASK)) <= PRIVATE_OP_LAST)	\
-				)
+#define	IS_PRIVATE_OP(x)	( \
+		(((x) & ~(XTALK_REPLY_MASK)) >= PRIVATE_OP_FIRST) &&	\
+		(((x) & ~(XTALK_REPLY_MASK)) <= PRIVATE_OP_LAST)	\
+	)
 
 #define	XTALK_ACK		0x80
 #define	XTALK_PROTO_GET		0x01
 #define	XTALK_PROTO_GET_REPLY	(XTALK_PROTO_GET | XTALK_REPLY_MASK)
 #define	XTALK_FWVERS_GET	0x11
 #define	XTALK_FWVERS_GET_REPLY	(XTALK_FWVERS_GET | XTALK_REPLY_MASK)
-#define XTALK_CAPS_GET		0x0E	/* Get EEPROM table contents Product/Vendor Id ... */
+/* Get EEPROM table contents Product/Vendor Id ... */
+#define XTALK_CAPS_GET		0x0E
 #define XTALK_CAPS_GET_REPLY	(XTALK_CAPS_GET | XTALK_REPLY_MASK)
 
 /*------------- XTALK: statuses in ACK ---------------------------------------*/

Modified: tools/trunk/xpp/xtalk/xusb.c
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/xtalk/xusb.c?view=diff&rev=10713&r1=10712&r2=10713
==============================================================================
--- tools/trunk/xpp/xtalk/xusb.c (original)
+++ tools/trunk/xpp/xtalk/xusb.c Thu Sep 20 08:43:41 2012
@@ -35,8 +35,6 @@
 #include <sys/ipc.h>
 #include <sys/sem.h>
 
-static const char rcsid[] = "$Id$";
-
 #define	DBG_MASK	0x01
 #define	TIMEOUT	500
 #define	MAX_RETRIES	10
@@ -67,8 +65,9 @@
 		uint16_t vendor_id, uint16_t product_id,
 		int nifaces, int iface, int nep, int ep_out, int ep_in)
 {
-	DBG("Initialize %s: interfaces=%d using interface num=%d endpoints=%d (OUT=0x%02X, IN=0x%02X)\n",
-			name, nifaces, iface, nep, ep_out, ep_in);
+	DBG("Initialize %s: interfaces=%d using interface num=%d endpoints=%d "
+		"(OUT=0x%02X, IN=0x%02X)\n",
+		name, nifaces, iface, nep, ep_out, ep_in);
 	memset(spec, 0, sizeof(*spec));
 	spec->name = name;
 	spec->num_interfaces = nifaces;
@@ -87,7 +86,7 @@
  * USB handling
  */
 
-static int get_usb_string(struct xusb *xusb, uint8_t item, char *buf, unsigned int len)
+static int get_usb_string(struct xusb *xusb, uint8_t item, char *buf)
 {
 	char	tmp[BUFSIZ];
 	int	ret;
@@ -98,10 +97,13 @@
 	ret = usb_get_string_simple(xusb->handle, item, tmp, BUFSIZ);
 	if (ret <= 0)
 		return ret;
-	return snprintf(buf, len, "%s", tmp);
-}
-
-static const struct usb_interface_descriptor *get_interface(const struct usb_device *dev, int my_interface_num, int num_interfaces)
+	return snprintf(buf, BUFSIZ, "%s", tmp);
+}
+
+static const struct usb_interface_descriptor *get_interface(
+		const struct usb_device *dev,
+		int my_interface_num,
+		int num_interfaces)
 {
 	const struct usb_interface		*interface;
 	const struct usb_interface_descriptor	*iface_desc;
@@ -113,7 +115,7 @@
 		ERR("No configuration descriptor: strange USB1 controller?\n");
 		return NULL;
 	}
-	if(num_interfaces && config_desc->bNumInterfaces != num_interfaces) {
+	if (num_interfaces && config_desc->bNumInterfaces != num_interfaces) {
 		DBG("Wrong number of interfaces: have %d need %d\n",
 			config_desc->bNumInterfaces, num_interfaces);
 		return NULL;
@@ -127,49 +129,57 @@
 	return iface_desc;
 }
 
-static int match_interface(const struct usb_device *dev, const struct xusb_spec *spec)
+static int match_interface(const struct usb_device *dev,
+		const struct xusb_spec *spec)
 {
 	const struct usb_device_descriptor	*dev_desc;
 	const struct usb_interface_descriptor	*iface_desc;
 
-	//debug_mask = 0xFF;
-	//verbose = 1;
 	dev_desc = &dev->descriptor;
 	assert(dev_desc);
-	DBG("Checking: %04X:%04X interfaces=%d interface num=%d endpoints=%d: \"%s\"\n",
+	DBG("Checking: %04X:%04X interfaces=%d interface num=%d endpoints=%d: "
+			"\"%s\"\n",
 			spec->my_vendor_id,
 			spec->my_product_id,
 			spec->num_interfaces,
 			spec->my_interface_num,
 			spec->num_endpoints,
 			spec->name);
-	if(dev_desc->idVendor != spec->my_vendor_id) {
+	if (dev_desc->idVendor != spec->my_vendor_id) {
 		DBG("Wrong vendor id 0x%X\n", dev_desc->idVendor);
 		return 0;
 	}
-	if(dev_desc->idProduct != spec->my_product_id) {
+	if (dev_desc->idProduct != spec->my_product_id) {
 		DBG("Wrong product id 0x%X\n", dev_desc->idProduct);
 		return 0;
 	}
-	if((iface_desc = get_interface(dev, spec->my_interface_num, spec->num_interfaces)) == NULL) {
-		ERR("Could not get interface descriptor of device: %s\n", usb_strerror());
-		return 0;
-	}
-	if(iface_desc->bInterfaceClass != 0xFF) {
-		DBG("Wrong interface class 0x%X\n", iface_desc->bInterfaceClass);
-		return 0;
-	}
-	if(iface_desc->bInterfaceNumber != spec->my_interface_num) {
+	iface_desc = get_interface(dev, spec->my_interface_num,
+				spec->num_interfaces);
+	if (!iface_desc) {
+		ERR("Could not get interface descriptor of device: %s\n",
+			usb_strerror());
+		return 0;
+	}
+	if (iface_desc->bInterfaceClass != 0xFF) {
+		DBG("Wrong interface class 0x%X\n",
+			iface_desc->bInterfaceClass);
+		return 0;
+	}
+	if (iface_desc->bInterfaceNumber != spec->my_interface_num) {
 		DBG("Wrong interface number %d (expected %d)\n",
 			iface_desc->bInterfaceNumber, spec->my_interface_num);
 		return 0;
 	}
-	if(iface_desc->bNumEndpoints != spec->num_endpoints) {
-		DBG("Wrong number of endpoints %d\n", iface_desc->bNumEndpoints);
+	if (iface_desc->bNumEndpoints != spec->num_endpoints) {
+		DBG("Wrong number of endpoints %d\n",
+			iface_desc->bNumEndpoints);
 		return 0;
 	}
 	return	1;
 }
+
+#define	GET_USB_STRING(xusb, from, item) \
+		get_usb_string((xusb), (from)->item, xusb->item)
 
 static int xusb_fill_strings(struct xusb *xusb)
 {
@@ -179,23 +189,28 @@
 
 	dev_desc = &xusb->dev->descriptor;
 	assert(dev_desc);
-	if(get_usb_string(xusb, dev_desc->iManufacturer, xusb->iManufacturer, BUFSIZ) < 0) {
-		ERR("Failed reading iManufacturer string: %s\n", usb_strerror());
-		return 0;
-	}
-	if(get_usb_string(xusb, dev_desc->iProduct, xusb->iProduct, BUFSIZ) < 0) {
-		ERR("Failed reading iProduct string: %s\n", usb_strerror());
-		return 0;
-	}
-	if(get_usb_string(xusb, dev_desc->iSerialNumber, xusb->iSerialNumber, BUFSIZ) < 0) {
-		ERR("Failed reading iSerialNumber string: %s\n", usb_strerror());
-		return 0;
-	}
-	if((iface_desc = get_interface(xusb->dev, xusb->interface_num, 0)) == NULL) {
-		ERR("Could not get interface descriptor of device: %s\n", usb_strerror());
-		return 0;
-	}
-	if(get_usb_string(xusb, iface_desc->iInterface, xusb->iInterface, BUFSIZ) < 0) {
+	if (GET_USB_STRING(xusb, dev_desc, iManufacturer) < 0) {
+		ERR("Failed reading iManufacturer string: %s\n",
+			usb_strerror());
+		return 0;
+	}
+	if (GET_USB_STRING(xusb, dev_desc, iProduct) < 0) {
+		ERR("Failed reading iProduct string: %s\n",
+			usb_strerror());
+		return 0;
+	}
+	if (GET_USB_STRING(xusb, dev_desc, iSerialNumber) < 0) {
+		ERR("Failed reading iSerialNumber string: %s\n",
+			usb_strerror());
+		return 0;
+	}
+	iface_desc = get_interface(xusb->dev, xusb->interface_num, 0);
+	if (!iface_desc) {
+		ERR("Could not get interface descriptor of device: %s\n",
+			usb_strerror());
+		return 0;
+	}
+	if (GET_USB_STRING(xusb, iface_desc, iInterface) < 0) {
 		ERR("Failed reading iInterface string: %s\n", usb_strerror());
 		return 0;
 	}
@@ -207,7 +222,8 @@
 	assert(xusb);
 	if (xusb->is_open)
 		return 1;
-	if((xusb->handle = usb_open(xusb->dev)) == NULL) {
+	xusb->handle = usb_open(xusb->dev);
+	if (!xusb->handle) {
 		ERR("Failed to open usb device '%s': %s\n",
 			xusb->devpath_tail, usb_strerror());
 		return 0;
@@ -223,30 +239,34 @@
 
 	assert(xusb);
 	xusb_open(xusb);	/* If it's not open yet... */
-	if(usb_claim_interface(xusb->handle, xusb->interface_num) != 0) {
+	if (usb_claim_interface(xusb->handle, xusb->interface_num) != 0) {
 		ERR("usb_claim_interface %d in '%s': %s\n",
-			xusb->interface_num, xusb->devpath_tail, usb_strerror());
+			xusb->interface_num,
+			xusb->devpath_tail,
+			usb_strerror());
 		return 0;
 	}
 	xusb->is_claimed = 1;
 	xusb_fill_strings(xusb);
 	dev_desc = &xusb->dev->descriptor;
-	DBG("ID=%04X:%04X Manufacturer=[%s] Product=[%s] SerialNumber=[%s] Interface=[%s]\n",
+	DBG("ID=%04X:%04X Manufacturer=[%s] Product=[%s] "
+		"SerialNumber=[%s] Interface=[%s]\n",
 		dev_desc->idVendor,
 		dev_desc->idProduct,
 		xusb->iManufacturer,
 		xusb->iProduct,
 		xusb->iSerialNumber,
 		xusb->iInterface);
-	if(usb_clear_halt(xusb->handle, EP_OUT(xusb)) != 0) {
+	if (usb_clear_halt(xusb->handle, EP_OUT(xusb)) != 0) {
 		ERR("Clearing output endpoint: %s\n", usb_strerror());
 		return 0;
 	}
-	if(usb_clear_halt(xusb->handle, EP_IN(xusb)) != 0) {
+	if (usb_clear_halt(xusb->handle, EP_IN(xusb)) != 0) {
 		ERR("Clearing input endpoint: %s\n", usb_strerror());
 		return 0;
 	}
-	if((ret = xusb_flushread(xusb)) < 0) {
+	ret = xusb_flushread(xusb);
+	if (ret < 0) {
 		ERR("xusb_flushread failed: %d\n", ret);
 		return 0;
 	}
@@ -258,7 +278,7 @@
 	struct xlist_node	*curr;
 	struct xusb		*xusb;
 
-	for(curr = xusb_list->next; curr != xusb_list; curr = curr->next) {
+	for (curr = xusb_list->next; curr != xusb_list; curr = curr->next) {
 		struct usb_device		*dev;
 		struct usb_bus			*bus;
 		struct usb_device_descriptor	*dev_desc;
@@ -285,14 +305,15 @@
 
 void xusb_destroy(struct xusb *xusb)
 {
-	if(xusb) {
+	if (xusb) {
 		xusb_close(xusb);
 		memset(xusb, 0, sizeof(*xusb));
 		free(xusb);
 	}
 }
 
-static struct xusb *xusb_new(struct usb_device *dev, const struct xusb_spec *spec)
+static struct xusb *xusb_new(struct usb_device *dev,
+		const struct xusb_spec *spec)
 {
 	struct usb_device_descriptor	*dev_desc;
 	struct usb_config_descriptor	*config_desc;
@@ -306,11 +327,13 @@
 	/*
 	 * Get information from the usb_device
 	 */
-	if((dev_desc = &dev->descriptor) == NULL) {
+	dev_desc = &dev->descriptor;
+	if (!dev_desc) {
 		ERR("usb device without a device descriptor\n");
 		goto fail;
 	}
-	if((config_desc = dev->config) == NULL) {
+	config_desc = dev->config;
+	if (!config_desc) {
 		ERR("usb device without a configuration descriptor\n");
 		goto fail;
 	}
@@ -319,20 +342,23 @@
 	endpoint = iface_desc->endpoint;
 	/* Calculate max packet size */
 	max_packet_size = PACKET_SIZE;
-	for(i = 0; i < iface_desc->bNumEndpoints; i++, endpoint++) {
-		DBG("Validating endpoint @ %d (interface %d)\n", i, spec->my_interface_num);
-		if(endpoint->bEndpointAddress == spec->my_ep_out || endpoint->bEndpointAddress == spec->my_ep_in) {
-			if(endpoint->wMaxPacketSize > PACKET_SIZE) {
-				ERR("Endpoint #%d wMaxPacketSize too large (%d)\n", i, endpoint->wMaxPacketSize);
+	for (i = 0; i < iface_desc->bNumEndpoints; i++, endpoint++) {
+		DBG("Validating endpoint @ %d (interface %d)\n",
+			i, spec->my_interface_num);
+		if (endpoint->bEndpointAddress == spec->my_ep_out ||
+			endpoint->bEndpointAddress == spec->my_ep_in) {
+			if (endpoint->wMaxPacketSize > PACKET_SIZE) {
+				ERR("EP #%d wMaxPacketSize too large (%d)\n",
+					i, endpoint->wMaxPacketSize);
 				goto fail;
 			}
-			if(endpoint->wMaxPacketSize < max_packet_size) {
+			if (endpoint->wMaxPacketSize < max_packet_size)
 				max_packet_size = endpoint->wMaxPacketSize;
-			}
 		}
 	}
 	/* Fill xusb */
-	if((xusb = malloc(sizeof(*xusb))) == NULL) {
+	xusb = malloc(sizeof(*xusb));
+	if (!xusb) {
 		ERR("Out of memory");
 		goto fail;
 	}
@@ -348,7 +374,7 @@
 	xusb->ep_in = spec->my_ep_in;
 	xusb->packet_size = max_packet_size;
 	xusb->is_usb2 = (max_packet_size == 512);
-	if (! xusb_open(xusb)) {
+	if (!xusb_open(xusb)) {
 		ERR("Failed opening device: %04X:%04X - %s\n",
 			dev_desc->idVendor,
 			dev_desc->idProduct,
@@ -396,7 +422,8 @@
 
 			sscanf(dev->filename, "%d", &device_num);
 			DBG("Check device %d\n", device_num);
-			snprintf(tmppath, sizeof(tmppath), "%03d/%03d", bus_num, device_num);
+			snprintf(tmppath, sizeof(tmppath), "%03d/%03d",
+				bus_num, device_num);
 			if (strncmp(tmppath, devpath, strlen(tmppath)) != 0)
 				continue;
 			dev_desc = &dev->descriptor;
@@ -405,7 +432,8 @@
 			assert(config_desc);
 			interface = config_desc->interface;
 			assert(interface);
-			DBG("Matched device %s: %X:%X\n", tmppath, dev_desc->idVendor, dev_desc->idProduct);
+			DBG("Matched device %s: %X:%X\n", tmppath,
+				dev_desc->idVendor, dev_desc->idProduct);
 			assert(dummy_spec);
 			xusb_init_spec(dummy_spec, "<none>",
 				dev_desc->idVendor, dev_desc->idProduct,
@@ -413,9 +441,9 @@
 				iface_num,
 				interface->altsetting->bNumEndpoints,
 				ep_out, ep_in);
-			if((xusb = xusb_new(dev, dummy_spec)) == NULL) {
+			xusb = xusb_new(dev, dummy_spec);
+			if (!xusb)
 				ERR("xusb allocation failed\n");
-			}
 			return xusb;
 		}
 	}
@@ -424,20 +452,21 @@
 
 static const char *path_tail(const char *path)
 {
-	const	char	*p;
+	const char	*p;
 
 	assert(path != NULL);
 	/* Find last '/' */
-	if((p = memrchr(path, '/', strlen(path))) == NULL) {
+	p = memrchr(path, '/', strlen(path));
+	if (!p) {
 		ERR("Missing a '/' in %s\n", path);
 		return NULL;
 	}
 	/* Search for a '/' before that */
-	if((p = memrchr(path, '/', p - path)) == NULL) {
+	p = memrchr(path, '/', p - path);
+	if (!p)
 		p = path;		/* No more '/' */
-	} else {
+	else
 		p++;			/* skip '/' */
-	}
 	return p;
 }
 
@@ -449,25 +478,29 @@
 	DBG("%s\n", path);
 	assert(path != NULL);
 	p = path_tail(path);
-	if(strcmp(xusb->devpath_tail, p) != 0) {
-		DBG("device path missmatch: '%s' != '%s'\n", xusb->devpath_tail, p);
+	if (strcmp(xusb->devpath_tail, p) != 0) {
+		DBG("device path missmatch: '%s' != '%s'\n",
+			xusb->devpath_tail, p);
 		return 0;
 	}
 	return 1;
 }
 
-struct xusb *xusb_find_bypath(const struct xusb_spec *specs, int numspecs, const char *path)
+struct xusb *xusb_find_bypath(const struct xusb_spec *specs, int numspecs,
+			const char *path)
 {
 	struct xlist_node	*xlist;
 	struct xlist_node	*head;
 	struct xusb		*xusb;
 
-	xlist = xusb_find_byproduct(specs, numspecs, xusb_filter_bypath, (void *)path);
+	xlist = xusb_find_byproduct(specs, numspecs,
+			xusb_filter_bypath, (void *)path);
 	head = xlist_shift(xlist);
 	if (!head)
 		return NULL;
-	if (! xlist_empty(xlist)) {
-		ERR("Too many matches (extra %zd) to '%s'\n", xlist_length(xlist), path);
+	if (!xlist_empty(xlist)) {
+		ERR("Too many matches (extra %zd) to '%s'\n",
+			xlist_length(xlist), path);
 		return NULL;
 	}
 	xusb = head->data;
@@ -475,14 +508,16 @@
 	return xusb;
 }
 
-struct xlist_node *xusb_find_byproduct(const struct xusb_spec *specs, int numspecs, xusb_filter_t filterfunc, void *data)
+struct xlist_node *xusb_find_byproduct(const struct xusb_spec *specs,
+		int numspecs, xusb_filter_t filterfunc, void *data)
 {
 	struct xlist_node	*xlist;
 	struct usb_bus		*bus;
 	struct usb_device	*dev;
 
 	DBG("specs(%d)\n", numspecs);
-	if((xlist = xlist_new(NULL)) == NULL) {
+	xlist = xlist_new(NULL);
+	if (!xlist) {
 		ERR("Failed allocation new xlist");
 		goto fail_xlist;
 	}
@@ -500,17 +535,18 @@
 				dev->filename,
 				dev_desc->idVendor,
 				dev_desc->idProduct);
-			for(i = 0; i < numspecs; i++) {
+			for (i = 0; i < numspecs; i++) {
 				struct xusb		*xusb;
 				const struct xusb_spec	*sp = &specs[i];
 
-				if(!match_interface(dev, sp))
+				if (!match_interface(dev, sp))
 					continue;
-				if((xusb = xusb_new(dev, sp)) == NULL) {
+				xusb = xusb_new(dev, sp);
+				if (!xusb) {
 					ERR("xusb allocation failed\n");
 					goto fail_malloc;
 				}
-				if(filterfunc && !filterfunc(xusb, data)) {
+				if (filterfunc && !filterfunc(xusb, data)) {
 					xusb_destroy(xusb);
 					continue;
 				}
@@ -528,7 +564,8 @@
 	return NULL;
 }
 
-struct xusb *xusb_open_one(const struct xusb_spec *specs, int numspecs, xusb_filter_t filterfunc, void *data)
+struct xusb *xusb_open_one(const struct xusb_spec *specs, int numspecs,
+		xusb_filter_t filterfunc, void *data)
 {
 	struct xlist_node	*xusb_list;
 	struct xlist_node	*curr;
@@ -538,7 +575,7 @@
 	xusb_list = xusb_find_byproduct(specs, numspecs, filterfunc, data);
 	num = xlist_length(xusb_list);
 	DBG("total %d devices\n", num);
-	switch(num) {
+	switch (num) {
 	case 0:
 		ERR("No matching device.\n");
 		break;
@@ -547,7 +584,7 @@
 		xusb = curr->data;
 		xlist_destroy(curr, NULL);
 		xlist_destroy(xusb_list, NULL);
-		if(!xusb_claim_interface(xusb)) {
+		if (!xusb_claim_interface(xusb)) {
 			xusb_destroy(xusb);
 			return NULL;
 		}
@@ -581,7 +618,7 @@
 	assert(xusb != NULL);
 	dev = xusb->dev;
 	dev_desc = &dev->descriptor;
-	if(verbose <= LOG_INFO) {
+	if (verbose <= LOG_INFO) {
 		INFO("usb:%s/%s: ID=%04X:%04X [%s / %s / %s]\n",
 			dev->bus->dirname,
 			dev->filename,
@@ -640,20 +677,22 @@
 
 int xusb_close(struct xusb *xusb)
 {
-	if(xusb) {
-		if(xusb->handle) {
+	if (xusb) {
+		if (xusb->handle) {
 			assert(xusb->spec);
 			assert(xusb->spec->name);
 			DBG("Closing interface \"%s\"\n", xusb->spec->name);
-			if(xusb->is_claimed) {
-				if(usb_release_interface(xusb->handle, xusb->spec->my_interface_num) != 0) {
-					ERR("Releasing interface: usb: %s\n", usb_strerror());
-				}
+			if (xusb->is_claimed) {
+				if (usb_release_interface(xusb->handle,
+					xusb->spec->my_interface_num) != 0)
+					ERR("Releasing interface: usb: %s\n",
+						usb_strerror());
 				xusb->is_claimed = 0;
 			}
-			if(xusb->is_open) {
-				if(usb_close(xusb->handle) != 0) {
-					ERR("Closing device: usb: %s\n", usb_strerror());
+			if (xusb->is_open) {
+				if (usb_close(xusb->handle) != 0) {
+					ERR("Closing device: usb: %s\n",
+						usb_strerror());
 				}
 				xusb->is_open = 0;
 			}
@@ -669,30 +708,33 @@
 	int		ret;
 	int		retries = 0;
 
-	dump_packet(LOG_DEBUG, DBG_MASK, __FUNCTION__, buf, len);
-	if(EP_OUT(xusb) & USB_ENDPOINT_IN) {
-		ERR("%s called with an input endpoint 0x%x\n", __FUNCTION__, EP_OUT(xusb));
+	dump_packet(LOG_DEBUG, DBG_MASK, __func__, buf, len);
+	if (EP_OUT(xusb) & USB_ENDPOINT_IN) {
+		ERR("%s called with an input endpoint 0x%x\n",
+			__func__, EP_OUT(xusb));
 		return -EINVAL;
 	}
 retry_write:
 	ret = usb_bulk_write(xusb->handle, EP_OUT(xusb), buf, len, timeout);
-	if(ret < 0) {
+	if (ret < 0) {
 		/*
 		 * If the device was gone, it may be the
 		 * result of renumeration. Ignore it.
 		 */
-		if(ret != -ENODEV) {
+		if (ret != -ENODEV) {
 			ERR("bulk_write to endpoint 0x%x failed: (%d) %s\n",
 				EP_OUT(xusb), ret, usb_strerror());
-			dump_packet(LOG_ERR, DBG_MASK, "xusb_send[ERR]", buf, len);
-			//exit(2);
+			dump_packet(LOG_ERR, DBG_MASK, "xusb_send[ERR]",
+				buf, len);
+			/*exit(2);*/
 		} else {
-			DBG("bulk_write to endpoint 0x%x got ENODEV\n", EP_OUT(xusb));
+			DBG("bulk_write to endpoint 0x%x got ENODEV\n",
+				EP_OUT(xusb));
 			xusb_close(xusb);
 		}
 		return ret;
 	}
-	if(!ret) {
+	if (!ret) {
 #if 0
 		FILE	*fp;
 
@@ -707,13 +749,12 @@
 #endif
 		ERR("bulk_write to endpoint 0x%x short write[%d]: (%d)\n",
 			EP_OUT(xusb), retries, ret);
-		if (retries++ > MAX_RETRIES) {
+		if (retries++ > MAX_RETRIES)
 			return -EFAULT;
-		}
 		usleep(100);
 		goto retry_write;
 	}
-	if(ret != len) {
+	if (ret != len) {
 		ERR("bulk_write to endpoint 0x%x short write: (%d) %s\n",
 			EP_OUT(xusb), ret, usb_strerror());
 		dump_packet(LOG_ERR, DBG_MASK, "xusb_send[ERR]", buf, len);

[... 110 lines stripped ...]



More information about the svn-commits mailing list