Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | /* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright IBM Corp. 2001, 2012 * Author(s): Robert Burroughs * Eric Rossman (edrossma@us.ibm.com) * * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com) * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com> * MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com> */ #ifndef _ZCRYPT_MSGTYPE6_H_ #define _ZCRYPT_MSGTYPE6_H_ #include <asm/zcrypt.h> #define MSGTYPE06_NAME "zcrypt_msgtype6" #define MSGTYPE06_VARIANT_DEFAULT 0 #define MSGTYPE06_VARIANT_NORNG 1 #define MSGTYPE06_VARIANT_EP11 2 /** * The type 6 message family is associated with CEXxC/CEXxP cards. * * It contains a message header followed by a CPRB, both of which * are described below. * * Note that all reserved fields must be zeroes. */ struct type6_hdr { unsigned char reserved1; /* 0x00 */ unsigned char type; /* 0x06 */ unsigned char reserved2[2]; /* 0x0000 */ unsigned char right[4]; /* 0x00000000 */ unsigned char reserved3[2]; /* 0x0000 */ unsigned char reserved4[2]; /* 0x0000 */ unsigned char apfs[4]; /* 0x00000000 */ unsigned int offset1; /* 0x00000058 (offset to CPRB) */ unsigned int offset2; /* 0x00000000 */ unsigned int offset3; /* 0x00000000 */ unsigned int offset4; /* 0x00000000 */ unsigned char agent_id[16]; /* 0x4341000000000000 */ /* 0x0000000000000000 */ unsigned char rqid[2]; /* rqid. internal to 603 */ unsigned char reserved5[2]; /* 0x0000 */ unsigned char function_code[2]; /* for PKD, 0x5044 (ascii 'PD') */ unsigned char reserved6[2]; /* 0x0000 */ unsigned int tocardlen1; /* (request CPRB len + 3) & -4 */ unsigned int tocardlen2; /* db len 0x00000000 for PKD */ unsigned int tocardlen3; /* 0x00000000 */ unsigned int tocardlen4; /* 0x00000000 */ unsigned int fromcardlen1; /* response buffer length */ unsigned int fromcardlen2; /* db len 0x00000000 for PKD */ unsigned int fromcardlen3; /* 0x00000000 */ unsigned int fromcardlen4; /* 0x00000000 */ } __packed; /** * The type 86 message family is associated with CEXxC/CEXxP cards. * * It contains a message header followed by a CPRB. The CPRB is * the same as the request CPRB, which is described above. * * If format is 1, an error condition exists and no data beyond * the 8-byte message header is of interest. * * The non-error message is shown below. * * Note that all reserved fields must be zeroes. */ struct type86_hdr { unsigned char reserved1; /* 0x00 */ unsigned char type; /* 0x86 */ unsigned char format; /* 0x01 (error) or 0x02 (ok) */ unsigned char reserved2; /* 0x00 */ unsigned char reply_code; /* reply code (see above) */ unsigned char reserved3[3]; /* 0x000000 */ } __packed; #define TYPE86_RSP_CODE 0x86 #define TYPE87_RSP_CODE 0x87 #define TYPE86_FMT2 0x02 struct type86_fmt2_ext { unsigned char reserved[4]; /* 0x00000000 */ unsigned char apfs[4]; /* final status */ unsigned int count1; /* length of CPRB + parameters */ unsigned int offset1; /* offset to CPRB */ unsigned int count2; /* 0x00000000 */ unsigned int offset2; /* db offset 0x00000000 for PKD */ unsigned int count3; /* 0x00000000 */ unsigned int offset3; /* 0x00000000 */ unsigned int count4; /* 0x00000000 */ unsigned int offset4; /* 0x00000000 */ } __packed; int prep_cca_ap_msg(bool userspace, struct ica_xcRB *xcrb, struct ap_message *ap_msg, unsigned int *fc, unsigned short **dom); int prep_ep11_ap_msg(bool userspace, struct ep11_urb *xcrb, struct ap_message *ap_msg, unsigned int *fc, unsigned int *dom); int prep_rng_ap_msg(struct ap_message *ap_msg, int *fc, unsigned int *dom); #define LOW 10 #define MEDIUM 100 #define HIGH 500 int speed_idx_cca(int); int speed_idx_ep11(int); /** * Prepare a type6 CPRB message for random number generation * * @ap_dev: AP device pointer * @ap_msg: pointer to AP message */ static inline void rng_type6cprb_msgx(struct ap_message *ap_msg, unsigned int random_number_length, unsigned int *domain) { struct { struct type6_hdr hdr; struct CPRBX cprbx; char function_code[2]; short int rule_length; char rule[8]; short int verb_length; short int key_length; } __packed * msg = ap_msg->msg; static struct type6_hdr static_type6_hdrX = { .type = 0x06, .offset1 = 0x00000058, .agent_id = {'C', 'A'}, .function_code = {'R', 'L'}, .tocardlen1 = sizeof(*msg) - sizeof(msg->hdr), .fromcardlen1 = sizeof(*msg) - sizeof(msg->hdr), }; static struct CPRBX local_cprbx = { .cprb_len = 0x00dc, .cprb_ver_id = 0x02, .func_id = {0x54, 0x32}, .req_parml = sizeof(*msg) - sizeof(msg->hdr) - sizeof(msg->cprbx), .rpl_msgbl = sizeof(*msg) - sizeof(msg->hdr), }; msg->hdr = static_type6_hdrX; msg->hdr.fromcardlen2 = random_number_length; msg->cprbx = local_cprbx; msg->cprbx.rpl_datal = random_number_length; memcpy(msg->function_code, msg->hdr.function_code, 0x02); msg->rule_length = 0x0a; memcpy(msg->rule, "RANDOM ", 8); msg->verb_length = 0x02; msg->key_length = 0x02; ap_msg->len = sizeof(*msg); *domain = (unsigned short)msg->cprbx.domain; } void zcrypt_msgtype6_init(void); void zcrypt_msgtype6_exit(void); #endif /* _ZCRYPT_MSGTYPE6_H_ */ |