ble_l2cap_evt_app.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /**
  2. * Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #include "ble_serialization.h"
  41. #include "ble_struct_serialization.h"
  42. #include "ble_l2cap_struct_serialization.h"
  43. #include "app_util.h"
  44. #include "ble_l2cap_evt_app.h"
  45. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
  46. uint32_t ble_l2cap_evt_rx_dec(uint8_t const * const p_buf,
  47. uint32_t packet_len,
  48. ble_evt_t * const p_event,
  49. uint32_t * const p_event_len)
  50. {
  51. SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_RX, l2cap, rx);
  52. SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle);
  53. SER_PULL_FIELD_EXTENDED(&p_event->evt.l2cap_evt.params.rx, ble_l2cap_evt_rx_t_dec);
  54. SER_EVT_DEC_END;
  55. }
  56. #endif
  57. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5
  58. uint32_t ble_l2cap_evt_ch_setup_request_dec(uint8_t const * const p_buf,
  59. uint32_t packet_len,
  60. ble_evt_t * const p_event,
  61. uint32_t * const p_event_len)
  62. {
  63. SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_SETUP_REQUEST, l2cap, ch_setup_request);
  64. SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle);
  65. SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid);
  66. SER_PULL_uint16(&p_event->evt.l2cap_evt.params.ch_setup_request.le_psm);
  67. SER_PULL_FIELD(&p_event->evt.l2cap_evt.params.ch_setup_request.tx_params, ble_l2cap_ch_tx_params_t_dec);
  68. SER_EVT_DEC_END;
  69. }
  70. uint32_t ble_l2cap_evt_ch_setup_refused_dec(uint8_t const * const p_buf,
  71. uint32_t packet_len,
  72. ble_evt_t * const p_event,
  73. uint32_t * const p_event_len)
  74. {
  75. SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_SETUP_REFUSED, l2cap, ch_setup_refused);
  76. SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle);
  77. SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid);
  78. SER_PULL_uint8(&p_event->evt.l2cap_evt.params.ch_setup_refused.source);
  79. SER_PULL_uint16(&p_event->evt.l2cap_evt.params.ch_setup_refused.status);
  80. SER_EVT_DEC_END;
  81. }
  82. uint32_t ble_l2cap_evt_ch_setup_dec(uint8_t const * const p_buf,
  83. uint32_t packet_len,
  84. ble_evt_t * const p_event,
  85. uint32_t * const p_event_len)
  86. {
  87. SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_SETUP, l2cap, ch_setup);
  88. SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle);
  89. SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid);
  90. SER_PULL_FIELD(&p_event->evt.l2cap_evt.params.ch_setup.tx_params, ble_l2cap_ch_tx_params_t_dec);
  91. SER_EVT_DEC_END;
  92. }
  93. uint32_t ble_l2cap_evt_ch_released_dec(uint8_t const * const p_buf,
  94. uint32_t packet_len,
  95. ble_evt_t * const p_event,
  96. uint32_t * const p_event_len)
  97. {
  98. SER_EVT_DEC_BEGIN_NO_STRUCT(BLE_L2CAP_EVT_CH_RELEASED, l2cap);
  99. SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle);
  100. SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid);
  101. SER_EVT_DEC_END;
  102. }
  103. uint32_t ble_l2cap_evt_ch_sdu_buf_released_dec(uint8_t const * const p_buf,
  104. uint32_t packet_len,
  105. ble_evt_t * const p_event,
  106. uint32_t * const p_event_len)
  107. {
  108. SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_SDU_BUF_RELEASED, l2cap, ch_sdu_buf_released);
  109. SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle);
  110. SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid);
  111. SER_PULL_uint16(&p_event->evt.l2cap_evt.params.ch_sdu_buf_released.sdu_buf.len);
  112. SER_PULL_uint32(&p_event->evt.l2cap_evt.params.ch_sdu_buf_released.sdu_buf.p_data);
  113. SER_EVT_DEC_END;
  114. }
  115. uint32_t ble_l2cap_evt_ch_credit_dec(uint8_t const * const p_buf,
  116. uint32_t packet_len,
  117. ble_evt_t * const p_event,
  118. uint32_t * const p_event_len)
  119. {
  120. SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_CREDIT, l2cap, ch_credit);
  121. SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle);
  122. SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid);
  123. SER_PULL_uint16(&p_event->evt.l2cap_evt.params.credit.credits);
  124. SER_EVT_DEC_END;
  125. }
  126. uint32_t ble_l2cap_evt_ch_rx_dec(uint8_t const * const p_buf,
  127. uint32_t packet_len,
  128. ble_evt_t * const p_event,
  129. uint32_t * const p_event_len)
  130. {
  131. SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_RX, l2cap, ch_rx);
  132. SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle);
  133. SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid);
  134. SER_PULL_uint16(&p_event->evt.l2cap_evt.params.rx.sdu_len);
  135. SER_PULL_uint16(&p_event->evt.l2cap_evt.params.rx.sdu_buf.len);
  136. SER_PULL_uint32(&p_event->evt.l2cap_evt.params.rx.sdu_buf.p_data);
  137. SER_PULL_buf(&p_event->evt.l2cap_evt.params.rx.sdu_buf.p_data, p_event->evt.l2cap_evt.params.rx.sdu_buf.len, p_event->evt.l2cap_evt.params.rx.sdu_buf.len);
  138. SER_EVT_DEC_END;
  139. }
  140. uint32_t ble_l2cap_evt_ch_tx_dec(uint8_t const * const p_buf,
  141. uint32_t packet_len,
  142. ble_evt_t * const p_event,
  143. uint32_t * const p_event_len)
  144. {
  145. SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_TX, l2cap, ch_tx);
  146. SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle);
  147. SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid);
  148. SER_PULL_uint16(&p_event->evt.l2cap_evt.params.tx.sdu_buf.len);
  149. SER_PULL_uint32(&p_event->evt.l2cap_evt.params.tx.sdu_buf.p_data);
  150. SER_EVT_DEC_END;
  151. }
  152. #endif