Icom frame patch

I'm implementing several changes to support some functionality for the
IC7300.  In order to minimize the review process I'm submitting this
small one separately (still working on finish the IC7300 but it's some
fairly extensive changes since ICOM has changed the protocol for several
things).

For the IC7300 turning power on requires ~150 0xfe's be sent to wake up
the rig.  This causes a buffer overflow condition in icom/frame.c.  This
patch increases the buffer size and ensures no overflow.

73
Mike W9MDB
Hamlib-3.1
Michael Black 2016-05-08 23:03:29 -05:00 zatwierdzone przez Nate Bargmann
rodzic f3ccfb855f
commit 1767cb5c43
3 zmienionych plików z 13 dodań i 11 usunięć

Wyświetl plik

@ -98,7 +98,9 @@ int icom_one_transaction (RIG *rig, int cmd, int subcmd, const unsigned char *pa
struct icom_priv_data *priv;
const struct icom_priv_caps *priv_caps;
struct rig_state *rs;
unsigned char buf[MAXFRAMELEN];
// this buf needs to be large enough for 0xfe strings for power up
// at 115,200 this is now at least 150
unsigned char buf[200];
unsigned char sendbuf[MAXFRAMELEN];
int frm_len, retval;
int ctrl_id;
@ -136,7 +138,7 @@ int icom_one_transaction (RIG *rig, int cmd, int subcmd, const unsigned char *pa
* up to rs->retry times.
*/
retval = read_icom_frame(&rs->rigport, buf);
retval = read_icom_frame(&rs->rigport, buf, sizeof(buf));
if (retval == -RIG_ETIMEOUT || retval == 0)
{
/* Nothing recieved, CI-V interface is not echoing */
@ -197,7 +199,7 @@ int icom_one_transaction (RIG *rig, int cmd, int subcmd, const unsigned char *pa
* FIXME: handle pading/collisions
* ACKFRMLEN is the smallest frame we can expect from the rig
*/
frm_len = read_icom_frame(&rs->rigport, buf);
frm_len = read_icom_frame(&rs->rigport, buf, sizeof(buf));
Unhold_Decode(rig);
if (frm_len < 0)
@ -272,7 +274,7 @@ static const char icom_block_end[2] = {FI, COL};
* TODO: strips padding/collisions
* FIXME: check return codes/bytes read
*/
int read_icom_frame(hamlib_port_t *p, unsigned char rxbuffer[])
int read_icom_frame(hamlib_port_t *p, unsigned char rxbuffer[], int rxbuffer_len)
{
int read = 0;
int retries = 10;
@ -297,7 +299,7 @@ int read_icom_frame(hamlib_port_t *p, unsigned char rxbuffer[])
/* OK, we got something. add it in and continue */
read += i;
rx_ptr += i;
} while ((rxbuffer[read-1] != FI) && (rxbuffer[read-1] != COL));
} while ((read < rxbuffer_len) && (rxbuffer[read-1] != FI) && (rxbuffer[read-1] != COL));
return read;
}

Wyświetl plik

@ -30,7 +30,7 @@
int make_cmd_frame(char frame[], char re_id, char ctrl_id, char cmd, int subcmd, const unsigned char *data, int data_len);
int icom_transaction (RIG *rig, int cmd, int subcmd, const unsigned char *payload, int payload_len, unsigned char *data, int *data_len);
int read_icom_frame(hamlib_port_t *p, unsigned char rxbuffer[]);
int read_icom_frame(hamlib_port_t *p, unsigned char rxbuffer[], int rxbuffer_len);
int rig2icom_mode(RIG *rig, rmode_t mode, pbwidth_t width, unsigned char *md, signed char *pd);
void icom2rig_mode(RIG *rig, unsigned char md, int pd, rmode_t *mode, pbwidth_t *width);

Wyświetl plik

@ -3247,7 +3247,7 @@ int icom_decode_event(RIG *rig)
rs = &rig->state;
priv = (struct icom_priv_data*)rs->priv;
frm_len = read_icom_frame(&rs->rigport, buf);
frm_len = read_icom_frame(&rs->rigport, buf, sizeof(buf));
if (frm_len == -RIG_ETIMEOUT)
rig_debug(RIG_DEBUG_VERBOSE, "icom: icom_decode got a timeout before the first character\n");
@ -3368,10 +3368,10 @@ DECLARE_PROBERIG_BACKEND(icom)
/* read out the bytes we just sent
* TODO: check this is what we expect
*/
frm_len = read_icom_frame(port, buf);
frm_len = read_icom_frame(port, buf, sizeof(buf));
/* this is the reply */
frm_len = read_icom_frame(port, buf);
frm_len = read_icom_frame(port, buf, sizeof(buf));
/* timeout.. nobody's there */
if (frm_len <= 0)
@ -3427,10 +3427,10 @@ DECLARE_PROBERIG_BACKEND(icom)
/* read out the bytes we just sent
* TODO: check this is what we expect
*/
frm_len = read_icom_frame(port, buf);
frm_len = read_icom_frame(port, buf, sizeof(buf));
/* this is the reply */
frm_len = read_icom_frame(port, buf);
frm_len = read_icom_frame(port, buf, sizeof(buf));
/* timeout.. nobody's there */
if (frm_len <= 0)