#ident "$Id: partition_common.h,v 1.28 2008/08/08 18:32:47 cnguyen Exp $"
/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  and  are protected by Federal copyright law. They may not be disclosed
 *  to  third  parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 */

#ifndef _PARTITION_COMMON_H_
#define _PARTITION_COMMON_H_

/*
 * This file contains declarations for routines common to programs
 * that generate partitions
 */


#include <sys/types.h>
#include <dirent.h>             // For definition of DIR
                                // used in getTypedFileName

#include "types.h"
#include "sha1.h"
#include "estypes.h"            // From NC/GBA tree
#include "es_int.h"             // From NC/GBA tree
#include "iosccert.h"           // From NC/GBA tree

typedef struct optionVals {
    /*
     * For unencrypted partitions, the prefix file name (rvl.bin)
     * For encrypted partitions, the content name
     */
    char *contentOrPrefixName;
    char *outputName;
    u64  titleId;
    /*
     * Version parameters are manipulated as strings so that the code
     * doesn't depend on the size of the variables in the ES structures
     */
    char *IOSversion;
    char *titleVersion;
    char *groupId;
    u64  accessBits;
    bool keepFiles;
    char *limitCodes;
    char *limitValues;
    bool useProduction;    /* Only used by make_ndev_partition */
    bool isNand;
    char *inputTmd;
    char *stopDirectory;
    char *combineDirectory;
    char *certFile;
    bool versionOnly;
    char *rmAccess;
    u16  bootIndex;
    u32  accessTitleId;
    u32  accessTitleMask;
} optionVals_t;

bool generateEticket(const char* const binRoot,
                     const char* const encryptedTitleKeyFile, 
                     const u64         titleID,
                     const char* const limitCodes,
                     const char* const limitValues,
                     const u32         accessTitleId, 
                     const u32         accessTitleMask,
                     const bool        production,
                     const bool        keepFiles,
                     char              *ticketName);
bool readCertBlob(const char* const pkiRoot, u8 **certArray, u32 *certBlobSize,
                  const bool production);
bool fileExists(const char* const fileName);
bool fileSize(const char* const fileName, off_t *fileSize);
void processOptions(int argc, char* argv[], optionVals_t* const optionVals);
bool getRoot(char **binRoot, char** pkiRoot);
bool getTypedFileName(DIR *dirPtr, const char* const dirName,
                      const char *nameExtension, char *pathName);

/* Should be big enough to contain a reasonable shell command */
#define COMMAND_BUF_LEN         1024

/*
 * These numbers vary from file system to file system, and operating
 * system to operating system.  So just pick some reasonable values.
 */
#define FILE_NAME_MAX            256
#define PATH_LEN_MAX            1024

#if defined(PRODUCTION) || defined(JOHN_CHO_HACK)
#define TMD_BINARY      "tmd"
#define TICKET_BINARY   "ticket"
#elif defined(DEVELOPER)
#define TMD_BINARY      "tmdIRD"
#define TICKET_BINARY   "ticketIRD"
#else
#error Must define either DEVELOPER or PRODUCTION
#endif

#endif
