Merge commit '430be849945688ae107b079db1e216329b1a1f06'
This commit is contained in:
commit
7a9b3f45b2
|
@ -12,3 +12,5 @@ $(top_srcdir)/.version:
|
|||
echo $(VERSION) > $@-t && mv $@-t $@
|
||||
dist-hook:
|
||||
echo $(VERSION) > $(distdir)/.tarball-version
|
||||
|
||||
EXTRA_DIST = git-version-gen
|
||||
|
|
|
@ -13,4 +13,6 @@ extern struct log_target *osmo_stderr_target;
|
|||
void osmo_init_ignore_signals(void);
|
||||
int osmo_init_logging(const struct log_info *);
|
||||
|
||||
int osmo_daemonize(void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#ifndef _OSMO_BACKTRACE_H_
|
||||
#define _OSMO_BACKTRACE_H_
|
||||
|
||||
void osmo_generate_backtrace();
|
||||
void osmo_generate_backtrace(void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include <stdint.h>
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
|
||||
#define LOG_MAX_CATEGORY 32
|
||||
#define LOG_MAX_CTX 8
|
||||
#define LOG_MAX_FILTERS 8
|
||||
|
||||
|
@ -20,7 +19,7 @@
|
|||
#endif
|
||||
|
||||
|
||||
void logp(unsigned int subsys, char *file, int line, int cont, const char *format, ...) __attribute__ ((format (printf, 5, 6)));
|
||||
void logp(int subsys, char *file, int line, int cont, const char *format, ...) __attribute__ ((format (printf, 5, 6)));
|
||||
|
||||
/* new logging interface */
|
||||
#define LOGP(ss, level, fmt, args...) \
|
||||
|
@ -37,6 +36,15 @@ void logp(unsigned int subsys, char *file, int line, int cont, const char *forma
|
|||
|
||||
#define LOG_FILTER_ALL 0x0001
|
||||
|
||||
/* logging levels defined by the library itself */
|
||||
#define DLGLOBAL -1
|
||||
#define DLLAPDM -2
|
||||
#define DLINP -3
|
||||
#define DLMUX -4
|
||||
#define DLMI -5
|
||||
#define DLMIB -6
|
||||
#define OSMO_NUM_DLIB 7
|
||||
|
||||
struct log_category {
|
||||
uint8_t loglevel;
|
||||
uint8_t enabled;
|
||||
|
@ -65,8 +73,9 @@ struct log_info {
|
|||
log_filter *filter_fn;
|
||||
|
||||
/* per-category information */
|
||||
const struct log_info_cat *cat;
|
||||
struct log_info_cat *cat;
|
||||
unsigned int num_cat;
|
||||
unsigned int num_cat_user;
|
||||
};
|
||||
|
||||
enum log_target_type {
|
||||
|
@ -82,10 +91,11 @@ struct log_target {
|
|||
int filter_map;
|
||||
void *filter_data[LOG_MAX_FILTERS+1];
|
||||
|
||||
struct log_category categories[LOG_MAX_CATEGORY+1];
|
||||
struct log_category *categories;
|
||||
|
||||
uint8_t loglevel;
|
||||
int use_color:1;
|
||||
int print_timestamp:1;
|
||||
unsigned int use_color:1;
|
||||
unsigned int print_timestamp:1;
|
||||
|
||||
enum log_target_type type;
|
||||
|
||||
|
@ -110,10 +120,10 @@ struct log_target {
|
|||
};
|
||||
|
||||
/* use the above macros */
|
||||
void logp2(unsigned int subsys, unsigned int level, char *file,
|
||||
void logp2(int subsys, unsigned int level, char *file,
|
||||
int line, int cont, const char *format, ...)
|
||||
__attribute__ ((format (printf, 6, 7)));
|
||||
void log_init(const struct log_info *cat);
|
||||
int log_init(const struct log_info *inf, void *talloc_ctx);
|
||||
|
||||
/* context management */
|
||||
void log_reset_context(void);
|
||||
|
|
|
@ -29,9 +29,13 @@
|
|||
struct msgb {
|
||||
struct llist_head list;
|
||||
|
||||
|
||||
/* Part of which TRX logical channel we were received / transmitted */
|
||||
/* FIXME: move them into the control buffer */
|
||||
struct gsm_bts_trx *trx;
|
||||
union {
|
||||
void *dst;
|
||||
struct gsm_bts_trx *trx;
|
||||
};
|
||||
struct gsm_lchan *lchan;
|
||||
|
||||
/* the Layer1 header (if any) */
|
||||
|
@ -193,5 +197,7 @@ static inline struct msgb *msgb_alloc_headroom(int size, int headroom,
|
|||
uint8_t *msgb_data(const struct msgb *msg);
|
||||
uint16_t msgb_length(const struct msgb *msg);
|
||||
|
||||
/* set the talloc context for msgb_alloc[_headroom] */
|
||||
void msgb_set_talloc_ctx(void *ctx);
|
||||
|
||||
#endif /* _MSGB_H */
|
||||
|
|
|
@ -1,6 +1,2 @@
|
|||
#ifndef _OSMO_PROCESS_H
|
||||
#define _OSMO_PROCESS_H
|
||||
|
||||
int osmo_daemonize(void);
|
||||
|
||||
#endif
|
||||
#warning "Update from osmocom/core/process.h to osmocom/core/application.h"
|
||||
#include <osmocom/core/application.h>
|
||||
|
|
|
@ -1,6 +1,29 @@
|
|||
#ifndef OSMO_SIGNAL_H
|
||||
#define OSMO_SIGNAL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* subsystem signaling numbers: we split the numberspace for applications and
|
||||
* libraries: from 0 to UINT_MAX/2 for applications, from UINT_MAX/2 to
|
||||
* UINT_MAX for libraries. */
|
||||
#define OSMO_SIGNAL_SS_APPS 0
|
||||
#define OSMO_SIGNAL_SS_RESERVED 2147483648
|
||||
|
||||
/* signal subsystems. */
|
||||
enum {
|
||||
SS_L_GLOBAL = OSMO_SIGNAL_SS_RESERVED,
|
||||
SS_L_INPUT,
|
||||
};
|
||||
|
||||
/* application-defined signal types. */
|
||||
#define OSMO_SIGNAL_T_APPS 0
|
||||
#define OSMO_SIGNAL_T_RESERVED 2147483648
|
||||
|
||||
/* signal types. */
|
||||
enum {
|
||||
S_L_GLOBAL_SHUTDOWN = OSMO_SIGNAL_T_RESERVED,
|
||||
};
|
||||
|
||||
typedef int osmo_signal_cbfn(unsigned int subsys, unsigned int signal, void *handler_data, void *signal_data);
|
||||
|
||||
|
||||
|
|
|
@ -64,9 +64,9 @@ int osmo_timer_pending(struct osmo_timer_list *timer);
|
|||
/**
|
||||
* internal timer list management
|
||||
*/
|
||||
struct timeval *osmo_timers_nearest();
|
||||
void osmo_timers_prepare();
|
||||
int osmo_timers_update();
|
||||
struct timeval *osmo_timers_nearest(void);
|
||||
void osmo_timers_prepare(void);
|
||||
int osmo_timers_update(void);
|
||||
int osmo_timers_check(void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#define OSMOCORE_UTIL_H
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
#define OSMO_MAX(a, b) (a) >= (b) ? (a) : (b)
|
||||
#define OSMO_MIN(a, b) (a) >= (b) ? (b) : (a)
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
osmogsm_HEADERS = a5.h comp128.h gsm0808.h gsm48_ie.h mncc.h rxlev_stat.h \
|
||||
gsm0480.h gsm48.h gsm_utils.h rsl.h tlv.h abis_nm.h \
|
||||
sysinfo.h prim.h
|
||||
sysinfo.h prim.h gsm0502.h lapdm.h
|
||||
|
||||
SUBDIRS = protocol
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#define MAX_LEN_USSD_STRING 31
|
||||
|
||||
struct ussd_request {
|
||||
char text[MAX_LEN_USSD_STRING + 1];
|
||||
uint8_t text[MAX_LEN_USSD_STRING + 1];
|
||||
uint8_t transaction_id;
|
||||
uint8_t invoke_id;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef OSMOCOM_GSM_0502_H
|
||||
#define OSMOCOM_GSM_0502_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <osmocom/gsm/protocol/gsm_04_08.h>
|
||||
#include <osmocom/gsm/protocol/gsm_08_58.h>
|
||||
|
||||
/* Table 5 Clause 7 TS 05.02 */
|
||||
static inline unsigned int
|
||||
gsm0502_get_n_pag_blocks(struct gsm48_control_channel_descr *chan_desc)
|
||||
{
|
||||
if (chan_desc->ccch_conf == RSL_BCCH_CCCH_CONF_1_C)
|
||||
return 3 - chan_desc->bs_ag_blks_res;
|
||||
else
|
||||
return 9 - chan_desc->bs_ag_blks_res;
|
||||
}
|
||||
|
||||
/* Chapter 6.5.2 of TS 05.02 */
|
||||
static inline unsigned int
|
||||
gsm0502_get_ccch_group(uint64_t imsi, unsigned int bs_cc_chans,
|
||||
unsigned int n_pag_blocks)
|
||||
{
|
||||
return (imsi % 1000) % (bs_cc_chans * n_pag_blocks) / n_pag_blocks;
|
||||
}
|
||||
|
||||
/* Chapter 6.5.2 of TS 05.02 */
|
||||
static inline unsigned int
|
||||
gsm0502_get_paging_group(uint64_t imsi, unsigned int bs_cc_chans,
|
||||
int n_pag_blocks)
|
||||
{
|
||||
return (imsi % 1000) % (bs_cc_chans * n_pag_blocks) % n_pag_blocks;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
gsm0502_calc_paging_group(struct gsm48_control_channel_descr *chan_desc, uint64_t imsi);
|
||||
|
||||
#endif
|
|
@ -41,6 +41,9 @@ struct msgb *gsm0808_create_clear_rqst(uint8_t cause);
|
|||
struct msgb *gsm0808_create_dtap(struct msgb *msg, uint8_t link_id);
|
||||
void gsm0808_prepend_dtap_header(struct msgb *msg, uint8_t link_id);
|
||||
|
||||
const struct tlv_definition *gsm0808_att_tlvdef();
|
||||
const struct tlv_definition *gsm0808_att_tlvdef(void);
|
||||
|
||||
const char *gsm0808_bssmap_name(uint8_t msg_type);
|
||||
const char *gsm0808_bssap_name(uint8_t msg_type);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -33,4 +33,6 @@ int gsm48_mi_to_string(char *string, const int str_len,
|
|||
void gsm48_parse_ra(struct gprs_ra_id *raid, const uint8_t *buf);
|
||||
int gsm48_construct_ra(uint8_t *buf, const struct gprs_ra_id *raid);
|
||||
|
||||
int gsm48_number_of_paging_subchannels(struct gsm48_control_channel_descr *chan_desc);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -57,9 +57,14 @@ const char *gsm_band_name(enum gsm_band band);
|
|||
enum gsm_band gsm_band_parse(const char *mhz);
|
||||
|
||||
int gsm_7bit_decode(char *decoded, const uint8_t *user_data, uint8_t length);
|
||||
int gsm_7bit_decode_hdr(char *decoded, const uint8_t *user_data, uint8_t length, uint8_t ud_hdr_ind);
|
||||
int gsm_7bit_encode(uint8_t *result, const char *data);
|
||||
|
||||
unsigned int ms_class_gmsk_dbm(enum gsm_band band, int class);
|
||||
int gsm_septets2octets(uint8_t *result, uint8_t *rdata, uint8_t septet_len, uint8_t padding);
|
||||
int gsm_septet_encode(uint8_t *result, const char *data);
|
||||
uint8_t gsm_get_octet_len(const uint8_t sept_len);
|
||||
|
||||
unsigned int ms_class_gmsk_dbm(enum gsm_band band, int ms_class);
|
||||
|
||||
int ms_pwr_ctl_lvl(enum gsm_band band, unsigned int dbm);
|
||||
int ms_pwr_dbm(enum gsm_band band, uint8_t lvl);
|
||||
|
|
|
@ -0,0 +1,186 @@
|
|||
#ifndef _OSMOCOM_LAPDM_H
|
||||
#define _OSMOCOM_LAPDM_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <osmocom/core/timer.h>
|
||||
#include <osmocom/core/msgb.h>
|
||||
#include <osmocom/gsm/prim.h>
|
||||
|
||||
/* primitive related sutff */
|
||||
|
||||
enum osmo_ph_prim {
|
||||
PRIM_PH_DATA, /* PH-DATA */
|
||||
PRIM_PH_RACH, /* PH-RANDOM_ACCESS */
|
||||
PRIM_PH_CONN, /* PH-CONNECT */
|
||||
PRIM_PH_EMPTY_FRAME, /* PH-EMPTY_FRAME */
|
||||
PRIM_PH_RTS, /* PH-RTS */
|
||||
};
|
||||
|
||||
/* for PH-RANDOM_ACCESS.req */
|
||||
struct ph_rach_req_param {
|
||||
uint8_t ra;
|
||||
uint8_t ta;
|
||||
uint8_t tx_power;
|
||||
uint8_t is_combined_ccch;
|
||||
uint16_t offset;
|
||||
};
|
||||
|
||||
/* for PH-RANDOM_ACCESS.ind */
|
||||
struct ph_rach_ind_param {
|
||||
uint8_t ra;
|
||||
uint8_t acc_delay;
|
||||
uint32_t fn;
|
||||
};
|
||||
|
||||
/* for PH-[UNIT]DATA.{req,ind} */
|
||||
struct ph_data_param {
|
||||
uint8_t link_id;
|
||||
uint8_t chan_nr;
|
||||
};
|
||||
|
||||
struct ph_conn_ind_param {
|
||||
uint32_t fn;
|
||||
};
|
||||
|
||||
struct osmo_phsap_prim {
|
||||
struct osmo_prim_hdr oph;
|
||||
union {
|
||||
struct ph_data_param data;
|
||||
struct ph_rach_req_param rach_req;
|
||||
struct ph_rach_ind_param rach_ind;
|
||||
struct ph_conn_ind_param conn_ind;
|
||||
} u;
|
||||
};
|
||||
|
||||
enum lapdm_mode {
|
||||
LAPDM_MODE_MS,
|
||||
LAPDM_MODE_BTS,
|
||||
};
|
||||
|
||||
enum lapdm_state {
|
||||
LAPDm_STATE_NULL = 0,
|
||||
LAPDm_STATE_IDLE,
|
||||
LAPDm_STATE_SABM_SENT,
|
||||
LAPDm_STATE_MF_EST,
|
||||
LAPDm_STATE_TIMER_RECOV,
|
||||
LAPDm_STATE_DISC_SENT,
|
||||
};
|
||||
|
||||
struct lapdm_entity;
|
||||
|
||||
struct lapdm_msg_ctx {
|
||||
struct lapdm_datalink *dl;
|
||||
int lapdm_fmt;
|
||||
uint8_t n201;
|
||||
uint8_t chan_nr;
|
||||
uint8_t link_id;
|
||||
uint8_t addr;
|
||||
uint8_t ctrl;
|
||||
uint8_t ta_ind;
|
||||
uint8_t tx_power_ind;
|
||||
};
|
||||
|
||||
/* TS 04.06 / Section 3.5.2 */
|
||||
struct lapdm_datalink {
|
||||
uint8_t V_send; /* seq nr of next I frame to be transmitted */
|
||||
uint8_t V_ack; /* last frame ACKed by peer */
|
||||
uint8_t N_send; /* ? set to V_send at Tx time*/
|
||||
uint8_t V_recv; /* seq nr of next I frame expected to be received */
|
||||
uint8_t N_recv; /* expected send seq nr of the next received I frame */
|
||||
uint32_t state;
|
||||
int seq_err_cond; /* condition of sequence error */
|
||||
uint8_t own_busy, peer_busy;
|
||||
struct osmo_timer_list t200;
|
||||
uint8_t retrans_ctr;
|
||||
struct llist_head send_queue; /* frames from L3 */
|
||||
struct msgb *send_buffer; /* current frame transmitting */
|
||||
int send_out; /* how much was sent from send_buffer */
|
||||
uint8_t tx_hist[8][200]; /* tx history buffer */
|
||||
int tx_length[8]; /* length in history buffer */
|
||||
struct llist_head tx_queue; /* frames to L1 */
|
||||
struct lapdm_msg_ctx mctx; /* context of established connection */
|
||||
struct msgb *rcv_buffer; /* buffer to assemble the received message */
|
||||
|
||||
struct lapdm_entity *entity;
|
||||
};
|
||||
|
||||
enum lapdm_dl_sapi {
|
||||
DL_SAPI0 = 0,
|
||||
DL_SAPI3 = 1,
|
||||
_NR_DL_SAPI
|
||||
};
|
||||
|
||||
typedef int (*lapdm_cb_t)(struct msgb *msg, struct lapdm_entity *le, void *ctx);
|
||||
|
||||
struct lapdm_cr_ent {
|
||||
uint8_t cmd;
|
||||
uint8_t resp;
|
||||
};
|
||||
|
||||
#define LAPDM_ENT_F_EMPTY_FRAME 0x0001
|
||||
#define LAPDM_ENT_F_POLLING_ONLY 0x0002
|
||||
|
||||
/* register message handler for messages that are sent from L2->L3 */
|
||||
struct lapdm_entity {
|
||||
struct lapdm_datalink datalink[_NR_DL_SAPI];
|
||||
int last_tx_dequeue; /* last entity that was dequeued */
|
||||
int tx_pending; /* currently a pending frame not confirmed by L1 */
|
||||
enum lapdm_mode mode; /* are we in BTS mode or MS mode */
|
||||
unsigned int flags;
|
||||
|
||||
struct {
|
||||
/* filled-in once we set the lapdm_mode above */
|
||||
struct lapdm_cr_ent loc2rem;
|
||||
struct lapdm_cr_ent rem2loc;
|
||||
} cr;
|
||||
|
||||
void *l1_ctx; /* context for layer1 instance */
|
||||
void *l3_ctx; /* context for layer3 instance */
|
||||
|
||||
osmo_prim_cb l1_prim_cb;
|
||||
lapdm_cb_t l3_cb; /* callback for sending stuff to L3 */
|
||||
|
||||
struct lapdm_channel *lapdm_ch;
|
||||
};
|
||||
|
||||
/* the two lapdm_entities that form a GSM logical channel (ACCH + DCCH) */
|
||||
struct lapdm_channel {
|
||||
struct llist_head list;
|
||||
char *name;
|
||||
struct lapdm_entity lapdm_acch;
|
||||
struct lapdm_entity lapdm_dcch;
|
||||
};
|
||||
|
||||
const char *get_rsl_name(int value);
|
||||
extern const char *lapdm_state_names[];
|
||||
|
||||
/* initialize a LAPDm entity */
|
||||
void lapdm_entity_init(struct lapdm_entity *le, enum lapdm_mode mode);
|
||||
void lapdm_channel_init(struct lapdm_channel *lc, enum lapdm_mode mode);
|
||||
|
||||
/* deinitialize a LAPDm entity */
|
||||
void lapdm_entity_exit(struct lapdm_entity *le);
|
||||
void lapdm_channel_exit(struct lapdm_channel *lc);
|
||||
|
||||
/* input into layer2 (from layer 1) */
|
||||
int lapdm_phsap_up(struct osmo_prim_hdr *oph, struct lapdm_entity *le);
|
||||
|
||||
/* input into layer2 (from layer 3) */
|
||||
int lapdm_rslms_recvmsg(struct msgb *msg, struct lapdm_channel *lc);
|
||||
|
||||
void lapdm_channel_set_l3(struct lapdm_channel *lc, lapdm_cb_t cb, void *ctx);
|
||||
void lapdm_channel_set_l1(struct lapdm_channel *lc, osmo_prim_cb cb, void *ctx);
|
||||
|
||||
int lapdm_entity_set_mode(struct lapdm_entity *le, enum lapdm_mode mode);
|
||||
int lapdm_channel_set_mode(struct lapdm_channel *lc, enum lapdm_mode mode);
|
||||
|
||||
void lapdm_entity_reset(struct lapdm_entity *le);
|
||||
void lapdm_channel_reset(struct lapdm_channel *lc);
|
||||
|
||||
void lapdm_entity_set_flags(struct lapdm_entity *le, unsigned int flags);
|
||||
void lapdm_channel_set_flags(struct lapdm_channel *lc, unsigned int flags);
|
||||
|
||||
int lapdm_phsap_dequeue_prim(struct lapdm_entity *le, struct osmo_phsap_prim *pp);
|
||||
|
||||
#endif /* _OSMOCOM_LAPDM_H */
|
|
@ -33,6 +33,7 @@ enum ipaccess_proto_ext {
|
|||
IPAC_PROTO_EXT_CTRL = 0x00,
|
||||
IPAC_PROTO_EXT_MGCP = 0x01,
|
||||
IPAC_PROTO_EXT_LAC = 0x02,
|
||||
IPAC_PROTO_EXT_SMSC = 0x03,
|
||||
};
|
||||
|
||||
enum ipaccess_msgtype {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/core/msgb.h>
|
||||
#include <osmocom/gsm/protocol/gsm_08_58.h>
|
||||
|
||||
void rsl_init_rll_hdr(struct abis_rsl_rll_hdr *dh, uint8_t msg_type);
|
||||
|
|
|
@ -236,11 +236,11 @@ struct tlv_def {
|
|||
};
|
||||
|
||||
struct tlv_definition {
|
||||
struct tlv_def def[0xff];
|
||||
struct tlv_def def[256];
|
||||
};
|
||||
|
||||
struct tlv_parsed {
|
||||
struct tlv_p_entry lv[0xff];
|
||||
struct tlv_p_entry lv[256];
|
||||
};
|
||||
|
||||
extern struct tlv_definition tvlv_att_def;
|
||||
|
|
|
@ -74,6 +74,9 @@ enum node_type {
|
|||
|
||||
VTY_NODE, /* Vty node. */
|
||||
|
||||
L_E1INP_NODE, /* E1 line in libosmo-abis. */
|
||||
L_IPA_NODE, /* IPA proxying commands in libosmo-abis. */
|
||||
|
||||
_LAST_OSMOVTY_NODE
|
||||
};
|
||||
|
||||
|
@ -134,7 +137,7 @@ struct desc {
|
|||
#define CMD_SUCCESS_DAEMON 10
|
||||
|
||||
/* Argc max counts. */
|
||||
#define CMD_ARGC_MAX 25
|
||||
#define CMD_ARGC_MAX 256
|
||||
|
||||
/* Turn off these macros when uisng cpp with extract.pl */
|
||||
#ifndef VTYSH_EXTRACT_PL
|
||||
|
@ -316,7 +319,7 @@ void install_node(struct cmd_node *, int (*)(struct vty *));
|
|||
void install_default(enum node_type);
|
||||
void install_element(enum node_type, struct cmd_element *);
|
||||
void install_element_ve(struct cmd_element *cmd);
|
||||
void sort_node();
|
||||
void sort_node(void);
|
||||
|
||||
/* Concatenates argv[shift] through argv[argc-1] into a single NUL-terminated
|
||||
string with a space between each element (allocated using
|
||||
|
|
|
@ -14,7 +14,7 @@ libosmocore_la_SOURCES = timer.c select.c signal.c msgb.c bits.c \
|
|||
write_queue.c utils.c socket.c \
|
||||
logging.c logging_syslog.c rate_ctr.c \
|
||||
gsmtap_util.c crc16.c panic.c backtrace.c \
|
||||
process.c conv.c application.c
|
||||
conv.c application.c
|
||||
|
||||
if ENABLE_PLUGIN
|
||||
libosmocore_la_SOURCES += plugin.c
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* Utility functions to setup applications */
|
||||
/*
|
||||
* (C) 2010 by Harald Welte <laforge@gnumonks.org>
|
||||
* (C) 2011 by Holger Hans Peter Freyther
|
||||
*
|
||||
* All Rights Reserved
|
||||
|
@ -24,6 +25,11 @@
|
|||
#include <osmocom/core/logging.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
struct log_target *osmo_stderr_target;
|
||||
|
||||
|
@ -38,7 +44,7 @@ void osmo_init_ignore_signals(void)
|
|||
|
||||
int osmo_init_logging(const struct log_info *log_info)
|
||||
{
|
||||
log_init(log_info);
|
||||
log_init(log_info, NULL);
|
||||
osmo_stderr_target = log_target_create_stderr();
|
||||
if (!osmo_stderr_target)
|
||||
return -1;
|
||||
|
@ -47,3 +53,50 @@ int osmo_init_logging(const struct log_info *log_info)
|
|||
log_set_all_filter(osmo_stderr_target, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int osmo_daemonize(void)
|
||||
{
|
||||
int rc;
|
||||
pid_t pid, sid;
|
||||
|
||||
/* Check if parent PID == init, in which case we are already a daemon */
|
||||
if (getppid() == 1)
|
||||
return -EEXIST;
|
||||
|
||||
/* Fork from the parent process */
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
/* some error happened */
|
||||
return pid;
|
||||
}
|
||||
|
||||
if (pid > 0) {
|
||||
/* if we have received a positive PID, then we are the parent
|
||||
* and can exit */
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* FIXME: do we really want this? */
|
||||
umask(0);
|
||||
|
||||
/* Create a new session and set process group ID */
|
||||
sid = setsid();
|
||||
if (sid < 0)
|
||||
return sid;
|
||||
|
||||
/* Change to the /tmp directory, which prevents the CWD from being locked
|
||||
* and unable to remove it */
|
||||
rc = chdir("/tmp");
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
/* Redirect stdio to /dev/null */
|
||||
/* since C89/C99 says stderr is a macro, we can safely do this! */
|
||||
#ifdef stderr
|
||||
freopen("/dev/null", "r", stdin);
|
||||
freopen("/dev/null", "w", stdout);
|
||||
freopen("/dev/null", "w", stderr);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
#include <execinfo.h>
|
||||
void osmo_generate_backtrace()
|
||||
void osmo_generate_backtrace(void)
|
||||
{
|
||||
int i, nptrs;
|
||||
void *buffer[100];
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# This is _NOT_ the library release version, it's an API version.
|
||||
# Please read Chapter 6 "Library interface versions" of the libtool documentation before making any modification
|
||||
LIBVERSION=0:0:0
|
||||
LIBVERSION=1:0:0
|
||||
|
||||
INCLUDES = $(all_includes) -I$(top_srcdir)/include
|
||||
AM_CFLAGS = -fPIC -Wall
|
||||
|
@ -9,6 +9,7 @@ lib_LTLIBRARIES = libosmogsm.la
|
|||
|
||||
libosmogsm_la_SOURCES = a5.c rxlev_stat.c tlv_parser.c comp128.c gsm_utils.c \
|
||||
rsl.c gsm48.c gsm48_ie.c gsm0808.c sysinfo.c \
|
||||
gprs_cipher_core.c gsm0480.c abis_nm.c
|
||||
gprs_cipher_core.c gsm0480.c abis_nm.c gsm0502.c \
|
||||
lapdm.c
|
||||
libosmogsm_la_LDFLAGS = -version-info $(LIBVERSION)
|
||||
libosmogsm_la_LIBADD = $(top_builddir)/src/libosmocore.la
|
||||
|
|
|
@ -399,6 +399,7 @@ void abis_nm_debugp_foh(int ss, struct abis_om_fom_hdr *foh)
|
|||
}
|
||||
|
||||
static const enum abis_nm_chan_comb chcomb4pchan[] = {
|
||||
[GSM_PCHAN_NONE] = 0xff,
|
||||
[GSM_PCHAN_CCCH] = NM_CHANC_mainBCCH,
|
||||
[GSM_PCHAN_CCCH_SDCCH4] = NM_CHANC_BCCHComb,
|
||||
[GSM_PCHAN_TCH_F] = NM_CHANC_TCHFull,
|
||||
|
@ -406,6 +407,7 @@ static const enum abis_nm_chan_comb chcomb4pchan[] = {
|
|||
[GSM_PCHAN_SDCCH8_SACCH8C] = NM_CHANC_SDCCH,
|
||||
[GSM_PCHAN_PDCH] = NM_CHANC_IPAC_PDCH,
|
||||
[GSM_PCHAN_TCH_F_PDCH] = NM_CHANC_IPAC_TCHFull_PDCH,
|
||||
[GSM_PCHAN_UNKNOWN] = 0xff,
|
||||
/* FIXME: bounds check */
|
||||
};
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ static struct gprs_cipher_impl *selected_ciphers[_GPRS_ALGO_NUM];
|
|||
/* register a cipher with the core */
|
||||
int gprs_cipher_register(struct gprs_cipher_impl *ciph)
|
||||
{
|
||||
if (ciph->algo > ARRAY_SIZE(selected_ciphers))
|
||||
if (ciph->algo >= ARRAY_SIZE(selected_ciphers))
|
||||
return -ERANGE;
|
||||
|
||||
llist_add_tail(&ciph->list, &gprs_ciphers);
|
||||
|
@ -60,7 +60,7 @@ int gprs_cipher_load(const char *path)
|
|||
int gprs_cipher_run(uint8_t *out, uint16_t len, enum gprs_ciph_algo algo,
|
||||
uint64_t kc, uint32_t iv, enum gprs_cipher_direction dir)
|
||||
{
|
||||
if (algo > ARRAY_SIZE(selected_ciphers))
|
||||
if (algo >= ARRAY_SIZE(selected_ciphers))
|
||||
return -ERANGE;
|
||||
|
||||
if (!selected_ciphers[algo])
|
||||
|
@ -75,7 +75,7 @@ int gprs_cipher_run(uint8_t *out, uint16_t len, enum gprs_ciph_algo algo,
|
|||
|
||||
int gprs_cipher_supported(enum gprs_ciph_algo algo)
|
||||
{
|
||||
if (algo > ARRAY_SIZE(selected_ciphers))
|
||||
if (algo >= ARRAY_SIZE(selected_ciphers))
|
||||
return -ERANGE;
|
||||
|
||||
if (selected_ciphers[algo])
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/* Paging helper code */
|
||||
|
||||
/* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <osmocom/gsm/protocol/gsm_04_08.h>
|
||||
#include <osmocom/gsm/gsm0502.h>
|
||||
#include <osmocom/gsm/gsm48.h>
|
||||
#include <osmocom/gsm/rsl.h>
|
||||
|
||||
unsigned int
|
||||
gsm0502_calc_paging_group(struct gsm48_control_channel_descr *chan_desc, uint64_t imsi)
|
||||
{
|
||||
int ccch_conf;
|
||||
int bs_cc_chans;
|
||||
int blocks;
|
||||
unsigned int group;
|
||||
|
||||
ccch_conf = chan_desc->ccch_conf;
|
||||
bs_cc_chans = rsl_ccch_conf_to_bs_cc_chans(ccch_conf);
|
||||
/* code word + 2, as 2 channels equals 0x0 */
|
||||
blocks = gsm48_number_of_paging_subchannels(chan_desc);
|
||||
group = gsm0502_get_paging_group(imsi, bs_cc_chans, blocks);
|
||||
|
||||
return group;
|
||||
}
|
|
@ -159,7 +159,7 @@ struct msgb *gsm0808_create_cipher_reject(uint8_t cause)
|
|||
if (!msg)
|
||||
return NULL;
|
||||
|
||||
msg->l3h = msgb_put(msg, 3);
|
||||
msg->l3h = msgb_put(msg, 4);
|
||||
msg->l3h[0] = BSSAP_MSG_BSS_MANAGEMENT;
|
||||
msg->l3h[1] = 2;
|
||||
msg->l3h[2] = BSS_MAP_MSG_CIPHER_MODE_REJECT;
|
||||
|
@ -363,7 +363,93 @@ static const struct tlv_definition bss_att_tlvdef = {
|
|||
},
|
||||
};
|
||||
|
||||
const struct tlv_definition *gsm0808_att_tlvdef()
|
||||
const struct tlv_definition *gsm0808_att_tlvdef(void)
|
||||
{
|
||||
return &bss_att_tlvdef;
|
||||
}
|
||||
|
||||
static const struct value_string gsm0808_msgt_names[] = {
|
||||
{ BSS_MAP_MSG_ASSIGMENT_RQST, "ASSIGNMENT REQ" },
|
||||
{ BSS_MAP_MSG_ASSIGMENT_COMPLETE, "ASSIGNMENT COMPL" },
|
||||
{ BSS_MAP_MSG_ASSIGMENT_FAILURE, "ASSIGNMENT FAIL" },
|
||||
|
||||
{ BSS_MAP_MSG_HANDOVER_RQST, "HANDOVER REQ" },
|
||||
{ BSS_MAP_MSG_HANDOVER_REQUIRED, "HANDOVER REQUIRED" },
|
||||
{ BSS_MAP_MSG_HANDOVER_RQST_ACKNOWLEDGE,"HANDOVER REQ ACK" },
|
||||
{ BSS_MAP_MSG_HANDOVER_CMD, "HANDOVER CMD" },
|
||||
{ BSS_MAP_MSG_HANDOVER_COMPLETE, "HANDOVER COMPLETE" },
|
||||
{ BSS_MAP_MSG_HANDOVER_SUCCEEDED, "HANDOVER SUCCESS" },
|
||||
{ BSS_MAP_MSG_HANDOVER_FAILURE, "HANDOVER FAILURE" },
|
||||
{ BSS_MAP_MSG_HANDOVER_PERFORMED, "HANDOVER PERFORMED" },
|
||||
{ BSS_MAP_MSG_HANDOVER_CANDIDATE_ENQUIRE, "HANDOVER CAND ENQ" },
|
||||
{ BSS_MAP_MSG_HANDOVER_CANDIDATE_RESPONSE, "HANDOVER CAND RESP" },
|
||||
{ BSS_MAP_MSG_HANDOVER_REQUIRED_REJECT, "HANDOVER REQ REJ" },
|
||||
{ BSS_MAP_MSG_HANDOVER_DETECT, "HANDOVER DETECT" },
|
||||
|
||||
{ BSS_MAP_MSG_CLEAR_CMD, "CLEAR COMMAND" },
|
||||
{ BSS_MAP_MSG_CLEAR_COMPLETE, "CLEAR COMPLETE" },
|
||||
{ BSS_MAP_MSG_CLEAR_RQST, "CLEAR REQUEST" },
|
||||
{ BSS_MAP_MSG_SAPI_N_REJECT, "SAPI N REJECT" },
|
||||
{ BSS_MAP_MSG_CONFUSION, "CONFUSION" },
|
||||
|
||||
{ BSS_MAP_MSG_SUSPEND, "SUSPEND" },
|
||||
{ BSS_MAP_MSG_RESUME, "RESUME" },
|
||||
{ BSS_MAP_MSG_CONNECTION_ORIENTED_INFORMATION, "CONN ORIENT INFO" },
|
||||
{ BSS_MAP_MSG_PERFORM_LOCATION_RQST, "PERFORM LOC REQ" },
|
||||
{ BSS_MAP_MSG_LSA_INFORMATION, "LSA INFORMATION" },
|
||||
{ BSS_MAP_MSG_PERFORM_LOCATION_RESPONSE, "PERFORM LOC RESP" },
|
||||
{ BSS_MAP_MSG_PERFORM_LOCATION_ABORT, "PERFORM LOC ABORT" },
|
||||
{ BSS_MAP_MSG_COMMON_ID, "COMMON ID" },
|
||||
|
||||
{ BSS_MAP_MSG_RESET, "RESET" },
|
||||
{ BSS_MAP_MSG_RESET_ACKNOWLEDGE, "RESET ACK" },
|
||||
{ BSS_MAP_MSG_OVERLOAD, "OVERLOAD" },
|
||||
{ BSS_MAP_MSG_RESET_CIRCUIT, "RESET CIRCUIT" },
|
||||
{ BSS_MAP_MSG_RESET_CIRCUIT_ACKNOWLEDGE, "RESET CIRCUIT ACK" },
|
||||
{ BSS_MAP_MSG_MSC_INVOKE_TRACE, "MSC INVOKE TRACE" },
|
||||
{ BSS_MAP_MSG_BSS_INVOKE_TRACE, "BSS INVOKE TRACE" },
|
||||
{ BSS_MAP_MSG_CONNECTIONLESS_INFORMATION, "CONNLESS INFO" },
|
||||
|
||||
{ BSS_MAP_MSG_BLOCK, "BLOCK" },
|
||||
{ BSS_MAP_MSG_BLOCKING_ACKNOWLEDGE, "BLOCK ACK" },
|
||||
{ BSS_MAP_MSG_UNBLOCK, "UNBLOCK" },
|
||||
{ BSS_MAP_MSG_UNBLOCKING_ACKNOWLEDGE, "UNBLOCK ACK" },
|
||||
{ BSS_MAP_MSG_CIRCUIT_GROUP_BLOCK, "CIRC GROUP BLOCK" },
|
||||
{ BSS_MAP_MSG_CIRCUIT_GROUP_BLOCKING_ACKNOWLEDGE, "CIRC GORUP BLOCK ACK" },
|
||||
{ BSS_MAP_MSG_CIRCUIT_GROUP_UNBLOCK, "CIRC GROUP UNBLOCK" },
|
||||
{ BSS_MAP_MSG_CIRCUIT_GROUP_UNBLOCKING_ACKNOWLEDGE, "CIRC GROUP UNBLOCK ACK" },
|
||||
{ BSS_MAP_MSG_UNEQUIPPED_CIRCUIT, "UNEQUIPPED CIRCUIT" },
|
||||
{ BSS_MAP_MSG_CHANGE_CIRCUIT, "CHANGE CIRCUIT" },
|
||||
{ BSS_MAP_MSG_CHANGE_CIRCUIT_ACKNOWLEDGE, "CHANGE CIRCUIT ACK" },
|
||||
|
||||
{ BSS_MAP_MSG_RESOURCE_RQST, "RESOURCE REQ" },
|
||||
{ BSS_MAP_MSG_RESOURCE_INDICATION, "RESOURCE IND" },
|
||||
{ BSS_MAP_MSG_PAGING, "PAGING" },
|
||||
{ BSS_MAP_MSG_CIPHER_MODE_CMD, "CIPHER MODE CMD" },
|
||||
{ BSS_MAP_MSG_CLASSMARK_UPDATE, "CLASSMARK UPDATE" },
|
||||
{ BSS_MAP_MSG_CIPHER_MODE_COMPLETE, "CIPHER MODE COMPLETE" },
|
||||
{ BSS_MAP_MSG_QUEUING_INDICATION, "QUEUING INDICATION" },
|
||||
{ BSS_MAP_MSG_COMPLETE_LAYER_3, "COMPLETE LAYER 3" },
|
||||
{ BSS_MAP_MSG_CLASSMARK_RQST, "CLASSMARK REQ" },
|
||||
{ BSS_MAP_MSG_CIPHER_MODE_REJECT, "CIPHER MODE REJECT" },
|
||||
{ BSS_MAP_MSG_LOAD_INDICATION, "LOAD IND" },
|
||||
|
||||
/* FIXME: VGCS/VBS */
|
||||
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
const char *gsm0808_bssmap_name(uint8_t msg_type)
|
||||
{
|
||||
return get_value_string(gsm0808_msgt_names, msg_type);
|
||||
}
|
||||
|
||||
static const struct value_string gsm0808_bssap_names[] = {
|
||||
{ BSSAP_MSG_BSS_MANAGEMENT, "MANAGEMENT" },
|
||||
{ BSSAP_MSG_DTAP, "DTAP" },
|
||||
};
|
||||
|
||||
const char *gsm0808_bssap_name(uint8_t msg_type)
|
||||
{
|
||||
return get_value_string(gsm0808_bssap_names, msg_type);
|
||||
}
|
||||
|
|
|
@ -31,8 +31,10 @@
|
|||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/gsm/tlv.h>
|
||||
#include <osmocom/gsm/gsm48.h>
|
||||
#include <osmocom/gsm/gsm0502.h>
|
||||
|
||||
#include <osmocom/gsm/protocol/gsm_04_08.h>
|
||||
#include <osmocom/gsm/protocol/gsm_08_58.h>
|
||||
|
||||
const struct tlv_definition gsm48_att_tlvdef = {
|
||||
.def = {
|
||||
|
@ -413,3 +415,14 @@ int gsm48_construct_ra(uint8_t *buf, const struct gprs_ra_id *raid)
|
|||
|
||||
return 6;
|
||||
}
|
||||
|
||||
/* From Table 10.5.33 of GSM 04.08 */
|
||||
int gsm48_number_of_paging_subchannels(struct gsm48_control_channel_descr *chan_desc)
|
||||
{
|
||||
unsigned int n_pag_blocks = gsm0502_get_n_pag_blocks(chan_desc);
|
||||
|
||||
if (chan_desc->ccch_conf == RSL_BCCH_CCCH_CONF_1_C)
|
||||
return OSMO_MAX(1, n_pag_blocks) * (chan_desc->bs_pa_mfrms + 2);
|
||||
else
|
||||
return n_pag_blocks * (chan_desc->bs_pa_mfrms + 2);
|
||||
}
|
||||
|
|
|
@ -66,35 +66,51 @@ static unsigned char gsm_7bit_alphabet[] = {
|
|||
static int gsm_septet_lookup(uint8_t ch)
|
||||
{
|
||||
int i = 0;
|
||||
for(; i < sizeof(gsm_7bit_alphabet); i++){
|
||||
if(gsm_7bit_alphabet[i] == ch)
|
||||
for (; i < sizeof(gsm_7bit_alphabet); i++) {
|
||||
if (gsm_7bit_alphabet[i] == ch)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Compute the number of octets from the number of septets, for instance: 47 septets needs 41,125 = 42 octets */
|
||||
uint8_t gsm_get_octet_len(const uint8_t sept_len){
|
||||
int octet_len = (sept_len * 7) / 8;
|
||||
if ((sept_len * 7) % 8 != 0)
|
||||
octet_len++;
|
||||
|
||||
return octet_len;
|
||||
}
|
||||
|
||||
/* GSM 03.38 6.2.1 Character unpacking */
|
||||
int gsm_7bit_decode(char *text, const uint8_t *user_data, uint8_t length)
|
||||
int gsm_7bit_decode_hdr(char *text, const uint8_t *user_data, uint8_t septet_l, uint8_t ud_hdr_ind)
|
||||
{
|
||||
int i = 0;
|
||||
int l = 0;
|
||||
int septet_l = (length * 8) / 7;
|
||||
int shift = 0;
|
||||
|
||||
uint8_t *rtext = calloc(septet_l, sizeof(uint8_t));
|
||||
uint8_t tmp;
|
||||
|
||||
/* FIXME: We need to account for user data headers here */
|
||||
i += l;
|
||||
for (; i < septet_l; i++){
|
||||
rtext[i] =
|
||||
((user_data[(i * 7 + 7) >> 3] <<
|
||||
(7 - ((i * 7 + 7) & 7))) |
|
||||
(user_data[(i * 7) >> 3] >>
|
||||
((i * 7) & 7))) & 0x7f;
|
||||
/* skip the user data header */
|
||||
if (ud_hdr_ind) {
|
||||
/* get user data header length + 1 (for the 'user data header length'-field) */
|
||||
shift = ((user_data[0] + 1) * 8) / 7;
|
||||
if ((((user_data[0] + 1) * 8) % 7) != 0)
|
||||
shift++;
|
||||
septet_l = septet_l - shift;
|
||||
}
|
||||
|
||||
for(i = 0; i < septet_l; i++){
|
||||
for (i = 0; i < septet_l; i++) {
|
||||
rtext[i] =
|
||||
((user_data[((i + shift) * 7 + 7) >> 3] <<
|
||||
(7 - (((i + shift) * 7 + 7) & 7))) |
|
||||
(user_data[((i + shift) * 7) >> 3] >>
|
||||
(((i + shift) * 7) & 7))) & 0x7f;
|
||||
}
|
||||
|
||||
for (i = 0; i < septet_l; i++) {
|
||||
/* this is an extension character */
|
||||
if(rtext[i] == 0x1b && i + 1 < length){
|
||||
if(rtext[i] == 0x1b && i + 1 < septet_l){
|
||||
tmp = rtext[i+1];
|
||||
*(text++) = gsm_7bit_alphabet[0x7f + tmp];
|
||||
i++;
|
||||
|
@ -104,18 +120,25 @@ int gsm_7bit_decode(char *text, const uint8_t *user_data, uint8_t length)
|
|||
*(text++) = gsm_septet_lookup(rtext[i]);
|
||||
}
|
||||
|
||||
if (ud_hdr_ind)
|
||||
i += shift;
|
||||
*text = '\0';
|
||||
free(rtext);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
int gsm_7bit_decode(char *text, const uint8_t *user_data, uint8_t septet_l)
|
||||
{
|
||||
return gsm_7bit_decode_hdr(text, user_data, septet_l, 0);
|
||||
}
|
||||
|
||||
/* GSM 03.38 6.2.1 Prepare character packing */
|
||||
static int gsm_septet_encode(uint8_t *result, const char *data)
|
||||
int gsm_septet_encode(uint8_t *result, const char *data)
|
||||
{
|
||||
int i, y = 0;
|
||||
uint8_t ch;
|
||||
for(i = 0; i < strlen(data); i++){
|
||||
for (i = 0; i < strlen(data); i++) {
|
||||
ch = data[i];
|
||||
switch(ch){
|
||||
/* fall-through for extension characters */
|
||||
|
@ -139,38 +162,75 @@ static int gsm_septet_encode(uint8_t *result, const char *data)
|
|||
return y;
|
||||
}
|
||||
|
||||
/* GSM 03.38 6.2.1 Character packing */
|
||||
int gsm_7bit_encode(uint8_t *result, const char *data)
|
||||
{
|
||||
int i,y,z = 0;
|
||||
/* prepare for the worst case, every character expanding to two bytes */
|
||||
uint8_t *rdata = calloc(strlen(data) * 2, sizeof(uint8_t));
|
||||
/* 7bit to octet packing */
|
||||
int gsm_septets2octets(uint8_t *result, uint8_t *rdata, uint8_t septet_len, uint8_t padding){
|
||||
int i = 0, z = 0;
|
||||
uint8_t cb, nb;
|
||||
int shift = 0;
|
||||
uint8_t *data = calloc(septet_len + 1, sizeof(uint8_t));
|
||||
|
||||
y = gsm_septet_encode(rdata, data);
|
||||
if (padding) {
|
||||
shift = 7 - padding;
|
||||
/* the first zero is needed for padding */
|
||||
memcpy(data + 1, rdata, septet_len);
|
||||
septet_len++;
|
||||
} else
|
||||
memcpy(data, rdata, septet_len);
|
||||
|
||||
for(i = 0; i < y; i++) {
|
||||
if(shift == 7 && i + 1 < y){
|
||||
shift = 0;
|
||||
continue;
|
||||
for (i = 0; i < septet_len; i++) {
|
||||
if (shift == 7) {
|
||||
/*
|
||||
* special end case with the. This is necessary if the
|
||||
* last septet fits into the previous octet. E.g. 48
|
||||
* non-extension characters:
|
||||
* ....ag ( a = 1100001, g = 1100111)
|
||||
* result[40] = 100001 XX, result[41] = 1100111 1 */
|
||||
if (i + 1 < septet_len) {
|
||||
shift = 0;
|
||||
continue;
|
||||
} else if (i + 1 == septet_len)
|
||||
break;
|
||||
}
|
||||
|
||||
cb = (rdata[i] & 0x7f) >> shift;
|
||||
if(i + 1 < y){
|
||||
nb = (rdata[i + 1] & 0x7f) << (7 - shift);
|
||||
cb = (data[i] & 0x7f) >> shift;
|
||||
if (i + 1 < septet_len) {
|
||||
nb = (data[i + 1] & 0x7f) << (7 - shift);
|
||||
cb = cb | nb;
|
||||
}
|
||||
|
||||
result[z++] = cb;
|
||||
|
||||
shift++;
|
||||
}
|
||||
|
||||
free(rdata);
|
||||
free(data);
|
||||
|
||||
return z;
|
||||
}
|
||||
|
||||
/* GSM 03.38 6.2.1 Character packing */
|
||||
int gsm_7bit_encode(uint8_t *result, const char *data)
|
||||
{
|
||||
int y = 0, z = 0;
|
||||
/* prepare for the worst case, every character expanding to two bytes */
|
||||
uint8_t *rdata = calloc(strlen(data) * 2, sizeof(uint8_t));
|
||||
y = gsm_septet_encode(rdata, data);
|
||||
z = gsm_septets2octets(result, rdata, y, 0);
|
||||
|
||||
free(rdata);
|
||||
|
||||
/*
|
||||
* We don't care about the number of octets (z), because they are not
|
||||
* unique. E.g.:
|
||||
* 1.) 46 non-extension characters + 1 extension character
|
||||
* => (46 * 7 bit + (1 * (2 * 7 bit))) / 8 bit = 42 octets
|
||||
* 2.) 47 non-extension characters
|
||||
* => (47 * 7 bit) / 8 bit = 41,125 = 42 octets
|
||||
* 3.) 48 non-extension characters
|
||||
* => (48 * 7 bit) / 8 bit = 42 octects
|
||||
*/
|
||||
return y;
|
||||
}
|
||||
|
||||
/* convert power class to dBm according to GSM TS 05.05 */
|
||||
unsigned int ms_class_gmsk_dbm(enum gsm_band band, int class)
|
||||
{
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -40,7 +40,7 @@
|
|||
|
||||
#include <osmocom/vty/logging.h> /* for LOGGING_STR. */
|
||||
|
||||
const struct log_info *osmo_log_info;
|
||||
struct log_info *osmo_log_info;
|
||||
|
||||
static struct log_context log_context;
|
||||
static void *tall_log_ctx = NULL;
|
||||
|
@ -58,6 +58,44 @@ static const struct value_string loglevel_strs[LOGLEVEL_DEFS+1] = {
|
|||
{ 0, NULL },
|
||||
};
|
||||
|
||||
#define INT2IDX(x) (-1*(x)-1)
|
||||
static const struct log_info_cat internal_cat[OSMO_NUM_DLIB] = {
|
||||
[INT2IDX(DLGLOBAL)] = { /* -1 becomes 0 */
|
||||
.name = "DLGLOBAL",
|
||||
.description = "Library-internal global log family",
|
||||
.loglevel = LOGL_NOTICE,
|
||||
.enabled = 1,
|
||||
},
|
||||
[INT2IDX(DLLAPDM)] = { /* -2 becomes 1 */
|
||||
.name = "DLLAPDM",
|
||||
.description = "LAPDm in libosmogsm",
|
||||
.loglevel = LOGL_NOTICE,
|
||||
.enabled = 1,
|
||||
},
|
||||
[INT2IDX(DLINP)] = {
|
||||
.name = "DINP",
|
||||
.description = "A-bis Intput Subsystem",
|
||||
.loglevel = LOGL_NOTICE,
|
||||
.enabled = 1,
|
||||
},
|
||||
[INT2IDX(DLMUX)] = {
|
||||
.name = "DMUX",
|
||||
.description = "A-bis B-Subchannel TRAU Frame Multiplex",
|
||||
.loglevel = LOGL_NOTICE,
|
||||
.enabled = 1,
|
||||
},
|
||||
[INT2IDX(DLMI)] = {
|
||||
.name = "DMI",
|
||||
.description = "A-bis Input Driver for Signalling",
|
||||
.enabled = 0, .loglevel = LOGL_NOTICE,
|
||||
},
|
||||
[INT2IDX(DLMIB)] = {
|
||||
.name = "DMIB",
|
||||
.description = "A-bis Input Driver for B-Channels (voice)",
|
||||
.enabled = 0, .loglevel = LOGL_NOTICE,
|
||||
},
|
||||
};
|
||||
|
||||
/* You have to keep this in sync with the structure loglevel_strs. */
|
||||
const char *loglevel_descriptions[LOGLEVEL_DEFS+1] = {
|
||||
"Log simply everything",
|
||||
|
@ -69,6 +107,12 @@ const char *loglevel_descriptions[LOGLEVEL_DEFS+1] = {
|
|||
NULL,
|
||||
};
|
||||
|
||||
/* special magic for negative (library-internal) log subsystem numbers */
|
||||
static int subsys_lib2index(int subsys)
|
||||
{
|
||||
return (subsys * -1) + (osmo_log_info->num_cat_user-1);
|
||||
}
|
||||
|
||||
int log_parse_level(const char *lvl)
|
||||
{
|
||||
return get_string_value(loglevel_strs, lvl);
|
||||
|
@ -84,6 +128,8 @@ int log_parse_category(const char *category)
|
|||
int i;
|
||||
|
||||
for (i = 0; i < osmo_log_info->num_cat; ++i) {
|
||||
if (osmo_log_info->cat[i].name == NULL)
|
||||
continue;
|
||||
if (!strcasecmp(osmo_log_info->cat[i].name+1, category))
|
||||
return i;
|
||||
}
|
||||
|
@ -103,7 +149,7 @@ void log_parse_category_mask(struct log_target* target, const char *_mask)
|
|||
char *category_token = NULL;
|
||||
|
||||
/* Disable everything to enable it afterwards */
|
||||
for (i = 0; i < ARRAY_SIZE(target->categories); ++i)
|
||||
for (i = 0; i < osmo_log_info->num_cat; ++i)
|
||||
target->categories[i].enabled = 0;
|
||||
|
||||
category_token = strtok(mask, ":");
|
||||
|
@ -112,6 +158,9 @@ void log_parse_category_mask(struct log_target* target, const char *_mask)
|
|||
char* colon = strstr(category_token, ",");
|
||||
int length = strlen(category_token);
|
||||
|
||||
if (!osmo_log_info->cat[i].name)
|
||||
continue;
|
||||
|
||||
if (colon)
|
||||
length = colon - category_token;
|
||||
|
||||
|
@ -189,12 +238,17 @@ err:
|
|||
target->output(target, level, buf);
|
||||
}
|
||||
|
||||
|
||||
static void _logp(unsigned int subsys, int level, char *file, int line,
|
||||
static void _logp(int subsys, int level, char *file, int line,
|
||||
int cont, const char *format, va_list ap)
|
||||
{
|
||||
struct log_target *tar;
|
||||
|
||||
if (subsys < 0)
|
||||
subsys = subsys_lib2index(subsys);
|
||||
|
||||
if (subsys > osmo_log_info->num_cat)
|
||||
subsys = DLGLOBAL;
|
||||
|
||||
llist_for_each_entry(tar, &osmo_log_target_list, entry) {
|
||||
struct log_category *category;
|
||||
int output = 0;
|
||||
|
@ -229,12 +283,12 @@ static void _logp(unsigned int subsys, int level, char *file, int line,
|
|||
* in undefined state. Since _output uses vsnprintf and it may
|
||||
* be called several times, we have to pass a copy of ap. */
|
||||
va_copy(bp, ap);
|
||||
_output(tar, subsys, level, file, line, cont, format, ap);
|
||||
_output(tar, subsys, level, file, line, cont, format, bp);
|
||||
va_end(bp);
|
||||
}
|
||||
}
|
||||
|
||||
void logp(unsigned int subsys, char *file, int line, int cont,
|
||||
void logp(int subsys, char *file, int line, int cont,
|
||||
const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
@ -244,7 +298,7 @@ void logp(unsigned int subsys, char *file, int line, int cont,
|
|||
va_end(ap);
|
||||
}
|
||||
|
||||
void logp2(unsigned int subsys, unsigned int level, char *file, int line, int cont, const char *format, ...)
|
||||
void logp2(int subsys, unsigned int level, char *file, int line, int cont, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
|
@ -326,6 +380,14 @@ struct log_target *log_target_create(void)
|
|||
if (!target)
|
||||
return NULL;
|
||||
|
||||
target->categories = talloc_zero_array(target,
|
||||
struct log_category,
|
||||
osmo_log_info->num_cat);
|
||||
if (!target->categories) {
|
||||
talloc_free(target);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
INIT_LLIST_HEAD(&target->entry);
|
||||
|
||||
/* initialize the per-category enabled/loglevel from defaults */
|
||||
|
@ -435,14 +497,18 @@ int log_target_file_reopen(struct log_target *target)
|
|||
}
|
||||
|
||||
/* This generates the logging command string for VTY. */
|
||||
const char *log_vty_command_string(const struct log_info *info)
|
||||
const char *log_vty_command_string(const struct log_info *unused_info)
|
||||
{
|
||||
struct log_info *info = osmo_log_info;
|
||||
int len = 0, offset = 0, ret, i, rem;
|
||||
int size = strlen("logging level () ()") + 1;
|
||||
char *str;
|
||||
|
||||
for (i = 0; i < info->num_cat; i++)
|
||||
for (i = 0; i < info->num_cat; i++) {
|
||||
if (info->cat[i].name == NULL)
|
||||
continue;
|
||||
size += strlen(info->cat[i].name) + 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < LOGLEVEL_DEFS; i++)
|
||||
size += strlen(loglevel_strs[i].str) + 1;
|
||||
|
@ -458,17 +524,19 @@ const char *log_vty_command_string(const struct log_info *info)
|
|||
OSMO_SNPRINTF_RET(ret, rem, offset, len);
|
||||
|
||||
for (i = 0; i < info->num_cat; i++) {
|
||||
int j, name_len = strlen(info->cat[i].name)+1;
|
||||
char name[name_len];
|
||||
if (info->cat[i].name) {
|
||||
int j, name_len = strlen(info->cat[i].name)+1;
|
||||
char name[name_len];
|
||||
|
||||
for (j = 0; j < name_len; j++)
|
||||
name[j] = tolower(info->cat[i].name[j]);
|
||||
for (j = 0; j < name_len; j++)
|
||||
name[j] = tolower(info->cat[i].name[j]);
|
||||
|
||||
name[name_len-1] = '\0';
|
||||
ret = snprintf(str + offset, rem, "%s|", name+1);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
OSMO_SNPRINTF_RET(ret, rem, offset, len);
|
||||
name[name_len-1] = '\0';
|
||||
ret = snprintf(str + offset, rem, "%s|", name+1);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
OSMO_SNPRINTF_RET(ret, rem, offset, len);
|
||||
}
|
||||
}
|
||||
offset--; /* to remove the trailing | */
|
||||
rem++;
|
||||
|
@ -504,16 +572,20 @@ err:
|
|||
}
|
||||
|
||||
/* This generates the logging command description for VTY. */
|
||||
const char *log_vty_command_description(const struct log_info *info)
|
||||
const char *log_vty_command_description(const struct log_info *unused_info)
|
||||
{
|
||||
struct log_info *info = osmo_log_info;
|
||||
char *str;
|
||||
int i, ret, len = 0, offset = 0, rem;
|
||||
unsigned int size =
|
||||
strlen(LOGGING_STR
|
||||
"Set the log level for a specified category\n") + 1;
|
||||
|
||||
for (i = 0; i < info->num_cat; i++)
|
||||
for (i = 0; i < info->num_cat; i++) {
|
||||
if (info->cat[i].name == NULL)
|
||||
continue;
|
||||
size += strlen(info->cat[i].description) + 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < LOGLEVEL_DEFS; i++)
|
||||
size += strlen(loglevel_descriptions[i]) + 1;
|
||||
|
@ -537,6 +609,8 @@ const char *log_vty_command_description(const struct log_info *info)
|
|||
OSMO_SNPRINTF_RET(ret, rem, offset, len);
|
||||
|
||||
for (i = 0; i < info->num_cat; i++) {
|
||||
if (info->cat[i].name == NULL)
|
||||
continue;
|
||||
ret = snprintf(str + offset, rem, "%s\n",
|
||||
info->cat[i].description);
|
||||
if (ret < 0)
|
||||
|
@ -555,8 +629,43 @@ err:
|
|||
return str;
|
||||
}
|
||||
|
||||
void log_init(const struct log_info *cat)
|
||||
int log_init(const struct log_info *inf, void *ctx)
|
||||
{
|
||||
tall_log_ctx = talloc_named_const(NULL, 1, "logging");
|
||||
osmo_log_info = cat;
|
||||
int i;
|
||||
|
||||
tall_log_ctx = talloc_named_const(ctx, 1, "logging");
|
||||
if (!tall_log_ctx)
|
||||
return -ENOMEM;
|
||||
|
||||
osmo_log_info = talloc_zero(tall_log_ctx, struct log_info);
|
||||
if (!osmo_log_info)
|
||||
return -ENOMEM;
|
||||
|
||||
osmo_log_info->num_cat_user = inf->num_cat;
|
||||
/* total number = number of user cat + library cat */
|
||||
osmo_log_info->num_cat = inf->num_cat + ARRAY_SIZE(internal_cat);
|
||||
|
||||
osmo_log_info->cat = talloc_zero_array(osmo_log_info,
|
||||
struct log_info_cat,
|
||||
osmo_log_info->num_cat);
|
||||
if (!osmo_log_info->cat) {
|
||||
talloc_free(osmo_log_info);
|
||||
osmo_log_info = NULL;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* copy over the user part */
|
||||
for (i = 0; i < inf->num_cat; i++) {
|
||||
memcpy(&osmo_log_info->cat[i], &inf->cat[i],
|
||||
sizeof(struct log_info_cat));
|
||||
}
|
||||
|
||||
/* copy over the library part */
|
||||
for (i = 0; i < ARRAY_SIZE(internal_cat); i++) {
|
||||
unsigned int cn = osmo_log_info->num_cat_user + i;
|
||||
memcpy(&osmo_log_info->cat[cn],
|
||||
&internal_cat[i], sizeof(struct log_info_cat));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -98,3 +98,8 @@ uint16_t msgb_length(const struct msgb *msg)
|
|||
{
|
||||
return msg->len;
|
||||
}
|
||||
|
||||
void msgb_set_talloc_ctx(void *ctx)
|
||||
{
|
||||
tall_msgb_ctx = ctx;
|
||||
}
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
/* Process handling support code */
|
||||
|
||||
/* (C) 2010 by Harald Welte <laforge@gnumonks.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
int osmo_daemonize(void)
|
||||
{
|
||||
int rc;
|
||||
pid_t pid, sid;
|
||||
|
||||
/* Check if parent PID == init, in which case we are already a daemon */
|
||||
if (getppid() == 1)
|
||||
return -EEXIST;
|
||||
|
||||
/* Fork from the parent process */
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
/* some error happened */
|
||||
return pid;
|
||||
}
|
||||
|
||||
if (pid > 0) {
|
||||
/* if we have received a positive PID, then we are the parent
|
||||
* and can exit */
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* FIXME: do we really want this? */
|
||||
umask(0);
|
||||
|
||||
/* Create a new session and set process group ID */
|
||||
sid = setsid();
|
||||
if (sid < 0)
|
||||
return sid;
|
||||
|
||||
/* Change to the /tmp directory, which prevents the CWD from being locked
|
||||
* and unable to remove it */
|
||||
rc = chdir("/tmp");
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
/* Redirect stdio to /dev/null */
|
||||
/* since C89/C99 says stderr is a macro, we can safely do this! */
|
||||
#ifdef stderr
|
||||
freopen("/dev/null", "r", stdin);
|
||||
freopen("/dev/null", "w", stdout);
|
||||
freopen("/dev/null", "w", stderr);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -47,6 +47,15 @@ int osmo_fd_register(struct osmo_fd *fd)
|
|||
if (flags < 0)
|
||||
return flags;
|
||||
|
||||
/* set close-on-exec flag */
|
||||
flags = fcntl(fd->fd, F_GETFD);
|
||||
if (flags < 0)
|
||||
return flags;
|
||||
flags |= FD_CLOEXEC;
|
||||
flags = fcntl(fd->fd, F_SETFD, flags);
|
||||
if (flags < 0)
|
||||
return flags;
|
||||
|
||||
/* Register FD */
|
||||
if (fd->fd > maxfd)
|
||||
maxfd = fd->fd;
|
||||
|
|
|
@ -80,7 +80,7 @@ int osmo_timer_pending(struct osmo_timer_list *timer)
|
|||
* If the nearest timer timed out return NULL and then we will
|
||||
* dispatch everything after the select
|
||||
*/
|
||||
struct timeval *osmo_timers_nearest()
|
||||
struct timeval *osmo_timers_nearest(void)
|
||||
{
|
||||
struct timeval current_time;
|
||||
|
||||
|
@ -107,7 +107,7 @@ struct timeval *osmo_timers_nearest()
|
|||
/*
|
||||
* Find the nearest time and update s_nearest_time
|
||||
*/
|
||||
void osmo_timers_prepare()
|
||||
void osmo_timers_prepare(void)
|
||||
{
|
||||
struct osmo_timer_list *timer, *nearest_timer = NULL;
|
||||
llist_for_each_entry(timer, &timer_list, entry) {
|
||||
|
@ -126,7 +126,7 @@ void osmo_timers_prepare()
|
|||
/*
|
||||
* fire all timers... and remove them
|
||||
*/
|
||||
int osmo_timers_update()
|
||||
int osmo_timers_update(void)
|
||||
{
|
||||
struct timeval current_time;
|
||||
struct osmo_timer_list *timer, *tmp;
|
||||
|
|
|
@ -86,6 +86,8 @@ static char *_osmo_hexdump(const unsigned char *buf, int len, char *delim)
|
|||
hexd_buff[0] = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
int len_remain = sizeof(hexd_buff) - (cur - hexd_buff);
|
||||
if (len_remain <= 0)
|
||||
break;
|
||||
int rc = snprintf(cur, len_remain, "%02x%s", buf[i], delim);
|
||||
if (rc <= 0)
|
||||
break;
|
||||
|
|
|
@ -152,7 +152,7 @@ static int is_config(struct vty *vty)
|
|||
}
|
||||
|
||||
/* Sort each node's command element according to command string. */
|
||||
void sort_node()
|
||||
void sort_node(void)
|
||||
{
|
||||
unsigned int i, j;
|
||||
struct cmd_node *cnode;
|
||||
|
|
|
@ -94,20 +94,19 @@ extern struct host host;
|
|||
|
||||
static void print_welcome(int fd)
|
||||
{
|
||||
int ret;
|
||||
static const char *msg1 = "Welcome to the ";
|
||||
static const char *msg2 = " control interface\r\n";
|
||||
char *app_name = "<unnamed>";
|
||||
const char *app_name = "<unnamed>";
|
||||
|
||||
if (host.app_info->name)
|
||||
app_name = host.app_info->name;
|
||||
|
||||
ret = write(fd, msg1, strlen(msg1));
|
||||
ret = write(fd, app_name, strlen(app_name));
|
||||
ret = write(fd, msg2, strlen(msg2));
|
||||
write(fd, msg1, strlen(msg1));
|
||||
write(fd, app_name, strlen(app_name));
|
||||
write(fd, msg2, strlen(msg2));
|
||||
|
||||
if (host.app_info->copyright)
|
||||
ret = write(fd, host.app_info->copyright, strlen(host.app_info->copyright));
|
||||
write(fd, host.app_info->copyright, strlen(host.app_info->copyright));
|
||||
}
|
||||
|
||||
int telnet_close_client(struct osmo_fd *fd)
|
||||
|
|
|
@ -45,7 +45,7 @@ static void vty_clear_buf(struct vty *vty)
|
|||
}
|
||||
|
||||
/* Allocate new vty struct. */
|
||||
struct vty *vty_new()
|
||||
struct vty *vty_new(void)
|
||||
{
|
||||
struct vty *new = talloc_zero(tall_vty_ctx, struct vty);
|
||||
|
||||
|
@ -1591,7 +1591,7 @@ struct cmd_node vty_node = {
|
|||
};
|
||||
|
||||
/* Reset all VTY status. */
|
||||
void vty_reset()
|
||||
void vty_reset(void)
|
||||
{
|
||||
unsigned int i;
|
||||
struct vty *vty;
|
||||
|
@ -1631,7 +1631,7 @@ static void vty_save_cwd(void)
|
|||
strcpy(vty_cwd, cwd);
|
||||
}
|
||||
|
||||
char *vty_get_cwd()
|
||||
char *vty_get_cwd(void)
|
||||
{
|
||||
return vty_cwd;
|
||||
}
|
||||
|
@ -1641,7 +1641,7 @@ int vty_shell_serv(struct vty *vty)
|
|||
return vty->type == VTY_SHELL_SERV ? 1 : 0;
|
||||
}
|
||||
|
||||
void vty_init_vtysh()
|
||||
void vty_init_vtysh(void)
|
||||
{
|
||||
vtyvec = vector_init(VECTOR_MIN_SIZE);
|
||||
}
|
||||
|
|
|
@ -31,15 +31,19 @@ struct test_case {
|
|||
const uint16_t input_length;
|
||||
|
||||
const uint8_t *expected;
|
||||
const uint16_t expected_length;
|
||||
const uint16_t expected_octet_length;
|
||||
const uint16_t expected_septet_length;
|
||||
const uint8_t ud_hdr_ind;
|
||||
};
|
||||
|
||||
static const char simple_text[] = "test text";
|
||||
#define simple_septet_length 9
|
||||
static const uint8_t simple_enc[] = {
|
||||
0xf4, 0xf2, 0x9c, 0x0e, 0xa2, 0x97, 0xf1, 0x74
|
||||
};
|
||||
|
||||
static const char escape_text[] = "!$ a more#^- complicated test@@?_\%! case";
|
||||
static const char escape_text[] = "!$ a more#^- complicated test@@?_%! case";
|
||||
#define escape_septet_length 41 /* note: the ^ counts as two, because it is a extension character */
|
||||
static const uint8_t escape_enc[] = {
|
||||
0x21, 0x01, 0x28, 0x0c, 0x6a, 0xbf, 0xe5, 0xe5, 0xd1,
|
||||
0x86, 0xd2, 0x02, 0x8d, 0xdf, 0x6d, 0x38, 0x3b, 0x3d,
|
||||
|
@ -47,17 +51,115 @@ static const uint8_t escape_enc[] = {
|
|||
0x00, 0xbf, 0x48, 0x29, 0x04, 0x1a, 0x87, 0xe7, 0x65,
|
||||
};
|
||||
|
||||
static const char enhanced_text[] = "enhanced ^ {][} test |+~ ^ test";
|
||||
#define enhanced_septet_length 39 /* note: the characters { } [ ] ^ | ~ count as two (each of them), because they are extension characters */
|
||||
static const uint8_t enhanced_enc[] = {
|
||||
0x65, 0x37, 0x3A, 0xEC, 0x1E, 0x97, 0xC9, 0xA0, 0x0D,
|
||||
0x05, 0xB4, 0x41, 0x6D, 0x7C, 0x1B, 0xDE, 0x26, 0x05,
|
||||
0xA2, 0x97, 0xE7, 0x74, 0xD0, 0x06, 0xB8, 0xDA, 0xF4,
|
||||
0x40, 0x1B, 0x0A, 0x88, 0x5E, 0x9E, 0xD3, 0x01,
|
||||
};
|
||||
|
||||
static const char enhancedV2_text[] = "enhanced ^ {][} test |+~ ^ tests";
|
||||
#define enhancedV2_septet_length 40 /* note: number of octets are equal to the enhanced_text! */
|
||||
static const uint8_t enhancedV2_enc[] = {
|
||||
0x65, 0x37, 0x3A, 0xEC, 0x1E, 0x97, 0xC9, 0xA0, 0x0D,
|
||||
0x05, 0xB4, 0x41, 0x6D, 0x7C, 0x1B, 0xDE, 0x26, 0x05,
|
||||
0xA2, 0x97, 0xE7, 0x74, 0xD0, 0x06, 0xB8, 0xDA, 0xF4,
|
||||
0x40, 0x1B, 0x0A, 0x88, 0x5E, 0x9E, 0xD3, 0xE7,
|
||||
};
|
||||
|
||||
|
||||
|
||||
static const char concatenated_text[] =
|
||||
"this is a testmessage. this is a testmessage. this is a testmessage. this is a testmessage. "
|
||||
"this is a testmessage. this is a testmessage. cut here .....: this is a second testmessage. end here.";
|
||||
|
||||
static const char splitted_text_part1[] =
|
||||
"this is a testmessage. this is a testmessage. this is a testmessage. this is a testmessage. "
|
||||
"this is a testmessage. this is a testmessage. cut here .....:";
|
||||
#define concatenated_part1_septet_length_with_header 160
|
||||
#define concatenated_part1_septet_length 153
|
||||
static const uint8_t concatenated_part1_enc[] = {
|
||||
0x05, 0x00, 0x03, 0x6f, 0x02, 0x01,
|
||||
0xe8, 0xe8, 0xf4, 0x1c, 0x94, 0x9e, 0x83, 0xc2,
|
||||
0x20, 0x7a, 0x79, 0x4e, 0x6f, 0x97, 0xe7, 0xf3,
|
||||
0xf0, 0xb9, 0xec, 0x02, 0xd1, 0xd1, 0xe9, 0x39,
|
||||
0x28, 0x3d, 0x07, 0x85, 0x41, 0xf4, 0xf2, 0x9c,
|
||||
0xde, 0x2e, 0xcf, 0xe7, 0xe1, 0x73, 0xd9, 0x05,
|
||||
0xa2, 0xa3, 0xd3, 0x73, 0x50, 0x7a, 0x0e, 0x0a,
|
||||
0x83, 0xe8, 0xe5, 0x39, 0xbd, 0x5d, 0x9e, 0xcf,
|
||||
0xc3, 0xe7, 0xb2, 0x0b, 0x44, 0x47, 0xa7, 0xe7,
|
||||
0xa0, 0xf4, 0x1c, 0x14, 0x06, 0xd1, 0xcb, 0x73,
|
||||
0x7a, 0xbb, 0x3c, 0x9f, 0x87, 0xcf, 0x65, 0x17,
|
||||
0x88, 0x8e, 0x4e, 0xcf, 0x41, 0xe9, 0x39, 0x28,
|
||||
0x0c, 0xa2, 0x97, 0xe7, 0xf4, 0x76, 0x79, 0x3e,
|
||||
0x0f, 0x9f, 0xcb, 0x2e, 0x10, 0x1d, 0x9d, 0x9e,
|
||||
0x83, 0xd2, 0x73, 0x50, 0x18, 0x44, 0x2f, 0xcf,
|
||||
0xe9, 0xed, 0xf2, 0x7c, 0x1e, 0x3e, 0x97, 0x5d,
|
||||
0xa0, 0x71, 0x9d, 0x0e, 0x42, 0x97, 0xe5, 0x65,
|
||||
0x90, 0xcb, 0xe5, 0x72, 0xb9, 0x74,
|
||||
};
|
||||
|
||||
static const char splitted_text_part2[] = " this is a second testmessage. end here.";
|
||||
#define concatenated_part2_septet_length_with_header 47
|
||||
#define concatenated_part2_septet_length 40
|
||||
static const uint8_t concatenated_part2_enc[] = {
|
||||
0x05, 0x00, 0x03, 0x6f, 0x02, 0x02,
|
||||
0x40, 0x74, 0x74, 0x7a, 0x0e, 0x4a, 0xcf, 0x41,
|
||||
0x61, 0xd0, 0xbc, 0x3c, 0x7e, 0xbb, 0xc9, 0x20,
|
||||
0x7a, 0x79, 0x4e, 0x6f, 0x97, 0xe7, 0xf3, 0xf0,
|
||||
0xb9, 0xec, 0x02, 0x95, 0xdd, 0x64, 0x10, 0xba,
|
||||
0x2c, 0x2f, 0xbb, 0x00,
|
||||
};
|
||||
|
||||
static const struct test_case test_multiple_encode[] =
|
||||
{
|
||||
{
|
||||
.input = concatenated_text,
|
||||
.expected = concatenated_part1_enc,
|
||||
.expected_octet_length = sizeof(concatenated_part1_enc),
|
||||
.expected_septet_length = concatenated_part1_septet_length,
|
||||
.ud_hdr_ind = 1,
|
||||
},
|
||||
{
|
||||
.input = concatenated_text,
|
||||
.expected = concatenated_part2_enc,
|
||||
.expected_octet_length = sizeof(concatenated_part2_enc),
|
||||
.expected_septet_length = concatenated_part2_septet_length,
|
||||
.ud_hdr_ind = 1,
|
||||
},
|
||||
};
|
||||
|
||||
static const struct test_case test_encode[] =
|
||||
{
|
||||
{
|
||||
.input = simple_text,
|
||||
.expected = simple_enc,
|
||||
.expected_length = sizeof(simple_enc),
|
||||
.expected_octet_length = sizeof(simple_enc),
|
||||
.expected_septet_length = simple_septet_length,
|
||||
.ud_hdr_ind = 0,
|
||||
},
|
||||
{
|
||||
.input = escape_text,
|
||||
.expected = escape_enc,
|
||||
.expected_length = sizeof(escape_enc),
|
||||
.expected_octet_length = sizeof(escape_enc),
|
||||
.expected_septet_length = escape_septet_length,
|
||||
.ud_hdr_ind = 0,
|
||||
},
|
||||
{
|
||||
.input = enhanced_text,
|
||||
.expected = enhanced_enc,
|
||||
.expected_octet_length = sizeof(enhanced_enc),
|
||||
.expected_septet_length = enhanced_septet_length,
|
||||
.ud_hdr_ind = 0,
|
||||
},
|
||||
{
|
||||
.input = enhancedV2_text,
|
||||
.expected = enhancedV2_enc,
|
||||
.expected_octet_length = sizeof(enhancedV2_enc),
|
||||
.expected_septet_length = enhancedV2_septet_length,
|
||||
.ud_hdr_ind = 0,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -67,11 +169,43 @@ static const struct test_case test_decode[] =
|
|||
.input = simple_enc,
|
||||
.input_length = sizeof(simple_enc),
|
||||
.expected = simple_text,
|
||||
.expected_septet_length = simple_septet_length,
|
||||
.ud_hdr_ind = 0,
|
||||
},
|
||||
{
|
||||
.input = escape_enc,
|
||||
.input_length = sizeof(escape_enc),
|
||||
.expected = escape_text,
|
||||
.expected_septet_length = escape_septet_length,
|
||||
.ud_hdr_ind = 0,
|
||||
},
|
||||
{
|
||||
.input = enhanced_enc,
|
||||
.input_length = sizeof(enhanced_enc),
|
||||
.expected = enhanced_text,
|
||||
.expected_septet_length = enhanced_septet_length,
|
||||
.ud_hdr_ind = 0,
|
||||
},
|
||||
{
|
||||
.input = enhancedV2_enc,
|
||||
.input_length = sizeof(enhancedV2_enc),
|
||||
.expected = enhancedV2_text,
|
||||
.expected_septet_length = enhancedV2_septet_length,
|
||||
.ud_hdr_ind = 0,
|
||||
},
|
||||
{
|
||||
.input = concatenated_part1_enc,
|
||||
.input_length = sizeof(concatenated_part1_enc),
|
||||
.expected = splitted_text_part1,
|
||||
.expected_septet_length = concatenated_part1_septet_length_with_header,
|
||||
.ud_hdr_ind = 1,
|
||||
},
|
||||
{
|
||||
.input = concatenated_part2_enc,
|
||||
.input_length = sizeof(concatenated_part2_enc),
|
||||
.expected = splitted_text_part2,
|
||||
.expected_septet_length = concatenated_part2_septet_length_with_header,
|
||||
.ud_hdr_ind = 1,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -79,41 +213,105 @@ int main(int argc, char** argv)
|
|||
{
|
||||
printf("SMS testing\n");
|
||||
struct msgb *msg;
|
||||
uint8_t *sms;
|
||||
uint8_t i;
|
||||
|
||||
uint8_t length;
|
||||
uint8_t octet_length;
|
||||
uint8_t septet_length;
|
||||
uint8_t gsm_septet_length;
|
||||
uint8_t coded[256];
|
||||
uint8_t tmp[160];
|
||||
uint8_t septet_data[256];
|
||||
uint8_t ud_header[6];
|
||||
char result[256];
|
||||
|
||||
/* test 7-bit encoding */
|
||||
for (i = 0; i < ARRAY_SIZE(test_encode); ++i) {
|
||||
memset(coded, 0x42, sizeof(coded));
|
||||
length = gsm_7bit_encode(coded, test_encode[i].input);
|
||||
|
||||
if (length != test_encode[i].expected_length) {
|
||||
fprintf(stderr, "Failed to encode case %d. Got %d, expected %d\n",
|
||||
i, length, test_encode[i].expected_length);
|
||||
septet_length = gsm_7bit_encode(coded, test_encode[i].input);
|
||||
octet_length = gsm_get_octet_len(septet_length);
|
||||
if (octet_length != test_encode[i].expected_octet_length) {
|
||||
fprintf(stderr, "Encode case %d: Octet length failure. Got %d, expected %d\n",
|
||||
i, octet_length, test_encode[i].expected_octet_length);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (memcmp(coded, test_encode[i].expected, length) != 0) {
|
||||
fprintf(stderr, "Encoded content does not match for %d\n",
|
||||
if (septet_length != test_encode[i].expected_septet_length){
|
||||
fprintf(stderr, "Encode case %d: Septet length failure. Got %d, expected %d\n",
|
||||
i, septet_length, test_encode[i].expected_septet_length);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (memcmp(coded, test_encode[i].expected, octet_length) != 0) {
|
||||
fprintf(stderr, "Encoded content does not match for case %d\n",
|
||||
i);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Test: encode multiple SMS */
|
||||
int number_of_septets = gsm_septet_encode(septet_data, test_multiple_encode[0].input);
|
||||
|
||||
/* SMS part 1 */
|
||||
memset(tmp, 0x42, sizeof(tmp));
|
||||
memset(coded, 0x42, sizeof(coded));
|
||||
memcpy(tmp, septet_data, concatenated_part1_septet_length);
|
||||
|
||||
/* In our case: test_multiple_decode[0].ud_hdr_ind equals number of padding bits*/
|
||||
octet_length = gsm_septets2octets(coded, tmp, concatenated_part1_septet_length, test_multiple_encode[0].ud_hdr_ind);
|
||||
|
||||
/* copy header */
|
||||
memset(tmp, 0x42, sizeof(tmp));
|
||||
int udh_length = test_multiple_encode[0].expected[0] + 1;
|
||||
memcpy(tmp, test_multiple_encode[0].expected, udh_length);
|
||||
memcpy(tmp + udh_length, coded, octet_length);
|
||||
memset(coded, 0x42, sizeof(coded));
|
||||
memcpy(coded, tmp, octet_length + 6);
|
||||
|
||||
if (memcmp(coded, test_multiple_encode[0].expected, octet_length) != 0) {
|
||||
fprintf(stderr, "Multiple-SMS encoded content does not match for part 1\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* SMS part 2 */
|
||||
memset(tmp, 0x42, sizeof(tmp));
|
||||
memset(coded, 0x42, sizeof(coded));
|
||||
memcpy(tmp, septet_data + concatenated_part1_septet_length, concatenated_part2_septet_length);
|
||||
|
||||
/* In our case: test_multiple_decode[1].ud_hdr_ind equals number of padding bits*/
|
||||
octet_length = gsm_septets2octets(coded, tmp, concatenated_part2_septet_length, test_multiple_encode[1].ud_hdr_ind);
|
||||
|
||||
/* copy header */
|
||||
memset(tmp, 0x42, sizeof(tmp));
|
||||
udh_length = test_multiple_encode[1].expected[0] + 1;
|
||||
memcpy(tmp, test_multiple_encode[1].expected, udh_length);
|
||||
memcpy(tmp + udh_length, coded, octet_length);
|
||||
memset(coded, 0x42, sizeof(coded));
|
||||
memcpy(coded, tmp, octet_length + 6);
|
||||
|
||||
if (memcmp(coded, test_multiple_encode[1].expected, octet_length) != 0) {
|
||||
fprintf(stderr, "Multiple-SMS encoded content does not match for part 2\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* test 7-bit decoding */
|
||||
for (i = 0; i < ARRAY_SIZE(test_decode); ++i) {
|
||||
memset(result, 0x42, sizeof(coded));
|
||||
gsm_7bit_decode(result, test_decode[i].input,
|
||||
test_decode[i].input_length);
|
||||
septet_length = gsm_7bit_decode_hdr(result, test_decode[i].input,
|
||||
test_decode[i].expected_septet_length, test_decode[i].ud_hdr_ind);
|
||||
|
||||
if (strcmp(result, test_decode[i].expected) != 0) {
|
||||
fprintf(stderr, "Test case %d failed to decode.\n", i);
|
||||
return -1;
|
||||
}
|
||||
if (septet_length != test_decode[i].expected_septet_length) {
|
||||
fprintf(stderr, "Decode case %d: Septet length failure. Got %d, expected %d\n",
|
||||
i, septet_length, test_decode[i].expected_septet_length);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("OK\n");
|
||||
|
|
Loading…
Reference in New Issue