libosmogsm  0.12.0
Osmocom GSM library
lapdm.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <osmocom/gsm/l1sap.h>
5 
11 enum lapdm_mode {
14 };
15 
16 struct lapdm_entity;
17 
19 struct lapdm_msg_ctx {
20  struct lapdm_datalink *dl;
21  int lapdm_fmt;
22  uint8_t chan_nr;
23  uint8_t link_id;
24  uint8_t ta_ind; /* TA indicated by network */
25  uint8_t tx_power_ind; /* MS power indicated by network */
26 };
27 
30  struct lapd_datalink dl; /* common LAPD */
33  struct lapdm_entity *entity;
34 };
35 
38  DL_SAPI0 = 0,
39  DL_SAPI3 = 1,
41 };
42 
43 typedef int (*lapdm_cb_t)(struct msgb *msg, struct lapdm_entity *le, void *ctx);
44 
45 #define LAPDM_ENT_F_EMPTY_FRAME 0x0001
46 #define LAPDM_ENT_F_POLLING_ONLY 0x0002
47 
49 struct lapdm_entity {
53  int tx_pending;
55  unsigned int flags;
56 
57  void *l1_ctx;
58  void *l3_ctx;
60  osmo_prim_cb l1_prim_cb;
65 
66  uint8_t ta; /* TA used and indicated to network */
67  uint8_t tx_power; /* MS power used and indicated to network */
68 };
69 
71 struct lapdm_channel {
72  struct llist_head list;
73  char *name;
76 };
77 
78 const char *get_rsl_name(int value);
79 extern const char *lapdm_state_names[];
80 
81 struct lapdm_datalink *lapdm_datalink_for_sapi(struct lapdm_entity *le, uint8_t sapi);
82 
83 /* initialize a LAPDm entity */
84 void lapdm_entity_init(struct lapdm_entity *le, enum lapdm_mode mode, int t200);
85 void lapdm_channel_init(struct lapdm_channel *lc, enum lapdm_mode mode);
86 
87 /* deinitialize a LAPDm entity */
88 void lapdm_entity_exit(struct lapdm_entity *le);
89 void lapdm_channel_exit(struct lapdm_channel *lc);
90 
91 /* input into layer2 (from layer 1) */
92 int lapdm_phsap_up(struct osmo_prim_hdr *oph, struct lapdm_entity *le);
93 
94 /* input into layer2 (from layer 3) */
95 int lapdm_rslms_recvmsg(struct msgb *msg, struct lapdm_channel *lc);
96 
97 void lapdm_channel_set_l3(struct lapdm_channel *lc, lapdm_cb_t cb, void *ctx);
98 void lapdm_channel_set_l1(struct lapdm_channel *lc, osmo_prim_cb cb, void *ctx);
99 
100 int lapdm_entity_set_mode(struct lapdm_entity *le, enum lapdm_mode mode);
102 
103 void lapdm_entity_reset(struct lapdm_entity *le);
104 void lapdm_channel_reset(struct lapdm_channel *lc);
105 
106 void lapdm_entity_set_flags(struct lapdm_entity *le, unsigned int flags);
107 void lapdm_channel_set_flags(struct lapdm_channel *lc, unsigned int flags);
108 
109 int lapdm_phsap_dequeue_prim(struct lapdm_entity *le, struct osmo_phsap_prim *pp);
110 
lapdm_channel_set_mode
int lapdm_channel_set_mode(struct lapdm_channel *lc, enum lapdm_mode mode)
Set the lapdm_mode of a LAPDm channel.
Definition: lapdm.c:1327
lapdm_entity::last_tx_dequeue
int last_tx_dequeue
last entity that was dequeued
Definition: lapdm.h:52
get_rsl_name
const char * get_rsl_name(int value)
lapdm_channel_set_flags
void lapdm_channel_set_flags(struct lapdm_channel *lc, unsigned int flags)
Set the flags of all LAPDm entities in a LAPDm channel.
Definition: lapdm.c:1382
osmo_phsap_prim
primitive header for PH-SAP primitives
Definition: l1sap.h:154
LAPDM_MODE_MS
@ LAPDM_MODE_MS
behave like a MS (mobile phone)
Definition: lapdm.h:12
lapdm_entity::mode
enum lapdm_mode mode
are we in BTS mode or MS mode
Definition: lapdm.h:54
lapdm_entity::tx_power
uint8_t tx_power
Definition: lapdm.h:67
l1sap.h
lapdm_channel::lapdm_dcch
struct lapdm_entity lapdm_dcch
Dedicated Control Channel.
Definition: lapdm.h:75
lapdm_msg_ctx::lapdm_fmt
int lapdm_fmt
Definition: lapdm.h:21
lapdm_channel_reset
void lapdm_channel_reset(struct lapdm_channel *lc)
Reset a LAPDm channel with all its entities.
Definition: lapdm.c:1369
lapdm_dl_sapi
lapdm_dl_sapi
LAPDm datalink SAPIs.
Definition: lapdm.h:37
lapdm_msg_ctx::ta_ind
uint8_t ta_ind
Definition: lapdm.h:24
lapdm_msg_ctx::tx_power_ind
uint8_t tx_power_ind
Definition: lapdm.h:25
lapdm_channel_exit
void lapdm_channel_exit(struct lapdm_channel *lc)
Definition: lapdm.c:197
lapdm_entity::l3_ctx
void * l3_ctx
context for layer3 instance
Definition: lapdm.h:58
lapdm_phsap_dequeue_prim
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
Definition: lapdm.c:297
lapdm_entity::flags
unsigned int flags
Definition: lapdm.h:55
lapdm_rslms_recvmsg
int lapdm_rslms_recvmsg(struct msgb *msg, struct lapdm_channel *lc)
Receive a RSLms msgb from Layer 3.
Definition: lapdm.c:1273
lapdm_phsap_up
int lapdm_phsap_up(struct osmo_prim_hdr *oph, struct lapdm_entity *le)
Receive a PH-SAP primitive from L1.
Definition: lapdm.c:771
lapdm_entity_init
void lapdm_entity_init(struct lapdm_entity *le, enum lapdm_mode mode, int t200)
initialize a LAPDm entity and all datalinks inside
Definition: lapdm.c:154
lapdm_channel
the two lapdm_entities that form a GSM logical channel (ACCH + DCCH)
Definition: lapdm.h:71
DL_SAPI0
@ DL_SAPI0
SAPI 0.
Definition: lapdm.h:38
mode
uint8_t mode
Definition: gsm_04_08.h:633
LAPDM_MODE_BTS
@ LAPDM_MODE_BTS
behave like a BTS (network)
Definition: lapdm.h:13
lapdm_channel_set_l1
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.
Definition: lapdm.c:1339
_NR_DL_SAPI
@ _NR_DL_SAPI
Definition: lapdm.h:40
lapdm_channel_set_l3
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.
Definition: lapdm.c:1348
lapdm_entity::l1_prim_cb
osmo_prim_cb l1_prim_cb
callback for sending prims to L1
Definition: lapdm.h:60
lapdm_entity::tx_pending
int tx_pending
currently a pending frame not confirmed by L1
Definition: lapdm.h:53
lapdm_msg_ctx::link_id
uint8_t link_id
Definition: lapdm.h:23
lapdm_entity::l1_ctx
void * l1_ctx
context for layer1 instance
Definition: lapdm.h:57
lapdm_entity
a LAPDm Entity
Definition: lapdm.h:49
lapdm_channel::list
struct llist_head list
internal linked list
Definition: lapdm.h:72
lapdm_datalink_for_sapi
struct lapdm_datalink * lapdm_datalink_for_sapi(struct lapdm_entity *le, uint8_t sapi)
Definition: lapdm.c:203
lapdm_state_names
const char * lapdm_state_names[]
lapdm_entity_exit
void lapdm_entity_exit(struct lapdm_entity *le)
flush and release all resoures in LAPDm entity
Definition: lapdm.c:181
DL_SAPI3
@ DL_SAPI3
SAPI 1.
Definition: lapdm.h:39
lapdm_entity::l3_cb
lapdm_cb_t l3_cb
callback for sending stuff to L3
Definition: lapdm.h:61
lapdm_msg_ctx::chan_nr
uint8_t chan_nr
Definition: lapdm.h:22
lapdm_entity::datalink
struct lapdm_datalink datalink[_NR_DL_SAPI]
the SAPIs of the LAPDm entity
Definition: lapdm.h:51
lapdm_entity_reset
void lapdm_entity_reset(struct lapdm_entity *le)
Reset an entire LAPDm entity and all its datalinks.
Definition: lapdm.c:1357
lapdm_channel::lapdm_acch
struct lapdm_entity lapdm_acch
Associated Control Channel.
Definition: lapdm.h:74
lapdm_channel::name
char * name
human-readable name
Definition: lapdm.h:73
lapdm_entity_set_flags
void lapdm_entity_set_flags(struct lapdm_entity *le, unsigned int flags)
Set the flags of a LAPDm entity.
Definition: lapdm.c:1376
lapdm_entity_set_mode
int lapdm_entity_set_mode(struct lapdm_entity *le, enum lapdm_mode mode)
Set the lapdm_mode of a LAPDm entity.
Definition: lapdm.c:1301
lapdm_channel_init
void lapdm_channel_init(struct lapdm_channel *lc, enum lapdm_mode mode)
initialize a LAPDm channel and all its channels
Definition: lapdm.c:171
lapdm_entity::ta
uint8_t ta
Definition: lapdm.h:66
lapdm_msg_ctx
LAPDm message context.
Definition: lapdm.h:19
lapdm_mode
lapdm_mode
LAPDm mode/role.
Definition: lapdm.h:11
lapdm_entity::lapdm_ch
struct lapdm_channel * lapdm_ch
pointer to lapdm_channel of which we're part
Definition: lapdm.h:64
lapd_core.h
lapdm_msg_ctx::dl
struct lapdm_datalink * dl
Definition: lapdm.h:20
lapdm_cb_t
int(* lapdm_cb_t)(struct msgb *msg, struct lapdm_entity *le, void *ctx)
Definition: lapdm.h:43