Vadim Yanitskiy | 85554db | 2023-03-14 20:33:51 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <stdint.h> |
| 4 | #include <stdbool.h> |
| 5 | |
| 6 | #include <osmocom/core/utils.h> |
| 7 | #include <osmocom/core/bits.h> |
| 8 | #include <osmocom/isdn/v110.h> |
| 9 | |
| 10 | /* Definition of this struct is [intentionally] kept private */ |
| 11 | struct osmo_v110_ta; |
| 12 | |
| 13 | /*! V.110 5.4.1 Local flow control (DTE-DCE or TE-TA) mode */ |
| 14 | enum osmo_v110_local_flow_ctrl_mode { |
| 15 | OSMO_V110_LOCAL_FLOW_CTRL_NONE, /*!< No local flow control */ |
| 16 | OSMO_V110_LOCAL_FLOW_CTRL_133_106, /*!< 5.4.1.1 133/106 operation */ |
| 17 | OSMO_V110_LOCAL_FLOW_CTRL_105_106, /*!< 5.4.1.2 105/106 operation */ |
| 18 | OSMO_V110_LOCAL_FLOW_CTRL_XON_XOFF, /*!< 5.4.1.3 XON/XOFF operation */ |
| 19 | }; |
| 20 | |
| 21 | /*! Configuration for a V.110 TA instance */ |
| 22 | struct osmo_v110_ta_cfg { |
| 23 | /*! Configuration flags (behavior switches and quirks) */ |
| 24 | unsigned int flags; |
| 25 | /*! Synchronous user rate */ |
| 26 | enum osmo_v100_sync_ra1_rate rate; |
| 27 | |
| 28 | /*! Flow control configuration */ |
| 29 | struct { |
| 30 | /*! Local TA-TE (DTE-DCE) flow control mode */ |
| 31 | enum osmo_v110_local_flow_ctrl_mode local; |
| 32 | /*! End-to-end (TA-to-TA) flow control state */ |
| 33 | bool end_to_end; |
| 34 | } flow_ctrl; |
| 35 | |
| 36 | /*! Opaque application-private data; passed to call-backs. */ |
| 37 | void *priv; |
| 38 | |
| 39 | /*! Receive call-back of the application. |
| 40 | * \param[in] priv opaque application-private data. |
| 41 | * \param[in] buf output buffer for writing to be transmitted data. |
| 42 | * \param[in] buf_size size of the output buffer. */ |
| 43 | void (*rx_cb)(void *priv, const ubit_t *buf, size_t buf_size); |
| 44 | |
| 45 | /*! Transmit call-back of the application. |
| 46 | * \param[in] priv opaque application-private data. |
| 47 | * \param[out] buf output buffer for writing to be transmitted data. |
| 48 | * \param[in] buf_size size of the output buffer. */ |
| 49 | void (*tx_cb)(void *priv, ubit_t *buf, size_t buf_size); |
| 50 | |
| 51 | /*! Modem status line update call-back (optional). |
| 52 | * \param[in] priv opaque application-private data. |
| 53 | * \param[in] status updated status; bit-mask of OSMO_V110_TA_C_*. */ |
| 54 | void (*status_update_cb)(void *priv, unsigned int status); |
| 55 | }; |
| 56 | |
| 57 | struct osmo_v110_ta *osmo_v110_ta_alloc(void *ctx, const char *name, |
| 58 | const struct osmo_v110_ta_cfg *cfg); |
| 59 | void osmo_v110_ta_free(struct osmo_v110_ta *ta); |
| 60 | |
| 61 | /*! Various timers for a V.110 TA instance */ |
| 62 | enum osmo_v110_ta_timer { |
| 63 | /*! 7.1.5 Loss of frame synchronization: sync recovery timer. |
| 64 | * T-number is not assigned in V.110, so we call it X1. */ |
| 65 | OSMO_V110_TA_TIMER_X1 = -1, |
| 66 | /*! 7.1.2 Connect TA to line: sync establishment timer */ |
| 67 | OSMO_V110_TA_TIMER_T1 = 1, |
| 68 | /*! 7.1.4 Disconnect mode: disconnect confirmation timer */ |
| 69 | OSMO_V110_TA_TIMER_T2 = 2, |
| 70 | }; |
| 71 | |
| 72 | int osmo_v110_ta_set_timer_val_ms(struct osmo_v110_ta *ta, |
| 73 | enum osmo_v110_ta_timer timer, |
| 74 | unsigned long val_ms); |
| 75 | |
| 76 | int osmo_v110_ta_frame_in(struct osmo_v110_ta *ta, const struct osmo_v110_decoded_frame *in); |
| 77 | int osmo_v110_ta_frame_out(struct osmo_v110_ta *ta, struct osmo_v110_decoded_frame *out); |
| 78 | |
| 79 | int osmo_v110_ta_sync_ind(struct osmo_v110_ta *ta); |
| 80 | int osmo_v110_ta_desync_ind(struct osmo_v110_ta *ta); |
| 81 | |
| 82 | /*! ITU-T Table 9 "Interchange circuit" (see also ITU-T V.24 Chapter 3). |
| 83 | * XXX: Not all circuits are present here, only those which we actually use. |
| 84 | * TODO: add human-friendly abbreviated circuit names. */ |
| 85 | enum osmo_v110_ta_circuit { |
| 86 | OSMO_V110_TA_C_105, /*!< DTE->DCE | RTS (Request to Send) */ |
| 87 | OSMO_V110_TA_C_106, /*!< DTE<-DCE | CTS (Clear to Send) */ |
| 88 | OSMO_V110_TA_C_107, /*!< DTE<-DCE | DSR (Data Set Ready) */ |
| 89 | OSMO_V110_TA_C_108, /*!< DTE->DCE | DTR (Data Terminal Ready) */ |
| 90 | OSMO_V110_TA_C_109, /*!< DTE<-DCE | DCD (Data Carrier Detect) */ |
| 91 | OSMO_V110_TA_C_133, /*!< DTE->DCE | Ready for receiving */ |
| 92 | }; |
| 93 | |
| 94 | extern const struct value_string osmo_v110_ta_circuit_names[]; |
| 95 | extern const struct value_string osmo_v110_ta_circuit_descs[]; |
| 96 | |
| 97 | /*! Get a short name of the given TA's circuit (format: NNN[/ABBR]). */ |
| 98 | static inline const char *osmo_v110_ta_circuit_name(enum osmo_v110_ta_circuit circuit) |
| 99 | { |
| 100 | return get_value_string(osmo_v110_ta_circuit_names, circuit); |
| 101 | } |
| 102 | |
| 103 | /*! Get a brief description of the given TA's circuit. */ |
| 104 | static inline const char *osmo_v110_ta_circuit_desc(enum osmo_v110_ta_circuit circuit) |
| 105 | { |
| 106 | return get_value_string(osmo_v110_ta_circuit_descs, circuit); |
| 107 | } |
| 108 | |
| 109 | unsigned int osmo_v110_ta_get_status(const struct osmo_v110_ta *ta); |
| 110 | bool osmo_v110_ta_get_circuit(const struct osmo_v110_ta *ta, |
| 111 | enum osmo_v110_ta_circuit circuit); |
| 112 | int osmo_v110_ta_set_circuit(struct osmo_v110_ta *ta, |
| 113 | enum osmo_v110_ta_circuit circuit, bool active); |