blob: 84d109d566b21fb30d2aea400b8546696f88f01b [file] [log] [blame]
Sylvain Munaut12ba7782014-06-16 10:13:40 +02001#pragma once
Harald Welte1f0b8c22011-06-27 10:51:37 +02002
Andreas Eversbergaa85a2d2013-02-07 12:18:37 +01003#include <osmocom/gsm/l1sap.h>
rootaf48bed2011-09-26 11:23:06 +02004#include <osmocom/gsm/lapd_core.h>
Harald Welte1f0b8c22011-06-27 10:51:37 +02005
Harald Welte6bdf0b12011-08-17 18:22:08 +02006/*! \defgroup lapdm LAPDm implementation according to GSM TS 04.06
7 * @{
8 */
9
10/*! \file lapdm.h */
11
Harald Welte6bdf0b12011-08-17 18:22:08 +020012/*! \brief LAPDm mode/role */
Harald Welte1f0b8c22011-06-27 10:51:37 +020013enum lapdm_mode {
Harald Welte6bdf0b12011-08-17 18:22:08 +020014 LAPDM_MODE_MS, /*!< \brief behave like a MS (mobile phone) */
15 LAPDM_MODE_BTS, /*!< \brief behave like a BTS (network) */
Harald Welte1f0b8c22011-06-27 10:51:37 +020016};
17
Harald Welte1f0b8c22011-06-27 10:51:37 +020018struct lapdm_entity;
19
Harald Welte6bdf0b12011-08-17 18:22:08 +020020/*! \brief LAPDm message context */
Harald Welte1f0b8c22011-06-27 10:51:37 +020021struct lapdm_msg_ctx {
22 struct lapdm_datalink *dl;
23 int lapdm_fmt;
Harald Welte1f0b8c22011-06-27 10:51:37 +020024 uint8_t chan_nr;
25 uint8_t link_id;
Andreas.Eversbergf1f80de2011-11-06 20:45:29 +010026 uint8_t ta_ind; /* TA indicated by network */
27 uint8_t tx_power_ind; /* MS power indicated by network */
Harald Welte1f0b8c22011-06-27 10:51:37 +020028};
29
Harald Welte6bdf0b12011-08-17 18:22:08 +020030/*! \brief LAPDm datalink like TS 04.06 / Section 3.5.2 */
Harald Welte1f0b8c22011-06-27 10:51:37 +020031struct lapdm_datalink {
rootaf48bed2011-09-26 11:23:06 +020032 struct lapd_datalink dl; /* \brief common LAPD */
Harald Welte6bdf0b12011-08-17 18:22:08 +020033 struct lapdm_msg_ctx mctx; /*!< \brief context of established connection */
Harald Welte1f0b8c22011-06-27 10:51:37 +020034
Harald Welte6bdf0b12011-08-17 18:22:08 +020035 struct lapdm_entity *entity; /*!< \brief LAPDm entity we are part of */
Harald Welte1f0b8c22011-06-27 10:51:37 +020036};
37
Harald Welte6bdf0b12011-08-17 18:22:08 +020038/*! \brief LAPDm datalink SAPIs */
Harald Welte1f0b8c22011-06-27 10:51:37 +020039enum lapdm_dl_sapi {
Harald Welte6bdf0b12011-08-17 18:22:08 +020040 DL_SAPI0 = 0, /*!< \brief SAPI 0 */
41 DL_SAPI3 = 1, /*!< \brief SAPI 1 */
Harald Welte1f0b8c22011-06-27 10:51:37 +020042 _NR_DL_SAPI
43};
44
45typedef int (*lapdm_cb_t)(struct msgb *msg, struct lapdm_entity *le, void *ctx);
46
Harald Welte1f0b8c22011-06-27 10:51:37 +020047#define LAPDM_ENT_F_EMPTY_FRAME 0x0001
48#define LAPDM_ENT_F_POLLING_ONLY 0x0002
49
Harald Welte6bdf0b12011-08-17 18:22:08 +020050/*! \brief a LAPDm Entity */
Harald Welte1f0b8c22011-06-27 10:51:37 +020051struct lapdm_entity {
Harald Welte6bdf0b12011-08-17 18:22:08 +020052 /*! \brief the SAPIs of the LAPDm entity */
Harald Welte1f0b8c22011-06-27 10:51:37 +020053 struct lapdm_datalink datalink[_NR_DL_SAPI];
Harald Welte6bdf0b12011-08-17 18:22:08 +020054 int last_tx_dequeue; /*!< \brief last entity that was dequeued */
55 int tx_pending; /*!< \brief currently a pending frame not confirmed by L1 */
56 enum lapdm_mode mode; /*!< \brief are we in BTS mode or MS mode */
Harald Welte1f0b8c22011-06-27 10:51:37 +020057 unsigned int flags;
58
Harald Welte6bdf0b12011-08-17 18:22:08 +020059 void *l1_ctx; /*!< \brief context for layer1 instance */
60 void *l3_ctx; /*!< \brief context for layer3 instance */
Harald Welte1f0b8c22011-06-27 10:51:37 +020061
Harald Welte6bdf0b12011-08-17 18:22:08 +020062 osmo_prim_cb l1_prim_cb;/*!< \brief callback for sending prims to L1 */
63 lapdm_cb_t l3_cb; /*!< \brief callback for sending stuff to L3 */
Harald Welte1f0b8c22011-06-27 10:51:37 +020064
Harald Welte6bdf0b12011-08-17 18:22:08 +020065 /*! \brief pointer to \ref lapdm_channel of which we're part */
Harald Welte1f0b8c22011-06-27 10:51:37 +020066 struct lapdm_channel *lapdm_ch;
Andreas.Eversbergf1f80de2011-11-06 20:45:29 +010067
68 uint8_t ta; /* TA used and indicated to network */
69 uint8_t tx_power; /* MS power used and indicated to network */
Harald Welte1f0b8c22011-06-27 10:51:37 +020070};
71
Harald Welte6bdf0b12011-08-17 18:22:08 +020072/*! \brief the two lapdm_entities that form a GSM logical channel (ACCH + DCCH) */
Harald Welte1f0b8c22011-06-27 10:51:37 +020073struct lapdm_channel {
Harald Welte6bdf0b12011-08-17 18:22:08 +020074 struct llist_head list; /*!< \brief internal linked list */
75 char *name; /*!< \brief human-readable name */
76 struct lapdm_entity lapdm_acch; /*!< \brief Associated Control Channel */
77 struct lapdm_entity lapdm_dcch; /*!< \brief Dedicated Control Channel */
Harald Welte1f0b8c22011-06-27 10:51:37 +020078};
79
80const char *get_rsl_name(int value);
81extern const char *lapdm_state_names[];
82
Daniel Willmann55405fb2014-03-26 13:45:17 +010083struct lapdm_datalink *lapdm_datalink_for_sapi(struct lapdm_entity *le, uint8_t sapi);
84
Harald Welte1f0b8c22011-06-27 10:51:37 +020085/* initialize a LAPDm entity */
Andreas.Eversberg5ac44782011-11-06 20:35:48 +010086void lapdm_entity_init(struct lapdm_entity *le, enum lapdm_mode mode, int t200);
Harald Welte1f0b8c22011-06-27 10:51:37 +020087void lapdm_channel_init(struct lapdm_channel *lc, enum lapdm_mode mode);
88
89/* deinitialize a LAPDm entity */
90void lapdm_entity_exit(struct lapdm_entity *le);
91void lapdm_channel_exit(struct lapdm_channel *lc);
92
93/* input into layer2 (from layer 1) */
94int lapdm_phsap_up(struct osmo_prim_hdr *oph, struct lapdm_entity *le);
95
96/* input into layer2 (from layer 3) */
97int lapdm_rslms_recvmsg(struct msgb *msg, struct lapdm_channel *lc);
98
99void lapdm_channel_set_l3(struct lapdm_channel *lc, lapdm_cb_t cb, void *ctx);
100void lapdm_channel_set_l1(struct lapdm_channel *lc, osmo_prim_cb cb, void *ctx);
101
102int lapdm_entity_set_mode(struct lapdm_entity *le, enum lapdm_mode mode);
103int lapdm_channel_set_mode(struct lapdm_channel *lc, enum lapdm_mode mode);
104
105void lapdm_entity_reset(struct lapdm_entity *le);
106void lapdm_channel_reset(struct lapdm_channel *lc);
107
108void lapdm_entity_set_flags(struct lapdm_entity *le, unsigned int flags);
109void lapdm_channel_set_flags(struct lapdm_channel *lc, unsigned int flags);
110
111int lapdm_phsap_dequeue_prim(struct lapdm_entity *le, struct osmo_phsap_prim *pp);
112
Sylvain Munautdca7d2c2012-04-18 21:53:23 +0200113/*! @} */