blob: a6e4ad72d5d43f5344f8992a163ff853ece79c5e [file] [log] [blame]
Harald Welte1f0b8c22011-06-27 10:51:37 +02001#ifndef _OSMOCOM_LAPDM_H
2#define _OSMOCOM_LAPDM_H
3
Andreas Eversbergaa85a2d2013-02-07 12:18:37 +01004#include <osmocom/gsm/l1sap.h>
rootaf48bed2011-09-26 11:23:06 +02005#include <osmocom/gsm/lapd_core.h>
Harald Welte1f0b8c22011-06-27 10:51:37 +02006
Harald Welte6bdf0b12011-08-17 18:22:08 +02007/*! \defgroup lapdm LAPDm implementation according to GSM TS 04.06
8 * @{
9 */
10
11/*! \file lapdm.h */
12
Harald Welte6bdf0b12011-08-17 18:22:08 +020013/*! \brief LAPDm mode/role */
Harald Welte1f0b8c22011-06-27 10:51:37 +020014enum lapdm_mode {
Harald Welte6bdf0b12011-08-17 18:22:08 +020015 LAPDM_MODE_MS, /*!< \brief behave like a MS (mobile phone) */
16 LAPDM_MODE_BTS, /*!< \brief behave like a BTS (network) */
Harald Welte1f0b8c22011-06-27 10:51:37 +020017};
18
Harald Welte1f0b8c22011-06-27 10:51:37 +020019struct lapdm_entity;
20
Harald Welte6bdf0b12011-08-17 18:22:08 +020021/*! \brief LAPDm message context */
Harald Welte1f0b8c22011-06-27 10:51:37 +020022struct lapdm_msg_ctx {
23 struct lapdm_datalink *dl;
24 int lapdm_fmt;
Harald Welte1f0b8c22011-06-27 10:51:37 +020025 uint8_t chan_nr;
26 uint8_t link_id;
Andreas.Eversbergf1f80de2011-11-06 20:45:29 +010027 uint8_t ta_ind; /* TA indicated by network */
28 uint8_t tx_power_ind; /* MS power indicated by network */
Harald Welte1f0b8c22011-06-27 10:51:37 +020029};
30
Harald Welte6bdf0b12011-08-17 18:22:08 +020031/*! \brief LAPDm datalink like TS 04.06 / Section 3.5.2 */
Harald Welte1f0b8c22011-06-27 10:51:37 +020032struct lapdm_datalink {
rootaf48bed2011-09-26 11:23:06 +020033 struct lapd_datalink dl; /* \brief common LAPD */
Harald Welte6bdf0b12011-08-17 18:22:08 +020034 struct lapdm_msg_ctx mctx; /*!< \brief context of established connection */
Harald Welte1f0b8c22011-06-27 10:51:37 +020035
Harald Welte6bdf0b12011-08-17 18:22:08 +020036 struct lapdm_entity *entity; /*!< \brief LAPDm entity we are part of */
Harald Welte1f0b8c22011-06-27 10:51:37 +020037};
38
Harald Welte6bdf0b12011-08-17 18:22:08 +020039/*! \brief LAPDm datalink SAPIs */
Harald Welte1f0b8c22011-06-27 10:51:37 +020040enum lapdm_dl_sapi {
Harald Welte6bdf0b12011-08-17 18:22:08 +020041 DL_SAPI0 = 0, /*!< \brief SAPI 0 */
42 DL_SAPI3 = 1, /*!< \brief SAPI 1 */
Harald Welte1f0b8c22011-06-27 10:51:37 +020043 _NR_DL_SAPI
44};
45
46typedef int (*lapdm_cb_t)(struct msgb *msg, struct lapdm_entity *le, void *ctx);
47
Harald Welte1f0b8c22011-06-27 10:51:37 +020048#define LAPDM_ENT_F_EMPTY_FRAME 0x0001
49#define LAPDM_ENT_F_POLLING_ONLY 0x0002
50
Harald Welte6bdf0b12011-08-17 18:22:08 +020051/*! \brief a LAPDm Entity */
Harald Welte1f0b8c22011-06-27 10:51:37 +020052struct lapdm_entity {
Harald Welte6bdf0b12011-08-17 18:22:08 +020053 /*! \brief the SAPIs of the LAPDm entity */
Harald Welte1f0b8c22011-06-27 10:51:37 +020054 struct lapdm_datalink datalink[_NR_DL_SAPI];
Harald Welte6bdf0b12011-08-17 18:22:08 +020055 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 Welte1f0b8c22011-06-27 10:51:37 +020058 unsigned int flags;
59
Harald Welte6bdf0b12011-08-17 18:22:08 +020060 void *l1_ctx; /*!< \brief context for layer1 instance */
61 void *l3_ctx; /*!< \brief context for layer3 instance */
Harald Welte1f0b8c22011-06-27 10:51:37 +020062
Harald Welte6bdf0b12011-08-17 18:22:08 +020063 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 Welte1f0b8c22011-06-27 10:51:37 +020065
Harald Welte6bdf0b12011-08-17 18:22:08 +020066 /*! \brief pointer to \ref lapdm_channel of which we're part */
Harald Welte1f0b8c22011-06-27 10:51:37 +020067 struct lapdm_channel *lapdm_ch;
Andreas.Eversbergf1f80de2011-11-06 20:45:29 +010068
69 uint8_t ta; /* TA used and indicated to network */
70 uint8_t tx_power; /* MS power used and indicated to network */
Harald Welte1f0b8c22011-06-27 10:51:37 +020071};
72
Harald Welte6bdf0b12011-08-17 18:22:08 +020073/*! \brief the two lapdm_entities that form a GSM logical channel (ACCH + DCCH) */
Harald Welte1f0b8c22011-06-27 10:51:37 +020074struct lapdm_channel {
Harald Welte6bdf0b12011-08-17 18:22:08 +020075 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 Welte1f0b8c22011-06-27 10:51:37 +020079};
80
81const char *get_rsl_name(int value);
82extern const char *lapdm_state_names[];
83
84/* initialize a LAPDm entity */
Andreas.Eversberg5ac44782011-11-06 20:35:48 +010085void lapdm_entity_init(struct lapdm_entity *le, enum lapdm_mode mode, int t200);
Harald Welte1f0b8c22011-06-27 10:51:37 +020086void lapdm_channel_init(struct lapdm_channel *lc, enum lapdm_mode mode);
87
88/* deinitialize a LAPDm entity */
89void lapdm_entity_exit(struct lapdm_entity *le);
90void lapdm_channel_exit(struct lapdm_channel *lc);
91
92/* input into layer2 (from layer 1) */
93int lapdm_phsap_up(struct osmo_prim_hdr *oph, struct lapdm_entity *le);
94
95/* input into layer2 (from layer 3) */
96int lapdm_rslms_recvmsg(struct msgb *msg, struct lapdm_channel *lc);
97
98void lapdm_channel_set_l3(struct lapdm_channel *lc, lapdm_cb_t cb, void *ctx);
99void lapdm_channel_set_l1(struct lapdm_channel *lc, osmo_prim_cb cb, void *ctx);
100
101int lapdm_entity_set_mode(struct lapdm_entity *le, enum lapdm_mode mode);
102int lapdm_channel_set_mode(struct lapdm_channel *lc, enum lapdm_mode mode);
103
104void lapdm_entity_reset(struct lapdm_entity *le);
105void lapdm_channel_reset(struct lapdm_channel *lc);
106
107void lapdm_entity_set_flags(struct lapdm_entity *le, unsigned int flags);
108void lapdm_channel_set_flags(struct lapdm_channel *lc, unsigned int flags);
109
110int lapdm_phsap_dequeue_prim(struct lapdm_entity *le, struct osmo_phsap_prim *pp);
111
Sylvain Munautdca7d2c2012-04-18 21:53:23 +0200112/*! @} */
Harald Welte6bdf0b12011-08-17 18:22:08 +0200113
Harald Welte1f0b8c22011-06-27 10:51:37 +0200114#endif /* _OSMOCOM_LAPDM_H */