}
-/* 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) {
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. */
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,
};
}
+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;