1: uhs_status_t Usbh_Cdc_SendEncapsulatedCommand(
void* pContext,
2:
PCDC_BUFF_INFO pstData)
3: {
4:
PCDC_DEVICE pCdcDevice;
5: usb_device_request_t* pRequest;
6: CDC_FUNC_STATUS nRetval;
7: uhs_ubit8_t u8CntDeviceId;
8: uhs_status_t nRetStatus;
9: uhs_status_t nRetvalResorce;
10:
11:
12:
13:
14:
if( pContext == NULL ){
15: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR );
16:
return(
USBCDC_API_PARAM_ERROR );
17: }
18:
19:
20:
21:
22:
if( g_pCdcDriver == NULL ) {
23: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_INIT );
24:
return(
USBCDC_API_SYS_SYSTEM_ERROR );
25: }
26:
27:
28:
29:
30:
31: nRetStatus = Usbh_Cdc_CheckDeviceStatus(pContext, &pCdcDevice, &u8CntDeviceId, ID_CLSREQ_DET);
32:
if(nRetStatus !=
USBCDC_API_SUCCESS){
33: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_SYSTEM_ERROR );
34:
return(nRetStatus);
35: }
36:
37:
38:
39:
40:
if( (pstData == NULL) ||
41: (pstData->pu8Buff == NULL) ||
42: (pstData->u32RequestLength == 0) ) {
43: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR );
44:
45:
46: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
47:
return(
USBCDC_API_PARAM_ERROR );
48: }
49:
50:
51:
52:
53:
if( (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_CONNECTING) ||
54: (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_REGIST) ) {
55:
56:
57: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
58: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_USE );
59:
return(
USBCDC_API_NOT_READY );
60: }
61:
else if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_NO_SUPPORT ) {
62:
63:
64: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
65: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NO_SUPPORT );
66:
return(
USBCDC_API_NO_SUPPORT );
67: }
68:
else {
69: ;
70: }
71:
72:
73:
74:
75: pRequest = CdcUtils_Malloc(
sizeof(usb_device_request_t));
76:
if(pRequest == NULL) {
77: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
78: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
79:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
80: }
81:
82:
83:
84:
85: pRequest->bmRequestType = 0x21;
86: pRequest->bRequest = 0x00;
87: pRequest->wValue0 = 0x00;
88: pRequest->wValue1 = 0x00;
89: pRequest->wIndex0 = 0x00;
90: pRequest->wIndex1 = 0x00;
91: pRequest->wLength0 = UNPACK16_LITTLE_ENDIAN_LSB( pstData->u32RequestLength );
92: pRequest->wLength1 = UNPACK16_LITTLE_ENDIAN_MSB( pstData->u32RequestLength );
93:
94:
95:
96:
97: nRetval = Usbh_Cdc_ForCommand(pCdcDevice, pRequest, pstData->pu8Buff, &pstData->u32ActualLength);
98:
if(nRetval != CDC_FUNC_STATUS_SUCCESS){
99: CdcUtils_Free(pRequest);
100:
101:
102: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
103: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_FAILED_CLSREQ );
104:
return(
USBCDC_API_TRANS_CLSREQ_FAILED );
105: }
106:
107:
108:
109:
110: CdcUtils_Free(pRequest);
111:
112:
113:
114:
115: nRetvalResorce = CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
116:
if(nRetvalResorce != TRUE){
117:
118: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
119:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
120: }
121:
122:
return(
USBCDC_API_SUCCESS );
123: }