libosmogsm  1.0.1.85-9f28
Osmocom GSM library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
LAPDm implementation according to GSM TS 04.06

Files

file  lapdm.h
 
file  lapdm.c
 GSM LAPDm (TS 04.06) implementation.
 

Data Structures

struct  lapdm_msg_ctx
 LAPDm message context. More...
 
struct  lapdm_datalink
 LAPDm datalink like TS 04.06 / Section 3.5.2. More...
 
struct  lapdm_entity
 a LAPDm Entity More...
 
struct  lapdm_channel
 the two lapdm_entities that form a GSM logical channel (ACCH + DCCH) More...
 

Macros

#define LAPDM_ENT_F_EMPTY_FRAME   0x0001
 
#define LAPDM_ENT_F_POLLING_ONLY   0x0002
 
#define LAPD_U_SABM   0x7
 
#define LAPDm_LPD_NORMAL   0
 
#define LAPDm_LPD_SMSCB   1
 
#define LAPDm_SAPI_NORMAL   0
 
#define LAPDm_SAPI_SMS   3
 
#define LAPDm_ADDR(lpd, sapi, cr)   ((((lpd) & 0x3) << 5) | (((sapi) & 0x7) << 2) | (((cr) & 0x1) << 1) | 0x1)
 
#define LAPDm_ADDR_LPD(addr)   (((addr) >> 5) & 0x3)
 
#define LAPDm_ADDR_SAPI(addr)   (((addr) >> 2) & 0x7)
 
#define LAPDm_ADDR_CR(addr)   (((addr) >> 1) & 0x1)
 
#define LAPDm_ADDR_EA(addr)   ((addr) & 0x1)
 
#define LAPDm_CTRL_I(nr, ns, p)   ((((nr) & 0x7) << 5) | (((p) & 0x1) << 4) | (((ns) & 0x7) << 1))
 
#define LAPDm_CTRL_S(nr, s, p)   ((((nr) & 0x7) << 5) | (((p) & 0x1) << 4) | (((s) & 0x3) << 2) | 0x1)
 
#define LAPDm_CTRL_U(u, p)   ((((u) & 0x1c) << (5-2)) | (((p) & 0x1) << 4) | (((u) & 0x3) << 2) | 0x3)
 
#define LAPDm_CTRL_is_I(ctrl)   (((ctrl) & 0x1) == 0)
 
#define LAPDm_CTRL_is_S(ctrl)   (((ctrl) & 0x3) == 1)
 
#define LAPDm_CTRL_is_U(ctrl)   (((ctrl) & 0x3) == 3)
 
#define LAPDm_CTRL_U_BITS(ctrl)   ((((ctrl) & 0xC) >> 2) | ((ctrl) & 0xE0) >> 3)
 
#define LAPDm_CTRL_PF_BIT(ctrl)   (((ctrl) >> 4) & 0x1)
 
#define LAPDm_CTRL_S_BITS(ctrl)   (((ctrl) & 0xC) >> 2)
 
#define LAPDm_CTRL_I_Ns(ctrl)   (((ctrl) & 0xE) >> 1)
 
#define LAPDm_CTRL_Nr(ctrl)   (((ctrl) & 0xE0) >> 5)
 
#define LAPDm_LEN(len)   ((len << 2) | 0x1)
 
#define LAPDm_MORE   0x2
 
#define LAPDm_EL   0x1
 
#define LAPDm_U_UI   0x0
 
#define N201_AB_SACCH   18
 
#define N201_AB_SDCCH   20
 
#define N201_AB_FACCH   20
 
#define N201_Bbis   23
 
#define N201_Bter_SACCH   21
 
#define N201_Bter_SDCCH   23
 
#define N201_Bter_FACCH   23
 
#define N201_B4   19
 
#define N200_EST_REL   5
 
#define N200_TR_SACCH   5
 
#define N200_TR_SDCCH   23
 
#define N200_TR_FACCH_FR   34
 
#define N200_TR_EFACCH_FR   48
 
#define N200_TR_FACCH_HR   29
 
#define N200   N200_TR_SDCCH
 

Typedefs

