/** * @file di/drv/hl854x/udp.h * @{ */ #ifndef DI_DRV_HL854X_UDP_H_ #define DI_DRV_HL854X_UDP_H_ #ifdef __cplusplus extern "C" { #endif /** Local UDP session state */ enum di_drv_hl854x_udp_state { HL854X_UDP_STATE_ERROR = -1, /**< Error (e.g received KUDP_NOTIF) */ HL854X_UDP_STATE_UNKNOWN = 0, /**< Session state unknown */ HL854X_UDP_STATE_WRITTEN = 1, /**< Session configuration written to modem */ HL854X_UDP_STATE_CONFIGURED = 2, /**< Session configured (acknowledged by the modem) */ HL854X_UDP_STATE_READY = 3, /**< Session ready for use */ }; /** KUDP_IND codes */ enum di_drv_hl854x_kudp_ind { DI_DRV_HL854X_KUDP_IND_UNKNOWN = -1, /**< Session indicator unknown (internal number) */ DI_DRV_HL854X_KUDP_IND_READY = 1, /**< Session modem ready indicator */ }; /** KUDP_NOTIF codes */ enum di_drv_hl854x_kudp_notif { DI_DRV_HL854X_KUDP_NOTIF_NETWORK_ERROR = 0, DI_DRV_HL854X_KUDP_NOTIF_NO_MORE_SOCK = 1, DI_DRV_HL854X_KUDP_NOTIF_MEMORY_PROB = 2, DI_DRV_HL854X_KUDP_NOTIF_DNS_ERROR = 3, DI_DRV_HL854X_KUDP_NOTIF_CONN_ERR_HOST_UNREACH = 5, DI_DRV_HL854X_KUDP_NOTIF_GENERIC_ERROR = 6, DI_DRV_HL854X_KUDP_NOTIF_SENDOK_MORE_OR_LESS_DATA = 8, DI_DRV_HL854X_KUDP_NOTIF_BAD_SESSION_ID = 9, DI_DRV_HL854X_KUDP_NOTIF_SESSION_ALREADY_RUNNING = 10, DI_DRV_HL854X_KUDP_NOTIF_ALL_SESSIONS_USED = 11, }; struct di_buffer; struct di_drv_hl854x_ctx_udp; /** * Initialize the UDP session context * @note May only be called once * @param ctx Modem UDP session context */ void di_drv_hl854x_udp_init(struct di_drv_hl854x_ctx_udp *ctx); /** * Set the local port where the UDP session listens on * @param ctx Modem driver context * @param port Port (valid 1 to 2^16-1) */ void di_drv_hl854x_udp_set_local_port(struct di_drv_hl854x_ctx *ctx, const char *port); /** * Set the remote endpoint for the UDP session * @param ctx Modem driver context * @param addr Remote host address (ip address or DNS name) * @param port Remote host port (valid 1 to 2^16-1) */ void di_drv_hl854x_udp_set_remote_endpoint(struct di_drv_hl854x_ctx *ctx, const char *addr, const char *port); /** * Get the current local state of the UDP session * @param ctx Modem driver context */ enum di_drv_hl854x_udp_state di_drv_hl854x_udp_get_state(struct di_drv_hl854x_ctx *ctx); /** * Open/configure the UDP session as a listening server, it is safe to call it multiple times. Before calling this * function one must make sure the modem has an carrier and an active PDP session * (e.g calling di_drv_hl854x_is_connected). * @note It can take some time for the modem to respond, for getting to know the actual session state * di_drv_hl854x_udp_get_state must be used after this function is successful. * @return DNOK when session configuration is written. */ di_errno_t di_drv_hl854x_udp_open(struct di_drv_hl854x_ctx *ctx); /** * Close the UDP session and delete the session configuration * @param ctx Modem driver context * @return DNOK when session is successfully closed. */ di_errno_t di_drv_hl854x_udp_close(struct di_drv_hl854x_ctx *ctx); /** * Send buffer over UDP * @param[in] ctx Modem driver context * @param[in] buf Buffer to send * @param size Size in bytes of the buffer to send * @return DNOK when send, !DNOK in case of an error */ di_errno_t di_drv_hl854x_udp_send(struct di_drv_hl854x_ctx *ctx, const void *buf, const size_t size); /** * Send di_buffer over UDP * @param[in] ctx Modem driver context * @param[in] buf DI buffer to send (the amount of bytes must be present in buf->used) * @return DNOK when send, !DNOK in case of an error */ di_errno_t di_drv_hl854x_udp_send_buffer(struct di_drv_hl854x_ctx *ctx, const struct di_buffer *buf); /** * Wait until data available on the active UDP session. * @note Upon succesfull call the UDP session ndata_available is reset to zero. * @param ctx Modem driver context * @param timeout_ms Timeout in milliseconds (or HL854X_TIMEOUT_INFINITE) * @param[out] ndata_available Amount of bytes available for receive on the active UDP session * @retval DNOK when data is available * @retval DNE_DISCONNECTED when there is no active UDP session * @retval DNE_TIMEOUT when there is no data available and timeout is reached */ di_errno_t di_drv_hl854x_udp_recv_wait_ndata_available(struct di_drv_hl854x_ctx *ctx, uint32_t timeout_ms, size_t *ndata_available); /** * Receive available data from the active UDP session * @param ctx Driver context * @param[out] buf Destination buffer to write available data into * @param size Size in bytes to be received * @retval 0 when recv failed * @retval size when recv was succesfull */ size_t di_drv_hl854x_udp_recv(struct di_drv_hl854x_ctx *ctx, void *buf, const size_t size); #ifdef __cplusplus } #endif /** @} */ #endif /* DI_DRV_HL854X_UDP_H_ */