qcota.h 5.5 KB

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