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