socket_common.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * Copyright (c) 2015 - 2018, 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. /**@file socket_common.h
  41. *
  42. * @defgroup socket_common BSD Socket internal functions and structures
  43. * @ingroup iot_sdk_socket
  44. * @{
  45. * @brief Nordic socket interface internal functions and structures.
  46. */
  47. #ifndef SOCKET_COMMON_H__
  48. #define SOCKET_COMMON_H__
  49. #include <stdint.h>
  50. #include "socket_api.h"
  51. #ifdef __cplusplus
  52. extern "C" {
  53. #endif
  54. struct socket_transport;
  55. #define AF_NRF_CFG_INTERNAL 41 /**< Socket family type, internal NRF configuration socket. */
  56. /**
  57. * @brief Function for initializing the socket API module.
  58. *
  59. * @return NRF_SUCCESS on success, otherwise error code is returned.
  60. */
  61. uint32_t socket_init(void);
  62. /**
  63. * @brief Waiting function for sockets.
  64. *
  65. * @details Must be implemented by specific modules such as BLEs.
  66. *
  67. * @return NRF_SUCCESS on success, otherwise error code is returned.
  68. */
  69. uint32_t socket_wait(void);
  70. /**
  71. * @brief Create parameters for a socket.
  72. */
  73. typedef struct {
  74. socket_family_t so_family; /**< Socket family. */
  75. socket_protocol_t so_protocol; /**< Socket protocol. */
  76. socket_type_t so_type; /**< Socket type. */
  77. } socket_params_t;
  78. /**
  79. * @brief Different states a socket can be in.
  80. */
  81. typedef enum {
  82. STATE_CLOSED = 0, /**< Socket is closed. */
  83. STATE_OPEN, /**< Socket is opened. */
  84. STATE_CONNECTED, /**< Socket is connected. */
  85. } socket_state_t;
  86. /**
  87. * @brief The state associated with a socket handle.
  88. */
  89. typedef struct {
  90. socket_params_t so_params; /**< Generic socket parameters. */
  91. void * so_ctx; /**< Transport specific context. */
  92. int so_flags; /**< Socket flags. */
  93. uint16_t so_read_evt; /**< Notifying of read events. */
  94. uint16_t so_write_evt; /**< Notifying of write events. */
  95. uint16_t so_except_evt; /**< Notifying of exceptional events. */
  96. struct socket_transport * so_transport; /**< Transport attached to this socket. */
  97. volatile socket_state_t so_state; /**< Socket state. */
  98. } socket_t;
  99. #ifdef __cplusplus
  100. }
  101. #endif
  102. #endif // SOCKET_COMMON_H__
  103. /**@} */