Sylvain Munaut | 12ba778 | 2014-06-16 10:13:40 +0200 | [diff] [blame] | 1 | #pragma once |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 2 | |
Andreas Eversberg | aa85a2d | 2013-02-07 12:18:37 +0100 | [diff] [blame] | 3 | #include <osmocom/gsm/l1sap.h> |
Harald Welte | 20de620 | 2019-06-02 21:33:38 +0200 | [diff] [blame] | 4 | #include <osmocom/gsm/gsm_utils.h> |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 5 | #include <osmocom/gsm/lapd_core.h> |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 6 | |
Harald Welte | 6bdf0b1 | 2011-08-17 18:22:08 +0200 | [diff] [blame] | 7 | /*! \defgroup lapdm LAPDm implementation according to GSM TS 04.06 |
| 8 | * @{ |
Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 9 | * \file lapdm.h */ |
Harald Welte | 6bdf0b1 | 2011-08-17 18:22:08 +0200 | [diff] [blame] | 10 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 11 | /*! LAPDm mode/role */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 12 | enum lapdm_mode { |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 13 | LAPDM_MODE_MS, /*!< behave like a MS (mobile phone) */ |
| 14 | LAPDM_MODE_BTS, /*!< behave like a BTS (network) */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 15 | }; |
| 16 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 17 | struct lapdm_entity; |
| 18 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 19 | /*! LAPDm message context */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 20 | struct lapdm_msg_ctx { |
| 21 | struct lapdm_datalink *dl; |
| 22 | int lapdm_fmt; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 23 | uint8_t chan_nr; |
| 24 | uint8_t link_id; |
Andreas.Eversberg | f1f80de | 2011-11-06 20:45:29 +0100 | [diff] [blame] | 25 | uint8_t ta_ind; /* TA indicated by network */ |
| 26 | uint8_t tx_power_ind; /* MS power indicated by network */ |
Pau Espin Pedrol | 1247aa1 | 2023-08-09 17:41:25 +0200 | [diff] [blame] | 27 | uint32_t fn; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 28 | }; |
| 29 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 30 | /*! LAPDm datalink like TS 04.06 / Section 3.5.2 */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 31 | struct lapdm_datalink { |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 32 | struct lapd_datalink dl; /* common LAPD */ |
| 33 | struct lapdm_msg_ctx mctx; /*!< context of established connection */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 34 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 35 | struct lapdm_entity *entity; /*!< LAPDm entity we are part of */ |
Andreas Eversberg | 2d7119d | 2023-11-09 13:06:19 +0100 | [diff] [blame] | 36 | |
Andreas Eversberg | f51f916 | 2023-11-09 13:19:34 +0100 | [diff] [blame] | 37 | struct llist_head tx_ui_queue; /*!< UI frames to L1 */ |
Andreas Eversberg | 2d7119d | 2023-11-09 13:06:19 +0100 | [diff] [blame] | 38 | uint32_t t200_fn; /*!< T200 timer in frames */ |
| 39 | uint32_t t200_timeout; /*!< T200 timeout frame number */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 40 | }; |
| 41 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 42 | /*! LAPDm datalink SAPIs */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 43 | enum lapdm_dl_sapi { |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 44 | DL_SAPI0 = 0, /*!< SAPI 0 */ |
| 45 | DL_SAPI3 = 1, /*!< SAPI 1 */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 46 | _NR_DL_SAPI |
| 47 | }; |
| 48 | |
| 49 | typedef int (*lapdm_cb_t)(struct msgb *msg, struct lapdm_entity *le, void *ctx); |
| 50 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 51 | #define LAPDM_ENT_F_EMPTY_FRAME 0x0001 |
| 52 | #define LAPDM_ENT_F_POLLING_ONLY 0x0002 |
Andreas Eversberg | bd2b897 | 2023-11-15 14:33:53 +0100 | [diff] [blame] | 53 | #define LAPDM_ENT_F_DROP_2ND_REJ 0x0004 |
Andreas Eversberg | 285f369 | 2023-11-29 12:03:00 +0100 | [diff] [blame] | 54 | #define LAPDM_ENT_F_RTS 0x0008 |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 55 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 56 | /*! a LAPDm Entity */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 57 | struct lapdm_entity { |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 58 | /*! the SAPIs of the LAPDm entity */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 59 | struct lapdm_datalink datalink[_NR_DL_SAPI]; |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 60 | int last_tx_dequeue; /*!< last entity that was dequeued */ |
| 61 | int tx_pending; /*!< currently a pending frame not confirmed by L1 */ |
| 62 | enum lapdm_mode mode; /*!< are we in BTS mode or MS mode */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 63 | unsigned int flags; |
| 64 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 65 | void *l1_ctx; /*!< context for layer1 instance */ |
| 66 | void *l3_ctx; /*!< context for layer3 instance */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 67 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 68 | osmo_prim_cb l1_prim_cb;/*!< callback for sending prims to L1 */ |
| 69 | lapdm_cb_t l3_cb; /*!< callback for sending stuff to L3 */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 70 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 71 | /*! pointer to \ref lapdm_channel of which we're part */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 72 | struct lapdm_channel *lapdm_ch; |
Andreas.Eversberg | f1f80de | 2011-11-06 20:45:29 +0100 | [diff] [blame] | 73 | |
| 74 | uint8_t ta; /* TA used and indicated to network */ |
| 75 | uint8_t tx_power; /* MS power used and indicated to network */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 76 | }; |
| 77 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 78 | /*! the two lapdm_entities that form a GSM logical channel (ACCH + DCCH) */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 79 | struct lapdm_channel { |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 80 | struct llist_head list; /*!< internal linked list */ |
| 81 | char *name; /*!< human-readable name */ |
| 82 | struct lapdm_entity lapdm_acch; /*!< Associated Control Channel */ |
| 83 | struct lapdm_entity lapdm_dcch; /*!< Dedicated Control Channel */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | const char *get_rsl_name(int value); |
| 87 | extern const char *lapdm_state_names[]; |
| 88 | |
Daniel Willmann | 55405fb | 2014-03-26 13:45:17 +0100 | [diff] [blame] | 89 | struct lapdm_datalink *lapdm_datalink_for_sapi(struct lapdm_entity *le, uint8_t sapi); |
| 90 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 91 | /* initialize a LAPDm entity */ |
Harald Welte | 20de620 | 2019-06-02 21:33:38 +0200 | [diff] [blame] | 92 | void lapdm_entity_init(struct lapdm_entity *le, enum lapdm_mode mode, int t200) |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 93 | OSMO_DEPRECATED("Use lapdm_entity_init3() instead"); |
Harald Welte | 20de620 | 2019-06-02 21:33:38 +0200 | [diff] [blame] | 94 | void lapdm_entity_init2(struct lapdm_entity *le, enum lapdm_mode mode, |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 95 | const int *t200_ms, int n200) |
| 96 | OSMO_DEPRECATED("Use lapdm_entity_init3() instead"); |
| 97 | void lapdm_entity_init3(struct lapdm_entity *le, enum lapdm_mode mode, |
| 98 | const int *t200_ms, int n200, const char *name_pfx); |
Harald Welte | 20de620 | 2019-06-02 21:33:38 +0200 | [diff] [blame] | 99 | void lapdm_channel_init(struct lapdm_channel *lc, enum lapdm_mode mode) |
Neels Hofmeyr | 137efc9 | 2021-09-29 15:22:28 +0200 | [diff] [blame] | 100 | OSMO_DEPRECATED_OUTSIDE("Use lapdm_channel_init3() instead"); |
Harald Welte | 20de620 | 2019-06-02 21:33:38 +0200 | [diff] [blame] | 101 | int lapdm_channel_init2(struct lapdm_channel *lc, enum lapdm_mode mode, |
| 102 | const int *t200_ms_dcch, const int *t200_ms_acch, enum gsm_chan_t chan_t); |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 103 | int lapdm_channel_init3(struct lapdm_channel *lc, enum lapdm_mode mode, |
| 104 | const int *t200_ms_dcch, const int *t200_ms_acch, enum gsm_chan_t chan_t, |
| 105 | const char *name_pfx); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 106 | /* deinitialize a LAPDm entity */ |
| 107 | void lapdm_entity_exit(struct lapdm_entity *le); |
| 108 | void lapdm_channel_exit(struct lapdm_channel *lc); |
| 109 | |
| 110 | /* input into layer2 (from layer 1) */ |
| 111 | int lapdm_phsap_up(struct osmo_prim_hdr *oph, struct lapdm_entity *le); |
| 112 | |
| 113 | /* input into layer2 (from layer 3) */ |
| 114 | int lapdm_rslms_recvmsg(struct msgb *msg, struct lapdm_channel *lc); |
| 115 | |
| 116 | void lapdm_channel_set_l3(struct lapdm_channel *lc, lapdm_cb_t cb, void *ctx); |
| 117 | void lapdm_channel_set_l1(struct lapdm_channel *lc, osmo_prim_cb cb, void *ctx); |
| 118 | |
| 119 | int lapdm_entity_set_mode(struct lapdm_entity *le, enum lapdm_mode mode); |
| 120 | int lapdm_channel_set_mode(struct lapdm_channel *lc, enum lapdm_mode mode); |
| 121 | |
| 122 | void lapdm_entity_reset(struct lapdm_entity *le); |
| 123 | void lapdm_channel_reset(struct lapdm_channel *lc); |
| 124 | |
| 125 | void lapdm_entity_set_flags(struct lapdm_entity *le, unsigned int flags); |
| 126 | void lapdm_channel_set_flags(struct lapdm_channel *lc, unsigned int flags); |
| 127 | |
Andreas Eversberg | 2d7119d | 2023-11-09 13:06:19 +0100 | [diff] [blame] | 128 | void lapdm_entity_set_t200_fn(struct lapdm_entity *le, const uint32_t *t200_fn); |
| 129 | void lapdm_channel_set_t200_fn(struct lapdm_channel *lc, const uint32_t *t200_fn_dcch, const uint32_t *t200_fn_acch); |
| 130 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 131 | int lapdm_phsap_dequeue_prim(struct lapdm_entity *le, struct osmo_phsap_prim *pp); |
Andreas Eversberg | 2d7119d | 2023-11-09 13:06:19 +0100 | [diff] [blame] | 132 | int lapdm_phsap_dequeue_prim_fn(struct lapdm_entity *le, struct osmo_phsap_prim *pp, uint32_t fn); |
| 133 | void lapdm_t200_fn(struct lapdm_entity *le, uint32_t fn); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 134 | |
Sylvain Munaut | dca7d2c | 2012-04-18 21:53:23 +0200 | [diff] [blame] | 135 | /*! @} */ |