Fix NDIS oid query

This commit is contained in:
Arti Zirk 2022-06-30 22:55:25 +03:00
parent 2feca930eb
commit d27077245b
2 changed files with 21 additions and 26 deletions

View File

@ -10,7 +10,7 @@ int main(void) {
usbd_device *usbd_dev; usbd_device *usbd_dev;
SEGGER_RTT_printf(0, "Hello World\n"); SEGGER_RTT_printf(0, "\nHello World\n");
rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE8_72MHZ]); rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE8_72MHZ]);

View File

@ -160,8 +160,7 @@ static const char *usb_strings[] = {
static void rndis_query_cmplt32(uint8_t **buf, uint32_t status, uint32_t data) static void rndis_query_cmplt32(uint8_t **buf, uint32_t status, uint32_t data)
{ {
rndis_query_cmplt_t *c; rndis_query_cmplt_t *c = (rndis_query_cmplt_t *)*buf;
c = (rndis_query_cmplt_t *)buf;
c->MessageType = REMOTE_NDIS_QUERY_CMPLT; c->MessageType = REMOTE_NDIS_QUERY_CMPLT;
c->MessageLength = sizeof(rndis_query_cmplt_t) + 4; c->MessageLength = sizeof(rndis_query_cmplt_t) + 4;
c->Status = status; c->Status = status;
@ -171,8 +170,7 @@ static void rndis_query_cmplt32(uint8_t **buf, uint32_t status, uint32_t data)
} }
static void rndis_query_cmplt(uint8_t **buf, uint32_t status, const void *data, uint32_t size){ static void rndis_query_cmplt(uint8_t **buf, uint32_t status, const void *data, uint32_t size){
rndis_query_cmplt_t *c; rndis_query_cmplt_t *c = (rndis_query_cmplt_t *)*buf;
c = (rndis_query_cmplt_t *)buf;
c->MessageType = REMOTE_NDIS_QUERY_CMPLT; c->MessageType = REMOTE_NDIS_QUERY_CMPLT;
c->MessageLength = sizeof(rndis_query_cmplt_t) + size; c->MessageLength = sizeof(rndis_query_cmplt_t) + size;
c->Status = status; c->Status = status;
@ -191,15 +189,19 @@ static void rndis_handle_query(uint8_t **buf, uint16_t *len)
} u; } u;
u.buf = *buf; u.buf = *buf;
SEGGER_RTT_printf(0, "NDIS Query oid: 0x%08x, len: 0x%02x\n", u.get->Oid, u.get->InformationBufferLength); SEGGER_RTT_printf(0, "NDIS Query oid: 0x%08x, len: 0x%02x\n", u.get->Oid, u.get->InformationBufferLength);
switch (u.get->Oid) switch (u.get->Oid)
{ {
case OID_GEN_PHYSICAL_MEDIUM: case OID_GEN_PHYSICAL_MEDIUM:
//rndis_query_cmplt32(buf, RNDIS_STATUS_SUCCESS, NDIS_MEDIUM_802_3); rndis_query_cmplt32(buf, RNDIS_STATUS_SUCCESS, NDIS_MEDIUM_802_3);
return; return;
case OID_802_3_PERMANENT_ADDRESS: case OID_802_3_PERMANENT_ADDRESS:
//rndis_query_cmplt(buf, RNDIS_STATUS_SUCCESS, &permanent_hwaddr, sizeof(permanent_hwaddr)); rndis_query_cmplt(buf, RNDIS_STATUS_SUCCESS, &permanent_hwaddr, sizeof(permanent_hwaddr));
return;
default:
rndis_query_cmplt(buf, RNDIS_STATUS_FAILURE, NULL, 0);
return; return;
} }
} }
@ -207,6 +209,9 @@ static void rndis_handle_query(uint8_t **buf, uint16_t *len)
static enum usbd_request_return_codes rndis_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, static enum usbd_request_return_codes rndis_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf,
uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req)) uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
{ {
(void)req;
(void)complete;
union { union {
void *buf; void *buf;
rndis_generic_msg_t *header; rndis_generic_msg_t *header;
@ -216,6 +221,7 @@ static enum usbd_request_return_codes rndis_control_request(usbd_device *usbd_de
rndis_query_cmplt_t *get_c; rndis_query_cmplt_t *get_c;
rndis_set_msg_t *set; rndis_set_msg_t *set;
rndis_set_cmplt_t *set_c; rndis_set_cmplt_t *set_c;
rndis_indicate_status_t *indic;
} u; } u;
//SEGGER_RTT_printf(0, "bmRequestType: 0x%02x, bRequest: 0x%02x\n", req->bmRequestType, req->bRequest); //SEGGER_RTT_printf(0, "bmRequestType: 0x%02x, bRequest: 0x%02x\n", req->bmRequestType, req->bRequest);
@ -224,11 +230,11 @@ static enum usbd_request_return_codes rndis_control_request(usbd_device *usbd_de
switch (u.header->MessageType) switch (u.header->MessageType)
{ {
case REMOTE_NDIS_INITIALIZE_MSG: case REMOTE_NDIS_INITIALIZE_MSG:
//SEGGER_RTT_printf(0, "NDIS Init: HOST Ver %d.%d, Max MTU: %dbytes \n", u.init->MajorVersion, u.init->MinorVersion, u.init->MaxTransferSize); SEGGER_RTT_printf(0, "NDIS Init: HOST Ver %d.%d, Max MTU: %dbytes \n", u.init->MajorVersion, u.init->MinorVersion, u.init->MaxTransferSize);
u.init_c->MessageType = REMOTE_NDIS_INITIALIZE_CMPLT; u.init_c->MessageType = REMOTE_NDIS_INITIALIZE_CMPLT;
return USBD_REQ_HANDLED; return USBD_REQ_HANDLED;
case REMOTE_NDIS_INITIALIZE_CMPLT: case REMOTE_NDIS_INITIALIZE_CMPLT:
//SEGGER_RTT_printf(0, "NDIS Init complete, MTU: %d\n", RNDIS_RX_BUFFER_SIZE); SEGGER_RTT_printf(0, "NDIS Init complete, MTU: %d\n", RNDIS_RX_BUFFER_SIZE);
u.init_c->MessageType = REMOTE_NDIS_INITIALIZE_CMPLT; u.init_c->MessageType = REMOTE_NDIS_INITIALIZE_CMPLT;
u.init_c->MessageLength = sizeof(rndis_initialize_cmplt_t); u.init_c->MessageLength = sizeof(rndis_initialize_cmplt_t);
// u.int_c->RequestId stays the same // u.int_c->RequestId stays the same
@ -246,29 +252,14 @@ static enum usbd_request_return_codes rndis_control_request(usbd_device *usbd_de
usbd_ep_write_packet(usbd_dev, 0x83, "\x01\x00\x00\x00\x00\x00\x00\x00", 8); usbd_ep_write_packet(usbd_dev, 0x83, "\x01\x00\x00\x00\x00\x00\x00\x00", 8);
return USBD_REQ_HANDLED; return USBD_REQ_HANDLED;
case REMOTE_NDIS_QUERY_MSG: case REMOTE_NDIS_QUERY_MSG:
SEGGER_RTT_printf(0, "NDIS Query oid: 0x%08x, len: 0x%02x\n", u.get->Oid, u.get->InformationBufferLength); rndis_handle_query(buf, len);
if (u.get->Oid == OID_GEN_PHYSICAL_MEDIUM) {
u.get_c->MessageType = REMOTE_NDIS_QUERY_CMPLT;
u.get_c->MessageLength = sizeof(rndis_query_cmplt_t) + 4;
u.get_c->Status = RNDIS_STATUS_SUCCESS;
u.get_c->InformationBufferLength = 4;
u.get_c->InformationBufferOffset = 16;
*(uint32_t *)(u.get_c + 1) = 0x0;
} else if (u.get->Oid == OID_802_3_PERMANENT_ADDRESS) {
u.get_c->MessageType = REMOTE_NDIS_QUERY_CMPLT;
u.get_c->MessageLength = sizeof(rndis_query_cmplt_t) + sizeof(permanent_hwaddr);
u.get_c->Status = RNDIS_STATUS_SUCCESS;
u.get_c->InformationBufferLength = sizeof(permanent_hwaddr);
u.get_c->InformationBufferOffset = 16;
memcpy(u.get_c + 1, &permanent_hwaddr, sizeof(permanent_hwaddr));
}
//rndis_handle_query(buf, len);
usbd_ep_write_packet(usbd_dev, 0x83, "\x01\x00\x00\x00\x00\x00\x00\x00", 8); usbd_ep_write_packet(usbd_dev, 0x83, "\x01\x00\x00\x00\x00\x00\x00\x00", 8);
//*len = u.get_c->MessageLength; //*len = u.get_c->MessageLength;
return USBD_REQ_HANDLED; return USBD_REQ_HANDLED;
case REMOTE_NDIS_QUERY_CMPLT: case REMOTE_NDIS_QUERY_CMPLT:
SEGGER_RTT_printf(0, "NDIS Query complete\n"); SEGGER_RTT_printf(0, "NDIS Query complete\n");
*len = u.get_c->MessageLength; *len = u.get_c->MessageLength;
usbd_ep_write_packet(usbd_dev, 0x83, "\x01\x00\x00\x00\x00\x00\x00\x00", 8);
return USBD_REQ_HANDLED; return USBD_REQ_HANDLED;
case REMOTE_NDIS_SET_MSG: case REMOTE_NDIS_SET_MSG:
SEGGER_RTT_printf(0, "NDIS Set oid: 0x%08x, len 0x%02x\n", u.set->Oid, u.set->InformationBufferLength); SEGGER_RTT_printf(0, "NDIS Set oid: 0x%08x, len 0x%02x\n", u.set->Oid, u.set->InformationBufferLength);
@ -281,6 +272,7 @@ static enum usbd_request_return_codes rndis_control_request(usbd_device *usbd_de
case REMOTE_NDIS_SET_CMPLT: case REMOTE_NDIS_SET_CMPLT:
SEGGER_RTT_printf(0, "NDIS Set complete\n"); SEGGER_RTT_printf(0, "NDIS Set complete\n");
*len = u.set_c->MessageLength; *len = u.set_c->MessageLength;
usbd_ep_write_packet(usbd_dev, 0x83, "\x01\x00\x00\x00\x00\x00\x00\x00", 8);
return USBD_REQ_HANDLED; return USBD_REQ_HANDLED;
} }
SEGGER_RTT_printf(0, "NDIS unknown MessageType: 0x%08x, MessageLength: %d, max len: %d\n", u.header->MessageType, u.header->MessageLength, *len); SEGGER_RTT_printf(0, "NDIS unknown MessageType: 0x%08x, MessageLength: %d, max len: %d\n", u.header->MessageType, u.header->MessageLength, *len);
@ -289,6 +281,8 @@ static enum usbd_request_return_codes rndis_control_request(usbd_device *usbd_de
static void rndis_data_rx_cb(usbd_device *usbd_dev, uint8_t ep) static void rndis_data_rx_cb(usbd_device *usbd_dev, uint8_t ep)
{ {
(void)ep;
char buf[64]; char buf[64];
int len = usbd_ep_read_packet(usbd_dev, 0x01, buf, 64); int len = usbd_ep_read_packet(usbd_dev, 0x01, buf, 64);
@ -306,6 +300,7 @@ static void rndis_set_config(usbd_device *usbd_dev, uint16_t wValue)
usbd_ep_setup(usbd_dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64, rndis_data_rx_cb); usbd_ep_setup(usbd_dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64, rndis_data_rx_cb);
usbd_ep_setup(usbd_dev, 0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL); usbd_ep_setup(usbd_dev, 0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
// Interrupt endpoint is used to only send notification that some data is ready to read
usbd_ep_setup(usbd_dev, 0x83, USB_ENDPOINT_ATTR_INTERRUPT, 8, NULL); usbd_ep_setup(usbd_dev, 0x83, USB_ENDPOINT_ATTR_INTERRUPT, 8, NULL);
usbd_register_control_callback(usbd_dev, usbd_register_control_callback(usbd_dev,