libosmogsm  0.11.0-dirty
Osmocom GSM library
include/osmocom/gsm/lapd_core.h
Go to the documentation of this file.
00001 
00004 #pragma once
00005 
00006 #include <stdint.h>
00007 
00008 #include <osmocom/core/timer.h>
00009 #include <osmocom/core/msgb.h>
00010 #include <osmocom/gsm/prim.h>
00011 
00018 enum osmo_dl_prim {
00019         PRIM_DL_UNIT_DATA,      
00020         PRIM_DL_DATA,           
00021         PRIM_DL_EST,            
00022         PRIM_DL_REL,            
00023         PRIM_DL_SUSP,           
00024         PRIM_DL_RES,            
00025         PRIM_DL_RECON,          
00026         PRIM_MDL_ERROR,         
00027 };
00028 
00029 /* Uses the same values as RLL, so no conversion for GSM is required. */
00030 #define MDL_CAUSE_T200_EXPIRED          0x01
00031 #define MDL_CAUSE_REEST_REQ             0x02
00032 #define MDL_CAUSE_UNSOL_UA_RESP         0x03
00033 #define MDL_CAUSE_UNSOL_DM_RESP         0x04
00034 #define MDL_CAUSE_UNSOL_DM_RESP_MF      0x05
00035 #define MDL_CAUSE_UNSOL_SPRV_RESP       0x06
00036 #define MDL_CAUSE_SEQ_ERR               0x07
00037 #define MDL_CAUSE_UFRM_INC_PARAM        0x08
00038 #define MDL_CAUSE_SFRM_INC_PARAM        0x09
00039 #define MDL_CAUSE_IFRM_INC_MBITS        0x0a
00040 #define MDL_CAUSE_IFRM_INC_LEN          0x0b
00041 #define MDL_CAUSE_FRM_UNIMPL            0x0c
00042 #define MDL_CAUSE_SABM_MF               0x0d
00043 #define MDL_CAUSE_SABM_INFO_NOTALL      0x0e
00044 #define MDL_CAUSE_FRMR                  0x0f
00045 
00047 struct mdl_error_ind_param {
00048         uint8_t cause;          
00049 };
00050 
00052 struct dl_rel_req_param {
00053         uint8_t mode;           
00054 };
00055 
00057 struct osmo_dlsap_prim {
00058         struct osmo_prim_hdr oph; 
00059         union {
00060                 struct mdl_error_ind_param error_ind;
00061                 struct dl_rel_req_param rel_req;
00062         } u;                    
00063 };
00064 
00066 enum lapd_mode {
00067         LAPD_MODE_USER,         
00068         LAPD_MODE_NETWORK,      
00069 };
00070 
00072 enum lapd_state {
00073         LAPD_STATE_NULL = 0,
00074         LAPD_STATE_TEI_UNASS,
00075         LAPD_STATE_ASS_TEI_WAIT,
00076         LAPD_STATE_EST_TEI_WAIT,
00077         LAPD_STATE_IDLE,
00078         LAPD_STATE_SABM_SENT,
00079         LAPD_STATE_DISC_SENT,
00080         LAPD_STATE_MF_EST,
00081         LAPD_STATE_TIMER_RECOV,
00082 };
00083 
00085 enum lapd_format {
00086         LAPD_FORM_UKN = 0,
00087         LAPD_FORM_I,
00088         LAPD_FORM_S,
00089         LAPD_FORM_U,
00090 };
00091 
00093 struct lapd_msg_ctx {
00094         struct lapd_datalink *dl;
00095         int n201;
00096         /* address */
00097         uint8_t cr;
00098         uint8_t sapi;
00099         uint8_t tei;
00100         uint8_t lpd;
00101         /* control */
00102         uint8_t format;
00103         uint8_t p_f; /* poll / final bit */
00104         uint8_t n_send;
00105         uint8_t n_recv;
00106         uint8_t s_u; /* S or repectivly U function bits */
00107         /* length */
00108         int     length;
00109         uint8_t more;
00110 };
00111 
00112 struct lapd_cr_ent {
00113         uint8_t cmd;
00114         uint8_t resp;
00115 };
00116 
00117 struct lapd_history {
00118         struct msgb *msg; /* message to be sent / NULL, if histoy is empty */
00119         int     more; /* if message is fragmented */
00120 };
00121 
00123 struct lapd_datalink {
00124         int (*send_dlsap)(struct osmo_dlsap_prim *dp,
00125                 struct lapd_msg_ctx *lctx);
00126         int (*send_ph_data_req)(struct lapd_msg_ctx *lctx, struct msgb *msg);
00127         int (*update_pending_frames)(struct lapd_msg_ctx *lctx);
00128         struct {
00130                 struct lapd_cr_ent loc2rem;
00131                 struct lapd_cr_ent rem2loc;
00132         } cr;
00133         enum lapd_mode mode; 
00134         int use_sabme; 
00135         int reestablish; 
00136         int n200, n200_est_rel; 
00137         struct lapd_msg_ctx lctx; 
00138         int maxf; 
00139         uint8_t k; 
00140         uint8_t v_range; 
00141         uint8_t v_send; 
00142         uint8_t v_ack;  
00143         uint8_t v_recv; 
00144         uint32_t state; 
00145         int seq_err_cond; 
00146         uint8_t own_busy; 
00147         uint8_t peer_busy; 
00148         int t200_sec, t200_usec; 
00149         int t203_sec, t203_usec; 
00150         struct osmo_timer_list t200; 
00151         struct osmo_timer_list t203; 
00152         uint8_t retrans_ctr; 
00153         struct llist_head tx_queue; 
00154         struct llist_head send_queue; 
00155         struct msgb *send_buffer; 
00156         int send_out; 
00157         struct lapd_history *tx_hist; 
00158         uint8_t range_hist; 
00159         struct msgb *rcv_buffer; 
00160         struct msgb *cont_res; 
00161 };
00162 
00163 void lapd_dl_init(struct lapd_datalink *dl, uint8_t k, uint8_t v_range,
00164         int maxf);
00165 void lapd_dl_exit(struct lapd_datalink *dl);
00166 void lapd_dl_reset(struct lapd_datalink *dl);
00167 int lapd_set_mode(struct lapd_datalink *dl, enum lapd_mode mode);
00168 int lapd_ph_data_ind(struct msgb *msg, struct lapd_msg_ctx *lctx);
00169 int lapd_recv_dlsap(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx);
00170 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines