remove osmocom_ms reference from lapdm_init()
[osmocom-bb.git] / src / host / layer23 / include / osmocom / bb / common / lapdm.h
1 #ifndef _OSMOCOM_LAPDM_H
2 #define _OSMOCOM_LAPDM_H
3
4 #include <stdint.h>
5
6 #include <osmocom/core/timer.h>
7 #include <osmocom/core/msgb.h>
8
9 #include <l1ctl_proto.h>
10
11 enum lapdm_state {
12         LAPDm_STATE_NULL = 0,
13         LAPDm_STATE_IDLE,
14         LAPDm_STATE_SABM_SENT,
15         LAPDm_STATE_MF_EST,
16         LAPDm_STATE_TIMER_RECOV,
17         LAPDm_STATE_DISC_SENT,
18 };
19
20 struct lapdm_entity;
21 struct osmocom_ms;
22
23 struct lapdm_msg_ctx {
24         struct lapdm_datalink *dl;
25         int lapdm_fmt;
26         uint8_t n201;
27         uint8_t chan_nr;
28         uint8_t link_id;
29         uint8_t addr;
30         uint8_t ctrl;
31         uint8_t ta_ind;
32         uint8_t tx_power_ind;
33 };
34
35 /* TS 04.06 / Section 3.5.2 */
36 struct lapdm_datalink {
37         uint8_t V_send; /* seq nr of next I frame to be transmitted */
38         uint8_t V_ack;  /* last frame ACKed by peer */
39         uint8_t N_send; /* ? set to V_send at Tx time*/
40         uint8_t V_recv; /* seq nr of next I frame expected to be received */
41         uint8_t N_recv; /* expected send seq nr of the next received I frame */
42         uint32_t state;
43         int seq_err_cond; /* condition of sequence error */
44         uint8_t own_busy, peer_busy;
45         struct osmo_timer_list t200;
46         uint8_t retrans_ctr;
47         struct llist_head send_queue; /* frames from L3 */
48         struct msgb *send_buffer; /* current frame transmitting */
49         int send_out; /* how much was sent from send_buffer */
50         uint8_t tx_hist[8][200]; /* tx history buffer */
51         int tx_length[8]; /* length in history buffer */
52         struct llist_head tx_queue; /* frames to L1 */
53         struct lapdm_msg_ctx mctx; /* context of established connection */
54         struct msgb *rcv_buffer; /* buffer to assemble the received message */
55
56         struct lapdm_entity *entity;
57 };
58
59 enum lapdm_dl_sapi {
60         DL_SAPI0        = 0,
61         DL_SAPI3        = 1,
62         _NR_DL_SAPI
63 };
64
65 struct lapdm_entity {
66         struct lapdm_datalink datalink[_NR_DL_SAPI];
67         int last_tx_dequeue; /* last entity that was dequeued */
68         int tx_pending; /* currently a pending frame not confirmed by L1 */
69
70         void *l1_ctx;   /* context for layer1 instance */
71         void *l3_ctx;   /* context for layer3 instance */
72 };
73
74 const char *get_rsl_name(int value);
75 extern const char *lapdm_state_names[];
76
77 /* initialize a LAPDm entity */
78 void lapdm_init(struct lapdm_entity *le);
79
80 /* deinitialize a LAPDm entity */
81 void lapdm_exit(struct lapdm_entity *le);
82
83 /* input into layer2 (from layer 1) */
84 int l2_ph_data_ind(struct msgb *msg, struct lapdm_entity *le, struct l1ctl_info_dl *l1i);
85 int l2_ph_data_conf(struct msgb *msg, struct lapdm_entity *le);
86
87 /* L1 confirms channel request */
88 int l2_ph_chan_conf(struct msgb *msg, struct osmocom_ms *ms,
89                         struct l1ctl_info_dl *dl);
90
91 /* input into layer2 (from layer 3) */
92 int rslms_recvmsg(struct msgb *msg, struct osmocom_ms *ms);
93
94 /* sending messages up from L2 to L3 */
95 int rslms_sendmsg(struct msgb *msg, struct osmocom_ms *ms);
96
97 typedef int (*osmol2_cb_t)(struct msgb *msg, struct osmocom_ms *ms);
98
99 /* register message handler for messages that are sent from L2->L3 */
100 int osmol2_register_handler(struct osmocom_ms *ms, osmol2_cb_t cb);
101
102 #endif /* _OSMOCOM_LAPDM_H */