mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-30 04:20:26 +00:00
extract send message & wait & get complete message to send_message_get_response_subtask
This commit is contained in:
parent
03873135a9
commit
3b12917fb0
@ -239,6 +239,22 @@ typedef struct {
|
||||
#define OID_802_3_MULTICAST_LIST 0x01010103
|
||||
#define OID_802_3_MAXIMUM_LIST_SIZE 0x01010104
|
||||
|
||||
//
|
||||
// Ndis Packet Filter Bits (OID_GEN_CURRENT_PACKET_FILTER).
|
||||
//
|
||||
#define NDIS_PACKET_TYPE_DIRECTED 0x00000001
|
||||
#define NDIS_PACKET_TYPE_MULTICAST 0x00000002
|
||||
#define NDIS_PACKET_TYPE_ALL_MULTICAST 0x00000004
|
||||
#define NDIS_PACKET_TYPE_BROADCAST 0x00000008
|
||||
#define NDIS_PACKET_TYPE_SOURCE_ROUTING 0x00000010
|
||||
#define NDIS_PACKET_TYPE_PROMISCUOUS 0x00000020
|
||||
#define NDIS_PACKET_TYPE_SMT 0x00000040
|
||||
#define NDIS_PACKET_TYPE_ALL_LOCAL 0x00000080
|
||||
#define NDIS_PACKET_TYPE_GROUP 0x00001000
|
||||
#define NDIS_PACKET_TYPE_ALL_FUNCTIONAL 0x00002000
|
||||
#define NDIS_PACKET_TYPE_FUNCTIONAL 0x00004000
|
||||
#define NDIS_PACKET_TYPE_MAC_FRAME 0x00008000
|
||||
#define NDIS_PACKET_TYPE_NO_LOCAL 0x00010000
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -65,6 +65,9 @@ STATIC_ rndish_data_t rndish_data[TUSB_CFG_HOST_DEVICE_MAX];
|
||||
// INTERNAL OBJECT & FUNCTION DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
static tusb_error_t rndis_body_subtask(void);
|
||||
static tusb_error_t send_message_get_response_subtask( uint8_t dev_addr, cdch_data_t *p_cdc,
|
||||
uint8_t const * p_mess, uint32_t mess_length,
|
||||
uint8_t *p_response , uint32_t* response_length );
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// IMPLEMENTATION
|
||||
@ -125,7 +128,7 @@ tusb_error_t rndish_open_subtask(uint8_t dev_addr, cdch_data_t *p_cdc)
|
||||
|
||||
OSAL_SUBTASK_BEGIN
|
||||
|
||||
//------------- Send RNDIS Message Initialize -------------//
|
||||
//------------- Message Initialize -------------//
|
||||
*((rndis_msg_initialize_t*) msg_payload) = (rndis_msg_initialize_t)
|
||||
{
|
||||
.type = RNDIS_MSG_INITIALIZE,
|
||||
@ -136,26 +139,12 @@ tusb_error_t rndish_open_subtask(uint8_t dev_addr, cdch_data_t *p_cdc)
|
||||
.max_xfer_size = 0x4000 // TODO mimic windows
|
||||
};
|
||||
|
||||
uint32_t response_length;
|
||||
OSAL_SUBTASK_INVOKED_AND_WAIT(
|
||||
usbh_control_xfer_subtask( dev_addr, bm_request_type(TUSB_DIR_HOST_TO_DEV, TUSB_REQUEST_TYPE_CLASS, TUSB_REQUEST_RECIPIENT_INTERFACE),
|
||||
SEND_ENCAPSULATED_COMMAND, 0, p_cdc->interface_number,
|
||||
sizeof(rndis_msg_initialize_t), (uint8_t*) msg_payload ),
|
||||
error
|
||||
);
|
||||
if ( TUSB_ERROR_NONE != error ) SUBTASK_EXIT(error);
|
||||
|
||||
//------------- waiting for Response Available notification -------------//
|
||||
(void) hcd_pipe_xfer(p_cdc->pipe_notification, msg_notification[dev_addr-1], 8, true);
|
||||
osal_semaphore_wait(rndish_data[dev_addr-1].sem_notification_hdl, OSAL_TIMEOUT_NORMAL, &error);
|
||||
if ( TUSB_ERROR_NONE != error ) SUBTASK_EXIT(error);
|
||||
SUBTASK_ASSERT(msg_notification[dev_addr-1][0] == 1);
|
||||
|
||||
//------------- Get RNDIS Message Initialize Complete -------------//
|
||||
OSAL_SUBTASK_INVOKED_AND_WAIT(
|
||||
usbh_control_xfer_subtask( dev_addr, bm_request_type(TUSB_DIR_DEV_TO_HOST, TUSB_REQUEST_TYPE_CLASS, TUSB_REQUEST_RECIPIENT_INTERFACE),
|
||||
GET_ENCAPSULATED_RESPONSE, 0, p_cdc->interface_number,
|
||||
RNDIS_MSG_PAYLOAD_MAX, (uint8_t*) msg_payload ),
|
||||
error
|
||||
send_message_get_response_subtask( dev_addr, p_cdc,
|
||||
(uint8_t*) msg_payload, sizeof(rndis_msg_initialize_t),
|
||||
(uint8_t*) msg_payload, &response_length),
|
||||
error
|
||||
);
|
||||
if ( TUSB_ERROR_NONE != error ) SUBTASK_EXIT(error);
|
||||
|
||||
@ -166,6 +155,7 @@ tusb_error_t rndish_open_subtask(uint8_t dev_addr, cdch_data_t *p_cdc)
|
||||
p_init_cmpt->max_packet_per_xfer == 1 && p_init_cmpt->max_xfer_size <= RNDIS_MSG_PAYLOAD_MAX);
|
||||
rndish_data[dev_addr-1].max_xfer_size = p_init_cmpt->max_xfer_size;
|
||||
|
||||
//------------- Message Initialize -------------//
|
||||
|
||||
|
||||
if ( tusbh_cdc_rndis_mounted_cb )
|
||||
@ -184,4 +174,64 @@ void rndish_xfer_isr(cdch_data_t *p_cdc, pipe_handle_t pipe_hdl, tusb_event_t ev
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL & HELPER
|
||||
//--------------------------------------------------------------------+
|
||||
//static tusb_error_t send_process_msg_initialize_subtask(uint8_t dev_addr, cdch_data_t *p_cdc)
|
||||
//{
|
||||
// tusb_error_t error;
|
||||
//
|
||||
// OSAL_SUBTASK_BEGIN
|
||||
//
|
||||
// *((rndis_msg_initialize_t*) msg_payload) = (rndis_msg_initialize_t)
|
||||
// {
|
||||
// .type = RNDIS_MSG_INITIALIZE,
|
||||
// .length = sizeof(rndis_msg_initialize_t),
|
||||
// .request_id = 1, // TODO should use some magic number
|
||||
// .major_version = 1,
|
||||
// .minor_version = 0,
|
||||
// .max_xfer_size = 0x4000 // TODO mimic windows
|
||||
// };
|
||||
//
|
||||
//
|
||||
//
|
||||
// OSAL_SUBTASK_END
|
||||
//}
|
||||
|
||||
static tusb_error_t send_message_get_response_subtask( uint8_t dev_addr, cdch_data_t *p_cdc,
|
||||
uint8_t const * p_mess, uint32_t mess_length,
|
||||
uint8_t *p_response , uint32_t* response_length )
|
||||
{
|
||||
tusb_error_t error;
|
||||
|
||||
OSAL_SUBTASK_BEGIN
|
||||
|
||||
//------------- Send RNDIS Control Message -------------//
|
||||
OSAL_SUBTASK_INVOKED_AND_WAIT(
|
||||
usbh_control_xfer_subtask( dev_addr, bm_request_type(TUSB_DIR_HOST_TO_DEV, TUSB_REQUEST_TYPE_CLASS, TUSB_REQUEST_RECIPIENT_INTERFACE),
|
||||
SEND_ENCAPSULATED_COMMAND, 0, p_cdc->interface_number,
|
||||
mess_length, p_mess),
|
||||
error
|
||||
);
|
||||
if ( TUSB_ERROR_NONE != error ) SUBTASK_EXIT(error);
|
||||
|
||||
//------------- waiting for Response Available notification -------------//
|
||||
(void) hcd_pipe_xfer(p_cdc->pipe_notification, msg_notification[dev_addr-1], 8, true);
|
||||
osal_semaphore_wait(rndish_data[dev_addr-1].sem_notification_hdl, OSAL_TIMEOUT_NORMAL, &error);
|
||||
if ( TUSB_ERROR_NONE != error ) SUBTASK_EXIT(error);
|
||||
SUBTASK_ASSERT(msg_notification[dev_addr-1][0] == 1);
|
||||
|
||||
//------------- Get RNDIS Message Initialize Complete -------------//
|
||||
OSAL_SUBTASK_INVOKED_AND_WAIT(
|
||||
usbh_control_xfer_subtask( dev_addr, bm_request_type(TUSB_DIR_DEV_TO_HOST, TUSB_REQUEST_TYPE_CLASS, TUSB_REQUEST_RECIPIENT_INTERFACE),
|
||||
GET_ENCAPSULATED_RESPONSE, 0, p_cdc->interface_number,
|
||||
RNDIS_MSG_PAYLOAD_MAX, p_response),
|
||||
error
|
||||
);
|
||||
if ( TUSB_ERROR_NONE != error ) SUBTASK_EXIT(error);
|
||||
|
||||
|
||||
OSAL_SUBTASK_END
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -210,7 +210,6 @@ tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, uint8_t bmRequestType,
|
||||
/*SUBTASK_ASSERT_STATUS*/ (void) ( hcd_pipe_control_xfer(dev_addr, &usbh_devices[dev_addr].control.request, data) );
|
||||
|
||||
osal_semaphore_wait(usbh_devices[dev_addr].control.sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // careful of local variable without static
|
||||
|
||||
osal_mutex_release(usbh_devices[dev_addr].control.mutex_hdl);
|
||||
|
||||
// TODO make handler for this function general purpose
|
||||
|
Loading…
x
Reference in New Issue
Block a user