blob: afc6b7fbd154b27b251346f3f4fa871d11432918 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#ifndef __QCOTA__H
15#define __QCOTA__H
16
17#include <linux/types.h>
18#include <linux/ioctl.h>
19
20#define QCE_OTA_MAX_BEARER 31
21#define OTA_KEY_SIZE 16 /* 128 bits of keys. */
22
23enum qce_ota_dir_enum {
24 QCE_OTA_DIR_UPLINK = 0,
25 QCE_OTA_DIR_DOWNLINK = 1,
26 QCE_OTA_DIR_LAST
27};
28
29enum qce_ota_algo_enum {
30 QCE_OTA_ALGO_KASUMI = 0,
31 QCE_OTA_ALGO_SNOW3G = 1,
32 QCE_OTA_ALGO_LAST
33};
34
35/**
36 * struct qce_f8_req - qce f8 request
37 * @data_in: packets input data stream to be ciphered.
38 * If NULL, streaming mode operation.
39 * @data_out: ciphered packets output data.
40 * @data_len: length of data_in and data_out in bytes.
41 * @count_c: count-C, ciphering sequence number, 32 bit
42 * @bearer: 5 bit of radio bearer identifier.
43 * @ckey: 128 bits of confidentiality key,
44 * ckey[0] bit 127-120, ckey[1] bit 119-112,.., ckey[15] bit 7-0.
45 * @direction: uplink or donwlink.
46 * @algorithm: Kasumi, or Snow3G.
47 *
48 * If data_in is NULL, the engine will run in a special mode called
49 * key stream mode. In this special mode, the engine will generate
50 * key stream output for the number of bytes specified in the
51 * data_len, based on the input parameters of direction, algorithm,
52 * ckey, bearer, and count_c. The data_len is restricted to
53 * the length of multiple of 16 bytes. Application can then take the
54 * output stream, do a exclusive or to the input data stream, and
55 * generate the final cipher data stream.
56 */
57struct qce_f8_req {
58 uint8_t *data_in;
59 uint8_t *data_out;
60 uint16_t data_len;
61 uint32_t count_c;
62 uint8_t bearer;
63 uint8_t ckey[OTA_KEY_SIZE];
64 enum qce_ota_dir_enum direction;
65 enum qce_ota_algo_enum algorithm;
66};
67
68/**
69 * struct qce_f8_multi_pkt_req - qce f8 multiple packet request
70 * Muliptle packets with uniform size, and
71 * F8 ciphering parameters can be ciphered in a
72 * single request.
73 *
74 * @num_pkt: number of packets.
75 *
76 * @cipher_start: ciphering starts offset within a packet.
77 *
78 * @cipher_size: number of bytes to be ciphered within a packet.
79 *
80 * @qce_f8_req: description of the packet and F8 parameters.
81 * The following fields have special meaning for
82 * multiple packet operation,
83 *
84 * @data_len: data_len indicates the length of a packet.
85 *
86 * @data_in: packets are concatenated together in a byte
87 * stream started at data_in.
88 *
89 * @data_out: The returned ciphered output for multiple
90 * packets.
91 * Each packet ciphered output are concatenated
92 * together into a byte stream started at data_out.
93 * Note, each ciphered packet output area from
94 * offset 0 to cipher_start-1, and from offset
95 * cipher_size to data_len -1 are remained
96 * unaltered from packet input area.
97 * @count_c: count-C of the first packet, 32 bit.
98 *
99 *
100 * In one request, multiple packets can be ciphered, and output to the
101 * data_out stream.
102 *
103 * Packet data are layed out contiguously in sequence in data_in,
104 * and data_out area. Every packet is identical size.
105 * If the PDU is not byte aligned, set the data_len value of
106 * to the rounded up value of the packet size. Eg, PDU size of
107 * 253 bits, set the packet size to 32 bytes. Next packet starts on
108 * the next byte boundary.
109 *
110 * For each packet, data from offset 0 to cipher_start
111 * will be left unchanged and output to the data_out area.
112 * This area of the packet can be for the RLC header, which is not
113 * to be ciphered.
114 *
115 * The ciphering of a packet starts from offset cipher_start, for
116 * cipher_size bytes of data. Data starting from
117 * offset cipher_start + cipher_size to the end of packet will be left
118 * unchanged and output to the dataOut area.
119 *
120 * For each packet the input arguments of bearer, direction,
121 * ckey, algoritm have to be the same. count_c is the ciphering sequence
122 * number of the first packet. The 2nd packet's ciphering sequence
123 * number is assumed to be count_c + 1. The 3rd packet's ciphering sequence
124 * number is count_c + 2.....
125 *
126 */
127struct qce_f8_multi_pkt_req {
128 uint16_t num_pkt;
129 uint16_t cipher_start;
130 uint16_t cipher_size;
131 struct qce_f8_req qce_f8_req;
132};
133
134/**
135 * struct qce_f9_req - qce f9 request
136 * @message: message
137 * @msize: message size in bytes (include the last partial byte).
138 * @last_bits: valid bits in the last byte of message.
139 * @mac_i: 32 bit message authentication code, to be returned.
140 * @fresh: random 32 bit number, one per user.
141 * @count_i: 32 bit count-I integrity sequence number.
142 * @direction: uplink or donwlink.
143 * @ikey: 128 bits of integrity key,
144 * ikey[0] bit 127-120, ikey[1] bit 119-112,.., ikey[15] bit 7-0.
145 * @algorithm: Kasumi, or Snow3G.
146 */
147struct qce_f9_req {
148 uint8_t *message;
149 uint16_t msize;
150 uint8_t last_bits;
151 uint32_t mac_i;
152 uint32_t fresh;
153 uint32_t count_i;
154 enum qce_ota_dir_enum direction;
155 uint8_t ikey[OTA_KEY_SIZE];
156 enum qce_ota_algo_enum algorithm;
157};
158
159#define QCOTA_IOC_MAGIC 0x85
160
161#define QCOTA_F8_REQ _IOWR(QCOTA_IOC_MAGIC, 1, struct qce_f8_req)
162#define QCOTA_F8_MPKT_REQ _IOWR(QCOTA_IOC_MAGIC, 2, struct qce_f8_multi_pkt_req)
163#define QCOTA_F9_REQ _IOWR(QCOTA_IOC_MAGIC, 3, struct qce_f9_req)
164
165#endif /* __QCOTA__H */