diff options
author | Amir Hammad <amir.hammad@hotmail.com> | 2016-07-30 12:24:20 +0200 |
---|---|---|
committer | Amir Hammad <amir.hammad@hotmail.com> | 2016-07-30 12:24:20 +0200 |
commit | 3e95b389c37046759cbe9df2e671240ec5666ad8 (patch) | |
tree | bca91eed95fab4b392426f6b8fa2efd8a0758a29 | |
parent | 0c1bd8ff76fbe191b7eb136d371ef30fc83c8eb0 (diff) | |
download | secure-hid-3e95b389c37046759cbe9df2e671240ec5666ad8.tar.gz secure-hid-3e95b389c37046759cbe9df2e671240ec5666ad8.tar.bz2 secure-hid-3e95b389c37046759cbe9df2e671240ec5666ad8.zip |
add option to pass data to control writes
Signed-off-by: Amir Hammad <amir.hammad@hotmail.com>
-rw-r--r-- | include/driver/usbh_device_driver.h | 10 | ||||
-rw-r--r-- | src/usbh_core.c | 33 | ||||
-rw-r--r-- | src/usbh_driver_ac_midi.c | 2 | ||||
-rw-r--r-- | src/usbh_driver_gp_xbox.c | 2 | ||||
-rw-r--r-- | src/usbh_driver_hid_mouse.c | 2 | ||||
-rw-r--r-- | src/usbh_driver_hub.c | 25 | ||||
-rw-r--r-- | src/usbh_lld_stm32f4.c | 18 |
7 files changed, 60 insertions, 32 deletions
diff --git a/include/driver/usbh_device_driver.h b/include/driver/usbh_device_driver.h index 690044c..9307f77 100644 --- a/include/driver/usbh_device_driver.h +++ b/include/driver/usbh_device_driver.h @@ -56,6 +56,11 @@ enum USBH_POLL_STATUS { USBH_POLL_STATUS_DEVICE_DISCONNECTED }; +enum USBH_CONTROL_TYPE { + USBH_CONTROL_TYPE_SETUP, + USBH_CONTROL_TYPE_DATA +}; + /** * @brief The _usbh_device struct * @@ -121,6 +126,8 @@ struct _usbh_packet { */ uint8_t endpoint_type; + enum USBH_CONTROL_TYPE control_type; + /// Endpoint number 0..15 uint8_t endpoint_address; @@ -210,7 +217,8 @@ void usbh_write(usbh_device_t *dev, const usbh_packet_t *packet); /* Helper functions used by device drivers */ void device_xfer_control_read(void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev); -void device_xfer_control_write(void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev); +void device_xfer_control_write_setup(void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev); +void device_xfer_control_write_data(void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev); END_DECLS diff --git a/src/usbh_core.c b/src/usbh_core.c index 82f080f..c14fbe4 100644 --- a/src/usbh_core.c +++ b/src/usbh_core.c @@ -198,7 +198,7 @@ void usbh_init(const void *low_level_drivers[], const usbh_dev_driver_t * const * NEW ENUMERATE * */ -void device_xfer_control_write(void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev) +void device_xfer_control_write_setup(void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev) { usbh_packet_t packet; @@ -208,13 +208,34 @@ void device_xfer_control_write(void *data, uint16_t datalen, usbh_packet_callbac packet.endpoint_address = 0; packet.endpoint_size_max = dev->packet_size_max0; packet.endpoint_type = USBH_ENDPOINT_TYPE_CONTROL; + packet.control_type = USBH_CONTROL_TYPE_SETUP; packet.speed = dev->speed; packet.callback = callback; packet.callback_arg = dev; packet.toggle = &dev->toggle0; usbh_write(dev, &packet); - LOG_PRINTF("WR@device...%d | \n", dev->address); + LOG_PRINTF("WR-setup@device...%d \n", dev->address); +} + +void device_xfer_control_write_data(void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev) +{ + usbh_packet_t packet; + + packet.data = data; + packet.datalen = datalen; + packet.address = dev->address; + packet.endpoint_address = 0; + packet.endpoint_size_max = dev->packet_size_max0; + packet.endpoint_type = USBH_ENDPOINT_TYPE_CONTROL; + packet.control_type = USBH_CONTROL_TYPE_DATA; + packet.speed = dev->speed; + packet.callback = callback; + packet.callback_arg = dev; + packet.toggle = &dev->toggle0; + + usbh_write(dev, &packet); + LOG_PRINTF("WR-data@device...%d \n", dev->address); } void device_xfer_control_read(void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev) @@ -323,7 +344,7 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ setup_data.wLength = USB_DT_DEVICE_SIZE; dev->state++; - device_xfer_control_write(&setup_data, sizeof(setup_data), + device_xfer_control_write_setup(&setup_data, sizeof(setup_data), device_enumerate, dev); break; @@ -380,7 +401,7 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ setup_data.wLength = ddt->bMaxPacketSize0;//USB_DT_CONFIGURATION_SIZE; dev->state++; - device_xfer_control_write(&setup_data, sizeof(setup_data), + device_xfer_control_write_setup(&setup_data, sizeof(setup_data), device_enumerate, dev); } break; @@ -443,7 +464,7 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ setup_data.wLength = cdt->wTotalLength; dev->state++; - device_xfer_control_write(&setup_data, sizeof(setup_data), + device_xfer_control_write_setup(&setup_data, sizeof(setup_data), device_enumerate, dev); } break; @@ -558,7 +579,7 @@ void device_enumeration_start(usbh_device_t *dev) setup_data.wIndex = 0; setup_data.wLength = 0; - device_xfer_control_write(&setup_data, sizeof(setup_data), + device_xfer_control_write_setup(&setup_data, sizeof(setup_data), device_enumerate, dev); } diff --git a/src/usbh_driver_ac_midi.c b/src/usbh_driver_ac_midi.c index c5403d2..413875f 100644 --- a/src/usbh_driver_ac_midi.c +++ b/src/usbh_driver_ac_midi.c @@ -308,7 +308,7 @@ static void midi_poll(void *drvdata, uint32_t t_us) midi->state++; - device_xfer_control_write(&setup_data, sizeof(setup_data), event, dev); + device_xfer_control_write_setup(&setup_data, sizeof(setup_data), event, dev); } break; } diff --git a/src/usbh_driver_gp_xbox.c b/src/usbh_driver_gp_xbox.c index d8bb1b2..ddd62de 100644 --- a/src/usbh_driver_gp_xbox.c +++ b/src/usbh_driver_gp_xbox.c @@ -372,7 +372,7 @@ static void poll(void *drvdata, uint32_t time_curr_us) gp_xbox->state_next = STATE_SET_CONFIGURATION_EMPTY_READ; - device_xfer_control_write(&setup_data, sizeof(setup_data), event, dev); + device_xfer_control_write_setup(&setup_data, sizeof(setup_data), event, dev); } break; diff --git a/src/usbh_driver_hid_mouse.c b/src/usbh_driver_hid_mouse.c index 62ba481..94f232d 100644 --- a/src/usbh_driver_hid_mouse.c +++ b/src/usbh_driver_hid_mouse.c @@ -261,7 +261,7 @@ static void poll(void *drvdata, uint32_t time_curr_us) mouse->state_next = STATE_SET_CONFIGURATION_EMPTY_READ; - device_xfer_control_write(&setup_data, sizeof(setup_data), event, dev); + device_xfer_control_write_setup(&setup_data, sizeof(setup_data), event, dev); } break; diff --git a/src/usbh_driver_hub.c b/src/usbh_driver_hub.c index 9f061b5..a26d7d0 100644 --- a/src/usbh_driver_hub.c +++ b/src/usbh_driver_hub.c @@ -204,7 +204,7 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) hub->current_port = port;
LOG_PRINTF("\n\nPORT FOUND: %d\n", port);
- device_xfer_control_write(&setup_data, sizeof(setup_data), event, dev);
+ device_xfer_control_write_setup(&setup_data, sizeof(setup_data), event, dev);
}
break;
@@ -265,7 +265,7 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) setup_data.wLength = hub->desc_len;
hub->state++;
- device_xfer_control_write(&setup_data, sizeof(setup_data), event, dev);
+ device_xfer_control_write_setup(&setup_data, sizeof(setup_data), event, dev);
LOG_PRINTF("DO Need to get HUB DESC\n");
}
break;
@@ -316,7 +316,7 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) setup_data.wLength = hub->desc_len;
hub->state = 4;
- device_xfer_control_write(&setup_data, sizeof(setup_data), event, dev);
+ device_xfer_control_write_setup(&setup_data, sizeof(setup_data), event, dev);
break;
} else if (hub_descriptor->head.bDescLength == hub->desc_len) {
hub->ports_num = hub_descriptor->head.bNbrPorts;
@@ -382,7 +382,7 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) hub->state_after_empty_read = hub->state;
hub->state = EMPTY_PACKET_READ_STATE;
- device_xfer_control_write(&setup_data, sizeof(setup_data), event, dev);
+ device_xfer_control_write_setup(&setup_data, sizeof(setup_data), event, dev);
} else {
hub->state++;
// TODO:
@@ -419,7 +419,7 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) setup_data.wLength = 4;
hub->state++;
- device_xfer_control_write(&setup_data, sizeof(setup_data), event, dev);
+ device_xfer_control_write_setup(&setup_data, sizeof(setup_data), event, dev);
}
break;
@@ -449,6 +449,7 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) }
}
break;
+
case 9:
{
switch (cb_data.status) {
@@ -464,7 +465,7 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) hub->state++;
- device_xfer_control_write(&setup_data, sizeof(setup_data), event, dev);
+ device_xfer_control_write_setup(&setup_data, sizeof(setup_data), event, dev);
}
break;
@@ -476,6 +477,7 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) }
}
break;
+
case 10:
{
switch (cb_data.status) {
@@ -492,6 +494,7 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) }
}
break;
+
case 11:
{
switch (cb_data.status) {
@@ -582,7 +585,7 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) hub->state_after_empty_read = 33;
hub->state = EMPTY_PACKET_READ_STATE;
- device_xfer_control_write(&setup_data, sizeof(setup_data), event, dev);
+ device_xfer_control_write_setup(&setup_data, sizeof(setup_data), event, dev);
} else if(stc & (1<<HUB_FEATURE_PORT_RESET)) {
// clear feature C_PORT_RESET
@@ -599,7 +602,7 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) hub->state = EMPTY_PACKET_READ_STATE;
LOG_PRINTF("RESET");
- device_xfer_control_write(&setup_data, sizeof(setup_data), event, dev);
+ device_xfer_control_write_setup(&setup_data, sizeof(setup_data), event, dev);
} else {
LOG_PRINTF("another STC %d\n", stc);
}
@@ -643,7 +646,7 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) LOG_PRINTF("CONN");
hub->busy = 1;
- device_xfer_control_write(&setup_data, sizeof(setup_data), event, dev);
+ device_xfer_control_write_setup(&setup_data, sizeof(setup_data), event, dev);
}
} else {
LOG_PRINTF("\t\t\t\tDISCONNECT EVENT\n");
@@ -707,7 +710,7 @@ static void event(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) hub->state = EMPTY_PACKET_READ_STATE;
hub->current_port = CURRENT_PORT_NONE;
- device_xfer_control_write(&setup_data, sizeof(setup_data), event, dev);
+ device_xfer_control_write_setup(&setup_data, sizeof(setup_data), event, dev);
} else if (!(sts & (1<<(HUB_FEATURE_PORT_LOWSPEED))) &&
!(sts & (1<<(HUB_FEATURE_PORT_HIGHSPEED)))) {
hub->device[port]->speed = USBH_SPEED_FULL;
@@ -799,7 +802,7 @@ static void poll(void *drvdata, uint32_t time_curr_us) hub->state = EMPTY_PACKET_READ_STATE;
hub->state_after_empty_read = 3;
- device_xfer_control_write(&setup_data, sizeof(setup_data), event, dev);
+ device_xfer_control_write_setup(&setup_data, sizeof(setup_data), event, dev);
}
break;
diff --git a/src/usbh_lld_stm32f4.c b/src/usbh_lld_stm32f4.c index 0b12888..6f1d4aa 100644 --- a/src/usbh_lld_stm32f4.c +++ b/src/usbh_lld_stm32f4.c @@ -261,20 +261,16 @@ static void write(void *drvdata, const usbh_packet_t *packet) uint32_t dpid;
if (packet->endpoint_type == USBH_ENDPOINT_TYPE_CONTROL) {
- dpid = OTG_HCTSIZ_DPID_MDATA;
- packet->toggle[0] = 0;
- } else if(packet->endpoint_type == USBH_ENDPOINT_TYPE_INTERRUPT) {
- if (packet->toggle[0]) {
- dpid = OTG_HCTSIZ_DPID_DATA1;
+ if (packet->control_type == USBH_CONTROL_TYPE_DATA) {
+ dpid = packet->toggle[0] ? OTG_HCTSIZ_DPID_DATA1 : OTG_HCTSIZ_DPID_DATA0;
} else {
- dpid = OTG_HCTSIZ_DPID_DATA0;
+ dpid = OTG_HCTSIZ_DPID_MDATA;
+ packet->toggle[0] = 0;
}
+ } else if(packet->endpoint_type == USBH_ENDPOINT_TYPE_INTERRUPT) {
+ dpid = packet->toggle[0] ? OTG_HCTSIZ_DPID_DATA1 : OTG_HCTSIZ_DPID_DATA0;
} else if (packet->endpoint_type == USBH_ENDPOINT_TYPE_BULK) {
- if (packet->toggle[0]) {
- dpid = OTG_HCTSIZ_DPID_DATA1;
- } else {
- dpid = OTG_HCTSIZ_DPID_DATA0;
- }
+ dpid = packet->toggle[0] ? OTG_HCTSIZ_DPID_DATA1 : OTG_HCTSIZ_DPID_DATA0;
} else {
dpid = OTG_HCTSIZ_DPID_DATA0; // ! TODO: BUG
ERROR("");
|