libosmogb 1.9.0.196-9975
Osmocom Gb library
gprs_ns.c File Reference

GPRS Networks Service (NS) messages on the Gb interface. More...

#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <osmocom/core/fsm.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/byteswap.h>
#include <osmocom/gsm/tlv.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/select.h>
#include <osmocom/core/rate_ctr.h>
#include <osmocom/core/stat_item.h>
#include <osmocom/core/stats.h>
#include <osmocom/core/socket.h>
#include <osmocom/core/signal.h>
#include <osmocom/gprs/gprs_ns.h>
#include <osmocom/gprs/gprs_bssgp.h>
#include <osmocom/gprs/gprs_ns_frgre.h>
#include "common_vty.h"
#include "gb_internal.h"

Macros

#define ns_set_state(ns_, st_)   ns_set_state_with_log(ns_, st_, false, __FILE__, __LINE__)
 
#define ns_set_remote_state(ns_, st_)   ns_set_state_with_log(ns_, st_, true, __FILE__, __LINE__)
 
#define ns_mark_blocked(ns_)   ns_set_state(ns_, (ns_)->state | NSE_S_BLOCKED)
 
#define ns_mark_unblocked(ns_)   ns_set_state(ns_, (ns_)->state & (~NSE_S_BLOCKED));
 
#define ns_mark_alive(ns_)   ns_set_state(ns_, (ns_)->state | NSE_S_ALIVE)
 
#define ns_mark_dead(ns_)   ns_set_state(ns_, (ns_)->state & (~NSE_S_ALIVE));
 
#define ERR_IF_NSVC_USES_SNS(nsvc, reason)
 
#define CHECK_TX_RC(rc, nsvc)
 

Enumerations

enum  ns_ctr {
  NS_CTR_PKTS_IN ,
  NS_CTR_PKTS_OUT ,
  NS_CTR_BYTES_IN ,
  NS_CTR_BYTES_OUT ,
  NS_CTR_BLOCKED ,
  NS_CTR_DEAD ,
  NS_CTR_REPLACED ,
  NS_CTR_NSEI_CHG ,
  NS_CTR_INV_VCI ,
  NS_CTR_INV_NSEI ,
  NS_CTR_LOST_ALIVE ,
  NS_CTR_LOST_RESET ,
  NS_CTR_PKTS_IN ,
  NS_CTR_PKTS_OUT ,
  NS_CTR_PKTS_OUT_DROP ,
  NS_CTR_BYTES_IN ,
  NS_CTR_BYTES_OUT ,
  NS_CTR_BYTES_OUT_DROP ,
  NS_CTR_BLOCKED ,
  NS_CTR_UNBLOCKED ,
  NS_CTR_DEAD ,
  NS_CTR_REPLACED ,
  NS_CTR_NSEI_CHG ,
  NS_CTR_INV_VCI ,
  NS_CTR_INV_NSEI ,
  NS_CTR_LOST_ALIVE ,
  NS_CTR_LOST_RESET
}
 
enum  ns_stat { NS_STAT_ALIVE_DELAY }
 

Functions

static bool nsvc_is_not_used (const struct gprs_nsvc *nsvc)
 
struct msgbgprs_ns_msgb_alloc (void)
 
static void ns_set_state_with_log (struct gprs_nsvc *nsvc, uint32_t state, bool is_remote, const char *file, unsigned line)
 
struct gprs_nsvcgprs_nsvc_by_nsvci (struct gprs_ns_inst *nsi, uint16_t nsvci)
 Lookup struct gprs_nsvc based on NSVCI. More...
 
struct gprs_nsvcgprs_nsvc_by_nsei (struct gprs_ns_inst *nsi, uint16_t nsei)
 Lookup struct gprs_nsvc based on NSEI. More...
 
static struct gprs_nsvcgprs_active_nsvc_by_nsei (struct gprs_ns_inst *nsi, uint16_t nsei, uint16_t bvci)
 Determine active NS-VC for given NSEI + BVCI. More...
 
struct gprs_nsvcgprs_nsvc_by_rem_addr (struct gprs_ns_inst *nsi, const struct sockaddr_in *sin)
 Lookup NS-VC based on specified remote peer socket addr. More...
 
static void gprs_ns_timer_cb (void *data)
 
struct gprs_nsvcgprs_nsvc_create2 (struct gprs_ns_inst *nsi, uint16_t nsvci, uint8_t sig_weight, uint8_t data_weight)
 Create a new NS-VC (Virtual Circuit) within given instance. More...
 
