qcota.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
  2. /*
  3. * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _UAPI_QCOTA_H
  7. #define _UAPI_QCOTA_H
  8. #include <linux/types.h>
  9. #include <linux/ioctl.h>
  10. #define QCE_OTA_MAX_BEARER 31
  11. #define OTA_KEY_SIZE 16 /* 128 bits of keys. */
  12. enum qce_ota_dir_enum {
  13. QCE_OTA_DIR_UPLINK = 0,
  14. QCE_OTA_DIR_DOWNLINK = 1,
  15. QCE_OTA_DIR_LAST
  16. };
  17. enum qce_ota_algo_enum {
  18. QCE_OTA_ALGO_KASUMI = 0,
  19. QCE_OTA_ALGO_SNOW3G = 1,
  20. QCE_OTA_ALGO_LAST
  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. __u8 *data_in;
  46. __u8 *data_out;
  47. __u16 data_len;
  48. __u32 count_c;
  49. __u8 bearer;
  50. __u8 ckey[OTA_KEY_SIZE];
  51. enum qce_ota_dir_enum direction;
  52. enum qce_ota_algo_enum algorithm;
  53. int current_req_info;
  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. __u16 num_pkt;
  116. __u16 cipher_start;
  117. __u16 cipher_size;
  118. struct qce_f8_req qce_f8_req;
  119. };
  120. /**
  121. * struct qce_f8_variable_multi_pkt_req - qce f8 multiple packet request
  122. * Muliptle packets with variable size, and
  123. * F8 ciphering parameters can be ciphered in a
  124. * single request.
  125. *
  126. * @num_pkt: number of packets.
  127. *
  128. * @cipher_iov[]: array of iov of packets to be ciphered.
  129. *
  130. *
  131. * @qce_f8_req: description of the packet and F8 parameters.
  132. * The following fields have special meaning for
  133. * multiple packet operation,
  134. *
  135. * @data_len: ignored.
  136. *
  137. * @data_in: ignored.
  138. *
  139. * @data_out: ignored.
  140. *
  141. * @count_c: count-C of the first packet, 32 bit.
  142. *
  143. *
  144. * In one request, multiple packets can be ciphered.
  145. *
  146. * The i-th packet are defined in cipher_iov[i-1].
  147. * The ciphering of i-th packet starts from offset 0 of the PDU specified
  148. * by cipher_iov[i-1].addr, for cipher_iov[i-1].size bytes of data.
  149. * If the PDU is not byte aligned, set the cipher_iov[i-1].size value
  150. * to the rounded up value of the packet size. Eg, PDU size of
  151. * 253 bits, set the packet size to 32 bytes.
  152. *
  153. * Ciphering are done in place. That is, the ciphering
  154. * input and output data are both in cipher_iov[i-1].addr for the i-th
  155. * packet.
  156. *
  157. * For each packet the input arguments of bearer, direction,
  158. * ckey, algorithm have to be the same. count_c is the ciphering sequence
  159. * number of the first packet. The 2nd packet's ciphering sequence
  160. * number is assumed to be count_c + 1. The 3rd packet's ciphering sequence
  161. * number is count_c + 2.....
  162. */
  163. #define MAX_NUM_V_MULTI_PKT 20
  164. struct cipher_iov {
  165. unsigned char *addr;
  166. unsigned short size;
  167. };
  168. struct qce_f8_variable_multi_pkt_req {
  169. unsigned short num_pkt;
  170. struct cipher_iov cipher_iov[MAX_NUM_V_MULTI_PKT];
  171. struct qce_f8_req qce_f8_req;
  172. };
  173. /**
  174. * struct qce_f9_req - qce f9 request
  175. * @message: message
  176. * @msize: message size in bytes (include the last partial byte).
  177. * @last_bits: valid bits in the last byte of message.
  178. * @mac_i: 32 bit message authentication code, to be returned.
  179. * @fresh: random 32 bit number, one per user.
  180. * @count_i: 32 bit count-I integrity sequence number.
  181. * @direction: uplink or donwlink.
  182. * @ikey: 128 bits of integrity key,
  183. * ikey[0] bit 127-120, ikey[1] bit 119-112,.., ikey[15] bit 7-0.
  184. * @algorithm: Kasumi, or Snow3G.
  185. */
  186. struct qce_f9_req {
  187. __u8 *message;
  188. __u16 msize;
  189. __u8 last_bits;
  190. __u32 mac_i;
  191. __u32 fresh;
  192. __u32 count_i;
  193. enum qce_ota_dir_enum direction;
  194. __u8 ikey[OTA_KEY_SIZE];
  195. enum qce_ota_algo_enum algorithm;
  196. int current_req_info;
  197. };
  198. #define QCOTA_IOC_MAGIC 0x85
  199. #define QCOTA_F8_REQ _IOWR(QCOTA_IOC_MAGIC, 1, struct qce_f8_req)
  200. #define QCOTA_F8_MPKT_REQ _IOWR(QCOTA_IOC_MAGIC, 2, struct qce_f8_multi_pkt_req)
  201. #define QCOTA_F9_REQ _IOWR(QCOTA_IOC_MAGIC, 3, struct qce_f9_req)
  202. #define QCOTA_F8_V_MPKT_REQ _IOWR(QCOTA_IOC_MAGIC, 4,\
  203. struct qce_f8_variable_multi_pkt_req)
  204. #endif /* _UAPI_QCOTA_H */