typedef int(* lapdm_cb_t )(struct msgb *msg, struct lapdm_entity *le, void *ctx)
 

Enumerations

enum  lapdm_mode {
  LAPDM_MODE_MS,
  LAPDM_MODE_BTS
}
 LAPDm mode/role. More...
 
enum  lapdm_dl_sapi {
  DL_SAPI0 = 0,
  DL_SAPI3 = 1,
  _NR_DL_SAPI
}
 LAPDm datalink SAPIs. More...
 
enum  lapdm_format {
  LAPDm_FMT_A,
  LAPDm_FMT_B,
  LAPDm_FMT_Bbis,
  LAPDm_FMT_Bter,
  LAPDm_FMT_B4
}
 

Functions

const char * get_rsl_name (int value)
 
struct lapdm_datalinklapdm_datalink_for_sapi (struct lapdm_entity *le, uint8_t sapi)
 
void lapdm_entity_init (struct lapdm_entity *le, enum lapdm_mode mode, int t200)
 initialize a LAPDm entity and all datalinks inside More...
 
void lapdm_channel_init (struct lapdm_channel *lc, enum lapdm_mode mode)
 initialize a LAPDm channel and all its channels More...
 
void lapdm_entity_exit (struct lapdm_entity *le)
 flush and release all resoures in LAPDm entity More...
 
void lapdm_channel_exit (struct lapdm_channel *lc)
 
int lapdm_phsap_up (struct osmo_prim_hdr *oph, struct lapdm_entity *le)
 Receive a PH-SAP primitive from L1. More...
 
int lapdm_rslms_recvmsg (struct msgb *msg, struct lapdm_channel *lc)
 Receive a RSLms Message buffers from Layer 3. More...
 
void lapdm_channel_set_l3 (struct lapdm_channel *lc, lapdm_cb_t cb, void *ctx)
 Set the L3 callback and context of a LAPDm channel. More...
 
void lapdm_channel_set_l1 (struct lapdm_channel *lc, osmo_prim_cb cb, void *ctx)
 Set the L1 callback and context of a LAPDm channel. More...
 
int lapdm_entity_set_mode (struct lapdm_entity *le, enum lapdm_mode mode)
 Set the lapdm_mode of a LAPDm entity. More...
 
int lapdm_channel_set_mode (struct lapdm_channel *lc, enum lapdm_mode mode)
 Set the lapdm_mode of a LAPDm channel. More...
 
void lapdm_entity_reset (struct lapdm_entity *le)
 Reset an entire LAPDm entity and all its datalinks. More...
 
void lapdm_channel_reset (struct lapdm_channel *lc)
 Reset a LAPDm channel with all its entities. More...
 
void lapdm_entity_set_flags (struct lapdm_entity *le, unsigned int flags)
 Set the flags of a LAPDm entity. More...
 
void lapdm_channel_set_flags (struct lapdm_channel *lc, unsigned int flags)
 Set the flags of all LAPDm entities in a LAPDm channel. More...
 
int lapdm_phsap_dequeue_prim (struct lapdm_entity *le, struct osmo_phsap_prim *pp)
 dequeue a msg that's pending transmission via L1 and wrap it into a osmo_phsap_prim More...
 
static int lapdm_send_ph_data_req (struct lapd_msg_ctx *lctx, struct msgb *msg)
 
static int send_rslms_dlsap (struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx)
 
static int update_pending_frames (struct lapd_msg_ctx *lctx)
 
static void lapdm_dl_init (struct lapdm_datalink *dl, struct lapdm_entity *entity, int t200)
 
static void lapdm_pad_msgb (struct msgb *msg, uint8_t n201)
 
static int rslms_sendmsg (struct msgb *msg, struct lapdm_entity *le)
 
static int tx_ph_data_enqueue (struct lapdm_datalink *dl, struct msgb *msg, uint8_t chan_nr, uint8_t link_id, uint8_t pad)
 
static struct msgbtx_dequeue_msgb (struct lapdm_entity *le)
 
static int l2_ph_data_conf (struct msgb *msg, struct lapdm_entity *le)
 
static int rsl_is_transparent (uint8_t msg_type)
 
