wavecom package[1.0] named "Release 7.43.3 cus WMP" version "7.43.3.201201300737"  by "Wavecom"
SHAREDVARS
{
    /* The following variables can be set through
     * the downloader's OLE interface to tailor
     * the download process */

    /* scrambled value for additional features activation */
    string VECTOR_VALUE;

    /* IMEI value to set (unless there is one in the
     * Wireless Microprocessor's memory */
    string IMEI;

    /* boolean: to be set to bypass the firmware and
     * eeprom files download stage */
    integer NO_DOWNLOAD;

    /* integer: to be set to the required value (in KBytes) of A&D Dota volume */
    integer DOTA_VOLUME_SIZE;

    /* when non-0, triggers the initialisation of the SDS service
     * using the value (in KBytes) as the quota */
    integer SDS_QUOTA;

    /* when non-empty, makes the script send the value
     * as the password protecting the application authentication
     * protection password */
    string OAT_PKEY_PASSWORD;

    /* when non-empty, makes the script change the current
     * value of the protection password */
    string NEW_OAT_PKEY_PASSWORD;

    /* when non-null, customized size in KB allocated for application
     * objects (ADL Flash API) */
    integer FLASH_APPLICATION_QUOTA;

    /* when non-null, customized number of objects entries (max. 7936)
     * Note: this pool of entries is shared by both the firmware and
     * the application */
    integer FLASH_ENTRIES_COUNT;

    /* when non-null, bypasses all dongle protected download steps */
    integer NO_DONGLE;

    /* name of the targeted Wireless CPU/Wireless Microprocessor
     * (e.g. "wmp100" or "wmp150") */
    string WCPU_TYPE;
    
    /* to enable OpenAT application after download */
    integer START_APPLICATION;
}
{
   if (RAM_SIZE < 0x100000) /* check that there is at least 1MByte of RAM */
      call die("The RAM is too small");
  
    /* Special use of the "Erase customization" check box:
     * if this box is checked, the dongle protected download steps
     * are skipped.
     * This can be achieved through OLE interface by setting NO_DONGLE to 1
     */
    integer BYPASS_DONGLE_PROTECTED = BOOL_ERASE_CUSTO || NO_DONGLE;

    /* Name of the module file (PNMKT) to download.
     * Either built from the WCPU_TYPE variable or from a
     * selection in GUI context */
    string strModuleFile;

    /* Install the Dota Manipulation Plug-In */
    file: "dotadwl.plg";

    if (! BYPASS_DONGLE_PROTECTED)
    {
        secure: "lock_cus_swift.bin";
        /* Force the initialisation of SFIE v2 */
        exec: INITLOCK/init_security_data();
    }

    /* Carry out the erase operations */
    if (BOOL_ERASE_WHOLE)
    {
         exec: ERASE_WHOLE "Erasing the whole flash memory...";
    }
    else
    {
        if (BOOL_ERASE_OAT)
            exec: ERASE_OAT "Erasing the Open AT application";

        if (BOOL_ERASE_OBJ)
            exec: ERASE_OBJ "Erasing application data";
    }

    /* Test the presence of the pro-dwl.wpb */
    integer boolProDwlInFlash = isFirmwareInstalled("pro-dwl.wpb");

    /* Ask the GUI user questions about the download process */
    if (isGui())
    {
        /* Select the Wireless CPU */
        call promptChoice("Please select the Wireless CPU type",
            strModuleFile, "wmp100.e2p","wmp100SM1.e2p","wmp100SM3.e2p","wmp120.e2p","wmp150.e2p","wmp150SM3.e2p","wmp50.e2p","wmp50SM3.e2p");

        /* Security related unless no dongle available */
        if (! BYPASS_DONGLE_PROTECTED)
        {
            if (promptBoolean("Do you want to set/enable security features?"))
            {
                if (promptBoolean("Reset the Secure Data Storage service?"))
                {
                  SDS_QUOTA = promptInteger("Enter the value of the quota for SDS in Kbytes");
                }

                if (promptBoolean("Use a passphrase to protect the authentication's public key?"))
                {
                  if (promptBoolean("Should the current passphrase be changed ?"))
                  {
                    call promptString("Enter the old key protection passwd:", OAT_PKEY_PASSWORD);
                    call promptString("Enter the new key protection passwd:", NEW_OAT_PKEY_PASSWORD);
                  }
                  else
                  {
                    call promptString("Enter key protection passwd:", OAT_PKEY_PASSWORD);
                  }
                }
            }
        }

        call statusDisplay("Configuring the download process...");

        /* DOTA volume customization */
        if (promptBoolean("Do you want to resize the A&D Dota volume ?"))
        {
            DOTA_VOLUME_SIZE = promptInteger("Enter the required size in Kbytes");
        }
        /* RAI area customization */
        if (promptBoolean("Do you want to customize the flash objects area (ADL Flash API) ?"))
        {
            FLASH_APPLICATION_QUOTA = promptInteger("Enter the required size in Kbytes");
            if (promptBoolean("Do you want to modify the default max number of entries?"))
            {
                FLASH_ENTRIES_COUNT = promptInteger("Enter the new max number");
            }
        }

        if (BOOL_ERASE_WHOLE)
            NO_DOWNLOAD = 0; /* always download the firmware after erase whole flash */
        else
        {
            if (boolProDwlInFlash)
            {
                NO_DOWNLOAD = !promptBoolean("The firmware is already present in flash memory: download it anyway?");
            }
            else
            {
                NO_DOWNLOAD = !promptBoolean("Do you want to download the firmware ?");
            }
        }

        /* No IMEI or VECTOR setup when no dongle */
        if (! BYPASS_DONGLE_PROTECTED)
        {
            if (promptBoolean("Do you want to program the IMEI ?"))
            {
                call promptString("Enter the IMEI (ignored unless the Wavecom default value is in flash memory)", IMEI);
            }

            if (promptBoolean("Do you want to configure the firmware's features ?"))
            {
                call promptString("Enter the features configuration code", VECTOR_VALUE);
            }
        }
    }

    /* Now proceeding with files download */
    if (! NO_DOWNLOAD)
    {
        /* build the PNMKT file name when required */
        if (strlen(strModuleFile) == 0)
        {
            if (strlen(WCPU_TYPE) == 0)
                call die("The variable CPU_TYPE must be set");
            call concatenate(strModuleFile, "module/", WCPU_TYPE, ".e2p");
        }
        else /* strModuleFile selected through GUI */
            call concatenate(strModuleFile, "module/", strModuleFile);

        /* skip download in automation mode unless required */
        /* deltavxx.e2p is overwritten by IE2P parameters when initlock is called */
        if (isGui() || (!boolProDwlInFlash))
        {
          file: "pro-dwl.wpb";
          file: "w.e2p";
          file: "wonce.e2p";
          file: strModuleFile;
          file: "e2p/deltavxx.e2p";
          if (FLASH_SIZE > 0x400000)
            file: "e2p/mem64.e2p";
          else
            file: "e2p/mem32.e2p";
        }
    }

    /* No IMEI or VECTOR setup when no dongle */
    if (! BYPASS_DONGLE_PROTECTED)
    {
        if (strlen(IMEI) > 0)
        {
            exec: INITLOCK/write_imei(IMEI);
        }

        if (strlen(VECTOR_VALUE) > 0)
        {
            file: "peafowl.plg";
            exec: peafowl/parseFeatures(VECTOR_VALUE) "Configuring the features in flash memory";
        }
    }

    /* Proceeding with security related setup when relevant */
    if (SDS_QUOTA > 0)
        exec: INITLOCK/define_secure_storage(SDS_QUOTA*1024)  "Setting up the Secure Data Storage";

    if (strlen(OAT_PKEY_PASSWORD) > 0)
        exec: INITLOCK/supply_auth_key_passwd(OAT_PKEY_PASSWORD) "Setting key's password";

    if (strlen(NEW_OAT_PKEY_PASSWORD) > 0)
        exec: INITLOCK/change_auth_key_passwd(NEW_OAT_PKEY_PASSWORD) "Changing key's password";

    if(DOTA_VOLUME_SIZE > 0)
        exec: dotadwl/PartitionDota(DOTA_VOLUME_SIZE) "Resizing the A&D Dota volume";

    if (FLASH_APPLICATION_QUOTA || FLASH_ENTRIES_COUNT)
    {
        /* Download the RAIDWL to manipulate RAI related EEPROM parameters */
        file: "raidwl.plg";
        if (FLASH_ENTRIES_COUNT)
            exec: raidwl/resize_raispace(FLASH_APPLICATION_QUOTA, FLASH_ENTRIES_COUNT) "Resizing objects space";
        else
            exec: raidwl/resize_raispace(FLASH_APPLICATION_QUOTA) "Resizing objects space";
    }

    /* Download any other file that might have been
     * selected in the GUI or through the OLE
     * automation routines */
    call downloadOtherFiles();
    exec: FLASH_REMAP "Commiting the changes in flash memory";

    /* Enable customer application if neecessary*/
    if (START_APPLICATION) {
        file: "e2p/openctrl.e2p";
    }
        
    if (isGui())
    {
        if (promptBoolean("Setup flash memory image for pre-programmed devices (very slow)?"))
        {
            string strImageName;
            secure: "imager.bin";
            call promptString("Enter the full (with path) file name of the image:", strImageName);
            call setupPreprgImage(strImageName, "lock_bin_swift.wpb");
        }
    }
}
