Example: ILE C program for allocating a Coprocessor

Change this program example to suit your needs for allocating a Coprocessor.

Note: Read the Code license and disclaimer information for important legal information.
/*-------------------------------------------------------------------*/
/* Allocate a crypto device to the job.                              */
/*                                                                   */
/*                                                                   */
/*  COPYRIGHT 5769-SS1 (C) IBM CORP. 2000, 2000                      */
/*                                                                   */
/*  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: Input format is more fully described in Chapter 2 of        */
/*       IBM  CCA Basic Services Reference and Guide             */
/*       (SC31-8609) publication.                                    */
/*                                                                   */
/* Parameters:                                                       */
/*   none.                                                           */
/*                                                                   */
/* Example:                                                          */
/*   CALL PGM(CRPALLOC)  (CRP02)                                     */
/*                                                                   */
/*                                                                   */
/* The Common Cryptographic Architecture (CCA) verb used is          */
/* Cryptographic_Resource_Allocate (CSUACRA).                        */
/*                                                                   */
/* Use these commands to compile this program on the system:         */
/* ADDLIBLE LIB(QCCA)                                                */
/* CRTCMOD MODULE(CRPALLOC) SRCFILE(SAMPLE)                          */
/* CRTPGM  PGM(CRPALLOC) MODULE(CRPALLOC)                            */
/*         BNDSRVPGM(QCCA/CSUACRA)                                   */
/*                                                                   */
/* Note: Authority to the CSUACRA service program in the             */
/*       QCCA library is assumed.                                    */
/*                                                                   */
/*-------------------------------------------------------------------*/
#include <string.h>
#include <stdio.h>
#include "csucincl.h"

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

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

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;
    long resource_name_length;

    /*-------------------------------------------------------------------*/
    /* Process the parameters                                            */
    /*-------------------------------------------------------------------*/
    if (argc < 1)
     {
      printf("Device parameter must be specified.\n");
      return(ERROR);
     }

    /*-------------------------------------------------------------------*/
    /* Set the keyword in the rule array                                 */
    /*-------------------------------------------------------------------*/
    memcpy(rule_array,"DEVICE  ",8);
    rule_array_count = 1;

    /*-------------------------------------------------------------------*/
    /* Set the resource name length                                      */
    /*-------------------------------------------------------------------*/
    resource_name_length = strlen(argv[1]);

    /*-------------------------------------------------------------------*/
    /* Call Cryptographic Resource Allocate SAPI                         */
    /*-------------------------------------------------------------------*/
    CSUACRA( &return_code, &reason_code, &exit_data_length,
             (char *)exit_data,
             (long *) &rule_array_count,
             (char *) rule_array,
             (long *) &resource_name_length,
             (char *) argv[1]);    /* resource name        */

    /*-------------------------------------------------------------------*/
    /* Check the return code and display the results                     */
    /*-------------------------------------------------------------------*/
    if ( (return_code == OK) | (return_code == WARNING) )
    {
    	printf("Request was successful\n");
    	return(OK);
    }
    else
    {
    	printf("Request failed with return/reason codes: %d/%d \n",
             return_code, reason_code);
    	return(ERROR);
    }
}
Related concepts
Allocating a device