static int send_rslms_rll_l3 (uint8_t msg_type, struct lapdm_msg_ctx *mctx, struct msgb *msg)
 
static int send_rslms_rll_l3_ui (struct lapdm_msg_ctx *mctx, struct msgb *msg)
 
static int send_rll_simple (uint8_t msg_type, struct lapdm_msg_ctx *mctx)
 
static int rsl_rll_error (uint8_t cause, struct lapdm_msg_ctx *mctx)
 
static int lapdm_rx_not_permitted (const struct lapdm_entity *le, const struct lapd_msg_ctx *lctx)
 
static int l2_ph_data_ind (struct msgb *msg, struct lapdm_entity *le, uint8_t chan_nr, uint8_t link_id)
 
static int l2_ph_rach_ind (struct lapdm_entity *le, uint8_t ra, uint32_t fn, uint8_t acc_delay)
 
static int l2_ph_chan_conf (struct msgb *msg, struct lapdm_entity *le, uint32_t frame_nr)
 
static int set_lapdm_context (struct lapdm_datalink *dl, uint8_t chan_nr, uint8_t link_id, int n201, uint8_t sapi)
 
static int rslms_rx_rll_est_req (struct msgb *msg, struct lapdm_datalink *dl)
 
static int rslms_rx_rll_udata_req (struct msgb *msg, struct lapdm_datalink *dl)
 
static int rslms_rx_rll_data_req (struct msgb *msg, struct lapdm_datalink *dl)
 
static int rslms_rx_rll_susp_req (struct msgb *msg, struct lapdm_datalink *dl)
 
static int rslms_rx_rll_res_req (struct msgb *msg, struct lapdm_datalink *dl)
 
static int rslms_rx_rll_rel_req (struct msgb *msg, struct lapdm_datalink *dl)
 
static int rslms_rx_chan_rqd (struct lapdm_channel *lc, struct msgb *msg)
 
static int rslms_rx_rll (struct msgb *msg, struct lapdm_channel *lc)
 
static int rslms_rx_com_chan (struct msgb *msg, struct lapdm_channel *lc)
 

Variables

const char * lapdm_state_names []
 
const struct value_string osmo_ph_prim_names []
 

Detailed Description

Macro Definition Documentation

#define LAPD_U_SABM   0x7

Referenced by lapdm_rx_not_permitted().

#define LAPDm_ADDR (   lpd,
  sapi,
  cr 
)    ((((lpd) & 0x3) << 5) | (((sapi) & 0x7) << 2) | (((cr) & 0x1) << 1) | 0x1)
#define LAPDm_ADDR_CR (   addr)    (((addr) >> 1) & 0x1)

Referenced by l2_ph_data_ind().

#define LAPDm_ADDR_EA (   addr)    ((addr) & 0x1)

Referenced by l2_ph_data_ind().

#define LAPDm_ADDR_LPD (   addr)    (((addr) >> 5) & 0x3)

Referenced by l2_ph_data_ind().

#define LAPDm_ADDR_SAPI (   addr)    (((addr) >> 2) & 0x7)

Referenced by l2_ph_data_ind().

#define LAPDm_CTRL_I (   nr,
  ns,
 
)    ((((nr) & 0x7) << 5) | (((p) & 0x1) << 4) | (((ns) & 0x7) << 1))
#define LAPDm_CTRL_I_Ns (   ctrl)    (((ctrl) & 0xE) >> 1)
#define LAPDm_CTRL_is_I (   ctrl)    (((ctrl) & 0x1) == 0)
#define LAPDm_CTRL_is_S (   ctrl)    (((ctrl) & 0x3) == 1)
#define LAPDm_CTRL_is_U (   ctrl)    (((ctrl) & 0x3) == 3)

Referenced by l2_ph_data_ind().

#define LAPDm_CTRL_Nr (   ctrl)    (((ctrl) & 0xE0) >> 5)

Referenced by l2_ph_data_ind().

#define LAPDm_CTRL_PF_BIT (   ctrl)    (((ctrl) >> 4) & 0x1)
#define LAPDm_CTRL_S (   nr,
  s,
 
)    ((((nr) & 0x7) << 5) | (((p) & 0x1) << 4) | (((s) & 0x3) << 2) | 0x1)

