libosmoisdn  1.9.0.189-35f20.202403212026
Osmocom ISDN library
lapd_core.h
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include <stdint.h>
7 
8 #include <osmocom/core/timer.h>
9 #include <osmocom/core/msgb.h>
10 #include <osmocom/gsm/prim.h>
11 
17 #define LOGDL(dl, level, fmt, args...) \
18  LOGP(DLLAPD, level, "(%s) " fmt, (dl)->name, ## args)
19 
30 };
31 
32 /* Uses the same values as RLL, so no conversion for GSM is required. */
33 #define MDL_CAUSE_T200_EXPIRED 0x01
34 #define MDL_CAUSE_REEST_REQ 0x02
35 #define MDL_CAUSE_UNSOL_UA_RESP 0x03
36 #define MDL_CAUSE_UNSOL_DM_RESP 0x04
37 #define MDL_CAUSE_UNSOL_DM_RESP_MF 0x05
38 #define MDL_CAUSE_UNSOL_SPRV_RESP 0x06
39 #define MDL_CAUSE_SEQ_ERR 0x07
40 #define MDL_CAUSE_UFRM_INC_PARAM 0x08
41 #define MDL_CAUSE_SFRM_INC_PARAM 0x09
42 #define MDL_CAUSE_IFRM_INC_MBITS 0x0a
43 #define MDL_CAUSE_IFRM_INC_LEN 0x0b
44 #define MDL_CAUSE_FRM_UNIMPL 0x0c
45 #define MDL_CAUSE_SABM_MF 0x0d
46 #define MDL_CAUSE_SABM_INFO_NOTALL 0x0e
47 #define MDL_CAUSE_FRMR 0x0f
48 
51  uint8_t cause;
52 };
53 
56  uint8_t mode;
57 };
58 
61  struct osmo_prim_hdr oph;
62  union {
65  } u;
66 };
67 
69 enum lapd_mode {
72 };
73 
75 enum lapd_state {
85 };
86 
88 #define LAPD_F_RTS 0x0001
89 #define LAPD_F_DROP_2ND_REJ 0x0002
90 
96 };
97 
104 };
105 
107 struct lapd_msg_ctx {
108  struct lapd_datalink *dl;
109  int n201;
110  /* address */
111  uint8_t cr;
112  uint8_t sapi;
113  uint8_t tei;
114  uint8_t lpd;
115  /* control */
116  uint8_t format;
117  uint8_t p_f; /* poll / final bit */
118  uint8_t n_send;
119  uint8_t n_recv;
120  uint8_t s_u; /* S or repectivly U function bits */
121  /* length */
122  int length;
123  uint8_t more;
124 };
125 
126 struct lapd_cr_ent {
127  uint8_t cmd;
128  uint8_t resp;
129 };
130 
131 struct lapd_history {
132  struct msgb *msg; /* message to be sent / NULL, if histoy is empty */
133  int more; /* if message is fragmented */
134 };
135 
138  int (*send_dlsap)(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx);
139  int (*send_ph_data_req)(struct lapd_msg_ctx *lctx, struct msgb *msg);
141  struct {
143  struct lapd_cr_ent loc2rem;
144  struct lapd_cr_ent rem2loc;
145  } cr;
146  enum lapd_mode mode;
147  unsigned int lapd_flags;
148  int use_sabme;
151  struct lapd_msg_ctx lctx;
152  int maxf;
153  uint8_t k;
154  uint8_t v_range;
155  uint8_t v_send;
156  uint8_t v_ack;
157  uint8_t v_recv;
158  uint32_t state;
160  uint8_t own_busy;
161  uint8_t peer_busy;
164  enum lapd_t200_rts t200_rts;
165  struct osmo_timer_list t200;
166  struct osmo_timer_list t203;
167  uint8_t retrans_ctr;
168  struct llist_head tx_queue;
169  struct llist_head send_queue;
170  struct msgb *send_buffer;
171  int send_out;
173  uint8_t range_hist;
174  struct msgb *rcv_buffer;
175  struct msgb *cont_res;
176  char *name;
177 };
178 
179 void lapd_dl_init(struct lapd_datalink *dl, uint8_t k, uint8_t v_range, int maxf)
180  OSMO_DEPRECATED("Use lapd_dl_init2() instead");
181 void lapd_dl_init2(struct lapd_datalink *dl, uint8_t k, uint8_t v_range, int maxf, const char *name);
182 void lapd_dl_set_name(struct lapd_datalink *dl, const char *name);
183 void lapd_dl_exit(struct lapd_datalink *dl);
184 void lapd_dl_reset(struct lapd_datalink *dl);
185 int lapd_dl_set_flags(struct lapd_datalink *dl, unsigned int flags);
186 int lapd_set_mode(struct lapd_datalink *dl, enum lapd_mode mode);
187 int lapd_ph_data_ind(struct msgb *msg, struct lapd_msg_ctx *lctx);
188 int lapd_ph_rts_ind(struct lapd_msg_ctx *lctx);
189 int lapd_recv_dlsap(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx);
190 int lapd_t200_timeout(struct lapd_datalink *dl);
191 
void lapd_dl_init2(struct lapd_datalink *dl, uint8_t k, uint8_t v_range, int maxf, const char *name)
Initialize LAPD datalink instance and allocate history.
Definition: lapd_core.c:305
int lapd_set_mode(struct lapd_datalink *dl, enum lapd_mode mode)
Set the lapdm_mode of a LAPDm entity.
Definition: lapd_core.c:432
int lapd_ph_data_ind(struct msgb *msg, struct lapd_msg_ctx *lctx)
Definition: lapd_core.c:1772
int lapd_dl_set_flags(struct lapd_datalink *dl, unsigned int flags)
Set lapd_flags to change behaviour.
Definition: lapd_core.c:403
void lapd_dl_reset(struct lapd_datalink *dl)
Definition: lapd_core.c:380
int lapd_t200_timeout(struct lapd_datalink *dl)
Handle timeout condition of T200 in RTS mode.
Definition: lapd_core.c:224
lapd_t200_rts
LAPD T200 state in RTS mode.
Definition: lapd_core.h:92
int lapd_recv_dlsap(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx)
Definition: lapd_core.c:2314
lapd_mode
LAPD mode/role.
Definition: lapd_core.h:69
void lapd_dl_exit(struct lapd_datalink *dl)
Definition: lapd_core.c:416
void lapd_dl_set_name(struct lapd_datalink *dl, const char *name)
Definition: lapd_core.c:372
void lapd_dl_init(struct lapd_datalink *dl, uint8_t k, uint8_t v_range, int maxf) OSMO_DEPRECATED("Use lapd_dl_init2() instead")
Initialize LAPD datalink instance and allocate history.
Definition: lapd_core.c:367
lapd_format
LAPD message format (I / S / U)
Definition: lapd_core.h:99
int lapd_ph_rts_ind(struct lapd_msg_ctx *lctx)
Enqueue next LAPD frame and run pending T200.
Definition: lapd_core.c:1800
osmo_dl_prim
LAPD related primitives (L2<->L3 SAP)
Definition: lapd_core.h:21
lapd_state
LAPD state (Figure B.2/Q.921)
Definition: lapd_core.h:75
@ LAPD_T200_RTS_OFF
Definition: lapd_core.h:93
@ LAPD_T200_RTS_PENDING
Definition: lapd_core.h:94
@ LAPD_T200_RTS_RUNNING
Definition: lapd_core.h:95
@ LAPD_MODE_USER
behave like user
Definition: lapd_core.h:70
@ LAPD_MODE_NETWORK
behave like network
Definition: lapd_core.h:71
@ LAPD_FORM_U
Definition: lapd_core.h:103
@ LAPD_FORM_I
Definition: lapd_core.h:101
@ LAPD_FORM_S
Definition: lapd_core.h:102
@ LAPD_FORM_UKN
Definition: lapd_core.h:100
@ PRIM_DL_REL
DL-RLEEASE.
Definition: lapd_core.h:25
@ PRIM_DL_RES
DL-RESUME.
Definition: lapd_core.h:27
@ PRIM_DL_SUSP
DL-SUSPEND.
Definition: lapd_core.h:26
@ PRIM_DL_EST
DL-ESTABLISH.
Definition: lapd_core.h:24
@ PRIM_DL_DATA
DL-DATA.
Definition: lapd_core.h:23
@ PRIM_DL_UNIT_DATA
DL-UNIT-DATA.
Definition: lapd_core.h:22
@ PRIM_MDL_ERROR
MDL-ERROR.
Definition: lapd_core.h:29
@ PRIM_DL_RECON
DL-RECONNECT.
Definition: lapd_core.h:28
@ LAPD_STATE_SABM_SENT
Definition: lapd_core.h:81
@ LAPD_STATE_TEI_UNASS
Definition: lapd_core.h:77
@ LAPD_STATE_MF_EST
Definition: lapd_core.h:83
@ LAPD_STATE_EST_TEI_WAIT
Definition: lapd_core.h:79
@ LAPD_STATE_DISC_SENT
Definition: lapd_core.h:82
@ LAPD_STATE_ASS_TEI_WAIT
Definition: lapd_core.h:78
@ LAPD_STATE_NULL
Definition: lapd_core.h:76
@ LAPD_STATE_TIMER_RECOV
Definition: lapd_core.h:84
@ LAPD_STATE_IDLE
Definition: lapd_core.h:80
const char * name
#define OSMO_DEPRECATED(text)
for DL-REL.req
Definition: lapd_core.h:55
uint8_t mode
release mode
Definition: lapd_core.h:56
Definition: lapd_core.h:126
uint8_t resp
Definition: lapd_core.h:128
uint8_t cmd
Definition: lapd_core.h:127
Definition: lapd_core.h:131
struct msgb * msg
Definition: lapd_core.h:132
int more
Definition: lapd_core.h:133
LAPD message context.
Definition: lapd_core.h:107
uint8_t more
Definition: lapd_core.h:123
uint8_t n_send
Definition: lapd_core.h:118
struct lapd_datalink * dl
Definition: lapd_core.h:108
uint8_t n_recv
Definition: lapd_core.h:119
uint8_t p_f
Definition: lapd_core.h:117
int n201
Definition: lapd_core.h:109
uint8_t lpd
Definition: lapd_core.h:114
uint8_t sapi
Definition: lapd_core.h:112
uint8_t cr
Definition: lapd_core.h:111
uint8_t format
Definition: lapd_core.h:116
int length
Definition: lapd_core.h:122
uint8_t tei
Definition: lapd_core.h:113
uint8_t s_u
Definition: lapd_core.h:120
for MDL-ERROR.ind
Definition: lapd_core.h:50
uint8_t cause
generic cause value
Definition: lapd_core.h:51
primitive header for LAPD DL-SAP primitives
Definition: lapd_core.h:60
union osmo_dlsap_prim::@2 u
request-specific data
struct osmo_prim_hdr oph
generic primitive header
Definition: lapd_core.h:61
struct dl_rel_req_param rel_req
Definition: lapd_core.h:64
struct mdl_error_ind_param error_ind
Definition: lapd_core.h:63