qcota.h 7.0 KB

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