Zhen Kong | 0e63d13 | 2017-03-07 19:01:55 -0800 | [diff] [blame] | 1 | #ifndef _UAPI_QCOTA_H |
| 2 | #define _UAPI_QCOTA_H |
| 3 | |
| 4 | #include <linux/types.h> |
| 5 | #include <linux/ioctl.h> |
| 6 | |
| 7 | #define QCE_OTA_MAX_BEARER 31 |
| 8 | #define OTA_KEY_SIZE 16 /* 128 bits of keys. */ |
| 9 | |
| 10 | enum qce_ota_dir_enum { |
| 11 | QCE_OTA_DIR_UPLINK = 0, |
| 12 | QCE_OTA_DIR_DOWNLINK = 1, |
| 13 | QCE_OTA_DIR_LAST |
| 14 | }; |
| 15 | |
| 16 | enum qce_ota_algo_enum { |
| 17 | QCE_OTA_ALGO_KASUMI = 0, |
| 18 | QCE_OTA_ALGO_SNOW3G = 1, |
| 19 | QCE_OTA_ALGO_LAST |
| 20 | }; |
| 21 | |
| 22 | /** |
| 23 | * struct qce_f8_req - qce f8 request |
| 24 | * @data_in: packets input data stream to be ciphered. |
| 25 | * If NULL, streaming mode operation. |
| 26 | * @data_out: ciphered packets output data. |
| 27 | * @data_len: length of data_in and data_out in bytes. |
| 28 | * @count_c: count-C, ciphering sequence number, 32 bit |
| 29 | * @bearer: 5 bit of radio bearer identifier. |
| 30 | * @ckey: 128 bits of confidentiality key, |
| 31 | * ckey[0] bit 127-120, ckey[1] bit 119-112,.., ckey[15] bit 7-0. |
| 32 | * @direction: uplink or donwlink. |
| 33 | * @algorithm: Kasumi, or Snow3G. |
| 34 | * |
| 35 | * If data_in is NULL, the engine will run in a special mode called |
| 36 | * key stream mode. In this special mode, the engine will generate |
| 37 | * key stream output for the number of bytes specified in the |
| 38 | * data_len, based on the input parameters of direction, algorithm, |
| 39 | * ckey, bearer, and count_c. The data_len is restricted to |
| 40 | * the length of multiple of 16 bytes. Application can then take the |
| 41 | * output stream, do a exclusive or to the input data stream, and |
| 42 | * generate the final cipher data stream. |
| 43 | */ |
| 44 | struct qce_f8_req { |
| 45 | uint8_t *data_in; |
| 46 | uint8_t *data_out; |
| 47 | uint16_t data_len; |
| 48 | uint32_t count_c; |
| 49 | uint8_t bearer; |
| 50 | uint8_t ckey[OTA_KEY_SIZE]; |
| 51 | enum qce_ota_dir_enum direction; |
| 52 | enum qce_ota_algo_enum algorithm; |
| 53 | }; |
| 54 | |
| 55 | /** |
| 56 | * struct qce_f8_multi_pkt_req - qce f8 multiple packet request |
| 57 | * Muliptle packets with uniform size, and |
| 58 | * F8 ciphering parameters can be ciphered in a |
| 59 | * single request. |
| 60 | * |
| 61 | * @num_pkt: number of packets. |
| 62 | * |
| 63 | * @cipher_start: ciphering starts offset within a packet. |
| 64 | * |
| 65 | * @cipher_size: number of bytes to be ciphered within a packet. |
| 66 | * |
| 67 | * @qce_f8_req: description of the packet and F8 parameters. |
| 68 | * The following fields have special meaning for |
| 69 | * multiple packet operation, |
| 70 | * |
| 71 | * @data_len: data_len indicates the length of a packet. |
| 72 | * |
| 73 | * @data_in: packets are concatenated together in a byte |
| 74 | * stream started at data_in. |
| 75 | * |
| 76 | * @data_out: The returned ciphered output for multiple |
| 77 | * packets. |
| 78 | * Each packet ciphered output are concatenated |
| 79 | * together into a byte stream started at data_out. |
| 80 | * Note, each ciphered packet output area from |
| 81 | * offset 0 to cipher_start-1, and from offset |
| 82 | * cipher_size to data_len -1 are remained |
| 83 | * unaltered from packet input area. |
| 84 | * @count_c: count-C of the first packet, 32 bit. |
| 85 | * |
| 86 | * |
| 87 | * In one request, multiple packets can be ciphered, and output to the |
| 88 | * data_out stream. |
| 89 | * |
| 90 | * Packet data are laid out contiguously in sequence in data_in, |
| 91 | * and data_out area. Every packet is identical size. |
| 92 | * If the PDU is not byte aligned, set the data_len value of |
| 93 | * to the rounded up value of the packet size. Eg, PDU size of |
| 94 | * 253 bits, set the packet size to 32 bytes. Next packet starts on |
| 95 | * the next byte boundary. |
| 96 | * |
| 97 | * For each packet, data from offset 0 to cipher_start |
| 98 | * will be left unchanged and output to the data_out area. |
| 99 | * This area of the packet can be for the RLC header, which is not |
| 100 | * to be ciphered. |
| 101 | * |
| 102 | * The ciphering of a packet starts from offset cipher_start, for |
| 103 | * cipher_size bytes of data. Data starting from |
| 104 | * offset cipher_start + cipher_size to the end of packet will be left |
| 105 | * unchanged and output to the dataOut area. |
| 106 | * |
| 107 | * For each packet the input arguments of bearer, direction, |
| 108 | * ckey, algorithm have to be the same. count_c is the ciphering sequence |
| 109 | * number of the first packet. The 2nd packet's ciphering sequence |
| 110 | * number is assumed to be count_c + 1. The 3rd packet's ciphering sequence |
| 111 | * number is count_c + 2..... |
| 112 | * |
| 113 | */ |
| 114 | struct qce_f8_multi_pkt_req { |
| 115 | uint16_t num_pkt; |
| 116 | uint16_t cipher_start; |
| 117 | uint16_t cipher_size; |
| 118 | struct qce_f8_req qce_f8_req; |
| 119 | }; |
| 120 | |
| 121 | /** |
| 122 | * struct qce_f8_variable_multi_pkt_req - qce f8 multiple packet request |
| 123 | * Muliptle packets with variable size, and |
| 124 | * F8 ciphering parameters can be ciphered in a |
| 125 | * single request. |
| 126 | * |
| 127 | * @num_pkt: number of packets. |
| 128 | * |
| 129 | * @cipher_iov[]: array of iov of packets to be ciphered. |
| 130 | * |
| 131 | * |
| 132 | * @qce_f8_req: description of the packet and F8 parameters. |
| 133 | * The following fields have special meaning for |
| 134 | * multiple packet operation, |
| 135 | * |
| 136 | * @data_len: ignored. |
| 137 | * |
| 138 | * @data_in: ignored. |
| 139 | * |
| 140 | * @data_out: ignored. |
| 141 | * |
| 142 | * @count_c: count-C of the first packet, 32 bit. |
| 143 | * |
| 144 | * |
| 145 | * In one request, multiple packets can be ciphered. |
| 146 | * |
| 147 | * The i-th packet are defined in cipher_iov[i-1]. |
| 148 | * The ciphering of i-th packet starts from offset 0 of the PDU specified |
| 149 | * by cipher_iov[i-1].addr, for cipher_iov[i-1].size bytes of data. |
| 150 | * If the PDU is not byte aligned, set the cipher_iov[i-1].size value |
| 151 | * to the rounded up value of the packet size. Eg, PDU size of |
| 152 | * 253 bits, set the packet size to 32 bytes. |
| 153 | * |
| 154 | * Ciphering are done in place. That is, the ciphering |
| 155 | * input and output data are both in cipher_iov[i-1].addr for the i-th |
| 156 | * packet. |
| 157 | * |
| 158 | * For each packet the input arguments of bearer, direction, |
| 159 | * ckey, algorithm have to be the same. count_c is the ciphering sequence |
| 160 | * number of the first packet. The 2nd packet's ciphering sequence |
| 161 | * number is assumed to be count_c + 1. The 3rd packet's ciphering sequence |
| 162 | * number is count_c + 2..... |
| 163 | */ |
| 164 | |
| 165 | #define MAX_NUM_V_MULTI_PKT 20 |
| 166 | struct cipher_iov { |
| 167 | unsigned char *addr; |
| 168 | unsigned short size; |
| 169 | }; |
| 170 | |
| 171 | struct qce_f8_varible_multi_pkt_req { |
| 172 | unsigned short num_pkt; |
| 173 | struct cipher_iov cipher_iov[MAX_NUM_V_MULTI_PKT]; |
| 174 | struct qce_f8_req qce_f8_req; |
| 175 | }; |
| 176 | |
| 177 | /** |
| 178 | * struct qce_f9_req - qce f9 request |
| 179 | * @message: message |
| 180 | * @msize: message size in bytes (include the last partial byte). |
| 181 | * @last_bits: valid bits in the last byte of message. |
| 182 | * @mac_i: 32 bit message authentication code, to be returned. |
| 183 | * @fresh: random 32 bit number, one per user. |
| 184 | * @count_i: 32 bit count-I integrity sequence number. |
| 185 | * @direction: uplink or donwlink. |
| 186 | * @ikey: 128 bits of integrity key, |
| 187 | * ikey[0] bit 127-120, ikey[1] bit 119-112,.., ikey[15] bit 7-0. |
| 188 | * @algorithm: Kasumi, or Snow3G. |
| 189 | */ |
| 190 | struct qce_f9_req { |
| 191 | uint8_t *message; |
| 192 | uint16_t msize; |
| 193 | uint8_t last_bits; |
| 194 | uint32_t mac_i; |
| 195 | uint32_t fresh; |
| 196 | uint32_t count_i; |
| 197 | enum qce_ota_dir_enum direction; |
| 198 | uint8_t ikey[OTA_KEY_SIZE]; |
| 199 | enum qce_ota_algo_enum algorithm; |
| 200 | }; |
| 201 | |
| 202 | #define QCOTA_IOC_MAGIC 0x85 |
| 203 | |
| 204 | #define QCOTA_F8_REQ _IOWR(QCOTA_IOC_MAGIC, 1, struct qce_f8_req) |
| 205 | #define QCOTA_F8_MPKT_REQ _IOWR(QCOTA_IOC_MAGIC, 2, struct qce_f8_multi_pkt_req) |
| 206 | #define QCOTA_F9_REQ _IOWR(QCOTA_IOC_MAGIC, 3, struct qce_f9_req) |
| 207 | #define QCOTA_F8_V_MPKT_REQ _IOWR(QCOTA_IOC_MAGIC, 4,\ |
| 208 | struct qce_f8_varible_multi_pkt_req) |
| 209 | |
| 210 | #endif /* _UAPI_QCOTA_H */ |