hantek-6xxx: Ignore requests to set Hantek 6022BE coupling.

Here's a patch to "Ignore requests to set coupling for the Hantek 6022BE",
this clears the LIBUSB errors for me.

Also in the patch:

 - There is a crash because config_list() can be called with sdi == NULL.

   This can be reproduced by doing:
     "sigrok-cli.exe --driver hantek-6xxx --show"

 - There seems to be a very unsafe loop in config_set() when setting COUPLING;
   the coupling vector is assumed to be zero terminated, but is not declared
   as such.

   Note: The same issue is present also for other hardware, at least for
   hantek-dso/api.c. The patch is only for hantek-6xxx though.
This commit is contained in:
Erik Montnemery 2016-08-18 23:05:11 +02:00 committed by Uwe Hermann
parent 7f46b27ef2
commit 817b7441a1
3 changed files with 18 additions and 12 deletions

View File

@ -62,12 +62,12 @@ static const struct hantek_6xxx_profile dev_profiles[] = {
{
0x04b4, 0x6022, 0x04b5, 0x6022,
"Hantek", "6022BE", "hantek-6022be.fw",
dc_coupling, ARRAY_SIZE(dc_coupling),
dc_coupling, ARRAY_SIZE(dc_coupling), FALSE,
},
{
0x8102, 0x8102, 0x1D50, 0x608E,
"Sainsmart", "DDS120", "sainsmart-dds120.fw",
acdc_coupling, ARRAY_SIZE(acdc_coupling),
acdc_coupling, ARRAY_SIZE(acdc_coupling), TRUE,
},
ALL_ZERO
};
@ -440,13 +440,13 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
break;
case SR_CONF_COUPLING:
tmp_str = g_variant_get_string(data, NULL);
for (i = 0; devc->coupling_vals[i]; i++) {
for (i = 0; i < devc->coupling_tab_size; i++) {
if (!strcmp(tmp_str, devc->coupling_vals[i])) {
devc->coupling[ch_idx] = i;
break;
}
}
if (devc->coupling_vals[i] == 0)
if (i == devc->coupling_tab_size)
ret = SR_ERR_ARG;
break;
default:
@ -465,7 +465,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
GVariantBuilder gvb;
unsigned int i;
GVariant *gvar;
struct dev_context *devc;
struct dev_context *devc = NULL;
if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
@ -477,10 +477,8 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
return SR_OK;
}
if (!sdi)
return SR_ERR_ARG;
devc = sdi->priv;
if (sdi)
devc = sdi->priv;
if (!cg) {
switch (key) {
@ -506,6 +504,8 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t));
break;
case SR_CONF_COUPLING:
if (!devc)
return SR_ERR_NA;
*data = g_variant_new_strv(devc->coupling_vals, devc->coupling_tab_size);
break;
case SR_CONF_VDIV:

View File

@ -220,9 +220,13 @@ SR_PRIV int hantek_6xxx_update_coupling(const struct sr_dev_inst *sdi)
struct dev_context *devc = sdi->priv;
uint8_t coupling = 0xFF & ((devc->coupling[1] << 4) | devc->coupling[0]);
sr_dbg("update coupling 0x%x", coupling);
return write_control(sdi, COUPLING_REG, coupling);
if (devc->has_coupling) {
sr_dbg("update coupling 0x%x", coupling);
return write_control(sdi, COUPLING_REG, coupling);
} else {
sr_dbg("coupling not supported");
return SR_OK;
}
}
SR_PRIV int hantek_6xxx_update_channels(const struct sr_dev_inst *sdi)

View File

@ -99,6 +99,7 @@ struct hantek_6xxx_profile {
const char *firmware;
const char **coupling_vals;
uint8_t coupling_tab_size;
gboolean has_coupling;
};
struct dev_context {
@ -127,6 +128,7 @@ struct dev_context {
int coupling[NUM_CHANNELS];
const char **coupling_vals;
uint8_t coupling_tab_size;
gboolean has_coupling;
uint64_t samplerate;
uint64_t limit_msec;