Holger Dengler | 5e55a48 | 2012-08-28 16:45:36 +0200 | [diff] [blame] | 1 | /* |
| 2 | * zcrypt 2.1.0 |
| 3 | * |
| 4 | * Copyright IBM Corp. 2001, 2012 |
| 5 | * Author(s): Robert Burroughs |
| 6 | * Eric Rossman (edrossma@us.ibm.com) |
| 7 | * |
| 8 | * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com) |
| 9 | * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com> |
| 10 | * MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com> |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2, or (at your option) |
| 15 | * any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 | */ |
| 26 | |
| 27 | #ifndef _ZCRYPT_MSGTYPE6_H_ |
| 28 | #define _ZCRYPT_MSGTYPE6_H_ |
| 29 | |
| 30 | #include <asm/zcrypt.h> |
| 31 | |
| 32 | #define MSGTYPE06_NAME "zcrypt_msgtype6" |
| 33 | #define MSGTYPE06_VARIANT_DEFAULT 0 |
| 34 | #define MSGTYPE06_VARIANT_NORNG 1 |
Ingo Tuchscherer | 91f3e3e | 2013-11-20 10:47:13 +0100 | [diff] [blame] | 35 | #define MSGTYPE06_VARIANT_EP11 2 |
Holger Dengler | 5e55a48 | 2012-08-28 16:45:36 +0200 | [diff] [blame] | 36 | |
| 37 | #define MSGTYPE06_MAX_MSG_SIZE (12*1024) |
| 38 | |
| 39 | /** |
| 40 | * The type 6 message family is associated with PCICC or PCIXCC cards. |
| 41 | * |
| 42 | * It contains a message header followed by a CPRB, both of which |
| 43 | * are described below. |
| 44 | * |
| 45 | * Note that all reserved fields must be zeroes. |
| 46 | */ |
| 47 | struct type6_hdr { |
| 48 | unsigned char reserved1; /* 0x00 */ |
| 49 | unsigned char type; /* 0x06 */ |
| 50 | unsigned char reserved2[2]; /* 0x0000 */ |
| 51 | unsigned char right[4]; /* 0x00000000 */ |
| 52 | unsigned char reserved3[2]; /* 0x0000 */ |
| 53 | unsigned char reserved4[2]; /* 0x0000 */ |
| 54 | unsigned char apfs[4]; /* 0x00000000 */ |
| 55 | unsigned int offset1; /* 0x00000058 (offset to CPRB) */ |
| 56 | unsigned int offset2; /* 0x00000000 */ |
| 57 | unsigned int offset3; /* 0x00000000 */ |
| 58 | unsigned int offset4; /* 0x00000000 */ |
| 59 | unsigned char agent_id[16]; /* PCICC: */ |
| 60 | /* 0x0100 */ |
| 61 | /* 0x4343412d4150504c202020 */ |
| 62 | /* 0x010101 */ |
| 63 | /* PCIXCC: */ |
| 64 | /* 0x4341000000000000 */ |
| 65 | /* 0x0000000000000000 */ |
| 66 | unsigned char rqid[2]; /* rqid. internal to 603 */ |
| 67 | unsigned char reserved5[2]; /* 0x0000 */ |
| 68 | unsigned char function_code[2]; /* for PKD, 0x5044 (ascii 'PD') */ |
| 69 | unsigned char reserved6[2]; /* 0x0000 */ |
| 70 | unsigned int ToCardLen1; /* (request CPRB len + 3) & -4 */ |
| 71 | unsigned int ToCardLen2; /* db len 0x00000000 for PKD */ |
| 72 | unsigned int ToCardLen3; /* 0x00000000 */ |
| 73 | unsigned int ToCardLen4; /* 0x00000000 */ |
| 74 | unsigned int FromCardLen1; /* response buffer length */ |
| 75 | unsigned int FromCardLen2; /* db len 0x00000000 for PKD */ |
| 76 | unsigned int FromCardLen3; /* 0x00000000 */ |
| 77 | unsigned int FromCardLen4; /* 0x00000000 */ |
| 78 | } __packed; |
| 79 | |
| 80 | /** |
| 81 | * The type 86 message family is associated with PCICC and PCIXCC cards. |
| 82 | * |
| 83 | * It contains a message header followed by a CPRB. The CPRB is |
| 84 | * the same as the request CPRB, which is described above. |
| 85 | * |
| 86 | * If format is 1, an error condition exists and no data beyond |
| 87 | * the 8-byte message header is of interest. |
| 88 | * |
| 89 | * The non-error message is shown below. |
| 90 | * |
| 91 | * Note that all reserved fields must be zeroes. |
| 92 | */ |
| 93 | struct type86_hdr { |
| 94 | unsigned char reserved1; /* 0x00 */ |
| 95 | unsigned char type; /* 0x86 */ |
| 96 | unsigned char format; /* 0x01 (error) or 0x02 (ok) */ |
| 97 | unsigned char reserved2; /* 0x00 */ |
| 98 | unsigned char reply_code; /* reply code (see above) */ |
| 99 | unsigned char reserved3[3]; /* 0x000000 */ |
| 100 | } __packed; |
| 101 | |
| 102 | #define TYPE86_RSP_CODE 0x86 |
Ingo Tuchscherer | 91f3e3e | 2013-11-20 10:47:13 +0100 | [diff] [blame] | 103 | #define TYPE87_RSP_CODE 0x87 |
Holger Dengler | 5e55a48 | 2012-08-28 16:45:36 +0200 | [diff] [blame] | 104 | #define TYPE86_FMT2 0x02 |
| 105 | |
| 106 | struct type86_fmt2_ext { |
| 107 | unsigned char reserved[4]; /* 0x00000000 */ |
| 108 | unsigned char apfs[4]; /* final status */ |
| 109 | unsigned int count1; /* length of CPRB + parameters */ |
| 110 | unsigned int offset1; /* offset to CPRB */ |
| 111 | unsigned int count2; /* 0x00000000 */ |
| 112 | unsigned int offset2; /* db offset 0x00000000 for PKD */ |
| 113 | unsigned int count3; /* 0x00000000 */ |
| 114 | unsigned int offset3; /* 0x00000000 */ |
| 115 | unsigned int count4; /* 0x00000000 */ |
| 116 | unsigned int offset4; /* 0x00000000 */ |
| 117 | } __packed; |
| 118 | |
| 119 | /** |
| 120 | * Prepare a type6 CPRB message for random number generation |
| 121 | * |
| 122 | * @ap_dev: AP device pointer |
| 123 | * @ap_msg: pointer to AP message |
| 124 | */ |
| 125 | static inline void rng_type6CPRB_msgX(struct ap_device *ap_dev, |
| 126 | struct ap_message *ap_msg, |
| 127 | unsigned random_number_length) |
| 128 | { |
| 129 | struct { |
| 130 | struct type6_hdr hdr; |
| 131 | struct CPRBX cprbx; |
| 132 | char function_code[2]; |
| 133 | short int rule_length; |
| 134 | char rule[8]; |
| 135 | short int verb_length; |
| 136 | short int key_length; |
| 137 | } __packed * msg = ap_msg->message; |
| 138 | static struct type6_hdr static_type6_hdrX = { |
| 139 | .type = 0x06, |
| 140 | .offset1 = 0x00000058, |
| 141 | .agent_id = {'C', 'A'}, |
| 142 | .function_code = {'R', 'L'}, |
| 143 | .ToCardLen1 = sizeof(*msg) - sizeof(msg->hdr), |
| 144 | .FromCardLen1 = sizeof(*msg) - sizeof(msg->hdr), |
| 145 | }; |
| 146 | static struct CPRBX local_cprbx = { |
| 147 | .cprb_len = 0x00dc, |
| 148 | .cprb_ver_id = 0x02, |
| 149 | .func_id = {0x54, 0x32}, |
| 150 | .req_parml = sizeof(*msg) - sizeof(msg->hdr) - |
| 151 | sizeof(msg->cprbx), |
| 152 | .rpl_msgbl = sizeof(*msg) - sizeof(msg->hdr), |
| 153 | }; |
| 154 | |
| 155 | msg->hdr = static_type6_hdrX; |
| 156 | msg->hdr.FromCardLen2 = random_number_length, |
| 157 | msg->cprbx = local_cprbx; |
| 158 | msg->cprbx.rpl_datal = random_number_length, |
| 159 | msg->cprbx.domain = AP_QID_QUEUE(ap_dev->qid); |
| 160 | memcpy(msg->function_code, msg->hdr.function_code, 0x02); |
| 161 | msg->rule_length = 0x0a; |
| 162 | memcpy(msg->rule, "RANDOM ", 8); |
| 163 | msg->verb_length = 0x02; |
| 164 | msg->key_length = 0x02; |
| 165 | ap_msg->length = sizeof(*msg); |
| 166 | } |
| 167 | |
| 168 | int zcrypt_msgtype6_init(void); |
| 169 | void zcrypt_msgtype6_exit(void); |
| 170 | |
| 171 | #endif /* _ZCRYPT_MSGTYPE6_H_ */ |