From e66c7c10ea1c34590992af4ac96455e4214b9eae Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Wed, 4 Aug 2010 18:51:16 +0800 Subject: cleanup: Remove code that is provided by libosmocore now. libosmocore contains the GSM08.08 definition, no need to copy that anymore. --- include/Makefile.am | 2 +- include/openbsc_nat/Makefile.am | 1 - include/openbsc_nat/bssap.h | 339 ---------------------------------------- include/openbsc_nat/tlv.h | 234 --------------------------- src/Makefile.am | 3 +- src/bss_patch.c | 5 +- src/bssap_sccp.c | 3 +- src/main.c | 3 +- src/openbsc_nat/bssap.c | 65 -------- src/openbsc_nat/tlv_parser.c | 160 ------------------- tests/patching/Makefile.am | 4 +- 11 files changed, 8 insertions(+), 811 deletions(-) delete mode 100644 include/openbsc_nat/Makefile.am delete mode 100644 include/openbsc_nat/bssap.h delete mode 100644 include/openbsc_nat/tlv.h delete mode 100644 src/openbsc_nat/bssap.c delete mode 100644 src/openbsc_nat/tlv_parser.c diff --git a/include/Makefile.am b/include/Makefile.am index 8b1dd4b..36756cd 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -2,4 +2,4 @@ noinst_HEADERS = mtp_level3.h mtp_data.h ipaccess.h thread.h mtp_pcap.h \ mgcp_ss7.h bss_patch.h bssap_sccp.h bsc_data.h udp_input.h \ snmp_mtp.h -SUBDIRS = mgcp openbsc_nat +SUBDIRS = mgcp diff --git a/include/openbsc_nat/Makefile.am b/include/openbsc_nat/Makefile.am deleted file mode 100644 index 96bb305..0000000 --- a/include/openbsc_nat/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -noinst_HEADERS = bssap.h tlv.h diff --git a/include/openbsc_nat/bssap.h b/include/openbsc_nat/bssap.h deleted file mode 100644 index eed6c0e..0000000 --- a/include/openbsc_nat/bssap.h +++ /dev/null @@ -1,339 +0,0 @@ -/* From GSM08.08 */ - -#ifndef BSSAP_H -#define BSSAP_H - -#include - -#include -#include - -struct gsm_network; -struct bss_sccp_connection_data; - -/* - * this is from GSM 03.03 CGI but is copied in GSM 08.08 - * in § 3.2.2.27 for Cell Identifier List - */ -enum CELL_IDENT { - CELL_IDENT_WHOLE_GLOBAL = 0, - CELL_IDENT_LAC_AND_CI = 1, - CELL_IDENT_CI = 2, - CELL_IDENT_NO_CELL = 3, - CELL_IDENT_LAI_AND_LAC = 4, - CELL_IDENT_LAC = 5, - CELL_IDENT_BSS = 6, - CELL_IDENT_UTRAN_PLMN_LAC_RNC = 8, - CELL_IDENT_UTRAN_RNC = 9, - CELL_IDENT_UTRAN_LAC_RNC = 10, -}; - - -/* GSM 08.06 § 6.3 */ -enum BSSAP_MSG_TYPE { - BSSAP_MSG_BSS_MANAGEMENT = 0x0, - BSSAP_MSG_DTAP = 0x1, -}; - -struct bssmap_header { - uint8_t type; - uint8_t length; -} __attribute__((packed)); - -struct dtap_header { - uint8_t type; - uint8_t link_id; - uint8_t length; -} __attribute__((packed)); - - -enum BSS_MAP_MSG_TYPE { - BSS_MAP_MSG_RESERVED_0 = 0, - - /* ASSIGNMENT MESSAGES */ - BSS_MAP_MSG_ASSIGMENT_RQST = 1, - BSS_MAP_MSG_ASSIGMENT_COMPLETE = 2, - BSS_MAP_MSG_ASSIGMENT_FAILURE = 3, - - /* HANDOVER MESSAGES */ - BSS_MAP_MSG_HANDOVER_RQST = 16, - BSS_MAP_MSG_HANDOVER_REQUIRED = 17, - BSS_MAP_MSG_HANDOVER_RQST_ACKNOWLEDGE= 18, - BSS_MAP_MSG_HANDOVER_CMD = 19, - BSS_MAP_MSG_HANDOVER_COMPLETE = 20, - BSS_MAP_MSG_HANDOVER_SUCCEEDED = 21, - BSS_MAP_MSG_HANDOVER_FAILURE = 22, - BSS_MAP_MSG_HANDOVER_PERFORMED = 23, - BSS_MAP_MSG_HANDOVER_CANDIDATE_ENQUIRE = 24, - BSS_MAP_MSG_HANDOVER_CANDIDATE_RESPONSE = 25, - BSS_MAP_MSG_HANDOVER_REQUIRED_REJECT = 26, - BSS_MAP_MSG_HANDOVER_DETECT = 27, - - /* RELEASE MESSAGES */ - BSS_MAP_MSG_CLEAR_CMD = 32, - BSS_MAP_MSG_CLEAR_COMPLETE = 33, - BSS_MAP_MSG_CLEAR_RQST = 34, - BSS_MAP_MSG_RESERVED_1 = 35, - BSS_MAP_MSG_RESERVED_2 = 36, - BSS_MAP_MSG_SAPI_N_REJECT = 37, - BSS_MAP_MSG_CONFUSION = 38, - - /* OTHER CONNECTION RELATED MESSAGES */ - BSS_MAP_MSG_SUSPEND = 40, - BSS_MAP_MSG_RESUME = 41, - BSS_MAP_MSG_CONNECTION_ORIENTED_INFORMATION = 42, - BSS_MAP_MSG_PERFORM_LOCATION_RQST = 43, - BSS_MAP_MSG_LSA_INFORMATION = 44, - BSS_MAP_MSG_PERFORM_LOCATION_RESPONSE = 45, - BSS_MAP_MSG_PERFORM_LOCATION_ABORT = 46, - BSS_MAP_MSG_COMMON_ID = 47, - - /* GENERAL MESSAGES */ - BSS_MAP_MSG_RESET = 48, - BSS_MAP_MSG_RESET_ACKNOWLEDGE = 49, - BSS_MAP_MSG_OVERLOAD = 50, - BSS_MAP_MSG_RESERVED_3 = 51, - BSS_MAP_MSG_RESET_CIRCUIT = 52, - BSS_MAP_MSG_RESET_CIRCUIT_ACKNOWLEDGE = 53, - BSS_MAP_MSG_MSC_INVOKE_TRACE = 54, - BSS_MAP_MSG_BSS_INVOKE_TRACE = 55, - BSS_MAP_MSG_CONNECTIONLESS_INFORMATION = 58, - - /* TERRESTRIAL RESOURCE MESSAGES */ - BSS_MAP_MSG_BLOCK = 64, - BSS_MAP_MSG_BLOCKING_ACKNOWLEDGE = 65, - BSS_MAP_MSG_UNBLOCK = 66, - BSS_MAP_MSG_UNBLOCKING_ACKNOWLEDGE = 67, - BSS_MAP_MSG_CIRCUIT_GROUP_BLOCK = 68, - BSS_MAP_MSG_CIRCUIT_GROUP_BLOCKING_ACKNOWLEDGE = 69, - BSS_MAP_MSG_CIRCUIT_GROUP_UNBLOCK = 70, - BSS_MAP_MSG_CIRCUIT_GROUP_UNBLOCKING_ACKNOWLEDGE = 71, - BSS_MAP_MSG_UNEQUIPPED_CIRCUIT = 72, - BSS_MAP_MSG_CHANGE_CIRCUIT = 78, - BSS_MAP_MSG_CHANGE_CIRCUIT_ACKNOWLEDGE = 79, - - /* RADIO RESOURCE MESSAGES */ - BSS_MAP_MSG_RESOURCE_RQST = 80, - BSS_MAP_MSG_RESOURCE_INDICATION = 81, - BSS_MAP_MSG_PAGING = 82, - BSS_MAP_MSG_CIPHER_MODE_CMD = 83, - BSS_MAP_MSG_CLASSMARK_UPDATE = 84, - BSS_MAP_MSG_CIPHER_MODE_COMPLETE = 85, - BSS_MAP_MSG_QUEUING_INDICATION = 86, - BSS_MAP_MSG_COMPLETE_LAYER_3 = 87, - BSS_MAP_MSG_CLASSMARK_RQST = 88, - BSS_MAP_MSG_CIPHER_MODE_REJECT = 89, - BSS_MAP_MSG_LOAD_INDICATION = 90, - - /* VGCS/VBS */ - BSS_MAP_MSG_VGCS_VBS_SETUP = 4, - BSS_MAP_MSG_VGCS_VBS_SETUP_ACK = 5, - BSS_MAP_MSG_VGCS_VBS_SETUP_REFUSE = 6, - BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_RQST = 7, - BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_RESULT = 28, - BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_FAILURE = 29, - BSS_MAP_MSG_VGCS_VBS_QUEUING_INDICATION = 30, - BSS_MAP_MSG_UPLINK_RQST = 31, - BSS_MAP_MSG_UPLINK_RQST_ACKNOWLEDGE = 39, - BSS_MAP_MSG_UPLINK_RQST_CONFIRMATION = 73, - BSS_MAP_MSG_UPLINK_RELEASE_INDICATION = 74, - BSS_MAP_MSG_UPLINK_REJECT_CMD = 75, - BSS_MAP_MSG_UPLINK_RELEASE_CMD = 76, - BSS_MAP_MSG_UPLINK_SEIZED_CMD = 77, -}; - -enum GSM0808_IE_CODING { - GSM0808_IE_CIRCUIT_IDENTITY_CODE = 1, - GSM0808_IE_RESERVED_0 = 2, - GSM0808_IE_RESOURCE_AVAILABLE = 3, - GSM0808_IE_CAUSE = 4, - GSM0808_IE_CELL_IDENTIFIER = 5, - GSM0808_IE_PRIORITY = 6, - GSM0808_IE_LAYER_3_HEADER_INFORMATION = 7, - GSM0808_IE_IMSI = 8, - GSM0808_IE_TMSI = 9, - GSM0808_IE_ENCRYPTION_INFORMATION = 10, - GSM0808_IE_CHANNEL_TYPE = 11, - GSM0808_IE_PERIODICITY = 12, - GSM0808_IE_EXTENDED_RESOURCE_INDICATOR = 13, - GSM0808_IE_NUMBER_OF_MSS = 14, - GSM0808_IE_RESERVED_1 = 15, - GSM0808_IE_RESERVED_2 = 16, - GSM0808_IE_RESERVED_3 = 17, - GSM0808_IE_CLASSMARK_INFORMATION_T2 = 18, - GSM0808_IE_CLASSMARK_INFORMATION_T3 = 19, - GSM0808_IE_INTERFERENCE_BAND_TO_USE = 20, - GSM0808_IE_RR_CAUSE = 21, - GSM0808_IE_RESERVED_4 = 22, - GSM0808_IE_LAYER_3_INFORMATION = 23, - GSM0808_IE_DLCI = 24, - GSM0808_IE_DOWNLINK_DTX_FLAG = 25, - GSM0808_IE_CELL_IDENTIFIER_LIST = 26, - GSM0808_IE_RESPONSE_RQST = 27, - GSM0808_IE_RESOURCE_INDICATION_METHOD = 28, - GSM0808_IE_CLASSMARK_INFORMATION_TYPE_1 = 29, - GSM0808_IE_CIRCUIT_IDENTITY_CODE_LIST = 30, - GSM0808_IE_DIAGNOSTIC = 31, - GSM0808_IE_LAYER_3_MESSAGE_CONTENTS = 32, - GSM0808_IE_CHOSEN_CHANNEL = 33, - GSM0808_IE_TOTAL_RESOURCE_ACCESSIBLE = 34, - GSM0808_IE_CIPHER_RESPONSE_MODE = 35, - GSM0808_IE_CHANNEL_NEEDED = 36, - GSM0808_IE_TRACE_TYPE = 37, - GSM0808_IE_TRIGGERID = 38, - GSM0808_IE_TRACE_REFERENCE = 39, - GSM0808_IE_TRANSACTIONID = 40, - GSM0808_IE_MOBILE_IDENTITY = 41, - GSM0808_IE_OMCID = 42, - GSM0808_IE_FORWARD_INDICATOR = 43, - GSM0808_IE_CHOSEN_ENCR_ALG = 44, - GSM0808_IE_CIRCUIT_POOL = 45, - GSM0808_IE_CIRCUIT_POOL_LIST = 46, - GSM0808_IE_TIME_INDICATION = 47, - GSM0808_IE_RESOURCE_SITUATION = 48, - GSM0808_IE_CURRENT_CHANNEL_TYPE_1 = 49, - GSM0808_IE_QUEUEING_INDICATOR = 50, - GSM0808_IE_SPEECH_VERSION = 64, - GSM0808_IE_ASSIGNMENT_REQUIREMENT = 51, - GSM0808_IE_TALKER_FLAG = 53, - GSM0808_IE_CONNECTION_RELEASE_RQSTED = 54, - GSM0808_IE_GROUP_CALL_REFERENCE = 55, - GSM0808_IE_EMLPP_PRIORITY = 56, - GSM0808_IE_CONFIG_EVO_INDI = 57, - GSM0808_IE_OLD_BSS_TO_NEW_BSS_INFORMATION = 58, - GSM0808_IE_LSA_IDENTIFIER = 59, - GSM0808_IE_LSA_IDENTIFIER_LIST = 60, - GSM0808_IE_LSA_INFORMATION = 61, - GSM0808_IE_LCS_QOS = 62, - GSM0808_IE_LSA_ACCESS_CTRL_SUPPR = 63, - GSM0808_IE_LCS_PRIORITY = 67, - GSM0808_IE_LOCATION_TYPE = 68, - GSM0808_IE_LOCATION_ESTIMATE = 69, - GSM0808_IE_POSITIONING_DATA = 70, - GSM0808_IE_LCS_CAUSE = 71, - GSM0808_IE_LCS_CLIENT_TYPE = 72, - GSM0808_IE_APDU = 73, - GSM0808_IE_NETWORK_ELEMENT_IDENTITY = 74, - GSM0808_IE_GPS_ASSISTANCE_DATA = 75, - GSM0808_IE_DECIPHERING_KEYS = 76, - GSM0808_IE_RETURN_ERROR_RQST = 77, - GSM0808_IE_RETURN_ERROR_CAUSE = 78, - GSM0808_IE_SEGMENTATION = 79, - GSM0808_IE_SERVICE_HANDOVER = 80, - GSM0808_IE_SOURCE_RNC_TO_TARGET_RNC_TRANSPARENT_UMTS = 81, - GSM0808_IE_SOURCE_RNC_TO_TARGET_RNC_TRANSPARENT_CDMA2000= 82, - GSM0808_IE_RESERVED_5 = 65, - GSM0808_IE_RESERVED_6 = 66, -}; - -enum gsm0808_cause { - GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE = 0, - GSM0808_CAUSE_RADIO_INTERFACE_FAILURE = 1, - GSM0808_CAUSE_UPLINK_QUALITY = 2, - GSM0808_CAUSE_UPLINK_STRENGTH = 3, - GSM0808_CAUSE_DOWNLINK_QUALITY = 4, - GSM0808_CAUSE_DOWNLINK_STRENGTH = 5, - GSM0808_CAUSE_DISTANCE = 6, - GSM0808_CAUSE_O_AND_M_INTERVENTION = 7, - GSM0808_CAUSE_RESPONSE_TO_MSC_INVOCATION = 8, - GSM0808_CAUSE_CALL_CONTROL = 9, - GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION = 10, - GSM0808_CAUSE_HANDOVER_SUCCESSFUL = 11, - GSM0808_CAUSE_BETTER_CELL = 12, - GSM0808_CAUSE_DIRECTED_RETRY = 13, - GSM0808_CAUSE_JOINED_GROUP_CALL_CHANNEL = 14, - GSM0808_CAUSE_TRAFFIC = 15, - GSM0808_CAUSE_EQUIPMENT_FAILURE = 32, - GSM0808_CAUSE_NO_RADIO_RESOURCE_AVAILABLE = 33, - GSM0808_CAUSE_RQSTED_TERRESTRIAL_RESOURCE_UNAVAILABLE = 34, - GSM0808_CAUSE_CCCH_OVERLOAD = 35, - GSM0808_CAUSE_PROCESSOR_OVERLOAD = 36, - GSM0808_CAUSE_BSS_NOT_EQUIPPED = 37, - GSM0808_CAUSE_MS_NOT_EQUIPPED = 38, - GSM0808_CAUSE_INVALID_CELL = 39, - GSM0808_CAUSE_TRAFFIC_LOAD = 40, - GSM0808_CAUSE_PREEMPTION = 41, - GSM0808_CAUSE_RQSTED_TRANSCODING_RATE_ADAPTION_UNAVAILABLE = 48, - GSM0808_CAUSE_CIRCUIT_POOL_MISMATCH = 49, - GSM0808_CAUSE_SWITCH_CIRCUIT_POOL = 50, - GSM0808_CAUSE_RQSTED_SPEECH_VERSION_UNAVAILABLE = 51, - GSM0808_CAUSE_LSA_NOT_ALLOWED = 52, - GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED = 64, - GSM0808_CAUSE_TERRESTRIAL_CIRCUIT_ALREADY_ALLOCATED = 80, - GSM0808_CAUSE_INVALID_MESSAGE_CONTENTS = 81, - GSM0808_CAUSE_INFORMATION_ELEMENT_OR_FIELD_MISSING = 82, - GSM0808_CAUSE_INCORRECT_VALUE = 83, - GSM0808_CAUSE_UNKNOWN_MESSAGE_TYPE = 84, - GSM0808_CAUSE_UNKNOWN_INFORMATION_ELEMENT = 85, - GSM0808_CAUSE_PROTOCOL_ERROR_BETWEEN_BSS_AND_MSC = 96, -}; - -/* GSM 08.08 3.2.2.11 Channel Type */ -enum gsm0808_chan_indicator { - GSM0808_CHAN_SPEECH = 1, - GSM0808_CHAN_DATA = 2, - GSM0808_CHAN_SIGN = 3, -}; - -enum gsm0808_chan_rate_type_data { - GSM0808_DATA_FULL_BM = 0x8, - GSM0808_DATA_HALF_LM = 0x9, - GSM0808_DATA_FULL_RPREF = 0xa, - GSM0808_DATA_HALF_PREF = 0xb, - GSM0808_DATA_FULL_PREF_NO_CHANGE = 0x1a, - GSM0808_DATA_HALF_PREF_NO_CHANGE = 0x1b, - GSM0808_DATA_MULTI_MASK = 0x20, - GSM0808_DATA_MULTI_MASK_NO_CHANGE = 0x30, -}; - -enum gsm0808_chan_rate_type_speech { - GSM0808_SPEECH_FULL_BM = 0x8, - GSM0808_SPEECH_HALF_LM = 0x9, - GSM0808_SPEECH_FULL_PREF= 0xa, - GSM0808_SPEECH_HALF_PREF= 0xb, - GSM0808_SPEECH_FULL_PREF_NO_CHANGE = 0x1a, - GSM0808_SPEECH_HALF_PREF_NO_CHANGE = 0x1b, - GSM0808_SPEECH_PERM = 0xf, - GSM0808_SPEECH_PERM_NO_CHANGE = 0x1f, -}; - -enum gsm0808_permitted_speech { - GSM0808_PERM_FR1 = 0x01, - GSM0808_PERM_FR2 = 0x11, - GSM0808_PERM_FR3 = 0x21, - GSM0808_PERM_HR1 = GSM0808_PERM_FR1 | 0x4, - GSM0808_PERM_HR2 = GSM0808_PERM_FR2 | 0x4, - GSM0808_PERM_HR3 = GSM0808_PERM_FR3 | 0x4, -}; - -int bssmap_rcvmsg_dt1(struct sccp_connection *conn, struct msgb *msg, unsigned int length); -int bssmap_rcvmsg_udt(struct gsm_network *net, struct msgb *msg, unsigned int length); - -struct msgb *bssmap_create_layer3(struct msgb *msg); -struct msgb *bssmap_create_reset(void); -struct msgb *bssmap_create_clear_complete(void); -struct msgb *bssmap_create_cipher_complete(struct msgb *layer3); -struct msgb *bssmap_create_cipher_reject(uint8_t cause); -struct msgb *bssmap_create_sapi_reject(uint8_t link_id); -struct msgb *bssmap_create_assignment_completed(struct gsm_lchan *lchan, uint8_t rr_cause); -struct msgb *bssmap_create_assignment_failure(uint8_t cause, uint8_t *rr_cause); -struct msgb *bssmap_create_classmark_update(const uint8_t *classmark, uint8_t length); - -void gsm0808_send_assignment_failure(struct gsm_lchan *l, uint8_t cause, uint8_t *rr_value); -void gsm0808_send_assignment_compl(struct gsm_lchan *l, uint8_t rr_value); - -int dtap_rcvmsg(struct gsm_lchan *lchan, struct msgb *msg, unsigned int length); -struct msgb *dtap_create_msg(struct msgb *msg_l3, uint8_t link_id); - -void bsc_queue_connection_write(struct sccp_connection *conn, struct msgb *msg); -void bsc_free_queued(struct sccp_connection *conn); -void bsc_send_queued(struct sccp_connection *conn); - -void bts_queue_send(struct msgb *msg, int link_id); -void bts_send_queued(struct bss_sccp_connection_data*); -void bts_free_queued(struct bss_sccp_connection_data*); -void bts_unblock_queue(struct bss_sccp_connection_data*); - -const struct tlv_definition *gsm0808_att_tlvdef(); - -#endif diff --git a/include/openbsc_nat/tlv.h b/include/openbsc_nat/tlv.h deleted file mode 100644 index e2d4b88..0000000 --- a/include/openbsc_nat/tlv.h +++ /dev/null @@ -1,234 +0,0 @@ -#ifndef _TLV_H -#define _TLV_H - -#include -#include - -#include - -/* Terminology / wording - tag length value (in bits) - - V - - 8 - LV - 8 N * 8 - TLV 8 8 N * 8 - TL16V 8 16 N * 8 - TLV16 8 8 N * 16 - TvLV 8 8/16 N * 8 - -*/ - -#define LV_GROSS_LEN(x) (x+1) -#define TLV_GROSS_LEN(x) (x+2) -#define TLV16_GROSS_LEN(x) ((2*x)+2) -#define TL16V_GROSS_LEN(x) (x+3) -#define L16TV_GROSS_LEN(x) (x+3) - -#define TVLV_MAX_ONEBYTE 0x7f - -static inline uint16_t TVLV_GROSS_LEN(uint16_t len) -{ - if (len <= TVLV_MAX_ONEBYTE) - return TLV_GROSS_LEN(len); - else - return TL16V_GROSS_LEN(len); -} - -/* TLV generation */ - -static inline uint8_t *lv_put(uint8_t *buf, uint8_t len, - const uint8_t *val) -{ - *buf++ = len; - memcpy(buf, val, len); - return buf + len; -} - -static inline uint8_t *tlv_put(uint8_t *buf, uint8_t tag, uint8_t len, - const uint8_t *val) -{ - *buf++ = tag; - *buf++ = len; - memcpy(buf, val, len); - return buf + len; -} - -static inline uint8_t *tlv16_put(uint8_t *buf, uint8_t tag, uint8_t len, - const uint16_t *val) -{ - *buf++ = tag; - *buf++ = len; - memcpy(buf, val, len*2); - return buf + len*2; -} - -static inline uint8_t *tl16v_put(uint8_t *buf, uint8_t tag, uint16_t len, - const uint8_t *val) -{ - *buf++ = tag; - *buf++ = len >> 8; - *buf++ = len & 0xff; - memcpy(buf, val, len); - return buf + len*2; -} - -static inline uint8_t *tvlv_put(uint8_t *buf, uint8_t tag, uint16_t len, - const uint8_t *val) -{ - uint8_t *ret; - - if (len <= TVLV_MAX_ONEBYTE) { - ret = tlv_put(buf, tag, len, val); - buf[1] |= 0x80; - } else - ret = tl16v_put(buf, tag, len, val); - - return ret; -} - -static inline uint8_t *msgb_tlv16_put(struct msgb *msg, uint8_t tag, uint8_t len, const uint16_t *val) -{ - uint8_t *buf = msgb_put(msg, TLV16_GROSS_LEN(len)); - return tlv16_put(buf, tag, len, val); -} - -static inline uint8_t *msgb_tl16v_put(struct msgb *msg, uint8_t tag, uint16_t len, - const uint8_t *val) -{ - uint8_t *buf = msgb_put(msg, TL16V_GROSS_LEN(len)); - return tl16v_put(buf, tag, len, val); -} - -static inline uint8_t *msgb_tvlv_put(struct msgb *msg, uint8_t tag, uint16_t len, - const uint8_t *val) -{ - uint8_t *buf = msgb_put(msg, TVLV_GROSS_LEN(len)); - return tvlv_put(buf, tag, len, val); -} - -static inline uint8_t *msgb_l16tv_put(struct msgb *msg, uint16_t len, uint8_t tag, - const uint8_t *val) -{ - uint8_t *buf = msgb_put(msg, L16TV_GROSS_LEN(len)); - - *buf++ = len >> 8; - *buf++ = len & 0xff; - *buf++ = tag; - memcpy(buf, val, len); - return buf + len; -} - -static inline uint8_t *v_put(uint8_t *buf, uint8_t val) -{ - *buf++ = val; - return buf; -} - -static inline uint8_t *tv_put(uint8_t *buf, uint8_t tag, - uint8_t val) -{ - *buf++ = tag; - *buf++ = val; - return buf; -} - -/* 'val' is still in host byte order! */ -static inline uint8_t *tv16_put(uint8_t *buf, uint8_t tag, - uint16_t val) -{ - *buf++ = tag; - *buf++ = val >> 8; - *buf++ = val & 0xff; - return buf; -} - -static inline uint8_t *msgb_lv_put(struct msgb *msg, uint8_t len, const uint8_t *val) -{ - uint8_t *buf = msgb_put(msg, LV_GROSS_LEN(len)); - return lv_put(buf, len, val); -} - -static inline uint8_t *msgb_tlv_put(struct msgb *msg, uint8_t tag, uint8_t len, const uint8_t *val) -{ - uint8_t *buf = msgb_put(msg, TLV_GROSS_LEN(len)); - return tlv_put(buf, tag, len, val); -} - -static inline uint8_t *msgb_tv_put(struct msgb *msg, uint8_t tag, uint8_t val) -{ - uint8_t *buf = msgb_put(msg, 2); - return tv_put(buf, tag, val); -} - -static inline uint8_t *msgb_v_put(struct msgb *msg, uint8_t val) -{ - uint8_t *buf = msgb_put(msg, 1); - return v_put(buf, val); -} - -static inline uint8_t *msgb_tv16_put(struct msgb *msg, uint8_t tag, uint16_t val) -{ - uint8_t *buf = msgb_put(msg, 3); - return tv16_put(buf, tag, val); -} - -static inline uint8_t *msgb_tlv_push(struct msgb *msg, uint8_t tag, uint8_t len, const uint8_t *val) -{ - uint8_t *buf = msgb_push(msg, TLV_GROSS_LEN(len)); - return tlv_put(buf, tag, len, val); -} - -static inline uint8_t *msgb_tv_push(struct msgb *msg, uint8_t tag, uint8_t val) -{ - uint8_t *buf = msgb_push(msg, 2); - return tv_put(buf, tag, val); -} - -static inline uint8_t *msgb_tv16_push(struct msgb *msg, uint8_t tag, uint16_t val) -{ - uint8_t *buf = msgb_push(msg, 3); - return tv16_put(buf, tag, val); -} - -/* TLV parsing */ - -struct tlv_p_entry { - uint16_t len; - const uint8_t *val; -}; - -enum tlv_type { - TLV_TYPE_FIXED, - TLV_TYPE_T, - TLV_TYPE_TV, - TLV_TYPE_TLV, - TLV_TYPE_TL16V, - TLV_TYPE_TvLV, -}; - -struct tlv_def { - enum tlv_type type; - uint8_t fixed_len; -}; - -struct tlv_definition { - struct tlv_def def[0xff]; -}; - -struct tlv_parsed { - struct tlv_p_entry lv[0xff]; -}; - -extern struct tlv_definition tvlv_att_def; - -int tlv_parse_one(uint8_t *o_tag, uint16_t *o_len, const uint8_t **o_val, - const struct tlv_definition *def, - const uint8_t *buf, int buf_len); -int tlv_parse(struct tlv_parsed *dec, const struct tlv_definition *def, - const uint8_t *buf, int buf_len, uint8_t lv_tag, uint8_t lv_tag2); - -#define TLVP_PRESENT(x, y) ((x)->lv[y].val) -#define TLVP_LEN(x, y) (x)->lv[y].len -#define TLVP_VAL(x, y) (x)->lv[y].val - -#endif /* _TLV_H */ diff --git a/src/Makefile.am b/src/Makefile.am index bf92f05..2657809 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,8 +10,7 @@ mgcp_mgw_LDADD = $(LAFORGE_LIBS) $(NEXUSWARE_C7_LIBS) $(NEXUSWARE_UNIPORTE_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOSMOCORE_LIBS) -lpthread cellmgr_ng_SOURCES = main.c mtp_layer3.c thread.c input/ipaccess.c pcap.c \ - bss_patch.c \ - openbsc_nat/bssap.c openbsc_nat/tlv_parser.c bssap_sccp.c \ + bss_patch.c bssap_sccp.c \ msc_conn.c link_udp.c snmp_mtp.c debug.c cellmgr_ng_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOSCCP_LIBS) $(LIBOSMOVTY_LIBS) $(NEXUSWARE_C7_LIBS) \ -lpthread -lnetsnmp -lcrypto diff --git a/src/bss_patch.c b/src/bss_patch.c index 5994b9e..88280e2 100644 --- a/src/bss_patch.c +++ b/src/bss_patch.c @@ -25,8 +25,9 @@ #include -#include -#include +#include +#include + #include #include diff --git a/src/bssap_sccp.c b/src/bssap_sccp.c index 3f4a8dd..3ae80a5 100644 --- a/src/bssap_sccp.c +++ b/src/bssap_sccp.c @@ -24,8 +24,7 @@ #include #include - -#include +#include #include diff --git a/src/main.c b/src/main.c index 0df22a1..8ce1330 100644 --- a/src/main.c +++ b/src/main.c @@ -30,12 +30,11 @@ #include #include +#include #include #include -#include - #include #include diff --git a/src/openbsc_nat/bssap.c b/src/openbsc_nat/bssap.c deleted file mode 100644 index 2d23a9f..0000000 --- a/src/openbsc_nat/bssap.c +++ /dev/null @@ -1,65 +0,0 @@ -/* GSM 08.08 BSSMAP handling */ -/* (C) 2009 by Holger Hans Peter Freyther - * (C) 2009 by on-waves.com - * 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 -#include - -#include - -#include -#include - - -#define BSSMAP_MSG_SIZE 512 -#define BSSMAP_MSG_HEADROOM 128 - - -static const struct tlv_definition bss_att_tlvdef = { - .def = { - [GSM0808_IE_IMSI] = { TLV_TYPE_TLV }, - [GSM0808_IE_TMSI] = { TLV_TYPE_TLV }, - [GSM0808_IE_CELL_IDENTIFIER_LIST] = { TLV_TYPE_TLV }, - [GSM0808_IE_CHANNEL_NEEDED] = { TLV_TYPE_TV }, - [GSM0808_IE_EMLPP_PRIORITY] = { TLV_TYPE_TV }, - [GSM0808_IE_CHANNEL_TYPE] = { TLV_TYPE_TLV }, - [GSM0808_IE_PRIORITY] = { TLV_TYPE_TLV }, - [GSM0808_IE_CIRCUIT_IDENTITY_CODE] = { TLV_TYPE_TV }, - [GSM0808_IE_DOWNLINK_DTX_FLAG] = { TLV_TYPE_TV }, - [GSM0808_IE_INTERFERENCE_BAND_TO_USE] = { TLV_TYPE_TV }, - [GSM0808_IE_CLASSMARK_INFORMATION_T2] = { TLV_TYPE_TLV }, - [GSM0808_IE_GROUP_CALL_REFERENCE] = { TLV_TYPE_TLV }, - [GSM0808_IE_TALKER_FLAG] = { TLV_TYPE_T }, - [GSM0808_IE_CONFIG_EVO_INDI] = { TLV_TYPE_TV }, - [GSM0808_IE_LSA_ACCESS_CTRL_SUPPR] = { TLV_TYPE_TV }, - [GSM0808_IE_SERVICE_HANDOVER] = { TLV_TYPE_TV}, - [GSM0808_IE_ENCRYPTION_INFORMATION] = { TLV_TYPE_TLV }, - [GSM0808_IE_CIPHER_RESPONSE_MODE] = { TLV_TYPE_TV }, - [GSM0808_IE_SPEECH_VERSION] = { TLV_TYPE_TV }, - [GSM0808_IE_CHOSEN_ENCR_ALG] = { TLV_TYPE_TV }, - [GSM0808_IE_CHOSEN_CHANNEL] = { TLV_TYPE_TV }, - }, -}; - -const struct tlv_definition *gsm0808_att_tlvdef() -{ - return &bss_att_tlvdef; -} - diff --git a/src/openbsc_nat/tlv_parser.c b/src/openbsc_nat/tlv_parser.c deleted file mode 100644 index 9b38b9f..0000000 --- a/src/openbsc_nat/tlv_parser.c +++ /dev/null @@ -1,160 +0,0 @@ -#include -#include - -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) -#endif - -struct tlv_definition tvlv_att_def; - -int tlv_dump(struct tlv_parsed *dec) -{ - int i; - - for (i = 0; i <= 0xff; i++) { - if (!dec->lv[i].val) - continue; - printf("T=%02x L=%d\n", i, dec->lv[i].len); - } - return 0; -} - -/* o_tag: output: tag found - * o_len: output: length of the data - * o_val: output: pointer to the data - * def: input: a structure defining the valid TLV tags / configurations - * buf: input: the input data buffer to be parsed - * buf_len: input: the length of the input data buffer - * - * Also, returns the number of bytes consumed by the TLV entry - */ -int tlv_parse_one(uint8_t *o_tag, uint16_t *o_len, const uint8_t **o_val, - const struct tlv_definition *def, - const uint8_t *buf, int buf_len) -{ - uint8_t tag; - int len; - - tag = *buf; - *o_tag = tag; - - /* FIXME: use tables for knwon IEI */ - switch (def->def[tag].type) { - case TLV_TYPE_T: - /* GSM TS 04.07 11.2.4: Type 1 TV or Type 2 T */ - *o_val = buf; - *o_len = 0; - len = 1; - break; - case TLV_TYPE_TV: - *o_val = buf+1; - *o_len = 1; - len = 2; - break; - case TLV_TYPE_FIXED: - *o_val = buf+1; - *o_len = def->def[tag].fixed_len; - len = def->def[tag].fixed_len + 1; - break; - case TLV_TYPE_TLV: - /* GSM TS 04.07 11.2.4: Type 4 TLV */ - if (buf + 1 > buf + buf_len) - return -1; - *o_val = buf+2; - *o_len = *(buf+1); - len = *o_len + 2; - if (len > buf_len) - return -2; - break; - case TLV_TYPE_TvLV: - if (*(buf+1) & 0x80) { - /* like TLV, but without highest bit of len */ - if (buf + 1 > buf + buf_len) - return -1; - *o_val = buf+2; - *o_len = *(buf+1) & 0x7f; - len = *o_len + 2; - if (len > buf_len) - return -2; - break; - } - /* like TL16V, fallthrough */ - case TLV_TYPE_TL16V: - if (2 > buf_len) - return -1; - *o_val = buf+3; - *o_len = *(buf+1) << 8 | *(buf+2); - len = *o_len + 3; - if (len > buf_len) - return -2; - break; - default: - return -3; - } - - return len; -} - -/* dec: output: a caller-allocated pointer to a struct tlv_parsed, - * def: input: a structure defining the valid TLV tags / configurations - * buf: input: the input data buffer to be parsed - * buf_len: input: the length of the input data buffer - * lv_tag: input: an initial LV tag at the start of the buffer - * lv_tag2: input: a second initial LV tag following lv_tag - */ -int tlv_parse(struct tlv_parsed *dec, const struct tlv_definition *def, - const uint8_t *buf, int buf_len, uint8_t lv_tag, - uint8_t lv_tag2) -{ - int ofs = 0, num_parsed = 0; - uint16_t len; - - memset(dec, 0, sizeof(*dec)); - - if (lv_tag) { - if (ofs > buf_len) - return -1; - dec->lv[lv_tag].val = &buf[ofs+1]; - dec->lv[lv_tag].len = buf[ofs]; - len = dec->lv[lv_tag].len + 1; - if (ofs + len > buf_len) - return -2; - num_parsed++; - ofs += len; - } - if (lv_tag2) { - if (ofs > buf_len) - return -1; - dec->lv[lv_tag2].val = &buf[ofs+1]; - dec->lv[lv_tag2].len = buf[ofs]; - len = dec->lv[lv_tag2].len + 1; - if (ofs + len > buf_len) - return -2; - num_parsed++; - ofs += len; - } - - while (ofs < buf_len) { - int rv; - uint8_t tag; - const uint8_t *val; - - rv = tlv_parse_one(&tag, &len, &val, def, - &buf[ofs], buf_len-ofs); - if (rv < 0) - return rv; - dec->lv[tag].val = val; - dec->lv[tag].len = len; - ofs += rv; - num_parsed++; - } - //tlv_dump(dec); - return num_parsed; -} - -static __attribute__((constructor)) void on_dso_load_tlv(void) -{ - int i; - for (i = 0; i < ARRAY_SIZE(tvlv_att_def.def); i++) - tvlv_att_def.def[i].type = TLV_TYPE_TvLV; -} diff --git a/tests/patching/Makefile.am b/tests/patching/Makefile.am index 8418806..009a6d7 100644 --- a/tests/patching/Makefile.am +++ b/tests/patching/Makefile.am @@ -1,8 +1,6 @@ INCLUDES = $(all_includes) -I$(top_srcdir)/include $(LIBOSMOCORE_CFLAGS) $(LIBOSMOSCCP_CFLAGS) -Wall noinst_PROGRAMS = patching_test -patching_test_SOURCES = patching_test.c $(top_srcdir)/src/bss_patch.c \ - $(top_srcdir)/src/openbsc_nat/tlv_parser.c \ - $(top_srcdir)/src/openbsc_nat/bssap.c +patching_test_SOURCES = patching_test.c $(top_srcdir)/src/bss_patch.c patching_test_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOSCCP_LIBS) -- cgit v1.2.3