The <cert.h> header file


  
This header file contains the following functions:
ceof               cfindfield         cgetc              cgetcertrevno
cgetflen           cgetfnl            cgetnl             cgetns
cgetsn             copen              copensub           cputhdr
cputnl             cputns             cread              ctell
cwrite
and the following predefined types:
Bool               CERT_FIELD         CFILE              HANDLE
NULL               H_NULL

NOTE: Functions caddcert, cgetcert, cgetvernum and cfindcertfield which were present in the AMS 1.xx TIOS jump table, don't more exist in AMS 2.xx TIOS jump table. Fortunately, all of them are only internal routines: you need to use FL_addCert, FL_getCert and FL_getVerNum from flash.h instead.

Functions


void copen (CFILE *context, char *data, unsigned long size);

Opens a certificate file context.

copen opens a memory mapped file which starts at address data, and which is size bytes long. It also initializes file context (this is a file control structure of type CFILE) pointed to by context. It does not reserve any memory. In fact, copen does nothing more than
context->Start = context->Pos = data;
context->End = data + size;
context->EOF = FALSE;
NOTE: All functions from this header file are used in TIOS exclusively for accessing certificate files, which are stored in the protected area of Flash ROM, and which contain certificate data. However, these functions are not limited to such files. They may be used with any memory mapped file (i.e. a "headerless" file which has not an entry in VAT table), which does not need to be a file which really contains certificate data.

unsigned char cgetc (CFILE *context);

Gets a character from a context.

cgetc gets a character from the file associated with the file context pointed to by context, and moves the file pointer to the next character. This function is functionally equal to
*(char*) context->Pos++;

short cgetns (CFILE *context);

Gets a non-aligned short integer from a context.

cgetns gets a short integer (which does not necessary be aligned to an even address) from the file associated with the file context pointed to by context, and moves the file pointer forward by two characters. In fact, it calls cgetc twice, and combines two returned bytes into one word.

long cgetnl (CFILE *context);

Gets a non-aligned long integer from a context.

cgetnl gets a long integer (which does not necessary be aligned to an even address) from the file associated with the file context pointed to by context, and moves the file pointer forward by four characters. In fact, it calls cgetc four times, and combines four returned bytes into one doubleword.

void cputns (CFILE *context, short s);

Puts a non-aligned short integer to a context.

cputns puts a short integer s to the file associated with the file context pointed to by context, and moves the file pointer forward by two characters. The stored integer will not always be aligned to an even address.

void cputnl (CFILE *context, long l);

Puts a non-aligned long integer to a context.

cputnl puts a long integer l to the file associated with the file context pointed to by context, and moves the file pointer forward by two characters. The stored integer will not always be aligned to an even address.

unsigned long ctell (CFILE *context);

Returns the current position from the start of a context.

ctell returns the current position of the file pointer associated with the file context pointed to by context, measured from the start address of the file.

short cread (CFILE *context, CERT_FIELD *dest);

Reads a field from a context.

Certificate files in TIOS (which packages up all the data required to perform authentification) are well-organized as files of variable-length records called "fields". So, the different components are split up into various fields, which can be accessed fairly easily. Each field begins with ID word. High 12 bits of ID are used as field ID number, and lower 4 bits are used to encode size of the field (as the length of the field can be a variable size). If these bits are smaller or equal to 0xC, this value is just the length of the field. If these bits are 0xD, 0xE or 0xF, then the following byte, word or doubleword contains the actual length of the field. Fields in the file are stored sequentially. They may contain various data, including other fields (i.e. "subfields"), which are usually opened with copensub.

cread reads a field from the file associated with the file context pointed to by context and collect necessary information (field ID number, length of the field, and the pointer to the actual content of the field) into the CERT_FIELD structure pointed to by dest. It also moves the field pointer to the next field, and sets the EOF indicator in the context if the end of the file is reached. cread returns TRUE if the operation was successful, else returns FALSE (this usually means end-of-file error).

short ceof (CFILE *context);

Returns end-of-file status of the context.

ceof returns TRUE if end-of-file indicator of the file associated with the file context pointed to by context is set, else returns FALSE.

unsigned long cgetflen (CFILE *context, unsigned short FieldIDWord);

Gets the length of a field.

cgetflen returns length of the field which has ID word (see cread) equal to FieldIDWord. This information is present in lower 4 bits of FieldIDWord if these bits are smaller or equal to 0xC. If not, necessary information needed to calculate the length are read from the context pointed to by context. cgetflen returns 0 if the end of the file is reached.

long cgetfnl (CERT_FIELD *field);

Gets a non-aligned long integer from a field.

cgetfnl gets a long integer (which does not necessary be aligned to an even address) from the field described by the structure pointed to by field. The field need not to be exactly four bytes long; it can be of any length, and cgetfnl gets as many bytes as available up to long.

