diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2010-03-26 05:45:44 +0100 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2010-03-26 05:49:34 +0100 |
commit | 17d751531ec42fc1e63dd985c117ed4cd69eb04b (patch) | |
tree | 1ff80d4210069db51548e2d152f424e0cae1cea0 /openbsc | |
parent | facb5cdfc2d20de703c90e12a62b4ca69dea278b (diff) | |
parent | 3c1221e2b23876cf0cb4170281eceb73e3395efd (diff) |
Merge branch 'on-waves/sccp' into on-waves/bsc-master
Diffstat (limited to 'openbsc')
-rw-r--r-- | openbsc/configure.in | 2 | ||||
-rw-r--r-- | openbsc/include/sccp/sccp.h | 2 | ||||
-rw-r--r-- | openbsc/src/abis_nm.c | 295 | ||||
-rw-r--r-- | openbsc/src/abis_rsl.c | 2 | ||||
-rw-r--r-- | openbsc/src/bsc_msc_ip.c | 9 | ||||
-rw-r--r-- | openbsc/src/gsm_04_08.c | 9 | ||||
-rw-r--r-- | openbsc/src/gsm_04_08_utils.c | 2 | ||||
-rw-r--r-- | openbsc/src/gsm_data.c | 135 | ||||
-rw-r--r-- | openbsc/src/sccp/sccp.c | 62 | ||||
-rw-r--r-- | openbsc/tests/sccp/sccp_test.c | 24 |
10 files changed, 229 insertions, 313 deletions
diff --git a/openbsc/configure.in b/openbsc/configure.in index b24603680..a8fdac73d 100644 --- a/openbsc/configure.in +++ b/openbsc/configure.in @@ -16,7 +16,7 @@ dnl checks for libraries AC_SEARCH_LIBS(crypt, crypt, [LIBCRYPT="-lcrypt"; AC_DEFINE([VTY_CRYPT_PW], [], [Use crypt functionality of vty.])]) -PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 0.1.0) +PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 0.1.1) dnl checks for header files AC_HEADER_STDC diff --git a/openbsc/include/sccp/sccp.h b/openbsc/include/sccp/sccp.h index 643479adc..2e1478812 100644 --- a/openbsc/include/sccp/sccp.h +++ b/openbsc/include/sccp/sccp.h @@ -94,7 +94,7 @@ struct sccp_connection { * call sccp_system_incoming for incoming data (from the network) * sccp will call outgoing whenever outgoing data exists */ -int sccp_system_init(int (*outgoing)(struct msgb *data, void *ctx), void *context); +int sccp_system_init(void (*outgoing)(struct msgb *data, void *ctx), void *context); int sccp_system_incoming(struct msgb *data); /** diff --git a/openbsc/src/abis_nm.c b/openbsc/src/abis_nm.c index 1e5e1c87c..c9852bf82 100644 --- a/openbsc/src/abis_nm.c +++ b/openbsc/src/abis_nm.c @@ -114,125 +114,117 @@ static const enum abis_nm_msgtype nacks[] = { NM_MT_BS11_DELETE_OBJ_NACK, }; -static const char *nack_names[0xff] = { - [NM_MT_LOAD_INIT_NACK] = "SOFTWARE LOAD INIT", - [NM_MT_LOAD_END_NACK] = "SOFTWARE LOAD END", - [NM_MT_SW_ACT_REQ_NACK] = "SOFTWARE ACTIVATE REQUEST", - [NM_MT_ACTIVATE_SW_NACK] = "ACTIVATE SOFTWARE", - [NM_MT_ESTABLISH_TEI_NACK] = "ESTABLISH TEI", - [NM_MT_CONN_TERR_SIGN_NACK] = "CONNECT TERRESTRIAL SIGNALLING", - [NM_MT_DISC_TERR_SIGN_NACK] = "DISCONNECT TERRESTRIAL SIGNALLING", - [NM_MT_CONN_TERR_TRAF_NACK] = "CONNECT TERRESTRIAL TRAFFIC", - [NM_MT_DISC_TERR_TRAF_NACK] = "DISCONNECT TERRESTRIAL TRAFFIC", - [NM_MT_CONN_MDROP_LINK_NACK] = "CONNECT MULTI-DROP LINK", - [NM_MT_DISC_MDROP_LINK_NACK] = "DISCONNECT MULTI-DROP LINK", - [NM_MT_SET_BTS_ATTR_NACK] = "SET BTS ATTRIBUTE", - [NM_MT_SET_RADIO_ATTR_NACK] = "SET RADIO ATTRIBUTE", - [NM_MT_SET_CHAN_ATTR_NACK] = "SET CHANNEL ATTRIBUTE", - [NM_MT_PERF_TEST_NACK] = "PERFORM TEST", - [NM_MT_SEND_TEST_REP_NACK] = "SEND TEST REPORT", - [NM_MT_STOP_TEST_NACK] = "STOP TEST", - [NM_MT_STOP_EVENT_REP_NACK] = "STOP EVENT REPORT", - [NM_MT_REST_EVENT_REP_NACK] = "RESET EVENT REPORT", - [NM_MT_CHG_ADM_STATE_NACK] = "CHANGE ADMINISTRATIVE STATE", - [NM_MT_CHG_ADM_STATE_REQ_NACK] = "CHANGE ADMINISTRATIVE STATE REQUEST", - [NM_MT_REP_OUTST_ALARMS_NACK] = "REPORT OUTSTANDING ALARMS", - [NM_MT_CHANGEOVER_NACK] = "CHANGEOVER", - [NM_MT_OPSTART_NACK] = "OPSTART", - [NM_MT_REINIT_NACK] = "REINIT", - [NM_MT_SET_SITE_OUT_NACK] = "SET SITE OUTPUT", - [NM_MT_CHG_HW_CONF_NACK] = "CHANGE HARDWARE CONFIGURATION", - [NM_MT_GET_ATTR_NACK] = "GET ATTRIBUTE", - [NM_MT_SET_ALARM_THRES_NACK] = "SET ALARM THRESHOLD", - [NM_MT_BS11_BEGIN_DB_TX_NACK] = "BS11 BEGIN DATABASE TRANSMISSION", - [NM_MT_BS11_END_DB_TX_NACK] = "BS11 END DATABASE TRANSMISSION", - [NM_MT_BS11_CREATE_OBJ_NACK] = "BS11 CREATE OBJECT", - [NM_MT_BS11_DELETE_OBJ_NACK] = "BS11 DELETE OBJECT", +static const struct value_string nack_names[] = { + { NM_MT_LOAD_INIT_NACK, "SOFTWARE LOAD INIT" }, + { NM_MT_LOAD_END_NACK, "SOFTWARE LOAD END" }, + { NM_MT_SW_ACT_REQ_NACK, "SOFTWARE ACTIVATE REQUEST" }, + { NM_MT_ACTIVATE_SW_NACK, "ACTIVATE SOFTWARE" }, + { NM_MT_ESTABLISH_TEI_NACK, "ESTABLISH TEI" }, + { NM_MT_CONN_TERR_SIGN_NACK, "CONNECT TERRESTRIAL SIGNALLING" }, + { NM_MT_DISC_TERR_SIGN_NACK, "DISCONNECT TERRESTRIAL SIGNALLING" }, + { NM_MT_CONN_TERR_TRAF_NACK, "CONNECT TERRESTRIAL TRAFFIC" }, + { NM_MT_DISC_TERR_TRAF_NACK, "DISCONNECT TERRESTRIAL TRAFFIC" }, + { NM_MT_CONN_MDROP_LINK_NACK, "CONNECT MULTI-DROP LINK" }, + { NM_MT_DISC_MDROP_LINK_NACK, "DISCONNECT MULTI-DROP LINK" }, + { NM_MT_SET_BTS_ATTR_NACK, "SET BTS ATTRIBUTE" }, + { NM_MT_SET_RADIO_ATTR_NACK, "SET RADIO ATTRIBUTE" }, + { NM_MT_SET_CHAN_ATTR_NACK, "SET CHANNEL ATTRIBUTE" }, + { NM_MT_PERF_TEST_NACK, "PERFORM TEST" }, + { NM_MT_SEND_TEST_REP_NACK, "SEND TEST REPORT" }, + { NM_MT_STOP_TEST_NACK, "STOP TEST" }, + { NM_MT_STOP_EVENT_REP_NACK, "STOP EVENT REPORT" }, + { NM_MT_REST_EVENT_REP_NACK, "RESET EVENT REPORT" }, + { NM_MT_CHG_ADM_STATE_NACK, "CHANGE ADMINISTRATIVE STATE" }, + { NM_MT_CHG_ADM_STATE_REQ_NACK, + "CHANGE ADMINISTRATIVE STATE REQUEST" }, + { NM_MT_REP_OUTST_ALARMS_NACK, "REPORT OUTSTANDING ALARMS" }, + { NM_MT_CHANGEOVER_NACK, "CHANGEOVER" }, + { NM_MT_OPSTART_NACK, "OPSTART" }, + { NM_MT_REINIT_NACK, "REINIT" }, + { NM_MT_SET_SITE_OUT_NACK, "SET SITE OUTPUT" }, + { NM_MT_CHG_HW_CONF_NACK, "CHANGE HARDWARE CONFIGURATION" }, + { NM_MT_GET_ATTR_NACK, "GET ATTRIBUTE" }, + { NM_MT_SET_ALARM_THRES_NACK, "SET ALARM THRESHOLD" }, + { NM_MT_BS11_BEGIN_DB_TX_NACK, "BS11 BEGIN DATABASE TRANSMISSION" }, + { NM_MT_BS11_END_DB_TX_NACK, "BS11 END DATABASE TRANSMISSION" }, + { NM_MT_BS11_CREATE_OBJ_NACK, "BS11 CREATE OBJECT" }, + { NM_MT_BS11_DELETE_OBJ_NACK, "BS11 DELETE OBJECT" }, + { 0, NULL } }; /* Chapter 9.4.36 */ -static const char *nack_cause_names[] = { +static const struct value_string nack_cause_names[] = { /* General Nack Causes */ - [NM_NACK_INCORR_STRUCT] = "Incorrect message structure", - [NM_NACK_MSGTYPE_INVAL] = "Invalid message type value", - [NM_NACK_OBJCLASS_INVAL] = "Invalid Object class value", - [NM_NACK_OBJCLASS_NOTSUPP] = "Object class not supported", - [NM_NACK_BTSNR_UNKN] = "BTS no. unknown", - [NM_NACK_TRXNR_UNKN] = "Baseband Transceiver no. unknown", - [NM_NACK_OBJINST_UNKN] = "Object Instance unknown", - [NM_NACK_ATTRID_INVAL] = "Invalid attribute identifier value", - [NM_NACK_ATTRID_NOTSUPP] = "Attribute identifier not supported", - [NM_NACK_PARAM_RANGE] = "Parameter value outside permitted range", - [NM_NACK_ATTRLIST_INCONSISTENT] = "Inconsistency in attribute list", - [NM_NACK_SPEC_IMPL_NOTSUPP] = "Specified implementation not supported", - [NM_NACK_CANT_PERFORM] = "Message cannot be performed", + { NM_NACK_INCORR_STRUCT, "Incorrect message structure" }, + { NM_NACK_MSGTYPE_INVAL, "Invalid message type value" }, + { NM_NACK_OBJCLASS_INVAL, "Invalid Object class value" }, + { NM_NACK_OBJCLASS_NOTSUPP, "Object class not supported" }, + { NM_NACK_BTSNR_UNKN, "BTS no. unknown" }, + { NM_NACK_TRXNR_UNKN, "Baseband Transceiver no. unknown" }, + { NM_NACK_OBJINST_UNKN, "Object Instance unknown" }, + { NM_NACK_ATTRID_INVAL, "Invalid attribute identifier value" }, + { NM_NACK_ATTRID_NOTSUPP, "Attribute identifier not supported" }, + { NM_NACK_PARAM_RANGE, "Parameter value outside permitted range" }, + { NM_NACK_ATTRLIST_INCONSISTENT,"Inconsistency in attribute list" }, + { NM_NACK_SPEC_IMPL_NOTSUPP, "Specified implementation not supported" }, + { NM_NACK_CANT_PERFORM, "Message cannot be performed" }, /* Specific Nack Causes */ - [NM_NACK_RES_NOTIMPL] = "Resource not implemented", - [NM_NACK_RES_NOTAVAIL] = "Resource not available", - [NM_NACK_FREQ_NOTAVAIL] = "Frequency not available", - [NM_NACK_TEST_NOTSUPP] = "Test not supported", - [NM_NACK_CAPACITY_RESTR] = "Capacity restrictions", - [NM_NACK_PHYSCFG_NOTPERFORM] = "Physical configuration cannot be performed", - [NM_NACK_TEST_NOTINIT] = "Test not initiated", - [NM_NACK_PHYSCFG_NOTRESTORE] = "Physical configuration cannot be restored", - [NM_NACK_TEST_NOSUCH] = "No such test", - [NM_NACK_TEST_NOSTOP] = "Test cannot be stopped", - [NM_NACK_MSGINCONSIST_PHYSCFG] = "Message inconsistent with physical configuration", - [NM_NACK_FILE_INCOMPLETE] = "Complete file notreceived", - [NM_NACK_FILE_NOTAVAIL] = "File not available at destination", - [NM_NACK_FILE_NOTACTIVATE] = "File cannot be activate", - [NM_NACK_REQ_NOT_GRANT] = "Request not granted", - [NM_NACK_WAIT] = "Wait", - [NM_NACK_NOTH_REPORT_EXIST] = "Nothing reportable existing", - [NM_NACK_MEAS_NOTSUPP] = "Measurement not supported", - [NM_NACK_MEAS_NOTSTART] = "Measurement not started", + { NM_NACK_RES_NOTIMPL, "Resource not implemented" }, + { NM_NACK_RES_NOTAVAIL, "Resource not available" }, + { NM_NACK_FREQ_NOTAVAIL, "Frequency not available" }, + { NM_NACK_TEST_NOTSUPP, "Test not supported" }, + { NM_NACK_CAPACITY_RESTR, "Capacity restrictions" }, + { NM_NACK_PHYSCFG_NOTPERFORM, "Physical configuration cannot be performed" }, + { NM_NACK_TEST_NOTINIT, "Test not initiated" }, + { NM_NACK_PHYSCFG_NOTRESTORE, "Physical configuration cannot be restored" }, + { NM_NACK_TEST_NOSUCH, "No such test" }, + { NM_NACK_TEST_NOSTOP, "Test cannot be stopped" }, + { NM_NACK_MSGINCONSIST_PHYSCFG, "Message inconsistent with physical configuration" }, + { NM_NACK_FILE_INCOMPLETE, "Complete file notreceived" }, + { NM_NACK_FILE_NOTAVAIL, "File not available at destination" }, + { NM_NACK_FILE_NOTACTIVATE, "File cannot be activate" }, + { NM_NACK_REQ_NOT_GRANT, "Request not granted" }, + { NM_NACK_WAIT, "Wait" }, + { NM_NACK_NOTH_REPORT_EXIST, "Nothing reportable existing" }, + { NM_NACK_MEAS_NOTSUPP, "Measurement not supported" }, + { NM_NACK_MEAS_NOTSTART, "Measurement not started" }, + { 0, NULL } }; -static char namebuf[255]; static const char *nack_cause_name(u_int8_t cause) { - if (cause < ARRAY_SIZE(nack_cause_names) && nack_cause_names[cause]) - return nack_cause_names[cause]; - - snprintf(namebuf, sizeof(namebuf), "0x%02x\n", cause); - return namebuf; + return get_value_string(nack_cause_names, cause); } /* Chapter 9.4.16: Event Type */ -static const char *event_type_names[] = { - [NM_EVT_COMM_FAIL] = "communication failure", - [NM_EVT_QOS_FAIL] = "quality of service failure", - [NM_EVT_PROC_FAIL] = "processing failure", - [NM_EVT_EQUIP_FAIL] = "equipment failure", - [NM_EVT_ENV_FAIL] = "environment failure", +static const struct value_string event_type_names[] = { + { NM_EVT_COMM_FAIL, "communication failure" }, + { NM_EVT_QOS_FAIL, "quality of service failure" }, + { NM_EVT_PROC_FAIL, "processing failure" }, + { NM_EVT_EQUIP_FAIL, "equipment failure" }, + { NM_EVT_ENV_FAIL, "environment failure" }, + { 0, NULL } }; static const char *event_type_name(u_int8_t cause) { - if (cause < ARRAY_SIZE(event_type_names) && event_type_names[cause]) - return event_type_names[cause]; - - snprintf(namebuf, sizeof(namebuf), "0x%02x\n", cause); - return namebuf; + return get_value_string(event_type_names, cause); } /* Chapter 9.4.63: Perceived Severity */ -static const char *severity_names[] = { - [NM_SEVER_CEASED] = "failure ceased", - [NM_SEVER_CRITICAL] = "critical failure", - [NM_SEVER_MAJOR] = "major failure", - [NM_SEVER_MINOR] = "minor failure", - [NM_SEVER_WARNING] = "warning level failure", - [NM_SEVER_INDETERMINATE] = "indeterminate failure", +static const struct value_string severity_names[] = { + { NM_SEVER_CEASED, "failure ceased" }, + { NM_SEVER_CRITICAL, "critical failure" }, + { NM_SEVER_MAJOR, "major failure" }, + { NM_SEVER_MINOR, "minor failure" }, + { NM_SEVER_WARNING, "warning level failure" }, + { NM_SEVER_INDETERMINATE, "indeterminate failure" }, + { 0, NULL } }; static const char *severity_name(u_int8_t cause) { - if (cause < ARRAY_SIZE(severity_names) && severity_names[cause]) - return severity_names[cause]; - - snprintf(namebuf, sizeof(namebuf), "0x%02x\n", cause); - return namebuf; + return get_value_string(severity_names, cause); } /* Attributes that the BSC can set, not only get, according to Section 9.4 */ @@ -427,46 +419,30 @@ int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg) static int abis_nm_rcvmsg_sw(struct msgb *mb); +static struct value_string obj_class_names[] = { + { NM_OC_SITE_MANAGER, "SITE MANAGER" }, + { NM_OC_BTS, "BTS" }, + { NM_OC_RADIO_CARRIER, "RADIO CARRIER" }, + { NM_OC_BASEB_TRANSC, "BASEBAND TRANSCEIVER" }, + { NM_OC_CHANNEL, "CHANNEL" }, + { NM_OC_BS11_ADJC, "ADJC" }, + { NM_OC_BS11_HANDOVER, "HANDOVER" }, + { NM_OC_BS11_PWR_CTRL, "POWER CONTROL" }, + { NM_OC_BS11_BTSE, "BTSE" }, + { NM_OC_BS11_RACK, "RACK" }, + { NM_OC_BS11_TEST, "TEST" }, + { NM_OC_BS11_ENVABTSE, "ENVABTSE" }, + { NM_OC_BS11_BPORT, "BPORT" }, + { NM_OC_GPRS_NSE, "GPRS NSE" }, + { NM_OC_GPRS_CELL, "GPRS CELL" }, + { NM_OC_GPRS_NSVC, "GPRS NSVC" }, + { NM_OC_BS11, "SIEMENSHW" }, + { 0, NULL } +}; + static const char *obj_class_name(u_int8_t oc) { - switch (oc) { - case NM_OC_SITE_MANAGER: - return "SITE MANAGER"; - case NM_OC_BTS: - return "BTS"; - case NM_OC_RADIO_CARRIER: - return "RADIO CARRIER"; - case NM_OC_BASEB_TRANSC: - return "BASEBAND TRANSCEIVER"; - case NM_OC_CHANNEL: - return "CHANNEL"; - case NM_OC_BS11_ADJC: - return "ADJC"; - case NM_OC_BS11_HANDOVER: - return "HANDOVER"; - case NM_OC_BS11_PWR_CTRL: - return "POWER CONTROL"; - case NM_OC_BS11_BTSE: - return "BTSE"; - case NM_OC_BS11_RACK: - return "RACK"; - case NM_OC_BS11_TEST: - return "TEST"; - case NM_OC_BS11_ENVABTSE: - return "ENVABTSE"; - case NM_OC_BS11_BPORT: - return "BPORT"; - case NM_OC_GPRS_NSE: - return "GPRS NSE"; - case NM_OC_GPRS_CELL: - return "GPRS CELL"; - case NM_OC_GPRS_NSVC: - return "GPRS NSVC"; - case NM_OC_BS11: - return "SIEMENSHW"; - } - - return "UNKNOWN"; + return get_value_string(obj_class_names, oc); } const char *nm_opstate_name(u_int8_t os) @@ -484,24 +460,22 @@ const char *nm_opstate_name(u_int8_t os) } /* Chapter 9.4.7 */ -static const char *avail_names[] = { - "In test", - "Failed", - "Power off", - "Off line", - "<not used>", - "Dependency", - "Degraded", - "Not installed", +static const struct value_string avail_names[] = { + { 0, "In test" }, + { 1, "Failed" }, + { 2, "Power off" }, + { 3, "Off line" }, + /* Not used */ + { 5, "Dependency" }, + { 6, "Degraded" }, + { 7, "Not installed" }, + { 0xff, "OK" }, + { 0, NULL } }; const char *nm_avail_name(u_int8_t avail) { - if (avail == 0xff) - return "OK"; - if (avail >= ARRAY_SIZE(avail_names)) - return "UNKNOWN"; - return avail_names[avail]; + return get_value_string(avail_names, avail); } static struct value_string test_names[] = { @@ -960,11 +934,7 @@ static int abis_nm_rcvmsg_fom(struct msgb *mb) debugp_foh(foh); - if (nack_names[mt]) - DEBUGPC(DNM, "%s NACK ", nack_names[mt]); - /* FIXME: NACK cause */ - else - DEBUGPC(DNM, "NACK 0x%02x ", mt); + DEBUGPC(DNM, "%s NACK ", get_value_string(nack_names, mt)); abis_nm_tlv_parse(&tp, mb->trx->bts, foh->data, oh->length-sizeof(*foh)); if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES)) @@ -2894,21 +2864,18 @@ void gsm_trx_lock_rf(struct gsm_bts_trx *trx, int locked) new_state); } -static const char *ipacc_testres_names[] = { - [NM_IPACC_TESTRES_SUCCESS] = "SUCCESS", - [NM_IPACC_TESTRES_TIMEOUT] = "TIMEOUT", - [NM_IPACC_TESTRES_NO_CHANS] = "NO CHANNELS", - [NM_IPACC_TESTRES_PARTIAL] = "PARTIAL", - [NM_IPACC_TESTRES_STOPPED] = "STOPPED", +static const struct value_string ipacc_testres_names[] = { + { NM_IPACC_TESTRES_SUCCESS, "SUCCESS" }, + { NM_IPACC_TESTRES_TIMEOUT, "TIMEOUT" }, + { NM_IPACC_TESTRES_NO_CHANS, "NO CHANNELS" }, + { NM_IPACC_TESTRES_PARTIAL, "PARTIAL" }, + { NM_IPACC_TESTRES_STOPPED, "STOPPED" }, + { 0, NULL } }; const char *ipacc_testres_name(u_int8_t res) { - if (res < ARRAY_SIZE(ipacc_testres_names) && - ipacc_testres_names[res]) - return ipacc_testres_names[res]; - - return "unknown"; + return get_value_string(ipacc_testres_names, res); } void ipac_parse_cgi(struct cell_global_id *cid, const u_int8_t *buf) diff --git a/openbsc/src/abis_rsl.c b/openbsc/src/abis_rsl.c index b0f4b6e1a..96a5ab896 100644 --- a/openbsc/src/abis_rsl.c +++ b/openbsc/src/abis_rsl.c @@ -1235,7 +1235,7 @@ static int rsl_rx_rll_err_ind(struct msgb *msg) LOGP(DRLL, LOGL_ERROR, "%s ERROR INDICATION cause=%s\n", gsm_lchan_name(msg->lchan), - get_value_string(rsl_rlm_cause_strs, rlm_cause[1])); + rsl_rlm_cause_name(rlm_cause[1])); rll_indication(msg->lchan, rllh->link_id, BSC_RLLR_IND_ERR_IND); diff --git a/openbsc/src/bsc_msc_ip.c b/openbsc/src/bsc_msc_ip.c index 3b5fd0896..25ccd7143 100644 --- a/openbsc/src/bsc_msc_ip.c +++ b/openbsc/src/bsc_msc_ip.c @@ -529,7 +529,7 @@ static void print_usage() /* * SCCP handling */ -static int msc_sccp_write_ipa(struct msgb *msg, void *data) +static void msc_sccp_write_ipa(struct msgb *msg, void *data) { int ret; @@ -539,13 +539,10 @@ static int msc_sccp_write_ipa(struct msgb *msg, void *data) DEBUGP(DMI, "MSC TX %s\n", hexdump(msg->l2h, msgb_l2len(msg))); ret = write(msc_connection.fd, msg->data, msg->len); + msgb_free(msg); - if (ret <= 0) { + if (ret <= 0) perror("MSC: Failed to send SCCP"); - return -1; - } - - return 0; } static int msc_sccp_accept(struct sccp_connection *connection, void *data) diff --git a/openbsc/src/gsm_04_08.c b/openbsc/src/gsm_04_08.c index adb9de80f..5c0bc8be9 100644 --- a/openbsc/src/gsm_04_08.c +++ b/openbsc/src/gsm_04_08.c @@ -1003,7 +1003,8 @@ static void new_cc_state(struct gsm_trans *trans, int state) return; DEBUGP(DCC, "new state %s -> %s\n", - cc_state_names[trans->cc.state], cc_state_names[state]); + gsm48_cc_state_name(trans->cc.state), + gsm48_cc_state_name(state)); trans->cc.state = state; } @@ -2714,7 +2715,7 @@ int mncc_send(struct gsm_network *net, int msg_type, void *arg) trans->transaction_id, (lchan->subscr)?(lchan->subscr->extension):"-", get_mncc_name(msg_type), trans->cc.state, - cc_state_names[trans->cc.state]); + gsm48_cc_state_name(trans->cc.state)); /* Find function for current state and message */ for (i = 0; i < DOWNSLLEN; i++) @@ -2807,8 +2808,8 @@ static int gsm0408_rcv_cc(struct msgb *msg) "Received '%s' from MS in state %d (%s)\n", lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, transaction_id, (lchan->subscr)?(lchan->subscr->extension):"-", - gsm48_cc_msg_names[msg_type], trans?(trans->cc.state):0, - cc_state_names[trans?(trans->cc.state):0]); + gsm48_cc_msg_name(msg_type), trans?(trans->cc.state):0, + gsm48_cc_state_name(trans?(trans->cc.state):0)); /* Create transaction */ if (!trans) { diff --git a/openbsc/src/gsm_04_08_utils.c b/openbsc/src/gsm_04_08_utils.c index f787dee64..2d957cae3 100644 --- a/openbsc/src/gsm_04_08_utils.c +++ b/openbsc/src/gsm_04_08_utils.c @@ -68,7 +68,7 @@ int gsm48_sendmsg(struct msgb *msg, struct gsm_trans *trans) "Sending '%s' to MS.\n", msg->trx->bts->nr, msg->trx->nr, msg->lchan->ts->nr, gh->proto_discr & 0xf0, - gsm48_cc_msg_names[gh->msg_type & 0x3f]); + gsm48_cc_msg_name(gh->msg_type)); else DEBUGP(DCC, "(bts %d trx %d ts %d pd %02x) " "Sending 0x%02x to MS.\n", msg->trx->bts->nr, diff --git a/openbsc/src/gsm_data.c b/openbsc/src/gsm_data.c index 5efebc208..74c6adcae 100644 --- a/openbsc/src/gsm_data.c +++ b/openbsc/src/gsm_data.c @@ -45,52 +45,41 @@ void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr, ts->e1_link.e1_ts_ss = e1_ts_ss; } -static const char *pchan_names[] = { - [GSM_PCHAN_NONE] = "NONE", - [GSM_PCHAN_CCCH] = "CCCH", - [GSM_PCHAN_CCCH_SDCCH4] = "CCCH+SDCCH4", - [GSM_PCHAN_TCH_F] = "TCH/F", - [GSM_PCHAN_TCH_H] = "TCH/H", - [GSM_PCHAN_SDCCH8_SACCH8C] = "SDCCH8", - [GSM_PCHAN_PDCH] = "PDCH", - [GSM_PCHAN_TCH_F_PDCH] = "TCH/F_PDCH", - [GSM_PCHAN_UNKNOWN] = "UNKNOWN", +static const struct value_string pchan_names[] = { + { GSM_PCHAN_NONE, "NONE" }, + { GSM_PCHAN_CCCH, "CCCH" }, + { GSM_PCHAN_CCCH_SDCCH4,"CCCH+SDCCH4" }, + { GSM_PCHAN_TCH_F, "TCH/F" }, + { GSM_PCHAN_TCH_H, "TCH/H" }, + { GSM_PCHAN_SDCCH8_SACCH8C, "SDCCH8" }, + { GSM_PCHAN_PDCH, "PDCH" }, + { GSM_PCHAN_TCH_F_PDCH, "TCH/F_PDCH" }, + { GSM_PCHAN_UNKNOWN, "UNKNOWN" }, + { 0, NULL } }; const char *gsm_pchan_name(enum gsm_phys_chan_config c) { - if (c >= ARRAY_SIZE(pchan_names)) - return "INVALID"; - - return pchan_names[c]; + return get_value_string(pchan_names, c); } enum gsm_phys_chan_config gsm_pchan_parse(const char *name) { - int i; - - for (i = 0; i < ARRAY_SIZE(pchan_names); i++) { - if (!strcasecmp(name, pchan_names[i])) - return i; - } - - return -1; + return get_string_value(pchan_names, name); } -static const char *lchan_names[] = { - [GSM_LCHAN_NONE] = "NONE", - [GSM_LCHAN_SDCCH] = "SDCCH", - [GSM_LCHAN_TCH_F] = "TCH/F", - [GSM_LCHAN_TCH_H] = "TCH/H", - [GSM_LCHAN_UNKNOWN] = "UNKNOWN", +static const struct value_string lchant_names[] = { + { GSM_LCHAN_NONE, "NONE" }, + { GSM_LCHAN_SDCCH, "SDCCH" }, + { GSM_LCHAN_TCH_F, "TCH/F" }, + { GSM_LCHAN_TCH_H, "TCH/H" }, + { GSM_LCHAN_UNKNOWN, "UNKNOWN" }, + { 0, NULL } }; const char *gsm_lchant_name(enum gsm_chan_t c) { - if (c >= ARRAY_SIZE(lchan_names)) - return "INVALID"; - - return lchan_names[c]; + return get_value_string(lchant_names, c); } static const struct value_string lchan_s_names[] = { @@ -99,7 +88,7 @@ static const struct value_string lchan_s_names[] = { { LCHAN_S_ACTIVE, "ACTIVE" }, { LCHAN_S_INACTIVE, "INACTIVE" }, { LCHAN_S_REL_REQ, "RELEASE REQUESTED" }, - { 0, NULL }, + { 0, NULL } }; const char *gsm_lchans_name(enum gsm_lchan_state s) @@ -107,20 +96,18 @@ const char *gsm_lchans_name(enum gsm_lchan_state s) return get_value_string(lchan_s_names, s); } -static const char *chreq_names[] = { - [GSM_CHREQ_REASON_EMERG] = "EMERGENCY", - [GSM_CHREQ_REASON_PAG] = "PAGING", - [GSM_CHREQ_REASON_CALL] = "CALL", - [GSM_CHREQ_REASON_LOCATION_UPD] = "LOCATION_UPDATE", - [GSM_CHREQ_REASON_OTHER] = "OTHER", +static const struct value_string chreq_names[] = { + { GSM_CHREQ_REASON_EMERG, "EMERGENCY" }, + { GSM_CHREQ_REASON_PAG, "PAGING" }, + { GSM_CHREQ_REASON_CALL, "CALL" }, + { GSM_CHREQ_REASON_LOCATION_UPD,"LOCATION_UPDATE" }, + { GSM_CHREQ_REASON_OTHER, "OTHER" }, + { 0, NULL } }; const char *gsm_chreq_name(enum gsm_chreq_reason_t c) { - if (c >= ARRAY_SIZE(chreq_names)) - return "INVALID"; - - return chreq_names[c]; + return get_value_string(chreq_names, c); } static struct gsm_bts_model *bts_model_find(enum gsm_bts_type type) @@ -383,27 +370,21 @@ char *gsm_lchan_name(struct gsm_lchan *lchan) return ts2str; } -static const char *bts_types[] = { - [GSM_BTS_TYPE_UNKNOWN] = "unknown", - [GSM_BTS_TYPE_BS11] = "bs11", - [GSM_BTS_TYPE_NANOBTS] = "nanobts", +static const struct value_string bts_types[] = { + { GSM_BTS_TYPE_UNKNOWN, "unknown" }, + { GSM_BTS_TYPE_BS11, "bs11" }, + { GSM_BTS_TYPE_NANOBTS, "nanobts" }, + { 0, NULL } }; enum gsm_bts_type parse_btstype(const char *arg) { - int i; - for (i = 0; i < ARRAY_SIZE(bts_types); i++) { - if (!strcmp(arg, bts_types[i])) - return i; - } - return GSM_BTS_TYPE_BS11; /* Default: BS11 */ + return get_string_value(bts_types, arg); } const char *btstype2str(enum gsm_bts_type type) { - if (type > ARRAY_SIZE(bts_types)) - return "undefined"; - return bts_types[type]; + return get_value_string(bts_types, type); } struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr) @@ -444,27 +425,21 @@ struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac, return NULL; } -static const char *gsm_auth_policy_names[] = { - [GSM_AUTH_POLICY_CLOSED] = "closed", - [GSM_AUTH_POLICY_ACCEPT_ALL] = "accept-all", - [GSM_AUTH_POLICY_TOKEN] = "token", +static const struct value_string auth_policy_names[] = { + { GSM_AUTH_POLICY_CLOSED, "closed" }, + { GSM_AUTH_POLICY_ACCEPT_ALL, "accept-all" }, + { GSM_AUTH_POLICY_TOKEN, "token" }, + { 0, NULL } }; enum gsm_auth_policy gsm_auth_policy_parse(const char *arg) { - int i; - for (i = 0; i < ARRAY_SIZE(gsm_auth_policy_names); i++) { - if (!strcmp(arg, gsm_auth_policy_names[i])) - return i; - } - return GSM_AUTH_POLICY_CLOSED; + return get_string_value(auth_policy_names, arg); } const char *gsm_auth_policy_name(enum gsm_auth_policy policy) { - if (policy > ARRAY_SIZE(gsm_auth_policy_names)) - return "undefined"; - return gsm_auth_policy_names[policy]; + return get_value_string(auth_policy_names, policy); } /* this should not be here but in gsm_04_08... but that creates @@ -511,28 +486,22 @@ int gsm48_ra_id_by_bts(u_int8_t *buf, struct gsm_bts *bts) return gsm48_construct_ra(buf, &raid); } -static const char *rrlp_mode_names[] = { - [RRLP_MODE_NONE] = "none", - [RRLP_MODE_MS_BASED] = "ms-based", - [RRLP_MODE_MS_PREF] = "ms-preferred", - [RRLP_MODE_ASS_PREF] = "ass-preferred", +static const struct value_string rrlp_mode_names[] = { + { RRLP_MODE_NONE, "none" }, + { RRLP_MODE_MS_BASED, "ms-based" }, + { RRLP_MODE_MS_PREF, "ms-preferred" }, + { RRLP_MODE_ASS_PREF, "ass-preferred" }, + { 0, NULL } }; enum rrlp_mode rrlp_mode_parse(const char *arg) { - int i; - for (i = 0; i < ARRAY_SIZE(rrlp_mode_names); i++) { - if (!strcmp(arg, rrlp_mode_names[i])) - return i; - } - return RRLP_MODE_NONE; + return get_string_value(rrlp_mode_names, arg); } const char *rrlp_mode_name(enum rrlp_mode mode) { - if (mode > ARRAY_SIZE(rrlp_mode_names)) - return "none"; - return rrlp_mode_names[mode]; + return get_value_string(rrlp_mode_names, mode); } struct gsm_meas_rep *lchan_next_meas_rep(struct gsm_lchan *lchan) diff --git a/openbsc/src/sccp/sccp.c b/openbsc/src/sccp/sccp.c index b1da2c721..4bd87c8ed 100644 --- a/openbsc/src/sccp/sccp.c +++ b/openbsc/src/sccp/sccp.c @@ -45,7 +45,7 @@ const struct sockaddr_sccp sccp_ssn_bssap = { struct sccp_system { /* layer3 -> layer2 */ - int (*write_data)(struct msgb *data, void *context); + void (*write_data)(struct msgb *data, void *context); void *write_context; }; @@ -91,9 +91,9 @@ static struct sccp_data_callback *_find_ssn(u_int8_t ssn) } -static int _send_msg(struct msgb *msg) +static void _send_msg(struct msgb *msg) { - return sccp_system.write_data(msg, sccp_system.write_context); + sccp_system.write_data(msg, sccp_system.write_context); } /* @@ -499,7 +499,6 @@ static int _sccp_send_data(int class, const struct sockaddr_sccp *in, { struct sccp_data_unitdata *udt; u_int8_t *data; - int ret; if (msgb_l3len(payload) > 256) { DEBUGP(DSCCP, "The payload is too big for one udt\n"); @@ -533,10 +532,8 @@ static int _sccp_send_data(int class, const struct sockaddr_sccp *in, data[0] = msgb_l3len(payload); memcpy(&data[1], payload->l3h, msgb_l3len(payload)); - ret = _send_msg(msg); - msgb_free(msg); - - return ret; + _send_msg(msg); + return 0; } static int _sccp_handle_read(struct msgb *msgb) @@ -627,7 +624,6 @@ static int _sccp_send_refuse(struct sccp_source_reference *src_ref, int cause) struct msgb *msgb; struct sccp_connection_refused *ref; u_int8_t *data; - int ret; msgb = msgb_alloc_headroom(SCCP_MSG_SIZE, SCCP_MSG_HEADROOM, "sccp ref"); @@ -643,9 +639,8 @@ static int _sccp_send_refuse(struct sccp_source_reference *src_ref, int cause) data = msgb_put(msgb, 1); data[0] = SCCP_PNC_END_OF_OPTIONAL; - ret = _send_msg(msgb); - msgb_free(msgb); - return ret; + _send_msg(msgb); + return 0; } static int _sccp_send_connection_confirm(struct sccp_connection *connection) @@ -653,7 +648,6 @@ static int _sccp_send_connection_confirm(struct sccp_connection *connection) struct msgb *response; struct sccp_connection_confirm *confirm; u_int8_t *optional_data; - int ret; if (assign_source_local_reference(connection) != 0) return -1; @@ -677,11 +671,9 @@ static int _sccp_send_connection_confirm(struct sccp_connection *connection) optional_data = (u_int8_t *) msgb_put(response, 1); optional_data[0] = SCCP_PNC_END_OF_OPTIONAL; - ret = _send_msg(response); - msgb_free(response); - + _send_msg(response); _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_ESTABLISHED); - return ret; + return 0; } static int _sccp_send_connection_request(struct sccp_connection *connection, @@ -691,7 +683,6 @@ static int _sccp_send_connection_request(struct sccp_connection *connection, struct sccp_connection_request *req; u_int8_t *data; u_int8_t extra_size = 3 + 1; - int ret; if (msg && (msgb_l3len(msg) < 3 || msgb_l3len(msg) > 130)) { @@ -741,10 +732,8 @@ static int _sccp_send_connection_request(struct sccp_connection *connection, llist_add_tail(&connection->list, &sccp_connections); _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_REQUEST); - ret = _send_msg(request); - msgb_free(request); - - return ret; + _send_msg(request); + return 0; } static int _sccp_send_connection_data(struct sccp_connection *conn, struct msgb *_data) @@ -753,7 +742,6 @@ static int _sccp_send_connection_data(struct sccp_connection *conn, struct msgb struct sccp_data_form1 *dt1; u_int8_t *data; int extra_size; - int ret; if (msgb_l3len(_data) < 2 || msgb_l3len(_data) > 256) { DEBUGP(DSCCP, "data size too big, segmenting unimplemented.\n"); @@ -777,17 +765,14 @@ static int _sccp_send_connection_data(struct sccp_connection *conn, struct msgb data[0] = extra_size - 1; memcpy(&data[1], _data->l3h, extra_size - 1); - ret = _send_msg(msgb); - msgb_free(msgb); - - return ret; + _send_msg(msgb); + return 0; } static int _sccp_send_connection_it(struct sccp_connection *conn) { struct msgb *msgb; struct sccp_data_it *it; - int ret; msgb = msgb_alloc_headroom(SCCP_MSG_SIZE, SCCP_MSG_HEADROOM, "sccp it"); @@ -803,9 +788,8 @@ static int _sccp_send_connection_it(struct sccp_connection *conn) it->sequencing[0] = it->sequencing[1] = 0; it->credit = 0; - ret = _send_msg(msgb); - msgb_free(msgb); - return ret; + _send_msg(msgb); + return 0; } static int _sccp_send_connection_released(struct sccp_connection *conn, int cause) @@ -813,7 +797,6 @@ static int _sccp_send_connection_released(struct sccp_connection *conn, int caus struct msgb *msg; struct sccp_connection_released *rel; u_int8_t *data; - int ret; msg = msgb_alloc_headroom(SCCP_MSG_SIZE, SCCP_MSG_HEADROOM, "sccp: connection released"); @@ -832,10 +815,8 @@ static int _sccp_send_connection_released(struct sccp_connection *conn, int caus data[0] = SCCP_PNC_END_OF_OPTIONAL; _sccp_set_connection_state(conn, SCCP_CONNECTION_STATE_RELEASE); - ret = _send_msg(msg); - msgb_free(msg); - - return ret; + _send_msg(msg); + return 0; } /* @@ -982,7 +963,6 @@ static int _sccp_send_connection_release_complete(struct sccp_connection *connec { struct msgb *msgb; struct sccp_connection_release_complete *rlc; - int ret; msgb = msgb_alloc_headroom(SCCP_MSG_SIZE, SCCP_MSG_HEADROOM, "sccp rlc"); @@ -995,8 +975,7 @@ static int _sccp_send_connection_release_complete(struct sccp_connection *connec memcpy(&rlc->source_local_reference, &connection->source_local_reference, sizeof(struct sccp_source_reference)); - ret = _send_msg(msgb); - msgb_free(msgb); + _send_msg(msgb); /* * Remove from the list of active connections and set the state. User code @@ -1004,8 +983,7 @@ static int _sccp_send_connection_release_complete(struct sccp_connection *connec */ llist_del(&connection->list); _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_RELEASE_COMPLETE); - - return ret; + return 0; } /* connection released, send a released confirm */ @@ -1118,7 +1096,7 @@ found: } -int sccp_system_init(int (*outgoing)(struct msgb *data, void *ctx), void *ctx) +int sccp_system_init(void (*outgoing)(struct msgb *data, void *ctx), void *ctx) { sccp_system.write_data = outgoing; sccp_system.write_context = ctx; diff --git a/openbsc/tests/sccp/sccp_test.c b/openbsc/tests/sccp/sccp_test.c index eb41d3eaf..0c2adc83f 100644 --- a/openbsc/tests/sccp/sccp_test.c +++ b/openbsc/tests/sccp/sccp_test.c @@ -354,14 +354,14 @@ int sccp_read_cb(struct msgb *data, unsigned len, void *context) return 0; } -int sccp_write_cb(struct msgb *data, void *ctx) +void sccp_write_cb(struct msgb *data, void *ctx) { int i = 0; const u_int8_t *got, *wanted; if (test_data[current_test].response == NULL) { FAIL("Didn't expect write callback\n"); - return -1; + goto exit; } else if (test_data[current_test].response_length != msgb_l2len(data)) { FAIL("Size does not match. Got: %d Wanted: %d\n", msgb_l2len(data), test_data[current_test].response_length); @@ -374,12 +374,14 @@ int sccp_write_cb(struct msgb *data, void *ctx) if (got[i] != wanted[i]) { FAIL("Failed to compare byte. Got: 0x%x Wanted: 0x%x at %d\n", got[i], wanted[i], i); - return -1; + goto exit; } } write_called = 1; - return 0; + +exit: + msgb_free(data); } void sccp_c_read(struct sccp_connection *connection, struct msgb *msgb, unsigned int len) @@ -409,7 +411,7 @@ int sccp_accept_cb(struct sccp_connection *connection, void *user_data) return 0; } -static int sccp_udt_write_cb(struct msgb *data, void *context) +static void sccp_udt_write_cb(struct msgb *data, void *context) { const u_int8_t *got, *wanted; int i; @@ -419,7 +421,7 @@ static int sccp_udt_write_cb(struct msgb *data, void *context) if (send_data[current_test].length != msgb_l2len(data)) { FAIL("Size does not match. Got: %d Wanted: %d\n", msgb_l2len(data), send_data[current_test].length); - return -1; + goto exit; } got = &data->l2h[0]; @@ -429,12 +431,14 @@ static int sccp_udt_write_cb(struct msgb *data, void *context) if (got[i] != wanted[i]) { FAIL("Failed to compare byte. Got: 0x%x Wanted: 0x%x at %d\n", got[i], wanted[i], i); - return -1; + goto exit; } } matched = 1; - return 0; + +exit: + msgb_free(data); } static void test_sccp_system(void) @@ -504,11 +508,11 @@ static int sccp_udt_read(struct msgb *data, unsigned int len, void *context) return 0; } -static int sccp_write_loop(struct msgb *data, void *context) +static void sccp_write_loop(struct msgb *data, void *context) { /* send it back to us */ sccp_system_incoming(data); - return 0; + msgb_free(data); } static void test_sccp_udt_communication(void) |