Referenced by lapdm_send_ph_data_req().

#define LAPDm_CTRL_S_BITS (   ctrl)    (((ctrl) & 0xC) >> 2)

Referenced by l2_ph_data_ind().

#define LAPDm_CTRL_U (   u,
 
)    ((((u) & 0x1c) << (5-2)) | (((p) & 0x1) << 4) | (((u) & 0x3) << 2) | 0x3)
#define LAPDm_CTRL_U_BITS (   ctrl)    ((((ctrl) & 0xC) >> 2) | ((ctrl) & 0xE0) >> 3)

Referenced by l2_ph_data_ind().

#define LAPDm_EL   0x1

Referenced by l2_ph_data_ind().

#define LAPDM_ENT_F_EMPTY_FRAME   0x0001

Referenced by l2_ph_data_conf().

#define LAPDM_ENT_F_POLLING_ONLY   0x0002

Referenced by tx_ph_data_enqueue().

#define LAPDm_LEN (   len)    ((len << 2) | 0x1)
#define LAPDm_LPD_NORMAL   0

Referenced by rslms_rx_rll_udata_req().

#define LAPDm_LPD_SMSCB   1
#define LAPDm_MORE   0x2
#define LAPDm_SAPI_NORMAL   0
#define LAPDm_SAPI_SMS   3
#define LAPDm_U_UI   0x0
#define N200   N200_TR_SDCCH

Referenced by lapdm_dl_init().

#define N200_EST_REL   5

Referenced by lapdm_dl_init().

#define N200_TR_EFACCH_FR   48
#define N200_TR_FACCH_FR   34
#define N200_TR_FACCH_HR   29
#define N200_TR_SACCH   5
#define N200_TR_SDCCH   23
#define N201_AB_FACCH   20
#define N201_AB_SACCH   18
#define N201_AB_SDCCH   20
#define N201_B4   19

Referenced by l2_ph_data_ind().

#define N201_Bbis   23

Referenced by l2_ph_data_ind().

#define N201_Bter_FACCH   23
#define N201_Bter_SACCH   21
#define N201_Bter_SDCCH   23

Typedef Documentation

typedef int(* lapdm_cb_t)(struct msgb *msg, struct lapdm_entity *le, void *ctx)

Enumeration Type Documentation

LAPDm datalink SAPIs.

Enumerator
DL_SAPI0 

SAPI 0.

DL_SAPI3 

SAPI 1.

_NR_DL_SAPI 
Enumerator
LAPDm_FMT_A 
LAPDm_FMT_B 
LAPDm_FMT_Bbis 
LAPDm_FMT_Bter 
LAPDm_FMT_B4 
enum lapdm_mode

LAPDm mode/role.

Enumerator
LAPDM_MODE_MS 

behave like a MS (mobile phone)

LAPDM_MODE_BTS 

behave like a BTS (network)

Function Documentation

const char* get_rsl_name ( int  value)
void lapdm_channel_exit ( struct lapdm_channel lc)
void lapdm_channel_init ( struct lapdm_channel lc,
enum lapdm_mode  mode 
)

initialize a LAPDm channel and all its channels

Parameters
[in]lclapdm_channel to be initialized
[in]modelapdm_mode (BTS/MS)

This really is a convenience wrapper around calling lapdm_entity_init twice.

References lapdm_channel::lapdm_acch, lapdm_entity::lapdm_ch, lapdm_channel::lapdm_dcch, and lapdm_entity_init().

void lapdm_channel_reset ( struct lapdm_channel lc)

Reset a LAPDm channel with all its entities.

References lapdm_channel::lapdm_acch, lapdm_channel::lapdm_dcch, and lapdm_entity_reset().

void lapdm_channel_set_flags ( struct lapdm_channel lc,
unsigned int  flags 
)

Set the flags of all LAPDm entities in a LAPDm channel.

References lapdm_channel::lapdm_acch, lapdm_channel::lapdm_dcch, and lapdm_entity_set_flags().

void lapdm_channel_set_l1 ( struct lapdm_channel lc,
osmo_prim_cb  cb,
void *  ctx 
)

Set the L1 callback and context of a LAPDm channel.

