conn_mw.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. #include <stddef.h>
  13. #include "ble_serialization.h"
  14. #include "nrf_soc.h"
  15. #include "ble.h"
  16. #include "ble_l2cap.h"
  17. #include "ble_gap.h"
  18. #include "ble_gattc.h"
  19. #include "ble_gatts.h"
  20. /**@brief Connectivity middleware handler type. */
  21. typedef uint32_t (*conn_mw_handler_t)(uint8_t const * const p_rx_buf,
  22. uint32_t rx_buf_len,
  23. uint8_t * const p_tx_buf,
  24. uint32_t * const p_tx_buf_len);
  25. /**@brief Connectivity middleware item. */
  26. typedef struct
  27. {
  28. uint8_t opcode; /**< Opcode by which specific codec is identified */
  29. conn_mw_handler_t fp_handler; /**< Function pointer to handler associated with given opcode */
  30. } conn_mw_item_t;
  31. /* Include handlers for given softdevice */
  32. #include "conn_mw_items.c"
  33. /**@brief Number of registered connectivity middleware handlers. */
  34. static const uint32_t conn_mw_item_len = sizeof (conn_mw_item) / sizeof (conn_mw_item[0]);
  35. /**@brief Local function for finding connectivity middleware handler in the table.. */
  36. static conn_mw_handler_t conn_mw_handler_get(uint8_t opcode)
  37. {
  38. conn_mw_handler_t fp_handler = NULL;
  39. uint32_t i;
  40. for (i = 0; i < conn_mw_item_len; i++)
  41. {
  42. if (opcode == conn_mw_item[i].opcode)
  43. {
  44. fp_handler = conn_mw_item[i].fp_handler;
  45. break;
  46. }
  47. }
  48. return fp_handler;
  49. }
  50. uint32_t conn_mw_handler(uint8_t const * const p_rx_buf,
  51. uint32_t rx_buf_len,
  52. uint8_t * const p_tx_buf,
  53. uint32_t * const p_tx_buf_len)
  54. {
  55. SER_ASSERT_NOT_NULL(p_rx_buf);
  56. SER_ASSERT_NOT_NULL(p_tx_buf);
  57. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  58. conn_mw_handler_t fp_handler;
  59. uint32_t err_code = NRF_SUCCESS;
  60. uint8_t opcode = p_rx_buf[SER_CMD_OP_CODE_POS];
  61. fp_handler = conn_mw_handler_get(opcode);
  62. if (fp_handler)
  63. {
  64. err_code = fp_handler(p_rx_buf, rx_buf_len, p_tx_buf, p_tx_buf_len);
  65. }
  66. else
  67. {
  68. err_code = NRF_ERROR_NOT_SUPPORTED;
  69. }
  70. return err_code;
  71. }