- /************************************************************************
- * ELM327: Transmission *
- * *
- * (all functions assume elm->lock taken) *
- ************************************************************************/
+ /***********************************************************************
+ * ELM327: Transmission *
+ * *
+ * (all functions assume elm->lock taken) *
+ ***********************************************************************/
static void elm327_send(struct elmcan *elm, const void *buf, size_t len)
{
}
-/* Take the ELM327 out of almost any state and back into command mode. */
+/* Take the ELM327 out of almost any state and back into command mode.
+ * We send ELM327_MAGIC_CHAR which will either abort any running
+ * operation, or be echoed back to us in case we're already in command
+ * mode.
+ */
static void elm327_kick_into_cmd_mode(struct elmcan *elm)
{
if (elm->state != ELM_GETMAGICCHAR && elm->state != ELM_GETPROMPT) {
- /************************************************************************
- * ELM327: Initialization sequence *
- * *
- * (assumes elm->lock taken) *
- ************************************************************************/
+ /***********************************************************************
+ * ELM327: Initialization sequence *
+ * *
+ * (assumes elm->lock taken) *
+ ***********************************************************************/
static char *elm327_init_script[] = {
"AT WS\r", /* v1.0: Warm Start */
- /************************************************************************
- * ELM327: Reception -> netdev glue *
- * *
- * (assumes elm->lock taken) *
- ************************************************************************/
+ /***********************************************************************
+ * ELM327: Reception -> netdev glue *
+ * *
+ * (assumes elm->lock taken) *
+ ***********************************************************************/
static void elm327_feed_frame_to_netdev(struct elmcan *elm,
const struct can_frame *frame)
- /************************************************************************
- * ELM327: "Panic" handler *
- * *
- * (assumes elm->lock taken) *
- ************************************************************************/
+ /***********************************************************************
+ * ELM327: "Panic" handler *
+ * *
+ * (assumes elm->lock taken) *
+ ***********************************************************************/
/* Called when we're out of ideas and just want it all to end. */
static inline void elm327_hw_failure(struct elmcan *elm)
switch (elm->state) {
case ELM_NOTINIT:
elm->rxfill = 0;
- return;
+ break;
case ELM_GETMAGICCHAR:
{
elm327_drop_bytes(elm, i);
- return;
+ break;
}
case ELM_GETPROMPT:
elm327_handle_prompt(elm);
elm->rxfill = 0;
- return;
+ break;
case ELM_RECEIVING:
/* Find <CR> delimiting feedback lines. */
netdev_err(elm->dev,
"RX buffer overflow. Faulty ELM327 or UART?\n");
elm327_hw_failure(elm);
- return;
+ break;
} else if (len == elm->rxfill) {
if (elm327_is_ready_char(elm->rxbuf[elm->rxfill - 1])) {
/* The ELM327's AT ST response timeout ran out,
elm->rxfill = 0;
elm327_handle_prompt(elm);
- return;
+ break;
}
/* No <CR> found - we haven't received a full line yet.
* Wait for more data.
*/
- return;
+ break;
}
/* We have a full line to parse. */
- /************************************************************************
- * netdev *
- * *
- * (takes elm->lock) *
- ************************************************************************/
+ /***********************************************************************
+ * netdev *
+ * *
+ * (takes elm->lock) *
+ ***********************************************************************/
static int elmcan_netdev_open(struct net_device *dev)
{
return NETDEV_TX_OK;
}
-static int elmcan_netdev_change_mtu(struct net_device *dev, int new_mtu)
-{
- return -EINVAL;
-}
static const struct net_device_ops elmcan_netdev_ops = {
.ndo_open = elmcan_netdev_open,
.ndo_stop = elmcan_netdev_close,
.ndo_start_xmit = elmcan_netdev_start_xmit,
- .ndo_change_mtu = elmcan_netdev_change_mtu,
+ .ndo_change_mtu = can_change_mtu,
};
- /************************************************************************
- * Line discipline *
- * *
- * (takes elm->lock) *
- ************************************************************************/
+ /***********************************************************************
+ * Line discipline *
+ * *
+ * (takes elm->lock) *
+ ***********************************************************************/
/* Get a reference to our struct, taking into account locks/refcounts.
* This is to ensure ordering in case we are shutting down, and to ensure
}
+static bool elmcan_is_valid_rx_char(char c)
+{
+ return (accept_flaky_uart
+ || isdigit(c)
+ || isupper(c)
+ || ELM327_MAGIC_CHAR == c
+ || ELM327_READY_CHAR == c
+ || '<' == c
+ || 'a' == c
+ || 'b' == c
+ || 'v' == c
+ || '.' == c
+ || '?' == c
+ || '\r' == c
+ || ' ' == c);
+}
+
/* Handle incoming ELM327 ASCII data.
* This will not be re-entered while running, but other ldisc
* functions may be called in parallel.
return;
spin_lock_bh(&elm->lock);
- if (elm->hw_failure) {
- spin_unlock_bh(&elm->lock);
- put_elm(elm);
- return;
+ if (elm->hw_failure) {
+ goto out;
}
while (count-- && elm->rxfill < sizeof(elm->rxbuf)) {
netdev_err(elm->dev, "Error in received character stream. Check your wiring.");
elm327_hw_failure(elm);
- spin_unlock_bh(&elm->lock);
- put_elm(elm);
- return;
+ goto out;
}
/* Ignore NUL characters, which the PIC microcontroller may
/* Check for stray characters on the UART line.
* Likely caused by bad hardware.
*/
- if (!accept_flaky_uart
- && !isdigit(*cp)
- && !isupper(*cp)
- && ELM327_MAGIC_CHAR != *cp
- && ELM327_READY_CHAR != *cp
- && '<' != *cp
- && 'a' != *cp
- && 'b' != *cp
- && 'v' != *cp
- && '.' != *cp
- && '?' != *cp
- && '\r' != *cp
- && ' ' != *cp) {
+ if (!elmcan_is_valid_rx_char(*cp)) {
netdev_err(elm->dev,
"Received illegal character %02x.\n",
*cp);
elm327_hw_failure(elm);
- spin_unlock_bh(&elm->lock);
- put_elm(elm);
- return;
+ goto out;
}
elm->rxbuf[elm->rxfill++] = *cp;
netdev_err(elm->dev, "Receive buffer overflowed. Bad chip or wiring?");
elm327_hw_failure(elm);
- spin_unlock_bh(&elm->lock);
- put_elm(elm);
- return;
+ goto out;
}
elm327_parse_rxbuf(elm);
- spin_unlock_bh(&elm->lock);
+out:
+ spin_unlock_bh(&elm->lock);
put_elm(elm);
}
/* Dummy needed to use bitrate_const */
static int elmcan_do_set_bittiming(struct net_device *netdev)
{
+ (void)netdev;
+
return 0;
}
-
-
- /************************************************************************
- * Module init/exit *
- ************************************************************************/
-
static int __init elmcan_init(void)
{
int status;