void gprs_nsvc_delete (struct gprs_nsvc *nsvc)
 Delete given NS-VC. More...
 
static void ns_osmo_signal_dispatch (struct gprs_nsvc *nsvc, unsigned int signal, uint8_t cause)
 
static void ns_osmo_signal_dispatch_mismatch (struct gprs_nsvc *nsvc, struct msgb *msg, uint8_t pdu_type, uint8_t ie_type)
 
static void ns_osmo_signal_dispatch_replaced (struct gprs_nsvc *nsvc, struct gprs_nsvc *old_nsvc)
 
const char * gprs_ns_cause_str (enum ns_cause cause)
 Obtain a human-readable string for NS cause value. More...
 
static int nsip_sendmsg (struct gprs_nsvc *nsvc, struct msgb *msg)
 
int grps_ns_frgre_sendmsg (struct gprs_nsvc *nsvc, struct msgb *msg)
 
static bool ns_is_sns (uint8_t pdu_type)
 
static int gprs_ns_tx (struct gprs_nsvc *nsvc, struct msgb *msg)
 
static int gprs_ns_tx_simple (struct gprs_nsvc *nsvc, uint8_t pdu_type)
 
int gprs_ns_tx_reset (struct gprs_nsvc *nsvc, uint8_t cause)
 Transmit a NS-RESET on a given NSVC. More...
 
int gprs_ns_tx_status (struct gprs_nsvc *nsvc, uint8_t cause, uint16_t bvci, struct msgb *orig_msg)
 Transmit a NS-STATUS on a given NSVC. More...
 
int gprs_ns_tx_block (struct gprs_nsvc *nsvc, uint8_t cause)
 Transmit a NS-BLOCK on a given NS-VC. More...
 
static int gprs_ns_tx_block_ack (struct gprs_nsvc *nsvc)
 Transmit a NS-BLOCK-ACK on a given NS-VC. More...
 
int gprs_ns_tx_unblock (struct gprs_nsvc *nsvc)
 Transmit a NS-UNBLOCK on a given NS-VC. More...
 
int gprs_ns_tx_alive (struct gprs_nsvc *nsvc)
 Transmit a NS-ALIVE on a given NS-VC. More...
 
int gprs_ns_tx_alive_ack (struct gprs_nsvc *nsvc)
 Transmit a NS-ALIVE-ACK on a given NS-VC. More...
 
static void nsvc_start_timer (struct gprs_nsvc *nsvc, enum nsvc_timer_mode mode)
 
static int nsvc_timer_elapsed_ms (struct gprs_nsvc *nsvc)
 
static int gprs_ns_tx_reset_ack (struct gprs_nsvc *nsvc)
 
int gprs_ns_tx_sns_ack (struct gprs_nsvc *nsvc, uint8_t trans_id, uint8_t *cause, const struct gprs_ns_ie_ip4_elem *ip4_elems, unsigned int num_ip4_elems)
 Encode + Transmit a SNS-ACK as per Section 9.3.1. More...
 
int gprs_ns_tx_sns_config (struct gprs_nsvc *nsvc, bool end_flag, const struct gprs_ns_ie_ip4_elem *ip4_elems, unsigned int num_ip4_elems)
 Encode + Transmit a SNS-CONFIG as per Section 9.3.4. More...
 
int gprs_ns_tx_sns_config_ack (struct gprs_nsvc *nsvc, uint8_t *cause)
 Encode + Transmit a SNS-CONFIG-ACK as per Section 9.3.5. More...
 
int gprs_ns_tx_sns_size (struct gprs_nsvc *nsvc, bool reset_flag, uint16_t max_nr_nsvc, uint16_t *ip4_ep_nr, uint16_t *ip6_ep_nr)
 Encode + transmit a SNS-SIZE as per Section 9.3.7. More...
 
int gprs_ns_tx_sns_size_ack (struct gprs_nsvc *nsvc, uint8_t *cause)
 Encode + Transmit a SNS-SIZE-ACK as per Section 9.3.8. More...
 
int gprs_ns_sendmsg (struct gprs_ns_inst *nsi, struct msgb *msg)
 High-level function for transmitting a NS-UNITDATA messsage. More...
 
static int gprs_ns_rx_unitdata (struct gprs_nsvc *nsvc, struct msgb *msg)
 
static int gprs_ns_rx_status (struct gprs_nsvc *nsvc, struct msgb *msg)
 
static int gprs_nsvc_replace_if_found (uint16_t nsvci, struct gprs_nsvc **nsvc, struct gprs_nsvc **old_nsvc)
 
