示例#1
0
// Uses information from section 5.2.2 of the U6 User's Guide to make a ConfigU6
// packet.
// http://labjack.com/support/u6/users-guide/5.2.2
void buildConfigU6Bytes(BYTE * sendBuffer) {
    int i; // For loops
    int checksum = 0;
    
    // Build up the bytes
    //sendBuffer[0] = Checksum8
    sendBuffer[1] = 0xF8;
    sendBuffer[2] = 0x0A;
    sendBuffer[3] = 0x08;
    //sendBuffer[4] = Checksum16 (LSB)
    //sendBuffer[5] = Checksum16 (MSB)
    
    // We just want to read, so we set the WriteMask to zero, and zero out the
    // rest of the bytes.
    sendBuffer[6] = 0;
    for( i = 7; i < CONFIGU6_COMMAND_LENGTH; i++){
        sendBuffer[i] = 0;
    }
    
    // Calculate and set the checksum16
    checksum = calculateChecksum16(sendBuffer, CONFIGU6_COMMAND_LENGTH);
    sendBuffer[4] = (BYTE)( checksum & 0xff );
    sendBuffer[5] = (BYTE)( (checksum / 256) & 0xff );
    
    // Calculate and set the checksum8
    sendBuffer[0] = calculateChecksum8(sendBuffer);
    
    // The bytes have been set, and the checksum calculated. We are ready to
    // write to the U6.
}
示例#2
0
// Checks the response for any errors.
int checkResponseForErrors(BYTE * recBuffer) {
    if(recBuffer[0] == 0xB8 && recBuffer[1] == 0xB8) {
        // If the packet is [ 0xB8, 0xB8 ], that's a bad checksum.
        printf("The U6 detected a bad checksum. Double check your checksum calculations and try again.\n");
        return -1;
    }
    else if (recBuffer[1] != 0xF8 || recBuffer[2] != 0x10 || recBuffer[3] != 0x08) {
        // Make sure the command bytes match what we expect.
        printf("Got the wrong command bytes back from the U6.\n");
        return -1;
    }
    
    // Calculate the checksums.
    int checksum16 = calculateChecksum16(recBuffer, CONFIGU6_RESPONSE_LENGTH);
    BYTE checksum8 = calculateChecksum8(recBuffer);
    
    if ( checksum8 != recBuffer[0] || recBuffer[4] != (BYTE)( checksum16 & 0xff ) || recBuffer[5] != (BYTE)( (checksum16 / 256) & 0xff ) ) {
        // Check the checksum
        printf("Response had invalid checksum.\n%d != %d, %d != %d, %d != %d\n", checksum8, recBuffer[0], (BYTE)( checksum16 & 0xff ), recBuffer[4], (BYTE)( (checksum16 / 256) & 0xff ), recBuffer[5] );
        return -1;
    }
    else if ( recBuffer[6] != 0 ) {
        // Check the error code in the packet. See section 5.3 of the U6
        // User's Guide for errorcode descriptions.
        printf("Command returned with an errorcode = %d\n", recBuffer[6]);
        return -1;
    }
    
    return 0;
    
}
示例#3
0
STATUS FitParser::parse(const QModelIndex & index, const QModelIndex & lastVtfIndex)
{
    // Check sanity
    if (!index.isValid() || !lastVtfIndex.isValid())
        return EFI_INVALID_PARAMETER;

    // Store lastVtfIndex
    lastVtf = lastVtfIndex;

    // Search for FIT
    QModelIndex fitIndex;
    UINT32 fitOffset;
    STATUS result = findFitRecursive(index, fitIndex, fitOffset);
    if (result)
        return result;

    // FIT not found
    if (!fitIndex.isValid())
        return ERR_SUCCESS;
    
    // Explicitly set the item as fixed
    model->setFixed(index, true);

    // Special case of FIT header
    const FIT_ENTRY* fitHeader = (const FIT_ENTRY*)(model->body(fitIndex).constData() + fitOffset);
    
    // Check FIT checksum, if present
    UINT32 fitSize = (fitHeader->Size & 0xFFFFFF) << 4;
    if (fitHeader->Type & 0x80) {
        // Calculate FIT entry checksum
        QByteArray tempFIT = model->body(fitIndex).mid(fitOffset, fitSize);
        FIT_ENTRY* tempFitHeader = (FIT_ENTRY*)tempFIT.data();
        tempFitHeader->Checksum = 0;
        UINT8 calculated = calculateChecksum8((const UINT8*)tempFitHeader, fitSize);
        if (calculated != fitHeader->Checksum) {
            msg(QObject::tr("Invalid FIT table checksum %1h, should be %2h").hexarg2(fitHeader->Checksum, 2).hexarg2(calculated, 2), fitIndex);
        }
    }

    // Check fit header type
    if ((fitHeader->Type & 0x7F) != FIT_TYPE_HEADER) {
        msg(QObject::tr("Invalid FIT header type"), fitIndex);
    }

    // Add FIT header to fitTable
    std::vector<QString> currentStrings;
    currentStrings.push_back(QObject::tr("_FIT_   "));
    currentStrings.push_back(QObject::tr("%1").hexarg2(fitSize, 8));
    currentStrings.push_back(QObject::tr("%1").hexarg2(fitHeader->Version, 4));
    currentStrings.push_back(fitEntryTypeToQString(fitHeader->Type));
    currentStrings.push_back(QObject::tr("%1").hexarg2(fitHeader->Checksum, 2));
    fitTable.push_back(currentStrings);

    // Process all other entries
    bool msgModifiedImageMayNotWork = false;
    for (UINT32 i = 1; i < fitHeader->Size; i++) {
        currentStrings.clear();
        const FIT_ENTRY* currentEntry = fitHeader + i;

        // Check entry type
        switch (currentEntry->Type & 0x7F) {
        case FIT_TYPE_HEADER:
            msg(QObject::tr("Second FIT header found, the table is damaged"), fitIndex);
            break;

        case FIT_TYPE_EMPTY:
        case FIT_TYPE_MICROCODE:
            break;

        case FIT_TYPE_BIOS_AC_MODULE:
        case FIT_TYPE_BIOS_INIT_MODULE:
        case FIT_TYPE_TPM_POLICY:
        case FIT_TYPE_BIOS_POLICY_DATA:
        case FIT_TYPE_TXT_CONF_POLICY:
        case FIT_TYPE_AC_KEY_MANIFEST:
        case FIT_TYPE_AC_BOOT_POLICY:
        default:
            msgModifiedImageMayNotWork = true;
            break;
        }

        // Add entry to fitTable
        currentStrings.push_back(QObject::tr("%1").hexarg2(currentEntry->Address, 16));
        currentStrings.push_back(QObject::tr("%1").hexarg2(currentEntry->Size, 8));
        currentStrings.push_back(QObject::tr("%1").hexarg2(currentEntry->Version, 4));
        currentStrings.push_back(fitEntryTypeToQString(currentEntry->Type));
        currentStrings.push_back(QObject::tr("%1").hexarg2(currentEntry->Checksum, 2));
        fitTable.push_back(currentStrings);
    }

    if (msgModifiedImageMayNotWork)
        msg(QObject::tr("Opened image may not work after any modification"));

    return ERR_SUCCESS;
}