1: uhs_status_t Usbh_Cdc_SetCommFeature(
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_ubit8_t *pu8SetBuff;
9: uhs_status_t nRetStatus;
10: uhs_status_t nRetvalResorce;
11:
12:
13:
14:
15:
if( pContext == NULL ){
16: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR );
17:
return(
USBCDC_API_PARAM_ERROR );
18: }
19:
20:
21:
22:
23:
if( g_pCdcDriver == NULL ) {
24: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_INIT );
25:
return(
USBCDC_API_SYS_SYSTEM_ERROR );
26: }
27:
28:
29:
30:
31:
32: nRetStatus = Usbh_Cdc_CheckDeviceStatus(pContext, &pCdcDevice, &u8CntDeviceId, ID_CLSREQ_DET);
33:
if(nRetStatus !=
USBCDC_API_SUCCESS){
34: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_SYSTEM_ERROR );
35:
return(nRetStatus);
36: }
37:
38:
39:
40:
41:
if( pstData == NULL ) {
42:
43:
44: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
45: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR );
46:
return(
USBCDC_API_PARAM_ERROR );
47: }
48:
if( (pstData->FeatureSelector != COMM_FEATURE_SELECTOR_ABSTRACT_STATE) &&
49: (pstData->FeatureSelector != COMM_FEATURE_SELECTOR_COUNTRY_SETTING) ) {
50:
51:
52: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
53: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR );
54:
return(
USBCDC_API_PARAM_ERROR );
55: }
56:
if( (pstData->FeatureSelector == COMM_FEATURE_SELECTOR_ABSTRACT_STATE) &&
57: (pstData->u16Data > 3) ) {
58:
59:
60: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
61: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR );
62:
return(
USBCDC_API_PARAM_ERROR );
63: }
64:
65:
66:
67:
68:
if( (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_CONNECTING) ||
69: (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_REGIST) ) {
70:
71:
72: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
73: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_USE );
74:
return(
USBCDC_API_NOT_READY );
75: }
76:
else if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_NO_SUPPORT ) {
77:
78:
79: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
80: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NO_SUPPORT );
81:
return(
USBCDC_API_NO_SUPPORT );
82: }
83:
else {
84: ;
85: }
86:
87:
88:
89:
90: pRequest = CdcUtils_Malloc(
sizeof(usb_device_request_t));
91:
if(pRequest == NULL) {
92: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
93: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
94:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
95: }
96:
97:
98:
99:
100: pu8SetBuff = CdcUtils_Malloc(2);
101:
if(pu8SetBuff == NULL) {
102: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
103: CdcUtils_Free(pRequest);
104: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
105: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
106:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
107: }
108:
109:
110:
111:
112: pRequest->bmRequestType = 0x21;
113: pRequest->bRequest = 0x02;
114: pRequest->wValue0 = UNPACK16_LITTLE_ENDIAN_LSB( pstData->FeatureSelector );
115: pRequest->wValue1 = UNPACK16_LITTLE_ENDIAN_MSB( pstData->FeatureSelector );
116: pRequest->wIndex0 = 0x00;
117: pRequest->wIndex1 = 0x00;
118: pRequest->wLength0 = UNPACK16_LITTLE_ENDIAN_LSB( 0x0002 );
119: pRequest->wLength1 = UNPACK16_LITTLE_ENDIAN_MSB( 0x0002 );
120:
121:
122:
123:
124: pu8SetBuff[0] = UNPACK16_LITTLE_ENDIAN_LSB( pstData->u16Data );
125: pu8SetBuff[1] = UNPACK16_LITTLE_ENDIAN_MSB( pstData->u16Data );
126:
127:
128:
129:
130: nRetval = Usbh_Cdc_ForCommand(pCdcDevice, pRequest, pu8SetBuff, NULL);
131:
if(nRetval != CDC_FUNC_STATUS_SUCCESS){
132: CdcUtils_Free(pu8SetBuff);
133: CdcUtils_Free(pRequest);
134:
135:
136: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
137: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_FAILED_CLSREQ );
138:
return(
USBCDC_API_TRANS_CLSREQ_FAILED );
139: }
140:
141:
142:
143:
144: CdcUtils_Free(pu8SetBuff);
145:
146:
147:
148:
149: CdcUtils_Free(pRequest);
150:
151:
152:
153:
154: nRetvalResorce = CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
155:
if(nRetvalResorce != TRUE){
156:
157: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
158:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
159: }
160:
161:
return(
USBCDC_API_SUCCESS );
162: }