References lapdm_entity::l1_ctx, lapdm_entity::l1_prim_cb, lapdm_channel::lapdm_acch, and lapdm_channel::lapdm_dcch.

void lapdm_channel_set_l3 ( struct lapdm_channel lc,
lapdm_cb_t  cb,
void *  ctx 
)

Set the L3 callback and context of a LAPDm channel.

References lapdm_entity::l3_cb, lapdm_entity::l3_ctx, lapdm_channel::lapdm_acch, and lapdm_channel::lapdm_dcch.

int lapdm_channel_set_mode ( struct lapdm_channel lc,
enum lapdm_mode  mode 
)
struct lapdm_datalink * lapdm_datalink_for_sapi ( struct lapdm_entity le,
uint8_t  sapi 
)
void lapdm_entity_exit ( struct lapdm_entity le)

flush and release all resoures in LAPDm entity

References ARRAY_SIZE, lapdm_entity::datalink, lapdm_datalink::dl, and lapd_dl_exit().

Referenced by lapdm_channel_exit().

void lapdm_entity_init ( struct lapdm_entity le,
enum lapdm_mode  mode,
int  t200 
)

initialize a LAPDm entity and all datalinks inside

Parameters
[in]leLAPDm entity
[in]modelapdm_mode (BTS/MS)

References ARRAY_SIZE, lapdm_entity::datalink, lapdm_dl_init(), and lapdm_entity_set_mode().

Referenced by lapdm_channel_init().

void lapdm_entity_reset ( struct lapdm_entity le)

Reset an entire LAPDm entity and all its datalinks.

References ARRAY_SIZE, lapdm_entity::datalink, lapdm_datalink::dl, and lapd_dl_reset().

Referenced by lapdm_channel_reset().

void lapdm_entity_set_flags ( struct lapdm_entity le,
unsigned int  flags 
)

Set the flags of a LAPDm entity.

References lapdm_entity::flags.

Referenced by lapdm_channel_set_flags().

int lapdm_entity_set_mode ( struct lapdm_entity le,
enum lapdm_mode  mode 
)
static void lapdm_pad_msgb ( struct msgb msg,
uint8_t  n201 
)
static
int lapdm_phsap_dequeue_prim ( struct lapdm_entity le,
struct osmo_phsap_prim pp 
)
int lapdm_rslms_recvmsg ( struct msgb msg,
struct lapdm_channel lc 
)
static int rsl_is_transparent ( uint8_t  msg_type)
static
static int rslms_rx_com_chan ( struct msgb msg,
struct lapdm_channel lc 
)
static
static int rslms_sendmsg ( struct msgb msg,
struct lapdm_entity le 
)
static
static int send_rslms_rll_l3 ( uint8_t  msg_type,
struct lapdm_msg_ctx mctx,
struct msgb msg 
)
static
static int set_lapdm_context ( struct lapdm_datalink dl,
uint8_t  chan_nr,
uint8_t  link_id,
int  n201,
uint8_t  sapi 
)
static

Variable Documentation

const char* lapdm_state_names[]
const struct value_string osmo_ph_prim_names[]
Initial value:
= {
{ PRIM_PH_DATA, "PH-DATA" },
{ PRIM_PH_RACH, "PH-RANDOM_ACCESS" },
{ PRIM_PH_CONN, "PH-CONNECT" },
{ PRIM_PH_EMPTY_FRAME, "PH-EMPTY_FRAME" },
{ PRIM_PH_RTS, "PH-RTS" },
{ PRIM_MPH_INFO, "MPH-INFO" },
{ PRIM_TCH, "TCH" },
{ PRIM_TCH_RTS, "TCH-RTS" },
{ 0, NULL }
}
TCH.
Definition: l1sap.h:15
PH-RANDOM_ACCESS.
Definition: l1sap.h:10
TCH.
Definition: l1sap.h:16
PH-RTS.
Definition: l1sap.h:13
PH-DATA.
Definition: l1sap.h:9
MPH-INFO.
Definition: l1sap.h:14
PH-EMPTY_FRAME.
Definition: l1sap.h:12
PH-CONNECT.
Definition: l1sap.h:11