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(-) (limited to 'src') diff --git a/src/gsm48.c b/src/gsm48.c index ff989eaf..9efc2bbd 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 c864b12f..1044b08f 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