AG903ライブラリリファレンス
内容インデックスホーム
前へ上へ次へ
usb_hub.c

USBH HUB (Root/Generic)

USBH HUB (Root/Generic)

none

AXELL CORPORATION

2017_02_22 初版 

2017_10_26 Ver2.0

1: 9: 10: 14: 15: 16: 17: 18: 19: 20: #include "uhs_config.h" 21: #include "usb_hub.h" 22: #include "usbh_api.h" 23: #include "hcd_com.h" 24: #include "usbh_errormon.h" 25: 26: 27: 28: 29: 30: static struct class_driver_reginfo hub_driver_reginfo = {0}; 31: struct usb_hub_driver usb_hub_driver = { {0},{0},{0} }; 32: USB_HUB_STATUS g_usb_hub_stat = USB_HUB_NON_INIT; 33: kernel_context_t usbhub_enum_sem; 34: uhs_ubit32_t g_hub_conn_cnt; 35: 36: static struct usb_class_driver_ids usb_hub_id[] = { 37: 38: { 39: CHECK_DEVCLASS_ID | 40: CHECK_INTCLASS_ID, 41: 0, 42: 0, 43: 0, 44: 0, 45: USB_HUB_CLASSID, 46: 0, 47: 0, 48: USB_HUB_CLASSID, 49: 0, 50: 0, 51: TERMINATE 52: } 53: }; 54: 55: 56: 57: 58: extern kernel_context_t mpl_osc; 59: extern uhs_status_t Usb_Core_GetDescriptor( struct usb_control_block* ucb,struct usbd_usb_deviceinfo* usb_dev, 60: uhs_ubit8_t index, uhs_ubit8_t type, uhs_ubit16_t wIndex, void*buf, uhs_ubit32_t size ); 61: extern uhs_status_t Usbc_Api_StopTrans( struct usb_control_block* ucb ); 62: extern void Usbc_Api_FixupPipeInfo( uhs_ubit32_t* pipe, uhs_ubit8_t usb_addr, uhs_ubit8_t ep_num, uhs_ubit8_t packet_id, 63: uhs_ubit8_t ep_type, uhs_ubit32_t maxpkt_siz ); 64: extern uhs_status_t Usbh_StatusMon_ReportStatus( usb_msgformat stsmsg ); 65: extern uhs_status_t Usb_Hub_PortDevDetach( struct usbd_usb_deviceinfo* usbdev, uhs_ubit8_t port_num ); 66: extern uhs_status_t Usb_Hub_PortDevDetachInHubClass( struct usbd_usb_deviceinfo* usbdev, uhs_ubit8_t port_num ); 67: extern void Usb_Hub_MainThread( void ); 68: 69: 70: 71: 72: uhs_status_t Usb_HubApi_Init( void ); 73: void Usb_HubApi_Exit( void ); 74: uhs_status_t Usb_HubApi_PortDevDetach( struct usbd_usb_deviceinfo* usbdev ); 75: uhs_status_t Usb_HubApi_ClearFeature( struct usb_hub_info* hub_info, uhs_ubit8_t feature, uhs_ubit16_t port_num ); 76: uhs_status_t Usb_HubApi_SetFeature( struct usb_hub_info* hub_info, uhs_ubit8_t feature, uhs_ubit16_t port_num ); 77: uhs_status_t Usb_HubApi_GetStatus( struct usb_hub_info* hub_info, void* buf, uhs_ubit16_t port_num ); 78: uhs_status_t Usb_HubApi_ClearTTBuffer( struct usb_hub_info* hub_info, uhs_ubit16_t tt_port, struct usbd_usb_spliterrinfo *split_err_info); 79: uhs_status_t Usb_HubApi_RESET_TT( struct usb_hub_info* hub_info, uhs_ubit16_t tt_port ); 80: static int Usb_Hub_IntCompleteFunc( int mod_id, int callback_id, void* context ); 81: static int Usb_Hub_CompleteFunc( int mod_id, int callback_id, void* context ); 82: static int Usb_Hub_Attached( int mod_id, int callback_id, void * context ); 83: static int Usb_Hub_Detached( int mod_id, int callback_id, void * context ); 84: static uhs_status_t Usb_Hub_CoverHubinfo( struct usb_hub_info* hub_info ); 85: uhs_status_t Usb_Hub_CheckGetDescriptor( struct usbd_usb_deviceinfo* usbdev ); 86: uhs_status_t Usb_Hub_StartInterrupt( struct usb_hub_info* hub_info ); 87: uhs_status_t Usb_Hub_StopInterrupt( struct usb_hub_info* hub_info ); 88: static uhs_status_t Usb_Hub_IssueClassRequest( struct usb_hub_info* hub_info, uhs_ubit8_t bmRequestType, uhs_ubit8_t bRequest, uhs_ubit16_t wValue, uhs_ubit16_t wIndex, uhs_ubit16_t wLength, uhs_ubit32_t pipe, void* buf ); 89: static uhs_status_t Usb_Hub_GetDescriptor( struct usb_hub_info* hub_info ); 90: uhs_status_t Usb_Hub_ClearFeature( struct usb_hub_info* hub_info, uhs_ubit8_t feature, uhs_ubit16_t port_num ); 91: uhs_status_t Usb_Hub_SetFeature( struct usb_hub_info* hub_info, uhs_ubit8_t feature, uhs_ubit16_t port_num ); 92: uhs_status_t Usb_Hub_GetStatus( struct usb_hub_info* hub_info, void* buf, uhs_ubit16_t port_num ); 93: static uhs_status_t Usb_Hub_PortInitial( struct usb_hub_info* hub_info ); 94: static uhs_status_t Usb_Hub_AllocHubInfo( struct usb_hub_info** hub_info, struct usbd_usb_deviceinfo* usbdev ); 95: static uhs_status_t Usb_Hub_FreeHubInfo( struct usb_hub_info* hub_info ); 96: 97: static uhs_status_t Usb_HubApi_ClearTTBuffer_detail( struct usb_hub_info* hub_info, uhs_ubit16_t tt_port,uhs_ubit8_t err_direction,uhs_ubit16_t err_ep_kind, uhs_ubit16_t err_dev_addr,uhs_ubit16_t err_ep_num); 98: static uhs_ubit16_t Usb_Hub_Make_wValue_for_CTTBUFF( uhs_ubit8_t direction, uhs_ubit16_t ep_kind, uhs_ubit16_t dev_addr, uhs_ubit16_t ep_num ); 99: static uhs_status_t Usb_Hub_ClearTTBuffer( struct usb_hub_info* hub_info, uhs_ubit16_t tt_port, uhs_ubit8_t err_direction, uhs_ubit16_t err_ep_kind, uhs_ubit16_t err_dev_addr, uhs_ubit16_t err_ep_num ); 100: static uhs_status_t Usb_Hub_RESET_TT( struct usb_hub_info* hub_info , uhs_ubit16_t tt_port); 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 126: uhs_status_t Usb_HubApi_Init( void ){ 127: 128: uhs_status_t retval = UDI_OK; 129: 130: 131: 132: 133: if( g_usb_hub_stat != USB_HUB_NON_INIT ){ 134: return UDI_STAT_INVALID_STATE; 135: } 136: 137: 138: 139: 140: retval = kernel_create_thread( 141: &usb_hub_driver.thread_info, 142: (kernel_thread_call_t*)&Usb_Hub_MainThread, 143: (uhs_ubit32_t)THREAD_ON, 144: HUB_TASK_PRI, 145: HUB_TASK_STKSZ 146: ); 147: if( retval != UDI_OK ){ 148: uhs_debug_print( DBG_ERR, ( "USB HUB Create Thread error: ercd=%d", retval ) ); 149: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 150: return retval; 151: } 152: 153: 154: 155: 156: if( g_usb_hub_stat == USB_HUB_ERROR ){ 157: 158: 159: 160: 161: g_usb_hub_stat = USB_HUB_NON_INIT; 162: return UDI_STAT_RESOURCE_UNAVAIL; 163: } 164: 165: 166: 167: 168: hub_driver_reginfo.attach = Usb_Hub_Attached; 169: hub_driver_reginfo.detach = Usb_Hub_Detached; 170: hub_driver_reginfo.id_table = usb_hub_id; 171: 172: hub_driver_reginfo.class_id = USB_CLASS_HUB; 173: 174: 175: 176: retval = Usbc_Api_DriverRegister( &hub_driver_reginfo ); 177: if( retval != UDI_OK ){ 178: 179: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 180: kernel_wait( NULL, 10 ); 181: 182: 183: retval = kernel_exit_thread( &usb_hub_driver.thread_info ); 184: if( retval != UDI_OK ){ 185: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 186: } 187: 188: 189: if( usb_hub_driver.mbx_osc.message.depend.control.mbxid != 0 ){ 190: retval = kernel_delete_message( &usb_hub_driver.mbx_osc, in_interrupt() ); 191: if( retval == UDI_OK ){ 192: 193: usb_hub_driver.mbx_osc.message.depend.control.mbxid = 0; 194: }else{ 195: uhs_debug_print( DBG_ERR, ( "fail:kernel_delete_message" ) ); 196: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 197: } 198: } 199: return UDI_STAT_RESOURCE_UNAVAIL; 200: } 201: 202: g_hub_conn_cnt = 0; 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: g_usb_hub_stat = USB_HUB_IDLE; 214: 215: 216: 217: 218: HUB_REPORT_MILESTONE( USBCLS_HUB_INIT_COMP, 0 , 0 ); 219: 220: return retval; 221: } 222: 223: 233: void Usb_HubApi_Exit( void ){ 234: 235: uhs_status_t retval = UDI_OK; 236: 237: 238: 239: 240: if( g_usb_hub_stat == USB_HUB_EXIT ){ 241: return; 242: } 243: 244: 245: 246: 247: g_usb_hub_stat = USB_HUB_EXIT; 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: retval = kernel_create_event( &usb_hub_driver.evt_osc, FALSE ); 259: if( retval != UDI_OK ){ 260: 261: uhs_debug_print( DBG_ERR, ( "could not create event( Usb_HubApi_Exit() )" ) ); 262: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 263: 264: 265: if( usb_hub_driver.mbx_osc.message.depend.control.mbxid != 0 ){ 266: retval = kernel_delete_message( &usb_hub_driver.mbx_osc, in_interrupt() ); 267: if( retval == UDI_OK ){ 268: 269: usb_hub_driver.mbx_osc.message.depend.control.mbxid = 0; 270: }else{ 271: uhs_debug_print( DBG_ERR, ( "fail:kernel_delete_message" ) ); 272: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 273: } 274: } 275: 276: 277: retval = kernel_exit_thread( &usb_hub_driver.thread_info ); 278: if( retval != UDI_OK ){ 279: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 280: } 281: 282: 283: if( hub_driver_reginfo.id_table != NULL ){ 284: Usbc_Api_DriverUnRegister( &hub_driver_reginfo ); 285: hub_driver_reginfo.attach = NULL; 286: hub_driver_reginfo.detach = NULL; 287: hub_driver_reginfo.id_table = NULL; 288: } 289: g_usb_hub_stat = USB_HUB_NON_INIT; 290: return; 291: } 292: 293: 294: 295: 296: 297: 298: 299: if( Usb_Hub_SendMsg_exit() != UDI_OK ){ 300: 301: uhs_debug_print( DBG_ERR, ( "HUB Exit Notify Sned error: ercd=%d", retval ) ); 302: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 303: 304: 305: retval = kernel_delete_event( &usb_hub_driver.evt_osc ); 306: if( retval != UDI_OK ){ 307: uhs_debug_print( DBG_ERR, ( "fail:kernel_delete_evflg" ) ); 308: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 309: } 310: 311: 312: retval = kernel_exit_thread( &usb_hub_driver.thread_info ); 313: if( retval != UDI_OK ){ 314: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 315: } 316: 317: 318: if( usb_hub_driver.mbx_osc.message.depend.control.mbxid != 0 ){ 319: retval = kernel_delete_message( &usb_hub_driver.mbx_osc, in_interrupt() ); 320: if( retval == UDI_OK ){ 321: 322: usb_hub_driver.mbx_osc.message.depend.control.mbxid = 0; 323: }else{ 324: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 325: } 326: } 327: 328: 329: if( hub_driver_reginfo.id_table != NULL ){ 330: Usbc_Api_DriverUnRegister( &hub_driver_reginfo ); 331: hub_driver_reginfo.attach = NULL; 332: hub_driver_reginfo.detach = NULL; 333: hub_driver_reginfo.id_table = NULL; 334: } 335: g_usb_hub_stat = USB_HUB_NON_INIT; 336: return; 337: } 338: 339: 340: 341: 342: 343: retval = kernel_wait_event( &usb_hub_driver.evt_osc, USB_HUB_ENDTASK_TIMEOUT, in_interrupt() ); 344: if( retval != UDI_OK ){ 345: 346: uhs_debug_print( DBG_ERR, ( "USB HUB Wait error: ercd=%d", retval ) ); 347: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 348: 349: 350: retval = kernel_delete_event( &usb_hub_driver.evt_osc ); 351: if( retval != UDI_OK ){ 352: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 353: } 354: 355: 356: retval = kernel_exit_thread( &usb_hub_driver.thread_info ); 357: if( retval != UDI_OK ){ 358: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 359: } 360: 361: 362: if( usb_hub_driver.mbx_osc.message.depend.control.mbxid != 0 ){ 363: retval = kernel_delete_message( &usb_hub_driver.mbx_osc, in_interrupt() ); 364: if( retval == UDI_OK ){ 365: 366: usb_hub_driver.mbx_osc.message.depend.control.mbxid = 0; 367: }else{ 368: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 369: } 370: } 371: 372: 373: if( hub_driver_reginfo.id_table != NULL ){ 374: Usbc_Api_DriverUnRegister( &hub_driver_reginfo ); 375: hub_driver_reginfo.attach = NULL; 376: hub_driver_reginfo.detach = NULL; 377: hub_driver_reginfo.id_table = NULL; 378: } 379: g_usb_hub_stat = USB_HUB_NON_INIT; 380: return; 381: } 382: 383: 384: 385: 386: if( hub_driver_reginfo.id_table != NULL ){ 387: Usbc_Api_DriverUnRegister( &hub_driver_reginfo ); 388: hub_driver_reginfo.attach = NULL; 389: hub_driver_reginfo.detach = NULL; 390: hub_driver_reginfo.id_table = NULL; 391: } 392: 393: 394: 395: 396: retval = kernel_delete_event( &usb_hub_driver.evt_osc ); 397: if( retval != UDI_OK ){ 398: 399: uhs_debug_print( DBG_ERR, ( "USB HUB Wait error: ercd=%d", retval ) ); 400: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 401: 402: g_usb_hub_stat = USB_HUB_NON_INIT; 403: return; 404: } 405: 406: 407: 408: 409: g_usb_hub_stat = USB_HUB_NON_INIT; 410: 411: 412: 413: 414: HUB_REPORT_MILESTONE( USBCLS_HUB_EXIT_COMP, 0 , 0 ); 415: 416: return; 417: } 418: 419: 420: 421: 422: 423: 432: uhs_status_t Usb_HubApi_PortDevDetach( struct usbd_usb_deviceinfo* usbdev ){ 433: 434: struct usbd_usb_deviceinfo* hubdev = NULL; 435: struct usb_hub_info* hub_info = NULL; 436: uhs_status_t retval = UDI_OK; 437: uhs_ubit16_t sarch_port = 0; 438: 439: 440: 441: 442: if( ( g_usb_hub_stat != USB_HUB_IDLE ) && ( g_usb_hub_stat != USB_HUB_RUN ) ){ 443: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_PortDevDetach: status error" ) ); 444: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_STATUS, 0 ); 445: return UDI_STAT_INVALID_STATE; 446: } 447: 448: 449: 450: 451: if( usbdev == NULL ){ 452: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_PortDevDetach: parameter error" ) ); 453: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 454: return UDI_STAT_DATA_ERROR; 455: } 456: 457: if( usbdev->usbdev_DevNum == 0 ){ 458: 459: return UDI_OK; 460: } 461: 462: hubdev = usbdev->usbdev_UpperHub; 463: if( hubdev != NULL ){ 464: 465: hub_info = (struct usb_hub_info *)hubdev->context; 466: sarch_port = 1; 467: while( hubdev->usbdev_LowerHub[sarch_port] != usbdev ){ 468: 469: if( sarch_port >= hub_info->port_num ){ 470: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_PortDevDetach: parameter error" ) ); 471: HUB_REPORT_WARNING( USBCLS_HUB_INVALID_PARAMETER, 0 ); 472: return UDI_STAT_DATA_ERROR; 473: } 474: sarch_port++; 475: } 476: }else{ 477: sarch_port = 1; 478: 479: } 480: 481: 482: 483: 484: 485: 486: 487: 488: uhs_debug_print( DBG_INFO, ( "PortDevDetach called by external module ( Usb_HubApi_PortDevDetach() )" ) ); 489: 490: retval = Usb_Hub_PortDevDetach( usbdev, sarch_port ); 491: if( retval != UDI_OK ){ 492: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_PortDevDttached: PortDevDetach error" ) ); 493: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 494: } 495: 496: return retval; 497: } 498: 499: 510: uhs_status_t Usb_HubApi_ClearFeature( struct usb_hub_info* hub_info, uhs_ubit8_t feature, uhs_ubit16_t port_num ){ 511: 512: uhs_status_t retval = UDI_OK; 513: uhs_status_t result = UDI_OK; 514: 515: 516: 517: 518: if( ( g_usb_hub_stat != USB_HUB_IDLE ) && ( g_usb_hub_stat != USB_HUB_RUN ) ){ 519: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_ClearFeature: status error" ) ); 520: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_STATUS, 0 ); 521: return UDI_STAT_INVALID_STATE; 522: } 523: 524: 525: 526: 527: if( hub_info == NULL ){ 528: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_ClearFeature: parameter error" ) ); 529: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 530: return UDI_STAT_DATA_ERROR; 531: } 532: if( hub_info->port_num == 0 ){ 533: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_ClearFeature: parameter error" ) ); 534: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 535: return UDI_STAT_DATA_ERROR; 536: } 537: if( hub_info->port_num < port_num ){ 538: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_ClearFeature: parameter error" ) ); 539: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 540: return UDI_STAT_DATA_ERROR; 541: } 542: if( port_num != 0 ){ 543: switch( feature ){ 544: 545: case PORT_ENABLE: 546: case PORT_SUSPEND: 547: 548: 549: case PORT_POWER: 550: 551: case C_PORT_CONNECTION: 552: case C_PORT_ENABLE: 553: case C_PORT_SUSPEND: 554: case C_PORT_OVERCURRENT: 555: case C_PORT_RESET: 556: 557: case PORT_INDICATOR: 558: break; 559: default: 560: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_ClearFeature: parameter error" ) ); 561: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 562: return UDI_STAT_DATA_ERROR; 563: } 564: }else{ 565: switch( feature ){ 566: case C_HUB_LOCAL_POWER: 567: case C_HUB_OVER_CURRENT: 568: break; 569: default: 570: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_ClearFeature: parameter error" ) ); 571: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 572: return UDI_STAT_DATA_ERROR; 573: } 574: } 575: 576: 577: 578: 579: retval = kernel_acquisition_semaphore( &(hub_info->hub_info_sem), USB_HOST_SEMTIMEOUT, in_interrupt() ); 580: if( retval != UDI_OK ){ 581: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_ClearFeature: semaphore error" ) ); 582: HUB_REPORT_WARNING( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 583: return retval; 584: } 585: 586: 587: 588: 589: uhs_debug_print( DBG_INFO, ( "Clear Feature called by external module( Usb_HubApi_ClearFeature() )" ) ); 590: result = Usb_Hub_ClearFeature( hub_info, feature, port_num ); 591: if( result != UDI_OK ){ 592: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_PortDevDttached: PortDevDetach error" ) ); 593: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 594: } 595: 596: 597: 598: 599: retval = kernel_release_semaphore( &(hub_info->hub_info_sem), in_interrupt() ); 600: if( retval != UDI_OK ){ 601: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_ClearFeature: semaphore error" ) ); 602: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 603: 604: if( result == UDI_OK ){ 605: return retval; 606: } 607: } 608: 609: return result; 610: } 611: 612: 623: uhs_status_t Usb_HubApi_SetFeature( struct usb_hub_info* hub_info, uhs_ubit8_t feature, uhs_ubit16_t port_num ){ 624: 625: uhs_status_t retval = UDI_OK; 626: uhs_status_t result = UDI_OK; 627: 628: 629: 630: 631: if( ( g_usb_hub_stat != USB_HUB_IDLE ) && ( g_usb_hub_stat != USB_HUB_RUN ) ){ 632: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_SetFeature: status error" ) ); 633: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_STATUS, 0 ); 634: return UDI_STAT_INVALID_STATE; 635: } 636: 637: 638: 639: 640: if( hub_info == NULL ){ 641: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_SetFeature: parameter error" ) ); 642: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 643: return UDI_STAT_DATA_ERROR; 644: } 645: if( hub_info->port_num == 0 ){ 646: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_SetFeature: parameter error" ) ); 647: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 648: return UDI_STAT_DATA_ERROR; 649: } 650: if( hub_info->port_num < port_num ){ 651: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_SetFeature: parameter error" ) ); 652: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 653: return UDI_STAT_DATA_ERROR; 654: } 655: if( port_num != 0 ){ 656: switch( feature ){ 657: 658: 659: case PORT_SUSPEND: 660: 661: case PORT_RESET: 662: case PORT_POWER: 663: 664: case C_PORT_CONNECTION: 665: case C_PORT_ENABLE: 666: case C_PORT_SUSPEND: 667: case C_PORT_OVERCURRENT: 668: case C_PORT_RESET: 669: case PORT_TEST: 670: case PORT_INDICATOR: 671: break; 672: default: 673: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_SetFeature: parameter error" ) ); 674: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 675: return UDI_STAT_DATA_ERROR; 676: } 677: }else{ 678: switch( feature ){ 679: case C_HUB_LOCAL_POWER: 680: case C_HUB_OVER_CURRENT: 681: break; 682: default: 683: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_SetFeature: parameter error" ) ); 684: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 685: return UDI_STAT_DATA_ERROR; 686: } 687: } 688: 689: 690: 691: 692: retval = kernel_acquisition_semaphore( &(hub_info->hub_info_sem), USB_HOST_SEMTIMEOUT, in_interrupt() ); 693: if( retval != UDI_OK ){ 694: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_SetFeature: semaphore error" ) ); 695: HUB_REPORT_WARNING( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 696: return retval; 697: } 698: 699: 700: 701: 702: uhs_debug_print( DBG_ERR, ( "Set Feature called by external module( Usb_HubApi_SetFeature() )" ) ); 703: result = Usb_Hub_SetFeature( hub_info, feature, port_num ); 704: if( result != UDI_OK ){ 705: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_PortDevDttached: PortDevDetach error" ) ); 706: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 707: } 708: 709: 710: 711: 712: retval = kernel_release_semaphore( &(hub_info->hub_info_sem), in_interrupt() ); 713: if( retval != UDI_OK ){ 714: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_SetFeature: semaphore error" ) ); 715: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 716: 717: if( result == UDI_OK ){ 718: return retval; 719: } 720: } 721: 722: return result; 723: } 724: 725: 737: uhs_status_t Usb_HubApi_GetStatus( struct usb_hub_info* hub_info, void* buf, uhs_ubit16_t port_num ){ 738: 739: uhs_status_t retval = UDI_OK; 740: uhs_status_t result = UDI_OK; 741: 742: 743: 744: 745: if( ( g_usb_hub_stat != USB_HUB_IDLE ) && ( g_usb_hub_stat != USB_HUB_RUN ) ){ 746: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_GetStatus: status error" ) ); 747: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_STATUS, 0 ); 748: return UDI_STAT_INVALID_STATE; 749: } 750: 751: 752: 753: 754: if( ( hub_info == NULL ) || ( buf == NULL ) ){ 755: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_GetStatus: parameter error" ) ); 756: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 757: return UDI_STAT_DATA_ERROR; 758: } 759: if( hub_info->port_num < port_num ){ 760: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_GetFeature: parameter error" ) ); 761: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 762: return UDI_STAT_DATA_ERROR; 763: } 764: 765: 766: 767: 768: retval = kernel_acquisition_semaphore( &(hub_info->hub_info_sem), USB_HOST_SEMTIMEOUT, in_interrupt() ); 769: if( retval != UDI_OK ){ 770: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_GetStatus: semaphore error" ) ); 771: HUB_REPORT_WARNING( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 772: return retval; 773: } 774: 775: 776: 777: 778: uhs_debug_print( DBG_ERR, ( "Get Status called by external module( Usb_HubApi_GetStatus() )" ) ); 779: result = Usb_Hub_GetStatus( hub_info, buf, port_num ); 780: if( result != UDI_OK ){ 781: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_PortDevDttached: PortDevDetach error" ) ); 782: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 783: } 784: 785: 786: 787: 788: retval = kernel_release_semaphore( &(hub_info->hub_info_sem), in_interrupt() ); 789: if( retval != UDI_OK ){ 790: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_GetStatus: semaphore error" ) ); 791: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 792: 793: if( result == UDI_OK ){ 794: return retval; 795: } 796: } 797: 798: return result; 799: } 800: 801: 812: uhs_status_t Usb_HubApi_ClearTTBuffer( 813: struct usb_hub_info* hub_info, 814: uhs_ubit16_t tt_port, 815: struct usbd_usb_spliterrinfo *split_err_info 816: ) 817: { 818: uhs_ubit8_t err_direction = 0; 819: uhs_ubit16_t err_ep_kind = 0; 820: uhs_ubit16_t err_dev_addr = 0; 821: uhs_ubit16_t err_ep_num = 0; 822: 823: 824: 825: 826: if( split_err_info == NULL ){ 827: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_ClearTTBuffer: parameter error" ) ); 828: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 829: return UDI_STAT_DATA_ERROR; 830: } 831: 832: 833: 834: 835: if( Usbc_Api_GetPipeDirIn( split_err_info->pipe ) == TRUE ){ 836: err_direction = USB_ENDPOINT_DIR_IN; 837: } 838: else{ 839: err_direction = USB_ENDPOINT_DIR_OUT; 840: } 841: err_ep_kind = Usbc_Api_GetPipeEpType( split_err_info->pipe ); 842: err_dev_addr = Usbc_Api_GetPipeAddr( split_err_info->pipe ); 843: err_ep_num = Usbc_Api_GetPipeEpNum( split_err_info->pipe ); 844: 845: 846: 847: 848: return Usb_HubApi_ClearTTBuffer_detail( 849: hub_info, 850: tt_port, 851: err_direction, 852: err_ep_kind, 853: err_dev_addr, 854: err_ep_num 855: ); 856: } 857: 858: 859: 867: static uhs_status_t Usb_HubApi_ClearTTBuffer_detail( 868: struct usb_hub_info* hub_info, 869: uhs_ubit16_t tt_port, 870: uhs_ubit8_t err_direction, 871: uhs_ubit16_t err_ep_kind, 872: uhs_ubit16_t err_dev_addr, 873: uhs_ubit16_t err_ep_num 874: ) 875: { 876: uhs_status_t retval = UDI_OK; 877: uhs_status_t result = UDI_OK; 878: 879: 880: 881: 882: if( ( g_usb_hub_stat != USB_HUB_IDLE ) && ( g_usb_hub_stat != USB_HUB_RUN ) ){ 883: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_ClearTTBuffer_detail: status error" ) ); 884: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_STATUS, 0 ); 885: return UDI_STAT_INVALID_STATE; 886: } 887: 888: 889: 890: 891: if( hub_info == NULL ){ 892: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_ClearTTBuffer_detail: parameter error" ) ); 893: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 894: return UDI_STAT_DATA_ERROR; 895: } 896: if( (hub_info->port_num < 1) || (hub_info->port_num > HUB_MAX_PORT_NUM) ){ 897: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_ClearTTBuffer_detail: parameter error" ) ); 898: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 899: return UDI_STAT_DATA_ERROR; 900: } 901: 902: 903: 904: 905: retval = kernel_acquisition_semaphore( &(hub_info->hub_info_sem), USB_HOST_SEMTIMEOUT, in_interrupt() ); 906: if( retval != UDI_OK ){ 907: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_ClearTTBuffer_detail: semaphore error" ) ); 908: HUB_REPORT_WARNING( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 909: return retval; 910: } 911: 912: 913: 914: 915: #ifdef USBH_DBG_ADD_MESSAGE 916: uhs_debug_print( DBG_ERR, ( "Clear TT Buffer called by external module( Usb_HubApi_ClearTTBuffer_detail() )" ) ); 917: #endif 918: result = Usb_Hub_ClearTTBuffer( 919: hub_info, 920: tt_port, 921: err_direction, 922: err_ep_kind, 923: err_dev_addr, 924: err_ep_num 925: ); 926: if( result != UDI_OK ){ 927: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_PortDevDttached: PortDevDetach error" ) ); 928: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 929: } 930: 931: 932: 933: 934: retval = kernel_release_semaphore( &(hub_info->hub_info_sem), in_interrupt() ); 935: if( retval != UDI_OK ){ 936: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_ClearTTBuffer_detail: semaphore error" ) ); 937: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 938: 939: if( result == UDI_OK ){ 940: return retval; 941: } 942: } 943: 944: return result; 945: } 946: 947: 957: uhs_status_t Usb_HubApi_RESET_TT( struct usb_hub_info* hub_info, uhs_ubit16_t tt_port ) 958: { 959: uhs_status_t retval = UDI_OK; 960: uhs_status_t result = UDI_OK; 961: 962: 963: 964: 965: if( ( g_usb_hub_stat != USB_HUB_IDLE ) && ( g_usb_hub_stat != USB_HUB_RUN ) ){ 966: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_ClearTTBuffer: status error" ) ); 967: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_STATUS, 0 ); 968: return UDI_STAT_INVALID_STATE; 969: } 970: 971: 972: 973: 974: if( hub_info == NULL ){ 975: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_ClearTTBuffer: parameter error" ) ); 976: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 977: return UDI_STAT_DATA_ERROR; 978: } 979: if( (hub_info->port_num < 1) || (hub_info->port_num > HUB_MAX_PORT_NUM) ){ 980: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_ClearTTBuffer: parameter error" ) ); 981: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 982: return UDI_STAT_DATA_ERROR; 983: } 984: 985: 986: 987: 988: retval = kernel_acquisition_semaphore( &(hub_info->hub_info_sem), USB_HOST_SEMTIMEOUT, in_interrupt() ); 989: if( retval != UDI_OK ){ 990: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_ClearTTBuffer: semaphore error" ) ); 991: HUB_REPORT_WARNING( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 992: return retval; 993: } 994: 995: 996: 997: 998: #ifdef USBH_DBG_ADD_MESSAGE 999: uhs_debug_print( DBG_ERR, ( "RESET_TT called by external module( Usb_HubApi_RESET_TT() )" ) ); 1000: #endif 1001: result = Usb_Hub_RESET_TT( hub_info, tt_port ); 1002: if( result != UDI_OK ){ 1003: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_PortDevDttached: PortDevDetach error" ) ); 1004: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1005: } 1006: 1007: 1008: 1009: 1010: retval = kernel_release_semaphore( &(hub_info->hub_info_sem), in_interrupt() ); 1011: if( retval != UDI_OK ){ 1012: uhs_debug_print( DBG_ERR, ( "Usb_HubApi_ClearTTBuffer: semaphore error" ) ); 1013: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 1014: 1015: if( result == UDI_OK ){ 1016: return retval; 1017: } 1018: } 1019: 1020: return result; 1021: } 1022: 1023: 1024: 1025: 1026: 1027: 1028: 1029: 1030: 1031: 1032: 1033: 1034: 1035: 1036: 1037: 1038: 1039: 1040: 1041: 1042: 1043: 1044: 1045: 1046: 1047: 1048: 1049: 1050: 1051: 1060: static int Usb_Hub_CompleteFunc( int mod_id, int callback_id, void* context ){ 1061: 1062: struct usb_control_block* ucb = (struct usb_control_block*)context; 1063: kernel_context_t* hub_trans_done = NULL; 1064: uhs_status_t retval = UDI_OK; 1065: 1066: 1067: 1068: 1069: if( ( g_usb_hub_stat != USB_HUB_IDLE ) && ( g_usb_hub_stat != USB_HUB_RUN ) ){ 1070: uhs_debug_print( DBG_ERR, ( "Usb_Hub_CompleteFunc: status error" ) ); 1071: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_STATUS, 0 ); 1072: return FALSE; 1073: } 1074: 1075: 1076: 1077: 1078: if( ( ucb == NULL ) || ( ucb->context == NULL ) || ( mod_id != MOD_ID_USBH ) || ( callback_id != CBID_CORE_REQ ) ){ 1079: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_CompleteFunc() )" ) ); 1080: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 1081: return FALSE; 1082: } 1083: 1084: 1085: 1086: 1087: hub_trans_done = (kernel_context_t*)ucb->context; 1088: retval = kernel_set_event( hub_trans_done, in_interrupt() ); 1089: if( retval != UDI_OK ){ 1090: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_CompleteFunc() adr=%d )",ucb->usbdev->usbdev_DevNum ) ); 1091: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 1092: return FALSE; 1093: } 1094: 1095: return TRUE; 1096: } 1097: 1098: 1108: static int Usb_Hub_IntCompleteFunc( int mod_id, int callback_id, void* context ){ 1109: 1110: struct usb_control_block* ucb = (struct usb_control_block*)context; 1111: 1112: 1113: 1114: 1115: if( ( g_usb_hub_stat != USB_HUB_IDLE ) && ( g_usb_hub_stat != USB_HUB_RUN ) ){ 1116: uhs_debug_print( DBG_ERR, ( "Usb_Hub_IntCompleteFunc: status error" ) ); 1117: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_STATUS, 0 ); 1118: return FALSE; 1119: } 1120: 1121: 1122: 1123: 1124: if( ( ucb == NULL ) || ( ucb->context == NULL ) || ( mod_id != MOD_ID_USBH ) || ( callback_id != CBID_CORE_REQ ) ){ 1125: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_IntCompleteFunc() )" ) ); 1126: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 1127: return FALSE; 1128: } 1129: 1130: if( ucb->status != EUSB_STOP_TRANS ){ 1131: 1132: 1133: 1134: 1135: 1136: 1137: if( Usb_Hub_SendMsg_intr_in( (struct usb_hub_info *)ucb->context ) != UDI_OK ){ 1138: return FALSE; 1139: } 1140: else{ 1141: 1142: #ifdef USBH_DBG_ADD_MESSAGE 1143: uhs_debug_print( DBG_ERR, ( "HUB_INTR_CB : Send_Mesg [ hub_adr = %d / ucb_sts = %d ]",((struct usb_hub_info *)ucb->context)->usbdev->usbdev_DevNum,ucb->status) ); 1144: #endif 1145: } 1146: } 1147: 1148: return TRUE; 1149: } 1150: 1151: 1152: 1153: 1154: 1155: 1156: 1157: 1158: 1159: 1160: 1171: static int Usb_Hub_Attached( int mod_id, int callback_id, void* context ){ 1172: 1173: uhs_status_t retval = UDI_OK; 1174: struct usb_hub_info* hub_info = NULL; 1175: uhs_ubit32_t pipe = 0; 1176: uhs_boolean_t bretval = 0; 1177: struct usbd_usb_deviceinfo* usbdev = NULL; 1178: usb_cbcontext_dev_detach detach_context; 1179: 1180: #ifdef USBH_DBG_ADD_MESSAGE 1181: uhs_debug_print( DBG_ERR, ("\r\n ===============================================================>>>>>") ); 1182: uhs_debug_print( DBG_ERR, ( "HUB : Attach") ); 1183: #endif 1184: 1185: 1186: 1187: if( ( g_usb_hub_stat != USB_HUB_IDLE ) && ( g_usb_hub_stat != USB_HUB_RUN ) ){ 1188: uhs_debug_print( DBG_ERR, ( "Usb_Hub_Attached: status error" ) ); 1189: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_STATUS, 0 ); 1190: return USBH_CBRTN_NG; 1191: } 1192: 1193: 1194: 1195: 1196: if( ( context == NULL ) || ( mod_id != MOD_ID_USBH ) || ( callback_id != CBID_CORE_DEVATTACH ) ){ 1197: uhs_debug_print( DBG_ERR, ( "Usb_Hub_Attached: argument error" ) ); 1198: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 1199: return USBH_CBRTN_NG; 1200: } 1201: 1202: 1203: 1204: 1205: if( g_hub_conn_cnt >= HUB_CONN_MAXCNT ){ 1206: uhs_debug_print( DBG_ERR, ( "HUB max conn cnt error" ) ); 1207: HUB_REPORT_WARNING( USBCLS_HUB_OVERCONN, 0 ); 1208: return USBH_CBRTN_NG_TOOMANY; 1209: } 1210: 1211: 1212: 1213: 1214: usbdev = ((usb_cbcontext_dev_attach*)context)->usbdev; 1215: 1216: 1217: 1218: 1219: #ifdef USBH_DBG_ADD_MESSAGE 1220: 1221: #endif 1222: 1223: 1224: 1225: retval = Usb_Hub_AllocHubInfo( &hub_info, usbdev ); 1226: if( retval != UDI_OK ){ 1227: uhs_debug_print( DBG_ERR, ( "USB HUB Attach Hub Struct Alloc Error error: ercd=%d", retval ) ); 1228: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 1229: return USBH_CBRTN_NG; 1230: } 1231: 1232: 1233: 1234: 1235: retval = kernel_acquisition_semaphore( &(hub_info->hub_info_sem), USB_HOST_SEMTIMEOUT, in_interrupt() ); 1236: if( retval != UDI_OK ){ 1237: 1238: 1239: uhs_debug_print( DBG_ERR, ( "Usb_Hub_Attached: semaphore error" ) ); 1240: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1241: 1242: 1243: retval = Usb_Hub_FreeHubInfo( hub_info ); 1244: if( retval != UDI_OK ){ 1245: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1246: } 1247: return USBH_CBRTN_NG; 1248: } 1249: 1250: 1251: 1252: 1253: 1254: 1255: 1256: hub_info->control_ucb->usbdev = usbdev; 1257: Usbc_Api_FixupPipeInfo( &pipe, usbdev->usbdev_DevNum, USB_DEFAULT_EP_NUM, USB_PACKETID_IN, 1258: USB_TRANS_CONTROL, usbdev->usbdev_EpMaxpktIn[USB_DEFAULT_EP_NUM] ); 1259: 1260: 1261: 1262: 1263: Usb_Core_FixupCtrlUcb( hub_info->control_ucb, usbdev, pipe, NULL, NULL, 0, Usb_Hub_IntCompleteFunc, (void*)hub_info ); 1264: 1265: 1266: 1267: 1268: retval = Usbc_Api_OpenPipe( hub_info->control_ucb ); 1269: if( retval != UDI_OK ){ 1270: uhs_debug_print( DBG_ERR, ( "USB HUB Control Open Error error: ercd=%d", retval ) ); 1271: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1272: 1273: 1274: retval = kernel_release_semaphore( &(hub_info->hub_info_sem), in_interrupt() ); 1275: if( retval != UDI_OK ){ 1276: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1277: } 1278: 1279: 1280: retval = Usb_Hub_FreeHubInfo( hub_info ); 1281: if( retval != UDI_OK ){ 1282: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1283: } 1284: 1285: return USBH_CBRTN_NG; 1286: } 1287: 1288: 1289: 1290: 1291: bretval = Usbc_Api_PipeIsOpened( hub_info->control_ucb ); 1292: if( bretval == FALSE ){ 1293: uhs_debug_print( DBG_ERR, ( "USB HUB Control Open Error error: ercd=%d", retval ) ); 1294: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1295: 1296: 1297: retval = kernel_release_semaphore( &(hub_info->hub_info_sem), in_interrupt() ); 1298: if( retval != UDI_OK ){ 1299: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1300: } 1301: 1302: 1303: retval = Usb_Hub_FreeHubInfo( hub_info ); 1304: if( retval != UDI_OK ){ 1305: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1306: } 1307: 1308: return USBH_CBRTN_NG; 1309: } 1310: 1311: #ifdef USBH_DBG_ADD_MESSAGE 1312: 1313: #endif 1314: 1315: 1316: 1317: retval = Usb_Hub_GetDescriptor( hub_info ); 1318: if( retval != UDI_OK ){ 1319: uhs_debug_print( DBG_ERR, ( "USB HUB Get Hub Descriptor Error error: ercd=%d", retval ) ); 1320: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1321: 1322: 1323: retval = kernel_release_semaphore( &(hub_info->hub_info_sem), in_interrupt() ); 1324: if( retval != UDI_OK ){ 1325: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1326: } 1327: 1328: 1329: retval = Usb_Hub_FreeHubInfo( hub_info ); 1330: if( retval != UDI_OK ){ 1331: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1332: } 1333: 1334: return USBH_CBRTN_NG; 1335: } 1336: 1337: 1338: 1339: 1340: retval = Usb_Hub_CoverHubinfo( hub_info ); 1341: if( retval != UDI_OK ){ 1342: uhs_debug_print( DBG_ERR, ( "USB HUB Get Hub Descriptor Error error: ercd=%d", retval ) ); 1343: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1344: 1345: 1346: retval = kernel_release_semaphore( &(hub_info->hub_info_sem), in_interrupt() ); 1347: if( retval != UDI_OK ){ 1348: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1349: } 1350: 1351: 1352: retval = Usb_Hub_FreeHubInfo( hub_info ); 1353: if( retval != UDI_OK ){ 1354: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1355: } 1356: 1357: return USBH_CBRTN_NG; 1358: } 1359: 1360: 1361: 1362: 1363: 1364: 1365: 1366: 1367: hub_info->hub_intr_buf_size = INTERRUPT_BUF_SIZE; 1368: 1369: 1370: 1371: retval = kernel_mem_alloc( &mpl_osc, (void**)&hub_info->hub_intr_buf, hub_info->hub_intr_buf_size, 0, in_interrupt() ); 1372: if( retval != UDI_OK ){ 1373: uhs_debug_print( DBG_ERR, ( "USB HUB Attach Hub Struct Alloc Error error: ercd=%d", retval ) ); 1374: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 1375: 1376: 1377: retval = kernel_release_semaphore( &(hub_info->hub_info_sem), in_interrupt() ); 1378: if( retval != UDI_OK ){ 1379: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1380: } 1381: 1382: 1383: retval = Usb_Hub_FreeHubInfo( hub_info ); 1384: if( retval != UDI_OK ){ 1385: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1386: } 1387: 1388: return USBH_CBRTN_NG; 1389: } 1390: memset( (void*)hub_info->hub_intr_buf, 0, (uhs_size_t)hub_info->hub_intr_buf_size ); 1391: 1392: 1393: 1394: 1395: 1396: 1397: 1398: hub_info->intr_ucb->usbdev = usbdev; 1399: Usbc_Api_FixupPipeInfo( &pipe, usbdev->usbdev_DevNum, hub_info->intr_epnum, USB_PACKETID_IN, USB_TRANS_INTERRUPT, 1400: hub_info->usbdev->usbdev_EpMaxpktIn[(hub_info->intr_epnum&~BYTE_MSB)] ); 1401: 1402: 1403: 1404: 1405: Usb_Core_FixupIntrUcb( hub_info->intr_ucb, usbdev, pipe, hub_info->hub_intr_buf, hub_info->hub_intr_buf_size, 1406: hub_info->intr_interval, Usb_Hub_IntCompleteFunc, (void*)hub_info ); 1407: 1408: #ifdef USBH_DBG_ADD_MESSAGE 1409: 1410: #endif 1411: 1412: 1413: 1414: retval = Usbc_Api_OpenPipe( hub_info->intr_ucb ); 1415: if( retval != UDI_OK ){ 1416: uhs_debug_print( DBG_ERR, ( "USB HUB Control Open Error error: ercd=%d", retval ) ); 1417: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1418: 1419: 1420: retval = kernel_release_semaphore( &(hub_info->hub_info_sem), in_interrupt() ); 1421: if( retval != UDI_OK ){ 1422: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1423: } 1424: 1425: 1426: retval = Usb_Hub_FreeHubInfo( hub_info ); 1427: if( retval != UDI_OK ){ 1428: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1429: } 1430: 1431: return USBH_CBRTN_NG; 1432: } 1433: 1434: 1435: 1436: 1437: 1438: retval = Usb_Hub_PortInitial( hub_info ); 1439: if( retval != UDI_OK ){ 1440: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1441: 1442: 1443: retval = kernel_release_semaphore( &(hub_info->hub_info_sem), in_interrupt() ); 1444: if( retval != UDI_OK ){ 1445: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1446: } 1447: 1448: 1449: retval = Usb_Hub_FreeHubInfo( hub_info ); 1450: if( retval != UDI_OK ){ 1451: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1452: } 1453: 1454: 1455: detach_context.usbdev = usbdev; 1456: detach_context.context = NULL; 1457: hub_driver_reginfo.detach( MOD_ID_USBH, CBID_CORE_DEVATTACH, &detach_context ); 1458: return USBH_CBRTN_NG; 1459: } 1460: 1461: #ifdef USBH_DBG_ADD_MESSAGE 1462: 1463: #endif 1464: 1465: 1466: 1467: retval = Usb_Hub_StartInterrupt( hub_info ); 1468: if( retval != UDI_OK ){ 1469: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1470: 1471: 1472: retval = kernel_release_semaphore( &(hub_info->hub_info_sem), in_interrupt() ); 1473: if( retval != UDI_OK ){ 1474: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1475: } 1476: 1477: 1478: retval = Usb_Hub_FreeHubInfo( hub_info ); 1479: if( retval != UDI_OK ){ 1480: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1481: } 1482: 1483: 1484: detach_context.usbdev = usbdev; 1485: detach_context.context = NULL; 1486: hub_driver_reginfo.detach( MOD_ID_USBH, CBID_CORE_DEVATTACH, &detach_context ); 1487: return USBH_CBRTN_NG; 1488: } 1489: 1490: 1491: 1492: 1493: retval = kernel_release_semaphore( &(hub_info->hub_info_sem), in_interrupt() ); 1494: if( retval != UDI_OK ){ 1495: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1496: 1497: 1498: retval = Usb_Hub_FreeHubInfo( hub_info ); 1499: if( retval != UDI_OK ){ 1500: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1501: } 1502: 1503: return USBH_CBRTN_NG; 1504: } 1505: 1506: return USBH_CBRTN_OK; 1507: } 1508: 1509: 1517: static uhs_status_t Usb_Hub_CoverHubinfo( struct usb_hub_info* hub_info ){ 1518: 1519: struct usb_endpoint_descriptor* ep_desc = NULL; 1520: 1521: 1522: 1523: 1524: if( hub_info == NULL ){ 1525: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_CoverHubInfo() )" ) ); 1526: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1527: return UDI_STAT_DATA_ERROR; 1528: } 1529: 1530: 1531: 1532: 1533: hub_info->port_num = hub_info->hub_desc->bNbrPorts; 1534: hub_info->PwrOnWait = (uhs_ubit16_t)(hub_info->hub_desc->bPwrOn2PwrGood << 1); 1535: hub_info->current = hub_info->hub_desc->bHubContrCurrent; 1536: hub_info->dev_removal = hub_info->hub_desc->DeviceRemovable; 1537: hub_info->power_switch = (uhs_ubit8_t)( hub_info->hub_desc->wHubCharacteristics & HUB_POWERSWITCH_MASK ); 1538: hub_info->compound_device = (uhs_ubit8_t)(( hub_info->hub_desc->wHubCharacteristics & HUB_COMPDEVICE_MASK ) >> 2); 1539: hub_info->current_protect = (uhs_ubit8_t)(( hub_info->hub_desc->wHubCharacteristics & HUB_OVERCURRENT_MASK ) >> 3); 1540: hub_info->tt_thinktime = (uhs_ubit8_t)(( hub_info->hub_desc->wHubCharacteristics & HUB_TTTHINKTIME_MASK ) >> 5); 1541: hub_info->indicator_support = (uhs_ubit8_t)(( hub_info->hub_desc->wHubCharacteristics & HUB_INDICATORSUPPORT_MASK ) >> 7); 1542: 1543: 1544: 1545: if( hub_info->port_num > HUB_MAX_PORT_NUM ){ 1546: uhs_debug_print( DBG_ERR, ( "hub port too many ( Usb_Hub_CoverHubInfo() ) )" ) ); 1547: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1548: return UDI_STAT_ATTR_MISMATCH; 1549: } 1550: 1551: 1552: 1553: 1554: ep_desc = Usbc_Api_GetEpDescriptor( hub_info->usbdev, 1, 0, (uhs_ubit8_t)USB_ENDPOINT_INTERRUPT, (uhs_ubit8_t)USB_ENDPOINT_DIR_IN ); 1555: if( ep_desc == NULL ){ 1556: uhs_debug_print( DBG_ERR, ( "fail:get_descriptor( Usb_Hub_CoverHubInfo() )" ) ); 1557: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1558: return UDI_STAT_MISTAKEN_IDENTITY; 1559: } 1560: hub_info->intr_epnum = ep_desc->bEndpointAddress; 1561: hub_info->intr_interval = ep_desc->bInterval; 1562: 1563: return UDI_OK; 1564: } 1565: 1566: 1576: static int Usb_Hub_Detached( int mod_id, int callback_id, void* context ){ 1577: 1578: uhs_status_t retval = UDI_OK; 1579: uhs_ubit8_t i = 0; 1580: struct usb_hub_info* hub_info = NULL; 1581: struct usbd_usb_deviceinfo* usbdev = NULL; 1582: int result = USBH_CBRTN_OK; 1583: 1584: 1585: 1586: 1587: if( ( g_usb_hub_stat != USB_HUB_IDLE ) && ( g_usb_hub_stat != USB_HUB_RUN ) ){ 1588: uhs_debug_print( DBG_ERR, ( "Usb_Hub_Detached: status error" ) ); 1589: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_STATUS, 0 ); 1590: return USBH_CBRTN_NG; 1591: } 1592: 1593: 1594: 1595: 1596: if( ( context == NULL ) || ( mod_id != MOD_ID_USBH ) || (callback_id != CBID_CORE_DEVDETACH) ){ 1597: uhs_debug_print( DBG_ERR, ( "Usb_Hub_Detached: argument error" ) ); 1598: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 1599: return USBH_CBRTN_NG; 1600: } 1601: 1602: 1603: 1604: 1605: usbdev = ( ( usb_cbcontext_dev_detach* )context )->usbdev; 1606: 1607: 1608: 1609: 1610: if( usbdev == NULL ){ 1611: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_Detached() )" ) ); 1612: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1613: return USBH_CBRTN_NG; 1614: } 1615: 1616: 1617: 1618: 1619: hub_info = (struct usb_hub_info *)usbdev->context; 1620: 1621: #ifdef USBH_DBG_ADD_MESSAGE 1622: uhs_debug_print( DBG_ERR, ( "HUB : Detach (hub_adr = %d)" , hub_info->usbdev->usbdev_DevNum ) ); 1623: uhs_debug_print( DBG_ERR, ( "===============================================================<< HUB >> \r\n") ); 1624: #endif 1625: 1626: 1627: 1628: 1629: if( hub_info == NULL ){ 1630: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_Detached() )" ) ); 1631: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1632: return USBH_CBRTN_NG; 1633: } 1634: 1635: 1636: 1637: 1638: retval = kernel_acquisition_semaphore( &( hub_info->hub_info_sem ), USB_HOST_SEMTIMEOUT, in_interrupt() ); 1639: if( retval != UDI_OK ){ 1640: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1641: return USBH_CBRTN_NG; 1642: } 1643: 1644: 1645: 1646: 1647: 1648: 1649: for( i = 1 ; i <= hub_info->port_num ; i ++ ){ 1650: 1651: 1652: if( usbdev->usbdev_LowerHub[i] != NULL ){ 1653: 1654: 1655: retval = Usb_Hub_PortDevDetachInHubClass( 1656: usbdev->usbdev_LowerHub[i], 1657: i 1658: ); 1659: if( retval != UDI_OK ){ 1660: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1661: result = FALSE; 1662: } 1663: } 1664: } 1665: 1666: #ifdef USBH_DBG_ADD_MESSAGE 1667: 1668: #endif 1669: 1670: 1671: 1672: retval = Usb_Hub_StopInterrupt( hub_info ); 1673: if( retval != UDI_OK ){ 1674: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1675: result = USBH_CBRTN_NG; 1676: } 1677: 1678: 1679: #ifdef USBH_DBG_ADD_MESSAGE 1680: 1681: #endif 1682: 1683: 1684: 1685: 1686: retval = kernel_release_semaphore( &( hub_info->hub_info_sem ), in_interrupt() ); 1687: if( retval != UDI_OK ){ 1688: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1689: result = USBH_CBRTN_NG; 1690: } 1691: 1692: #ifdef USBH_DBG_ADD_MESSAGE 1693: 1694: #endif 1695: 1696: 1697: 1698: retval = Usb_Hub_FreeHubInfo( hub_info ); 1699: if( retval != UDI_OK ){ 1700: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1701: result = USBH_CBRTN_NG; 1702: } 1703: 1704: return result; 1705: } 1706: 1707: 1708: 1709: 1710: 1718: uhs_status_t Usb_Hub_SendPortReset( struct usb_hub_info* hub_info, uhs_ubit8_t port_num ){ 1719: 1720: uhs_ubit32_t i = 0, j = 0; 1721: struct usbh_port_status port_status; 1722: uhs_status_t retval = UDI_OK; 1723: 1724: 1725: 1726: 1727: if( hub_info == NULL ){ 1728: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_SendPortReset() )" ) ); 1729: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 1730: return UDI_STAT_DATA_ERROR; 1731: } 1732: if( ( port_num == 0 ) || ( hub_info->port_num < port_num ) ){ 1733: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_SendPortReset() )" ) ); 1734: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 1735: return UDI_STAT_DATA_ERROR; 1736: } 1737: 1738: #ifdef USBH_DBG_ADD_MESSAGE 1739: uhs_debug_print( DBG_ERR, ( "HUB : Set (PORT_RESET) %d" , port_num ) ); 1740: #endif 1741: 1742: 1743: 1744: retval = Usb_Hub_SetFeature( hub_info, PORT_RESET, port_num ); 1745: if( retval != UDI_OK ){ 1746: uhs_debug_print( DBG_ERR, ( "USB HUB SetPortFeature( PORT_RESET ) Error: ercd=%d", retval ) ); 1747: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1748: return retval; 1749: } 1750: 1751: #ifdef USBH_DBG_ADD_MESSAGE 1752: uhs_debug_print( DBG_ERR, ( "HUB : Exit (PORT_RESET) %d" , port_num ) ); 1753: #endif 1754: kernel_wait( NULL, USB_PORT_RESET_WAIT ); 1755: 1756: 1757: 1758: 1759: 1760: for( i = BUS_RESET_TIMEOUT ; i > 0 ; i-- ){ 1761: 1762: retval = Usb_Hub_GetStatus( hub_info, (void*)&port_status.port_status, port_num ); 1763: if( retval != UDI_OK ){ 1764: uhs_debug_print( DBG_ERR, ( "USB HUB Get Hub Status error: ercd=%d", retval ) ); 1765: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1766: return retval; 1767: } 1768: 1769: 1770: if( port_status.port_status & PS_PORT_ENABLE ){ 1771: break; 1772: } 1773: 1774: 1775: if( port_status.port_change_status & PS_C_PORT_ENABLE ){ 1776: i = 0; 1777: break; 1778: } 1779: kernel_wait( NULL, 10 ); 1780: } 1781: 1782: #ifdef USBH_DBG_ADD_MESSAGE 1783: uhs_debug_print( DBG_ERR, ( "HUB : Finish Bus Reset (PORT_RESET) %d" , port_num ) ); 1784: #endif 1785: 1786: 1787: 1788: if( i == 0 ){ 1789: uhs_debug_print( DBG_ERR, ( "USB HUB SetPortFeature( PORT_RESET ) Error: ercd=%d, portnum=%d", retval, i+1 ) ); 1790: HUB_REPORT_WARNING( USBCLS_HUB_IMPORTANT_ERROR, 0 ); 1791: return UDI_STAT_TIMEOUT; 1792: } 1793: 1794: 1795: 1796: 1797: if( port_status.port_change_status & PS_C_PORT_RESET ){ 1798: for( i = 0 ; i < USB_HUB_RETRY_CNT ; i++ ){ 1799: 1800: retval = Usb_Hub_ClearFeature( hub_info, C_PORT_RESET, port_num ); 1801: if( retval != UDI_OK ){ 1802: uhs_debug_print( DBG_ERR, ( "USB HUB ClearPortFeature( C_PORT_RESET ) Error: ercd=%d", retval ) ); 1803: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1804: return retval; 1805: } 1806: 1807: 1808: for( j = 0 ; j < USB_HUB_RETRY_CNT ; j++ ){ 1809: 1810: retval = Usb_Hub_GetStatus( hub_info, (void*)&port_status.port_status, port_num ); 1811: if( retval != UDI_OK ){ 1812: uhs_debug_print( DBG_ERR, ( "USB HUB Get Hub Status error: ercd=%d", retval ) ); 1813: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1814: return retval; 1815: } 1816: 1817: 1818: if( !( port_status.port_status & PS_C_PORT_RESET ) ){ 1819: return UDI_OK; 1820: } 1821: } 1822: } 1823: } 1824: 1825: return UDI_STAT_TIMEOUT; 1826: } 1827: 1828: 1836: uhs_status_t Usb_Hub_CheckGetDescriptor( struct usbd_usb_deviceinfo* usbdev ){ 1837: 1838: uhs_status_t retval = UDI_OK; 1839: uhs_status_t result = UDI_OK; 1840: struct usb_control_block* ucb = NULL; 1841: uhs_ubit32_t pipe = 0; 1842: 1843: 1844: 1845: 1846: if( usbdev == NULL ){ 1847: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_CheckGetDescriptor())" ) ); 1848: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 1849: return UDI_STAT_DATA_ERROR; 1850: } 1851: 1852: 1853: 1854: 1855: retval = kernel_acquisition_semaphore( &(usbdev->usbdev_sem), USB_HOST_SEMTIMEOUT, in_interrupt() ); 1856: if( retval != UDI_OK ){ 1857: 1858: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1859: return UDI_STAT_RESOURCE_UNAVAIL; 1860: } 1861: 1862: 1863: 1864: 1865: 1866: usbdev->usbdev_EpMaxpktIn[0] = DESC_LENGTH; 1867: usbdev->usbdev_EpMaxpktOut[0] = DESC_LENGTH; 1868: 1869: 1870: 1871: 1872: 1873: 1874: 1875: retval = Usbc_Api_AllocUsbCtrlBlock( &ucb ); 1876: if( retval != UDI_OK ){ 1877: retval = kernel_release_semaphore( &(usbdev->usbdev_sem), in_interrupt() ); 1878: if ( retval != UDI_OK ) { 1879: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1880: } 1881: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1882: return UDI_STAT_RESOURCE_UNAVAIL; 1883: } 1884: 1885: 1886: 1887: 1888: 1889: 1890: 1891: Usbc_Api_FixupPipeInfo( &pipe, 0, USB_DEFAULT_EP_NUM, USB_PACKETID_IN, 1892: USB_TRANS_CONTROL, usbdev->usbdev_EpMaxpktIn[0] ); 1893: 1894: 1895: 1896: 1897: Usb_Core_FixupCtrlUcb( ucb, usbdev, pipe, NULL, NULL, 0, NULL, (void*)&usbdev->usbdev_mbx ); 1898: 1899: #ifdef USBH_DBG_ADD_MESSAGE 1900: 1901: #endif 1902: 1903: 1904: 1905: 1906: retval = Usbc_Api_OpenPipe( ucb ); 1907: if( retval != UDI_OK ){ 1908: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1909: result = Usbc_Api_FreeUsbCtrlBlock( ucb ); 1910: if ( result != UDI_OK ) { 1911: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1912: } 1913: result = kernel_release_semaphore( &(usbdev->usbdev_sem), in_interrupt() ); 1914: if ( result != UDI_OK ) { 1915: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1916: } 1917: #ifdef USBH_DBG_ADD_MESSAGE 1918: uhs_debug_print( DBG_ERR, ( "Pipe Error") ); 1919: #endif 1920: return retval; 1921: } 1922: 1923: 1924: 1925: 1926: retval = kernel_mem_alloc( &mpl_osc, (void**)&usbdev->usbdev_DevDescriptor, sizeof( struct usb_device_descriptor ), 0, in_interrupt() ); 1927: if( retval != UDI_OK ){ 1928: 1929: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 1930: retval = Usbc_Api_ClosePipe( ucb ); 1931: if( retval != UDI_OK ){ 1932: uhs_debug_print( DBG_ERR, ( "USB Hub Pipe Close Error" ) ); 1933: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1934: } 1935: 1936: 1937: retval = Usbc_Api_FreeUsbCtrlBlock( ucb ); 1938: if( retval != UDI_OK ){ 1939: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1940: } 1941: uhs_debug_print( DBG_ERR, ( "USB DeviceDescriptor Buffer Allocate Error" ) ); 1942: 1943: 1944: retval = kernel_release_semaphore( &(usbdev->usbdev_sem), in_interrupt() ); 1945: if( retval != UDI_OK ){ 1946: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1947: } 1948: return UDI_STAT_RESOURCE_UNAVAIL; 1949: } 1950: 1951: memset( (void*)usbdev->usbdev_DevDescriptor, 0, sizeof( struct usb_device_descriptor ) ); 1952: 1953: #ifdef USBH_DBG_ADD_MESSAGE 1954: 1955: #endif 1956: 1957: 1958: 1959: retval = Usb_Core_GetDescriptor( ucb, usbdev, USB_DESC_TYPE_DEVICE, 0, 0, usbdev->usbdev_DevDescriptor, DESC_LENGTH ); 1960: if( retval != UDI_OK ){ 1961: 1962: #ifdef USBH_DBG_ADD_MESSAGE 1963: uhs_debug_print( DBG_ERR, ( "\x1b[31m\x1b[4mFail (GET_DESCRIPTOR)\x1b[0m\x1b[39m") ); 1964: #endif 1965: 1966: 1967: 1968: 1969: 1970: 1971: result = Usbc_Api_ClosePipe( ucb ); 1972: if( result != UDI_OK ){ 1973: uhs_debug_print( DBG_ERR, ( "USB Hub Pipe Close Error" ) ); 1974: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1975: } 1976: 1977: 1978: result = Usbc_Api_FreeUsbCtrlBlock( ucb ); 1979: if( result != UDI_OK ){ 1980: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1981: } 1982: 1983: 1984: result = kernel_mem_free( &mpl_osc, usbdev->usbdev_DevDescriptor, in_interrupt() ); 1985: if ( result != UDI_OK ) { 1986: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1987: }else{ 1988: usbdev->usbdev_DevDescriptor = NULL; 1989: } 1990: 1991: 1992: result = kernel_release_semaphore( &(usbdev->usbdev_sem), in_interrupt() ); 1993: if( result != UDI_OK ){ 1994: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1995: } 1996: 1997: uhs_debug_print( DBG_ERR, ( "unable to device attach" ) ); 1998: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 1999: return retval; 2000: 2001: }else{ 2002: 2003: if( ( usbdev->usbdev_DevDescriptor->bLength != USB_DEVDESC_SIZE ) || ( usbdev->usbdev_DevDescriptor->bMaxPacketSize > USB_MAXPKT_CTRLEP ) ){ 2004: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2005: uhs_debug_print( DBG_ERR, ( "GetDescriptor DEVICE's Data is Invalid" ) ); 2006: 2007: 2008: retval = Usbc_Api_ClosePipe( ucb ); 2009: if( retval != UDI_OK ){ 2010: uhs_debug_print( DBG_ERR, ( "USB Hub Pipe Close Error" ) ); 2011: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2012: } 2013: 2014: 2015: retval = Usbc_Api_FreeUsbCtrlBlock( ucb ); 2016: if( retval != UDI_OK ){ 2017: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2018: } 2019: 2020: 2021: result = kernel_mem_free( &mpl_osc, usbdev->usbdev_DevDescriptor, in_interrupt() ); 2022: if ( result != UDI_OK ) { 2023: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2024: }else{ 2025: usbdev->usbdev_DevDescriptor = NULL; 2026: } 2027: 2028: 2029: retval = kernel_release_semaphore( &(usbdev->usbdev_sem), in_interrupt() ); 2030: if( retval != UDI_OK ){ 2031: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2032: } 2033: 2034: return UDI_STAT_DATA_ERROR; 2035: } 2036: } 2037: 2038: 2039: 2040: 2041: usbdev->usbdev_EpMaxpktOut[0] = usbdev->usbdev_EpMaxpktIn[0] = usbdev->usbdev_DevDescriptor->bMaxPacketSize; 2042: 2043: #ifdef USBH_DBG_ADD_MESSAGE 2044: 2045: #endif 2046: 2047: 2048: 2049: retval = Usbc_Api_ClosePipe( ucb ); 2050: if( retval != UDI_OK ){ 2051: uhs_debug_print( DBG_ERR, ( "USB Hub Pipe Close Error" ) ); 2052: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2053: } 2054: 2055: 2056: 2057: 2058: retval = Usbc_Api_FreeUsbCtrlBlock( ucb ); 2059: if( retval != UDI_OK ){ 2060: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2061: } 2062: 2063: 2064: 2065: 2066: retval = kernel_release_semaphore( &(usbdev->usbdev_sem), in_interrupt() ); 2067: if( retval != UDI_OK ){ 2068: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2069: } 2070: 2071: return UDI_OK; 2072: } 2073: 2074: 2075: 2076: 2077: 2078: 2079: 2080: 2081: 2082: 2089: uhs_status_t Usb_Hub_StartInterrupt( struct usb_hub_info* hub_info ){ 2090: 2091: uhs_status_t retval = UDI_OK; 2092: 2093: 2094: 2095: 2096: if( hub_info == NULL ){ 2097: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_StartInterrupt() )" ) ); 2098: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2099: return UDI_STAT_DATA_ERROR; 2100: } 2101: 2102: 2103: 2104: 2105: retval = Usbc_Api_IntMsg( hub_info->intr_ucb ); 2106: if( retval == UDI_STAT_TERMINATED ){ 2107: retval = UDI_OK; 2108: } 2109: if( retval != UDI_OK ){ 2110: uhs_debug_print( DBG_ERR, ( "USB HUB Start Interrupt Error: ercd=%d", retval ) ); 2111: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2112: } 2113: 2114: return retval; 2115: } 2116: 2117: 2124: uhs_status_t Usb_Hub_StopInterrupt( struct usb_hub_info* hub_info ){ 2125: 2126: uhs_status_t retval = UDI_OK; 2127: 2128: 2129: 2130: 2131: if( hub_info == NULL ){ 2132: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_StopInterrupt() )" ) ); 2133: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2134: return UDI_STAT_DATA_ERROR; 2135: } 2136: 2137: 2138: 2139: 2140: retval = Usbc_Api_StopTrans( hub_info->intr_ucb ); 2141: if( retval == UDI_STAT_TERMINATED ){ 2142: retval = UDI_OK; 2143: } 2144: if( retval != UDI_OK ){ 2145: uhs_debug_print( DBG_ERR, ( "USB HUB Stop Interrupt Error: ercd=%d", retval ) ); 2146: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2147: } 2148: 2149: return retval; 2150: } 2151: 2152: 2153: 2154: 2155: 2156: 2157: 2158: 2159: 2160: 2174: static uhs_status_t Usb_Hub_IssueClassRequest( 2175: struct usb_hub_info* hub_info, 2176: uhs_ubit8_t bmRequestType, 2177: uhs_ubit8_t bRequest, 2178: uhs_ubit16_t wValue, 2179: uhs_ubit16_t wIndex, 2180: uhs_ubit16_t wLength, 2181: uhs_ubit32_t pipe, 2182: void* buf ){ 2183: 2184: kernel_context_t hub_classreq_done; 2185: usb_device_request_t *setup=NULL; 2186: uhs_status_t retval = UDI_OK; 2187: uhs_status_t result = UDI_OK; 2188: void *ucb_buf_ptr = NULL; 2189: void *buf_ptr = NULL; 2190: 2191: 2192: 2193: 2194: 2195: if( ( hub_info == NULL ) || ( buf == NULL ) ){ 2196: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_IssueClassRequest() )" ) ); 2197: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2198: return UDI_STAT_DATA_ERROR; 2199: } 2200: 2201: 2202: retval = kernel_mem_alloc( &mpl_osc, (void**)&setup, sizeof( usb_device_request_t ), 0, in_interrupt() ); 2203: if( retval != UDI_OK ){ 2204: uhs_debug_print( DBG_ERR, ( "Usb_Hub_IssueClassRequest : USB HUB Issu Class Req Alloc Error[1] error: ercd=%d", retval ) ); 2205: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 2206: return UDI_STAT_RESOURCE_UNAVAIL; 2207: } 2208: memset( (void*)setup, 0, sizeof( usb_device_request_t ) ); 2209: 2210: ucb_buf_ptr = buf; 2211: 2212: 2213: if( ( (bmRequestType & USB_DEVICE_REEQUEST_TYPE_DIR_MASK) != 0 ) && 2214: ( wLength != 0 ) ){ 2215: 2216: 2217: retval = kernel_mem_alloc( &mpl_osc, (void**)&buf_ptr, wLength, 0, in_interrupt() ); 2218: if( retval != UDI_OK ){ 2219: 2220: 2221: kernel_mem_free( &mpl_osc, setup, in_interrupt() ); 2222: 2223: uhs_debug_print( DBG_ERR, ( "Usb_Hub_IssueClassRequest : USB HUB Issu Class Req Alloc Error[2] error: ercd=%d", retval ) ); 2224: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 2225: return UDI_STAT_RESOURCE_UNAVAIL; 2226: } 2227: memset( (void*)buf_ptr, 0, wLength ); 2228: ucb_buf_ptr = buf_ptr; 2229: } 2230: 2231: 2232: 2233: 2234: setup->bmRequestType = bmRequestType; 2235: setup->bRequest = bRequest; 2236: setup->wValue0 = (uhs_ubit8_t)( wValue & 0x00FF ); 2237: setup->wValue1 = (uhs_ubit8_t)( ( wValue & 0xFF00 ) >> 8 ); 2238: setup->wIndex0 = (uhs_ubit8_t)( wIndex & 0x00FF ); 2239: setup->wIndex1 = (uhs_ubit8_t)( ( wIndex & 0xFF00 ) >> 8 ); 2240: setup->wLength0 = (uhs_ubit8_t)( wLength & 0x00FF ); 2241: setup->wLength1 = (uhs_ubit8_t)( ( wLength & 0xFF00 ) >> 8 ); 2242: 2243: 2244: 2245: 2246: 2247: 2248: 2249: retval = kernel_create_event( &hub_classreq_done, FALSE ); 2250: if( retval != UDI_OK ){ 2251: uhs_debug_print( DBG_ERR, ( "Usb_Hub_IssueClassRequest : could not create event( Usb_Hub_IssueClassRequest() )" ) ); 2252: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 2253: 2254: 2255: if( setup ) { kernel_mem_free( &mpl_osc, setup, in_interrupt() ); } 2256: if( buf_ptr ) { kernel_mem_free( &mpl_osc, buf_ptr, in_interrupt() ); } 2257: 2258: return UDI_STAT_RESOURCE_UNAVAIL; 2259: } 2260: 2261: 2262: 2263: 2264: Usb_Core_FixupCtrlUcb( hub_info->control_ucb, hub_info->usbdev, pipe, setup, ucb_buf_ptr , wLength, Usb_Hub_CompleteFunc, (void*)&hub_classreq_done ); 2265: 2266: 2267: 2268: 2269: retval = Usbc_Api_ControlMsg( hub_info->control_ucb ); 2270: if( retval != UDI_OK ){ 2271: uhs_debug_print( DBG_ERR, ( "Usb_Hub_IssueClassRequest : Usbc_Api_ControlMsg error: ercd=%d", retval ) ); 2272: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2273: result = kernel_delete_event( &hub_classreq_done ); 2274: if( result != UDI_OK ){ 2275: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2276: } 2277: 2278: 2279: if( setup ) { kernel_mem_free( &mpl_osc, setup, in_interrupt() ); } 2280: if( buf_ptr ) { kernel_mem_free( &mpl_osc, buf_ptr, in_interrupt() ); } 2281: 2282: return retval; 2283: } 2284: 2285: 2286: 2287: 2288: retval = kernel_wait_event( &hub_classreq_done, USB_CTRL_GET_TIMEOUT, in_interrupt() ); 2289: if( retval != UDI_OK ){ 2290: uhs_debug_print( DBG_ERR, ( "Usb_Hub_IssueClassRequest : kernel_wait_event error: ercd=%d", retval ) ); 2291: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2292: 2293: 2294: retval = Usbc_Api_StopTrans( hub_info->control_ucb ); 2295: if( retval != UDI_OK ){ 2296: uhs_debug_print( DBG_ERR, ( "Usb_Hub_IssueClassRequest : USB HUB Stop Interrupt Error: ercd=%d", retval ) ); 2297: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2298: } 2299: 2300: result = kernel_delete_event( &hub_classreq_done ); 2301: if( result != UDI_OK ){ 2302: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2303: } 2304: 2305: 2306: if( setup ) { kernel_mem_free( &mpl_osc, setup, in_interrupt() ); } 2307: if( buf_ptr ) { kernel_mem_free( &mpl_osc, buf_ptr, in_interrupt() ); } 2308: 2309: return UDI_STAT_TERMINATED; 2310: } 2311: 2312: 2313: if( buf_ptr ){ 2314: memcpy( buf , buf_ptr , wLength ); 2315: } 2316: 2317: 2318: 2319: if( setup ) { kernel_mem_free( &mpl_osc, setup, in_interrupt() ); } 2320: if( buf_ptr ) { kernel_mem_free( &mpl_osc, buf_ptr, in_interrupt() ); } 2321: 2322: 2323: 2324: 2325: retval = hub_info->control_ucb->status; 2326: 2327: 2328: 2329: 2330: 2331: 2332: 2333: result = kernel_delete_event( &hub_classreq_done ); 2334: if( result != UDI_OK ){ 2335: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2336: } 2337: 2338: return retval; 2339: } 2340: 2341: 2342: 2349: static uhs_status_t Usb_Hub_GetDescriptor( struct usb_hub_info* hub_info ){ 2350: 2351: uhs_status_t retval = UDI_OK; 2352: uhs_ubit32_t pipe = 0; 2353: uhs_ubit16_t temp = 0; 2354: 2355: 2356: 2357: 2358: if( hub_info == NULL ){ 2359: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_GetDescriptor() )" ) ); 2360: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2361: return UDI_STAT_DATA_ERROR; 2362: } 2363: 2364: 2365: 2366: 2367: Usbc_Api_FixupPipeInfo( &pipe, hub_info->usbdev->usbdev_DevNum, USB_DEFAULT_EP_NUM, USB_PACKETID_IN, USB_TRANS_CONTROL, 2368: hub_info->usbdev->usbdev_EpMaxpktIn[USB_DEFAULT_EP_NUM] ); 2369: 2370: 2371: 2372: 2373: retval = Usb_Hub_IssueClassRequest( hub_info, (uhs_ubit8_t)GET_HUB_DESCRIPTOR_REQTYPE, GET_HUB_DESCRIPTOR_REQ, 2374: GET_HUB_DESCRIPTOR_VALUE, GET_HUB_DESCRIPTOR_INDEX, 2, pipe, hub_info->hub_desc ); 2375: if( ( retval != UDI_OK ) || ( hub_info->hub_desc->bDescLength==0 ) ){ 2376: uhs_debug_print( DBG_ERR, ( "USB HUB GetHubDescriptor( 2Byte ) Wait error: ercd=%d", retval ) ); 2377: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2378: return UDI_STAT_TERMINATED; 2379: } 2380: 2381: 2382: 2383: 2384: retval = Usb_Hub_IssueClassRequest( hub_info, (uhs_ubit8_t)GET_HUB_DESCRIPTOR_REQTYPE, GET_HUB_DESCRIPTOR_REQ, 2385: GET_HUB_DESCRIPTOR_VALUE, GET_HUB_DESCRIPTOR_INDEX, hub_info->hub_desc->bDescLength, pipe, hub_info->hub_desc ); 2386: if( retval != UDI_OK ){ 2387: uhs_debug_print( DBG_ERR, ( "USB HUB GetHubDescriptor( ALL Byte ) Wait error: ercd=%d", retval ) ); 2388: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2389: return UDI_STAT_TERMINATED; 2390: } 2391: 2392: 2393: 2394: 2395: temp = (hub_info->hub_desc->wHubCharacteristics & 0x00FF) << 8; 2396: temp |= (hub_info->hub_desc->wHubCharacteristics & 0xFF00) >> 8; 2397: hub_info->hub_desc->wHubCharacteristics = temp; 2398: 2399: return UDI_OK; 2400: } 2401: 2402: 2411: uhs_status_t Usb_Hub_ClearFeature( struct usb_hub_info* hub_info, uhs_ubit8_t feature, uhs_ubit16_t port_num ){ 2412: 2413: uhs_sbit8_t RequestType = 0; 2414: uhs_ubit32_t pipe = 0; 2415: uhs_status_t retval = UDI_OK; 2416: 2417: 2418: 2419: 2420: if( hub_info == NULL ){ 2421: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_ClearFeature() )" ) ); 2422: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2423: return UDI_STAT_DATA_ERROR; 2424: } 2425: if( hub_info->port_num < port_num ){ 2426: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_ClearFeature() )" ) ); 2427: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2428: return UDI_STAT_DATA_ERROR; 2429: } 2430: if( port_num != 0 ){ 2431: switch( feature ){ 2432: 2433: case PORT_ENABLE: 2434: case PORT_SUSPEND: 2435: 2436: 2437: case PORT_POWER: 2438: 2439: case C_PORT_CONNECTION: 2440: case C_PORT_ENABLE: 2441: case C_PORT_SUSPEND: 2442: case C_PORT_OVERCURRENT: 2443: case C_PORT_RESET: 2444: 2445: case PORT_INDICATOR: 2446: 2447: RequestType = CLEAR_PORT_FEATURE; 2448: break; 2449: default: 2450: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_ClearFeature() )" ) ); 2451: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2452: return UDI_STAT_DATA_ERROR; 2453: } 2454: }else{ 2455: switch( feature ){ 2456: case C_HUB_LOCAL_POWER: 2457: case C_HUB_OVER_CURRENT: 2458: 2459: RequestType = CLEAR_HUB_FEATURE; 2460: break; 2461: default: 2462: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_ClearFeature() )" ) ); 2463: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2464: return UDI_STAT_DATA_ERROR; 2465: } 2466: } 2467: 2468: 2469: 2470: 2471: Usbc_Api_FixupPipeInfo( &pipe, hub_info->usbdev->usbdev_DevNum, USB_DEFAULT_EP_NUM, USB_PACKETID_OUT, 2472: USB_TRANS_CONTROL, hub_info->usbdev->usbdev_EpMaxpktIn[USB_DEFAULT_EP_NUM] ); 2473: 2474: 2475: 2476: 2477: retval = Usb_Hub_IssueClassRequest( hub_info, ( uhs_ubit8_t )RequestType, HUB_CLEAR_FEATURE_REQ, feature, port_num, 0, pipe, hub_info->hub_desc ); 2478: if( retval != UDI_OK ){ 2479: uhs_debug_print( DBG_ERR, ( "Usb_Hub_IssueClassRequest error: ercd=%d", retval ) ); 2480: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2481: return UDI_STAT_TERMINATED; 2482: } 2483: 2484: return UDI_OK; 2485: } 2486: 2487: 2496: uhs_status_t Usb_Hub_SetFeature( struct usb_hub_info* hub_info, uhs_ubit8_t feature, uhs_ubit16_t port_num ){ 2497: 2498: uhs_sbit8_t RequestType = 0; 2499: uhs_ubit32_t pipe = 0; 2500: uhs_status_t retval = UDI_OK; 2501: 2502: 2503: 2504: 2505: if( hub_info == NULL ){ 2506: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_SetFeature() )" ) ); 2507: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2508: return UDI_STAT_DATA_ERROR; 2509: } 2510: if( hub_info->port_num < port_num ){ 2511: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_SetFeature() )" ) ); 2512: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2513: return UDI_STAT_DATA_ERROR; 2514: } 2515: if( port_num != 0 ){ 2516: switch( feature ){ 2517: 2518: 2519: case PORT_SUSPEND: 2520: 2521: case PORT_RESET: 2522: case PORT_POWER: 2523: 2524: case C_PORT_CONNECTION: 2525: case C_PORT_ENABLE: 2526: case C_PORT_SUSPEND: 2527: case C_PORT_OVERCURRENT: 2528: case C_PORT_RESET: 2529: case PORT_TEST: 2530: case PORT_INDICATOR: 2531: 2532: RequestType = CLEAR_PORT_FEATURE; 2533: break; 2534: default: 2535: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_SetFeature() )" ) ); 2536: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2537: return UDI_STAT_DATA_ERROR; 2538: } 2539: }else{ 2540: switch( feature ){ 2541: case C_HUB_LOCAL_POWER: 2542: case C_HUB_OVER_CURRENT: 2543: 2544: RequestType = CLEAR_HUB_FEATURE; 2545: break; 2546: default: 2547: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_SetFeature() )" ) ); 2548: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2549: return UDI_STAT_DATA_ERROR; 2550: } 2551: } 2552: 2553: 2554: 2555: 2556: Usbc_Api_FixupPipeInfo( &pipe, hub_info->usbdev->usbdev_DevNum, USB_DEFAULT_EP_NUM, USB_PACKETID_OUT, 2557: USB_TRANS_CONTROL, hub_info->usbdev->usbdev_EpMaxpktIn[USB_DEFAULT_EP_NUM] ); 2558: 2559: 2560: 2561: 2562: retval = Usb_Hub_IssueClassRequest( hub_info, ( uhs_ubit8_t )RequestType, HUB_SET_FEATURE_REQ, 2563: feature, port_num, 0, pipe, hub_info->hub_desc ); 2564: if( retval != UDI_OK ){ 2565: uhs_debug_print( DBG_ERR, ( "USB HUB Usb_Hub_SetFeature error: ercd=%d", retval ) ); 2566: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2567: return UDI_STAT_TERMINATED; 2568: } 2569: 2570: return UDI_OK; 2571: } 2572: 2573: 2582: uhs_status_t Usb_Hub_GetStatus( struct usb_hub_info* hub_info, void* buf, uhs_ubit16_t port_num ){ 2583: 2584: uhs_ubit8_t RequestType = 0; 2585: uhs_ubit32_t pipe = 0; 2586: uhs_status_t retval = UDI_OK; 2587: 2588: 2589: 2590: 2591: if( ( hub_info == NULL ) || ( buf == NULL ) ){ 2592: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_GetStatus() )" ) ); 2593: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2594: return UDI_STAT_DATA_ERROR; 2595: } 2596: if( hub_info->port_num < port_num ){ 2597: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_GetStatus() )" ) ); 2598: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2599: return UDI_STAT_DATA_ERROR; 2600: } 2601: 2602: 2603: 2604: 2605: if( port_num != 0 ){ 2606: 2607: RequestType = GET_PORT_STATUS; 2608: }else{ 2609: 2610: RequestType = GET_HUB_STATUS; 2611: } 2612: 2613: 2614: 2615: 2616: Usbc_Api_FixupPipeInfo( &pipe, hub_info->usbdev->usbdev_DevNum, USB_DEFAULT_EP_NUM, USB_PACKETID_IN, 2617: USB_TRANS_CONTROL, hub_info->usbdev->usbdev_EpMaxpktIn[USB_DEFAULT_EP_NUM] ); 2618: 2619: 2620: 2621: 2622: retval = Usb_Hub_IssueClassRequest( hub_info, ( uhs_ubit8_t )RequestType, HUB_GET_STATUS_REQ, 0, 2623: port_num, GET_STATUS_LENGTH, pipe, buf ); 2624: if( retval != UDI_OK ){ 2625: uhs_debug_print( DBG_ERR, ( "Usb_Hub_IssueClassRequest error: ercd=%d", retval ) ); 2626: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2627: 2628: #ifdef USBH_DBG_ADD_MESSAGE 2629: uhs_debug_print( DBG_ERR, ( "Fail - Get Port ststus ") ); 2630: #endif 2631: 2632: return UDI_STAT_TERMINATED; 2633: } 2634: 2635: #ifdef USBH_DBG_ADD_MESSAGE 2636: 2637: 2638: 2639: 2640: #endif 2641: 2642: return UDI_OK; 2643: } 2644: 2645: 2646: 2647: 2657: static uhs_ubit16_t Usb_Hub_Make_wValue_for_CTTBUFF( 2658: uhs_ubit8_t direction, 2659: uhs_ubit16_t ep_kind, 2660: uhs_ubit16_t dev_addr, 2661: uhs_ubit16_t ep_num 2662: ) 2663: { 2664: uhs_ubit16_t ret = 0; 2665: uhs_ubit16_t dir16 = (uhs_ubit16_t)direction; 2666: 2667: 2668: dir16 = dir16 << 8; 2669: 2670: ret |= (dir16 & USB_HUB_WVALUE_DIR_MSK); 2671: ret |= ((ep_kind << 11) & USB_HUB_WVALUE_EPKIND_MSK); 2672: ret |= ((dev_addr << 4) & USB_HUB_WVALUE_DEVADDR_MSK); 2673: ret |= ((ep_num << 0) & USB_HUB_WVALUE_EPNUM_MSK); 2674: 2675: return ret; 2676: } 2677: 2678: 2679: 2680: 2681: 2693: static uhs_status_t Usb_Hub_ClearTTBuffer( 2694: struct usb_hub_info* hub_info, 2695: uhs_ubit16_t tt_port, 2696: uhs_ubit8_t err_direction, 2697: uhs_ubit16_t err_ep_kind, 2698: uhs_ubit16_t err_dev_addr, 2699: uhs_ubit16_t err_ep_num 2700: ){ 2701: 2702: uhs_sbit16_t wValue = 0; 2703: uhs_ubit32_t pipe = 0; 2704: uhs_status_t retval = UDI_OK; 2705: 2706: 2707: 2708: 2709: if( hub_info == NULL ){ 2710: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_ClearTTBuffer() )" ) ); 2711: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2712: return UDI_STAT_DATA_ERROR; 2713: } 2714: if( 1 > tt_port ){ 2715: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_ClearTTBuffer() )" ) ); 2716: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2717: return UDI_STAT_DATA_ERROR; 2718: } 2719: 2720: 2721: 2722: 2723: Usbc_Api_FixupPipeInfo( 2724: &pipe, 2725: hub_info->usbdev->usbdev_DevNum, 2726: USB_DEFAULT_EP_NUM, 2727: USB_PACKETID_OUT, 2728: USB_TRANS_CONTROL, 2729: hub_info->usbdev->usbdev_EpMaxpktIn[USB_DEFAULT_EP_NUM] 2730: ); 2731: 2732: 2733: 2734: 2735: 2736: 2737: 2738: 2739: 2740: wValue = Usb_Hub_Make_wValue_for_CTTBUFF( 2741: err_direction, 2742: err_ep_kind, 2743: err_dev_addr, 2744: err_ep_num 2745: ); 2746: 2747: 2748: 2749: 2750: retval = Usb_Hub_IssueClassRequest( 2751: hub_info, 2752: CLEAR_TT_BUFFER_BMREQ, 2753: CLEAR_TT_BUFFER_BREQ, 2754: wValue, 2755: tt_port, 2756: 0, 2757: pipe, 2758: hub_info->hub_desc 2759: ); 2760: if( retval != UDI_OK ){ 2761: uhs_debug_print( DBG_ERR, ( "USB HUB Usb_Hub_ClearTTBuffer error: ercd=%d", retval ) ); 2762: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2763: return UDI_STAT_TERMINATED; 2764: } 2765: 2766: return UDI_OK; 2767: } 2768: 2769: 2770: 2771: 2772: 2779: static uhs_status_t Usb_Hub_RESET_TT( struct usb_hub_info* hub_info , uhs_ubit16_t tt_port) 2780: { 2781: uhs_ubit32_t pipe = 0; 2782: uhs_status_t retval = UDI_OK; 2783: 2784: 2785: 2786: 2787: if( hub_info == NULL ){ 2788: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_HubApi_RESET_TT() )" ) ); 2789: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2790: return UDI_STAT_DATA_ERROR; 2791: } 2792: if( 1 > tt_port ){ 2793: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_HubApi_RESET_TT() )" ) ); 2794: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2795: return UDI_STAT_DATA_ERROR; 2796: } 2797: 2798: 2799: 2800: 2801: Usbc_Api_FixupPipeInfo( 2802: &pipe, 2803: hub_info->usbdev->usbdev_DevNum, 2804: USB_DEFAULT_EP_NUM, 2805: USB_PACKETID_OUT, 2806: USB_TRANS_CONTROL, 2807: hub_info->usbdev->usbdev_EpMaxpktIn[USB_DEFAULT_EP_NUM] 2808: ); 2809: 2810: 2811: 2812: 2813: retval = Usb_Hub_IssueClassRequest( 2814: hub_info, 2815: RESET_TT_BMREQ, 2816: RESET_TT_BREQ, 2817: 0, 2818: tt_port, 2819: 0, 2820: pipe, 2821: hub_info->hub_desc 2822: ); 2823: if( retval != UDI_OK ){ 2824: uhs_debug_print( DBG_ERR, ( "USB HUB Usb_HubApi_RESET_TT error: ercd=%d", retval ) ); 2825: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2826: return UDI_STAT_TERMINATED; 2827: } 2828: 2829: return UDI_OK; 2830: } 2831: 2832: 2833: 2834: 2835: 2836: 2837: 2838: 2839: 2840: 2841: 2842: 2849: static uhs_status_t Usb_Hub_PortInitial( struct usb_hub_info* hub_info ){ 2850: 2851: uhs_ubit8_t i = 0; 2852: uhs_status_t retval = UDI_OK; 2853: 2854: 2855: 2856: 2857: if( hub_info == NULL ){ 2858: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_IntCompleteFunc() )" ) ); 2859: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2860: return UDI_STAT_DATA_ERROR; 2861: } 2862: 2863: 2864: 2865: 2866: for( i = 1 ; i <= hub_info->port_num ; i++ ){ 2867: 2868: #ifdef USBH_DBG_ADD_MESSAGE 2869: 2870: uhs_debug_print( DBG_ERR, ( "\x1b[7mHUB : Set (PORT_POWER) total=%d / hub_adr=%d / port=%d \x1b[0m", hub_info->port_num , hub_info->usbdev->usbdev_DevNum , i) ); 2871: #endif 2872: 2873: retval = Usb_Hub_SetFeature( hub_info, PORT_POWER, i ); 2874: if( retval != UDI_OK ){ 2875: uhs_debug_print( DBG_ERR, ( "USB HUB SetPortFeature( PORT_POWER ) Error: ercd=%d, portnum=%d", retval, i ) ); 2876: HUB_REPORT_WARNING( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2877: return retval; 2878: } 2879: 2880: 2881: 2882: 2883: kernel_wait( NULL, hub_info->PwrOnWait ); 2884: } 2885: 2886: return UDI_OK; 2887: } 2888: 2889: 2890: 2891: 2892: 2900: static uhs_status_t Usb_Hub_AllocHubInfo( struct usb_hub_info** hub_info, struct usbd_usb_deviceinfo* usbdev ){ 2901: 2902: uhs_status_t retval = UDI_OK; 2903: uhs_status_t result = UDI_OK; 2904: struct usb_hub_info* hub_info_temp = NULL; 2905: 2906: 2907: 2908: 2909: if( ( hub_info == NULL ) || ( usbdev == NULL ) ){ 2910: uhs_debug_print( DBG_ERR, ( "Parameter Error( Usb_Hub_AllocHubInfo() )" ) ); 2911: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 2912: return UDI_STAT_DATA_ERROR; 2913: } 2914: 2915: 2916: 2917: 2918: retval = kernel_mem_alloc( &mpl_osc, (void**)hub_info, sizeof( struct usb_hub_info ), 0, in_interrupt() ); 2919: if( retval != UDI_OK ){ 2920: uhs_debug_print( DBG_ERR, ( "USB HUB Attach Hub Struct Alloc Error error: ercd=%d", retval ) ); 2921: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 2922: return retval; 2923: } 2924: memset( (void*)*hub_info, 0, sizeof( struct usb_hub_info ) ); 2925: hub_info_temp = *hub_info; 2926: 2927: 2928: 2929: 2930: hub_info_temp->usbdev = usbdev; 2931: usbdev->context = hub_info_temp; 2932: 2933: 2934: 2935: 2936: retval = kernel_create_semaphore( &hub_info_temp->hub_info_sem, 1, 1 ); 2937: if( retval != UDI_OK ){ 2938: uhs_debug_print( DBG_ERR, ( "USB HUB Attach Hub Struct SemCreate Error error: ercd=%d", retval ) ); 2939: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 2940: 2941: 2942: result = kernel_mem_free( &mpl_osc, *hub_info, in_interrupt() ); 2943: if( result != UDI_OK ){ 2944: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2945: } 2946: 2947: return retval; 2948: } 2949: 2950: 2951: 2952: 2953: retval = kernel_mem_alloc( &mpl_osc, (void**)&hub_info_temp->hub_desc, sizeof( struct hub_descriptor ), 0, in_interrupt() ); 2954: if( retval != UDI_OK ){ 2955: uhs_debug_print( DBG_ERR, ( "USB HUB Attach Hub Descriptor Alloc Error error: ercd=%d", retval ) ); 2956: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 2957: 2958: 2959: result = kernel_delete_semaphore( &hub_info_temp->hub_info_sem ); 2960: if( result != UDI_OK ){ 2961: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2962: } 2963: 2964: 2965: result = kernel_mem_free( &mpl_osc, *hub_info, in_interrupt() ); 2966: if( result != UDI_OK ){ 2967: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2968: } 2969: return retval; 2970: } 2971: 2972: memset( (void*)hub_info_temp->hub_desc, 0, sizeof( struct hub_descriptor ) ); 2973: 2974: 2975: 2976: 2977: retval = Usbc_Api_AllocUsbCtrlBlock( &hub_info_temp->control_ucb ); 2978: if( retval != UDI_OK ){ 2979: uhs_debug_print( DBG_ERR, ( "USB HUB Control ucb Mem Alloc error: ercd=%d", retval ) ); 2980: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 2981: 2982: 2983: result = kernel_mem_free( &mpl_osc, hub_info_temp->hub_desc, in_interrupt() ); 2984: if( result != UDI_OK ){ 2985: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2986: } 2987: 2988: 2989: result = kernel_delete_semaphore( &hub_info_temp->hub_info_sem ); 2990: if( result != UDI_OK ){ 2991: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2992: } 2993: 2994: 2995: result = kernel_mem_free( &mpl_osc,* hub_info, in_interrupt() ); 2996: if( result != UDI_OK ){ 2997: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 2998: } 2999: return UDI_STAT_RESOURCE_UNAVAIL; 3000: } 3001: 3002: 3003: 3004: 3005: retval = Usbc_Api_AllocUsbCtrlBlock( &hub_info_temp->intr_ucb ); 3006: if( retval != UDI_OK ){ 3007: uhs_debug_print( DBG_ERR, ( "USB HUB Interrupt ucb Mem Alloc error: ercd=%d", retval ) ); 3008: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 3009: 3010: 3011: retval = Usbc_Api_FreeUsbCtrlBlock( hub_info_temp->control_ucb ); 3012: if( result != UDI_OK ){ 3013: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 3014: } 3015: 3016: 3017: result = kernel_mem_free( &mpl_osc, hub_info_temp->hub_desc, in_interrupt() ); 3018: if( result != UDI_OK ){ 3019: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 3020: } 3021: 3022: 3023: result = kernel_delete_semaphore( &hub_info_temp->hub_info_sem ); 3024: if( result != UDI_OK ){ 3025: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 3026: } 3027: 3028: 3029: result = kernel_mem_free( &mpl_osc,* hub_info, in_interrupt() ); 3030: if( result != UDI_OK ){ 3031: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 3032: } 3033: 3034: return UDI_STAT_RESOURCE_UNAVAIL; 3035: } 3036: 3037: 3038: 3039: 3040: retval = Usb_Hub_AddHubInfo_List( *hub_info ); 3041: if( retval != UDI_OK ){ 3042: uhs_debug_print( DBG_ERR, ( "USB HUB Attach Hub Struct List Add Error error: ercd=%d", retval ) ); 3043: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 3044: return UDI_STAT_RESOURCE_UNAVAIL; 3045: } 3046: 3047: g_hub_conn_cnt++; 3048: 3049: #ifdef USBH_DBG_ADD_MESSAGE 3050: 3051: #endif 3052: return UDI_OK; 3053: } 3054: 3055: 3062: static uhs_status_t Usb_Hub_FreeHubInfo( struct usb_hub_info* hub_info ){ 3063: 3064: uhs_status_t retval = UDI_OK; 3065: uhs_status_t result = UDI_OK; 3066: 3067: 3068: 3069: 3070: if( hub_info == NULL ){ 3071: HUB_REPORT_ERROR( USBCLS_HUB_INVALID_PARAMETER, 0 ); 3072: return UDI_STAT_DATA_ERROR; 3073: } 3074: 3075: if( g_hub_conn_cnt ){ 3076: g_hub_conn_cnt--; 3077: } 3078: 3079: #ifdef USBH_DBG_ADD_MESSAGE 3080: 3081: #endif 3082: 3083: 3084: 3085: 3086: retval = Usb_Hub_DelHubInfo_List( hub_info ); 3087: if( retval != UDI_OK ){ 3088: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 3089: } 3090: 3091: 3092: 3093: 3094: retval = Usbc_Api_ClosePipe( hub_info->control_ucb ); 3095: if( retval != UDI_OK ){ 3096: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 3097: result = UDI_STAT_RESOURCE_UNAVAIL; 3098: } 3099: 3100: 3101: 3102: 3103: retval = Usbc_Api_ClosePipe( hub_info->intr_ucb ); 3104: if( retval != UDI_OK ){ 3105: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 3106: result = UDI_STAT_RESOURCE_UNAVAIL; 3107: } 3108: 3109: 3110: 3111: 3112: if( hub_info->control_ucb != NULL ){ 3113: retval = Usbc_Api_FreeUsbCtrlBlock( hub_info->control_ucb ); 3114: if( retval != UDI_OK ){ 3115: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 3116: result = UDI_STAT_RESOURCE_UNAVAIL; 3117: } 3118: } 3119: 3120: 3121: 3122: 3123: if( hub_info->intr_ucb != NULL ){ 3124: retval = Usbc_Api_FreeUsbCtrlBlock( hub_info->intr_ucb ); 3125: if( retval != UDI_OK ){ 3126: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 3127: result = UDI_STAT_RESOURCE_UNAVAIL; 3128: } 3129: } 3130: 3131: 3132: 3133: 3134: if( hub_info->hub_desc != NULL ){ 3135: retval = kernel_mem_free( &mpl_osc, hub_info->hub_desc, in_interrupt() ); 3136: if( retval != UDI_OK ){ 3137: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 3138: result = UDI_STAT_RESOURCE_UNAVAIL; 3139: } 3140: } 3141: 3142: 3143: 3144: 3145: if( hub_info->hub_intr_buf != NULL ){ 3146: retval = kernel_mem_free( &mpl_osc, (void*)hub_info->hub_intr_buf, in_interrupt() ); 3147: if( retval != UDI_OK ){ 3148: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 3149: result = UDI_STAT_RESOURCE_UNAVAIL; 3150: } 3151: } 3152: 3153: 3154: 3155: 3156: retval = kernel_delete_semaphore( &hub_info->hub_info_sem ); 3157: if( retval != UDI_OK ){ 3158: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 3159: result = UDI_STAT_RESOURCE_UNAVAIL; 3160: } 3161: 3162: 3163: 3164: 3165: retval = kernel_mem_free( &mpl_osc, hub_info, in_interrupt() ); 3166: if( retval != UDI_OK ){ 3167: HUB_REPORT_ERROR( USBCLS_HUB_ILLEGAL_ERROR, 0 ); 3168: result = UDI_STAT_RESOURCE_UNAVAIL; 3169: } 3170: 3171: return result; 3172: } 3173: 3174: 3187: void Usb_Hub_ReportStatus( 3188: const char* pFileName, 3189: uhs_ubit32_t nLine, 3190: usb_msglevel level, 3191: uhs_ubit16_t msgdata, 3192: uhs_ubit8_t port_num, 3193: uhs_ubit8_t hub_adr 3194: ){ 3195: 3196: char extdata[HUB_EXTDATA_MAXLENGTH] = { 0 }; 3197: usb_msgformat stsmsg; 3198: uhs_status_t result = UDI_OK; 3199: const char* tmp = NULL; 3200: int i = 0; 3201: int count = 0; 3202: 3203: 3204: 3205: 3206: if( pFileName == NULL ){ 3207: return; 3208: } 3209: if( level == USB_MSGMON_MSGLVL_ERROR || 3210: level == USB_MSGMON_MSGLVL_WARNING ){ 3211: switch( msgdata ){ 3212: case USBCLS_HUB_DETECT_OVERCURRENT: 3213: case USBCLS_HUB_ILLEGAL_ERROR: 3214: case USBCLS_HUB_RESOURCE_UNAVAIL: 3215: case USBCLS_HUB_INVALID_PARAMETER: 3216: case USBCLS_HUB_IMPORTANT_ERROR: 3217: case USBCLS_HUB_OVERCONN: 3218: break; 3219: default: 3220: return; 3221: } 3222: }else if( level == USB_MSGMON_MSGLVL_MILESTONE ){ 3223: switch( msgdata ){ 3224: case USBCLS_HUB_INIT_COMP: 3225: case USBCLS_HUB_EXIT_COMP: 3226: case USBCLS_HUB_DEVICE_CONNECTED: 3227: case USBCLS_HUB_DEVICE_DISCONNECTED: 3228: case USBCLS_HUB_DEVICE_CONNECT_NG: 3229: break; 3230: default: 3231: return; 3232: } 3233: }else{ 3234: return; 3235: } 3236: 3237: if( level == USB_MSGMON_MSGLVL_MILESTONE ){ 3238: 3239: 3240: 3241: if(( ( msgdata == USBCLS_HUB_DEVICE_CONNECTED ) || ( msgdata == USBCLS_HUB_DEVICE_DISCONNECTED ) || ( msgdata == USBCLS_HUB_DEVICE_CONNECT_NG ) ) ){ 3242: tmp = "hub_adr:port("; 3243: while( ( *tmp != '\0' ) && ( i < HUB_EXTDATA_MAXLENGTH-10 ) ){ 3244: extdata[i++] = *(tmp++); 3245: } 3246: count = Usbh_StatusMon_getDecimalString( hub_adr, &extdata[i] ); 3247: i+=count; 3248: extdata[i++] = ':'; 3249: count = Usbh_StatusMon_getDecimalString( port_num, &extdata[i] ); 3250: i+=count; 3251: extdata[i++] = ')'; 3252: 3253: extdata[i++] = ' '; 3254: 3255: stsmsg.extdatasize = strlen(extdata)+1; 3256: stsmsg.extdata = extdata; 3257: } 3258: else{ 3259: 3260: stsmsg.extdatasize = 0; 3261: stsmsg.extdata = NULL; 3262: } 3263: } 3264: else{ 3265: 3266: 3267: 3268: tmp = pFileName; 3269: while( ( *tmp != '\0' ) && ( i < HUB_EXTDATA_MAXLENGTH-10 ) ){ 3270: extdata[i++] = *(tmp++); 3271: } 3272: extdata[i++] = '('; 3273: count = Usbh_StatusMon_getDecimalString( nLine, &extdata[i] ); 3274: i += count; 3275: extdata[i++] = ')'; 3276: extdata[i++] = '\0'; 3277: 3278: stsmsg.extdatasize = strlen(extdata)+1; 3279: stsmsg.extdata = extdata; 3280: } 3281: 3282: 3283: 3284: 3285: stsmsg.msglayer = USB_MSGMON_LAYER_USBH_CLASSDRIVER; 3286: stsmsg.msgsublayer = USB_MSGMON_SUBLAYER_CLSDRV_HUB; 3287: stsmsg.msgtype = 0; 3288: stsmsg.msglevel = level; 3289: stsmsg.msgdata = msgdata; 3290: 3291: 3292: 3293: 3294: result = Usbh_StatusMon_ReportStatus( stsmsg ); 3295: if( result != UDI_OK ){ 3296: 3297: } 3298: 3299: return; 3300: } 3301: 3302: 3303: 3304: 3305: extern uhs_list_node_t g_hub_info_list; 3306: extern kernel_context_t g_hub_info_listsem; 3307: 3308: 3315: uhs_status_t Usb_Hub_AddHubInfo_List( struct usb_hub_info* hub_info ) 3316: { 3317: uhs_status_t retval = UDI_OK; 3318: 3319: 3320: retval = kernel_acquisition_semaphore( &g_hub_info_listsem, WAITFOREVER, in_interrupt() ); 3321: if( retval != UDI_OK ){ 3322: uhs_debug_print( DBG_ERR, ( "Usb_Hub_AddHubInfo_List: semaphore acq error" ) ); 3323: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 3324: return retval; 3325: } 3326: 3327: 3328: lists_addition_ListTail( &g_hub_info_list , (void *)hub_info ); 3329: 3330: 3331: retval = kernel_release_semaphore( &g_hub_info_listsem , in_interrupt() ); 3332: if( retval != UDI_OK ){ 3333: uhs_debug_print( DBG_ERR, ( "Usb_Hub_AddHubInfo_List: semaphore rel error" ) ); 3334: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 3335: } 3336: 3337: return retval; 3338: } 3339: 3340: 3341: 3348: uhs_status_t Usb_Hub_DelHubInfo_List( struct usb_hub_info* hub_info ) 3349: { 3350: uhs_status_t retval = UDI_OK; 3351: 3352: 3353: retval = kernel_acquisition_semaphore( &g_hub_info_listsem, WAITFOREVER, in_interrupt() ); 3354: if( retval != UDI_OK ){ 3355: uhs_debug_print( DBG_ERR, ( "Usb_Hub_DelHubInfo_List: semaphore acq error" ) ); 3356: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 3357: return retval; 3358: } 3359: 3360: 3361: lists_delet_FromList( &g_hub_info_list , (void *)hub_info ); 3362: 3363: 3364: retval = kernel_release_semaphore( &g_hub_info_listsem , in_interrupt() ); 3365: if( retval != UDI_OK ){ 3366: uhs_debug_print( DBG_ERR, ( "Usb_Hub_DelHubInfo_List: semaphore rel error" ) ); 3367: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 3368: } 3369: 3370: return retval; 3371: } 3372: 3373: 3374: 3382: uhs_status_t Usb_Hub_ChkHubInfo_List( struct usb_hub_info* hub_info , uhs_ubit8_t *chk_result ) 3383: { 3384: uhs_status_t retval = UDI_OK; 3385: struct usb_hub_info *tmpnode = NULL; 3386: 3387: 3388: *chk_result = 0; 3389: 3390: 3391: retval = kernel_acquisition_semaphore( &g_hub_info_listsem, WAITFOREVER, in_interrupt() ); 3392: if( retval != UDI_OK ){ 3393: uhs_debug_print( DBG_ERR, ( "Usb_Hub_ChkHubInfo_List: semaphore acq error" ) ); 3394: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 3395: return retval; 3396: } 3397: 3398: 3399: tmpnode = (struct usb_hub_info *)lists_get_FirstElement( &g_hub_info_list ); 3400: while ( lists_get_RoopIsEnd( tmpnode ) == FALSE ) { 3401: 3402: 3403: if( tmpnode == hub_info ){ 3404: 3405: 3406: *chk_result = 1; 3407: break; 3408: } 3409: 3410: 3411: tmpnode = (struct usb_hub_info *)lists_get_NextElement( &g_hub_info_list , tmpnode ); 3412: } 3413: 3414: 3415: retval = kernel_release_semaphore( &g_hub_info_listsem , in_interrupt() ); 3416: if( retval != UDI_OK ){ 3417: uhs_debug_print( DBG_ERR, ( "Usb_Hub_ChkHubInfo_List: semaphore rel error" ) ); 3418: HUB_REPORT_ERROR( USBCLS_HUB_RESOURCE_UNAVAIL, 0 ); 3419: } 3420: 3421: return retval; 3422: }
Copyright (c) 2017-2025 Axell Corporation. All rights reserved.