libosmogb 1.9.0.195-dafd
Osmocom Gb library
gprs_ns2.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/logging.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/rate_ctr.h>
#include <osmocom/core/socket.h>
#include <osmocom/core/sockaddr_str.h>
#include <osmocom/core/stats.h>
#include <osmocom/core/stat_item.h>
#include <osmocom/core/talloc.h>
#include <osmocom/gprs/gprs_msgb.h>
#include <osmocom/gsm/prim.h>
#include <osmocom/gsm/tlv.h>
#include "gprs_ns2_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 NS2_LL_MAX_STR   4+2*(INET6_ADDRSTRLEN+9)+8
 

Functions

char * gprs_ns2_ll_str_buf (char *buf, size_t buf_len, struct gprs_ns2_vc *nsvc)
 string-format a given NS-VC into a user-supplied buffer. More...
 
const char * gprs_ns2_ll_str (struct gprs_ns2_vc *nsvc)
 string-format a given NS-VC to a thread-local static buffer. More...
 
char * gprs_ns2_ll_str_c (const void *ctx, struct gprs_ns2_vc *nsvc)
 string-format a given NS-VC to a dynamically allocated string. More...
 
const char * gprs_ns2_nsvc_state_name (struct gprs_ns2_vc *nsvc)
 Return the current state name of a given NS-VC to a thread-local static buffer. More...
 
static struct gprs_ns2_vcns2_load_sharing_signal (struct gprs_ns2_nse *nse)
 
static struct gprs_ns2_vcns2_load_sharing_modulo (struct gprs_ns2_nse *nse, uint16_t bvci, uint32_t load_selector)
 
static struct gprs_ns2_vcns2_load_sharing_weight_modulo (struct gprs_ns2_nse *nse, uint16_t bvci, uint32_t load_selector)
 
struct gprs_ns2_vcns2_load_sharing_first (struct gprs_ns2_nse *nse)
 
static struct gprs_ns2_vcns2_load_sharing (struct gprs_ns2_nse *nse, uint16_t bvci, uint32_t link_selector)
 
int gprs_ns2_recv_prim (struct gprs_ns2_inst *nsi, struct osmo_prim_hdr *oph)
 Receive a primitive from the NS User (Gb). More...
 
void ns2_prim_status_ind (struct gprs_ns2_nse *nse, struct gprs_ns2_vc *nsvc, uint16_t bvci, enum gprs_ns2_affecting_cause cause)
 Send a STATUS.ind primitive to the specified NS instance user. More...
 
struct gprs_ns2_vcns2_vc_alloc (struct gprs_ns2_vc_bind *bind, struct gprs_ns2_nse *nse, bool initiater, enum gprs_ns2_vc_mode vc_mode, const char *id)
 Allocate a NS-VC within the given bind + NSE. More...
 
void gprs_ns2_free_nsvc (struct gprs_ns2_vc *nsvc)
 Destroy/release given NS-VC. More...
 
void ns2_free_nsvcs (struct gprs_ns2_nse *nse)
 
void gprs_ns2_free_nsvcs (struct gprs_ns2_nse *nse)
 Destroy/release all NS-VC of given NSE. More...
 
struct msgbns2_msgb_alloc (void)
 Allocate a message buffer for use with the NS2 stack. More...
 
static int reject_status_msg (struct msgb *orig_msg, struct tlv_parsed *tp, struct msgb **reject, enum ns_cause cause)
 Create a status message to be sent over a new connection. More...
 
struct gprs_ns2_nsegprs_ns2_nse_by_nsei (struct gprs_ns2_inst *nsi, uint16_t nsei)
 Resolve a NS Entity based on its NSEI. More...
 
struct gprs_ns2_vcgprs_ns2_nsvc_by_nsvci (struct gprs_ns2_inst *nsi, uint16_t nsvci)
 Resolve a NS-VC Entity based on its NS-VCI. More...
 
struct gprs_ns2_nsegprs_ns2_create_nse2 (struct gprs_ns2_inst *nsi, uint16_t nsei, enum gprs_ns2_ll linklayer, enum gprs_ns2_dialect dialect, bool ip_sns_role_sgsn)
 Create a NS Entity within given NS instance. More...
 
int ns2_nse_set_dialect (struct gprs_ns2_nse *nse, enum gprs_ns2_dialect dialect)
 
struct gprs_ns2_nsegprs_ns2_create_nse (struct gprs_ns2_inst *nsi, uint16_t nsei, enum gprs_ns2_ll linklayer, enum gprs_ns2_dialect dialect)
 Create a NS Entity within given NS instance. More...
 
uint16_t gprs_ns2_nse_nsei (struct gprs_ns2_nse *nse)
 Return the NSEI. More...
 
void gprs_ns2_free_nse (struct gprs_ns2_nse *nse)
 Destroy given NS Entity. More...
 
