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> |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 4 | #include <osmocom/gsm/lapd_core.h> |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 5 | |
Harald Welte | 6bdf0b1 | 2011-08-17 18:22:08 +0200 | [diff] [blame] | 6 | /*! \defgroup lapdm LAPDm implementation according to GSM TS 04.06 |
| 7 | * @{ |
Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 8 | * \file lapdm.h */ |
Harald Welte | 6bdf0b1 | 2011-08-17 18:22:08 +0200 | [diff] [blame] | 9 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 10 | /*! LAPDm mode/role */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 11 | enum lapdm_mode { |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 12 | LAPDM_MODE_MS, /*!< behave like a MS (mobile phone) */ |
| 13 | LAPDM_MODE_BTS, /*!< behave like a BTS (network) */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 14 | }; |
| 15 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 16 | struct lapdm_entity; |
| 17 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 18 | /*! LAPDm message context */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 19 | struct lapdm_msg_ctx { |
| 20 | struct lapdm_datalink *dl; |
| 21 | int lapdm_fmt; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 22 | uint8_t chan_nr; |
| 23 | uint8_t link_id; |
Andreas.Eversberg | f1f80de | 2011-11-06 20:45:29 +0100 | [diff] [blame] | 24 | uint8_t ta_ind; /* TA indicated by network */ |
| 25 | uint8_t tx_power_ind; /* MS power indicated by network */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 26 | }; |
| 27 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 28 | /*! LAPDm datalink like TS 04.06 / Section 3.5.2 */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 29 | struct lapdm_datalink { |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 30 | struct lapd_datalink dl; /* common LAPD */ |
| 31 | struct lapdm_msg_ctx mctx; /*!< context of established connection */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 32 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 33 | struct lapdm_entity *entity; /*!< LAPDm entity we are part of */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 34 | }; |
| 35 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 36 | /*! LAPDm datalink SAPIs */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 37 | enum lapdm_dl_sapi { |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 38 | DL_SAPI0 = 0, /*!< SAPI 0 */ |
| 39 | DL_SAPI3 = 1, /*!< SAPI 1 */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 40 | _NR_DL_SAPI |
| 41 | }; |
| 42 | |
| 43 | typedef int (*lapdm_cb_t)(struct msgb *msg, struct lapdm_entity *le, void *ctx); |
| 44 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 45 | #define LAPDM_ENT_F_EMPTY_FRAME 0x0001 |
| 46 | #define LAPDM_ENT_F_POLLING_ONLY 0x0002 |
| 47 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 48 | /*! a LAPDm Entity */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 49 | struct lapdm_entity { |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 50 | /*! the SAPIs of the LAPDm entity */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 51 | struct lapdm_datalink datalink[_NR_DL_SAPI]; |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 52 | int last_tx_dequeue; /*!< last entity that was dequeued */ |
| 53 | int tx_pending; /*!< currently a pending frame not confirmed by L1 */ |
| 54 | enum lapdm_mode mode; /*!< are we in BTS mode or MS mode */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 55 | unsigned int flags; |
| 56 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 57 | void *l1_ctx; /*!< context for layer1 instance */ |
| 58 | void *l3_ctx; /*!< context for layer3 instance */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 59 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 60 | osmo_prim_cb l1_prim_cb;/*!< callback for sending prims to L1 */ |
| 61 | lapdm_cb_t l3_cb; /*!< callback for sending stuff to L3 */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 62 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 63 | /*! pointer to \ref lapdm_channel of which we're part */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 64 | struct lapdm_channel *lapdm_ch; |
Andreas.Eversberg | f1f80de | 2011-11-06 20:45:29 +0100 | [diff] [blame] | 65 | |
| 66 | uint8_t ta; /* TA used and indicated to network */ |
| 67 | uint8_t tx_power; /* MS power used and indicated to network */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 68 | }; |
| 69 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 70 | /*! the two lapdm_entities that form a GSM logical channel (ACCH + DCCH) */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 71 | struct lapdm_channel { |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 72 | struct llist_head list; /*!< internal linked list */ |
| 73 | char *name; /*!< human-readable name */ |
| 74 | struct lapdm_entity lapdm_acch; /*!< Associated Control Channel */ |
| 75 | struct lapdm_entity lapdm_dcch; /*!< Dedicated Control Channel */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | const char *get_rsl_name(int value); |
| 79 | extern const char *lapdm_state_names[]; |
| 80 | |
Daniel Willmann | 55405fb | 2014-03-26 13:45:17 +0100 | [diff] [blame] | 81 | struct lapdm_datalink *lapdm_datalink_for_sapi(struct lapdm_entity *le, uint8_t sapi); |
| 82 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 83 | /* initialize a LAPDm entity */ |
Andreas.Eversberg | 5ac4478 | 2011-11-06 20:35:48 +0100 | [diff] [blame] | 84 | void lapdm_entity_init(struct lapdm_entity *le, enum lapdm_mode mode, int t200); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 85 | void lapdm_channel_init(struct lapdm_channel *lc, enum lapdm_mode mode); |
| 86 | |
| 87 | /* deinitialize a LAPDm entity */ |
| 88 | void lapdm_entity_exit(struct lapdm_entity *le); |
| 89 | void lapdm_channel_exit(struct lapdm_channel *lc); |
| 90 | |
| 91 | /* input into layer2 (from layer 1) */ |
| 92 | int lapdm_phsap_up(struct osmo_prim_hdr *oph, struct lapdm_entity *le); |
| 93 | |
| 94 | /* input into layer2 (from layer 3) */ |
| 95 | int lapdm_rslms_recvmsg(struct msgb *msg, struct lapdm_channel *lc); |
| 96 | |
| 97 | void lapdm_channel_set_l3(struct lapdm_channel *lc, lapdm_cb_t cb, void *ctx); |
| 98 | void lapdm_channel_set_l1(struct lapdm_channel *lc, osmo_prim_cb cb, void *ctx); |
| 99 | |
| 100 | int lapdm_entity_set_mode(struct lapdm_entity *le, enum lapdm_mode mode); |
| 101 | int lapdm_channel_set_mode(struct lapdm_channel *lc, enum lapdm_mode mode); |
| 102 | |
| 103 | void lapdm_entity_reset(struct lapdm_entity *le); |
| 104 | void lapdm_channel_reset(struct lapdm_channel *lc); |
| 105 | |
| 106 | void lapdm_entity_set_flags(struct lapdm_entity *le, unsigned int flags); |
| 107 | void lapdm_channel_set_flags(struct lapdm_channel *lc, unsigned int flags); |
| 108 | |
| 109 | int lapdm_phsap_dequeue_prim(struct lapdm_entity *le, struct osmo_phsap_prim *pp); |
| 110 | |
Sylvain Munaut | dca7d2c | 2012-04-18 21:53:23 +0200 | [diff] [blame] | 111 | /*! @} */ |