/** Check TDs Results @Param Ohc UHC private data @Param Td TD_DESCRIPTOR @Param Result Result to return @retval TRUE means OK @retval FLASE means Error or Short packet **/ BOOLEAN OhciCheckTDsResults ( IN USB_OHCI_HC_DEV *Ohc, IN TD_DESCRIPTOR *Td, OUT UINT32 *Result ) { UINT32 TdCompletionCode; *Result = EFI_USB_NOERROR; while (Td) { TdCompletionCode = Td->Word0.ConditionCode; *Result |= ConvertErrorCode(TdCompletionCode); // // if any error encountered, stop processing the left TDs. // if (*Result) { return FALSE; } Td = (TD_DESCRIPTOR *)(UINTN)(Td->NextTDPointer); } return TRUE; }
datatypes::ReturnType HaierCommonSDK::ExecuteOperations(const char *deviceid, const datatypes::AttributeValuePair &pair) { context_t *context = ugw_new_context(); char str[64] = {0}; datatypes::ValType type = pair.GetValue().GetValues()[0].GetValueType(); const void *value = pair.GetValue().GetValues()[0].GetValue(); switch (type) { case datatypes::ValType::INT: { sprintf(str, "%d", *(int *) value); break; } case datatypes::ValType::FLOAT: { sprintf(str, "%d", *(int *) value); break; } case datatypes::ValType::DOUBLE: { sprintf(str, "%d", *(int *) value); break; } } int ret = ugw_set_attr(handle, context, (char *) deviceid, (char *) (pair.GetAttribute().GetAttributeName().c_str()), str); datatypes::ReturnType returnType = datatypes::ReturnType(datatypes::RealDevice(deviceid, HAIER_VENDOR_ID), pair, "", ConvertErrorCode(ret), ""); ugw_free_context(context); return returnType; }
datatypes::ReturnType HaierCommonSDK::GetInfo(const datatypes::RealDevice &device, const datatypes::Attribute &attr_names, void *extra) { if (attr_names.GetAttributeName().compare(GET_ALARM) == 0) { if (device_alarm_cache.find(device) != device_alarm_cache.end()) { datatypes::Value value = datatypes::Value(); if (device_alarm_cache.find(device) != device_alarm_cache.end()) { for (int i = 0; i < device_alarm_cache[device].size(); i++) { value.InsertValue( datatypes::ValueTypePair( device_alarm_cache[device][i], datatypes::ValType::STRING ) ); } } datatypes::AttributeValuePair pair = datatypes::AttributeValuePair( datatypes::Attribute(GET_ALARM), value); datatypes::ReturnType returnType = datatypes::ReturnType(device, pair, "", datatypes::ReturnType::SDK_OK, ""); return returnType; } else { datatypes::AttributeValuePair pair = datatypes::AttributeValuePair(datatypes::Attribute(GET_ALARM), datatypes::Value()); return datatypes::ReturnType(device, pair, "", datatypes::ReturnType::SDK_OK, ""); } } char *attr_name = (char *) attr_names.GetAttributeName().c_str(); context_t *context = ugw_new_context(); //while (!device_set_attr_lock); int ret = ugw_get_attr(handle, context, (char *) device.GetDeviceId().c_str(), attr_name); std::vector<datatypes::ValueTypePair> vector;// = std::vector<datatypes::ValueTypePair>(); if (ret == 0) { datatypes::ValueTypePair pair(new int(atoi(context->value)), datatypes::ValType::INT); vector.push_back(pair); } datatypes::AttributeValuePair attributeValuePair(attr_names, datatypes::Value(vector)); datatypes::ReturnType returnType(device, attributeValuePair, "", ConvertErrorCode(ret), ""); ugw_free_context(context); return returnType; }
datatypes::ReturnType HaierCommonSDK::ConfigureDevice(const char *ssid, const char *passwd, const char *deviceid) { int ret = 0;//ugw_smartconfig(handle, (char *) ssid, (char *) passwd, (char *) deviceid); // int i = 0; // std::cout<<"ssid: "<<ssid<<std::endl<<"passwd: "<<passwd<<std::endl<<"deviceid: "<<deviceid<<std::endl; // while (!device_configure_lock) { // i++; // if (i > 90) { // datatypes::ReturnType returnType = datatypes::ReturnType( // datatypes::RealDevice(deviceid, HAIER_VENDOR_ID), // datatypes::AttributeValuePair( datatypes::Attribute(DEVICE_CONFIG), // datatypes::Value()), "", // datatypes::ReturnType::SDK_CMD_TIMED_OUT, ""); // return returnType; // } // } datatypes::ReturnType returnType = datatypes::ReturnType(datatypes::RealDevice(deviceid, HAIER_VENDOR_ID), datatypes::AttributeValuePair( datatypes::Attribute("DeviceConfigure"), datatypes::Value()), "", ConvertErrorCode(ret), ""); //GetDevList(nullptr); returnType.SetErrorCode(ConvertErrorCode(ret)); return returnType; }
datatypes::ReturnType HaierCommonSDK::GetDevList(void *extra) { context_t *context = ugw_new_context(); int ret = ugw_get_devs(handle, context); datatypes::Value value = datatypes::Value(); for (int i = 0; i < context->dev_count; i++) { datatypes::RealDevice *rd = new datatypes::RealDevice(context->devs[i].device_id, HAIER_VENDOR_ID); datatypes::ValueTypePair pair(rd, datatypes::ValType::REAL_DEVICE); value.InsertValue(pair); } datatypes::Attribute attr = datatypes::Attribute(REAL_DEVICE_LIST); datatypes::AttributeValuePair attributeValuePair = datatypes::AttributeValuePair(attr, value); datatypes::ReturnType returnType(datatypes::RealDevice("", HAIER_VENDOR_ID), attributeValuePair, "", ConvertErrorCode(ret), ""); ugw_free_context(context); return returnType; }
/** Submits control transfer to a target USB device. @param PeiServices The pointer of EFI_PEI_SERVICES. @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI. @param DeviceAddress The target device address. @param DeviceSpeed Target device speed. @param MaximumPacketLength Maximum packet size the default control transfer endpoint is capable of sending or receiving. @param Request USB device request to send. @param TransferDirection Specifies the data direction for the data stage. @param Data Data buffer to be transmitted or received from USB device. @param DataLength The size (in bytes) of the data buffer. @param TimeOut Indicates the maximum timeout, in millisecond. @param TransferResult Return the result of this control transfer. @retval EFI_SUCCESS Transfer was completed successfully. @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resources. @retval EFI_INVALID_PARAMETER Some parameters are invalid. @retval EFI_TIMEOUT Transfer failed due to timeout. @retval EFI_DEVICE_ERROR Transfer failed due to host controller or device error. **/ EFI_STATUS EFIAPI OhciControlTransfer ( IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_HOST_CONTROLLER_PPI *This, IN UINT8 DeviceAddress, IN UINT8 DeviceSpeed, IN UINT8 MaxPacketLength, IN EFI_USB_DEVICE_REQUEST *Request, IN EFI_USB_DATA_DIRECTION TransferDirection, IN OUT VOID *Data, IN OUT UINTN *DataLength, IN UINTN TimeOut, OUT UINT32 *TransferResult ) { USB_OHCI_HC_DEV *Ohc; ED_DESCRIPTOR *Ed; TD_DESCRIPTOR *HeadTd; TD_DESCRIPTOR *SetupTd; TD_DESCRIPTOR *DataTd; TD_DESCRIPTOR *StatusTd; TD_DESCRIPTOR *EmptyTd; EFI_STATUS Status; UINT32 DataPidDir; UINT32 StatusPidDir; UINTN TimeCount; UINT32 ErrorCode; UINTN ActualSendLength; UINTN LeftLength; UINT8 DataToggle; EFI_PHYSICAL_ADDRESS ReqMapPhyAddr = 0; UINTN DataMapLength = 0; EFI_PHYSICAL_ADDRESS DataMapPhyAddr = 0; HeadTd = NULL; DataTd = NULL; if ((TransferDirection != EfiUsbDataOut && TransferDirection != EfiUsbDataIn && TransferDirection != EfiUsbNoData) || Request == NULL || DataLength == NULL || TransferResult == NULL || (TransferDirection == EfiUsbNoData && (*DataLength != 0 || Data != NULL)) || (TransferDirection != EfiUsbNoData && (*DataLength == 0 || Data == NULL)) || (DeviceSpeed != EFI_USB_SPEED_LOW && DeviceSpeed != EFI_USB_SPEED_FULL) || (MaxPacketLength != 8 && MaxPacketLength != 16 && MaxPacketLength != 32 && MaxPacketLength != 64)) { DEBUG ((EFI_D_INFO, "OhciControlTransfer: EFI_INVALID_PARAMETER\n")); return EFI_INVALID_PARAMETER; } if (*DataLength > MAX_BYTES_PER_TD) { DEBUG ((EFI_D_ERROR, "OhciControlTransfer: Request data size is too large\n")); return EFI_INVALID_PARAMETER; } Ohc = PEI_RECOVERY_USB_OHC_DEV_FROM_EHCI_THIS(This); if (TransferDirection == EfiUsbDataIn) { DataPidDir = TD_IN_PID; StatusPidDir = TD_OUT_PID; } else { DataPidDir = TD_OUT_PID; StatusPidDir = TD_IN_PID; } OhciSetHcControl (Ohc, CONTROL_ENABLE, 0); if (OhciGetHcControl (Ohc, CONTROL_ENABLE) != 0) { MicroSecondDelay (HC_1_MILLISECOND); if (OhciGetHcControl (Ohc, CONTROL_ENABLE) != 0) { *TransferResult = EFI_USB_ERR_SYSTEM; DEBUG ((EFI_D_INFO, "OhciControlTransfer: Fail to disable CONTROL transfer\n")); return EFI_DEVICE_ERROR; } } OhciSetMemoryPointer (Ohc, HC_CONTROL_HEAD, NULL); Ed = OhciCreateED (Ohc); if (Ed == NULL) { DEBUG ((EFI_D_INFO, "OhciControlTransfer: Fail to allocate ED buffer\n")); return EFI_OUT_OF_RESOURCES; } OhciSetEDField (Ed, ED_SKIP, 1); OhciSetEDField (Ed, ED_FUNC_ADD, DeviceAddress); OhciSetEDField (Ed, ED_ENDPT_NUM, 0); OhciSetEDField (Ed, ED_DIR, ED_FROM_TD_DIR); OhciSetEDField (Ed, ED_SPEED, DeviceSpeed); OhciSetEDField (Ed, ED_FORMAT | ED_HALTED | ED_DTTOGGLE, 0); OhciSetEDField (Ed, ED_MAX_PACKET, MaxPacketLength); OhciSetEDField (Ed, ED_PDATA, 0); OhciSetEDField (Ed, ED_ZERO, 0); OhciSetEDField (Ed, ED_TDHEAD_PTR, (UINT32) NULL); OhciSetEDField (Ed, ED_TDTAIL_PTR, (UINT32) NULL); OhciSetEDField (Ed, ED_NEXT_EDPTR, (UINT32) NULL); OhciAttachEDToList (Ohc, CONTROL_LIST, Ed, NULL); // // Setup Stage // if(Request != NULL) { ReqMapPhyAddr = (EFI_PHYSICAL_ADDRESS)(UINTN)Request; } SetupTd = OhciCreateTD (Ohc); if (SetupTd == NULL) { Status = EFI_OUT_OF_RESOURCES; DEBUG ((EFI_D_INFO, "OhciControlTransfer: Fail to allocate Setup TD buffer\n")); goto FREE_ED_BUFF; } HeadTd = SetupTd; OhciSetTDField (SetupTd, TD_PDATA, 0); OhciSetTDField (SetupTd, TD_BUFFER_ROUND, 1); OhciSetTDField (SetupTd, TD_DIR_PID, TD_SETUP_PID); OhciSetTDField (SetupTd, TD_DELAY_INT, TD_NO_DELAY); OhciSetTDField (SetupTd, TD_DT_TOGGLE, 2); OhciSetTDField (SetupTd, TD_ERROR_CNT, 0); OhciSetTDField (SetupTd, TD_COND_CODE, TD_TOBE_PROCESSED); OhciSetTDField (SetupTd, TD_CURR_BUFFER_PTR, (UINTN)ReqMapPhyAddr); OhciSetTDField (SetupTd, TD_NEXT_PTR, (UINT32) NULL); OhciSetTDField (SetupTd, TD_BUFFER_END_PTR, (UINTN)ReqMapPhyAddr + sizeof (EFI_USB_DEVICE_REQUEST) - 1); SetupTd->ActualSendLength = 0; SetupTd->DataBuffer = NULL; SetupTd->NextTDPointer = NULL; DataMapLength = *DataLength; if ((Data != NULL) && (DataMapLength != 0)) { DataMapPhyAddr = (EFI_PHYSICAL_ADDRESS)(UINTN)Data; } // //Data Stage // LeftLength = DataMapLength; ActualSendLength = DataMapLength; DataToggle = 1; while (LeftLength > 0) { ActualSendLength = LeftLength; if (LeftLength > MaxPacketLength) { ActualSendLength = MaxPacketLength; } DataTd = OhciCreateTD (Ohc); if (DataTd == NULL) { DEBUG ((EFI_D_INFO, "OhciControlTransfer: Fail to allocate Data TD buffer\n")); Status = EFI_OUT_OF_RESOURCES; goto FREE_TD_BUFF; } OhciSetTDField (DataTd, TD_PDATA, 0); OhciSetTDField (DataTd, TD_BUFFER_ROUND, 1); OhciSetTDField (DataTd, TD_DIR_PID, DataPidDir); OhciSetTDField (DataTd, TD_DELAY_INT, TD_NO_DELAY); OhciSetTDField (DataTd, TD_DT_TOGGLE, DataToggle); OhciSetTDField (DataTd, TD_ERROR_CNT, 0); OhciSetTDField (DataTd, TD_COND_CODE, TD_TOBE_PROCESSED); OhciSetTDField (DataTd, TD_CURR_BUFFER_PTR, (UINT32) DataMapPhyAddr); OhciSetTDField (DataTd, TD_BUFFER_END_PTR, (UINT32) DataMapPhyAddr + ActualSendLength - 1); OhciSetTDField (DataTd, TD_NEXT_PTR, (UINT32) NULL); DataTd->ActualSendLength = ActualSendLength; DataTd->DataBuffer = (UINT8 *)(UINTN)DataMapPhyAddr; DataTd->NextTDPointer = 0; OhciLinkTD (HeadTd, DataTd); DataToggle ^= 1; DataMapPhyAddr += ActualSendLength; LeftLength -= ActualSendLength; } // // Status Stage // StatusTd = OhciCreateTD (Ohc); if (StatusTd == NULL) { DEBUG ((EFI_D_INFO, "OhciControlTransfer: Fail to allocate Status TD buffer\n")); Status = EFI_OUT_OF_RESOURCES; goto FREE_TD_BUFF; } OhciSetTDField (StatusTd, TD_PDATA, 0); OhciSetTDField (StatusTd, TD_BUFFER_ROUND, 1); OhciSetTDField (StatusTd, TD_DIR_PID, StatusPidDir); OhciSetTDField (StatusTd, TD_DELAY_INT, 7); OhciSetTDField (StatusTd, TD_DT_TOGGLE, 3); OhciSetTDField (StatusTd, TD_ERROR_CNT, 0); OhciSetTDField (StatusTd, TD_COND_CODE, TD_TOBE_PROCESSED); OhciSetTDField (StatusTd, TD_CURR_BUFFER_PTR, (UINT32) NULL); OhciSetTDField (StatusTd, TD_NEXT_PTR, (UINT32) NULL); OhciSetTDField (StatusTd, TD_BUFFER_END_PTR, (UINT32) NULL); StatusTd->ActualSendLength = 0; StatusTd->DataBuffer = NULL; StatusTd->NextTDPointer = NULL; OhciLinkTD (HeadTd, StatusTd); // // Empty Stage // EmptyTd = OhciCreateTD (Ohc); if (EmptyTd == NULL) { Status = EFI_OUT_OF_RESOURCES; DEBUG ((EFI_D_INFO, "OhciControlTransfer: Fail to allocate Empty TD buffer\n")); goto FREE_TD_BUFF; } OhciSetTDField (EmptyTd, TD_PDATA, 0); OhciSetTDField (EmptyTd, TD_BUFFER_ROUND, 0); OhciSetTDField (EmptyTd, TD_DIR_PID, 0); OhciSetTDField (EmptyTd, TD_DELAY_INT, 0); //OhciSetTDField (EmptyTd, TD_DT_TOGGLE, CurrentToggle); EmptyTd->Word0.DataToggle = 0; OhciSetTDField (EmptyTd, TD_ERROR_CNT, 0); OhciSetTDField (EmptyTd, TD_COND_CODE, 0); OhciSetTDField (EmptyTd, TD_CURR_BUFFER_PTR, 0); OhciSetTDField (EmptyTd, TD_BUFFER_END_PTR, 0); OhciSetTDField (EmptyTd, TD_NEXT_PTR, 0); EmptyTd->ActualSendLength = 0; EmptyTd->DataBuffer = NULL; EmptyTd->NextTDPointer = NULL; OhciLinkTD (HeadTd, EmptyTd); Ed->TdTailPointer = EmptyTd; OhciAttachTDListToED (Ed, HeadTd); // OhciSetEDField (Ed, ED_SKIP, 0); MicroSecondDelay (20 * HC_1_MILLISECOND); OhciSetHcCommandStatus (Ohc, CONTROL_LIST_FILLED, 1); OhciSetHcControl (Ohc, CONTROL_ENABLE, 1); MicroSecondDelay (20 * HC_1_MILLISECOND); if (OhciGetHcControl (Ohc, CONTROL_ENABLE) != 1) { MicroSecondDelay (HC_1_MILLISECOND); if (OhciGetHcControl (Ohc, CONTROL_ENABLE) != 1) { *TransferResult = EFI_USB_ERR_SYSTEM; Status = EFI_DEVICE_ERROR; DEBUG ((EFI_D_INFO, "OhciControlTransfer: Fail to enable CONTROL transfer\n")); goto FREE_TD_BUFF; } } TimeCount = 0; Status = CheckIfDone (Ohc, CONTROL_LIST, Ed, HeadTd, &ErrorCode); while (Status == EFI_NOT_READY && TimeCount <= TimeOut) { MicroSecondDelay (HC_1_MILLISECOND); TimeCount++; Status = CheckIfDone (Ohc, CONTROL_LIST, Ed, HeadTd, &ErrorCode); } // *TransferResult = ConvertErrorCode (ErrorCode); if (ErrorCode != TD_NO_ERROR) { if (ErrorCode == TD_TOBE_PROCESSED) { DEBUG ((EFI_D_INFO, "Control pipe timeout, > %d mS\r\n", TimeOut)); } else { DEBUG ((EFI_D_INFO, "Control pipe broken\r\n")); } *DataLength = 0; } OhciSetHcControl (Ohc, CONTROL_ENABLE, 0); if (OhciGetHcControl (Ohc, CONTROL_ENABLE) != 0) { MicroSecondDelay (HC_1_MILLISECOND); if (OhciGetHcControl (Ohc, CONTROL_ENABLE) != 0) { *TransferResult = EFI_USB_ERR_SYSTEM; DEBUG ((EFI_D_INFO, "OhciControlTransfer: Cannot disable CONTROL_ENABLE transfer\n")); goto FREE_TD_BUFF; } } FREE_TD_BUFF: while (HeadTd) { DataTd = HeadTd; HeadTd = HeadTd->NextTDPointer; UsbHcFreeMem(Ohc->MemPool, DataTd, sizeof(TD_DESCRIPTOR)); } FREE_ED_BUFF: UsbHcFreeMem(Ohc->MemPool, Ed, sizeof(ED_DESCRIPTOR)); return Status; }
/** Submits bulk transfer to a bulk endpoint of a USB device. @param PeiServices The pointer of EFI_PEI_SERVICES. @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI. @param DeviceAddress Target device address. @param EndPointAddress Endpoint number and its direction in bit 7. @param MaxiPacketLength Maximum packet size the endpoint is capable of sending or receiving. @param Data A pointers to the buffers of data to transmit from or receive into. @param DataLength The lenght of the data buffer. @param DataToggle On input, the initial data toggle for the transfer; On output, it is updated to to next data toggle to use of the subsequent bulk transfer. @param TimeOut Indicates the maximum time, in millisecond, which the transfer is allowed to complete. @param TransferResult A pointer to the detailed result information of the bulk transfer. @retval EFI_SUCCESS The transfer was completed successfully. @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resource. @retval EFI_INVALID_PARAMETER Parameters are invalid. @retval EFI_TIMEOUT The transfer failed due to timeout. @retval EFI_DEVICE_ERROR The transfer failed due to host controller error. **/ EFI_STATUS EFIAPI OhciBulkTransfer ( IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_HOST_CONTROLLER_PPI *This, IN UINT8 DeviceAddress, IN UINT8 EndPointAddress, IN UINT8 MaxPacketLength, IN OUT VOID *Data, IN OUT UINTN *DataLength, IN OUT UINT8 *DataToggle, IN UINTN TimeOut, OUT UINT32 *TransferResult ) { USB_OHCI_HC_DEV *Ohc; ED_DESCRIPTOR *Ed; UINT32 DataPidDir; TD_DESCRIPTOR *HeadTd; TD_DESCRIPTOR *DataTd; TD_DESCRIPTOR *EmptyTd; EFI_STATUS Status; UINT8 EndPointNum; UINTN TimeCount; UINT32 ErrorCode; UINT8 CurrentToggle; UINTN MapLength; EFI_PHYSICAL_ADDRESS MapPyhAddr; UINTN LeftLength; UINTN ActualSendLength; BOOLEAN FirstTD; MapLength = 0; MapPyhAddr = 0; LeftLength = 0; Status = EFI_SUCCESS; if (Data == NULL || DataLength == NULL || DataToggle == NULL || TransferResult == NULL || *DataLength == 0 || (*DataToggle != 0 && *DataToggle != 1) || (MaxPacketLength != 8 && MaxPacketLength != 16 && MaxPacketLength != 32 && MaxPacketLength != 64)) { return EFI_INVALID_PARAMETER; } Ohc = PEI_RECOVERY_USB_OHC_DEV_FROM_EHCI_THIS (This); if ((EndPointAddress & 0x80) != 0) { DataPidDir = TD_IN_PID; } else { DataPidDir = TD_OUT_PID; } EndPointNum = (EndPointAddress & 0xF); OhciSetHcControl (Ohc, BULK_ENABLE, 0); if (OhciGetHcControl (Ohc, BULK_ENABLE) != 0) { MicroSecondDelay (HC_1_MILLISECOND); if (OhciGetHcControl (Ohc, BULK_ENABLE) != 0) { *TransferResult = EFI_USB_ERR_SYSTEM; return EFI_DEVICE_ERROR; } } OhciSetMemoryPointer (Ohc, HC_BULK_HEAD, NULL); Ed = OhciCreateED (Ohc); if (Ed == NULL) { DEBUG ((EFI_D_INFO, "OhcBulkTransfer: Fail to allocate ED buffer\r\n")); return EFI_OUT_OF_RESOURCES; } OhciSetEDField (Ed, ED_SKIP, 1); OhciSetEDField (Ed, ED_FUNC_ADD, DeviceAddress); OhciSetEDField (Ed, ED_ENDPT_NUM, EndPointNum); OhciSetEDField (Ed, ED_DIR, ED_FROM_TD_DIR); OhciSetEDField (Ed, ED_SPEED, HI_SPEED); OhciSetEDField (Ed, ED_FORMAT | ED_HALTED | ED_DTTOGGLE, 0); OhciSetEDField (Ed, ED_MAX_PACKET, MaxPacketLength); OhciSetEDField (Ed, ED_PDATA, 0); OhciSetEDField (Ed, ED_ZERO, 0); OhciSetEDField (Ed, ED_TDHEAD_PTR, (UINT32) NULL); OhciSetEDField (Ed, ED_TDTAIL_PTR, (UINT32) NULL); OhciSetEDField (Ed, ED_NEXT_EDPTR, (UINT32) NULL); OhciAttachEDToList (Ohc, BULK_LIST, Ed, NULL); if(Data != NULL) { MapLength = *DataLength; MapPyhAddr = (EFI_PHYSICAL_ADDRESS)(UINTN)Data; } // //Data Stage // LeftLength = MapLength; ActualSendLength = MapLength; CurrentToggle = *DataToggle; HeadTd = NULL; FirstTD = TRUE; while (LeftLength > 0) { ActualSendLength = LeftLength; if (LeftLength > MaxPacketLength) { ActualSendLength = MaxPacketLength; } DataTd = OhciCreateTD (Ohc); if (DataTd == NULL) { DEBUG ((EFI_D_INFO, "OhcBulkTransfer: Fail to allocate Data TD buffer\r\n")); Status = EFI_OUT_OF_RESOURCES; goto FREE_TD_BUFF; } OhciSetTDField (DataTd, TD_PDATA, 0); OhciSetTDField (DataTd, TD_BUFFER_ROUND, 1); OhciSetTDField (DataTd, TD_DIR_PID, DataPidDir); OhciSetTDField (DataTd, TD_DELAY_INT, TD_NO_DELAY); OhciSetTDField (DataTd, TD_DT_TOGGLE, CurrentToggle); OhciSetTDField (DataTd, TD_ERROR_CNT, 0); OhciSetTDField (DataTd, TD_COND_CODE, TD_TOBE_PROCESSED); OhciSetTDField (DataTd, TD_CURR_BUFFER_PTR, (UINT32) MapPyhAddr); OhciSetTDField (DataTd, TD_BUFFER_END_PTR, (UINT32) MapPyhAddr + ActualSendLength - 1); OhciSetTDField (DataTd, TD_NEXT_PTR, (UINT32) NULL); DataTd->ActualSendLength = ActualSendLength; DataTd->DataBuffer = (UINT8 *)(UINTN)MapPyhAddr; DataTd->NextTDPointer = 0; if (FirstTD) { HeadTd = DataTd; FirstTD = FALSE; } else { OhciLinkTD (HeadTd, DataTd); } CurrentToggle ^= 1; MapPyhAddr += ActualSendLength; LeftLength -= ActualSendLength; } // // Empty Stage // EmptyTd = OhciCreateTD (Ohc); if (EmptyTd == NULL) { Status = EFI_OUT_OF_RESOURCES; DEBUG ((EFI_D_INFO, "OhcBulkTransfer: Fail to allocate Empty TD buffer\r\n")); goto FREE_TD_BUFF; } OhciSetTDField (EmptyTd, TD_PDATA, 0); OhciSetTDField (EmptyTd, TD_BUFFER_ROUND, 0); OhciSetTDField (EmptyTd, TD_DIR_PID, 0); OhciSetTDField (EmptyTd, TD_DELAY_INT, 0); //OhciSetTDField (EmptyTd, TD_DT_TOGGLE, CurrentToggle); EmptyTd->Word0.DataToggle = 0; OhciSetTDField (EmptyTd, TD_ERROR_CNT, 0); OhciSetTDField (EmptyTd, TD_COND_CODE, 0); OhciSetTDField (EmptyTd, TD_CURR_BUFFER_PTR, 0); OhciSetTDField (EmptyTd, TD_BUFFER_END_PTR, 0); OhciSetTDField (EmptyTd, TD_NEXT_PTR, 0); EmptyTd->ActualSendLength = 0; EmptyTd->DataBuffer = NULL; EmptyTd->NextTDPointer = NULL; OhciLinkTD (HeadTd, EmptyTd); Ed->TdTailPointer = EmptyTd; OhciAttachTDListToED (Ed, HeadTd); OhciSetEDField (Ed, ED_SKIP, 0); OhciSetHcCommandStatus (Ohc, BULK_LIST_FILLED, 1); OhciSetHcControl (Ohc, BULK_ENABLE, 1); if (OhciGetHcControl (Ohc, BULK_ENABLE) != 1) { MicroSecondDelay (HC_1_MILLISECOND); if (OhciGetHcControl (Ohc, BULK_ENABLE) != 1) { *TransferResult = EFI_USB_ERR_SYSTEM; goto FREE_TD_BUFF; } } TimeCount = 0; Status = CheckIfDone (Ohc, BULK_LIST, Ed, HeadTd, &ErrorCode); while (Status == EFI_NOT_READY && TimeCount <= TimeOut) { MicroSecondDelay (HC_1_MILLISECOND); TimeCount++; Status = CheckIfDone (Ohc, BULK_LIST, Ed, HeadTd, &ErrorCode); } *TransferResult = ConvertErrorCode (ErrorCode); if (ErrorCode != TD_NO_ERROR) { if (ErrorCode == TD_TOBE_PROCESSED) { DEBUG ((EFI_D_INFO, "Bulk pipe timeout, > %d mS\r\n", TimeOut)); } else { DEBUG ((EFI_D_INFO, "Bulk pipe broken\r\n")); } *DataLength = 0; } *DataToggle = (UINT8) OhciGetEDField (Ed, ED_DTTOGGLE); FREE_TD_BUFF: while (HeadTd) { DataTd = HeadTd; HeadTd = HeadTd->NextTDPointer; UsbHcFreeMem(Ohc->MemPool, DataTd, sizeof(TD_DESCRIPTOR)); } UsbHcFreeMem(Ohc->MemPool, Ed, sizeof(ED_DESCRIPTOR)); return Status; }
int main(int argc, char* argv[]) { FILE * fpin; char szIn[1024]; DWORD dwInput[1024]; DWORD dwOutput[1024]; DWORD dwProhibitChar; int iInputSize = 0; int iOutputSize = 0; int counter = 0; int res; int i; /* Arg check */ if (argc < 2) { printf("usage: <unicode codepoints file>\n", argv[0] ); return 1; } /* Get file */ fpin = fopen(argv[1], "r"); if (fpin == NULL) { printf("Cannot open %s\n",argv[1]); return 1; } while ( !feof( fpin ) ) { memset( szIn, 0, sizeof(szIn) ); memset( dwInput, 0, sizeof(dwInput) ); memset( dwOutput, 0, sizeof(dwOutput) ); fgets( szIn, sizeof(szIn), fpin ); if ( szIn[0] == ' ' || szIn[0] == '#' || strlen( szIn ) < 2 ) { printf( szIn ); continue; } /* Clip off \n */ szIn[strlen(szIn)-1] = 0; Read32BitLine( szIn, dwInput, &iInputSize ); iOutputSize = 1024; res = Xcode_nameprepString32( dwInput, iInputSize, dwOutput, &iOutputSize, &dwProhibitChar ); counter++; if ( res != XCODE_SUCCESS ) { char szMsg[1024]; ConvertErrorCode( res, szMsg ); printf( "Fail: Line=%d '%25s' (%s)\n", counter, szMsg, szIn ); continue; } for( i = 0; i < iOutputSize; i++ ) { printf( "%05X ", dwOutput[i] ); } printf( "\n" ); } fclose(fpin); #ifdef WIN32 getchar(); #endif return 0; }
int main(int argc, char* argv[]) { FILE * fpin; char szIn[1024]; char szOut[1024]; DWORD dwInput[1024]; DWORD dwOutput[1024]; UCHAR8 szData[1024]; UTF16CHAR uInput[1024]; int iInputSize = 0; int iOutputSize = 0; int counter = 0; int res; /* Arg check */ if (argc < 2) { printf("usage: <fullcircle file>\n", argv[0] ); return 1; } /* Get file */ fpin = fopen(argv[1], "r"); if (fpin == NULL) { printf("Cannot open %s\n",argv[1]); return 1; } while ( !feof( fpin ) ) { memset( szIn, 0, sizeof(szIn) ); memset( szOut, 0, sizeof(szOut) ); memset( dwInput, 0, sizeof(dwInput) ); memset( dwOutput, 0, sizeof(dwOutput) ); memset( szData, 0, sizeof(szData) ); fgets( szIn, sizeof(szIn), fpin ); counter++; if ( szIn[0] == ' ' || szIn[0] == '#' || strlen( szIn ) < 2 ) { printf( szIn ); continue; } fgets( szOut, sizeof(szOut), fpin ); counter++; /* Clip off \n */ szIn[strlen(szIn)-1] = 0; szOut[strlen(szOut)-1] = 0; if ( szIn[0] != 'i' ) { printf("Invalid input file format.\n"); return 1; } if ( szOut[0] != 'o' ) { printf("Invalid input file format.\n"); return 1; } if ( szOut[strlen(szOut)-1] == ' ' ) szOut[strlen(szOut)-1] = '\0'; /* Read32BitLine( &szIn[2], dwInput, &iInputSize ); iOutputSize = sizeof(dwOutput); res = Xcode_nameprepString32( dwInput, iInputSize, dwOutput, &iOutputSize, &dwProhibitChar ); if ( res != XCODE_SUCCESS ) goto error; iInputSize = sizeof(szData); res = Xcode_puny_encodeString( dwOutput, iOutputSize, szData, &iInputSize ); */ iInputSize = sizeof( dwInput ); Read32BitLine( &szIn[2], dwInput, &iInputSize ); iOutputSize = sizeof(uInput); res = Xcode_convert32BitToUTF16( dwInput, iInputSize, uInput, &iOutputSize ); iInputSize = iOutputSize; iOutputSize = sizeof(szData); res = Xcode_ToASCII( uInput, iInputSize, szData, &iOutputSize ); if ( res != XCODE_SUCCESS ) { char szMsg[1024]; ConvertErrorCode( res, szMsg ); printf( "Fail: Line=%d '%25s' (%s)(%s)\n", counter, szMsg, szIn, szOut ); continue; } if ( stricmp( &szOut[2], szData ) != 0 ) { //printf( "%s\no:%s\n", szIn, szData ); printf( "Error : Line=%d '%s' != '%s'\n", counter, &szOut[2], szData ); continue; } printf( "Success: Line=%d '%s'\n", counter, &szOut[2] ); //printf( "%s\no:%s\n", szIn, szData ); } fclose(fpin); #ifdef WIN32 getchar(); #endif return 0; }
int main(int argc, char* argv[]) { FILE * fpin; char szIn[1024]; UTF16CHAR uInput[1024]; DWORD dwOutput[1024]; UCHAR8 szData[1024]; UTF16CHAR uData[1024]; int iInputSize = 0; int iOutputSize = 0; int counter = 0; int res; int i; int encode = 0; /* Arg check */ if (argc < 2) { printf("usage: [encode (to race)|decode (to unicode)] <file>\n", argv[0] ); return 1; } /* Get file */ fpin = fopen(argv[2], "r"); if (fpin == NULL) { printf("Cannot open %s\n",argv[2]); return 1; } if ( strcmp( argv[1], "encode" ) == 0 ) encode = 1; while ( !feof( fpin ) ) { memset( szIn, 0, sizeof(szIn) ); memset( uInput, 0, sizeof(uInput) ); memset( dwOutput, 0, sizeof(dwOutput) ); memset( uData, 0, sizeof(uData) ); memset( szData, 0, sizeof(szData) ); fgets( szIn, sizeof(szIn), fpin ); if ( szIn[0] == ' ' || szIn[0] == '#' || strlen( szIn ) < 2 ) { printf( szIn ); continue; } /* Clip off \n */ szIn[strlen(szIn)-1] = 0; if ( encode ) Read16BitLine( szIn, uInput, &iInputSize ); iOutputSize = 1024; if ( encode ) { res = Xcode_race_encodeString( uInput, iInputSize, szData, &iOutputSize, "bq--", 4 ); } else { iInputSize = strlen( szIn ); res = Xcode_race_decodeString( szIn, iInputSize, uData, &iOutputSize, "bq--", 4 ); if ( res != XCODE_SUCCESS ) goto error; res = Xcode_convertUTF16To32Bit( uData, iOutputSize, dwOutput, &iOutputSize ); } counter++; error: if ( res != XCODE_SUCCESS ) { char szMsg[1024]; ConvertErrorCode( res, szMsg ); printf( "Fail: Line=%d '%25s' (%s)\n", counter, szMsg, szIn ); continue; } for( i = 0; i < iOutputSize; i++ ) { if ( encode ) printf( "%c", szData[i] ); else printf( "%x ", dwOutput[i] ); } printf( "\n" ); } fclose(fpin); #ifdef WIN32 getchar(); #endif return 0; }