blob: 939340681db4e1becba1abc2cce8503a2fac0eb4 [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
Daniel Willmann55405fb2014-03-26 13:45:17 +010084struct lapdm_datalink *lapdm_datalink_for_sapi(struct lapdm_entity *le, uint8_t sapi);
85
Harald Welte1f0b8c22011-06-27 10:51:37 +020086/* initialize a LAPDm entity */
Andreas.Eversberg5ac44782011-11-06 20:35:48 +010087void lapdm_entity_init(struct lapdm_entity *le, enum lapdm_mode mode, int t200);
Harald Welte1f0b8c22011-06-27 10:51:37 +020088void lapdm_channel_init(struct lapdm_channel *lc, enum lapdm_mode mode);
89
90/* deinitialize a LAPDm entity */
91void lapdm_entity_exit(struct lapdm_entity *le);
92void lapdm_channel_exit(struct lapdm_channel *lc);
93
94/* input into layer2 (from layer 1) */
95int lapdm_phsap_up(struct osmo_prim_hdr *oph, struct lapdm_entity *le);
96
97/* input into layer2 (from layer 3) */
98int lapdm_rslms_recvmsg(struct msgb *msg, struct lapdm_channel *lc);
99
100void lapdm_channel_set_l3(struct lapdm_channel *lc, lapdm_cb_t cb, void *ctx);
101void lapdm_channel_set_l1(struct lapdm_channel *lc, osmo_prim_cb cb, void *ctx);
102
103int lapdm_entity_set_mode(struct lapdm_entity *le, enum lapdm_mode mode);
104int lapdm_channel_set_mode(struct lapdm_channel *lc, enum lapdm_mode mode);
105
106void lapdm_entity_reset(struct lapdm_entity *le);
107void lapdm_channel_reset(struct lapdm_channel *lc);
108
109void lapdm_entity_set_flags(struct lapdm_entity *le, unsigned int flags);
110void lapdm_channel_set_flags(struct lapdm_channel *lc, unsigned int flags);
111
112int lapdm_phsap_dequeue_prim(struct lapdm_entity *le, struct osmo_phsap_prim *pp);
113
Sylvain Munautdca7d2c2012-04-18 21:53:23 +0200114/*! @} */
Harald Welte6bdf0b12011-08-17 18:22:08 +0200115
Harald Welte1f0b8c22011-06-27 10:51:37 +0200116#endif /* _OSMOCOM_LAPDM_H */