lapd_core.h
Go to the documentation of this file.
#pragma once
#include <stdint.h>
#include <osmocom/core/timer.h>
#include <osmocom/core/msgb.h>
#include <osmocom/gsm/prim.h>
enum osmo_dl_prim {
PRIM_DL_UNIT_DATA,
PRIM_DL_DATA,
PRIM_DL_EST,
PRIM_DL_REL,
PRIM_DL_SUSP,
PRIM_DL_RES,
PRIM_DL_RECON,
PRIM_MDL_ERROR,
};
/* Uses the same values as RLL, so no conversion for GSM is required. */
#define MDL_CAUSE_T200_EXPIRED 0x01
#define MDL_CAUSE_REEST_REQ 0x02
#define MDL_CAUSE_UNSOL_UA_RESP 0x03
#define MDL_CAUSE_UNSOL_DM_RESP 0x04
#define MDL_CAUSE_UNSOL_DM_RESP_MF 0x05
#define MDL_CAUSE_UNSOL_SPRV_RESP 0x06
#define MDL_CAUSE_SEQ_ERR 0x07
#define MDL_CAUSE_UFRM_INC_PARAM 0x08
#define MDL_CAUSE_SFRM_INC_PARAM 0x09
#define MDL_CAUSE_IFRM_INC_MBITS 0x0a
#define MDL_CAUSE_IFRM_INC_LEN 0x0b
#define MDL_CAUSE_FRM_UNIMPL 0x0c
#define MDL_CAUSE_SABM_MF 0x0d
#define MDL_CAUSE_SABM_INFO_NOTALL 0x0e
#define MDL_CAUSE_FRMR 0x0f
struct mdl_error_ind_param {
uint8_t cause;
};
struct dl_rel_req_param {
uint8_t mode;
};
struct osmo_dlsap_prim {
struct osmo_prim_hdr oph;
union {
struct mdl_error_ind_param error_ind;
struct dl_rel_req_param rel_req;
} u;
};
enum lapd_mode {
LAPD_MODE_USER,
LAPD_MODE_NETWORK,
};
enum lapd_state {
LAPD_STATE_NULL = 0,
LAPD_STATE_TEI_UNASS,
LAPD_STATE_ASS_TEI_WAIT,
LAPD_STATE_EST_TEI_WAIT,
LAPD_STATE_IDLE,
LAPD_STATE_SABM_SENT,
LAPD_STATE_DISC_SENT,
LAPD_STATE_MF_EST,
LAPD_STATE_TIMER_RECOV,
};
enum lapd_format {
LAPD_FORM_UKN = 0,
LAPD_FORM_I,
LAPD_FORM_S,
LAPD_FORM_U,
};
struct lapd_msg_ctx {
struct lapd_datalink *dl;
int n201;
/* address */
uint8_t cr;
uint8_t sapi;
uint8_t tei;
uint8_t lpd;
/* control */
uint8_t format;
uint8_t p_f; /* poll / final bit */
uint8_t n_send;
uint8_t n_recv;
uint8_t s_u; /* S or repectivly U function bits */
/* length */
int length;
uint8_t more;
};
struct lapd_cr_ent {
uint8_t cmd;
uint8_t resp;
};
struct lapd_history {
struct msgb *msg; /* message to be sent / NULL, if histoy is empty */
int more; /* if message is fragmented */
};
struct lapd_datalink {
int (*send_dlsap)(struct osmo_dlsap_prim *dp,
struct lapd_msg_ctx *lctx);
int (*send_ph_data_req)(struct lapd_msg_ctx *lctx, struct msgb *msg);
int (*update_pending_frames)(struct lapd_msg_ctx *lctx);
struct {
struct lapd_cr_ent loc2rem;
struct lapd_cr_ent rem2loc;
} cr;
enum lapd_mode mode;
int use_sabme;
int reestablish;
int n200, n200_est_rel;
struct lapd_msg_ctx lctx;
int maxf;
uint8_t k;
uint8_t v_range;
uint8_t v_send;
uint8_t v_ack;
uint8_t v_recv;
uint32_t state;
int seq_err_cond;
uint8_t own_busy;
uint8_t peer_busy;
int t200_sec, t200_usec;
int t203_sec, t203_usec;
struct osmo_timer_list t200;
struct osmo_timer_list t203;
uint8_t retrans_ctr;
struct llist_head tx_queue;
struct llist_head send_queue;
struct msgb *send_buffer;
int send_out;
struct lapd_history *tx_hist;
uint8_t range_hist;
struct msgb *rcv_buffer;
struct msgb *cont_res;
};
void lapd_dl_init(struct lapd_datalink *dl, uint8_t k, uint8_t v_range,
int maxf);
void lapd_dl_exit(struct lapd_datalink *dl);
void lapd_dl_reset(struct lapd_datalink *dl);
int lapd_set_mode(struct lapd_datalink *dl, enum lapd_mode mode);
int lapd_ph_data_ind(struct msgb *msg, struct lapd_msg_ctx *lctx);
int lapd_recv_dlsap(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx);
dl_rel_req_param
for DL-REL.req
Definition: lapd_core.h:52
PRIM_DL_REL
@ PRIM_DL_REL
DL-RLEEASE.
Definition: lapd_core.h:22
PRIM_DL_EST
@ PRIM_DL_EST
DL-ESTABLISH.
Definition: lapd_core.h:21
LAPD_STATE_TIMER_RECOV
@ LAPD_STATE_TIMER_RECOV
Definition: lapd_core.h:81
lapd_cr_ent::resp
uint8_t resp
Definition: lapd_core.h:114
lapd_datalink::send_out
int send_out
how much was sent from send_buffer
Definition: lapd_core.h:156
lapd_datalink::use_sabme
int use_sabme
use SABME instead of SABM
Definition: lapd_core.h:134
LAPD_MODE_NETWORK
@ LAPD_MODE_NETWORK
behave like network
Definition: lapd_core.h:68
lapd_msg_ctx::length
int length
Definition: lapd_core.h:108
lapd_history::more
int more
Definition: lapd_core.h:119
PRIM_DL_SUSP
@ PRIM_DL_SUSP
DL-SUSPEND.
Definition: lapd_core.h:23
lapd_msg_ctx::n_send
uint8_t n_send
Definition: lapd_core.h:104
lapd_datalink::mode
enum lapd_mode mode
current mode of link
Definition: lapd_core.h:133
LAPD_STATE_IDLE
@ LAPD_STATE_IDLE
Definition: lapd_core.h:77
lapd_datalink::rem2loc
struct lapd_cr_ent rem2loc
Definition: lapd_core.h:131
lapd_datalink::n200
int n200
Definition: lapd_core.h:136
lapd_msg_ctx::sapi
uint8_t sapi
Definition: lapd_core.h:98
lapd_datalink::t200
struct osmo_timer_list t200
T200 timer.
Definition: lapd_core.h:150
lapd_recv_dlsap
int lapd_recv_dlsap(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx)
Definition: lapd_core.c:2209
lapd_datalink::seq_err_cond
int seq_err_cond
condition of sequence error
Definition: lapd_core.h:145
lapd_dl_exit
void lapd_dl_exit(struct lapd_datalink *dl)
Definition: lapd_core.c:330
LAPD_MODE_USER
@ LAPD_MODE_USER
behave like user
Definition: lapd_core.h:67
LAPD_FORM_UKN
@ LAPD_FORM_UKN
Definition: lapd_core.h:86
lapd_msg_ctx::format
uint8_t format
Definition: lapd_core.h:102
lapd_msg_ctx::s_u
uint8_t s_u
Definition: lapd_core.h:106
lapd_datalink::tx_queue
struct llist_head tx_queue
frames to L1
Definition: lapd_core.h:153
lapd_datalink::loc2rem
struct lapd_cr_ent loc2rem
filled-in once we set the lapd_mode above
Definition: lapd_core.h:130
LAPD_STATE_ASS_TEI_WAIT
@ LAPD_STATE_ASS_TEI_WAIT
Definition: lapd_core.h:75
PRIM_DL_UNIT_DATA
@ PRIM_DL_UNIT_DATA
DL-UNIT-DATA.
Definition: lapd_core.h:19
lapd_set_mode
int lapd_set_mode(struct lapd_datalink *dl, enum lapd_mode mode)
Set the lapdm_mode of a LAPDm entity.
Definition: lapd_core.c:344
osmo_dlsap_prim::oph
struct osmo_prim_hdr oph
generic primitive header
Definition: lapd_core.h:58
lapd_dl_reset
void lapd_dl_reset(struct lapd_datalink *dl)
Definition: lapd_core.c:308
lapd_datalink::maxf
int maxf
maximum frame size (after defragmentation)
Definition: lapd_core.h:138
osmo_dlsap_prim::u
union osmo_dlsap_prim::@8 u
request-specific data
lapd_datalink::cr
struct lapd_datalink::@9 cr
lapd_datalink::t203
struct osmo_timer_list t203
T203 timer.
Definition: lapd_core.h:151
lapd_datalink::send_dlsap
int(* send_dlsap)(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx)
Definition: lapd_core.h:124
osmo_dlsap_prim
primitive header for LAPD DL-SAP primitives
Definition: lapd_core.h:57
osmo_dlsap_prim::rel_req
struct dl_rel_req_param rel_req
Definition: lapd_core.h:61
lapd_datalink::range_hist
uint8_t range_hist
range of history buffer 2..2^n
Definition: lapd_core.h:158
lapd_datalink::own_busy
uint8_t own_busy
receiver busy on our side
Definition: lapd_core.h:146
lapd_datalink::state
uint32_t state
LAPD state (lapd_state)
Definition: lapd_core.h:144
lapd_datalink::cont_res
struct msgb * cont_res
buffer to store content resolution data on network side, to detect multiple phones on same channel
Definition: lapd_core.h:160
mode
uint8_t mode
Definition: gsm_04_08.h:633
lapd_datalink::t203_usec
int t203_usec
retry timer (default 10 secs)
Definition: lapd_core.h:149
lapd_datalink
LAPD datalink.
Definition: lapd_core.h:123
dl_rel_req_param::mode
uint8_t mode
release mode
Definition: lapd_core.h:53
lapd_cr_ent::cmd
uint8_t cmd
Definition: lapd_core.h:113
lapd_ph_data_ind
int lapd_ph_data_ind(struct msgb *msg, struct lapd_msg_ctx *lctx)
Definition: lapd_core.c:1692
LAPD_STATE_TEI_UNASS
@ LAPD_STATE_TEI_UNASS
Definition: lapd_core.h:74
LAPD_STATE_NULL
@ LAPD_STATE_NULL
Definition: lapd_core.h:73
PRIM_MDL_ERROR
@ PRIM_MDL_ERROR
MDL-ERROR.
Definition: lapd_core.h:26
lapd_datalink::peer_busy
uint8_t peer_busy
receiver busy on remote side
Definition: lapd_core.h:147
lapd_msg_ctx::p_f
uint8_t p_f
Definition: lapd_core.h:103
lapd_datalink::n200_est_rel
int n200_est_rel
number of retranmissions
Definition: lapd_core.h:136
lapd_history
Definition: lapd_core.h:117
lapd_datalink::send_ph_data_req
int(* send_ph_data_req)(struct lapd_msg_ctx *lctx, struct msgb *msg)
Definition: lapd_core.h:126
lapd_msg_ctx::n201
int n201
Definition: lapd_core.h:95
lapd_datalink::t203_sec
int t203_sec
Definition: lapd_core.h:149
LAPD_STATE_EST_TEI_WAIT
@ LAPD_STATE_EST_TEI_WAIT
Definition: lapd_core.h:76
lapd_datalink::k
uint8_t k
maximum number of unacknowledged frames
Definition: lapd_core.h:139
PRIM_DL_RECON
@ PRIM_DL_RECON
DL-RECONNECT.
Definition: lapd_core.h:25
lapd_datalink::v_recv
uint8_t v_recv
seq nr of next I frame expected to be received
Definition: lapd_core.h:143
lapd_history::msg
struct msgb * msg
Definition: lapd_core.h:118
LAPD_FORM_U
@ LAPD_FORM_U
Definition: lapd_core.h:89
lapd_datalink::lctx
struct lapd_msg_ctx lctx
LAPD context.
Definition: lapd_core.h:137
lapd_datalink::send_buffer
struct msgb * send_buffer
current frame transmitting
Definition: lapd_core.h:155
osmo_dl_prim
osmo_dl_prim
LAPD related primitives (L2<->L3 SAP)
Definition: lapd_core.h:18
lapd_msg_ctx::tei
uint8_t tei
Definition: lapd_core.h:99
lapd_datalink::update_pending_frames
int(* update_pending_frames)(struct lapd_msg_ctx *lctx)
Definition: lapd_core.h:127
lapd_cr_ent
Definition: lapd_core.h:112
lapd_dl_init
void lapd_dl_init(struct lapd_datalink *dl, uint8_t k, uint8_t v_range, int maxf)
Definition: lapd_core.c:258
lapd_msg_ctx::cr
uint8_t cr
Definition: lapd_core.h:97
lapd_datalink::t200_sec
int t200_sec
Definition: lapd_core.h:148
lapd_datalink::retrans_ctr
uint8_t retrans_ctr
re-transmission counter
Definition: lapd_core.h:152
LAPD_FORM_I
@ LAPD_FORM_I
Definition: lapd_core.h:87
PRIM_DL_RES
@ PRIM_DL_RES
DL-RESUME.
Definition: lapd_core.h:24
lapd_msg_ctx::n_recv
uint8_t n_recv
Definition: lapd_core.h:105
mdl_error_ind_param
for MDL-ERROR.ind
Definition: lapd_core.h:47
lapd_datalink::send_queue
struct llist_head send_queue
frames from L3
Definition: lapd_core.h:154
LAPD_STATE_DISC_SENT
@ LAPD_STATE_DISC_SENT
Definition: lapd_core.h:79
lapd_mode
lapd_mode
LAPD mode/role.
Definition: lapd_core.h:66
lapd_datalink::tx_hist
struct lapd_history * tx_hist
tx history structure array
Definition: lapd_core.h:157
lapd_msg_ctx
LAPD message context.
Definition: lapd_core.h:93
lapd_datalink::t200_usec
int t200_usec
retry timer (default 1 sec)
Definition: lapd_core.h:148
lapd_msg_ctx::lpd
uint8_t lpd
Definition: lapd_core.h:100
lapd_datalink::v_send
uint8_t v_send
seq nr of next I frame to be transmitted
Definition: lapd_core.h:141
LAPD_FORM_S
@ LAPD_FORM_S
Definition: lapd_core.h:88
lapd_msg_ctx::dl
struct lapd_datalink * dl
Definition: lapd_core.h:94
lapd_datalink::reestablish
int reestablish
enable reestablish support
Definition: lapd_core.h:135
lapd_datalink::rcv_buffer
struct msgb * rcv_buffer
buffer to assemble the received message
Definition: lapd_core.h:159
lapd_msg_ctx::more
uint8_t more
Definition: lapd_core.h:109
LAPD_STATE_SABM_SENT
@ LAPD_STATE_SABM_SENT
Definition: lapd_core.h:78
lapd_datalink::v_range
uint8_t v_range
range of sequence numbers
Definition: lapd_core.h:140
prim.h
lapd_format
lapd_format
LAPD message format (I / S / U)
Definition: lapd_core.h:85
mdl_error_ind_param::cause
uint8_t cause
generic cause value
Definition: lapd_core.h:48
PRIM_DL_DATA
@ PRIM_DL_DATA
DL-DATA.
Definition: lapd_core.h:20
osmo_dlsap_prim::error_ind
struct mdl_error_ind_param error_ind
Definition: lapd_core.h:60
lapd_datalink::v_ack
uint8_t v_ack
last frame ACKed by peer
Definition: lapd_core.h:142
LAPD_STATE_MF_EST
@ LAPD_STATE_MF_EST
Definition: lapd_core.h:80
lapd_state
lapd_state
LAPD state (Figure B.2/Q.921)
Definition: lapd_core.h:72