From b2eb83fa95b209fb01de2996a1382c944fc265fe Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Wed, 24 Mar 2010 02:55:33 +0100 Subject: Create a dummy m4 directory to make autoreconf --install --force work Even when removing AC_CONFIG_MACRO_DIR aclocal insisted that it needs to have a m4 directory. Make it happy by providing one. As git is not tracking directories I needed to add a dummy file. --- m4/DUMMY | 1 + 1 file changed, 1 insertion(+) create mode 100644 m4/DUMMY diff --git a/m4/DUMMY b/m4/DUMMY new file mode 100644 index 000000000..fda557ad9 --- /dev/null +++ b/m4/DUMMY @@ -0,0 +1 @@ +Dummply placeholder. -- cgit v1.2.3 From 92b1fe4c2dbdc6ed831afdb694097bb10b2274a5 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 25 Mar 2010 11:45:30 +0800 Subject: increase the use of 'struct value_string' in abis_nm and gsm_data --- openbsc/src/abis_nm.c | 295 ++++++++++++++++++++++--------------------------- openbsc/src/gsm_data.c | 135 +++++++++------------- 2 files changed, 183 insertions(+), 247 deletions(-) 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", - "", - "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/gsm_data.c b/openbsc/src/gsm_data.c index 5314d1212..176367dc7 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) @@ -377,27 +364,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) @@ -438,27 +419,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 @@ -505,28 +480,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) -- cgit v1.2.3 From b59f9350f873833757cc750306a074495f24e095 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 25 Mar 2010 11:37:04 +0800 Subject: get_value_string(): return "unknown 0x..." instead of "unknown" --- src/utils.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils.c b/src/utils.c index 2a73d397e..4dab06455 100644 --- a/src/utils.c +++ b/src/utils.c @@ -2,9 +2,11 @@ #include #include #include +#include #include +static char namebuf[255]; const char *get_value_string(const struct value_string *vs, uint32_t val) { int i; @@ -15,7 +17,9 @@ const char *get_value_string(const struct value_string *vs, uint32_t val) if (vs[i].value == val) return vs[i].str; } - return "unknown"; + + snprintf(namebuf, sizeof(namebuf), "unknown 0x%x", val); + return namebuf; } int get_string_value(const struct value_string *vs, const char *str) -- cgit v1.2.3 From e9e190a8d8251c83a423df1244b8efb79e68b143 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 25 Mar 2010 11:44:57 +0800 Subject: use more value_string in gsm48 and rsl --- src/gsm48.c | 44 +++++++++++++++++--------------------- src/rsl.c | 71 +++++++++++++++++++++++++++++-------------------------------- 2 files changed, 54 insertions(+), 61 deletions(-) diff --git a/src/gsm48.c b/src/gsm48.c index ff989eaf6..9efc2bbde 100644 --- a/src/gsm48.c +++ b/src/gsm48.c @@ -75,24 +75,25 @@ const struct tlv_definition gsm48_att_tlvdef = { }, }; -static const char *rr_cause_names[] = { - [GSM48_RR_CAUSE_NORMAL] = "Normal event", - [GSM48_RR_CAUSE_ABNORMAL_UNSPEC] = "Abnormal release, unspecified", - [GSM48_RR_CAUSE_ABNORMAL_UNACCT] = "Abnormal release, channel unacceptable", - [GSM48_RR_CAUSE_ABNORMAL_TIMER] = "Abnormal release, timer expired", - [GSM48_RR_CAUSE_ABNORMAL_NOACT] = "Abnormal release, no activity on radio path", - [GSM48_RR_CAUSE_PREMPTIVE_REL] = "Preemptive release", - [GSM48_RR_CAUSE_HNDOVER_IMP] = "Handover impossible, timing advance out of range", - [GSM48_RR_CAUSE_CHAN_MODE_UNACCT] = "Channel mode unacceptable", - [GSM48_RR_CAUSE_FREQ_NOT_IMPL] = "Frequency not implemented", - [GSM48_RR_CAUSE_CALL_CLEARED] = "Call already cleared", - [GSM48_RR_CAUSE_SEMANT_INCORR] = "Semantically incorrect message", - [GSM48_RR_CAUSE_INVALID_MAND_INF] = "Invalid mandatory information", - [GSM48_RR_CAUSE_MSG_TYPE_N] = "Message type non-existant or not implemented", - [GSM48_RR_CAUSE_MSG_TYPE_N_COMPAT] = "Message type not compatible with protocol state", - [GSM48_RR_CAUSE_COND_IE_ERROR] = "Conditional IE error", - [GSM48_RR_CAUSE_NO_CELL_ALLOC_A] = "No cell allocation available", - [GSM48_RR_CAUSE_PROT_ERROR_UNSPC] = "Protocol error unspecified", +static const struct value_string rr_cause_names[] = { + { GSM48_RR_CAUSE_NORMAL, "Normal event" }, + { GSM48_RR_CAUSE_ABNORMAL_UNSPEC, "Abnormal release, unspecified" }, + { GSM48_RR_CAUSE_ABNORMAL_UNACCT, "Abnormal release, channel unacceptable" }, + { GSM48_RR_CAUSE_ABNORMAL_TIMER, "Abnormal release, timer expired" }, + { GSM48_RR_CAUSE_ABNORMAL_NOACT, "Abnormal release, no activity on radio path" }, + { GSM48_RR_CAUSE_PREMPTIVE_REL, "Preemptive release" }, + { GSM48_RR_CAUSE_HNDOVER_IMP, "Handover impossible, timing advance out of range" }, + { GSM48_RR_CAUSE_CHAN_MODE_UNACCT, "Channel mode unacceptable" }, + { GSM48_RR_CAUSE_FREQ_NOT_IMPL, "Frequency not implemented" }, + { GSM48_RR_CAUSE_CALL_CLEARED, "Call already cleared" }, + { GSM48_RR_CAUSE_SEMANT_INCORR, "Semantically incorrect message" }, + { GSM48_RR_CAUSE_INVALID_MAND_INF, "Invalid mandatory information" }, + { GSM48_RR_CAUSE_MSG_TYPE_N, "Message type non-existant or not implemented" }, + { GSM48_RR_CAUSE_MSG_TYPE_N_COMPAT, "Message type not compatible with protocol state" }, + { GSM48_RR_CAUSE_COND_IE_ERROR, "Conditional IE error" }, + { GSM48_RR_CAUSE_NO_CELL_ALLOC_A, "No cell allocation available" }, + { GSM48_RR_CAUSE_PROT_ERROR_UNSPC, "Protocol error unspecified" }, + { 0, NULL }, }; const char *cc_state_names[32] = { @@ -201,12 +202,7 @@ static char strbuf[64]; const char *rr_cause_name(uint8_t cause) { - if (cause < ARRAY_SIZE(rr_cause_names) && - rr_cause_names[cause]) - return rr_cause_names[cause]; - - snprintf(strbuf, sizeof(strbuf), "0x%02x", cause); - return strbuf; + return get_value_string(rr_cause_names, cause); } static void to_bcd(uint8_t *bcd, uint16_t val) diff --git a/src/rsl.c b/src/rsl.c index c864b12f7..1044b08f8 100644 --- a/src/rsl.c +++ b/src/rsl.c @@ -176,39 +176,39 @@ int rsl_dec_chan_nr(uint8_t chan_nr, uint8_t *type, uint8_t *subch, uint8_t *tim return 0; } -/* FIXME: convert to value_string */ -static const char *rsl_err_vals[0xff] = { - [RSL_ERR_RADIO_IF_FAIL] = "Radio Interface Failure", - [RSL_ERR_RADIO_LINK_FAIL] = "Radio Link Failure", - [RSL_ERR_HANDOVER_ACC_FAIL] = "Handover Access Failure", - [RSL_ERR_TALKER_ACC_FAIL] = "Talker Access Failure", - [RSL_ERR_OM_INTERVENTION] = "O&M Intervention", - [RSL_ERR_NORMAL_UNSPEC] = "Normal event, unspecified", - [RSL_ERR_T_MSRFPCI_EXP] = "Siemens: T_MSRFPCI Expired", - [RSL_ERR_EQUIPMENT_FAIL] = "Equipment Failure", - [RSL_ERR_RR_UNAVAIL] = "Radio Resource not available", - [RSL_ERR_TERR_CH_FAIL] = "Terrestrial Channel Failure", - [RSL_ERR_CCCH_OVERLOAD] = "CCCH Overload", - [RSL_ERR_ACCH_OVERLOAD] = "ACCH Overload", - [RSL_ERR_PROCESSOR_OVERLOAD] = "Processor Overload", - [RSL_ERR_RES_UNAVAIL] = "Resource not available, unspecified", - [RSL_ERR_TRANSC_UNAVAIL] = "Transcoding not available", - [RSL_ERR_SERV_OPT_UNAVAIL] = "Service or Option not available", - [RSL_ERR_ENCR_UNIMPL] = "Encryption algorithm not implemented", - [RSL_ERR_SERV_OPT_UNIMPL] = "Service or Option not implemented", - [RSL_ERR_RCH_ALR_ACTV_ALLOC] = "Radio channel already activated", - [RSL_ERR_INVALID_MESSAGE] = "Invalid Message, unspecified", - [RSL_ERR_MSG_DISCR] = "Message Discriminator Error", - [RSL_ERR_MSG_TYPE] = "Message Type Error", - [RSL_ERR_MSG_SEQ] = "Message Sequence Error", - [RSL_ERR_IE_ERROR] = "General IE error", - [RSL_ERR_MAND_IE_ERROR] = "Mandatory IE error", - [RSL_ERR_OPT_IE_ERROR] = "Optional IE error", - [RSL_ERR_IE_NONEXIST] = "IE non-existent", - [RSL_ERR_IE_LENGTH] = "IE length error", - [RSL_ERR_IE_CONTENT] = "IE content error", - [RSL_ERR_PROTO] = "Protocol error, unspecified", - [RSL_ERR_INTERWORKING] = "Interworking error, unspecified", +static const struct value_string rsl_err_vals[] = { + { RSL_ERR_RADIO_IF_FAIL, "Radio Interface Failure" }, + { RSL_ERR_RADIO_LINK_FAIL, "Radio Link Failure" }, + { RSL_ERR_HANDOVER_ACC_FAIL, "Handover Access Failure" }, + { RSL_ERR_TALKER_ACC_FAIL, "Talker Access Failure" }, + { RSL_ERR_OM_INTERVENTION, "O&M Intervention" }, + { RSL_ERR_NORMAL_UNSPEC, "Normal event, unspecified" }, + { RSL_ERR_T_MSRFPCI_EXP, "Siemens: T_MSRFPCI Expired" }, + { RSL_ERR_EQUIPMENT_FAIL, "Equipment Failure" }, + { RSL_ERR_RR_UNAVAIL, "Radio Resource not available" }, + { RSL_ERR_TERR_CH_FAIL, "Terrestrial Channel Failure" }, + { RSL_ERR_CCCH_OVERLOAD, "CCCH Overload" }, + { RSL_ERR_ACCH_OVERLOAD, "ACCH Overload" }, + { RSL_ERR_PROCESSOR_OVERLOAD, "Processor Overload" }, + { RSL_ERR_RES_UNAVAIL, "Resource not available, unspecified" }, + { RSL_ERR_TRANSC_UNAVAIL, "Transcoding not available" }, + { RSL_ERR_SERV_OPT_UNAVAIL, "Service or Option not available" }, + { RSL_ERR_ENCR_UNIMPL, "Encryption algorithm not implemented" }, + { RSL_ERR_SERV_OPT_UNIMPL, "Service or Option not implemented" }, + { RSL_ERR_RCH_ALR_ACTV_ALLOC, "Radio channel already activated" }, + { RSL_ERR_INVALID_MESSAGE, "Invalid Message, unspecified" }, + { RSL_ERR_MSG_DISCR, "Message Discriminator Error" }, + { RSL_ERR_MSG_TYPE, "Message Type Error" }, + { RSL_ERR_MSG_SEQ, "Message Sequence Error" }, + { RSL_ERR_IE_ERROR, "General IE error" }, + { RSL_ERR_MAND_IE_ERROR, "Mandatory IE error" }, + { RSL_ERR_OPT_IE_ERROR, "Optional IE error" }, + { RSL_ERR_IE_NONEXIST, "IE non-existent" }, + { RSL_ERR_IE_LENGTH, "IE length error" }, + { RSL_ERR_IE_CONTENT, "IE content error" }, + { RSL_ERR_PROTO, "Protocol error, unspecified" }, + { RSL_ERR_INTERWORKING, "Interworking error, unspecified" }, + { 0, NULL } }; const struct value_string rsl_rlm_cause_strs[] = { @@ -231,10 +231,7 @@ const struct value_string rsl_rlm_cause_strs[] = { const char *rsl_err_name(uint8_t err) { - if (rsl_err_vals[err]) - return rsl_err_vals[err]; - else - return "unknown"; + return get_value_string(rsl_err_vals, err); } /* Section 3.3.2.3 TS 05.02. I think this looks like a table */ -- cgit v1.2.3 From 9eb6d88d644c9e7d85177c39f12952fd2f4d9138 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 25 Mar 2010 12:00:54 +0800 Subject: replace gsm48_cc_msg_names[] with gsm48_cc_msg_name() and implement the backend using value_string --- include/osmocore/gsm48.h | 4 +- src/gsm48.c | 120 ++++++++++++++++++++--------------------------- 2 files changed, 54 insertions(+), 70 deletions(-) diff --git a/include/osmocore/gsm48.h b/include/osmocore/gsm48.h index 787cdd0d9..1e963573c 100644 --- a/include/osmocore/gsm48.h +++ b/include/osmocore/gsm48.h @@ -5,8 +5,8 @@ #include extern const struct tlv_definition gsm48_att_tlvdef; -extern const char *cc_state_names[32]; -extern const char *gsm48_cc_msg_names[0x40]; +const char *gsm48_cc_state_name(uint8_t state); +const char *gsm48_cc_msg_name(uint8_t msgtype); const char *rr_cause_name(uint8_t cause); void gsm48_generate_lai(struct gsm48_loc_area_id *lai48, uint16_t mcc, diff --git a/src/gsm48.c b/src/gsm48.c index 9efc2bbde..5761c67b4 100644 --- a/src/gsm48.c +++ b/src/gsm48.c @@ -1,7 +1,7 @@ /* GSM Mobile Radio Interface Layer 3 messages * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */ -/* (C) 2008-2009 by Harald Welte +/* (C) 2008-2010 by Harald Welte * (C) 2008, 2009 by Holger Hans Peter Freyther * * All Rights Reserved @@ -96,7 +96,8 @@ static const struct value_string rr_cause_names[] = { { 0, NULL }, }; -const char *cc_state_names[32] = { +/* FIXME: convert to value_string */ +static const char *cc_state_names[32] = { "NULL", "INITIATED", "illegal state 2", @@ -131,74 +132,57 @@ const char *cc_state_names[32] = { "illegal state 31", }; -const char *gsm48_cc_msg_names[0x40] = { - "unknown 0x00", - "ALERTING", - "CALL_PROC", - "PROGRESS", - "ESTAB", - "SETUP", - "ESTAB_CONF", - "CONNECT", - "CALL_CONF", - "START_CC", - "unknown 0x0a", - "RECALL", - "unknown 0x0c", - "unknown 0x0d", - "EMERG_SETUP", - "CONNECT_ACK", - "USER_INFO", - "unknown 0x11", - "unknown 0x12", - "MODIFY_REJECT", - "unknown 0x14", - "unknown 0x15", - "unknown 0x16", - "MODIFY", - "HOLD", - "HOLD_ACK", - "HOLD_REJ", - "unknown 0x1b", - "RETR", - "RETR_ACK", - "RETR_REJ", - "MODIFY_COMPL", - "unknown 0x20", - "unknown 0x21", - "unknown 0x22", - "unknown 0x23", - "unknown 0x24", - "DISCONNECT", - "unknown 0x26", - "unknown 0x27", - "unknown 0x28", - "unknown 0x29", - "RELEASE_COMPL", - "unknown 0x2b", - "unknown 0x2c", - "RELEASE", - "unknown 0x2e", - "unknown 0x2f", - "unknown 0x30", - "STOP_DTMF", - "STOP_DTMF_ACK", - "unknown 0x33", - "STATUS_ENQ", - "START_DTMF", - "START_DTMF_ACK", - "START_DTMF_REJ", - "unknown 0x38", - "CONG_CTRL", - "FACILITY", - "unknown 0x3b", - "STATUS", - "unknown 0x3d", - "NOTIFY", - "unknown 0x3f", +const char *gsm48_cc_state_name(uint8_t state) +{ + if (state < ARRAY_SIZE(cc_state_names)) + return cc_state_names[state]; + + return "invalid"; +} + +static const struct value_string cc_msg_names[] = { + { GSM48_MT_CC_ALERTING, "ALERTING" }, + { GSM48_MT_CC_CALL_PROC, "CALL_PROC" }, + { GSM48_MT_CC_PROGRESS, "PROGRESS" }, + { GSM48_MT_CC_ESTAB, "ESTAB" }, + { GSM48_MT_CC_SETUP, "SETUP" }, + { GSM48_MT_CC_ESTAB_CONF, "ESTAB_CONF" }, + { GSM48_MT_CC_CONNECT, "CONNECT" }, + { GSM48_MT_CC_CALL_CONF, "CALL_CONF" }, + { GSM48_MT_CC_START_CC, "START_CC" }, + { GSM48_MT_CC_RECALL, "RECALL" }, + { GSM48_MT_CC_EMERG_SETUP, "EMERG_SETUP" }, + { GSM48_MT_CC_CONNECT_ACK, "CONNECT_ACK" }, + { GSM48_MT_CC_USER_INFO, "USER_INFO" }, + { GSM48_MT_CC_MODIFY_REJECT, "MODIFY_REJECT" }, + { GSM48_MT_CC_MODIFY, "MODIFY" }, + { GSM48_MT_CC_HOLD, "HOLD" }, + { GSM48_MT_CC_HOLD_ACK, "HOLD_ACK" }, + { GSM48_MT_CC_HOLD_REJ, "HOLD_REJ" }, + { GSM48_MT_CC_RETR, "RETR" }, + { GSM48_MT_CC_RETR_ACK, "RETR_ACK" }, + { GSM48_MT_CC_RETR_REJ, "RETR_REJ" }, + { GSM48_MT_CC_MODIFY_COMPL, "MODIFY_COMPL" }, + { GSM48_MT_CC_DISCONNECT, "DISCONNECT" }, + { GSM48_MT_CC_RELEASE_COMPL, "RELEASE_COMPL" }, + { GSM48_MT_CC_RELEASE, "RELEASE" }, + { GSM48_MT_CC_STOP_DTMF, "STOP_DTMF" }, + { GSM48_MT_CC_STOP_DTMF_ACK, "STOP_DTMF_ACK" }, + { GSM48_MT_CC_STATUS_ENQ, "STATUS_ENQ" }, + { GSM48_MT_CC_START_DTMF, "START_DTMF" }, + { GSM48_MT_CC_START_DTMF_ACK, "START_DTMF_ACK" }, + { GSM48_MT_CC_START_DTMF_REJ, "START_DTMF_REJ" }, + { GSM48_MT_CC_CONG_CTRL, "CONG_CTRL" }, + { GSM48_MT_CC_FACILITY, "FACILITY" }, + { GSM48_MT_CC_STATUS, "STATUS" }, + { GSM48_MT_CC_NOTIFY, "NOTFIY" }, + { 0, NULL } }; -static char strbuf[64]; +const char *gsm48_cc_msg_name(uint8_t msgtype) +{ + return get_value_string(cc_msg_names, msgtype); +} const char *rr_cause_name(uint8_t cause) { -- cgit v1.2.3 From 5e6466780f34f0e34953040a9dcf2bd7ddc7e3ce Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 25 Mar 2010 12:02:36 +0800 Subject: current version needs exactly 0.1.0 version of libosmocore --- openbsc/configure.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbsc/configure.in b/openbsc/configure.in index b733f780b..de0a9a958 100644 --- a/openbsc/configure.in +++ b/openbsc/configure.in @@ -18,7 +18,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.0) dnl checks for header files AC_HEADER_STDC -- cgit v1.2.3 From 52b4abdcb351830f5493a50c4181ef3947f3feab Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 25 Mar 2010 12:11:38 +0800 Subject: replace rsl_rlm_cause_strs with rsl_rlm_cause_name() --- include/osmocore/rsl.h | 3 +-- src/rsl.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/osmocore/rsl.h b/include/osmocore/rsl.h index c1080812e..99b90d68b 100644 --- a/include/osmocore/rsl.h +++ b/include/osmocore/rsl.h @@ -16,9 +16,8 @@ uint8_t rsl_enc_chan_nr(uint8_t type, uint8_t subch, uint8_t timeslot); /* decode channel number as per Section 9.3.1 */ int rsl_dec_chan_nr(uint8_t chan_nr, uint8_t *type, uint8_t *subch, uint8_t *timeslot); -extern const struct value_string rsl_rlm_cause_strs[]; - const char *rsl_err_name(uint8_t err); +const char *rsl_rlm_cause_name(uint8_t err); /* Section 3.3.2.3 TS 05.02. I think this looks like a table */ int rsl_ccch_conf_to_bs_cc_chans(int ccch_conf); diff --git a/src/rsl.c b/src/rsl.c index 1044b08f8..c002d33e2 100644 --- a/src/rsl.c +++ b/src/rsl.c @@ -211,7 +211,12 @@ static const struct value_string rsl_err_vals[] = { { 0, NULL } }; -const struct value_string rsl_rlm_cause_strs[] = { +const char *rsl_err_name(uint8_t err) +{ + return get_value_string(rsl_err_vals, err); +} + +static const struct value_string rsl_rlm_cause_strs[] = { { RLL_CAUSE_T200_EXPIRED, "Timer T200 expired (N200+1) times" }, { RLL_CAUSE_REEST_REQ, "Re-establishment request" }, { RLL_CAUSE_UNSOL_UA_RESP, "Unsolicited UA response" }, @@ -229,9 +234,9 @@ const struct value_string rsl_rlm_cause_strs[] = { { 0, NULL }, }; -const char *rsl_err_name(uint8_t err) +const char *rsl_rlm_cause_name(uint8_t err) { - return get_value_string(rsl_err_vals, err); + return get_value_string(rsl_rlm_cause_strs, err); } /* Section 3.3.2.3 TS 05.02. I think this looks like a table */ -- cgit v1.2.3 From e95daf19258999a00b8bea5247ee21603941b639 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 25 Mar 2010 12:13:02 +0800 Subject: convert openbsc to use libosmocore-0.1.1 API the 0.1.1 API is cleaned up and removes all exported global static arrays (like rlm_cause_strs). There are now proper accessor functions. --- openbsc/configure.in | 2 +- openbsc/src/abis_rsl.c | 2 +- openbsc/src/gsm_04_08.c | 9 +++++---- openbsc/src/gsm_04_08_utils.c | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/openbsc/configure.in b/openbsc/configure.in index de0a9a958..27fb0ed36 100644 --- a/openbsc/configure.in +++ b/openbsc/configure.in @@ -18,7 +18,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/src/abis_rsl.c b/openbsc/src/abis_rsl.c index 60e64cf8e..e7844afd2 100644 --- a/openbsc/src/abis_rsl.c +++ b/openbsc/src/abis_rsl.c @@ -1234,7 +1234,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/gsm_04_08.c b/openbsc/src/gsm_04_08.c index fb90ae3de..2eda0bd99 100644 --- a/openbsc/src/gsm_04_08.c +++ b/openbsc/src/gsm_04_08.c @@ -1008,7 +1008,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; } @@ -2720,7 +2721,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++) @@ -2813,8 +2814,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 68f34f409..2472f12b0 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, -- cgit v1.2.3 From 3c1221e2b23876cf0cb4170281eceb73e3395efd Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Fri, 26 Mar 2010 05:44:21 +0100 Subject: sccp: Change the ownership of the msgb passed to the callback Instead of deleting the msgb within the SCCP library the implementor of the write callback needs to free it. This is required for non blocking io with the server. --- openbsc/include/sccp/sccp.h | 2 +- openbsc/src/sccp/sccp.c | 62 ++++++++++++++---------------------------- openbsc/tests/sccp/sccp_test.c | 24 +++++++++------- 3 files changed, 35 insertions(+), 53 deletions(-) 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/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) -- cgit v1.2.3