void gprs_ns2_free_nses (struct gprs_ns2_inst *nsi)
 
static int ns2_tlv_parse (struct tlv_parsed *dec, const uint8_t *buf, int buf_len, uint8_t lv_tag, uint8_t lv_tag2)
 
static enum ns2_cs ns2_create_vc_sns (struct gprs_ns2_vc_bind *bind, const struct osmo_sockaddr *remote, struct gprs_ns2_vc **success, uint16_t nsei)
 
enum ns2_cs ns2_create_vc (struct gprs_ns2_vc_bind *bind, struct msgb *msg, const struct osmo_sockaddr *remote, const char *logname, struct msgb **reject, struct gprs_ns2_vc **success)
 Create a new NS-VC based on a [received] message. More...
 
struct gprs_ns2_vcgprs_ns2_ip_connect_inactive (struct gprs_ns2_vc_bind *bind, const struct osmo_sockaddr *remote, struct gprs_ns2_nse *nse, uint16_t nsvci)
 Create, and connect an inactive, new IP-based NS-VC. More...
 
struct gprs_ns2_vcgprs_ns2_ip_connect (struct gprs_ns2_vc_bind *bind, const struct osmo_sockaddr *remote, struct gprs_ns2_nse *nse, uint16_t nsvci)
 Create, connect and activate a new IP-based NS-VC. More...
 
struct gprs_ns2_vcgprs_ns2_ip_connect2 (struct gprs_ns2_vc_bind *bind, const struct osmo_sockaddr *remote, uint16_t nsei, uint16_t nsvci, enum gprs_ns2_dialect dialect)
 Create, connect and activate a new IP-based NS-VC. More...
 
struct gprs_ns2_vcgprs_ns2_nsvc_by_sockaddr_nse (struct gprs_ns2_nse *nse, const struct osmo_sockaddr *sockaddr)
 Find NS-VC for given socket address. More...
 
int gprs_ns2_nse_foreach_nsvc (struct gprs_ns2_nse *nse, gprs_ns2_foreach_nsvc_cb cb, void *cb_data)
 Iterate over all nsvc of a NS Entity and call the callback. More...
 
int ns2_recv_vc (struct gprs_ns2_vc *nsvc, struct msgb *msg)
 Bottom-side entry-point for received NS PDU from the driver/bind. More...
 
void ns2_nse_data_sum (struct gprs_ns2_nse *nse)
 
void ns2_nse_notify_unblocked (struct gprs_ns2_vc *nsvc, bool unblocked)
 Notify a nse about the change of a NS-VC. More...
 
struct gprs_ns2_instgprs_ns2_instantiate (void *ctx, osmo_prim_cb cb, void *cb_data)
 Create a new GPRS NS instance. More...
 
void gprs_ns2_free (struct gprs_ns2_inst *nsi)
 Destroy a NS Instance (including all its NSEs, binds, ...). More...
 
void gprs_ns2_start_alive_all_nsvcs (struct gprs_ns2_nse *nse)
 Start the NS-ALIVE FSM in all NS-VCs of given NSE. More...
 
void gprs_ns2_free_bind (struct gprs_ns2_vc_bind *bind)
 Destroy a given bind. More...
 
void gprs_ns2_free_binds (struct gprs_ns2_inst *nsi)
 
struct gprs_ns2_vc_bindgprs_ns2_bind_by_name (struct gprs_ns2_inst *nsi, const char *name)
 Search for a bind with a unique name. More...
 
enum gprs_ns2_vc_mode ns2_dialect_to_vc_mode (enum gprs_ns2_dialect dialect)
 
static void add_bind_array (struct gprs_ns2_vc_bind **array, struct gprs_ns2_vc_bind *bind, int size)
 
void ns2_nse_update_mtu (struct gprs_ns2_nse *nse)
 
int ns2_count_transfer_cap (struct gprs_ns2_nse *nse, uint16_t bvci)
 calculate the transfer capabilities for a nse More...
 
int ns2_bind_alloc (struct gprs_ns2_inst *nsi, const char *name, struct gprs_ns2_vc_bind **result)
 common allocation + low-level initialization of a bind. More...
 

Variables

static const struct tlv_definition ns_att_tlvdef1
 
static const struct tlv_definition ns_att_tlvdef2
 
const struct value_string gprs_ns2_cause_strs []
 
static const struct rate_ctr_desc ns_ctr_description []
 
static const struct rate_ctr_group_desc nse_ctrg_desc
 
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 osmo_stat_item_desc nsbind_stat_description []
 
static const struct osmo_stat_item_group_desc nsbind_statg_desc
 
const struct value_string gprs_ns2_aff_cause_prim_strs []
 
const struct value_string gprs_ns2_prim_strs []
 
const struct value_string gprs_ns2_lltype_strs []
 

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