large refactoring: use FSMs for lchans; add inter-BSC HO

Add FSMs:

- timeslot_fsm: handle dynamic timeslots and OML+RSL availability.
- lchan_fsm: handle an individual lchan activation, RTP stream and release,
  signal the appropriate calling FSMs on success, failure, release.
- mgw_endpoint_fsm: handle one entire endpoint with several CI.
- assignment_fsm: BSSMAP Assignment Request.
- handover_fsm: all of intra, inter-MO and inter-MT handover.

Above FSMs absorb large parts of the gscon FSM. The gscon FSM was surpassing
the maximum amount events (32), and it is more logical to treat assignment,
handover and MGW procedures in separate FSMs.

- Add logging macros for each FSM type:
  - LOG_TS()
  - LOG_LCHAN()
  - LOG_MGWEP(), LOG_CI()
  - LOG_ASSIGNMENT()
  - LOG_HO()
  These log with the osmo_fsm_inst where present.
  New style decision: logging without a final newline char is awkward,
  especially for gsmtap logging and when other logs interleave LOGPC() calls;
  we have various cases where the final \n goes missing, and also this invokes
  the log category checking N times instead of once.
  So I decided to make these macros *always* append a newline, but only if
  there is no final newline yet. I hope that the compiler optimizes the
  strlen() of the constant format strings away. Thus I can log with or without
  typing "\n" and always get an \n termination anyway.

General:

- replace osmo_timers, state enums and program-wide osmo_signal_dispatch()
  with dedicated FSM timeouts, states and events.

- introduce a common way to handle Tnnn timers: gsm_timers.h/.c: struct T_def.
  These can be used (with some macro magic) to define a state's timeout once,
  and not make mistakes for each osmo_fsm_inst_state_chg().

Details:

bsc_subscr_conn_fsm.c:

- move most states of this FSM to lchan_fsm, assignment_fsm, handover_fsm and
  mgw_endpoint_fsm.

- There is exactly one state for an ongoing Assignment, with all details
  handled in conn->assignment.fi. The state relies on the assignment_fsm's
  timeout.

- There is one state for an ongoing Handover; except for an incoming Handover
  from a remote BSS, the gscon remains in ST_INIT until the new lchan and conn
  are both established.

- move bssmap_add_lcls_status() to osmo_bsc_lcls.c

abis_rsl.c:

- move all dynamic timeslot logic away into timeslot_fsm. Only keep plain send/receive functions in
  abis_rsl.c

- reduce some rsl functions to merely send a message, rename to "_tx_".
  - rsl_ipacc_mdcx(): add '_tx_' in the name; move parts that change the lchan state out into the
    lchan_fsm, the lchan->abis_ip.* are now set there prior to invoking this function.

- move all timers and error/release handling away into various FSMs.

- tweak ipa_smod_s_for_lchan() and ipa_rtp_pt_for_lchan() to not require an
  lchan passed, but just mode,type that they require. Rename to
  ipacc_speech_mode*() and ipacc_payload_type().

- add rsl_forward_layer3_info, used for inter-BSC HO MO, to just send the RR
  message received during BSSMAP Handover Command.

- move various logging to LOG_LCHAN() in order to log with the lchan FSM instance.
  One drawback is that the lchan FSM is limited to one logging category, i.e. this moves some logging
  from DRR to DRSL. It might actually make sense to combine those categories.

- lose LOGP...LOGPC logging cascades: they are bad for gsmtap logging and for performance.

- handle_classmark_chg(): change logging, move cm2 len check out of the cm3 condition (I hope that's
  correct).

- gsm48_send_ho_cmd(): split off gsm48_make_ho_cmd() which doesn't send right away, so that during
  inter-bsc HO we can make an RR Handover Command to send via the MSC to the remote BSS.

assignment_fsm.c:

- the Chan Mode Modify in case of re-using the same lchan is not implemented
  yet, because this was also missing in the previous implementation (OS#3357).

osmo_bsc_api.c:

- simplify bsc_mr_config() and move to lchan_fsm.c, the only caller; rename to
  lchan_mr_config(). (bsc_mr_config() used to copy the values to mr_bts_lv
  twice, once by member assignment and then again with a memcpy.)

- During handover, we used to copy the MR config from the old lchan. Since we
  may handover between FR and HR, rather set the MR Config anew every time, so
  that FR rates are always available on FR lchans, and never on HR lchans.

Depends: I03ee7ce840ecfa0b6a33358e7385528aabd4873f (libosmocore),
         I1f2918418c38918c5ac70acaa51a47adfca12b5e (libosmocore)
Change-Id: I82e3f918295daa83274a4cf803f046979f284366
This commit is contained in:
Neels Hofmeyr 2018-05-14 18:14:15 +02:00
parent 596c402835
commit 31f525e756
75 changed files with 8461 additions and 4784 deletions

View File

@ -5,6 +5,7 @@ noinst_HEADERS = \
abis_rsl.h \
acc_ramp.h \
arfcn_range_encode.h \
assignment_fsm.h \
bsc_msg_filter.h \
bsc_rll.h \
bsc_subscriber.h \
@ -24,11 +25,15 @@ noinst_HEADERS = \
handover_cfg.h \
handover_decision.h \
handover_decision_2.h \
handover_fsm.h \
handover_vty.h \
ipaccess.h \
lchan_fsm.h \
lchan_select.h \
meas_feed.h \
meas_rep.h \
misdn.h \
mgw_endpoint_fsm.h \
neighbor_ident.h \
network_listen.h \
openbscdefines.h \
@ -45,6 +50,7 @@ noinst_HEADERS = \
rs232.h \
signal.h \
system_information.h \
timeslot_fsm.h \
ussd.h \
vty.h \
bsc_api.h \

View File

@ -35,19 +35,18 @@ struct gsm_bts_trx_ts;
#define GSM48_LEN2PLEN(a) (((a) << 2) | 1)
#define rsl_lchan_set_state(lch_, st_) \
rsl_lchan_set_state_with_log(lch_, st_, __BASE_FILE__, __LINE__)
int rsl_bcch_info(const struct gsm_bts_trx *trx, enum osmo_sysinfo_type si_type, const uint8_t *data, int len);
int rsl_sacch_filling(struct gsm_bts_trx *trx, uint8_t type,
const uint8_t *data, int len);
int rsl_chan_activate_lchan(struct gsm_lchan *lchan, uint8_t act_type,
uint8_t ho_ref);
int rsl_tx_chan_activ(struct gsm_lchan *lchan, uint8_t act_type, uint8_t ho_ref);
int rsl_chan_mode_modify_req(struct gsm_lchan *ts);
int rsl_encryption_cmd(struct msgb *msg);
int rsl_paging_cmd(struct gsm_bts *bts, uint8_t paging_group, uint8_t len,
uint8_t *ms_ident, uint8_t chan_needed, bool is_gprs);
int rsl_imm_assign_cmd(struct gsm_bts *bts, uint8_t len, uint8_t *val);
int rsl_tx_imm_assignment(struct gsm_lchan *lchan);
int rsl_tx_imm_ass_rej(struct gsm_bts *bts, struct gsm48_req_ref *rqd_ref);
int gsm48_send_rr_ass_cmd(struct gsm_lchan *dest_lchan, struct gsm_lchan *lchan, uint8_t power_command);
int rsl_data_request(struct msgb *msg, uint8_t link_id);
int rsl_establish_request(struct gsm_lchan *lchan, uint8_t link_id);
@ -60,9 +59,8 @@ int rsl_ericsson_imm_assign_cmd(struct gsm_bts *bts, uint32_t tlli, uint8_t len,
int rsl_siemens_mrpci(struct gsm_lchan *lchan, struct rsl_mrpci *mrpci);
/* ip.access specfic RSL extensions */
int rsl_ipacc_crcx(struct gsm_lchan *lchan);
int rsl_ipacc_mdcx(struct gsm_lchan *lchan, uint32_t ip,
uint16_t port, uint8_t rtp_payload2);
int rsl_tx_ipacc_crcx(struct gsm_lchan *lchan);
int rsl_tx_ipacc_mdcx(struct gsm_lchan *lchan);
int rsl_ipacc_mdcx_to_rtpsock(struct gsm_lchan *lchan);
int rsl_ipacc_pdch_activate(struct gsm_bts_trx_ts *ts, int act);
@ -71,7 +69,6 @@ int abis_rsl_rcvmsg(struct msgb *msg);
int rsl_release_request(struct gsm_lchan *lchan, uint8_t link_id,
enum rsl_rel_mode release_mode);
int rsl_lchan_set_state_with_log(struct gsm_lchan *lchan, enum gsm_lchan_state state, const char *file, unsigned line);
int rsl_lchan_mark_broken(struct gsm_lchan *lchan, const char *broken);
/* to be provided by external code */
@ -106,9 +103,15 @@ int rsl_start_t3109(struct gsm_lchan *lchan);
int rsl_direct_rf_release(struct gsm_lchan *lchan);
void dyn_ts_init(struct gsm_bts_trx_ts *ts);
int dyn_ts_switchover_start(struct gsm_bts_trx_ts *ts,
enum gsm_phys_chan_config to_pchan);
int rsl_tx_dyn_ts_pdch_act_deact(struct gsm_bts_trx_ts *ts, bool activate);
int rsl_forward_layer3_info(struct gsm_lchan *lchan, const uint8_t *l3_info, uint8_t l3_info_len);
int ipacc_speech_mode(enum gsm48_chan_mode tch_mode, enum gsm_chan_t type);
void ipacc_speech_mode_set_direction(uint8_t *speech_mode, bool send);
int ipacc_payload_type(enum gsm48_chan_mode tch_mode, enum gsm_chan_t type);
int rsl_tx_rf_chan_release(struct gsm_lchan *lchan);
#endif /* RSL_MT_H */

View File

@ -0,0 +1,44 @@
/* osmo-bsc API to manage BSSMAP Assignment Command */
#pragma once
#include <osmocom/gsm/protocol/gsm_04_08.h>
#include <osmocom/bsc/debug.h>
/* This macro automatically includes a final \n, if omitted. */
#define LOG_ASSIGNMENT(conn, level, fmt, args...) do { \
if (conn->assignment.fi) \
LOGPFSML(conn->assignment.fi, level, "%s%s" fmt, \
conn->assignment.new_lchan ? gsm_lchan_name(conn->assignment.new_lchan) : "", \
conn->assignment.new_lchan ? " " : "", \
## args); \
else \
LOGP(DMSC, level, "Assignment%s%s: " fmt, \
conn->assignment.new_lchan ? " of " : "", \
conn->assignment.new_lchan ? gsm_lchan_name(conn->assignment.new_lchan) : "", \
## args); \
} while(0)
enum assignment_fsm_state {
ASSIGNMENT_ST_WAIT_LCHAN_ACTIVE,
ASSIGNMENT_ST_WAIT_RR_ASS_COMPLETE,
ASSIGNMENT_ST_WAIT_LCHAN_ESTABLISHED,
ASSIGNMENT_ST_WAIT_MGW_ENDPOINT_TO_MSC,
};
enum assignment_fsm_event {
ASSIGNMENT_EV_LCHAN_ACTIVE,
ASSIGNMENT_EV_LCHAN_ESTABLISHED,
ASSIGNMENT_EV_LCHAN_ERROR,
ASSIGNMENT_EV_MSC_MGW_OK,
ASSIGNMENT_EV_MSC_MGW_FAIL,
ASSIGNMENT_EV_RR_ASSIGNMENT_COMPLETE,
ASSIGNMENT_EV_RR_ASSIGNMENT_FAIL,
ASSIGNMENT_EV_CONN_RELEASING,
};
void assignment_fsm_init();
void assignment_fsm_start(struct gsm_subscriber_connection *conn, struct gsm_bts *bts,
struct assignment_request *req);
void assignment_reset(struct gsm_subscriber_connection *conn);

View File

@ -12,15 +12,13 @@ void bsc_sapi_n_reject(struct gsm_subscriber_connection *conn, int dlci);
void bsc_cipher_mode_compl(struct gsm_subscriber_connection *conn, struct msgb *msg, uint8_t chosen_encr);
int bsc_compl_l3(struct gsm_subscriber_connection *conn, struct msgb *msg, uint16_t chosen_channel);
void bsc_dtap(struct gsm_subscriber_connection *conn, uint8_t link_id, struct msgb *msg);
void bsc_assign_compl(struct gsm_subscriber_connection *conn, uint8_t rr_cause);
void bsc_assign_fail(struct gsm_subscriber_connection *conn, uint8_t cause, uint8_t *rr_cause);
int bsc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause);
void bsc_cm_update(struct gsm_subscriber_connection *conn,
const uint8_t *cm2, uint8_t cm2_len,
const uint8_t *cm3, uint8_t cm3_len);
void bsc_mr_config(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan, int full_rate);
int gsm0808_submit_dtap(struct gsm_subscriber_connection *conn, struct msgb *msg, int link_id, int allow_sacch);
int gsm0808_submit_dtap(struct gsm_subscriber_connection *conn, struct msgb *msg, uint8_t link_id,
bool allow_sacch);
int gsm0808_assign_req(struct gsm_subscriber_connection *conn, int chan_mode, int full_rate);
int gsm0808_cipher_mode(struct gsm_subscriber_connection *conn, int cipher,
const uint8_t *key, int len, int include_imeisv);
@ -28,4 +26,5 @@ int gsm0808_page(struct gsm_bts *bts, unsigned int page_group,
unsigned int mi_len, uint8_t *mi, int chan_type);
int gsm0808_clear(struct gsm_subscriber_connection *conn);
bool msc_connected(struct gsm_subscriber_connection *conn);
#endif

View File

@ -48,11 +48,6 @@
struct osmo_bsc_rf;
struct gsm_network;
struct gsm_audio_support {
uint8_t hr : 1,
ver : 7;
};
enum {
MSC_CON_TYPE_NORMAL,
MSC_CON_TYPE_LOCAL,

View File

@ -8,28 +8,20 @@ enum gscon_fsm_event {
GSCON_EV_A_CONN_REQ,
/* MSC confirms the SCCP connection */
GSCON_EV_A_CONN_CFM,
/* MSC requests assignment */
GSCON_EV_A_ASSIGNMENT_CMD,
/* MSC has sent BSSMAP CLEAR CMD */
GSCON_EV_A_CLEAR_CMD,
/* MSC SCCP disconnect indication */
GSCON_EV_A_DISC_IND,
/* MSC sends Handover Request (in CR) */
GSCON_EV_A_HO_REQ,
/* RR ASSIGNMENT COMPLETE received */
GSCON_EV_RR_ASS_COMPL,
/* RR ASSIGNMENT FAIL received */
GSCON_EV_RR_ASS_FAIL,
GSCON_EV_ASSIGNMENT_START,
GSCON_EV_ASSIGNMENT_END,
GSCON_EV_HANDOVER_START,
GSCON_EV_HANDOVER_END,
/* RSL RLL Release Indication */
GSCON_EV_RLL_REL_IND,
/* RSL CONNection FAILure Indication */
GSCON_EV_RSL_CONN_FAIL,
/* RSL/lchan tells us clearing is complete */
GSCON_EV_RSL_CLEAR_COMPL,
/* Mobile-originated DTAP (from MS) */
GSCON_EV_MO_DTAP,
/* Mobile-terminated DTAP (from MSC) */
@ -38,42 +30,53 @@ enum gscon_fsm_event {
/* Transmit custom SCCP message */
GSCON_EV_TX_SCCP,
/* MGW is indicating failure (BTS) */
GSCON_EV_MGW_FAIL_BTS,
/* MGW is indicating failure (MSC) */
GSCON_EV_MGW_FAIL_MSC,
/* CRCX response received (BTS) */
GSCON_EV_MGW_CRCX_RESP_BTS,
/* MDCX response received (BTS) */
GSCON_EV_MGW_MDCX_RESP_BTS,
/* CRCX response received (MSC) */
GSCON_EV_MGW_CRCX_RESP_MSC,
/* MDCX response received (MSC) - triggered by LCLS */
GSCON_EV_MGW_MDCX_RESP_MSC,
/* Internal handover request (intra-BSC handover) */
GSCON_EV_HO_START,
/* Handover timed out (T3103 in handover_logic.c) */
GSCON_EV_HO_TIMEOUT,
/* Handover failed (handover_logic.c) */
GSCON_EV_HO_FAIL,
/* Handover completed successfully (handover_logic.c) */
GSCON_EV_HO_COMPL,
/* LCLS child FSM has terminated due to hard failure */
GSCON_EV_LCLS_FAIL,
GSCON_EV_FORGET_LCHAN,
GSCON_EV_FORGET_MGW_ENDPOINT,
};
struct gsm_subscriber_connection;
struct gsm_network;
struct mgcp_conn_peer;
struct msgb;
struct mgwep_ci;
struct assignment_request;
struct gsm_lchan;
void bsc_subscr_conn_fsm_init();
/* Allocate a subscriber connection and its associated FSM */
struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_network *net);
void bsc_subscr_pick_codec(struct mgcp_conn_peer *conn_peer, struct gsm_subscriber_connection *conn);
void gscon_update_id(struct gsm_subscriber_connection *conn);
void gscon_submit_rsl_dtap(struct gsm_subscriber_connection *conn,
struct msgb *msg, int link_id, int allow_sacch);
void gscon_dtap_queue_flush(struct gsm_subscriber_connection *conn, int send);
int gscon_sigtran_send(struct gsm_subscriber_connection *conn, struct msgb *msg);
struct mgw_endpoint *gscon_ensure_mgw_endpoint(struct gsm_subscriber_connection *conn,
uint16_t msc_assigned_cic);
bool gscon_connect_mgw_to_msc(struct gsm_subscriber_connection *conn,
struct gsm_lchan *for_lchan,
const char *addr, uint16_t port,
struct osmo_fsm_inst *notify,
uint32_t event_success, uint32_t event_failure,
void *notify_data,
struct mgwep_ci **created_ci);
void gscon_start_assignment(struct gsm_subscriber_connection *conn,
struct assignment_request *req);
void gscon_change_primary_lchan(struct gsm_subscriber_connection *conn, struct gsm_lchan *new_lchan);
void gscon_release_lchans(struct gsm_subscriber_connection *conn, bool do_sacch_deact);
void gscon_lchan_releasing(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan);
void gscon_forget_lchan(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan);
void gscon_forget_mgw_endpoint_ci(struct gsm_subscriber_connection *conn, struct mgwep_ci *ci);
bool gscon_is_aoip(struct gsm_subscriber_connection *conn);
bool gscon_is_sccplite(struct gsm_subscriber_connection *conn);

View File

@ -19,6 +19,7 @@ struct bsc_subscr {
};
const char *bsc_subscr_name(struct bsc_subscr *bsub);
const char *bsc_subscr_id(struct bsc_subscr *bsub);
struct bsc_subscr *bsc_subscr_find_or_create_by_imsi(struct llist_head *list,
const char *imsi);

View File

@ -24,18 +24,11 @@
struct gsm_subscriber_connection;
/* Count number of free TS of given pchan type */
int bts_count_free_ts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan);
/* Allocate a logical channel (SDCCH, TCH, ...) */
struct gsm_lchan *lchan_alloc(struct gsm_bts *bts, enum gsm_chan_t type, int allow_bigger);
/* Free a logical channel (SDCCH, TCH, ...) */
void lchan_free(struct gsm_lchan *lchan);
void lchan_reset(struct gsm_lchan *lchan);
/* Release the given lchan */
int lchan_release(struct gsm_lchan *lchan, int sacch_deact, enum rsl_rel_mode release_mode);
struct pchan_load {
struct load_counter pchan[_GSM_PCHAN_MAX];
@ -45,6 +38,4 @@ void bts_chan_load(struct pchan_load *cl, const struct gsm_bts *bts);
void network_chan_load(struct pchan_load *pl, struct gsm_network *net);
void bts_update_t3122_chan_load(struct gsm_bts *bts);
bool ts_is_usable(const struct gsm_bts_trx_ts *ts);
#endif /* _CHAN_ALLOC_H */

View File

@ -1,6 +1,17 @@
#pragma once
struct gsm_bts;
#include <stdbool.h>
#include <osmocom/gsm/protocol/gsm_04_08.h>
int match_codec_pref(int *full_rate, enum gsm48_chan_mode *chan_mode, const struct gsm0808_channel_type *ct,
const struct gsm0808_speech_codec_list *scl, const struct bsc_msc_data *msc, struct gsm_bts *bts);
struct gsm0808_channel_type;
struct gsm0808_speech_codec_list;
struct gsm_audio_support;
struct bts_codec_conf;
int match_codec_pref(enum gsm48_chan_mode *chan_mode,
bool *full_rate,
const struct gsm0808_channel_type *ct,
const struct gsm0808_speech_codec_list *scl,
struct gsm_audio_support * const *audio_support,
int audio_length,
const struct bts_codec_conf *bts_codec);

View File

@ -12,6 +12,7 @@ int gsm48_send_rr_ciph_mode(struct gsm_lchan *lchan, int want_imeisv);
void gsm48_lchan2chan_desc(struct gsm48_chan_desc *cd,
const struct gsm_lchan *lchan);
int gsm48_multirate_config(uint8_t *lv, const struct amr_multirate_conf *mr, const struct amr_mode *modes);
struct msgb *gsm48_make_ho_cmd(struct gsm_lchan *new_lchan, uint8_t power_command, uint8_t ho_ref);
int gsm48_send_ho_cmd(struct gsm_lchan *old_lchan, struct gsm_lchan *new_lchan,
uint8_t power_command, uint8_t ho_ref);
int gsm48_send_rr_ass_cmd(struct gsm_lchan *dest_lchan, struct gsm_lchan *lchan, uint8_t power_command);
@ -42,4 +43,5 @@ static inline struct msgb *gsm48_msgb_alloc_name(const char *name)
uint64_t str_to_imsi(const char *imsi_str);
int gsm48_sendmsg(struct msgb *msg);
int gsm0408_rcvmsg(struct msgb *msg, uint8_t link_id);

View File

@ -14,13 +14,13 @@
#include <osmocom/core/stat_item.h>
#include <osmocom/gsm/bts_features.h>
#include <osmocom/gsm/protocol/gsm_08_08.h>
#include <osmocom/gsm/gsm0808.h>
#include <osmocom/gsm/gsm48.h>
#include <osmocom/core/fsm.h>
#include <osmocom/crypt/auth.h>
#include <osmocom/bsc/rest_octets.h>
#include <osmocom/bsc/handover.h>
#include <osmocom/core/bitvec.h>
#include <osmocom/gsm/gsm_utils.h>
@ -31,6 +31,8 @@
#include <osmocom/bsc/meas_rep.h>
#include <osmocom/bsc/bsc_msg_filter.h>
#include <osmocom/bsc/acc_ramp.h>
#include <osmocom/bsc/gsm_timers.h>
#include <osmocom/bsc/neighbor_ident.h>
#define GSM_T3122_DEFAULT 10
@ -38,6 +40,7 @@ struct mgcp_client_conf;
struct mgcp_client;
struct mgcp_ctx;
struct gsm0808_cell_id;
struct mgw_endpoint;
/** annotations for msgb ownership */
#define __uses
@ -46,6 +49,7 @@ struct gsm0808_cell_id;
struct bsc_subscr;
struct gprs_ra_id;
struct handover;
#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
@ -95,6 +99,96 @@ enum subscr_sccp_state {
SUBSCR_SCCP_ST_CONNECTED
};
struct assignment_request {
bool aoip;
uint16_t msc_assigned_cic;
char msc_rtp_addr[INET_ADDRSTRLEN];
uint16_t msc_rtp_port;
enum gsm48_chan_mode chan_mode;
bool full_rate;
};
struct assignment_fsm_data {
struct assignment_request req;
bool requires_voice_stream;
struct osmo_fsm_inst *fi;
struct gsm_lchan *new_lchan;
/* Whether this assignment triggered creation of the MGW endpoint: if the assignment
* fails, we will release that again as soon as possible. (If false, the endpoint already
* existed before or isn't needed at all.)*/
struct mgwep_ci *created_ci_for_msc;
enum gsm0808_cause failure_cause;
enum gsm48_rr_cause rr_cause;
bool result_rate_ctr_done;
};
enum hodec_id {
HODEC_NONE,
HODEC1 = 1,
HODEC2 = 2,
HODEC_USER,
HODEC_REMOTE,
};
/* For example, to count specific kinds of ongoing handovers, it is useful to be able to OR-combine
* scopes. */
enum handover_scope {
HO_NO_HANDOVER = 0,
HO_INTRA_CELL = 0x1,
HO_INTRA_BSC = 0x2,
HO_INTER_BSC_OUT = 0x4,
HO_INTER_BSC_IN = 0x8,
HO_SCOPE_ALL = 0xffff,
};
extern const struct value_string handover_scope_names[];
inline static const char *handover_scope_name(enum handover_scope val)
{ return get_value_string(handover_scope_names, val); }
struct handover_out_req {
enum hodec_id from_hodec_id;
struct gsm_lchan *old_lchan;
struct neighbor_ident_key target_nik;
enum gsm_chan_t new_lchan_type; /*< leave GSM_LCHAN_NONE to use same as old_lchan */
};
struct handover_in_req {
struct gsm0808_channel_type ct;
struct gsm0808_speech_codec_list scl;
struct gsm0808_encrypt_info ei;
struct gsm_classmark classmark;
struct gsm0808_cell_id cell_id_serving;
char cell_id_serving_name[64];
struct gsm0808_cell_id cell_id_target;
char cell_id_target_name[64];
uint16_t msc_assigned_cic;
char msc_assigned_rtp_addr[INET_ADDRSTRLEN];
uint16_t msc_assigned_rtp_port;
};
struct handover {
struct osmo_fsm_inst *fi;
enum hodec_id from_hodec_id;
enum handover_scope scope;
enum gsm_chan_t new_lchan_type;
struct neighbor_ident_key target_cell;
uint8_t ho_ref;
struct gsm_bts *new_bts;
struct gsm_lchan *new_lchan;
bool async;
struct handover_in_req inter_bsc_in;
struct mgwep_ci *created_ci_for_msc;
};
/* active radio connection of a mobile subscriber */
struct gsm_subscriber_connection {
/* global linked list of subscriber_connections */
@ -112,11 +206,10 @@ struct gsm_subscriber_connection {
/* the primary / currently active lchan to the BTS/subscriber */
struct gsm_lchan *lchan;
/* handover information, if a handover is pending for this conn. */
struct bsc_handover *ho;
struct assignment_fsm_data assignment;
/* the future allocated but not yet used lchan during ASSIGNMENT */
struct gsm_lchan *secondary_lchan;
/* handover information, if a handover is pending for this conn. */
struct handover ho;
/* buffer/cache for classmark of the ME of the subscriber */
struct gsm_classmark classmark;
@ -137,7 +230,6 @@ struct gsm_subscriber_connection {
* i.e. by heeding the "Codec list (MSC Preferred)", we inherently heed the MS bearer
* capabilities, which the MSC is required to translate into the codec list. */
struct gsm0808_speech_codec_list codec_list;
bool codec_list_present;
/* flag to prevent multiple simultaneous ciphering commands */
int ciphering_handled;
@ -163,29 +255,24 @@ struct gsm_subscriber_connection {
/* for audio handling */
struct {
uint16_t cic;
uint32_t rtp_ip;
int rtp_port;
/* RTP address of the remote end (assigned by MSC through assignment request) */
struct sockaddr_storage aoip_rtp_addr_remote;
uint16_t msc_assigned_cic;
/* Local RTP address (reported back to the MSC by us with the
* assignment complete message) */
struct sockaddr_storage aoip_rtp_addr_local;
/* RTP address where the MSC expects us to send the RTP stream coming from the BTS. */
char msc_assigned_rtp_addr[INET_ADDRSTRLEN];
uint16_t msc_assigned_rtp_port;
/* FSM instance to control the BTS sided RTP connection */
struct osmo_fsm_inst *fi_bts;
/* The endpoint at the MGW used to join both BTS and MSC side connections, e.g.
* "rtpbridge/23@mgw". */
struct mgw_endpoint *mgw_endpoint;
/* FSM instance to control the MSC sided RTP connection */
struct osmo_fsm_inst *fi_msc;
/* The connection identifier of the mgw_endpoint used to transceive RTP towards the MSC.
* (The BTS side CI is handled by struct gsm_lchan and the lchan_fsm.) */
struct mgwep_ci *mgw_endpoint_ci_msc;
/* Endpoint identifier of the MGCP endpoint the connection uses */
char *mgw_endpoint;
/* Channel rate flag, FR=1, HR=0, Invalid=-1 */
/* Channel rate flag requested by the MSC, FR=1, HR=0, Invalid=-1 */
int full_rate;
/* Channel mode flag (signaling or voice channel) */
/* Channel mode requested by the MSC (signalling or voice channel) */
enum gsm48_chan_mode chan_mode;
} user_plane;
@ -298,18 +385,6 @@ struct om2k_mo {
#define LCHAN_SAPI_UNUSED 0
#define LCHAN_SAPI_MS 1
#define LCHAN_SAPI_NET 2
#define LCHAN_SAPI_REL 3
/* state of a logical channel */
enum gsm_lchan_state {
LCHAN_S_NONE, /* channel is not active */
LCHAN_S_ACT_REQ, /* channel activation requested */
LCHAN_S_ACTIVE, /* channel is active and operational */
LCHAN_S_REL_REQ, /* channel release has been requested */
LCHAN_S_REL_ERR, /* channel is in an error state */
LCHAN_S_BROKEN, /* channel is somehow unusable */
LCHAN_S_INACTIVE, /* channel is set inactive */
};
/* BTS ONLY */
#define MAX_NUM_UL_MEAS 104
@ -386,11 +461,68 @@ struct gsm_encr {
bsc_subscr_name(lchan && lchan->conn ? lchan->conn->bsub : NULL), \
## args)
/* usage:
* struct gsm_lchan *lchan;
* struct gsm_bts_trx_ts *ts = get_some_timeslot();
* ts_for_each_lchan(lchan, ts) {
* LOGPLCHAN(DMAIN, LOGL_DEBUG, "hello world\n");
* }
* Iterate only those lchans that have an FSM allocated. */
#define ts_for_each_lchan(lchan, ts) ts_as_pchan_for_each_lchan(lchan, ts, (ts)->pchan_is)
/* Same as ts_for_each_lchan() but with an explicit pchan kind (GSM_PCHAN_* constant).
* Iterate only those lchans that have an FSM allocated. */
#define ts_as_pchan_for_each_lchan(lchan, ts, as_pchan) \
for (lchan = (ts)->lchan; \
((lchan - (ts)->lchan) < ARRAY_SIZE((ts)->lchan)) \
&& lchan->fi \
&& lchan->nr < pchan_subslots(as_pchan); \
lchan++)
enum lchan_activate_mode {
FOR_NONE,
FOR_MS_CHANNEL_REQUEST,
FOR_ASSIGNMENT,
FOR_HANDOVER,
FOR_VTY,
};
extern const struct value_string lchan_activate_mode_names[];
static inline const char *lchan_activate_mode_name(enum lchan_activate_mode activ_for)
{ return get_value_string(lchan_activate_mode_names, activ_for); }
struct gsm_lchan {
/* The TS that we're part of */
struct gsm_bts_trx_ts *ts;
/* The logical subslot number in the TS */
uint8_t nr;
char *name;
struct osmo_fsm_inst *fi;
struct mgwep_ci *mgw_endpoint_ci_bts;
struct {
enum lchan_activate_mode activ_for;
bool concluded; /*< true as soon as LCHAN_ST_ESTABLISHED is reached */
bool requires_voice_stream;
bool mgw_endpoint_available;
uint16_t msc_assigned_cic;
enum gsm0808_cause gsm0808_error_cause;
struct gsm_lchan *re_use_mgw_endpoint_from_lchan;
} activate;
/* If an event to release the lchan comes in while still waiting for responses, just mark this
* flag, so that the lchan will gracefully release at the next sensible junction. */
bool release_requested;
bool deact_sacch;
char *last_error;
/* There is an RSL error cause of value 0, so we need a separate flag. */
bool release_in_error;
/* RSL error code, RSL_ERR_* */
uint8_t rsl_error_cause;
/* The logical channel type */
enum gsm_chan_t type;
/* RSL channel mode */
@ -398,9 +530,6 @@ struct gsm_lchan {
/* If TCH, traffic channel mode */
enum gsm48_chan_mode tch_mode;
enum lchan_csd_mode csd_mode;
/* State */
enum gsm_lchan_state state;
const char *broken_reason;
/* Power levels for MS and BTS */
uint8_t bs_power;
uint8_t ms_power;
@ -415,15 +544,14 @@ struct gsm_lchan {
uint8_t sapis[8];
struct {
uint32_t bound_ip;
uint32_t connect_ip;
uint32_t bound_ip; /*< where the BTS receives RTP */
uint16_t bound_port;
uint32_t connect_ip; /*< where the BTS sends RTP to (MGW) */
uint16_t connect_port;
uint16_t conn_id;
uint8_t rtp_payload;
uint8_t rtp_payload2;
uint8_t speech_mode;
struct rtp_socket *rtp_socket;
/* info we need to postpone the AoIP
* assignment completed message */
@ -435,16 +563,6 @@ struct gsm_lchan {
uint8_t rqd_ta;
char *name;
struct osmo_timer_list T3101;
struct osmo_timer_list T3109;
struct osmo_timer_list T3111;
struct osmo_timer_list error_timer;
struct osmo_timer_list act_timer;
struct osmo_timer_list rel_work;
uint8_t error_cause;
/* table of neighbor cell measurements */
struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
@ -455,43 +573,38 @@ struct gsm_lchan {
uint8_t meas_rep_last_seen_nr;
/* GSM Random Access data */
/* TODO: don't allocate this, rather keep an "is_present" flag */
struct gsm48_req_ref *rqd_ref;
struct gsm_subscriber_connection *conn;
struct {
/* channel activation type and handover ref */
uint8_t act_type;
uint8_t ho_ref;
struct gsm48_req_ref *rqd_ref;
uint8_t rqd_ta;
} dyn;
};
enum {
TS_F_PDCH_ACTIVE = 0x1000,
TS_F_PDCH_ACT_PENDING = 0x2000,
TS_F_PDCH_DEACT_PENDING = 0x4000,
TS_F_PDCH_PENDING_MASK = (TS_F_PDCH_ACT_PENDING | TS_F_PDCH_DEACT_PENDING),
} gsm_bts_trx_ts_flags;
/* One Timeslot in a TRX */
struct gsm_bts_trx_ts {
struct gsm_bts_trx *trx;
bool initialized;
/* number of this timeslot at the TRX */
uint8_t nr;
enum gsm_phys_chan_config pchan;
struct osmo_fsm_inst *fi;
char *last_errmsg;
struct {
enum gsm_phys_chan_config pchan_is;
enum gsm_phys_chan_config pchan_want;
struct msgb *pending_chan_activ;
} dyn;
/* vty phys_chan_config setting, not necessarily in effect in case it was changed in the telnet
* vty after OML activation. Gets written on vty 'write file'. */
enum gsm_phys_chan_config pchan_from_config;
/* When the timeslot OML is established, pchan_from_config is copied here. This is the pchan
* currently in effect; for dynamic ts, this is the dyn kind (GSM_PCHAN_TCH_F_TCH_H_PDCH or
* GSM_PCHAN_TCH_F_PDCH) and does not show the pchan type currently active. */
enum gsm_phys_chan_config pchan_on_init;
/* This is the *actual* pchan type currently active. For dynamic timeslots, this reflects either
* GSM_PCHAN_NONE or one of the standard GSM_PCHAN_TCH_F, GSM_PCHAN_TCH_H, GSM_PCHAN_PDCH.
* Callers can use this transparently without being aware of dyn ts. */
enum gsm_phys_chan_config pchan_is;
/* After a PDCH ACT NACK, we shall not infinitely loop to try and ACT again.
* Also marks a timeslot where PDCH was deactivated by VTY. This is cleared whenever a timeslot
* enters IN_USE state, i.e. after each TCH use we try to PDCH ACT once again. */
bool pdch_act_allowed;
unsigned int flags;
struct gsm_abis_mo mo;
struct tlv_parsed nm_attr;
uint8_t nm_chan_comb;
@ -1033,9 +1146,12 @@ enum gsm_bts_type_variant str2btsvariant(const char *arg);
const char *btsvariant2str(enum gsm_bts_type_variant v);
extern const struct value_string gsm_chreq_descs[];
const struct value_string gsm_pchant_names[13];
const struct value_string gsm_pchant_descs[13];
extern const struct value_string gsm_pchant_names[];
extern const struct value_string gsm_pchant_descs[];
extern const struct value_string gsm_pchan_ids[];
const char *gsm_pchan_name(enum gsm_phys_chan_config c);
static inline const char *gsm_pchan_id(enum gsm_phys_chan_config c)
{ return get_value_string(gsm_pchan_ids, c); }
enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
const char *gsm_lchant_name(enum gsm_chan_t c);
const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
@ -1043,7 +1159,6 @@ char *gsm_trx_name(const struct gsm_bts_trx *trx);
char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
const char *gsm_lchans_name(enum gsm_lchan_state s);
static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
{
@ -1089,7 +1204,7 @@ struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
int *rc);
enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts);
uint8_t ts_subslots(struct gsm_bts_trx_ts *ts);
uint8_t pchan_subslots(enum gsm_phys_chan_config pchan);
bool ts_is_tch(struct gsm_bts_trx_ts *ts);
@ -1159,11 +1274,32 @@ enum {
};
enum {
BSC_CTR_ASSIGNMENT_ATTEMPTED,
BSC_CTR_ASSIGNMENT_COMPLETED,
BSC_CTR_ASSIGNMENT_STOPPED,
BSC_CTR_ASSIGNMENT_NO_CHANNEL,
BSC_CTR_ASSIGNMENT_TIMEOUT,
BSC_CTR_ASSIGNMENT_FAILED,
BSC_CTR_ASSIGNMENT_ERROR,
BSC_CTR_HANDOVER_ATTEMPTED,
BSC_CTR_HANDOVER_COMPLETED,
BSC_CTR_HANDOVER_STOPPED,
BSC_CTR_HANDOVER_NO_CHANNEL,
BSC_CTR_HANDOVER_TIMEOUT,
BSC_CTR_HANDOVER_COMPLETED,
BSC_CTR_HANDOVER_FAILED,
BSC_CTR_HANDOVER_ERROR,
BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED,
BSC_CTR_INTER_BSC_HO_OUT_COMPLETED,
BSC_CTR_INTER_BSC_HO_OUT_STOPPED,
BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT,
BSC_CTR_INTER_BSC_HO_OUT_ERROR,
BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED,
BSC_CTR_INTER_BSC_HO_IN_COMPLETED,
BSC_CTR_INTER_BSC_HO_IN_STOPPED,
BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL,
BSC_CTR_INTER_BSC_HO_IN_FAILED,
BSC_CTR_INTER_BSC_HO_IN_TIMEOUT,
BSC_CTR_INTER_BSC_HO_IN_ERROR,
BSC_CTR_PAGING_ATTEMPTED,
BSC_CTR_PAGING_DETACHED,
BSC_CTR_PAGING_RESPONDED,
@ -1171,11 +1307,42 @@ enum {
};
static const struct rate_ctr_desc bsc_ctr_description[] = {
[BSC_CTR_HANDOVER_ATTEMPTED] = {"handover:attempted", "Received handover attempts."},
[BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover:no_channel", "Sent no channel available responses."},
[BSC_CTR_HANDOVER_TIMEOUT] = {"handover:timeout", "Timeouts of timer T3103."},
[BSC_CTR_HANDOVER_COMPLETED] = {"handover:completed", "Received handover completed."},
[BSC_CTR_HANDOVER_FAILED] = {"handover:failed", "Received HO FAIL messages."},
[BSC_CTR_ASSIGNMENT_ATTEMPTED] = {"assignment:attempted", "Intra-cell re-assignment attempts."},
[BSC_CTR_ASSIGNMENT_COMPLETED] = {"assignment:completed", "Intra-cell re-assignment completed."},
[BSC_CTR_ASSIGNMENT_STOPPED] = {"assignment:stopped", "Connection ended during re-assignment."},
[BSC_CTR_ASSIGNMENT_NO_CHANNEL] = {"assignment:no_channel", "Failure to allocate lchan for re-assignment."},
[BSC_CTR_ASSIGNMENT_TIMEOUT] = {"assignment:timeout", "Re-assignment timed out."},
[BSC_CTR_ASSIGNMENT_FAILED] = {"assignment:failed", "Received FAIL message."},
[BSC_CTR_ASSIGNMENT_ERROR] = {"assignment:error", "Re-assigment failed for other reason."},
[BSC_CTR_HANDOVER_ATTEMPTED] = {"handover:attempted", "Intra-BSC handover attempts."},
[BSC_CTR_HANDOVER_COMPLETED] = {"handover:completed", "Intra-BSC handover completed."},
[BSC_CTR_HANDOVER_STOPPED] = {"handover:stopped", "Connection ended during HO."},
[BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover:no_channel", "Failure to allocate lchan for HO."},
[BSC_CTR_HANDOVER_TIMEOUT] = {"handover:timeout", "Handover timed out."},
[BSC_CTR_HANDOVER_FAILED] = {"handover:failed", "Received Handover Fail messages."},
[BSC_CTR_HANDOVER_ERROR] = {"handover:error", "Re-assigment failed for other reason."},
[BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED] = {"interbsc_ho_out:attempted",
"Attempts to handover to remote BSS."},
[BSC_CTR_INTER_BSC_HO_OUT_COMPLETED] = {"interbsc_ho_out:completed",
"Handover to remote BSS completed."},
[BSC_CTR_INTER_BSC_HO_OUT_STOPPED] = {"interbsc_ho_out:stopped", "Connection ended during HO."},
[BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT] = {"interbsc_ho_out:timeout", "Handover timed out."},
[BSC_CTR_INTER_BSC_HO_OUT_ERROR] = {"interbsc_ho_out:error",
"Handover to remote BSS failed for other reason."},
[BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED] = {"interbsc_ho_in:attempted",
"Attempts to handover from remote BSS."},
[BSC_CTR_INTER_BSC_HO_IN_COMPLETED] = {"interbsc_ho_in:completed",
"Handover from remote BSS completed."},
[BSC_CTR_INTER_BSC_HO_IN_STOPPED] = {"interbsc_ho_in:stopped", "Connection ended during HO."},
[BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL] = {"interbsc_ho_in:no_channel",
"Failure to allocate lchan for HO."},
[BSC_CTR_INTER_BSC_HO_IN_TIMEOUT] = {"interbsc_ho_in:timeout", "Handover from remote BSS timed out."},
[BSC_CTR_INTER_BSC_HO_IN_FAILED] = {"interbsc_ho_in:failed", "Received Handover Fail message."},
[BSC_CTR_INTER_BSC_HO_IN_ERROR] = {"interbsc_ho_in:error",
"Handover from remote BSS failed for other reason."},
[BSC_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
[BSC_CTR_PAGING_DETACHED] = {"paging:detached", "Paging request send failures because no responsible BTS was found."},
@ -1272,6 +1439,11 @@ struct gsm_network {
struct neighbor_ident_list *neighbor_bss_cells;
};
struct gsm_audio_support {
uint8_t hr : 1,
ver : 7;
};
static inline const struct osmo_location_area_id *bts_lai(struct gsm_bts *bts)
{
static struct osmo_location_area_id lai;
@ -1407,12 +1579,15 @@ void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
bool classmark_is_r99(struct gsm_classmark *cm);
void gsm_ts_check_init(struct gsm_bts_trx_ts *ts);
void gsm_trx_mark_all_ts_uninitialized(struct gsm_bts_trx *trx);
void gsm_bts_mark_all_ts_uninitialized(struct gsm_bts *bts);
bool trx_is_usable(const struct gsm_bts_trx *trx);
bool ts_is_usable(const struct gsm_bts_trx_ts *ts);
bool on_gsm_ts_init(struct gsm_bts_trx_ts *ts);
int gsm_lchan_type_by_pchan(enum gsm_phys_chan_config pchan);
enum gsm_phys_chan_config gsm_pchan_by_lchan_type(enum gsm_chan_t type);
void gsm_bts_all_ts_dispatch(struct gsm_bts *bts, uint32_t ts_ev, void *data);
void gsm_trx_all_ts_dispatch(struct gsm_bts_trx *trx, uint32_t ts_ev, void *data);
int bts_count_free_ts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan);
#endif /* _GSM_DATA_H */

View File

@ -31,7 +31,7 @@ struct T_def {
#define for_each_T_def(d, T_defs) \
for (d = T_defs; d && (d->T || d->default_val || d->desc); d++)
int T_def_get(struct T_def *T_defs, int T, enum T_unit as_unit, int val_if_not_present);
int T_def_get(const struct T_def *T_defs, int T, enum T_unit as_unit, int val_if_not_present);
void T_defs_reset(struct T_def *T_defs);
struct T_def *T_def_get_entry(struct T_def *T_defs, int T);
@ -44,12 +44,13 @@ struct state_timeout {
bool keep_timer;
};
struct state_timeout *get_state_timeout(uint32_t state, struct state_timeout *timeouts_array);
const struct state_timeout *get_state_timeout(uint32_t state,
const struct state_timeout *timeouts_array);
#define fsm_inst_state_chg_T(fi, state, timeouts_array, T_defs, default_timeout) \
_fsm_inst_state_chg_T(fi, state, timeouts_array, T_defs, default_timeout, \
__FILE__, __LINE__)
int _fsm_inst_state_chg_T(struct osmo_fsm_inst *fi, uint32_t state,
struct state_timeout *timeouts_array,
struct T_def *T_defs, int default_timeout,
const struct state_timeout *timeouts_array,
const struct T_def *T_defs, int default_timeout,
const char *file, int line);

View File

@ -5,72 +5,38 @@
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/timer.h>
#include <osmocom/gsm/gsm_utils.h>
#include <osmocom/gsm/gsm0808.h>
#include <osmocom/bsc/neighbor_ident.h>
#include <osmocom/bsc/gsm_data.h>
struct gsm_network;
struct gsm_lchan;
struct gsm_bts;
struct gsm_subscriber_connection;
struct gsm_meas_rep mr;
#define LOGPHOLCHANTOLCHAN(old_lchan, new_lchan, level, fmt, args...) \
LOGP(DHODEC, level, "(BTS %u trx %u arfcn %u ts %u lchan %u %s %s)->(BTS %u trx %u arfcn %u ts %u lchan %u %s) (subscr %s) " fmt, \
old_lchan->ts->trx->bts->nr, \
old_lchan->ts->trx->nr, \
old_lchan->ts->trx->arfcn, \
old_lchan->ts->nr, \
old_lchan->nr, \
gsm_lchant_name(old_lchan->type), \
gsm48_chan_mode_name(old_lchan->tch_mode), \
new_lchan->ts->trx->bts->nr, \
new_lchan->ts->trx->nr, \
new_lchan->ts->trx->arfcn, \
new_lchan->ts->nr, \
new_lchan->nr, \
gsm_pchan_name(new_lchan->ts->pchan), \
bsc_subscr_name(old_lchan->conn? old_lchan->conn->bsub : NULL), \
## args)
#define LOGPHO(struct_bsc_handover, level, fmt, args ...) \
LOGPHOLCHANTOLCHAN(struct_bsc_handover->old_lchan, struct_bsc_handover->new_lchan, level, fmt, ## args)
enum hodec_id {
HODEC_NONE,
HODEC1 = 1,
HODEC2 = 2,
enum handover_result {
HO_RESULT_OK,
HO_RESULT_FAIL_NO_CHANNEL,
HO_RESULT_FAIL_RR_HO_FAIL,
HO_RESULT_FAIL_TIMEOUT,
HO_RESULT_CONN_RELEASE,
HO_RESULT_ERROR,
};
struct bsc_handover {
struct llist_head list;
extern const struct value_string handover_result_names[];
inline static const char *handover_result_name(enum handover_result val)
{ return get_value_string(handover_result_names, val); }
/* Initial details of what is requested */
struct gsm_lchan *old_lchan;
struct gsm_bts *new_bts;
enum gsm_chan_t new_lchan_type;
bool async;
/* Derived and resulting state */
bool inter_cell;
uint8_t ho_ref;
enum hodec_id from_hodec_id;
struct gsm_lchan *new_lchan;
struct osmo_timer_list T3103;
};
int bsc_handover_start(enum hodec_id from_hodec_id, struct gsm_lchan *old_lchan, struct gsm_bts *new_bts,
enum gsm_chan_t new_lchan_type);
int bsc_handover_start_gscon(struct gsm_subscriber_connection *conn);
void bsc_clear_handover(struct gsm_subscriber_connection *conn, int free_lchan);
struct gsm_lchan *bsc_handover_pending(struct gsm_lchan *new_lchan);
int bsc_ho_count(struct gsm_bts *bts, bool inter_cell);
int bts_handover_count(struct gsm_bts *bts, int ho_scopes);
/* Handover decision algorithms' actions to take on incoming handover-relevant events.
*
* All events that are interesting for handover decision are actually communicated by S_LCHAN_* signals,
* so theoretically, each handover algorithm could evaluate those. However, handover_logic.c cleans up
* handover operation state upon receiving some of these signals. To allow a handover decision algorithm
* to take advantage of e.g. the struct bsc_handover before it is discarded, the handover decision event
* to take advantage of e.g. the struct handover before it is discarded, the handover decision event
* handler needs to be invoked before handover_logic.c discards the state. For example, if the handover
* decision wants to place a penalty timer upon a handover failure, it still needs to know which target
* cell the handover failed for; handover_logic.c erases that knowledge on handover failure, since it
@ -90,13 +56,26 @@ struct handover_decision_callbacks {
int hodec_id;
void (*on_measurement_report)(struct gsm_meas_rep *mr);
void (*on_ho_chan_activ_nack)(struct bsc_handover *ho);
void (*on_ho_failure)(struct bsc_handover *ho);
void (*on_handover_end)(struct gsm_subscriber_connection *conn, enum handover_result result);
};
void handover_decision_callbacks_register(struct handover_decision_callbacks *hdc);
struct handover_decision_callbacks *handover_decision_callbacks_get(int hodec_id);
int bsc_tx_bssmap_ho_required(struct gsm_lchan *lchan, const struct gsm0808_cell_id_list2 *target_cells);
int bsc_tx_bssmap_ho_request_ack(struct gsm_subscriber_connection *conn,
struct msgb *rr_ho_command);
int bsc_tx_bssmap_ho_detect(struct gsm_subscriber_connection *conn);
enum handover_result bsc_tx_bssmap_ho_complete(struct gsm_subscriber_connection *conn,
struct gsm_lchan *lchan);
void bsc_tx_bssmap_ho_failure(struct gsm_subscriber_connection *conn);
struct gsm_bts *bts_by_neighbor_ident(const struct gsm_network *net,
const struct neighbor_ident_key *search_for);
struct neighbor_ident_key *bts_ident_key(const struct gsm_bts *bts);
void handover_parse_inter_bsc_mt(struct gsm_subscriber_connection *conn,
struct msgb *ho_request_msg);
void handover_mt_allocate_lchan(struct handover *ho);
int handover_mt_send_rr_ho_command(struct handover *ho);

View File

@ -0,0 +1,80 @@
/* Handover FSM API for intra-BSC and inter-BSC Handover. */
#pragma once
#include <osmocom/bsc/debug.h>
#include <osmocom/bsc/handover.h>
const char *handover_status(struct gsm_subscriber_connection *conn);
/* This macro automatically includes a final \n, if omitted. */
#define LOG_HO(conn, level, fmt, args...) do { \
if (conn->ho.fi) \
LOGPFSML(conn->ho.fi, level, "%s: " fmt, \
handover_status(conn), ## args); \
else \
LOGP(DHODEC, level, "%s: " fmt, \
handover_status(conn), ## args); \
} while(0)
/* Terminology:
* Intra-Cell: stays within one BTS, this should actually be an Assignment.
* Intra-BSC: stays within one BSC, but moves between BTSes.
* Inter-BSC: moves between BSCs.
* Inter-BSC Out: move away from this BSC to another one.
* Inter-BSC In: move from another BSC to this one.
*/
enum handover_fsm_state {
HO_ST_NOT_STARTED,
HO_ST_WAIT_LCHAN_ACTIVE,
HO_ST_WAIT_RR_HO_DETECT,
HO_ST_WAIT_RR_HO_COMPLETE,
HO_ST_WAIT_LCHAN_ESTABLISHED,
HO_ST_WAIT_MGW_ENDPOINT_TO_MSC,
/* The inter-BSC Outgoing Handover FSM has completely separate states, but since it makes sense for it
* to also live in conn->ho.fi, it should share the same event enum. From there it is merely
* cosmetic to just include the separate fairly trivial states in the same FSM definition.
* An inter-BSC Outgoing FSM is almost unnecessary. The sole reason is to wait whether the MSC
* indeed clears the conn, and if not to log and count a failed handover attempt. */
HO_OUT_ST_WAIT_HO_COMMAND,
HO_OUT_ST_WAIT_CLEAR,
};
enum handover_fsm_event {
HO_EV_LCHAN_ACTIVE,
HO_EV_LCHAN_ESTABLISHED,
HO_EV_LCHAN_ERROR,
HO_EV_RR_HO_DETECT,
HO_EV_RR_HO_COMPLETE,
HO_EV_RR_HO_FAIL,
HO_EV_MSC_MGW_OK,
HO_EV_MSC_MGW_FAIL,
HO_EV_CONN_RELEASING,
HO_OUT_EV_BSSMAP_HO_COMMAND,
};
struct ho_out_rx_bssmap_ho_command {
const uint8_t *l3_info;
const uint8_t l3_info_len;
};
/* To be sent along with the HO_EV_RR_HO_DETECT */
struct handover_rr_detect_data {
struct msgb *msg;
const uint8_t *access_delay;
};
void handover_fsm_init();
void handover_request(struct handover_out_req *req);
void handover_start(struct handover_out_req *req);
void handover_start_inter_bsc_in(struct gsm_subscriber_connection *conn,
struct msgb *ho_request_msg);
void handover_end(struct gsm_subscriber_connection *conn, enum handover_result result);
const char *handover_status(struct gsm_subscriber_connection *conn);
bool handover_is_sane(struct gsm_subscriber_connection *conn, struct gsm_lchan *old_lchan,
struct gsm_lchan *new_lchan);

View File

@ -0,0 +1,89 @@
/* osmo-bsc API to manage lchans, logical channels in GSM cells. */
#pragma once
#include <osmocom/bsc/gsm_data.h>
#include <osmocom/bsc/debug.h>
/* This macro automatically includes a final \n, if omitted. */
#define LOG_LCHAN(lchan, level, fmt, args...) do { \
if (lchan->fi) \
LOGPFSML(lchan->fi, level, "(type=%s) " fmt, gsm_lchant_name(lchan->type), ## args); \
else \
LOGP(DRSL, level, "%s (not initialized) " fmt, gsm_lchan_name(lchan), ## args); \
} while(0)
enum lchan_fsm_state {
LCHAN_ST_UNUSED,
LCHAN_ST_WAIT_TS_READY,
LCHAN_ST_WAIT_ACTIV_ACK, /*< After RSL Chan Act Ack, lchan is active but RTP not configured. */
LCHAN_ST_WAIT_RLL_ESTABLISH,
LCHAN_ST_WAIT_MGW_ENDPOINT_AVAILABLE,
LCHAN_ST_WAIT_IPACC_CRCX_ACK,
LCHAN_ST_WAIT_IPACC_MDCX_ACK,
LCHAN_ST_WAIT_MGW_ENDPOINT_CONFIGURED,
LCHAN_ST_ESTABLISHED, /*< Active and RTP is fully configured. */
LCHAN_ST_WAIT_SAPIS_RELEASED,
LCHAN_ST_WAIT_BEFORE_RF_RELEASE,
LCHAN_ST_WAIT_RF_RELEASE_ACK,
LCHAN_ST_WAIT_AFTER_ERROR,
LCHAN_ST_BORKEN,
};
enum lchan_fsm_event {
LCHAN_EV_ACTIVATE,
LCHAN_EV_TS_READY,
LCHAN_EV_TS_ERROR,
LCHAN_EV_RSL_CHAN_ACTIV_ACK,
LCHAN_EV_RSL_CHAN_ACTIV_NACK,
LCHAN_EV_RLL_ESTABLISH_IND,
LCHAN_EV_MGW_ENDPOINT_AVAILABLE,
LCHAN_EV_MGW_ENDPOINT_CONFIGURED,
LCHAN_EV_MGW_ENDPOINT_ERROR,
LCHAN_EV_IPACC_CRCX_ACK,
LCHAN_EV_IPACC_CRCX_NACK,
LCHAN_EV_IPACC_MDCX_ACK,
LCHAN_EV_IPACC_MDCX_NACK,
LCHAN_EV_RLL_REL_IND,
LCHAN_EV_RLL_REL_CONF,
LCHAN_EV_RSL_RF_CHAN_REL_ACK,
LCHAN_EV_RLL_ERR_IND,
/* FIXME: not yet implemented: Chan Mode Modify, see assignment_fsm_start(). */
LCHAN_EV_CHAN_MODE_MODIF_ACK,
LCHAN_EV_CHAN_MODE_MODIF_ERROR,
};
void lchan_fsm_init();
void lchan_fsm_alloc(struct gsm_lchan *lchan);
void lchan_release(struct gsm_lchan *lchan, bool sacch_deact,
bool err, enum gsm48_rr_cause cause_rr);
struct lchan_activate_info {
enum lchan_activate_mode activ_for;
struct gsm_subscriber_connection *for_conn;
/* This always is for a specific lchan, so its lchan->type indicates full or half rate.
* When a dyn TS was selected, the lchan->type has been set to the desired rate. */
enum gsm48_chan_mode chan_mode;
bool requires_voice_stream;
uint16_t msc_assigned_cic;
struct gsm_lchan *old_lchan;
};
void lchan_activate(struct gsm_lchan *lchan, struct lchan_activate_info *info);
static inline const char *lchan_state_name(struct gsm_lchan *lchan)
{
return lchan->fi ? osmo_fsm_inst_state_name(lchan->fi) : "NULL";
}
static inline bool lchan_state_is(struct gsm_lchan *lchan, uint32_t state)
{
return (!lchan->fi && state == LCHAN_ST_UNUSED)
|| (lchan->fi && lchan->fi->state == state);
}
bool lchan_may_receive_data(struct gsm_lchan *lchan);
void lchan_forget_conn(struct gsm_lchan *lchan);
void lchan_forget_mgw_endpoint(struct gsm_lchan *lchan);

View File

@ -0,0 +1,6 @@
/* Select a suitable lchan from a given cell. */
#pragma once
struct gsm_lchan *lchan_select_by_type(struct gsm_bts *bts, enum gsm_chan_t type);
struct gsm_lchan *lchan_select_by_chan_mode(struct gsm_bts *bts,
enum gsm48_chan_mode chan_mode, bool full_rate);

View File

@ -0,0 +1,59 @@
/* osmo-bsc API to manage all sides of an MGW endpoint */
#pragma once
#include <osmocom/mgcp_client/mgcp_client_fsm.h>
#include <osmocom/bsc/debug.h>
/* This macro automatically includes a final \n, if omitted. */
#define LOG_MGWEP(mgwep, level, fmt, args...) do { \
LOGPFSML(mgwep->fi, level, "(%s) " fmt, \
mgw_endpoint_name(mgwep), ## args); \
} while(0)
enum mgwep_fsm_state {
MGWEP_ST_UNUSED,
MGWEP_ST_WAIT_MGW_RESPONSE,
MGWEP_ST_IN_USE,
};
enum mgwep_fsm_event {
_MGWEP_EV_LAST,
/* and MGW response events are allocated dynamically */
};
struct mgw_endpoint;
struct mgwep_ci;
struct T_def;
void mgw_endpoint_fsm_init(struct T_def *T_defs);
struct mgw_endpoint *mgw_endpoint_alloc(struct osmo_fsm_inst *parent, uint32_t parent_term_event,
struct mgcp_client *mgcp_client,
const char *fsm_id,
const char *endpoint_str_fmt, ...);
struct mgwep_ci *mgw_endpoint_ci_add(struct mgw_endpoint *mgwep,
const char *label_fmt, ...);
const struct mgcp_conn_peer *mgwep_ci_get_rtp_info(const struct mgwep_ci *ci);
bool mgwep_ci_get_crcx_info_to_sockaddr(const struct mgwep_ci *ci, struct sockaddr_storage *dest);
void mgw_endpoint_ci_request(struct mgwep_ci *ci,
enum mgcp_verb verb, const struct mgcp_conn_peer *verb_info,
struct osmo_fsm_inst *notify,
uint32_t event_success, uint32_t event_failure,
void *notify_data);
static inline void mgw_endpoint_ci_dlcx(struct mgwep_ci *ci)
{
mgw_endpoint_ci_request(ci, MGCP_VERB_DLCX, NULL, NULL, 0, 0, NULL);
}
void mgw_endpoint_clear(struct mgw_endpoint *mgwep);
const char *mgw_endpoint_name(const struct mgw_endpoint *mgwep);
const char *mgwep_ci_name(const struct mgwep_ci *ci);
const char *mgcp_conn_peer_name(const struct mgcp_conn_peer *info);
enum mgcp_codecs chan_mode_to_mgcp_codec(enum gsm48_chan_mode chan_mode, bool full_rate);
void mgcp_pick_codec(struct mgcp_conn_peer *verb_info, const struct gsm_lchan *lchan);

View File

@ -1,10 +1,9 @@
/* OpenBSC BSC code */
#pragma once
#ifndef OSMO_BSC_H
#define OSMO_BSC_H
#include <osmocom/gsm/protocol/gsm_04_08.h>
#include "bsc_api.h"
#include "bsc_msg_filter.h"
#include <osmocom/bsc/bsc_api.h>
#include <osmocom/bsc/bsc_msg_filter.h>
#define BSS_SEND_USSD 1
@ -16,6 +15,9 @@ enum bsc_con {
};
struct bsc_msc_data;
struct gsm0808_channel_type;
struct gsm0808_speech_codec_list;
struct gsm_audio_support;
struct bsc_api *osmo_bsc_api();
@ -38,5 +40,3 @@ int bsc_ctrl_cmds_install();
void bsc_gen_location_state_trap(struct gsm_bts *bts);
struct llist_head *bsc_access_lists(void);
#endif

View File

@ -38,3 +38,4 @@ void lcls_apply_config(struct gsm_subscriber_connection *conn);
extern struct osmo_fsm lcls_fsm;
void bssmap_add_lcls_status_if_needed(struct gsm_subscriber_connection *conn, struct msgb *msg);

View File

@ -0,0 +1,53 @@
/* osmo-bsc API to manage timeslot status: init and switch of dynamic PDCH. */
#pragma once
#include <osmocom/bsc/gsm_data.h>
/* This macro automatically includes a final \n, if omitted. */
#define LOG_TS(ts, level, fmt, args...) do { \
if (ts->fi) \
LOGPFSML(ts->fi, level, "%s%s%s" fmt "%s", \
ts->pchan_is != ts->pchan_from_config ? "(pchan_is=" : "", \
ts->pchan_is != ts->pchan_from_config ? gsm_pchan_name(ts->pchan_is) : "", \
ts->pchan_is != ts->pchan_from_config ? ") " : "", \
## args, \
(!fmt || !*fmt || fmt[strlen(fmt)-1] != '\n') ? "\n" : ""); \
else \
LOGP(DRSL, level, "%s" fmt "%s", \
gsm_ts_name(ts), \
## args, \
(!fmt || !*fmt || fmt[strlen(fmt)-1] != '\n') ? "\n" : ""); \
} while(0)
enum ts_fsm_state {
TS_ST_NOT_INITIALIZED,
TS_ST_UNUSED,
TS_ST_WAIT_PDCH_ACT,
TS_ST_PDCH,
TS_ST_WAIT_PDCH_DEACT,
TS_ST_IN_USE,
TS_ST_BORKEN,
};
enum ts_fsm_event {
TS_EV_OML_READY,
TS_EV_OML_DOWN,
TS_EV_RSL_READY,
TS_EV_RSL_DOWN,
TS_EV_LCHAN_REQUESTED,
TS_EV_LCHAN_UNUSED,
TS_EV_PDCH_ACT_ACK,
TS_EV_PDCH_ACT_NACK,
TS_EV_PDCH_DEACT_ACK,
TS_EV_PDCH_DEACT_NACK,
};
void ts_fsm_init();
void ts_fsm_alloc(struct gsm_bts_trx_ts *ts);
bool ts_is_capable_of_pchan(struct gsm_bts_trx_ts *ts, enum gsm_phys_chan_config pchan);
bool ts_is_capable_of_lchant(struct gsm_bts_trx_ts *ts, enum gsm_chan_t type);
bool ts_is_lchan_waiting_for_pchan(struct gsm_bts_trx_ts *ts, enum gsm_phys_chan_config *target_pchan);
bool ts_is_pchan_switching(struct gsm_bts_trx_ts *ts, enum gsm_phys_chan_config *target_pchan);
bool ts_usable_as_pchan(struct gsm_bts_trx_ts *ts, enum gsm_phys_chan_config as_pchan);

View File

@ -54,8 +54,8 @@ ipaccess_config_LDADD = \
$(top_builddir)/src/osmo-bsc/bts_ipaccess_nanobts.o \
$(top_builddir)/src/osmo-bsc/bts_ipaccess_nanobts_omlattr.o \
$(top_builddir)/src/osmo-bsc/gsm_data.o \
$(top_builddir)/src/osmo-bsc/net_init.o \
$(top_builddir)/src/osmo-bsc/gsm_timers.o \
$(top_builddir)/src/osmo-bsc/net_init.o \
$(OSMO_LIBS) \
$(NULL)

View File

@ -41,3 +41,6 @@ void paging_flush_bts(struct gsm_bts *bts, struct bsc_msc_data *msc)
{
/* No paging flushing */
}
void ts_fsm_alloc(struct gsm_bts_trx_ts *ts)
{}

View File

@ -34,10 +34,10 @@ osmo_bsc_SOURCES = \
abis_rsl.c \
acc_ramp.c \
arfcn_range_encode.c \
assignment_fsm.c \
bsc_api.c \
bsc_ctrl_commands.c \
bsc_ctrl_lookup.c \
bsc_dyn_ts.c \
bsc_init.c \
bsc_rf_ctrl.c \
bsc_rll.c \
@ -63,15 +63,18 @@ osmo_bsc_SOURCES = \
handover_cfg.c \
handover_decision.c \
handover_decision_2.c \
handover_fsm.c \
handover_logic.c \
handover_vty.c \
lchan_fsm.c \
lchan_select.c \
meas_feed.c \
meas_rep.c \
mgw_endpoint_fsm.c \
neighbor_ident.c \
neighbor_ident_vty.c \
net_init.c \
osmo_bsc_api.c \
osmo_bsc_audio.c \
osmo_bsc_bssap.c \
osmo_bsc_ctrl.c \
osmo_bsc_filter.c \
@ -86,6 +89,7 @@ osmo_bsc_SOURCES = \
penalty_timers.c \
rest_octets.c \
system_information.c \
timeslot_fsm.c \
$(NULL)
osmo_bsc_LDADD = \

View File

@ -43,6 +43,7 @@
#include <osmocom/bsc/abis_om2000.h>
#include <osmocom/bsc/signal.h>
#include <osmocom/bsc/gsm_timers.h>
#include <osmocom/bsc/timeslot_fsm.h>
#include <osmocom/abis/e1_input.h>
/* FIXME: move to libosmocore */
@ -1296,8 +1297,7 @@ static uint8_t pchan2comb(enum gsm_phys_chan_config pchan)
static uint8_t ts2comb(struct gsm_bts_trx_ts *ts)
{
switch (ts->pchan) {
case GSM_PCHAN_TCH_F_PDCH:
if (ts->pchan_on_init == GSM_PCHAN_TCH_F_PDCH) {
LOGP(DNM, LOGL_ERROR, "%s pchan %s not intended for use"
" with OM2000, use %s instead\n",
gsm_ts_and_pchan_name(ts),
@ -1307,11 +1307,8 @@ static uint8_t ts2comb(struct gsm_bts_trx_ts *ts)
* when we try to send the ip.access specific RSL PDCH Act
* message for it. Rather fail completely right now: */
return 0;
case GSM_PCHAN_TCH_F_TCH_H_PDCH:
return pchan2comb(GSM_PCHAN_TCH_F);
default:
return pchan2comb(ts->pchan);
}
return pchan2comb(ts->pchan_is);
}
static int put_freq_list(uint8_t *buf, uint16_t arfcn)
@ -1374,7 +1371,7 @@ int abis_om2k_tx_ts_conf_req(struct gsm_bts_trx_ts *ts)
msgb_tv_put(msg, OM2K_DEI_EXT_RANGE, 0); /* Off */
/* Optional: Interference Rejection Combining */
msgb_tv_put(msg, OM2K_DEI_INTERF_REJ_COMB, 0x00);
switch (ts->pchan) {
switch (ts->pchan_is) {
case GSM_PCHAN_CCCH:
msgb_tv_put(msg, OM2K_DEI_BA_PA_MFRMS, 0x06);
msgb_tv_put(msg, OM2K_DEI_BS_AG_BKS_RES, 0x01);
@ -1418,7 +1415,7 @@ int abis_om2k_tx_ts_conf_req(struct gsm_bts_trx_ts *ts)
msgb_tv_fixed_put(msg, OM2K_DEI_ICM_BOUND_PARAMS,
sizeof(icm_bound_params), icm_bound_params);
msgb_tv_put(msg, OM2K_DEI_TTA, 10); /* Timer for Time Alignment */
if (ts->pchan == GSM_PCHAN_TCH_H)
if (ts->pchan_is == GSM_PCHAN_TCH_H)
msgb_tv_put(msg, OM2K_DEI_ICM_CHAN_RATE, 1); /* TCH/H */
else
msgb_tv_put(msg, OM2K_DEI_ICM_CHAN_RATE, 0); /* TCH/F */
@ -2744,7 +2741,8 @@ void abis_om2k_trx_init(struct gsm_bts_trx *trx)
struct gsm_bts_trx_ts *ts = &trx->ts[i];
om2k_mo_init(&ts->rbs2000.om2k_mo, OM2K_MO_CLS_TS,
bts->nr, trx->nr, i);
gsm_ts_check_init(ts);
OSMO_ASSERT(ts->fi);
osmo_fsm_inst_dispatch(ts->fi, TS_EV_OML_READY, NULL);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,650 @@
/* osmo-bsc BSSMAP Assignment procedure implementation.
*
* (C) 2018 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
* All Rights Reserved
*
* Author: Neels Hofmeyr <neels@hofmeyr.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <osmocom/gsm/gsm0808.h>
#include <osmocom/mgcp_client/mgcp_client_fsm.h>
#include <osmocom/bsc/debug.h>
#include <osmocom/bsc/gsm_data.h>
#include <osmocom/bsc/gsm_timers.h>
#include <osmocom/bsc/lchan_fsm.h>
#include <osmocom/bsc/mgw_endpoint_fsm.h>
#include <osmocom/bsc/bsc_subscr_conn_fsm.h>
#include <osmocom/bsc/osmo_bsc_lcls.h>
#include <osmocom/bsc/bsc_msc_data.h>
#include <osmocom/bsc/bsc_api.h>
#include <osmocom/bsc/lchan_select.h>
#include <osmocom/bsc/abis_rsl.h>
#include <osmocom/bsc/assignment_fsm.h>
static struct osmo_fsm assignment_fsm;
struct gsm_subscriber_connection *assignment_fi_conn(struct osmo_fsm_inst *fi)
{
OSMO_ASSERT(fi);
OSMO_ASSERT(fi->fsm == &assignment_fsm);
OSMO_ASSERT(fi->priv);
return fi->priv;
}
static const struct state_timeout assignment_fsm_timeouts[32] = {
[ASSIGNMENT_ST_WAIT_LCHAN_ACTIVE] = { .T=10 },
[ASSIGNMENT_ST_WAIT_RR_ASS_COMPLETE] = { .keep_timer=true },
[ASSIGNMENT_ST_WAIT_LCHAN_ESTABLISHED] = { .keep_timer=true },
[ASSIGNMENT_ST_WAIT_MGW_ENDPOINT_TO_MSC] = { .T=23042 },
};
/* Transition to a state, using the T timer defined in assignment_fsm_timeouts.
* The actual timeout value is in turn obtained from network->T_defs.
* Assumes local variable fi exists. */
#define assignment_fsm_state_chg(state) \
fsm_inst_state_chg_T(fi, state, \
assignment_fsm_timeouts, \
((struct gsm_subscriber_connection*)(fi->priv))->network->T_defs, \
5)
/* Log failure and transition to ASSIGNMENT_ST_FAILURE, which triggers the appropriate actions. */
#define assignment_fail(cause, fmt, args...) do { \
struct gsm_subscriber_connection *_conn = fi->priv; \
_conn->assignment.failure_cause = cause; \
LOG_ASSIGNMENT(_conn, LOGL_ERROR, "Assignment failed in state %s, cause %s: " fmt "\n", \
osmo_fsm_inst_state_name(fi), gsm0808_cause_name(cause), ## args); \
assignment_count_result(BSC_CTR_ASSIGNMENT_ERROR); \
on_assignment_failure(_conn); \
} while(0)
/* Assume presence of local var 'conn' as struct gsm_subscriber_connection */
#define assignment_count(counter) do { \
LOG_ASSIGNMENT(conn, LOGL_DEBUG, "incrementing rate counter: %s %s\n", \
bsc_ctr_description[counter].name, \
bsc_ctr_description[counter].description); \
rate_ctr_inc(&conn->network->bsc_ctrs->ctr[counter]); \
} while(0)
#define assignment_count_result(counter) do { \
if (!conn->assignment.result_rate_ctr_done) { \
assignment_count(counter); \
conn->assignment.result_rate_ctr_done = true; \
} else \
LOG_ASSIGNMENT(conn, LOGL_DEBUG, \
"result rate counter already recorded, NOT counting as: %s %s", \
bsc_ctr_description[counter].name, \
bsc_ctr_description[counter].description); \
} while(0)
void assignment_reset(struct gsm_subscriber_connection *conn)
{
if (conn->assignment.new_lchan) {
struct gsm_lchan *lchan = conn->assignment.new_lchan;
conn->assignment.new_lchan = NULL;
lchan_release(lchan, false, true, RSL_ERR_EQUIPMENT_FAIL);
}
if (conn->assignment.created_ci_for_msc) {
gscon_forget_mgw_endpoint_ci(conn, conn->assignment.created_ci_for_msc);
/* If this is the last endpoint released, the mgw_endpoint_fsm will terminate and tell
* the gscon about it. */
mgw_endpoint_ci_dlcx(conn->assignment.created_ci_for_msc);
}
conn->assignment = (struct assignment_fsm_data){
.fi = conn->assignment.fi, /* The FSM shall clear itself when it's done. */
};
}
static void on_assignment_failure(struct gsm_subscriber_connection *conn)
{
struct msgb *resp = gsm0808_create_assignment_failure(conn->assignment.failure_cause, NULL);
if (!resp)
LOG_ASSIGNMENT(conn, LOGL_ERROR, "Unable to compose BSSMAP Assignment Failure message\n");
else
gscon_sigtran_send(conn, resp);
/* If assignment failed as early as in assignment_fsm_start(), there may not be an fi yet. */
if (conn->assignment.fi) {
LOG_ASSIGNMENT(conn, LOGL_ERROR, "Assignment failed\n");
osmo_fsm_inst_term(conn->assignment.fi, OSMO_FSM_TERM_ERROR, 0);
}
}
static void send_assignment_complete(struct gsm_subscriber_connection *conn, struct gsm_lchan *new_lchan)
{
int rc;
struct gsm0808_speech_codec sc;
struct gsm0808_speech_codec *sc_ptr = NULL;
struct sockaddr_storage addr_local;
struct sockaddr_storage *addr_local_p = NULL;
int perm_spch = 0;
uint8_t chosen_channel;
struct msgb *resp;
struct gsm_lchan *lchan = new_lchan;
struct osmo_fsm_inst *fi = conn->fi;
chosen_channel = gsm0808_chosen_channel(lchan->type, lchan->tch_mode);
if (!chosen_channel) {
assignment_fail(GSM0808_CAUSE_EQUIPMENT_FAILURE,
"Unable to compose Chosen Channel for mode=%s type=%s",
get_value_string(gsm48_chan_mode_names, lchan->tch_mode),
gsm_lchant_name(lchan->type));
return;
}
/* Generate voice related fields */
if (conn->assignment.requires_voice_stream) {
perm_spch = gsm0808_permitted_speech(lchan->type, lchan->tch_mode);
if (gscon_is_aoip(conn)) {
if (!mgwep_ci_get_crcx_info_to_sockaddr(conn->user_plane.mgw_endpoint_ci_msc,
&addr_local)) {
assignment_fail(GSM0808_CAUSE_EQUIPMENT_FAILURE,
"Unable to compose RTP address of MGW -> MSC");
return;
}
addr_local_p = &addr_local;
/* Extrapolate speech codec from speech mode */
gsm0808_speech_codec_from_chan_type(&sc, perm_spch);
sc_ptr = &sc;
}
/* FIXME: AMR codec configuration must be derived from lchan1! */
}
gsm0808_speech_codec_from_chan_type(&sc, perm_spch);
resp = gsm0808_create_ass_compl(lchan->abis_ip.ass_compl.rr_cause,
chosen_channel,
lchan->encr.alg_id, perm_spch,
addr_local_p, sc_ptr, NULL);
if (!resp) {
assignment_fail(GSM0808_CAUSE_EQUIPMENT_FAILURE,
"Unable to compose Assignment Complete message");
return;
}
/* Add LCLS BSS-Status IE in case there is any LCLS status for this connection */
bssmap_add_lcls_status_if_needed(conn, resp);
rc = gscon_sigtran_send(conn, resp);
if (rc) {
assignment_fail(GSM0808_CAUSE_EQUIPMENT_FAILURE,
"Unable send Assignment Complete message: rc=%d %s",
rc, strerror(-rc));
return;
}
}
static void assignment_success(struct gsm_subscriber_connection *conn)
{
/* apply LCLS configuration (if any) */
lcls_apply_config(conn);
send_assignment_complete(conn, conn->assignment.new_lchan);
/* If something went wrong during send_assignment_complete(), the fi will be gone from
* error handling in there. Almost a success, but then again the whole thing failed. */
if (!conn->assignment.fi)
return;
/* Take on the new lchan */
gscon_change_primary_lchan(conn, conn->assignment.new_lchan);
conn->assignment.new_lchan = NULL;
/* Rembered this only for error handling: should assignment fail, assignment_reset() will release
* the MGW endpoint right away. If successful, the conn continues to use the endpoint. */
conn->assignment.created_ci_for_msc = NULL;
/* New RTP information is now accepted */
conn->user_plane.msc_assigned_cic = conn->assignment.req.msc_assigned_cic;
osmo_strlcpy(conn->user_plane.msc_assigned_rtp_addr, conn->assignment.req.msc_rtp_addr,
sizeof(conn->user_plane.msc_assigned_rtp_addr));
conn->user_plane.msc_assigned_rtp_port = conn->assignment.req.msc_rtp_port;
LOG_ASSIGNMENT(conn, LOGL_DEBUG, "Assignment successful\n");
osmo_fsm_inst_term(conn->assignment.fi, OSMO_FSM_TERM_REGULAR, 0);
assignment_count_result(BSC_CTR_ASSIGNMENT_COMPLETED);
}
static void assignment_fsm_update_id(struct gsm_subscriber_connection *conn)
{
struct gsm_lchan *new_lchan = conn->assignment.new_lchan;
if (!new_lchan) {
osmo_fsm_inst_update_id(conn->assignment.fi, conn->fi->id);
return;
}
osmo_fsm_inst_update_id_f(conn->assignment.fi, "%s_%u-%u-%u-%s%s%s-%u",
conn->fi->id,
new_lchan->ts->trx->bts->nr, new_lchan->ts->trx->nr, new_lchan->ts->nr,
gsm_pchan_id(new_lchan->ts->pchan_on_init),
(new_lchan->ts->pchan_on_init == new_lchan->ts->pchan_is)? "" : "as",
(new_lchan->ts->pchan_on_init == new_lchan->ts->pchan_is)? ""
: gsm_pchan_id(new_lchan->ts->pchan_is),
new_lchan->nr);
}
static bool lchan_type_compat_with_mode(enum gsm_chan_t type,
enum gsm48_chan_mode chan_mode, int full_rate)
{
switch (chan_mode) {
case GSM48_CMODE_SIGN:
switch (type) {
case GSM_LCHAN_TCH_F:
case GSM_LCHAN_TCH_H:
case GSM_LCHAN_SDCCH:
return true;
default:
return false;
}
case GSM48_CMODE_SPEECH_V1:
case GSM48_CMODE_SPEECH_AMR:
case GSM48_CMODE_DATA_3k6:
case GSM48_CMODE_DATA_6k0:
/* these services can all run on TCH/H, but we may have
* an explicit override by the 'full_rate' argument */
switch (type) {
case GSM_LCHAN_TCH_F:
return full_rate;
case GSM_LCHAN_TCH_H:
return !full_rate;
default:
return false;
}
case GSM48_CMODE_DATA_12k0:
case GSM48_CMODE_DATA_14k5:
case GSM48_CMODE_SPEECH_EFR:
/* these services all explicitly require a TCH/F */
return type == GSM_LCHAN_TCH_F;
default:
return false;
}
}
void assignment_fsm_init()
{
OSMO_ASSERT(osmo_fsm_register(&assignment_fsm) == 0);
}
void assignment_fsm_start(struct gsm_subscriber_connection *conn, struct gsm_bts *bts,
struct assignment_request *req)
{
struct osmo_fsm_inst *fi;
struct lchan_activate_info info;
OSMO_ASSERT(conn);
OSMO_ASSERT(conn->fi);
OSMO_ASSERT(!conn->assignment.fi);
OSMO_ASSERT(!conn->assignment.new_lchan);
assignment_count(BSC_CTR_ASSIGNMENT_ATTEMPTED);
fi = osmo_fsm_inst_alloc_child(&assignment_fsm, conn->fi, GSCON_EV_ASSIGNMENT_END);
OSMO_ASSERT(fi);
conn->assignment.fi = fi;
fi->priv = conn;
conn->assignment.req = *req;
switch (req->chan_mode) {
case GSM48_CMODE_SPEECH_V1:
case GSM48_CMODE_SPEECH_EFR:
case GSM48_CMODE_SPEECH_AMR:
conn->assignment.requires_voice_stream = true;
/* Select an lchan below. */
break;
case GSM48_CMODE_SIGN:
conn->assignment.requires_voice_stream = false;
/* Select an lchan below. */
break;
default:
assignment_fail(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_NOT_SUPP,
"Channel mode not supported: %s",
gsm48_chan_mode_name(req->chan_mode));
return;
}
if (conn->lchan
&& lchan_type_compat_with_mode(conn->lchan->type, req->chan_mode, req->full_rate)) {
if (conn->lchan->tch_mode == req->chan_mode) {
/* current lchan suffices and already is in the right mode. We're done. */
LOG_ASSIGNMENT(conn, LOGL_DEBUG,
"Current lchan is compatible with requested chan_mode,"
" sending BSSMAP Assignment Complete directly."
" requested chan_mode=%s; current lchan is %s\n",
gsm48_chan_mode_name(req->chan_mode),
gsm_lchan_name(conn->lchan));
send_assignment_complete(conn, conn->lchan);
return;
}
/* FIXME: send Channel Mode Modify to put the current lchan in the right mode, and kick
* off its RTP stream setup code path. See gsm48_lchan_modify() and
* gsm48_rx_rr_modif_ack(), and see lchan_fsm.h LCHAN_EV_CHAN_MODE_MODIF_* */
LOG_ASSIGNMENT(conn, LOGL_ERROR,
"NOT IMPLEMENTED:"
" Current lchan would be compatible, we should send Channel Mode Modify\n");
}
conn->assignment.new_lchan = lchan_select_by_chan_mode(bts, req->chan_mode, req->full_rate);
if (!conn->assignment.new_lchan) {
assignment_count_result(BSC_CTR_ASSIGNMENT_NO_CHANNEL);
assignment_fail(GSM0808_CAUSE_NO_RADIO_RESOURCE_AVAILABLE,
"BSSMAP Assignment Command:"
" No lchan available for: chan_mode=%s, full_rate=%i\n",
get_value_string(gsm48_chan_mode_names, req->chan_mode), req->full_rate);
return;
}
assignment_fsm_update_id(conn);
LOG_ASSIGNMENT(conn, LOGL_INFO, "Starting Assignment: chan_mode=%s, full_rate=%d,"
" aoip=%s MSC-rtp=%s:%u\n",
gsm48_chan_mode_name(req->chan_mode), req->full_rate,
req->aoip ? "yes" : "no", req->msc_rtp_addr, req->msc_rtp_port);
assignment_fsm_state_chg(ASSIGNMENT_ST_WAIT_LCHAN_ACTIVE);
info = (struct lchan_activate_info){
.activ_for = FOR_ASSIGNMENT,
.for_conn = conn,
.chan_mode = req->chan_mode,
.requires_voice_stream = conn->assignment.requires_voice_stream,
.msc_assigned_cic = req->msc_assigned_cic,
.old_lchan = conn->lchan,
};
lchan_activate(conn->assignment.new_lchan, &info);
}
static void assignment_fsm_wait_lchan(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
struct gsm_subscriber_connection *conn = assignment_fi_conn(fi);
switch (event) {
case ASSIGNMENT_EV_LCHAN_ACTIVE:
if (data != conn->assignment.new_lchan)
return;
/* The TS may have changed its pchan_is */
assignment_fsm_update_id(conn);
assignment_fsm_state_chg(ASSIGNMENT_ST_WAIT_RR_ASS_COMPLETE);
return;
default:
OSMO_ASSERT(false);
}
}
static void assignment_fsm_wait_rr_ass_complete_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
{
int rc;
struct gsm_subscriber_connection *conn = assignment_fi_conn(fi);
rc = gsm48_send_rr_ass_cmd(conn->lchan, conn->assignment.new_lchan,
conn->lchan->ms_power);
if (rc)
assignment_fail(GSM0808_CAUSE_EQUIPMENT_FAILURE, "Unable to send RR Assignment Command");
}
static uint8_t get_cause(void *data)
{
if (data)
return *(uint8_t*)data;
return GSM0808_CAUSE_EQUIPMENT_FAILURE;
}
static void assignment_fsm_wait_rr_ass_complete(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
struct gsm_subscriber_connection *conn = assignment_fi_conn(fi);
switch (event) {
case ASSIGNMENT_EV_RR_ASSIGNMENT_COMPLETE:
assignment_fsm_state_chg(ASSIGNMENT_ST_WAIT_LCHAN_ESTABLISHED);
return;
case ASSIGNMENT_EV_LCHAN_ESTABLISHED:
/* The lchan is already done with all of its RTP setup. We will notice the lchan state to
* be established in assignment_fsm_wait_lchan_established_onenter(). */
return;
case ASSIGNMENT_EV_RR_ASSIGNMENT_FAIL:
assignment_count_result(BSC_CTR_ASSIGNMENT_FAILED);
assignment_fail(get_cause(data), "Rx RR Assignment Failure");
return;
default:
OSMO_ASSERT(false);
}
}
static void assignment_fsm_post_lchan_established(struct osmo_fsm_inst *fi);
static void assignment_fsm_wait_lchan_established_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
{
struct gsm_subscriber_connection *conn = assignment_fi_conn(fi);
/* Do we still need to wait for the RTP stream at all? */
if (lchan_state_is(conn->assignment.new_lchan, LCHAN_ST_ESTABLISHED))
assignment_fsm_post_lchan_established(fi);
}
static void assignment_fsm_wait_lchan_established(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
switch (event) {
case ASSIGNMENT_EV_LCHAN_ESTABLISHED:
assignment_fsm_post_lchan_established(fi);
return;
default:
OSMO_ASSERT(false);
}
}
static void assignment_fsm_post_lchan_established(struct osmo_fsm_inst *fi)
{
struct gsm_subscriber_connection *conn = assignment_fi_conn(fi);
if (conn->assignment.requires_voice_stream)
assignment_fsm_state_chg(ASSIGNMENT_ST_WAIT_MGW_ENDPOINT_TO_MSC);
else
assignment_success(conn);
}
static void assignment_fsm_wait_mgw_endpoint_to_msc_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
{
struct gsm_subscriber_connection *conn = assignment_fi_conn(fi);
OSMO_ASSERT(conn->assignment.requires_voice_stream);
LOG_ASSIGNMENT(conn, LOGL_DEBUG,
"Connecting MGW endpoint to the MSC's RTP port: %s:%u\n",
conn->assignment.req.msc_rtp_addr,
conn->assignment.req.msc_rtp_port);
if (!gscon_connect_mgw_to_msc(conn,
conn->assignment.new_lchan,
conn->assignment.req.msc_rtp_addr,
conn->assignment.req.msc_rtp_port,
fi,
ASSIGNMENT_EV_MSC_MGW_OK,
ASSIGNMENT_EV_MSC_MGW_FAIL,
NULL,
&conn->assignment.created_ci_for_msc)) {
assignment_fail(GSM0808_CAUSE_EQUIPMENT_FAILURE,
"Unable to connect MGW endpoint to the MSC side");
return;
}
}
static void assignment_fsm_wait_mgw_endpoint_to_msc(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
struct gsm_subscriber_connection *conn = assignment_fi_conn(fi);
switch (event) {
case ASSIGNMENT_EV_MSC_MGW_OK:
/* For AoIP, we created the MGW endpoint. Ensure it is really there, and log it. */
if (gscon_is_aoip(conn)) {
const struct mgcp_conn_peer *mgw_info;
mgw_info = mgwep_ci_get_rtp_info(conn->user_plane.mgw_endpoint_ci_msc);
if (!mgw_info) {
assignment_fail(GSM0808_CAUSE_EQUIPMENT_FAILURE,
"Unable to retrieve RTP port info allocated by MGW for"
" the MSC side.");
return;
}
LOG_ASSIGNMENT(conn, LOGL_DEBUG, "MGW's MSC side CI: %s:%u\n",
mgw_info->addr, mgw_info->port);
}
assignment_success(conn);
return;
case ASSIGNMENT_EV_MSC_MGW_FAIL:
assignment_fail(GSM0808_CAUSE_EQUIPMENT_FAILURE,
"Unable to connect MGW endpoint to the MSC side");
return;
default:
OSMO_ASSERT(false);
}
}
#define S(x) (1 << (x))
static const struct osmo_fsm_state assignment_fsm_states[] = {
[ASSIGNMENT_ST_WAIT_LCHAN_ACTIVE] = {
.name = "WAIT_LCHAN_ACTIVE",
.action = assignment_fsm_wait_lchan,
.in_event_mask = 0
| S(ASSIGNMENT_EV_LCHAN_ACTIVE)
,
.out_state_mask = 0
| S(ASSIGNMENT_ST_WAIT_LCHAN_ACTIVE)
| S(ASSIGNMENT_ST_WAIT_RR_ASS_COMPLETE)
,
},
[ASSIGNMENT_ST_WAIT_RR_ASS_COMPLETE] = {
.name = "WAIT_RR_ASS_COMPLETE",
.onenter = assignment_fsm_wait_rr_ass_complete_onenter,
.action = assignment_fsm_wait_rr_ass_complete,
.in_event_mask = 0
| S(ASSIGNMENT_EV_RR_ASSIGNMENT_COMPLETE)
| S(ASSIGNMENT_EV_RR_ASSIGNMENT_FAIL)
,
.out_state_mask = 0
| S(ASSIGNMENT_ST_WAIT_LCHAN_ESTABLISHED)
,
},
[ASSIGNMENT_ST_WAIT_LCHAN_ESTABLISHED] = {
.name = "WAIT_LCHAN_ESTABLISHED",
.onenter = assignment_fsm_wait_lchan_established_onenter,
.action = assignment_fsm_wait_lchan_established,
.in_event_mask = 0
| S(ASSIGNMENT_EV_LCHAN_ESTABLISHED)
,
.out_state_mask = 0
| S(ASSIGNMENT_ST_WAIT_MGW_ENDPOINT_TO_MSC)
,
},
[ASSIGNMENT_ST_WAIT_MGW_ENDPOINT_TO_MSC] = {
.name = "WAIT_MGW_ENDPOINT_TO_MSC",
.onenter = assignment_fsm_wait_mgw_endpoint_to_msc_onenter,
.action = assignment_fsm_wait_mgw_endpoint_to_msc,
.in_event_mask = 0
| S(ASSIGNMENT_EV_MSC_MGW_OK)
| S(ASSIGNMENT_EV_MSC_MGW_FAIL)
,
},
};
static const struct value_string assignment_fsm_event_names[] = {
OSMO_VALUE_STRING(ASSIGNMENT_EV_LCHAN_ACTIVE),
OSMO_VALUE_STRING(ASSIGNMENT_EV_LCHAN_ESTABLISHED),
OSMO_VALUE_STRING(ASSIGNMENT_EV_LCHAN_ERROR),
OSMO_VALUE_STRING(ASSIGNMENT_EV_MSC_MGW_OK),
OSMO_VALUE_STRING(ASSIGNMENT_EV_MSC_MGW_FAIL),
OSMO_VALUE_STRING(ASSIGNMENT_EV_RR_ASSIGNMENT_COMPLETE),
OSMO_VALUE_STRING(ASSIGNMENT_EV_RR_ASSIGNMENT_FAIL),
OSMO_VALUE_STRING(ASSIGNMENT_EV_CONN_RELEASING),
{}
};
void assignment_fsm_allstate_action(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
struct gsm_subscriber_connection *conn = assignment_fi_conn(fi);
switch (event) {
case ASSIGNMENT_EV_CONN_RELEASING:
assignment_count_result(BSC_CTR_ASSIGNMENT_STOPPED);
osmo_fsm_inst_term(fi, OSMO_FSM_TERM_REQUEST, 0);
return;
case ASSIGNMENT_EV_LCHAN_ERROR:
if (data != conn->assignment.new_lchan)
return;
assignment_fail(conn->assignment.new_lchan->activate.gsm0808_error_cause,
"Failed to activate lchan %s",
gsm_lchan_name(conn->assignment.new_lchan));
return;
default:
return;
}
}
int assignment_fsm_timer_cb(struct osmo_fsm_inst *fi)
{
struct gsm_subscriber_connection *conn = assignment_fi_conn(fi);
assignment_count_result(BSC_CTR_ASSIGNMENT_TIMEOUT);
assignment_fail(GSM0808_CAUSE_EQUIPMENT_FAILURE, "Timeout");
return 0;
}
void assignment_fsm_cleanup(struct osmo_fsm_inst *fi, enum osmo_fsm_term_cause cause)
{
struct gsm_subscriber_connection *conn = assignment_fi_conn(fi);
assignment_reset(conn);
conn->assignment.fi = NULL;
}
static struct osmo_fsm assignment_fsm = {
.name = "assignment",
.states = assignment_fsm_states,
.num_states = ARRAY_SIZE(assignment_fsm_states),
.log_subsys = DRSL,
.event_names = assignment_fsm_event_names,
.allstate_action = assignment_fsm_allstate_action,
.allstate_event_mask = 0
| S(ASSIGNMENT_EV_CONN_RELEASING)
| S(ASSIGNMENT_EV_LCHAN_ERROR)
,
.timer_cb = assignment_fsm_timer_cb,
.cleanup = assignment_fsm_cleanup,
};

View File

@ -22,7 +22,6 @@
*/
#include <osmocom/bsc/bsc_api.h>
#include <osmocom/bsc/bsc_rll.h>
#include <osmocom/bsc/gsm_data.h>
#include <osmocom/bsc/signal.h>
#include <osmocom/bsc/abis_rsl.h>
@ -34,161 +33,13 @@
#include <osmocom/bsc/penalty_timers.h>
#include <osmocom/bsc/osmo_bsc_sigtran.h>
#include <osmocom/bsc/bsc_subscr_conn_fsm.h>
#include <osmocom/bsc/lchan_fsm.h>
#include <osmocom/gsm/protocol/gsm_08_08.h>
#include <osmocom/gsm/gsm48.h>
#include <osmocom/core/talloc.h>
#define GSM0808_T10_VALUE 6, 0
static void handle_release(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan);
static void handle_chan_ack(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan);
static void handle_chan_nack(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan);
/*
* Start a new assignment and make sure that it is completed within T10 either
* positively, negatively or by the timeout.
*
* 1.) allocate a new lchan
* 2.) copy the encryption key and other data from the
* old to the new channel.
* 3.) RSL Channel Activate this channel and wait
*
* -> Signal handler for the LCHAN
* 4.) Send GSM 04.08 assignment command to the MS
*
* -> Assignment Complete/Assignment Failure
* 5.) Release the SDCCH, continue signalling on the new link
*/
static int handle_new_assignment(struct gsm_subscriber_connection *conn, int chan_mode, int full_rate)
{
struct gsm_lchan *new_lchan;
enum gsm_chan_t chan_type;
chan_type = full_rate ? GSM_LCHAN_TCH_F : GSM_LCHAN_TCH_H;
new_lchan = lchan_alloc(conn_get_bts(conn), chan_type, 0);
if (!new_lchan) {
LOGP(DMSC, LOGL_NOTICE, "%s No free channel for %s\n",
bsc_subscr_name(conn->bsub), gsm_lchant_name(chan_type));
return -1;
}
/* check if we are on TCH/F and requested TCH/H, but got TCH/F */
if (conn->lchan->type == new_lchan->type
&& chan_type != new_lchan->type) {
LOGPLCHAN(conn->lchan, DHO, LOGL_NOTICE,
"-> %s Will not re-assign to identical channel type, %s was requested\n",
gsm_lchan_name(new_lchan), gsm_lchant_name(chan_type));
lchan_free(new_lchan);
return -1;
}
/* copy old data to the new channel */
memcpy(&new_lchan->encr, &conn->lchan->encr, sizeof(new_lchan->encr));
new_lchan->ms_power = conn->lchan->ms_power;
new_lchan->bs_power = conn->lchan->bs_power;
new_lchan->rqd_ta = conn->lchan->rqd_ta;
/* copy new data to it */
new_lchan->tch_mode = chan_mode;
new_lchan->rsl_cmode = (chan_mode == GSM48_CMODE_SIGN) ?
RSL_CMOD_SPD_SIGN : RSL_CMOD_SPD_SPEECH;
/* handle AMR correctly */
if (chan_mode == GSM48_CMODE_SPEECH_AMR)
bsc_mr_config(conn, new_lchan, full_rate);
if (rsl_chan_activate_lchan(new_lchan, RSL_ACT_INTRA_NORM_ASS, 0) < 0) {
LOGPLCHAN(new_lchan, DHO, LOGL_ERROR, "could not activate channel\n");
lchan_free(new_lchan);
return -1;
}
/* remember that we have the channel */
conn->secondary_lchan = new_lchan;
new_lchan->conn = conn;
return 0;
}
/*
* \brief Check if the given channel is compatible with the mode/fullrate
*/
static int chan_compat_with_mode(struct gsm_lchan *lchan, int chan_mode, int full_rate)
{
switch (chan_mode) {
case GSM48_CMODE_SIGN:
switch (lchan->type) {
case GSM_LCHAN_TCH_F:
case GSM_LCHAN_TCH_H:
case GSM_LCHAN_SDCCH:
return 1;
default:
return 0;
}
case GSM48_CMODE_SPEECH_V1:
case GSM48_CMODE_SPEECH_AMR:
case GSM48_CMODE_DATA_3k6:
case GSM48_CMODE_DATA_6k0:
/* these services can all run on TCH/H, but we may have
* an explicit override by the 'full_rate' argument */
switch (lchan->type) {
case GSM_LCHAN_TCH_F:
return full_rate ? 1 : 0;
case GSM_LCHAN_TCH_H:
return full_rate ? 0 : 1;
default:
return 0;
}
case GSM48_CMODE_DATA_12k0:
case GSM48_CMODE_DATA_14k5:
case GSM48_CMODE_SPEECH_EFR:
/* these services all explicitly require a TCH/F */
return (lchan->type == GSM_LCHAN_TCH_F) ? 1 : 0;
default:
return 0;
}
}
/*! Send a GSM08.08 Assignment Request. Right now this does not contain the
* audio codec type or the allowed rates for the config. In case the current
* channel does not allow the selected mode a new one will be allocated.
* \param[out] conn related subscriber connection
* \param[in] chan_mode mode of the channel (see enum gsm48_chan_mode)
* \param[in] full_rate select full rate or half rate channel
* \returns 0 on success, 1 when no operation is neccessary, -1 on failure */
int gsm0808_assign_req(struct gsm_subscriber_connection *conn, int chan_mode, int full_rate)
{
/* TODO: Add multirate configuration, make it work for more than audio. */
if (!chan_compat_with_mode(conn->lchan, chan_mode, full_rate)) {
if (handle_new_assignment(conn, chan_mode, full_rate) != 0)
goto error;
} else {
/* Check if the channel is already in the requested mode, if
* yes, we skip unnecessary channel mode modify operations. */
if (conn->lchan->tch_mode == chan_mode)
return 1;
if (chan_mode == GSM48_CMODE_SPEECH_AMR)
bsc_mr_config(conn, conn->lchan, full_rate);
LOGPLCHAN(conn->lchan, DMSC, LOGL_NOTICE,
"Sending ChanModify for speech: %s\n",
get_value_string(gsm48_chan_mode_names, chan_mode));
gsm48_lchan_modify(conn->lchan, chan_mode);
}
/* we expect the caller will manage T10 */
return 0;
error:
bsc_assign_fail(conn, 0, NULL);
return -1;
}
int gsm0808_page(struct gsm_bts *bts, unsigned int page_group, unsigned int mi_len,
uint8_t *mi, int chan_type)
{
@ -222,101 +73,3 @@ int gsm0808_cipher_mode(struct gsm_subscriber_connection *conn, int cipher,
return gsm48_send_rr_ciph_mode(conn->lchan, include_imeisv);
}
/*
* Release all occupied RF Channels but stay around for more.
*/
int gsm0808_clear(struct gsm_subscriber_connection *conn)
{
if (conn->ho)
bsc_clear_handover(conn, 1);
if (conn->secondary_lchan)
lchan_release(conn->secondary_lchan, 0, RSL_REL_LOCAL_END);
if (conn->lchan)
lchan_release(conn->lchan, 1, RSL_REL_NORMAL);
conn->lchan = NULL;
conn->secondary_lchan = NULL;
return 0;
}
static int bsc_handle_lchan_signal(unsigned int subsys, unsigned int signal,
void *handler_data, void *signal_data)
{
struct gsm_lchan *lchan;
struct lchan_signal_data *lchan_data;
if (subsys != SS_LCHAN)
return 0;
lchan_data = signal_data;
if (!lchan_data->lchan || !lchan_data->lchan->conn)
return 0;
lchan = lchan_data->lchan;
switch (signal) {
case S_LCHAN_UNEXPECTED_RELEASE:
LOGPLCHAN(lchan, DMSC, LOGL_NOTICE, "S_LCHAN_UNEXPECTED_RELEASE\n");
handle_release(lchan->conn, lchan);
break;
case S_LCHAN_ACTIVATE_ACK:
handle_chan_ack(lchan->conn, lchan);
break;
case S_LCHAN_ACTIVATE_NACK:
handle_chan_nack(lchan->conn, lchan);
break;
}
return 0;
}
static void handle_release(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan)
{
if (conn->secondary_lchan == lchan) {
LOGPLCHAN(lchan, DMSC, LOGL_NOTICE,
"lchan release on new lchan, Assignment failed\n");
conn->secondary_lchan = NULL;
bsc_assign_fail(conn, GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, NULL);
}
/* clear the connection now */
bsc_clear_request(conn, 0);
/* now give up all channels */
if (conn->lchan == lchan)
conn->lchan = NULL;
if (conn->ho && conn->ho->new_lchan == lchan)
bsc_clear_handover(conn, 0);
lchan->conn = NULL;
}
static void handle_chan_ack(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan)
{
if (conn->secondary_lchan != lchan)
return;
LOGPLCHAN(lchan, DMSC, LOGL_NOTICE, "Sending RR Assignment\n");
gsm48_send_rr_ass_cmd(conn->lchan, lchan, lchan->ms_power);
}
static void handle_chan_nack(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan)
{
if (conn->secondary_lchan != lchan)
return;
LOGPLCHAN(lchan, DMSC, LOGL_ERROR, "Channel activation failed.\n");
conn->secondary_lchan->conn = NULL;
conn->secondary_lchan = NULL;
bsc_assign_fail(conn, GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, NULL);
}
static __attribute__((constructor)) void on_dso_load_bsc(void)
{
osmo_signal_register_handler(SS_LCHAN, bsc_handle_lchan_signal, NULL);
}

View File

@ -1,60 +0,0 @@
/* Dynamic PDCH initialisation implementation shared across NM and RSL */
/* (C) 2016 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <osmocom/core/logging.h>
#include <osmocom/bsc/debug.h>
#include <osmocom/bsc/gsm_data.h>
#include <osmocom/bsc/abis_rsl.h>
static void tchf_pdch_ts_init(struct gsm_bts_trx_ts *ts)
{
int rc;
rc = rsl_ipacc_pdch_activate(ts, 1);
if (rc != 0 && rc != -ENOTSUP)
LOGP(DRSL, LOGL_ERROR, "%s %s: PDCH ACT failed\n",
gsm_ts_name(ts), gsm_pchan_name(ts->pchan));
}
static void tchf_tchh_pdch_ts_init(struct gsm_bts_trx_ts *ts)
{
dyn_ts_switchover_start(ts, GSM_PCHAN_PDCH);
}
void dyn_ts_init(struct gsm_bts_trx_ts *ts)
{
/* Clear all TCH/F_PDCH flags */
ts->flags &= ~(TS_F_PDCH_PENDING_MASK | TS_F_PDCH_ACTIVE);
/* Clear TCH/F_TCH/H_PDCH state */
ts->dyn.pchan_is = ts->dyn.pchan_want = GSM_PCHAN_NONE;
ts->dyn.pending_chan_activ = NULL;
switch (ts->pchan) {
case GSM_PCHAN_TCH_F_PDCH:
tchf_pdch_ts_init(ts);
break;
case GSM_PCHAN_TCH_F_TCH_H_PDCH:
tchf_tchh_pdch_ts_init(ts);
break;
default:
break;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -118,6 +118,20 @@ const char *bsc_subscr_name(struct bsc_subscr *bsub)
return buf;
}
/* Like bsc_subscr_name() but returns only characters approved by osmo_identifier_valid(), useful for
* osmo_fsm_inst IDs. */
const char *bsc_subscr_id(struct bsc_subscr *bsub)
{
static char buf[32];
if (!bsub)
return "unknown";
if (bsub->imsi[0])
snprintf(buf, sizeof(buf), "IMSI%s", bsub->imsi);
else
snprintf(buf, sizeof(buf), "TMSI%08x", bsub->tmsi);
return buf;
}
static void bsc_subscr_free(struct bsc_subscr *bsub)
{
llist_del(&bsub->entry);

View File

@ -33,6 +33,7 @@
#include <osmocom/gsm/gsm0502.h>
#include <osmocom/ctrl/control_if.h>
#include <osmocom/gsm/gsm48.h>
#include <osmocom/gsm/gsm0808.h>
#include <arpa/inet.h>
@ -56,7 +57,7 @@
#include <osmocom/bsc/bsc_msc_data.h>
#include <osmocom/bsc/osmo_bsc_rf.h>
#include <osmocom/bsc/pcu_if.h>
#include <osmocom/bsc/handover.h>
#include <osmocom/bsc/handover_fsm.h>
#include <osmocom/bsc/handover_cfg.h>
#include <osmocom/bsc/handover_vty.h>
#include <osmocom/bsc/gsm_04_08_rr.h>
@ -65,6 +66,10 @@
#include <osmocom/bsc/neighbor_ident.h>
#include <osmocom/bsc/handover.h>
#include <osmocom/bsc/gsm_timers.h>
#include <osmocom/bsc/timeslot_fsm.h>
#include <osmocom/bsc/lchan_fsm.h>
#include <osmocom/bsc/gsm_timers.h>
#include <osmocom/bsc/mgw_endpoint_fsm.h>
#include <inttypes.h>
@ -552,9 +557,9 @@ static void config_write_ts_single(struct vty *vty, struct gsm_bts_trx_ts *ts)
vty_out(vty, " timeslot %u%s", ts->nr, VTY_NEWLINE);
if (ts->tsc != -1)
vty_out(vty, " training_sequence_code %u%s", ts->tsc, VTY_NEWLINE);
if (ts->pchan != GSM_PCHAN_NONE)
if (ts->pchan_from_config != GSM_PCHAN_NONE)
vty_out(vty, " phys_chan_config %s%s",
gsm_pchan_name(ts->pchan), VTY_NEWLINE);
gsm_pchan_name(ts->pchan_from_config), VTY_NEWLINE);
vty_out(vty, " hopping enabled %u%s",
ts->hopping.enabled, VTY_NEWLINE);
if (ts->hopping.enabled) {
@ -1100,17 +1105,12 @@ DEFUN(show_trx,
static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts)
{
vty_out(vty, "BTS %u, TRX %u, Timeslot %u, phys cfg %s, TSC %u",
vty_out(vty, "BTS %u, TRX %u, Timeslot %u, phys cfg %s",
ts->trx->bts->nr, ts->trx->nr, ts->nr,
gsm_pchan_name(ts->pchan), gsm_ts_tsc(ts));
if (ts->pchan == GSM_PCHAN_TCH_F_PDCH) {
vty_out(vty, " (%s mode)",
ts->flags & TS_F_PDCH_ACTIVE ? "PDCH" : "TCH/F");
} else if (ts->pchan == GSM_PCHAN_TCH_F_TCH_H_PDCH) {
vty_out(vty, " (%s mode)", gsm_pchan_name(ts->dyn.pchan_is));
}
vty_out(vty, "%s", VTY_NEWLINE);
vty_out(vty, " NM State: ");
gsm_pchan_name(ts->pchan_on_init));
if (ts->pchan_is != ts->pchan_on_init)
vty_out(vty, " (%s mode)", gsm_pchan_name(ts->pchan_is));
vty_out(vty, ", TSC %u%s NM State: ", gsm_ts_tsc(ts), VTY_NEWLINE);
net_dump_nmstate(vty, &ts->mo.nm_state);
if (!is_ipaccess_bts(ts->trx->bts))
vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s",
@ -1237,48 +1237,17 @@ static void meas_rep_dump_vty(struct vty *vty, struct gsm_meas_rep *mr,
meas_rep_dump_uni_vty(vty, &mr->ul, prefix, "ul");
}
/* FIXME: move this to libosmogsm */
static const struct value_string gsm48_cmode_names[] = {
{ GSM48_CMODE_SIGN, "signalling" },
{ GSM48_CMODE_SPEECH_V1, "FR or HR" },
{ GSM48_CMODE_SPEECH_EFR, "EFR" },
{ GSM48_CMODE_SPEECH_AMR, "AMR" },
{ GSM48_CMODE_DATA_14k5, "CSD(14k5)" },
{ GSM48_CMODE_DATA_12k0, "CSD(12k0)" },
{ GSM48_CMODE_DATA_6k0, "CSD(6k0)" },
{ GSM48_CMODE_DATA_3k6, "CSD(3k6)" },
{ 0, NULL }
};
/* call vty_out() to print a string like " as TCH/H" for dynamic timeslots.
* Don't do anything if the ts is not dynamic. */
static void vty_out_dyn_ts_status(struct vty *vty, struct gsm_bts_trx_ts *ts)
{
switch (ts->pchan) {
case GSM_PCHAN_TCH_F_TCH_H_PDCH:
if (ts->dyn.pchan_is == ts->dyn.pchan_want)
vty_out(vty, " as %s",
gsm_pchan_name(ts->dyn.pchan_is));
else
vty_out(vty, " switching %s -> %s",
gsm_pchan_name(ts->dyn.pchan_is),
gsm_pchan_name(ts->dyn.pchan_want));
break;
case GSM_PCHAN_TCH_F_PDCH:
if ((ts->flags & TS_F_PDCH_PENDING_MASK) == 0)
vty_out(vty, " as %s",
(ts->flags & TS_F_PDCH_ACTIVE)? "PDCH"
: "TCH/F");
else
vty_out(vty, " switching %s -> %s",
(ts->flags & TS_F_PDCH_ACTIVE)? "PDCH"
: "TCH/F",
(ts->flags & TS_F_PDCH_ACT_PENDING)? "PDCH"
: "TCH/F");
break;
default:
/* no dyn ts */
break;
enum gsm_phys_chan_config target;
if (ts_is_pchan_switching(ts, &target)) {
vty_out(vty, " switching %s -> %s", gsm_pchan_name(ts->pchan_is),
gsm_pchan_name(target));
} else if (ts->pchan_is != ts->pchan_on_init) {
vty_out(vty, " as %s", gsm_pchan_name(ts->pchan_is));
}
}
@ -1290,7 +1259,7 @@ static void lchan_dump_full_vty(struct vty *vty, struct gsm_lchan *lchan)
lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr,
lchan->nr, gsm_lchant_name(lchan->type), VTY_NEWLINE);
/* show dyn TS details, if applicable */
switch (lchan->ts->pchan) {
switch (lchan->ts->pchan_on_init) {
case GSM_PCHAN_TCH_F_TCH_H_PDCH:
vty_out(vty, " Osmocom Dyn TS:");
vty_out_dyn_ts_status(vty, lchan->ts);
@ -1306,10 +1275,9 @@ static void lchan_dump_full_vty(struct vty *vty, struct gsm_lchan *lchan)
break;
}
vty_out(vty, " Connection: %u, State: %s%s%s%s",
lchan->conn ? 1: 0,
gsm_lchans_name(lchan->state),
lchan->state == LCHAN_S_BROKEN ? " Error reason: " : "",
lchan->state == LCHAN_S_BROKEN ? lchan->broken_reason : "",
lchan->conn ? 1: 0, lchan_state_name(lchan),
lchan->fi && lchan->fi->state == LCHAN_ST_BORKEN ? " Error reason: " : "",
lchan->fi && lchan->fi->state == LCHAN_ST_BORKEN ? lchan->last_error : "",
VTY_NEWLINE);
vty_out(vty, " BS Power: %u dBm, MS Power: %u dBm%s",
lchan->ts->trx->nominal_power - lchan->ts->trx->max_power_red
@ -1317,7 +1285,7 @@ static void lchan_dump_full_vty(struct vty *vty, struct gsm_lchan *lchan)
ms_pwr_dbm(lchan->ts->trx->bts->band, lchan->ms_power),
VTY_NEWLINE);
vty_out(vty, " Channel Mode / Codec: %s%s",
get_value_string(gsm48_cmode_names, lchan->tch_mode),
gsm48_chan_mode_name(lchan->tch_mode),
VTY_NEWLINE);
if (lchan->conn && lchan->conn->bsub) {
vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
@ -1361,12 +1329,12 @@ static void lchan_dump_short_vty(struct vty *vty, struct gsm_lchan *lchan)
vty_out(vty, "BTS %u, TRX %u, Timeslot %u %s",
lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr,
gsm_pchan_name(lchan->ts->pchan));
gsm_pchan_name(lchan->ts->pchan_on_init));
vty_out_dyn_ts_status(vty, lchan->ts);
vty_out(vty, ", Lchan %u, Type %s, State %s - "
"L1 MS Power: %u dBm RXL-FULL-dl: %4d dBm RXL-FULL-ul: %4d dBm%s",
lchan->nr,
gsm_lchant_name(lchan->type), gsm_lchans_name(lchan->state),
gsm_lchant_name(lchan->type), lchan_state_name(lchan),
mr->ms_l1.pwr,
rxlev2dbm(mr->dl.full.rx_lev),
rxlev2dbm(mr->ul.full.rx_lev),
@ -1377,10 +1345,9 @@ static void lchan_dump_short_vty(struct vty *vty, struct gsm_lchan *lchan)
static int dump_lchan_trx_ts(struct gsm_bts_trx_ts *ts, struct vty *vty,
void (*dump_cb)(struct vty *, struct gsm_lchan *))
{
int lchan_nr;
for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN; lchan_nr++) {
struct gsm_lchan *lchan = &ts->lchan[lchan_nr];
if ((lchan->type == GSM_LCHAN_NONE) && (lchan->state == LCHAN_S_NONE))
struct gsm_lchan *lchan;
ts_for_each_lchan(lchan, ts) {
if (lchan_state_is(lchan, LCHAN_ST_UNUSED))
continue;
dump_cb(vty, lchan);
}
@ -1507,7 +1474,7 @@ static void dump_one_subscr_conn(struct vty *vty, const struct gsm_subscriber_co
vty_out(vty, "conn ID=%u, MSC=%u, hodec2_fail=%d, mode=%s, mgw_ep=%s%s",
conn->sccp.conn_id, conn->sccp.msc->nr, conn->hodec2.failures,
get_value_string(gsm48_chan_mode_names, conn->user_plane.chan_mode),
conn->user_plane.mgw_endpoint, VTY_NEWLINE);
mgw_endpoint_name(conn->user_plane.mgw_endpoint), VTY_NEWLINE);
if (conn->lcls.global_call_ref_len) {
vty_out(vty, " LCLS GCR: %s%s",
osmo_hexdump_nospc(conn->lcls.global_call_ref, conn->lcls.global_call_ref_len),
@ -1518,8 +1485,8 @@ static void dump_one_subscr_conn(struct vty *vty, const struct gsm_subscriber_co
}
if (conn->lchan)
lchan_dump_full_vty(vty, conn->lchan);
if (conn->secondary_lchan)
lchan_dump_full_vty(vty, conn->secondary_lchan);
if (conn->assignment.new_lchan)
lchan_dump_full_vty(vty, conn->assignment.new_lchan);
}
DEFUN(show_subscr_conn,
@ -1548,8 +1515,6 @@ DEFUN(show_subscr_conn,
static int trigger_ho_or_as(struct vty *vty, struct gsm_lchan *from_lchan, struct gsm_bts *to_bts)
{
int rc;
if (!to_bts || from_lchan->ts->trx->bts == to_bts) {
LOGP(DHO, LOGL_NOTICE, "%s Manually triggering Assignment from VTY\n",
gsm_lchan_name(from_lchan));
@ -1557,11 +1522,13 @@ static int trigger_ho_or_as(struct vty *vty, struct gsm_lchan *from_lchan, struc
} else
LOGP(DHO, LOGL_NOTICE, "%s (ARFCN %u) --> BTS %u Manually triggering Handover from VTY\n",
gsm_lchan_name(from_lchan), from_lchan->ts->trx->arfcn, to_bts->nr);
rc = bsc_handover_start(HODEC_NONE, from_lchan, to_bts, from_lchan->type);
if (rc) {
vty_out(vty, "bsc_handover_start() returned %d=%s%s", rc,
strerror(-rc), VTY_NEWLINE);
return CMD_WARNING;
{
struct handover_out_req req = {
.from_hodec_id = HODEC_USER,
.old_lchan = from_lchan,
.target_nik = *bts_ident_key(to_bts),
};
handover_request(&req);
}
return CMD_SUCCESS;
}
@ -1650,18 +1617,13 @@ static struct gsm_lchan *find_used_voice_lchan(struct vty *vty)
int i;
for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
struct gsm_bts_trx_ts *ts = &trx->ts[i];
int j;
int subslots;
struct gsm_lchan *lchan;
/* skip administratively deactivated timeslots */
if (!nm_is_running(&ts->mo.nm_state))
if (ts->fi->state != TS_ST_IN_USE)
continue;
subslots = ts_subslots(ts);
for (j = 0; j < subslots; j++) {
struct gsm_lchan *lchan = &ts->lchan[j];
if (lchan->state == LCHAN_S_ACTIVE
ts_for_each_lchan(lchan, ts) {
if (lchan_state_is(lchan, LCHAN_ST_ESTABLISHED)
&& (lchan->type == GSM_LCHAN_TCH_F
|| lchan->type == GSM_LCHAN_TCH_H)) {
@ -1693,30 +1655,27 @@ static struct gsm_bts *find_other_bts_with_free_slots(struct vty *vty, struct gs
llist_for_each_entry(trx, &bts->trx_list, list) {
int i;
/* FIXME: use lchan_select_by_type() instead */
for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
struct gsm_bts_trx_ts *ts = &trx->ts[i];
int j;
int subslots;
struct gsm_lchan *lchan;
/* skip administratively deactivated timeslots */
if (!nm_is_running(&ts->mo.nm_state))
continue;
if (ts->pchan != free_type)
if (ts->pchan_is != free_type)
continue;
subslots = ts_subslots(ts);
for (j = 0; j < subslots; j++) {
struct gsm_lchan *lchan = &ts->lchan[j];
if (lchan->state == LCHAN_S_NONE) {
vty_out(vty, "Found unused %s slot: %s%s",
gsm_pchan_name(free_type),
gsm_lchan_name(lchan),
VTY_NEWLINE);
lchan_dump_full_vty(vty, lchan);
return bts;
}
ts_for_each_lchan(lchan, ts) {
if (lchan->fi->state != LCHAN_ST_UNUSED)
continue;
vty_out(vty, "Found unused %s slot: %s%s",
gsm_pchan_name(free_type),
gsm_lchan_name(lchan),
VTY_NEWLINE);
lchan_dump_full_vty(vty, lchan);
return bts;
}
}
}
@ -1740,7 +1699,7 @@ DEFUN(handover_any, handover_any_cmd,
return CMD_WARNING;
to_bts = find_other_bts_with_free_slots(vty, from_lchan->ts->trx->bts,
ts_pchan(from_lchan->ts));
from_lchan->ts->pchan_is);
if (!to_bts)
return CMD_WARNING;
@ -1762,6 +1721,38 @@ DEFUN(assignment_any, assignment_any_cmd,
return trigger_ho_or_as(vty, from_lchan, NULL);
}
DEFUN(handover_any_to_arfcn_bsic, handover_any_to_arfcn_bsic_cmd,
"handover any to " NEIGHBOR_IDENT_VTY_KEY_PARAMS,
MANUAL_HANDOVER_STR
"Pick any actively used TCH/F or TCH/H lchan to handover to another cell."
" This is likely to fail outside of a lab setup where you are certain that"
" all MS are able to see the target cell.\n"
"'to'\n"
NEIGHBOR_IDENT_VTY_KEY_DOC)
{
struct handover_out_req req;
struct gsm_lchan *from_lchan;
from_lchan = find_used_voice_lchan(vty);
if (!from_lchan)
return CMD_WARNING;
req = (struct handover_out_req){
.from_hodec_id = HODEC_USER,
.old_lchan = from_lchan,
};
if (!neighbor_ident_bts_parse_key_params(vty, from_lchan->ts->trx->bts,
argv, &req.target_nik)) {
vty_out(vty, "%% BTS %u does not know about this neighbor%s",
from_lchan->ts->trx->bts->nr, VTY_NEWLINE);
return CMD_WARNING;
}
handover_request(&req);
return CMD_SUCCESS;
}
static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag)
{
vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE);
@ -3956,7 +3947,7 @@ DEFUN(cfg_ts_pchan,
if (pchanc < 0)
return CMD_WARNING;
ts->pchan = pchanc;
ts->pchan_from_config = pchanc;
return CMD_SUCCESS;
}
@ -3977,7 +3968,7 @@ DEFUN_HIDDEN(cfg_ts_pchan_compat,
return CMD_ERR_NO_MATCH;
}
ts->pchan = pchanc;
ts->pchan_from_config = pchanc;
return CMD_SUCCESS;
}
@ -4325,8 +4316,10 @@ DEFUN(pdch_act, pdch_act_cmd,
int activate;
ts = vty_get_ts(vty, argv[0], argv[1], argv[2]);
if (!ts)
if (!ts || !ts->fi || ts->fi->state == TS_ST_NOT_INITIALIZED || ts->fi->state == TS_ST_BORKEN) {
vty_out(vty, "%% Timeslot is not usable%s", VTY_NEWLINE);
return CMD_WARNING;
}
if (!is_ipaccess_bts(ts->trx->bts)) {
vty_out(vty, "%% This command only works for ipaccess BTS%s",
@ -4334,9 +4327,10 @@ DEFUN(pdch_act, pdch_act_cmd,
return CMD_WARNING;
}
if (ts->pchan != GSM_PCHAN_TCH_F_PDCH) {
vty_out(vty, "%% Timeslot %u is not in dynamic TCH_F/PDCH "
"mode%s", ts->nr, VTY_NEWLINE);
if (ts->pchan_on_init != GSM_PCHAN_TCH_F_TCH_H_PDCH
&& ts->pchan_on_init != GSM_PCHAN_TCH_F_PDCH) {
vty_out(vty, "%% Timeslot %u is not dynamic TCH/F_TCH/H_PDCH or TCH/F_PDCH%s",
ts->nr, VTY_NEWLINE);
return CMD_WARNING;
}
@ -4345,30 +4339,24 @@ DEFUN(pdch_act, pdch_act_cmd,
else
activate = 0;
rsl_ipacc_pdch_activate(ts, activate);
if (activate && ts->fi->state != TS_ST_UNUSED) {
vty_out(vty, "%% Timeslot %u is still in use%s",
ts->nr, VTY_NEWLINE);
return CMD_WARNING;
} else if (!activate && ts->fi->state != TS_ST_PDCH) {
vty_out(vty, "%% Timeslot %u is not in PDCH mode%s",
ts->nr, VTY_NEWLINE);
return CMD_WARNING;
}
LOG_TS(ts, LOGL_NOTICE, "telnet VTY user asks to %s\n", activate ? "PDCH ACT" : "PDCH DEACT");
ts->pdch_act_allowed = activate;
osmo_fsm_inst_state_chg(ts->fi, activate ? TS_ST_WAIT_PDCH_ACT : TS_ST_WAIT_PDCH_DEACT, 4, 0);
return CMD_SUCCESS;
}
/* determine the logical channel type based on the physical channel type */
static int lchan_type_by_pchan(enum gsm_phys_chan_config pchan)
{
switch (pchan) {
case GSM_PCHAN_TCH_F:
return GSM_LCHAN_TCH_F;
case GSM_PCHAN_TCH_H:
return GSM_LCHAN_TCH_H;
case GSM_PCHAN_SDCCH8_SACCH8C:
case GSM_PCHAN_SDCCH8_SACCH8C_CBCH:
case GSM_PCHAN_CCCH_SDCCH4:
case GSM_PCHAN_CCCH_SDCCH4_CBCH:
return GSM_LCHAN_SDCCH;
default:
return -1;
}
}
/* configure the lchan for a single AMR mode (as specified) */
static int lchan_set_single_amr_mode(struct gsm_lchan *lchan, uint8_t amr_mode)
{
@ -4425,19 +4413,21 @@ DEFUN(lchan_act, lchan_act_cmd,
else
activate = 0;
if (ss_nr >= ts_subslots(ts)) {
vty_out(vty, "%% subslot %d >= permitted %d for physical channel %s%s",
ss_nr, ts_subslots(ts), gsm_pchan_name(ts->pchan), VTY_NEWLINE);
/* FIXME: allow dynamic channels with switchover, lchan_activate(lchan, FOR_VTY) */
if (ss_nr >= pchan_subslots(ts->pchan_is)) {
vty_out(vty, "%% subslot index %d too large for physical channel %s (%u slots)%s",
ss_nr, gsm_pchan_name(ts->pchan_is), pchan_subslots(ts->pchan_is),
VTY_NEWLINE);
return CMD_WARNING;
}
if (activate) {
int lchan_t;
if (lchan->state != LCHAN_S_NONE) {
if (lchan->fi->state != LCHAN_ST_UNUSED) {
vty_out(vty, "%% Cannot activate: Channel busy!%s", VTY_NEWLINE);
return CMD_WARNING;
}
lchan_t = lchan_type_by_pchan(ts->pchan);
lchan_t = gsm_lchan_type_by_pchan(ts->pchan_is);
if (lchan_t < 0)
return CMD_WARNING;
/* configure the lchan */
@ -4458,10 +4448,16 @@ DEFUN(lchan_act, lchan_act_cmd,
lchan_set_single_amr_mode(lchan, amr_mode);
}
vty_out(vty, "%% activating lchan %s%s", gsm_lchan_name(lchan), VTY_NEWLINE);
rsl_chan_activate_lchan(lchan, RSL_ACT_TYPE_INITIAL, 0);
rsl_ipacc_crcx(lchan);
rsl_tx_chan_activ(lchan, RSL_ACT_TYPE_INITIAL, 0);
rsl_tx_ipacc_crcx(lchan);
} else {
rsl_direct_rf_release(lchan);
if (!lchan->fi) {
vty_out(vty, "%% Cannot release: Channel not initialized%s", VTY_NEWLINE);
return CMD_WARNING;
}
vty_out(vty, "%% Asking for release of %s in state %s%s", gsm_lchan_name(lchan),
osmo_fsm_inst_state_name(lchan->fi), VTY_NEWLINE);
lchan_release(lchan, false, false, 0);
}
return CMD_SUCCESS;
@ -4485,15 +4481,18 @@ DEFUN(lchan_mdcx, lchan_mdcx_cmd,
lchan = &ts->lchan[ss_nr];
if (ss_nr >= ts_subslots(ts)) {
vty_out(vty, "%% subslot %d >= permitted %d for physical channel %s%s",
ss_nr, ts_subslots(ts), gsm_pchan_name(ts->pchan), VTY_NEWLINE);
if (ss_nr >= pchan_subslots(ts->pchan_is)) {
vty_out(vty, "%% subslot index %d too large for physical channel %s (%u slots)%s",
ss_nr, gsm_pchan_name(ts->pchan_is), pchan_subslots(ts->pchan_is),
VTY_NEWLINE);
return CMD_WARNING;
}
vty_out(vty, "%% connecting RTP of %s to %s:%u%s", gsm_lchan_name(lchan),
inet_ntoa(ia), port, VTY_NEWLINE);
rsl_ipacc_mdcx(lchan, ntohl(ia.s_addr), port, 0);
lchan->abis_ip.connect_ip = ia.s_addr;
lchan->abis_ip.connect_port = port;
rsl_tx_ipacc_mdcx(lchan);
return CMD_SUCCESS;
}
@ -4775,12 +4774,14 @@ int bsc_vty_init(struct gsm_network *network)
install_element_ve(&show_lchan_summary_cmd);
install_element_ve(&show_subscr_conn_cmd);
install_element_ve(&handover_any_cmd);
install_element_ve(&assignment_any_cmd);
install_element_ve(&show_paging_cmd);
install_element_ve(&show_paging_group_cmd);
install_element(ENABLE_NODE, &handover_any_cmd);
install_element(ENABLE_NODE, &assignment_any_cmd);
install_element(ENABLE_NODE, &handover_any_to_arfcn_bsic_cmd);
logging_vty_add_cmds(NULL);
osmo_talloc_vty_add_cmds();

View File

@ -28,6 +28,7 @@
#include <osmocom/bsc/abis_nm.h>
#include <osmocom/abis/e1_input.h>
#include <osmocom/bsc/signal.h>
#include <osmocom/bsc/timeslot_fsm.h>
#include <osmocom/abis/lapd.h>
@ -52,7 +53,7 @@ static void bootstrap_om_trx(struct gsm_bts_trx *trx)
static int shutdown_om(struct gsm_bts *bts)
{
gsm_bts_mark_all_ts_uninitialized(bts);
gsm_bts_all_ts_dispatch(bts, TS_EV_OML_DOWN, NULL);
/* FIXME */
return 0;

View File

@ -42,6 +42,7 @@
#include <osmocom/bsc/ipaccess.h>
#include <osmocom/bsc/bts_ipaccess_nanobts_omlattr.h>
#include <osmocom/bsc/paging.h>
#include <osmocom/bsc/timeslot_fsm.h>
static int bts_model_nanobts_start(struct gsm_network *net);
static void bts_model_nanobts_e1line_bind_ops(struct e1inp_line *line);
@ -169,7 +170,7 @@ static int nm_statechg_event(int evt, struct nm_statechg_signal_data *nsd)
if (new_state->operational == NM_OPSTATE_DISABLED &&
new_state->availability == NM_AVSTATE_DEPENDENCY) {
enum abis_nm_chan_comb ccomb =
abis_nm_chcomb4pchan(ts->pchan);
abis_nm_chcomb4pchan(ts->pchan_from_config);
if (abis_nm_set_channel_attr(ts, ccomb) == -EINVAL) {
ipaccess_drop_oml(trx->bts);
return -1;
@ -305,8 +306,12 @@ static void nm_rx_opstart_ack_chan(struct msgb *oml_msg)
if (!ts)
/* error already logged in abis_nm_get_ts() */
return;
if (!ts->fi) {
LOG_TS(ts, LOGL_ERROR, "Channel OPSTART ACK for uninitialized TS\n");
return;
}
gsm_ts_check_init(ts);
osmo_fsm_inst_dispatch(ts->fi, TS_EV_OML_READY, NULL);
}
static void nm_rx_opstart_ack(struct msgb *oml_msg)
@ -413,7 +418,7 @@ void ipaccess_drop_oml(struct gsm_bts *bts)
llist_for_each_entry(trx, &bts->trx_list, list)
ipaccess_drop_rsl(trx);
gsm_bts_mark_all_ts_uninitialized(bts);
gsm_bts_all_ts_dispatch(bts, TS_EV_OML_DOWN, NULL);
bts->ip_access.flags = 0;

View File

@ -35,6 +35,7 @@
#include <osmocom/bsc/abis_nm.h>
#include <osmocom/abis/e1_input.h>
#include <osmocom/bsc/signal.h>
#include <osmocom/bsc/timeslot_fsm.h>
#include <osmocom/core/timer.h>
@ -55,13 +56,13 @@ static void bootstrap_om_bts(struct gsm_bts *bts)
{
LOGP(DNM, LOGL_NOTICE, "bootstrapping OML for BTS %u\n", bts->nr);
gsm_bts_mark_all_ts_uninitialized(bts);
if (!bts->nokia.skip_reset) {
if (!bts->nokia.did_reset)
abis_nm_reset(bts, 1);
} else
bts->nokia.did_reset = 1;
gsm_bts_all_ts_dispatch(bts, TS_EV_OML_READY, NULL);
}
static void bootstrap_om_trx(struct gsm_bts_trx *trx)
@ -69,7 +70,7 @@ static void bootstrap_om_trx(struct gsm_bts_trx *trx)
LOGP(DNM, LOGL_NOTICE, "bootstrapping OML for TRX %u/%u\n",
trx->bts->nr, trx->nr);
gsm_trx_mark_all_ts_uninitialized(trx);
gsm_trx_all_ts_dispatch(trx, TS_EV_OML_READY, NULL);
}
static int shutdown_om(struct gsm_bts *bts)
@ -779,24 +780,32 @@ static int make_fu_config(struct gsm_bts_trx *trx, uint8_t id,
0xFF = spare TS
*/
if (ts->pchan == GSM_PCHAN_NONE)
switch (ts->pchan_from_config) {
case GSM_PCHAN_NONE:
chan_config = 0xFF;
else if (ts->pchan == GSM_PCHAN_CCCH)
break;
case GSM_PCHAN_CCCH:
chan_config = 0;
else if (ts->pchan == GSM_PCHAN_CCCH_SDCCH4)
break;
case GSM_PCHAN_CCCH_SDCCH4:
chan_config = 1;
else if (ts->pchan == GSM_PCHAN_TCH_F)
break;
case GSM_PCHAN_TCH_F:
chan_config = 6; /* 9 should work too */
else if (ts->pchan == GSM_PCHAN_TCH_H)
break;
case GSM_PCHAN_TCH_H:
chan_config = 9;
else if (ts->pchan == GSM_PCHAN_SDCCH8_SACCH8C)
break;
case GSM_PCHAN_SDCCH8_SACCH8C:
chan_config = 4;
else if (ts->pchan == GSM_PCHAN_PDCH)
break;
case GSM_PCHAN_PDCH:
chan_config = 11;
else {
break;
default:
fprintf(stderr,
"unsupported channel config %d for timeslot %d\n",
ts->pchan, i);
"unsupported channel config %s for timeslot %d\n",
gsm_pchan_name(ts->pchan_from_config), i);
return 0;
}

View File

@ -28,6 +28,7 @@
#include <osmocom/abis/e1_input.h>
#include <osmocom/bsc/signal.h>
#include <osmocom/bsc/gsm_timers.h>
#include <osmocom/bsc/timeslot_fsm.h>
static int bts_model_bs11_start(struct gsm_network *net);
@ -393,7 +394,7 @@ static void patch_nm_tables(struct gsm_bts *bts)
static void nm_reconfig_ts(struct gsm_bts_trx_ts *ts)
{
enum abis_nm_chan_comb ccomb = abis_nm_chcomb4pchan(ts->pchan);
enum abis_nm_chan_comb ccomb = abis_nm_chcomb4pchan(ts->pchan_from_config);
struct gsm_e1_subslot *e1l = &ts->e1_link;
abis_nm_set_channel_attr(ts, ccomb);
@ -537,7 +538,7 @@ static int shutdown_om(struct gsm_bts *bts)
/* Reset BTS Site manager resource */
abis_nm_bs11_reset_resource(bts);
gsm_bts_mark_all_ts_uninitialized(bts);
gsm_bts_all_ts_dispatch(bts, TS_EV_OML_DOWN, NULL);
return 0;
}

View File

@ -31,576 +31,12 @@
#include <osmocom/bsc/abis_rsl.h>
#include <osmocom/bsc/debug.h>
#include <osmocom/bsc/signal.h>
#include <osmocom/bsc/timeslot_fsm.h>
#include <osmocom/bsc/lchan_fsm.h>
#include <osmocom/bsc/gsm_04_08_rr.h>
#include <osmocom/core/talloc.h>
bool ts_is_usable(const struct gsm_bts_trx_ts *ts)
{
if (!trx_is_usable(ts->trx)) {
LOGP(DRLL, LOGL_DEBUG, "%s not usable\n", gsm_trx_name(ts->trx));
return false;
}
/* If a TCH/F_PDCH TS is busy changing, it is already taken or not
* yet available. */
if (ts->pchan == GSM_PCHAN_TCH_F_PDCH) {
if (ts->flags & TS_F_PDCH_PENDING_MASK) {
LOGP(DRLL, LOGL_DEBUG, "%s in switchover, not available\n",
gsm_ts_and_pchan_name(ts));
return false;
}
}
/* If a dynamic channel is busy changing, it is already taken or not
* yet available. */
if (ts->pchan == GSM_PCHAN_TCH_F_TCH_H_PDCH) {
if (ts->dyn.pchan_is != ts->dyn.pchan_want) {
LOGP(DRLL, LOGL_DEBUG, "%s in switchover, not available\n",
gsm_ts_and_pchan_name(ts));
return false;
}
}
return true;
}
static int trx_count_free_ts(struct gsm_bts_trx *trx, enum gsm_phys_chan_config pchan)
{
struct gsm_bts_trx_ts *ts;
int j, ss;
int count = 0;
if (!trx_is_usable(trx))
return 0;
for (j = 0; j < ARRAY_SIZE(trx->ts); j++) {
enum gsm_phys_chan_config ts_pchan_is;
ts = &trx->ts[j];
if (!ts_is_usable(ts))
continue;
ts_pchan_is = ts_pchan(ts);
if (ts_pchan_is == GSM_PCHAN_PDCH) {
/* Dynamic timeslots in PDCH mode will become TCH if needed. */
switch (ts->pchan) {
case GSM_PCHAN_TCH_F_PDCH:
if (pchan == GSM_PCHAN_TCH_F)
count++;
continue;
case GSM_PCHAN_TCH_F_TCH_H_PDCH:
if (pchan == GSM_PCHAN_TCH_F)
count++;
else if (pchan == GSM_PCHAN_TCH_H)
count += 2;
continue;
default:
/* Not dynamic, not applicable. */
continue;
}
}
if (ts_pchan_is != pchan)
continue;
/* check if all sub-slots are allocated yet */
for (ss = 0; ss < ts_subslots(ts); ss++) {
struct gsm_lchan *lc = &ts->lchan[ss];
if (lc->type == GSM_LCHAN_NONE &&
lc->state == LCHAN_S_NONE)
count++;
}
}
return count;
}
/* Count number of free TS of given pchan type */
int bts_count_free_ts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan)
{
struct gsm_bts_trx *trx;
int count = 0;
llist_for_each_entry(trx, &bts->trx_list, list)
count += trx_count_free_ts(trx, pchan);
return count;
}
static bool ts_usable_as_pchan(struct gsm_bts_trx_ts *ts,
enum gsm_phys_chan_config as_pchan)
{
switch (ts->pchan) {
case GSM_PCHAN_TCH_F_PDCH:
if (ts->flags & TS_F_PDCH_PENDING_MASK) {
/* currently being switched over. Not usable. */
return false;
}
switch (as_pchan) {
case GSM_PCHAN_TCH_F:
case GSM_PCHAN_PDCH:
/* continue to check below. */
break;
default:
return false;
}
break;
case GSM_PCHAN_TCH_F_TCH_H_PDCH:
if (ts->dyn.pchan_is != ts->dyn.pchan_want) {
/* currently being switched over. Not usable. */
return false;
}
switch (as_pchan) {
case GSM_PCHAN_TCH_F:
case GSM_PCHAN_TCH_H:
case GSM_PCHAN_PDCH:
/* continue to check below. */
break;
default:
return false;
}
break;
default:
/* static timeslots never switch. */
return ts->pchan == as_pchan;
}
/* Dynamic timeslots -- Checks depending on the current actual pchan mode: */
switch (ts_pchan(ts)) {
case GSM_PCHAN_NONE:
/* Not initialized, possibly because GPRS was disabled. We may switch. */
return true;
case GSM_PCHAN_PDCH:
/* This slot is in PDCH mode and available to switch pchan mode. But check for
* error states: */
if (ts->lchan->state != LCHAN_S_NONE && ts->lchan->state != LCHAN_S_ACTIVE)
return false;
return true;
case GSM_PCHAN_TCH_F:
case GSM_PCHAN_TCH_H:
/* No need to switch at all? */
if (ts_pchan(ts) == as_pchan)
return true;
/* If any lchan is in use, we can't change the pchan kind */
{
int ss;
int subslots = ts_subslots(ts);
for (ss = 0; ss < subslots; ss++) {
struct gsm_lchan *lc = &ts->lchan[ss];
if (lc->type != GSM_LCHAN_NONE || lc->state != LCHAN_S_NONE)
return false;
}
}
return true;
default:
/* Not implemented. */
return false;
}
}
static struct gsm_lchan *
_lc_find_trx(struct gsm_bts_trx *trx, enum gsm_phys_chan_config pchan,
enum gsm_phys_chan_config as_pchan)
{
struct gsm_bts_trx_ts *ts;
int j, start, stop, dir, ss;
int check_subslots;
#define LOGPLCHANALLOC(fmt, args...) \
LOGP(DRLL, LOGL_DEBUG, "looking for lchan %s as %s: " fmt, \
gsm_pchan_name(pchan), gsm_pchan_name(as_pchan), ## args)
if (!trx_is_usable(trx)) {
LOGPLCHANALLOC("%s trx not usable\n", gsm_trx_name(trx));
return NULL;
}
if (trx->bts->chan_alloc_reverse) {
/* check TS 7..0 */
start = 7;
stop = -1;
dir = -1;
} else {
/* check TS 0..7 */
start = 0;
stop = 8;
dir = 1;
}
for (j = start; j != stop; j += dir) {
ts = &trx->ts[j];
if (!ts_is_usable(ts))
continue;
/* The caller first selects what kind of TS to search in, e.g. looking for exact
* GSM_PCHAN_TCH_F, or maybe among dynamic GSM_PCHAN_TCH_F_TCH_H_PDCH... */
if (ts->pchan != pchan) {
LOGPLCHANALLOC("%s is != %s\n", gsm_ts_and_pchan_name(ts),
gsm_pchan_name(pchan));
continue;
}
/* Next, is this timeslot in or can it be switched to the pchan we want to use it for? */
if (!ts_usable_as_pchan(ts, as_pchan)) {
LOGPLCHANALLOC("%s is not usable as %s\n", gsm_ts_and_pchan_name(ts),
gsm_pchan_name(as_pchan));
continue;
}
/* If we need to switch it, after above check we are also allowed to switch it, and we
* will always use the first lchan after the switch. Return that lchan and rely on the
* caller to perform the pchan switchover. */
if (ts_pchan(ts) != as_pchan) {
LOGPLCHANALLOC("%s is a match, will switch to %s\n", gsm_ts_and_pchan_name(ts),
gsm_pchan_name(as_pchan));
return ts->lchan;
}
/* TS is in desired pchan mode. Go ahead and check for an available lchan. */
check_subslots = ts_subslots(ts);
for (ss = 0; ss < check_subslots; ss++) {
struct gsm_lchan *lc = &ts->lchan[ss];
if (lc->type == GSM_LCHAN_NONE &&
lc->state == LCHAN_S_NONE) {
LOGPLCHANALLOC("%s ss=%d is available\n", gsm_ts_and_pchan_name(ts),
lc->nr);
return lc;
}
LOGPLCHANALLOC("%s ss=%d in type=%s,state=%s not suitable\n",
gsm_ts_and_pchan_name(ts), lc->nr, gsm_lchant_name(lc->type),
gsm_lchans_name(lc->state));
}
}
return NULL;
#undef LOGPLCHANALLOC
}
static struct gsm_lchan *
_lc_dyn_find_bts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan,
enum gsm_phys_chan_config dyn_as_pchan)
{
struct gsm_bts_trx *trx;
struct gsm_lchan *lc;
if (bts->chan_alloc_reverse) {
llist_for_each_entry_reverse(trx, &bts->trx_list, list) {
lc = _lc_find_trx(trx, pchan, dyn_as_pchan);
if (lc)
return lc;
}
} else {
llist_for_each_entry(trx, &bts->trx_list, list) {
lc = _lc_find_trx(trx, pchan, dyn_as_pchan);
if (lc)
return lc;
}
}
return NULL;
}
static struct gsm_lchan *
_lc_find_bts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan)
{
return _lc_dyn_find_bts(bts, pchan, pchan);
}
/* Allocate a logical channel.
*
* Dynamic channel types: we always prefer a dedicated TS, and only pick +
* switch a dynamic TS if no pure TS of the requested PCHAN is available.
*
* TCH_F/PDCH: if we pick a PDCH ACT style dynamic TS as TCH/F channel, PDCH
* will be disabled in rsl_chan_activate_lchan(); there is no need to check
* whether PDCH mode is currently active, here.
*/
struct gsm_lchan *lchan_alloc(struct gsm_bts *bts, enum gsm_chan_t type,
int allow_bigger)
{
struct gsm_lchan *lchan = NULL;
enum gsm_phys_chan_config first, first_cbch, second, second_cbch;
LOGP(DRLL, LOGL_DEBUG, "(bts=%d) lchan_alloc(%s)\n", bts->nr, gsm_lchant_name(type));
switch (type) {
case GSM_LCHAN_SDCCH:
if (bts->chan_alloc_reverse) {
first = GSM_PCHAN_SDCCH8_SACCH8C;
first_cbch = GSM_PCHAN_SDCCH8_SACCH8C_CBCH;
second = GSM_PCHAN_CCCH_SDCCH4;
second_cbch = GSM_PCHAN_CCCH_SDCCH4_CBCH;
} else {
first = GSM_PCHAN_CCCH_SDCCH4;
first_cbch = GSM_PCHAN_CCCH_SDCCH4_CBCH;
second = GSM_PCHAN_SDCCH8_SACCH8C;
second_cbch = GSM_PCHAN_SDCCH8_SACCH8C_CBCH;
}
lchan = _lc_find_bts(bts, first);
if (lchan == NULL)
lchan = _lc_find_bts(bts, first_cbch);
if (lchan == NULL)
lchan = _lc_find_bts(bts, second);
if (lchan == NULL)
lchan = _lc_find_bts(bts, second_cbch);
/* allow to assign bigger channels */
if (allow_bigger) {
if (lchan == NULL) {
lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_H);
if (lchan)
type = GSM_LCHAN_TCH_H;
}
if (lchan == NULL) {
lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_F);
if (lchan)
type = GSM_LCHAN_TCH_F;
}
/* try dynamic TCH/F_PDCH */
if (lchan == NULL) {
lchan = _lc_dyn_find_bts(bts, GSM_PCHAN_TCH_F_PDCH,
GSM_PCHAN_TCH_F);
/* TCH/F_PDCH will be used as TCH/F */
if (lchan)
type = GSM_LCHAN_TCH_F;
}
/* try fully dynamic TCH/F_TCH/H_PDCH */
if (lchan == NULL) {
lchan = _lc_dyn_find_bts(bts, GSM_PCHAN_TCH_F_TCH_H_PDCH,
GSM_PCHAN_TCH_H);
if (lchan)
type = GSM_LCHAN_TCH_H;
}
/*
* No need to check fully dynamic channels for TCH/F:
* if no TCH/H was available, neither will be TCH/F.
*/
}
break;
case GSM_LCHAN_TCH_F:
lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_F);
/* If we don't have TCH/F available, fall-back to TCH/H */
if (!lchan) {
lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_H);
if (lchan)
type = GSM_LCHAN_TCH_H;
}
/* If we don't have TCH/H either, try dynamic TCH/F_PDCH */
if (!lchan) {
lchan = _lc_dyn_find_bts(bts, GSM_PCHAN_TCH_F_PDCH,
GSM_PCHAN_TCH_F);
/* TCH/F_PDCH used as TCH/F -- here, type is already
* set to GSM_LCHAN_TCH_F, but for clarity's sake... */
if (lchan)
type = GSM_LCHAN_TCH_F;
}
/* Try fully dynamic TCH/F_TCH/H_PDCH as TCH/F... */
if (!lchan && bts->network->dyn_ts_allow_tch_f) {
lchan = _lc_dyn_find_bts(bts,
GSM_PCHAN_TCH_F_TCH_H_PDCH,
GSM_PCHAN_TCH_F);
if (lchan)
type = GSM_LCHAN_TCH_F;
}
/* ...and as TCH/H. */
if (!lchan) {
lchan = _lc_dyn_find_bts(bts,
GSM_PCHAN_TCH_F_TCH_H_PDCH,
GSM_PCHAN_TCH_H);
if (lchan)
type = GSM_LCHAN_TCH_H;
}
break;
case GSM_LCHAN_TCH_H:
lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_H);
/* If we don't have TCH/H available, fall-back to TCH/F */
if (!lchan) {
lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_F);
if (lchan)
type = GSM_LCHAN_TCH_F;
}
/* No dedicated TCH/x available -- try fully dynamic
* TCH/F_TCH/H_PDCH */
if (!lchan) {
lchan = _lc_dyn_find_bts(bts,
GSM_PCHAN_TCH_F_TCH_H_PDCH,
GSM_PCHAN_TCH_H);
if (lchan)
type = GSM_LCHAN_TCH_H;
}
/*
* No need to check TCH/F_TCH/H_PDCH channels for TCH/F:
* if no TCH/H was available, neither will be TCH/F.
*/
/* If we don't have TCH/F either, try dynamic TCH/F_PDCH */
if (!lchan) {
lchan = _lc_dyn_find_bts(bts, GSM_PCHAN_TCH_F_PDCH,
GSM_PCHAN_TCH_F);
if (lchan)
type = GSM_LCHAN_TCH_F;
}
break;
default:
LOGP(DRLL, LOGL_ERROR, "Unknown gsm_chan_t %u\n", type);
}
if (lchan) {
lchan->type = type;
LOGP(DRLL, LOGL_INFO, "%s Allocating lchan=%u as %s\n",
gsm_ts_and_pchan_name(lchan->ts),
lchan->nr, gsm_lchant_name(lchan->type));
/* reset measurement report counter and index */
lchan->meas_rep_count = 0;
lchan->meas_rep_idx = 0;
lchan->meas_rep_last_seen_nr = 255;
/* clear sapis */
memset(lchan->sapis, 0, ARRAY_SIZE(lchan->sapis));
/* clear multi rate config */
memset(&lchan->mr_ms_lv, 0, sizeof(lchan->mr_ms_lv));
memset(&lchan->mr_bts_lv, 0, sizeof(lchan->mr_bts_lv));
lchan->broken_reason = "";
} else {
struct challoc_signal_data sig;
LOGP(DRLL, LOGL_ERROR, "(bts=%d) Failed to allocate %s channel\n",
bts->nr, gsm_lchant_name(type));
sig.bts = bts;
sig.type = type;
osmo_signal_dispatch(SS_CHALLOC, S_CHALLOC_ALLOC_FAIL, &sig);
}
return lchan;
}
/* Free a logical channel */
void lchan_free(struct gsm_lchan *lchan)
{
struct challoc_signal_data sig;
int i;
sig.type = lchan->type;
lchan->type = GSM_LCHAN_NONE;
if (lchan->conn
&& !(lchan->ts->pchan == GSM_PCHAN_TCH_F_TCH_H_PDCH
&& lchan->ts->dyn.pchan_is != lchan->ts->dyn.pchan_want)) {
struct lchan_signal_data sig;
/* We might kill an active channel... */
sig.lchan = lchan;
sig.mr = NULL;
osmo_signal_dispatch(SS_LCHAN, S_LCHAN_UNEXPECTED_RELEASE, &sig);
}
/* stop the timer */
osmo_timer_del(&lchan->T3101);
/* clear cached measuement reports */
lchan->meas_rep_idx = 0;
for (i = 0; i < ARRAY_SIZE(lchan->meas_rep); i++) {
lchan->meas_rep[i].flags = 0;
lchan->meas_rep[i].nr = 0;
}
for (i = 0; i < ARRAY_SIZE(lchan->neigh_meas); i++)
lchan->neigh_meas[i].arfcn = 0;
if (lchan->rqd_ref) {
talloc_free(lchan->rqd_ref);
lchan->rqd_ref = NULL;
lchan->rqd_ta = 0;
}
sig.lchan = lchan;
sig.bts = lchan->ts->trx->bts;
osmo_signal_dispatch(SS_CHALLOC, S_CHALLOC_FREED, &sig);
if (lchan->conn
&& !(lchan->ts->pchan == GSM_PCHAN_TCH_F_TCH_H_PDCH
&& lchan->ts->dyn.pchan_is != lchan->ts->dyn.pchan_want)) {
LOGP(DRLL, LOGL_ERROR, "the subscriber connection should be gone.\n");
lchan->conn = NULL;
}
/* FIXME: ts_free() the timeslot, if we're the last logical
* channel using it */
/* reset RTP voice connection related data */
memset(&lchan->abis_ip, 0, sizeof(lchan->abis_ip));
}
/*
* There was an error with the TRX and we need to forget
* any state so that a lchan can be allocated again after
* the trx is fully usable.
*
* This should be called after lchan_free to force a channel
* be available for allocation again. This means that this
* method will stop the "delay after error"-timer and set the
* state to LCHAN_S_NONE.
*/
void lchan_reset(struct gsm_lchan *lchan)
{
osmo_timer_del(&lchan->T3101);
osmo_timer_del(&lchan->T3109);
osmo_timer_del(&lchan->T3111);
osmo_timer_del(&lchan->error_timer);
lchan->type = GSM_LCHAN_NONE;
rsl_lchan_set_state(lchan, LCHAN_S_NONE);
}
/* Drive the release process of the lchan */
static void _lchan_handle_release(struct gsm_lchan *lchan,
int sacch_deact, int mode)
{
/* Release all SAPIs on the local end and continue */
rsl_release_sapis_from(lchan, 1, RSL_REL_LOCAL_END);
/*
* Shall we send a RR Release, start T3109 and wait for the
* release indication from the BTS or just take it down (e.g.
* on assignment requests)
*/
if (sacch_deact) {
gsm48_send_rr_release(lchan);
/* Deactivate the SACCH on the BTS side */
rsl_deact_sacch(lchan);
rsl_start_t3109(lchan);
} else if (lchan->sapis[0] == LCHAN_SAPI_UNUSED) {
rsl_direct_rf_release(lchan);
} else {
rsl_release_request(lchan, 0, mode);
}
}
/* Consider releasing the channel now */
int lchan_release(struct gsm_lchan *lchan, int sacch_deact, enum rsl_rel_mode mode)
{
DEBUGP(DRLL, "%s starting release sequence\n", gsm_lchan_name(lchan));
rsl_lchan_set_state(lchan, LCHAN_S_REL_REQ);
lchan->conn = NULL;
_lchan_handle_release(lchan, sacch_deact, mode);
return 1;
}
void bts_chan_load(struct pchan_load *cl, const struct gsm_bts *bts)
{
struct gsm_bts_trx *trx;
@ -615,22 +51,18 @@ void bts_chan_load(struct pchan_load *cl, const struct gsm_bts *bts)
for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
struct gsm_bts_trx_ts *ts = &trx->ts[i];
struct load_counter *pl = &cl->pchan[ts->pchan];
int j;
int subslots;
struct load_counter *pl = &cl->pchan[ts->pchan_on_init];
struct gsm_lchan *lchan;
/* skip administratively deactivated timeslots */
if (!nm_is_running(&ts->mo.nm_state))
continue;
subslots = ts_subslots(ts);
for (j = 0; j < subslots; j++) {
struct gsm_lchan *lchan = &ts->lchan[j];
ts_for_each_lchan(lchan, ts) {
pl->total++;
switch (lchan->state) {
case LCHAN_S_NONE:
switch (lchan->fi->state) {
case LCHAN_ST_UNUSED:
break;
default:
pl->used++;

View File

@ -27,7 +27,7 @@
/* Helper function for match_codec_pref(), looks up a matching chan mode for
* a given permitted speech value */
enum gsm48_chan_mode gsm88_to_chan_mode(enum gsm0808_permitted_speech speech)
static enum gsm48_chan_mode gsm88_to_chan_mode(enum gsm0808_permitted_speech speech)
{
switch (speech) {
case GSM0808_PERM_HR1:
@ -50,7 +50,7 @@ enum gsm48_chan_mode gsm88_to_chan_mode(enum gsm0808_permitted_speech speech)
/* Helper function for match_codec_pref(), looks up a matching permitted speech
* value for a given msc audio codec pref */
enum gsm0808_permitted_speech audio_support_to_gsm88(struct gsm_audio_support *audio)
static enum gsm0808_permitted_speech audio_support_to_gsm88(const struct gsm_audio_support *audio)
{
if (audio->hr) {
switch (audio->ver) {
@ -108,7 +108,7 @@ static bool test_codec_pref(const struct gsm0808_channel_type *ct,
/* If we do not have a speech codec list to test against,
* we just exit early (will be always the case in non-AoIP networks) */
if (!scl)
if (!scl || !scl->len)
return match;
/* If we failed to match until here, there is no
@ -133,7 +133,7 @@ static bool test_codec_pref(const struct gsm0808_channel_type *ct,
/* Helper function to check if the given permitted speech value is supported
* by the BTS. (vty option bts->codec-support). */
static bool test_codec_support_bts(struct gsm_bts *bts, uint8_t perm_spch)
static bool test_codec_support_bts(const struct bts_codec_conf *bts_codec, uint8_t perm_spch)
{
switch (perm_spch) {
case GSM0808_PERM_FR1:
@ -141,16 +141,16 @@ static bool test_codec_support_bts(struct gsm_bts *bts, uint8_t perm_spch)
* selectively disable GSM-RF per BTS via VTY. */
return true;
case GSM0808_PERM_FR2:
if (bts->codec.efr)
if (bts_codec->efr)
return true;
case GSM0808_PERM_FR3:
if (bts->codec.amr)
if (bts_codec->amr)
return true;
case GSM0808_PERM_HR1:
if (bts->codec.hr)
if (bts_codec->hr)
return true;
case GSM0808_PERM_HR3:
if (bts->codec.amr)
if (bts_codec->amr)
return true;
default:
return false;
@ -159,29 +159,35 @@ static bool test_codec_support_bts(struct gsm_bts *bts, uint8_t perm_spch)
return false;
}
/*! Helper function for bssmap_handle_assignm_req(), matches the codec
* preferences from the MSC with the codec preferences
* \param[out] full_rate '1' if full-rate, '0' if half-rate, '-1' if no match
* \param[out] chan_mode GSM 04.08 channel mode
* \param[in] ct GSM 08.08 channel type
* \param[in] scl GSM 08.08 speech codec list
* \param[in] msc MSC data [for configuration]
* \param[in] bts BTS data [for configuration]
/*! Match the codec preferences from local config with a received codec preferences IEs received from the
* MSC and the BTS' codec configuration.
* \param[out] chan_mode GSM 04.08 channel mode.
* \param[out] full_rate true iff full-rate.
* \param[in] ct GSM 08.08 channel type received from MSC.
* \param[in] scl GSM 08.08 speech codec list received from MSC (optional).
* \param[in] audio_support List of allowed codecs as from local config.
* \param[in] audio_length Number of items in audio_support.
* \param[in] bts_codec BTS codec configuration.
* \returns 0 on success, -1 in case no match was found */
int match_codec_pref(int *full_rate, enum gsm48_chan_mode *chan_mode, const struct gsm0808_channel_type *ct,
const struct gsm0808_speech_codec_list *scl, const struct bsc_msc_data *msc, struct gsm_bts *bts)
int match_codec_pref(enum gsm48_chan_mode *chan_mode,
bool *full_rate,
const struct gsm0808_channel_type *ct,
const struct gsm0808_speech_codec_list *scl,
struct gsm_audio_support * const *audio_support,
int audio_length,
const struct bts_codec_conf *bts_codec)
{
unsigned int i;
uint8_t perm_spch;
bool match = false;
for (i = 0; i < msc->audio_length; i++) {
for (i = 0; i < audio_length; i++) {
/* Pick a permitted speech value from the global codec configuration list */
perm_spch = audio_support_to_gsm88(msc->audio_support[i]);
perm_spch = audio_support_to_gsm88(audio_support[i]);
/* Check this permitted speech value against the BTS specific parameters.
* if the BTS does not support the codec, try the next one */
if (test_codec_support_bts(bts, perm_spch) == false)
if (!test_codec_support_bts(bts_codec, perm_spch))
continue;
/* Match the permitted speech value against the codec lists that were
@ -194,17 +200,33 @@ int match_codec_pref(int *full_rate, enum gsm48_chan_mode *chan_mode, const stru
/* Exit without result, in case no match can be deteched */
if (!match) {
*full_rate = -1;
*full_rate = false;
*chan_mode = GSM48_CMODE_SIGN;
return -1;
}
/* Check if the result is a half or full rate codec */
if (perm_spch == GSM0808_PERM_HR1 || perm_spch == GSM0808_PERM_HR2 || perm_spch == GSM0808_PERM_HR3
|| perm_spch == GSM0808_PERM_HR4 || perm_spch == GSM0808_PERM_HR6)
*full_rate = 0;
else
*full_rate = 1;
switch (perm_spch) {
case GSM0808_PERM_HR1:
case GSM0808_PERM_HR2:
case GSM0808_PERM_HR3:
case GSM0808_PERM_HR4:
case GSM0808_PERM_HR6:
*full_rate = false;
break;
case GSM0808_PERM_FR1:
case GSM0808_PERM_FR2:
case GSM0808_PERM_FR3:
case GSM0808_PERM_FR4:
case GSM0808_PERM_FR5:
*full_rate = true;
break;
default:
LOGP(DMSC, LOGL_ERROR, "Invalid permitted-speech value: %u\n", perm_spch);
return -EINVAL;
}
/* Lookup a channel mode for the selected codec */
*chan_mode = gsm88_to_chan_mode(perm_spch);

View File

@ -36,14 +36,16 @@
#include <osmocom/bsc/signal.h>
#include <osmocom/bsc/bsc_subscr_conn_fsm.h>
#include <osmocom/bsc/gsm_04_08_rr.h>
#include <osmocom/bsc/chan_alloc.h>
#include <osmocom/bsc/lchan_fsm.h>
#include <osmocom/bsc/assignment_fsm.h>
#include <osmocom/bsc/handover_fsm.h>
#include <osmocom/bsc/bsc_api.h>
/* should ip.access BTS use direct RTP streams between each other (1),
* or should OpenBSC always act as RTP relay/proxy in between (0) ? */
int ipacc_rtp_direct = 1;
static int gsm48_sendmsg(struct msgb *msg)
int gsm48_sendmsg(struct msgb *msg)
{
if (msg->lchan)
msg->dst = msg->lchan->ts->trx->rsl_link;
@ -352,15 +354,13 @@ int gsm48_multirate_config(uint8_t *lv, const struct amr_multirate_conf *mr, con
#define GSM48_HOCMD_CCHDESC_LEN 16
/* Chapter 9.1.15: Handover Command */
int gsm48_send_ho_cmd(struct gsm_lchan *old_lchan, struct gsm_lchan *new_lchan,
uint8_t power_command, uint8_t ho_ref)
struct msgb *gsm48_make_ho_cmd(struct gsm_lchan *new_lchan, uint8_t power_command, uint8_t ho_ref)
{
struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 HO CMD");
struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
struct gsm48_ho_cmd *ho =
(struct gsm48_ho_cmd *) msgb_put(msg, sizeof(*ho));
msg->lchan = old_lchan;
gh->proto_discr = GSM48_PDISC_RR;
gh->msg_type = GSM48_MT_RR_HANDO_CMD;
@ -395,6 +395,16 @@ int gsm48_send_ho_cmd(struct gsm_lchan *old_lchan, struct gsm_lchan *new_lchan,
msgb_tlv_put(msg, GSM48_IE_MUL_RATE_CFG, new_lchan->mr_ms_lv[0],
new_lchan->mr_ms_lv + 1);
return msg;
}
int gsm48_send_ho_cmd(struct gsm_lchan *old_lchan, struct gsm_lchan *new_lchan,
uint8_t power_command, uint8_t ho_ref)
{
struct msgb *msg = gsm48_make_ho_cmd(new_lchan, power_command, ho_ref);
if (!msg)
return -EINVAL;
msg->lchan = old_lchan;
return gsm48_sendmsg(msg);
}
@ -472,11 +482,14 @@ int gsm48_rx_rr_modif_ack(struct msgb *msg)
struct gsm48_chan_mode_modify *mod =
(struct gsm48_chan_mode_modify *) gh->data;
DEBUGP(DRR, "CHANNEL MODE MODIFY ACK\n");
LOG_LCHAN(msg->lchan, LOGL_DEBUG, "CHANNEL MODE MODIFY ACK for %s\n",
gsm48_chan_mode_name(mod->mode));
if (mod->mode != msg->lchan->tch_mode) {
LOGP(DRR, LOGL_ERROR, "CHANNEL MODE change failed. Wanted: %d Got: %d\n",
msg->lchan->tch_mode, mod->mode);
LOG_LCHAN(msg->lchan, LOGL_ERROR,
"CHANNEL MODE MODIFY ACK has wrong mode: Wanted: %s Got: %s\n",
gsm48_chan_mode_name(msg->lchan->tch_mode),
gsm48_chan_mode_name(mod->mode));
return -1;
}
@ -505,7 +518,7 @@ int gsm48_rx_rr_modif_ack(struct msgb *msg)
/* FIXME: we not only need to do this after mode modify, but
* also after channel activation */
if (is_ipaccess_bts(msg->lchan->ts->trx->bts) && mod->mode != GSM48_CMODE_SIGN)
rsl_ipacc_crcx(msg->lchan);
rsl_tx_ipacc_crcx(msg->lchan);
return rc;
}
@ -589,41 +602,6 @@ int gsm48_parse_meas_rep(struct gsm_meas_rep *rep, struct msgb *msg)
return 0;
}
/* 9.2.5 CM service accept */
int gsm48_tx_mm_serv_ack(struct gsm_subscriber_connection *conn)
{
struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 SERV ACK");
struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
msg->lchan = conn->lchan;
gh->proto_discr = GSM48_PDISC_MM;
gh->msg_type = GSM48_MT_MM_CM_SERV_ACC;
DEBUGP(DMM, "-> CM SERVICE ACK\n");
gscon_submit_rsl_dtap(conn, msg, 0, 0);
return 0;
}
/* 9.2.6 CM service reject */
int gsm48_tx_mm_serv_rej(struct gsm_subscriber_connection *conn,
enum gsm48_reject_value value)
{
struct msgb *msg;
msg = gsm48_create_mm_serv_rej(value);
if (!msg) {
LOGP(DMM, LOGL_ERROR, "Failed to allocate CM Service Reject.\n");
return -1;
}
DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value);
gscon_submit_rsl_dtap(conn, msg, 0, 0);
return 0;
}
/* 9.1.29 RR Status */
struct msgb *gsm48_create_rr_status(uint8_t cause)
{
@ -719,108 +697,6 @@ uint64_t str_to_imsi(const char *imsi_str)
return ret;
}
static void handle_ass_compl(struct gsm_subscriber_connection *conn,
struct msgb *msg)
{
struct gsm48_hdr *gh = msgb_l3(msg);
enum gsm48_rr_cause cause;
/* Expecting gsm48_hdr + cause value */
if (msgb_l3len(msg) != sizeof(*gh) + 1) {
LOGPLCHAN(msg->lchan, DRR, LOGL_ERROR,
"RR Assignment Complete: length invalid: %u, expected %zu\n",
msgb_l3len(msg), sizeof(*gh) + 1);
return;
}
cause = gh->data[0];
LOGPLCHAN(msg->lchan, DRR, LOGL_DEBUG, "ASSIGNMENT COMPLETE cause = %s\n",
rr_cause_name(cause));
if (conn->ho) {
struct lchan_signal_data sig = {
.lchan = msg->lchan,
};
osmo_signal_dispatch(SS_LCHAN, S_LCHAN_ASSIGNMENT_COMPL, &sig);
/* FIXME: release old channel */
/* send pending messages, if any */
gscon_dtap_queue_flush(conn, 1);
return;
}
if (conn->secondary_lchan != msg->lchan) {
LOGPLCHAN(msg->lchan, DRR, LOGL_ERROR,
"RR Assignment Complete does not match conn's secondary lchan.\n");
return;
}
lchan_release(conn->lchan, 0, RSL_REL_LOCAL_END);
conn->lchan = conn->secondary_lchan;
conn->secondary_lchan = NULL;
/* send pending messages, if any */
gscon_dtap_queue_flush(conn, 1);
if (is_ipaccess_bts(conn_get_bts(conn)) && conn->lchan->tch_mode != GSM48_CMODE_SIGN)
rsl_ipacc_crcx(conn->lchan);
bsc_assign_compl(conn, cause);
}
static void handle_ass_fail(struct gsm_subscriber_connection *conn,
struct msgb *msg)
{
uint8_t *rr_failure;
struct gsm48_hdr *gh;
if (conn->ho) {
struct lchan_signal_data sig;
struct gsm48_hdr *gh = msgb_l3(msg);
LOGPLCHAN(msg->lchan, DRR, LOGL_DEBUG, "ASSIGNMENT FAILED cause = %s\n",
rr_cause_name(gh->data[0]));
sig.lchan = msg->lchan;
sig.mr = NULL;
osmo_signal_dispatch(SS_LCHAN, S_LCHAN_ASSIGNMENT_FAIL, &sig);
/* FIXME: release allocated new channel */
/* send pending messages, if any */
gscon_dtap_queue_flush(conn, 1);
return;
}
if (conn->lchan != msg->lchan) {
LOGPLCHAN(msg->lchan, DMSC, LOGL_ERROR,
"Assignment failure should occur on primary lchan.\n");
return;
}
/* stop the timer and release it */
if (conn->secondary_lchan) {
lchan_release(conn->secondary_lchan, 0, RSL_REL_LOCAL_END);
conn->secondary_lchan = NULL;
}
/* send pending messages, if any */
gscon_dtap_queue_flush(conn, 1);
gh = msgb_l3(msg);
if (msgb_l3len(msg) - sizeof(*gh) != 1) {
LOGPLCHAN(conn->lchan, DMSC, LOGL_ERROR, "assignment failure unhandled: %zu\n",
msgb_l3len(msg) - sizeof(*gh));
rr_failure = NULL;
} else {
rr_failure = &gh->data[0];
}
bsc_assign_fail(conn, GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE, rr_failure);
}
static void handle_classmark_chg(struct gsm_subscriber_connection *conn,
struct msgb *msg)
{
@ -829,75 +705,37 @@ static void handle_classmark_chg(struct gsm_subscriber_connection *conn,
uint8_t cm2_len, cm3_len = 0;
uint8_t *cm2, *cm3 = NULL;
LOGPLCHAN(msg->lchan, DRR, LOGL_DEBUG, "CLASSMARK CHANGE ");
/* classmark 2 */
cm2_len = gh->data[0];
cm2 = &gh->data[1];
DEBUGPC(DRR, "CM2(len=%u) ", cm2_len);
if (cm2_len > 3) {
LOG_LCHAN(msg->lchan, LOGL_ERROR, "CLASSMARK CHANGE: CM2 too long: %u\n", cm2_len);
return;
}
if (payload_len > cm2_len + 1) {
/* we must have a classmark3 */
if (gh->data[cm2_len+1] != 0x20) {
DEBUGPC(DRR, "ERR CM3 TAG\n");
return;
}
if (cm2_len > 3) {
DEBUGPC(DRR, "CM2 too long!\n");
LOG_LCHAN(msg->lchan, LOGL_ERROR, "CLASSMARK CHANGE: invalid CM3 TAG\n");
return;
}
cm3_len = gh->data[cm2_len+2];
cm3 = &gh->data[cm2_len+3];
if (cm3_len > 14) {
DEBUGPC(DRR, "CM3 len %u too long!\n", cm3_len);
LOG_LCHAN(msg->lchan, LOGL_ERROR, "CLASSMARK CHANGE: CM3 too long: %u\n",
cm3_len);
return;
}
DEBUGPC(DRR, "CM3(len=%u)\n", cm3_len);
}
LOG_LCHAN(msg->lchan, LOGL_DEBUG, "CLASSMARK CHANGE CM2(len=%u) CM3(len=%u)\n",
cm2_len, cm3_len);
bsc_cm_update(conn, cm2, cm2_len, cm3, cm3_len);
}
/* Chapter 9.1.16 Handover complete */
static void handle_rr_ho_compl(struct msgb *msg)
{
struct lchan_signal_data sig;
struct gsm48_hdr *gh = msgb_l3(msg);
LOGPLCHAN(msg->lchan, DRR, LOGL_DEBUG,
"HANDOVER COMPLETE cause = %s\n", rr_cause_name(gh->data[0]));
sig.lchan = msg->lchan;
sig.mr = NULL;
osmo_signal_dispatch(SS_LCHAN, S_LCHAN_HANDOVER_COMPL, &sig);
/* FIXME: release old channel */
/* send pending messages, if any */
gscon_dtap_queue_flush(msg->lchan->conn, 1);
}
/* Chapter 9.1.17 Handover Failure */
static void handle_rr_ho_fail(struct msgb *msg)
{
struct lchan_signal_data sig;
struct gsm48_hdr *gh = msgb_l3(msg);
/* Log on both RR and HO categories: it is an RR message, but is still quite important when
* filtering on HO. */
LOGPLCHAN(msg->lchan, DRR, LOGL_DEBUG,
"HANDOVER FAILED cause = %s\n", rr_cause_name(gh->data[0]));
LOGPLCHAN(msg->lchan, DHO, LOGL_DEBUG,
"HANDOVER FAILED cause = %s\n", rr_cause_name(gh->data[0]));
sig.lchan = msg->lchan;
sig.mr = NULL;
osmo_signal_dispatch(SS_LCHAN, S_LCHAN_HANDOVER_FAIL, &sig);
/* FIXME: release allocated new channel */
/* send pending messages, if any */
gscon_dtap_queue_flush(msg->lchan->conn, 1);
}
static void dispatch_dtap(struct gsm_subscriber_connection *conn,
uint8_t link_id, struct msgb *msg)
{
@ -907,8 +745,8 @@ static void dispatch_dtap(struct gsm_subscriber_connection *conn,
int rc;
if (msgb_l3len(msg) < sizeof(*gh)) {
LOGP(DMSC, LOGL_ERROR, "(%s) Message too short for a GSM48 header.\n",
bsc_subscr_name(conn->bsub));
LOG_LCHAN(msg->lchan, LOGL_ERROR,
"Message too short for a GSM48 header (%u)\n", msgb_l3len(msg));
return;
}
@ -924,45 +762,63 @@ static void dispatch_dtap(struct gsm_subscriber_connection *conn,
* will call api->compl_l3() for it */
switch (pdisc) {
case GSM48_PDISC_RR:
LOG_LCHAN(msg->lchan, LOGL_DEBUG, "Rx %s\n", gsm48_rr_msg_name(msg_type));
switch (msg_type) {
case GSM48_MT_RR_GPRS_SUSP_REQ:
LOGPLCHAN(msg->lchan, DRR, LOGL_DEBUG,
"%s\n", gsm48_rr_msg_name(GSM48_MT_RR_GPRS_SUSP_REQ));
/* do something? */
break;
case GSM48_MT_RR_STATUS:
LOGPLCHAN(msg->lchan, DRR, LOGL_NOTICE,
"%s (cause: %s)\n", gsm48_rr_msg_name(GSM48_MT_RR_STATUS),
rr_cause_name(gh->data[0]));
LOG_LCHAN(msg->lchan, LOGL_NOTICE, "RR Status: %s\n", rr_cause_name(gh->data[0]));
/* do something? */
break;
case GSM48_MT_RR_MEAS_REP:
/* This shouldn't actually end up here, as RSL treats
* L3 Info of 08.58 MEASUREMENT REPORT different by calling
* directly into gsm48_parse_meas_rep */
LOGPLCHAN(msg->lchan, DMEAS, LOGL_ERROR,
"DIRECT GSM48 MEASUREMENT REPORT ?!?\n");
LOG_LCHAN(msg->lchan, LOGL_ERROR, "DIRECT GSM48 MEASUREMENT REPORT ?!?\n");
gsm48_tx_rr_status(conn, GSM48_RR_CAUSE_MSG_TYPE_N_COMPAT);
break;
case GSM48_MT_RR_HANDO_COMPL:
handle_rr_ho_compl(msg);
/* Chapter 9.1.16 Handover complete */
if (!conn->ho.fi)
LOG_LCHAN(msg->lchan, LOGL_ERROR,
"Rx RR Handover Complete, but no handover is ongoing\n");
else
osmo_fsm_inst_dispatch(conn->ho.fi, HO_EV_RR_HO_COMPLETE, msg);
break;
case GSM48_MT_RR_HANDO_FAIL:
handle_rr_ho_fail(msg);
/* Chapter 9.1.17 Handover Failure */
if (!conn->ho.fi)
LOG_LCHAN(msg->lchan, LOGL_ERROR,
"Rx RR Handover Fail, but no handover is ongoing\n");
else
osmo_fsm_inst_dispatch(conn->ho.fi, HO_EV_RR_HO_FAIL, msg);
break;
case GSM48_MT_RR_CIPH_M_COMPL:
bsc_cipher_mode_compl(conn, msg, conn->lchan->encr.alg_id);
break;
case GSM48_MT_RR_ASS_COMPL:
handle_ass_compl(conn, msg);
if (conn->assignment.fi)
osmo_fsm_inst_dispatch(conn->assignment.fi,
ASSIGNMENT_EV_RR_ASSIGNMENT_COMPLETE, msg);
else
LOGPLCHAN(msg->lchan, DRR, LOGL_ERROR,
"Rx RR Assignment Complete, but no assignment is ongoing\n");
break;
case GSM48_MT_RR_ASS_FAIL:
handle_ass_fail(conn, msg);
if (conn->assignment.fi)
osmo_fsm_inst_dispatch(conn->assignment.fi,
ASSIGNMENT_EV_RR_ASSIGNMENT_FAIL, msg);
else
LOGPLCHAN(msg->lchan, DRR, LOGL_ERROR,
"Rx RR Assignment Failure, but no assignment is ongoing\n");
break;
case GSM48_MT_RR_CHAN_MODE_MODIF_ACK:
rc = gsm48_rx_rr_modif_ack(msg);
if (rc < 0)
bsc_assign_fail(conn, GSM0808_CAUSE_NO_RADIO_RESOURCE_AVAILABLE, NULL);
osmo_fsm_inst_dispatch(msg->lchan->fi, LCHAN_EV_CHAN_MODE_MODIF_ERROR, &rc);
else
bsc_assign_compl(conn, 0);
osmo_fsm_inst_dispatch(msg->lchan->fi, LCHAN_EV_CHAN_MODE_MODIF_ACK, msg);
break;
case GSM48_MT_RR_CLSM_CHG:
handle_classmark_chg(conn, msg);
@ -974,8 +830,8 @@ static void dispatch_dtap(struct gsm_subscriber_connection *conn,
break;
default:
/* Drop unknown RR message */
LOGPLCHAN(msg->lchan, DRR, LOGL_NOTICE,
"Dropping %s 04.08 RR message\n", gsm48_rr_msg_name(msg_type));
LOG_LCHAN(msg->lchan, LOGL_NOTICE, "Unknown RR message: %s\n",
gsm48_rr_msg_name(msg_type));
gsm48_tx_rr_status(conn, GSM48_RR_CAUSE_MSG_TYPE_N);
break;
}
@ -989,36 +845,30 @@ static void dispatch_dtap(struct gsm_subscriber_connection *conn,
/*! \brief RSL has received a DATA INDICATION with L3 from MS */
int gsm0408_rcvmsg(struct msgb *msg, uint8_t link_id)
{
int rc;
struct gsm_lchan *lchan;
lchan = msg->lchan;
if (lchan->state != LCHAN_S_ACTIVE) {
LOGPLCHAN(msg->lchan, DRSL, LOGL_INFO, "Got data in non active state, discarding.\n");
if (!lchan_may_receive_data(lchan)) {
LOG_LCHAN(msg->lchan, LOGL_INFO, "Got data in non active state, discarding.\n");
return -1;
}
if (lchan->conn) {
/* if we already have a connection, forward via DTAP to
* MSC */
dispatch_dtap(lchan->conn, link_id, msg);
} else {
/* allocate a new connection */
rc = BSC_API_CONN_POL_REJECT;
lchan->conn = bsc_subscr_con_allocate(msg->lchan->ts->trx->bts->network);
if (!lchan->conn) {
lchan_release(lchan, 1, RSL_REL_NORMAL);
lchan_release(lchan, false, true, RSL_ERR_EQUIPMENT_FAIL);
return -1;
}
lchan->conn->lchan = lchan;
/* fwd via bsc_api to send COMPLETE L3 INFO to MSC */
rc = bsc_compl_l3(lchan->conn, msg, 0);
if (rc != BSC_API_CONN_POL_ACCEPT) {
//osmo_fsm_inst_dispatch(lchan->conn->fi, FIXME, NULL);
}
bsc_compl_l3(lchan->conn, msg, 0);
/* conn shall release lchan on teardown, also if this Layer 3 Complete is rejected. */
}
return 0;

View File

@ -25,9 +25,10 @@
#include <ctype.h>
#include <stdbool.h>
#include <netinet/in.h>
#include <talloc.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/byteswap.h>
#include <osmocom/gsm/gsm_utils.h>
#include <osmocom/gsm/abis_nm.h>
#include <osmocom/core/statistics.h>
@ -40,6 +41,9 @@
#include <osmocom/bsc/abis_nm.h>
#include <osmocom/bsc/handover_cfg.h>
#include <osmocom/bsc/gsm_timers.h>
#include <osmocom/bsc/timeslot_fsm.h>
#include <osmocom/bsc/lchan_fsm.h>
#include <osmocom/bsc/mgw_endpoint_fsm.h>
void *tall_bsc_ctx = NULL;
@ -471,7 +475,7 @@ const struct value_string gsm_chreq_descs[] = {
{ 0, NULL }
};
const struct value_string gsm_pchant_names[13] = {
const struct value_string gsm_pchant_names[] = {
{ GSM_PCHAN_NONE, "NONE" },
{ GSM_PCHAN_CCCH, "CCCH" },
{ GSM_PCHAN_CCCH_SDCCH4,"CCCH+SDCCH4" },
@ -487,6 +491,22 @@ const struct value_string gsm_pchant_names[13] = {
{ 0, NULL }
};
const struct value_string gsm_pchan_ids[] = {
{ GSM_PCHAN_NONE, "NONE" },
{ GSM_PCHAN_CCCH, "CCCH" },
{ GSM_PCHAN_CCCH_SDCCH4,"CCCH_SDCCH4" },
{ GSM_PCHAN_TCH_F, "TCH_F" },
{ GSM_PCHAN_TCH_H, "TCH_H" },
{ GSM_PCHAN_SDCCH8_SACCH8C, "SDCCH8" },
{ GSM_PCHAN_PDCH, "PDCH" },
{ GSM_PCHAN_TCH_F_PDCH, "TCH_F_PDCH" },
{ GSM_PCHAN_UNKNOWN, "UNKNOWN" },
{ GSM_PCHAN_CCCH_SDCCH4_CBCH, "CCCH_SDCCH4_CBCH" },
{ GSM_PCHAN_SDCCH8_SACCH8C_CBCH, "SDCCH8_CBCH" },
{ GSM_PCHAN_TCH_F_TCH_H_PDCH, "TCH_F_TCH_H_PDCH" },
{ 0, NULL }
};
const struct value_string gsm_pchant_descs[13] = {
{ GSM_PCHAN_NONE, "Physical Channel not configured" },
{ GSM_PCHAN_CCCH, "FCCH + SCH + BCCH + CCCH (Comb. IV)" },
@ -520,22 +540,6 @@ const char *gsm_lchant_name(enum gsm_chan_t c)
return get_value_string(gsm_chan_t_names, c);
}
static const struct value_string lchan_s_names[] = {
{ LCHAN_S_NONE, "NONE" },
{ LCHAN_S_ACT_REQ, "ACTIVATION REQUESTED" },
{ LCHAN_S_ACTIVE, "ACTIVE" },
{ LCHAN_S_INACTIVE, "INACTIVE" },
{ LCHAN_S_REL_REQ, "RELEASE REQUESTED" },
{ LCHAN_S_REL_ERR, "RELEASE DUE ERROR" },
{ LCHAN_S_BROKEN, "BROKEN UNUSABLE" },
{ 0, NULL }
};
const char *gsm_lchans_name(enum gsm_lchan_state s)
{
return get_value_string(lchan_s_names, s);
}
static const struct value_string chreq_names[] = {
{ GSM_CHREQ_REASON_EMERG, "EMERGENCY" },
{ GSM_CHREQ_REASON_PAG, "PAGING" },
@ -698,13 +702,14 @@ struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts)
struct gsm_bts_trx_ts *ts = &trx->ts[k];
int l;
ts->trx = trx;
ts->nr = k;
ts->pchan = GSM_PCHAN_NONE;
ts->dyn.pchan_is = GSM_PCHAN_NONE;
ts->dyn.pchan_want = GSM_PCHAN_NONE;
ts->pchan_from_config = ts->pchan_on_init = ts->pchan_is = GSM_PCHAN_NONE;
ts->tsc = -1;
ts_fsm_alloc(ts);
gsm_mo_init(&ts->mo, bts, NM_OC_CHANNEL,
bts->nr, trx->nr, ts->nr);
@ -819,7 +824,7 @@ struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, uint8_t bts_num)
talloc_free(bts);
return NULL;
}
bts->c0->ts[0].pchan = GSM_PCHAN_CCCH_SDCCH4;
bts->c0->ts[0].pchan_from_config = GSM_PCHAN_CCCH_SDCCH4; /* TODO: really?? */
bts->rach_b_thresh = -1;
bts->rach_ldavg_slots = -1;
@ -947,49 +952,30 @@ char *gsm_ts_name(const struct gsm_bts_trx_ts *ts)
/*! Log timeslot number with full pchan information */
char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts)
{
switch (ts->pchan) {
case GSM_PCHAN_TCH_F_TCH_H_PDCH:
if (ts->dyn.pchan_is == ts->dyn.pchan_want)
snprintf(ts2str, sizeof(ts2str),
"(bts=%d,trx=%d,ts=%d,pchan=%s as %s)",
ts->trx->bts->nr, ts->trx->nr, ts->nr,
gsm_pchan_name(ts->pchan),
gsm_pchan_name(ts->dyn.pchan_is));
else
snprintf(ts2str, sizeof(ts2str),
"(bts=%d,trx=%d,ts=%d,pchan=%s"
" switching %s -> %s)",
ts->trx->bts->nr, ts->trx->nr, ts->nr,
gsm_pchan_name(ts->pchan),
gsm_pchan_name(ts->dyn.pchan_is),
gsm_pchan_name(ts->dyn.pchan_want));
break;
case GSM_PCHAN_TCH_F_PDCH:
if ((ts->flags & TS_F_PDCH_PENDING_MASK) == 0)
snprintf(ts2str, sizeof(ts2str),
"(bts=%d,trx=%d,ts=%d,pchan=%s as %s)",
ts->trx->bts->nr, ts->trx->nr, ts->nr,
gsm_pchan_name(ts->pchan),
(ts->flags & TS_F_PDCH_ACTIVE)? "PDCH"
: "TCH/F");
else
snprintf(ts2str, sizeof(ts2str),
"(bts=%d,trx=%d,ts=%d,pchan=%s"
" switching %s -> %s)",
ts->trx->bts->nr, ts->trx->nr, ts->nr,
gsm_pchan_name(ts->pchan),
(ts->flags & TS_F_PDCH_ACTIVE)? "PDCH"
: "TCH/F",
(ts->flags & TS_F_PDCH_ACT_PENDING)? "PDCH"
: "TCH/F");
break;
default:
snprintf(ts2str, sizeof(ts2str), "(bts=%d,trx=%d,ts=%d,pchan=%s)",
if (!ts->fi)
snprintf(ts2str, sizeof(ts2str),
"(bts=%d,trx=%d,ts=%d,pchan_from_config=%s, not allocated)",
ts->trx->bts->nr, ts->trx->nr, ts->nr,
gsm_pchan_name(ts->pchan));
break;
}
gsm_pchan_name(ts->pchan_from_config));
else if (ts->fi->state == TS_ST_NOT_INITIALIZED)
snprintf(ts2str, sizeof(ts2str),
"(bts=%d,trx=%d,ts=%d,pchan_from_config=%s,state=%s)",
ts->trx->bts->nr, ts->trx->nr, ts->nr,
gsm_pchan_name(ts->pchan_from_config),
osmo_fsm_inst_state_name(ts->fi));
else if (ts->pchan_is == ts->pchan_on_init)
snprintf(ts2str, sizeof(ts2str),
"(bts=%d,trx=%d,ts=%d,pchan=%s,state=%s)",
ts->trx->bts->nr, ts->trx->nr, ts->nr,
gsm_pchan_name(ts->pchan_is),
osmo_fsm_inst_state_name(ts->fi));
else
snprintf(ts2str, sizeof(ts2str),
"(bts=%d,trx=%d,ts=%d,pchan_on_init=%s,pchan=%s,state=%s)",
ts->trx->bts->nr, ts->trx->nr, ts->nr,
gsm_pchan_name(ts->pchan_on_init),
gsm_pchan_name(ts->pchan_is),
osmo_fsm_inst_state_name(ts->fi));
return ts2str;
}
@ -1207,20 +1193,9 @@ uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan)
{
enum gsm_phys_chan_config pchan = lchan->ts->pchan;
if (pchan == GSM_PCHAN_TCH_F_TCH_H_PDCH)
return gsm_lchan_as_pchan2chan_nr(lchan,
lchan->ts->dyn.pchan_is);
return gsm_pchan2chan_nr(lchan->ts->pchan, lchan->ts->nr, lchan->nr);
}
uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
enum gsm_phys_chan_config as_pchan)
{
if (lchan->ts->pchan == GSM_PCHAN_TCH_F_TCH_H_PDCH
&& as_pchan == GSM_PCHAN_PDCH)
return RSL_CHAN_OSMO_PDCH | (lchan->ts->nr & ~RSL_CHAN_NR_MASK);
return gsm_pchan2chan_nr(as_pchan, lchan->ts->nr, lchan->nr);
/* Note: non-standard Osmocom style dyn TS PDCH mode chan_nr is only used within
* rsl_tx_dyn_ts_pdch_act_deact(). */
return gsm_pchan2chan_nr(lchan->ts->pchan_is, lchan->ts->nr, lchan->nr);
}
/* return the gsm_lchan for the CBCH (if it exists at all) */
@ -1229,12 +1204,12 @@ struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts)
struct gsm_lchan *lchan = NULL;
struct gsm_bts_trx *trx = bts->c0;
if (trx->ts[0].pchan == GSM_PCHAN_CCCH_SDCCH4_CBCH)
if (trx->ts[0].pchan_is == GSM_PCHAN_CCCH_SDCCH4_CBCH)
lchan = &trx->ts[0].lchan[2];
else {
int i;
for (i = 0; i < 8; i++) {
if (trx->ts[i].pchan == GSM_PCHAN_SDCCH8_SACCH8C_CBCH) {
if (trx->ts[i].pchan_is == GSM_PCHAN_SDCCH8_SACCH8C_CBCH) {
lchan = &trx->ts[i].lchan[2];
break;
}
@ -1252,48 +1227,31 @@ struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
uint8_t cbits = chan_nr >> 3;
uint8_t lch_idx;
struct gsm_bts_trx_ts *ts = &trx->ts[ts_nr];
bool ok = true;
bool ok;
if (rc)
*rc = -EINVAL;
if (cbits == 0x01) {
lch_idx = 0; /* TCH/F */
if (ts->pchan != GSM_PCHAN_TCH_F &&
ts->pchan != GSM_PCHAN_PDCH &&
ts->pchan != GSM_PCHAN_TCH_F_PDCH
&& !(ts->pchan == GSM_PCHAN_TCH_F_TCH_H_PDCH
&& (ts->dyn.pchan_is == GSM_PCHAN_TCH_F
|| ts->dyn.pchan_want == GSM_PCHAN_TCH_F)))
ok = false;
lch_idx = 0; /* TCH/F */
ok = ts_is_capable_of_pchan(ts, GSM_PCHAN_TCH_F)
|| ts->pchan_on_init == GSM_PCHAN_PDCH; /* PDCH? really? */
} else if ((cbits & 0x1e) == 0x02) {
lch_idx = cbits & 0x1; /* TCH/H */
if (ts->pchan != GSM_PCHAN_TCH_H
&& !(ts->pchan == GSM_PCHAN_TCH_F_TCH_H_PDCH
&& (ts->dyn.pchan_is == GSM_PCHAN_TCH_H
|| ts->dyn.pchan_want == GSM_PCHAN_TCH_H)))
ok = false;
ok = ts_is_capable_of_pchan(ts, GSM_PCHAN_TCH_H);
} else if ((cbits & 0x1c) == 0x04) {
lch_idx = cbits & 0x3; /* SDCCH/4 */
if (ts->pchan != GSM_PCHAN_CCCH_SDCCH4 &&
ts->pchan != GSM_PCHAN_CCCH_SDCCH4_CBCH)
ok = false;
ok = ts_is_capable_of_pchan(ts, GSM_PCHAN_CCCH_SDCCH4);
} else if ((cbits & 0x18) == 0x08) {
lch_idx = cbits & 0x7; /* SDCCH/8 */
if (ts->pchan != GSM_PCHAN_SDCCH8_SACCH8C &&
ts->pchan != GSM_PCHAN_SDCCH8_SACCH8C_CBCH)
ok = false;
ok = ts_is_capable_of_pchan(ts, GSM_PCHAN_SDCCH8_SACCH8C);
} else if (cbits == 0x10 || cbits == 0x11 || cbits == 0x12) {
lch_idx = 0;
if (ts->pchan != GSM_PCHAN_CCCH &&
ts->pchan != GSM_PCHAN_CCCH_SDCCH4 &&
ts->pchan != GSM_PCHAN_CCCH_SDCCH4_CBCH)
ok = false;
lch_idx = 0; /* CCCH? */
ok = ts_is_capable_of_pchan(ts, GSM_PCHAN_CCCH);
/* FIXME: we should not return first sdcch4 !!! */
} else if ((chan_nr & RSL_CHAN_NR_MASK) == RSL_CHAN_OSMO_PDCH) {
lch_idx = 0;
if (ts->pchan != GSM_PCHAN_TCH_F_TCH_H_PDCH)
ok = false;
ok = (ts->pchan_on_init == GSM_PCHAN_TCH_F_TCH_H_PDCH);
} else
return NULL;
@ -1313,33 +1271,18 @@ static const uint8_t subslots_per_pchan[] = {
[GSM_PCHAN_SDCCH8_SACCH8C] = 8,
[GSM_PCHAN_CCCH_SDCCH4_CBCH] = 4,
[GSM_PCHAN_SDCCH8_SACCH8C_CBCH] = 8,
/*
* GSM_PCHAN_TCH_F_PDCH and GSM_PCHAN_TCH_F_TCH_H_PDCH should not be
* part of this, those TS are handled according to their dynamic state.
*/
/* Dyn TS: maximum allowed subslots */
[GSM_PCHAN_TCH_F_TCH_H_PDCH] = 2,
[GSM_PCHAN_TCH_F_PDCH] = 1,
};
/*! Return the actual pchan type, also heeding dynamic TS. */
enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts)
{
switch (ts->pchan) {
case GSM_PCHAN_TCH_F_TCH_H_PDCH:
return ts->dyn.pchan_is;
case GSM_PCHAN_TCH_F_PDCH:
if (ts->flags & TS_F_PDCH_ACTIVE)
return GSM_PCHAN_PDCH;
else
return GSM_PCHAN_TCH_F;
default:
return ts->pchan;
}
}
/*! According to ts->pchan and possibly ts->dyn_pchan, return the number of
* logical channels available in the timeslot. */
uint8_t ts_subslots(struct gsm_bts_trx_ts *ts)
uint8_t pchan_subslots(enum gsm_phys_chan_config pchan)
{
return subslots_per_pchan[ts_pchan(ts)];
if (pchan < 0 || pchan >= ARRAY_SIZE(subslots_per_pchan))
return 0;
return subslots_per_pchan[pchan];
}
static bool pchan_is_tch(enum gsm_phys_chan_config pchan)
@ -1355,7 +1298,7 @@ static bool pchan_is_tch(enum gsm_phys_chan_config pchan)
bool ts_is_tch(struct gsm_bts_trx_ts *ts)
{
return pchan_is_tch(ts_pchan(ts));
return pchan_is_tch(ts->pchan_is);
}
bool trx_is_usable(const struct gsm_bts_trx *trx)
@ -1370,34 +1313,20 @@ bool trx_is_usable(const struct gsm_bts_trx *trx)
return true;
}
void gsm_trx_mark_all_ts_uninitialized(struct gsm_bts_trx *trx)
void gsm_trx_all_ts_dispatch(struct gsm_bts_trx *trx, uint32_t ts_ev, void *data)
{
int i;
for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
struct gsm_bts_trx_ts *ts = &trx->ts[i];
ts->initialized = false;
osmo_fsm_inst_dispatch(ts->fi, ts_ev, data);
}
}
void gsm_bts_mark_all_ts_uninitialized(struct gsm_bts *bts)
void gsm_bts_all_ts_dispatch(struct gsm_bts *bts, uint32_t ts_ev, void *data)
{
struct gsm_bts_trx *trx;
llist_for_each_entry(trx, &bts->trx_list, list)
gsm_trx_mark_all_ts_uninitialized(trx);
}
/* Trigger initial timeslot actions iff both OML and RSL are setup. */
void gsm_ts_check_init(struct gsm_bts_trx_ts *ts)
{
struct gsm_bts *bts = ts->trx->bts;
if (bts->model->oml_is_ts_ready
&& !bts->model->oml_is_ts_ready(ts))
return;
if (!ts->trx->rsl_link)
return;
if (ts->initialized)
return;
ts->initialized = on_gsm_ts_init(ts);
gsm_trx_all_ts_dispatch(trx, ts_ev, data);
}
void gsm48_lchan2chan_desc(struct gsm48_chan_desc *cd,
@ -1426,3 +1355,258 @@ bool nm_is_running(const struct gsm_nm_state *s) {
(s->availability == 0xff)
);
}
/* determine the logical channel type based on the physical channel type */
int gsm_lchan_type_by_pchan(enum gsm_phys_chan_config pchan)
{
switch (pchan) {
case GSM_PCHAN_TCH_F:
return GSM_LCHAN_TCH_F;
case GSM_PCHAN_TCH_H:
return GSM_LCHAN_TCH_H;
case GSM_PCHAN_SDCCH8_SACCH8C:
case GSM_PCHAN_SDCCH8_SACCH8C_CBCH:
case GSM_PCHAN_CCCH_SDCCH4:
case GSM_PCHAN_CCCH_SDCCH4_CBCH:
return GSM_LCHAN_SDCCH;
default:
return -1;
}
}
enum gsm_phys_chan_config gsm_pchan_by_lchan_type(enum gsm_chan_t type)
{
switch (type) {
case GSM_LCHAN_TCH_F:
return GSM_PCHAN_TCH_F;
case GSM_LCHAN_TCH_H:
return GSM_PCHAN_TCH_H;
case GSM_LCHAN_NONE:
case GSM_LCHAN_PDTCH:
/* TODO: so far lchan->type is NONE in PDCH mode. PDTCH is only
* used in osmo-bts. Maybe set PDTCH and drop the NONE case
* here. */
return GSM_PCHAN_PDCH;
default:
return GSM_PCHAN_UNKNOWN;
}
}
/* Can the timeslot in principle be used as this PCHAN kind? */
bool ts_is_capable_of_pchan(struct gsm_bts_trx_ts *ts, enum gsm_phys_chan_config pchan)
{
switch (ts->pchan_on_init) {
case GSM_PCHAN_TCH_F_PDCH:
switch (pchan) {
case GSM_PCHAN_TCH_F:
case GSM_PCHAN_PDCH:
return true;
default:
return false;
}
case GSM_PCHAN_TCH_F_TCH_H_PDCH:
switch (pchan) {
case GSM_PCHAN_TCH_F:
case GSM_PCHAN_TCH_H:
case GSM_PCHAN_PDCH:
return true;
default:
return false;
}
case GSM_PCHAN_CCCH_SDCCH4_CBCH:
switch (pchan) {
case GSM_PCHAN_CCCH_SDCCH4_CBCH:
case GSM_PCHAN_CCCH_SDCCH4:
case GSM_PCHAN_CCCH:
return true;
default:
return false;
}
case GSM_PCHAN_CCCH_SDCCH4:
switch (pchan) {
case GSM_PCHAN_CCCH_SDCCH4:
case GSM_PCHAN_CCCH:
return true;
default:
return false;
}
case GSM_PCHAN_SDCCH8_SACCH8C_CBCH:
switch (pchan) {
case GSM_PCHAN_SDCCH8_SACCH8C_CBCH:
case GSM_PCHAN_SDCCH8_SACCH8C:
return true;
default:
return false;
}
default:
return ts->pchan_on_init == pchan;
}
}
bool ts_is_capable_of_lchant(struct gsm_bts_trx_ts *ts, enum gsm_chan_t type)
{
switch (ts->pchan_on_init) {
case GSM_PCHAN_TCH_F:
switch (type) {
case GSM_LCHAN_TCH_F:
return true;
default:
return false;
}
case GSM_PCHAN_TCH_H:
switch (type) {
case GSM_LCHAN_TCH_H:
return true;
default:
return false;
}
case GSM_PCHAN_TCH_F_PDCH:
switch (type) {
case GSM_LCHAN_TCH_F:
case GSM_LCHAN_PDTCH:
return true;
default:
return false;
}
case GSM_PCHAN_TCH_F_TCH_H_PDCH:
switch (type) {
case GSM_LCHAN_TCH_F:
case GSM_LCHAN_TCH_H:
case GSM_LCHAN_PDTCH:
return true;
default:
return false;
}
case GSM_PCHAN_PDCH:
switch (type) {
case GSM_LCHAN_PDTCH:
return true;
default:
return false;
}
case GSM_PCHAN_CCCH:
switch (type) {
case GSM_LCHAN_CCCH:
return true;
default:
return false;
}
break;
case GSM_PCHAN_CCCH_SDCCH4_CBCH:
case GSM_PCHAN_CCCH_SDCCH4:
case GSM_PCHAN_SDCCH8_SACCH8C:
case GSM_PCHAN_SDCCH8_SACCH8C_CBCH:
switch (type) {
case GSM_LCHAN_CCCH:
case GSM_LCHAN_SDCCH:
return true;
default:
return false;
}
default:
return false;
}
}
static int trx_count_free_ts(struct gsm_bts_trx *trx, enum gsm_phys_chan_config pchan)
{
struct gsm_bts_trx_ts *ts;
struct gsm_lchan *lchan;
int j;
int count = 0;
if (!trx_is_usable(trx))
return 0;
for (j = 0; j < ARRAY_SIZE(trx->ts); j++) {
ts = &trx->ts[j];
if (!ts_is_usable(ts))
continue;
if (ts->pchan_is == GSM_PCHAN_PDCH) {
/* Dynamic timeslots in PDCH mode will become TCH if needed. */
switch (ts->pchan_on_init) {
case GSM_PCHAN_TCH_F_PDCH:
if (pchan == GSM_PCHAN_TCH_F)
count++;
continue;
case GSM_PCHAN_TCH_F_TCH_H_PDCH:
if (pchan == GSM_PCHAN_TCH_F)
count++;
else if (pchan == GSM_PCHAN_TCH_H)
count += 2;
continue;
default:
/* Not dynamic, not applicable. */
continue;
}
}
if (ts->pchan_is != pchan)
continue;
ts_for_each_lchan(lchan, ts) {
if (lchan_state_is(lchan, LCHAN_ST_UNUSED))
count++;
}
}
return count;
}
/* Count number of free TS of given pchan type */
int bts_count_free_ts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan)
{
struct gsm_bts_trx *trx;
int count = 0;
llist_for_each_entry(trx, &bts->trx_list, list)
count += trx_count_free_ts(trx, pchan);
return count;
}
bool ts_is_usable(const struct gsm_bts_trx_ts *ts)
{
if (!trx_is_usable(ts->trx)) {
LOGP(DRLL, LOGL_DEBUG, "%s not usable\n", gsm_trx_name(ts->trx));
return false;
}
if (!ts->fi)
return false;
switch (ts->fi->state) {
case TS_ST_NOT_INITIALIZED:
case TS_ST_BORKEN:
return false;
default:
break;
}
return true;
}
const struct value_string lchan_activate_mode_names[] = {
OSMO_VALUE_STRING(FOR_NONE),
OSMO_VALUE_STRING(FOR_MS_CHANNEL_REQUEST),
OSMO_VALUE_STRING(FOR_ASSIGNMENT),
OSMO_VALUE_STRING(FOR_HANDOVER),
OSMO_VALUE_STRING(FOR_VTY),
{}
};

View File

@ -95,9 +95,9 @@ static int T_round(int val, enum T_unit from_unit, enum T_unit to_unit)
*
* val = T_def_get(global_T_defs, 99, T_S, 3); // not defined, returns 3
*/
int T_def_get(struct T_def *T_defs, int T, enum T_unit as_unit, int val_if_not_present)
int T_def_get(const struct T_def *T_defs, int T, enum T_unit as_unit, int val_if_not_present)
{
struct T_def *d = T_def_get_entry(T_defs, T);
const struct T_def *d = T_def_get_entry((struct T_def*)T_defs, T);
if (!d) {
OSMO_ASSERT(val_if_not_present >= 0);
return val_if_not_present;
@ -142,9 +142,10 @@ struct T_def *T_def_get_entry(struct T_def *T_defs, int T)
* The intention is then to obtain the timer like T_def_get(global_T_defs, T=235); see also
* fsm_inst_state_chg_T() below.
*/
struct state_timeout *get_state_timeout(uint32_t state, struct state_timeout *timeouts_array)
const struct state_timeout *get_state_timeout(uint32_t state,
const struct state_timeout *timeouts_array)
{
struct state_timeout *t;
const struct state_timeout *t;
OSMO_ASSERT(state < 32);
t = &timeouts_array[state];
if (!t->keep_timer && !t->T)
@ -176,11 +177,11 @@ struct state_timeout *get_state_timeout(uint32_t state, struct state_timeout *ti
*
*/
int _fsm_inst_state_chg_T(struct osmo_fsm_inst *fi, uint32_t state,
struct state_timeout *timeouts_array,
struct T_def *T_defs, int default_timeout,
const struct state_timeout *timeouts_array,
const struct T_def *T_defs, int default_timeout,
const char *file, int line)
{
struct state_timeout *t = get_state_timeout(state, timeouts_array);
const struct state_timeout *t = get_state_timeout(state, timeouts_array);
int val;
/* No timeout defined for this state? */

View File

@ -32,47 +32,9 @@
#include <osmocom/core/talloc.h>
#include <osmocom/gsm/gsm_utils.h>
#include <osmocom/bsc/handover.h>
#include <osmocom/bsc/handover_fsm.h>
#include <osmocom/bsc/handover_cfg.h>
/* Find BTS by ARFCN and BSIC */
struct gsm_bts *bts_by_arfcn_bsic(const struct gsm_network *net,
uint16_t arfcn, uint8_t bsic)
{
struct gsm_bts *bts;
llist_for_each_entry(bts, &net->bts_list, list) {
if (bts->c0->arfcn == arfcn &&
bts->bsic == bsic)
return bts;
}
return NULL;
}
/* issue handover to a cell identified by ARFCN and BSIC */
static int handover_to_arfcn_bsic(struct gsm_lchan *lchan,
uint16_t arfcn, uint8_t bsic)
{
struct gsm_bts *new_bts;
/* resolve the gsm_bts structure for the best neighbor */
/* FIXME: use some better heuristics here to determine which cell
* using this ARFCN really is closest to the target cell. For
* now we simply assume that each ARFCN will only be used by one
* cell */
new_bts = bts_by_arfcn_bsic(lchan->ts->trx->bts->network, arfcn, bsic);
if (!new_bts) {
LOGP(DHODEC, LOGL_NOTICE, "unable to determine neighbor BTS "
"for ARFCN %u BSIC %u ?!?\n", arfcn, bsic);
return -EINVAL;
}
/* and actually try to handover to that cell */
return bsc_handover_start(HODEC1, lchan, new_bts, lchan->type);
}
/* did we get a RXLEV for a given cell in the given report? */
static int rxlev_for_cell_in_rep(struct gsm_meas_rep *mr,
uint16_t arfcn, uint8_t bsic)
@ -196,15 +158,16 @@ static void process_meas_neigh(struct gsm_meas_rep *mr)
}
/* attempt to do a handover */
static int attempt_handover(struct gsm_meas_rep *mr)
static void attempt_handover(struct gsm_meas_rep *mr)
{
struct handover_out_req req;
struct gsm_bts *bts = mr->lchan->ts->trx->bts;
struct neigh_meas_proc *best_cell = NULL;
unsigned int best_better_db = 0;
int i;
if (!ho_get_ho_active(bts->ho))
return 0;
return;
/* find the best cell in this report that is at least RXLEV_HYST
* better than the current serving cell */
@ -232,9 +195,18 @@ static int attempt_handover(struct gsm_meas_rep *mr)
}
if (!best_cell)
return 0;
return;
return handover_to_arfcn_bsic(mr->lchan, best_cell->arfcn, best_cell->bsic);
req = (struct handover_out_req){
.from_hodec_id = HODEC1,
.old_lchan = mr->lchan,
.target_nik = {
.from_bts = bts->nr,
.arfcn = best_cell->arfcn,
.bsic = best_cell->bsic,
},
};
handover_request(&req);
}
/* process an already parsed measurement report and decide if we want to

View File

@ -27,14 +27,16 @@
#include <osmocom/bsc/debug.h>
#include <osmocom/bsc/gsm_data.h>
#include <osmocom/bsc/handover.h>
#include <osmocom/bsc/handover_fsm.h>
#include <osmocom/bsc/handover_decision.h>
#include <osmocom/bsc/handover_decision_2.h>
#include <osmocom/bsc/handover_cfg.h>
#include <osmocom/bsc/bsc_subscriber.h>
#include <osmocom/bsc/chan_alloc.h>
#include <osmocom/bsc/lchan_fsm.h>
#include <osmocom/bsc/signal.h>
#include <osmocom/bsc/penalty_timers.h>
#include <osmocom/bsc/neighbor_ident.h>
#include <osmocom/bsc/timeslot_fsm.h>
#define LOGPHOBTS(bts, level, fmt, args...) \
LOGP(DHODEC, level, "(BTS %u) " fmt, bts->nr, ## args)
@ -76,7 +78,8 @@
struct ho_candidate {
struct gsm_lchan *lchan; /* candidate for whom */
struct gsm_bts *bts; /* target BTS */
struct gsm_bts *bts; /* target BTS in local BSS */
struct gsm0808_cell_id_list2 *cil; /* target cells in remote BSS */
uint8_t requirements; /* what is fulfilled */
int avg; /* average RX level */
};
@ -149,22 +152,47 @@ void hodec2_on_change_congestion_check_interval(struct gsm_network *net, unsigne
reinit_congestion_timer(net);
}
static void conn_penalty_time_add(struct gsm_subscriber_connection *conn, struct gsm_bts *bts,
static void _conn_penalty_time_add(struct gsm_subscriber_connection *conn,
const void *for_object,
int penalty_time)
{
if (!for_object) {
LOGP(DHODEC, LOGL_ERROR, "%s Unable to set Handover-2 penalty timer:"
" no target cell pointer\n",
bsc_subscr_name(conn->bsub));
return;
}
if (!conn->hodec2.penalty_timers) {
conn->hodec2.penalty_timers = penalty_timers_init(conn);
OSMO_ASSERT(conn->hodec2.penalty_timers);
}
penalty_timers_add(conn->hodec2.penalty_timers, bts, penalty_time);
penalty_timers_add(conn->hodec2.penalty_timers, for_object, penalty_time);
}
static void nik_penalty_time_add(struct gsm_subscriber_connection *conn,
struct neighbor_ident_key *nik,
int penalty_time)
{
_conn_penalty_time_add(conn,
neighbor_ident_get(conn->network->neighbor_bss_cells, nik),
penalty_time);
}
static void bts_penalty_time_add(struct gsm_subscriber_connection *conn,
struct gsm_bts *bts,
int penalty_time)
{
_conn_penalty_time_add(conn, bts, penalty_time);
}
static unsigned int conn_penalty_time_remaining(struct gsm_subscriber_connection *conn,
struct gsm_bts *bts)
const void *for_object)
{
if (!conn->hodec2.penalty_timers)
return 0;
return penalty_timers_remaining(conn->hodec2.penalty_timers, bts);
return penalty_timers_remaining(conn->hodec2.penalty_timers, for_object);
}
/* did we get a RXLEV for a given cell in the given report? Mark matches as MRC_F_PROCESSED. */
@ -298,7 +326,7 @@ static bool codec_type_is_supported(struct gsm_subscriber_connection *conn,
int i;
struct gsm0808_speech_codec_list *clist = &conn->codec_list;
if (!conn->codec_list_present) {
if (!conn->codec_list.len) {
/* We don't have a list of supported codecs. This should never happen. */
LOGPHOLCHAN(conn->lchan, LOGL_ERROR,
"No Speech Codec List present, accepting all codecs\n");
@ -530,7 +558,7 @@ static uint8_t check_requirements(struct gsm_lchan *lchan, struct gsm_bts *bts,
/* the maximum number of unsynchonized handovers must no be exceeded */
if (current_bts != bts
&& bsc_ho_count(bts, true) >= ho_get_hodec2_ho_max(bts->ho)) {
&& bts_handover_count(bts, HO_SCOPE_ALL) >= ho_get_hodec2_ho_max(bts->ho)) {
LOGPHOLCHANTOBTS(lchan, bts, LOGL_DEBUG,
"not a candidate, number of allowed handovers (%d) would be exceeded\n",
ho_get_hodec2_ho_max(bts->ho));
@ -573,6 +601,7 @@ static uint8_t check_requirements(struct gsm_lchan *lchan, struct gsm_bts *bts,
/* Trigger handover or assignment depending on the target BTS */
static int trigger_handover_or_assignment(struct gsm_lchan *lchan, struct gsm_bts *new_bts, uint8_t requirements)
{
struct handover_out_req req;
struct gsm_bts *current_bts = lchan->ts->trx->bts;
int afs_bias = 0;
bool full_rate = false;
@ -640,8 +669,14 @@ static int trigger_handover_or_assignment(struct gsm_lchan *lchan, struct gsm_bt
full_rate ? "TCH/F" : "TCH/H",
ho_reason_name(global_ho_reason));
return bsc_handover_start(HODEC2, lchan, current_bts == new_bts? NULL : new_bts,
full_rate? GSM_LCHAN_TCH_F : GSM_LCHAN_TCH_H);
req = (struct handover_out_req){
.from_hodec_id = HODEC2,
.old_lchan = lchan,
.target_nik = *bts_ident_key(new_bts),
.new_lchan_type = full_rate? GSM_LCHAN_TCH_F : GSM_LCHAN_TCH_H,
};
handover_request(&req);
return 0;
}
/* debug collected candidates */
@ -706,6 +741,12 @@ static void collect_handover_candidate(struct gsm_lchan *lchan, struct neigh_mea
struct gsm_bts *bts = lchan->ts->trx->bts;
int tchf_count, tchh_count;
struct gsm_bts *neighbor_bts;
const struct gsm0808_cell_id_list2 *neighbor_cil;
struct neighbor_ident_key ni = {
.from_bts = bts->nr,
.arfcn = nmp->arfcn,
.bsic = nmp->bsic,
};
int avg;
struct ho_candidate *c;
int min_rxlev;
@ -719,16 +760,24 @@ static void collect_handover_candidate(struct gsm_lchan *lchan, struct neigh_mea
/* skip if measurement report is old */
if (nmp->last_seen_nr != lchan->meas_rep_last_seen_nr) {
LOGPHOLCHAN(lchan, LOGL_DEBUG, "neighbor ARFCN %u measurement report is old"
LOGPHOLCHAN(lchan, LOGL_DEBUG, "neighbor ARFCN %u BSIC %u measurement report is old"
" (nmp->last_seen_nr=%u lchan->meas_rep_last_seen_nr=%u)\n",
nmp->arfcn, nmp->last_seen_nr, lchan->meas_rep_last_seen_nr);
nmp->arfcn, nmp->bsic, nmp->last_seen_nr, lchan->meas_rep_last_seen_nr);
return;
}
neighbor_bts = bts_by_arfcn_bsic(bts->network, nmp->arfcn, nmp->bsic);
neighbor_bts = bts_by_neighbor_ident(bts->network, &ni);
if (!neighbor_bts) {
LOGPHOBTS(bts, LOGL_DEBUG, "neighbor ARFCN %u does not belong to this network\n",
nmp->arfcn);
neighbor_cil = neighbor_ident_get(bts->network->neighbor_bss_cells, &ni);
if (neighbor_cil) {
LOGPHOBTS(bts, LOGL_ERROR, "would inter-BSC handover to ARFCN %u BSIC %u,"
" but inter-BSC handover not implemented for ho decision 2\n",
nmp->arfcn, nmp->bsic);
return;
}
LOGPHOBTS(bts, LOGL_DEBUG, "no neighbor ARFCN %u BSIC %u configured for this cell\n",
nmp->arfcn, nmp->bsic);
return;
}
@ -738,7 +787,7 @@ static void collect_handover_candidate(struct gsm_lchan *lchan, struct neigh_mea
return;
}
/* caculate average rxlev for this cell over the window */
/* calculate average rxlev for this cell over the window */
avg = neigh_meas_avg(nmp, ho_get_hodec2_rxlev_neigh_avg_win(bts->ho));
/* Heed rxlev hysteresis only if the RXLEV/RXQUAL/TA levels of the MS aren't critically bad and
@ -1054,12 +1103,12 @@ static void on_measurement_report(struct gsm_meas_rep *mr)
LOGPHOLCHAN(lchan, LOGL_ERROR, "Skipping, No subscriber connection???\n");
return;
}
if (lchan->conn->secondary_lchan) {
if (lchan->conn->assignment.new_lchan) {
LOGPHOLCHAN(lchan, LOGL_INFO, "Skipping, Initial Assignment is still ongoing\n");
return;
}
if (lchan->conn->ho) {
LOGPHOLCHAN(lchan, LOGL_INFO, "Skipping, Handover already triggered\n");
if (lchan->conn->ho.fi) {
LOGPHOLCHAN(lchan, LOGL_INFO, "Skipping, Handover still ongoing\n");
return;
}
@ -1130,11 +1179,11 @@ static void on_measurement_report(struct gsm_meas_rep *mr)
global_ho_reason = HO_REASON_MAX_DISTANCE;
LOGPHOLCHAN(lchan, LOGL_NOTICE, "TA is TOO HIGH: %u > %d\n",
lchan->rqd_ta, ho_get_hodec2_max_distance(bts->ho));
/* start penalty timer to prevent comming back too
/* start penalty timer to prevent coming back too
* early. it must be started before selecting a better cell,
* so there is no assignment selected, due to running
* penalty timer. */
conn_penalty_time_add(lchan->conn, bts, ho_get_hodec2_penalty_max_dist(bts->ho));
bts_penalty_time_add(lchan->conn, bts, ho_get_hodec2_penalty_max_dist(bts->ho));
find_alternative_lchan(lchan, true);
return;
}
@ -1242,16 +1291,16 @@ static int bts_resolve_congestion(struct gsm_bts *bts, int tchf_congestion, int
continue;
/* (Do not consider dynamic TS that are in PDCH mode) */
switch (ts_pchan(ts)) {
switch (ts->pchan_is) {
case GSM_PCHAN_TCH_F:
lc = &ts->lchan[0];
/* omit if channel not active */
if (lc->type != GSM_LCHAN_TCH_F
|| lc->state != LCHAN_S_ACTIVE)
|| !lchan_state_is(lc, LCHAN_ST_ESTABLISHED))
break;
/* omit if there is an ongoing ho/as */
if (!lc->conn || lc->conn->secondary_lchan
|| lc->conn->ho)
if (!lc->conn || lc->conn->assignment.new_lchan
|| lc->conn->ho.fi)
break;
/* We desperately want to resolve congestion, ignore rxlev when
* collecting candidates by passing include_weaker_rxlev=true. */
@ -1262,12 +1311,12 @@ static int bts_resolve_congestion(struct gsm_bts *bts, int tchf_congestion, int
lc = &ts->lchan[j];
/* omit if channel not active */
if (lc->type != GSM_LCHAN_TCH_H
|| lc->state != LCHAN_S_ACTIVE)
|| !lchan_state_is(lc, LCHAN_ST_ESTABLISHED))
continue;
/* omit of there is an ongoing ho/as */
if (!lc->conn
|| lc->conn->secondary_lchan
|| lc->conn->ho)
|| lc->conn->assignment.new_lchan
|| lc->conn->ho.fi)
continue;
/* We desperately want to resolve congestion, ignore rxlev when
* collecting candidates by passing include_weaker_rxlev=true. */
@ -1663,50 +1712,58 @@ static void congestion_check_cb(void *arg)
reinit_congestion_timer(net);
}
void on_ho_chan_activ_nack(struct bsc_handover *ho)
static void on_handover_end(struct gsm_subscriber_connection *conn, enum handover_result result)
{
struct gsm_bts *new_bts = ho->new_lchan->ts->trx->bts;
struct gsm_bts *old_bts = NULL;
struct gsm_bts *new_bts = NULL;
int penalty;
struct handover *ho = &conn->ho;
LOGPHO(ho, LOGL_ERROR, "Channel Activate Nack for %s, starting penalty timer\n", ho->inter_cell? "Handover" : "Assignment");
/* If all went fine, then there are no penalty timers to set. */
if (result == HO_RESULT_OK)
return;
/* if channel failed, wait 10 seconds before allowing to retry handover */
conn_penalty_time_add(ho->old_lchan->conn, new_bts, 10); /* FIXME configurable */
}
if (conn->lchan)
old_bts = conn->lchan->ts->trx->bts;
if (ho->new_lchan)
new_bts = ho->new_lchan->ts->trx->bts;
void on_ho_failure(struct bsc_handover *ho)
{
struct gsm_bts *old_bts = ho->old_lchan->ts->trx->bts;
struct gsm_bts *new_bts = ho->new_lchan->ts->trx->bts;
struct gsm_subscriber_connection *conn = ho->old_lchan->conn;
/* Only interested in handovers within this BSS or going out into another BSS. Incoming handovers
* from another BSS are accounted for in the other BSS. */
if (!old_bts)
return;
if (!conn) {
LOGPHO(ho, LOGL_ERROR, "HO failure, but no conn\n");
if (conn->hodec2.failures < ho_get_hodec2_retries(old_bts->ho)) {
conn->hodec2.failures++;
LOG_HO(conn, LOGL_NOTICE, "Failed, allowing handover decision to try again"
" (%d/%d attempts)\n",
conn->hodec2.failures, ho_get_hodec2_retries(old_bts->ho));
return;
}
if (conn->hodec2.failures >= ho_get_hodec2_retries(old_bts->ho)) {
int penalty = ho->inter_cell
? ho_get_hodec2_penalty_failed_ho(old_bts->ho)
: ho_get_hodec2_penalty_failed_as(old_bts->ho);
LOGPHO(ho, LOGL_NOTICE, "%s failed, starting penalty timer (%d s)\n",
ho->inter_cell ? "Handover" : "Assignment",
penalty);
conn->hodec2.failures = 0;
conn_penalty_time_add(conn, new_bts, penalty);
} else {
conn->hodec2.failures++;
LOGPHO(ho, LOGL_NOTICE, "%s failed, allowing handover decision to try again"
" (%d/%d attempts)\n",
ho->inter_cell ? "Handover" : "Assignment",
conn->hodec2.failures, ho_get_hodec2_retries(old_bts->ho));
switch (ho->scope) {
case HO_INTRA_CELL:
penalty = ho_get_hodec2_penalty_failed_as(old_bts->ho);
break;
default:
/* TODO: separate penalty for inter-BSC HO? */
penalty = ho_get_hodec2_penalty_failed_ho(old_bts->ho);
break;
}
LOG_HO(conn, LOGL_NOTICE, "Failed, starting penalty timer (%d s)\n", penalty);
conn->hodec2.failures = 0;
if (new_bts)
bts_penalty_time_add(conn, new_bts, penalty);
else
nik_penalty_time_add(conn, &ho->target_cell, penalty);
}
struct handover_decision_callbacks hodec2_callbacks = {
static struct handover_decision_callbacks hodec2_callbacks = {
.hodec_id = 2,
.on_measurement_report = on_measurement_report,
.on_ho_chan_activ_nack = on_ho_chan_activ_nack,
.on_ho_failure = on_ho_failure,
.on_handover_end = on_handover_end,
};
void hodec2_init(struct gsm_network *net)

1187
src/osmo-bsc/handover_fsm.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,7 @@
#include <osmocom/bsc/gsm_data.h>
#include <osmocom/gsm/gsm_utils.h>
#include <osmocom/bsc/abis_rsl.h>
#include <osmocom/bsc/chan_alloc.h>
#include <osmocom/bsc/lchan_select.h>
#include <osmocom/bsc/signal.h>
#include <osmocom/core/talloc.h>
#include <osmocom/bsc/bsc_subscriber.h>
@ -41,352 +41,88 @@
#include <osmocom/bsc/handover.h>
#include <osmocom/bsc/handover_cfg.h>
#include <osmocom/bsc/bsc_subscr_conn_fsm.h>
#include <osmocom/bsc/neighbor_ident.h>
#include <osmocom/bsc/abis_nm.h>
#include <osmocom/gsm/gsm0808.h>
#include <osmocom/gsm/gsm0808_utils.h>
const struct value_string handover_scope_names[] = {
{ HO_NO_HANDOVER, "HO-none" },
{ HO_INTRA_CELL, "AS" },
{ HO_INTRA_BSC, "HO-intraBSC" },
{ HO_INTER_BSC_OUT, "HO-interBSC-Out" },
{ HO_INTER_BSC_IN, "HO-interBSC-In" },
{ HO_SCOPE_ALL, "HO-any" },
{}
};
const struct value_string handover_result_names[] = {
{ HO_RESULT_OK, "Complete" },
{ HO_RESULT_FAIL_NO_CHANNEL, "Failure (no channel could be allocated)" },
{ HO_RESULT_FAIL_RR_HO_FAIL, "Failure (MS sent RR Handover Failure)" },
{ HO_RESULT_FAIL_TIMEOUT, "Failure (timeout)" },
{ HO_RESULT_CONN_RELEASE, "Connection released" },
{ HO_RESULT_ERROR, "Failure" },
{}
};
static LLIST_HEAD(bsc_handovers);
static LLIST_HEAD(handover_decision_callbacks);
static void handover_free(struct bsc_handover *ho)
void handover_decision_callbacks_register(struct handover_decision_callbacks *hdc)
{
osmo_timer_del(&ho->T3103);
llist_del(&ho->list);
talloc_free(ho);
llist_add_tail(&hdc->entry, &handover_decision_callbacks);
}
static struct bsc_handover *bsc_ho_by_new_lchan(struct gsm_lchan *new_lchan)
struct handover_decision_callbacks *handover_decision_callbacks_get(int hodec_id)
{
struct bsc_handover *ho;
llist_for_each_entry(ho, &bsc_handovers, list) {
if (ho->new_lchan == new_lchan)
return ho;
struct handover_decision_callbacks *hdc;
llist_for_each_entry(hdc, &handover_decision_callbacks, entry) {
if (hdc->hodec_id == hodec_id)
return hdc;
}
return NULL;
}
static struct bsc_handover *bsc_ho_by_old_lchan(struct gsm_lchan *old_lchan)
{
struct bsc_handover *ho;
llist_for_each_entry(ho, &bsc_handovers, list) {
if (ho->old_lchan == old_lchan)
return ho;
}
return NULL;
}
/*! Hand over the specified logical channel to the specified new BTS and possibly change the lchan type.
* This is the main entry point for the actual handover algorithm, after the decision whether to initiate
* HO to a specific BTS. To not change the lchan type, pass old_lchan->type. */
int bsc_handover_start(enum hodec_id from_hodec_id, struct gsm_lchan *old_lchan, struct gsm_bts *new_bts,
enum gsm_chan_t new_lchan_type)
{
int rc;
struct gsm_subscriber_connection *conn;
struct bsc_handover *ho;
static uint8_t ho_ref = 0;
bool do_assignment;
OSMO_ASSERT(old_lchan);
/* don't attempt multiple handovers for the same lchan at
* the same time */
if (bsc_ho_by_old_lchan(old_lchan))
return -EBUSY;
conn = old_lchan->conn;
if (!conn) {
LOGP(DHO, LOGL_ERROR, "Old lchan lacks connection data.\n");
return -ENOSPC;
}
if (!new_bts)
new_bts = old_lchan->ts->trx->bts;
OSMO_ASSERT(new_bts);
do_assignment = (new_bts == old_lchan->ts->trx->bts);
ho = talloc_zero(conn, struct bsc_handover);
if (!ho) {
LOGP(DHO, LOGL_FATAL, "Out of Memory\n");
return -ENOMEM;
}
ho->from_hodec_id = from_hodec_id;
ho->old_lchan = old_lchan;
ho->new_bts = new_bts;
ho->new_lchan_type = new_lchan_type;
ho->ho_ref = ho_ref++;
ho->inter_cell = !do_assignment;
ho->async = true;
llist_add(&ho->list, &bsc_handovers);
conn->ho = ho;
rc = osmo_fsm_inst_dispatch(conn->fi, GSCON_EV_HO_START, NULL);
if (rc < 0) {
LOGPHO(ho, LOGL_ERROR, "Failed to trigger handover, conn state does not allow it\n");
conn->ho = NULL;
talloc_free(ho);
}
return rc;
}
/*! Start actual handover. Call bsc_handover_start() instead; The only legal caller is the GSCON FSM in
* bsc_subscr_conn_fsm.c. */
int bsc_handover_start_gscon(struct gsm_subscriber_connection *conn)
{
int rc;
struct gsm_network *network = conn->network;
struct bsc_handover *ho = conn->ho;
struct gsm_lchan *old_lchan;
struct gsm_lchan *new_lchan;
if (!ho) {
LOGP(DHO, LOGL_ERROR, "%s: Requested to start handover, but conn->ho is NULL\n",
bsc_subscr_name(conn->bsub));
return -EINVAL;
}
OSMO_ASSERT(ho->old_lchan && ho->new_bts);
if (ho->old_lchan->conn != conn) {
LOGP(DHO, LOGL_ERROR,
"%s: Requested to start handover, but the lchan does not belong to this conn\n",
bsc_subscr_name(conn->bsub));
return -EINVAL;
}
rate_ctr_inc(&network->bsc_ctrs->ctr[BSC_CTR_HANDOVER_ATTEMPTED]);
ho->new_lchan = lchan_alloc(ho->new_bts, ho->new_lchan_type, 0);
if (!ho->new_lchan) {
LOGP(DHO, LOGL_NOTICE, "No free channel for %s\n", gsm_lchant_name(ho->new_lchan_type));
rate_ctr_inc(&network->bsc_ctrs->ctr[BSC_CTR_HANDOVER_NO_CHANNEL]);
return -ENOSPC;
}
LOGPHO(ho, LOGL_INFO, "Triggering %s\n", ho->inter_cell? "Handover" : "Assignment");
/* copy some parameters from old lchan */
old_lchan = ho->old_lchan;
new_lchan = ho->new_lchan;
memcpy(&new_lchan->encr, &old_lchan->encr, sizeof(new_lchan->encr));
if (!ho->inter_cell) {
new_lchan->ms_power = old_lchan->ms_power;
new_lchan->rqd_ta = old_lchan->rqd_ta;
} else {
new_lchan->ms_power =
ms_pwr_ctl_lvl(ho->new_bts->band, ho->new_bts->ms_max_power);
/* FIXME: do we have a better idea of the timing advance? */
//new_lchan->rqd_ta = old_lchan->rqd_ta;
}
new_lchan->bs_power = old_lchan->bs_power;
new_lchan->rsl_cmode = old_lchan->rsl_cmode;
new_lchan->tch_mode = old_lchan->tch_mode;
memcpy(&new_lchan->mr_ms_lv, &old_lchan->mr_ms_lv, sizeof(new_lchan->mr_ms_lv));
memcpy(&new_lchan->mr_bts_lv, &old_lchan->mr_bts_lv, sizeof(new_lchan->mr_bts_lv));
new_lchan->conn = conn;
rc = rsl_chan_activate_lchan(new_lchan,
ho->async ? RSL_ACT_INTER_ASYNC : RSL_ACT_INTER_SYNC,
ho->ho_ref);
if (rc < 0) {
LOGPHO(ho, LOGL_INFO, "%s Failure: activate lchan rc = %d\n",
ho->inter_cell? "Handover" : "Assignment", rc);
lchan_free(new_lchan);
ho->new_lchan = NULL;
bsc_clear_handover(conn, 0);
return rc;
}
rsl_lchan_set_state(new_lchan, LCHAN_S_ACT_REQ);
/* we continue in the SS_LCHAN handler / ho_chan_activ_ack */
return 0;
}
/* clear any operation for this connection */
void bsc_clear_handover(struct gsm_subscriber_connection *conn, int free_lchan)
{
struct bsc_handover *ho = conn->ho;
if (!ho)
return;
if (ho->new_lchan) {
ho->new_lchan->conn = NULL;
if (free_lchan)
lchan_release(ho->new_lchan, 0, RSL_REL_LOCAL_END);
ho->new_lchan = NULL;
}
handover_free(ho);
conn->ho = NULL;
}
/* T3103 expired: Handover has failed without HO COMPLETE or HO FAIL */
static void ho_T3103_cb(void *_ho)
{
struct bsc_handover *ho = _ho;
struct gsm_network *net = ho->new_lchan->ts->trx->bts->network;
DEBUGP(DHO, "HO T3103 expired\n");
rate_ctr_inc(&net->bsc_ctrs->ctr[BSC_CTR_HANDOVER_TIMEOUT]);
/* Inform the GSCON FSM about the timed out handover */
osmo_fsm_inst_dispatch(ho->old_lchan->conn->fi, GSCON_EV_HO_TIMEOUT, NULL);
bsc_clear_handover(ho->old_lchan->conn, 1);
}
/* RSL has acknowledged activation of the new lchan */
static int ho_chan_activ_ack(struct gsm_lchan *new_lchan)
{
struct bsc_handover *ho;
/* we need to check if this channel activation is related to
* a handover at all (and if, which particular handover) */
ho = bsc_ho_by_new_lchan(new_lchan);
if (!ho)
return -ENODEV;
LOGPHO(ho, LOGL_INFO, "Channel Activate Ack, send %s COMMAND\n", ho->inter_cell? "HANDOVER" : "ASSIGNMENT");
/* we can now send the 04.08 HANDOVER COMMAND to the MS
* using the old lchan */
gsm48_send_ho_cmd(ho->old_lchan, new_lchan, new_lchan->ms_power, ho->ho_ref);
/* start T3103. We can continue either with T3103 expiration,
* 04.08 HANDOVER COMPLETE or 04.08 HANDOVER FAIL */
osmo_timer_setup(&ho->T3103, ho_T3103_cb, ho);
osmo_timer_schedule(&ho->T3103, 10, 0);
/* create a RTP connection */
if (is_ipaccess_bts(new_lchan->ts->trx->bts))
rsl_ipacc_crcx(new_lchan);
return 0;
}
/* RSL has not acknowledged activation of the new lchan */
static int ho_chan_activ_nack(struct gsm_lchan *new_lchan)
{
struct bsc_handover *ho;
struct handover_decision_callbacks *hdc;
ho = bsc_ho_by_new_lchan(new_lchan);
if (!ho) {
/* This lchan is not involved in a handover. */
return 0;
}
hdc = handover_decision_callbacks_get(ho->from_hodec_id);
if (hdc && hdc->on_ho_chan_activ_nack)
hdc->on_ho_chan_activ_nack(ho);
bsc_clear_handover(new_lchan->conn, 0);
return 0;
}
/* GSM 04.08 HANDOVER COMPLETE has been received on new channel */
static int ho_gsm48_ho_compl(struct gsm_lchan *new_lchan)
{
struct gsm_network *net;
struct bsc_handover *ho;
ho = bsc_ho_by_new_lchan(new_lchan);
if (!ho) {
LOGP(DHO, LOGL_ERROR, "unable to find HO record\n");
return -ENODEV;
}
net = new_lchan->ts->trx->bts->network;
LOGPHO(ho, LOGL_INFO, "%s Complete\n", ho->inter_cell ? "Handover" : "Assignment");
rate_ctr_inc(&net->bsc_ctrs->ctr[BSC_CTR_HANDOVER_COMPLETED]);
osmo_timer_del(&ho->T3103);
/* Replace the ho lchan with the primary one */
if (ho->old_lchan != new_lchan->conn->lchan)
LOGPHO(ho, LOGL_ERROR, "Primary lchan changed during handover.\n");
if (new_lchan->conn->ho != ho)
LOGPHO(ho, LOGL_ERROR, "Handover channel changed during this handover.\n");
new_lchan->conn->lchan = new_lchan;
ho->old_lchan->conn = NULL;
lchan_release(ho->old_lchan, 0, RSL_REL_LOCAL_END);
handover_free(ho);
new_lchan->conn->ho = NULL;
/* Inform the GSCON FSM that the handover is complete */
osmo_fsm_inst_dispatch(new_lchan->conn->fi, GSCON_EV_HO_COMPL, NULL);
return 0;
}
/* GSM 04.08 HANDOVER FAIL has been received */
static int ho_gsm48_ho_fail(struct gsm_lchan *old_lchan)
{
struct gsm_network *net = old_lchan->ts->trx->bts->network;
struct bsc_handover *ho;
struct handover_decision_callbacks *hdc;
ho = bsc_ho_by_old_lchan(old_lchan);
if (!ho) {
LOGP(DHO, LOGL_ERROR, "unable to find HO record\n");
return -ENODEV;
}
hdc = handover_decision_callbacks_get(ho->from_hodec_id);
if (hdc && hdc->on_ho_failure)
hdc->on_ho_failure(ho);
rate_ctr_inc(&net->bsc_ctrs->ctr[BSC_CTR_HANDOVER_FAILED]);
bsc_clear_handover(ho->new_lchan->conn, 1);
/* Inform the GSCON FSM that the handover failed */
osmo_fsm_inst_dispatch(old_lchan->conn->fi, GSCON_EV_HO_FAIL, NULL);
return 0;
}
/* GSM 08.58 HANDOVER DETECT has been received */
static int ho_rsl_detect(struct gsm_lchan *new_lchan)
{
struct bsc_handover *ho;
ho = bsc_ho_by_new_lchan(new_lchan);
if (!ho) {
LOGP(DHO, LOGL_ERROR, "unable to find HO record\n");
return -ENODEV;
}
LOGPHO(ho, LOGL_DEBUG, "Handover RACH detected\n");
/* This is just for logging on the DHO category. The actual MGCP switchover happens in
* osmo_bsc_mgcp.c by receiving the same S_LCHAN_HANDOVER_DETECT signal.
* (Calling mgcp_handover() directly currently breaks linking in utils/...) */
return 0;
}
static int ho_meas_rep(struct gsm_meas_rep *mr)
static void ho_meas_rep(struct gsm_meas_rep *mr)
{
struct handover_decision_callbacks *hdc;
enum hodec_id hodec_id = ho_get_algorithm(mr->lchan->ts->trx->bts->ho);
hdc = handover_decision_callbacks_get(hodec_id);
if (!hdc || !hdc->on_measurement_report)
return 0;
return;
hdc->on_measurement_report(mr);
return 0;
}
/* Count ongoing handovers within the given BTS.
* ho_scopes is an OR'd combination of enum handover_scope values to include in the count. */
int bts_handover_count(struct gsm_bts *bts, int ho_scopes)
{
struct gsm_bts_trx *trx;
int count = 0;
llist_for_each_entry(trx, &bts->trx_list, list) {
int i;
for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
struct gsm_bts_trx_ts *ts = &trx->ts[i];
struct gsm_lchan *lchan;
/* skip administratively deactivated timeslots */
if (!nm_is_running(&ts->mo.nm_state))
continue;
ts_for_each_lchan(lchan, ts) {
if (!lchan->conn)
continue;
if (!lchan->conn->ho.fi)
continue;
if (lchan->conn->ho.scope & ho_scopes)
count++;
}
}
}
return count;
}
struct gsm_bts *bts_by_neighbor_ident(const struct gsm_network *net,
@ -440,73 +176,23 @@ static int ho_logic_sig_cb(unsigned int subsys, unsigned int signal,
lchan_data = signal_data;
switch (subsys) {
case SS_LCHAN:
OSMO_ASSERT(lchan_data);
lchan = lchan_data->lchan;
OSMO_ASSERT(lchan);
switch (signal) {
case S_LCHAN_ACTIVATE_ACK:
return ho_chan_activ_ack(lchan);
case S_LCHAN_ACTIVATE_NACK:
return ho_chan_activ_nack(lchan);
case S_LCHAN_HANDOVER_DETECT:
return ho_rsl_detect(lchan);
case S_LCHAN_HANDOVER_COMPL:
return ho_gsm48_ho_compl(lchan);
case S_LCHAN_HANDOVER_FAIL:
return ho_gsm48_ho_fail(lchan);
case S_LCHAN_MEAS_REP:
return ho_meas_rep(lchan_data->mr);
ho_meas_rep(lchan_data->mr);
break;
}
break;
default:
break;
}
return 0;
}
/* Return the old lchan or NULL. This is meant for audio handling */
struct gsm_lchan *bsc_handover_pending(struct gsm_lchan *new_lchan)
{
struct bsc_handover *ho;
ho = bsc_ho_by_new_lchan(new_lchan);
if (!ho)
return NULL;
return ho->old_lchan;
}
static __attribute__((constructor)) void on_dso_load_ho_logic(void)
{
osmo_signal_register_handler(SS_LCHAN, ho_logic_sig_cb, NULL);
}
/* Count number of currently ongoing handovers
* inter_cell: if true, count only handovers between two cells. If false, count only handovers within one
* cell. */
int bsc_ho_count(struct gsm_bts *bts, bool inter_cell)
{
struct bsc_handover *ho;
int count = 0;
llist_for_each_entry(ho, &bsc_handovers, list) {
if (ho->inter_cell != inter_cell)
continue;
if (ho->new_lchan->ts->trx->bts == bts)
count++;
}
return count;
}
void handover_decision_callbacks_register(struct handover_decision_callbacks *hdc)
{
llist_add_tail(&hdc->entry, &handover_decision_callbacks);
}
struct handover_decision_callbacks *handover_decision_callbacks_get(int hodec_id)
{
struct handover_decision_callbacks *hdc;
llist_for_each_entry(hdc, &handover_decision_callbacks, entry) {
if (hdc->hodec_id == hodec_id)
return hdc;
}
return NULL;
}

1522
src/osmo-bsc/lchan_fsm.c Normal file

File diff suppressed because it is too large Load Diff

260
src/osmo-bsc/lchan_select.c Normal file
View File

@ -0,0 +1,260 @@
/* Select a suitable lchan from a given cell.
*
* (C) 2008 by Harald Welte <laforge@gnumonks.org>
* (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2018 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
*
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <osmocom/bsc/debug.h>
#include <osmocom/bsc/gsm_data.h>
#include <osmocom/bsc/timeslot_fsm.h>
#include <osmocom/bsc/lchan_fsm.h>
#include <osmocom/bsc/lchan_select.h>
static struct gsm_lchan *
_lc_find_trx(struct gsm_bts_trx *trx, enum gsm_phys_chan_config pchan,
enum gsm_phys_chan_config as_pchan)
{
struct gsm_lchan *lchan;
struct gsm_bts_trx_ts *ts;
int j, start, stop, dir;
#define LOGPLCHANALLOC(fmt, args...) \
LOGP(DRLL, LOGL_DEBUG, "looking for lchan %s%s%s: " fmt, \
gsm_pchan_name(pchan), \
pchan == as_pchan ? "" : " as ", \
pchan == as_pchan ? "" : gsm_pchan_name(as_pchan), ## args)
if (!trx_is_usable(trx)) {
LOGPLCHANALLOC("%s trx not usable\n", gsm_trx_name(trx));
return NULL;
}
if (trx->bts->chan_alloc_reverse) {
/* check TS 7..0 */
start = 7;
stop = -1;
dir = -1;
} else {
/* check TS 0..7 */
start = 0;
stop = 8;
dir = 1;
}
for (j = start; j != stop; j += dir) {
ts = &trx->ts[j];
if (!ts_is_usable(ts))
continue;
/* The caller first selects what kind of TS to search in, e.g. looking for exact
* GSM_PCHAN_TCH_F, or maybe among dynamic GSM_PCHAN_TCH_F_TCH_H_PDCH... */
if (ts->pchan_on_init != pchan) {
LOGPLCHANALLOC("%s is != %s\n", gsm_ts_and_pchan_name(ts),
gsm_pchan_name(pchan));
continue;
}
/* Next, is this timeslot in or can it be switched to the pchan we want to use it for? */
if (!ts_usable_as_pchan(ts, as_pchan)) {
LOGPLCHANALLOC("%s is not usable as %s\n", gsm_ts_and_pchan_name(ts),
gsm_pchan_name(as_pchan));
continue;
}
/* TS is (going to be) in desired pchan mode. Go ahead and check for an available lchan. */
ts_as_pchan_for_each_lchan(lchan, ts, as_pchan) {
if (lchan->fi->state == LCHAN_ST_UNUSED) {
LOGPLCHANALLOC("%s ss=%d is available%s\n",
gsm_ts_and_pchan_name(ts), lchan->nr,
ts->pchan_is != as_pchan ? " after dyn PCHAN change" : "");
return lchan;
}
LOGPLCHANALLOC("%s ss=%d in type=%s,state=%s not suitable\n",
gsm_ts_and_pchan_name(ts), lchan->nr,
gsm_lchant_name(lchan->type),
osmo_fsm_inst_state_name(lchan->fi));
}
}
return NULL;
#undef LOGPLCHANALLOC
}
static struct gsm_lchan *
_lc_dyn_find_bts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan,
enum gsm_phys_chan_config dyn_as_pchan)
{
struct gsm_bts_trx *trx;
struct gsm_lchan *lc;
if (bts->chan_alloc_reverse) {
llist_for_each_entry_reverse(trx, &bts->trx_list, list) {
lc = _lc_find_trx(trx, pchan, dyn_as_pchan);
if (lc)
return lc;
}
} else {
llist_for_each_entry(trx, &bts->trx_list, list) {
lc = _lc_find_trx(trx, pchan, dyn_as_pchan);
if (lc)
return lc;
}
}
return NULL;
}
static struct gsm_lchan *
_lc_find_bts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan)
{
return _lc_dyn_find_bts(bts, pchan, pchan);
}
struct gsm_lchan *lchan_select_by_chan_mode(struct gsm_bts *bts,
enum gsm48_chan_mode chan_mode, bool full_rate)
{
enum gsm_chan_t type;
switch (chan_mode) {
case GSM48_CMODE_SIGN:
type = GSM_LCHAN_SDCCH;
break;
case GSM48_CMODE_SPEECH_V1:
case GSM48_CMODE_SPEECH_EFR:
case GSM48_CMODE_SPEECH_AMR:
type = full_rate ? GSM_LCHAN_TCH_F : GSM_LCHAN_TCH_H;
break;
default:
return NULL;
}
return lchan_select_by_type(bts, type);
}
/* Return a matching lchan from a specific BTS that is currently available. The next logical step is
* lchan_activate() on it, which would possibly cause dynamic timeslot pchan switching, taken care of by
* the lchan and timeslot FSMs. */
struct gsm_lchan *lchan_select_by_type(struct gsm_bts *bts, enum gsm_chan_t type)
{
struct gsm_lchan *lchan = NULL;
enum gsm_phys_chan_config first, first_cbch, second, second_cbch;
LOGP(DRLL, LOGL_DEBUG, "(bts=%d) lchan_select_by_type(%s)\n", bts->nr, gsm_lchant_name(type));
switch (type) {
case GSM_LCHAN_SDCCH:
if (bts->chan_alloc_reverse) {
first = GSM_PCHAN_SDCCH8_SACCH8C;
first_cbch = GSM_PCHAN_SDCCH8_SACCH8C_CBCH;
second = GSM_PCHAN_CCCH_SDCCH4;
second_cbch = GSM_PCHAN_CCCH_SDCCH4_CBCH;
} else {
first = GSM_PCHAN_CCCH_SDCCH4;
first_cbch = GSM_PCHAN_CCCH_SDCCH4_CBCH;
second = GSM_PCHAN_SDCCH8_SACCH8C;
second_cbch = GSM_PCHAN_SDCCH8_SACCH8C_CBCH;
}
lchan = _lc_find_bts(bts, first);
if (lchan == NULL)
lchan = _lc_find_bts(bts, first_cbch);
if (lchan == NULL)
lchan = _lc_find_bts(bts, second);
if (lchan == NULL)
lchan = _lc_find_bts(bts, second_cbch);
break;
case GSM_LCHAN_TCH_F:
lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_F);
/* If we don't have TCH/F available, fall-back to TCH/H */
if (!lchan) {
lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_H);
if (lchan)
type = GSM_LCHAN_TCH_H;
}
/* If we don't have TCH/H either, try dynamic TCH/F_PDCH */
if (!lchan) {
lchan = _lc_dyn_find_bts(bts, GSM_PCHAN_TCH_F_PDCH,
GSM_PCHAN_TCH_F);
/* TCH/F_PDCH used as TCH/F -- here, type is already
* set to GSM_LCHAN_TCH_F, but for clarity's sake... */
if (lchan)
type = GSM_LCHAN_TCH_F;
}
/* Try fully dynamic TCH/F_TCH/H_PDCH as TCH/F... */
if (!lchan && bts->network->dyn_ts_allow_tch_f) {
lchan = _lc_dyn_find_bts(bts,
GSM_PCHAN_TCH_F_TCH_H_PDCH,
GSM_PCHAN_TCH_F);
if (lchan)
type = GSM_LCHAN_TCH_F;
}
/* ...and as TCH/H. */
if (!lchan) {
lchan = _lc_dyn_find_bts(bts,
GSM_PCHAN_TCH_F_TCH_H_PDCH,
GSM_PCHAN_TCH_H);
if (lchan)
type = GSM_LCHAN_TCH_H;
}
break;
case GSM_LCHAN_TCH_H:
lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_H);
/* If we don't have TCH/H available, fall-back to TCH/F */
if (!lchan) {
lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_F);
if (lchan)
type = GSM_LCHAN_TCH_F;
}
/* No dedicated TCH/x available -- try fully dynamic
* TCH/F_TCH/H_PDCH */
if (!lchan) {
lchan = _lc_dyn_find_bts(bts,
GSM_PCHAN_TCH_F_TCH_H_PDCH,
GSM_PCHAN_TCH_H);
if (lchan)
type = GSM_LCHAN_TCH_H;
}
/*
* No need to check TCH/F_TCH/H_PDCH channels for TCH/F:
* if no TCH/H was available, neither will be TCH/F.
*/
/* If we don't have TCH/F either, try dynamic TCH/F_PDCH */
if (!lchan) {
lchan = _lc_dyn_find_bts(bts, GSM_PCHAN_TCH_F_PDCH,
GSM_PCHAN_TCH_F);
if (lchan)
type = GSM_LCHAN_TCH_F;
}
break;
default:
LOGP(DRLL, LOGL_ERROR, "Unknown gsm_chan_t %u\n", type);
}
if (lchan) {
lchan->type = type;
LOG_LCHAN(lchan, LOGL_INFO, "Selected\n");
} else
LOGP(DRLL, LOGL_ERROR, "(bts=%d) Failed to select %s channel\n",
bts->nr, gsm_lchant_name(type));
return lchan;
}

View File

@ -75,7 +75,7 @@ static int process_meas_rep(struct gsm_meas_rep *mr)
/* copy channel information */
/* we assume that the measurement report always belong to some timeslot */
mfm->lchan_type = (uint8_t)mr->lchan->type;
mfm->pchan_type = (uint8_t)mr->lchan->ts->pchan;
mfm->pchan_type = (uint8_t)mr->lchan->ts->pchan_is;
mfm->bts_nr = mr->lchan->ts->trx->bts->nr;
mfm->trx_nr = mr->lchan->ts->trx->nr;
mfm->ts_nr = mr->lchan->ts->nr;

View File

@ -0,0 +1,746 @@
/* osmo-bsc API to manage all sides of an MGW endpoint
*
* (C) 2018 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
* All Rights Reserved
*
* Author: Neels Hofmeyr <neels@hofmeyr.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <osmocom/core/fsm.h>
#include <osmocom/core/byteswap.h>
#include <osmocom/bsc/debug.h>
#include <osmocom/bsc/gsm_timers.h>
#include <osmocom/bsc/mgw_endpoint_fsm.h>
#include <osmocom/bsc/lchan_fsm.h>
#include <osmocom/bsc/gsm_data.h>
#define LOG_CI(ci, level, fmt, args...) do { \
if (!ci || !ci->mgwep) \
LOGP(DLGLOBAL, level, "(unknown MGW endpoint) " fmt, ## args); \
else \
LOG_MGWEP(ci->mgwep, level, "CI[%d] %s%s%s: " fmt, \
(int)(ci - ci->mgwep->ci), \
ci->label ? : "-", \
ci->mgcp_ci_str[0] ? " CI=" : "", \
ci->mgcp_ci_str[0] ? ci->mgcp_ci_str : "", \
## args); \
} while(0)
#define LOG_CI_VERB(ci, level, fmt, args...) do { \
if (ci->verb_info.addr) \
LOG_CI(ci, level, "%s %s:%u: " fmt, \
mgcp_verb_name(ci->verb), ci->verb_info.addr, ci->verb_info.port, \
## args); \
else \
LOG_CI(ci, level, "%s: " fmt, \
mgcp_verb_name(ci->verb), \
## args); \
} while(0)
#define FIRST_CI_EVENT (_MGWEP_EV_LAST + (_MGWEP_EV_LAST & 1)) /* rounded up to even nr */
#define USABLE_CI ((32 - FIRST_CI_EVENT)/2)
#define EV_TO_CI_IDX(event) ((event - FIRST_CI_EVENT) / 2)
#define CI_EV_SUCCESS(ci) (FIRST_CI_EVENT + (((ci) - ci->mgwep->ci) * 2))
#define CI_EV_FAILURE(ci) (CI_EV_SUCCESS(ci) + 1)
static struct osmo_fsm mgwep_fsm;
struct mgwep_ci {
struct mgw_endpoint *mgwep;
bool occupied;
char label[64];
struct osmo_fsm_inst *mgcp_client_fi;
bool pending;
bool sent;
enum mgcp_verb verb;
struct mgcp_conn_peer verb_info;
struct osmo_fsm_inst *notify;
uint32_t notify_success;
uint32_t notify_failure;
void *notify_data;
bool got_port_info;
struct mgcp_conn_peer rtp_info;
char mgcp_ci_str[MGCP_CONN_ID_LENGTH];
};
struct mgw_endpoint {
struct mgcp_client *mgcp_client;
struct osmo_fsm_inst *fi;
char endpoint[MGCP_ENDPOINT_MAXLEN];
struct mgwep_ci ci[USABLE_CI];
};
static const struct value_string mgcp_verb_names[] = {
{ MGCP_VERB_CRCX, "CRCX" },
{ MGCP_VERB_MDCX, "MDCX" },
{ MGCP_VERB_DLCX, "DLCX" },
{ MGCP_VERB_AUEP, "AUEP" },
{ MGCP_VERB_RSIP, "RSIP" },
{}
};
static inline const char *mgcp_verb_name(enum mgcp_verb val)
{ return get_value_string(mgcp_verb_names, val); }
static struct mgwep_ci *mgwep_check_ci(struct mgwep_ci *ci)
{
if (!ci)
return NULL;
if (!ci->mgwep)
return NULL;
if (ci < ci->mgwep->ci || ci >= &ci->mgwep->ci[USABLE_CI])
return NULL;
return ci;
}
static struct mgwep_ci *mgwep_ci_for_event(struct mgw_endpoint *mgwep, uint32_t event)
{
int idx;
if (event < FIRST_CI_EVENT)
return NULL;
idx = EV_TO_CI_IDX(event);
if (idx >= sizeof(mgwep->ci))
return NULL;
return mgwep_check_ci(&mgwep->ci[idx]);
}
const char *mgw_endpoint_name(const struct mgw_endpoint *mgwep)
{
if (!mgwep)
return "NULL";
if (mgwep->endpoint[0])
return mgwep->endpoint;
return osmo_fsm_inst_name(mgwep->fi);
}
const char *mgcp_conn_peer_name(const struct mgcp_conn_peer *info)
{
/* I'd be fine with a smaller buffer and accept truncation, but gcc possibly refuses to build if
* this buffer is too small. */
static char buf[1024];
if (!info)
return "NULL";
if (info->endpoint[0]
&& info->addr[0])
snprintf(buf, sizeof(buf), "%s:%s:%u",
info->endpoint, info->addr, info->port);
else if (info->endpoint[0])
snprintf(buf, sizeof(buf), "%s", info->endpoint);
else if (info->addr[0])
snprintf(buf, sizeof(buf), "%s:%u", info->addr, info->port);
else
return "empty";
return buf;
}
const char *mgwep_ci_name(const struct mgwep_ci *ci)
{
const struct mgcp_conn_peer *rtp_info;
if (!ci)
return "NULL";
rtp_info = mgwep_ci_get_rtp_info(ci);
if (rtp_info)
return mgcp_conn_peer_name(rtp_info);
return mgw_endpoint_name(ci->mgwep);
}
static struct value_string mgwep_fsm_event_names[33] = {};
static char mgwep_fsm_event_name_bufs[32][32] = {};
static void fill_event_names()
{
int i;
for (i = 0; i < (ARRAY_SIZE(mgwep_fsm_event_names) - 1); i++) {
if (i < _MGWEP_EV_LAST)
continue;
if (i < FIRST_CI_EVENT || EV_TO_CI_IDX(i) > USABLE_CI) {
mgwep_fsm_event_names[i] = (struct value_string){i, "Unused"};
continue;
}
snprintf(mgwep_fsm_event_name_bufs[i], sizeof(mgwep_fsm_event_name_bufs[i]),
"MGW Response for CI #%d", EV_TO_CI_IDX(i));
mgwep_fsm_event_names[i] = (struct value_string){i, mgwep_fsm_event_name_bufs[i]};
}
}
static struct T_def *g_T_defs = NULL;
void mgw_endpoint_fsm_init(struct T_def *T_defs)
{
g_T_defs = T_defs;
OSMO_ASSERT(osmo_fsm_register(&mgwep_fsm) == 0);
fill_event_names();
}
struct mgw_endpoint *mgwep_fi_mgwep(struct osmo_fsm_inst *fi)
{
OSMO_ASSERT(fi);
OSMO_ASSERT(fi->fsm == &mgwep_fsm);
OSMO_ASSERT(fi->priv);
return fi->priv;
}
struct mgw_endpoint *mgw_endpoint_alloc(struct osmo_fsm_inst *parent, uint32_t parent_term_event,
struct mgcp_client *mgcp_client,
const char *fsm_id,
const char *endpoint_str_fmt, ...)
{
va_list ap;
struct osmo_fsm_inst *fi;
struct mgw_endpoint *mgwep;
int rc;
if (!mgcp_client)
return NULL;
/* use mgcp_client as talloc ctx, so that the conn, lchan, ts can deallocate while MGCP DLCX are
* still going on. */
fi = osmo_fsm_inst_alloc_child(&mgwep_fsm, parent, parent_term_event);
OSMO_ASSERT(fi);
osmo_fsm_inst_update_id(fi, fsm_id);
mgwep = talloc_zero(fi, struct mgw_endpoint);
OSMO_ASSERT(mgwep);
mgwep->mgcp_client = mgcp_client;
mgwep->fi = fi;
mgwep->fi->priv = mgwep;
va_start(ap, endpoint_str_fmt);
rc = vsnprintf(mgwep->endpoint, sizeof(mgwep->endpoint), endpoint_str_fmt, ap);
va_end(ap);
if (rc <= 0 || rc >= sizeof(mgwep->endpoint)) {
LOG_MGWEP(mgwep, LOGL_ERROR, "Endpoint name too long or too short: %s\n",
mgwep->endpoint);
osmo_fsm_inst_term(mgwep->fi, OSMO_FSM_TERM_ERROR, 0);
return NULL;
}
return mgwep;
}
struct mgwep_ci *mgw_endpoint_ci_add(struct mgw_endpoint *mgwep,
const char *label_fmt, ...)
{
va_list ap;
int i;
struct mgwep_ci *ci;
for (i = 0; i < USABLE_CI; i++) {
ci = &mgwep->ci[i];
if (ci->occupied || ci->mgcp_client_fi)
continue;
*ci = (struct mgwep_ci){
.mgwep = mgwep,
.occupied = true,
};
if (label_fmt) {
va_start(ap, label_fmt);
vsnprintf(ci->label, sizeof(ci->label), label_fmt, ap);
va_end(ap);
}
return ci;
}
LOG_MGWEP(mgwep, LOGL_ERROR,
"Cannot allocate another endpoint, all "
OSMO_STRINGIFY_VAL(USABLE_CI) " are in use\n");
return NULL;
}
static void mgwep_fsm_check_state_chg_after_response(struct osmo_fsm_inst *fi);
static void on_failure(struct mgwep_ci *ci)
{
if (!ci->occupied)
return;
if (ci->notify)
osmo_fsm_inst_dispatch(ci->notify, ci->notify_failure, ci->notify_data);
*ci = (struct mgwep_ci){
.mgwep = ci->mgwep,
};
mgwep_fsm_check_state_chg_after_response(ci->mgwep->fi);
}
static void on_success(struct mgwep_ci *ci, void *data)
{
struct mgcp_conn_peer *rtp_info;
if (!ci->occupied)
return;
ci->pending = false;
switch (ci->verb) {
case MGCP_VERB_CRCX:
/* If we sent a wildcarded endpoint name on CRCX, we need to store the resulting endpoint
* name here. Also, we receive the MGW's RTP port information. */
rtp_info = data;
OSMO_ASSERT(rtp_info);
ci->got_port_info = true;
ci->rtp_info = *rtp_info;
osmo_strlcpy(ci->mgcp_ci_str, mgcp_conn_get_ci(ci->mgcp_client_fi),
sizeof(ci->mgcp_ci_str));
if (rtp_info->endpoint[0]) {
int rc;
rc = osmo_strlcpy(ci->mgwep->endpoint, rtp_info->endpoint,
sizeof(ci->mgwep->endpoint));
if (rc <= 0 || rc >= sizeof(ci->mgwep->endpoint)) {
LOG_CI(ci, LOGL_ERROR, "Unable to copy endpoint name '%s'\n",
rtp_info->endpoint);
mgw_endpoint_ci_dlcx(ci);
on_failure(ci);
return;
}
}
break;
default:
break;
}
LOG_CI(ci, LOGL_DEBUG, "received successful response to %s RTP=%s%s\n",
mgcp_verb_name(ci->verb),
mgcp_conn_peer_name(ci->got_port_info? &ci->rtp_info : NULL),
ci->notify ? "" : " (not sending a notification)");
if (ci->notify)
osmo_fsm_inst_dispatch(ci->notify, ci->notify_success, ci->notify_data);
mgwep_fsm_check_state_chg_after_response(ci->mgwep->fi);
}
const struct mgcp_conn_peer *mgwep_ci_get_rtp_info(const struct mgwep_ci *ci)
{
ci = mgwep_check_ci((struct mgwep_ci*)ci);
if (!ci)
return NULL;
if (!ci->got_port_info)
return NULL;
return &ci->rtp_info;
}
bool mgwep_ci_get_crcx_info_to_sockaddr(const struct mgwep_ci *ci, struct sockaddr_storage *dest)
{
const struct mgcp_conn_peer *rtp_info;
struct sockaddr_in *sin;
rtp_info = mgwep_ci_get_rtp_info(ci);
if (!rtp_info)
return false;
sin = (struct sockaddr_in *)dest;
sin->sin_family = AF_INET;
sin->sin_addr.s_addr = inet_addr(rtp_info->addr);
sin->sin_port = osmo_ntohs(rtp_info->port);
return true;
}
static const struct state_timeout mgwep_fsm_timeouts[32] = {
[MGWEP_ST_WAIT_MGW_RESPONSE] = { .T=23042 },
};
/* Transition to a state, using the T timer defined in assignment_fsm_timeouts.
* The actual timeout value is in turn obtained from g_T_defs.
* Assumes local variable fi exists. */
#define mgwep_fsm_state_chg(state) \
fsm_inst_state_chg_T(fi, state, mgwep_fsm_timeouts, g_T_defs, 5)
void mgw_endpoint_ci_request(struct mgwep_ci *ci,
enum mgcp_verb verb, const struct mgcp_conn_peer *verb_info,
struct osmo_fsm_inst *notify,
uint32_t event_success, uint32_t event_failure,
void *notify_data)
{
struct mgw_endpoint *mgwep;
struct osmo_fsm_inst *fi;
struct mgwep_ci cleared_ci;
ci = mgwep_check_ci(ci);
if (!ci) {
LOGP(DLGLOBAL, LOGL_ERROR, "Invalid MGW endpoint request: no ci\n");
goto dispatch_error;
}
if (!verb_info && verb != MGCP_VERB_DLCX) {
LOG_CI(ci, LOGL_ERROR, "Invalid MGW endpoint request: missing verb details for %s\n",
mgcp_verb_name(verb));
goto dispatch_error;
}
if ((verb < 0) || (verb > MGCP_VERB_RSIP)) {
LOG_CI(ci, LOGL_ERROR, "Invalid MGW endpoint request: unknown verb: %s\n",
mgcp_verb_name(verb));
goto dispatch_error;
}
mgwep = ci->mgwep;
fi = mgwep->fi;
/* Clear volatile state by explicitly keeping those that should remain. Because we can't assign
* the char[] directly, dance through cleared_ci and copy back. */
cleared_ci = (struct mgwep_ci){
.mgwep = mgwep,
.mgcp_client_fi = ci->mgcp_client_fi,
.got_port_info = ci->got_port_info,
.rtp_info = ci->rtp_info,
.occupied = true,
/* .pending = true follows below */
.verb = verb,
.notify = notify,
.notify_success = event_success,
.notify_failure = event_failure,
.notify_data = notify_data,
};
osmo_strlcpy(cleared_ci.label, ci->label, sizeof(cleared_ci.label));
osmo_strlcpy(cleared_ci.mgcp_ci_str, ci->mgcp_ci_str, sizeof(cleared_ci.mgcp_ci_str));
*ci = cleared_ci;
LOG_CI_VERB(ci, LOGL_DEBUG, "notify=%s\n", osmo_fsm_inst_name(ci->notify));
if (verb_info)
ci->verb_info = *verb_info;
if (mgwep->endpoint[0]) {
if (ci->verb_info.endpoint[0] && strcmp(ci->verb_info.endpoint, mgwep->endpoint))
LOG_CI(ci, LOGL_ERROR,
"Warning: Requested %s on endpoint %s, but this CI is on endpoint %s."
" Using the proper endpoint instead.\n",
mgcp_verb_name(verb), ci->verb_info.endpoint, mgwep->endpoint);
osmo_strlcpy(ci->verb_info.endpoint, mgwep->endpoint, sizeof(ci->verb_info.endpoint));
}
switch (ci->verb) {
case MGCP_VERB_CRCX:
if (ci->mgcp_client_fi) {
LOG_CI(ci, LOGL_ERROR, "CRCX can be called only once per MGW endpoint CI\n");
on_failure(ci);
return;
}
break;
case MGCP_VERB_MDCX:
case MGCP_VERB_DLCX:
if (!ci->mgcp_client_fi) {
LOG_CI_VERB(ci, LOGL_ERROR, "The first verb on an unused MGW endpoint CI must be CRCX, not %s\n",
mgcp_verb_name(ci->verb));
on_failure(ci);
return;
}
break;
default:
LOG_CI(ci, LOGL_ERROR, "This verb is not supported: %s\n", mgcp_verb_name(ci->verb));
on_failure(ci);
return;
}
ci->pending = true;
LOG_CI_VERB(ci, LOGL_DEBUG, "Scheduling\n");
if (mgwep->fi->state != MGWEP_ST_WAIT_MGW_RESPONSE)
mgwep_fsm_state_chg(MGWEP_ST_WAIT_MGW_RESPONSE);
return;
dispatch_error:
if (notify)
osmo_fsm_inst_dispatch(notify, event_failure, notify_data);
}
static int send_verb(struct mgwep_ci *ci)
{
int rc;
struct mgw_endpoint *mgwep = ci->mgwep;
if (!ci->occupied || !ci->pending || ci->sent)
return 0;
switch (ci->verb) {
case MGCP_VERB_CRCX:
OSMO_ASSERT(!ci->mgcp_client_fi);
LOG_CI_VERB(ci, LOGL_DEBUG, "Sending\n");
ci->mgcp_client_fi = mgcp_conn_create(mgwep->mgcp_client, mgwep->fi,
CI_EV_FAILURE(ci), CI_EV_SUCCESS(ci),
&ci->verb_info);
ci->sent = true;
if (!ci->mgcp_client_fi){
LOG_CI_VERB(ci, LOGL_ERROR, "Cannot send\n");
on_failure(ci);
}
osmo_fsm_inst_update_id(ci->mgcp_client_fi, ci->label);
break;
case MGCP_VERB_MDCX:
OSMO_ASSERT(ci->mgcp_client_fi);
LOG_CI_VERB(ci, LOGL_DEBUG, "Sending\n");
rc = mgcp_conn_modify(ci->mgcp_client_fi, CI_EV_SUCCESS(ci), &ci->verb_info);
ci->sent = true;
if (rc) {
LOG_CI_VERB(ci, LOGL_ERROR, "Cannot send (rc=%d %s)\n", rc, strerror(-rc));
on_failure(ci);
}
break;
case MGCP_VERB_DLCX:
LOG_CI(ci, LOGL_DEBUG, "Sending MGCP: %s %s\n",
mgcp_verb_name(ci->verb), ci->mgcp_ci_str);
/* The way this is designed, we actually need to forget all about the ci right away. */
mgcp_conn_delete(ci->mgcp_client_fi);
if (ci->notify)
osmo_fsm_inst_dispatch(ci->notify, ci->notify_success, ci->notify_data);
*ci = (struct mgwep_ci){
.mgwep = mgwep,
};
break;
default:
OSMO_ASSERT(false);
}
return 1;
}
void mgw_endpoint_clear(struct mgw_endpoint *mgwep)
{
if (!mgwep)
return;
osmo_fsm_inst_term(mgwep->fi, OSMO_FSM_TERM_REGULAR, 0);
}
static void mgwep_count(struct mgw_endpoint *mgwep, int *occupied, int *pending_not_sent,
int *waiting_for_response)
{
int i;
if (occupied)
*occupied = 0;
if (pending_not_sent)
*pending_not_sent = 0;
if (waiting_for_response)
*waiting_for_response = 0;
for (i = 0; i < ARRAY_SIZE(mgwep->ci); i++) {
struct mgwep_ci *ci = &mgwep->ci[i];
if (ci->occupied) {
if (occupied)
(*occupied)++;
} else
continue;
if (ci->pending)
LOG_CI_VERB(ci, LOGL_DEBUG, "%s\n",
ci->sent ? "waiting for response" : "waiting to be sent");
else
LOG_CI_VERB(ci, LOGL_DEBUG, "%s\n", mgcp_conn_peer_name(mgwep_ci_get_rtp_info(ci)));
if (ci->pending && ci->sent)
if (waiting_for_response)
(*waiting_for_response)++;
if (ci->pending && !ci->sent)
if (pending_not_sent)
(*pending_not_sent)++;
}
}
static void mgwep_fsm_check_state_chg_after_response(struct osmo_fsm_inst *fi)
{
int waiting_for_response;
int occupied;
struct mgw_endpoint *mgwep = mgwep_fi_mgwep(fi);
mgwep_count(mgwep, &occupied, NULL, &waiting_for_response);
LOG_MGWEP(mgwep, LOGL_DEBUG, "CI in use: %d, waiting for response: %d\n", occupied, waiting_for_response);
if (!occupied) {
/* All CI have been released. The endpoint no longer exists. Notify the parent FSM, by
* terminating. */
osmo_fsm_inst_term(fi, OSMO_FSM_TERM_REGULAR, 0);
return;
}
if (!waiting_for_response) {
if (fi->state != MGWEP_ST_IN_USE)
mgwep_fsm_state_chg(MGWEP_ST_IN_USE);
return;
}
}
static void mgwep_fsm_wait_mgw_response_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
{
int count = 0;
int i;
struct mgw_endpoint *mgwep = mgwep_fi_mgwep(fi);
for (i = 0; i < ARRAY_SIZE(mgwep->ci); i++) {
count += send_verb(&mgwep->ci[i]);
}
LOG_MGWEP(mgwep, LOGL_DEBUG, "Sent messages: %d\n", count);
mgwep_fsm_check_state_chg_after_response(fi);
}
static void mgwep_fsm_handle_ci_events(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
struct mgwep_ci *ci;
struct mgw_endpoint *mgwep = mgwep_fi_mgwep(fi);
ci = mgwep_ci_for_event(mgwep, event);
if (ci) {
if (event == CI_EV_SUCCESS(ci))
on_success(ci, data);
else
on_failure(ci);
}
}
static void mgwep_fsm_in_use_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
{
int pending_not_sent;
struct mgw_endpoint *mgwep = mgwep_fi_mgwep(fi);
mgwep_count(mgwep, NULL, &pending_not_sent, NULL);
if (pending_not_sent)
mgwep_fsm_state_chg(MGWEP_ST_WAIT_MGW_RESPONSE);
}
#define S(x) (1 << (x))
static const struct osmo_fsm_state mgwep_fsm_states[] = {
[MGWEP_ST_UNUSED] = {
.name = "UNUSED",
.in_event_mask = 0,
.out_state_mask = 0
| S(MGWEP_ST_WAIT_MGW_RESPONSE)
,
},
[MGWEP_ST_WAIT_MGW_RESPONSE] = {
.name = "WAIT_MGW_RESPONSE",
.onenter = mgwep_fsm_wait_mgw_response_onenter,
.action = mgwep_fsm_handle_ci_events,
.in_event_mask = 0xffffffff,
.out_state_mask = 0
| S(MGWEP_ST_IN_USE)
,
},
[MGWEP_ST_IN_USE] = {
.name = "IN_USE",
.onenter = mgwep_fsm_in_use_onenter,
.action = mgwep_fsm_handle_ci_events,
.in_event_mask = 0xffffffff, /* mgcp_client_fsm may send parent term anytime */
.out_state_mask = 0
| S(MGWEP_ST_WAIT_MGW_RESPONSE)
,
},
};
static int mgwep_fsm_timer_cb(struct osmo_fsm_inst *fi)
{
int i;
struct mgw_endpoint *mgwep = mgwep_fi_mgwep(fi);
switch (fi->T) {
default:
for (i = 0; i < ARRAY_SIZE(mgwep->ci); i++) {
struct mgwep_ci *ci = &mgwep->ci[i];
if (!ci->occupied)
continue;
if (!(ci->pending && ci->sent))
continue;
on_failure(ci);
}
return 0;
}
return 0;
}
static struct osmo_fsm mgwep_fsm = {
.name = "mgw-endpoint",
.states = mgwep_fsm_states,
.num_states = ARRAY_SIZE(mgwep_fsm_states),
.log_subsys = DRSL,
.event_names = mgwep_fsm_event_names,
.timer_cb = mgwep_fsm_timer_cb,
/* The FSM termination will automatically trigger any mgcp_client_fsm instances to DLCX. */
};
/* Depending on the channel mode and rate, return the codec type that is signalled towards the MGW. */
enum mgcp_codecs chan_mode_to_mgcp_codec(enum gsm48_chan_mode chan_mode, bool full_rate)
{
switch (chan_mode) {
case GSM48_CMODE_SPEECH_V1:
if (full_rate)
return CODEC_GSM_8000_1;
return CODEC_GSMHR_8000_1;
case GSM48_CMODE_SPEECH_EFR:
return CODEC_GSMEFR_8000_1;
case GSM48_CMODE_SPEECH_AMR:
return CODEC_AMR_8000_1;
default:
return -1;
}
}
void mgcp_pick_codec(struct mgcp_conn_peer *verb_info, const struct gsm_lchan *lchan)
{
enum mgcp_codecs codec = chan_mode_to_mgcp_codec(lchan->tch_mode,
lchan->type == GSM_LCHAN_TCH_H? false : true);
if (codec < 0) {
LOG_LCHAN(lchan, LOGL_ERROR,
"Unable to determine MGCP codec type for %s in chan-mode %s\n",
gsm_lchant_name(lchan->type), gsm48_chan_mode_name(lchan->tch_mode));
verb_info->codecs_len = 0;
}
verb_info->codecs[0] = codec;
verb_info->codecs_len = 1;
}

View File

@ -22,6 +22,7 @@
#include <osmocom/bsc/bsc_msc_data.h>
#include <osmocom/bsc/bsc_subscriber.h>
#include <osmocom/bsc/debug.h>
#include <osmocom/bsc/paging.h>
#include <osmocom/bsc/gsm_04_80.h>
#include <osmocom/bsc/gsm_04_08_rr.h>
@ -35,7 +36,7 @@
#include <osmocom/bsc/osmo_bsc_sigtran.h>
/* Check if we have a proper connection to the MSC */
static bool msc_connected(struct gsm_subscriber_connection *conn)
bool msc_connected(struct gsm_subscriber_connection *conn)
{
/* No subscriber conn at all */
if (!conn)
@ -167,6 +168,23 @@ void bsc_cipher_mode_compl(struct gsm_subscriber_connection *conn, struct msgb *
msgb_free(resp);
}
/* 9.2.5 CM service accept */
int gsm48_tx_mm_serv_ack(struct gsm_subscriber_connection *conn)
{
struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 SERV ACK");
struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
msg->lchan = conn->lchan;
gh->proto_discr = GSM48_PDISC_MM;
gh->msg_type = GSM48_MT_MM_CM_SERV_ACC;
DEBUGP(DMM, "-> CM SERVICE ACK\n");
gscon_submit_rsl_dtap(conn, msg, 0, 0);
return 0;
}
static void bsc_send_ussd_no_srv(struct gsm_subscriber_connection *conn,
struct msgb *msg, const char *text)
{
@ -211,6 +229,141 @@ static void bsc_send_ussd_no_srv(struct gsm_subscriber_connection *conn,
bsc_send_ussd_release_complete(conn);
}
static int is_cm_service_for_emerg(struct msgb *msg)
{
struct gsm48_service_request *cm;
struct gsm48_hdr *gh = msgb_l3(msg);
if (msgb_l3len(msg) < sizeof(*gh) + sizeof(*cm)) {
LOGP(DMSC, LOGL_ERROR, "CM ServiceRequest does not fit.\n");
return 0;
}
cm = (struct gsm48_service_request *) &gh->data[0];
return cm->cm_service_type == GSM48_CMSERV_EMERGENCY;
}
/* extract a subscriber from the paging response */
static struct bsc_subscr *extract_sub(struct gsm_subscriber_connection *conn,
struct msgb *msg)
{
uint8_t mi_type;
char mi_string[GSM48_MI_SIZE];
struct gsm48_hdr *gh;
struct gsm48_pag_resp *resp;
struct bsc_subscr *subscr;
if (msgb_l3len(msg) < sizeof(*gh) + sizeof(*resp)) {
LOGP(DMSC, LOGL_ERROR, "PagingResponse too small: %u\n", msgb_l3len(msg));
return NULL;
}
gh = msgb_l3(msg);
resp = (struct gsm48_pag_resp *) &gh->data[0];
gsm48_paging_extract_mi(resp, msgb_l3len(msg) - sizeof(*gh),
mi_string, &mi_type);
DEBUGP(DRR, "PAGING RESPONSE: MI(%s)=%s\n",
gsm48_mi_type_name(mi_type), mi_string);
switch (mi_type) {
case GSM_MI_TYPE_TMSI:
subscr = bsc_subscr_find_by_tmsi(conn->network->bsc_subscribers,
tmsi_from_string(mi_string));
break;
case GSM_MI_TYPE_IMSI:
subscr = bsc_subscr_find_by_imsi(conn->network->bsc_subscribers,
mi_string);
break;
default:
subscr = NULL;
break;
}
return subscr;
}
struct bsc_msc_data *bsc_find_msc(struct gsm_subscriber_connection *conn,
struct msgb *msg)
{
struct gsm48_hdr *gh;
int8_t pdisc;
uint8_t mtype;
struct osmo_bsc_data *bsc;
struct bsc_msc_data *msc, *pag_msc;
struct bsc_subscr *subscr;
int is_emerg = 0;
bsc = conn->network->bsc_data;
if (msgb_l3len(msg) < sizeof(*gh)) {
LOGP(DMSC, LOGL_ERROR, "There is no GSM48 header here.\n");
return NULL;
}
gh = msgb_l3(msg);
pdisc = gsm48_hdr_pdisc(gh);
mtype = gsm48_hdr_msg_type(gh);
/*
* We are asked to select a MSC here but they are not equal. We
* want to respond to a paging request on the MSC where we got the
* request from. This is where we need to decide where this connection
* will go.
*/
if (pdisc == GSM48_PDISC_RR && mtype == GSM48_MT_RR_PAG_RESP)
goto paging;
else if (pdisc == GSM48_PDISC_MM && mtype == GSM48_MT_MM_CM_SERV_REQ) {
is_emerg = is_cm_service_for_emerg(msg);
goto round_robin;
} else
goto round_robin;
round_robin:
llist_for_each_entry(msc, &bsc->mscs, entry) {
if (!msc->is_authenticated)
continue;
if (!is_emerg && msc->type != MSC_CON_TYPE_NORMAL)
continue;
if (is_emerg && !msc->allow_emerg)
continue;
/* force round robin by moving it to the end */
llist_move_tail(&msc->entry, &bsc->mscs);
return msc;
}
return NULL;
paging:
subscr = extract_sub(conn, msg);
if (!subscr) {
LOGP(DMSC, LOGL_ERROR, "Got paged but no subscriber found.\n");
return NULL;
}
pag_msc = paging_get_msc(conn_get_bts(conn), subscr);
bsc_subscr_put(subscr);
llist_for_each_entry(msc, &bsc->mscs, entry) {
if (msc != pag_msc)
continue;
/*
* We don't check if the MSC is connected. In case it
* is not the connection will be dropped.
*/
/* force round robin by moving it to the end */
llist_move_tail(&msc->entry, &bsc->mscs);
return msc;
}
LOGP(DMSC, LOGL_ERROR, "Got paged but no request found.\n");
return NULL;
}
/*! MS->MSC: New MM context with L3 payload. */
int bsc_compl_l3(struct gsm_subscriber_connection *conn, struct msgb *msg, uint16_t chosen_channel)
{
@ -230,6 +383,61 @@ int bsc_compl_l3(struct gsm_subscriber_connection *conn, struct msgb *msg, uint1
return complete_layer3(conn, msg, msc);
}
static int handle_page_resp(struct gsm_subscriber_connection *conn, struct msgb *msg)
{
struct bsc_subscr *subscr = extract_sub(conn, msg);
if (!subscr) {
LOGP(DMSC, LOGL_ERROR, "Non active subscriber got paged.\n");
return -1;
}
paging_request_stop(&conn->network->bts_list, conn_get_bts(conn), subscr, conn,
msg);
bsc_subscr_put(subscr);
return 0;
}
static void handle_lu_request(struct gsm_subscriber_connection *conn,
struct msgb *msg)
{
struct gsm48_hdr *gh;
struct gsm48_loc_upd_req *lu;
struct gsm48_loc_area_id lai;
if (msgb_l3len(msg) < sizeof(*gh) + sizeof(*lu)) {
LOGP(DMSC, LOGL_ERROR, "LU too small to look at: %u\n", msgb_l3len(msg));
return;
}
gh = msgb_l3(msg);
lu = (struct gsm48_loc_upd_req *) gh->data;
gsm48_generate_lai2(&lai, bts_lai(conn_get_bts(conn)));
if (memcmp(&lai, &lu->lai, sizeof(lai)) != 0) {
LOGP(DMSC, LOGL_DEBUG, "Marking con for welcome USSD.\n");
conn->new_subscriber = 1;
}
}
int bsc_scan_bts_msg(struct gsm_subscriber_connection *conn, struct msgb *msg)
{
struct gsm48_hdr *gh = msgb_l3(msg);
uint8_t pdisc = gsm48_hdr_pdisc(gh);
uint8_t mtype = gsm48_hdr_msg_type(gh);
if (pdisc == GSM48_PDISC_MM) {
if (mtype == GSM48_MT_MM_LOC_UPD_REQUEST)
handle_lu_request(conn, msg);
} else if (pdisc == GSM48_PDISC_RR) {
if (mtype == GSM48_MT_RR_PAG_RESP)
handle_page_resp(conn, msg);
}
return 0;
}
static int complete_layer3(struct gsm_subscriber_connection *conn,
struct msgb *msg, struct bsc_msc_data *msc)
{
@ -274,6 +482,7 @@ static int complete_layer3(struct gsm_subscriber_connection *conn,
} else
conn->bsub = bsc_subscr_find_or_create_by_imsi(msc->network->bsc_subscribers,
imsi);
gscon_update_id(conn);
}
conn->filter_state.con_type = con_type;
@ -311,8 +520,10 @@ static int move_to_msc(struct gsm_subscriber_connection *_conn,
* properly.
*/
if (complete_layer3(_conn, msg, msc) != BSC_API_CONN_POL_ACCEPT) {
gsm0808_clear(_conn);
//bsc_subscr_con_free(_conn);
/* FIXME: I have not the slightest idea what move_to_msc() intends to do; during lchan
* FSM introduction, I changed this and hope it is the appropriate action. I actually
* assume this is unused legacy code for osmo-bsc_nat?? */
gscon_release_lchans(_conn, false);
return 1;
}
@ -411,40 +622,6 @@ void bsc_dtap(struct gsm_subscriber_connection *conn, uint8_t link_id, struct ms
osmo_fsm_inst_dispatch(conn->fi, GSCON_EV_MO_DTAP, msg);
}
/*! BSC->MSC: Assignment of lchan successful. */
void bsc_assign_compl(struct gsm_subscriber_connection *conn, uint8_t rr_cause)
{
if (!msc_connected(conn))
return;
conn->lchan->abis_ip.ass_compl.rr_cause = rr_cause;
if (is_ipaccess_bts(conn_get_bts(conn)) && conn->user_plane.rtp_ip) {
/* NOTE: In a network that makes use of an IPA base station
* and AoIP, we have to wait until the BTS reports its RTP
* IP/Port combination back to BSC via RSL. Unfortunately, the
* IPA protocol sends its Abis assignment complete message
* before it sends its RTP IP/Port via IPACC. So we will now
* postpone the AoIP assignment completed message until we
* know the RTP IP/Port combination. */
LOGP(DMSC, LOGL_INFO, "POSTPONE MSC ASSIGN COMPL\n");
conn->lchan->abis_ip.ass_compl.valid = true;
} else {
/* NOTE: Send the A assignment complete message immediately. */
LOGP(DMSC, LOGL_INFO, "Tx MSC ASSIGN COMPL\n");
osmo_fsm_inst_dispatch(conn->fi, GSCON_EV_RR_ASS_COMPL, NULL);
}
}
/*! BSC->MSC: Assignment of lchan failed. */
void bsc_assign_fail(struct gsm_subscriber_connection *conn, uint8_t cause, uint8_t *rr_cause)
{
LOGPFSML(conn->fi, LOGL_ERROR, "Assignment failure: BSSMAP: '%s' from RR: '%s'\n",
gsm0808_cause_name(cause), rr_cause ? rr_cause_name(*rr_cause) : "(none)");
osmo_fsm_inst_dispatch(conn->fi, GSCON_EV_RR_ASS_FAIL, &cause);
}
/*! BSC->MSC: RR conn has been cleared. */
int bsc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause)
{
@ -485,45 +662,3 @@ void bsc_cm_update(struct gsm_subscriber_connection *conn,
if (rc != 0)
msgb_free(resp);
}
/*! Configure the multirate setting on this channel. */
void bsc_mr_config(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan, int full_rate)
{
struct bsc_msc_data *msc;
struct gsm48_multi_rate_conf *ms_conf, *bts_conf;
if (!conn) {
LOGP(DMSC, LOGL_ERROR,
"No msc data available on conn %p. Audio will be broken.\n",
conn);
return;
}
msc = conn->sccp.msc;
/* initialize the data structure */
lchan->mr_ms_lv[0] = sizeof(*ms_conf);
lchan->mr_bts_lv[0] = sizeof(*bts_conf);
ms_conf = (struct gsm48_multi_rate_conf *) &lchan->mr_ms_lv[1];
bts_conf = (struct gsm48_multi_rate_conf *) &lchan->mr_bts_lv[1];
memset(ms_conf, 0, sizeof(*ms_conf));
memset(bts_conf, 0, sizeof(*bts_conf));
bts_conf->ver = ms_conf->ver = 1;
bts_conf->icmi = ms_conf->icmi = 1;
/* maybe gcc see's it is copy of _one_ byte */
bts_conf->m4_75 = ms_conf->m4_75 = msc->amr_conf.m4_75;
bts_conf->m5_15 = ms_conf->m5_15 = msc->amr_conf.m5_15;
bts_conf->m5_90 = ms_conf->m5_90 = msc->amr_conf.m5_90;
bts_conf->m6_70 = ms_conf->m6_70 = msc->amr_conf.m6_70;
bts_conf->m7_40 = ms_conf->m7_40 = msc->amr_conf.m7_40;
bts_conf->m7_95 = ms_conf->m7_95 = msc->amr_conf.m7_95;
if (full_rate) {
bts_conf->m10_2 = ms_conf->m10_2 = msc->amr_conf.m10_2;
bts_conf->m12_2 = ms_conf->m12_2 = msc->amr_conf.m12_2;
}
/* now copy this into the bts structure */
memcpy(lchan->mr_bts_lv, lchan->mr_ms_lv, sizeof(lchan->mr_ms_lv));
}

View File

@ -1,98 +0,0 @@
/*
* ipaccess audio handling
*
* (C) 2009-2010 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2009-2010 by On-Waves
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <osmocom/bsc/bsc_msc_data.h>
#include <osmocom/bsc/osmo_bsc.h>
#include <osmocom/bsc/abis_rsl.h>
#include <osmocom/bsc/gsm_data.h>
#include <osmocom/bsc/debug.h>
#include <osmocom/bsc/signal.h>
#include <osmocom/gsm/gsm0808.h>
#include <osmocom/gsm/gsm0808_utils.h>
#include <osmocom/bsc/osmo_bsc_sigtran.h>
#include <osmocom/bsc/bsc_subscr_conn_fsm.h>
#include <osmocom/bsc/bsc_subscriber.h>
#include <arpa/inet.h>
static int handle_abisip_signal(unsigned int subsys, unsigned int signal,
void *handler_data, void *signal_data)
{
struct gsm_subscriber_connection *con;
struct gsm_lchan *lchan = signal_data;
int rc;
uint32_t rtp_ip;
if (subsys != SS_ABISIP)
return 0;
con = lchan->conn;
if (!con)
return 0;
switch (signal) {
case S_ABISIP_CRCX_ACK:
/* we can ask it to connect now */
LOGP(DMSC, LOGL_DEBUG, "Connecting BTS to port: %d conn: %d\n",
con->user_plane.rtp_port, lchan->abis_ip.conn_id);
/* If AoIP is in use, the rtp_ip, which has been communicated
* via the A interface as connect_ip */
if(con->user_plane.rtp_ip)
rtp_ip = con->user_plane.rtp_ip;
else
rtp_ip = ntohl(INADDR_ANY);
rc = rsl_ipacc_mdcx(lchan, rtp_ip,
con->user_plane.rtp_port,
lchan->abis_ip.rtp_payload2);
if (rc < 0) {
LOGP(DMSC, LOGL_ERROR, "Failed to send MDCX: %d\n", rc);
return rc;
}
break;
case S_ABISIP_MDCX_ACK:
if (con->ho) {
LOGPHO(con->ho, LOGL_DEBUG, "BTS sent MDCX ACK\n");
/* No need to do anything for handover here. As soon as a HANDOVER DETECT
* happens, handover_logic.c and bsc_subscr_conn_fsm.c will trigger the
* MGCP MDCX towards MGW by receiving an S_LCHAN_HANDOVER_DETECT signal. */
} else if (is_ipaccess_bts(conn_get_bts(con)) && con->user_plane.rtp_ip) {
/* NOTE: This is only relevant on AoIP networks with
* IPA based base stations. See also osmo_bsc_api.c,
* function bsc_assign_compl() */
LOGP(DMSC, LOGL_INFO, "Tx MSC ASSIGN COMPL (POSTPONED)\n");
osmo_fsm_inst_dispatch(con->fi, GSCON_EV_RR_ASS_COMPL, NULL);
}
break;
}
return 0;
}
int osmo_bsc_audio_init(struct gsm_network *net)
{
osmo_signal_register_handler(SS_ABISIP, handle_abisip_signal, net);
return 0;
}

View File

@ -19,6 +19,8 @@
*
*/
#include <osmocom/mgcp_client/mgcp_client_fsm.h>
#include <osmocom/bsc/osmo_bsc.h>
#include <osmocom/bsc/osmo_bsc_grace.h>
#include <osmocom/bsc/osmo_bsc_rf.h>
@ -26,14 +28,20 @@
#include <osmocom/bsc/bsc_subscriber.h>
#include <osmocom/bsc/paging.h>
#include <osmocom/bsc/gsm_04_08_rr.h>
#include <osmocom/bsc/gsm_04_80.h>
#include <osmocom/bsc/bsc_subscr_conn_fsm.h>
#include <osmocom/bsc/codec_pref.h>
#include <osmocom/bsc/abis_rsl.h>
#include <osmocom/bsc/handover_fsm.h>
#include <osmocom/gsm/protocol/gsm_08_08.h>
#include <osmocom/gsm/gsm0808.h>
#include <osmocom/bsc/osmo_bsc_sigtran.h>
#include <osmocom/bsc/osmo_bsc_lcls.h>
#include <osmocom/bsc/a_reset.h>
#include <osmocom/core/byteswap.h>
#include <osmocom/bsc/handover.h>
#include <osmocom/core/fsm.h>
#include <osmocom/core/socket.h>
#define IP_V4_ADDR_LEN 4
@ -553,7 +561,6 @@ static int bssmap_handle_lcls_connect_ctrl(struct gsm_subscriber_connection *con
return 0;
}
/*
* Handle the assignment request message.
*
@ -565,26 +572,24 @@ static int bssmap_handle_assignm_req(struct gsm_subscriber_connection *conn,
struct msgb *resp;
struct bsc_msc_data *msc;
struct tlv_parsed tp;
uint8_t timeslot = 0;
uint8_t multiplex = 0;
uint16_t cic = 0;
enum gsm48_chan_mode chan_mode = GSM48_CMODE_SIGN;
int full_rate = -1;
bool full_rate = false;
bool aoip = false;
struct sockaddr_storage rtp_addr;
struct gsm0808_channel_type ct;
struct gsm0808_speech_codec_list *scl_ptr = NULL;
uint8_t cause;
int rc;
struct assignment_request req = {};
if (!conn) {
LOGP(DMSC, LOGL_ERROR,
"No lchan/msc_data in cipher mode command.\n");
"No lchan/msc_data in Assignment Request\n");
return -1;
}
msc = conn->sccp.msc;
if (msc->a.asp_proto != OSMO_SS7_ASP_PROT_IPA)
aoip = true;
aoip = gscon_is_aoip(conn);
tlv_parse(&tp, gsm0808_att_tlvdef(), msg->l4h + 1, length - 1, 0, 0);
@ -616,10 +621,7 @@ static int bssmap_handle_assignm_req(struct gsm_subscriber_connection *conn,
case GSM0808_CHAN_SPEECH:
if (TLVP_PRESENT(&tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE)) {
/* CIC is permitted in both AoIP and SCCPlite */
conn->user_plane.cic =
osmo_load16be(TLVP_VAL(&tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE));
timeslot = conn->user_plane.cic & 0x1f;
multiplex = (conn->user_plane.cic & ~0x1f) >> 5;
cic = osmo_load16be(TLVP_VAL(&tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE));
} else {
if (!aoip) {
/* no CIC but SCCPlite: illegal */
@ -644,27 +646,18 @@ static int bssmap_handle_assignm_req(struct gsm_subscriber_connection *conn,
cause = GSM0808_CAUSE_INCORRECT_VALUE;
goto reject;
}
} else {
if (aoip) {
/* no AoIP transport level address but AoIP transport: illegal */
LOGP(DMSC, LOGL_ERROR, "AoIP transport address missing in ASSIGN REQ, "
"audio would not work; rejecting\n");
cause = GSM0808_CAUSE_INFORMATION_ELEMENT_OR_FIELD_MISSING;
goto reject;
}
} else if (aoip) {
/* no AoIP transport level address but AoIP transport: illegal */
LOGP(DMSC, LOGL_ERROR, "AoIP transport address missing in ASSIGN REQ, "
"audio would not work; rejecting\n");
cause = GSM0808_CAUSE_INFORMATION_ELEMENT_OR_FIELD_MISSING;
goto reject;
}
/* Decode speech codec list (AoIP) */
conn->codec_list_present = false;
if (aoip) {
/* Check for speech codec list element */
if (!TLVP_PRESENT(&tp, GSM0808_IE_SPEECH_CODEC_LIST)) {
LOGP(DMSC, LOGL_ERROR, "Mandatory speech codec list not present.\n");
cause = GSM0808_CAUSE_INFORMATION_ELEMENT_OR_FIELD_MISSING;
goto reject;
}
/* Decode speech codec list. First set len = 0. */
conn->codec_list = (struct gsm0808_speech_codec_list){};
/* Check for speech codec list element */
if (TLVP_PRESENT(&tp, GSM0808_IE_SPEECH_CODEC_LIST)) {
/* Decode Speech Codec list */
rc = gsm0808_dec_speech_codec_list(&conn->codec_list,
TLVP_VAL(&tp, GSM0808_IE_SPEECH_CODEC_LIST),
@ -674,13 +667,20 @@ static int bssmap_handle_assignm_req(struct gsm_subscriber_connection *conn,
cause = GSM0808_CAUSE_INCORRECT_VALUE;
goto reject;
}
conn->codec_list_present = true;
scl_ptr = &conn->codec_list;
}
if (aoip && !conn->codec_list.len) {
LOGP(DMSC, LOGL_ERROR, "%s: AoIP speech mode Assignment Request:"
" Missing or empty Speech Codec List IE\n", bsc_subscr_name(conn->bsub));
cause = GSM0808_CAUSE_INFORMATION_ELEMENT_OR_FIELD_MISSING;
goto reject;
}
/* Match codec information from the assignment command against the
* local preferences of the BSC */
rc = match_codec_pref(&full_rate, &chan_mode, &ct, scl_ptr, msc, conn_get_bts(conn));
* local preferences of the BSC and BTS */
rc = match_codec_pref(&chan_mode, &full_rate, &ct, &conn->codec_list,
msc->audio_support, msc->audio_length,
&conn_get_bts(conn)->codec);
if (rc < 0) {
LOGP(DMSC, LOGL_ERROR, "No supported audio type found for channel_type ="
" { ch_indctr=0x%x, ch_rate_type=0x%x, perm_spch=[ %s] }\n",
@ -697,37 +697,37 @@ static int bssmap_handle_assignm_req(struct gsm_subscriber_connection *conn,
get_value_string(gsm48_chan_mode_names, chan_mode),
ct.ch_indctr, ct.ch_rate_type, osmo_hexdump(ct.perm_spch, ct.perm_spch_len));
/* Forward the assignment request to lower layers */
req = (struct assignment_request){
.aoip = aoip,
.msc_assigned_cic = cic,
.chan_mode = chan_mode,
.full_rate = full_rate,
};
if (aoip) {
/* Store network side RTP connection information, we will
* process this address later after we have established an RTP
* connection to the BTS. This is just for organizational
* reasons, functional wise it would not matter when exactly
* the network side RTP connection is made, as long it is made
* before we return with the assignment complete message. */
memcpy(&conn->user_plane.aoip_rtp_addr_remote, &rtp_addr, sizeof(rtp_addr));
} else {
/* Note: In the sccp-lite case we to not perform any mgcp operation,
* (the MSC does that for us). We set conn->rtp_ip to 0 and check
* on this later. By this we know that we have to behave accordingly
* to sccp-lite. */
conn->user_plane.rtp_port = mgcp_timeslot_to_port(multiplex, timeslot, msc->rtp_base);
conn->user_plane.rtp_ip = 0;
unsigned int rc = osmo_sockaddr_to_str_and_uint(req.msc_rtp_addr,
sizeof(req.msc_rtp_addr),
&req.msc_rtp_port,
(const struct sockaddr*)&rtp_addr);
if (!rc || rc >= sizeof(req.msc_rtp_addr)) {
LOGP(DMSC, LOGL_ERROR, "Assignment request: RTP address is too long\n");
cause = GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL;
goto reject;
}
}
conn->user_plane.chan_mode = chan_mode;
conn->user_plane.full_rate = full_rate;
osmo_fsm_inst_dispatch(conn->fi, GSCON_EV_A_ASSIGNMENT_CMD, NULL);
break;
case GSM0808_CHAN_SIGN:
conn->user_plane.chan_mode = GSM48_CMODE_SIGN;
osmo_fsm_inst_dispatch(conn->fi, GSCON_EV_A_ASSIGNMENT_CMD, NULL);
req = (struct assignment_request){
.aoip = aoip,
.chan_mode = chan_mode,
};
break;
default:
cause = GSM0808_CAUSE_INVALID_MESSAGE_CONTENTS;
goto reject;
}
return 0;
return osmo_fsm_inst_dispatch(conn->fi, GSCON_EV_ASSIGNMENT_START, &req);
reject:
resp = gsm0808_create_assignment_failure(cause, NULL);
OSMO_ASSERT(resp);
@ -736,6 +736,51 @@ reject:
return -1;
}
/* Handle Handover Command message, part of inter-BSC handover:
* This BSS sent a Handover Required message.
* The MSC contacts the remote BSS and receives from it an RR Handover Command; this BSSMAP Handover
* Command passes the RR Handover Command over to us and it's our job to forward to the MS.
*
* See 3GPP TS 48.008 §3.2.1.11
*/
static int bssmap_handle_handover_cmd(struct gsm_subscriber_connection *conn,
struct msgb *msg, unsigned int length)
{
struct tlv_parsed tp;
if (!conn->ho.fi) {
LOGPFSML(conn->fi, LOGL_ERROR,
"Received Handover Command, but no handover was requested\n");
/* Should we actually allow the MSC to make us handover without us having requested it
* first? Doesn't make any practical sense AFAICT. */
return -EINVAL;
}
tlv_parse(&tp, gsm0808_att_tlvdef(), msg->l4h + 1, length - 1, 0, 0);
/* Check for channel type element, if its missing, immediately reject */
if (!TLVP_PRESENT(&tp, GSM0808_IE_LAYER_3_INFORMATION)) {
LOGPFSML(conn->fi, LOGL_ERROR,
"Received Handover Command,"
" but mandatory IE not present: Layer 3 Information\n");
goto reject;
}
/* Due to constness, need to declare this after tlv_parse(). */
struct ho_out_rx_bssmap_ho_command rx = {
.l3_info = TLVP_VAL(&tp, GSM0808_IE_LAYER_3_INFORMATION),
.l3_info_len = TLVP_LEN(&tp, GSM0808_IE_LAYER_3_INFORMATION),
};
osmo_fsm_inst_dispatch(conn->ho.fi, HO_OUT_EV_BSSMAP_HO_COMMAND, &rx);
return 0;
reject:
/* No "Handover Command Reject" message or similar is specified, so we cannot reply in case of
* failure. Or is there?? */
handover_end(conn, HO_RESULT_ERROR);
return -EINVAL;
}
static int bssmap_rcvmsg_udt(struct bsc_msc_data *msc,
struct msgb *msg, unsigned int length)
{
@ -794,6 +839,9 @@ static int bssmap_rcvmsg_dt1(struct gsm_subscriber_connection *conn,
case BSS_MAP_MSG_LCLS_CONNECT_CTRL:
ret = bssmap_handle_lcls_connect_ctrl(conn, msg, length);
break;
case BSS_MAP_MSG_HANDOVER_CMD:
ret = bssmap_handle_handover_cmd(conn, msg, length);
break;
default:
LOGP(DMSC, LOGL_NOTICE, "Unimplemented msg type: %s\n",
gsm0808_bssmap_name(msg->l4h[0]));
@ -803,6 +851,14 @@ static int bssmap_rcvmsg_dt1(struct gsm_subscriber_connection *conn,
return ret;
}
int bsc_send_welcome_ussd(struct gsm_subscriber_connection *conn)
{
bsc_send_ussd_notify(conn, 1, conn->sccp.msc->ussd_welcome_txt);
bsc_send_ussd_release_complete(conn);
return 0;
}
static int dtap_rcvmsg(struct gsm_subscriber_connection *conn,
struct msgb *msg, unsigned int length)
{
@ -907,3 +963,137 @@ int bsc_handle_dt(struct gsm_subscriber_connection *conn,
return -1;
}
int bsc_tx_bssmap_ho_required(struct gsm_lchan *lchan, const struct gsm0808_cell_id_list2 *target_cells)
{
int rc;
struct msgb *msg;
struct gsm0808_handover_required params = {
.cause = GSM0808_CAUSE_BETTER_CELL,
.cil = *target_cells,
.current_channel_type_1_present = true,
.current_channel_type_1 = gsm0808_current_channel_type_1(lchan->type),
};
switch (lchan->type) {
case GSM_LCHAN_TCH_F:
case GSM_LCHAN_TCH_H:
params.speech_version_used_present = true;
params.speech_version_used = gsm0808_permitted_speech(lchan->type,
lchan->tch_mode);
if (!params.speech_version_used) {
LOG_HO(lchan->conn, LOGL_ERROR, "Cannot encode Speech Version (Used)"
" for BSSMAP Handover Required message\n");
return -EINVAL;
}
break;
default:
break;
}
msg = gsm0808_create_handover_required(&params);
if (!msg) {
LOG_HO(lchan->conn, LOGL_ERROR, "Cannot compose BSSMAP Handover Required message\n");
return -EINVAL;
}
rc = gscon_sigtran_send(lchan->conn, msg);
if (rc) {
LOG_HO(lchan->conn, LOGL_ERROR, "Cannot send BSSMAP Handover Required message\n");
return rc;
}
return 0;
}
/* Inter-BSC MT HO, new BSS has allocated a channel and sends the RR Handover Command via MSC to the old
* BSS, encapsulated in a BSSMAP Handover Request Acknowledge. */
int bsc_tx_bssmap_ho_request_ack(struct gsm_subscriber_connection *conn, struct msgb *rr_ho_command)
{
struct msgb *msg;
struct gsm_lchan *new_lchan = conn->ho.new_lchan;
msg = gsm0808_create_handover_request_ack(rr_ho_command->data, rr_ho_command->len,
gsm0808_chosen_channel(new_lchan->type,
new_lchan->tch_mode),
new_lchan->encr.alg_id,
gsm0808_permitted_speech(new_lchan->type,
new_lchan->tch_mode));
msgb_free(rr_ho_command);
if (!msg)
return -ENOMEM;
return osmo_bsc_sigtran_send(conn, msg);
}
int bsc_tx_bssmap_ho_detect(struct gsm_subscriber_connection *conn)
{
struct msgb *msg;
msg = gsm0808_create_handover_detect();
if (!msg)
return -ENOMEM;
return osmo_bsc_sigtran_send(conn, msg);
}
enum handover_result bsc_tx_bssmap_ho_complete(struct gsm_subscriber_connection *conn,
struct gsm_lchan *lchan)
{
int rc;
struct msgb *msg;
struct handover *ho = &conn->ho;
enum gsm0808_lcls_status lcls_status = lcls_get_status(conn);
struct gsm0808_handover_complete params = {
.chosen_encr_alg_present = true,
.chosen_encr_alg = lchan->encr.alg_id,
.chosen_channel_present = true,
.chosen_channel = gsm0808_chosen_channel(lchan->type, lchan->tch_mode),
.lcls_bss_status_present = (lcls_status != 0xff),
.lcls_bss_status = lcls_status,
};
/* speech_codec_chosen */
if (ho->new_lchan->activate.requires_voice_stream && gscon_is_aoip(conn)) {
int perm_spch = gsm0808_permitted_speech(lchan->type, lchan->tch_mode);
params.speech_codec_chosen_present = true;
rc = gsm0808_speech_codec_from_chan_type(&params.speech_codec_chosen, perm_spch);
if (rc) {
LOG_HO(conn, LOGL_ERROR, "Unable to compose Speech Codec (Chosen)\n");
return HO_RESULT_ERROR;
}
}
msg = gsm0808_create_handover_complete(&params);
if (!msg) {
LOG_HO(conn, LOGL_ERROR, "Unable to compose BSSMAP Handover Complete message\n");
return HO_RESULT_ERROR;
}
rc = gscon_sigtran_send(conn, msg);
if (rc) {
LOG_HO(conn, LOGL_ERROR, "Cannot send BSSMAP Handover Complete message\n");
return HO_RESULT_ERROR;
}
return HO_RESULT_OK;
}
void bsc_tx_bssmap_ho_failure(struct gsm_subscriber_connection *conn)
{
int rc;
struct msgb *msg;
struct gsm0808_handover_failure params = {};
msg = gsm0808_create_handover_failure(&params);
if (!msg) {
LOG_HO(conn, LOGL_ERROR, "Unable to compose BSSMAP Handover Failure message\n");
return;
}
rc = gscon_sigtran_send(conn, msg);
if (rc)
LOG_HO(conn, LOGL_ERROR, "Cannot send BSSMAP Handover Failure message (rc=%d %s)\n",
rc, strerror(-rc));
}

View File

@ -676,7 +676,7 @@ static int set_net_ussd_notify(struct ctrl_cmd *cmd, void *data)
net = cmd->node;
llist_for_each_entry(conn, &net->subscr_conns, entry) {
if (conn->user_plane.cic != cic)
if (conn->user_plane.msc_assigned_cic != cic)
continue;
/*

View File

@ -30,203 +30,6 @@
#include <stdlib.h>
static void handle_lu_request(struct gsm_subscriber_connection *conn,
struct msgb *msg)
{
struct gsm48_hdr *gh;
struct gsm48_loc_upd_req *lu;
struct gsm48_loc_area_id lai;
if (msgb_l3len(msg) < sizeof(*gh) + sizeof(*lu)) {
LOGP(DMSC, LOGL_ERROR, "LU too small to look at: %u\n", msgb_l3len(msg));
return;
}
gh = msgb_l3(msg);
lu = (struct gsm48_loc_upd_req *) gh->data;
gsm48_generate_lai2(&lai, bts_lai(conn_get_bts(conn)));
if (memcmp(&lai, &lu->lai, sizeof(lai)) != 0) {
LOGP(DMSC, LOGL_DEBUG, "Marking con for welcome USSD.\n");
conn->new_subscriber = 1;
}
}
/* extract a subscriber from the paging response */
static struct bsc_subscr *extract_sub(struct gsm_subscriber_connection *conn,
struct msgb *msg)
{
uint8_t mi_type;
char mi_string[GSM48_MI_SIZE];
struct gsm48_hdr *gh;
struct gsm48_pag_resp *resp;
struct bsc_subscr *subscr;
if (msgb_l3len(msg) < sizeof(*gh) + sizeof(*resp)) {
LOGP(DMSC, LOGL_ERROR, "PagingResponse too small: %u\n", msgb_l3len(msg));
return NULL;
}
gh = msgb_l3(msg);
resp = (struct gsm48_pag_resp *) &gh->data[0];
gsm48_paging_extract_mi(resp, msgb_l3len(msg) - sizeof(*gh),
mi_string, &mi_type);
DEBUGP(DRR, "PAGING RESPONSE: MI(%s)=%s\n",
gsm48_mi_type_name(mi_type), mi_string);
switch (mi_type) {
case GSM_MI_TYPE_TMSI:
subscr = bsc_subscr_find_by_tmsi(conn->network->bsc_subscribers,
tmsi_from_string(mi_string));
break;
case GSM_MI_TYPE_IMSI:
subscr = bsc_subscr_find_by_imsi(conn->network->bsc_subscribers,
mi_string);
break;
default:
subscr = NULL;
break;
}
return subscr;
}
/* we will need to stop the paging request */
static int handle_page_resp(struct gsm_subscriber_connection *conn, struct msgb *msg)
{
struct bsc_subscr *subscr = extract_sub(conn, msg);
if (!subscr) {
LOGP(DMSC, LOGL_ERROR, "Non active subscriber got paged.\n");
return -1;
}
paging_request_stop(&conn->network->bts_list, conn_get_bts(conn), subscr, conn,
msg);
bsc_subscr_put(subscr);
return 0;
}
static int is_cm_service_for_emerg(struct msgb *msg)
{
struct gsm48_service_request *cm;
struct gsm48_hdr *gh = msgb_l3(msg);
if (msgb_l3len(msg) < sizeof(*gh) + sizeof(*cm)) {
LOGP(DMSC, LOGL_ERROR, "CM ServiceRequest does not fit.\n");
return 0;
}
cm = (struct gsm48_service_request *) &gh->data[0];
return cm->cm_service_type == GSM48_CMSERV_EMERGENCY;
}
struct bsc_msc_data *bsc_find_msc(struct gsm_subscriber_connection *conn,
struct msgb *msg)
{
struct gsm48_hdr *gh;
int8_t pdisc;
uint8_t mtype;
struct osmo_bsc_data *bsc;
struct bsc_msc_data *msc, *pag_msc;
struct bsc_subscr *subscr;
int is_emerg = 0;
bsc = conn->network->bsc_data;
if (msgb_l3len(msg) < sizeof(*gh)) {
LOGP(DMSC, LOGL_ERROR, "There is no GSM48 header here.\n");
return NULL;
}
gh = msgb_l3(msg);
pdisc = gsm48_hdr_pdisc(gh);
mtype = gsm48_hdr_msg_type(gh);
/*
* We are asked to select a MSC here but they are not equal. We
* want to respond to a paging request on the MSC where we got the
* request from. This is where we need to decide where this connection
* will go.
*/
if (pdisc == GSM48_PDISC_RR && mtype == GSM48_MT_RR_PAG_RESP)
goto paging;
else if (pdisc == GSM48_PDISC_MM && mtype == GSM48_MT_MM_CM_SERV_REQ) {
is_emerg = is_cm_service_for_emerg(msg);
goto round_robin;
} else
goto round_robin;
round_robin:
llist_for_each_entry(msc, &bsc->mscs, entry) {
if (!msc->is_authenticated)
continue;
if (!is_emerg && msc->type != MSC_CON_TYPE_NORMAL)
continue;
if (is_emerg && !msc->allow_emerg)
continue;
/* force round robin by moving it to the end */
llist_move_tail(&msc->entry, &bsc->mscs);
return msc;
}
return NULL;
paging:
subscr = extract_sub(conn, msg);
if (!subscr) {
LOGP(DMSC, LOGL_ERROR, "Got paged but no subscriber found.\n");
return NULL;
}
pag_msc = paging_get_msc(conn_get_bts(conn), subscr);
bsc_subscr_put(subscr);
llist_for_each_entry(msc, &bsc->mscs, entry) {
if (msc != pag_msc)
continue;
/*
* We don't check if the MSC is connected. In case it
* is not the connection will be dropped.
*/
/* force round robin by moving it to the end */
llist_move_tail(&msc->entry, &bsc->mscs);
return msc;
}
LOGP(DMSC, LOGL_ERROR, "Got paged but no request found.\n");
return NULL;
}
/**
* This is used to scan a message for extra functionality of the BSC. This
* includes scanning for location updating requests/acceptd and then send
* a welcome USSD message to the subscriber.
*/
int bsc_scan_bts_msg(struct gsm_subscriber_connection *conn, struct msgb *msg)
{
struct gsm48_hdr *gh = msgb_l3(msg);
uint8_t pdisc = gsm48_hdr_pdisc(gh);
uint8_t mtype = gsm48_hdr_msg_type(gh);
if (pdisc == GSM48_PDISC_MM) {
if (mtype == GSM48_MT_MM_LOC_UPD_REQUEST)
handle_lu_request(conn, msg);
} else if (pdisc == GSM48_PDISC_RR) {
if (mtype == GSM48_MT_RR_PAG_RESP)
handle_page_resp(conn, msg);
}
return 0;
}
static int send_welcome_ussd(struct gsm_subscriber_connection *conn)
{
if (!conn->sccp.msc->ussd_welcome_txt) {
@ -237,14 +40,6 @@ static int send_welcome_ussd(struct gsm_subscriber_connection *conn)
return BSS_SEND_USSD;
}
int bsc_send_welcome_ussd(struct gsm_subscriber_connection *conn)
{
bsc_send_ussd_notify(conn, 1, conn->sccp.msc->ussd_welcome_txt);
bsc_send_ussd_release_complete(conn);
return 0;
}
static int bsc_patch_mm_info(struct gsm_subscriber_connection *conn,
uint8_t *data, unsigned int length)
{

View File

@ -25,6 +25,7 @@
#include <osmocom/bsc/bsc_subscriber.h>
#include <osmocom/bsc/paging.h>
#include <osmocom/bsc/signal.h>
#include <osmocom/bsc/lchan_fsm.h>
int bsc_grace_allow_new_connection(struct gsm_network *network, struct gsm_bts *bts)
{
@ -89,7 +90,7 @@ static int handle_sub(struct gsm_lchan *lchan, const char *text)
return -1;
/* only when active */
if (lchan->state != LCHAN_S_ACTIVE)
if (lchan->fi->state != LCHAN_ST_ESTABLISHED)
return -1;
bsc_send_ussd_notify(conn, 0, text);

View File

@ -28,6 +28,7 @@
#include <osmocom/bsc/bsc_subscr_conn_fsm.h>
#include <osmocom/bsc/gsm_data.h>
#include <osmocom/bsc/osmo_bsc_lcls.h>
#include <osmocom/bsc/mgw_endpoint_fsm.h>
#include <osmocom/mgcp_client/mgcp_client_fsm.h>
struct value_string lcls_event_names[] = {
@ -228,24 +229,24 @@ void lcls_apply_config(struct gsm_subscriber_connection *conn)
static void lcls_break_local_switching(struct gsm_subscriber_connection *conn)
{
struct mgcp_conn_peer peer;
struct sockaddr_in *sin;
struct mgcp_conn_peer mdcx_info;
LOGPFSM(conn->lcls.fi, "=== HERE IS WHERE WE DISABLE LCLS\n");
if (!conn->user_plane.fi_msc) {
if (!conn->user_plane.mgw_endpoint_ci_msc) {
/* the MGCP FSM has died, e.g. due to some MGCP/SDP parsing error */
LOGPFSML(conn->lcls.fi, LOGL_NOTICE, "Cannot disable LCLS without MSC-side MGCP FSM\n");
return;
}
sin = (struct sockaddr_in *)&conn->user_plane.aoip_rtp_addr_remote;
OSMO_ASSERT(sin->sin_family == AF_INET);
mdcx_info = (struct mgcp_conn_peer){
.port = conn->user_plane.msc_assigned_rtp_port,
};
osmo_strlcpy(mdcx_info.addr, conn->user_plane.msc_assigned_rtp_addr, sizeof(mdcx_info.addr));
mgcp_pick_codec(&mdcx_info, conn->lchan);
memset(&peer, 0, sizeof(peer));
peer.port = htons(sin->sin_port);
osmo_strlcpy(peer.addr, inet_ntoa(sin->sin_addr), sizeof(peer.addr));
bsc_subscr_pick_codec(&peer, conn);
mgcp_conn_modify(conn->user_plane.fi_msc, 0, &peer);
mgw_endpoint_ci_request(conn->user_plane.mgw_endpoint_ci_msc,
MGCP_VERB_MDCX, &mdcx_info,
NULL, 0, 0, NULL);
}
static bool lcls_enable_possible(struct gsm_subscriber_connection *conn)
@ -547,26 +548,35 @@ static void lcls_locally_switched_onenter(struct osmo_fsm_inst *fi, uint32_t pre
{
struct gsm_subscriber_connection *conn = fi->priv;
struct gsm_subscriber_connection *conn_other = conn->lcls.other;
struct mgcp_conn_peer peer;
struct sockaddr_in *sin;
const struct mgcp_conn_peer *other_mgw_info;
struct mgcp_conn_peer mdcx_info;
OSMO_ASSERT(conn_other);
LOGPFSM(fi, "=== HERE IS WHERE WE ENABLE LCLS\n");
if (!conn->user_plane.fi_msc) {
if (!conn->user_plane.mgw_endpoint_ci_msc) {
LOGPFSML(fi, LOGL_ERROR, "Cannot enable LCLS without MSC-side MGCP FSM. FIXME\n");
return;
}
if (!conn_other->user_plane.mgw_endpoint_ci_msc) {
LOGPFSML(fi, LOGL_ERROR, "Cannot enable LCLS without MSC-side MGCP FSM. FIXME\n");
return;
}
sin = (struct sockaddr_in *)&conn_other->user_plane.aoip_rtp_addr_local;
OSMO_ASSERT(sin->sin_family == AF_INET);
memset(&peer, 0, sizeof(peer));
peer.port = htons(sin->sin_port);
osmo_strlcpy(peer.addr, inet_ntoa(sin->sin_addr), sizeof(peer.addr));
bsc_subscr_pick_codec(&peer, conn);
mgcp_conn_modify(conn->user_plane.fi_msc, 0, &peer);
other_mgw_info = mgwep_ci_get_rtp_info(conn_other->user_plane.mgw_endpoint_ci_msc);
if (!other_mgw_info) {
LOGPFSML(fi, LOGL_ERROR, "Cannot enable LCLS without RTP port info of MSC-side"
" -- missing CRCX?\n");
return;
}
mdcx_info = *other_mgw_info;
/* Make sure the request doesn't want to use the other side's endpoint string. */
mdcx_info.endpoint[0] = 0;
mgcp_pick_codec(&mdcx_info, conn->lchan);
mgw_endpoint_ci_request(conn->user_plane.mgw_endpoint_ci_msc,
MGCP_VERB_MDCX, &mdcx_info,
NULL, 0, 0, NULL);
}
static void lcls_locally_switched_wait_break_fn(struct osmo_fsm_inst *fi, uint32_t event, void *data)
@ -766,3 +776,35 @@ struct osmo_fsm lcls_fsm = {
.log_subsys = DLCLS,
.event_names = lcls_event_names,
};
/* Add the LCLS BSS Status IE to a BSSMAP message. We assume this is
* called on a msgb that was returned by gsm0808_create_ass_compl() */
static void bssmap_add_lcls_status(struct msgb *msg, enum gsm0808_lcls_status status)
{
OSMO_ASSERT(msg->l3h[0] == BSSAP_MSG_BSS_MANAGEMENT);
OSMO_ASSERT(msg->l3h[2] == BSS_MAP_MSG_ASSIGMENT_COMPLETE ||
msg->l3h[2] == BSS_MAP_MSG_HANDOVER_RQST_ACKNOWLEDGE ||
msg->l3h[2] == BSS_MAP_MSG_HANDOVER_COMPLETE ||
msg->l3h[2] == BSS_MAP_MSG_HANDOVER_PERFORMED);
OSMO_ASSERT(msgb_tailroom(msg) >= 2);
/* append IE to end of message */
msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, status);
/* increment the "length" byte in the BSSAP header */
msg->l3h[1] += 2;
}
/* Add (append) the LCLS BSS Status IE to a BSSMAP message, if there is any LCLS
* active on the given \a conn */
void bssmap_add_lcls_status_if_needed(struct gsm_subscriber_connection *conn, struct msgb *msg)
{
enum gsm0808_lcls_status status = lcls_get_status(conn);
if (status != 0xff) {
LOGPFSM(conn->fi, "Adding LCLS BSS-Status (%s) to %s\n",
gsm0808_lcls_status_name(status),
gsm0808_bssmap_name(msg->l3h[2]));
bssmap_add_lcls_status(msg, status);
}
}

View File

@ -31,6 +31,12 @@
#include <osmocom/bsc/osmo_bsc_sigtran.h>
#include <osmocom/bsc/handover_decision.h>
#include <osmocom/bsc/handover_decision_2.h>
#include <osmocom/bsc/timeslot_fsm.h>
#include <osmocom/bsc/lchan_fsm.h>
#include <osmocom/bsc/mgw_endpoint_fsm.h>
#include <osmocom/bsc/bsc_subscr_conn_fsm.h>
#include <osmocom/bsc/assignment_fsm.h>
#include <osmocom/bsc/handover_fsm.h>
#include <osmocom/ctrl/control_cmd.h>
#include <osmocom/ctrl/control_if.h>
@ -298,7 +304,8 @@ static void bootstrap_rsl(struct gsm_bts_trx *trx)
for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
struct gsm_bts_trx_ts *ts = &trx->ts[i];
generate_ma_for_ts(ts);
gsm_ts_check_init(ts);
OSMO_ASSERT(ts->fi);
osmo_fsm_inst_dispatch(ts->fi, TS_EV_RSL_READY, NULL);
}
}
@ -308,7 +315,7 @@ static int inp_sig_cb(unsigned int subsys, unsigned int signal,
{
struct input_signal_data *isd = signal_data;
struct gsm_bts_trx *trx = isd->trx;
int ts_no, lchan_no;
int ts_no;
/* N. B: we rely on attribute order when parsing response in abis_nm_rx_get_attr_resp() */
const uint8_t bts_attr[] = { NM_ATT_MANUF_ID, NM_ATT_SW_CONFIG, };
const uint8_t trx_attr[] = { NM_ATT_MANUF_STATE, NM_ATT_SW_CONFIG, };
@ -367,12 +374,8 @@ static int inp_sig_cb(unsigned int subsys, unsigned int signal,
*/
for (ts_no = 0; ts_no < ARRAY_SIZE(trx->ts); ++ts_no) {
struct gsm_bts_trx_ts *ts = &trx->ts[ts_no];
for (lchan_no = 0; lchan_no < ARRAY_SIZE(ts->lchan); ++lchan_no) {
if (ts->lchan[lchan_no].state != LCHAN_S_NONE)
lchan_free(&ts->lchan[lchan_no]);
lchan_reset(&ts->lchan[lchan_no]);
}
if (ts->fi)
osmo_fsm_inst_dispatch(ts->fi, TS_EV_OML_DOWN, 0);
}
gsm_bts_mo_reset(trx->bts);
@ -436,11 +439,9 @@ static int bootstrap_bts(struct gsm_bts *bts)
/* Control Channel Description is set from vty/config */
/* T3212 is set from vty/config */
/* Set ccch config by looking at ts config */
for (n=0, i=0; i<8; i++)
n += bts->c0->ts[i].pchan == GSM_PCHAN_CCCH ? 1 : 0;
n += bts->c0->ts[i].pchan_is == GSM_PCHAN_CCCH ? 1 : 0;
/* Indicate R99 MSC in SI3 */
bts->si_common.chan_desc.mscr = 1;
@ -821,6 +822,13 @@ int main(int argc, char **argv)
/* seed the PRNG */
srand(time(NULL));
ts_fsm_init();
lchan_fsm_init();
bsc_subscr_conn_fsm_init();
assignment_fsm_init();
mgw_endpoint_fsm_init(bsc_gsmnet->T_defs);
handover_fsm_init();
/* Read the config */
rc = bsc_network_configure(config_file);
if (rc < 0) {
@ -875,11 +883,6 @@ int main(int argc, char **argv)
exit(1);
}
if (osmo_bsc_audio_init(bsc_gsmnet) != 0) {
LOGP(DMSC, LOGL_ERROR, "Failed to register audio support.\n");
exit(1);
}
handover_decision_1_init();
hodec2_init(bsc_gsmnet);

View File

@ -153,6 +153,47 @@ static int handle_unitdata_from_msc(const struct osmo_sccp_addr *msc_addr, struc
return rc;
}
static int handle_n_connect_from_msc(struct osmo_sccp_user *scu, struct osmo_scu_prim *scu_prim)
{
struct bsc_msc_data *msc = get_msc_by_addr(&scu_prim->u.connect.calling_addr);
struct gsm_subscriber_connection *conn;
int rc = 0;
conn = get_bsc_conn_by_conn_id(scu_prim->u.connect.conn_id);
if (conn) {
LOGP(DMSC, LOGL_NOTICE,
"(calling_addr=%s conn_id=%u) N-CONNECT.ind with already used conn_id, ignoring\n",
osmo_sccp_addr_dump(&scu_prim->u.connect.calling_addr),
scu_prim->u.connect.conn_id);
/* The situation is illogical. A conn was already established with this conn id, if we
* would like to reply with a disconn onto this conn id, we would close the existing
* conn. So just ignore this impossible N-CONNECT completely (including the BSSMAP PDU). */
return -EINVAL;
}
if (!msc) {
LOGP(DMSC, LOGL_NOTICE, "(calling_addr=%s conn_id=%u) N-CONNECT.ind from unknown MSC\n",
osmo_sccp_addr_dump(&scu_prim->u.connect.calling_addr),
scu_prim->u.connect.conn_id);
rc = -ENOENT;
goto refuse;
}
conn = bsc_subscr_con_allocate(bsc_gsmnet);
if (!conn)
return -ENOMEM;
conn->sccp.msc = msc;
conn->sccp.conn_id = scu_prim->u.connect.conn_id;
/* Take actions asked for by the enclosed PDU */
osmo_fsm_inst_dispatch(conn->fi, GSCON_EV_A_CONN_IND, scu_prim);
return 0;
refuse:
osmo_sccp_tx_disconn(scu, scu_prim->u.connect.conn_id, &scu_prim->u.connect.called_addr, 0);
return rc;
}
/* Callback function, called by the SSCP stack when data arrives */
static int sccp_sap_up(struct osmo_prim_hdr *oph, void *_scu)
{
@ -171,13 +212,7 @@ static int sccp_sap_up(struct osmo_prim_hdr *oph, void *_scu)
case OSMO_PRIM(OSMO_SCU_PRIM_N_CONNECT, PRIM_OP_INDICATION):
/* Handle inbound connections */
DEBUGP(DMSC, "N-CONNECT.ind(X->%u)\n", scu_prim->u.connect.conn_id);
conn = bsc_subscr_con_allocate(bsc_gsmnet);
if (conn) {
conn->sccp.msc = get_msc_by_addr(&scu_prim->u.connect.calling_addr);
/* MSC may be NULL, let the FSM deal with it */
osmo_fsm_inst_dispatch(conn->fi, GSCON_EV_A_CONN_IND, scu_prim);
} else
LOGP(DMSC, LOGL_ERROR, "Unable to alloc subscr_conn for inbound N-CONNECT.ind\n");
rc = handle_n_connect_from_msc(scu, scu_prim);
break;
case OSMO_PRIM(OSMO_SCU_PRIM_N_CONNECT, PRIM_OP_CONFIRM):
@ -191,7 +226,7 @@ static int sccp_sap_up(struct osmo_prim_hdr *oph, void *_scu)
if (msgb_l2len(oph->msg) > 0)
handle_data_from_msc(conn, oph->msg);
} else {
LOGP(DMSC, LOGL_ERROR, "N-CONNET.cfm(%u, %s) for unknown conn?!?\n",
LOGP(DMSC, LOGL_ERROR, "N-CONNECT.cfm(%u, %s) for unknown conn?!?\n",
scu_prim->u.connect.conn_id, osmo_hexdump(msgb_l2(oph->msg),
msgb_l2len(oph->msg)));
}

View File

@ -52,6 +52,7 @@
#include <osmocom/bsc/bsc_api.h>
#include <osmocom/bsc/gsm_04_08_rr.h>
#include <osmocom/bsc/gsm_timers.h>
#include <osmocom/bsc/bsc_subscr_conn_fsm.h>
void *tall_paging_ctx = NULL;
@ -394,6 +395,7 @@ void paging_request_stop(struct llist_head *bts_list,
log_set_context(LOG_CTX_BSC_SUBSCR, bsub);
conn->bsub = bsc_subscr_get(bsub);
gscon_update_id(conn);
/* Stop this first and dispatch the request */
if (_bts) {

View File

@ -94,33 +94,6 @@ struct msgb *pcu_msgb_alloc(uint8_t msg_type, uint8_t bts_nr)
return msg;
}
/* Helper function exclusivly used by pcu_if_signal_cb() */
static bool ts_should_be_pdch(struct gsm_bts_trx_ts *ts) {
if (ts->pchan == GSM_PCHAN_PDCH)
return true;
if (ts->pchan == GSM_PCHAN_TCH_F_PDCH) {
/* When we're busy deactivating the PDCH, we first set
* DEACT_PENDING, tell the PCU about it and wait for a
* response. So DEACT_PENDING means "no PDCH" to the PCU.
* Similarly, when we're activating PDCH, we set the
* ACT_PENDING and wait for an activation response from the
* PCU, so ACT_PENDING means "is PDCH". */
if (ts->flags & TS_F_PDCH_ACTIVE)
return !(ts->flags & TS_F_PDCH_DEACT_PENDING);
else
return (ts->flags & TS_F_PDCH_ACT_PENDING);
}
if (ts->pchan == GSM_PCHAN_TCH_F_TCH_H_PDCH) {
/*
* When we're busy de-/activating the PDCH, we first set
* ts->dyn.pchan_want, tell the PCU about it and wait for a
* response. So only care about dyn.pchan_want here.
*/
return ts->dyn.pchan_want == GSM_PCHAN_PDCH;
}
return false;
}
/* Send BTS properties to the PCU */
static int pcu_tx_info_ind(struct gsm_bts *bts)
{
@ -232,7 +205,7 @@ static int pcu_tx_info_ind(struct gsm_bts *bts)
for (j = 0; j < ARRAY_SIZE(trx->ts); j++) {
ts = &trx->ts[j];
if (ts->mo.nm_state.operational == NM_OPSTATE_ENABLED
&& ts_should_be_pdch(ts)) {
&& ts->pchan_is == GSM_PCHAN_PDCH) {
info_ind->trx[i].pdch_mask |= (1 << j);
info_ind->trx[i].tsc[j] =
(ts->tsc >= 0) ? ts->tsc : bts->bsic & 7;
@ -521,7 +494,7 @@ static void pcu_sock_close(struct pcu_sock_state *state)
for (j = 0; j < 8; j++) {
ts = &trx->ts[j];
if (ts->mo.nm_state.operational == NM_OPSTATE_ENABLED
&& ts->pchan == GSM_PCHAN_PDCH) {
&& ts->pchan_is == GSM_PCHAN_PDCH) {
printf("l1sap_chan_rel(trx,gsm_lchan2chan_nr(ts->lchan));\n");
}
}

View File

@ -1224,6 +1224,7 @@ static const gen_si_fn_t gen_si_fn[_MAX_SYSINFO_TYPE] = {
int gsm_generate_si(struct gsm_bts *bts, enum osmo_sysinfo_type si_type)
{
int rc;
gen_si_fn_t gen_si;
switch (bts->gprs.mode) {
@ -1244,8 +1245,15 @@ int gsm_generate_si(struct gsm_bts *bts, enum osmo_sysinfo_type si_type)
sizeof(struct gsm48_si_selection_params));
gen_si = gen_si_fn[si_type];
if (!gen_si)
if (!gen_si) {
LOGP(DRR, LOGL_ERROR, "bts %u: no gen_si_fn() for SI%s\n",
bts->nr, get_value_string(osmo_sitype_strs, si_type));
return -EINVAL;
}
return gen_si(si_type, bts);
rc = gen_si(si_type, bts);
if (rc < 0)
LOGP(DRR, LOGL_ERROR, "bts %u: Error while generating SI%s: %s (%d)\n",
bts->nr, get_value_string(osmo_sitype_strs, si_type), strerror(-rc), rc);
return rc;
}

913
src/osmo-bsc/timeslot_fsm.c Normal file
View File

@ -0,0 +1,913 @@
/* osmo-bsc API to manage timeslot status: init and switch of dynamic PDCH.
*
* (C) 2017 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
* All Rights Reserved
*
* Author: Neels Hofmeyr <neels@hofmeyr.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <osmocom/core/logging.h>
#include <osmocom/bsc/debug.h>
#include <osmocom/bsc/timeslot_fsm.h>
#include <osmocom/bsc/lchan_fsm.h>
#include <osmocom/bsc/abis_rsl.h>
#include <osmocom/bsc/pcu_if.h>
static struct osmo_fsm ts_fsm;
#define CHAN_ACT_DEACT_TIMEOUT 4 /* TODO: proper T number? */
enum ts_fsm_T {
T_CHAN_ACT_DEACT=23001,
};
struct gsm_bts_trx_ts *ts_fi_ts(struct osmo_fsm_inst *fi)
{
OSMO_ASSERT(fi);
OSMO_ASSERT(fi->fsm == &ts_fsm);
OSMO_ASSERT(fi->priv);
return fi->priv;
}
static void ts_fsm_update_id(struct gsm_bts_trx_ts *ts)
{
osmo_fsm_inst_update_id_f(ts->fi, "%u-%u-%u-%s", ts->trx->bts->nr, ts->trx->nr, ts->nr,
gsm_pchan_id(ts->pchan_on_init));
}
void ts_fsm_init()
{
OSMO_ASSERT(osmo_fsm_register(&ts_fsm) == 0);
}
void ts_fsm_alloc(struct gsm_bts_trx_ts *ts)
{
OSMO_ASSERT(!ts->fi);
OSMO_ASSERT(ts->trx);
ts->fi = osmo_fsm_inst_alloc(&ts_fsm, ts->trx, ts, LOGL_DEBUG, NULL);
OSMO_ASSERT(ts->fi);
}
enum lchan_sanity {
LCHAN_IS_INSANE = -1,
LCHAN_IS_READY_TO_GO,
LCHAN_NEEDS_PCHAN_CHANGE,
};
static enum lchan_sanity is_lchan_sane(struct gsm_bts_trx_ts *ts, struct gsm_lchan *lchan)
{
OSMO_ASSERT(ts);
OSMO_ASSERT(lchan);
if (lchan->ts != ts)
return LCHAN_IS_INSANE;
if (!lchan->fi)
return LCHAN_IS_INSANE;
if (lchan->type == gsm_lchan_type_by_pchan(ts->pchan_is))
return LCHAN_IS_READY_TO_GO;
switch (ts->pchan_on_init) {
case GSM_PCHAN_TCH_F_TCH_H_PDCH:
if (lchan->type == GSM_LCHAN_TCH_H)
return LCHAN_NEEDS_PCHAN_CHANGE;
/* fall thru */
case GSM_PCHAN_TCH_F_PDCH:
if (lchan->type == GSM_LCHAN_TCH_F)
return LCHAN_NEEDS_PCHAN_CHANGE;
/* fall thru */
default:
return LCHAN_IS_INSANE;
}
}
static void lchan_dispatch(struct gsm_lchan *lchan, uint32_t lchan_ev)
{
if (!lchan->fi)
return;
osmo_fsm_inst_dispatch(lchan->fi, lchan_ev, NULL);
OSMO_ASSERT(lchan->fi->state != LCHAN_ST_WAIT_TS_READY);
}
static int ts_count_active_lchans(struct gsm_bts_trx_ts *ts)
{
struct gsm_lchan *lchan;
int count = 0;
ts_for_each_lchan(lchan, ts) {
if (lchan->fi->state == LCHAN_ST_UNUSED)
continue;
count++;
}
return count;
}
static void ts_lchans_dispatch(struct gsm_bts_trx_ts *ts, int lchan_state, uint32_t lchan_ev)
{
struct gsm_lchan *lchan;
ts_for_each_lchan(lchan, ts) {
if (lchan_state >= 0
&& !lchan_state_is(lchan, lchan_state))
continue;
lchan_dispatch(lchan, lchan_ev);
}
}
static void ts_terminate_lchan_fsms(struct gsm_bts_trx_ts *ts)
{
struct gsm_lchan *lchan;
ts_for_each_lchan(lchan, ts) {
osmo_fsm_inst_term(lchan->fi, OSMO_FSM_TERM_REQUEST, NULL);
}
}
static int ts_lchans_waiting(struct gsm_bts_trx_ts *ts)
{
struct gsm_lchan *lchan;
int count = 0;
ts_for_each_lchan(lchan, ts)
if (lchan->fi->state == LCHAN_ST_WAIT_TS_READY)
count++;
return count;
}
static void ts_fsm_error(struct osmo_fsm_inst *fi, uint32_t state_chg, const char *fmt, ...)
{
struct gsm_bts_trx_ts *ts = ts_fi_ts(fi);
char *errmsg = NULL;
if (fmt) {
va_list ap;
va_start(ap, fmt);
errmsg = talloc_vasprintf(ts->trx, fmt, ap);
va_end(ap);
}
if (ts->last_errmsg)
talloc_free(ts->last_errmsg);
ts->last_errmsg = errmsg;
if (errmsg)
LOG_TS(ts, LOGL_ERROR, "%s\n", errmsg);
ts_lchans_dispatch(ts, LCHAN_ST_WAIT_TS_READY, LCHAN_EV_TS_ERROR);
if (fi->state != state_chg)
osmo_fsm_inst_state_chg(fi, state_chg, 0, 0);
}
static void ts_fsm_err_ready_to_go_in_pdch(struct osmo_fsm_inst *fi, struct gsm_lchan *lchan)
{
/* This shouldn't ever happen, so aggressively mark it. */
ts_fsm_error(fi, TS_ST_BORKEN,
"Internal error: lchan marked as 'ready to go', but activating"
" any lchan should need PCHAN switchover in state %s (lchan: %s)",
osmo_fsm_inst_state_name(fi), gsm_lchan_name(lchan));
}
static void ts_setup_lchans(struct gsm_bts_trx_ts *ts)
{
int i, max_lchans;
ts->pchan_on_init = ts->pchan_from_config;
ts_fsm_update_id(ts);
max_lchans = pchan_subslots(ts->pchan_on_init);
LOG_TS(ts, LOGL_DEBUG, "max lchans: %d\n", max_lchans);
for (i = 0; i < max_lchans; i++) {
/* If we receive more than one Channel OPSTART ACK, don't fail on the second init. */
if (ts->lchan[i].fi)
continue;
lchan_fsm_alloc(&ts->lchan[i]);
}
switch (ts->pchan_on_init) {
case GSM_PCHAN_TCH_F_TCH_H_PDCH:
ts->pchan_is = GSM_PCHAN_NONE;
break;
case GSM_PCHAN_TCH_F_PDCH:
ts->pchan_is = GSM_PCHAN_TCH_F;
break;
default:
ts->pchan_is = ts->pchan_on_init;
break;
}
LOG_TS(ts, LOGL_DEBUG, "lchans initialized: %d\n", max_lchans);
}
static void ts_fsm_not_initialized(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
struct gsm_bts_trx_ts *ts = ts_fi_ts(fi);
struct gsm_bts *bts = ts->trx->bts;
switch (event) {
case TS_EV_OML_READY:
ts->pdch_act_allowed = true;
ts_setup_lchans(ts);
if (!ts->trx->rsl_link) {
LOG_TS(ts, LOGL_DEBUG, "No RSL link yet\n");
return;
}
/* -> UNUSED below */
break;
case TS_EV_RSL_READY:
ts->pdch_act_allowed = true;
if (bts->model->oml_is_ts_ready
&& !bts->model->oml_is_ts_ready(ts)) {
LOG_TS(ts, LOGL_DEBUG, "OML not ready yet\n");
return;
}
/* -> UNUSED below */
break;
case TS_EV_LCHAN_REQUESTED:
{
/* TS is not initialized, no lchan can be requested. */
struct gsm_lchan *lchan = data;
if (lchan && lchan->fi)
osmo_fsm_inst_dispatch(fi, LCHAN_EV_TS_ERROR, NULL);
}
return;
case TS_EV_LCHAN_UNUSED:
/* ignored. */
return;
default:
OSMO_ASSERT(false);
}
osmo_fsm_inst_state_chg(fi, TS_ST_UNUSED, 0, 0);
}
static void ts_fsm_unused_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
{
struct gsm_bts_trx_ts *ts = ts_fi_ts(fi);
struct gsm_bts *bts = ts->trx->bts;
/* We are entering the unused state. There must by definition not be any lchans waiting to be
* activated. */
if (ts_lchans_waiting(ts)) {
ts_fsm_error(fi, TS_ST_BORKEN,
"Internal error: entering UNUSED state, but there are lchans waiting to be"
" activated. Not activating them to prevent infinite loops.");
return;
}
switch (ts->pchan_on_init) {
case GSM_PCHAN_TCH_F_TCH_H_PDCH:
case GSM_PCHAN_TCH_F_PDCH:
if (bts->gprs.mode == BTS_GPRS_NONE) {
LOG_TS(ts, LOGL_DEBUG, "GPRS mode is 'none': not activating PDCH.\n");
return;
}
if (!ts->pdch_act_allowed) {
LOG_TS(ts, LOGL_DEBUG, "PDCH is disabled for this timeslot,"
" either due to a PDCH ACT NACK, or from manual VTY command:"
" not activating PDCH. (last error: %s)\n",
ts->last_errmsg ? : "-");
return;
}
osmo_fsm_inst_state_chg(fi, TS_ST_WAIT_PDCH_ACT, CHAN_ACT_DEACT_TIMEOUT,
T_CHAN_ACT_DEACT);
break;
default:
/* nothing to do */
break;
}
}
static void ts_fsm_unused(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
struct gsm_bts_trx_ts *ts = ts_fi_ts(fi);
switch (event) {
case TS_EV_LCHAN_REQUESTED:
{
struct gsm_lchan *lchan = data;
switch (is_lchan_sane(ts, lchan)) {
case LCHAN_NEEDS_PCHAN_CHANGE:
/* Osmocom style dyn TS: in UNUSED state, PDCH is already switched off,
* we merely need to RSL Chan Activ the new lchan. For ip.access style
* dyn TS this is already TCH/F, and we should never hit this. */
case LCHAN_IS_READY_TO_GO:
osmo_fsm_inst_state_chg(fi, TS_ST_IN_USE, 0, 0);
return;
default:
osmo_fsm_inst_dispatch(lchan->fi, LCHAN_EV_TS_ERROR, NULL);
return;
}
}
case TS_EV_LCHAN_UNUSED:
/* ignored. */
return;
default:
OSMO_ASSERT(false);
}
}
static inline void ts_fsm_pdch_deact(struct osmo_fsm_inst *fi)
{
osmo_fsm_inst_state_chg(fi, TS_ST_WAIT_PDCH_DEACT, CHAN_ACT_DEACT_TIMEOUT, T_CHAN_ACT_DEACT);
}
static void ts_fsm_wait_pdch_act_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
{
int rc;
struct gsm_bts_trx_ts *ts = ts_fi_ts(fi);
rc = rsl_tx_dyn_ts_pdch_act_deact(ts, true);
/* On error, we couldn't send the activation message and remain unused. */
if (rc)
ts_fsm_error(fi, TS_ST_UNUSED, "Unable to send PDCH activation");
}
static void ts_fsm_wait_pdch_act(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
struct gsm_bts_trx_ts *ts = ts_fi_ts(fi);
switch (event) {
case TS_EV_PDCH_ACT_ACK:
osmo_fsm_inst_state_chg(fi, TS_ST_PDCH, 0, 0);
return;
case TS_EV_PDCH_ACT_NACK:
if (ts->pchan_on_init == GSM_PCHAN_TCH_F_PDCH)
rate_ctr_inc(&ts->trx->bts->bts_ctrs->ctr[BTS_CTR_RSL_IPA_NACK]);
else
rate_ctr_inc(&ts->trx->bts->bts_ctrs->ctr[BTS_CTR_CHAN_ACT_NACK]);
ts->pdch_act_allowed = false;
ts_fsm_error(fi, TS_ST_UNUSED, "Received PDCH activation NACK");
return;
case TS_EV_LCHAN_REQUESTED:
{
struct gsm_lchan *lchan = data;
switch (is_lchan_sane(ts, lchan)) {
case LCHAN_IS_READY_TO_GO:
/* PDCH activation has not been acked, the previous pchan kind may still
* linger in ts->pchan and make it look like the ts is usable right away.
* But we've started the switchover and must finish that first. */
case LCHAN_NEEDS_PCHAN_CHANGE:
/* PDCH onenter will see that the lchan is waiting and continue to switch
* off PDCH right away. */
return;
default:
lchan_dispatch(lchan, LCHAN_EV_TS_ERROR);
return;
}
}
case TS_EV_LCHAN_UNUSED:
/* ignored. */
return;
default:
OSMO_ASSERT(false);
}
}
static void ts_fsm_pdch_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
{
int count;
struct gsm_bts_trx_ts *ts = ts_fi_ts(fi);
/* Set pchan = PDCH status, but double check. */
switch (ts->pchan_on_init) {
case GSM_PCHAN_TCH_F_TCH_H_PDCH:
case GSM_PCHAN_TCH_F_PDCH:
case GSM_PCHAN_PDCH:
ts->pchan_is = GSM_PCHAN_PDCH;
break;
default:
ts_fsm_error(fi, TS_ST_BORKEN, "pchan %s is incapable of activating PDCH",
gsm_pchan_name(ts->pchan_on_init));
return;
}
/* PDCH use has changed, tell the PCU about it. */
pcu_info_update(ts->trx->bts);
/* If we received TS_EV_LCHAN_REQUESTED in the meantime, go right out of PDCH again. */
if ((count = ts_lchans_waiting(ts))) {
LOG_TS(ts, LOGL_DEBUG, "%d lchan(s) waiting for usable timeslot\n", count);
ts_fsm_pdch_deact(fi);
}
}
static void ts_fsm_pdch(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
struct gsm_bts_trx_ts *ts = ts_fi_ts(fi);
switch (event) {
case TS_EV_LCHAN_REQUESTED:
{
struct gsm_lchan *lchan = data;
switch (is_lchan_sane(ts, lchan)) {
case LCHAN_NEEDS_PCHAN_CHANGE:
ts_fsm_pdch_deact(fi);
return;
case LCHAN_IS_READY_TO_GO:
ts_fsm_err_ready_to_go_in_pdch(fi, lchan);
return;
default:
/* Reject just this lchan. */
lchan_dispatch(lchan, LCHAN_EV_TS_ERROR);
return;
}
}
case TS_EV_LCHAN_UNUSED:
/* ignored */
return;
default:
OSMO_ASSERT(false);
}
}
static void ts_fsm_wait_pdch_deact_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
{
int rc;
struct gsm_bts_trx_ts *ts = ts_fi_ts(fi);
rc = rsl_tx_dyn_ts_pdch_act_deact(ts, false);
/* On error, we couldn't send the deactivation message and remain in PDCH. */
if (rc)
ts_fsm_error(fi, TS_ST_PDCH, "Unable to send PDCH deactivation");
}
static void ts_fsm_wait_pdch_deact(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
struct gsm_bts_trx_ts *ts = ts_fi_ts(fi);
switch (event) {
case TS_EV_PDCH_DEACT_ACK:
/* Remove pchan = PDCH status, but double check. */
switch (ts->pchan_on_init) {
case GSM_PCHAN_TCH_F_TCH_H_PDCH:
ts->pchan_is = GSM_PCHAN_NONE;
break;
case GSM_PCHAN_TCH_F_PDCH:
ts->pchan_is = GSM_PCHAN_TCH_F;
break;
default:
ts_fsm_error(fi, TS_ST_BORKEN, "pchan %s is incapable of deactivating PDCH",
gsm_pchan_name(ts->pchan_on_init));
return;
}
osmo_fsm_inst_state_chg(fi, TS_ST_IN_USE, 0, 0);
/* IN_USE onenter will signal all waiting lchans. */
/* PDCH use has changed, tell the PCU about it. */
pcu_info_update(ts->trx->bts);
return;
case TS_EV_PDCH_DEACT_NACK:
if (ts->pchan_on_init == GSM_PCHAN_TCH_F_PDCH)
rate_ctr_inc(&ts->trx->bts->bts_ctrs->ctr[BTS_CTR_RSL_IPA_NACK]);
/* For Osmocom style dyn TS, there actually is no NACK, since there is no RF Channel
* Release NACK message in RSL. */
ts_fsm_error(fi, TS_ST_BORKEN, "Received PDCH deactivation NACK");
return;
case TS_EV_LCHAN_REQUESTED:
{
struct gsm_lchan *lchan = data;
switch (is_lchan_sane(ts, lchan)) {
case LCHAN_NEEDS_PCHAN_CHANGE:
/* IN_USE onenter will see that the lchan is waiting and signal it. */
return;
case LCHAN_IS_READY_TO_GO:
ts_fsm_err_ready_to_go_in_pdch(fi, lchan);
return;
default:
/* Reject just this lchan. */
lchan_dispatch(lchan, LCHAN_EV_TS_ERROR);
return;
}
}
default:
OSMO_ASSERT(false);
}
}
static void ts_fsm_in_use_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
{
bool ok;
struct gsm_lchan *lchan;
struct gsm_bts_trx_ts *ts = ts_fi_ts(fi);
enum gsm_chan_t activating_type = GSM_LCHAN_NONE;
/* After being in use, allow PDCH act again, if appropriate. */
ts->pdch_act_allowed = true;
/* For static TS, check validity. For dyn TS, figure out which PCHAN this should become. */
ts_as_pchan_for_each_lchan(lchan, ts, ts->pchan_on_init) {
if (lchan_state_is(lchan, LCHAN_ST_UNUSED))
continue;
switch (lchan->type) {
case GSM_LCHAN_TCH_H:
case GSM_LCHAN_TCH_F:
case GSM_LCHAN_SDCCH:
ok = ts_is_capable_of_lchant(ts, lchan->type);
break;
default:
ok = false;
break;
}
if (!ok && lchan_state_is(lchan, LCHAN_ST_WAIT_TS_READY)) {
LOG_TS(ts, LOGL_ERROR, "lchan activation of %s is not permitted for %s (%s)\n",
gsm_lchant_name(lchan->type), gsm_pchan_name(ts->pchan_on_init),
gsm_lchan_name(lchan));
lchan_dispatch(lchan, LCHAN_EV_TS_ERROR);
}
if (!ok)
continue;
if (activating_type == GSM_LCHAN_NONE)
activating_type = lchan->type;
else if (activating_type != lchan->type) {
LOG_TS(ts, LOGL_ERROR, "lchan type %s mismatches %s (%s)\n",
gsm_lchant_name(lchan->type), gsm_lchant_name(activating_type),
gsm_lchan_name(lchan));
lchan_dispatch(lchan, LCHAN_EV_TS_ERROR);
}
}
ok = false;
switch (activating_type) {
case GSM_LCHAN_SDCCH:
case GSM_LCHAN_TCH_F:
case GSM_LCHAN_TCH_H:
ok = ts_is_capable_of_lchant(ts, activating_type);
break;
case GSM_LCHAN_NONE:
LOG_TS(ts, LOGL_DEBUG, "Entered IN_USE state but no lchans are actually in use now.\n");
break;
default:
LOG_TS(ts, LOGL_ERROR, "cannot use timeslot as %s\n", gsm_lchant_name(activating_type));
ts_lchans_dispatch(ts, LCHAN_ST_WAIT_TS_READY, LCHAN_EV_TS_ERROR);
break;
}
if (!ok) {
osmo_fsm_inst_state_chg(fi, TS_ST_UNUSED, 0, 0);
return;
}
/* Make sure dyn TS pchan_is is updated. For TCH/F_PDCH, there are only PDCH or TCH/F modes, but
* for Osmocom style TCH/F_TCH/H_PDCH the pchan_is == NONE until an lchan is activated. */
if (ts->pchan_on_init == GSM_PCHAN_TCH_F_TCH_H_PDCH)
ts->pchan_is = gsm_pchan_by_lchan_type(activating_type);
ts_lchans_dispatch(ts, LCHAN_ST_WAIT_TS_READY, LCHAN_EV_TS_READY);
}
static void ts_fsm_in_use(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
struct gsm_bts_trx_ts *ts = ts_fi_ts(fi);
switch (event) {
case TS_EV_LCHAN_UNUSED:
if (!ts_count_active_lchans(ts))
osmo_fsm_inst_state_chg(fi, TS_ST_UNUSED, 0, 0);
return;
case TS_EV_LCHAN_REQUESTED:
{
struct gsm_lchan *lchan = data;
switch (is_lchan_sane(ts, lchan)) {
case LCHAN_IS_READY_TO_GO:
osmo_fsm_inst_dispatch(lchan->fi, LCHAN_EV_TS_READY, NULL);
return;
case LCHAN_NEEDS_PCHAN_CHANGE:
LOG_TS(ts, LOGL_ERROR,
"cannot activate lchan of mismatching pchan type"
" when the TS is already in use: %s\n",
gsm_lchan_name(lchan));
/* fall thru */
default:
/* Reject just this lchan. */
lchan_dispatch(lchan, LCHAN_EV_TS_ERROR);
return;
}
}
default:
OSMO_ASSERT(false);
}
}
static void ts_fsm_borken(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
switch (event) {
case TS_EV_LCHAN_UNUSED:
/* ignored */
return;
case TS_EV_LCHAN_REQUESTED:
{
struct gsm_lchan *lchan = data;
lchan_dispatch(lchan, LCHAN_EV_TS_ERROR);
return;
}
default:
OSMO_ASSERT(false);
}
}
static int ts_fsm_timer_cb(struct osmo_fsm_inst *fi)
{
switch (fi->state) {
case TS_ST_WAIT_PDCH_ACT:
ts_fsm_error(fi, TS_ST_BORKEN, "PDCH activation timeout");
return 0;
case TS_ST_WAIT_PDCH_DEACT:
ts_fsm_error(fi, TS_ST_BORKEN, "PDCH deactivation timeout");
return 0;
default:
ts_fsm_error(fi, TS_ST_BORKEN, "Unknown timeout in state %s",
osmo_fsm_inst_state_name(fi));
return 0;
}
}
static void ts_fsm_allstate(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
struct gsm_bts_trx_ts *ts = ts_fi_ts(fi);
switch (event) {
case TS_EV_OML_DOWN:
if (fi->state != TS_ST_NOT_INITIALIZED)
osmo_fsm_inst_state_chg(fi, TS_ST_NOT_INITIALIZED, 0, 0);
OSMO_ASSERT(fi->state == TS_ST_NOT_INITIALIZED);
ts_terminate_lchan_fsms(ts);
ts->pchan_is = ts->pchan_on_init = GSM_PCHAN_NONE;
ts_fsm_update_id(ts);
break;
case TS_EV_RSL_DOWN:
if (fi->state != TS_ST_NOT_INITIALIZED)
osmo_fsm_inst_state_chg(fi, TS_ST_NOT_INITIALIZED, 0, 0);
OSMO_ASSERT(fi->state == TS_ST_NOT_INITIALIZED);
ts->pchan_is = GSM_PCHAN_NONE;
ts_lchans_dispatch(ts, -1, LCHAN_EV_TS_ERROR);
break;
default:
OSMO_ASSERT(false);
}
}
#define S(x) (1 << (x))
static const struct osmo_fsm_state ts_fsm_states[] = {
[TS_ST_NOT_INITIALIZED] = {
.name = "NOT_INITIALIZED",
.action = ts_fsm_not_initialized,
.in_event_mask = 0
| S(TS_EV_OML_READY)
| S(TS_EV_RSL_READY)
| S(TS_EV_LCHAN_REQUESTED)
| S(TS_EV_LCHAN_UNUSED)
,
.out_state_mask = 0
| S(TS_ST_UNUSED)
,
},
[TS_ST_UNUSED] = {
.name = "UNUSED",
.onenter = ts_fsm_unused_onenter,
.action = ts_fsm_unused,
.in_event_mask = 0
| S(TS_EV_LCHAN_REQUESTED)
| S(TS_EV_LCHAN_UNUSED)
,
.out_state_mask = 0
| S(TS_ST_WAIT_PDCH_ACT)
| S(TS_ST_IN_USE)
| S(TS_ST_NOT_INITIALIZED)
,
},
[TS_ST_WAIT_PDCH_ACT] = {
.name = "WAIT_PDCH_ACT",
.onenter = ts_fsm_wait_pdch_act_onenter,
.action = ts_fsm_wait_pdch_act,
.in_event_mask = 0
| S(TS_EV_PDCH_ACT_ACK)
| S(TS_EV_PDCH_ACT_NACK)
| S(TS_EV_LCHAN_REQUESTED)
| S(TS_EV_LCHAN_UNUSED)
,
.out_state_mask = 0
| S(TS_ST_PDCH)
| S(TS_ST_UNUSED)
| S(TS_ST_BORKEN)
| S(TS_ST_NOT_INITIALIZED)
,
},
[TS_ST_PDCH] = {
.name = "PDCH",
.onenter = ts_fsm_pdch_onenter,
.action = ts_fsm_pdch,
.in_event_mask = 0
| S(TS_EV_LCHAN_REQUESTED)
| S(TS_EV_LCHAN_UNUSED)
,
.out_state_mask = 0
| S(TS_ST_WAIT_PDCH_DEACT)
| S(TS_ST_NOT_INITIALIZED)
,
},
[TS_ST_WAIT_PDCH_DEACT] = {
.name = "WAIT_PDCH_DEACT",
.onenter = ts_fsm_wait_pdch_deact_onenter,
.action = ts_fsm_wait_pdch_deact,
.in_event_mask = 0
| S(TS_EV_PDCH_DEACT_ACK)
| S(TS_EV_PDCH_DEACT_NACK)
| S(TS_EV_LCHAN_REQUESTED)
| S(TS_EV_LCHAN_UNUSED)
,
.out_state_mask = 0
| S(TS_ST_IN_USE)
| S(TS_ST_UNUSED)
| S(TS_ST_BORKEN)
| S(TS_ST_NOT_INITIALIZED)
,
},
[TS_ST_IN_USE] = {
.name = "IN_USE",
.onenter = ts_fsm_in_use_onenter,
.action = ts_fsm_in_use,
.in_event_mask = 0
| S(TS_EV_LCHAN_REQUESTED)
| S(TS_EV_LCHAN_UNUSED)
,
.out_state_mask = 0
| S(TS_ST_UNUSED)
| S(TS_ST_NOT_INITIALIZED)
,
},
[TS_ST_BORKEN] = {
.name = "BORKEN",
.action = ts_fsm_borken,
.in_event_mask = 0
| S(TS_EV_LCHAN_REQUESTED)
| S(TS_EV_LCHAN_UNUSED)
,
.out_state_mask = 0
| S(TS_ST_NOT_INITIALIZED)
,
},
};
static const struct value_string ts_fsm_event_names[] = {
OSMO_VALUE_STRING(TS_EV_OML_READY),
OSMO_VALUE_STRING(TS_EV_OML_DOWN),
OSMO_VALUE_STRING(TS_EV_RSL_READY),
OSMO_VALUE_STRING(TS_EV_RSL_DOWN),
OSMO_VALUE_STRING(TS_EV_LCHAN_REQUESTED),
OSMO_VALUE_STRING(TS_EV_LCHAN_UNUSED),
OSMO_VALUE_STRING(TS_EV_PDCH_ACT_ACK),
OSMO_VALUE_STRING(TS_EV_PDCH_ACT_NACK),
OSMO_VALUE_STRING(TS_EV_PDCH_DEACT_ACK),
OSMO_VALUE_STRING(TS_EV_PDCH_DEACT_NACK),
{}
};
static struct osmo_fsm ts_fsm = {
.name = "timeslot",
.states = ts_fsm_states,
.num_states = ARRAY_SIZE(ts_fsm_states),
.timer_cb = ts_fsm_timer_cb,
.log_subsys = DRSL,
.event_names = ts_fsm_event_names,
.allstate_event_mask = 0
| S(TS_EV_OML_DOWN)
| S(TS_EV_RSL_DOWN)
,
.allstate_action = ts_fsm_allstate,
};
/* Return true if any lchans are waiting for this timeslot to become a specific PCHAN. If target_pchan is
* not NULL, also return the PCHAN being waited for. */
bool ts_is_lchan_waiting_for_pchan(struct gsm_bts_trx_ts *ts, enum gsm_phys_chan_config *target_pchan)
{
struct gsm_lchan *lchan;
ts_for_each_lchan(lchan, ts) {
if (lchan->fi->state == LCHAN_ST_WAIT_TS_READY) {
if (target_pchan)
*target_pchan = gsm_pchan_by_lchan_type(lchan->type);
return true;
}
}
if (target_pchan)
*target_pchan = ts->pchan_is;
return false;
}
/* Return true if we are busy changing the PCHAN kind. If target_pchan is not NULL, also return the PCHAN
* (ultimately) being switched to. */
bool ts_is_pchan_switching(struct gsm_bts_trx_ts *ts, enum gsm_phys_chan_config *target_pchan)
{
switch (ts->fi->state) {
case TS_ST_NOT_INITIALIZED:
case TS_ST_BORKEN:
return false;
default:
break;
}
/* If an lchan is waiting, return the final pchan after all switching is done. */
if (ts_is_lchan_waiting_for_pchan(ts, target_pchan))
return true;
/* No lchans waiting. Return any ongoing switching. */
switch (ts->fi->state) {
case TS_ST_WAIT_PDCH_ACT:
if (target_pchan)
*target_pchan = GSM_PCHAN_PDCH;
return true;
case TS_ST_WAIT_PDCH_DEACT:
/* If we were switching to a specific pchan kind, an lchan would be waiting. So this must
* be NONE then. */
if (target_pchan)
*target_pchan = GSM_PCHAN_NONE;
return true;
default:
return false;
}
}
/* Does the timeslot's *current* state allow use as this PCHAN kind? If the ts is in switchover, return
* true if the switchover's target PCHAN matches, i.e. an lchan for this pchan kind could be requested
* and will be served after the switch. (Do not check whether any lchans are actually available.) */
bool ts_usable_as_pchan(struct gsm_bts_trx_ts *ts, enum gsm_phys_chan_config as_pchan)
{
if (!ts_is_usable(ts))
return false;
switch (ts->fi->state) {
case TS_ST_IN_USE:
return ts->pchan_is == as_pchan;
default:
break;
}
{
enum gsm_phys_chan_config target_pchan;
if (ts_is_lchan_waiting_for_pchan(ts, &target_pchan))
return target_pchan == as_pchan;
}
return ts_is_capable_of_pchan(ts, as_pchan);
}

View File

@ -46,7 +46,6 @@ endif
bs11_config_SOURCES = \
bs11_config.c \
stubs.c \
$(NULL)
bs11_config_LDADD = \
@ -118,7 +117,6 @@ osmo_meas_udp2db_CFLAGS = \
meas_json_SOURCES = \
meas_json.c \
stubs.c \
$(NULL)
meas_json_LDADD = \

View File

@ -980,3 +980,6 @@ int osmo_bsc_sigtran_open_conn(struct gsm_subscriber_connection *conn, struct ms
{
return 0;
}
void ts_fsm_alloc(struct gsm_bts_trx_ts *ts) {}
int abis_rsl_rcvmsg(struct msgb *msg) { return 0; }

View File

@ -187,3 +187,6 @@ int main(int argc, char **argv)
exit(0);
}
void ts_fsm_alloc(struct gsm_bts_trx_ts *ts) {}
int abis_rsl_rcvmsg(struct msgb *msg) { return 0; }

View File

@ -1,36 +0,0 @@
/* Stubs required for linking */
/* (C) 2018 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
*
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <stdbool.h>
struct gsm_bts_trx_ts;
struct msgb;
bool on_gsm_ts_init(struct gsm_bts_trx_ts *ts)
{
/* No TS init required here. */
return true;
}
int abis_rsl_rcvmsg(struct msgb *msg)
{
/* No RSL handling here */
return 0;
}

View File

@ -188,3 +188,4 @@ struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_network *ne
}
bool on_gsm_ts_init(struct gsm_bts_trx_ts *ts) { return true; }
void ts_fsm_alloc(struct gsm_bts_trx_ts *ts) {}

View File

@ -11,6 +11,8 @@ AM_CFLAGS = \
$(LIBOSMOABIS_CFLAGS) \
$(LIBOSMOLEGACYMGCP_CFLAGS) \
$(LIBOSMOSIGTRAN_CFLAGS) \
$(LIBOSMOMGCPCLIENT_CFLAGS) \
$(LIBOSMOSIGTRAN_CFLAGS) \
$(COVERAGE_CFLAGS) \
$(NULL)
@ -32,26 +34,15 @@ bsc_test_SOURCES = \
bsc_test_LDADD = \
$(top_builddir)/src/osmo-bsc/abis_nm.o \
$(top_builddir)/src/osmo-bsc/abis_rsl.o \
$(top_builddir)/src/osmo-bsc/arfcn_range_encode.o \
$(top_builddir)/src/osmo-bsc/bsc_api.o \
$(top_builddir)/src/osmo-bsc/bsc_dyn_ts.o \
$(top_builddir)/src/osmo-bsc/osmo_bsc_filter.o \
$(top_builddir)/src/osmo-bsc/bsc_rll.o \
$(top_builddir)/src/osmo-bsc/bsc_subscriber.o \
$(top_builddir)/src/osmo-bsc/chan_alloc.o \
$(top_builddir)/src/osmo-bsc/gsm_04_08_rr.o \
$(top_builddir)/src/osmo-bsc/gsm_04_80_utils.o \
$(top_builddir)/src/osmo-bsc/gsm_data.o \
$(top_builddir)/src/osmo-bsc/gsm_timers.o \
$(top_builddir)/src/osmo-bsc/handover_cfg.o \
$(top_builddir)/src/osmo-bsc/handover_logic.o \
$(top_builddir)/src/osmo-bsc/neighbor_ident.o \
$(top_builddir)/src/osmo-bsc/net_init.o \
$(top_builddir)/src/osmo-bsc/paging.o \
$(top_builddir)/src/osmo-bsc/pcu_sock.o \
$(top_builddir)/src/osmo-bsc/rest_octets.o \
$(top_builddir)/src/osmo-bsc/system_information.o \
$(LIBOSMOCORE_LIBS) \
$(LIBOSMOGSM_LIBS) \
$(LIBOSMOVTY_LIBS) \

View File

@ -248,7 +248,7 @@ int bsc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause)
void bsc_cm_update(struct gsm_subscriber_connection *conn,
const uint8_t *cm2, uint8_t cm2_len,
const uint8_t *cm3, uint8_t cm3_len) {}
void bsc_mr_config(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan, int full_rate) {}
void gscon_submit_rsl_dtap(struct gsm_subscriber_connection *conn,
struct msgb *msg, int link_id, int allow_sacch) {}
void gscon_dtap_queue_flush(struct gsm_subscriber_connection *conn, int send) {}
void ts_fsm_alloc(struct gsm_bts_trx_ts *ts) {}
void lchan_activate(struct gsm_lchan *lchan, void *info) {}

View File

@ -329,7 +329,7 @@ static int test_match_codec_pref(const struct gsm0808_channel_type *ct, const st
{
int rc;
unsigned int i;
int full_rate;
bool full_rate;
enum gsm48_chan_mode chan_mode;
printf("Determining channel mode and rate:\n");
@ -355,7 +355,7 @@ static int test_match_codec_pref(const struct gsm0808_channel_type *ct, const st
printf(" codec->efr=%u\n", bts->codec.efr);
printf(" codec->amr=%u\n", bts->codec.amr);
rc = match_codec_pref(&full_rate, &chan_mode, ct, scl, msc, bts);
rc = match_codec_pref(&chan_mode, &full_rate, ct, scl, msc->audio_support, msc->audio_length, &bts->codec);
printf(" * result: rc=%i, full_rate=%i, chan_mode=%s\n", rc, full_rate, gsm48_chan_mode_name(chan_mode));
printf("\n");

View File

@ -932,7 +932,7 @@ Determining channel mode and rate:
codec->hr=1
codec->efr=1
codec->amr=1
* result: rc=-1, full_rate=-1, chan_mode=SIGNALLING
* result: rc=-1, full_rate=0, chan_mode=SIGNALLING
Determining channel mode and rate:
* MS: speech codec list (1 items):
@ -949,7 +949,7 @@ Determining channel mode and rate:
codec->hr=1
codec->efr=1
codec->amr=1
* result: rc=-1, full_rate=-1, chan_mode=SIGNALLING
* result: rc=-1, full_rate=0, chan_mode=SIGNALLING
Determining channel mode and rate:
* MS: speech codec list (1 items):
@ -965,7 +965,7 @@ Determining channel mode and rate:
codec->hr=1
codec->efr=1
codec->amr=1
* result: rc=-1, full_rate=-1, chan_mode=SIGNALLING
* result: rc=-1, full_rate=0, chan_mode=SIGNALLING
Determining channel mode and rate:
* MS: speech codec list (1 items):
@ -981,7 +981,7 @@ Determining channel mode and rate:
codec->hr=1
codec->efr=1
codec->amr=1
* result: rc=-1, full_rate=-1, chan_mode=SIGNALLING
* result: rc=-1, full_rate=0, chan_mode=SIGNALLING
Determining channel mode and rate:
* MS: speech codec list (1 items):
@ -996,7 +996,7 @@ Determining channel mode and rate:
codec->hr=1
codec->efr=1
codec->amr=1
* result: rc=-1, full_rate=-1, chan_mode=SIGNALLING
* result: rc=-1, full_rate=0, chan_mode=SIGNALLING
Determining channel mode and rate:
* MS: speech codec list (5 items):
@ -1016,6 +1016,6 @@ Determining channel mode and rate:
codec->hr=0
codec->efr=0
codec->amr=1
* result: rc=-1, full_rate=-1, chan_mode=SIGNALLING
* result: rc=-1, full_rate=0, chan_mode=SIGNALLING
Testing execution completed.

View File

@ -852,3 +852,5 @@ bool on_gsm_ts_init(struct gsm_bts_trx_ts *ts)
{
return true;
}
void ts_fsm_alloc(struct gsm_bts_trx_ts *ts) {}

View File

@ -32,8 +32,9 @@ handover_test_SOURCES = \
handover_test.c \
$(NULL)
handover_test_LDFLAGS =\
-Wl,--wrap=abis_rsl_sendmsg,--wrap=mgcp_conn_modify,--wrap=mgcp_conn_delete\
handover_test_LDFLAGS = \
-Wl,--wrap=abis_rsl_sendmsg \
-Wl,--wrap=mgw_endpoint_ci_request \
$(NULL)
handover_test_LDADD = \
@ -41,8 +42,8 @@ handover_test_LDADD = \
$(top_builddir)/src/osmo-bsc/abis_nm.o \
$(top_builddir)/src/osmo-bsc/abis_rsl.o \
$(top_builddir)/src/osmo-bsc/arfcn_range_encode.o \
$(top_builddir)/src/osmo-bsc/assignment_fsm.o \
$(top_builddir)/src/osmo-bsc/bsc_api.o \
$(top_builddir)/src/osmo-bsc/bsc_dyn_ts.o \
$(top_builddir)/src/osmo-bsc/bsc_init.o \
$(top_builddir)/src/osmo-bsc/bsc_rll.o \
$(top_builddir)/src/osmo-bsc/bsc_subscr_conn_fsm.o \
@ -51,6 +52,7 @@ handover_test_LDADD = \
$(top_builddir)/src/osmo-bsc/bts_ipaccess_nanobts_omlattr.o \
$(top_builddir)/src/osmo-bsc/bts_sysmobts.o \
$(top_builddir)/src/osmo-bsc/chan_alloc.o \
$(top_builddir)/src/osmo-bsc/codec_pref.o \
$(top_builddir)/src/osmo-bsc/gsm_04_08_rr.o \
$(top_builddir)/src/osmo-bsc/gsm_04_80_utils.o \
$(top_builddir)/src/osmo-bsc/gsm_data.o \
@ -58,16 +60,21 @@ handover_test_LDADD = \
$(top_builddir)/src/osmo-bsc/handover_cfg.o \
$(top_builddir)/src/osmo-bsc/handover_decision.o \
$(top_builddir)/src/osmo-bsc/handover_decision_2.o \
$(top_builddir)/src/osmo-bsc/handover_fsm.o \
$(top_builddir)/src/osmo-bsc/handover_logic.o \
$(top_builddir)/src/osmo-bsc/lchan_fsm.o \
$(top_builddir)/src/osmo-bsc/lchan_select.o \
$(top_builddir)/src/osmo-bsc/meas_rep.o \
$(top_builddir)/src/osmo-bsc/mgw_endpoint_fsm.o \
$(top_builddir)/src/osmo-bsc/neighbor_ident.o \
$(top_builddir)/src/osmo-bsc/osmo_bsc_lcls.o \
$(top_builddir)/src/osmo-bsc/net_init.o \
$(top_builddir)/src/osmo-bsc/osmo_bsc_lcls.o \
$(top_builddir)/src/osmo-bsc/paging.o \
$(top_builddir)/src/osmo-bsc/pcu_sock.o \
$(top_builddir)/src/osmo-bsc/penalty_timers.o \
$(top_builddir)/src/osmo-bsc/rest_octets.o \
$(top_builddir)/src/osmo-bsc/system_information.o \
$(top_builddir)/src/osmo-bsc/timeslot_fsm.o \
$(LIBOSMOCORE_LIBS) \
$(LIBOSMOGSM_LIBS) \
$(LIBOSMOABIS_LIBS) \

View File

@ -32,67 +32,45 @@
#include <osmocom/bsc/abis_rsl.h>
#include <osmocom/bsc/debug.h>
#include <osmocom/bsc/bsc_subscriber.h>
#include <osmocom/bsc/chan_alloc.h>
#include <osmocom/bsc/lchan_select.h>
#include <osmocom/bsc/lchan_fsm.h>
#include <osmocom/bsc/handover_decision.h>
#include <osmocom/bsc/system_information.h>
#include <osmocom/bsc/handover.h>
#include <osmocom/bsc/handover_cfg.h>
#include <osmocom/bsc/handover_decision_2.h>
#include <osmocom/bsc/bss.h>
#include <osmocom/bsc/bsc_api.h>
#include <osmocom/bsc/osmo_bsc.h>
#include <osmocom/bsc/bsc_subscr_conn_fsm.h>
#include <osmocom/bsc/timeslot_fsm.h>
#include <osmocom/bsc/lchan_fsm.h>
#include <osmocom/bsc/mgw_endpoint_fsm.h>
#include <osmocom/bsc/handover_fsm.h>
#include <osmocom/bsc/bsc_msc_data.h>
void *ctx;
struct gsm_network *bsc_gsmnet;
/* override, requires '-Wl,--wrap=mgcp_conn_modify'.
/* override, requires '-Wl,--wrap=mgw_endpoint_ci_request'.
* Catch modification of an MGCP connection. */
int __real_mgcp_conn_modify(struct osmo_fsm_inst *fi, uint32_t parent_evt, struct mgcp_conn_peer *conn_peer);
int __wrap_mgcp_conn_modify(struct osmo_fsm_inst *fi, uint32_t parent_evt, struct mgcp_conn_peer *conn_peer)
void __real_mgw_endpoint_ci_request(struct mgwep_ci *ci,
enum mgcp_verb verb, const struct mgcp_conn_peer *verb_info,
struct osmo_fsm_inst *notify,
uint32_t event_success, uint32_t event_failure,
void *notify_data);
void __wrap_mgw_endpoint_ci_request(struct mgwep_ci *ci,
enum mgcp_verb verb, const struct mgcp_conn_peer *verb_info,
struct osmo_fsm_inst *notify,
uint32_t event_success, uint32_t event_failure,
void *notify_data)
{
/* CAUTION HACK:
*
* The pointer fi is misused to pass a reference to GSCON FSM !
*
* This function is called from gscon_fsm_wait_ho_compl() from
* bsc_subscr_conn_fsm.c when GSCON_EV_HO_COMPL is dispatched to the
* GSCON FSM. By then, the GSCON FSM has already changed to the state
* ST_WAIT_MDCX_BTS_HO (see gscon_fsm_wait_mdcx_bts_ho()) and waits for
* GSCON_EV_MGW_MDCX_RESP_BTS. The signal GSCON_EV_MGW_MDCX_RESP_BTS
* is sent to this function using the parameter parent_evt. So we
* implicitly know the event that is needed to simulate a successful
* MGW negotiation to the GSCON FSM. All we need to do is to dispatch
* parent_evt back to the GSCON FSM in order to make it think that the
* MGW negotiation is done.
*
* Unfortunately, there is a problem with this test implementation.
* in order to simplfy the test we do not allocate any MGCP Client
* FSM but the GSCON FSM will call this function with the fi pointer
* pointing to the MGCP Client FSM. This means we get a nullpointer
* here and there is no way to distinguish which GSCON FSM called
* the function at all (normally we would know through the parent
* pointer).
*
* To get around this problem we populate the fi pointer with the
* reference to the GSCON FSM itsself, so we can know who called the
* function. This is a misuse of the pointer since it normally would
* hold an MGCP Client FSM instead of a GSCON FSM.
*
* See also note in function create_conn() */
osmo_fsm_inst_dispatch(fi, parent_evt, NULL);
return 0;
}
/* override, requires '-Wl,--wrap=mgcp_conn_delete'.
* Catch deletion of an MGCP connection. */
int __real_mgcp_conn_delete(struct osmo_fsm_inst *fi);
int __wrap_mgcp_conn_delete(struct osmo_fsm_inst *fi)
{
/* Just do nothing and pretend that everything went well.
* We never have allocatec any MGCP connections. */
return 0;
struct mgcp_conn_peer fake_data = {};
/* All MGCP shall be successful */
if (!notify)
return;
osmo_fsm_inst_dispatch(notify, event_success, &fake_data);
}
/* measurement report */
@ -225,36 +203,34 @@ static struct gsm_bts *create_bts(int arfcn)
/* 4 full rate and 4 half rate channels */
for (i = 1; i <= 6; i++) {
bts->c0->ts[i].pchan =
(i < 5) ? GSM_PCHAN_TCH_F : GSM_PCHAN_TCH_H;
bts->c0->ts[i].pchan_from_config = (i < 5) ? GSM_PCHAN_TCH_F : GSM_PCHAN_TCH_H;
bts->c0->ts[i].mo.nm_state.operational = NM_OPSTATE_ENABLED;
bts->c0->ts[i].mo.nm_state.availability = NM_AVSTATE_OK;
bts->c0->ts[i].lchan[0].type = GSM_LCHAN_NONE;
bts->c0->ts[i].lchan[0].state = LCHAN_S_NONE;
bts->c0->ts[i].lchan[1].type = GSM_LCHAN_NONE;
bts->c0->ts[i].lchan[1].state = LCHAN_S_NONE;
}
for (i = 0; i < ARRAY_SIZE(bts->c0->ts); i++) {
/* make sure ts->lchans[] get initialized */
osmo_fsm_inst_dispatch(bts->c0->ts[i].fi, TS_EV_OML_READY, 0);
}
return bts;
}
void create_conn(struct gsm_lchan *lchan)
{
static struct bsc_msc_data fake_msc_data = {};
static unsigned int next_imsi = 0;
char imsi[sizeof(lchan->conn->bsub->imsi)];
struct gsm_network *net = lchan->ts->trx->bts->network;
struct gsm_subscriber_connection *conn;
struct mgcp_client *fake_mgcp_client = (void*)talloc_zero(net, int);
conn = bsc_subscr_con_allocate(net);
/* CAUTION HACK: When __real_mgcp_conn_modify() is called by the GSCON
* FSM, then we need to know the reference to caller FSM (GSCON FSM).
* Unfortunately the function __real_mgcp_conn_modify() is called with
* fi_bts, which is unpopulated in this setup. The real function would
* perform the communication with the MGW and then dispatch a signal
* back to the parent FSM. Since we do not have all that in this setup
* we populate the fi_bts pointer with a reference to the GSCON FSM in
* order to have it available later in __real_mgcp_conn_modify(). */
conn->user_plane.fi_bts = conn->fi;
conn->user_plane.mgw_endpoint = mgw_endpoint_alloc(conn->fi,
GSCON_EV_FORGET_MGW_ENDPOINT,
fake_mgcp_client, "test",
"fake endpoint");
conn->sccp.msc = &fake_msc_data;
lchan->conn = conn;
conn->lchan = lchan;
@ -274,13 +250,17 @@ struct gsm_lchan *create_lchan(struct gsm_bts *bts, int full_rate, char *codec)
{
struct gsm_lchan *lchan;
lchan = lchan_alloc(bts,
(full_rate) ? GSM_LCHAN_TCH_F : GSM_LCHAN_TCH_H, 0);
lchan = lchan_select_by_type(bts, (full_rate) ? GSM_LCHAN_TCH_F : GSM_LCHAN_TCH_H);
if (!lchan) {
printf("No resource for lchan\n");
exit(EXIT_FAILURE);
}
lchan->state = LCHAN_S_ACTIVE;
/* serious hack into osmo_fsm */
lchan->fi->state = LCHAN_ST_ESTABLISHED;
lchan->ts->fi->state = TS_ST_IN_USE;
LOG_LCHAN(lchan, LOGL_DEBUG, "activated by handover_test.c\n");
create_conn(lchan);
if (!strcasecmp(codec, "FR") && full_rate)
lchan->tch_mode = GSM48_CMODE_SPEECH_V1;
@ -305,7 +285,6 @@ struct gsm_lchan *create_lchan(struct gsm_bts *bts, int full_rate, char *codec)
},
.len = 5,
};
lchan->conn->codec_list_present = true;
return lchan;
}
@ -382,6 +361,27 @@ static void send_chan_act_ack(struct gsm_lchan *lchan, int act)
abis_rsl_rcvmsg(msg);
}
/* Send RLL Est Ind for SAPI[0] */
static void send_est_ind(struct gsm_lchan *lchan)
{
struct msgb *msg = msgb_alloc_headroom(256, 64, "RSL");
struct abis_rsl_rll_hdr *rh;
uint8_t chan_nr = gsm_lchan2chan_nr(lchan);
rh = (struct abis_rsl_rll_hdr *) msgb_put(msg, sizeof(*rh));
rh->c.msg_discr = ABIS_RSL_MDISC_RLL;
rh->c.msg_type = RSL_MT_EST_IND;
rh->ie_chan = RSL_IE_CHAN_NR;
rh->chan_nr = chan_nr;
rh->ie_link_id = RSL_IE_LINK_IDENT;
rh->link_id = 0x00;
msg->dst = lchan->ts->trx->bts->c0->rsl_link;
msg->l2h = (unsigned char *)rh;
abis_rsl_rcvmsg(msg);
}
/* send handover complete */
static void send_ho_complete(struct gsm_lchan *lchan, bool success)
{
@ -392,6 +392,8 @@ static void send_ho_complete(struct gsm_lchan *lchan, bool success)
struct gsm48_hdr *gh;
struct gsm48_ho_cpl *hc;
send_est_ind(lchan);
rh = (struct abis_rsl_rll_hdr *) msgb_put(msg, sizeof(*rh));
rh->c.msg_discr = ABIS_RSL_MDISC_RLL;
rh->c.msg_type = RSL_MT_DATA_IND;
@ -1336,6 +1338,18 @@ static const struct log_info_cat log_categories[] = {
.color = "\033[1;35m",
.enabled = 1, .loglevel = LOGL_DEBUG,
},
[DRR] = {
.name = "DRR",
.description = "RR",
.color = "\033[1;35m",
.enabled = 1, .loglevel = LOGL_DEBUG,
},
[DRLL] = {
.name = "DRLL",
.description = "RLL",
.color = "\033[1;35m",
.enabled = 1, .loglevel = LOGL_DEBUG,
},
[DMSC] = {
.name = "DMSC",
.description = "Mobile Switching Center",
@ -1380,11 +1394,18 @@ int main(int argc, char **argv)
log_set_print_category(osmo_stderr_target, 1);
log_set_print_category_hex(osmo_stderr_target, 0);
log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_BASENAME);
osmo_fsm_log_addr(false);
bsc_network_alloc();
if (!bsc_gsmnet)
exit(1);
ts_fsm_init();
lchan_fsm_init();
mgw_endpoint_fsm_init(bsc_gsmnet->T_defs);
bsc_subscr_conn_fsm_init();
handover_fsm_init();
ho_set_algorithm(bsc_gsmnet->ho, 2);
ho_set_ho_active(bsc_gsmnet->ho, true);
ho_set_hodec2_as_active(bsc_gsmnet->ho, true);
@ -1429,7 +1450,7 @@ int main(int argc, char **argv)
for (i = 0; i < n; i++)
bts[bts_num + i] = create_bts(arfcn++);
for (i = 0; i < n; i++) {
if (gsm_generate_si(bts[bts_num + i], SYSINFO_TYPE_2))
if (gsm_generate_si(bts[bts_num + i], SYSINFO_TYPE_2) <= 0)
fprintf(stderr, "Error generating SI2\n");
}
bts_num += n;
@ -1670,6 +1691,27 @@ int main(int argc, char **argv)
*test_case);
return EXIT_FAILURE;
}
{
/* Help the lchan out of releasing states */
struct gsm_bts *bts;
llist_for_each_entry(bts, &bsc_gsmnet->bts_list, list) {
struct gsm_bts_trx *trx;
llist_for_each_entry(trx, &bts->trx_list, list) {
int ts_nr;
for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
struct gsm_lchan *lchan;
ts_for_each_lchan(lchan, &trx->ts[ts_nr]) {
if (lchan->fi && lchan->fi->state == LCHAN_ST_WAIT_BEFORE_RF_RELEASE) {
osmo_fsm_inst_state_chg(lchan->fi, LCHAN_ST_WAIT_RF_RELEASE_ACK, 0, 0);
osmo_fsm_inst_dispatch(lchan->fi, LCHAN_EV_RSL_RF_CHAN_REL_ACK, 0);
}
}
}
}
}
}
}
for (i = 0; i < lchan_num; i++) {
@ -1677,7 +1719,6 @@ int main(int argc, char **argv)
lchan[i]->conn = NULL;
conn->lchan = NULL;
osmo_fsm_inst_term(conn->fi, OSMO_FSM_TERM_REGULAR, NULL);
lchan_free(lchan[i]);
}
fprintf(stderr, "--------------------\n");
@ -1708,10 +1749,17 @@ int bsc_compl_l3(struct gsm_subscriber_connection *conn, struct msgb *msg, uint1
{ return 0; }
void bsc_dtap(struct gsm_subscriber_connection *conn, uint8_t link_id, struct msgb *msg) {}
void bsc_assign_compl(struct gsm_subscriber_connection *conn, uint8_t rr_cause) {}
void bsc_assign_fail(struct gsm_subscriber_connection *conn, uint8_t cause, uint8_t *rr_cause) {}
int bsc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause)
{ return 0; }
void bsc_cm_update(struct gsm_subscriber_connection *conn,
const uint8_t *cm2, uint8_t cm2_len,
const uint8_t *cm3, uint8_t cm3_len) {}
void bsc_mr_config(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan, int full_rate) {}
struct gsm0808_handover_required;
int bsc_tx_bssmap_ho_required(struct gsm_lchan *lchan, const struct gsm0808_cell_id_list2 *target_cells)
{ return 0; }
int bsc_tx_bssmap_ho_request_ack(struct gsm_subscriber_connection *conn, struct msgb *rr_ho_command)
{ return 0; }
int bsc_tx_bssmap_ho_detect(struct gsm_subscriber_connection *conn) { return 0; }
enum handover_result bsc_tx_bssmap_ho_complete(struct gsm_subscriber_connection *conn,
struct gsm_lchan *lchan) { return HO_RESULT_OK; }
void bsc_tx_bssmap_ho_failure(struct gsm_subscriber_connection *conn) {}

View File

@ -28,7 +28,7 @@
#include <osmocom/bsc/neighbor_ident.h>
struct neighbor_ident_list *nil;
static struct neighbor_ident_list *nil;
static const struct neighbor_ident_key *k(int from_bts, uint16_t arfcn, uint8_t bsic)
{
@ -105,7 +105,7 @@ static const struct gsm0808_cell_id_list2 lac2 = {
},
};
void print_cil(const struct gsm0808_cell_id_list2 *cil)
static void print_cil(const struct gsm0808_cell_id_list2 *cil)
{
unsigned int i;
if (!cil) {
@ -132,7 +132,7 @@ void print_cil(const struct gsm0808_cell_id_list2 *cil)
static int print_nil_i;
bool nil_cb(const struct neighbor_ident_key *key, const struct gsm0808_cell_id_list2 *val,
static bool nil_cb(const struct neighbor_ident_key *key, const struct gsm0808_cell_id_list2 *val,
void *cb_data)
{
printf(" %2d: %s\n", print_nil_i++, neighbor_ident_key_name(key));
@ -140,7 +140,7 @@ bool nil_cb(const struct neighbor_ident_key *key, const struct gsm0808_cell_id_l
return true;
}
void print_nil()
static void print_nil()
{
print_nil_i = 0;
neighbor_ident_iter(nil, nil_cb, NULL);

View File

@ -317,3 +317,5 @@ struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_network *ne
bool on_gsm_ts_init(struct gsm_bts_trx_ts *ts)
{ return true; }
void ts_fsm_alloc(struct gsm_bts_trx_ts *ts) {}