drv_ps_path.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _DRV_PS_PATH_H_
  13. #define _DRV_PS_PATH_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <stddef.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /**
  21. * opaque data structure for PS interface
  22. */
  23. typedef struct drvPsIntf drvPsIntf_t;
  24. /**
  25. * callback function of PS interface data arrival
  26. *
  27. * The callback is executed in PS path thread, or the thread calling
  28. * \p drvPsPathDataArrive. Inside the callback, it is permitted to call
  29. * \p drvPsIntfRead. However, it is not permitted to call
  30. * \p drvPsInterfaceOpen and \p drvPsIntfClose.
  31. */
  32. typedef void (*drvPsIntfDataArriveCB_t)(void *ctx, drvPsIntf_t *p);
  33. /**
  34. * @brief initialize PS path module
  35. */
  36. void drvPsPathInit(void);
  37. /**
  38. * @brief PS data arrive callback in external source
  39. *
  40. * For external source, this API is implemented inside this module and called
  41. * by external source.
  42. *
  43. * For non-external source, this API may be unimplemented.
  44. *
  45. * @param sim SIM id
  46. * @param cid CID
  47. * @param data PS data
  48. * @param size PS data size
  49. */
  50. void drvPsPathDataArrive(uint8_t sim, uint8_t cid, const void *data, uint16_t size);
  51. /**
  52. * @brief PS data send function
  53. *
  54. * For extenal source, this API will be called in this module, and sould be
  55. * implemented in other modules.
  56. *
  57. * For non-external source, this API won't be called.
  58. *
  59. * @param sim SIM id
  60. * @param cid CID
  61. * @param data PS data
  62. * @param size PS data size
  63. * @param rai NAS Release assistance indication 0 1 2
  64. * @return
  65. * - sent size, it should be equal to \p size on success
  66. * - -1 on failed
  67. */
  68. int drvPsPathDataSend(uint8_t sim, uint8_t cid, const void *data, uint16_t size, uint8_t rai, uint8_t app_sn);
  69. /**
  70. * @brief open a PS interface
  71. *
  72. * Each sim and cid combination is an interface. For each interface,
  73. * it can be opened only once.
  74. *
  75. * @param sim SIM number
  76. * @param cid CID
  77. * @param cb callback of data arrival
  78. * @param cb_ctx callback contex pointer
  79. * @return
  80. * - PS interface pointer
  81. * - NULL on error
  82. * - the SIM/CID is already opened
  83. * - invalid sim cid combination
  84. */
  85. drvPsIntf_t *drvPsIntfOpen(uint8_t sim, uint8_t cid, drvPsIntfDataArriveCB_t cb, void *cb_ctx);
  86. /**
  87. * @brief close a PS interface
  88. *
  89. * When \p p is NULL or the interface is already opened, there are no
  90. * operations.
  91. *
  92. * @param p PS interface pointer
  93. */
  94. void drvPsIntfClose(drvPsIntf_t *p);
  95. /**
  96. * @brief change PS interface data arrive callback
  97. *
  98. * When \p cb is NULL, the registered callback won't be changed. And the
  99. * original callback will be returned.
  100. *
  101. * @param p PS interface pointer, can't be NULL
  102. * @param cb data arrive callback
  103. * @return the original data arrive callback
  104. */
  105. drvPsIntfDataArriveCB_t drvPsIntfSetDataArriveCB(drvPsIntf_t *p, drvPsIntfDataArriveCB_t cb);
  106. /**
  107. * @brief read from PS interface
  108. *
  109. * When there are no data in PS interface, return 0.
  110. *
  111. * When the input \p size is too small for one packet, return -1.
  112. * The maximum packet size is \p PS_BUF_DL_LEN_B.
  113. *
  114. * @param p PS interface pointer, can't be NULL
  115. * @param data memory for read, can't be NULL
  116. * @param size memory size
  117. * @return
  118. * - read size
  119. * - 0 if no data
  120. * - -1 if input \p size is too small for one packet
  121. */
  122. int drvPsIntfRead(drvPsIntf_t *p, void *data, size_t size);
  123. /**
  124. * @brief available read size of PS interface
  125. *
  126. * @param p PS interface pointer, can't be NULL
  127. * @return available read size
  128. */
  129. int drvPsIntfReadAvail(drvPsIntf_t *p);
  130. /**
  131. * @brief write to PS interface
  132. *
  133. * This won't wait available uplink buffer. When uplink buffer is unavailable,
  134. * this will return 0.
  135. *
  136. * @param p PS interface pointer, can't be NULL
  137. * @param data data to be written
  138. * @param size data size
  139. * @param rai NAS Release assistance indication 0 1 2
  140. * @param app_sn rf_ack app_sn
  141. * @return
  142. * - 0 is uplink buffer is unavailable
  143. * - written size, it should be equal to \p size on success
  144. * - -1 if \p data is NULL or \p size is too large for one packet
  145. */
  146. int drvPsIntfWrite(drvPsIntf_t *p, const void *data, size_t size, uint8_t rai, uint8_t app_sn);
  147. /**
  148. * @brief write multiple buffers to PS interface
  149. *
  150. * When \p data[n] is NULL or \p size[n] is too large, the buffers from it
  151. * won't be written.
  152. *
  153. * This won't wait available uplink buffer. So, the returned written size will be
  154. * smaller than provided total size.
  155. *
  156. * @param p PS interface pointer, can't be NULL
  157. * @param count buffer count
  158. * @param data array of buffer address to be written
  159. * @param size array of buffer size to be written
  160. * @return
  161. * - written bytes, may be smaller than provided total size
  162. */
  163. int drvPsIntfWriteMulti(drvPsIntf_t *p, size_t count, const void *data[], size_t size[]);
  164. #ifdef __cplusplus
  165. }
  166. #endif
  167. #endif