diff options
Diffstat (limited to 'include/osmocom')
-rw-r--r-- | include/osmocom/core/fsm.h | 10 | ||||
-rw-r--r-- | include/osmocom/core/gsmtap.h | 14 | ||||
-rw-r--r-- | include/osmocom/core/logging.h | 21 | ||||
-rw-r--r-- | include/osmocom/core/msgb.h | 34 | ||||
-rw-r--r-- | include/osmocom/core/signal.h | 1 | ||||
-rw-r--r-- | include/osmocom/core/socket.h | 2 | ||||
-rw-r--r-- | include/osmocom/core/utils.h | 2 | ||||
-rw-r--r-- | include/osmocom/gprs/gprs_bssgp.h | 3 | ||||
-rw-r--r-- | include/osmocom/gsm/gsm0480.h | 8 | ||||
-rw-r--r-- | include/osmocom/gsm/gsm48.h | 8 | ||||
-rw-r--r-- | include/osmocom/gsm/ipa.h | 13 | ||||
-rw-r--r-- | include/osmocom/gsm/mncc.h | 2 | ||||
-rw-r--r-- | include/osmocom/gsm/oap_client.h | 82 |
13 files changed, 179 insertions, 21 deletions
diff --git a/include/osmocom/core/fsm.h b/include/osmocom/core/fsm.h index 9e1062f5..54bbad5d 100644 --- a/include/osmocom/core/fsm.h +++ b/include/osmocom/core/fsm.h @@ -178,7 +178,7 @@ static inline const char *osmo_fsm_inst_state_name(struct osmo_fsm_inst *fi) */ #define osmo_fsm_inst_state_chg(fi, new_state, timeout_secs, T) \ _osmo_fsm_inst_state_chg(fi, new_state, timeout_secs, T, \ - __BASE_FILE__, __LINE__) + __FILE__, __LINE__) int _osmo_fsm_inst_state_chg(struct osmo_fsm_inst *fi, uint32_t new_state, unsigned long timeout_secs, int T, const char *file, int line); @@ -194,7 +194,7 @@ int _osmo_fsm_inst_state_chg(struct osmo_fsm_inst *fi, uint32_t new_state, */ #define osmo_fsm_inst_state_chg_keep_timer(fi, new_state) \ _osmo_fsm_inst_state_chg_keep_timer(fi, new_state, \ - __BASE_FILE__, __LINE__) + __FILE__, __LINE__) int _osmo_fsm_inst_state_chg_keep_timer(struct osmo_fsm_inst *fi, uint32_t new_state, const char *file, int line); @@ -205,7 +205,7 @@ int _osmo_fsm_inst_state_chg_keep_timer(struct osmo_fsm_inst *fi, uint32_t new_s * purposes. See there for documentation. */ #define osmo_fsm_inst_dispatch(fi, event, data) \ - _osmo_fsm_inst_dispatch(fi, event, data, __BASE_FILE__, __LINE__) + _osmo_fsm_inst_dispatch(fi, event, data, __FILE__, __LINE__) int _osmo_fsm_inst_dispatch(struct osmo_fsm_inst *fi, uint32_t event, void *data, const char *file, int line); @@ -216,7 +216,7 @@ int _osmo_fsm_inst_dispatch(struct osmo_fsm_inst *fi, uint32_t event, void *data * See there for documentation. */ #define osmo_fsm_inst_term(fi, cause, data) \ - _osmo_fsm_inst_term(fi, cause, data, __BASE_FILE__, __LINE__) + _osmo_fsm_inst_term(fi, cause, data, __FILE__, __LINE__) void _osmo_fsm_inst_term(struct osmo_fsm_inst *fi, enum osmo_fsm_term_cause cause, void *data, const char *file, int line); @@ -228,7 +228,7 @@ void _osmo_fsm_inst_term(struct osmo_fsm_inst *fi, * purposes. See there for documentation. */ #define osmo_fsm_inst_term_children(fi, cause, data) \ - _osmo_fsm_inst_term_children(fi, cause, data, __BASE_FILE__, __LINE__) + _osmo_fsm_inst_term_children(fi, cause, data, __FILE__, __LINE__) void _osmo_fsm_inst_term_children(struct osmo_fsm_inst *fi, enum osmo_fsm_term_cause cause, void *data, diff --git a/include/osmocom/core/gsmtap.h b/include/osmocom/core/gsmtap.h index b4239f8c..9f5049f8 100644 --- a/include/osmocom/core/gsmtap.h +++ b/include/osmocom/core/gsmtap.h @@ -33,7 +33,7 @@ #define GSMTAP_TYPE_UM 0x01 #define GSMTAP_TYPE_ABIS 0x02 #define GSMTAP_TYPE_UM_BURST 0x03 /* raw burst bits */ -#define GSMTAP_TYPE_SIM 0x04 +#define GSMTAP_TYPE_SIM 0x04 /* ISO 7816 smart card interface */ #define GSMTAP_TYPE_TETRA_I1 0x05 /* tetra air interface */ #define GSMTAP_TYPE_TETRA_I1_BURST 0x06 /* tetra air interface */ #define GSMTAP_TYPE_WMX_BURST 0x07 /* WiMAX burst */ @@ -103,6 +103,18 @@ /* ====== DO NOT MAKE UNAPPROVED MODIFICATIONS HERE ===== */ +/* sub-types for GSMTAP_TYPE_SIM */ +#define GSMTAP_SIM_APDU 0x00 /* APDU data (complete APDU) */ +#define GSMTAP_SIM_ATR 0x01 /* card ATR data */ +#define GSMTAP_SIM_PPS_REQ 0x02 /* PPS request data */ +#define GSMTAP_SIM_PPS_RSP 0x03 /* PPS response data */ +#define GSMTAP_SIM_TPDU_HDR 0x04 /* TPDU command header */ +#define GSMTAP_SIM_TPDU_CMD 0x05 /* TPDU command body */ +#define GSMTAP_SIM_TPDU_RSP 0x06 /* TPDU response body */ +#define GSMTAP_SIM_TPDU_SW 0x07 /* TPDU response trailer */ + +/* ====== DO NOT MAKE UNAPPROVED MODIFICATIONS HERE ===== */ + /* sub-types for TYPE_TETRA_AIR */ #define GSMTAP_TETRA_BSCH 0x01 #define GSMTAP_TETRA_AACH 0x02 diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h index e68f6181..8464043f 100644 --- a/include/osmocom/core/logging.h +++ b/include/osmocom/core/logging.h @@ -55,17 +55,17 @@ void logp(int subsys, const char *file, int line, int cont, const char *format, #define LOGPC(ss, level, fmt, args...) \ do { \ if (log_check_level(ss, level)) \ - logp2(ss, level, __BASE_FILE__, __LINE__, 1, fmt, ##args); \ + logp2(ss, level, __FILE__, __LINE__, 1, fmt, ##args); \ } while(0) /*! Log through the Osmocom logging framework with explicit source. - * If caller_file is passed as NULL, __BASE_FILE__ and __LINE__ are used + * If caller_file is passed as NULL, __FILE__ and __LINE__ are used * instead of caller_file and caller_line (so that this macro here defines * both cases in the same place, and to catch cases where callers fail to pass * a non-null filename string). * \param[in] ss logging subsystem (e.g. \ref DLGLOBAL) * \param[in] level logging level (e.g. \ref LOGL_NOTICE) - * \param[in] caller_file caller's source file string (e.g. __BASE_FILE__) + * \param[in] caller_file caller's source file string (e.g. __FILE__) * \param[in] caller_line caller's source line nr (e.g. __LINE__) * \param[in] fmt format string * \param[in] args variable argument list @@ -74,13 +74,13 @@ void logp(int subsys, const char *file, int line, int cont, const char *format, LOGPSRCC(ss, level, caller_file, caller_line, 0, fmt, ##args) /*! Log through the Osmocom logging framework with explicit source. - * If caller_file is passed as NULL, __BASE_FILE__ and __LINE__ are used + * If caller_file is passed as NULL, __FILE__ and __LINE__ are used * instead of caller_file and caller_line (so that this macro here defines * both cases in the same place, and to catch cases where callers fail to pass * a non-null filename string). * \param[in] ss logging subsystem (e.g. \ref DLGLOBAL) * \param[in] level logging level (e.g. \ref LOGL_NOTICE) - * \param[in] caller_file caller's source file string (e.g. __BASE_FILE__) + * \param[in] caller_file caller's source file string (e.g. __FILE__) * \param[in] caller_line caller's source line nr (e.g. __LINE__) * \param[in] cont continuation (1) or new line (0) * \param[in] fmt format string @@ -92,7 +92,7 @@ void logp(int subsys, const char *file, int line, int cont, const char *format, if (caller_file) \ logp2(ss, level, caller_file, caller_line, cont, fmt, ##args); \ else \ - logp2(ss, level, __BASE_FILE__, __LINE__, cont, fmt, ##args); \ + logp2(ss, level, __FILE__, __LINE__, cont, fmt, ##args); \ }\ } while(0) @@ -228,6 +228,12 @@ enum log_filename_type { LOG_FILENAME_BASENAME, }; +/*! Where on a log line source file and line should be logged. */ +enum log_filename_pos { + LOG_FILENAME_POS_HEADER_END, + LOG_FILENAME_POS_LINE_END, +}; + /*! structure representing a logging target */ struct log_target { struct llist_head entry; /*!< linked list */ @@ -313,6 +319,8 @@ struct log_target { bool print_category_hex; /* Should we print the source file and line, and in which way? */ enum log_filename_type print_filename2; + /* Where on a log line to put the source file info. */ + enum log_filename_pos print_filename_pos; }; /* use the above macros */ @@ -335,6 +343,7 @@ void log_set_print_extended_timestamp(struct log_target *target, int); void log_set_print_timestamp(struct log_target *target, int); void log_set_print_filename(struct log_target *target, int); void log_set_print_filename2(struct log_target *target, enum log_filename_type lft); +void log_set_print_filename_pos(struct log_target *target, enum log_filename_pos pos); void log_set_print_category(struct log_target *target, int); void log_set_print_category_hex(struct log_target *target, int); void log_set_print_level(struct log_target *target, int); diff --git a/include/osmocom/core/msgb.h b/include/osmocom/core/msgb.h index a8dc205b..b1cb6ec7 100644 --- a/include/osmocom/core/msgb.h +++ b/include/osmocom/core/msgb.h @@ -81,6 +81,40 @@ static inline void msgb_queue_free(struct llist_head *queue) while ((msg = msgb_dequeue(queue))) msgb_free(msg); } +/*! Enqueue message buffer to tail of a queue and increment queue size counter + * \param[in] queue linked list header of queue + * \param[in] msg message buffer to be added to the queue + * \param[in] count pointer to variable holding size of the queue + * + * The function will append the specified message buffer \a msg to the queue + * implemented by \ref llist_head \a queue using function \ref msgb_enqueue_count, + * then increment \a count + */ +static inline void msgb_enqueue_count(struct llist_head *queue, struct msgb *msg, + unsigned int *count) +{ + msgb_enqueue(queue, msg); + (*count)++; +} + +/*! Dequeue message buffer from head of queue and decrement queue size counter + * \param[in] queue linked list header of queue + * \param[in] count pointer to variable holding size of the queue + * \returns message buffer (if any) or NULL if queue empty + * + * The function will remove the first message buffer from the queue + * implemented by \ref llist_head \a queue using function \ref msgb_enqueue_count, + * and decrement \a count, all if queue is not empty. + */ +static inline struct msgb *msgb_dequeue_count(struct llist_head *queue, + unsigned int *count) +{ + struct msgb *msg = msgb_dequeue(queue); + if (msg) + (*count)--; + return msg; +} + #ifdef MSGB_DEBUG #include <osmocom/core/panic.h> #define MSGB_ABORT(msg, fmt, args ...) do { \ diff --git a/include/osmocom/core/signal.h b/include/osmocom/core/signal.h index ae78f152..449b9762 100644 --- a/include/osmocom/core/signal.h +++ b/include/osmocom/core/signal.h @@ -34,6 +34,7 @@ typedef int osmo_signal_cbfn(unsigned int subsys, unsigned int signal, void *han /* Management */ +void *osmo_signal_talloc_ctx_init(void *root_ctx); int osmo_signal_register_handler(unsigned int subsys, osmo_signal_cbfn *cbfn, void *data); void osmo_signal_unregister_handler(unsigned int subsys, osmo_signal_cbfn *cbfn, void *data); diff --git a/include/osmocom/core/socket.h b/include/osmocom/core/socket.h index 20515b99..f23a2436 100644 --- a/include/osmocom/core/socket.h +++ b/include/osmocom/core/socket.h @@ -24,6 +24,8 @@ struct osmo_fd; #define OSMO_SOCK_F_NO_MCAST_LOOP (1 << 3) /*! disable receiving all multiast even for non-subscribed groups */ #define OSMO_SOCK_F_NO_MCAST_ALL (1 << 4) +/*! use SO_REUSEADDR on UDP ports (required for multicast) */ +#define OSMO_SOCK_F_UDP_REUSEADDR (1 << 5) int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto, const char *host, uint16_t port, unsigned int flags); diff --git a/include/osmocom/core/utils.h b/include/osmocom/core/utils.h index dd4461cc..e2d51349 100644 --- a/include/osmocom/core/utils.h +++ b/include/osmocom/core/utils.h @@ -78,7 +78,7 @@ do { \ */ #define OSMO_ASSERT(exp) \ if (!(exp)) { \ - osmo_panic("Assert failed %s %s:%d\n", #exp, __BASE_FILE__, __LINE__); \ + osmo_panic("Assert failed %s %s:%d\n", #exp, __FILE__, __LINE__); \ } /*! duplicate a string using talloc and release its prior content (if any) diff --git a/include/osmocom/gprs/gprs_bssgp.h b/include/osmocom/gprs/gprs_bssgp.h index 2dead692..400c3e00 100644 --- a/include/osmocom/gprs/gprs_bssgp.h +++ b/include/osmocom/gprs/gprs_bssgp.h @@ -207,6 +207,9 @@ int bssgp_fc_in(struct bssgp_flow_control *fc, struct msgb *msg, int bssgp_fc_ms_init(struct bssgp_flow_control *fc_ms, uint16_t bvci, uint16_t nsei, uint32_t max_queue_depth); +void bssgp_flush_all_queues(); +void bssgp_fc_flush_queue(struct bssgp_flow_control *fc); + /* gprs_bssgp_vty.c */ int bssgp_vty_init(void); void bssgp_set_log_ss(int ss); diff --git a/include/osmocom/gsm/gsm0480.h b/include/osmocom/gsm/gsm0480.h index e928d83f..827464e1 100644 --- a/include/osmocom/gsm/gsm0480.h +++ b/include/osmocom/gsm/gsm0480.h @@ -108,6 +108,11 @@ int gsm0480_parse_facility_ie(const uint8_t *facility_ie, uint16_t length, int gsm0480_decode_ss_request(const struct gsm48_hdr *hdr, uint16_t len, struct ss_request *request); +struct msgb *gsm0480_msgb_alloc_name(const char *name); +struct msgb *gsm0480_gen_ussd_resp_7bit(uint8_t invoke_id, const char *text); +struct msgb *gsm0480_gen_return_error(uint8_t invoke_id, uint8_t error_code); +struct msgb *gsm0480_gen_reject(int invoke_id, uint8_t problem_tag, uint8_t problem_code); + struct msgb *gsm0480_create_ussd_resp(uint8_t invoke_id, uint8_t trans_id, const char *text); struct msgb *gsm0480_create_unstructuredSS_Notify(int alertPattern, const char *text); struct msgb *gsm0480_create_notifySS(const char *text); @@ -116,6 +121,3 @@ struct msgb *gsm0480_create_ussd_release_complete(void); int gsm0480_wrap_invoke(struct msgb *msg, int op, int link_id); int gsm0480_wrap_facility(struct msgb *msg); - -struct gsm48_hdr *gsm0480_l3hdr_push(struct msgb *msg, uint8_t proto_discr, - uint8_t msg_type); diff --git a/include/osmocom/gsm/gsm48.h b/include/osmocom/gsm/gsm48.h index cfae83da..2b14e6cd 100644 --- a/include/osmocom/gsm/gsm48.h +++ b/include/osmocom/gsm/gsm48.h @@ -4,6 +4,8 @@ #include <stdbool.h> +#include <osmocom/core/msgb.h> + #include <osmocom/gsm/tlv.h> #include <osmocom/gsm/protocol/gsm_04_08.h> #include <osmocom/gsm/gsm48_ie.h> @@ -63,3 +65,9 @@ void gsm48_mcc_mnc_to_bcd(uint8_t *bcd_dst, uint16_t mcc, uint16_t mnc) OSMO_DEPRECATED("Use osmo_plmn_to_bcd() instead, to not lose leading zeros in the MNC"); void gsm48_mcc_mnc_from_bcd(uint8_t *bcd_src, uint16_t *mcc, uint16_t *mnc) OSMO_DEPRECATED("Use osmo_plmn_from_bcd() instead, to not lose leading zeros in the MNC"); + +struct gsm48_hdr *gsm48_push_l3hdr(struct msgb *msg, + uint8_t pdisc, uint8_t msg_type); + +#define gsm48_push_l3hdr_tid(msg, pdisc, tid, msg_type) \ + gsm48_push_l3hdr(msg, (pdisc & 0x0f) | (tid << 4), msg_type) diff --git a/include/osmocom/gsm/ipa.h b/include/osmocom/gsm/ipa.h index 7e1d7237..93cb1bf1 100644 --- a/include/osmocom/gsm/ipa.h +++ b/include/osmocom/gsm/ipa.h @@ -26,11 +26,16 @@ struct ipaccess_unit { /* obtain the human-readable name of an IPA CCM ID TAG */ const char *ipa_ccm_idtag_name(uint8_t tag); -/* parse a buffer of ID tags into a osmocom TLV style representation */ -int ipa_ccm_idtag_parse(struct tlv_parsed *dec, unsigned char *buf, int len); +int ipa_ccm_idtag_parse(struct tlv_parsed *dec, unsigned char *buf, int len) + OSMO_DEPRECATED("Use ipa_ccm_id_{get,resp}_parse instead"); +int ipa_ccm_idtag_parse_off(struct tlv_parsed *dec, unsigned char *buf, int len, const int len_offset) + OSMO_DEPRECATED("Use ipa_ccm_id_{get,resp}_parse instead"); -/* Is the TAG included in the length field? */ -int ipa_ccm_idtag_parse_off(struct tlv_parsed *dec, unsigned char *buf, int len, const int len_offset); +/* parse payload of IPA CCM ID GET into a osmocom TLV style representation */ +int ipa_ccm_id_get_parse(struct tlv_parsed *dec, const uint8_t *buf, unsigned int len); + +/* parse payload of IPA CCM ID RESP into a osmocom TLV style representation */ +int ipa_ccm_id_resp_parse(struct tlv_parsed *dec, const uint8_t *buf, unsigned int len); /* parse an Unit ID in string format into the 'ipaccess_unit' data structure */ int ipa_parse_unitid(const char *str, struct ipaccess_unit *unit_data); diff --git a/include/osmocom/gsm/mncc.h b/include/osmocom/gsm/mncc.h index 6b94d469..7e7d12c3 100644 --- a/include/osmocom/gsm/mncc.h +++ b/include/osmocom/gsm/mncc.h @@ -90,7 +90,7 @@ void _osmo_mncc_log(int subsys, int level, const char *file, int line, const cha const uint8_t *msg, unsigned int len); #define osmo_mncc_log(ss, level, prefix, msg, len) \ - _osmo_mncc_log(ss, level, __BASE_FILE__, __LINE__, prefix, msg, len); + _osmo_mncc_log(ss, level, __FILE__, __LINE__, prefix, msg, len); extern const struct value_string osmo_mncc_names[]; static inline const char *osmo_mncc_name(uint32_t msg_type) { diff --git a/include/osmocom/gsm/oap_client.h b/include/osmocom/gsm/oap_client.h new file mode 100644 index 00000000..763f982c --- /dev/null +++ b/include/osmocom/gsm/oap_client.h @@ -0,0 +1,82 @@ +/* Osmocom Authentication Protocol API */ + +/* (C) 2015 by Sysmocom s.f.m.c. GmbH + * All Rights Reserved + * + * Author: Neels Hofmeyr + * + * 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/>. + * + */ + +#pragma once + +#include <stdint.h> + +struct msgb; +struct osmo_oap_message; + +/* This is the config part for vty. It is essentially copied in + * oap_client_state, where values are copied over once the config is + * considered valid. */ +struct osmo_oap_client_config { + uint16_t client_id; + int secret_k_present; + uint8_t secret_k[16]; + int secret_opc_present; + uint8_t secret_opc[16]; +}; + +/* The runtime state of the OAP client. client_id and the secrets are in fact + * duplicated from oap_client_config, so that a separate validation of the + * config data is possible, and so that only a struct oap_client_state* is + * passed around. */ +struct osmo_oap_client_state { + enum { + OSMO_OAP_UNINITIALIZED = 0, /* just allocated. */ + OSMO_OAP_DISABLED, /* disabled by config. */ + OSMO_OAP_INITIALIZED, /* enabled, config is valid. */ + OSMO_OAP_REQUESTED_CHALLENGE, + OSMO_OAP_SENT_CHALLENGE_RESULT, + OSMO_OAP_REGISTERED + } state; + uint16_t client_id; + uint8_t secret_k[16]; + uint8_t secret_opc[16]; + int registration_failures; +}; + +/* From config, initialize state. Return 0 on success. */ +int osmo_oap_client_init(struct osmo_oap_client_config *config, + struct osmo_oap_client_state *state); + +/* Construct an OAP registration message and return in *msg_tx. Use + * state->client_id and update state->state. + * Return 0 on success, or a negative value on error. + * If an error is returned, *msg_tx is guaranteed to be NULL. */ +int osmo_oap_client_register(struct osmo_oap_client_state *state, struct msgb **msg_tx); + +/* Decode and act on a received OAP message msg_rx. Update state->state. If a + * non-NULL pointer is returned in *msg_tx, that msgb should be sent to the OAP + * server (and freed) by the caller. The received msg_rx is not freed. + * Return 0 on success, or a negative value on error. + * If an error is returned, *msg_tx is guaranteed to be NULL. */ +int osmo_oap_client_handle(struct osmo_oap_client_state *state, + const struct msgb *msg_rx, struct msgb **msg_tx); + +/* Allocate a msgb and in it, return the encoded oap_client_msg. Return + * NULL on error. (Like oap_client_encode(), but also allocates a msgb.) + * About the name: the idea is do_something(oap_client_encoded(my_struct)) + */ +struct msgb *osmo_oap_client_encoded(const struct osmo_oap_message *oap_client_msg); |