static int gprs_ns_rx_reset (struct gprs_nsvc **nsvc, struct msgb *msg)
 
static int gprs_ns_rx_reset_ack (struct gprs_nsvc **nsvc, struct msgb *msg)
 
static int gprs_ns_rx_block (struct gprs_nsvc *nsvc, struct msgb *msg)
 
int gprs_ns_vc_create (struct gprs_ns_inst *nsi, struct msgb *msg, struct gprs_nsvc *fallback_nsvc, struct gprs_nsvc **new_nsvc)
 Create/get NS-VC independently from underlying transport layer. More...
 
int gprs_ns_process_msg (struct gprs_ns_inst *nsi, struct msgb *msg, struct gprs_nsvc **nsvc)
 Process NS message independently from underlying transport layer. More...
 
int gprs_ns_rcvmsg (struct gprs_ns_inst *nsi, struct msgb *msg, struct sockaddr_in *saddr, enum gprs_ns_ll ll)
 Receive incoming NS message from underlying transport layer. More...
 
char * gprs_ns_ll_str_buf (char *buf, size_t buf_len, const struct gprs_nsvc *nsvc)
 
const char * gprs_ns_ll_str (const struct gprs_nsvc *nsvc)
 
char * gprs_ns_ll_str_c (const void *ctx, const struct gprs_nsvc *nsvc)
 
void gprs_ns_ll_copy (struct gprs_nsvc *nsvc, struct gprs_nsvc *other)
 
void gprs_ns_ll_clear (struct gprs_nsvc *nsvc)
 
struct gprs_ns_instgprs_ns_instantiate (gprs_ns_cb_t *cb, void *ctx)
 Create a new GPRS NS instance. More...
 
void gprs_ns_close (struct gprs_ns_inst *nsi)
 
void gprs_ns_destroy (struct gprs_ns_inst *nsi)
 Destroy an entire NS instance. More...
 
static struct msgbread_nsip_msg (struct osmo_fd *bfd, int *error, struct sockaddr_in *saddr)
 
static int handle_nsip_read (struct osmo_fd *bfd)
 
static int handle_nsip_write (struct osmo_fd *bfd)
 
static int nsip_fd_cb (struct osmo_fd *bfd, unsigned int what)
 
int gprs_ns_nsip_listen (struct gprs_ns_inst *nsi)
 Create a listening socket for GPRS NS/UDP/IP. More...
 
int gprs_nsvc_reset (struct gprs_nsvc *nsvc, uint8_t cause)
 Initiate a RESET procedure. More...
 
struct gprs_nsvcgprs_ns_nsip_connect (struct gprs_ns_inst *nsi, struct sockaddr_in *dest, uint16_t nsei, uint16_t nsvci)
 Establish a NS connection (from the BSS) to the SGSN. More...
 
struct gprs_nsvcgprs_ns_nsip_connect_sns (struct gprs_ns_inst *nsi, struct sockaddr_in *dest, uint16_t nsei, uint16_t nsvci)
 Establish a NS connection (from the BSS) to the SGSN using SNS auto-configuration. More...
 
void gprs_ns_set_log_ss (int ss)
 
char * gprs_nsvc_state_append (char *s, struct gprs_nsvc *nsvc)
 Append the nsvc state to a talloc string. More...
 
void gprs_nsvc_start_test (struct gprs_nsvc *nsvc)
 Start the ALIVE timer procedure in all NS-VCs part of this NS Instance. More...
 
void gprs_start_alive_all_nsvcs (struct gprs_ns_inst *nsi)
 

Variables

static const struct tlv_definition ns_att_tlvdef
 
static const struct rate_ctr_desc nsvc_ctr_description []
 
static const struct rate_ctr_group_desc nsvc_ctrg_desc
 
static const struct osmo_stat_item_desc nsvc_stat_description []
 
static const struct osmo_stat_item_group_desc nsvc_statg_desc
 
const struct value_string gprs_ns_signal_ns_names []
 
const struct value_string gprs_ns_pdu_strings []
 
static const struct value_string ns_cause_str []
 
static enum ns_timeout timer_mode_tout [_NSVC_TIMER_NR]
 
static const struct value_string timer_mode_strs []
 
static bool gprs_sns_fsm_registered = false
 

Detailed Description

GPRS Networks Service (NS) messages on the Gb interface.

3GPP TS 08.16 version 8.0.1 Release 1999 / ETSI TS 101 299 V8.0.1 (2002-05) as well as its successor 3GPP TS 48.016