//------------------------------------------------------------------------------
static void cleanupTransmission(tFirmwareUpdateTransmissionInfo* pInfo_p)
{
    tFirmwareUpdateEntry*   pRem;
    tFirmwareStoreHandle    pFwStore;

    pInfo_p->fTranmissionActive = FALSE;
    pFwStore = pInfo_p->pUpdateList->pStoreHandle;

    pRem = pInfo_p->pUpdateList;
    pInfo_p->pUpdateList = pInfo_p->pUpdateList->pNext;
    free(pRem);

    firmwarestore_flushData(pFwStore);
}
//------------------------------------------------------------------------------
tFirmwareRet firmwareinfodecode_decodeInfo(tFirmwareStoreHandle pStore_p,
                                           tFirmwareInfoList* ppInfoList_p)
{
    tFirmwareRet            ret = kFwReturnOk;
    size_t                  dataSize;
    void*                   pData;
    char*                   pFileString;
    char*                   pLine;
    tFirmwareInfoList       pList = NULL;
    tFirmwareInfoEntry**    ppInsertIter = &pList;
    tFirmwareInfoEntry*     pEntry = NULL;

    if (ppInfoList_p == NULL)
    {
        ret = kFwReturnInvalidParameter;
        goto EXIT;
    }

    ret = firmwarestore_loadData(pStore_p);
    if (ret != kFwReturnOk)
    {
        goto EXIT;
    }

    ret = firmwarestore_getData(pStore_p, &pData, &dataSize);
    if (ret != kFwReturnOk)
    {
        goto EXIT;
    }

    pFileString = pData;

    pLine = strtok(pFileString, FIRMWAREINFO_ASCII_LINE_SEPERATOR);

    while (pLine != NULL)
    {
        pEntry = malloc(sizeof(tFirmwareInfoEntry));
        if (pEntry == NULL)
        {
            ret = kFwReturnNoResource;
            goto EXIT;
        }

        memset(pEntry, 0, sizeof(tFirmwareInfoEntry));

        ret = parseLine(pStore_p, pLine, &pEntry->fwInfo);
        if (ret == kFwReturnOk)
        {
            if (*ppInsertIter != NULL)
            {
                (*ppInsertIter)->pNext = pEntry;
            }
            *ppInsertIter = pEntry;
            ppInsertIter = &pEntry->pNext;
        }
        else
        {
            free(pEntry);

            if (ret == kFwReturnIgnoreInfoFileLine)
            {
                ret = kFwReturnOk;
            }
            else
            {
                break;
            }
        }

        pLine = strtok(NULL, FIRMWAREINFO_ASCII_LINE_SEPERATOR);
    }

    *ppInfoList_p = pList;

EXIT:
    (void)firmwarestore_flushData(pStore_p);

    if (ret != kFwReturnOk)
    {
        while (pList != NULL)
        {
            pEntry = pList;
            pList = pEntry->pNext;
            free(pEntry);
        }
    }

    return ret;
}
//------------------------------------------------------------------------------
static tFirmwareRet transmitFirmware(tFirmwareUpdateTransmissionInfo* pInfo_p)
{
    tFirmwareRet    ret = kFwReturnOk;
    tOplkError      oplkRet;

    if (pInfo_p->fTranmissionActive)
    {
        goto EXIT;
    }

    if (!isTransmissionAllowed(pInfo_p))
    {
        FWM_TRACE("Postpone update for node: %u index: 0x%x subindex: 0x%x\n",
                  pInfo_p->pUpdateList->nodeId, pInfo_p->pUpdateList->index,
                  pInfo_p->pUpdateList->subindex);

        goto EXIT;
    }

    FWM_TRACE("Start update for node: %u index: 0x%x subindex: 0x%x\n",
              pInfo_p->pUpdateList->nodeId, pInfo_p->pUpdateList->index,
              pInfo_p->pUpdateList->subindex);

    ret = firmwarestore_loadData(pInfo_p->pUpdateList->pStoreHandle);
    if (ret != kFwReturnOk)
    {
        FWM_ERROR("Loading image for transmission failed with %d and errno %d\n",
                  ret, errno);
        goto EXIT;
    }

    ret = firmwarestore_getData(pInfo_p->pUpdateList->pStoreHandle,
                                &pInfo_p->pFirmwareImage,
                                &pInfo_p->firmwareSize);
    if (ret != kFwReturnOk)
    {
        FWM_ERROR("Getting the image for transmission failed with %d and errno %d\n",
                  ret, errno);
        goto EXIT;
    }

    oplkRet = oplk_writeObject(&pInfo_p->sdoComCon,
                               pInfo_p->pUpdateList->nodeId,
                               pInfo_p->pUpdateList->index,
                               pInfo_p->pUpdateList->subindex,
                               pInfo_p->pFirmwareImage,
                               (UINT)pInfo_p->firmwareSize,
                               FIRMWARE_UPDATE_SDO_TYPE,
                               &instance_l);

    if ((oplkRet != kErrorApiTaskDeferred) && (pInfo_p->sdoComCon != FIRMWARE_UPDATE_INVALID_SDO))
    {
        FWM_ERROR("Writing the firmware object failed with 0x%X\n", oplkRet);
        ret = kFwReturnSdoWriteFailed;
        goto EXIT;
    }

    instance_l.numberOfStartedTransmissions++;
    pInfo_p->fTranmissionActive = TRUE;

EXIT:
    if (ret != kFwReturnOk)
    {
        firmwarestore_flushData(pInfo_p->pUpdateList->pStoreHandle);
    }
    return ret;
}