void* COptionBytesDialog_L1::GetOptions(LPBYTE User, LPBYTE RDP, LPBYTE WRP0 , LPBYTE WRP1, LPBYTE WRP2, LPBYTE WRP3, LPBYTE WRP4, LPBYTE WRP5, LPBYTE WRP6, LPBYTE WRP7, LPBYTE WRP8, LPBYTE WRP9, LPBYTE WRP10, LPBYTE WRP11 ) { m_pBuffer = (LPBYTE) malloc(64); memset(m_pBuffer, 0x00, 64); if (STDFU_SelectCurrentConfiguration(&m_phDevice, 0, 0,1)==STDFU_NOERROR) { DFUSTATUS DFUStatus; STDFU_Getstatus(&m_phDevice, &DFUStatus); while(DFUStatus.bState != STATE_DFU_IDLE) { STDFU_Clrstatus(&m_phDevice); STDFU_Getstatus(&m_phDevice, &DFUStatus); } m_pBuffer[0] = 0x21; m_pBuffer[1] = 0x00; m_pBuffer[2] = 0x00; m_pBuffer[3] = 0xF8; m_pBuffer[4] = 0x1F; STDFU_Dnload(&m_phDevice, m_pBuffer, 0x05, 0); STDFU_Getstatus(&m_phDevice, &DFUStatus); while(DFUStatus.bState != STATE_DFU_IDLE) { STDFU_Clrstatus(&m_phDevice); STDFU_Getstatus(&m_phDevice, &DFUStatus); } if(STDFU_Upload(&m_phDevice, m_pBuffer, 0x20, 2) == STDFU_NOERROR) { *RDP = m_pBuffer[0] ; *User = m_pBuffer[4]; *WRP0 = m_pBuffer[8]; *WRP1 = m_pBuffer[9]; *WRP2 = m_pBuffer[12]; *WRP3 = m_pBuffer[13]; *WRP4 = m_pBuffer[16]; *WRP5 = m_pBuffer[17]; *WRP6 = m_pBuffer[20]; *WRP7 = m_pBuffer[21]; *WRP8 = m_pBuffer[24]; *WRP9 = m_pBuffer[25]; *WRP10 = m_pBuffer[28]; *WRP11 = m_pBuffer[29]; return 0; } return 0; } return 0; }
void* COptionBytesDialog_F2::GetOptions(LPBYTE User, LPBYTE RDP, LPBYTE WRP0 , LPBYTE WRP1 ) { m_pBuffer = (LPBYTE) malloc(64); memset(m_pBuffer, 0x00, 64); if (STDFU_SelectCurrentConfiguration(&m_phDevice, 0, 0,1)==STDFU_NOERROR) { DFUSTATUS DFUStatus; STDFU_Getstatus(&m_phDevice, &DFUStatus); while(DFUStatus.bState != STATE_DFU_IDLE) { STDFU_Clrstatus(&m_phDevice); STDFU_Getstatus(&m_phDevice, &DFUStatus); } m_pBuffer[0] = 0x21; m_pBuffer[1] = 0x00; m_pBuffer[2] = 0xC0; m_pBuffer[3] = 0xFF; m_pBuffer[4] = 0x1F; STDFU_Dnload(&m_phDevice, m_pBuffer, 0x05, 0); STDFU_Getstatus(&m_phDevice, &DFUStatus); while(DFUStatus.bState != STATE_DFU_IDLE) { STDFU_Clrstatus(&m_phDevice); STDFU_Getstatus(&m_phDevice, &DFUStatus); } if(STDFU_Upload(&m_phDevice, m_pBuffer, 0x10, 2) == STDFU_NOERROR) { *User = m_pBuffer[0] ; *RDP = m_pBuffer[1]; *WRP0 = m_pBuffer[8]; *WRP1 = m_pBuffer[9]; return 0; } return 0; } return 0; }
void* COptionBytesDialog_F2::SetOptions(BYTE User, BYTE RDP, BYTE WRP0, BYTE WRP1) { m_pBuffer = (LPBYTE) malloc(0x10); memset(m_pBuffer, 0xFF, 0x10); if (STDFU_SelectCurrentConfiguration(&m_phDevice, 0, 0,1)==STDFU_NOERROR) { DFUSTATUS DFUStatus; STDFU_Getstatus(&m_phDevice, &DFUStatus); while(DFUStatus.bState != STATE_DFU_IDLE) { STDFU_Clrstatus(&m_phDevice); STDFU_Getstatus(&m_phDevice, &DFUStatus); } m_pBuffer[0] = 0x21; m_pBuffer[1] = 0x00; m_pBuffer[2] = 0xC0; m_pBuffer[3] = 0xFF; m_pBuffer[4] = 0x1F; STDFU_Dnload(&m_phDevice, m_pBuffer, 0x05, 0); STDFU_Getstatus(&m_phDevice, &DFUStatus); while(DFUStatus.bState != STATE_DFU_DOWNLOAD_IDLE) { //STDFU_Clrstatus(&m_phDevice); STDFU_Getstatus(&m_phDevice, &DFUStatus); } memset(m_pBuffer, 0xFF, 0x10); m_pBuffer[0] = User; m_pBuffer[1] = RDP; m_pBuffer[2] = 0xFF; m_pBuffer[3] = 0xFF; m_pBuffer[4] = 0xFF; m_pBuffer[5] = 0xFF; m_pBuffer[6] = 0xFF; m_pBuffer[7] = 0xFF; m_pBuffer[8] = WRP0; m_pBuffer[9] = WRP1; m_pBuffer[10] = 0xFF; m_pBuffer[11] = 0xFF; m_pBuffer[12] = 0xFF; m_pBuffer[13] = 0xFF; m_pBuffer[14] = 0xFF; m_pBuffer[15] = 0xFF; /*#define STATE_IDLE 0x00 #define STATE_DETACH 0x01 #define STATE_DFU_IDLE 0x02 #define STATE_DFU_DOWNLOAD_SYNC 0x03 #define STATE_DFU_DOWNLOAD_BUSY 0x04 #define STATE_DFU_DOWNLOAD_IDLE 0x05 #define STATE_DFU_MANIFEST_SYNC 0x06 #define STATE_DFU_MANIFEST 0x07 #define STATE_DFU_MANIFEST_WAIT_RESET 0x08 #define STATE_DFU_UPLOAD_IDLE 0x09 #define STATE_DFU_ERROR 0x0A #define STATE_DFU_UPLOAD_SYNC 0x91 #define STATE_DFU_UPLOAD_BUSY 0x92*/ if(STDFU_Dnload(&m_phDevice, m_pBuffer, 0x10, 2) == STDFU_NOERROR) { STDFU_Getstatus(&m_phDevice, &DFUStatus); /*while(DFUStatus.bState != STATE_DFU_DOWNLOAD_IDLE) { //STDFU_Clrstatus(&m_phDevice); STDFU_Getstatus(&m_phDevice, &DFUStatus); }*/ return 0; } return 0; } return 0; }
BOOL CUploadThread::RunThread() { DFUThreadContext Context; BOOL bRet=TRUE; BOOL bReDownload=FALSE; BOOL NeedsToChangeElement; DWORD dwPercentCalc; // UploadState Machine m_PollTime=0; GetCurrentContext(&Context); switch (Context.LastDFUStatus.bState) { case 0xFF: m_Retry=NB_TRIALS; Context.LastDFUStatus.bState=0xFE; Context.CurrentRequest=STDFU_RQ_OPEN; SetCurrentContext(&Context); // We start our state machine. Let's open the handle if (STDFU_Open(Context.szDevLink, &Context.hDevice)!=STDFU_NOERROR) { Context.ErrorCode=STDFU_OPENDRIVERERROR; bRet=FALSE; // Stops here SetCurrentContext(&Context); } else { Context.CurrentRequest=STDFU_RQ_SELECT_ALTERNATE; SetCurrentContext(&Context); CImage *pImage=(CImage*)Context.hImage; if (STDFU_SelectCurrentConfiguration(&Context.hDevice, 0, 0, pImage->GetAlternate())!=STDFU_NOERROR) { Context.ErrorCode=STDFUPRT_UNEXPECTEDERROR; SetCurrentContext(&Context); bRet=FALSE; STDFU_Abort(&Context.hDevice); // Reset State machine } else { bRet=EnsureIdleMode(&Context); if (bRet) { CImage *pImage=(CImage*)Context.hImage; if (pImage->GetNbElements()==0) { Context.Percent=100; SetCurrentContext(&Context); bRet=FALSE; } else { Context.CurrentImageElement=0; bRet=SetAddressAndGetStatus(&Context); } } } } break; case STATE_DFU_DOWNLOAD_BUSY: case STATE_DFU_UPLOAD_BUSY: // End of PollTimeOut Context.CurrentRequest=STDFU_RQ_GET_STATUS; SetCurrentContext(&Context); // We finished to wait. Let's get the status if (STDFU_Getstatus(&Context.hDevice, &Context.LastDFUStatus)!=STDFU_NOERROR) { Context.ErrorCode=STDFUPRT_UNEXPECTEDERROR; SetCurrentContext(&Context); bRet=FALSE; // Stops here STDFU_Abort(&Context.hDevice); // Reset State machine } else { SetCurrentContext(&Context); if (Context.LastDFUStatus.bStatus!=STATUS_OK) { Context.CurrentRequest=STDFU_RQ_CLR_STATUS; SetCurrentContext(&Context); if (Context.LastDFUStatus.bState==STATE_DFU_ERROR) STDFU_Clrstatus(&Context.hDevice); m_Retry--; if (!m_Retry) { Context.ErrorCode=STDFUPRT_UNEXPECTEDERROR; bRet=FALSE; // Stops here SetCurrentContext(&Context); STDFU_Abort(&Context.hDevice); // Reset State machine } else bReDownload=TRUE; } else { if ( (Context.LastDFUStatus.bStatus!=STATUS_OK) || ( (Context.LastDFUStatus.bState!=STATE_DFU_DOWNLOAD_IDLE) && (Context.LastDFUStatus.bState!=STATE_DFU_UPLOAD_IDLE) && (Context.LastDFUStatus.bState!=STATE_DFU_UPLOAD_IDLE) && (Context.LastDFUStatus.bState!=STATE_DFU_DOWNLOAD_BUSY) ) ) { if (Context.LastDFUStatus.bStatus!=STATUS_OK) Context.ErrorCode=STDFUPRT_DFUERROR; else Context.ErrorCode=STDFUPRT_BADFIRMWARESTATEMACHINE; bRet=FALSE; // Stops here SetCurrentContext(&Context); STDFU_Abort(&Context.hDevice); // Reset State machine } else { if ( (Context.LastDFUStatus.bState==STATE_DFU_DOWNLOAD_BUSY) || (Context.LastDFUStatus.bState==STATE_DFU_UPLOAD_BUSY) ) m_PollTime=Context.LastDFUStatus.bwPollTimeout[0]+0x100*Context.LastDFUStatus.bwPollTimeout[1]+0x10000*Context.LastDFUStatus.bwPollTimeout[2]; m_Retry=NB_TRIALS; } } } if (!bReDownload) break; case STATE_DFU_DOWNLOAD_IDLE: case STATE_DFU_UPLOAD_IDLE: { bRet=FALSE; NeedsToChangeElement=FALSE; if (Context.CurrentNBlock>=2) { dwPercentCalc=Context.CurrentNBlock-2; DFUIMAGEELEMENT Element; CImage *pImage=(CImage*)Context.hImage; DWORD i, NbEl=pImage->GetNbElements(); for (i=0;i<Context.CurrentImageElement;i++) { memset(&Element, 0, sizeof(Element)); pImage->GetImageElement(i, &Element); dwPercentCalc+=(Element.dwDataLength/m_Context.wTransferSize); if (Element.dwDataLength % m_Context.wTransferSize!=0) dwPercentCalc++; } Context.Percent=(dwPercentCalc*99)/m_NumBlockMax; SetCurrentContext(&Context); } else { if (Context.LastDFUStatus.bState==STATE_DFU_DOWNLOAD_IDLE) { // We just set the address of the current transfer, we need to go back to idle state Context.CurrentRequest=STDFU_RQ_ABORT; SetCurrentContext(&Context); STDFU_Abort(&Context.hDevice); // Go to IDLE mode } } if (!bReDownload) { while (SetNextBlockDataParameters(&Context, &NeedsToChangeElement)) { if (NeedsToChangeElement) { // We need to set the address of the current transfer, we need to go back to idle state Context.CurrentRequest=STDFU_RQ_ABORT; SetCurrentContext(&Context); STDFU_Abort(&Context.hDevice); // Go to IDLE mode Context.CurrentImageElement++; bRet=SetAddressAndGetStatus(&Context); if (bRet) break; } else { bRet=TRUE; break; } } if ( (bRet) && (!NeedsToChangeElement) ) bRet=UploadAndGetStatus(&Context); else if ( (!bRet) && (NeedsToChangeElement) ) { // Success ! EnsureIdleMode(&Context); Context.Percent=100; SetCurrentContext(&Context); bRet=FALSE; } } else { if (Context.CurrentNBlock>=2) bRet=UploadAndGetStatus(&Context); else bRet=SetAddressAndGetStatus(&Context); } } break; default: Context.ErrorCode=STDFUPRT_BADFIRMWARESTATEMACHINE; bRet=FALSE; // Stops here SetCurrentContext(&Context); STDFU_Abort(&Context.hDevice); // Reset State machine break; } return bRet; }