1 #ifndef _OSMOCOM_LAPDM_H
2 #define _OSMOCOM_LAPDM_H
6 #include <osmocom/core/timer.h>
7 #include <osmocom/core/msgb.h>
8 #include <osmocom/gsm/prim.h>
10 /* primitive related sutff */
13 PRIM_PH_DATA, /* PH-DATA */
14 PRIM_PH_RACH, /* PH-RANDOM_ACCESS */
15 PRIM_PH_CONN, /* PH-CONNECT */
16 PRIM_PH_EMPTY_FRAME, /* PH-EMPTY_FRAME */
17 PRIM_PH_RTS, /* PH-RTS */
20 /* for PH-RANDOM_ACCESS.req */
21 struct ph_rach_req_param {
25 uint8_t is_combined_ccch;
29 /* for PH-RANDOM_ACCESS.ind */
30 struct ph_rach_ind_param {
36 /* for PH-[UNIT]DATA.{req,ind} */
37 struct ph_data_param {
42 struct ph_conn_ind_param {
46 struct osmo_phsap_prim {
47 struct osmo_prim_hdr oph;
49 struct ph_data_param data;
50 struct ph_rach_req_param rach_req;
51 struct ph_rach_ind_param rach_ind;
52 struct ph_conn_ind_param conn_ind;
64 LAPDm_STATE_SABM_SENT,
66 LAPDm_STATE_TIMER_RECOV,
67 LAPDm_STATE_DISC_SENT,
72 struct lapdm_msg_ctx {
73 struct lapdm_datalink *dl;
84 /* TS 04.06 / Section 3.5.2 */
85 struct lapdm_datalink {
86 uint8_t V_send; /* seq nr of next I frame to be transmitted */
87 uint8_t V_ack; /* last frame ACKed by peer */
88 uint8_t N_send; /* ? set to V_send at Tx time*/
89 uint8_t V_recv; /* seq nr of next I frame expected to be received */
90 uint8_t N_recv; /* expected send seq nr of the next received I frame */
92 int seq_err_cond; /* condition of sequence error */
93 uint8_t own_busy, peer_busy;
94 struct osmo_timer_list t200;
96 struct llist_head send_queue; /* frames from L3 */
97 struct msgb *send_buffer; /* current frame transmitting */
98 int send_out; /* how much was sent from send_buffer */
99 uint8_t tx_hist[8][200]; /* tx history buffer */
100 int tx_length[8]; /* length in history buffer */
101 struct llist_head tx_queue; /* frames to L1 */
102 struct lapdm_msg_ctx mctx; /* context of established connection */
103 struct msgb *rcv_buffer; /* buffer to assemble the received message */
105 struct lapdm_entity *entity;
114 typedef int (*lapdm_cb_t)(struct msgb *msg, struct lapdm_entity *le, void *ctx);
116 struct lapdm_cr_ent {
121 #define LAPDM_ENT_F_EMPTY_FRAME 0x0001
122 #define LAPDM_ENT_F_POLLING_ONLY 0x0002
124 /* register message handler for messages that are sent from L2->L3 */
125 struct lapdm_entity {
126 struct lapdm_datalink datalink[_NR_DL_SAPI];
127 int last_tx_dequeue; /* last entity that was dequeued */
128 int tx_pending; /* currently a pending frame not confirmed by L1 */
129 enum lapdm_mode mode; /* are we in BTS mode or MS mode */
133 /* filled-in once we set the lapdm_mode above */
134 struct lapdm_cr_ent loc2rem;
135 struct lapdm_cr_ent rem2loc;
138 void *l1_ctx; /* context for layer1 instance */
139 void *l3_ctx; /* context for layer3 instance */
141 osmo_prim_cb l1_prim_cb;
142 lapdm_cb_t l3_cb; /* callback for sending stuff to L3 */
144 struct lapdm_channel *lapdm_ch;
147 /* the two lapdm_entities that form a GSM logical channel (ACCH + DCCH) */
148 struct lapdm_channel {
149 struct llist_head list;
151 struct lapdm_entity lapdm_acch;
152 struct lapdm_entity lapdm_dcch;
155 const char *get_rsl_name(int value);
156 extern const char *lapdm_state_names[];
158 /* initialize a LAPDm entity */
159 void lapdm_entity_init(struct lapdm_entity *le, enum lapdm_mode mode);
160 void lapdm_channel_init(struct lapdm_channel *lc, enum lapdm_mode mode);
162 /* deinitialize a LAPDm entity */
163 void lapdm_entity_exit(struct lapdm_entity *le);
164 void lapdm_channel_exit(struct lapdm_channel *lc);
166 /* input into layer2 (from layer 1) */
167 int lapdm_phsap_up(struct osmo_prim_hdr *oph, struct lapdm_entity *le);
169 /* input into layer2 (from layer 3) */
170 int lapdm_rslms_recvmsg(struct msgb *msg, struct lapdm_channel *lc);
172 void lapdm_channel_set_l3(struct lapdm_channel *lc, lapdm_cb_t cb, void *ctx);
173 void lapdm_channel_set_l1(struct lapdm_channel *lc, osmo_prim_cb cb, void *ctx);
175 int lapdm_entity_set_mode(struct lapdm_entity *le, enum lapdm_mode mode);
176 int lapdm_channel_set_mode(struct lapdm_channel *lc, enum lapdm_mode mode);
178 void lapdm_entity_reset(struct lapdm_entity *le);
179 void lapdm_channel_reset(struct lapdm_channel *lc);
181 void lapdm_entity_set_flags(struct lapdm_entity *le, unsigned int flags);
182 void lapdm_channel_set_flags(struct lapdm_channel *lc, unsigned int flags);
184 int lapdm_phsap_dequeue_prim(struct lapdm_entity *le, struct osmo_phsap_prim *pp);
186 #endif /* _OSMOCOM_LAPDM_H */