Example: Querying the status of your Cryptographic Coprocessor

Change this program example to suit your needs for querying the status of your Cryptographic Coprocessor. This program uses the STATEID and TIMEDATE keywords.

Note: Read the Code license and disclaimer information for important legal information.

If you choose to use this program example, change it to suit your specific needs. For security reasons, IBM® recommends that you individualize these program examples rather than using the default values provided.

/*-------------------------------------------------------------------*/
/* Query the  card for status or other information.              */
/* This sample program uses the STATEID and TIMEDATE keywords.       */
/*                                                                   */
/*                                                                   */
/*  COPYRIGHT 5769-SS1 (C) IBM CORP. 1999                      */
/*                                                                   */
/*  This material contains programming source code for your          */
/*  consideration.  These examples have not been thoroughly          */
/*  tested under all conditions.  IBM, therefore, cannot             */
/*  guarantee or imply reliability, serviceability, or function      */
/*  of these program.  All programs contained herein are             */
/*  provided to you "AS IS".  THE IMPLIED WARRANTIES OF              */
/*  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE         */
/*  ARE EXPRESSLY DISCLAIMED.  IBM provides no program services for  */
/*  these programs and files.                                        */
/*                                                                   */
/*                                                                   */
/* Note: This verb is more fully described in Chapter 2 of           */
/*       IBM  CCA Basic Services Reference and Guide             */
/*       (SC31-8609) publication.                                    */
/*                                                                   */
/* Parameters:                                                       */
/*   none.                                                           */
/*                                                                   */
/* Example:                                                          */
/*   CALL PGM(QUERY)                                                 */
/*                                                                   */
/*                                                                   */
/* Note: This program assumes the device to use is                   */
/*       already identified either by defaulting to the CRP01        */
/*       device or by being explicitly named using the               */
/*       Cryptographic_Resource_Allocate verb. Also this             */
/*       device must be varied on and you must be authorized         */
/*       to use this device description.                             */
/*                                                                   */
/* Use these commands to compile this program on the system:         */
/* ADDLIBLE LIB(QCCA)                                                */
/* CRTCMOD MODULE(QUERY) SRCFILE(SAMPLE)                             */
/* CRTPGM  PGM(QUERY) MODULE(QUERY) BNDSRVPGM(QCCA/CSUACFQ)          */
/*                                                                   */
/* Note: Authority to the CSUACFQ service program in the             */
/*       QCCA library is assumed.                                    */
/*                                                                   */
/* The Common Cryptographic Architecture (CCA) verb used is          */
/* Cryptographic_Facility_Query (CSUACFQ).                           */
/*                                                                   */
/*-------------------------------------------------------------------*/


#include "csucincl.h"     /* header file for CCA Cryptographic       */
                          /* Service Provider                        */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

/*-------------------------------------------------------------------*/
/* standard return codes                                             */
/*-------------------------------------------------------------------*/

#define ERROR        -1
#define OK            0
#define WARNING       4

#define IDSIZE       16   /* number of bytes in environment ID       */
#define TIMEDATESIZE 24   /* number of bytes in time and date        */


int main(int argc, char *argv[])

{
    /*-------------------------------------------------------------------*/
    /* standard CCA parameters                                           */
    /*-------------------------------------------------------------------*/

    long return_code = 0;
    long reason_code = 0;
    long exit_data_length = 2;
    char exit_data[4];
    char rule_array[2][8];
    long rule_array_count = 2;
    char rule_array2[3][8];

    /*-------------------------------------------------------------------*/
    /* fields unique to this sample program                              */
    /*-------------------------------------------------------------------*/

    long verb_data_length = 0; /* currently not used by this verb        */
    char * verb_data = " ";

    /* set keywords in the rule array                                    */

    memcpy(rule_array,"ADAPTER1STATEID ",16);

    /* get the environment ID from the card                              */

    CSUACFQ(  &return_code,
	      &reason_code,
	      &exit_data_length,
	      exit_data,
	      &rule_array_count,
	      (char *)rule_array,
	      &verb_data_length,
	      verb_data);

    if ( (return_code == OK) | (return_code == WARNING) )
    {
	printf("Environment ID was successfully returned.\n");

	printf("Return/reason codes ");

	printf("%ld/%ld\n\n", return_code, reason_code);

	printf("ID = %.16s\n", rule_array);
	
    }

    else
    {
	printf("An error occurred while getting the environment ID.\n");

	printf("Return/reason codes ");

	printf("%ld/%ld\n\n", return_code, reason_code);

/*	return(ERROR) */;
    }

    /* set count to number of bytes of returned data                    */

    rule_array_count = 2;

    return_code = 0;
    reason_code = 0;

    /* set keywords in the rule array                                    */

    memcpy(rule_array2,"ADAPTER1TIMEDATE",16);

    /* get the time from the card                                        */

    CSUACFQ(  &return_code,
	      &reason_code,
	      &exit_data_length,
	      exit_data,
	      &rule_array_count,
	      (char *)rule_array2,
	      &verb_data_length,
	      verb_data);

    if ( (return_code == OK) | (return_code == WARNING) )
    {
	printf("Time and date was successfully returned.\n");

	printf("Return/reason codes ");

	printf("%ld/%ld\n\n", return_code, reason_code);
	
	printf("DATE = %.8s\n", rule_array2);
	printf("TIME = %.8s\n", &rule_array2[1]);
	printf("DAY of WEEK = %.8s\n", &rule_array2[2]);
    }

    else
    {
	printf("An error occurred while getting the time and date.\n");

	printf("Return/reason codes ");

	printf("%ld/%ld\n\n", return_code, reason_code);

	return(ERROR);
    }
}