use static memory to malloc & free class
This commit is contained in:
@@ -108,6 +108,13 @@
|
|||||||
#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1
|
#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1
|
||||||
#define CONFIG_USBHOST_MAX_ENDPOINTS 4
|
#define CONFIG_USBHOST_MAX_ENDPOINTS 4
|
||||||
|
|
||||||
|
#define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
|
||||||
|
#define CONFIG_USBHOST_MAX_HID_CLASS 4
|
||||||
|
#define CONFIG_USBHOST_MAX_MSC_CLASS 2
|
||||||
|
#define CONFIG_USBHOST_MAX_AUDIO_CLASS 1
|
||||||
|
#define CONFIG_USBHOST_MAX_VIDEO_CLASS 1
|
||||||
|
#define CONFIG_USBHOST_MAX_RNDIS_CLASS 1
|
||||||
|
|
||||||
#define CONFIG_USBHOST_DEV_NAMELEN 16
|
#define CONFIG_USBHOST_DEV_NAMELEN 16
|
||||||
|
|
||||||
#ifndef CONFIG_USBHOST_PSC_PRIO
|
#ifndef CONFIG_USBHOST_PSC_PRIO
|
||||||
|
|||||||
@@ -17,33 +17,38 @@
|
|||||||
#define INTF_DESC_bInterfaceNumber 2 /** Interface number offset */
|
#define INTF_DESC_bInterfaceNumber 2 /** Interface number offset */
|
||||||
#define INTF_DESC_bAlternateSetting 3 /** Alternate setting offset */
|
#define INTF_DESC_bAlternateSetting 3 /** Alternate setting offset */
|
||||||
|
|
||||||
static uint32_t g_devinuse = 0;
|
#ifndef CONFIG_USBHOST_MAX_AUDIO_CLASS
|
||||||
|
#define CONFIG_USBHOST_MAX_AUDIO_CLASS 4
|
||||||
|
#endif
|
||||||
|
|
||||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_audio_buf[128];
|
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_audio_buf[128];
|
||||||
|
|
||||||
static int usbh_audio_devno_alloc(struct usbh_audio *audio_class)
|
static struct usbh_audio g_audio_class[CONFIG_USBHOST_MAX_AUDIO_CLASS];
|
||||||
|
static uint32_t g_devinuse = 0;
|
||||||
|
|
||||||
|
static struct usbh_audio *usbd_audio_class_alloc(void)
|
||||||
{
|
{
|
||||||
int devno;
|
int devno;
|
||||||
|
|
||||||
for (devno = 0; devno < 32; devno++) {
|
for (devno = 0; devno < CONFIG_USBHOST_MAX_AUDIO_CLASS; devno++) {
|
||||||
uint32_t bitno = 1 << devno;
|
if ((g_devinuse & (1 << devno)) == 0) {
|
||||||
if ((g_devinuse & bitno) == 0) {
|
g_devinuse |= (1 << devno);
|
||||||
g_devinuse |= bitno;
|
memset(&g_audio_class[devno], 0, sizeof(struct usbh_audio));
|
||||||
audio_class->minor = devno;
|
g_audio_class[devno].minor = devno;
|
||||||
return 0;
|
return &g_audio_class[devno];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return NULL;
|
||||||
return -EMFILE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usbh_audio_devno_free(struct usbh_audio *audio_class)
|
static void usbd_audio_class_free(struct usbh_audio *audio_class)
|
||||||
{
|
{
|
||||||
int devno = audio_class->minor;
|
int devno = audio_class->minor;
|
||||||
|
|
||||||
if (devno >= 0 && devno < 32) {
|
if (devno >= 0 && devno < 32) {
|
||||||
g_devinuse &= ~(1 << devno);
|
g_devinuse &= ~(1 << devno);
|
||||||
}
|
}
|
||||||
|
memset(audio_class, 0, sizeof(struct usbh_audio));
|
||||||
}
|
}
|
||||||
|
|
||||||
int usbh_audio_open(struct usbh_audio *audio_class, const char *name, uint32_t samp_freq)
|
int usbh_audio_open(struct usbh_audio *audio_class, const char *name, uint32_t samp_freq)
|
||||||
@@ -269,14 +274,12 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
uint8_t format_offset = 0;
|
uint8_t format_offset = 0;
|
||||||
uint8_t *p;
|
uint8_t *p;
|
||||||
|
|
||||||
struct usbh_audio *audio_class = usb_malloc(sizeof(struct usbh_audio));
|
struct usbh_audio *audio_class = usbd_audio_class_alloc();
|
||||||
if (audio_class == NULL) {
|
if (audio_class == NULL) {
|
||||||
USB_LOG_ERR("Fail to alloc audio_class\r\n");
|
USB_LOG_ERR("Fail to alloc audio_class\r\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(audio_class, 0, sizeof(struct usbh_audio));
|
|
||||||
usbh_audio_devno_alloc(audio_class);
|
|
||||||
audio_class->hport = hport;
|
audio_class->hport = hport;
|
||||||
audio_class->ctrl_intf = intf;
|
audio_class->ctrl_intf = intf;
|
||||||
audio_class->num_of_intf_altsettings = hport->config.intf[intf + 1].altsetting_num;
|
audio_class->num_of_intf_altsettings = hport->config.intf[intf + 1].altsetting_num;
|
||||||
@@ -412,8 +415,6 @@ static int usbh_audio_ctrl_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
struct usbh_audio *audio_class = (struct usbh_audio *)hport->config.intf[intf].priv;
|
struct usbh_audio *audio_class = (struct usbh_audio *)hport->config.intf[intf].priv;
|
||||||
|
|
||||||
if (audio_class) {
|
if (audio_class) {
|
||||||
usbh_audio_devno_free(audio_class);
|
|
||||||
|
|
||||||
if (audio_class->isoin) {
|
if (audio_class->isoin) {
|
||||||
usbh_pipe_free(audio_class->isoin);
|
usbh_pipe_free(audio_class->isoin);
|
||||||
}
|
}
|
||||||
@@ -427,8 +428,7 @@ static int usbh_audio_ctrl_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
usbh_audio_stop(audio_class);
|
usbh_audio_stop(audio_class);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(audio_class, 0, sizeof(struct usbh_audio));
|
usbd_audio_class_free(audio_class);
|
||||||
usb_free(audio_class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -8,32 +8,34 @@
|
|||||||
|
|
||||||
#define DEV_FORMAT "/dev/ttyACM%d"
|
#define DEV_FORMAT "/dev/ttyACM%d"
|
||||||
|
|
||||||
static uint32_t g_devinuse = 0;
|
|
||||||
|
|
||||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX struct cdc_line_coding g_cdc_line_coding;
|
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX struct cdc_line_coding g_cdc_line_coding;
|
||||||
|
|
||||||
static int usbh_cdc_acm_devno_alloc(struct usbh_cdc_acm *cdc_acm_class)
|
static struct usbh_cdc_acm g_cdc_acm_class[CONFIG_USBHOST_MAX_CDC_ACM_CLASS];
|
||||||
|
static uint32_t g_devinuse = 0;
|
||||||
|
|
||||||
|
static struct usbh_cdc_acm *usbd_cdc_acm_class_alloc(void)
|
||||||
{
|
{
|
||||||
int devno;
|
int devno;
|
||||||
|
|
||||||
for (devno = 0; devno < 32; devno++) {
|
for (devno = 0; devno < CONFIG_USBHOST_MAX_CDC_ACM_CLASS; devno++) {
|
||||||
uint32_t bitno = 1 << devno;
|
if ((g_devinuse & (1 << devno)) == 0) {
|
||||||
if ((g_devinuse & bitno) == 0) {
|
g_devinuse |= (1 << devno);
|
||||||
g_devinuse |= bitno;
|
memset(&g_cdc_acm_class[devno], 0, sizeof(struct usbh_cdc_acm));
|
||||||
cdc_acm_class->minor = devno;
|
g_cdc_acm_class[devno].minor = devno;
|
||||||
return 0;
|
return &g_cdc_acm_class[devno];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -EMFILE;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usbh_cdc_acm_devno_free(struct usbh_cdc_acm *cdc_acm_class)
|
static void usbd_cdc_acm_class_free(struct usbh_cdc_acm *cdc_acm_class)
|
||||||
{
|
{
|
||||||
int devno = cdc_acm_class->minor;
|
int devno = cdc_acm_class->minor;
|
||||||
|
|
||||||
if (devno >= 0 && devno < 32) {
|
if (devno >= 0 && devno < 32) {
|
||||||
g_devinuse &= ~(1 << devno);
|
g_devinuse &= ~(1 << devno);
|
||||||
}
|
}
|
||||||
|
memset(cdc_acm_class, 0, sizeof(struct usbh_cdc_acm));
|
||||||
}
|
}
|
||||||
|
|
||||||
int usbh_cdc_acm_set_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_line_coding *line_coding)
|
int usbh_cdc_acm_set_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_line_coding *line_coding)
|
||||||
@@ -91,14 +93,12 @@ static int usbh_cdc_acm_connect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
struct usb_endpoint_descriptor *ep_desc;
|
struct usb_endpoint_descriptor *ep_desc;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
struct usbh_cdc_acm *cdc_acm_class = usb_malloc(sizeof(struct usbh_cdc_acm));
|
struct usbh_cdc_acm *cdc_acm_class = usbd_cdc_acm_class_alloc();
|
||||||
if (cdc_acm_class == NULL) {
|
if (cdc_acm_class == NULL) {
|
||||||
USB_LOG_ERR("Fail to alloc cdc_acm_class\r\n");
|
USB_LOG_ERR("Fail to alloc cdc_acm_class\r\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(cdc_acm_class, 0, sizeof(struct usbh_cdc_acm));
|
|
||||||
usbh_cdc_acm_devno_alloc(cdc_acm_class);
|
|
||||||
cdc_acm_class->hport = hport;
|
cdc_acm_class->hport = hport;
|
||||||
cdc_acm_class->ctrl_intf = intf;
|
cdc_acm_class->ctrl_intf = intf;
|
||||||
cdc_acm_class->data_intf = intf + 1;
|
cdc_acm_class->data_intf = intf + 1;
|
||||||
@@ -151,8 +151,6 @@ static int usbh_cdc_acm_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
struct usbh_cdc_acm *cdc_acm_class = (struct usbh_cdc_acm *)hport->config.intf[intf].priv;
|
struct usbh_cdc_acm *cdc_acm_class = (struct usbh_cdc_acm *)hport->config.intf[intf].priv;
|
||||||
|
|
||||||
if (cdc_acm_class) {
|
if (cdc_acm_class) {
|
||||||
usbh_cdc_acm_devno_free(cdc_acm_class);
|
|
||||||
|
|
||||||
if (cdc_acm_class->bulkin) {
|
if (cdc_acm_class->bulkin) {
|
||||||
usbh_pipe_free(cdc_acm_class->bulkin);
|
usbh_pipe_free(cdc_acm_class->bulkin);
|
||||||
}
|
}
|
||||||
@@ -166,8 +164,7 @@ static int usbh_cdc_acm_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
usbh_cdc_acm_stop(cdc_acm_class);
|
usbh_cdc_acm_stop(cdc_acm_class);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(cdc_acm_class, 0, sizeof(struct usbh_cdc_acm));
|
usbd_cdc_acm_class_free(cdc_acm_class);
|
||||||
usb_free(cdc_acm_class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -8,33 +8,34 @@
|
|||||||
|
|
||||||
#define DEV_FORMAT "/dev/input%d"
|
#define DEV_FORMAT "/dev/input%d"
|
||||||
|
|
||||||
static uint32_t g_devinuse = 0;
|
|
||||||
|
|
||||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_hid_buf[128];
|
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_hid_buf[128];
|
||||||
|
|
||||||
static int usbh_hid_devno_alloc(struct usbh_hid *hid_class)
|
static struct usbh_hid g_hid_class[CONFIG_USBHOST_MAX_HID_CLASS];
|
||||||
|
static uint32_t g_devinuse = 0;
|
||||||
|
|
||||||
|
static struct usbh_hid *usbd_hid_class_alloc(void)
|
||||||
{
|
{
|
||||||
int devno;
|
int devno;
|
||||||
|
|
||||||
for (devno = 0; devno < 32; devno++) {
|
for (devno = 0; devno < CONFIG_USBHOST_MAX_HID_CLASS; devno++) {
|
||||||
uint32_t bitno = 1 << devno;
|
if ((g_devinuse & (1 << devno)) == 0) {
|
||||||
if ((g_devinuse & bitno) == 0) {
|
g_devinuse |= (1 << devno);
|
||||||
g_devinuse |= bitno;
|
memset(&g_hid_class[devno], 0, sizeof(struct usbh_hid));
|
||||||
hid_class->minor = devno;
|
g_hid_class[devno].minor = devno;
|
||||||
return 0;
|
return &g_hid_class[devno];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return NULL;
|
||||||
return -EMFILE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usbh_hid_devno_free(struct usbh_hid *hid_class)
|
static void usbd_hid_class_free(struct usbh_hid *hid_class)
|
||||||
{
|
{
|
||||||
int devno = hid_class->minor;
|
int devno = hid_class->minor;
|
||||||
|
|
||||||
if (devno >= 0 && devno < 32) {
|
if (devno >= 0 && devno < 32) {
|
||||||
g_devinuse &= ~(1 << devno);
|
g_devinuse &= ~(1 << devno);
|
||||||
}
|
}
|
||||||
|
memset(hid_class, 0, sizeof(struct usbh_hid));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usbh_hid_get_report_descriptor(struct usbh_hid *hid_class, uint8_t *buffer)
|
static int usbh_hid_get_report_descriptor(struct usbh_hid *hid_class, uint8_t *buffer)
|
||||||
@@ -106,14 +107,12 @@ int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
struct usb_endpoint_descriptor *ep_desc;
|
struct usb_endpoint_descriptor *ep_desc;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
struct usbh_hid *hid_class = usb_malloc(sizeof(struct usbh_hid));
|
struct usbh_hid *hid_class = usbd_hid_class_alloc();
|
||||||
if (hid_class == NULL) {
|
if (hid_class == NULL) {
|
||||||
USB_LOG_ERR("Fail to alloc hid_class\r\n");
|
USB_LOG_ERR("Fail to alloc hid_class\r\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(hid_class, 0, sizeof(struct usbh_hid));
|
|
||||||
usbh_hid_devno_alloc(hid_class);
|
|
||||||
hid_class->hport = hport;
|
hid_class->hport = hport;
|
||||||
hid_class->intf = intf;
|
hid_class->intf = intf;
|
||||||
|
|
||||||
@@ -159,8 +158,6 @@ int usbh_hid_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
struct usbh_hid *hid_class = (struct usbh_hid *)hport->config.intf[intf].priv;
|
struct usbh_hid *hid_class = (struct usbh_hid *)hport->config.intf[intf].priv;
|
||||||
|
|
||||||
if (hid_class) {
|
if (hid_class) {
|
||||||
usbh_hid_devno_free(hid_class);
|
|
||||||
|
|
||||||
if (hid_class->intin) {
|
if (hid_class->intin) {
|
||||||
usbh_pipe_free(hid_class->intin);
|
usbh_pipe_free(hid_class->intin);
|
||||||
}
|
}
|
||||||
@@ -174,8 +171,7 @@ int usbh_hid_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
usbh_hid_stop(hid_class);
|
usbh_hid_stop(hid_class);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(hid_class, 0, sizeof(struct usbh_hid));
|
usbd_hid_class_free(hid_class);
|
||||||
usb_free(hid_class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -14,10 +14,6 @@
|
|||||||
|
|
||||||
#define EXTHUB_FIRST_INDEX 2
|
#define EXTHUB_FIRST_INDEX 2
|
||||||
|
|
||||||
#if CONFIG_USBHOST_MAX_EXTHUBS > 0
|
|
||||||
static uint32_t g_devinuse = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_hub_buf[32];
|
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_hub_buf[32];
|
||||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_hub_intbuf[CONFIG_USBHOST_MAX_EXTHUBS + 1][CONFIG_USB_ALIGN_SIZE];
|
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_hub_intbuf[CONFIG_USBHOST_MAX_EXTHUBS + 1][CONFIG_USB_ALIGN_SIZE];
|
||||||
|
|
||||||
@@ -28,9 +24,6 @@ usb_osal_mq_t hub_mq;
|
|||||||
|
|
||||||
struct usbh_hub roothub;
|
struct usbh_hub roothub;
|
||||||
|
|
||||||
#if CONFIG_USBHOST_MAX_EXTHUBS > 0
|
|
||||||
struct usbh_hub exthub[CONFIG_USBHOST_MAX_EXTHUBS];
|
|
||||||
#endif
|
|
||||||
extern int usbh_hport_activate_ep0(struct usbh_hubport *hport);
|
extern int usbh_hport_activate_ep0(struct usbh_hubport *hport);
|
||||||
extern int usbh_hport_deactivate_ep0(struct usbh_hubport *hport);
|
extern int usbh_hport_deactivate_ep0(struct usbh_hubport *hport);
|
||||||
extern int usbh_enumerate(struct usbh_hubport *hport);
|
extern int usbh_enumerate(struct usbh_hubport *hport);
|
||||||
@@ -46,26 +39,32 @@ struct usbh_hubport *usbh_get_roothub_port(unsigned int port)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CONFIG_USBHOST_MAX_EXTHUBS > 0
|
#if CONFIG_USBHOST_MAX_EXTHUBS > 0
|
||||||
static int usbh_hub_devno_alloc(void)
|
static struct usbh_hub g_hub_class[CONFIG_USBHOST_MAX_EXTHUBS];
|
||||||
|
static uint32_t g_devinuse = 0;
|
||||||
|
|
||||||
|
static struct usbh_hub *usbd_hub_class_alloc(void)
|
||||||
{
|
{
|
||||||
int devno;
|
int devno;
|
||||||
|
|
||||||
for (devno = EXTHUB_FIRST_INDEX; devno < 32; devno++) {
|
for (devno = 0; devno < CONFIG_USBHOST_MAX_EXTHUBS; devno++) {
|
||||||
uint32_t bitno = 1 << devno;
|
if ((g_devinuse & (1 << devno)) == 0) {
|
||||||
if ((g_devinuse & bitno) == 0) {
|
g_devinuse |= (1 << devno);
|
||||||
g_devinuse |= bitno;
|
memset(&g_hub_class[devno], 0, sizeof(struct usbh_hub));
|
||||||
return devno;
|
g_hub_class[devno].index = EXTHUB_FIRST_INDEX + devno;
|
||||||
|
return &g_hub_class[devno];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return NULL;
|
||||||
return -EMFILE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usbh_hub_devno_free(uint8_t devno)
|
static void usbd_hub_class_free(struct usbh_hub *hub_class)
|
||||||
{
|
{
|
||||||
if (devno >= EXTHUB_FIRST_INDEX && devno < 32) {
|
int devno = hub_class->index - EXTHUB_FIRST_INDEX;
|
||||||
|
|
||||||
|
if (devno >= 0 && devno < 32) {
|
||||||
g_devinuse &= ~(1 << devno);
|
g_devinuse &= ~(1 << devno);
|
||||||
}
|
}
|
||||||
|
memset(hub_class, 0, sizeof(struct usbh_hub));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -309,21 +308,15 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
struct usb_endpoint_descriptor *ep_desc;
|
struct usb_endpoint_descriptor *ep_desc;
|
||||||
struct hub_port_status port_status;
|
struct hub_port_status port_status;
|
||||||
int ret;
|
int ret;
|
||||||
int index;
|
|
||||||
|
|
||||||
index = usbh_hub_devno_alloc();
|
struct usbh_hub *hub = usbd_hub_class_alloc();
|
||||||
if (index > (CONFIG_USBHOST_MAX_EXTHUBS + EXTHUB_FIRST_INDEX - 1)) {
|
if (hub == NULL) {
|
||||||
USB_LOG_ERR("No memory to alloc hub class\r\n");
|
USB_LOG_ERR("Fail to alloc cdc_acm_class\r\n");
|
||||||
usbh_hub_devno_free(index);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct usbh_hub *hub = &exthub[index - EXTHUB_FIRST_INDEX];
|
|
||||||
|
|
||||||
memset(hub, 0, sizeof(struct usbh_hub));
|
|
||||||
hub->hub_addr = hport->dev_addr;
|
hub->hub_addr = hport->dev_addr;
|
||||||
hub->parent = hport;
|
hub->parent = hport;
|
||||||
hub->index = index;
|
|
||||||
|
|
||||||
hport->config.intf[intf].priv = hub;
|
hport->config.intf[intf].priv = hub;
|
||||||
|
|
||||||
@@ -394,8 +387,6 @@ static int usbh_hub_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
struct usbh_hub *hub = (struct usbh_hub *)hport->config.intf[intf].priv;
|
struct usbh_hub *hub = (struct usbh_hub *)hport->config.intf[intf].priv;
|
||||||
|
|
||||||
if (hub) {
|
if (hub) {
|
||||||
usbh_hub_devno_free(hub->index);
|
|
||||||
|
|
||||||
if (hub->intin) {
|
if (hub->intin) {
|
||||||
usbh_pipe_free(hub->intin);
|
usbh_pipe_free(hub->intin);
|
||||||
}
|
}
|
||||||
@@ -413,11 +404,12 @@ static int usbh_hub_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
child->parent = NULL;
|
child->parent = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
usbh_hub_unregister(hub);
|
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||||
memset(hub, 0, sizeof(struct usbh_hub));
|
|
||||||
|
|
||||||
if (hport->config.intf[intf].devname[0] != '\0')
|
|
||||||
USB_LOG_INFO("Unregister HUB Class:%s\r\n", hport->config.intf[intf].devname);
|
USB_LOG_INFO("Unregister HUB Class:%s\r\n", hport->config.intf[intf].devname);
|
||||||
|
usbh_hub_unregister(hub);
|
||||||
|
}
|
||||||
|
|
||||||
|
usbd_hub_class_free(hub);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,33 +9,34 @@
|
|||||||
|
|
||||||
#define DEV_FORMAT "/dev/sd%c"
|
#define DEV_FORMAT "/dev/sd%c"
|
||||||
|
|
||||||
static uint32_t g_devinuse = 0;
|
|
||||||
|
|
||||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_msc_buf[32];
|
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_msc_buf[32];
|
||||||
|
|
||||||
static int usbh_msc_devno_alloc(struct usbh_msc *msc_class)
|
static struct usbh_msc g_msc_class[CONFIG_USBHOST_MAX_MSC_CLASS];
|
||||||
|
static uint32_t g_devinuse = 0;
|
||||||
|
|
||||||
|
static struct usbh_msc *usbd_msc_class_alloc(void)
|
||||||
{
|
{
|
||||||
int devno;
|
int devno;
|
||||||
|
|
||||||
for (devno = 0; devno < 26; devno++) {
|
for (devno = 0; devno < CONFIG_USBHOST_MAX_MSC_CLASS; devno++) {
|
||||||
uint32_t bitno = 1 << devno;
|
if ((g_devinuse & (1 << devno)) == 0) {
|
||||||
if ((g_devinuse & bitno) == 0) {
|
g_devinuse |= (1 << devno);
|
||||||
g_devinuse |= bitno;
|
memset(&g_msc_class[devno], 0, sizeof(struct usbh_msc));
|
||||||
msc_class->sdchar = 'a' + devno;
|
g_msc_class[devno].sdchar = 'a' + devno;
|
||||||
return 0;
|
return &g_msc_class[devno];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return NULL;
|
||||||
return -EMFILE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usbh_msc_devno_free(struct usbh_msc *msc_class)
|
static void usbd_msc_class_free(struct usbh_msc *msc_class)
|
||||||
{
|
{
|
||||||
int devno = msc_class->sdchar - 'a';
|
int devno = msc_class->sdchar - 'a';
|
||||||
|
|
||||||
if (devno >= 0 && devno < 26) {
|
if (devno >= 0 && devno < 32) {
|
||||||
g_devinuse &= ~(1 << devno);
|
g_devinuse &= ~(1 << devno);
|
||||||
}
|
}
|
||||||
|
memset(msc_class, 0, sizeof(struct usbh_msc));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usbh_msc_get_maxlun(struct usbh_msc *msc_class, uint8_t *buffer)
|
static int usbh_msc_get_maxlun(struct usbh_msc *msc_class, uint8_t *buffer)
|
||||||
@@ -278,14 +279,12 @@ static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
struct usb_endpoint_descriptor *ep_desc;
|
struct usb_endpoint_descriptor *ep_desc;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
struct usbh_msc *msc_class = usb_malloc(sizeof(struct usbh_msc));
|
struct usbh_msc *msc_class = usbd_msc_class_alloc();
|
||||||
if (msc_class == NULL) {
|
if (msc_class == NULL) {
|
||||||
USB_LOG_ERR("Fail to alloc msc_class\r\n");
|
USB_LOG_ERR("Fail to alloc msc_class\r\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(msc_class, 0, sizeof(struct usbh_msc));
|
|
||||||
usbh_msc_devno_alloc(msc_class);
|
|
||||||
msc_class->hport = hport;
|
msc_class->hport = hport;
|
||||||
msc_class->intf = intf;
|
msc_class->intf = intf;
|
||||||
|
|
||||||
@@ -349,8 +348,6 @@ static int usbh_msc_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
struct usbh_msc *msc_class = (struct usbh_msc *)hport->config.intf[intf].priv;
|
struct usbh_msc *msc_class = (struct usbh_msc *)hport->config.intf[intf].priv;
|
||||||
|
|
||||||
if (msc_class) {
|
if (msc_class) {
|
||||||
usbh_msc_devno_free(msc_class);
|
|
||||||
|
|
||||||
if (msc_class->bulkin) {
|
if (msc_class->bulkin) {
|
||||||
usbh_pipe_free(msc_class->bulkin);
|
usbh_pipe_free(msc_class->bulkin);
|
||||||
}
|
}
|
||||||
@@ -364,8 +361,7 @@ static int usbh_msc_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
usbh_msc_stop(msc_class);
|
usbh_msc_stop(msc_class);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(msc_class, 0, sizeof(struct usbh_msc));
|
usbd_msc_class_free(msc_class);
|
||||||
usb_free(msc_class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -8,6 +8,34 @@
|
|||||||
|
|
||||||
#define DEV_FORMAT "/dev/printer"
|
#define DEV_FORMAT "/dev/printer"
|
||||||
|
|
||||||
|
static struct usbh_printer g_printer_class[CONFIG_USBHOST_MAX_PRINTER_CLASS];
|
||||||
|
static uint32_t g_devinuse = 0;
|
||||||
|
|
||||||
|
static struct usbh_printer *usbd_printer_class_alloc(void)
|
||||||
|
{
|
||||||
|
int devno;
|
||||||
|
|
||||||
|
for (devno = 0; devno < CONFIG_USBHOST_MAX_PRINTER_CLASS; devno++) {
|
||||||
|
if ((g_devinuse & (1 << devno)) == 0) {
|
||||||
|
g_devinuse |= (1 << devno);
|
||||||
|
memset(&g_printer_class[devno], 0, sizeof(struct usbh_printer));
|
||||||
|
g_printer_class[devno].minor = devno;
|
||||||
|
return &g_printer_class[devno];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void usbd_printer_class_free(struct usbh_printer *printer_class)
|
||||||
|
{
|
||||||
|
int devno = printer_class->minor;
|
||||||
|
|
||||||
|
if (devno >= 0 && devno < 32) {
|
||||||
|
g_devinuse &= ~(1 << devno);
|
||||||
|
}
|
||||||
|
memset(printer_class, 0, sizeof(struct usbh_printer));
|
||||||
|
}
|
||||||
|
|
||||||
static int usbh_printer_get_device_id(struct usbh_printer *printer_class, uint8_t *buffer)
|
static int usbh_printer_get_device_id(struct usbh_printer *printer_class, uint8_t *buffer)
|
||||||
{
|
{
|
||||||
struct usb_setup_packet *setup = &printer_class->hport->setup;
|
struct usb_setup_packet *setup = &printer_class->hport->setup;
|
||||||
@@ -56,14 +84,12 @@ static int usbh_printer_connect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
struct usb_endpoint_descriptor *ep_desc;
|
struct usb_endpoint_descriptor *ep_desc;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
struct usbh_printer *printer_class = usb_malloc(sizeof(struct usbh_printer));
|
struct usbh_printer *printer_class = usbd_printer_class_alloc();
|
||||||
if (printer_class == NULL) {
|
if (printer_class == NULL) {
|
||||||
USB_LOG_ERR("Fail to alloc printer_class\r\n");
|
USB_LOG_ERR("Fail to alloc printer_class\r\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(printer_class, 0, sizeof(struct usbh_printer));
|
|
||||||
|
|
||||||
printer_class->hport = hport;
|
printer_class->hport = hport;
|
||||||
printer_class->intf = intf;
|
printer_class->intf = intf;
|
||||||
|
|
||||||
@@ -107,8 +133,7 @@ static int usbh_printer_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
USB_LOG_INFO("Unregister Printer Class:%s\r\n", hport->config.intf[intf].devname);
|
USB_LOG_INFO("Unregister Printer Class:%s\r\n", hport->config.intf[intf].devname);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(printer_class, 0, sizeof(struct usbh_printer));
|
usbd_printer_class_free(printer_class);
|
||||||
usb_free(printer_class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ struct usbh_printer {
|
|||||||
struct usbh_hubport *hport;
|
struct usbh_hubport *hport;
|
||||||
|
|
||||||
uint8_t intf; /* interface number */
|
uint8_t intf; /* interface number */
|
||||||
|
uint8_t minor;
|
||||||
usbh_pipe_t bulkin; /* BULK IN endpoint */
|
usbh_pipe_t bulkin; /* BULK IN endpoint */
|
||||||
usbh_pipe_t bulkout; /* BULK OUT endpoint */
|
usbh_pipe_t bulkout; /* BULK OUT endpoint */
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,43 +3,47 @@
|
|||||||
|
|
||||||
#define DEV_FORMAT "/dev/xxx"
|
#define DEV_FORMAT "/dev/xxx"
|
||||||
|
|
||||||
|
static struct usbh_xxx g_xxx_class[CONFIG_USBHOST_MAX_CUSTOM_CLASS];
|
||||||
|
static uint32_t g_devinuse = 0;
|
||||||
|
|
||||||
|
static struct usbh_xxx *usbd_xxx_class_alloc(void)
|
||||||
|
{
|
||||||
|
int devno;
|
||||||
|
|
||||||
|
for (devno = 0; devno < CONFIG_USBHOST_MAX_CUSTOM_CLASS; devno++) {
|
||||||
|
if ((g_devinuse & (1 << devno)) == 0) {
|
||||||
|
g_devinuse |= (1 << devno);
|
||||||
|
memset(&g_xxx_class[devno], 0, sizeof(struct usbh_xxx));
|
||||||
|
g_xxx_class[devno].minor = devno;
|
||||||
|
return &g_xxx_class[devno];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void usbd_xxx_class_free(struct usbh_xxx *xxx_class)
|
||||||
|
{
|
||||||
|
int devno = xxx_class->minor;
|
||||||
|
|
||||||
|
if (devno >= 0 && devno < 32) {
|
||||||
|
g_devinuse &= ~(1 << devno);
|
||||||
|
}
|
||||||
|
memset(xxx_class, 0, sizeof(struct usbh_xxx));
|
||||||
|
}
|
||||||
|
|
||||||
static int usbh_xxx_connect(struct usbh_hubport *hport, uint8_t intf)
|
static int usbh_xxx_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||||
{
|
{
|
||||||
struct usbh_endpoint_cfg ep_cfg = { 0 };
|
struct usbh_endpoint_cfg ep_cfg = { 0 };
|
||||||
struct usb_endpoint_descriptor *ep_desc;
|
struct usb_endpoint_descriptor *ep_desc;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
struct usbh_xxx *xxx_class = usb_malloc(sizeof(struct usbh_xxx));
|
struct usbh_xxx *xxx_class = usbd_xxx_class_alloc();
|
||||||
if (xxx_class == NULL) {
|
if (xxx_class == NULL) {
|
||||||
USB_LOG_ERR("Fail to alloc xxx_class\r\n");
|
USB_LOG_ERR("Fail to alloc xxx_class\r\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(xxx_class, 0, sizeof(struct usbh_xxx));
|
|
||||||
|
|
||||||
xxx_class->hport = hport;
|
|
||||||
xxx_class->intf = intf;
|
|
||||||
|
|
||||||
hport->config.intf[intf].priv = xxx_class;
|
|
||||||
strncpy(hport->config.intf[intf].devname, DEV_FORMAT, CONFIG_USBHOST_DEV_NAMELEN);
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < hport->config.intf[intf + 1].intf_desc.bNumEndpoints; i++) {
|
|
||||||
ep_desc = &hport->config.intf[intf + 1].ep[i].ep_desc;
|
|
||||||
|
|
||||||
ep_cfg.ep_addr = ep_desc->bEndpointAddress;
|
|
||||||
ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK;
|
|
||||||
ep_cfg.ep_mps = ep_desc->wMaxPacketSize;
|
|
||||||
ep_cfg.ep_interval = ep_desc->bInterval;
|
|
||||||
ep_cfg.hport = hport;
|
|
||||||
if (ep_desc->bEndpointAddress & 0x80) {
|
|
||||||
usbh_pipe_alloc(&rndis_class->bulkin, &ep_cfg);
|
|
||||||
} else {
|
|
||||||
usbh_pipe_alloc(&rndis_class->bulkout, &ep_cfg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -58,17 +62,24 @@ static int usbh_xxx_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
usbh_pipe_free(xxx_class->bulkout);
|
usbh_pipe_free(xxx_class->bulkout);
|
||||||
}
|
}
|
||||||
|
|
||||||
usb_free(xxx_class);
|
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||||
|
USB_LOG_INFO("Unregister xxx Class:%s\r\n", hport->config.intf[intf].devname);
|
||||||
|
usbh_xxx_stop(xxx_class);
|
||||||
|
}
|
||||||
|
|
||||||
USB_LOG_INFO("Unregister xxx Class:%s\r\n", hport->config.intf[intf].devname);
|
usbd_xxx_class_free(xxx_class);
|
||||||
memset(hport->config.intf[intf].devname, 0, CONFIG_USBHOST_DEV_NAMELEN);
|
|
||||||
|
|
||||||
hport->config.intf[intf].priv = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__WEAK void usbh_xxx_run(struct usbh_xxx *xxx_class)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
__WEAK void usbh_xxx_stop(struct usbh_xxx *xxx_class)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
static const struct usbh_class_driver xxx_class_driver = {
|
static const struct usbh_class_driver xxx_class_driver = {
|
||||||
.driver_name = "xxx",
|
.driver_name = "xxx",
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ struct usbh_xxx {
|
|||||||
struct usbh_hubport *hport;
|
struct usbh_hubport *hport;
|
||||||
|
|
||||||
uint8_t intf; /* interface number */
|
uint8_t intf; /* interface number */
|
||||||
usbh_pipe_t intin; /* INTR IN endpoint */
|
uint8_t minor;
|
||||||
usbh_pipe_t intout; /* INTR OUT endpoint */
|
usbh_pipe_t bulkin; /* bulk IN endpoint */
|
||||||
|
usbh_pipe_t bulkout; /* bulk OUT endpoint */
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -21,35 +21,36 @@
|
|||||||
#define INTF_DESC_bInterfaceNumber 2 /** Interface number offset */
|
#define INTF_DESC_bInterfaceNumber 2 /** Interface number offset */
|
||||||
#define INTF_DESC_bAlternateSetting 3 /** Alternate setting offset */
|
#define INTF_DESC_bAlternateSetting 3 /** Alternate setting offset */
|
||||||
|
|
||||||
static uint32_t g_devinuse = 0;
|
|
||||||
|
|
||||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_video_buf[128];
|
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_video_buf[128];
|
||||||
|
|
||||||
static const char *format_type[] = { "uncompressed", "mjpeg" };
|
static const char *format_type[] = { "uncompressed", "mjpeg" };
|
||||||
|
|
||||||
static int usbh_video_devno_alloc(struct usbh_video *video_class)
|
static struct usbh_video g_video_class[CONFIG_USBHOST_MAX_VIDEO_CLASS];
|
||||||
|
static uint32_t g_devinuse = 0;
|
||||||
|
|
||||||
|
static struct usbh_video *usbd_video_class_alloc(void)
|
||||||
{
|
{
|
||||||
int devno;
|
int devno;
|
||||||
|
|
||||||
for (devno = 0; devno < 32; devno++) {
|
for (devno = 0; devno < CONFIG_USBHOST_MAX_VIDEO_CLASS; devno++) {
|
||||||
uint32_t bitno = 1 << devno;
|
if ((g_devinuse & (1 << devno)) == 0) {
|
||||||
if ((g_devinuse & bitno) == 0) {
|
g_devinuse |= (1 << devno);
|
||||||
g_devinuse |= bitno;
|
memset(&g_video_class[devno], 0, sizeof(struct usbh_video));
|
||||||
video_class->minor = devno;
|
g_video_class[devno].minor = devno;
|
||||||
return 0;
|
return &g_video_class[devno];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return NULL;
|
||||||
return -EMFILE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usbh_video_devno_free(struct usbh_video *video_class)
|
static void usbd_video_class_free(struct usbh_video *video_class)
|
||||||
{
|
{
|
||||||
int devno = video_class->minor;
|
int devno = video_class->minor;
|
||||||
|
|
||||||
if (devno >= 0 && devno < 32) {
|
if (devno >= 0 && devno < 32) {
|
||||||
g_devinuse &= ~(1 << devno);
|
g_devinuse &= ~(1 << devno);
|
||||||
}
|
}
|
||||||
|
memset(video_class, 0, sizeof(struct usbh_video));
|
||||||
}
|
}
|
||||||
|
|
||||||
int usbh_video_get_cur(struct usbh_video *video_class, uint8_t intf, uint8_t entity_id, uint8_t cs, uint8_t *buf, uint16_t len)
|
int usbh_video_get_cur(struct usbh_video *video_class, uint8_t intf, uint8_t entity_id, uint8_t cs, uint8_t *buf, uint16_t len)
|
||||||
@@ -292,14 +293,12 @@ static int usbh_video_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
uint8_t num_of_frames = 0xff;
|
uint8_t num_of_frames = 0xff;
|
||||||
uint8_t *p;
|
uint8_t *p;
|
||||||
|
|
||||||
struct usbh_video *video_class = usb_malloc(sizeof(struct usbh_video));
|
struct usbh_video *video_class = usbd_video_class_alloc();
|
||||||
if (video_class == NULL) {
|
if (video_class == NULL) {
|
||||||
USB_LOG_ERR("Fail to alloc video_class\r\n");
|
USB_LOG_ERR("Fail to alloc video_class\r\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(video_class, 0, sizeof(struct usbh_video));
|
|
||||||
usbh_video_devno_alloc(video_class);
|
|
||||||
video_class->hport = hport;
|
video_class->hport = hport;
|
||||||
video_class->ctrl_intf = intf;
|
video_class->ctrl_intf = intf;
|
||||||
video_class->data_intf = intf + 1;
|
video_class->data_intf = intf + 1;
|
||||||
@@ -401,8 +400,6 @@ static int usbh_video_ctrl_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
struct usbh_video *video_class = (struct usbh_video *)hport->config.intf[intf].priv;
|
struct usbh_video *video_class = (struct usbh_video *)hport->config.intf[intf].priv;
|
||||||
|
|
||||||
if (video_class) {
|
if (video_class) {
|
||||||
usbh_video_devno_free(video_class);
|
|
||||||
|
|
||||||
if (video_class->isoin) {
|
if (video_class->isoin) {
|
||||||
usbh_pipe_free(video_class->isoin);
|
usbh_pipe_free(video_class->isoin);
|
||||||
}
|
}
|
||||||
@@ -416,8 +413,7 @@ static int usbh_video_ctrl_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
usbh_video_stop(video_class);
|
usbh_video_stop(video_class);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(video_class, 0, sizeof(struct usbh_video));
|
usbd_video_class_free(video_class);
|
||||||
usb_free(video_class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -7,10 +7,38 @@
|
|||||||
#include "usbh_rndis.h"
|
#include "usbh_rndis.h"
|
||||||
#include "rndis_protocol.h"
|
#include "rndis_protocol.h"
|
||||||
|
|
||||||
#define DEV_FORMAT "/dev/rndis"
|
#define DEV_FORMAT "/dev/rndis%d"
|
||||||
|
|
||||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rndis_buf[4096];
|
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rndis_buf[4096];
|
||||||
|
|
||||||
|
static struct usbh_rndis g_rndis_class[CONFIG_USBHOST_MAX_RNDIS_CLASS];
|
||||||
|
static uint32_t g_devinuse = 0;
|
||||||
|
|
||||||
|
static struct usbh_rndis *usbd_rndis_class_alloc(void)
|
||||||
|
{
|
||||||
|
int devno;
|
||||||
|
|
||||||
|
for (devno = 0; devno < CONFIG_USBHOST_MAX_RNDIS_CLASS; devno++) {
|
||||||
|
if ((g_devinuse & (1 << devno)) == 0) {
|
||||||
|
g_devinuse |= (1 << devno);
|
||||||
|
memset(&g_rndis_class[devno], 0, sizeof(struct usbh_rndis));
|
||||||
|
g_rndis_class[devno].minor = devno;
|
||||||
|
return &g_rndis_class[devno];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void usbd_rndis_class_free(struct usbh_rndis *rndis_class)
|
||||||
|
{
|
||||||
|
int devno = rndis_class->minor;
|
||||||
|
|
||||||
|
if (devno >= 0 && devno < 32) {
|
||||||
|
g_devinuse &= ~(1 << devno);
|
||||||
|
}
|
||||||
|
memset(rndis_class, 0, sizeof(struct usbh_rndis));
|
||||||
|
}
|
||||||
|
|
||||||
static int usbh_rndis_init_msg_transfer(struct usbh_rndis *rndis_class)
|
static int usbh_rndis_init_msg_transfer(struct usbh_rndis *rndis_class)
|
||||||
{
|
{
|
||||||
struct usb_setup_packet *setup = rndis_class->hport->setup;
|
struct usb_setup_packet *setup = rndis_class->hport->setup;
|
||||||
@@ -242,14 +270,12 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
uint8_t tmp_buffer[512];
|
uint8_t tmp_buffer[512];
|
||||||
uint8_t data[32];
|
uint8_t data[32];
|
||||||
|
|
||||||
struct usbh_rndis *rndis_class = usb_malloc(sizeof(struct usbh_rndis));
|
struct usbh_rndis *rndis_class = usbd_rndis_class_alloc();
|
||||||
if (rndis_class == NULL) {
|
if (rndis_class == NULL) {
|
||||||
USB_LOG_ERR("Fail to alloc rndis_class\r\n");
|
USB_LOG_ERR("Fail to alloc rndis_class\r\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(rndis_class, 0, sizeof(struct usbh_rndis));
|
|
||||||
|
|
||||||
rndis_class->hport = hport;
|
rndis_class->hport = hport;
|
||||||
rndis_class->ctrl_intf = intf;
|
rndis_class->ctrl_intf = intf;
|
||||||
rndis_class->data_intf = intf + 1;
|
rndis_class->data_intf = intf + 1;
|
||||||
@@ -363,7 +389,7 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
}
|
}
|
||||||
USB_LOG_INFO("rndis set OID_802_3_MULTICAST_LIST success\r\n");
|
USB_LOG_INFO("rndis set OID_802_3_MULTICAST_LIST success\r\n");
|
||||||
|
|
||||||
strncpy(hport->config.intf[intf].devname, DEV_FORMAT, CONFIG_USBHOST_DEV_NAMELEN);
|
snprintf(hport->config.intf[intf].devname, CONFIG_USBHOST_DEV_NAMELEN, DEV_FORMAT, rndis_class->minor);
|
||||||
|
|
||||||
USB_LOG_INFO("Register RNDIS Class:%s\r\n", hport->config.intf[intf].devname);
|
USB_LOG_INFO("Register RNDIS Class:%s\r\n", hport->config.intf[intf].devname);
|
||||||
usbh_rndis_run(rndis_class);
|
usbh_rndis_run(rndis_class);
|
||||||
@@ -393,8 +419,7 @@ static int usbh_rndis_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
|||||||
usbh_rndis_stop(rndis_class);
|
usbh_rndis_stop(rndis_class);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(rndis_class, 0, sizeof(struct usbh_rndis));
|
usbd_rndis_class_free(rndis_class);
|
||||||
usb_free(rndis_class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ struct usbh_rndis {
|
|||||||
|
|
||||||
uint8_t ctrl_intf; /* Control interface number */
|
uint8_t ctrl_intf; /* Control interface number */
|
||||||
uint8_t data_intf; /* Data interface number */
|
uint8_t data_intf; /* Data interface number */
|
||||||
|
uint8_t minor;
|
||||||
usbh_pipe_t bulkin; /* Bulk IN endpoint */
|
usbh_pipe_t bulkin; /* Bulk IN endpoint */
|
||||||
usbh_pipe_t bulkout; /* Bulk OUT endpoint */
|
usbh_pipe_t bulkout; /* Bulk OUT endpoint */
|
||||||
usbh_pipe_t intin; /* Notify endpoint */
|
usbh_pipe_t intin; /* Notify endpoint */
|
||||||
|
|||||||
Reference in New Issue
Block a user