1: uhs_status_t Usbh_Cdc_GetCommFeature(
void* pContext,
2:
PCDC_COMM_FEATURE 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:
42:
43: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
44: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR );
45:
return(
USBCDC_API_PARAM_ERROR );
46: }
47:
if( (pstData->FeatureSelector != COMM_FEATURE_SELECTOR_ABSTRACT_STATE) &&
48: (pstData->FeatureSelector != COMM_FEATURE_SELECTOR_COUNTRY_SETTING) ) {
49:
50:
51: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
52: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR );
53:
return(
USBCDC_API_PARAM_ERROR );
54: }
55:
56:
57:
58:
59:
if( (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_CONNECTING) ||
60: (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_REGIST) ) {
61:
62:
63: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
64: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_USE );
65:
return(
USBCDC_API_NOT_READY );
66: }
67:
else if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_NO_SUPPORT ) {
68:
69:
70: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
71: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NO_SUPPORT );
72:
return(
USBCDC_API_NO_SUPPORT );
73: }
74:
else {
75: ;
76: }
77:
78:
79:
80:
81: pRequest = CdcUtils_Malloc(
sizeof(usb_device_request_t));
82:
if(pRequest == NULL) {
83: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
84: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
85:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
86: }
87:
88:
89:
90:
91: pRequest->bmRequestType = 0xA1;
92: pRequest->bRequest = 0x03;
93: pRequest->wValue0 = UNPACK16_LITTLE_ENDIAN_LSB( pstData->FeatureSelector );
94: pRequest->wValue1 = UNPACK16_LITTLE_ENDIAN_MSB( pstData->FeatureSelector );
95: pRequest->wIndex0 = 0x00;
96: pRequest->wIndex1 = 0x00;
97: pRequest->wLength0 = UNPACK16_LITTLE_ENDIAN_LSB( 0x0002 );
98: pRequest->wLength1 = UNPACK16_LITTLE_ENDIAN_MSB( 0x0002 );
99:
100:
101:
102:
103: nRetval = Usbh_Cdc_ForCommand(pCdcDevice, pRequest, (uhs_ubit8_t*)(&pstData->u16Data), NULL);
104:
if(nRetval != CDC_FUNC_STATUS_SUCCESS){
105: CdcUtils_Free(pRequest);
106:
107:
108: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
109: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_FAILED_CLSREQ );
110:
return(
USBCDC_API_TRANS_CLSREQ_FAILED );
111: }
112:
113:
114:
115:
116: CdcUtils_Free(pRequest);
117:
118:
119:
120:
121: nRetvalResorce = CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
122:
if(nRetvalResorce != TRUE){
123:
124: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
125:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
126: }
127:
128:
return(
USBCDC_API_SUCCESS );
129: }