Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update(class/audio/usbh_auido): add check for audio stream validation
Browse files Browse the repository at this point in the history
sakumisu committed Oct 25, 2024

Verified

This commit was signed with the committer’s verified signature.
breezewish Wenxuan
1 parent 65151b9 commit dde1d7e
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions class/audio/usbh_audio.c
Original file line number Diff line number Diff line change
@@ -187,7 +187,6 @@ int usbh_audio_close(struct usbh_audio *audio_class, const char *name)
int usbh_audio_set_volume(struct usbh_audio *audio_class, const char *name, uint8_t ch, uint8_t volume)
{
struct usb_setup_packet *setup;
int ret;
uint8_t feature_id = 0xff;
uint16_t volume_hex;

@@ -213,18 +212,15 @@ int usbh_audio_set_volume(struct usbh_audio *audio_class, const char *name, uint
setup->wIndex = (feature_id << 8) | audio_class->ctrl_intf;
setup->wLength = 2;

volume_hex = -0xDB00 / 100 * volume + 0xdb00;
volume_hex = volume / 100 * (-0xdb00) + 0xdb00;

memcpy(g_audio_buf, &volume_hex, 2);
ret = usbh_control_transfer(audio_class->hport, setup, NULL);

return ret;
return usbh_control_transfer(audio_class->hport, setup, g_audio_buf);
}

int usbh_audio_set_mute(struct usbh_audio *audio_class, const char *name, uint8_t ch, bool mute)
{
struct usb_setup_packet *setup;
int ret;
uint8_t feature_id = 0xff;

if (!audio_class || !audio_class->hport) {
@@ -245,9 +241,7 @@ int usbh_audio_set_mute(struct usbh_audio *audio_class, const char *name, uint8_
setup->wLength = 1;

memcpy(g_audio_buf, &mute, 1);
ret = usbh_control_transfer(audio_class->hport, setup, g_audio_buf);

return ret;
return usbh_control_transfer(audio_class->hport, setup, g_audio_buf);
}

void usbh_audio_list_module(struct usbh_audio *audio_class)
@@ -286,9 +280,9 @@ void usbh_audio_list_module(struct usbh_audio *audio_class)
static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
{
int ret;
uint8_t cur_iface = 0xff;
uint8_t cur_iface_count = 0xff;
uint8_t cur_alt_setting = 0xff;
uint8_t cur_iface = 0;
uint8_t cur_iface_count = 0;
uint8_t cur_alt_setting = 0;
uint8_t input_offset = 0;
uint8_t output_offset = 0;
uint8_t feature_unit_offset = 0;
@@ -342,11 +336,9 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
memcpy(&audio_class->ac_msg_table[feature_unit_offset].ac_feature_unit, desc, desc->bLength);
feature_unit_offset++;
} break;
case AUDIO_CONTROL_PROCESSING_UNIT:

break;
default:
break;
USB_LOG_ERR("Do not support %02x subtype\r\n", p[DESC_bDescriptorSubType]);
return -USB_ERR_NOTSUPP;
}
} else if ((cur_iface > audio_class->ctrl_intf) && (cur_iface < (audio_class->ctrl_intf + cur_iface_count))) {
switch (p[DESC_bDescriptorSubType]) {
@@ -459,6 +451,10 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
}

for (uint8_t i = 0; i < audio_class->stream_intf_num; i++) {
if (audio_class->as_msg_table[i].stream_name == NULL) {
USB_LOG_ERR("Not find any supported audio stream device\r\n");
return -USB_ERR_NODEV;
}
ret = usbh_audio_close(audio_class, audio_class->as_msg_table[i].stream_name);
if (ret < 0) {
USB_LOG_ERR("Fail to close audio stream :%s\r\n", audio_class->as_msg_table[i].stream_name);

0 comments on commit dde1d7e

Please sign in to comment.