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 {
35 /* for PH-[UNIT]DATA.{req,ind} */
36 struct ph_data_param {
41 struct ph_conn_ind_param {
45 struct osmo_phsap_prim {
46 struct osmo_prim_hdr oph;
48 struct ph_data_param data;
49 struct ph_rach_req_param rach_req;
50 struct ph_rach_ind_param rach_ind;
51 struct ph_conn_ind_param conn_ind;
58 LAPDm_STATE_SABM_SENT,
60 LAPDm_STATE_TIMER_RECOV,
61 LAPDm_STATE_DISC_SENT,
66 struct lapdm_msg_ctx {
67 struct lapdm_datalink *dl;
78 /* TS 04.06 / Section 3.5.2 */
79 struct lapdm_datalink {
80 uint8_t V_send; /* seq nr of next I frame to be transmitted */
81 uint8_t V_ack; /* last frame ACKed by peer */
82 uint8_t N_send; /* ? set to V_send at Tx time*/
83 uint8_t V_recv; /* seq nr of next I frame expected to be received */
84 uint8_t N_recv; /* expected send seq nr of the next received I frame */
86 int seq_err_cond; /* condition of sequence error */
87 uint8_t own_busy, peer_busy;
88 struct osmo_timer_list t200;
90 struct llist_head send_queue; /* frames from L3 */
91 struct msgb *send_buffer; /* current frame transmitting */
92 int send_out; /* how much was sent from send_buffer */
93 uint8_t tx_hist[8][200]; /* tx history buffer */
94 int tx_length[8]; /* length in history buffer */
95 struct llist_head tx_queue; /* frames to L1 */
96 struct lapdm_msg_ctx mctx; /* context of established connection */
97 struct msgb *rcv_buffer; /* buffer to assemble the received message */
99 struct lapdm_entity *entity;
108 typedef int (*lapdm_cb_t)(struct msgb *msg, struct lapdm_entity *le, void *ctx);
110 /* register message handler for messages that are sent from L2->L3 */
111 struct lapdm_entity {
112 struct lapdm_datalink datalink[_NR_DL_SAPI];
113 int last_tx_dequeue; /* last entity that was dequeued */
114 int tx_pending; /* currently a pending frame not confirmed by L1 */
116 void *l1_ctx; /* context for layer1 instance */
117 void *l3_ctx; /* context for layer3 instance */
119 osmo_prim_cb l1_prim_cb;
120 lapdm_cb_t l3_cb; /* callback for sending stuff to L3 */
122 struct lapdm_channel *lapdm_ch;
125 /* the two lapdm_entities that form a GSM logical channel (ACCH + DCCH) */
126 struct lapdm_channel {
127 struct llist_head list;
129 struct lapdm_entity lapdm_acch;
130 struct lapdm_entity lapdm_dcch;
133 const char *get_rsl_name(int value);
134 extern const char *lapdm_state_names[];
136 /* initialize a LAPDm entity */
137 void lapdm_entity_init(struct lapdm_entity *le);
138 void lapdm_channel_init(struct lapdm_channel *lc);
140 /* deinitialize a LAPDm entity */
141 void lapdm_entity_exit(struct lapdm_entity *le);
142 void lapdm_channel_exit(struct lapdm_channel *lc);
144 /* input into layer2 (from layer 1) */
145 int lapdm_phsap_up(struct osmo_prim_hdr *oph, struct lapdm_entity *le);
147 /* input into layer2 (from layer 3) */
148 int lapdm_rslms_recvmsg(struct msgb *msg, struct lapdm_channel *lc);
150 void lapdm_channel_set_l3(struct lapdm_channel *lc, lapdm_cb_t cb, void *ctx);
151 void lapdm_channel_set_l1(struct lapdm_channel *lc, osmo_prim_cb cb, void *ctx);
153 #endif /* _OSMOCOM_LAPDM_H */