Ejemplo n.º 1
0
OSStatus fogCloudDevAuthorize(app_context_t* const inContext,
                              MVDAuthorizeRequestData_t devAuthorizeReqData)
{
    cloud_if_log_trace();
    OSStatus err = kUnknownErr;
    easycloud_service_state_t cloudServiceState = FOGCLOUD_STOPPED;

    cloud_if_log("Device authorize...");

    cloudServiceState = FogCloudServiceState(&easyCloudContext);
    if (FOGCLOUD_STOPPED == cloudServiceState)
    {
        return kStateErr;
    }

    //ok, set cloud context
    strncpy(easyCloudContext.service_config_info.loginId,
            devAuthorizeReqData.loginId, MAX_SIZE_LOGIN_ID);
    strncpy(easyCloudContext.service_config_info.devPasswd,
            devAuthorizeReqData.devPasswd, MAX_SIZE_DEV_PASSWD);
    strncpy(easyCloudContext.service_config_info.userToken,
            devAuthorizeReqData.user_token, MAX_SIZE_USER_TOKEN);

    err = FogCloudAuthorize(&easyCloudContext);
    require_noerr_action( err, exit, cloud_if_log("ERROR: authorize failed! err=%d", err) );
    return kNoErr;

exit:
    return err;
}
Ejemplo n.º 2
0
OSStatus fogCloudSendtoChannel(const char* channel, unsigned char *inBuf, unsigned int inBufLen)
{
  cloud_if_log_trace();
  OSStatus err = kUnknownErr;

  cloud_if_log("MVD => Cloud[%s]:[%d]=%.*s", channel, inBufLen, inBufLen, inBuf);
  err = FogCloudPublishtoChannel(&easyCloudContext, channel, inBuf, inBufLen);
  require_noerr_action( err, exit, cloud_if_log("ERROR: fogCloudSendtoChannel failed! err=%d", err) );
  return kNoErr;
  
exit:
  return err;
}
Ejemplo n.º 3
0
OSStatus MVDCloudInterfaceSendto(const char* topic, unsigned char *inBuf, unsigned int inBufLen)
{
  cloud_if_log_trace();
  OSStatus err = kUnknownErr;

  cloud_if_log("MVD => Cloud[%s]:[%d]=%.*s", topic, inBufLen, inBufLen, inBuf);
  err = EasyCloudPublishto(&easyCloudContext, topic, inBuf, inBufLen);
  require_noerr_action( err, exit, cloud_if_log("ERROR: MVDCloudInterfaceSendto failed! err=%d", err) );
  return kNoErr;
  
exit:
  return err;
}
Ejemplo n.º 4
0
OSStatus fogCloudSend(unsigned char *inBuf, unsigned int inBufLen)
{
    cloud_if_log_trace();
    OSStatus err = kUnknownErr;

    cloud_if_log("KIT => Cloud[publish]:[%d]=%.*s", inBufLen, inBufLen, inBuf);
    err = FogCloudPublish(&easyCloudContext, inBuf, inBufLen);
    require_noerr_action( err, exit, cloud_if_log("ERROR: fogCloudSend failed! err=%d", err) );
    return kNoErr;

exit:
    return err;
}
Ejemplo n.º 5
0
OSStatus fogCloudDeinit(mico_Context_t* const inContext)
{  
  cloud_if_log_trace();
  OSStatus err = kUnknownErr;
  
  cloud_if_log("fogCloudDeinit");
  err = FogCloudServiceDeInit(&easyCloudContext);
  require_noerr_action( err, exit, 
                       cloud_if_log("ERROR: FogCloudServiceDeInit err=%d.", err) );
  return kNoErr;
  
exit:
  return err;
}
Ejemplo n.º 6
0
OSStatus MVDCloudInterfaceStop(mico_Context_t* const inContext)
{  
  cloud_if_log_trace();
  OSStatus err = kUnknownErr;
  
  cloud_if_log("MVDCloudInterfaceStop");
  err = EasyCloudServiceStop(&easyCloudContext);
  require_noerr_action( err, exit, 
                       cloud_if_log("ERROR: EasyCloudServiceStop err=%d.", err) );
  return kNoErr;
  
exit:
  return err;
}
Ejemplo n.º 7
0
OSStatus fogCloudStop(app_context_t* const inContext)
{
    cloud_if_log_trace();
    OSStatus err = kUnknownErr;

    cloud_if_log("fogCloudStop");
    err = FogCloudServiceStop(&easyCloudContext);
    require_noerr_action( err, exit,
                          cloud_if_log("ERROR: FogCloudServiceStop err=%d.", err) );
    return kNoErr;

exit:
    return err;
}
Ejemplo n.º 8
0
OSStatus fogCloudDevActivate(app_context_t* const inContext,
                             MVDActivateRequestData_t devActivateRequestData)
{
    cloud_if_log_trace();
    OSStatus err = kUnknownErr;

    cloud_if_log("Device activate...");

    //ok, set cloud context
    strncpy(easyCloudContext.service_config_info.loginId,
            devActivateRequestData.loginId, MAX_SIZE_LOGIN_ID);
    strncpy(easyCloudContext.service_config_info.devPasswd,
            devActivateRequestData.devPasswd, MAX_SIZE_DEV_PASSWD);
    strncpy(easyCloudContext.service_config_info.userToken,
            devActivateRequestData.user_token, MAX_SIZE_USER_TOKEN);

    // activate request
    err = FogCloudActivate(&easyCloudContext);
    require_noerr_action(err, exit,
                         cloud_if_log("ERROR: fogCloudDevActivate failed! err=%d", err) );

    inContext->appStatus.fogcloudStatus.isActivated = true;

    // write activate data back to flash
    mico_rtos_lock_mutex(&inContext->mico_context->flashContentInRam_mutex);
    inContext->appConfig->fogcloudConfig.isActivated = true;
    strncpy(inContext->appConfig->fogcloudConfig.deviceId,
            easyCloudContext.service_status.deviceId, MAX_SIZE_DEVICE_ID);
    strncpy(inContext->appConfig->fogcloudConfig.masterDeviceKey,
            easyCloudContext.service_status.masterDeviceKey, MAX_SIZE_DEVICE_KEY);

    strncpy(inContext->appConfig->fogcloudConfig.loginId,
            easyCloudContext.service_config_info.loginId, MAX_SIZE_LOGIN_ID);
    strncpy(inContext->appConfig->fogcloudConfig.devPasswd,
            easyCloudContext.service_config_info.devPasswd, MAX_SIZE_DEV_PASSWD);
    strncpy(inContext->appConfig->fogcloudConfig.userToken,
            easyCloudContext.service_config_info.userToken, MAX_SIZE_USER_TOKEN);

    err = mico_system_context_update(inContext->mico_context);
    mico_rtos_unlock_mutex(&inContext->mico_context->flashContentInRam_mutex);
    require_noerr_action(err, exit,
                         cloud_if_log("ERROR: activate write flash failed! err=%d", err) );

    return kNoErr;

exit:
    return err;
}
Ejemplo n.º 9
0
OSStatus fogCloudDevAuthorize(mico_Context_t* const inContext,
                                       MVDAuthorizeRequestData_t devAuthorizeReqData)
{
  cloud_if_log_trace();
  OSStatus err = kUnknownErr;
  easycloud_service_state_t cloudServiceState = FOGCLOUD_STOPPED;
  
  cloud_if_log("Device authorize...");

  cloudServiceState = FogCloudServiceState(&easyCloudContext);
  if (FOGCLOUD_STOPPED == cloudServiceState){
    return kStateErr;
  }
  
  // dev_passwd ok ?
  if(0 != strncmp(inContext->flashContentInRam.appConfig.fogcloudConfig.devPasswd, 
                  devAuthorizeReqData.devPasswd, 
                  strlen(inContext->flashContentInRam.appConfig.fogcloudConfig.devPasswd)))
  {
    // devPass err
    cloud_if_log("ERROR: fogCloudDevAuthorize: devPasswd mismatch!");
    return kMismatchErr;
  }
  cloud_if_log("fogCloudDevAuthorize: devPasswd ok!");
  
  //ok, set cloud context
  strncpy(easyCloudContext.service_config_info.loginId, 
          devAuthorizeReqData.loginId, MAX_SIZE_LOGIN_ID);
  strncpy(easyCloudContext.service_config_info.devPasswd, 
          devAuthorizeReqData.devPasswd, MAX_SIZE_DEV_PASSWD);
  strncpy(easyCloudContext.service_config_info.userToken, 
          devAuthorizeReqData.user_token, MAX_SIZE_USER_TOKEN);
  
  err = FogCloudAuthorize(&easyCloudContext);
  require_noerr_action( err, exit, cloud_if_log("ERROR: authorize failed! err=%d", err) );
  return kNoErr;
  
exit:
  return err;
}
Ejemplo n.º 10
0
OSStatus fogCloudDevFirmwareUpdate(mico_Context_t* const inContext,
                                            MVDOTARequestData_t devOTARequestData)
{
  cloud_if_log_trace();
  OSStatus err = kUnknownErr;
  ecs_ota_flash_params_t ota_flash_params = {
    MICO_FLASH_FOR_UPDATE,
    UPDATE_START_ADDRESS,
    UPDATE_END_ADDRESS,
    UPDATE_FLASH_SIZE
  };

  cloud_if_log("fogCloudDevFirmwareUpdate: start ...");
  
  // login_id/dev_passwd ok ?
  if((0 != strncmp(inContext->flashContentInRam.appConfig.fogcloudConfig.loginId, 
                   devOTARequestData.loginId, 
                   strlen(inContext->flashContentInRam.appConfig.fogcloudConfig.loginId))) ||
     (0 != strncmp(inContext->flashContentInRam.appConfig.fogcloudConfig.devPasswd, 
                   devOTARequestData.devPasswd, 
                   strlen(inContext->flashContentInRam.appConfig.fogcloudConfig.devPasswd))))
  {
    // devPass err
    cloud_if_log("ERROR: fogCloudDevFirmwareUpdate: loginId/devPasswd mismatch!");
    return kMismatchErr;
  }
  cloud_if_log("fogCloudDevFirmwareUpdate: loginId/devPasswd ok!");
  
  //get latest rom version, file_path, md5
  cloud_if_log("fogCloudDevFirmwareUpdate: get latest rom version from server ...");
  err = FogCloudGetLatestRomVersion(&easyCloudContext);
  if(kNoErr != err){
    if(kNotFoundErr == err){
      cloud_if_log("WARNING: FogCloudGetLatestRomVersion: ROM not found on server!");
      inContext->appStatus.fogcloudStatus.RecvRomFileSize = 0;  // no rom to update
      return kNoErr;
    }
    else{
      cloud_if_log("ERROR: FogCloudGetLatestRomVersion failed! err=%d", err);
      goto exit;
    }
  }

  //FW version compare
  cloud_if_log("currnt_version=%s", inContext->flashContentInRam.appConfig.fogcloudConfig.romVersion);
  cloud_if_log("latestRomVersion=%s", easyCloudContext.service_status.latestRomVersion);
  cloud_if_log("bin_file=%s", easyCloudContext.service_status.bin_file);
  cloud_if_log("bin_md5=%s", easyCloudContext.service_status.bin_md5);
  
  if(0 == strncmp(inContext->flashContentInRam.appConfig.fogcloudConfig.romVersion,
                  easyCloudContext.service_status.latestRomVersion, 
                  strlen(inContext->flashContentInRam.appConfig.fogcloudConfig.romVersion))){
     cloud_if_log("the current firmware version[%s] is up-to-date!", 
                  inContext->flashContentInRam.appConfig.fogcloudConfig.romVersion);
     inContext->appStatus.fogcloudStatus.RecvRomFileSize = 0;
     return kNoErr;
  }
  cloud_if_log("fogCloudDevFirmwareUpdate: new firmware[%s] found on server, downloading ...",
               easyCloudContext.service_status.latestRomVersion);
  
  //get rom data
  err = FogCloudGetRomData(&easyCloudContext, ota_flash_params);
  require_noerr_action( err, exit, 
                       cloud_if_log("ERROR: FogCloudGetRomData failed! err=%d", err) );
  
  //update rom version in flash
  cloud_if_log("fogCloudDevFirmwareUpdate: return rom version && file size.");
  mico_rtos_lock_mutex(&inContext->flashContentInRam_mutex);
  memset(inContext->flashContentInRam.appConfig.fogcloudConfig.romVersion,
         0, MAX_SIZE_FW_VERSION);
  strncpy(inContext->flashContentInRam.appConfig.fogcloudConfig.romVersion,
          easyCloudContext.service_status.latestRomVersion, 
          strlen(easyCloudContext.service_status.latestRomVersion));
  inContext->appStatus.fogcloudStatus.RecvRomFileSize = easyCloudContext.service_status.bin_file_size;
  MICOUpdateConfiguration(inContext);
  mico_rtos_unlock_mutex(&inContext->flashContentInRam_mutex);
  
  return kNoErr;
  
exit:
  return err;
}
Ejemplo n.º 11
0
OSStatus fogCloudDevActivate(mico_Context_t* const inContext,
                                      MVDActivateRequestData_t devActivateRequestData)
{
  cloud_if_log_trace();
  OSStatus err = kUnknownErr;

  cloud_if_log("fogCloudDevActivate: entry");
  cloud_if_log("Device activate...");
  
  // login_id/dev_passwd set(not default value) ?
  if((0 != strncmp((char*)DEFAULT_LOGIN_ID,
                   inContext->flashContentInRam.appConfig.fogcloudConfig.loginId,       
                   strlen((char*)DEFAULT_LOGIN_ID))) ||
     (0 != strncmp((char*)DEFAULT_DEV_PASSWD,
                   inContext->flashContentInRam.appConfig.fogcloudConfig.devPasswd,
                   strlen((char*)DEFAULT_DEV_PASSWD))))
  {
    // login_id/dev_passwd ok ?
    if((0 != strncmp(inContext->flashContentInRam.appConfig.fogcloudConfig.loginId, 
                     devActivateRequestData.loginId, 
                     strlen(inContext->flashContentInRam.appConfig.fogcloudConfig.loginId))) ||
       (0 != strncmp(inContext->flashContentInRam.appConfig.fogcloudConfig.devPasswd, 
                     devActivateRequestData.devPasswd, 
                     strlen(inContext->flashContentInRam.appConfig.fogcloudConfig.devPasswd))))
    {
      // devPass err
      cloud_if_log("ERROR: fogCloudDevActivate: loginId/devPasswd mismatch!");
      return kMismatchErr;
    }
  }
  cloud_if_log("fogCloudDevActivate: loginId/devPasswd ok!");
  
  //ok, set cloud context
  strncpy(easyCloudContext.service_config_info.loginId, 
          devActivateRequestData.loginId, MAX_SIZE_LOGIN_ID);
  cloud_if_log("fogCloudDevActivate: loginId: %s", easyCloudContext.service_config_info.loginId);
  
  strncpy(easyCloudContext.service_config_info.devPasswd, 
          devActivateRequestData.devPasswd, MAX_SIZE_DEV_PASSWD);
  cloud_if_log("fogCloudDevActivate: devPasswd: %s", easyCloudContext.service_config_info.devPasswd);
  
  strncpy(easyCloudContext.service_config_info.userToken, 
          devActivateRequestData.user_token, MAX_SIZE_USER_TOKEN);
  cloud_if_log("fogCloudDevActivate: userToken: %s", easyCloudContext.service_config_info.userToken);
    
  // activate request
  cloud_if_log("fogCloudDevActivate: start FogCloudActivate()");
  err = FogCloudActivate(&easyCloudContext);
  cloud_if_log("fogCloudDevActivate: FogCloudActivate() finished");
  require_noerr_action(err, exit, 
                       cloud_if_log("ERROR: fogCloudDevActivate failed! err=%d", err) );

  inContext->appStatus.fogcloudStatus.isActivated = true;
  cloud_if_log("fogCloudDevActivate: inContext->appStatus.fogcloudStatus.isActivated = true");
  
  // write activate data back to flash
  mico_rtos_lock_mutex(&inContext->flashContentInRam_mutex);
  inContext->flashContentInRam.appConfig.fogcloudConfig.isActivated = true;
  strncpy(inContext->flashContentInRam.appConfig.fogcloudConfig.deviceId,
          easyCloudContext.service_status.deviceId, MAX_SIZE_DEVICE_ID);
  strncpy(inContext->flashContentInRam.appConfig.fogcloudConfig.masterDeviceKey,
          easyCloudContext.service_status.masterDeviceKey, MAX_SIZE_DEVICE_KEY);
  
  strncpy(inContext->flashContentInRam.appConfig.fogcloudConfig.loginId,
          easyCloudContext.service_config_info.loginId, MAX_SIZE_LOGIN_ID);
  strncpy(inContext->flashContentInRam.appConfig.fogcloudConfig.devPasswd,
          easyCloudContext.service_config_info.devPasswd, MAX_SIZE_DEV_PASSWD);
  strncpy(inContext->flashContentInRam.appConfig.fogcloudConfig.userToken,
          easyCloudContext.service_config_info.userToken, MAX_SIZE_USER_TOKEN);
    
  err = MICOUpdateConfiguration(inContext);
  mico_rtos_unlock_mutex(&inContext->flashContentInRam_mutex);
  require_noerr_action(err, exit, 
                       cloud_if_log("ERROR: activate write flash failed! err=%d", err) );
  
  return kNoErr;
  
exit:
  return err;
}
Ejemplo n.º 12
0
OSStatus MVDCloudInterfaceDevFirmwareUpdate(mico_Context_t* const inContext,
                                            MVDOTARequestData_t devOTARequestData)
{
  cloud_if_log_trace();
  OSStatus err = kUnknownErr;

  cloud_if_log("MVDCloudInterfaceDevFirmwareUpdate: start ...");
  
  // login_id/dev_passwd ok ?
  if((0 != strncmp(inContext->flashContentInRam.appConfig.virtualDevConfig.loginId, 
                   devOTARequestData.loginId, 
                   strlen(inContext->flashContentInRam.appConfig.virtualDevConfig.loginId))) ||
     (0 != strncmp(inContext->flashContentInRam.appConfig.virtualDevConfig.devPasswd, 
                   devOTARequestData.devPasswd, 
                   strlen(inContext->flashContentInRam.appConfig.virtualDevConfig.devPasswd))))
  {
    // devPass err
    cloud_if_log("ERROR: MVDCloudInterfaceDevFirmwareUpdate: loginId/devPasswd mismatch!");
    return kMismatchErr;
  }
  cloud_if_log("MVDCloudInterfaceDevFirmwareUpdate: loginId/devPasswd ok!");
  
  //get latest rom version, file_path, md5
  cloud_if_log("MVDCloudInterfaceDevFirmwareUpdate: get latest rom version from server ...");
  err = EasyCloudGetLatestRomVersion(&easyCloudContext);
  require_noerr_action( err, exit, cloud_if_log("ERROR: EasyCloudGetLatestRomVersion failed! err=%d", err) );
  
  //FW version compare
  cloud_if_log("currnt_version=%s", inContext->flashContentInRam.appConfig.virtualDevConfig.romVersion);
  cloud_if_log("latestRomVersion=%s", easyCloudContext.service_status.latestRomVersion);
  cloud_if_log("bin_file=%s", easyCloudContext.service_status.bin_file);
  cloud_if_log("bin_md5=%s", easyCloudContext.service_status.bin_md5);
  
  if(0 == strncmp(inContext->flashContentInRam.appConfig.virtualDevConfig.romVersion,
                  easyCloudContext.service_status.latestRomVersion, 
                  strlen(inContext->flashContentInRam.appConfig.virtualDevConfig.romVersion))){
     cloud_if_log("the current firmware version[%s] is up-to-date!", 
                  inContext->flashContentInRam.appConfig.virtualDevConfig.romVersion);
     inContext->appStatus.virtualDevStatus.RecvRomFileSize = 0;
     return kNoErr;
  }
  cloud_if_log("MVDCloudInterfaceDevFirmwareUpdate: new firmware[%s] found on server, downloading ...",
               easyCloudContext.service_status.latestRomVersion);
  
  //get rom data
  err = EasyCloudGetRomData(&easyCloudContext);
  require_noerr_action( err, exit, 
                       cloud_if_log("ERROR: EasyCloudGetRomData failed! err=%d", err) );
  
  //update rom version in flash
  cloud_if_log("MVDCloudInterfaceDevFirmwareUpdate: return rom version && file size.");
  mico_rtos_lock_mutex(&inContext->flashContentInRam_mutex);
  memset(inContext->flashContentInRam.appConfig.virtualDevConfig.romVersion,
         0, MAX_SIZE_FW_VERSION);
  strncpy(inContext->flashContentInRam.appConfig.virtualDevConfig.romVersion,
          easyCloudContext.service_status.latestRomVersion, 
          strlen(easyCloudContext.service_status.latestRomVersion));
  inContext->appStatus.virtualDevStatus.RecvRomFileSize = easyCloudContext.service_status.bin_file_size;
  MICOUpdateConfiguration(inContext);
  mico_rtos_unlock_mutex(&inContext->flashContentInRam_mutex);
  
  return kNoErr;
  
exit:
  return err;
}
Ejemplo n.º 13
0
OSStatus fogCloudDevFirmwareUpdate(app_context_t* const inContext,
                                   MVDOTARequestData_t devOTARequestData)
{
    cloud_if_log_trace();
    OSStatus err = kUnknownErr;
    ecs_ota_flash_params_t ota_flash_params =
    {
        MICO_PARTITION_OTA_TEMP,
        0x0,
    };

    md5_context md5;
    unsigned char md5_16[16] = {0};
    char *pmd5_32 = NULL;
    char rom_file_md5[32] = {0};
    uint8_t data[SizePerRW] = {0};
    uint32_t updateStartAddress = 0;
    uint32_t readLength = 0;
    uint32_t i = 0, size = 0;
    uint32_t romStringLen = 0;

    // crc16
    CRC16_Context contex;

    cloud_if_log("fogCloudDevFirmwareUpdate: start ...");

    //get latest rom version, file_path, md5
    cloud_if_log("fogCloudDevFirmwareUpdate: get latest rom version from server ...");
    err = FogCloudGetLatestRomVersion(&easyCloudContext);
    require_noerr_action( err, exit_with_error, cloud_if_log("ERROR: FogCloudGetLatestRomVersion failed! err=%d", err) );

    //FW version compare
    cloud_if_log("currnt_version=%s", inContext->appConfig->fogcloudConfig.romVersion);
    cloud_if_log("latestRomVersion=%s", easyCloudContext.service_status.latestRomVersion);
    cloud_if_log("bin_file=%s", easyCloudContext.service_status.bin_file);
    cloud_if_log("bin_md5=%s", easyCloudContext.service_status.bin_md5);

    romStringLen = strlen(easyCloudContext.service_status.latestRomVersion) > strlen(inContext->appConfig->fogcloudConfig.romVersion) ?
                   strlen(easyCloudContext.service_status.latestRomVersion):strlen(inContext->appConfig->fogcloudConfig.romVersion);
    if(0 == strncmp(inContext->appConfig->fogcloudConfig.romVersion,
                    easyCloudContext.service_status.latestRomVersion,
                    romStringLen))
    {
        cloud_if_log("the current firmware version[%s] is up-to-date!",
                     inContext->appConfig->fogcloudConfig.romVersion);
        inContext->appStatus.fogcloudStatus.RecvRomFileSize = 0;
        err = kNoErr;
        goto exit_with_no_error;
    }
    cloud_if_log("fogCloudDevFirmwareUpdate: new firmware[%s] found on server, downloading ...",
                 easyCloudContext.service_status.latestRomVersion);

    inContext->appStatus.fogcloudStatus.isOTAInProgress = true;
    OTAWillStart(inContext);

    //get rom data
    err = FogCloudGetRomData(&easyCloudContext, ota_flash_params);
    require_noerr_action( err, exit_with_error,
                          cloud_if_log("ERROR: FogCloudGetRomData failed! err=%d", err) );

//------------------------------ OTA DATA VERIFY -----------------------------
    // md5 init
    InitMd5(&md5);
    CRC16_Init( &contex );
    memset(rom_file_md5, 0, 32);
    memset(data, 0xFF, SizePerRW);
    updateStartAddress = ota_flash_params.update_offset;
    size = (easyCloudContext.service_status.bin_file_size)/SizePerRW;

    // read flash, md5 update
    for(i = 0; i <= size; i++)
    {
        if( i == size )
        {
            if( (easyCloudContext.service_status.bin_file_size)%SizePerRW )
            {
                readLength = (easyCloudContext.service_status.bin_file_size)%SizePerRW;
            }
            else
            {
                break;
            }
        }
        else
        {
            readLength = SizePerRW;
        }
        err = MicoFlashRead(ota_flash_params.update_partion, &updateStartAddress, data, readLength);
        require_noerr(err, exit_with_error);
        Md5Update(&md5, (uint8_t *)data, readLength);
        CRC16_Update( &contex, data, readLength );
    }

// read done, calc MD5
    Md5Final(&md5, md5_16);
    CRC16_Final( &contex, &ota_crc );
    pmd5_32 = ECS_DataToHexStringLowercase(md5_16,  sizeof(md5_16));  //convert hex data to hex string
    cloud_if_log("ota_data_in_flash_md5[%d]=%s", strlen(pmd5_32), pmd5_32);

    if (NULL != pmd5_32)
    {
        strncpy(rom_file_md5, pmd5_32, strlen(pmd5_32));
        free(pmd5_32);
        pmd5_32 = NULL;
    }
    else
    {
        err = kNoMemoryErr;
        goto exit_with_error;
    }

    // check md5
    if(0 != strncmp( easyCloudContext.service_status.bin_md5, (char*)&(rom_file_md5[0]),
                     strlen( easyCloudContext.service_status.bin_md5)))
    {
        cloud_if_log("ERROR: ota data wrote in flash md5 checksum err!!!");
        err = kChecksumErr;
        goto exit_with_error;
    }
    else
    {
        cloud_if_log("OTA data in flash md5 check success, crc16=%d.", ota_crc);
    }
    //----------------------------------------------------------------------------

    //update rom version in flash
    cloud_if_log("fogCloudDevFirmwareUpdate: return rom version && file size.");
    mico_rtos_lock_mutex(&inContext->mico_context->flashContentInRam_mutex);
    memset(inContext->appConfig->fogcloudConfig.romVersion,
           0, MAX_SIZE_FW_VERSION);
    strncpy(inContext->appConfig->fogcloudConfig.romVersion,
            easyCloudContext.service_status.latestRomVersion,
            strlen(easyCloudContext.service_status.latestRomVersion));
    inContext->appStatus.fogcloudStatus.RecvRomFileSize = easyCloudContext.service_status.bin_file_size;
    err = mico_system_context_update(inContext->mico_context);
    mico_rtos_unlock_mutex(&inContext->mico_context->flashContentInRam_mutex);

    OTASuccess(inContext);
    err = kNoErr;
    goto exit_with_no_error;

exit_with_no_error:
    cloud_if_log("fogCloudDevFirmwareUpdate exit with no error.");
    inContext->appStatus.fogcloudStatus.isOTAInProgress = false;
    return err;

exit_with_error:
    cloud_if_log("fogCloudDevFirmwareUpdate exit with err=%d.", err);
    OTAFailed(inContext);
    inContext->appStatus.fogcloudStatus.isOTAInProgress = false;
    return err;
}