short cputhdr (CFILE *context, unsigned short FieldID, unsigned short len);

Puts a field header to a context.

cputhdr puts a field header to the file associated with the file context pointed to by context and moves the file pointer accordingly. The field header includes ID word (i.e. field ID number and four length bits), and up to four length bytes if necessary (see cread for more info about fields). Required data for forming the header are taken from parameters FieldID and len. cputhdr returns TRUE if the operation was successful, else returns FALSE.

short cwrite (CFILE *context, CERT_FIELD *source);

Puts a field to a context.

cwrite writes a field described with CERT_FIELD structure pointed to by source to the file associated with the file context pointed to by context. cwrite is the reverse of cread. Returns TRUE if the operation was successful, else returns FALSE.

void copensub (CFILE *context, CERT_FIELD *subfield);

Opens a subcontext.

As the certificate file is usually consist of various field, this function is used for initializing the context pointed to by context to point to the actual content of the field described in the structure pointed to by subfield. This function is equal to
copen (context, subfield->Data, subfield->Len);
copen is used mainly to reset file pointer to the start of a group of items. See cfindfield for more info.

short cfindfield (CFILE *context, unsigned short FieldID, CERT_FIELD *dest);

Finds a matching field from a context.

cfindfield searches a file associated with the file context pointed to by context for a field which has field ID number equal to FieldID (length bits should be set to 0). If such field is found, cfindfield fills the field descriptor structure pointed to by dest and returns TRUE, else returns FALSE.

cfindfield is used often in TIOS to access particular data in a certificate file. Usually, function copensub is called immediately after cfindfield to get access to the content of the field. If the field contains subfields, this procedure may be repeated several times if necessary.

As an illustration of layout of certificate files, the layout of certificate files used in TIOS is given below. First, the field ID number is shown, then the short description of the field follows. Indentation shows that a particular field is a subfield of the field with smaller indentation. As it is not possible to access certificate part of Flash ROM directly, ecxept from the Base Code part of TIOS (this area of ROM is read-protected), the usuall method for reading certificates is to call FL_getCert first. This function will copy all data from the certificate area which may be shown to the public into the RAM, so the certificate can be read later from the RAM. For example, if you need to access the certificate data which shows the name of the author of an Flash application (assuming that such data is present in the certificate), the usual procedure is:
HANDLE handle;
unsigned long size;
CFILE context;
CERT_FIELD field;
...
FL_getCert (&handle, &size, FALSE);
copen (&context, HeapDeref (handle), size);
cfindfield (&context, 0x300, &field);
copensub (&context, &field);
cfindfield (&context, 0x500, &field);
copensub (&context, &field);
cfindfield (&context, 0x510, &field);
copensub (&context, &field);
After this, context.Pos will point to the author name. Alternatively, you can pick the name character-by-character using cgetc. If any of calls to cfindfield functions fail (i.e. return FALSE), then such data are not present in the certificate area.

short cgetcertrevno (long *dest);

Gets a certificate revision number.

cgetcertrevno fills the variable pointed to by dest with the certificate revision number. Returns TRUE if the operation was successful, else returns FALSE.

void cgetsn (char *dest);

Gets the calculator serial number from the Flash ROM certificate.

cgetsn fills the buffer pointed to by dest with the calculator serial number picked from the Flash ROM certificate. It has the form "pphnnnnnnn", where "pp" is the platform number (01 for TI-92 Plus, 03 for TI-89), "h" is hardware revision level, and "nnnnnnn" is an ID number which is unique to each calculator. All the above fields consist of hexadecimal digits. buffer must be at least 17 bytes long to accept the serial number.

Predefined types


enum Bool

Bool is enumerated type for describing true or false values. It is defined as
enum Bool {FALSE, TRUE};

const NULL

NULL is a null-pointer value, defined as (void *) 0.

type HANDLE

HANDLE is a type which represents handles associated to allocated memory blocks. It is defined as
typedef unsigned short HANDLE;

const H_NULL

H_NULL is a null-handle defined as a constant with value 0.

type CFILE

CFILE is a structure which represents context of a memory-mapped file (usually a certificate file). It is defined as
typedef struct
  {
    void *Start, *Pos, *End;   // Start, current and end position of the file pointer
    unsigned short EOF;        // Boolean value
  } CFILE;

type CERT_FIELD

CERT_FIELD is a structure which describes a variable-length records (usually called "fields") of certificate files. Each field has its ID number, and some ID numbers have predefined meanings in TIOS (see cfindfield). This structure is defined as
typedef struct
  {
    unsigned short Field;  // Field ID number (without the length)
    unsigned short HdrLen; // Size of the header (ID word & optional length bytes:
                           //    0, 1, 2 or 4)
    unsigned long Len;     // Total length of the field
    void *Data;            // Pointer to an actual data
  } CERT_FIELD;

Return to the main index