l4p/tcp: introduce tle_tcp_stream_abort() API
[tldk.git] / lib / libtle_l4p / tle_tcp.h
index 9947041..289683f 100644 (file)
 extern "C" {
 #endif
 
+/**
+ * TCP stream states
+ */
+enum {
+       TLE_TCP_ST_CLOSED,
+       TLE_TCP_ST_LISTEN,
+       TLE_TCP_ST_SYN_SENT,
+       TLE_TCP_ST_SYN_RCVD,
+       TLE_TCP_ST_ESTABLISHED,
+       TLE_TCP_ST_FIN_WAIT_1,
+       TLE_TCP_ST_FIN_WAIT_2,
+       TLE_TCP_ST_CLOSE_WAIT,
+       TLE_TCP_ST_CLOSING,
+       TLE_TCP_ST_LAST_ACK,
+       TLE_TCP_ST_TIME_WAIT,
+       TLE_TCP_ST_NUM
+};
+
+/**
+ * User control operations for TCP stream
+ */
+enum {
+       TLE_TCP_OP_LISTEN =    0x1,
+       TLE_TCP_OP_ACCEPT =    0x2,
+       TLE_TCP_OP_CONNECT =   0x4,
+       TLE_TCP_OP_ESTABLISH = 0x8,
+       TLE_TCP_OP_CLOSE =     0x10,
+       TLE_TCP_OP_ABORT =     0x20,
+};
+
+#define TLE_TCP_OP_CLOSE_ABORT (TLE_TCP_OP_CLOSE | TLE_TCP_OP_ABORT)
+
+/**
+ * termination/error events from remote peer
+ */
+enum {
+       TLE_TCP_REV_FIN = 0x1,  /** FIN received from peer*/
+       TLE_TCP_REV_RST = 0x2,  /** RST received from peer */
+       TLE_TCP_REV_RTO = 0x4,  /** receive timed-out */
+};
+
 /**
  * TCP stream creation parameters.
  */
@@ -35,6 +76,8 @@ struct tle_tcp_stream_addr {
 struct tle_tcp_stream_cfg {
        uint8_t nb_retries;     /**< max number of retransmission attempts. */
 
+       uint64_t udata; /**< user data to be associated with the stream. */
+
        /* _cb and _ev are mutually exclusive */
        struct tle_event *err_ev;      /**< error event to use.  */
        struct tle_stream_cb err_cb;   /**< error callback to use. */
@@ -78,6 +121,18 @@ struct tle_tcp_conn_info {
        struct tle_tcp_syn_opts so;
 };
 
+/**
+ * TCP stream state information.
+ */
+struct tle_tcp_stream_state {
+       /** current TCP state (one of TLE_TCP_ST_*) */
+       uint16_t state;
+       /** bitmask of control ops performed by user (TLE_TCP_OP_*) */
+       uint16_t uop;
+       /** bitmask of remote termination events (TLE_TCP_REV_*) */
+       uint16_t rev;
+};
+
 /**
  * create a new stream within given TCP context.
  * @param ctx
@@ -102,7 +157,7 @@ tle_tcp_stream_open(struct tle_ctx *ctx,
  * - if stream contains unsent data, then actual close will be postponed
  * till either remaining data will be TX-ed, or timeout will expire.
  * All packets that belong to that stream and remain in the device
- * TX queue will be kept for father transmission.
+ * TX queue will be kept for further transmission.
  * @param s
  *   Pointer to the stream to close.
  * @return
@@ -112,6 +167,25 @@ tle_tcp_stream_open(struct tle_ctx *ctx,
  */
 int tle_tcp_stream_close(struct tle_stream *s);
 
+/**
+ * abnormal stream termination.
+ * if the stream is in connected state, then:
+ * - abnormal connection termination would be performed.
+ * - if stream contains unread data, then it will be wiped out.
+ * - if stream contains unsent data, then it will be wiped out,
+ *   without further attempt to TX it.
+ * All packets that belong to that stream and remain in the device
+ * TX queue will be kept for further transmission.
+ * @param s
+ *   Pointer to the stream to close.
+ * @return
+ *   zero on successful completion.
+ *   - -EINVAL - invalid parameter passed to function
+ *   - -EDEADLK - close was already invoked on that stream
+ */
+int tle_tcp_stream_abort(struct tle_stream *s);
+
+
 /**
  * close a group of open streams.
  * if the stream is in connected state, then:
@@ -156,6 +230,17 @@ tle_tcp_stream_get_addr(const struct tle_stream *s,
  */
 int tle_tcp_stream_get_mss(const struct tle_stream *ts);
 
+/**
+ * Get current TCP stream state
+ * @param ts
+ *   Stream to retrieve state information from.
+ * @return
+ *   zero on successful completion.
+ *   - EINVAL - invalid parameter passed to function
+ */
+int tle_tcp_stream_get_state(const struct tle_stream *ts,
+       struct tle_tcp_stream_state *st);
+
 struct tle_stream *
 tle_tcp_stream_establish(struct tle_ctx *ctx,
        const struct tle_tcp_stream_param *prm,