Skip to content

Commit

Permalink
parse error
Browse files Browse the repository at this point in the history
  • Loading branch information
acagliano committed Jan 18, 2024
1 parent 9a570d6 commit 3f42185
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
49 changes: 25 additions & 24 deletions src/ecm.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,53 +223,54 @@ usb_error_t ecm_init(void)
// use this to set configuration
ecm_device.usb.config.addr = &descriptor.conf;
ecm_device.usb.config.len = desc_len;
parse_state = PARSE_AWAIT_CS_INTERFACE;
parse_state = PARSE_AWAIT_MAC_ADDR;
}
}
}
break;
case USB_CS_INTERFACE_DESCRIPTOR:
// this is a class-specific descriptor that specifies the interfaces used by the control interface
{
if ((parse_state == PARSE_AWAIT_CS_INTERFACE) || (parse_state == PARSE_AWAIT_MAC_ADDR))
usb_cs_interface_descriptor_t *cs = (usb_cs_interface_descriptor_t *)desc;
if ((parse_state == PARSE_AWAIT_MAC_ADDR) && (cs->bDescriptorSubType == USB_ETHERNET_FUNCTIONAL_DESCRIPTOR))
{
usb_cs_interface_descriptor_t *cs = (usb_cs_interface_descriptor_t *)desc;
if (cs->bDescriptorSubType == USB_ETHERNET_FUNCTIONAL_DESCRIPTOR)
{
// if ethernet functional type, contains ethernet configuration data
usb_ethernet_functional_descriptor_t *eth = (usb_ethernet_functional_descriptor_t *)cs;
size_t xferd_tmp;
uint8_t mac_str[12];
usb_GetStringDescriptor(ecm_device.usb.device, eth->iMacAddress, 0,
mac_str, 12, &xferd_tmp);
// convert to bytearray and save to ecm_device.usb.mac_addr
for (int i = 0; i < 6; i++)
ecm_device.usb.mac_addr[i] = nibble(mac_str[2 * i]) << 4 | nibble(mac_str[2 * i + 1]);
}
else if (cs->bDescriptorSubType == USB_UNION_FUNCTIONAL_DESCRIPTOR)
{
// if union functional type, this contains interface number for bulk transfer
usb_union_functional_descriptor_t *func = (usb_union_functional_descriptor_t *)cs;
ifnum = func->bInterface;
parse_state = PARSE_AWAIT_BULK_IF;
}
usb_ethernet_functional_descriptor_t *eth = (usb_ethernet_functional_descriptor_t *)cs;
size_t xferd_tmp;
uint8_t mac_str[12];
usb_GetStringDescriptor(ecm_device.usb.device, eth->iMacAddress, 0,
mac_str, 12, &xferd_tmp);
// convert to bytearray and save to ecm_device.usb.mac_addr
for (int i = 0; i < 6; i++)
ecm_device.usb.mac_addr[i] = nibble(mac_str[2 * i]) << 4 | nibble(mac_str[2 * i + 1]);
parse_state = PARSE_AWAIT_CS_INTERFACE;
}
if ((parse_state == PARSE_AWAIT_CS_INTERFACE) && (cs->bDescriptorSubType == USB_UNION_FUNCTIONAL_DESCRIPTOR))
{

// if union functional type, this contains interface number for bulk transfer
usb_union_functional_descriptor_t *func = (usb_union_functional_descriptor_t *)cs;
ifnum = func->bInterface;
parse_state = PARSE_AWAIT_BULK_IF;
}
break;
}
parsed_len += desc->bLength;
desc = (usb_descriptor_t *)(((uint8_t *)desc) + desc->bLength);
}
parsed_len += desc->bLength;
desc = (usb_descriptor_t *)(((uint8_t *)desc) + desc->bLength);
}
}
printf("device parse fail\n");
return USB_ERROR_NO_DEVICE;
init_success:
printf("got config\n");
if (usb_SetConfiguration(ecm_device.usb.device, ecm_device.usb.config.addr, ecm_device.usb.config.len))
return USB_ERROR_FAILED;
if (usb_SetInterface(ecm_device.usb.device, ecm_device.usb.if_data.addr, ecm_device.usb.if_data.len))
return USB_ERROR_FAILED;
ecm_device.usb.if_data.endpoint.in = usb_GetDeviceEndpoint(ecm_device.usb.device, ecm_device.usb.if_data.endpoint.addr_in);
ecm_device.usb.if_data.endpoint.out = usb_GetDeviceEndpoint(ecm_device.usb.device, ecm_device.usb.if_data.endpoint.addr_out);
ecm_device.status = ECM_READY;
ecm_receive();
return USB_SUCCESS;
}

Expand Down
4 changes: 3 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <ti/screen.h>
#undef NDEBUG
// #include <debug.h>
#include <keypadc.h>
Expand Down Expand Up @@ -39,6 +40,7 @@ my_netif_init(struct netif *netif)

int main(void)
{
os_ClrHomeFull();
// initialize usb hardware
if (usb_Init(ecm_handle_usb_event, NULL, NULL /* descriptors */, USB_DEFAULT_INIT_FLAGS))
return 1;
Expand All @@ -52,6 +54,7 @@ int main(void)
{
// queue ecm_receive
// configure ip addr info
printf("device ready\n");
lwip_init();
ip4_addr_t addr = IPADDR4_INIT_BYTES(192, 168, 25, 2);
ip4_addr_t netmask = IPADDR4_INIT_BYTES(255, 255, 255, 0);
Expand All @@ -65,7 +68,6 @@ int main(void)
netif_set_status_callback(&ecm_device.netif, netif_status_callback);
netif_set_default(&ecm_device.netif);
netif_set_up(&ecm_device.netif);
ecm_receive();
netif_init = true;
}
if (kb_IsDown(kb_KeyClear))
Expand Down

0 comments on commit 3f42185

Please sign in to comment.